i2c: Drop I2C_CLIENT_INSMOD_1
[safe/jmp/linux-2.6] / drivers / hwmon / lm63.c
index 00a50be..bf81aff 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * lm63.c - driver for the National Semiconductor LM63 temperature sensor
  *          with integrated fan control
- * Copyright (C) 2004-2006  Jean Delvare <khali@linux-fr.org>
+ * Copyright (C) 2004-2008  Jean Delvare <khali@linux-fr.org>
  * Based on the lm90 driver.
  *
  * The LM63 is a sensor chip made by National Semiconductor. It measures
 #include <linux/hwmon.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
+#include <linux/sysfs.h>
 
 /*
  * Addresses to scan
  * Address is fully defined internally and cannot be changed.
  */
 
-static unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END };
-
-/*
- * Insmod parameters
- */
-
-I2C_CLIENT_INSMOD_1(lm63);
+static const unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END };
 
 /*
  * The LM63 registers
@@ -127,24 +122,35 @@ I2C_CLIENT_INSMOD_1(lm63);
  * Functions declaration
  */
 
-static int lm63_attach_adapter(struct i2c_adapter *adapter);
-static int lm63_detach_client(struct i2c_client *client);
+static int lm63_probe(struct i2c_client *client,
+                     const struct i2c_device_id *id);
+static int lm63_remove(struct i2c_client *client);
 
 static struct lm63_data *lm63_update_device(struct device *dev);
 
-static int lm63_detect(struct i2c_adapter *adapter, int address, int kind);
+static int lm63_detect(struct i2c_client *client, struct i2c_board_info *info);
 static void lm63_init_client(struct i2c_client *client);
 
 /*
  * Driver data (common to all clients)
  */
 
+static const struct i2c_device_id lm63_id[] = {
+       { "lm63", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, lm63_id);
+
 static struct i2c_driver lm63_driver = {
+       .class          = I2C_CLASS_HWMON,
        .driver = {
                .name   = "lm63",
        },
-       .attach_adapter = lm63_attach_adapter,
-       .detach_client  = lm63_detach_client,
+       .probe          = lm63_probe,
+       .remove         = lm63_remove,
+       .id_table       = lm63_id,
+       .detect         = lm63_detect,
+       .address_list   = normal_i2c,
 };
 
 /*
@@ -152,8 +158,7 @@ static struct i2c_driver lm63_driver = {
  */
 
 struct lm63_data {
-       struct i2c_client client;
-       struct class_device *class_dev;
+       struct device *hwmon_dev;
        struct mutex update_lock;
        char valid; /* zero until following fields are valid */
        unsigned long last_updated; /* in jiffies */
@@ -363,145 +368,133 @@ static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst,
 /* Individual alarm files */
 static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
 static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
-static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 2);
 static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
 static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
 static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
 /* Raw alarm file for compatibility */
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
 
+static struct attribute *lm63_attributes[] = {
+       &dev_attr_pwm1.attr,
+       &dev_attr_pwm1_enable.attr,
+       &sensor_dev_attr_temp1_input.dev_attr.attr,
+       &sensor_dev_attr_temp2_input.dev_attr.attr,
+       &sensor_dev_attr_temp2_min.dev_attr.attr,
+       &sensor_dev_attr_temp1_max.dev_attr.attr,
+       &sensor_dev_attr_temp2_max.dev_attr.attr,
+       &sensor_dev_attr_temp2_crit.dev_attr.attr,
+       &dev_attr_temp2_crit_hyst.attr,
+
+       &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_fault.dev_attr.attr,
+       &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+       &dev_attr_alarms.attr,
+       NULL
+};
+
+static const struct attribute_group lm63_group = {
+       .attrs = lm63_attributes,
+};
+
+static struct attribute *lm63_attributes_fan1[] = {
+       &sensor_dev_attr_fan1_input.dev_attr.attr,
+       &sensor_dev_attr_fan1_min.dev_attr.attr,
+
+       &sensor_dev_attr_fan1_min_alarm.dev_attr.attr,
+       NULL
+};
+
+static const struct attribute_group lm63_group_fan1 = {
+       .attrs = lm63_attributes_fan1,
+};
+
 /*
  * Real code
  */
 
-static int lm63_attach_adapter(struct i2c_adapter *adapter)
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int lm63_detect(struct i2c_client *new_client,
+                      struct i2c_board_info *info)
 {
-       if (!(adapter->class & I2C_CLASS_HWMON))
-               return 0;
-       return i2c_probe(adapter, &addr_data, lm63_detect);
+       struct i2c_adapter *adapter = new_client->adapter;
+       u8 man_id, chip_id, reg_config1, reg_config2;
+       u8 reg_alert_status, reg_alert_mask;
+
+       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+               return -ENODEV;
+
+       man_id = i2c_smbus_read_byte_data(new_client, LM63_REG_MAN_ID);
+       chip_id = i2c_smbus_read_byte_data(new_client, LM63_REG_CHIP_ID);
+
+       reg_config1 = i2c_smbus_read_byte_data(new_client,
+                     LM63_REG_CONFIG1);
+       reg_config2 = i2c_smbus_read_byte_data(new_client,
+                     LM63_REG_CONFIG2);
+       reg_alert_status = i2c_smbus_read_byte_data(new_client,
+                          LM63_REG_ALERT_STATUS);
+       reg_alert_mask = i2c_smbus_read_byte_data(new_client,
+                        LM63_REG_ALERT_MASK);
+
+       if (man_id != 0x01 /* National Semiconductor */
+        || chip_id != 0x41 /* LM63 */
+        || (reg_config1 & 0x18) != 0x00
+        || (reg_config2 & 0xF8) != 0x00
+        || (reg_alert_status & 0x20) != 0x00
+        || (reg_alert_mask & 0xA4) != 0xA4) {
+               dev_dbg(&adapter->dev,
+                       "Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n",
+                       man_id, chip_id);
+               return -ENODEV;
+       }
+
+       strlcpy(info->type, "lm63", I2C_NAME_SIZE);
+
+       return 0;
 }
 
-/*
- * The following function does more than just detection. If detection
- * succeeds, it also registers the new chip.
- */
-static int lm63_detect(struct i2c_adapter *adapter, int address, int kind)
+static int lm63_probe(struct i2c_client *new_client,
+                     const struct i2c_device_id *id)
 {
-       struct i2c_client *new_client;
        struct lm63_data *data;
-       int err = 0;
-
-       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
-               goto exit;
+       int err;
 
-       if (!(data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL))) {
+       data = kzalloc(sizeof(struct lm63_data), GFP_KERNEL);
+       if (!data) {
                err = -ENOMEM;
                goto exit;
        }
 
-       /* The common I2C client data is placed right before the
-          LM63-specific data. */
-       new_client = &data->client;
        i2c_set_clientdata(new_client, data);
-       new_client->addr = address;
-       new_client->adapter = adapter;
-       new_client->driver = &lm63_driver;
-       new_client->flags = 0;
-
-       /* Default to an LM63 if forced */
-       if (kind == 0)
-               kind = lm63;
-
-       if (kind < 0) { /* must identify */
-               u8 man_id, chip_id, reg_config1, reg_config2;
-               u8 reg_alert_status, reg_alert_mask;
-
-               man_id = i2c_smbus_read_byte_data(new_client,
-                        LM63_REG_MAN_ID);
-               chip_id = i2c_smbus_read_byte_data(new_client,
-                         LM63_REG_CHIP_ID);
-               reg_config1 = i2c_smbus_read_byte_data(new_client,
-                             LM63_REG_CONFIG1);
-               reg_config2 = i2c_smbus_read_byte_data(new_client,
-                             LM63_REG_CONFIG2);
-               reg_alert_status = i2c_smbus_read_byte_data(new_client,
-                                  LM63_REG_ALERT_STATUS);
-               reg_alert_mask = i2c_smbus_read_byte_data(new_client,
-                                LM63_REG_ALERT_MASK);
-
-               if (man_id == 0x01 /* National Semiconductor */
-                && chip_id == 0x41 /* LM63 */
-                && (reg_config1 & 0x18) == 0x00
-                && (reg_config2 & 0xF8) == 0x00
-                && (reg_alert_status & 0x20) == 0x00
-                && (reg_alert_mask & 0xA4) == 0xA4) {
-                       kind = lm63;
-               } else { /* failed */
-                       dev_dbg(&adapter->dev, "Unsupported chip "
-                               "(man_id=0x%02X, chip_id=0x%02X).\n",
-                               man_id, chip_id);
-                       goto exit_free;
-               }
-       }
-
-       strlcpy(new_client->name, "lm63", I2C_NAME_SIZE);
        data->valid = 0;
        mutex_init(&data->update_lock);
 
-       /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(new_client)))
-               goto exit_free;
-
        /* Initialize the LM63 chip */
        lm63_init_client(new_client);
 
        /* Register sysfs hooks */
-       data->class_dev = hwmon_device_register(&new_client->dev);
-       if (IS_ERR(data->class_dev)) {
-               err = PTR_ERR(data->class_dev);
-               goto exit_detach;
+       if ((err = sysfs_create_group(&new_client->dev.kobj,
+                                     &lm63_group)))
+               goto exit_free;
+       if (data->config & 0x04) { /* tachometer enabled */
+               if ((err = sysfs_create_group(&new_client->dev.kobj,
+                                             &lm63_group_fan1)))
+                       goto exit_remove_files;
        }
 
-       if (data->config & 0x04) { /* tachometer enabled */
-               device_create_file(&new_client->dev,
-                                  &sensor_dev_attr_fan1_input.dev_attr);
-               device_create_file(&new_client->dev,
-                                  &sensor_dev_attr_fan1_min.dev_attr);
-               device_create_file(&new_client->dev,
-                                  &sensor_dev_attr_fan1_min_alarm.dev_attr);
+       data->hwmon_dev = hwmon_device_register(&new_client->dev);
+       if (IS_ERR(data->hwmon_dev)) {
+               err = PTR_ERR(data->hwmon_dev);
+               goto exit_remove_files;
        }
-       device_create_file(&new_client->dev, &dev_attr_pwm1);
-       device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
-       device_create_file(&new_client->dev,
-                          &sensor_dev_attr_temp1_input.dev_attr);
-       device_create_file(&new_client->dev,
-                          &sensor_dev_attr_temp2_input.dev_attr);
-       device_create_file(&new_client->dev,
-                          &sensor_dev_attr_temp2_min.dev_attr);
-       device_create_file(&new_client->dev,
-                          &sensor_dev_attr_temp1_max.dev_attr);
-       device_create_file(&new_client->dev,
-                          &sensor_dev_attr_temp2_max.dev_attr);
-       device_create_file(&new_client->dev,
-                          &sensor_dev_attr_temp2_crit.dev_attr);
-       device_create_file(&new_client->dev, &dev_attr_temp2_crit_hyst);
-
-       device_create_file(&new_client->dev,
-                          &sensor_dev_attr_temp2_input_fault.dev_attr);
-       device_create_file(&new_client->dev,
-                          &sensor_dev_attr_temp2_min_alarm.dev_attr);
-       device_create_file(&new_client->dev,
-                          &sensor_dev_attr_temp1_max_alarm.dev_attr);
-       device_create_file(&new_client->dev,
-                          &sensor_dev_attr_temp2_max_alarm.dev_attr);
-       device_create_file(&new_client->dev,
-                          &sensor_dev_attr_temp2_crit_alarm.dev_attr);
-       device_create_file(&new_client->dev, &dev_attr_alarms);
 
        return 0;
 
-exit_detach:
-       i2c_detach_client(new_client);
+exit_remove_files:
+       sysfs_remove_group(&new_client->dev.kobj, &lm63_group);
+       sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1);
 exit_free:
        kfree(data);
 exit:
@@ -520,7 +513,7 @@ static void lm63_init_client(struct i2c_client *client)
 
        /* Start converting if needed */
        if (data->config & 0x40) { /* standby */
-               dev_dbg(&client->dev, "Switching to operational mode");
+               dev_dbg(&client->dev, "Switching to operational mode\n");
                data->config &= 0xA7;
                i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1,
                                          data->config);
@@ -543,15 +536,13 @@ static void lm63_init_client(struct i2c_client *client)
                (data->config_fan & 0x20) ? "manual" : "auto");
 }
 
-static int lm63_detach_client(struct i2c_client *client)
+static int lm63_remove(struct i2c_client *client)
 {
        struct lm63_data *data = i2c_get_clientdata(client);
-       int err;
-
-       hwmon_device_unregister(data->class_dev);
 
-       if ((err = i2c_detach_client(client)))
-               return err;
+       hwmon_device_unregister(data->hwmon_dev);
+       sysfs_remove_group(&client->dev.kobj, &lm63_group);
+       sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1);
 
        kfree(data);
        return 0;