diff options
author | Guenter Roeck <linux@roeck-us.net> | 2015-04-02 11:23:45 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2016-04-19 09:32:37 -0400 |
commit | 2310048db70a58ae89b37fded0322b6a5ae6443f (patch) | |
tree | 02fd5a6e4b618e7293bf7b90f2975537f49821fc /drivers/hwmon/it87.c | |
parent | 48b2ae7fe9d0eba523a3633ff0f939aba9e962e2 (diff) |
hwmon: (it87) Use defines for array sizes and sensor counts
Using array size defines makes it much easier to find errors
in index values and loop counts.
Tested-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/it87.c')
-rw-r--r-- | drivers/hwmon/it87.c | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index 0d6d106d53a2..118d4c756e40 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -260,6 +260,16 @@ static const u8 IT87_REG_VIN[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, | |||
260 | 260 | ||
261 | #define IT87_REG_TEMP456_ENABLE 0x77 | 261 | #define IT87_REG_TEMP456_ENABLE 0x77 |
262 | 262 | ||
263 | #define NUM_VIN ARRAY_SIZE(IT87_REG_VIN) | ||
264 | #define NUM_VIN_LIMIT 8 | ||
265 | #define NUM_TEMP 6 | ||
266 | #define NUM_TEMP_OFFSET ARRAY_SIZE(IT87_REG_TEMP_OFFSET) | ||
267 | #define NUM_TEMP_LIMIT 3 | ||
268 | #define NUM_FAN ARRAY_SIZE(IT87_REG_FAN) | ||
269 | #define NUM_FAN_DIV 3 | ||
270 | #define NUM_PWM ARRAY_SIZE(IT87_REG_PWM) | ||
271 | #define NUM_AUTO_PWM ARRAY_SIZE(IT87_REG_PWM) | ||
272 | |||
263 | struct it87_devices { | 273 | struct it87_devices { |
264 | const char *name; | 274 | const char *name; |
265 | const char * const suffix; | 275 | const char * const suffix; |
@@ -484,14 +494,14 @@ struct it87_data { | |||
484 | u16 in_scaled; /* Internal voltage sensors are scaled */ | 494 | u16 in_scaled; /* Internal voltage sensors are scaled */ |
485 | u16 in_internal; /* Bitfield, internal sensors (for labels) */ | 495 | u16 in_internal; /* Bitfield, internal sensors (for labels) */ |
486 | u16 has_in; /* Bitfield, voltage sensors enabled */ | 496 | u16 has_in; /* Bitfield, voltage sensors enabled */ |
487 | u8 in[13][3]; /* [nr][0]=in, [1]=min, [2]=max */ | 497 | u8 in[NUM_VIN][3]; /* [nr][0]=in, [1]=min, [2]=max */ |
488 | u8 has_fan; /* Bitfield, fans enabled */ | 498 | u8 has_fan; /* Bitfield, fans enabled */ |
489 | u16 fan[6][2]; /* Register values, [nr][0]=fan, [1]=min */ | 499 | u16 fan[NUM_FAN][2]; /* Register values, [nr][0]=fan, [1]=min */ |
490 | u8 has_temp; /* Bitfield, temp sensors enabled */ | 500 | u8 has_temp; /* Bitfield, temp sensors enabled */ |
491 | s8 temp[6][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */ | 501 | s8 temp[NUM_TEMP][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */ |
492 | u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */ | 502 | u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */ |
493 | u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */ | 503 | u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */ |
494 | u8 fan_div[3]; /* Register encoding, shifted right */ | 504 | u8 fan_div[NUM_FAN_DIV];/* Register encoding, shifted right */ |
495 | bool has_vid; /* True if VID supported */ | 505 | bool has_vid; /* True if VID supported */ |
496 | u8 vid; /* Register encoding, combined */ | 506 | u8 vid; /* Register encoding, combined */ |
497 | u8 vrm; | 507 | u8 vrm; |
@@ -512,13 +522,13 @@ struct it87_data { | |||
512 | * simple. | 522 | * simple. |
513 | */ | 523 | */ |
514 | u8 has_pwm; /* Bitfield, pwm control enabled */ | 524 | u8 has_pwm; /* Bitfield, pwm control enabled */ |
515 | u8 pwm_ctrl[6]; /* Register value */ | 525 | u8 pwm_ctrl[NUM_PWM]; /* Register value */ |
516 | u8 pwm_duty[6]; /* Manual PWM value set by user */ | 526 | u8 pwm_duty[NUM_PWM]; /* Manual PWM value set by user */ |
517 | u8 pwm_temp_map[6]; /* PWM to temp. chan. mapping (bits 1-0) */ | 527 | u8 pwm_temp_map[NUM_PWM];/* PWM to temp. chan. mapping (bits 1-0) */ |
518 | 528 | ||
519 | /* Automatic fan speed control registers */ | 529 | /* Automatic fan speed control registers */ |
520 | u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */ | 530 | u8 auto_pwm[NUM_AUTO_PWM][4]; /* [nr][3] is hard-coded */ |
521 | s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ | 531 | s8 auto_temp[NUM_AUTO_PWM][5]; /* [nr][0] is point1_temp_hyst */ |
522 | }; | 532 | }; |
523 | 533 | ||
524 | static int adc_lsb(const struct it87_data *data, int nr) | 534 | static int adc_lsb(const struct it87_data *data, int nr) |
@@ -686,7 +696,7 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
686 | it87_write_value(data, IT87_REG_CONFIG, | 696 | it87_write_value(data, IT87_REG_CONFIG, |
687 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); | 697 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); |
688 | } | 698 | } |
689 | for (i = 0; i < ARRAY_SIZE(IT87_REG_VIN); i++) { | 699 | for (i = 0; i < NUM_VIN; i++) { |
690 | if (!(data->has_in & BIT(i))) | 700 | if (!(data->has_in & BIT(i))) |
691 | continue; | 701 | continue; |
692 | 702 | ||
@@ -694,7 +704,7 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
694 | it87_read_value(data, IT87_REG_VIN[i]); | 704 | it87_read_value(data, IT87_REG_VIN[i]); |
695 | 705 | ||
696 | /* VBAT and AVCC don't have limit registers */ | 706 | /* VBAT and AVCC don't have limit registers */ |
697 | if (i >= 8) | 707 | if (i >= NUM_VIN_LIMIT) |
698 | continue; | 708 | continue; |
699 | 709 | ||
700 | data->in[i][1] = | 710 | data->in[i][1] = |
@@ -703,7 +713,7 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
703 | it87_read_value(data, IT87_REG_VIN_MAX(i)); | 713 | it87_read_value(data, IT87_REG_VIN_MAX(i)); |
704 | } | 714 | } |
705 | 715 | ||
706 | for (i = 0; i < 6; i++) { | 716 | for (i = 0; i < NUM_FAN; i++) { |
707 | /* Skip disabled fans */ | 717 | /* Skip disabled fans */ |
708 | if (!(data->has_fan & BIT(i))) | 718 | if (!(data->has_fan & BIT(i))) |
709 | continue; | 719 | continue; |
@@ -720,24 +730,24 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
720 | IT87_REG_FANX_MIN[i]) << 8; | 730 | IT87_REG_FANX_MIN[i]) << 8; |
721 | } | 731 | } |
722 | } | 732 | } |
723 | for (i = 0; i < 6; i++) { | 733 | for (i = 0; i < NUM_TEMP; i++) { |
724 | if (!(data->has_temp & BIT(i))) | 734 | if (!(data->has_temp & BIT(i))) |
725 | continue; | 735 | continue; |
726 | data->temp[i][0] = | 736 | data->temp[i][0] = |
727 | it87_read_value(data, IT87_REG_TEMP(i)); | 737 | it87_read_value(data, IT87_REG_TEMP(i)); |
728 | 738 | ||
729 | /* No limits/offset for additional sensors */ | 739 | if (has_temp_offset(data) && i < NUM_TEMP_OFFSET) |
730 | if (i >= 3) | 740 | data->temp[i][3] = |
741 | it87_read_value(data, | ||
742 | IT87_REG_TEMP_OFFSET[i]); | ||
743 | |||
744 | if (i >= NUM_TEMP_LIMIT) | ||
731 | continue; | 745 | continue; |
732 | 746 | ||
733 | data->temp[i][1] = | 747 | data->temp[i][1] = |
734 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); | 748 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); |
735 | data->temp[i][2] = | 749 | data->temp[i][2] = |
736 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); | 750 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
737 | if (has_temp_offset(data)) | ||
738 | data->temp[i][3] = | ||
739 | it87_read_value(data, | ||
740 | IT87_REG_TEMP_OFFSET[i]); | ||
741 | } | 751 | } |
742 | 752 | ||
743 | /* Newer chips don't have clock dividers */ | 753 | /* Newer chips don't have clock dividers */ |
@@ -757,7 +767,7 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
757 | data->fan_main_ctrl = it87_read_value(data, | 767 | data->fan_main_ctrl = it87_read_value(data, |
758 | IT87_REG_FAN_MAIN_CTRL); | 768 | IT87_REG_FAN_MAIN_CTRL); |
759 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); | 769 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); |
760 | for (i = 0; i < 6; i++) | 770 | for (i = 0; i < NUM_PWM; i++) |
761 | it87_update_pwm_ctrl(data, i); | 771 | it87_update_pwm_ctrl(data, i); |
762 | 772 | ||
763 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); | 773 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
@@ -2509,7 +2519,7 @@ static void it87_init_device(struct platform_device *pdev) | |||
2509 | * these have separate registers for the temperature mapping and the | 2519 | * these have separate registers for the temperature mapping and the |
2510 | * manual duty cycle. | 2520 | * manual duty cycle. |
2511 | */ | 2521 | */ |
2512 | for (i = 0; i < 3; i++) { | 2522 | for (i = 0; i < NUM_AUTO_PWM; i++) { |
2513 | data->pwm_temp_map[i] = i; | 2523 | data->pwm_temp_map[i] = i; |
2514 | data->pwm_duty[i] = 0x7f; /* Full speed */ | 2524 | data->pwm_duty[i] = 0x7f; /* Full speed */ |
2515 | data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ | 2525 | data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ |
@@ -2522,12 +2532,12 @@ static void it87_init_device(struct platform_device *pdev) | |||
2522 | * means -1 degree C, which surprisingly doesn't trigger an alarm, | 2532 | * means -1 degree C, which surprisingly doesn't trigger an alarm, |
2523 | * but is still confusing, so change to 127 degrees C. | 2533 | * but is still confusing, so change to 127 degrees C. |
2524 | */ | 2534 | */ |
2525 | for (i = 0; i < 8; i++) { | 2535 | for (i = 0; i < NUM_VIN_LIMIT; i++) { |
2526 | tmp = it87_read_value(data, IT87_REG_VIN_MIN(i)); | 2536 | tmp = it87_read_value(data, IT87_REG_VIN_MIN(i)); |
2527 | if (tmp == 0xff) | 2537 | if (tmp == 0xff) |
2528 | it87_write_value(data, IT87_REG_VIN_MIN(i), 0); | 2538 | it87_write_value(data, IT87_REG_VIN_MIN(i), 0); |
2529 | } | 2539 | } |
2530 | for (i = 0; i < 3; i++) { | 2540 | for (i = 0; i < NUM_TEMP_LIMIT; i++) { |
2531 | tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i)); | 2541 | tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
2532 | if (tmp == 0xff) | 2542 | if (tmp == 0xff) |
2533 | it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127); | 2543 | it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127); |
@@ -2620,7 +2630,7 @@ static int it87_check_pwm(struct device *dev) | |||
2620 | int i; | 2630 | int i; |
2621 | u8 pwm[3]; | 2631 | u8 pwm[3]; |
2622 | 2632 | ||
2623 | for (i = 0; i < 3; i++) | 2633 | for (i = 0; i < ARRAY_SIZE(pwm); i++) |
2624 | pwm[i] = it87_read_value(data, | 2634 | pwm[i] = it87_read_value(data, |
2625 | IT87_REG_PWM[i]); | 2635 | IT87_REG_PWM[i]); |
2626 | 2636 | ||