Merge branch 'drm-forlinus' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
[pandora-kernel.git] / drivers / hwmon / gl520sm.c
index 80ae8d3..baee60e 100644 (file)
@@ -26,8 +26,9 @@
 #include <linux/slab.h>
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
-#include <linux/i2c-sensor.h>
-#include <linux/i2c-vid.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-vid.h>
+#include <linux/err.h>
 
 /* Type of the extra sensor */
 static unsigned short extra_sensor_type;
@@ -36,10 +37,9 @@ MODULE_PARM_DESC(extra_sensor_type, "Type of extra sensor (0=autodetect, 1=tempe
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
-static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
 
 /* Insmod parameters */
-SENSORS_INSMOD_1(gl520sm);
+I2C_CLIENT_INSMOD_1(gl520sm);
 
 /* Many GL520 constants specified below 
 One of the inputs can be configured as either temp or voltage.
@@ -109,10 +109,10 @@ static struct gl520_data *gl520_update_device(struct device *dev);
 
 /* Driver data */
 static struct i2c_driver gl520_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "gl520sm",
+       .driver = {
+               .name   = "gl520sm",
+       },
        .id             = I2C_DRIVERID_GL520,
-       .flags          = I2C_DF_NOTIFY,
        .attach_adapter = gl520_attach_adapter,
        .detach_client  = gl520_detach_client,
 };
@@ -120,6 +120,7 @@ static struct i2c_driver gl520_driver = {
 /* Client data */
 struct gl520_data {
        struct i2c_client client;
+       struct class_device *class_dev;
        struct semaphore update_lock;
        char valid;             /* zero until the following fields are valid */
        unsigned long last_updated;     /* in jiffies */
@@ -518,7 +519,7 @@ static int gl520_attach_adapter(struct i2c_adapter *adapter)
 {
        if (!(adapter->class & I2C_CLASS_HWMON))
                return 0;
-       return i2c_detect(adapter, &addr_data, gl520_detect);
+       return i2c_probe(adapter, &addr_data, gl520_detect);
 }
 
 static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -535,11 +536,10 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
           client structure, even though we cannot fill it completely yet.
           But it allows us to access gl520_{read,write}_value. */
 
-       if (!(data = kmalloc(sizeof(struct gl520_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct gl520_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto exit;
        }
-       memset(data, 0, sizeof(struct gl520_data));
 
        new_client = &data->client;
        i2c_set_clientdata(new_client, data);
@@ -571,6 +571,12 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
        gl520_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_vid(new_client, 0);
 
        device_create_file_in(new_client, 0);
@@ -592,6 +598,8 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
 
        return 0;
 
+exit_detach:
+       i2c_detach_client(new_client);
 exit_free:
        kfree(data);
 exit:
@@ -608,7 +616,7 @@ static void gl520_init_client(struct i2c_client *client)
        conf = oldconf = gl520_read_value(client, GL520_REG_CONF);
 
        data->alarm_mask = 0xff;
-       data->vrm = i2c_which_vrm();
+       data->vrm = vid_which_vrm();
 
        if (extra_sensor_type == 1)
                conf &= ~0x10;
@@ -639,15 +647,15 @@ static void gl520_init_client(struct i2c_client *client)
 
 static int gl520_detach_client(struct i2c_client *client)
 {
+       struct gl520_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;
 }