aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/gl520sm.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2007-11-04 17:44:52 -0500
committerMark M. Hoffman <mhoffman@lightlink.com>2008-02-07 20:39:41 -0500
commit8b4b0ab41bb0a5e72b6fceb9a7aff303c88960b4 (patch)
tree2d01ab14c447fe9b415e81a872854930ee1ac614 /drivers/hwmon/gl520sm.c
parentf28dc2f78bbcbf07b8a084fcd89cf6b4256f0664 (diff)
hwmon: (gl520sm) Put register addresses in arrays
This allows for some code refactoring, making the binary slightly smaller. This is also required to use dynamic sysfs callbacks for voltage and temperature files. Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon/gl520sm.c')
-rw-r--r--drivers/hwmon/gl520sm.c104
1 files changed, 40 insertions, 64 deletions
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index 4fdfe820294b..7c3b73a1623d 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -56,37 +56,14 @@ That's why _TEMP2 and _IN4 access the same register
56 56
57#define GL520_REG_VID_INPUT 0x02 57#define GL520_REG_VID_INPUT 0x02
58 58
59#define GL520_REG_IN0_INPUT 0x15 59static const u8 GL520_REG_IN_INPUT[] = { 0x15, 0x14, 0x13, 0x0d, 0x0e };
60#define GL520_REG_IN0_LIMIT 0x0c 60static const u8 GL520_REG_IN_LIMIT[] = { 0x0c, 0x09, 0x0a, 0x0b };
61#define GL520_REG_IN0_MIN GL520_REG_IN0_LIMIT 61static const u8 GL520_REG_IN_MIN[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x18 };
62#define GL520_REG_IN0_MAX GL520_REG_IN0_LIMIT 62static const u8 GL520_REG_IN_MAX[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x17 };
63 63
64#define GL520_REG_IN1_INPUT 0x14 64static const u8 GL520_REG_TEMP_INPUT[] = { 0x04, 0x0e };
65#define GL520_REG_IN1_LIMIT 0x09 65static const u8 GL520_REG_TEMP_MAX[] = { 0x05, 0x17 };
66#define GL520_REG_IN1_MIN GL520_REG_IN1_LIMIT 66static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 };
67#define GL520_REG_IN1_MAX GL520_REG_IN1_LIMIT
68
69#define GL520_REG_IN2_INPUT 0x13
70#define GL520_REG_IN2_LIMIT 0x0a
71#define GL520_REG_IN2_MIN GL520_REG_IN2_LIMIT
72#define GL520_REG_IN2_MAX GL520_REG_IN2_LIMIT
73
74#define GL520_REG_IN3_INPUT 0x0d
75#define GL520_REG_IN3_LIMIT 0x0b
76#define GL520_REG_IN3_MIN GL520_REG_IN3_LIMIT
77#define GL520_REG_IN3_MAX GL520_REG_IN3_LIMIT
78
79#define GL520_REG_IN4_INPUT 0x0e
80#define GL520_REG_IN4_MAX 0x17
81#define GL520_REG_IN4_MIN 0x18
82
83#define GL520_REG_TEMP1_INPUT 0x04
84#define GL520_REG_TEMP1_MAX 0x05
85#define GL520_REG_TEMP1_MAX_HYST 0x06
86
87#define GL520_REG_TEMP2_INPUT 0x0e
88#define GL520_REG_TEMP2_MAX 0x17
89#define GL520_REG_TEMP2_MAX_HYST 0x18
90 67
91#define GL520_REG_FAN_INPUT 0x07 68#define GL520_REG_FAN_INPUT 0x07
92#define GL520_REG_FAN_MIN 0x08 69#define GL520_REG_FAN_MIN 0x08
@@ -191,9 +168,9 @@ static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL);
191sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT) 168sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT)
192 169
193#define sysfs_in(n) \ 170#define sysfs_in(n) \
194sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \ 171sysfs_ro_n(in, n, _input, GL520_REG_IN_INPUT[n]) \
195sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \ 172sysfs_rw_n(in, n, _min, GL520_REG_IN_MIN[n]) \
196sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) 173sysfs_rw_n(in, n, _max, GL520_REG_IN_MAX[n])
197 174
198#define sysfs_fan(n) \ 175#define sysfs_fan(n) \
199sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \ 176sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \
@@ -204,9 +181,9 @@ sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV)
204sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) 181sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF)
205 182
206#define sysfs_temp(n) \ 183#define sysfs_temp(n) \
207sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \ 184sysfs_ro_n(temp, n, _input, GL520_REG_TEMP_INPUT[(n) - 1]) \
208sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \ 185sysfs_rw_n(temp, n, _max, GL520_REG_TEMP_MAX[(n) - 1]) \
209sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST) 186sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP_MAX_HYST[(n) - 1])
210 187
211#define sysfs_alarms() \ 188#define sysfs_alarms() \
212sysfs_ro(alarms, , GL520_REG_ALARMS) \ 189sysfs_ro(alarms, , GL520_REG_ALARMS) \
@@ -717,7 +694,7 @@ static struct gl520_data *gl520_update_device(struct device *dev)
717{ 694{
718 struct i2c_client *client = to_i2c_client(dev); 695 struct i2c_client *client = to_i2c_client(dev);
719 struct gl520_data *data = i2c_get_clientdata(client); 696 struct gl520_data *data = i2c_get_clientdata(client);
720 int val; 697 int val, i;
721 698
722 mutex_lock(&data->update_lock); 699 mutex_lock(&data->update_lock);
723 700
@@ -729,18 +706,13 @@ static struct gl520_data *gl520_update_device(struct device *dev)
729 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); 706 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
730 data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f; 707 data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f;
731 708
732 val = gl520_read_value(client, GL520_REG_IN0_LIMIT); 709 for (i = 0; i < 4; i++) {
733 data->in_min[0] = val & 0xff; 710 data->in_input[i] = gl520_read_value(client,
734 data->in_max[0] = (val >> 8) & 0xff; 711 GL520_REG_IN_INPUT[i]);
735 val = gl520_read_value(client, GL520_REG_IN1_LIMIT); 712 val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]);
736 data->in_min[1] = val & 0xff; 713 data->in_min[i] = val & 0xff;
737 data->in_max[1] = (val >> 8) & 0xff; 714 data->in_max[i] = (val >> 8) & 0xff;
738 val = gl520_read_value(client, GL520_REG_IN2_LIMIT); 715 }
739 data->in_min[2] = val & 0xff;
740 data->in_max[2] = (val >> 8) & 0xff;
741 val = gl520_read_value(client, GL520_REG_IN3_LIMIT);
742 data->in_min[3] = val & 0xff;
743 data->in_max[3] = (val >> 8) & 0xff;
744 716
745 val = gl520_read_value(client, GL520_REG_FAN_INPUT); 717 val = gl520_read_value(client, GL520_REG_FAN_INPUT);
746 data->fan_input[0] = (val >> 8) & 0xff; 718 data->fan_input[0] = (val >> 8) & 0xff;
@@ -750,9 +722,12 @@ static struct gl520_data *gl520_update_device(struct device *dev)
750 data->fan_min[0] = (val >> 8) & 0xff; 722 data->fan_min[0] = (val >> 8) & 0xff;
751 data->fan_min[1] = val & 0xff; 723 data->fan_min[1] = val & 0xff;
752 724
753 data->temp_input[0] = gl520_read_value(client, GL520_REG_TEMP1_INPUT); 725 data->temp_input[0] = gl520_read_value(client,
754 data->temp_max[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX); 726 GL520_REG_TEMP_INPUT[0]);
755 data->temp_max_hyst[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX_HYST); 727 data->temp_max[0] = gl520_read_value(client,
728 GL520_REG_TEMP_MAX[0]);
729 data->temp_max_hyst[0] = gl520_read_value(client,
730 GL520_REG_TEMP_MAX_HYST[0]);
756 731
757 val = gl520_read_value(client, GL520_REG_FAN_DIV); 732 val = gl520_read_value(client, GL520_REG_FAN_DIV);
758 data->fan_div[0] = (val >> 6) & 0x03; 733 data->fan_div[0] = (val >> 6) & 0x03;
@@ -764,20 +739,21 @@ static struct gl520_data *gl520_update_device(struct device *dev)
764 val = gl520_read_value(client, GL520_REG_CONF); 739 val = gl520_read_value(client, GL520_REG_CONF);
765 data->beep_enable = !((val >> 2) & 1); 740 data->beep_enable = !((val >> 2) & 1);
766 741
767 data->in_input[0] = gl520_read_value(client, GL520_REG_IN0_INPUT);
768 data->in_input[1] = gl520_read_value(client, GL520_REG_IN1_INPUT);
769 data->in_input[2] = gl520_read_value(client, GL520_REG_IN2_INPUT);
770 data->in_input[3] = gl520_read_value(client, GL520_REG_IN3_INPUT);
771
772 /* Temp1 and Vin4 are the same input */ 742 /* Temp1 and Vin4 are the same input */
773 if (data->two_temps) { 743 if (data->two_temps) {
774 data->temp_input[1] = gl520_read_value(client, GL520_REG_TEMP2_INPUT); 744 data->temp_input[1] = gl520_read_value(client,
775 data->temp_max[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX); 745 GL520_REG_TEMP_INPUT[1]);
776 data->temp_max_hyst[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX_HYST); 746 data->temp_max[1] = gl520_read_value(client,
747 GL520_REG_TEMP_MAX[1]);
748 data->temp_max_hyst[1] = gl520_read_value(client,
749 GL520_REG_TEMP_MAX_HYST[1]);
777 } else { 750 } else {
778 data->in_input[4] = gl520_read_value(client, GL520_REG_IN4_INPUT); 751 data->in_input[4] = gl520_read_value(client,
779 data->in_min[4] = gl520_read_value(client, GL520_REG_IN4_MIN); 752 GL520_REG_IN_INPUT[4]);
780 data->in_max[4] = gl520_read_value(client, GL520_REG_IN4_MAX); 753 data->in_min[4] = gl520_read_value(client,
754 GL520_REG_IN_MIN[4]);
755 data->in_max[4] = gl520_read_value(client,
756 GL520_REG_IN_MAX[4]);
781 } 757 }
782 758
783 data->last_updated = jiffies; 759 data->last_updated = jiffies;