fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / hwmon / fscher.c
index 2540918..1971775 100644 (file)
@@ -33,6 +33,8 @@
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
 #include <linux/err.h>
+#include <linux/mutex.h>
+#include <linux/sysfs.h>
 
 /*
  * Addresses to scan
@@ -133,7 +135,7 @@ static struct i2c_driver fscher_driver = {
 struct fscher_data {
        struct i2c_client client;
        struct class_device *class_dev;
-       struct semaphore update_lock;
+       struct mutex update_lock;
        char valid; /* zero until following fields are valid */
        unsigned long last_updated; /* in jiffies */
 
@@ -239,47 +241,45 @@ sysfs_alarms(FSCHER_REG_EVENTS)
 sysfs_control(FSCHER_REG_CONTROL)
 sysfs_watchdog(FSCHER_REG_WDOG_CONTROL, FSCHER_REG_WDOG_STATE, FSCHER_REG_WDOG_PRESET)
   
-#define device_create_file_fan(client, offset) \
-do { \
-       device_create_file(&client->dev, &dev_attr_fan##offset##_status); \
-       device_create_file(&client->dev, &dev_attr_pwm##offset); \
-       device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
-       device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
-} while (0)
-
-#define device_create_file_temp(client, offset) \
-do { \
-       device_create_file(&client->dev, &dev_attr_temp##offset##_status); \
-       device_create_file(&client->dev, &dev_attr_temp##offset##_input); \
-} while (0)
-
-#define device_create_file_in(client, offset) \
-do { \
-       device_create_file(&client->dev, &dev_attr_in##offset##_input); \
-} while (0)
-
-#define device_create_file_revision(client) \
-do { \
-       device_create_file(&client->dev, &dev_attr_revision); \
-} while (0)
-
-#define device_create_file_alarms(client) \
-do { \
-       device_create_file(&client->dev, &dev_attr_alarms); \
-} while (0)
-
-#define device_create_file_control(client) \
-do { \
-       device_create_file(&client->dev, &dev_attr_control); \
-} while (0)
-
-#define device_create_file_watchdog(client) \
-do { \
-       device_create_file(&client->dev, &dev_attr_watchdog_status); \
-       device_create_file(&client->dev, &dev_attr_watchdog_control); \
-       device_create_file(&client->dev, &dev_attr_watchdog_preset); \
-} while (0)
-  
+static struct attribute *fscher_attributes[] = {
+       &dev_attr_revision.attr,
+       &dev_attr_alarms.attr,
+       &dev_attr_control.attr,
+
+       &dev_attr_watchdog_status.attr,
+       &dev_attr_watchdog_control.attr,
+       &dev_attr_watchdog_preset.attr,
+
+       &dev_attr_in0_input.attr,
+       &dev_attr_in1_input.attr,
+       &dev_attr_in2_input.attr,
+
+       &dev_attr_fan1_status.attr,
+       &dev_attr_fan1_div.attr,
+       &dev_attr_fan1_input.attr,
+       &dev_attr_pwm1.attr,
+       &dev_attr_fan2_status.attr,
+       &dev_attr_fan2_div.attr,
+       &dev_attr_fan2_input.attr,
+       &dev_attr_pwm2.attr,
+       &dev_attr_fan3_status.attr,
+       &dev_attr_fan3_div.attr,
+       &dev_attr_fan3_input.attr,
+       &dev_attr_pwm3.attr,
+
+       &dev_attr_temp1_status.attr,
+       &dev_attr_temp1_input.attr,
+       &dev_attr_temp2_status.attr,
+       &dev_attr_temp2_input.attr,
+       &dev_attr_temp3_status.attr,
+       &dev_attr_temp3_input.attr,
+       NULL
+};
+
+static const struct attribute_group fscher_group = {
+       .attrs = fscher_attributes,
+};
+
 /*
  * Real code
  */
@@ -332,7 +332,7 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
         * global list */
        strlcpy(new_client->name, "fscher", 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)))
@@ -341,31 +341,19 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
        fscher_init_client(new_client);
 
        /* Register sysfs hooks */
+       if ((err = sysfs_create_group(&new_client->dev.kobj, &fscher_group)))
+               goto exit_detach;
+
        data->class_dev = hwmon_device_register(&new_client->dev);
        if (IS_ERR(data->class_dev)) {
                err = PTR_ERR(data->class_dev);
-               goto exit_detach;
+               goto exit_remove_files;
        }
 
-       device_create_file_revision(new_client);
-       device_create_file_alarms(new_client);
-       device_create_file_control(new_client);
-       device_create_file_watchdog(new_client);
-
-       device_create_file_in(new_client, 0);
-       device_create_file_in(new_client, 1);
-       device_create_file_in(new_client, 2);
-
-       device_create_file_fan(new_client, 1);
-       device_create_file_fan(new_client, 2);
-       device_create_file_fan(new_client, 3);
-
-       device_create_file_temp(new_client, 1);
-       device_create_file_temp(new_client, 2);
-       device_create_file_temp(new_client, 3);
-
        return 0;
 
+exit_remove_files:
+       sysfs_remove_group(&new_client->dev.kobj, &fscher_group);
 exit_detach:
        i2c_detach_client(new_client);
 exit_free:
@@ -380,6 +368,7 @@ static int fscher_detach_client(struct i2c_client *client)
        int err;
 
        hwmon_device_unregister(data->class_dev);
+       sysfs_remove_group(&client->dev.kobj, &fscher_group);
 
        if ((err = i2c_detach_client(client)))
                return err;
@@ -417,7 +406,7 @@ static struct fscher_data *fscher_update_device(struct device *dev)
        struct i2c_client *client = to_i2c_client(dev);
        struct fscher_data *data = i2c_get_clientdata(client);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
 
@@ -457,7 +446,7 @@ static struct fscher_data *fscher_update_device(struct device *dev)
                data->valid = 1;                 
        }
 
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return data;
 }
@@ -472,10 +461,10 @@ static ssize_t set_fan_status(struct i2c_client *client, struct fscher_data *dat
        /* bits 0..1, 3..7 reserved => mask with 0x04 */  
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0x04;
        
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->fan_status[FAN_INDEX_FROM_NUM(nr)] &= ~v;
        fscher_write_value(client, reg, v);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -490,10 +479,10 @@ static ssize_t set_pwm(struct i2c_client *client, struct fscher_data *data,
 {
        unsigned long v = simple_strtoul(buf, NULL, 10);
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->fan_min[FAN_INDEX_FROM_NUM(nr)] = v > 0xff ? 0xff : v;
        fscher_write_value(client, reg, data->fan_min[FAN_INDEX_FROM_NUM(nr)]);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -518,14 +507,14 @@ static ssize_t set_fan_div(struct i2c_client *client, struct fscher_data *data,
                return -EINVAL;
        }
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        /* bits 2..7 reserved => mask with 0x03 */
        data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] &= ~0x03;
        data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] |= v;
 
        fscher_write_value(client, reg, data->fan_ripple[FAN_INDEX_FROM_NUM(nr)]);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -552,10 +541,10 @@ static ssize_t set_temp_status(struct i2c_client *client, struct fscher_data *da
        /* bits 2..7 reserved, 0 read only => mask with 0x02 */  
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->temp_status[TEMP_INDEX_FROM_NUM(nr)] &= ~v;
        fscher_write_value(client, reg, v);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -609,10 +598,10 @@ static ssize_t set_control(struct i2c_client *client, struct fscher_data *data,
        /* bits 1..7 reserved => mask with 0x01 */  
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0x01;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->global_control &= ~v;
        fscher_write_value(client, reg, v);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -631,11 +620,11 @@ static ssize_t set_watchdog_control(struct i2c_client *client, struct
        /* bits 0..3 reserved => mask with 0xf0 */  
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->watchdog[2] &= ~0xf0;
        data->watchdog[2] |= v;
        fscher_write_value(client, reg, data->watchdog[2]);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -651,10 +640,10 @@ static ssize_t set_watchdog_status(struct i2c_client *client, struct fscher_data
        /* bits 0, 2..7 reserved => mask with 0x02 */  
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->watchdog[1] &= ~v;
        fscher_write_value(client, reg, v);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
@@ -669,10 +658,10 @@ static ssize_t set_watchdog_preset(struct i2c_client *client, struct fscher_data
 {
        unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff;
        
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
        data->watchdog[0] = v;
        fscher_write_value(client, reg, data->watchdog[0]);
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
        return count;
 }