[PATCH] i2c: convert ds1374 to use a workqueue
[powerpc.git] / drivers / i2c / chips / max6875.c
index 35a8e92..88d2dde 100644 (file)
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
-#include <linux/i2c-sensor.h>
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 
 /* Do not scan - the MAX6875 access method will write to some EEPROM chips */
 static unsigned short normal_i2c[] = {I2C_CLIENT_END};
-static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END};
 
 /* Insmod parameters */
-SENSORS_INSMOD_1(max6875);
+I2C_CLIENT_INSMOD_1(max6875);
 
 /* The MAX6875 can only read/write 16 bytes at a time */
 #define SLICE_SIZE                     16
@@ -56,7 +54,7 @@ SENSORS_INSMOD_1(max6875);
 /* Each client has this additional data */
 struct max6875_data {
        struct i2c_client       client;
-       struct semaphore        update_lock;
+       struct mutex            update_lock;
 
        u32                     valid;
        u8                      data[USER_EEPROM_SIZE];
@@ -69,9 +67,9 @@ static int max6875_detach_client(struct i2c_client *client);
 
 /* This is the driver that will be inserted */
 static struct i2c_driver max6875_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "max6875",
-       .flags          = I2C_DF_NOTIFY,
+       .driver = {
+               .name   = "max6875",
+       },
        .attach_adapter = max6875_attach_adapter,
        .detach_client  = max6875_detach_client,
 };
@@ -81,12 +79,11 @@ static void max6875_update_slice(struct i2c_client *client, int slice)
        struct max6875_data *data = i2c_get_clientdata(client);
        int i, j, addr;
        u8 *buf;
-       int retval = 0;
 
        if (slice >= USER_EEPROM_SLICES)
                return;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        buf = &data->data[slice << SLICE_BITS];
 
@@ -102,7 +99,6 @@ static void max6875_update_slice(struct i2c_client *client, int slice)
                /* select the eeprom address */
                if (i2c_smbus_write_byte_data(client, addr >> 8, addr & 0xFF)) {
                        dev_err(&client->dev, "address set failed\n");
-                       retval = -1;
                        goto exit_up;
                }
 
@@ -111,14 +107,12 @@ static void max6875_update_slice(struct i2c_client *client, int slice)
                        if (i2c_smbus_read_i2c_block_data(client,
                                                          MAX6875_CMD_BLK_READ,
                                                          buf) != SLICE_SIZE) {
-                               retval = -1;
                                goto exit_up;
                        }
                } else {
                        for (i = 0; i < SLICE_SIZE; i++) {
                                j = i2c_smbus_read_byte(client);
                                if (j < 0) {
-                                       retval = -1;
                                        goto exit_up;
                                }
                                buf[i] = j;
@@ -128,7 +122,7 @@ static void max6875_update_slice(struct i2c_client *client, int slice)
                data->valid |= (1 << slice);
        }
 exit_up:
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 }
 
 static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off,
@@ -166,10 +160,10 @@ static struct bin_attribute user_eeprom_attr = {
 
 static int max6875_attach_adapter(struct i2c_adapter *adapter)
 {
-       return i2c_detect(adapter, &addr_data, max6875_detect);
+       return i2c_probe(adapter, &addr_data, max6875_detect);
 }
 
-/* This function is called by i2c_detect */
+/* This function is called by i2c_probe */
 static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
 {
        struct i2c_client *real_client;
@@ -177,12 +171,7 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
        struct max6875_data *data;
        int err = 0;
 
-       /* Prevent 24rf08 corruption (in case of user error) */
-       if (kind < 0)
-               i2c_smbus_xfer(adapter, address, 0, 0, 0,
-                              I2C_SMBUS_QUICK, NULL);
-
-       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
+       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA
                                     | I2C_FUNC_SMBUS_READ_BYTE))
                return 0;
 
@@ -190,16 +179,14 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
        if (address & 1)
                return 0;
 
-       if (!(data = kmalloc(sizeof(struct max6875_data), GFP_KERNEL)))
+       if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL)))
                return -ENOMEM;
-       memset(data, 0, sizeof(struct max6875_data));
 
        /* A fake client is created on the odd address */
-       if (!(fake_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
+       if (!(fake_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
                err = -ENOMEM;
                goto exit_kfree1;
        }
-       memset(fake_client, 0, sizeof(struct i2c_client));
 
        /* Init real i2c_client */
        real_client = &data->client;
@@ -209,7 +196,7 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
        real_client->driver = &max6875_driver;
        real_client->flags = 0;
        strlcpy(real_client->name, "max6875", I2C_NAME_SIZE);
-       init_MUTEX(&data->update_lock);
+       mutex_init(&data->update_lock);
 
        /* Init fake client data */
        /* set the client data to the i2c_client so that it will get freed */
@@ -218,7 +205,7 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
        fake_client->adapter = adapter;
        fake_client->driver = &max6875_driver;
        fake_client->flags = 0;
-       strlcpy(fake_client->name, "max6875-dummy", I2C_NAME_SIZE);
+       strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE);
 
        /* Prevent 24RF08 corruption (in case of user error) */
        i2c_smbus_write_quick(real_client, 0);
@@ -247,10 +234,8 @@ static int max6875_detach_client(struct i2c_client *client)
        int err;
 
        err = i2c_detach_client(client);
-       if (err) {
-               dev_err(&client->dev, "i2c_detach_client() failed\n");
+       if (err)
                return err;
-       }
        kfree(i2c_get_clientdata(client));
        return 0;
 }