Commit 52bc9802 authored by Gabriele Gorla's avatar Gabriele Gorla Committed by Jean Delvare

hwmon: (adm1026) Fix setting fan_div

Prevent setting fan_div from stomping on other fans that share the
same I2C register.
Signed-off-by: default avatarGabriele Gorla <gorlik@penguintown.net>
Cc: stable@kernel.org
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent 6229cdb2
...@@ -916,7 +916,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, ...@@ -916,7 +916,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
int nr = sensor_attr->index; int nr = sensor_attr->index;
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct adm1026_data *data = i2c_get_clientdata(client); struct adm1026_data *data = i2c_get_clientdata(client);
int val, orig_div, new_div, shift; int val, orig_div, new_div;
val = simple_strtol(buf, NULL, 10); val = simple_strtol(buf, NULL, 10);
new_div = DIV_TO_REG(val); new_div = DIV_TO_REG(val);
...@@ -928,15 +928,17 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, ...@@ -928,15 +928,17 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
data->fan_div[nr] = DIV_FROM_REG(new_div); data->fan_div[nr] = DIV_FROM_REG(new_div);
if (nr < 4) { /* 0 <= nr < 4 */ if (nr < 4) { /* 0 <= nr < 4 */
shift = 2 * nr;
adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3, adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
((DIV_TO_REG(orig_div) & (~(0x03 << shift))) | (DIV_TO_REG(data->fan_div[0]) << 0) |
(new_div << shift))); (DIV_TO_REG(data->fan_div[1]) << 2) |
(DIV_TO_REG(data->fan_div[2]) << 4) |
(DIV_TO_REG(data->fan_div[3]) << 6));
} else { /* 3 < nr < 8 */ } else { /* 3 < nr < 8 */
shift = 2 * (nr - 4);
adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7, adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) | (DIV_TO_REG(data->fan_div[4]) << 0) |
(new_div << shift))); (DIV_TO_REG(data->fan_div[5]) << 2) |
(DIV_TO_REG(data->fan_div[6]) << 4) |
(DIV_TO_REG(data->fan_div[7]) << 6));
} }
if (data->fan_div[nr] != orig_div) { if (data->fan_div[nr] != orig_div) {
......
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