diff options
Diffstat (limited to 'drivers/hwmon/gl520sm.c')
-rw-r--r-- | drivers/hwmon/gl520sm.c | 128 |
1 files changed, 82 insertions, 46 deletions
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c index 14e810f3c2c0..ebe7b9aaa916 100644 --- a/drivers/hwmon/gl520sm.c +++ b/drivers/hwmon/gl520sm.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/hwmon-vid.h> | 30 | #include <linux/hwmon-vid.h> |
31 | #include <linux/err.h> | 31 | #include <linux/err.h> |
32 | #include <linux/mutex.h> | 32 | #include <linux/mutex.h> |
33 | #include <linux/sysfs.h> | ||
33 | 34 | ||
34 | /* Type of the extra sensor */ | 35 | /* Type of the extra sensor */ |
35 | static unsigned short extra_sensor_type; | 36 | static unsigned short extra_sensor_type; |
@@ -190,55 +191,29 @@ static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL); | |||
190 | #define sysfs_vid(n) \ | 191 | #define sysfs_vid(n) \ |
191 | sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT) | 192 | sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT) |
192 | 193 | ||
193 | #define device_create_file_vid(client, n) \ | ||
194 | device_create_file(&client->dev, &dev_attr_cpu##n##_vid) | ||
195 | |||
196 | #define sysfs_in(n) \ | 194 | #define sysfs_in(n) \ |
197 | sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \ | 195 | sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \ |
198 | sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \ | 196 | sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \ |
199 | sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \ | 197 | sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \ |
200 | 198 | ||
201 | #define device_create_file_in(client, n) \ | ||
202 | ({device_create_file(&client->dev, &dev_attr_in##n##_input); \ | ||
203 | device_create_file(&client->dev, &dev_attr_in##n##_min); \ | ||
204 | device_create_file(&client->dev, &dev_attr_in##n##_max);}) | ||
205 | |||
206 | #define sysfs_fan(n) \ | 199 | #define sysfs_fan(n) \ |
207 | sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \ | 200 | sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \ |
208 | sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \ | 201 | sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \ |
209 | sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV) | 202 | sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV) |
210 | 203 | ||
211 | #define device_create_file_fan(client, n) \ | ||
212 | ({device_create_file(&client->dev, &dev_attr_fan##n##_input); \ | ||
213 | device_create_file(&client->dev, &dev_attr_fan##n##_min); \ | ||
214 | device_create_file(&client->dev, &dev_attr_fan##n##_div);}) | ||
215 | |||
216 | #define sysfs_fan_off(n) \ | 204 | #define sysfs_fan_off(n) \ |
217 | sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \ | 205 | sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \ |
218 | 206 | ||
219 | #define device_create_file_fan_off(client, n) \ | ||
220 | device_create_file(&client->dev, &dev_attr_fan##n##_off) | ||
221 | |||
222 | #define sysfs_temp(n) \ | 207 | #define sysfs_temp(n) \ |
223 | sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \ | 208 | sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \ |
224 | sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \ | 209 | sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \ |
225 | sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST) | 210 | sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST) |
226 | 211 | ||
227 | #define device_create_file_temp(client, n) \ | ||
228 | ({device_create_file(&client->dev, &dev_attr_temp##n##_input); \ | ||
229 | device_create_file(&client->dev, &dev_attr_temp##n##_max); \ | ||
230 | device_create_file(&client->dev, &dev_attr_temp##n##_max_hyst);}) | ||
231 | |||
232 | #define sysfs_alarms() \ | 212 | #define sysfs_alarms() \ |
233 | sysfs_ro(alarms, , GL520_REG_ALARMS) \ | 213 | sysfs_ro(alarms, , GL520_REG_ALARMS) \ |
234 | sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \ | 214 | sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \ |
235 | sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK) | 215 | sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK) |
236 | 216 | ||
237 | #define device_create_file_alarms(client) \ | ||
238 | ({device_create_file(&client->dev, &dev_attr_alarms); \ | ||
239 | device_create_file(&client->dev, &dev_attr_beep_enable); \ | ||
240 | device_create_file(&client->dev, &dev_attr_beep_mask);}) | ||
241 | |||
242 | 217 | ||
243 | sysfs_vid(0) | 218 | sysfs_vid(0) |
244 | 219 | ||
@@ -511,6 +486,59 @@ static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data, | |||
511 | return count; | 486 | return count; |
512 | } | 487 | } |
513 | 488 | ||
489 | static struct attribute *gl520_attributes[] = { | ||
490 | &dev_attr_cpu0_vid.attr, | ||
491 | |||
492 | &dev_attr_in0_input.attr, | ||
493 | &dev_attr_in0_min.attr, | ||
494 | &dev_attr_in0_max.attr, | ||
495 | &dev_attr_in1_input.attr, | ||
496 | &dev_attr_in1_min.attr, | ||
497 | &dev_attr_in1_max.attr, | ||
498 | &dev_attr_in2_input.attr, | ||
499 | &dev_attr_in2_min.attr, | ||
500 | &dev_attr_in2_max.attr, | ||
501 | &dev_attr_in3_input.attr, | ||
502 | &dev_attr_in3_min.attr, | ||
503 | &dev_attr_in3_max.attr, | ||
504 | |||
505 | &dev_attr_fan1_input.attr, | ||
506 | &dev_attr_fan1_min.attr, | ||
507 | &dev_attr_fan1_div.attr, | ||
508 | &dev_attr_fan1_off.attr, | ||
509 | &dev_attr_fan2_input.attr, | ||
510 | &dev_attr_fan2_min.attr, | ||
511 | &dev_attr_fan2_div.attr, | ||
512 | |||
513 | &dev_attr_temp1_input.attr, | ||
514 | &dev_attr_temp1_max.attr, | ||
515 | &dev_attr_temp1_max_hyst.attr, | ||
516 | |||
517 | &dev_attr_alarms.attr, | ||
518 | &dev_attr_beep_enable.attr, | ||
519 | &dev_attr_beep_mask.attr, | ||
520 | NULL | ||
521 | }; | ||
522 | |||
523 | static const struct attribute_group gl520_group = { | ||
524 | .attrs = gl520_attributes, | ||
525 | }; | ||
526 | |||
527 | static struct attribute *gl520_attributes_opt[] = { | ||
528 | &dev_attr_in4_input.attr, | ||
529 | &dev_attr_in4_min.attr, | ||
530 | &dev_attr_in4_max.attr, | ||
531 | |||
532 | &dev_attr_temp2_input.attr, | ||
533 | &dev_attr_temp2_max.attr, | ||
534 | &dev_attr_temp2_max_hyst.attr, | ||
535 | NULL | ||
536 | }; | ||
537 | |||
538 | static const struct attribute_group gl520_group_opt = { | ||
539 | .attrs = gl520_attributes_opt, | ||
540 | }; | ||
541 | |||
514 | 542 | ||
515 | /* | 543 | /* |
516 | * Real code | 544 | * Real code |
@@ -572,33 +600,39 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind) | |||
572 | gl520_init_client(new_client); | 600 | gl520_init_client(new_client); |
573 | 601 | ||
574 | /* Register sysfs hooks */ | 602 | /* Register sysfs hooks */ |
575 | data->class_dev = hwmon_device_register(&new_client->dev); | 603 | if ((err = sysfs_create_group(&new_client->dev.kobj, &gl520_group))) |
576 | if (IS_ERR(data->class_dev)) { | ||
577 | err = PTR_ERR(data->class_dev); | ||
578 | goto exit_detach; | 604 | goto exit_detach; |
579 | } | ||
580 | |||
581 | device_create_file_vid(new_client, 0); | ||
582 | 605 | ||
583 | device_create_file_in(new_client, 0); | 606 | if (data->two_temps) { |
584 | device_create_file_in(new_client, 1); | 607 | if ((err = device_create_file(&new_client->dev, |
585 | device_create_file_in(new_client, 2); | 608 | &dev_attr_temp2_input)) |
586 | device_create_file_in(new_client, 3); | 609 | || (err = device_create_file(&new_client->dev, |
587 | if (!data->two_temps) | 610 | &dev_attr_temp2_max)) |
588 | device_create_file_in(new_client, 4); | 611 | || (err = device_create_file(&new_client->dev, |
589 | 612 | &dev_attr_temp2_max_hyst))) | |
590 | device_create_file_fan(new_client, 1); | 613 | goto exit_remove_files; |
591 | device_create_file_fan(new_client, 2); | 614 | } else { |
592 | device_create_file_fan_off(new_client, 1); | 615 | if ((err = device_create_file(&new_client->dev, |
616 | &dev_attr_in4_input)) | ||
617 | || (err = device_create_file(&new_client->dev, | ||
618 | &dev_attr_in4_min)) | ||
619 | || (err = device_create_file(&new_client->dev, | ||
620 | &dev_attr_in4_max))) | ||
621 | goto exit_remove_files; | ||
622 | } | ||
593 | 623 | ||
594 | device_create_file_temp(new_client, 1); | ||
595 | if (data->two_temps) | ||
596 | device_create_file_temp(new_client, 2); | ||
597 | 624 | ||
598 | device_create_file_alarms(new_client); | 625 | data->class_dev = hwmon_device_register(&new_client->dev); |
626 | if (IS_ERR(data->class_dev)) { | ||
627 | err = PTR_ERR(data->class_dev); | ||
628 | goto exit_remove_files; | ||
629 | } | ||
599 | 630 | ||
600 | return 0; | 631 | return 0; |
601 | 632 | ||
633 | exit_remove_files: | ||
634 | sysfs_remove_group(&new_client->dev.kobj, &gl520_group); | ||
635 | sysfs_remove_group(&new_client->dev.kobj, &gl520_group_opt); | ||
602 | exit_detach: | 636 | exit_detach: |
603 | i2c_detach_client(new_client); | 637 | i2c_detach_client(new_client); |
604 | exit_free: | 638 | exit_free: |
@@ -652,6 +686,8 @@ static int gl520_detach_client(struct i2c_client *client) | |||
652 | int err; | 686 | int err; |
653 | 687 | ||
654 | hwmon_device_unregister(data->class_dev); | 688 | hwmon_device_unregister(data->class_dev); |
689 | sysfs_remove_group(&client->dev.kobj, &gl520_group); | ||
690 | sysfs_remove_group(&client->dev.kobj, &gl520_group_opt); | ||
655 | 691 | ||
656 | if ((err = i2c_detach_client(client))) | 692 | if ((err = i2c_detach_client(client))) |
657 | return err; | 693 | return err; |