hwmon: (lm90) Add SMBus alert support
[safe/jmp/linux-2.6] / drivers / hwmon / adm1026.c
index 8002f68..65335b2 100644 (file)
 #include <linux/mutex.h>
 
 /* Addresses to scan */
-static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
-
-/* Insmod parameters */
-I2C_CLIENT_INSMOD_1(adm1026);
+static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
 
 static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
                                -1, -1, -1, -1, -1, -1, -1, -1 };
@@ -259,7 +256,6 @@ struct pwm_data {
 };
 
 struct adm1026_data {
-       struct i2c_client client;
        struct device *hwmon_dev;
 
        struct mutex update_lock;
@@ -280,7 +276,6 @@ struct adm1026_data {
        u8 fan_min[8];          /* Register value */
        u8 fan_div[8];          /* Decoded value */
        struct pwm_data pwm1;   /* Pwm control values */
-       int vid;                /* Decoded value */
        u8 vrm;                 /* VRM version */
        u8 analog_out;          /* Register value (DAC) */
        long alarms;            /* Register encoding, combined */
@@ -293,10 +288,11 @@ struct adm1026_data {
        u8 config3;             /* Register value */
 };
 
-static int adm1026_attach_adapter(struct i2c_adapter *adapter);
-static int adm1026_detect(struct i2c_adapter *adapter, int address,
-       int kind);
-static int adm1026_detach_client(struct i2c_client *client);
+static int adm1026_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id);
+static int adm1026_detect(struct i2c_client *client,
+                         struct i2c_board_info *info);
+static int adm1026_remove(struct i2c_client *client);
 static int adm1026_read_value(struct i2c_client *client, u8 reg);
 static int adm1026_write_value(struct i2c_client *client, u8 reg, int value);
 static void adm1026_print_gpio(struct i2c_client *client);
@@ -305,22 +301,24 @@ static struct adm1026_data *adm1026_update_device(struct device *dev);
 static void adm1026_init_client(struct i2c_client *client);
 
 
+static const struct i2c_device_id adm1026_id[] = {
+       { "adm1026", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, adm1026_id);
+
 static struct i2c_driver adm1026_driver = {
+       .class          = I2C_CLASS_HWMON,
        .driver = {
                .name   = "adm1026",
        },
-       .attach_adapter = adm1026_attach_adapter,
-       .detach_client  = adm1026_detach_client,
+       .probe          = adm1026_probe,
+       .remove         = adm1026_remove,
+       .id_table       = adm1026_id,
+       .detect         = adm1026_detect,
+       .address_list   = normal_i2c,
 };
 
-static int adm1026_attach_adapter(struct i2c_adapter *adapter)
-{
-       if (!(adapter->class & I2C_CLASS_HWMON)) {
-               return 0;
-       }
-       return i2c_probe(adapter, &addr_data, adm1026_detect);
-}
-
 static int adm1026_read_value(struct i2c_client *client, u8 reg)
 {
        int res;
@@ -453,7 +451,7 @@ static void adm1026_print_gpio(struct i2c_client *client)
        struct adm1026_data *data = i2c_get_clientdata(client);
        int i;
 
-       dev_dbg(&client->dev, "GPIO config is:");
+       dev_dbg(&client->dev, "GPIO config is:\n");
        for (i = 0;i <= 7;++i) {
                if (data->config2 & (1 << i)) {
                        dev_dbg(&client->dev, "\t%sGP%s%d\n",
@@ -695,8 +693,6 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
                data->last_config = jiffies;
        }; /* last_config */
 
-       dev_dbg(&client->dev, "Setting VID from GPIO11-15.\n");
-       data->vid = (data->gpio >> 11) & 0x1f;
        data->valid = 1;
        mutex_unlock(&data->update_lock);
        return data;
@@ -1213,7 +1209,10 @@ static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf, "%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
+       int vid = (data->gpio >> 11) & 0x1f;
+
+       dev_dbg(dev, "Setting VID from GPIO11-15.\n");
+       return sprintf(buf, "%d\n", vid_from_reg(vid, data->vrm));
 }
 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
 
@@ -1624,6 +1623,7 @@ static struct attribute *adm1026_attributes_temp3[] = {
        &dev_attr_temp3_crit_enable.attr,
        &dev_attr_temp3_auto_point1_pwm.attr,
        &dev_attr_temp3_auto_point2_pwm.attr,
+       NULL
 };
 
 static const struct attribute_group adm1026_group_temp3 = {
@@ -1639,105 +1639,76 @@ static struct attribute *adm1026_attributes_in8_9[] = {
        &sensor_dev_attr_in9_max.dev_attr.attr,
        &sensor_dev_attr_in9_min.dev_attr.attr,
        &sensor_dev_attr_in9_alarm.dev_attr.attr,
+       NULL
 };
 
 static const struct attribute_group adm1026_group_in8_9 = {
        .attrs = adm1026_attributes_in8_9,
 };
 
-static int adm1026_detect(struct i2c_adapter *adapter, int address,
-                         int kind)
+/* Return 0 if detection is successful, -ENODEV otherwise */
+static int adm1026_detect(struct i2c_client *client,
+                         struct i2c_board_info *info)
 {
+       struct i2c_adapter *adapter = client->adapter;
+       int address = client->addr;
        int company, verstep;
-       struct i2c_client *client;
-       struct adm1026_data *data;
-       int err = 0;
-       const char *type_name = "";
 
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
                /* We need to be able to do byte I/O */
-               goto exit;
+               return -ENODEV;
        };
 
-       /* 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 adm1026_{read,write}_value. */
-
-       if (!(data = kzalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
-               err = -ENOMEM;
-               goto exit;
-       }
-
-       client = &data->client;
-       i2c_set_clientdata(client, data);
-       client->addr = address;
-       client->adapter = adapter;
-       client->driver = &adm1026_driver;
-
        /* Now, we do the remaining detection. */
 
        company = adm1026_read_value(client, ADM1026_REG_COMPANY);
        verstep = adm1026_read_value(client, ADM1026_REG_VERSTEP);
 
-       dev_dbg(&client->dev, "Detecting device at %d,0x%02x with"
+       dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with"
                " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
                i2c_adapter_id(client->adapter), client->addr,
                company, verstep);
 
-       /* If auto-detecting, Determine the chip type. */
-       if (kind <= 0) {
-               dev_dbg(&client->dev, "Autodetecting device at %d,0x%02x "
-                       "...\n", i2c_adapter_id(adapter), address);
-               if (company == ADM1026_COMPANY_ANALOG_DEV
-                   && verstep == ADM1026_VERSTEP_ADM1026) {
-                       kind = adm1026;
-               } else if (company == ADM1026_COMPANY_ANALOG_DEV
-                       && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
-                       dev_err(&adapter->dev, ": Unrecognized stepping "
-                               "0x%02x. Defaulting to ADM1026.\n", verstep);
-                       kind = adm1026;
-               } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
-                       dev_err(&adapter->dev, ": Found version/stepping "
-                               "0x%02x. Assuming generic ADM1026.\n",
-                               verstep);
-                       kind = any_chip;
-               } else {
-                       dev_dbg(&client->dev, ": Autodetection "
-                               "failed\n");
-                       /* Not an ADM1026 ... */
-                       if (kind == 0) { /* User used force=x,y */
-                               dev_err(&adapter->dev, "Generic ADM1026 not "
-                                       "found at %d,0x%02x.  Try "
-                                       "force_adm1026.\n",
-                                       i2c_adapter_id(adapter), address);
-                       }
-                       goto exitfree;
-               }
+       /* Determine the chip type. */
+       dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x...\n",
+               i2c_adapter_id(adapter), address);
+       if (company == ADM1026_COMPANY_ANALOG_DEV
+           && verstep == ADM1026_VERSTEP_ADM1026) {
+               /* Analog Devices ADM1026 */
+       } else if (company == ADM1026_COMPANY_ANALOG_DEV
+               && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
+               dev_err(&adapter->dev, "Unrecognized stepping "
+                       "0x%02x. Defaulting to ADM1026.\n", verstep);
+       } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
+               dev_err(&adapter->dev, "Found version/stepping "
+                       "0x%02x. Assuming generic ADM1026.\n",
+                       verstep);
+       } else {
+               dev_dbg(&adapter->dev, "Autodetection failed\n");
+               /* Not an ADM1026... */
+               return -ENODEV;
        }
 
-       /* Fill in the chip specific driver values */
-       switch (kind) {
-       case any_chip :
-               type_name = "adm1026";
-               break;
-       case adm1026 :
-               type_name = "adm1026";
-               break;
-       default :
-               dev_err(&adapter->dev, ": Internal error, invalid "
-                       "kind (%d)!\n", kind);
-               err = -EFAULT;
-               goto exitfree;
+       strlcpy(info->type, "adm1026", I2C_NAME_SIZE);
+
+       return 0;
+}
+
+static int adm1026_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id)
+{
+       struct adm1026_data *data;
+       int err;
+
+       data = kzalloc(sizeof(struct adm1026_data), GFP_KERNEL);
+       if (!data) {
+               err = -ENOMEM;
+               goto exit;
        }
-       strlcpy(client->name, type_name, I2C_NAME_SIZE);
 
-       /* Fill in the remaining client fields */
+       i2c_set_clientdata(client, data);
        mutex_init(&data->update_lock);
 
-       /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(client)))
-               goto exitfree;
-
        /* Set the VRM version */
        data->vrm = vid_which_vrm();
 
@@ -1746,7 +1717,7 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
 
        /* Register sysfs hooks */
        if ((err = sysfs_create_group(&client->dev.kobj, &adm1026_group)))
-               goto exitdetach;
+               goto exitfree;
        if (data->config1 & CFG1_AIN8_9)
                err = sysfs_create_group(&client->dev.kobj,
                                         &adm1026_group_in8_9);
@@ -1771,15 +1742,13 @@ exitremove:
                sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9);
        else
                sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3);
-exitdetach:
-       i2c_detach_client(client);
 exitfree:
        kfree(data);
 exit:
        return err;
 }
 
-static int adm1026_detach_client(struct i2c_client *client)
+static int adm1026_remove(struct i2c_client *client)
 {
        struct adm1026_data *data = i2c_get_clientdata(client);
        hwmon_device_unregister(data->hwmon_dev);
@@ -1788,7 +1757,6 @@ static int adm1026_detach_client(struct i2c_client *client)
                sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9);
        else
                sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3);
-       i2c_detach_client(client);
        kfree(data);
        return 0;
 }