X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fhwmon%2Fgl520sm.c;h=2d39d8fc2389fbc904fbc1c93632981efa7d1be5;hb=eba0e319c12fb098d66316a8eafbaaa9174a07c3;hp=47b4d49f75c6a3393136fd50e9eecaf429bb33b9;hpb=aca361c1a0dc0165ac3148137983cb4b1458b5c1;p=linux-2.6-omap-h63xx.git diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c index 47b4d49f75c..2d39d8fc238 100644 --- a/drivers/hwmon/gl520sm.c +++ b/drivers/hwmon/gl520sm.c @@ -2,7 +2,7 @@ gl520sm.c - Part of lm_sensors, Linux kernel modules for hardware monitoring Copyright (c) 1998, 1999 Frodo Looijaard , - Kyösti Mälkki + Kyösti Mälkki Copyright (c) 2005 Maarten Deprez This program is free software; you can redistribute it and/or modify @@ -30,6 +30,7 @@ #include #include #include +#include /* Type of the extra sensor */ static unsigned short extra_sensor_type; @@ -121,7 +122,7 @@ static struct i2c_driver gl520_driver = { /* Client data */ struct gl520_data { struct i2c_client client; - struct class_device *class_dev; + struct device *hwmon_dev; struct mutex update_lock; char valid; /* zero until the following fields are valid */ unsigned long last_updated; /* in jiffies */ @@ -190,55 +191,29 @@ static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL); #define sysfs_vid(n) \ sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT) -#define device_create_file_vid(client, n) \ -device_create_file(&client->dev, &dev_attr_cpu##n##_vid) - #define sysfs_in(n) \ sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \ sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \ sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \ -#define device_create_file_in(client, n) \ -({device_create_file(&client->dev, &dev_attr_in##n##_input); \ -device_create_file(&client->dev, &dev_attr_in##n##_min); \ -device_create_file(&client->dev, &dev_attr_in##n##_max);}) - #define sysfs_fan(n) \ sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \ sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \ sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV) -#define device_create_file_fan(client, n) \ -({device_create_file(&client->dev, &dev_attr_fan##n##_input); \ -device_create_file(&client->dev, &dev_attr_fan##n##_min); \ -device_create_file(&client->dev, &dev_attr_fan##n##_div);}) - #define sysfs_fan_off(n) \ sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \ -#define device_create_file_fan_off(client, n) \ -device_create_file(&client->dev, &dev_attr_fan##n##_off) - #define sysfs_temp(n) \ sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \ sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \ sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST) -#define device_create_file_temp(client, n) \ -({device_create_file(&client->dev, &dev_attr_temp##n##_input); \ -device_create_file(&client->dev, &dev_attr_temp##n##_max); \ -device_create_file(&client->dev, &dev_attr_temp##n##_max_hyst);}) - #define sysfs_alarms() \ sysfs_ro(alarms, , GL520_REG_ALARMS) \ sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \ sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK) -#define device_create_file_alarms(client) \ -({device_create_file(&client->dev, &dev_attr_alarms); \ -device_create_file(&client->dev, &dev_attr_beep_enable); \ -device_create_file(&client->dev, &dev_attr_beep_mask);}) - sysfs_vid(0) @@ -456,7 +431,7 @@ static ssize_t set_temp_max(struct i2c_client *client, struct gl520_data *data, long v = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); - data->temp_max[n - 1] = TEMP_TO_REG(v);; + data->temp_max[n - 1] = TEMP_TO_REG(v); gl520_write_value(client, reg, data->temp_max[n - 1]); mutex_unlock(&data->update_lock); return count; @@ -511,6 +486,59 @@ static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data, return count; } +static struct attribute *gl520_attributes[] = { + &dev_attr_cpu0_vid.attr, + + &dev_attr_in0_input.attr, + &dev_attr_in0_min.attr, + &dev_attr_in0_max.attr, + &dev_attr_in1_input.attr, + &dev_attr_in1_min.attr, + &dev_attr_in1_max.attr, + &dev_attr_in2_input.attr, + &dev_attr_in2_min.attr, + &dev_attr_in2_max.attr, + &dev_attr_in3_input.attr, + &dev_attr_in3_min.attr, + &dev_attr_in3_max.attr, + + &dev_attr_fan1_input.attr, + &dev_attr_fan1_min.attr, + &dev_attr_fan1_div.attr, + &dev_attr_fan1_off.attr, + &dev_attr_fan2_input.attr, + &dev_attr_fan2_min.attr, + &dev_attr_fan2_div.attr, + + &dev_attr_temp1_input.attr, + &dev_attr_temp1_max.attr, + &dev_attr_temp1_max_hyst.attr, + + &dev_attr_alarms.attr, + &dev_attr_beep_enable.attr, + &dev_attr_beep_mask.attr, + NULL +}; + +static const struct attribute_group gl520_group = { + .attrs = gl520_attributes, +}; + +static struct attribute *gl520_attributes_opt[] = { + &dev_attr_in4_input.attr, + &dev_attr_in4_min.attr, + &dev_attr_in4_max.attr, + + &dev_attr_temp2_input.attr, + &dev_attr_temp2_max.attr, + &dev_attr_temp2_max_hyst.attr, + NULL +}; + +static const struct attribute_group gl520_group_opt = { + .attrs = gl520_attributes_opt, +}; + /* * Real code @@ -572,33 +600,39 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) gl520_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, &gl520_group))) goto exit_detach; - } - - device_create_file_vid(new_client, 0); - - device_create_file_in(new_client, 0); - device_create_file_in(new_client, 1); - device_create_file_in(new_client, 2); - device_create_file_in(new_client, 3); - if (!data->two_temps) - device_create_file_in(new_client, 4); - device_create_file_fan(new_client, 1); - device_create_file_fan(new_client, 2); - device_create_file_fan_off(new_client, 1); + if (data->two_temps) { + if ((err = device_create_file(&new_client->dev, + &dev_attr_temp2_input)) + || (err = device_create_file(&new_client->dev, + &dev_attr_temp2_max)) + || (err = device_create_file(&new_client->dev, + &dev_attr_temp2_max_hyst))) + goto exit_remove_files; + } else { + if ((err = device_create_file(&new_client->dev, + &dev_attr_in4_input)) + || (err = device_create_file(&new_client->dev, + &dev_attr_in4_min)) + || (err = device_create_file(&new_client->dev, + &dev_attr_in4_max))) + goto exit_remove_files; + } - device_create_file_temp(new_client, 1); - if (data->two_temps) - device_create_file_temp(new_client, 2); - device_create_file_alarms(new_client); + data->hwmon_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->hwmon_dev)) { + err = PTR_ERR(data->hwmon_dev); + goto exit_remove_files; + } return 0; +exit_remove_files: + sysfs_remove_group(&new_client->dev.kobj, &gl520_group); + sysfs_remove_group(&new_client->dev.kobj, &gl520_group_opt); exit_detach: i2c_detach_client(new_client); exit_free: @@ -651,7 +685,9 @@ static int gl520_detach_client(struct i2c_client *client) struct gl520_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, &gl520_group); + sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); if ((err = i2c_detach_client(client))) return err; @@ -769,7 +805,7 @@ static void __exit sensors_gl520sm_exit(void) MODULE_AUTHOR("Frodo Looijaard , " - "Kyösti Mälkki , " + "Kyösti Mälkki , " "Maarten Deprez "); MODULE_DESCRIPTION("GL520SM driver"); MODULE_LICENSE("GPL");