Merge branch 'linus' into cont_syslog
[safe/jmp/linux-2.6] / drivers / hwmon / gl520sm.c
index 8984ef1..ec58802 100644 (file)
@@ -41,9 +41,6 @@ MODULE_PARM_DESC(extra_sensor_type, "Type of extra sensor (0=autodetect, 1=tempe
 /* Addresses to scan */
 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
 
-/* Insmod parameters */
-I2C_CLIENT_INSMOD_1(gl520sm);
-
 /* Many GL520 constants specified below
 One of the inputs can be configured as either temp or voltage.
 That's why _TEMP2 and _IN4 access the same register
@@ -79,26 +76,36 @@ static const u8 GL520_REG_TEMP_MAX_HYST[]   = { 0x06, 0x18 };
  * Function declarations
  */
 
-static int gl520_attach_adapter(struct i2c_adapter *adapter);
-static int gl520_detect(struct i2c_adapter *adapter, int address, int kind);
+static int gl520_probe(struct i2c_client *client,
+                      const struct i2c_device_id *id);
+static int gl520_detect(struct i2c_client *client, struct i2c_board_info *info);
 static void gl520_init_client(struct i2c_client *client);
-static int gl520_detach_client(struct i2c_client *client);
+static int gl520_remove(struct i2c_client *client);
 static int gl520_read_value(struct i2c_client *client, u8 reg);
 static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value);
 static struct gl520_data *gl520_update_device(struct device *dev);
 
 /* Driver data */
+static const struct i2c_device_id gl520_id[] = {
+       { "gl520sm", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, gl520_id);
+
 static struct i2c_driver gl520_driver = {
+       .class          = I2C_CLASS_HWMON,
        .driver = {
                .name   = "gl520sm",
        },
-       .attach_adapter = gl520_attach_adapter,
-       .detach_client  = gl520_detach_client,
+       .probe          = gl520_probe,
+       .remove         = gl520_remove,
+       .id_table       = gl520_id,
+       .detect         = gl520_detect,
+       .address_list   = normal_i2c,
 };
 
 /* Client data */
 struct gl520_data {
-       struct i2c_client client;
        struct device *hwmon_dev;
        struct mutex update_lock;
        char valid;             /* zero until the following fields are valid */
@@ -669,62 +676,49 @@ static const struct attribute_group gl520_group_opt = {
  * Real code
  */
 
-static int gl520_attach_adapter(struct i2c_adapter *adapter)
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int gl520_detect(struct i2c_client *client, struct i2c_board_info *info)
 {
-       if (!(adapter->class & I2C_CLASS_HWMON))
-               return 0;
-       return i2c_probe(adapter, &addr_data, gl520_detect);
-}
-
-static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
-{
-       struct i2c_client *client;
-       struct gl520_data *data;
-       int err = 0;
+       struct i2c_adapter *adapter = client->adapter;
 
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
                                     I2C_FUNC_SMBUS_WORD_DATA))
-               goto exit;
+               return -ENODEV;
+
+       /* Determine the chip type. */
+       if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) ||
+           ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) ||
+           ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) {
+               dev_dbg(&client->dev, "Unknown chip type, skipping\n");
+               return -ENODEV;
+       }
+
+       strlcpy(info->type, "gl520sm", I2C_NAME_SIZE);
+
+       return 0;
+}
 
-       /* OK. For now, we presume we have a valid client. We now create the
-          client structure, even though we cannot fill it completely yet.
-          But it allows us to access gl520_{read,write}_value. */
+static int gl520_probe(struct i2c_client *client,
+                      const struct i2c_device_id *id)
+{
+       struct gl520_data *data;
+       int err;
 
-       if (!(data = kzalloc(sizeof(struct gl520_data), GFP_KERNEL))) {
+       data = kzalloc(sizeof(struct gl520_data), GFP_KERNEL);
+       if (!data) {
                err = -ENOMEM;
                goto exit;
        }
 
-       client = &data->client;
        i2c_set_clientdata(client, data);
-       client->addr = address;
-       client->adapter = adapter;
-       client->driver = &gl520_driver;
-
-       /* Determine the chip type. */
-       if (kind < 0) {
-               if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) ||
-                   ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) ||
-                   ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) {
-                       dev_dbg(&client->dev, "Unknown chip type, skipping\n");
-                       goto exit_free;
-               }
-       }
-
-       /* Fill in the remaining client fields */
-       strlcpy(client->name, "gl520sm", I2C_NAME_SIZE);
        mutex_init(&data->update_lock);
 
-       /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(client)))
-               goto exit_free;
-
        /* Initialize the GL520SM chip */
        gl520_init_client(client);
 
        /* Register sysfs hooks */
        if ((err = sysfs_create_group(&client->dev.kobj, &gl520_group)))
-               goto exit_detach;
+               goto exit_free;
 
        if (data->two_temps) {
                if ((err = device_create_file(&client->dev,
@@ -764,8 +758,6 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
 exit_remove_files:
        sysfs_remove_group(&client->dev.kobj, &gl520_group);
        sysfs_remove_group(&client->dev.kobj, &gl520_group_opt);
-exit_detach:
-       i2c_detach_client(client);
 exit_free:
        kfree(data);
 exit:
@@ -811,18 +803,14 @@ static void gl520_init_client(struct i2c_client *client)
        gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
 }
 
-static int gl520_detach_client(struct i2c_client *client)
+static int gl520_remove(struct i2c_client *client)
 {
        struct gl520_data *data = i2c_get_clientdata(client);
-       int err;
 
        hwmon_device_unregister(data->hwmon_dev);
        sysfs_remove_group(&client->dev.kobj, &gl520_group);
        sysfs_remove_group(&client->dev.kobj, &gl520_group_opt);
 
-       if ((err = i2c_detach_client(client)))
-               return err;
-
        kfree(data);
        return 0;
 }