fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / hwmon / lm80.c
index c9a7cde..064516d 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
 #include <linux/err.h>
+#include <linux/mutex.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c,
@@ -108,7 +109,7 @@ static inline long TEMP_FROM_REG(u16 temp)
 struct lm80_data {
        struct i2c_client client;
        struct class_device *class_dev;
-       struct semaphore update_lock;
+       struct mutex update_lock;
        char valid;             /* !=0 if following fields are valid */
        unsigned long last_updated;     /* In jiffies */
 
@@ -191,10 +192,10 @@ static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr
        struct lm80_data *data = i2c_get_clientdata(client); \
        long val = simple_strtol(buf, NULL, 10); \
  \
-       down(&data->update_lock);\
+       mutex_lock(&data->update_lock);\
        data->value = IN_TO_REG(val); \
        lm80_write_value(client, reg, data->value); \
-       up(&data->update_lock);\
+       mutex_unlock(&data->update_lock);\
        return count; \
 }
 set_in(min0, in_min[0], LM80_REG_IN_MIN(0));
@@ -241,10 +242,10 @@ static ssize_t set_fan_##suffix(struct device *dev, struct device_attribute *att
        struct lm80_data *data = i2c_get_clientdata(client); \
        long val = simple_strtoul(buf, NULL, 10); \
  \
-       down(&data->update_lock);\
+       mutex_lock(&data->update_lock);\
        data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \
        lm80_write_value(client, reg, data->value); \
-       up(&data->update_lock);\
+       mutex_unlock(&data->update_lock);\
        return count; \
 }
 set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]);
@@ -252,7 +253,7 @@ set_fan(min2, fan_min[1], LM80_REG_FAN_MIN(2), fan_div[1]);
 
 /* Note: we save and restore the fan minimum here, because its value is
    determined in part by the fan divisor.  This follows the principle of
-   least suprise; the user doesn't expect the fan minimum to change just
+   least surprise; the user doesn't expect the fan minimum to change just
    because the divisor changed. */
 static ssize_t set_fan_div(struct device *dev, const char *buf,
        size_t count, int nr)
@@ -263,7 +264,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
        u8 reg;
 
        /* Save fan_min */
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        min = FAN_FROM_REG(data->fan_min[nr],
                           DIV_FROM_REG(data->fan_div[nr]));
 
@@ -275,7 +276,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
        default:
                dev_err(&client->dev, "fan_div value %ld not "
                        "supported. Choose one of 1, 2, 4 or 8!\n", val);
-               up(&data->update_lock);
+               mutex_unlock(&data->update_lock);
                return -EINVAL;
        }
 
@@ -286,7 +287,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
        /* Restore fan_min */
        data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
        lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return count;
 }
@@ -325,10 +326,10 @@ static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *at
        struct lm80_data *data = i2c_get_clientdata(client); \
        long val = simple_strtoul(buf, NULL, 10); \
  \
-       down(&data->update_lock); \
+       mutex_lock(&data->update_lock); \
        data->value = TEMP_LIMIT_TO_REG(val); \
        lm80_write_value(client, reg, data->value); \
-       up(&data->update_lock); \
+       mutex_unlock(&data->update_lock); \
        return count; \
 }
 set_temp(hot_max, temp_hot_max, LM80_REG_TEMP_HOT_MAX);
@@ -393,6 +394,48 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter)
        return i2c_probe(adapter, &addr_data, lm80_detect);
 }
 
+static struct attribute *lm80_attributes[] = {
+       &dev_attr_in0_min.attr,
+       &dev_attr_in1_min.attr,
+       &dev_attr_in2_min.attr,
+       &dev_attr_in3_min.attr,
+       &dev_attr_in4_min.attr,
+       &dev_attr_in5_min.attr,
+       &dev_attr_in6_min.attr,
+       &dev_attr_in0_max.attr,
+       &dev_attr_in1_max.attr,
+       &dev_attr_in2_max.attr,
+       &dev_attr_in3_max.attr,
+       &dev_attr_in4_max.attr,
+       &dev_attr_in5_max.attr,
+       &dev_attr_in6_max.attr,
+       &dev_attr_in0_input.attr,
+       &dev_attr_in1_input.attr,
+       &dev_attr_in2_input.attr,
+       &dev_attr_in3_input.attr,
+       &dev_attr_in4_input.attr,
+       &dev_attr_in5_input.attr,
+       &dev_attr_in6_input.attr,
+       &dev_attr_fan1_min.attr,
+       &dev_attr_fan2_min.attr,
+       &dev_attr_fan1_input.attr,
+       &dev_attr_fan2_input.attr,
+       &dev_attr_fan1_div.attr,
+       &dev_attr_fan2_div.attr,
+       &dev_attr_temp1_input.attr,
+       &dev_attr_temp1_max.attr,
+       &dev_attr_temp1_max_hyst.attr,
+       &dev_attr_temp1_crit.attr,
+       &dev_attr_temp1_crit_hyst.attr,
+       &dev_attr_alarms.attr,
+
+       NULL
+};
+
+static const struct attribute_group lm80_group = {
+       .attrs = lm80_attributes,
+};
+
 static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
 {
        int i, cur;
@@ -437,7 +480,7 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
        /* Fill in the remaining client fields and put it into the global list */
        strlcpy(new_client->name, name, I2C_NAME_SIZE);
        data->valid = 0;
-       init_MUTEX(&data->update_lock);
+       mutex_init(&data->update_lock);
 
        /* Tell the I2C layer a new client has arrived */
        if ((err = i2c_attach_client(new_client)))
@@ -451,48 +494,19 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
        data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2));
 
        /* Register sysfs hooks */
+       if ((err = sysfs_create_group(&new_client->dev.kobj, &lm80_group)))
+               goto error_detach;
+
        data->class_dev = hwmon_device_register(&new_client->dev);
        if (IS_ERR(data->class_dev)) {
                err = PTR_ERR(data->class_dev);
-               goto error_detach;
+               goto error_remove;
        }
 
-       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_in5_min);
-       device_create_file(&new_client->dev, &dev_attr_in6_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_in5_max);
-       device_create_file(&new_client->dev, &dev_attr_in6_max);
-       device_create_file(&new_client->dev, &dev_attr_in0_input);
-       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_in5_input);
-       device_create_file(&new_client->dev, &dev_attr_in6_input);
-       device_create_file(&new_client->dev, &dev_attr_fan1_min);
-       device_create_file(&new_client->dev, &dev_attr_fan2_min);
-       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_fan1_div);
-       device_create_file(&new_client->dev, &dev_attr_fan2_div);
-       device_create_file(&new_client->dev, &dev_attr_temp1_input);
-       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_temp1_crit);
-       device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
-       device_create_file(&new_client->dev, &dev_attr_alarms);
-
        return 0;
 
+error_remove:
+       sysfs_remove_group(&new_client->dev.kobj, &lm80_group);
 error_detach:
        i2c_detach_client(new_client);
 error_free:
@@ -507,7 +521,7 @@ static int lm80_detach_client(struct i2c_client *client)
        int err;
 
        hwmon_device_unregister(data->class_dev);
-
+       sysfs_remove_group(&client->dev.kobj, &lm80_group);
        if ((err = i2c_detach_client(client)))
                return err;
 
@@ -545,7 +559,7 @@ static struct lm80_data *lm80_update_device(struct device *dev)
        struct lm80_data *data = i2c_get_clientdata(client);
        int i;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
                dev_dbg(&client->dev, "Starting lm80 update\n");
@@ -585,7 +599,7 @@ static struct lm80_data *lm80_update_device(struct device *dev)
                data->valid = 1;
        }
 
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return data;
 }