Skip to content

Commit 6bbfdcb

Browse files
ChiaYuShihgroeck
authored andcommitted
hwmon: (nct7904) Add array fan_alarm and vsen_alarm to store the alarms in nct7904_data struct.
SMI# interrupt for fan and voltage is Two-Times Interrupt Mode. Fan or voltage exceeds high limit or going below low limit, it will causes an interrupt if the previous interrupt has been reset by reading all the interrupt Status Register. Thus, add the array fan_alarm and vsen_alarm to store the alarms for all of the fan and voltage sensors. Signed-off-by: amy.shih <[email protected]> Link: https://lore.kernel.org/r/[email protected] Fixes: 486842d ("hwmon: (nct7904) Add extra sysfs support for fan, voltage and temperature.") Signed-off-by: Guenter Roeck <[email protected]>
1 parent b428db1 commit 6bbfdcb

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

drivers/hwmon/nct7904.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ struct nct7904_data {
9999
u8 enable_dts;
100100
u8 has_dts;
101101
u8 temp_mode; /* 0: TR mode, 1: TD mode */
102+
u8 fan_alarm[2];
103+
u8 vsen_alarm[3];
102104
};
103105

104106
/* Access functions */
@@ -214,7 +216,15 @@ static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
214216
SMI_STS5_REG + (channel >> 3));
215217
if (ret < 0)
216218
return ret;
217-
*val = (ret >> (channel & 0x07)) & 1;
219+
if (!data->fan_alarm[channel >> 3])
220+
data->fan_alarm[channel >> 3] = ret & 0xff;
221+
else
222+
/* If there is new alarm showing up */
223+
data->fan_alarm[channel >> 3] |= (ret & 0xff);
224+
*val = (data->fan_alarm[channel >> 3] >> (channel & 0x07)) & 1;
225+
/* Needs to clean the alarm if alarm existing */
226+
if (*val)
227+
data->fan_alarm[channel >> 3] ^= 1 << (channel & 0x07);
218228
return 0;
219229
default:
220230
return -EOPNOTSUPP;
@@ -298,7 +308,15 @@ static int nct7904_read_in(struct device *dev, u32 attr, int channel,
298308
SMI_STS1_REG + (index >> 3));
299309
if (ret < 0)
300310
return ret;
301-
*val = (ret >> (index & 0x07)) & 1;
311+
if (!data->vsen_alarm[index >> 3])
312+
data->vsen_alarm[index >> 3] = ret & 0xff;
313+
else
314+
/* If there is new alarm showing up */
315+
data->vsen_alarm[index >> 3] |= (ret & 0xff);
316+
*val = (data->vsen_alarm[index >> 3] >> (index & 0x07)) & 1;
317+
/* Needs to clean the alarm if alarm existing */
318+
if (*val)
319+
data->vsen_alarm[index >> 3] ^= 1 << (index & 0x07);
302320
return 0;
303321
default:
304322
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)