]> Pileus Git - ~andy/linux/blobdiff - drivers/hwmon/w83781d.c
[PATCH] hwmon: hwmon vs i2c, second round (04/11)
[~andy/linux] / drivers / hwmon / w83781d.c
index c83ae769e3622231ed3eea289d3ca1ea065e5376..f269faeffa47c102ede3bb0086e09873a509929c 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/slab.h>
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
+#include <linux/i2c-isa.h>
 #include <linux/i2c-sensor.h>
 #include <linux/i2c-vid.h>
 #include <linux/hwmon.h>
@@ -49,7 +50,7 @@
 static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
                                        0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
                                        0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
-static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END };
+static unsigned short isa_address = 0x290;
 
 /* Insmod parameters */
 SENSORS_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f);
@@ -258,6 +259,7 @@ struct w83781d_data {
 };
 
 static int w83781d_attach_adapter(struct i2c_adapter *adapter);
+static int w83781d_isa_attach_adapter(struct i2c_adapter *adapter);
 static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind);
 static int w83781d_detach_client(struct i2c_client *client);
 
@@ -276,6 +278,14 @@ static struct i2c_driver w83781d_driver = {
        .detach_client = w83781d_detach_client,
 };
 
+static struct i2c_driver w83781d_isa_driver = {
+       .owner = THIS_MODULE,
+       .name = "w83781d-isa",
+       .attach_adapter = w83781d_isa_attach_adapter,
+       .detach_client = w83781d_detach_client,
+};
+
+
 /* following are the sysfs callback functions */
 #define show_in_reg(reg) \
 static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
@@ -859,7 +869,13 @@ w83781d_attach_adapter(struct i2c_adapter *adapter)
 {
        if (!(adapter->class & I2C_CLASS_HWMON))
                return 0;
-       return i2c_detect(adapter, &addr_data, w83781d_detect);
+       return i2c_probe(adapter, &addr_data, w83781d_detect);
+}
+
+static int
+w83781d_isa_attach_adapter(struct i2c_adapter *adapter)
+{
+       return w83781d_detect(adapter, isa_address, -1);
 }
 
 /* Assumes that adapter is of I2C, not ISA variety.
@@ -1002,7 +1018,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
        
        if (is_isa)
                if (!request_region(address, W83781D_EXTENT,
-                                   w83781d_driver.name)) {
+                                   w83781d_isa_driver.name)) {
                        dev_dbg(&adapter->dev, "Request of region "
                                "0x%x-0x%x for w83781d failed\n", address,
                                address + W83781D_EXTENT - 1);
@@ -1060,7 +1076,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
        new_client->addr = address;
        init_MUTEX(&data->lock);
        new_client->adapter = adapter;
-       new_client->driver = &w83781d_driver;
+       new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver;
        new_client->flags = 0;
 
        /* Now, we do the remaining detection. */
@@ -1283,11 +1299,8 @@ w83781d_detach_client(struct i2c_client *client)
        if (i2c_is_isa_client(client))
                release_region(client->addr, W83781D_EXTENT);
 
-       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;
-       }
 
        /* main client */
        if (data)
@@ -1636,12 +1649,25 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
 static int __init
 sensors_w83781d_init(void)
 {
-       return i2c_add_driver(&w83781d_driver);
+       int res;
+
+       res = i2c_add_driver(&w83781d_driver);
+       if (res)
+               return res;
+
+       res = i2c_isa_add_driver(&w83781d_isa_driver);
+       if (res) {
+               i2c_del_driver(&w83781d_driver);
+               return res;
+       }
+
+       return 0;
 }
 
 static void __exit
 sensors_w83781d_exit(void)
 {
+       i2c_isa_del_driver(&w83781d_isa_driver);
        i2c_del_driver(&w83781d_driver);
 }