[PATCH] hwmon: Semaphore to mutex conversions
[safe/jmp/linux-2.6] / drivers / hwmon / max1619.c
index 56c34c2..b4135b5 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>
 
 static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
                                        0x29, 0x2a, 0x2b,
                                        0x4c, 0x4d, 0x4e,
                                        I2C_CLIENT_END };
-static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
 
 /*
  * Insmod parameters
  */
 
-SENSORS_INSMOD_1(max1619);
+I2C_CLIENT_INSMOD_1(max1619);
 
 /*
  * The MAX1619 registers
@@ -92,9 +91,9 @@ static struct max1619_data *max1619_update_device(struct device *dev);
  */
 
 static struct i2c_driver max1619_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "max1619",
-       .flags          = I2C_DF_NOTIFY,
+       .driver = {
+               .name   = "max1619",
+       },
        .attach_adapter = max1619_attach_adapter,
        .detach_client  = max1619_detach_client,
 };
@@ -106,7 +105,7 @@ static struct i2c_driver max1619_driver = {
 struct max1619_data {
        struct i2c_client client;
        struct class_device *class_dev;
-       struct semaphore update_lock;
+       struct mutex update_lock;
        char valid; /* zero until following fields are valid */
        unsigned long last_updated; /* in jiffies */
 
@@ -143,10 +142,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
        struct max1619_data *data = i2c_get_clientdata(client); \
        long val = simple_strtol(buf, NULL, 10); \
  \
-       down(&data->update_lock); \
+       mutex_lock(&data->update_lock); \
        data->value = TEMP_TO_REG(val); \
        i2c_smbus_write_byte_data(client, reg, data->value); \
-       up(&data->update_lock); \
+       mutex_unlock(&data->update_lock); \
        return count; \
 }
 
@@ -181,7 +180,7 @@ static int max1619_attach_adapter(struct i2c_adapter *adapter)
 {
        if (!(adapter->class & I2C_CLASS_HWMON))
                return 0;
-       return i2c_detect(adapter, &addr_data, max1619_detect);
+       return i2c_probe(adapter, &addr_data, max1619_detect);
 }
 
 /*
@@ -195,15 +194,14 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
        int err = 0;
        const char *name = "";  
        u8 reg_config=0, reg_convrate=0, reg_status=0;
-       u8 man_id, chip_id;
+
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
                goto exit;
 
-       if (!(data = kmalloc(sizeof(struct max1619_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct max1619_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto exit;
        }
-       memset(data, 0, sizeof(struct max1619_data));
 
        /* The common I2C client data is placed right before the
           MAX1619-specific data. */
@@ -241,16 +239,15 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
        }
 
        if (kind <= 0) { /* identification */
+               u8 man_id, chip_id;
        
                man_id = i2c_smbus_read_byte_data(new_client,
                         MAX1619_REG_R_MAN_ID);
                chip_id = i2c_smbus_read_byte_data(new_client,
                          MAX1619_REG_R_CHIP_ID);
                
-               if ((man_id == 0x4D) && (chip_id == 0x04)){  
-                               kind = max1619;
-                       }
-               }
+               if ((man_id == 0x4D) && (chip_id == 0x04))
+                       kind = max1619;
 
                if (kind <= 0) { /* identification failed */
                        dev_info(&adapter->dev,
@@ -258,16 +255,15 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
                            "chip_id=0x%02X).\n", man_id, chip_id);
                        goto exit_free;
                }
-       
+       }
 
-       if (kind == max1619){
+       if (kind == max1619)
                name = "max1619";
-       }
 
        /* We can fill in the remaining client fields */
        strlcpy(new_client->name, name, 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)))
@@ -323,11 +319,8 @@ static int max1619_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);
        return 0;
@@ -338,7 +331,7 @@ static struct max1619_data *max1619_update_device(struct device *dev)
        struct i2c_client *client = to_i2c_client(dev);
        struct max1619_data *data = i2c_get_clientdata(client);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
                dev_dbg(&client->dev, "Updating max1619 data.\n");
@@ -361,7 +354,7 @@ static struct max1619_data *max1619_update_device(struct device *dev)
                data->valid = 1;
        }
 
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return data;
 }