Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (w83795) Check for BEEP pin availability

On the W83795ADG, there's a single pin for BEEP and OVT#, so you
can't have both. Check the configuration and don't create beep
attributes when BEEP pin is not available.

The W83795G has a dedicated BEEP pin so the functionality is always
available there.

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
52d159ee 793c51d5

+51 -7
+51 -7
drivers/hwmon/w83795.c
··· 171 171 #define W83795_REG_CLR_CHASSIS 0x4D 172 172 #define W83795_REG_BEEP(index) (0x50 + (index)) 173 173 174 + #define W83795_REG_OVT_CFG 0x58 175 + #define OVT_CFG_SEL (1 << 7) 176 + 174 177 175 178 #define W83795_REG_FCMS1 0x201 176 179 #define W83795_REG_FCMS2 0x208 ··· 381 378 u8 setup_pwm[3]; /* Register value */ 382 379 383 380 u8 alarms[6]; /* Register value */ 381 + u8 enable_beep; 384 382 u8 beeps[6]; /* Register value */ 385 383 386 384 char valid; ··· 512 508 } 513 509 514 510 /* Read beep settings */ 515 - for (i = 0; i < ARRAY_SIZE(data->beeps); i++) 516 - data->beeps[i] = w83795_read(client, W83795_REG_BEEP(i)); 511 + if (data->enable_beep) { 512 + for (i = 0; i < ARRAY_SIZE(data->beeps); i++) 513 + data->beeps[i] = 514 + w83795_read(client, W83795_REG_BEEP(i)); 515 + } 517 516 518 517 data->valid_limits = 1; 519 518 } ··· 1595 1588 1596 1589 #define NOT_USED -1 1597 1590 1598 - /* Don't change the attribute order, _max and _min are accessed by index 1591 + /* Don't change the attribute order, _max, _min and _beep are accessed by index 1599 1592 * somewhere else in the code */ 1600 1593 #define SENSOR_ATTR_IN(index) { \ 1601 1594 SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \ ··· 1610 1603 show_alarm_beep, store_beep, BEEP_ENABLE, \ 1611 1604 index + ((index > 14) ? 1 : 0)) } 1612 1605 1606 + /* Don't change the attribute order, _beep is accessed by index 1607 + * somewhere else in the code */ 1613 1608 #define SENSOR_ATTR_FAN(index) { \ 1614 1609 SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \ 1615 1610 NULL, FAN_INPUT, index - 1), \ ··· 1640 1631 SENSOR_ATTR_2(fan##index##_target, S_IWUSR | S_IRUGO, \ 1641 1632 show_fanin, store_fanin, FANIN_TARGET, index - 1) } 1642 1633 1634 + /* Don't change the attribute order, _beep is accessed by index 1635 + * somewhere else in the code */ 1643 1636 #define SENSOR_ATTR_DTS(index) { \ 1644 1637 SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \ 1645 1638 show_dts_mode, NULL, NOT_USED, index - 7), \ ··· 1660 1649 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \ 1661 1650 show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) } 1662 1651 1652 + /* Don't change the attribute order, _beep is accessed by index 1653 + * somewhere else in the code */ 1663 1654 #define SENSOR_ATTR_TEMP(index) { \ 1664 1655 SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \ 1665 1656 show_temp_mode, store_temp_mode, NOT_USED, index - 1), \ ··· 1815 1802 static const struct sensor_device_attribute_2 sda_single_files[] = { 1816 1803 SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_alarm_beep, 1817 1804 store_chassis_clear, ALARM_STATUS, 46), 1818 - SENSOR_ATTR_2(intrusion0_beep, S_IWUSR | S_IRUGO, show_alarm_beep, 1819 - store_beep, BEEP_ENABLE, 46), 1820 - SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_alarm_beep, 1821 - store_beep, BEEP_ENABLE, 47), 1822 1805 #ifdef CONFIG_SENSORS_W83795_FANCTRL 1823 1806 SENSOR_ATTR_2(speed_cruise_tolerance, S_IWUSR | S_IRUGO, show_fanin, 1824 1807 store_fanin, FANIN_TOL, NOT_USED), ··· 1825 1816 SENSOR_ATTR_2(pwm_downtime, S_IWUSR | S_IRUGO, show_sf_setup, 1826 1817 store_sf_setup, SETUP_PWM_DOWNTIME, NOT_USED), 1827 1818 #endif 1819 + }; 1820 + 1821 + static const struct sensor_device_attribute_2 sda_beep_files[] = { 1822 + SENSOR_ATTR_2(intrusion0_beep, S_IWUSR | S_IRUGO, show_alarm_beep, 1823 + store_beep, BEEP_ENABLE, 46), 1824 + SENSOR_ATTR_2(beep_enable, S_IWUSR | S_IRUGO, show_alarm_beep, 1825 + store_beep, BEEP_ENABLE, 47), 1828 1826 }; 1829 1827 1830 1828 /* ··· 1963 1947 if (!(data->has_in & (1 << i))) 1964 1948 continue; 1965 1949 for (j = 0; j < ARRAY_SIZE(w83795_in[0]); j++) { 1950 + if (j == 4 && !data->enable_beep) 1951 + continue; 1966 1952 err = fn(dev, &w83795_in[i][j].dev_attr); 1967 1953 if (err) 1968 1954 return err; ··· 1975 1957 if (!(data->has_fan & (1 << i))) 1976 1958 continue; 1977 1959 for (j = 0; j < ARRAY_SIZE(w83795_fan[0]); j++) { 1960 + if (j == 3 && !data->enable_beep) 1961 + continue; 1978 1962 err = fn(dev, &w83795_fan[i][j].dev_attr); 1979 1963 if (err) 1980 1964 return err; ··· 1998 1978 return err; 1999 1979 } 2000 1980 1981 + if (data->enable_beep) { 1982 + for (i = 0; i < ARRAY_SIZE(sda_beep_files); i++) { 1983 + err = fn(dev, &sda_beep_files[i].dev_attr); 1984 + if (err) 1985 + return err; 1986 + } 1987 + } 1988 + 2001 1989 #ifdef CONFIG_SENSORS_W83795_FANCTRL 2002 1990 for (i = 0; i < data->has_pwm; i++) { 2003 1991 for (j = 0; j < ARRAY_SIZE(w83795_pwm[0]); j++) { ··· 2024 1996 #else 2025 1997 for (j = 0; j < 8; j++) { 2026 1998 #endif 1999 + if (j == 7 && !data->enable_beep) 2000 + continue; 2027 2001 err = fn(dev, &w83795_temp[i][j].dev_attr); 2028 2002 if (err) 2029 2003 return err; ··· 2037 2007 if (!(data->has_dts & (1 << i))) 2038 2008 continue; 2039 2009 for (j = 0; j < ARRAY_SIZE(w83795_dts[0]); j++) { 2010 + if (j == 7 && !data->enable_beep) 2011 + continue; 2040 2012 err = fn(dev, &w83795_dts[i][j].dev_attr); 2041 2013 if (err) 2042 2014 return err; ··· 2177 2145 data->has_pwm = 8; 2178 2146 else 2179 2147 data->has_pwm = 2; 2148 + 2149 + /* Check if BEEP pin is available */ 2150 + if (data->chip_type == w83795g) { 2151 + /* The W83795G has a dedicated BEEP pin */ 2152 + data->enable_beep = 1; 2153 + } else { 2154 + /* The W83795ADG has a shared pin for OVT# and BEEP, so you 2155 + * can't have both */ 2156 + tmp = w83795_read(client, W83795_REG_OVT_CFG); 2157 + if ((tmp & OVT_CFG_SEL) == 0) 2158 + data->enable_beep = 1; 2159 + } 2180 2160 2181 2161 err = w83795_handle_files(dev, device_create_file); 2182 2162 if (err)