]> err.no Git - linux-2.6/blobdiff - drivers/hwmon/lm92.c
hwmon: (w83793) VID and VRM handling cleanups
[linux-2.6] / drivers / hwmon / lm92.c
index 9c43120d6bd78386f2fcf59ee6c6d3ddd9a7976a..c31942e08246a9ee3441258f7f7365c14784ba2b 100644 (file)
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/i2c.h>
-#include <linux/i2c-sensor.h>
 #include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
 #include <linux/err.h>
+#include <linux/mutex.h>
 
 /* The LM92 and MAX6635 have 2 two-state pins for address selection,
    resulting in 4 possible addresses. */
-static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
-                                      I2C_CLIENT_END };
+static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
+                                               I2C_CLIENT_END };
 
 /* Insmod parameters */
-SENSORS_INSMOD_1(lm92);
+I2C_CLIENT_INSMOD_1(lm92);
 
 /* The LM92 registers */
 #define LM92_REG_CONFIG                        0x01 /* 8-bit, RW */
@@ -96,8 +97,8 @@ static struct i2c_driver lm92_driver;
 /* Client data (each client gets its own) */
 struct lm92_data {
        struct i2c_client client;
-       struct class_device *class_dev;
-       struct semaphore update_lock;
+       struct device *hwmon_dev;
+       struct mutex update_lock;
        char valid; /* zero until following fields are valid */
        unsigned long last_updated; /* in jiffies */
 
@@ -115,7 +116,7 @@ static struct lm92_data *lm92_update_device(struct device *dev)
        struct i2c_client *client = to_i2c_client(dev);
        struct lm92_data *data = i2c_get_clientdata(client);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        if (time_after(jiffies, data->last_updated + HZ)
         || !data->valid) {
@@ -135,7 +136,7 @@ static struct lm92_data *lm92_update_device(struct device *dev)
                data->valid = 1;
        }
 
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return data;
 }
@@ -159,10 +160,10 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
        struct lm92_data *data = i2c_get_clientdata(client); \
        long val = simple_strtol(buf, NULL, 10); \
  \
-       down(&data->update_lock); \
+       mutex_lock(&data->update_lock); \
        data->value = TEMP_TO_REG(val); \
        i2c_smbus_write_word_data(client, reg, swab16(data->value)); \
-       up(&data->update_lock); \
+       mutex_unlock(&data->update_lock); \
        return count; \
 }
 set_temp(temp1_crit, LM92_REG_TEMP_CRIT);
@@ -195,11 +196,11 @@ static ssize_t set_temp1_crit_hyst(struct device *dev, struct device_attribute *
        struct lm92_data *data = i2c_get_clientdata(client);
        long val = simple_strtol(buf, NULL, 10);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val;
        i2c_smbus_write_word_data(client, LM92_REG_TEMP_HYST,
                                  swab16(TEMP_TO_REG(data->temp1_hyst)));
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -209,6 +210,14 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
        return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->temp1_input));
 }
 
+static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
+                         char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct lm92_data *data = lm92_update_device(dev);
+       return sprintf(buf, "%d\n", (data->temp1_input >> bitnr) & 1);
+}
+
 static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1_input, NULL);
 static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp1_crit,
        set_temp1_crit);
@@ -221,6 +230,9 @@ static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp1_max,
        set_temp1_max);
 static DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_temp1_max_hyst, NULL);
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
+static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1);
 
 
 /*
@@ -288,6 +300,25 @@ static int max6635_check(struct i2c_client *client)
        return 1;
 }
 
+static struct attribute *lm92_attributes[] = {
+       &dev_attr_temp1_input.attr,
+       &dev_attr_temp1_crit.attr,
+       &dev_attr_temp1_crit_hyst.attr,
+       &dev_attr_temp1_min.attr,
+       &dev_attr_temp1_min_hyst.attr,
+       &dev_attr_temp1_max.attr,
+       &dev_attr_temp1_max_hyst.attr,
+       &dev_attr_alarms.attr,
+       &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+       NULL
+};
+
+static const struct attribute_group lm92_group = {
+       .attrs = lm92_attributes,
+};
+
 /* The following function does more than just detection. If detection
    succeeds, it also registers the new chip. */
 static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -301,11 +332,10 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
                                            | I2C_FUNC_SMBUS_WORD_DATA))
                goto exit;
 
-       if (!(data = kmalloc(sizeof(struct lm92_data), GFP_KERNEL))) {
+       if (!(data = kzalloc(sizeof(struct lm92_data), GFP_KERNEL))) {
                err = -ENOMEM;
                goto exit;
        }
-       memset(data, 0, sizeof(struct lm92_data));
 
        /* Fill in enough client fields so that we can read from the chip,
           which is required for identication */
@@ -350,7 +380,7 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
        /* Fill in the remaining client fields */
        strlcpy(new_client->name, name, I2C_NAME_SIZE);
        data->valid = 0;
-       init_MUTEX(&data->update_lock);
+       mutex_init(&data->update_lock);
 
        /* Tell the i2c subsystem a new client has arrived */
        if ((err = i2c_attach_client(new_client)))
@@ -360,23 +390,19 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
        lm92_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);
+       if ((err = sysfs_create_group(&new_client->dev.kobj, &lm92_group)))
                goto exit_detach;
-       }
 
-       device_create_file(&new_client->dev, &dev_attr_temp1_input);
-       device_create_file(&new_client->dev, &dev_attr_temp1_crit);
-       device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
-       device_create_file(&new_client->dev, &dev_attr_temp1_min);
-       device_create_file(&new_client->dev, &dev_attr_temp1_min_hyst);
-       device_create_file(&new_client->dev, &dev_attr_temp1_max);
-       device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
-       device_create_file(&new_client->dev, &dev_attr_alarms);
+       data->hwmon_dev = hwmon_device_register(&new_client->dev);
+       if (IS_ERR(data->hwmon_dev)) {
+               err = PTR_ERR(data->hwmon_dev);
+               goto exit_remove;
+       }
 
        return 0;
 
+exit_remove:
+       sysfs_remove_group(&new_client->dev.kobj, &lm92_group);
 exit_detach:
        i2c_detach_client(new_client);
 exit_free:
@@ -389,7 +415,7 @@ static int lm92_attach_adapter(struct i2c_adapter *adapter)
 {
        if (!(adapter->class & I2C_CLASS_HWMON))
                return 0;
-       return i2c_detect(adapter, &addr_data, lm92_detect);
+       return i2c_probe(adapter, &addr_data, lm92_detect);
 }
 
 static int lm92_detach_client(struct i2c_client *client)
@@ -397,13 +423,11 @@ static int lm92_detach_client(struct i2c_client *client)
        struct lm92_data *data = i2c_get_clientdata(client);
        int err;
 
-       hwmon_device_unregister(data->class_dev);
+       hwmon_device_unregister(data->hwmon_dev);
+       sysfs_remove_group(&client->dev.kobj, &lm92_group);
 
-       if ((err = i2c_detach_client(client))) {
-               dev_err(&client->dev, "Client deregistration failed, "
-                       "client not detached.\n");
+       if ((err = i2c_detach_client(client)))
                return err;
-       }
 
        kfree(data);
        return 0;
@@ -415,10 +439,9 @@ static int lm92_detach_client(struct i2c_client *client)
  */
 
 static struct i2c_driver lm92_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "lm92",
-       .id             = I2C_DRIVERID_LM92,
-       .flags          = I2C_DF_NOTIFY,
+       .driver = {
+               .name   = "lm92",
+       },
        .attach_adapter = lm92_attach_adapter,
        .detach_client  = lm92_detach_client,
 };