Merge master.kernel.org:/pub/scm/linux/kernel/git/mchehab/v4l-dvb
[powerpc.git] / drivers / i2c / chips / pca9539.c
index 9f3ad45..cb22280 100644 (file)
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/hwmon-sysfs.h>
-#include <linux/i2c-sensor.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END};
-static unsigned int normal_isa[] = {I2C_CLIENT_ISA_END};
 
 /* Insmod parameters */
-SENSORS_INSMOD_1(pca9539);
+I2C_CLIENT_INSMOD_1(pca9539);
 
 enum pca9539_cmd
 {
@@ -40,9 +38,9 @@ static int pca9539_detach_client(struct i2c_client *client);
 
 /* This is the driver that will be inserted */
 static struct i2c_driver pca9539_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "pca9539",
-       .flags          = I2C_DF_NOTIFY,
+       .driver = {
+               .name   = "pca9539",
+       },
        .attach_adapter = pca9539_attach_adapter,
        .detach_client  = pca9539_detach_client,
 };
@@ -109,10 +107,10 @@ static struct attribute_group pca9539_defattr_group = {
 
 static int pca9539_attach_adapter(struct i2c_adapter *adapter)
 {
-       return i2c_detect(adapter, &addr_data, pca9539_detect);
+       return i2c_probe(adapter, &addr_data, pca9539_detect);
 }
 
-/* This function is called by i2c_detect */
+/* This function is called by i2c_probe */
 static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
 {
        struct i2c_client *new_client;
@@ -124,11 +122,10 @@ static int pca9539_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. */
-       if (!(data = kmalloc(sizeof(struct pca9539_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct pca9539_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto exit;
        }
-       memset(data, 0, sizeof(struct pca9539_data));
 
        new_client = &data->client;
        i2c_set_clientdata(new_client, data);
@@ -137,11 +134,13 @@ static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
        new_client->driver = &pca9539_driver;
        new_client->flags = 0;
 
-       /* Detection: the pca9539 only has 8 registers (0-7).
-          A read of 7 should succeed, but a read of 8 should fail. */
-       if ((i2c_smbus_read_byte_data(new_client, 7) < 0) ||
-           (i2c_smbus_read_byte_data(new_client, 8) >= 0))
-               goto exit_kfree;
+       if (kind < 0) {
+               /* Detection: the pca9539 only has 8 registers (0-7).
+                  A read of 7 should succeed, but a read of 8 should fail. */
+               if ((i2c_smbus_read_byte_data(new_client, 7) < 0) ||
+                   (i2c_smbus_read_byte_data(new_client, 8) >= 0))
+                       goto exit_kfree;
+       }
 
        strlcpy(new_client->name, "pca9539", I2C_NAME_SIZE);
 
@@ -164,10 +163,8 @@ static int pca9539_detach_client(struct i2c_client *client)
 {
        int err;
 
-       if ((err = i2c_detach_client(client))) {
-               dev_err(&client->dev, "Client deregistration failed.\n");
+       if ((err = i2c_detach_client(client)))
                return err;
-       }
 
        kfree(i2c_get_clientdata(client));
        return 0;