Commit 8b4b0ab4 authored by Jean Delvare's avatar Jean Delvare Committed by Mark M. Hoffman

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: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarMark M. Hoffman <mhoffman@lightlink.com>
parent f28dc2f7
...@@ -56,37 +56,14 @@ That's why _TEMP2 and _IN4 access the same register ...@@ -56,37 +56,14 @@ That's why _TEMP2 and _IN4 access the same register
#define GL520_REG_VID_INPUT 0x02 #define GL520_REG_VID_INPUT 0x02
#define GL520_REG_IN0_INPUT 0x15 static const u8 GL520_REG_IN_INPUT[] = { 0x15, 0x14, 0x13, 0x0d, 0x0e };
#define GL520_REG_IN0_LIMIT 0x0c static const u8 GL520_REG_IN_LIMIT[] = { 0x0c, 0x09, 0x0a, 0x0b };
#define GL520_REG_IN0_MIN GL520_REG_IN0_LIMIT static const u8 GL520_REG_IN_MIN[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x18 };
#define GL520_REG_IN0_MAX GL520_REG_IN0_LIMIT static const u8 GL520_REG_IN_MAX[] = { 0x0c, 0x09, 0x0a, 0x0b, 0x17 };
#define GL520_REG_IN1_INPUT 0x14 static const u8 GL520_REG_TEMP_INPUT[] = { 0x04, 0x0e };
#define GL520_REG_IN1_LIMIT 0x09 static const u8 GL520_REG_TEMP_MAX[] = { 0x05, 0x17 };
#define GL520_REG_IN1_MIN GL520_REG_IN1_LIMIT static const u8 GL520_REG_TEMP_MAX_HYST[] = { 0x06, 0x18 };
#define GL520_REG_IN1_MAX GL520_REG_IN1_LIMIT
#define GL520_REG_IN2_INPUT 0x13
#define GL520_REG_IN2_LIMIT 0x0a
#define GL520_REG_IN2_MIN GL520_REG_IN2_LIMIT
#define GL520_REG_IN2_MAX GL520_REG_IN2_LIMIT
#define GL520_REG_IN3_INPUT 0x0d
#define GL520_REG_IN3_LIMIT 0x0b
#define GL520_REG_IN3_MIN GL520_REG_IN3_LIMIT
#define GL520_REG_IN3_MAX GL520_REG_IN3_LIMIT
#define GL520_REG_IN4_INPUT 0x0e
#define GL520_REG_IN4_MAX 0x17
#define GL520_REG_IN4_MIN 0x18
#define GL520_REG_TEMP1_INPUT 0x04
#define GL520_REG_TEMP1_MAX 0x05
#define GL520_REG_TEMP1_MAX_HYST 0x06
#define GL520_REG_TEMP2_INPUT 0x0e
#define GL520_REG_TEMP2_MAX 0x17
#define GL520_REG_TEMP2_MAX_HYST 0x18
#define GL520_REG_FAN_INPUT 0x07 #define GL520_REG_FAN_INPUT 0x07
#define GL520_REG_FAN_MIN 0x08 #define GL520_REG_FAN_MIN 0x08
...@@ -191,9 +168,9 @@ static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL); ...@@ -191,9 +168,9 @@ static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL);
sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT) sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT)
#define sysfs_in(n) \ #define sysfs_in(n) \
sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \ sysfs_ro_n(in, n, _input, GL520_REG_IN_INPUT[n]) \
sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \ sysfs_rw_n(in, n, _min, GL520_REG_IN_MIN[n]) \
sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) sysfs_rw_n(in, n, _max, GL520_REG_IN_MAX[n])
#define sysfs_fan(n) \ #define sysfs_fan(n) \
sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \ sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \
...@@ -204,9 +181,9 @@ sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV) ...@@ -204,9 +181,9 @@ sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV)
sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF)
#define sysfs_temp(n) \ #define sysfs_temp(n) \
sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \ sysfs_ro_n(temp, n, _input, GL520_REG_TEMP_INPUT[(n) - 1]) \
sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \ sysfs_rw_n(temp, n, _max, GL520_REG_TEMP_MAX[(n) - 1]) \
sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST) sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP_MAX_HYST[(n) - 1])
#define sysfs_alarms() \ #define sysfs_alarms() \
sysfs_ro(alarms, , GL520_REG_ALARMS) \ sysfs_ro(alarms, , GL520_REG_ALARMS) \
...@@ -717,7 +694,7 @@ static struct gl520_data *gl520_update_device(struct device *dev) ...@@ -717,7 +694,7 @@ static struct gl520_data *gl520_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct gl520_data *data = i2c_get_clientdata(client); struct gl520_data *data = i2c_get_clientdata(client);
int val; int val, i;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
...@@ -729,18 +706,13 @@ static struct gl520_data *gl520_update_device(struct device *dev) ...@@ -729,18 +706,13 @@ static struct gl520_data *gl520_update_device(struct device *dev)
data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK); data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f; data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f;
val = gl520_read_value(client, GL520_REG_IN0_LIMIT); for (i = 0; i < 4; i++) {
data->in_min[0] = val & 0xff; data->in_input[i] = gl520_read_value(client,
data->in_max[0] = (val >> 8) & 0xff; GL520_REG_IN_INPUT[i]);
val = gl520_read_value(client, GL520_REG_IN1_LIMIT); val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]);
data->in_min[1] = val & 0xff; data->in_min[i] = val & 0xff;
data->in_max[1] = (val >> 8) & 0xff; data->in_max[i] = (val >> 8) & 0xff;
val = gl520_read_value(client, GL520_REG_IN2_LIMIT); }
data->in_min[2] = val & 0xff;
data->in_max[2] = (val >> 8) & 0xff;
val = gl520_read_value(client, GL520_REG_IN3_LIMIT);
data->in_min[3] = val & 0xff;
data->in_max[3] = (val >> 8) & 0xff;
val = gl520_read_value(client, GL520_REG_FAN_INPUT); val = gl520_read_value(client, GL520_REG_FAN_INPUT);
data->fan_input[0] = (val >> 8) & 0xff; data->fan_input[0] = (val >> 8) & 0xff;
...@@ -750,9 +722,12 @@ static struct gl520_data *gl520_update_device(struct device *dev) ...@@ -750,9 +722,12 @@ static struct gl520_data *gl520_update_device(struct device *dev)
data->fan_min[0] = (val >> 8) & 0xff; data->fan_min[0] = (val >> 8) & 0xff;
data->fan_min[1] = val & 0xff; data->fan_min[1] = val & 0xff;
data->temp_input[0] = gl520_read_value(client, GL520_REG_TEMP1_INPUT); data->temp_input[0] = gl520_read_value(client,
data->temp_max[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX); GL520_REG_TEMP_INPUT[0]);
data->temp_max_hyst[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX_HYST); data->temp_max[0] = gl520_read_value(client,
GL520_REG_TEMP_MAX[0]);
data->temp_max_hyst[0] = gl520_read_value(client,
GL520_REG_TEMP_MAX_HYST[0]);
val = gl520_read_value(client, GL520_REG_FAN_DIV); val = gl520_read_value(client, GL520_REG_FAN_DIV);
data->fan_div[0] = (val >> 6) & 0x03; data->fan_div[0] = (val >> 6) & 0x03;
...@@ -764,20 +739,21 @@ static struct gl520_data *gl520_update_device(struct device *dev) ...@@ -764,20 +739,21 @@ static struct gl520_data *gl520_update_device(struct device *dev)
val = gl520_read_value(client, GL520_REG_CONF); val = gl520_read_value(client, GL520_REG_CONF);
data->beep_enable = !((val >> 2) & 1); data->beep_enable = !((val >> 2) & 1);
data->in_input[0] = gl520_read_value(client, GL520_REG_IN0_INPUT);
data->in_input[1] = gl520_read_value(client, GL520_REG_IN1_INPUT);
data->in_input[2] = gl520_read_value(client, GL520_REG_IN2_INPUT);
data->in_input[3] = gl520_read_value(client, GL520_REG_IN3_INPUT);
/* Temp1 and Vin4 are the same input */ /* Temp1 and Vin4 are the same input */
if (data->two_temps) { if (data->two_temps) {
data->temp_input[1] = gl520_read_value(client, GL520_REG_TEMP2_INPUT); data->temp_input[1] = gl520_read_value(client,
data->temp_max[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX); GL520_REG_TEMP_INPUT[1]);
data->temp_max_hyst[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX_HYST); data->temp_max[1] = gl520_read_value(client,
GL520_REG_TEMP_MAX[1]);
data->temp_max_hyst[1] = gl520_read_value(client,
GL520_REG_TEMP_MAX_HYST[1]);
} else { } else {
data->in_input[4] = gl520_read_value(client, GL520_REG_IN4_INPUT); data->in_input[4] = gl520_read_value(client,
data->in_min[4] = gl520_read_value(client, GL520_REG_IN4_MIN); GL520_REG_IN_INPUT[4]);
data->in_max[4] = gl520_read_value(client, GL520_REG_IN4_MAX); data->in_min[4] = gl520_read_value(client,
GL520_REG_IN_MIN[4]);
data->in_max[4] = gl520_read_value(client,
GL520_REG_IN_MAX[4]);
} }
data->last_updated = jiffies; data->last_updated = jiffies;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment