diff options
author | Jean Delvare <khali@linux-fr.org> | 2010-11-15 15:38:56 -0500 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2010-11-15 15:38:56 -0500 |
commit | edff2f8d81ce976ad6895f1d649fcb164be80e3d (patch) | |
tree | 515492332c52068c084a5e362254cc8f98899356 /drivers/hwmon/w83795.c | |
parent | d5ab845a13de7ff2d195917dad8879acfb6d8ff9 (diff) |
hwmon: (w83795) List all usable temperature sources
Temperature sources are not correlated directly with temperature
channels. A look-up table is required to find out which temperature
sources can be used depending on which temperature channels (both
analog and digital) are enabled.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
Diffstat (limited to 'drivers/hwmon/w83795.c')
-rw-r--r-- | drivers/hwmon/w83795.c | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/drivers/hwmon/w83795.c b/drivers/hwmon/w83795.c index 95b1f860c14e..c941d3eb249e 100644 --- a/drivers/hwmon/w83795.c +++ b/drivers/hwmon/w83795.c | |||
@@ -178,6 +178,14 @@ static const u8 IN_LSB_SHIFT_IDX[][2] = { | |||
178 | 178 | ||
179 | #define W83795_REG_TSS(index) (0x209 + (index)) | 179 | #define W83795_REG_TSS(index) (0x209 + (index)) |
180 | 180 | ||
181 | #define TSS_MAP_RESERVED 0xff | ||
182 | static const u8 tss_map[4][6] = { | ||
183 | { 0, 1, 2, 3, 4, 5}, | ||
184 | { 6, 7, 8, 9, 0, 1}, | ||
185 | {10, 11, 12, 13, 2, 3}, | ||
186 | { 4, 5, 4, 5, TSS_MAP_RESERVED, TSS_MAP_RESERVED}, | ||
187 | }; | ||
188 | |||
181 | #define PWM_OUTPUT 0 | 189 | #define PWM_OUTPUT 0 |
182 | #define PWM_FREQ 1 | 190 | #define PWM_FREQ 1 |
183 | #define PWM_START 2 | 191 | #define PWM_START 2 |
@@ -930,6 +938,27 @@ show_pwm_mode(struct device *dev, struct device_attribute *attr, char *buf) | |||
930 | return sprintf(buf, "%u\n", mode); | 938 | return sprintf(buf, "%u\n", mode); |
931 | } | 939 | } |
932 | 940 | ||
941 | /* | ||
942 | * Check whether a given temperature source can ever be useful. | ||
943 | * Returns the number of selectable temperature channels which are | ||
944 | * enabled. | ||
945 | */ | ||
946 | static int w83795_tss_useful(const struct w83795_data *data, int tsrc) | ||
947 | { | ||
948 | int useful = 0, i; | ||
949 | |||
950 | for (i = 0; i < 4; i++) { | ||
951 | if (tss_map[i][tsrc] == TSS_MAP_RESERVED) | ||
952 | continue; | ||
953 | if (tss_map[i][tsrc] < 6) /* Analog */ | ||
954 | useful += (data->has_temp >> tss_map[i][tsrc]) & 1; | ||
955 | else /* Digital */ | ||
956 | useful += (data->has_dts >> (tss_map[i][tsrc] - 6)) & 1; | ||
957 | } | ||
958 | |||
959 | return useful; | ||
960 | } | ||
961 | |||
933 | static ssize_t | 962 | static ssize_t |
934 | show_temp_src(struct device *dev, struct device_attribute *attr, char *buf) | 963 | show_temp_src(struct device *dev, struct device_attribute *attr, char *buf) |
935 | { | 964 | { |
@@ -1608,8 +1637,6 @@ store_sf_setup(struct device *dev, struct device_attribute *attr, | |||
1608 | SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ | 1637 | SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ |
1609 | show_alarm_beep, store_beep, BEEP_ENABLE, \ | 1638 | show_alarm_beep, store_beep, BEEP_ENABLE, \ |
1610 | index + (index > 4 ? 11 : 17)), \ | 1639 | index + (index > 4 ? 11 : 17)), \ |
1611 | SENSOR_ATTR_2(temp##index##_source_sel, S_IWUSR | S_IRUGO, \ | ||
1612 | show_temp_src, store_temp_src, NOT_USED, index - 1), \ | ||
1613 | SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \ | 1640 | SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \ |
1614 | show_temp_pwm_enable, store_temp_pwm_enable, \ | 1641 | show_temp_pwm_enable, store_temp_pwm_enable, \ |
1615 | TEMP_PWM_ENABLE, index - 1), \ | 1642 | TEMP_PWM_ENABLE, index - 1), \ |
@@ -1695,7 +1722,7 @@ static const struct sensor_device_attribute_2 w83795_fan[][4] = { | |||
1695 | SENSOR_ATTR_FAN(14), | 1722 | SENSOR_ATTR_FAN(14), |
1696 | }; | 1723 | }; |
1697 | 1724 | ||
1698 | static const struct sensor_device_attribute_2 w83795_temp[][29] = { | 1725 | static const struct sensor_device_attribute_2 w83795_temp[][28] = { |
1699 | SENSOR_ATTR_TEMP(1), | 1726 | SENSOR_ATTR_TEMP(1), |
1700 | SENSOR_ATTR_TEMP(2), | 1727 | SENSOR_ATTR_TEMP(2), |
1701 | SENSOR_ATTR_TEMP(3), | 1728 | SENSOR_ATTR_TEMP(3), |
@@ -1726,6 +1753,21 @@ static const struct sensor_device_attribute_2 w83795_pwm[][8] = { | |||
1726 | SENSOR_ATTR_PWM(8), | 1753 | SENSOR_ATTR_PWM(8), |
1727 | }; | 1754 | }; |
1728 | 1755 | ||
1756 | static const struct sensor_device_attribute_2 w83795_tss[6] = { | ||
1757 | SENSOR_ATTR_2(temp1_source_sel, S_IWUSR | S_IRUGO, | ||
1758 | show_temp_src, store_temp_src, NOT_USED, 0), | ||
1759 | SENSOR_ATTR_2(temp2_source_sel, S_IWUSR | S_IRUGO, | ||
1760 | show_temp_src, store_temp_src, NOT_USED, 1), | ||
1761 | SENSOR_ATTR_2(temp3_source_sel, S_IWUSR | S_IRUGO, | ||
1762 | show_temp_src, store_temp_src, NOT_USED, 2), | ||
1763 | SENSOR_ATTR_2(temp4_source_sel, S_IWUSR | S_IRUGO, | ||
1764 | show_temp_src, store_temp_src, NOT_USED, 3), | ||
1765 | SENSOR_ATTR_2(temp5_source_sel, S_IWUSR | S_IRUGO, | ||
1766 | show_temp_src, store_temp_src, NOT_USED, 4), | ||
1767 | SENSOR_ATTR_2(temp6_source_sel, S_IWUSR | S_IRUGO, | ||
1768 | show_temp_src, store_temp_src, NOT_USED, 5), | ||
1769 | }; | ||
1770 | |||
1729 | static const struct sensor_device_attribute_2 sda_single_files[] = { | 1771 | static const struct sensor_device_attribute_2 sda_single_files[] = { |
1730 | SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep, | 1772 | SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep, |
1731 | store_chassis_clear, ALARM_STATUS, 46), | 1773 | store_chassis_clear, ALARM_STATUS, 46), |
@@ -1890,6 +1932,15 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *, | |||
1890 | } | 1932 | } |
1891 | } | 1933 | } |
1892 | 1934 | ||
1935 | for (i = 0; i < ARRAY_SIZE(w83795_tss); i++) { | ||
1936 | j = w83795_tss_useful(data, i); | ||
1937 | if (!j) | ||
1938 | continue; | ||
1939 | err = fn(dev, &w83795_tss[i].dev_attr); | ||
1940 | if (err) | ||
1941 | return err; | ||
1942 | } | ||
1943 | |||
1893 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { | 1944 | for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) { |
1894 | err = fn(dev, &sda_single_files[i].dev_attr); | 1945 | err = fn(dev, &sda_single_files[i].dev_attr); |
1895 | if (err) | 1946 | if (err) |