]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/hwmon/fscher.c
Merge by hand (whitespace conflicts in libata.h)
[linux-2.6-omap-h63xx.git] / drivers / hwmon / fscher.c
index da411741c2c579964e8b1ac857d370154a8a33f3..a02e1c34c757db66aaf5048d3544146c057fe8d6 100644 (file)
 #include <linux/slab.h>
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
-#include <linux/i2c-sensor.h>
+#include <linux/hwmon.h>
+#include <linux/err.h>
 
 /*
  * Addresses to scan
  */
 
 static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
-static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
 
 /*
  * Insmod parameters
  */
 
-SENSORS_INSMOD_1(fscher);
+I2C_CLIENT_INSMOD_1(fscher);
 
 /*
  * The FSCHER registers
@@ -132,6 +132,7 @@ static struct i2c_driver fscher_driver = {
 
 struct fscher_data {
        struct i2c_client client;
+       struct class_device *class_dev;
        struct semaphore update_lock;
        char valid; /* zero until following fields are valid */
        unsigned long last_updated; /* in jiffies */
@@ -287,7 +288,7 @@ static int fscher_attach_adapter(struct i2c_adapter *adapter)
 {
        if (!(adapter->class & I2C_CLASS_HWMON))
                return 0;
-       return i2c_detect(adapter, &addr_data, fscher_detect);
+       return i2c_probe(adapter, &addr_data, fscher_detect);
 }
 
 static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -302,11 +303,10 @@ static int fscher_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.
         * But it allows us to access i2c_smbus_read_byte_data. */
-       if (!(data = kmalloc(sizeof(struct fscher_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct fscher_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto exit;
        }
-       memset(data, 0, sizeof(struct fscher_data));
 
        /* The common I2C client data is placed right before the
         * Hermes-specific data. */
@@ -341,6 +341,12 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
        fscher_init_client(new_client);
 
        /* 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 exit_detach;
+       }
+
        device_create_file_revision(new_client);
        device_create_file_alarms(new_client);
        device_create_file_control(new_client);
@@ -360,6 +366,8 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
 
        return 0;
 
+exit_detach:
+       i2c_detach_client(new_client);
 exit_free:
        kfree(data);
 exit:
@@ -368,15 +376,15 @@ exit:
 
 static int fscher_detach_client(struct i2c_client *client)
 {
+       struct fscher_data *data = i2c_get_clientdata(client);
        int err;
 
-       if ((err = i2c_detach_client(client))) {
-               dev_err(&client->dev, "Client deregistration failed, "
-                       "client not detached.\n");
+       hwmon_device_unregister(data->class_dev);
+
+       if ((err = i2c_detach_client(client)))
                return err;
-       }
 
-       kfree(i2c_get_clientdata(client));
+       kfree(data);
        return 0;
 }