fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / hwmon / w83791d.c
index 87f7312..9e5f885 100644 (file)
@@ -27,9 +27,9 @@
 
     The w83791d chip appears to be part way between the 83781d and the
     83792d. Thus, this file is derived from both the w83792d.c and
 
     The w83791d chip appears to be part way between the 83781d and the
     83792d. Thus, this file is derived from both the w83792d.c and
-    w83781d.c files, but its output is more along the lines of the
-    83781d (which means there are no changes to the user-mode sensors
-    program which treats the 83791d as an 83781d).
+    w83781d.c files.
+
+    The w83791g chip is the same as the w83791d but lead-free.
 */
 
 #include <linux/module.h>
 */
 
 #include <linux/module.h>
@@ -746,6 +746,52 @@ static ssize_t store_vrm_reg(struct device *dev,
 
 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
 
 
 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
 
+#define IN_UNIT_ATTRS(X) \
+       &sda_in_input[X].dev_attr.attr, \
+       &sda_in_min[X].dev_attr.attr,   \
+       &sda_in_max[X].dev_attr.attr
+
+#define FAN_UNIT_ATTRS(X) \
+       &sda_fan_input[X].dev_attr.attr,        \
+       &sda_fan_min[X].dev_attr.attr,          \
+       &sda_fan_div[X].dev_attr.attr
+
+#define TEMP_UNIT_ATTRS(X) \
+       &sda_temp_input[X].dev_attr.attr,       \
+       &sda_temp_max[X].dev_attr.attr,         \
+       &sda_temp_max_hyst[X].dev_attr.attr
+
+static struct attribute *w83791d_attributes[] = {
+       IN_UNIT_ATTRS(0),
+       IN_UNIT_ATTRS(1),
+       IN_UNIT_ATTRS(2),
+       IN_UNIT_ATTRS(3),
+       IN_UNIT_ATTRS(4),
+       IN_UNIT_ATTRS(5),
+       IN_UNIT_ATTRS(6),
+       IN_UNIT_ATTRS(7),
+       IN_UNIT_ATTRS(8),
+       IN_UNIT_ATTRS(9),
+       FAN_UNIT_ATTRS(0),
+       FAN_UNIT_ATTRS(1),
+       FAN_UNIT_ATTRS(2),
+       FAN_UNIT_ATTRS(3),
+       FAN_UNIT_ATTRS(4),
+       TEMP_UNIT_ATTRS(0),
+       TEMP_UNIT_ATTRS(1),
+       TEMP_UNIT_ATTRS(2),
+       &dev_attr_alarms.attr,
+       &sda_beep_ctrl[0].dev_attr.attr,
+       &sda_beep_ctrl[1].dev_attr.attr,
+       &dev_attr_cpu0_vid.attr,
+       &dev_attr_vrm.attr,
+       NULL
+};
+
+static const struct attribute_group w83791d_group = {
+       .attrs = w83791d_attributes,
+};
+
 /* This function is called when:
      * w83791d_driver is inserted (when this module is loaded), for each
        available adapter
 /* This function is called when:
      * w83791d_driver is inserted (when this module is loaded), for each
        available adapter
@@ -967,41 +1013,20 @@ static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind)
        }
 
        /* Register sysfs hooks */
        }
 
        /* Register sysfs hooks */
+       if ((err = sysfs_create_group(&client->dev.kobj, &w83791d_group)))
+               goto error3;
+
+       /* Everything is ready, now register the working device */
        data->class_dev = hwmon_device_register(dev);
        if (IS_ERR(data->class_dev)) {
                err = PTR_ERR(data->class_dev);
        data->class_dev = hwmon_device_register(dev);
        if (IS_ERR(data->class_dev)) {
                err = PTR_ERR(data->class_dev);
-               goto error3;
-       }
-
-       for (i = 0; i < NUMBER_OF_VIN; i++) {
-               device_create_file(dev, &sda_in_input[i].dev_attr);
-               device_create_file(dev, &sda_in_min[i].dev_attr);
-               device_create_file(dev, &sda_in_max[i].dev_attr);
+               goto error4;
        }
 
        }
 
-       for (i = 0; i < NUMBER_OF_FANIN; i++) {
-               device_create_file(dev, &sda_fan_input[i].dev_attr);
-               device_create_file(dev, &sda_fan_div[i].dev_attr);
-               device_create_file(dev, &sda_fan_min[i].dev_attr);
-       }
-
-       for (i = 0; i < NUMBER_OF_TEMPIN; i++) {
-               device_create_file(dev, &sda_temp_input[i].dev_attr);
-               device_create_file(dev, &sda_temp_max[i].dev_attr);
-               device_create_file(dev, &sda_temp_max_hyst[i].dev_attr);
-       }
-
-       device_create_file(dev, &dev_attr_alarms);
-
-       for (i = 0; i < ARRAY_SIZE(sda_beep_ctrl); i++) {
-               device_create_file(dev, &sda_beep_ctrl[i].dev_attr);
-       }
-
-       device_create_file(dev, &dev_attr_cpu0_vid);
-       device_create_file(dev, &dev_attr_vrm);
-
        return 0;
 
        return 0;
 
+error4:
+       sysfs_remove_group(&client->dev.kobj, &w83791d_group);
 error3:
        if (data->lm75[0] != NULL) {
                i2c_detach_client(data->lm75[0]);
 error3:
        if (data->lm75[0] != NULL) {
                i2c_detach_client(data->lm75[0]);
@@ -1025,8 +1050,10 @@ static int w83791d_detach_client(struct i2c_client *client)
        int err;
 
        /* main client */
        int err;
 
        /* main client */
-       if (data)
+       if (data) {
                hwmon_device_unregister(data->class_dev);
                hwmon_device_unregister(data->class_dev);
+               sysfs_remove_group(&client->dev.kobj, &w83791d_group);
+       }
 
        if ((err = i2c_detach_client(client)))
                return err;
 
        if ((err = i2c_detach_client(client)))
                return err;
@@ -1171,6 +1198,7 @@ static struct w83791d_data *w83791d_update_device(struct device *dev)
                        (w83791d_read(client, W83791D_REG_BEEP_CTRL[1]) << 8) +
                        (w83791d_read(client, W83791D_REG_BEEP_CTRL[2]) << 16);
 
                        (w83791d_read(client, W83791D_REG_BEEP_CTRL[1]) << 8) +
                        (w83791d_read(client, W83791D_REG_BEEP_CTRL[2]) << 16);
 
+               /* Extract global beep enable flag */
                data->beep_enable =
                        (data->beep_mask >> GLOBAL_BEEP_ENABLE_SHIFT) & 0x01;
 
                data->beep_enable =
                        (data->beep_mask >> GLOBAL_BEEP_ENABLE_SHIFT) & 0x01;