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>

authored by Jean Delvare and committed by Jean Delvare edff2f8d d5ab845a

+54 -3
+54 -3
drivers/hwmon/w83795.c
··· 178 179 #define W83795_REG_TSS(index) (0x209 + (index)) 180 181 #define PWM_OUTPUT 0 182 #define PWM_FREQ 1 183 #define PWM_START 2 ··· 938 return sprintf(buf, "%u\n", mode); 939 } 940 941 static ssize_t 942 show_temp_src(struct device *dev, struct device_attribute *attr, char *buf) 943 { ··· 1637 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ 1638 show_alarm_beep, store_beep, BEEP_ENABLE, \ 1639 index + (index > 4 ? 11 : 17)), \ 1640 - SENSOR_ATTR_2(temp##index##_source_sel, S_IWUSR | S_IRUGO, \ 1641 - show_temp_src, store_temp_src, NOT_USED, index - 1), \ 1642 SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \ 1643 show_temp_pwm_enable, store_temp_pwm_enable, \ 1644 TEMP_PWM_ENABLE, index - 1), \ ··· 1722 SENSOR_ATTR_FAN(14), 1723 }; 1724 1725 - static const struct sensor_device_attribute_2 w83795_temp[][29] = { 1726 SENSOR_ATTR_TEMP(1), 1727 SENSOR_ATTR_TEMP(2), 1728 SENSOR_ATTR_TEMP(3), ··· 1751 SENSOR_ATTR_PWM(6), 1752 SENSOR_ATTR_PWM(7), 1753 SENSOR_ATTR_PWM(8), 1754 }; 1755 1756 static const struct sensor_device_attribute_2 sda_single_files[] = { ··· 1930 if (err) 1931 return err; 1932 } 1933 } 1934 1935 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {
··· 178 179 #define W83795_REG_TSS(index) (0x209 + (index)) 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 + 189 #define PWM_OUTPUT 0 190 #define PWM_FREQ 1 191 #define PWM_START 2 ··· 930 return sprintf(buf, "%u\n", mode); 931 } 932 933 + /* 934 + * Check whether a given temperature source can ever be useful. 935 + * Returns the number of selectable temperature channels which are 936 + * enabled. 937 + */ 938 + static int w83795_tss_useful(const struct w83795_data *data, int tsrc) 939 + { 940 + int useful = 0, i; 941 + 942 + for (i = 0; i < 4; i++) { 943 + if (tss_map[i][tsrc] == TSS_MAP_RESERVED) 944 + continue; 945 + if (tss_map[i][tsrc] < 6) /* Analog */ 946 + useful += (data->has_temp >> tss_map[i][tsrc]) & 1; 947 + else /* Digital */ 948 + useful += (data->has_dts >> (tss_map[i][tsrc] - 6)) & 1; 949 + } 950 + 951 + return useful; 952 + } 953 + 954 static ssize_t 955 show_temp_src(struct device *dev, struct device_attribute *attr, char *buf) 956 { ··· 1608 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ 1609 show_alarm_beep, store_beep, BEEP_ENABLE, \ 1610 index + (index > 4 ? 11 : 17)), \ 1611 SENSOR_ATTR_2(temp##index##_pwm_enable, S_IWUSR | S_IRUGO, \ 1612 show_temp_pwm_enable, store_temp_pwm_enable, \ 1613 TEMP_PWM_ENABLE, index - 1), \ ··· 1695 SENSOR_ATTR_FAN(14), 1696 }; 1697 1698 + static const struct sensor_device_attribute_2 w83795_temp[][28] = { 1699 SENSOR_ATTR_TEMP(1), 1700 SENSOR_ATTR_TEMP(2), 1701 SENSOR_ATTR_TEMP(3), ··· 1724 SENSOR_ATTR_PWM(6), 1725 SENSOR_ATTR_PWM(7), 1726 SENSOR_ATTR_PWM(8), 1727 + }; 1728 + 1729 + static const struct sensor_device_attribute_2 w83795_tss[6] = { 1730 + SENSOR_ATTR_2(temp1_source_sel, S_IWUSR | S_IRUGO, 1731 + show_temp_src, store_temp_src, NOT_USED, 0), 1732 + SENSOR_ATTR_2(temp2_source_sel, S_IWUSR | S_IRUGO, 1733 + show_temp_src, store_temp_src, NOT_USED, 1), 1734 + SENSOR_ATTR_2(temp3_source_sel, S_IWUSR | S_IRUGO, 1735 + show_temp_src, store_temp_src, NOT_USED, 2), 1736 + SENSOR_ATTR_2(temp4_source_sel, S_IWUSR | S_IRUGO, 1737 + show_temp_src, store_temp_src, NOT_USED, 3), 1738 + SENSOR_ATTR_2(temp5_source_sel, S_IWUSR | S_IRUGO, 1739 + show_temp_src, store_temp_src, NOT_USED, 4), 1740 + SENSOR_ATTR_2(temp6_source_sel, S_IWUSR | S_IRUGO, 1741 + show_temp_src, store_temp_src, NOT_USED, 5), 1742 }; 1743 1744 static const struct sensor_device_attribute_2 sda_single_files[] = { ··· 1888 if (err) 1889 return err; 1890 } 1891 + } 1892 + 1893 + for (i = 0; i < ARRAY_SIZE(w83795_tss); i++) { 1894 + j = w83795_tss_useful(data, i); 1895 + if (!j) 1896 + continue; 1897 + err = fn(dev, &w83795_tss[i].dev_attr); 1898 + if (err) 1899 + return err; 1900 } 1901 1902 for (i = 0; i < ARRAY_SIZE(sda_single_files); i++) {