aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2009-12-09 14:36:00 -0500
committerJean Delvare <khali@linux-fr.org>2009-12-09 14:36:00 -0500
commitb69b039922673dfabe0b5774f2e313f2a2297d01 (patch)
tree6910b304d59f8b113c8c4bc8306155f642dec54c /drivers/hwmon
parent66344aa6adc4397f79f134ad122072dbe5abcb48 (diff)
hwmon: (f71882fg) Cleanup sysfs attr creation 2/2
This patch merges the f71882fg_auto_pwm_attr array into the fxxxx_fan_attr resp. fxxxx_auto_pwm_attr array, as the f71882fg_auto_pwm_attr array was merely extending these 2 with entries for a 4th fan, it also makes these 2 arrays 2 dimensional so that the rest of the code can choose to add attr for 3 or 4 fans without needing to know the nr of attr per fan. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/f71882fg.c116
1 files changed, 52 insertions, 64 deletions
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index 40dd6cf3e80d..210ed6619df4 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -416,41 +416,51 @@ static struct sensor_device_attribute_2 f8000_in_temp_attr[] = {
416}; 416};
417 417
418/* Fan / PWM attr common to all models */ 418/* Fan / PWM attr common to all models */
419static struct sensor_device_attribute_2 fxxxx_fan_attr[] = { 419static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
420 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0), 420 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
421 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR, 421 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
422 show_fan_full_speed, 422 show_fan_full_speed,
423 store_fan_full_speed, 0, 0), 423 store_fan_full_speed, 0, 0),
424 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0), 424 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
425 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
426 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
427 show_fan_full_speed,
428 store_fan_full_speed, 0, 1),
429 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
430 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
431 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
432 show_fan_full_speed,
433 store_fan_full_speed, 0, 2),
434 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
435
436 SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0), 425 SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0),
437 SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable, 426 SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
438 store_pwm_enable, 0, 0), 427 store_pwm_enable, 0, 0),
439 SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR, 428 SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR,
440 show_pwm_interpolate, store_pwm_interpolate, 0, 0), 429 show_pwm_interpolate, store_pwm_interpolate, 0, 0),
441 430}, {
431 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
432 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
433 show_fan_full_speed,
434 store_fan_full_speed, 0, 1),
435 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
442 SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1), 436 SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1),
443 SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable, 437 SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
444 store_pwm_enable, 0, 1), 438 store_pwm_enable, 0, 1),
445 SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR, 439 SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR,
446 show_pwm_interpolate, store_pwm_interpolate, 0, 1), 440 show_pwm_interpolate, store_pwm_interpolate, 0, 1),
447 441}, {
442 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
443 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
444 show_fan_full_speed,
445 store_fan_full_speed, 0, 2),
446 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
448 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2), 447 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
449 SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable, 448 SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
450 store_pwm_enable, 0, 2), 449 store_pwm_enable, 0, 2),
451 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR, 450 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
452 show_pwm_interpolate, store_pwm_interpolate, 0, 2), 451 show_pwm_interpolate, store_pwm_interpolate, 0, 2),
453}; 452}, {
453 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
454 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
455 show_fan_full_speed,
456 store_fan_full_speed, 0, 3),
457 SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
458 SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
459 SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
460 store_pwm_enable, 0, 3),
461 SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
462 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
463} };
454 464
455/* Attr for models which can beep on Fan alarm */ 465/* Attr for models which can beep on Fan alarm */
456static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = { 466static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
@@ -460,6 +470,8 @@ static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
460 store_fan_beep, 0, 1), 470 store_fan_beep, 0, 1),
461 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep, 471 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
462 store_fan_beep, 0, 2), 472 store_fan_beep, 0, 2),
473 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
474 store_fan_beep, 0, 3),
463}; 475};
464 476
465/* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the 477/* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
@@ -533,7 +545,7 @@ static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[] = {
533}; 545};
534 546
535/* PWM attr common to the f71858fg, f71882fg and f71889fg */ 547/* PWM attr common to the f71858fg, f71882fg and f71889fg */
536static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[] = { 548static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
537 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR, 549 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
538 show_pwm_auto_point_channel, 550 show_pwm_auto_point_channel,
539 store_pwm_auto_point_channel, 0, 0), 551 store_pwm_auto_point_channel, 0, 0),
@@ -574,7 +586,7 @@ static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[] = {
574 show_pwm_auto_point_temp_hyst, NULL, 2, 0), 586 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
575 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO, 587 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO,
576 show_pwm_auto_point_temp_hyst, NULL, 3, 0), 588 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
577 589}, {
578 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR, 590 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
579 show_pwm_auto_point_channel, 591 show_pwm_auto_point_channel,
580 store_pwm_auto_point_channel, 0, 1), 592 store_pwm_auto_point_channel, 0, 1),
@@ -615,7 +627,7 @@ static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[] = {
615 show_pwm_auto_point_temp_hyst, NULL, 2, 1), 627 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
616 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO, 628 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO,
617 show_pwm_auto_point_temp_hyst, NULL, 3, 1), 629 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
618 630}, {
619 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR, 631 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
620 show_pwm_auto_point_channel, 632 show_pwm_auto_point_channel,
621 store_pwm_auto_point_channel, 0, 2), 633 store_pwm_auto_point_channel, 0, 2),
@@ -656,23 +668,7 @@ static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[] = {
656 show_pwm_auto_point_temp_hyst, NULL, 2, 2), 668 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
657 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO, 669 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO,
658 show_pwm_auto_point_temp_hyst, NULL, 3, 2), 670 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
659}; 671}, {
660
661/* Fan / PWM attr found on the f71882fg but not on the f71858fg */
662static struct sensor_device_attribute_2 f71882fg_auto_pwm_attr[] = {
663 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
664 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
665 show_fan_full_speed,
666 store_fan_full_speed, 0, 3),
667 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
668 store_fan_beep, 0, 3),
669 SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
670
671 SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
672 SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
673 store_pwm_enable, 0, 3),
674 SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
675 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
676 SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR, 672 SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR,
677 show_pwm_auto_point_channel, 673 show_pwm_auto_point_channel,
678 store_pwm_auto_point_channel, 0, 3), 674 store_pwm_auto_point_channel, 0, 3),
@@ -713,7 +709,7 @@ static struct sensor_device_attribute_2 f71882fg_auto_pwm_attr[] = {
713 show_pwm_auto_point_temp_hyst, NULL, 2, 3), 709 show_pwm_auto_point_temp_hyst, NULL, 2, 3),
714 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO, 710 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO,
715 show_pwm_auto_point_temp_hyst, NULL, 3, 3), 711 show_pwm_auto_point_temp_hyst, NULL, 3, 3),
716}; 712} };
717 713
718/* Fan attr specific to the f8000 (4th fan input can only measure speed) */ 714/* Fan attr specific to the f8000 (4th fan input can only measure speed) */
719static struct sensor_device_attribute_2 f8000_fan_attr[] = { 715static struct sensor_device_attribute_2 f8000_fan_attr[] = {
@@ -1917,39 +1913,24 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
1917 goto exit_unregister_sysfs; 1913 goto exit_unregister_sysfs;
1918 } 1914 }
1919 1915
1920 err = f71882fg_create_sysfs_files(pdev, fxxxx_fan_attr, 1916 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
1921 ARRAY_SIZE(fxxxx_fan_attr)); 1917 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
1922 if (err) 1918 if (err)
1923 goto exit_unregister_sysfs; 1919 goto exit_unregister_sysfs;
1924 1920
1925 switch (data->type) { 1921 if (data->type == f71862fg || data->type == f71882fg) {
1926 case f71862fg:
1927 err = f71882fg_create_sysfs_files(pdev, 1922 err = f71882fg_create_sysfs_files(pdev,
1928 fxxxx_fan_beep_attr, 1923 fxxxx_fan_beep_attr, nr_fans);
1929 ARRAY_SIZE(fxxxx_fan_beep_attr));
1930 if (err) 1924 if (err)
1931 goto exit_unregister_sysfs; 1925 goto exit_unregister_sysfs;
1926 }
1927
1928 switch (data->type) {
1929 case f71862fg:
1932 err = f71882fg_create_sysfs_files(pdev, 1930 err = f71882fg_create_sysfs_files(pdev,
1933 f71862fg_auto_pwm_attr, 1931 f71862fg_auto_pwm_attr,
1934 ARRAY_SIZE(f71862fg_auto_pwm_attr)); 1932 ARRAY_SIZE(f71862fg_auto_pwm_attr));
1935 break; 1933 break;
1936 case f71882fg:
1937 err = f71882fg_create_sysfs_files(pdev,
1938 fxxxx_fan_beep_attr,
1939 ARRAY_SIZE(fxxxx_fan_beep_attr));
1940 if (err)
1941 goto exit_unregister_sysfs;
1942 err = f71882fg_create_sysfs_files(pdev,
1943 f71882fg_auto_pwm_attr,
1944 ARRAY_SIZE(f71882fg_auto_pwm_attr));
1945 if (err)
1946 goto exit_unregister_sysfs;
1947 /* fall through! */
1948 case f71858fg:
1949 err = f71882fg_create_sysfs_files(pdev,
1950 fxxxx_auto_pwm_attr,
1951 ARRAY_SIZE(fxxxx_auto_pwm_attr));
1952 break;
1953 case f8000: 1934 case f8000:
1954 err = f71882fg_create_sysfs_files(pdev, 1935 err = f71882fg_create_sysfs_files(pdev,
1955 f8000_fan_attr, 1936 f8000_fan_attr,
@@ -1960,6 +1941,10 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
1960 f8000_auto_pwm_attr, 1941 f8000_auto_pwm_attr,
1961 ARRAY_SIZE(f8000_auto_pwm_attr)); 1942 ARRAY_SIZE(f8000_auto_pwm_attr));
1962 break; 1943 break;
1944 default: /* f71858fg / f71882fg */
1945 err = f71882fg_create_sysfs_files(pdev,
1946 &fxxxx_auto_pwm_attr[0][0],
1947 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
1963 } 1948 }
1964 if (err) 1949 if (err)
1965 goto exit_unregister_sysfs; 1950 goto exit_unregister_sysfs;
@@ -1989,7 +1974,7 @@ exit_free:
1989 1974
1990static int f71882fg_remove(struct platform_device *pdev) 1975static int f71882fg_remove(struct platform_device *pdev)
1991{ 1976{
1992 int i; 1977 int i, j;
1993 struct f71882fg_data *data = platform_get_drvdata(pdev); 1978 struct f71882fg_data *data = platform_get_drvdata(pdev);
1994 1979
1995 platform_set_drvdata(pdev, NULL); 1980 platform_set_drvdata(pdev, NULL);
@@ -2009,15 +1994,18 @@ static int f71882fg_remove(struct platform_device *pdev)
2009 &fxxxx_in1_alarm_attr[i].dev_attr); 1994 &fxxxx_in1_alarm_attr[i].dev_attr);
2010 1995
2011 for (i = 0; i < ARRAY_SIZE(fxxxx_fan_attr); i++) 1996 for (i = 0; i < ARRAY_SIZE(fxxxx_fan_attr); i++)
2012 device_remove_file(&pdev->dev, &fxxxx_fan_attr[i].dev_attr); 1997 for (j = 0; j < ARRAY_SIZE(fxxxx_fan_attr[0]); j++)
1998 device_remove_file(&pdev->dev,
1999 &fxxxx_fan_attr[i][j].dev_attr);
2013 2000
2014 for (i = 0; i < ARRAY_SIZE(fxxxx_fan_beep_attr); i++) 2001 for (i = 0; i < ARRAY_SIZE(fxxxx_fan_beep_attr); i++)
2015 device_remove_file(&pdev->dev, 2002 device_remove_file(&pdev->dev,
2016 &fxxxx_fan_beep_attr[i].dev_attr); 2003 &fxxxx_fan_beep_attr[i].dev_attr);
2017 2004
2018 for (i = 0; i < ARRAY_SIZE(f71882fg_auto_pwm_attr); i++) 2005 for (i = 0; i < ARRAY_SIZE(fxxxx_auto_pwm_attr); i++)
2019 device_remove_file(&pdev->dev, 2006 for (j = 0; j < ARRAY_SIZE(fxxxx_auto_pwm_attr[0]); j++)
2020 &f71882fg_auto_pwm_attr[i].dev_attr); 2007 device_remove_file(&pdev->dev,
2008 &fxxxx_auto_pwm_attr[i][j].dev_attr);
2021 2009
2022 for (i = 0; i < ARRAY_SIZE(f8000_auto_pwm_attr); i++) 2010 for (i = 0; i < ARRAY_SIZE(f8000_auto_pwm_attr); i++)
2023 device_remove_file(&pdev->dev, 2011 device_remove_file(&pdev->dev,