hp_accel: fix race in device removal
[safe/jmp/linux-2.6] / drivers / hwmon / max1619.c
index 1ab1cac..022ded0 100644 (file)
@@ -41,12 +41,6 @@ static const unsigned short normal_i2c[] = {
        0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END };
 
 /*
- * Insmod parameters
- */
-
-I2C_CLIENT_INSMOD_1(max1619);
-
-/*
  * The MAX1619 registers
  */
 
@@ -69,11 +63,18 @@ I2C_CLIENT_INSMOD_1(max1619);
 #define MAX1619_REG_W_TCRIT_HYST       0x13
 
 /*
- * Conversions and various macros
+ * Conversions
  */
 
-#define TEMP_FROM_REG(val)     ((val & 0x80 ? val-0x100 : val) * 1000)
-#define TEMP_TO_REG(val)       ((val < 0 ? val+0x100*1000 : val) / 1000)
+static int temp_from_reg(int val)
+{
+       return (val & 0x80 ? val-0x100 : val) * 1000;
+}
+
+static int temp_to_reg(int val)
+{
+       return (val < 0 ? val+0x100*1000 : val) / 1000;
+}
 
 /*
  * Functions declaration
@@ -81,7 +82,7 @@ I2C_CLIENT_INSMOD_1(max1619);
 
 static int max1619_probe(struct i2c_client *client,
                         const struct i2c_device_id *id);
-static int max1619_detect(struct i2c_client *client, int kind,
+static int max1619_detect(struct i2c_client *client,
                          struct i2c_board_info *info);
 static void max1619_init_client(struct i2c_client *client);
 static int max1619_remove(struct i2c_client *client);
@@ -92,7 +93,7 @@ static struct max1619_data *max1619_update_device(struct device *dev);
  */
 
 static const struct i2c_device_id max1619_id[] = {
-       { "max1619", max1619 },
+       { "max1619", 0 },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, max1619_id);
@@ -106,7 +107,7 @@ static struct i2c_driver max1619_driver = {
        .remove         = max1619_remove,
        .id_table       = max1619_id,
        .detect         = max1619_detect,
-       .address_data   = &addr_data,
+       .address_list   = normal_i2c,
 };
 
 /*
@@ -135,7 +136,7 @@ struct max1619_data {
 static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \
 { \
        struct max1619_data *data = max1619_update_device(dev); \
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \
+       return sprintf(buf, "%d\n", temp_from_reg(data->value)); \
 }
 show_temp(temp_input1);
 show_temp(temp_input2);
@@ -153,7 +154,7 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
        long val = simple_strtol(buf, NULL, 10); \
  \
        mutex_lock(&data->update_lock); \
-       data->value = TEMP_TO_REG(val); \
+       data->value = temp_to_reg(val); \
        i2c_smbus_write_byte_data(client, reg, data->value); \
        mutex_unlock(&data->update_lock); \
        return count; \
@@ -219,58 +220,34 @@ static const struct attribute_group max1619_group = {
  */
 
 /* Return 0 if detection is successful, -ENODEV otherwise */
-static int max1619_detect(struct i2c_client *new_client, int kind,
+static int max1619_detect(struct i2c_client *client,
                          struct i2c_board_info *info)
 {
-       struct i2c_adapter *adapter = new_client->adapter;
-       u8 reg_config=0, reg_convrate=0, reg_status=0;
+       struct i2c_adapter *adapter = client->adapter;
+       u8 reg_config, reg_convrate, reg_status, man_id, chip_id;
 
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
                return -ENODEV;
 
-       /*
-        * Now we do the remaining detection. A negative kind means that
-        * the driver was loaded with no force parameter (default), so we
-        * must both detect and identify the chip. A zero kind means that
-        * the driver was loaded with the force parameter, the detection
-        * step shall be skipped. A positive kind means that the driver
-        * was loaded with the force parameter and a given kind of chip is
-        * requested, so both the detection and the identification steps
-        * are skipped.
-        */
-       if (kind < 0) { /* detection */
-               reg_config = i2c_smbus_read_byte_data(new_client,
-                             MAX1619_REG_R_CONFIG);
-               reg_convrate = i2c_smbus_read_byte_data(new_client,
-                              MAX1619_REG_R_CONVRATE);
-               reg_status = i2c_smbus_read_byte_data(new_client,
-                               MAX1619_REG_R_STATUS);
-               if ((reg_config & 0x03) != 0x00
-                || reg_convrate > 0x07 || (reg_status & 0x61 ) !=0x00) {
-                       dev_dbg(&adapter->dev,
-                               "MAX1619 detection failed at 0x%02x.\n",
-                               new_client->addr);
-                       return -ENODEV;
-               }
+       /* detection */
+       reg_config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG);
+       reg_convrate = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONVRATE);
+       reg_status = i2c_smbus_read_byte_data(client, MAX1619_REG_R_STATUS);
+       if ((reg_config & 0x03) != 0x00
+        || reg_convrate > 0x07 || (reg_status & 0x61) != 0x00) {
+               dev_dbg(&adapter->dev, "MAX1619 detection failed at 0x%02x\n",
+                       client->addr);
+               return -ENODEV;
        }
 
-       if (kind <= 0) { /* identification */
-               u8 man_id, chip_id;
-       
-               man_id = i2c_smbus_read_byte_data(new_client,
-                        MAX1619_REG_R_MAN_ID);
-               chip_id = i2c_smbus_read_byte_data(new_client,
-                         MAX1619_REG_R_CHIP_ID);
-               
-               if ((man_id == 0x4D) && (chip_id == 0x04))
-                       kind = max1619;
-
-               if (kind <= 0) { /* identification failed */
-                       dev_info(&adapter->dev,
-                           "Unsupported chip (man_id=0x%02X, "
-                           "chip_id=0x%02X).\n", man_id, chip_id);
-                       return -ENODEV;
-               }
+       /* identification */
+       man_id = i2c_smbus_read_byte_data(client, MAX1619_REG_R_MAN_ID);
+       chip_id = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CHIP_ID);
+       if (man_id != 0x4D || chip_id != 0x04) {
+               dev_info(&adapter->dev,
+                        "Unsupported chip (man_id=0x%02X, chip_id=0x%02X).\n",
+                        man_id, chip_id);
+               return -ENODEV;
        }
 
        strlcpy(info->type, "max1619", I2C_NAME_SIZE);