Merge branches 'at91', 'dyntick', 'ep93xx', 'iop', 'ixp', 'misc', 'orion', 'omap...
[pandora-kernel.git] / drivers / i2c / chips / pcf8574.c
index c3e6449..e5b3132 100644 (file)
 #include <linux/i2c.h>
 
 /* Addresses to scan */
-static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
-                                       0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
-                                       I2C_CLIENT_END };
+static const unsigned short normal_i2c[] = {
+       0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+       0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+       I2C_CLIENT_END
+};
 
 /* Insmod parameters */
 I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a);
 
-/* Initial values */
-#define PCF8574_INIT 255       /* All outputs on (input mode) */
-
 /* Each client has this additional data */
 struct pcf8574_data {
        struct i2c_client client;
 
-       u8 write;                       /* Remember last written value */
+       int write;                      /* Remember last written value */
 };
 
 static int pcf8574_attach_adapter(struct i2c_adapter *adapter);
@@ -68,7 +67,6 @@ static struct i2c_driver pcf8574_driver = {
        .driver = {
                .name   = "pcf8574",
        },
-       .id             = I2C_DRIVERID_PCF8574,
        .attach_adapter = pcf8574_attach_adapter,
        .detach_client  = pcf8574_detach_client,
 };
@@ -85,7 +83,11 @@ static DEVICE_ATTR(read, S_IRUGO, show_read, NULL);
 static ssize_t show_write(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct pcf8574_data *data = i2c_get_clientdata(to_i2c_client(dev));
-       return sprintf(buf, "%u\n", data->write);
+
+       if (data->write < 0)
+               return data->write;
+
+       return sprintf(buf, "%d\n", data->write);
 }
 
 static ssize_t set_write(struct device *dev, struct device_attribute *attr, const char *buf,
@@ -105,6 +107,16 @@ static ssize_t set_write(struct device *dev, struct device_attribute *attr, cons
 
 static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write);
 
+static struct attribute *pcf8574_attributes[] = {
+       &dev_attr_read.attr,
+       &dev_attr_write.attr,
+       NULL
+};
+
+static const struct attribute_group pcf8574_attr_group = {
+       .attrs = pcf8574_attributes,
+};
+
 /*
  * Real code
  */
@@ -166,13 +178,13 @@ static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
        pcf8574_init_client(new_client);
 
        /* Register sysfs hooks */
-       device_create_file(&new_client->dev, &dev_attr_read);
-       device_create_file(&new_client->dev, &dev_attr_write);
+       err = sysfs_create_group(&new_client->dev.kobj, &pcf8574_attr_group);
+       if (err)
+               goto exit_detach;
        return 0;
 
-/* OK, this is not exactly good programming practice, usually. But it is
-   very code-efficient in this case. */
-
+      exit_detach:
+       i2c_detach_client(new_client);
       exit_free:
        kfree(data);
       exit:
@@ -183,6 +195,8 @@ static int pcf8574_detach_client(struct i2c_client *client)
 {
        int err;
 
+       sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group);
+
        if ((err = i2c_detach_client(client)))
                return err;
 
@@ -194,8 +208,7 @@ static int pcf8574_detach_client(struct i2c_client *client)
 static void pcf8574_init_client(struct i2c_client *client)
 {
        struct pcf8574_data *data = i2c_get_clientdata(client);
-       data->write = PCF8574_INIT;
-       i2c_smbus_write_byte(client, data->write);
+       data->write = -EAGAIN;
 }
 
 static int __init pcf8574_init(void)