hwmon: (adm1026) Don't create files for missing inputs
authorJean Delvare <khali@linux-fr.org>
Thu, 29 Nov 2007 22:47:54 +0000 (23:47 +0100)
committerMark M. Hoffman <mhoffman@lightlink.com>
Fri, 8 Feb 2008 01:39:43 +0000 (20:39 -0500)
On the ADM1026, pins 27 and 28 can be used for two different functions:
either temp3, or in8+in9. We should only create the sysfs files for the
function that is configured, otherwise it is confusing for the user.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
drivers/hwmon/adm1026.c

index a20af03f4fc657c1c3b6889cd1521939e98cd5c4..8002f68240c4e47c1dc2d7492fbbfb38d6f7752c 100644 (file)
@@ -1507,14 +1507,6 @@ static struct attribute *adm1026_attributes[] = {
        &sensor_dev_attr_in7_max.dev_attr.attr,
        &sensor_dev_attr_in7_min.dev_attr.attr,
        &sensor_dev_attr_in7_alarm.dev_attr.attr,
-       &sensor_dev_attr_in8_input.dev_attr.attr,
-       &sensor_dev_attr_in8_max.dev_attr.attr,
-       &sensor_dev_attr_in8_min.dev_attr.attr,
-       &sensor_dev_attr_in8_alarm.dev_attr.attr,
-       &sensor_dev_attr_in9_input.dev_attr.attr,
-       &sensor_dev_attr_in9_max.dev_attr.attr,
-       &sensor_dev_attr_in9_min.dev_attr.attr,
-       &sensor_dev_attr_in9_alarm.dev_attr.attr,
        &sensor_dev_attr_in10_input.dev_attr.attr,
        &sensor_dev_attr_in10_max.dev_attr.attr,
        &sensor_dev_attr_in10_min.dev_attr.attr,
@@ -1583,28 +1575,18 @@ static struct attribute *adm1026_attributes[] = {
        &sensor_dev_attr_temp2_max.dev_attr.attr,
        &sensor_dev_attr_temp2_min.dev_attr.attr,
        &sensor_dev_attr_temp2_alarm.dev_attr.attr,
-       &sensor_dev_attr_temp3_input.dev_attr.attr,
-       &sensor_dev_attr_temp3_max.dev_attr.attr,
-       &sensor_dev_attr_temp3_min.dev_attr.attr,
-       &sensor_dev_attr_temp3_alarm.dev_attr.attr,
        &sensor_dev_attr_temp1_offset.dev_attr.attr,
        &sensor_dev_attr_temp2_offset.dev_attr.attr,
-       &sensor_dev_attr_temp3_offset.dev_attr.attr,
        &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
        &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
-       &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
        &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr.attr,
        &sensor_dev_attr_temp2_auto_point1_temp_hyst.dev_attr.attr,
-       &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr.attr,
        &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
        &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
-       &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
        &sensor_dev_attr_temp1_crit.dev_attr.attr,
        &sensor_dev_attr_temp2_crit.dev_attr.attr,
-       &sensor_dev_attr_temp3_crit.dev_attr.attr,
        &dev_attr_temp1_crit_enable.attr,
        &dev_attr_temp2_crit_enable.attr,
-       &dev_attr_temp3_crit_enable.attr,
        &dev_attr_cpu0_vid.attr,
        &dev_attr_vrm.attr,
        &dev_attr_alarms.attr,
@@ -1619,10 +1601,8 @@ static struct attribute *adm1026_attributes[] = {
        &dev_attr_pwm3_enable.attr,
        &dev_attr_temp1_auto_point1_pwm.attr,
        &dev_attr_temp2_auto_point1_pwm.attr,
-       &dev_attr_temp3_auto_point1_pwm.attr,
        &dev_attr_temp1_auto_point2_pwm.attr,
        &dev_attr_temp2_auto_point2_pwm.attr,
-       &dev_attr_temp3_auto_point2_pwm.attr,
        &dev_attr_analog_out.attr,
        NULL
 };
@@ -1631,6 +1611,40 @@ static const struct attribute_group adm1026_group = {
        .attrs = adm1026_attributes,
 };
 
+static struct attribute *adm1026_attributes_temp3[] = {
+       &sensor_dev_attr_temp3_input.dev_attr.attr,
+       &sensor_dev_attr_temp3_max.dev_attr.attr,
+       &sensor_dev_attr_temp3_min.dev_attr.attr,
+       &sensor_dev_attr_temp3_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp3_offset.dev_attr.attr,
+       &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
+       &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
+       &sensor_dev_attr_temp3_crit.dev_attr.attr,
+       &dev_attr_temp3_crit_enable.attr,
+       &dev_attr_temp3_auto_point1_pwm.attr,
+       &dev_attr_temp3_auto_point2_pwm.attr,
+};
+
+static const struct attribute_group adm1026_group_temp3 = {
+       .attrs = adm1026_attributes_temp3,
+};
+
+static struct attribute *adm1026_attributes_in8_9[] = {
+       &sensor_dev_attr_in8_input.dev_attr.attr,
+       &sensor_dev_attr_in8_max.dev_attr.attr,
+       &sensor_dev_attr_in8_min.dev_attr.attr,
+       &sensor_dev_attr_in8_alarm.dev_attr.attr,
+       &sensor_dev_attr_in9_input.dev_attr.attr,
+       &sensor_dev_attr_in9_max.dev_attr.attr,
+       &sensor_dev_attr_in9_min.dev_attr.attr,
+       &sensor_dev_attr_in9_alarm.dev_attr.attr,
+};
+
+static const struct attribute_group adm1026_group_in8_9 = {
+       .attrs = adm1026_attributes_in8_9,
+};
+
 static int adm1026_detect(struct i2c_adapter *adapter, int address,
                          int kind)
 {
@@ -1733,6 +1747,14 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
        /* Register sysfs hooks */
        if ((err = sysfs_create_group(&client->dev.kobj, &adm1026_group)))
                goto exitdetach;
+       if (data->config1 & CFG1_AIN8_9)
+               err = sysfs_create_group(&client->dev.kobj,
+                                        &adm1026_group_in8_9);
+       else
+               err = sysfs_create_group(&client->dev.kobj,
+                                        &adm1026_group_temp3);
+       if (err)
+               goto exitremove;
 
        data->hwmon_dev = hwmon_device_register(&client->dev);
        if (IS_ERR(data->hwmon_dev)) {
@@ -1745,6 +1767,10 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
        /* Error out and cleanup code */
 exitremove:
        sysfs_remove_group(&client->dev.kobj, &adm1026_group);
+       if (data->config1 & CFG1_AIN8_9)
+               sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9);
+       else
+               sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3);
 exitdetach:
        i2c_detach_client(client);
 exitfree:
@@ -1758,6 +1784,10 @@ static int adm1026_detach_client(struct i2c_client *client)
        struct adm1026_data *data = i2c_get_clientdata(client);
        hwmon_device_unregister(data->hwmon_dev);
        sysfs_remove_group(&client->dev.kobj, &adm1026_group);
+       if (data->config1 & CFG1_AIN8_9)
+               sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9);
+       else
+               sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3);
        i2c_detach_client(client);
        kfree(data);
        return 0;