aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/fscher.c106
-rw-r--r--drivers/hwmon/fscpos.c75
-rw-r--r--drivers/hwmon/gl518sm.c74
-rw-r--r--drivers/hwmon/gl520sm.c128
-rw-r--r--drivers/hwmon/it87.c234
5 files changed, 368 insertions, 249 deletions
diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c
index 6bc76b407636..19717752cfca 100644
--- a/drivers/hwmon/fscher.c
+++ b/drivers/hwmon/fscher.c
@@ -34,6 +34,7 @@
34#include <linux/hwmon.h> 34#include <linux/hwmon.h>
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/sysfs.h>
37 38
38/* 39/*
39 * Addresses to scan 40 * Addresses to scan
@@ -240,47 +241,45 @@ sysfs_alarms(FSCHER_REG_EVENTS)
240sysfs_control(FSCHER_REG_CONTROL) 241sysfs_control(FSCHER_REG_CONTROL)
241sysfs_watchdog(FSCHER_REG_WDOG_CONTROL, FSCHER_REG_WDOG_STATE, FSCHER_REG_WDOG_PRESET) 242sysfs_watchdog(FSCHER_REG_WDOG_CONTROL, FSCHER_REG_WDOG_STATE, FSCHER_REG_WDOG_PRESET)
242 243
243#define device_create_file_fan(client, offset) \ 244static struct attribute *fscher_attributes[] = {
244do { \ 245 &dev_attr_revision.attr,
245 device_create_file(&client->dev, &dev_attr_fan##offset##_status); \ 246 &dev_attr_alarms.attr,
246 device_create_file(&client->dev, &dev_attr_pwm##offset); \ 247 &dev_attr_control.attr,
247 device_create_file(&client->dev, &dev_attr_fan##offset##_div); \ 248
248 device_create_file(&client->dev, &dev_attr_fan##offset##_input); \ 249 &dev_attr_watchdog_status.attr,
249} while (0) 250 &dev_attr_watchdog_control.attr,
250 251 &dev_attr_watchdog_preset.attr,
251#define device_create_file_temp(client, offset) \ 252
252do { \ 253 &dev_attr_in0_input.attr,
253 device_create_file(&client->dev, &dev_attr_temp##offset##_status); \ 254 &dev_attr_in1_input.attr,
254 device_create_file(&client->dev, &dev_attr_temp##offset##_input); \ 255 &dev_attr_in2_input.attr,
255} while (0) 256
256 257 &dev_attr_fan1_status.attr,
257#define device_create_file_in(client, offset) \ 258 &dev_attr_fan1_div.attr,
258do { \ 259 &dev_attr_fan1_input.attr,
259 device_create_file(&client->dev, &dev_attr_in##offset##_input); \ 260 &dev_attr_pwm1.attr,
260} while (0) 261 &dev_attr_fan2_status.attr,
261 262 &dev_attr_fan2_div.attr,
262#define device_create_file_revision(client) \ 263 &dev_attr_fan2_input.attr,
263do { \ 264 &dev_attr_pwm2.attr,
264 device_create_file(&client->dev, &dev_attr_revision); \ 265 &dev_attr_fan3_status.attr,
265} while (0) 266 &dev_attr_fan3_div.attr,
266 267 &dev_attr_fan3_input.attr,
267#define device_create_file_alarms(client) \ 268 &dev_attr_pwm3.attr,
268do { \ 269
269 device_create_file(&client->dev, &dev_attr_alarms); \ 270 &dev_attr_temp1_status.attr,
270} while (0) 271 &dev_attr_temp1_input.attr,
271 272 &dev_attr_temp2_status.attr,
272#define device_create_file_control(client) \ 273 &dev_attr_temp2_input.attr,
273do { \ 274 &dev_attr_temp3_status.attr,
274 device_create_file(&client->dev, &dev_attr_control); \ 275 &dev_attr_temp3_input.attr,
275} while (0) 276 NULL
276 277};
277#define device_create_file_watchdog(client) \ 278
278do { \ 279static const struct attribute_group fscher_group = {
279 device_create_file(&client->dev, &dev_attr_watchdog_status); \ 280 .attrs = fscher_attributes,
280 device_create_file(&client->dev, &dev_attr_watchdog_control); \ 281};
281 device_create_file(&client->dev, &dev_attr_watchdog_preset); \ 282
282} while (0)
283
284/* 283/*
285 * Real code 284 * Real code
286 */ 285 */
@@ -342,31 +341,19 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
342 fscher_init_client(new_client); 341 fscher_init_client(new_client);
343 342
344 /* Register sysfs hooks */ 343 /* Register sysfs hooks */
344 if ((err = sysfs_create_group(&new_client->dev.kobj, &fscher_group)))
345 goto exit_detach;
346
345 data->class_dev = hwmon_device_register(&new_client->dev); 347 data->class_dev = hwmon_device_register(&new_client->dev);
346 if (IS_ERR(data->class_dev)) { 348 if (IS_ERR(data->class_dev)) {
347 err = PTR_ERR(data->class_dev); 349 err = PTR_ERR(data->class_dev);
348 goto exit_detach; 350 goto exit_remove_files;
349 } 351 }
350 352
351 device_create_file_revision(new_client);
352 device_create_file_alarms(new_client);
353 device_create_file_control(new_client);
354 device_create_file_watchdog(new_client);
355
356 device_create_file_in(new_client, 0);
357 device_create_file_in(new_client, 1);
358 device_create_file_in(new_client, 2);
359
360 device_create_file_fan(new_client, 1);
361 device_create_file_fan(new_client, 2);
362 device_create_file_fan(new_client, 3);
363
364 device_create_file_temp(new_client, 1);
365 device_create_file_temp(new_client, 2);
366 device_create_file_temp(new_client, 3);
367
368 return 0; 353 return 0;
369 354
355exit_remove_files:
356 sysfs_remove_group(&new_client->dev.kobj, &fscher_group);
370exit_detach: 357exit_detach:
371 i2c_detach_client(new_client); 358 i2c_detach_client(new_client);
372exit_free: 359exit_free:
@@ -381,6 +368,7 @@ static int fscher_detach_client(struct i2c_client *client)
381 int err; 368 int err;
382 369
383 hwmon_device_unregister(data->class_dev); 370 hwmon_device_unregister(data->class_dev);
371 sysfs_remove_group(&client->dev.kobj, &fscher_group);
384 372
385 if ((err = i2c_detach_client(client))) 373 if ((err = i2c_detach_client(client)))
386 return err; 374 return err;
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c
index 6dc4846b9eeb..ea506a77f9c9 100644
--- a/drivers/hwmon/fscpos.c
+++ b/drivers/hwmon/fscpos.c
@@ -38,6 +38,7 @@
38#include <linux/hwmon.h> 38#include <linux/hwmon.h>
39#include <linux/err.h> 39#include <linux/err.h>
40#include <linux/mutex.h> 40#include <linux/mutex.h>
41#include <linux/sysfs.h>
41 42
42/* 43/*
43 * Addresses to scan 44 * Addresses to scan
@@ -432,6 +433,44 @@ static DEVICE_ATTR(in0_input, S_IRUGO, show_volt_12, NULL);
432static DEVICE_ATTR(in1_input, S_IRUGO, show_volt_5, NULL); 433static DEVICE_ATTR(in1_input, S_IRUGO, show_volt_5, NULL);
433static DEVICE_ATTR(in2_input, S_IRUGO, show_volt_batt, NULL); 434static DEVICE_ATTR(in2_input, S_IRUGO, show_volt_batt, NULL);
434 435
436static struct attribute *fscpos_attributes[] = {
437 &dev_attr_event.attr,
438 &dev_attr_in0_input.attr,
439 &dev_attr_in1_input.attr,
440 &dev_attr_in2_input.attr,
441
442 &dev_attr_wdog_control.attr,
443 &dev_attr_wdog_preset.attr,
444 &dev_attr_wdog_state.attr,
445
446 &dev_attr_temp1_input.attr,
447 &dev_attr_temp1_status.attr,
448 &dev_attr_temp1_reset.attr,
449 &dev_attr_temp2_input.attr,
450 &dev_attr_temp2_status.attr,
451 &dev_attr_temp2_reset.attr,
452 &dev_attr_temp3_input.attr,
453 &dev_attr_temp3_status.attr,
454 &dev_attr_temp3_reset.attr,
455
456 &dev_attr_fan1_input.attr,
457 &dev_attr_fan1_status.attr,
458 &dev_attr_fan1_ripple.attr,
459 &dev_attr_pwm1.attr,
460 &dev_attr_fan2_input.attr,
461 &dev_attr_fan2_status.attr,
462 &dev_attr_fan2_ripple.attr,
463 &dev_attr_pwm2.attr,
464 &dev_attr_fan3_input.attr,
465 &dev_attr_fan3_status.attr,
466 &dev_attr_fan3_ripple.attr,
467 NULL
468};
469
470static const struct attribute_group fscpos_group = {
471 .attrs = fscpos_attributes,
472};
473
435static int fscpos_attach_adapter(struct i2c_adapter *adapter) 474static int fscpos_attach_adapter(struct i2c_adapter *adapter)
436{ 475{
437 if (!(adapter->class & I2C_CLASS_HWMON)) 476 if (!(adapter->class & I2C_CLASS_HWMON))
@@ -497,42 +536,19 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind)
497 dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision); 536 dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision);
498 537
499 /* Register sysfs hooks */ 538 /* Register sysfs hooks */
539 if ((err = sysfs_create_group(&new_client->dev.kobj, &fscpos_group)))
540 goto exit_detach;
541
500 data->class_dev = hwmon_device_register(&new_client->dev); 542 data->class_dev = hwmon_device_register(&new_client->dev);
501 if (IS_ERR(data->class_dev)) { 543 if (IS_ERR(data->class_dev)) {
502 err = PTR_ERR(data->class_dev); 544 err = PTR_ERR(data->class_dev);
503 goto exit_detach; 545 goto exit_remove_files;
504 } 546 }
505 547
506 device_create_file(&new_client->dev, &dev_attr_event);
507 device_create_file(&new_client->dev, &dev_attr_in0_input);
508 device_create_file(&new_client->dev, &dev_attr_in1_input);
509 device_create_file(&new_client->dev, &dev_attr_in2_input);
510 device_create_file(&new_client->dev, &dev_attr_wdog_control);
511 device_create_file(&new_client->dev, &dev_attr_wdog_preset);
512 device_create_file(&new_client->dev, &dev_attr_wdog_state);
513 device_create_file(&new_client->dev, &dev_attr_temp1_input);
514 device_create_file(&new_client->dev, &dev_attr_temp1_status);
515 device_create_file(&new_client->dev, &dev_attr_temp1_reset);
516 device_create_file(&new_client->dev, &dev_attr_temp2_input);
517 device_create_file(&new_client->dev, &dev_attr_temp2_status);
518 device_create_file(&new_client->dev, &dev_attr_temp2_reset);
519 device_create_file(&new_client->dev, &dev_attr_temp3_input);
520 device_create_file(&new_client->dev, &dev_attr_temp3_status);
521 device_create_file(&new_client->dev, &dev_attr_temp3_reset);
522 device_create_file(&new_client->dev, &dev_attr_fan1_input);
523 device_create_file(&new_client->dev, &dev_attr_fan1_status);
524 device_create_file(&new_client->dev, &dev_attr_fan1_ripple);
525 device_create_file(&new_client->dev, &dev_attr_pwm1);
526 device_create_file(&new_client->dev, &dev_attr_fan2_input);
527 device_create_file(&new_client->dev, &dev_attr_fan2_status);
528 device_create_file(&new_client->dev, &dev_attr_fan2_ripple);
529 device_create_file(&new_client->dev, &dev_attr_pwm2);
530 device_create_file(&new_client->dev, &dev_attr_fan3_input);
531 device_create_file(&new_client->dev, &dev_attr_fan3_status);
532 device_create_file(&new_client->dev, &dev_attr_fan3_ripple);
533
534 return 0; 548 return 0;
535 549
550exit_remove_files:
551 sysfs_remove_group(&new_client->dev.kobj, &fscpos_group);
536exit_detach: 552exit_detach:
537 i2c_detach_client(new_client); 553 i2c_detach_client(new_client);
538exit_free: 554exit_free:
@@ -547,6 +563,7 @@ static int fscpos_detach_client(struct i2c_client *client)
547 int err; 563 int err;
548 564
549 hwmon_device_unregister(data->class_dev); 565 hwmon_device_unregister(data->class_dev);
566 sysfs_remove_group(&client->dev.kobj, &fscpos_group);
550 567
551 if ((err = i2c_detach_client(client))) 568 if ((err = i2c_detach_client(client)))
552 return err; 569 return err;
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index 6606aabdb49d..c103640455a3 100644
--- a/drivers/hwmon/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
@@ -44,6 +44,7 @@
44#include <linux/hwmon.h> 44#include <linux/hwmon.h>
45#include <linux/err.h> 45#include <linux/err.h>
46#include <linux/mutex.h> 46#include <linux/mutex.h>
47#include <linux/sysfs.h>
47 48
48/* Addresses to scan */ 49/* Addresses to scan */
49static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 50static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
@@ -340,6 +341,42 @@ static DEVICE_ATTR(beep_enable, S_IWUSR|S_IRUGO,
340static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO, 341static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO,
341 show_beep_mask, set_beep_mask); 342 show_beep_mask, set_beep_mask);
342 343
344static struct attribute *gl518_attributes[] = {
345 &dev_attr_in0_input.attr,
346 &dev_attr_in1_input.attr,
347 &dev_attr_in2_input.attr,
348 &dev_attr_in3_input.attr,
349 &dev_attr_in0_min.attr,
350 &dev_attr_in1_min.attr,
351 &dev_attr_in2_min.attr,
352 &dev_attr_in3_min.attr,
353 &dev_attr_in0_max.attr,
354 &dev_attr_in1_max.attr,
355 &dev_attr_in2_max.attr,
356 &dev_attr_in3_max.attr,
357
358 &dev_attr_fan1_auto.attr,
359 &dev_attr_fan1_input.attr,
360 &dev_attr_fan2_input.attr,
361 &dev_attr_fan1_min.attr,
362 &dev_attr_fan2_min.attr,
363 &dev_attr_fan1_div.attr,
364 &dev_attr_fan2_div.attr,
365
366 &dev_attr_temp1_input.attr,
367 &dev_attr_temp1_max.attr,
368 &dev_attr_temp1_max_hyst.attr,
369
370 &dev_attr_alarms.attr,
371 &dev_attr_beep_enable.attr,
372 &dev_attr_beep_mask.attr,
373 NULL
374};
375
376static const struct attribute_group gl518_group = {
377 .attrs = gl518_attributes,
378};
379
343/* 380/*
344 * Real code 381 * Real code
345 */ 382 */
@@ -420,43 +457,19 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
420 gl518_init_client((struct i2c_client *) new_client); 457 gl518_init_client((struct i2c_client *) new_client);
421 458
422 /* Register sysfs hooks */ 459 /* Register sysfs hooks */
460 if ((err = sysfs_create_group(&new_client->dev.kobj, &gl518_group)))
461 goto exit_detach;
462
423 data->class_dev = hwmon_device_register(&new_client->dev); 463 data->class_dev = hwmon_device_register(&new_client->dev);
424 if (IS_ERR(data->class_dev)) { 464 if (IS_ERR(data->class_dev)) {
425 err = PTR_ERR(data->class_dev); 465 err = PTR_ERR(data->class_dev);
426 goto exit_detach; 466 goto exit_remove_files;
427 } 467 }
428 468
429 device_create_file(&new_client->dev, &dev_attr_in0_input);
430 device_create_file(&new_client->dev, &dev_attr_in1_input);
431 device_create_file(&new_client->dev, &dev_attr_in2_input);
432 device_create_file(&new_client->dev, &dev_attr_in3_input);
433 device_create_file(&new_client->dev, &dev_attr_in0_min);
434 device_create_file(&new_client->dev, &dev_attr_in1_min);
435 device_create_file(&new_client->dev, &dev_attr_in2_min);
436 device_create_file(&new_client->dev, &dev_attr_in3_min);
437 device_create_file(&new_client->dev, &dev_attr_in0_max);
438 device_create_file(&new_client->dev, &dev_attr_in1_max);
439 device_create_file(&new_client->dev, &dev_attr_in2_max);
440 device_create_file(&new_client->dev, &dev_attr_in3_max);
441 device_create_file(&new_client->dev, &dev_attr_fan1_auto);
442 device_create_file(&new_client->dev, &dev_attr_fan1_input);
443 device_create_file(&new_client->dev, &dev_attr_fan2_input);
444 device_create_file(&new_client->dev, &dev_attr_fan1_min);
445 device_create_file(&new_client->dev, &dev_attr_fan2_min);
446 device_create_file(&new_client->dev, &dev_attr_fan1_div);
447 device_create_file(&new_client->dev, &dev_attr_fan2_div);
448 device_create_file(&new_client->dev, &dev_attr_temp1_input);
449 device_create_file(&new_client->dev, &dev_attr_temp1_max);
450 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
451 device_create_file(&new_client->dev, &dev_attr_alarms);
452 device_create_file(&new_client->dev, &dev_attr_beep_enable);
453 device_create_file(&new_client->dev, &dev_attr_beep_mask);
454
455 return 0; 469 return 0;
456 470
457/* OK, this is not exactly good programming practice, usually. But it is 471exit_remove_files:
458 very code-efficient in this case. */ 472 sysfs_remove_group(&new_client->dev.kobj, &gl518_group);
459
460exit_detach: 473exit_detach:
461 i2c_detach_client(new_client); 474 i2c_detach_client(new_client);
462exit_free: 475exit_free:
@@ -490,6 +503,7 @@ static int gl518_detach_client(struct i2c_client *client)
490 int err; 503 int err;
491 504
492 hwmon_device_unregister(data->class_dev); 505 hwmon_device_unregister(data->class_dev);
506 sysfs_remove_group(&client->dev.kobj, &gl518_group);
493 507
494 if ((err = i2c_detach_client(client))) 508 if ((err = i2c_detach_client(client)))
495 return err; 509 return err;
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 */
35static unsigned short extra_sensor_type; 36static 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) \
191sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT) 192sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT)
192 193
193#define device_create_file_vid(client, n) \
194device_create_file(&client->dev, &dev_attr_cpu##n##_vid)
195
196#define sysfs_in(n) \ 194#define sysfs_in(n) \
197sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \ 195sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \
198sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \ 196sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \
199sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \ 197sysfs_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); \
203device_create_file(&client->dev, &dev_attr_in##n##_min); \
204device_create_file(&client->dev, &dev_attr_in##n##_max);})
205
206#define sysfs_fan(n) \ 199#define sysfs_fan(n) \
207sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \ 200sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \
208sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \ 201sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \
209sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV) 202sysfs_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); \
213device_create_file(&client->dev, &dev_attr_fan##n##_min); \
214device_create_file(&client->dev, &dev_attr_fan##n##_div);})
215
216#define sysfs_fan_off(n) \ 204#define sysfs_fan_off(n) \
217sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \ 205sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \
218 206
219#define device_create_file_fan_off(client, n) \
220device_create_file(&client->dev, &dev_attr_fan##n##_off)
221
222#define sysfs_temp(n) \ 207#define sysfs_temp(n) \
223sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \ 208sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \
224sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \ 209sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \
225sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST) 210sysfs_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); \
229device_create_file(&client->dev, &dev_attr_temp##n##_max); \
230device_create_file(&client->dev, &dev_attr_temp##n##_max_hyst);})
231
232#define sysfs_alarms() \ 212#define sysfs_alarms() \
233sysfs_ro(alarms, , GL520_REG_ALARMS) \ 213sysfs_ro(alarms, , GL520_REG_ALARMS) \
234sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \ 214sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \
235sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK) 215sysfs_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); \
239device_create_file(&client->dev, &dev_attr_beep_enable); \
240device_create_file(&client->dev, &dev_attr_beep_mask);})
241
242 217
243sysfs_vid(0) 218sysfs_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
489static 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
523static const struct attribute_group gl520_group = {
524 .attrs = gl520_attributes,
525};
526
527static 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
538static 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
633exit_remove_files:
634 sysfs_remove_group(&new_client->dev.kobj, &gl520_group);
635 sysfs_remove_group(&new_client->dev.kobj, &gl520_group_opt);
602exit_detach: 636exit_detach:
603 i2c_detach_client(new_client); 637 i2c_detach_client(new_client);
604exit_free: 638exit_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;
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index af5740d5d70f..323ef06719c1 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -37,6 +37,7 @@
37#include <linux/hwmon-vid.h> 37#include <linux/hwmon-vid.h>
38#include <linux/err.h> 38#include <linux/err.h>
39#include <linux/mutex.h> 39#include <linux/mutex.h>
40#include <linux/sysfs.h>
40#include <asm/io.h> 41#include <asm/io.h>
41 42
42 43
@@ -758,8 +759,6 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf
758 return count; 759 return count;
759} 760}
760static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 761static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
761#define device_create_file_vrm(client) \
762device_create_file(&client->dev, &dev_attr_vrm)
763 762
764static ssize_t 763static ssize_t
765show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 764show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -768,8 +767,88 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
768 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 767 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
769} 768}
770static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 769static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
771#define device_create_file_vid(client) \ 770
772device_create_file(&client->dev, &dev_attr_cpu0_vid) 771static struct attribute *it87_attributes[] = {
772 &sensor_dev_attr_in0_input.dev_attr.attr,
773 &sensor_dev_attr_in1_input.dev_attr.attr,
774 &sensor_dev_attr_in2_input.dev_attr.attr,
775 &sensor_dev_attr_in3_input.dev_attr.attr,
776 &sensor_dev_attr_in4_input.dev_attr.attr,
777 &sensor_dev_attr_in5_input.dev_attr.attr,
778 &sensor_dev_attr_in6_input.dev_attr.attr,
779 &sensor_dev_attr_in7_input.dev_attr.attr,
780 &sensor_dev_attr_in8_input.dev_attr.attr,
781 &sensor_dev_attr_in0_min.dev_attr.attr,
782 &sensor_dev_attr_in1_min.dev_attr.attr,
783 &sensor_dev_attr_in2_min.dev_attr.attr,
784 &sensor_dev_attr_in3_min.dev_attr.attr,
785 &sensor_dev_attr_in4_min.dev_attr.attr,
786 &sensor_dev_attr_in5_min.dev_attr.attr,
787 &sensor_dev_attr_in6_min.dev_attr.attr,
788 &sensor_dev_attr_in7_min.dev_attr.attr,
789 &sensor_dev_attr_in0_max.dev_attr.attr,
790 &sensor_dev_attr_in1_max.dev_attr.attr,
791 &sensor_dev_attr_in2_max.dev_attr.attr,
792 &sensor_dev_attr_in3_max.dev_attr.attr,
793 &sensor_dev_attr_in4_max.dev_attr.attr,
794 &sensor_dev_attr_in5_max.dev_attr.attr,
795 &sensor_dev_attr_in6_max.dev_attr.attr,
796 &sensor_dev_attr_in7_max.dev_attr.attr,
797
798 &sensor_dev_attr_temp1_input.dev_attr.attr,
799 &sensor_dev_attr_temp2_input.dev_attr.attr,
800 &sensor_dev_attr_temp3_input.dev_attr.attr,
801 &sensor_dev_attr_temp1_max.dev_attr.attr,
802 &sensor_dev_attr_temp2_max.dev_attr.attr,
803 &sensor_dev_attr_temp3_max.dev_attr.attr,
804 &sensor_dev_attr_temp1_min.dev_attr.attr,
805 &sensor_dev_attr_temp2_min.dev_attr.attr,
806 &sensor_dev_attr_temp3_min.dev_attr.attr,
807 &sensor_dev_attr_temp1_type.dev_attr.attr,
808 &sensor_dev_attr_temp2_type.dev_attr.attr,
809 &sensor_dev_attr_temp3_type.dev_attr.attr,
810
811 &dev_attr_alarms.attr,
812 NULL
813};
814
815static const struct attribute_group it87_group = {
816 .attrs = it87_attributes,
817};
818
819static struct attribute *it87_attributes_opt[] = {
820 &sensor_dev_attr_fan1_input16.dev_attr.attr,
821 &sensor_dev_attr_fan1_min16.dev_attr.attr,
822 &sensor_dev_attr_fan2_input16.dev_attr.attr,
823 &sensor_dev_attr_fan2_min16.dev_attr.attr,
824 &sensor_dev_attr_fan3_input16.dev_attr.attr,
825 &sensor_dev_attr_fan3_min16.dev_attr.attr,
826
827 &sensor_dev_attr_fan1_input.dev_attr.attr,
828 &sensor_dev_attr_fan1_min.dev_attr.attr,
829 &sensor_dev_attr_fan1_div.dev_attr.attr,
830 &sensor_dev_attr_fan2_input.dev_attr.attr,
831 &sensor_dev_attr_fan2_min.dev_attr.attr,
832 &sensor_dev_attr_fan2_div.dev_attr.attr,
833 &sensor_dev_attr_fan3_input.dev_attr.attr,
834 &sensor_dev_attr_fan3_min.dev_attr.attr,
835 &sensor_dev_attr_fan3_div.dev_attr.attr,
836
837 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
838 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
839 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
840 &sensor_dev_attr_pwm1.dev_attr.attr,
841 &sensor_dev_attr_pwm2.dev_attr.attr,
842 &sensor_dev_attr_pwm3.dev_attr.attr,
843
844 &dev_attr_vrm.attr,
845 &dev_attr_cpu0_vid.attr,
846 NULL
847};
848
849static const struct attribute_group it87_group_opt = {
850 .attrs = it87_attributes_opt,
851};
773 852
774/* This function is called when: 853/* This function is called when:
775 * it87_driver is inserted (when this module is loaded), for each 854 * it87_driver is inserted (when this module is loaded), for each
@@ -948,107 +1027,78 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
948 it87_init_client(new_client, data); 1027 it87_init_client(new_client, data);
949 1028
950 /* Register sysfs hooks */ 1029 /* Register sysfs hooks */
951 data->class_dev = hwmon_device_register(&new_client->dev); 1030 if ((err = sysfs_create_group(&new_client->dev.kobj, &it87_group)))
952 if (IS_ERR(data->class_dev)) {
953 err = PTR_ERR(data->class_dev);
954 goto ERROR3; 1031 goto ERROR3;
955 }
956
957 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
958 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
959 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
960 device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr);
961 device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr);
962 device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr);
963 device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr);
964 device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr);
965 device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr);
966 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
967 device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr);
968 device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr);
969 device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr);
970 device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr);
971 device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr);
972 device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr);
973 device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr);
974 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
975 device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr);
976 device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr);
977 device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr);
978 device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr);
979 device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr);
980 device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr);
981 device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr);
982 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr);
983 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr);
984 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr);
985 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr);
986 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr);
987 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr);
988 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr);
989 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr);
990 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr);
991 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_type.dev_attr);
992 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_type.dev_attr);
993 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_type.dev_attr);
994 1032
995 /* Do not create fan files for disabled fans */ 1033 /* Do not create fan files for disabled fans */
996 if (data->type == it8716 || data->type == it8718) { 1034 if (data->type == it8716 || data->type == it8718) {
997 /* 16-bit tachometers */ 1035 /* 16-bit tachometers */
998 if (data->has_fan & (1 << 0)) { 1036 if (data->has_fan & (1 << 0)) {
999 device_create_file(&new_client->dev, 1037 if ((err = device_create_file(&new_client->dev,
1000 &sensor_dev_attr_fan1_input16.dev_attr); 1038 &sensor_dev_attr_fan1_input16.dev_attr))
1001 device_create_file(&new_client->dev, 1039 || (err = device_create_file(&new_client->dev,
1002 &sensor_dev_attr_fan1_min16.dev_attr); 1040 &sensor_dev_attr_fan1_min16.dev_attr)))
1041 goto ERROR4;
1003 } 1042 }
1004 if (data->has_fan & (1 << 1)) { 1043 if (data->has_fan & (1 << 1)) {
1005 device_create_file(&new_client->dev, 1044 if ((err = device_create_file(&new_client->dev,
1006 &sensor_dev_attr_fan2_input16.dev_attr); 1045 &sensor_dev_attr_fan2_input16.dev_attr))
1007 device_create_file(&new_client->dev, 1046 || (err = device_create_file(&new_client->dev,
1008 &sensor_dev_attr_fan2_min16.dev_attr); 1047 &sensor_dev_attr_fan2_min16.dev_attr)))
1048 goto ERROR4;
1009 } 1049 }
1010 if (data->has_fan & (1 << 2)) { 1050 if (data->has_fan & (1 << 2)) {
1011 device_create_file(&new_client->dev, 1051 if ((err = device_create_file(&new_client->dev,
1012 &sensor_dev_attr_fan3_input16.dev_attr); 1052 &sensor_dev_attr_fan3_input16.dev_attr))
1013 device_create_file(&new_client->dev, 1053 || (err = device_create_file(&new_client->dev,
1014 &sensor_dev_attr_fan3_min16.dev_attr); 1054 &sensor_dev_attr_fan3_min16.dev_attr)))
1055 goto ERROR4;
1015 } 1056 }
1016 } else { 1057 } else {
1017 /* 8-bit tachometers with clock divider */ 1058 /* 8-bit tachometers with clock divider */
1018 if (data->has_fan & (1 << 0)) { 1059 if (data->has_fan & (1 << 0)) {
1019 device_create_file(&new_client->dev, 1060 if ((err = device_create_file(&new_client->dev,
1020 &sensor_dev_attr_fan1_input.dev_attr); 1061 &sensor_dev_attr_fan1_input.dev_attr))
1021 device_create_file(&new_client->dev, 1062 || (err = device_create_file(&new_client->dev,
1022 &sensor_dev_attr_fan1_min.dev_attr); 1063 &sensor_dev_attr_fan1_min.dev_attr))
1023 device_create_file(&new_client->dev, 1064 || (err = device_create_file(&new_client->dev,
1024 &sensor_dev_attr_fan1_div.dev_attr); 1065 &sensor_dev_attr_fan1_div.dev_attr)))
1066 goto ERROR4;
1025 } 1067 }
1026 if (data->has_fan & (1 << 1)) { 1068 if (data->has_fan & (1 << 1)) {
1027 device_create_file(&new_client->dev, 1069 if ((err = device_create_file(&new_client->dev,
1028 &sensor_dev_attr_fan2_input.dev_attr); 1070 &sensor_dev_attr_fan2_input.dev_attr))
1029 device_create_file(&new_client->dev, 1071 || (err = device_create_file(&new_client->dev,
1030 &sensor_dev_attr_fan2_min.dev_attr); 1072 &sensor_dev_attr_fan2_min.dev_attr))
1031 device_create_file(&new_client->dev, 1073 || (err = device_create_file(&new_client->dev,
1032 &sensor_dev_attr_fan2_div.dev_attr); 1074 &sensor_dev_attr_fan2_div.dev_attr)))
1075 goto ERROR4;
1033 } 1076 }
1034 if (data->has_fan & (1 << 2)) { 1077 if (data->has_fan & (1 << 2)) {
1035 device_create_file(&new_client->dev, 1078 if ((err = device_create_file(&new_client->dev,
1036 &sensor_dev_attr_fan3_input.dev_attr); 1079 &sensor_dev_attr_fan3_input.dev_attr))
1037 device_create_file(&new_client->dev, 1080 || (err = device_create_file(&new_client->dev,
1038 &sensor_dev_attr_fan3_min.dev_attr); 1081 &sensor_dev_attr_fan3_min.dev_attr))
1039 device_create_file(&new_client->dev, 1082 || (err = device_create_file(&new_client->dev,
1040 &sensor_dev_attr_fan3_div.dev_attr); 1083 &sensor_dev_attr_fan3_div.dev_attr)))
1084 goto ERROR4;
1041 } 1085 }
1042 } 1086 }
1043 1087
1044 device_create_file(&new_client->dev, &dev_attr_alarms);
1045 if (enable_pwm_interface) { 1088 if (enable_pwm_interface) {
1046 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1_enable.dev_attr); 1089 if ((err = device_create_file(&new_client->dev,
1047 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2_enable.dev_attr); 1090 &sensor_dev_attr_pwm1_enable.dev_attr))
1048 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3_enable.dev_attr); 1091 || (err = device_create_file(&new_client->dev,
1049 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr); 1092 &sensor_dev_attr_pwm2_enable.dev_attr))
1050 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr); 1093 || (err = device_create_file(&new_client->dev,
1051 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr); 1094 &sensor_dev_attr_pwm3_enable.dev_attr))
1095 || (err = device_create_file(&new_client->dev,
1096 &sensor_dev_attr_pwm1.dev_attr))
1097 || (err = device_create_file(&new_client->dev,
1098 &sensor_dev_attr_pwm2.dev_attr))
1099 || (err = device_create_file(&new_client->dev,
1100 &sensor_dev_attr_pwm3.dev_attr)))
1101 goto ERROR4;
1052 } 1102 }
1053 1103
1054 if (data->type == it8712 || data->type == it8716 1104 if (data->type == it8712 || data->type == it8716
@@ -1056,12 +1106,24 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
1056 data->vrm = vid_which_vrm(); 1106 data->vrm = vid_which_vrm();
1057 /* VID reading from Super-I/O config space if available */ 1107 /* VID reading from Super-I/O config space if available */
1058 data->vid = vid_value; 1108 data->vid = vid_value;
1059 device_create_file_vrm(new_client); 1109 if ((err = device_create_file(&new_client->dev,
1060 device_create_file_vid(new_client); 1110 &dev_attr_vrm))
1111 || (err = device_create_file(&new_client->dev,
1112 &dev_attr_cpu0_vid)))
1113 goto ERROR4;
1114 }
1115
1116 data->class_dev = hwmon_device_register(&new_client->dev);
1117 if (IS_ERR(data->class_dev)) {
1118 err = PTR_ERR(data->class_dev);
1119 goto ERROR4;
1061 } 1120 }
1062 1121
1063 return 0; 1122 return 0;
1064 1123
1124ERROR4:
1125 sysfs_remove_group(&new_client->dev.kobj, &it87_group);
1126 sysfs_remove_group(&new_client->dev.kobj, &it87_group_opt);
1065ERROR3: 1127ERROR3:
1066 i2c_detach_client(new_client); 1128 i2c_detach_client(new_client);
1067ERROR2: 1129ERROR2:
@@ -1079,6 +1141,8 @@ static int it87_detach_client(struct i2c_client *client)
1079 int err; 1141 int err;
1080 1142
1081 hwmon_device_unregister(data->class_dev); 1143 hwmon_device_unregister(data->class_dev);
1144 sysfs_remove_group(&client->dev.kobj, &it87_group);
1145 sysfs_remove_group(&client->dev.kobj, &it87_group_opt);
1082 1146
1083 if ((err = i2c_detach_client(client))) 1147 if ((err = i2c_detach_client(client)))
1084 return err; 1148 return err;