[PATCH] fbdev: neofb: Driver cleanups
[powerpc.git] / drivers / hwmon / lm85.c
index b4d7fd4..7389a01 100644 (file)
 #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>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
-static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
 
 /* Insmod parameters */
-SENSORS_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
+I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
 
 /* The LM85 registers */
 
@@ -281,15 +281,6 @@ static int ZONE_TO_REG( int zone )
 #define PPR_TO_REG(val,fan) (SENSORS_LIMIT((val)-1,0,3)<<(fan *2))
 #define PPR_FROM_REG(val,fan) ((((val)>>(fan * 2))&0x03)+1)
 
-/* i2c-vid.h defines vid_from_reg() */
-#define VID_FROM_REG(val,vrm) (vid_from_reg((val),(vrm)))
-
-/* Unlike some other drivers we DO NOT set initial limits.  Use
- * the config file to set limits.  Some users have reported
- * motherboards shutting down when we set limits in a previous
- * version of the driver.
- */
-
 /* Chip sampling rates
  *
  * Some sensors are not updated more frequently than once per second
@@ -339,6 +330,7 @@ struct lm85_autofan {
 
 struct lm85_data {
        struct i2c_client client;
+       struct class_device *class_dev;
        struct semaphore lock;
        enum chips type;
 
@@ -388,10 +380,10 @@ static void lm85_init_client(struct i2c_client *client);
 
 
 static struct i2c_driver lm85_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "lm85",
+       .driver = {
+               .name   = "lm85",
+       },
        .id             = I2C_DRIVERID_LM85,
-       .flags          = I2C_DF_NOTIFY,
        .attach_adapter = lm85_attach_adapter,
        .detach_client  = lm85_detach_client,
 };
@@ -451,7 +443,17 @@ show_fan_offset(4);
 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct lm85_data *data = lm85_update_device(dev);
-       return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
+       int vid;
+
+       if (data->type == adt7463 && (data->vid & 0x80)) {
+               /* 6-pin VID (VRM 10) */
+               vid = vid_from_reg(data->vid & 0x3f, data->vrm);
+       } else {
+               /* 5-pin VID (VRM 9) */
+               vid = vid_from_reg(data->vid & 0x1f, data->vrm);
+       }
+
+       return sprintf(buf, "%d\n", vid);
 }
 
 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
@@ -1015,14 +1017,14 @@ temp_auto(1);
 temp_auto(2);
 temp_auto(3);
 
-int lm85_attach_adapter(struct i2c_adapter *adapter)
+static int lm85_attach_adapter(struct i2c_adapter *adapter)
 {
        if (!(adapter->class & I2C_CLASS_HWMON))
                return 0;
-       return i2c_detect(adapter, &addr_data, lm85_detect);
+       return i2c_probe(adapter, &addr_data, lm85_detect);
 }
 
-int lm85_detect(struct i2c_adapter *adapter, int address,
+static int lm85_detect(struct i2c_adapter *adapter, int address,
                int kind)
 {
        int company, verstep ;
@@ -1031,11 +1033,6 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
        int err = 0;
        const char *type_name = "";
 
-       if (i2c_is_isa_adapter(adapter)) {
-               /* This chip has no ISA interface */
-               goto ERROR0 ;
-       };
-
        if (!i2c_check_functionality(adapter,
                                        I2C_FUNC_SMBUS_BYTE_DATA)) {
                /* We need to be able to do byte I/O */
@@ -1046,11 +1043,10 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
           client structure, even though we cannot fill it completely yet.
           But it allows us to access lm85_{read,write}_value. */
 
-       if (!(data = kmalloc(sizeof(struct lm85_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto ERROR0;
        }
-       memset(data, 0, sizeof(struct lm85_data));
 
        new_client = &data->client;
        i2c_set_clientdata(new_client, data);
@@ -1160,12 +1156,18 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
                goto ERROR1;
 
        /* Set the VRM version */
-       data->vrm = i2c_which_vrm();
+       data->vrm = vid_which_vrm();
 
        /* Initialize the LM85 chip */
        lm85_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 ERROR2;
+       }
+
        device_create_file(&new_client->dev, &dev_attr_fan1_input);
        device_create_file(&new_client->dev, &dev_attr_fan2_input);
        device_create_file(&new_client->dev, &dev_attr_fan3_input);
@@ -1184,17 +1186,14 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
        device_create_file(&new_client->dev, &dev_attr_in1_input);
        device_create_file(&new_client->dev, &dev_attr_in2_input);
        device_create_file(&new_client->dev, &dev_attr_in3_input);
-       device_create_file(&new_client->dev, &dev_attr_in4_input);
        device_create_file(&new_client->dev, &dev_attr_in0_min);
        device_create_file(&new_client->dev, &dev_attr_in1_min);
        device_create_file(&new_client->dev, &dev_attr_in2_min);
        device_create_file(&new_client->dev, &dev_attr_in3_min);
-       device_create_file(&new_client->dev, &dev_attr_in4_min);
        device_create_file(&new_client->dev, &dev_attr_in0_max);
        device_create_file(&new_client->dev, &dev_attr_in1_max);
        device_create_file(&new_client->dev, &dev_attr_in2_max);
        device_create_file(&new_client->dev, &dev_attr_in3_max);
-       device_create_file(&new_client->dev, &dev_attr_in4_max);
        device_create_file(&new_client->dev, &dev_attr_temp1_input);
        device_create_file(&new_client->dev, &dev_attr_temp2_input);
        device_create_file(&new_client->dev, &dev_attr_temp3_input);
@@ -1232,24 +1231,37 @@ int lm85_detect(struct i2c_adapter *adapter, int address,
        device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_crit);
        device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_crit);
 
+       /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
+          as a sixth digital VID input rather than an analog input. */
+       data->vid = lm85_read_value(new_client, LM85_REG_VID);
+       if (!(kind == adt7463 && (data->vid & 0x80))) {
+               device_create_file(&new_client->dev, &dev_attr_in4_input);
+               device_create_file(&new_client->dev, &dev_attr_in4_min);
+               device_create_file(&new_client->dev, &dev_attr_in4_max);
+       }
+
        return 0;
 
        /* Error out and cleanup code */
+    ERROR2:
+       i2c_detach_client(new_client);
     ERROR1:
        kfree(data);
     ERROR0:
        return err;
 }
 
-int lm85_detach_client(struct i2c_client *client)
+static int lm85_detach_client(struct i2c_client *client)
 {
+       struct lm85_data *data = i2c_get_clientdata(client);
+       hwmon_device_unregister(data->class_dev);
        i2c_detach_client(client);
-       kfree(i2c_get_clientdata(client));
+       kfree(data);
        return 0;
 }
 
 
-int lm85_read_value(struct i2c_client *client, u8 reg)
+static int lm85_read_value(struct i2c_client *client, u8 reg)
 {
        int res;
 
@@ -1279,7 +1291,7 @@ int lm85_read_value(struct i2c_client *client, u8 reg)
        return res ;
 }
 
-int lm85_write_value(struct i2c_client *client, u8 reg, int value)
+static int lm85_write_value(struct i2c_client *client, u8 reg, int value)
 {
        int res ;
 
@@ -1308,7 +1320,7 @@ int lm85_write_value(struct i2c_client *client, u8 reg, int value)
        return res ;
 }
 
-void lm85_init_client(struct i2c_client *client)
+static void lm85_init_client(struct i2c_client *client)
 {
        int value;
        struct lm85_data *data = i2c_get_clientdata(client);
@@ -1386,11 +1398,18 @@ static struct lm85_data *lm85_update_device(struct device *dev)
                   irrelevant. So it is left in 4*/
                data->adc_scale = (data->type == emc6d102 ) ? 16 : 4;
 
-               for (i = 0; i <= 4; ++i) {
+               data->vid = lm85_read_value(client, LM85_REG_VID);
+
+               for (i = 0; i <= 3; ++i) {
                        data->in[i] =
                            lm85_read_value(client, LM85_REG_IN(i));
                }
 
+               if (!(data->type == adt7463 && (data->vid & 0x80))) {
+                       data->in[4] = lm85_read_value(client,
+                                     LM85_REG_IN(4));
+               }
+
                for (i = 0; i <= 3; ++i) {
                        data->fan[i] =
                            lm85_read_value(client, LM85_REG_FAN(i));
@@ -1454,13 +1473,20 @@ static struct lm85_data *lm85_update_device(struct device *dev)
                /* Things that don't change often */
                dev_dbg(&client->dev, "Reading config values\n");
 
-               for (i = 0; i <= 4; ++i) {
+               for (i = 0; i <= 3; ++i) {
                        data->in_min[i] =
                            lm85_read_value(client, LM85_REG_IN_MIN(i));
                        data->in_max[i] =
                            lm85_read_value(client, LM85_REG_IN_MAX(i));
                }
 
+               if (!(data->type == adt7463 && (data->vid & 0x80))) {
+                       data->in_min[4] = lm85_read_value(client,
+                                         LM85_REG_IN_MIN(4));
+                       data->in_max[4] = lm85_read_value(client,
+                                         LM85_REG_IN_MAX(4));
+               }
+
                if ( data->type == emc6d100 ) {
                        for (i = 5; i <= 7; ++i) {
                                data->in_min[i] =
@@ -1482,8 +1508,6 @@ static struct lm85_data *lm85_update_device(struct device *dev)
                            lm85_read_value(client, LM85_REG_TEMP_MAX(i));
                }
 
-               data->vid = lm85_read_value(client, LM85_REG_VID);
-
                for (i = 0; i <= 2; ++i) {
                        int val ;
                        data->autofan[i].config =