[ALSA] Fix compile warning in timer.c
[safe/jmp/linux-2.6] / drivers / hwmon / ds1621.c
index 9ed21ac..478eb4b 100644 (file)
 #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>
 #include "lm75.h"
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
                                        0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
-static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
 
 /* Insmod parameters */
-SENSORS_INSMOD_1(ds1621);
+I2C_CLIENT_INSMOD_1(ds1621);
 static int polarity = -1;
 module_param(polarity, int, 0);
 MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low");
@@ -74,7 +73,7 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low")
 struct ds1621_data {
        struct i2c_client client;
        struct class_device *class_dev;
-       struct semaphore update_lock;
+       struct mutex update_lock;
        char valid;                     /* !=0 if following fields are valid */
        unsigned long last_updated;     /* In jiffies */
 
@@ -91,10 +90,10 @@ static struct ds1621_data *ds1621_update_client(struct device *dev);
 
 /* This is the driver that will be inserted */
 static struct i2c_driver ds1621_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "ds1621",
+       .driver = {
+               .name   = "ds1621",
+       },
        .id             = I2C_DRIVERID_DS1621,
-       .flags          = I2C_DF_NOTIFY,
        .attach_adapter = ds1621_attach_adapter,
        .detach_client  = ds1621_detach_client,
 };
@@ -158,10 +157,10 @@ static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *at
        struct ds1621_data *data = ds1621_update_client(dev);           \
        u16 val = LM75_TEMP_TO_REG(simple_strtoul(buf, NULL, 10));      \
                                                                        \
-       down(&data->update_lock);                                       \
+       mutex_lock(&data->update_lock);                                 \
        data->value = val;                                              \
        ds1621_write_value(client, reg, data->value);                   \
-       up(&data->update_lock);                                         \
+       mutex_unlock(&data->update_lock);                               \
        return count;                                                   \
 }
 
@@ -182,12 +181,14 @@ static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max);
 
 static int ds1621_attach_adapter(struct i2c_adapter *adapter)
 {
-       return i2c_detect(adapter, &addr_data, ds1621_detect);
+       if (!(adapter->class & I2C_CLASS_HWMON))
+               return 0;
+       return i2c_probe(adapter, &addr_data, ds1621_detect);
 }
 
-/* This function is called by i2c_detect */
-int ds1621_detect(struct i2c_adapter *adapter, int address,
-                  int kind)
+/* This function is called by i2c_probe */
+static int ds1621_detect(struct i2c_adapter *adapter, int address,
+                        int kind)
 {
        int conf, temp;
        struct i2c_client *new_client;
@@ -202,11 +203,10 @@ int ds1621_detect(struct i2c_adapter *adapter, int address,
        /* 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 ds1621_{read,write}_value. */
-       if (!(data = kmalloc(sizeof(struct ds1621_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct ds1621_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto exit;
        }
-       memset(data, 0, sizeof(struct ds1621_data));
        
        new_client = &data->client;
        i2c_set_clientdata(new_client, data);
@@ -243,7 +243,7 @@ int ds1621_detect(struct i2c_adapter *adapter, int address,
        /* Fill in remaining client fields and put it into the global list */
        strlcpy(new_client->name, "ds1621", I2C_NAME_SIZE);
        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)))
@@ -283,11 +283,8 @@ static int ds1621_detach_client(struct i2c_client *client)
 
        hwmon_device_unregister(data->class_dev);
 
-       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);
 
@@ -301,7 +298,7 @@ static struct ds1621_data *ds1621_update_client(struct device *dev)
        struct ds1621_data *data = i2c_get_clientdata(client);
        u8 new_conf;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
            || !data->valid) {
@@ -331,7 +328,7 @@ static struct ds1621_data *ds1621_update_client(struct device *dev)
                data->valid = 1;
        }
 
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return data;
 }