aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2010-11-15 15:38:56 -0500
committerJean Delvare <khali@endymion.delvare>2010-11-15 15:38:56 -0500
commit2a2d27da00250c9f117e35653ed5a6a3212e5d77 (patch)
tree01f9d3363878eb50352c1786dc42bddf35017963
parentedff2f8d81ce976ad6895f1d649fcb164be80e3d (diff)
hwmon: (w83795) Print the actual temperature channels as sources
Don't expose raw register values to user-space. Decode and encode temperature channels selected as temperature sources as needed. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
-rw-r--r--drivers/hwmon/w83795.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c
index c941d3eb249e..400558d97f3d 100644
--- a/drivers/hwmon/w83795.c
+++ b/drivers/hwmon/w83795.c
@@ -966,17 +966,18 @@ show_temp_src(struct device *dev, struct device_attribute *attr, char *buf)
966 to_sensor_dev_attr_2(attr); 966 to_sensor_dev_attr_2(attr);
967 struct w83795_data *data = w83795_update_pwm_config(dev); 967 struct w83795_data *data = w83795_update_pwm_config(dev);
968 int index = sensor_attr->index; 968 int index = sensor_attr->index;
969 u8 val = index / 2; 969 u8 tmp = data->temp_src[index / 2];
970 u8 tmp = data->temp_src[val];
971 970
972 if (index & 1) 971 if (index & 1)
973 val = 4; 972 tmp >>= 4; /* Pick high nibble */
974 else 973 else
975 val = 0; 974 tmp &= 0x0f; /* Pick low nibble */
976 tmp >>= val;
977 tmp &= 0x0f;
978 975
979 return sprintf(buf, "%u\n", tmp); 976 /* Look-up the actual temperature channel number */
977 if (tmp >= 4 || tss_map[tmp][index] == TSS_MAP_RESERVED)
978 return -EINVAL; /* Shouldn't happen */
979
980 return sprintf(buf, "%u\n", (unsigned int)tss_map[tmp][index] + 1);
980} 981}
981 982
982static ssize_t 983static ssize_t
@@ -988,12 +989,21 @@ store_temp_src(struct device *dev, struct device_attribute *attr,
988 struct sensor_device_attribute_2 *sensor_attr = 989 struct sensor_device_attribute_2 *sensor_attr =
989 to_sensor_dev_attr_2(attr); 990 to_sensor_dev_attr_2(attr);
990 int index = sensor_attr->index; 991 int index = sensor_attr->index;
991 unsigned long tmp; 992 int tmp;
993 unsigned long channel;
992 u8 val = index / 2; 994 u8 val = index / 2;
993 995
994 if (strict_strtoul(buf, 10, &tmp) < 0) 996 if (strict_strtoul(buf, 10, &channel) < 0 ||
997 channel < 1 || channel > 14)
998 return -EINVAL;
999
1000 /* Check if request can be fulfilled */
1001 for (tmp = 0; tmp < 4; tmp++) {
1002 if (tss_map[tmp][index] == channel - 1)
1003 break;
1004 }
1005 if (tmp == 4) /* No match */
995 return -EINVAL; 1006 return -EINVAL;
996 tmp = SENSORS_LIMIT(tmp, 0, 15);
997 1007
998 mutex_lock(&data->update_lock); 1008 mutex_lock(&data->update_lock);
999 if (index & 1) { 1009 if (index & 1) {