[PATCH] x86_64 irq: In __DO_ACTION perform the FINAL action for every entry.
[powerpc.git] / drivers / hwmon / adm1021.c
index 093d09c..c466329 100644 (file)
@@ -24,9 +24,9 @@
 #include <linux/slab.h>
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
-#include <linux/i2c-sensor.h>
 #include <linux/hwmon.h>
 #include <linux/err.h>
+#include <linux/mutex.h>
 
 
 /* Addresses to scan */
@@ -36,7 +36,7 @@ static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
                                        I2C_CLIENT_END };
 
 /* Insmod parameters */
-SENSORS_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1066);
+I2C_CLIENT_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1066);
 
 /* adm1021 constants specified below */
 
@@ -93,7 +93,7 @@ struct adm1021_data {
        struct class_device *class_dev;
        enum chips type;
 
-       struct semaphore update_lock;
+       struct mutex update_lock;
        char valid;             /* !=0 if following fields are valid */
        unsigned long last_updated;     /* In jiffies */
 
@@ -122,15 +122,15 @@ static int adm1021_write_value(struct i2c_client *client, u8 reg,
 static struct adm1021_data *adm1021_update_device(struct device *dev);
 
 /* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */
-static int read_only = 0;
+static int read_only;
 
 
 /* This is the driver that will be inserted */
 static struct i2c_driver adm1021_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "adm1021",
+       .driver = {
+               .name   = "adm1021",
+       },
        .id             = I2C_DRIVERID_ADM1021,
-       .flags          = I2C_DF_NOTIFY,
        .attach_adapter = adm1021_attach_adapter,
        .detach_client  = adm1021_detach_client,
 };
@@ -163,10 +163,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
        struct adm1021_data *data = i2c_get_clientdata(client); \
        int temp = simple_strtoul(buf, NULL, 10);               \
                                                                \
-       down(&data->update_lock);                               \
+       mutex_lock(&data->update_lock);                         \
        data->value = TEMP_TO_REG(temp);                        \
        adm1021_write_value(client, reg, data->value);          \
-       up(&data->update_lock);                                 \
+       mutex_unlock(&data->update_lock);                       \
        return count;                                           \
 }
 set(temp_max, ADM1021_REG_TOS_W);
@@ -187,9 +187,24 @@ static int adm1021_attach_adapter(struct i2c_adapter *adapter)
 {
        if (!(adapter->class & I2C_CLASS_HWMON))
                return 0;
-       return i2c_detect(adapter, &addr_data, adm1021_detect);
+       return i2c_probe(adapter, &addr_data, adm1021_detect);
 }
 
+static struct attribute *adm1021_attributes[] = {
+       &dev_attr_temp1_max.attr,
+       &dev_attr_temp1_min.attr,
+       &dev_attr_temp1_input.attr,
+       &dev_attr_temp2_max.attr,
+       &dev_attr_temp2_min.attr,
+       &dev_attr_temp2_input.attr,
+       &dev_attr_alarms.attr,
+       NULL
+};
+
+static const struct attribute_group adm1021_group = {
+       .attrs = adm1021_attributes,
+};
+
 static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
 {
        int i;
@@ -198,15 +213,6 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
        int err = 0;
        const char *type_name = "";
 
-       /* Make sure we aren't probing the ISA bus!! This is just a safety check
-          at this moment; i2c_detect really won't call us. */
-#ifdef DEBUG
-       if (i2c_is_isa_adapter(adapter)) {
-               dev_dbg(&adapter->dev, "adm1021_detect called for an ISA bus adapter?!?\n");
-               return 0;
-       }
-#endif
-
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
                goto error0;
 
@@ -214,11 +220,10 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
           client structure, even though we cannot fill it completely yet.
           But it allows us to access adm1021_{read,write}_value. */
 
-       if (!(data = kmalloc(sizeof(struct adm1021_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct adm1021_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto error0;
        }
-       memset(data, 0, sizeof(struct adm1021_data));
 
        new_client = &data->client;
        i2c_set_clientdata(new_client, data);
@@ -286,7 +291,7 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
        strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
        data->type = kind;
        data->valid = 0;
-       init_MUTEX(&data->update_lock);
+       mutex_init(&data->update_lock);
 
        /* Tell the I2C layer a new client has arrived */
        if ((err = i2c_attach_client(new_client)))
@@ -297,22 +302,19 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
                adm1021_init_client(new_client);
 
        /* Register sysfs hooks */
+       if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1021_group)))
+               goto error2;
+
        data->class_dev = hwmon_device_register(&new_client->dev);
        if (IS_ERR(data->class_dev)) {
                err = PTR_ERR(data->class_dev);
-               goto error2;
+               goto error3;
        }
 
-       device_create_file(&new_client->dev, &dev_attr_temp1_max);
-       device_create_file(&new_client->dev, &dev_attr_temp1_min);
-       device_create_file(&new_client->dev, &dev_attr_temp1_input);
-       device_create_file(&new_client->dev, &dev_attr_temp2_max);
-       device_create_file(&new_client->dev, &dev_attr_temp2_min);
-       device_create_file(&new_client->dev, &dev_attr_temp2_input);
-       device_create_file(&new_client->dev, &dev_attr_alarms);
-
        return 0;
 
+error3:
+       sysfs_remove_group(&new_client->dev.kobj, &adm1021_group);
 error2:
        i2c_detach_client(new_client);
 error1:
@@ -336,11 +338,10 @@ static int adm1021_detach_client(struct i2c_client *client)
        int err;
 
        hwmon_device_unregister(data->class_dev);
+       sysfs_remove_group(&client->dev.kobj, &adm1021_group);
 
-       if ((err = i2c_detach_client(client))) {
-               dev_err(&client->dev, "Client deregistration failed, client not detached.\n");
+       if ((err = i2c_detach_client(client)))
                return err;
-       }
 
        kfree(data);
        return 0;
@@ -364,7 +365,7 @@ static struct adm1021_data *adm1021_update_device(struct device *dev)
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1021_data *data = i2c_get_clientdata(client);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
            || !data->valid) {
@@ -388,7 +389,7 @@ static struct adm1021_data *adm1021_update_device(struct device *dev)
                data->valid = 1;
        }
 
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return data;
 }