aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/hwmon/asb100.c122
-rw-r--r--drivers/hwmon/lm75.c24
-rw-r--r--drivers/hwmon/lm78.c88
-rw-r--r--drivers/hwmon/smsc47b397.c39
-rw-r--r--drivers/hwmon/w83627hf.c232
5 files changed, 299 insertions, 206 deletions
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index facc1ccb8338..57b1c7b7ac3f 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -298,12 +298,6 @@ sysfs_in(4);
298sysfs_in(5); 298sysfs_in(5);
299sysfs_in(6); 299sysfs_in(6);
300 300
301#define device_create_file_in(client, offset) do { \
302 device_create_file(&client->dev, &dev_attr_in##offset##_input); \
303 device_create_file(&client->dev, &dev_attr_in##offset##_min); \
304 device_create_file(&client->dev, &dev_attr_in##offset##_max); \
305} while (0)
306
307/* 3 Fans */ 301/* 3 Fans */
308static ssize_t show_fan(struct device *dev, char *buf, int nr) 302static ssize_t show_fan(struct device *dev, char *buf, int nr)
309{ 303{
@@ -421,12 +415,6 @@ sysfs_fan(1);
421sysfs_fan(2); 415sysfs_fan(2);
422sysfs_fan(3); 416sysfs_fan(3);
423 417
424#define device_create_file_fan(client, offset) do { \
425 device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
426 device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
427 device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
428} while (0)
429
430/* 4 Temp. Sensors */ 418/* 4 Temp. Sensors */
431static int sprintf_temp_from_reg(u16 reg, char *buf, int nr) 419static int sprintf_temp_from_reg(u16 reg, char *buf, int nr)
432{ 420{
@@ -515,12 +503,6 @@ sysfs_temp(3);
515sysfs_temp(4); 503sysfs_temp(4);
516 504
517/* VID */ 505/* VID */
518#define device_create_file_temp(client, num) do { \
519 device_create_file(&client->dev, &dev_attr_temp##num##_input); \
520 device_create_file(&client->dev, &dev_attr_temp##num##_max); \
521 device_create_file(&client->dev, &dev_attr_temp##num##_max_hyst); \
522} while (0)
523
524static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 506static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
525{ 507{
526 struct asb100_data *data = asb100_update_device(dev); 508 struct asb100_data *data = asb100_update_device(dev);
@@ -528,8 +510,6 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char
528} 510}
529 511
530static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 512static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
531#define device_create_file_vid(client) \
532device_create_file(&client->dev, &dev_attr_cpu0_vid)
533 513
534/* VRM */ 514/* VRM */
535static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 515static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
@@ -549,8 +529,6 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const
549 529
550/* Alarms */ 530/* Alarms */
551static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 531static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
552#define device_create_file_vrm(client) \
553device_create_file(&client->dev, &dev_attr_vrm);
554 532
555static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 533static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
556{ 534{
@@ -559,8 +537,6 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
559} 537}
560 538
561static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 539static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
562#define device_create_file_alarms(client) \
563device_create_file(&client->dev, &dev_attr_alarms)
564 540
565/* 1 PWM */ 541/* 1 PWM */
566static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, char *buf) 542static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, char *buf)
@@ -607,10 +583,65 @@ static ssize_t set_pwm_enable1(struct device *dev, struct device_attribute *attr
607static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1); 583static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1);
608static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, 584static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
609 show_pwm_enable1, set_pwm_enable1); 585 show_pwm_enable1, set_pwm_enable1);
610#define device_create_file_pwm1(client) do { \ 586
611 device_create_file(&new_client->dev, &dev_attr_pwm1); \ 587static struct attribute *asb100_attributes[] = {
612 device_create_file(&new_client->dev, &dev_attr_pwm1_enable); \ 588 &dev_attr_in0_input.attr,
613} while (0) 589 &dev_attr_in0_min.attr,
590 &dev_attr_in0_max.attr,
591 &dev_attr_in1_input.attr,
592 &dev_attr_in1_min.attr,
593 &dev_attr_in1_max.attr,
594 &dev_attr_in2_input.attr,
595 &dev_attr_in2_min.attr,
596 &dev_attr_in2_max.attr,
597 &dev_attr_in3_input.attr,
598 &dev_attr_in3_min.attr,
599 &dev_attr_in3_max.attr,
600 &dev_attr_in4_input.attr,
601 &dev_attr_in4_min.attr,
602 &dev_attr_in4_max.attr,
603 &dev_attr_in5_input.attr,
604 &dev_attr_in5_min.attr,
605 &dev_attr_in5_max.attr,
606 &dev_attr_in6_input.attr,
607 &dev_attr_in6_min.attr,
608 &dev_attr_in6_max.attr,
609
610 &dev_attr_fan1_input.attr,
611 &dev_attr_fan1_min.attr,
612 &dev_attr_fan1_div.attr,
613 &dev_attr_fan2_input.attr,
614 &dev_attr_fan2_min.attr,
615 &dev_attr_fan2_div.attr,
616 &dev_attr_fan3_input.attr,
617 &dev_attr_fan3_min.attr,
618 &dev_attr_fan3_div.attr,
619
620 &dev_attr_temp1_input.attr,
621 &dev_attr_temp1_max.attr,
622 &dev_attr_temp1_max_hyst.attr,
623 &dev_attr_temp2_input.attr,
624 &dev_attr_temp2_max.attr,
625 &dev_attr_temp2_max_hyst.attr,
626 &dev_attr_temp3_input.attr,
627 &dev_attr_temp3_max.attr,
628 &dev_attr_temp3_max_hyst.attr,
629 &dev_attr_temp4_input.attr,
630 &dev_attr_temp4_max.attr,
631 &dev_attr_temp4_max_hyst.attr,
632
633 &dev_attr_cpu0_vid.attr,
634 &dev_attr_vrm.attr,
635 &dev_attr_alarms.attr,
636 &dev_attr_pwm1.attr,
637 &dev_attr_pwm1_enable.attr,
638
639 NULL
640};
641
642static const struct attribute_group asb100_group = {
643 .attrs = asb100_attributes,
644};
614 645
615/* This function is called when: 646/* This function is called when:
616 asb100_driver is inserted (when this module is loaded), for each 647 asb100_driver is inserted (when this module is loaded), for each
@@ -810,38 +841,19 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
810 data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2)); 841 data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2));
811 842
812 /* Register sysfs hooks */ 843 /* Register sysfs hooks */
844 if ((err = sysfs_create_group(&new_client->dev.kobj, &asb100_group)))
845 goto ERROR3;
846
813 data->class_dev = hwmon_device_register(&new_client->dev); 847 data->class_dev = hwmon_device_register(&new_client->dev);
814 if (IS_ERR(data->class_dev)) { 848 if (IS_ERR(data->class_dev)) {
815 err = PTR_ERR(data->class_dev); 849 err = PTR_ERR(data->class_dev);
816 goto ERROR3; 850 goto ERROR4;
817 } 851 }
818 852
819 device_create_file_in(new_client, 0);
820 device_create_file_in(new_client, 1);
821 device_create_file_in(new_client, 2);
822 device_create_file_in(new_client, 3);
823 device_create_file_in(new_client, 4);
824 device_create_file_in(new_client, 5);
825 device_create_file_in(new_client, 6);
826
827 device_create_file_fan(new_client, 1);
828 device_create_file_fan(new_client, 2);
829 device_create_file_fan(new_client, 3);
830
831 device_create_file_temp(new_client, 1);
832 device_create_file_temp(new_client, 2);
833 device_create_file_temp(new_client, 3);
834 device_create_file_temp(new_client, 4);
835
836 device_create_file_vid(new_client);
837 device_create_file_vrm(new_client);
838
839 device_create_file_alarms(new_client);
840
841 device_create_file_pwm1(new_client);
842
843 return 0; 853 return 0;
844 854
855ERROR4:
856 sysfs_remove_group(&new_client->dev.kobj, &asb100_group);
845ERROR3: 857ERROR3:
846 i2c_detach_client(data->lm75[1]); 858 i2c_detach_client(data->lm75[1]);
847 i2c_detach_client(data->lm75[0]); 859 i2c_detach_client(data->lm75[0]);
@@ -861,8 +873,10 @@ static int asb100_detach_client(struct i2c_client *client)
861 int err; 873 int err;
862 874
863 /* main client */ 875 /* main client */
864 if (data) 876 if (data) {
865 hwmon_device_unregister(data->class_dev); 877 hwmon_device_unregister(data->class_dev);
878 sysfs_remove_group(&client->dev.kobj, &asb100_group);
879 }
866 880
867 if ((err = i2c_detach_client(client))) 881 if ((err = i2c_detach_client(client)))
868 return err; 882 return err;
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index fc25b90ec24a..7c65b8bb6d72 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -112,6 +112,18 @@ static int lm75_attach_adapter(struct i2c_adapter *adapter)
112 return i2c_probe(adapter, &addr_data, lm75_detect); 112 return i2c_probe(adapter, &addr_data, lm75_detect);
113} 113}
114 114
115static struct attribute *lm75_attributes[] = {
116 &dev_attr_temp1_input.attr,
117 &dev_attr_temp1_max.attr,
118 &dev_attr_temp1_max_hyst.attr,
119
120 NULL
121};
122
123static const struct attribute_group lm75_group = {
124 .attrs = lm75_attributes,
125};
126
115/* This function is called by i2c_probe */ 127/* This function is called by i2c_probe */
116static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) 128static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
117{ 129{
@@ -199,18 +211,19 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
199 lm75_init_client(new_client); 211 lm75_init_client(new_client);
200 212
201 /* Register sysfs hooks */ 213 /* Register sysfs hooks */
214 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm75_group)))
215 goto exit_detach;
216
202 data->class_dev = hwmon_device_register(&new_client->dev); 217 data->class_dev = hwmon_device_register(&new_client->dev);
203 if (IS_ERR(data->class_dev)) { 218 if (IS_ERR(data->class_dev)) {
204 err = PTR_ERR(data->class_dev); 219 err = PTR_ERR(data->class_dev);
205 goto exit_detach; 220 goto exit_remove;
206 } 221 }
207 222
208 device_create_file(&new_client->dev, &dev_attr_temp1_max);
209 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
210 device_create_file(&new_client->dev, &dev_attr_temp1_input);
211
212 return 0; 223 return 0;
213 224
225exit_remove:
226 sysfs_remove_group(&new_client->dev.kobj, &lm75_group);
214exit_detach: 227exit_detach:
215 i2c_detach_client(new_client); 228 i2c_detach_client(new_client);
216exit_free: 229exit_free:
@@ -223,6 +236,7 @@ static int lm75_detach_client(struct i2c_client *client)
223{ 236{
224 struct lm75_data *data = i2c_get_clientdata(client); 237 struct lm75_data *data = i2c_get_clientdata(client);
225 hwmon_device_unregister(data->class_dev); 238 hwmon_device_unregister(data->class_dev);
239 sysfs_remove_group(&client->dev.kobj, &lm75_group);
226 i2c_detach_client(client); 240 i2c_detach_client(client);
227 kfree(data); 241 kfree(data);
228 return 0; 242 return 0;
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index fa1715b9a996..ac1b746df6d0 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -482,6 +482,50 @@ static int lm78_isa_attach_adapter(struct i2c_adapter *adapter)
482 return lm78_detect(adapter, isa_address, -1); 482 return lm78_detect(adapter, isa_address, -1);
483} 483}
484 484
485static struct attribute *lm78_attributes[] = {
486 &dev_attr_in0_input.attr,
487 &dev_attr_in0_min.attr,
488 &dev_attr_in0_max.attr,
489 &dev_attr_in1_input.attr,
490 &dev_attr_in1_min.attr,
491 &dev_attr_in1_max.attr,
492 &dev_attr_in2_input.attr,
493 &dev_attr_in2_min.attr,
494 &dev_attr_in2_max.attr,
495 &dev_attr_in3_input.attr,
496 &dev_attr_in3_min.attr,
497 &dev_attr_in3_max.attr,
498 &dev_attr_in4_input.attr,
499 &dev_attr_in4_min.attr,
500 &dev_attr_in4_max.attr,
501 &dev_attr_in5_input.attr,
502 &dev_attr_in5_min.attr,
503 &dev_attr_in5_max.attr,
504 &dev_attr_in6_input.attr,
505 &dev_attr_in6_min.attr,
506 &dev_attr_in6_max.attr,
507 &dev_attr_temp1_input.attr,
508 &dev_attr_temp1_max.attr,
509 &dev_attr_temp1_max_hyst.attr,
510 &dev_attr_fan1_input.attr,
511 &dev_attr_fan1_min.attr,
512 &dev_attr_fan1_div.attr,
513 &dev_attr_fan2_input.attr,
514 &dev_attr_fan2_min.attr,
515 &dev_attr_fan2_div.attr,
516 &dev_attr_fan3_input.attr,
517 &dev_attr_fan3_min.attr,
518 &dev_attr_fan3_div.attr,
519 &dev_attr_alarms.attr,
520 &dev_attr_cpu0_vid.attr,
521
522 NULL
523};
524
525static const struct attribute_group lm78_group = {
526 .attrs = lm78_attributes,
527};
528
485/* This function is called by i2c_probe */ 529/* This function is called by i2c_probe */
486static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) 530static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
487{ 531{
@@ -616,50 +660,19 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
616 } 660 }
617 661
618 /* Register sysfs hooks */ 662 /* Register sysfs hooks */
663 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm78_group)))
664 goto ERROR3;
665
619 data->class_dev = hwmon_device_register(&new_client->dev); 666 data->class_dev = hwmon_device_register(&new_client->dev);
620 if (IS_ERR(data->class_dev)) { 667 if (IS_ERR(data->class_dev)) {
621 err = PTR_ERR(data->class_dev); 668 err = PTR_ERR(data->class_dev);
622 goto ERROR3; 669 goto ERROR4;
623 } 670 }
624 671
625 device_create_file(&new_client->dev, &dev_attr_in0_input);
626 device_create_file(&new_client->dev, &dev_attr_in0_min);
627 device_create_file(&new_client->dev, &dev_attr_in0_max);
628 device_create_file(&new_client->dev, &dev_attr_in1_input);
629 device_create_file(&new_client->dev, &dev_attr_in1_min);
630 device_create_file(&new_client->dev, &dev_attr_in1_max);
631 device_create_file(&new_client->dev, &dev_attr_in2_input);
632 device_create_file(&new_client->dev, &dev_attr_in2_min);
633 device_create_file(&new_client->dev, &dev_attr_in2_max);
634 device_create_file(&new_client->dev, &dev_attr_in3_input);
635 device_create_file(&new_client->dev, &dev_attr_in3_min);
636 device_create_file(&new_client->dev, &dev_attr_in3_max);
637 device_create_file(&new_client->dev, &dev_attr_in4_input);
638 device_create_file(&new_client->dev, &dev_attr_in4_min);
639 device_create_file(&new_client->dev, &dev_attr_in4_max);
640 device_create_file(&new_client->dev, &dev_attr_in5_input);
641 device_create_file(&new_client->dev, &dev_attr_in5_min);
642 device_create_file(&new_client->dev, &dev_attr_in5_max);
643 device_create_file(&new_client->dev, &dev_attr_in6_input);
644 device_create_file(&new_client->dev, &dev_attr_in6_min);
645 device_create_file(&new_client->dev, &dev_attr_in6_max);
646 device_create_file(&new_client->dev, &dev_attr_temp1_input);
647 device_create_file(&new_client->dev, &dev_attr_temp1_max);
648 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
649 device_create_file(&new_client->dev, &dev_attr_fan1_input);
650 device_create_file(&new_client->dev, &dev_attr_fan1_min);
651 device_create_file(&new_client->dev, &dev_attr_fan1_div);
652 device_create_file(&new_client->dev, &dev_attr_fan2_input);
653 device_create_file(&new_client->dev, &dev_attr_fan2_min);
654 device_create_file(&new_client->dev, &dev_attr_fan2_div);
655 device_create_file(&new_client->dev, &dev_attr_fan3_input);
656 device_create_file(&new_client->dev, &dev_attr_fan3_min);
657 device_create_file(&new_client->dev, &dev_attr_fan3_div);
658 device_create_file(&new_client->dev, &dev_attr_alarms);
659 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
660
661 return 0; 672 return 0;
662 673
674ERROR4:
675 sysfs_remove_group(&new_client->dev.kobj, &lm78_group);
663ERROR3: 676ERROR3:
664 i2c_detach_client(new_client); 677 i2c_detach_client(new_client);
665ERROR2: 678ERROR2:
@@ -677,6 +690,7 @@ static int lm78_detach_client(struct i2c_client *client)
677 int err; 690 int err;
678 691
679 hwmon_device_unregister(data->class_dev); 692 hwmon_device_unregister(data->class_dev);
693 sysfs_remove_group(&client->dev.kobj, &lm78_group);
680 694
681 if ((err = i2c_detach_client(client))) 695 if ((err = i2c_detach_client(client)))
682 return err; 696 return err;
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index a85869393bab..72b0e2d8650c 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -176,9 +176,6 @@ sysfs_temp(2);
176sysfs_temp(3); 176sysfs_temp(3);
177sysfs_temp(4); 177sysfs_temp(4);
178 178
179#define device_create_file_temp(client, num) \
180 device_create_file(&client->dev, &dev_attr_temp##num##_input)
181
182/* FAN: 1 RPM/bit 179/* FAN: 1 RPM/bit
183 REG: count of 90kHz pulses / revolution */ 180 REG: count of 90kHz pulses / revolution */
184static int fan_from_reg(u16 reg) 181static int fan_from_reg(u16 reg)
@@ -205,8 +202,22 @@ sysfs_fan(2);
205sysfs_fan(3); 202sysfs_fan(3);
206sysfs_fan(4); 203sysfs_fan(4);
207 204
208#define device_create_file_fan(client, num) \ 205static struct attribute *smsc47b397_attributes[] = {
209 device_create_file(&client->dev, &dev_attr_fan##num##_input) 206 &dev_attr_temp1_input.attr,
207 &dev_attr_temp2_input.attr,
208 &dev_attr_temp3_input.attr,
209 &dev_attr_temp4_input.attr,
210 &dev_attr_fan1_input.attr,
211 &dev_attr_fan2_input.attr,
212 &dev_attr_fan3_input.attr,
213 &dev_attr_fan4_input.attr,
214
215 NULL
216};
217
218static const struct attribute_group smsc47b397_group = {
219 .attrs = smsc47b397_attributes,
220};
210 221
211static int smsc47b397_detach_client(struct i2c_client *client) 222static int smsc47b397_detach_client(struct i2c_client *client)
212{ 223{
@@ -214,6 +225,7 @@ static int smsc47b397_detach_client(struct i2c_client *client)
214 int err; 225 int err;
215 226
216 hwmon_device_unregister(data->class_dev); 227 hwmon_device_unregister(data->class_dev);
228 sysfs_remove_group(&client->dev.kobj, &smsc47b397_group);
217 229
218 if ((err = i2c_detach_client(client))) 230 if ((err = i2c_detach_client(client)))
219 return err; 231 return err;
@@ -268,24 +280,19 @@ static int smsc47b397_detect(struct i2c_adapter *adapter)
268 if ((err = i2c_attach_client(new_client))) 280 if ((err = i2c_attach_client(new_client)))
269 goto error_free; 281 goto error_free;
270 282
283 if ((err = sysfs_create_group(&new_client->dev.kobj, &smsc47b397_group)))
284 goto error_detach;
285
271 data->class_dev = hwmon_device_register(&new_client->dev); 286 data->class_dev = hwmon_device_register(&new_client->dev);
272 if (IS_ERR(data->class_dev)) { 287 if (IS_ERR(data->class_dev)) {
273 err = PTR_ERR(data->class_dev); 288 err = PTR_ERR(data->class_dev);
274 goto error_detach; 289 goto error_remove;
275 } 290 }
276 291
277 device_create_file_temp(new_client, 1);
278 device_create_file_temp(new_client, 2);
279 device_create_file_temp(new_client, 3);
280 device_create_file_temp(new_client, 4);
281
282 device_create_file_fan(new_client, 1);
283 device_create_file_fan(new_client, 2);
284 device_create_file_fan(new_client, 3);
285 device_create_file_fan(new_client, 4);
286
287 return 0; 292 return 0;
288 293
294error_remove:
295 sysfs_remove_group(&new_client->dev.kobj, &smsc47b397_group);
289error_detach: 296error_detach:
290 i2c_detach_client(new_client); 297 i2c_detach_client(new_client);
291error_free: 298error_free:
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 30295028ea99..dfdc29c77123 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -512,13 +512,6 @@ static DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR,
512static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR, 512static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR,
513 show_regs_in_max0, store_regs_in_max0); 513 show_regs_in_max0, store_regs_in_max0);
514 514
515#define device_create_file_in(client, offset) \
516do { \
517device_create_file(&client->dev, &dev_attr_in##offset##_input); \
518device_create_file(&client->dev, &dev_attr_in##offset##_min); \
519device_create_file(&client->dev, &dev_attr_in##offset##_max); \
520} while (0)
521
522#define show_fan_reg(reg) \ 515#define show_fan_reg(reg) \
523static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 516static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
524{ \ 517{ \
@@ -576,12 +569,6 @@ sysfs_fan_min_offset(2);
576sysfs_fan_offset(3); 569sysfs_fan_offset(3);
577sysfs_fan_min_offset(3); 570sysfs_fan_min_offset(3);
578 571
579#define device_create_file_fan(client, offset) \
580do { \
581device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
582device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
583} while (0)
584
585#define show_temp_reg(reg) \ 572#define show_temp_reg(reg) \
586static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 573static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
587{ \ 574{ \
@@ -656,13 +643,6 @@ sysfs_temp_offsets(1);
656sysfs_temp_offsets(2); 643sysfs_temp_offsets(2);
657sysfs_temp_offsets(3); 644sysfs_temp_offsets(3);
658 645
659#define device_create_file_temp(client, offset) \
660do { \
661device_create_file(&client->dev, &dev_attr_temp##offset##_input); \
662device_create_file(&client->dev, &dev_attr_temp##offset##_max); \
663device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \
664} while (0)
665
666static ssize_t 646static ssize_t
667show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 647show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
668{ 648{
@@ -670,8 +650,6 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
670 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 650 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
671} 651}
672static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 652static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
673#define device_create_file_vid(client) \
674device_create_file(&client->dev, &dev_attr_cpu0_vid)
675 653
676static ssize_t 654static ssize_t
677show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 655show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -692,8 +670,6 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf
692 return count; 670 return count;
693} 671}
694static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 672static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
695#define device_create_file_vrm(client) \
696device_create_file(&client->dev, &dev_attr_vrm)
697 673
698static ssize_t 674static ssize_t
699show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 675show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -702,8 +678,6 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
702 return sprintf(buf, "%ld\n", (long) data->alarms); 678 return sprintf(buf, "%ld\n", (long) data->alarms);
703} 679}
704static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 680static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
705#define device_create_file_alarms(client) \
706device_create_file(&client->dev, &dev_attr_alarms)
707 681
708#define show_beep_reg(REG, reg) \ 682#define show_beep_reg(REG, reg) \
709static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ 683static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \
@@ -766,12 +740,6 @@ static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, \
766sysfs_beep(ENABLE, enable); 740sysfs_beep(ENABLE, enable);
767sysfs_beep(MASK, mask); 741sysfs_beep(MASK, mask);
768 742
769#define device_create_file_beep(client) \
770do { \
771device_create_file(&client->dev, &dev_attr_beep_enable); \
772device_create_file(&client->dev, &dev_attr_beep_mask); \
773} while (0)
774
775static ssize_t 743static ssize_t
776show_fan_div_reg(struct device *dev, char *buf, int nr) 744show_fan_div_reg(struct device *dev, char *buf, int nr)
777{ 745{
@@ -837,11 +805,6 @@ sysfs_fan_div(1);
837sysfs_fan_div(2); 805sysfs_fan_div(2);
838sysfs_fan_div(3); 806sysfs_fan_div(3);
839 807
840#define device_create_file_fan_div(client, offset) \
841do { \
842device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
843} while (0)
844
845static ssize_t 808static ssize_t
846show_pwm_reg(struct device *dev, char *buf, int nr) 809show_pwm_reg(struct device *dev, char *buf, int nr)
847{ 810{
@@ -896,11 +859,6 @@ sysfs_pwm(1);
896sysfs_pwm(2); 859sysfs_pwm(2);
897sysfs_pwm(3); 860sysfs_pwm(3);
898 861
899#define device_create_file_pwm(client, offset) \
900do { \
901device_create_file(&client->dev, &dev_attr_pwm##offset); \
902} while (0)
903
904static ssize_t 862static ssize_t
905show_sensor_reg(struct device *dev, char *buf, int nr) 863show_sensor_reg(struct device *dev, char *buf, int nr)
906{ 864{
@@ -972,12 +930,6 @@ sysfs_sensor(1);
972sysfs_sensor(2); 930sysfs_sensor(2);
973sysfs_sensor(3); 931sysfs_sensor(3);
974 932
975#define device_create_file_sensor(client, offset) \
976do { \
977device_create_file(&client->dev, &dev_attr_temp##offset##_type); \
978} while (0)
979
980
981static int __init w83627hf_find(int sioaddr, unsigned short *addr) 933static int __init w83627hf_find(int sioaddr, unsigned short *addr)
982{ 934{
983 u16 val; 935 u16 val;
@@ -1009,6 +961,85 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr)
1009 return 0; 961 return 0;
1010} 962}
1011 963
964static struct attribute *w83627hf_attributes[] = {
965 &dev_attr_in0_input.attr,
966 &dev_attr_in0_min.attr,
967 &dev_attr_in0_max.attr,
968 &dev_attr_in2_input.attr,
969 &dev_attr_in2_min.attr,
970 &dev_attr_in2_max.attr,
971 &dev_attr_in3_input.attr,
972 &dev_attr_in3_min.attr,
973 &dev_attr_in3_max.attr,
974 &dev_attr_in4_input.attr,
975 &dev_attr_in4_min.attr,
976 &dev_attr_in4_max.attr,
977 &dev_attr_in7_input.attr,
978 &dev_attr_in7_min.attr,
979 &dev_attr_in7_max.attr,
980 &dev_attr_in8_input.attr,
981 &dev_attr_in8_min.attr,
982 &dev_attr_in8_max.attr,
983
984 &dev_attr_fan1_input.attr,
985 &dev_attr_fan1_min.attr,
986 &dev_attr_fan1_div.attr,
987 &dev_attr_fan2_input.attr,
988 &dev_attr_fan2_min.attr,
989 &dev_attr_fan2_div.attr,
990
991 &dev_attr_temp1_input.attr,
992 &dev_attr_temp1_max.attr,
993 &dev_attr_temp1_max_hyst.attr,
994 &dev_attr_temp1_type.attr,
995 &dev_attr_temp2_input.attr,
996 &dev_attr_temp2_max.attr,
997 &dev_attr_temp2_max_hyst.attr,
998 &dev_attr_temp2_type.attr,
999
1000 &dev_attr_alarms.attr,
1001 &dev_attr_beep_enable.attr,
1002 &dev_attr_beep_mask.attr,
1003
1004 &dev_attr_pwm1.attr,
1005 &dev_attr_pwm2.attr,
1006
1007 NULL
1008};
1009
1010static const struct attribute_group w83627hf_group = {
1011 .attrs = w83627hf_attributes,
1012};
1013
1014static struct attribute *w83627hf_attributes_opt[] = {
1015 &dev_attr_in1_input.attr,
1016 &dev_attr_in1_min.attr,
1017 &dev_attr_in1_max.attr,
1018 &dev_attr_in5_input.attr,
1019 &dev_attr_in5_min.attr,
1020 &dev_attr_in5_max.attr,
1021 &dev_attr_in6_input.attr,
1022 &dev_attr_in6_min.attr,
1023 &dev_attr_in6_max.attr,
1024
1025 &dev_attr_fan3_input.attr,
1026 &dev_attr_fan3_min.attr,
1027 &dev_attr_fan3_div.attr,
1028
1029 &dev_attr_temp3_input.attr,
1030 &dev_attr_temp3_max.attr,
1031 &dev_attr_temp3_max_hyst.attr,
1032 &dev_attr_temp3_type.attr,
1033
1034 &dev_attr_pwm3.attr,
1035
1036 NULL
1037};
1038
1039static const struct attribute_group w83627hf_group_opt = {
1040 .attrs = w83627hf_attributes_opt,
1041};
1042
1012static int w83627hf_detect(struct i2c_adapter *adapter) 1043static int w83627hf_detect(struct i2c_adapter *adapter)
1013{ 1044{
1014 int val, kind; 1045 int val, kind;
@@ -1108,62 +1139,72 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1108 data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2)); 1139 data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2));
1109 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); 1140 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3));
1110 1141
1111 /* Register sysfs hooks */ 1142 /* Register common device attributes */
1112 data->class_dev = hwmon_device_register(&new_client->dev); 1143 if ((err = sysfs_create_group(&new_client->dev.kobj, &w83627hf_group)))
1113 if (IS_ERR(data->class_dev)) {
1114 err = PTR_ERR(data->class_dev);
1115 goto ERROR3; 1144 goto ERROR3;
1116 }
1117
1118 device_create_file_in(new_client, 0);
1119 if (kind != w83697hf)
1120 device_create_file_in(new_client, 1);
1121 device_create_file_in(new_client, 2);
1122 device_create_file_in(new_client, 3);
1123 device_create_file_in(new_client, 4);
1124 if (kind == w83627hf || kind == w83697hf) {
1125 device_create_file_in(new_client, 5);
1126 device_create_file_in(new_client, 6);
1127 }
1128 device_create_file_in(new_client, 7);
1129 device_create_file_in(new_client, 8);
1130
1131 device_create_file_fan(new_client, 1);
1132 device_create_file_fan(new_client, 2);
1133 if (kind != w83697hf)
1134 device_create_file_fan(new_client, 3);
1135
1136 device_create_file_temp(new_client, 1);
1137 device_create_file_temp(new_client, 2);
1138 if (kind != w83697hf)
1139 device_create_file_temp(new_client, 3);
1140 1145
1141 if (kind != w83697hf && data->vid != 0xff) { 1146 /* Register chip-specific device attributes */
1142 device_create_file_vid(new_client); 1147 if (kind == w83627hf || kind == w83697hf)
1143 device_create_file_vrm(new_client); 1148 if ((err = device_create_file(&new_client->dev,
1144 } 1149 &dev_attr_in5_input))
1150 || (err = device_create_file(&new_client->dev,
1151 &dev_attr_in5_min))
1152 || (err = device_create_file(&new_client->dev,
1153 &dev_attr_in5_max))
1154 || (err = device_create_file(&new_client->dev,
1155 &dev_attr_in6_input))
1156 || (err = device_create_file(&new_client->dev,
1157 &dev_attr_in6_min))
1158 || (err = device_create_file(&new_client->dev,
1159 &dev_attr_in6_max)))
1160 goto ERROR4;
1145 1161
1146 device_create_file_fan_div(new_client, 1);
1147 device_create_file_fan_div(new_client, 2);
1148 if (kind != w83697hf) 1162 if (kind != w83697hf)
1149 device_create_file_fan_div(new_client, 3); 1163 if ((err = device_create_file(&new_client->dev,
1150 1164 &dev_attr_in1_input))
1151 device_create_file_alarms(new_client); 1165 || (err = device_create_file(&new_client->dev,
1152 1166 &dev_attr_in1_min))
1153 device_create_file_beep(new_client); 1167 || (err = device_create_file(&new_client->dev,
1168 &dev_attr_in1_max))
1169 || (err = device_create_file(&new_client->dev,
1170 &dev_attr_fan3_input))
1171 || (err = device_create_file(&new_client->dev,
1172 &dev_attr_fan3_min))
1173 || (err = device_create_file(&new_client->dev,
1174 &dev_attr_fan3_div))
1175 || (err = device_create_file(&new_client->dev,
1176 &dev_attr_temp3_input))
1177 || (err = device_create_file(&new_client->dev,
1178 &dev_attr_temp3_max))
1179 || (err = device_create_file(&new_client->dev,
1180 &dev_attr_temp3_max_hyst))
1181 || (err = device_create_file(&new_client->dev,
1182 &dev_attr_temp3_type)))
1183 goto ERROR4;
1184
1185 if (kind != w83697hf && data->vid != 0xff)
1186 if ((err = device_create_file(&new_client->dev,
1187 &dev_attr_cpu0_vid))
1188 || (err = device_create_file(&new_client->dev,
1189 &dev_attr_vrm)))
1190 goto ERROR4;
1154 1191
1155 device_create_file_pwm(new_client, 1);
1156 device_create_file_pwm(new_client, 2);
1157 if (kind == w83627thf || kind == w83637hf || kind == w83687thf) 1192 if (kind == w83627thf || kind == w83637hf || kind == w83687thf)
1158 device_create_file_pwm(new_client, 3); 1193 if ((err = device_create_file(&new_client->dev,
1194 &dev_attr_pwm3)))
1195 goto ERROR4;
1159 1196
1160 device_create_file_sensor(new_client, 1); 1197 data->class_dev = hwmon_device_register(&new_client->dev);
1161 device_create_file_sensor(new_client, 2); 1198 if (IS_ERR(data->class_dev)) {
1162 if (kind != w83697hf) 1199 err = PTR_ERR(data->class_dev);
1163 device_create_file_sensor(new_client, 3); 1200 goto ERROR4;
1201 }
1164 1202
1165 return 0; 1203 return 0;
1166 1204
1205 ERROR4:
1206 sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group);
1207 sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group_opt);
1167 ERROR3: 1208 ERROR3:
1168 i2c_detach_client(new_client); 1209 i2c_detach_client(new_client);
1169 ERROR2: 1210 ERROR2:
@@ -1181,6 +1222,9 @@ static int w83627hf_detach_client(struct i2c_client *client)
1181 1222
1182 hwmon_device_unregister(data->class_dev); 1223 hwmon_device_unregister(data->class_dev);
1183 1224
1225 sysfs_remove_group(&client->dev.kobj, &w83627hf_group);
1226 sysfs_remove_group(&client->dev.kobj, &w83627hf_group_opt);
1227
1184 if ((err = i2c_detach_client(client))) 1228 if ((err = i2c_detach_client(client)))
1185 return err; 1229 return err;
1186 1230