Commit df48ed80 authored by Jim Cromie's avatar Jim Cromie Committed by Mark M. Hoffman

hwmon: (w83627hf) hoist nr-1 offset out of show-store-temp-X

This hoists nr-1 offset out of (show|store)_temp_*(.*) callbacks, and into
SENSOR_DEVICE_ATTRs for sysfs tempN_X files.  It also combines
temp[1] and temp_add[2] (array) fields in w83627hf_data into 3 elem arrays,
which simplifies special-case handling of nr, allowing simplification
of callback bodies and rerolling a flattened loop in
w83627hf_update_device(struct device *dev).

The array conversion changes temp[1] from u8 to u16, but this was
happening implicitly via the helper functions anyway.
Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
Acked-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarMark M. Hoffman <mhoffman@lightlink.com>
parent 38fb56a2
...@@ -173,17 +173,12 @@ superio_exit(void) ...@@ -173,17 +173,12 @@ superio_exit(void)
#define W83781D_REG_FAN_MIN(nr) (0x3a + (nr)) #define W83781D_REG_FAN_MIN(nr) (0x3a + (nr))
#define W83781D_REG_FAN(nr) (0x27 + (nr)) #define W83781D_REG_FAN(nr) (0x27 + (nr))
#define W83781D_REG_TEMP2_CONFIG 0x152 #define W83627HF_REG_TEMP2_CONFIG 0x152
#define W83781D_REG_TEMP3_CONFIG 0x252 #define W83627HF_REG_TEMP3_CONFIG 0x252
#define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \ /* these are zero-based, unlike config constants above */
((nr == 2) ? (0x0150) : \ static const u16 w83627hf_reg_temp[] = { 0x27, 0x150, 0x250 };
(0x27))) static const u16 w83627hf_reg_temp_hyst[] = { 0x3A, 0x153, 0x253 };
#define W83781D_REG_TEMP_HYST(nr) ((nr == 3) ? (0x253) : \ static const u16 w83627hf_reg_temp_over[] = { 0x39, 0x155, 0x255 };
((nr == 2) ? (0x153) : \
(0x3A)))
#define W83781D_REG_TEMP_OVER(nr) ((nr == 3) ? (0x255) : \
((nr == 2) ? (0x155) : \
(0x39)))
#define W83781D_REG_BANK 0x4E #define W83781D_REG_BANK 0x4E
...@@ -360,12 +355,9 @@ struct w83627hf_data { ...@@ -360,12 +355,9 @@ struct w83627hf_data {
u8 in_min[9]; /* Register value */ u8 in_min[9]; /* Register value */
u8 fan[3]; /* Register value */ u8 fan[3]; /* Register value */
u8 fan_min[3]; /* Register value */ u8 fan_min[3]; /* Register value */
u8 temp; u16 temp[3]; /* Register value */
u8 temp_max; /* Register value */ u16 temp_max[3]; /* Register value */
u8 temp_max_hyst; /* Register value */ u16 temp_max_hyst[3]; /* Register value */
u16 temp_add[2]; /* Register value */
u16 temp_max_add[2]; /* Register value */
u16 temp_max_hyst_add[2]; /* Register value */
u8 fan_div[3]; /* Register encoding, shifted right */ u8 fan_div[3]; /* Register encoding, shifted right */
u8 vid; /* Register encoding, combined */ u8 vid; /* Register encoding, combined */
u32 alarms; /* Register encoding, combined */ u32 alarms; /* Register encoding, combined */
...@@ -611,12 +603,10 @@ show_temp(struct device *dev, struct device_attribute *devattr, char *buf) ...@@ -611,12 +603,10 @@ show_temp(struct device *dev, struct device_attribute *devattr, char *buf)
{ {
int nr = to_sensor_dev_attr(devattr)->index; int nr = to_sensor_dev_attr(devattr)->index;
struct w83627hf_data *data = w83627hf_update_device(dev); struct w83627hf_data *data = w83627hf_update_device(dev);
if (nr >= 2) { /* TEMP2 and TEMP3 */
return sprintf(buf, "%ld\n", u16 tmp = data->temp[nr];
(long)LM75_TEMP_FROM_REG(data->temp_add[nr-2])); return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp)
} else { /* TEMP1 */ : (long) TEMP_FROM_REG(tmp));
return sprintf(buf, "%ld\n", (long)TEMP_FROM_REG(data->temp));
}
} }
static ssize_t static ssize_t
...@@ -625,13 +615,10 @@ show_temp_max(struct device *dev, struct device_attribute *devattr, ...@@ -625,13 +615,10 @@ show_temp_max(struct device *dev, struct device_attribute *devattr,
{ {
int nr = to_sensor_dev_attr(devattr)->index; int nr = to_sensor_dev_attr(devattr)->index;
struct w83627hf_data *data = w83627hf_update_device(dev); struct w83627hf_data *data = w83627hf_update_device(dev);
if (nr >= 2) { /* TEMP2 and TEMP3 */
return sprintf(buf, "%ld\n", u16 tmp = data->temp_max[nr];
(long)LM75_TEMP_FROM_REG(data->temp_max_add[nr-2])); return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp)
} else { /* TEMP1 */ : (long) TEMP_FROM_REG(tmp));
return sprintf(buf, "%ld\n",
(long)TEMP_FROM_REG(data->temp_max));
}
} }
static ssize_t static ssize_t
...@@ -640,13 +627,10 @@ show_temp_max_hyst(struct device *dev, struct device_attribute *devattr, ...@@ -640,13 +627,10 @@ show_temp_max_hyst(struct device *dev, struct device_attribute *devattr,
{ {
int nr = to_sensor_dev_attr(devattr)->index; int nr = to_sensor_dev_attr(devattr)->index;
struct w83627hf_data *data = w83627hf_update_device(dev); struct w83627hf_data *data = w83627hf_update_device(dev);
if (nr >= 2) { /* TEMP2 and TEMP3 */
return sprintf(buf, "%ld\n", u16 tmp = data->temp_max_hyst[nr];
(long)LM75_TEMP_FROM_REG(data->temp_max_hyst_add[nr-2])); return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp)
} else { /* TEMP1 */ : (long) TEMP_FROM_REG(tmp));
return sprintf(buf, "%ld\n",
(long)TEMP_FROM_REG(data->temp_max_hyst));
}
} }
static ssize_t static ssize_t
...@@ -656,18 +640,11 @@ store_temp_max(struct device *dev, struct device_attribute *devattr, ...@@ -656,18 +640,11 @@ store_temp_max(struct device *dev, struct device_attribute *devattr,
int nr = to_sensor_dev_attr(devattr)->index; int nr = to_sensor_dev_attr(devattr)->index;
struct w83627hf_data *data = dev_get_drvdata(dev); struct w83627hf_data *data = dev_get_drvdata(dev);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val);
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max[nr] = tmp;
if (nr >= 2) { /* TEMP2 and TEMP3 */ w83627hf_write_value(data, w83627hf_reg_temp_over[nr], tmp);
data->temp_max_add[nr-2] = LM75_TEMP_TO_REG(val);
w83627hf_write_value(data, W83781D_REG_TEMP_OVER(nr),
data->temp_max_add[nr-2]);
} else { /* TEMP1 */
data->temp_max = TEMP_TO_REG(val);
w83627hf_write_value(data, W83781D_REG_TEMP_OVER(nr),
data->temp_max);
}
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
...@@ -679,29 +656,22 @@ store_temp_max_hyst(struct device *dev, struct device_attribute *devattr, ...@@ -679,29 +656,22 @@ store_temp_max_hyst(struct device *dev, struct device_attribute *devattr,
int nr = to_sensor_dev_attr(devattr)->index; int nr = to_sensor_dev_attr(devattr)->index;
struct w83627hf_data *data = dev_get_drvdata(dev); struct w83627hf_data *data = dev_get_drvdata(dev);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val);
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_max_hyst[nr] = tmp;
if (nr >= 2) { /* TEMP2 and TEMP3 */ w83627hf_write_value(data, w83627hf_reg_temp_hyst[nr], tmp);
data->temp_max_hyst_add[nr-2] = LM75_TEMP_TO_REG(val);
w83627hf_write_value(data, W83781D_REG_TEMP_HYST(nr),
data->temp_max_hyst_add[nr-2]);
} else { /* TEMP1 */
data->temp_max_hyst = TEMP_TO_REG(val);
w83627hf_write_value(data, W83781D_REG_TEMP_HYST(nr),
data->temp_max_hyst);
}
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
#define sysfs_temp_decl(offset) \ #define sysfs_temp_decl(offset) \
static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
show_temp, NULL, offset); \ show_temp, NULL, offset - 1); \
static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO|S_IWUSR, \ static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO|S_IWUSR, \
show_temp_max, store_temp_max, offset); \ show_temp_max, store_temp_max, offset - 1); \
static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO|S_IWUSR, \ static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO|S_IWUSR, \
show_temp_max_hyst, store_temp_max_hyst, offset); show_temp_max_hyst, store_temp_max_hyst, offset - 1);
sysfs_temp_decl(1); sysfs_temp_decl(1);
sysfs_temp_decl(2); sysfs_temp_decl(2);
...@@ -1514,23 +1484,23 @@ static void __devinit w83627hf_init_device(struct platform_device *pdev) ...@@ -1514,23 +1484,23 @@ static void __devinit w83627hf_init_device(struct platform_device *pdev)
if(init) { if(init) {
/* Enable temp2 */ /* Enable temp2 */
tmp = w83627hf_read_value(data, W83781D_REG_TEMP2_CONFIG); tmp = w83627hf_read_value(data, W83627HF_REG_TEMP2_CONFIG);
if (tmp & 0x01) { if (tmp & 0x01) {
dev_warn(&pdev->dev, "Enabling temp2, readings " dev_warn(&pdev->dev, "Enabling temp2, readings "
"might not make sense\n"); "might not make sense\n");
w83627hf_write_value(data, W83781D_REG_TEMP2_CONFIG, w83627hf_write_value(data, W83627HF_REG_TEMP2_CONFIG,
tmp & 0xfe); tmp & 0xfe);
} }
/* Enable temp3 */ /* Enable temp3 */
if (type != w83697hf) { if (type != w83697hf) {
tmp = w83627hf_read_value(data, tmp = w83627hf_read_value(data,
W83781D_REG_TEMP3_CONFIG); W83627HF_REG_TEMP3_CONFIG);
if (tmp & 0x01) { if (tmp & 0x01) {
dev_warn(&pdev->dev, "Enabling temp3, " dev_warn(&pdev->dev, "Enabling temp3, "
"readings might not make sense\n"); "readings might not make sense\n");
w83627hf_write_value(data, w83627hf_write_value(data,
W83781D_REG_TEMP3_CONFIG, tmp & 0xfe); W83627HF_REG_TEMP3_CONFIG, tmp & 0xfe);
} }
} }
} }
...@@ -1563,7 +1533,7 @@ static void w83627hf_update_fan_div(struct w83627hf_data *data) ...@@ -1563,7 +1533,7 @@ static void w83627hf_update_fan_div(struct w83627hf_data *data)
static struct w83627hf_data *w83627hf_update_device(struct device *dev) static struct w83627hf_data *w83627hf_update_device(struct device *dev)
{ {
struct w83627hf_data *data = dev_get_drvdata(dev); struct w83627hf_data *data = dev_get_drvdata(dev);
int i; int i, num_temps = (data->type == w83697hf) ? 2 : 3;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
...@@ -1616,25 +1586,13 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev) ...@@ -1616,25 +1586,13 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
break; break;
} }
} }
for (i = 0; i < num_temps; i++) {
data->temp = w83627hf_read_value(data, W83781D_REG_TEMP(1)); data->temp[i] = w83627hf_read_value(
data->temp_max = data, w83627hf_reg_temp[i]);
w83627hf_read_value(data, W83781D_REG_TEMP_OVER(1)); data->temp_max[i] = w83627hf_read_value(
data->temp_max_hyst = data, w83627hf_reg_temp_over[i]);
w83627hf_read_value(data, W83781D_REG_TEMP_HYST(1)); data->temp_max_hyst[i] = w83627hf_read_value(
data->temp_add[0] = data, w83627hf_reg_temp_hyst[i]);
w83627hf_read_value(data, W83781D_REG_TEMP(2));
data->temp_max_add[0] =
w83627hf_read_value(data, W83781D_REG_TEMP_OVER(2));
data->temp_max_hyst_add[0] =
w83627hf_read_value(data, W83781D_REG_TEMP_HYST(2));
if (data->type != w83697hf) {
data->temp_add[1] =
w83627hf_read_value(data, W83781D_REG_TEMP(3));
data->temp_max_add[1] =
w83627hf_read_value(data, W83781D_REG_TEMP_OVER(3));
data->temp_max_hyst_add[1] =
w83627hf_read_value(data, W83781D_REG_TEMP_HYST(3));
} }
w83627hf_update_fan_div(data); w83627hf_update_fan_div(data);
......
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