[PATCH] hwmon: Semaphore to mutex conversions
[safe/jmp/linux-2.6] / drivers / hwmon / fscher.c
index ddf22fb..6bc76b4 100644 (file)
@@ -31,9 +31,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
@@ -45,7 +45,7 @@ static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
  * Insmod parameters
  */
 
-SENSORS_INSMOD_1(fscher);
+I2C_CLIENT_INSMOD_1(fscher);
 
 /*
  * The FSCHER registers
@@ -119,10 +119,10 @@ static int fscher_write_value(struct i2c_client *client, u8 reg, u8 value);
  */
  
 static struct i2c_driver fscher_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "fscher",
+       .driver = {
+               .name   = "fscher",
+       },
        .id             = I2C_DRIVERID_FSCHER,
-       .flags          = I2C_DF_NOTIFY,
        .attach_adapter = fscher_attach_adapter,
        .detach_client  = fscher_detach_client,
 };
@@ -134,7 +134,7 @@ static struct i2c_driver fscher_driver = {
 struct fscher_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 */
 
@@ -289,7 +289,7 @@ static int fscher_attach_adapter(struct i2c_adapter *adapter)
 {
        if (!(adapter->class & I2C_CLASS_HWMON))
                return 0;
-       return i2c_detect(adapter, &addr_data, fscher_detect);
+       return i2c_probe(adapter, &addr_data, fscher_detect);
 }
 
 static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -304,11 +304,10 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
        /* 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 i2c_smbus_read_byte_data. */
-       if (!(data = kmalloc(sizeof(struct fscher_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct fscher_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto exit;
        }
-       memset(data, 0, sizeof(struct fscher_data));
 
        /* The common I2C client data is placed right before the
         * Hermes-specific data. */
@@ -334,7 +333,7 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
         * global list */
        strlcpy(new_client->name, "fscher", 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)))
@@ -419,7 +418,7 @@ static struct fscher_data *fscher_update_device(struct device *dev)
        struct i2c_client *client = to_i2c_client(dev);
        struct fscher_data *data = i2c_get_clientdata(client);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
 
@@ -459,7 +458,7 @@ static struct fscher_data *fscher_update_device(struct device *dev)
                data->valid = 1;                 
        }
 
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return data;
 }
@@ -474,10 +473,10 @@ static ssize_t set_fan_status(struct i2c_client *client, struct fscher_data *dat
        /* bits 0..1, 3..7 reserved => mask with 0x04 */  
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0x04;
        
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->fan_status[FAN_INDEX_FROM_NUM(nr)] &= ~v;
        fscher_write_value(client, reg, v);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -492,10 +491,10 @@ static ssize_t set_pwm(struct i2c_client *client, struct fscher_data *data,
 {
        unsigned long v = simple_strtoul(buf, NULL, 10);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->fan_min[FAN_INDEX_FROM_NUM(nr)] = v > 0xff ? 0xff : v;
        fscher_write_value(client, reg, data->fan_min[FAN_INDEX_FROM_NUM(nr)]);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -520,14 +519,14 @@ static ssize_t set_fan_div(struct i2c_client *client, struct fscher_data *data,
                return -EINVAL;
        }
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        /* bits 2..7 reserved => mask with 0x03 */
        data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] &= ~0x03;
        data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] |= v;
 
        fscher_write_value(client, reg, data->fan_ripple[FAN_INDEX_FROM_NUM(nr)]);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -554,10 +553,10 @@ static ssize_t set_temp_status(struct i2c_client *client, struct fscher_data *da
        /* bits 2..7 reserved, 0 read only => mask with 0x02 */  
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->temp_status[TEMP_INDEX_FROM_NUM(nr)] &= ~v;
        fscher_write_value(client, reg, v);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -611,10 +610,10 @@ static ssize_t set_control(struct i2c_client *client, struct fscher_data *data,
        /* bits 1..7 reserved => mask with 0x01 */  
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0x01;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->global_control &= ~v;
        fscher_write_value(client, reg, v);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -633,11 +632,11 @@ static ssize_t set_watchdog_control(struct i2c_client *client, struct
        /* bits 0..3 reserved => mask with 0xf0 */  
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->watchdog[2] &= ~0xf0;
        data->watchdog[2] |= v;
        fscher_write_value(client, reg, data->watchdog[2]);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -653,10 +652,10 @@ static ssize_t set_watchdog_status(struct i2c_client *client, struct fscher_data
        /* bits 0, 2..7 reserved => mask with 0x02 */  
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->watchdog[1] &= ~v;
        fscher_write_value(client, reg, v);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -671,10 +670,10 @@ static ssize_t set_watchdog_preset(struct i2c_client *client, struct fscher_data
 {
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff;
        
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->watchdog[0] = v;
        fscher_write_value(client, reg, data->watchdog[0]);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }