]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/hwmon/pc87360.c
[PATCH] I2C: Separate non-i2c hwmon drivers from i2c-core (5/9)
[linux-2.6-omap-h63xx.git] / drivers / hwmon / pc87360.c
index 876c68f3af31e4e80fbc5263ad47e97b650ea4a5..4041488de6f14719660c790fdbb1bbc1395ad69d 100644 (file)
 #include <linux/slab.h>
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
-#include <linux/i2c-sensor.h>
+#include <linux/i2c-isa.h>
 #include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 #include <asm/io.h>
 
-static unsigned short normal_i2c[] = { I2C_CLIENT_END };
-static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END };
-static struct i2c_force_data forces[] = {{ NULL }};
 static u8 devid;
-static unsigned int extra_isa[3];
+static unsigned short address;
+static unsigned short extra_isa[3];
 static u8 confreg[4];
 
 enum chips { any_chip, pc87360, pc87363, pc87364, pc87365, pc87366 };
-static struct i2c_address_data addr_data = {
-       .normal_i2c             = normal_i2c,
-       .normal_isa             = normal_isa,
-       .forces                 = forces,
-};
 
 static int init = 1;
 module_param(init, int, 0);
@@ -186,6 +181,7 @@ static inline u8 PWM_TO_REG(int val, int inv)
 
 struct pc87360_data {
        struct i2c_client client;
+       struct class_device *class_dev;
        struct semaphore lock;
        struct semaphore update_lock;
        char valid;             /* !=0 if following fields are valid */
@@ -224,8 +220,7 @@ struct pc87360_data {
  * Functions declaration
  */
 
-static int pc87360_attach_adapter(struct i2c_adapter *adapter);
-static int pc87360_detect(struct i2c_adapter *adapter, int address, int kind);
+static int pc87360_detect(struct i2c_adapter *adapter);
 static int pc87360_detach_client(struct i2c_client *client);
 
 static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
@@ -242,8 +237,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev);
 static struct i2c_driver pc87360_driver = {
        .owner          = THIS_MODULE,
        .name           = "pc87360",
-       .flags          = I2C_DF_NOTIFY,
-       .attach_adapter = pc87360_attach_adapter,
+       .attach_adapter = pc87360_detect,
        .detach_client  = pc87360_detach_client,
 };
 
@@ -632,12 +626,7 @@ static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL);
  * Device detection, registration and update
  */
 
-static int pc87360_attach_adapter(struct i2c_adapter *adapter)
-{
-       return i2c_detect(adapter, &addr_data, pc87360_detect);
-}
-
-static int pc87360_find(int sioaddr, u8 *devid, int *address)
+static int pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses)
 {
        u16 val;
        int i;
@@ -683,7 +672,7 @@ static int pc87360_find(int sioaddr, u8 *devid, int *address)
                        continue;
                }
 
-               address[i] = val;
+               addresses[i] = val;
 
                if (i==0) { /* Fans */
                        confreg[0] = superio_inb(sioaddr, 0xF0);
@@ -727,9 +716,7 @@ static int pc87360_find(int sioaddr, u8 *devid, int *address)
        return 0;
 }
 
-/* We don't really care about the address.
-   Read from extra_isa instead. */
-int pc87360_detect(struct i2c_adapter *adapter, int address, int kind)
+static int pc87360_detect(struct i2c_adapter *adapter)
 {
        int i;
        struct i2c_client *new_client;
@@ -738,9 +725,6 @@ int pc87360_detect(struct i2c_adapter *adapter, int address, int kind)
        const char *name = "pc87360";
        int use_thermistors = 0;
 
-       if (!i2c_is_isa_adapter(adapter))
-               return -ENODEV;
-
        if (!(data = kmalloc(sizeof(struct pc87360_data), GFP_KERNEL)))
                return -ENOMEM;
        memset(data, 0x00, sizeof(struct pc87360_data));
@@ -838,6 +822,12 @@ int pc87360_detect(struct i2c_adapter *adapter, int address, int kind)
        }
 
        /* Register sysfs hooks */
+       data->class_dev = hwmon_device_register(&new_client->dev);
+       if (IS_ERR(data->class_dev)) {
+               err = PTR_ERR(data->class_dev);
+               goto ERROR3;
+       }
+
        if (data->innr) {
                device_create_file(&new_client->dev, &dev_attr_in0_input);
                device_create_file(&new_client->dev, &dev_attr_in1_input);
@@ -974,6 +964,8 @@ int pc87360_detect(struct i2c_adapter *adapter, int address, int kind)
 
        return 0;
 
+ERROR3:
+       i2c_detach_client(new_client);
 ERROR2:
        for (i = 0; i < 3; i++) {
                if (data->address[i]) {
@@ -990,6 +982,8 @@ static int pc87360_detach_client(struct i2c_client *client)
        struct pc87360_data *data = i2c_get_clientdata(client);
        int i;
 
+       hwmon_device_unregister(data->class_dev);
+
        if ((i = i2c_detach_client(client))) {
                dev_err(&client->dev, "Client deregistration failed, "
                        "client not detached.\n");
@@ -1043,7 +1037,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
        if (init >= 2 && data->innr) {
                reg = pc87360_read_value(data, LD_IN, NO_BANK,
                                         PC87365_REG_IN_CONVRATE);
-               dev_info(&client->dev, "VLM conversion set to"
+               dev_info(&client->dev, "VLM conversion set to "
                         "1s period, 160us delay\n");
                pc87360_write_value(data, LD_IN, NO_BANK,
                                    PC87365_REG_IN_CONVRATE,
@@ -1320,23 +1314,23 @@ static int __init pc87360_init(void)
        /* Arbitrarily pick one of the addresses */
        for (i = 0; i < 3; i++) {
                if (extra_isa[i] != 0x0000) {
-                       normal_isa[0] = extra_isa[i];
+                       address = extra_isa[i];
                        break;
                }
        }
 
-       if (normal_isa[0] == 0x0000) {
+       if (address == 0x0000) {
                printk(KERN_WARNING "pc87360: No active logical device, "
                       "module not inserted.\n");
                return -ENODEV;
        }
 
-       return i2c_add_driver(&pc87360_driver);
+       return i2c_isa_add_driver(&pc87360_driver);
 }
 
 static void __exit pc87360_exit(void)
 {
-       i2c_del_driver(&pc87360_driver);
+       i2c_isa_del_driver(&pc87360_driver);
 }