Commit 39deb699 authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare

hwmon: (w83795) Simplify temperature sensor type handling

All 3 temperature sensor type sysfs functions (show_temp_mode,
store_temp_mode and show_dts_mode) can be simplified. We don't
create these files when the correponding input isn't in temperature
monitoring mode, so there is no point in handling that case.
Likewise, we don't allow changing inputs from temperature to voltage,
so the code handling this case is dead and can be removed.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent cd316df5
...@@ -66,23 +66,6 @@ MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended"); ...@@ -66,23 +66,6 @@ MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended");
#define W83795_REG_FANIN_CTRL2 0x07 #define W83795_REG_FANIN_CTRL2 0x07
#define W83795_REG_VMIGB_CTRL 0x08 #define W83795_REG_VMIGB_CTRL 0x08
#define TEMP_CTRL_DISABLE 0
#define TEMP_CTRL_TD 1
#define TEMP_CTRL_VSEN 2
#define TEMP_CTRL_TR 3
#define TEMP_CTRL_SHIFT 4
#define TEMP_CTRL_HASIN_SHIFT 5
/* temp mode may effect VSEN17-12 (in20-15) */
static const u16 W83795_REG_TEMP_CTRL[][6] = {
/* Disable, TD, VSEN, TR, register shift value, has_in shift num */
{0x00, 0x01, 0x02, 0x03, 0, 17}, /* TR1 */
{0x00, 0x04, 0x08, 0x0C, 2, 18}, /* TR2 */
{0x00, 0x10, 0x20, 0x30, 4, 19}, /* TR3 */
{0x00, 0x40, 0x80, 0xC0, 6, 20}, /* TR4 */
{0x00, 0x00, 0x02, 0x03, 0, 15}, /* TR5 */
{0x00, 0x00, 0x08, 0x0C, 2, 16}, /* TR6 */
};
#define TEMP_READ 0 #define TEMP_READ 0
#define TEMP_CRIT 1 #define TEMP_CRIT 1
#define TEMP_CRIT_HYST 2 #define TEMP_CRIT_HYST 2
...@@ -359,7 +342,7 @@ struct w83795_data { ...@@ -359,7 +342,7 @@ struct w83795_data {
u8 has_temp; /* Enable monitor temp6-1 or not */ u8 has_temp; /* Enable monitor temp6-1 or not */
s8 temp[6][5]; /* current, crit, crit_hyst, warn, warn_hyst */ s8 temp[6][5]; /* current, crit, crit_hyst, warn, warn_hyst */
u8 temp_read_vrlsb[6]; u8 temp_read_vrlsb[6];
u8 temp_mode; /* bit 0: TR mode, bit 1: TD mode */ u8 temp_mode; /* Bit vector, 0 = TR, 1 = TD */
u8 temp_src[3]; /* Register value */ u8 temp_src[3]; /* Register value */
u8 enable_dts; /* Enable PECI and SB-TSI, u8 enable_dts; /* Enable PECI and SB-TSI,
...@@ -509,13 +492,6 @@ static struct w83795_data *w83795_update_device(struct device *dev) ...@@ -509,13 +492,6 @@ static struct w83795_data *w83795_update_device(struct device *dev)
/* Update temperature */ /* Update temperature */
for (i = 0; i < ARRAY_SIZE(data->temp); i++) { for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
/* even stop monitor, register still keep value, just read out
* it */
if (!(data->has_temp & (1 << i))) {
data->temp[i][TEMP_READ] = 0;
data->temp_read_vrlsb[i] = 0;
continue;
}
data->temp[i][TEMP_READ] = data->temp[i][TEMP_READ] =
w83795_read(client, W83795_REG_TEMP[i][TEMP_READ]); w83795_read(client, W83795_REG_TEMP[i][TEMP_READ]);
data->temp_read_vrlsb[i] = data->temp_read_vrlsb[i] =
...@@ -1163,22 +1139,12 @@ show_dts_mode(struct device *dev, struct device_attribute *attr, char *buf) ...@@ -1163,22 +1139,12 @@ show_dts_mode(struct device *dev, struct device_attribute *attr, char *buf)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct w83795_data *data = i2c_get_clientdata(client); struct w83795_data *data = i2c_get_clientdata(client);
struct sensor_device_attribute_2 *sensor_attr = int tmp;
to_sensor_dev_attr_2(attr);
int index = sensor_attr->index;
u8 tmp;
if (data->enable_dts == 0) if (data->enable_dts & 2)
return sprintf(buf, "%d\n", 0); tmp = 5;
else
if ((data->has_dts >> index) & 0x01) { tmp = 6;
if (data->enable_dts & 2)
tmp = 5;
else
tmp = 6;
} else {
tmp = 0;
}
return sprintf(buf, "%d\n", tmp); return sprintf(buf, "%d\n", tmp);
} }
...@@ -1231,14 +1197,6 @@ store_dts_ext(struct device *dev, struct device_attribute *attr, ...@@ -1231,14 +1197,6 @@ store_dts_ext(struct device *dev, struct device_attribute *attr,
} }
/*
Type 3: Thermal diode
Type 4: Thermistor
Temp5-6, default TR
Temp1-4, default TD
*/
static ssize_t static ssize_t
show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf) show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf)
{ {
...@@ -1247,20 +1205,17 @@ show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf) ...@@ -1247,20 +1205,17 @@ show_temp_mode(struct device *dev, struct device_attribute *attr, char *buf)
struct sensor_device_attribute_2 *sensor_attr = struct sensor_device_attribute_2 *sensor_attr =
to_sensor_dev_attr_2(attr); to_sensor_dev_attr_2(attr);
int index = sensor_attr->index; int index = sensor_attr->index;
u8 tmp; int tmp;
if (data->has_temp >> index & 0x01) { if (data->temp_mode & (1 << index))
if (data->temp_mode >> index & 0x01) tmp = 3; /* Thermal diode */
tmp = 3; else
else tmp = 4; /* Thermistor */
tmp = 4;
} else {
tmp = 0;
}
return sprintf(buf, "%d\n", tmp); return sprintf(buf, "%d\n", tmp);
} }
/* Only for temp1-4 (temp5-6 can only be thermistor) */
static ssize_t static ssize_t
store_temp_mode(struct device *dev, struct device_attribute *attr, store_temp_mode(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
...@@ -1270,45 +1225,31 @@ store_temp_mode(struct device *dev, struct device_attribute *attr, ...@@ -1270,45 +1225,31 @@ store_temp_mode(struct device *dev, struct device_attribute *attr,
struct sensor_device_attribute_2 *sensor_attr = struct sensor_device_attribute_2 *sensor_attr =
to_sensor_dev_attr_2(attr); to_sensor_dev_attr_2(attr);
int index = sensor_attr->index; int index = sensor_attr->index;
int reg_shift;
unsigned long val; unsigned long val;
u8 tmp; u8 tmp;
u32 mask;
if (strict_strtoul(buf, 10, &val) < 0) if (strict_strtoul(buf, 10, &val) < 0)
return -EINVAL; return -EINVAL;
if ((val != 4) && (val != 3)) if ((val != 4) && (val != 3))
return -EINVAL; return -EINVAL;
if ((index > 3) && (val == 3))
return -EINVAL;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
if (val == 3) { if (val == 3) {
val = TEMP_CTRL_TD; /* Thermal diode */
data->has_temp |= 1 << index; val = 0x01;
data->temp_mode |= 1 << index; data->temp_mode |= 1 << index;
} else if (val == 4) { } else if (val == 4) {
val = TEMP_CTRL_TR; /* Thermistor */
data->has_temp |= 1 << index; val = 0x03;
tmp = 1 << index; data->temp_mode &= ~(1 << index);
data->temp_mode &= ~tmp;
} }
if (index > 3) reg_shift = 2 * index;
tmp = w83795_read(client, W83795_REG_TEMP_CTRL1); tmp = w83795_read(client, W83795_REG_TEMP_CTRL2);
else tmp &= ~(0x03 << reg_shift);
tmp = w83795_read(client, W83795_REG_TEMP_CTRL2); tmp |= val << reg_shift;
w83795_write(client, W83795_REG_TEMP_CTRL2, tmp);
mask = 0x03 << W83795_REG_TEMP_CTRL[index][TEMP_CTRL_SHIFT];
tmp &= ~mask;
tmp |= W83795_REG_TEMP_CTRL[index][val];
mask = 1 << W83795_REG_TEMP_CTRL[index][TEMP_CTRL_HASIN_SHIFT];
data->has_in &= ~mask;
if (index > 3)
w83795_write(client, W83795_REG_TEMP_CTRL1, tmp);
else
w83795_write(client, W83795_REG_TEMP_CTRL2, tmp);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
...@@ -1506,7 +1447,7 @@ store_sf_setup(struct device *dev, struct device_attribute *attr, ...@@ -1506,7 +1447,7 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) } show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) }
#define SENSOR_ATTR_TEMP(index) { \ #define SENSOR_ATTR_TEMP(index) { \
SENSOR_ATTR_2(temp##index##_type, S_IRUGO | S_IWUSR, \ SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \
show_temp_mode, store_temp_mode, NOT_USED, index - 1), \ show_temp_mode, store_temp_mode, NOT_USED, index - 1), \
SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \ SENSOR_ATTR_2(temp##index##_input, S_IRUGO, show_temp, \
NULL, TEMP_READ, index - 1), \ NULL, TEMP_READ, index - 1), \
......
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