[PATCH] w83781d: Don't reset the chip by default
[cascardo/linux.git] / drivers / hwmon / atxp1.c
index ced5418..728a1e8 100644 (file)
 #include <linux/module.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>
+#include <linux/mutex.h>
 
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
@@ -43,7 +43,7 @@ MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>");
 
 static unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END };
 
-SENSORS_INSMOD_1(atxp1);
+I2C_CLIENT_INSMOD_1(atxp1);
 
 static int atxp1_attach_adapter(struct i2c_adapter * adapter);
 static int atxp1_detach_client(struct i2c_client * client);
@@ -51,9 +51,9 @@ static struct atxp1_data * atxp1_update_device(struct device *dev);
 static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind);
 
 static struct i2c_driver atxp1_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "atxp1",
-       .flags          = I2C_DF_NOTIFY,
+       .driver = {
+               .name   = "atxp1",
+       },
        .attach_adapter = atxp1_attach_adapter,
        .detach_client  = atxp1_detach_client,
 };
@@ -61,7 +61,7 @@ static struct i2c_driver atxp1_driver = {
 struct atxp1_data {
        struct i2c_client client;
        struct class_device *class_dev;
-       struct semaphore update_lock;
+       struct mutex update_lock;
        unsigned long last_updated;
        u8 valid;
        struct {
@@ -81,7 +81,7 @@ static struct atxp1_data * atxp1_update_device(struct device *dev)
        client = to_i2c_client(dev);
        data = i2c_get_clientdata(client);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
 
@@ -94,7 +94,7 @@ static struct atxp1_data * atxp1_update_device(struct device *dev)
                data->valid = 1;
        }
 
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return(data);
 }
@@ -254,7 +254,9 @@ static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2);
 
 static int atxp1_attach_adapter(struct i2c_adapter *adapter)
 {
-       return i2c_detect(adapter, &addr_data, &atxp1_detect);
+       if (!(adapter->class & I2C_CLASS_HWMON))
+               return 0;
+       return i2c_probe(adapter, &addr_data, &atxp1_detect);
 };
 
 static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -267,12 +269,11 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
                goto exit;
 
-       if (!(data = kmalloc(sizeof(struct atxp1_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct atxp1_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto exit;
        }
 
-       memset(data, 0, sizeof(struct atxp1_data));
        new_client = &data->client;
        i2c_set_clientdata(new_client, data);
 
@@ -297,7 +298,7 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
        }
 
        /* Get VRM */
-       data->vrm = i2c_which_vrm();
+       data->vrm = vid_which_vrm();
 
        if ((data->vrm != 90) && (data->vrm != 91)) {
                dev_err(&new_client->dev, "Not supporting VRM %d.%d\n",
@@ -309,7 +310,7 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
 
        data->valid = 0;
 
-       init_MUTEX(&data->update_lock);
+       mutex_init(&data->update_lock);
 
        err = i2c_attach_client(new_client);