@@ -171,6 +171,9 @@ static const u8 IN_LSB_SHIFT_IDX[][2] = {
171171#define W83795_REG_CLR_CHASSIS 0x4D
172172#define W83795_REG_BEEP (index ) (0x50 + (index))
173173
174+ #define W83795_REG_OVT_CFG 0x58
175+ #define OVT_CFG_SEL (1 << 7)
176+
174177
175178#define W83795_REG_FCMS1 0x201
176179#define W83795_REG_FCMS2 0x208
@@ -378,6 +381,7 @@ struct w83795_data {
378381 u8 setup_pwm [3 ]; /* Register value */
379382
380383 u8 alarms [6 ]; /* Register value */
384+ u8 enable_beep ;
381385 u8 beeps [6 ]; /* Register value */
382386
383387 char valid ;
@@ -508,8 +512,11 @@ static void w83795_update_limits(struct i2c_client *client)
508512 }
509513
510514 /* Read beep settings */
511- for (i = 0 ; i < ARRAY_SIZE (data -> beeps ); i ++ )
512- data -> beeps [i ] = w83795_read (client , W83795_REG_BEEP (i ));
515+ if (data -> enable_beep ) {
516+ for (i = 0 ; i < ARRAY_SIZE (data -> beeps ); i ++ )
517+ data -> beeps [i ] =
518+ w83795_read (client , W83795_REG_BEEP (i ));
519+ }
513520
514521 data -> valid_limits = 1 ;
515522}
@@ -1588,7 +1595,7 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
15881595
15891596#define NOT_USED -1
15901597
1591- /* Don't change the attribute order, _max and _min are accessed by index
1598+ /* Don't change the attribute order, _max, _min and _beep are accessed by index
15921599 * somewhere else in the code */
15931600#define SENSOR_ATTR_IN (index ) { \
15941601 SENSOR_ATTR_2(in##index##_input, S_IRUGO, show_in, NULL, \
@@ -1603,6 +1610,8 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
16031610 show_alarm_beep, store_beep, BEEP_ENABLE, \
16041611 index + ((index > 14) ? 1 : 0)) }
16051612
1613+ /* Don't change the attribute order, _beep is accessed by index
1614+ * somewhere else in the code */
16061615#define SENSOR_ATTR_FAN (index ) { \
16071616 SENSOR_ATTR_2(fan##index##_input, S_IRUGO, show_fan, \
16081617 NULL, FAN_INPUT, index - 1), \
@@ -1631,6 +1640,8 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
16311640 SENSOR_ATTR_2(fan##index##_target, S_IWUSR | S_IRUGO, \
16321641 show_fanin, store_fanin, FANIN_TARGET, index - 1) }
16331642
1643+ /* Don't change the attribute order, _beep is accessed by index
1644+ * somewhere else in the code */
16341645#define SENSOR_ATTR_DTS (index ) { \
16351646 SENSOR_ATTR_2(temp##index##_type, S_IRUGO , \
16361647 show_dts_mode, NULL, NOT_USED, index - 7), \
@@ -1649,6 +1660,8 @@ store_sf_setup(struct device *dev, struct device_attribute *attr,
16491660 SENSOR_ATTR_2(temp##index##_beep, S_IWUSR | S_IRUGO, \
16501661 show_alarm_beep, store_beep, BEEP_ENABLE, index + 17) }
16511662
1663+ /* Don't change the attribute order, _beep is accessed by index
1664+ * somewhere else in the code */
16521665#define SENSOR_ATTR_TEMP (index ) { \
16531666 SENSOR_ATTR_2(temp##index##_type, S_IRUGO | (index < 4 ? S_IWUSR : 0), \
16541667 show_temp_mode, store_temp_mode, NOT_USED, index - 1), \
@@ -1802,10 +1815,6 @@ static const struct sensor_device_attribute_2 w83795_tss[6] = {
18021815static const struct sensor_device_attribute_2 sda_single_files [] = {
18031816 SENSOR_ATTR_2 (intrusion0_alarm , S_IWUSR | S_IRUGO , show_alarm_beep ,
18041817 store_chassis_clear , ALARM_STATUS , 46 ),
1805- SENSOR_ATTR_2 (intrusion0_beep , S_IWUSR | S_IRUGO , show_alarm_beep ,
1806- store_beep , BEEP_ENABLE , 46 ),
1807- SENSOR_ATTR_2 (beep_enable , S_IWUSR | S_IRUGO , show_alarm_beep ,
1808- store_beep , BEEP_ENABLE , 47 ),
18091818#ifdef CONFIG_SENSORS_W83795_FANCTRL
18101819 SENSOR_ATTR_2 (speed_cruise_tolerance , S_IWUSR | S_IRUGO , show_fanin ,
18111820 store_fanin , FANIN_TOL , NOT_USED ),
@@ -1818,6 +1827,13 @@ static const struct sensor_device_attribute_2 sda_single_files[] = {
18181827#endif
18191828};
18201829
1830+ static const struct sensor_device_attribute_2 sda_beep_files [] = {
1831+ SENSOR_ATTR_2 (intrusion0_beep , S_IWUSR | S_IRUGO , show_alarm_beep ,
1832+ store_beep , BEEP_ENABLE , 46 ),
1833+ SENSOR_ATTR_2 (beep_enable , S_IWUSR | S_IRUGO , show_alarm_beep ,
1834+ store_beep , BEEP_ENABLE , 47 ),
1835+ };
1836+
18211837/*
18221838 * Driver interface
18231839 */
@@ -1947,6 +1963,8 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
19471963 if (!(data -> has_in & (1 << i )))
19481964 continue ;
19491965 for (j = 0 ; j < ARRAY_SIZE (w83795_in [0 ]); j ++ ) {
1966+ if (j == 4 && !data -> enable_beep )
1967+ continue ;
19501968 err = fn (dev , & w83795_in [i ][j ].dev_attr );
19511969 if (err )
19521970 return err ;
@@ -1957,6 +1975,8 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
19571975 if (!(data -> has_fan & (1 << i )))
19581976 continue ;
19591977 for (j = 0 ; j < ARRAY_SIZE (w83795_fan [0 ]); j ++ ) {
1978+ if (j == 3 && !data -> enable_beep )
1979+ continue ;
19601980 err = fn (dev , & w83795_fan [i ][j ].dev_attr );
19611981 if (err )
19621982 return err ;
@@ -1978,6 +1998,14 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
19781998 return err ;
19791999 }
19802000
2001+ if (data -> enable_beep ) {
2002+ for (i = 0 ; i < ARRAY_SIZE (sda_beep_files ); i ++ ) {
2003+ err = fn (dev , & sda_beep_files [i ].dev_attr );
2004+ if (err )
2005+ return err ;
2006+ }
2007+ }
2008+
19812009#ifdef CONFIG_SENSORS_W83795_FANCTRL
19822010 for (i = 0 ; i < data -> has_pwm ; i ++ ) {
19832011 for (j = 0 ; j < ARRAY_SIZE (w83795_pwm [0 ]); j ++ ) {
@@ -1996,6 +2024,8 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
19962024#else
19972025 for (j = 0 ; j < 8 ; j ++ ) {
19982026#endif
2027+ if (j == 7 && !data -> enable_beep )
2028+ continue ;
19992029 err = fn (dev , & w83795_temp [i ][j ].dev_attr );
20002030 if (err )
20012031 return err ;
@@ -2007,6 +2037,8 @@ static int w83795_handle_files(struct device *dev, int (*fn)(struct device *,
20072037 if (!(data -> has_dts & (1 << i )))
20082038 continue ;
20092039 for (j = 0 ; j < ARRAY_SIZE (w83795_dts [0 ]); j ++ ) {
2040+ if (j == 7 && !data -> enable_beep )
2041+ continue ;
20102042 err = fn (dev , & w83795_dts [i ][j ].dev_attr );
20112043 if (err )
20122044 return err ;
@@ -2146,6 +2178,18 @@ static int w83795_probe(struct i2c_client *client,
21462178 else
21472179 data -> has_pwm = 2 ;
21482180
2181+ /* Check if BEEP pin is available */
2182+ if (data -> chip_type == w83795g ) {
2183+ /* The W83795G has a dedicated BEEP pin */
2184+ data -> enable_beep = 1 ;
2185+ } else {
2186+ /* The W83795ADG has a shared pin for OVT# and BEEP, so you
2187+ * can't have both */
2188+ tmp = w83795_read (client , W83795_REG_OVT_CFG );
2189+ if ((tmp & OVT_CFG_SEL ) == 0 )
2190+ data -> enable_beep = 1 ;
2191+ }
2192+
21492193 err = w83795_handle_files (dev , device_create_file );
21502194 if (err )
21512195 goto exit_remove ;
0 commit comments