Linux-Hwmon Archive on lore.kernel.org
 help / color / Atom feed
* [v1,1/1] hwmon: (nct7904) Add array fan_alarm and vsen_alarm to store the alarms in nct7904_data struct.
@ 2019-09-19  3:02 Amy.Shih
  2019-10-02 13:43 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Amy.Shih @ 2019-09-19  3:02 UTC (permalink / raw)
  To: she90122
  Cc: amy.shih, oakley.ding, bichan.lu, Jean Delvare, Guenter Roeck,
	linux-hwmon, linux-kernel

From: "amy.shih" <amy.shih@advantech.com.tw>

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 <amy.shih@advantech.com.tw>
---
 drivers/hwmon/nct7904.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
index f62dd1882451..b26419dbe840 100644
--- a/drivers/hwmon/nct7904.c
+++ b/drivers/hwmon/nct7904.c
@@ -99,6 +99,8 @@ struct nct7904_data {
 	u8 enable_dts;
 	u8 has_dts;
 	u8 temp_mode; /* 0: TR mode, 1: TD mode */
+	u8 fan_alarm[2];
+	u8 vsen_alarm[3];
 };
 
 /* Access functions */
@@ -214,7 +216,15 @@ static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
 				       SMI_STS5_REG + (channel >> 3));
 		if (ret < 0)
 			return ret;
-		*val = (ret >> (channel & 0x07)) & 1;
+		if (!data->fan_alarm[channel >> 3])
+			data->fan_alarm[channel >> 3] = ret & 0xff;
+		else
+			/* If there is new alarm showing up */
+			data->fan_alarm[channel >> 3] |= (ret & 0xff);
+		*val = (data->fan_alarm[channel >> 3] >> (channel & 0x07)) & 1;
+		/* Needs to clean the alarm if alarm existing */
+		if (*val)
+			data->fan_alarm[channel >> 3] ^= 1 << (channel & 0x07);
 		return 0;
 	default:
 		return -EOPNOTSUPP;
@@ -298,7 +308,15 @@ static int nct7904_read_in(struct device *dev, u32 attr, int channel,
 				       SMI_STS1_REG + (index >> 3));
 		if (ret < 0)
 			return ret;
-		*val = (ret >> (index & 0x07)) & 1;
+		if (!data->vsen_alarm[index >> 3])
+			data->vsen_alarm[index >> 3] = ret & 0xff;
+		else
+			/* If there is new alarm showing up */
+			data->vsen_alarm[index >> 3] |= (ret & 0xff);
+		*val = (data->vsen_alarm[index >> 3] >> (index & 0x07)) & 1;
+		/* Needs to clean the alarm if alarm existing */
+		if (*val)
+			data->vsen_alarm[index >> 3] ^= 1 << (index & 0x07);
 		return 0;
 	default:
 		return -EOPNOTSUPP;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [v1,1/1] hwmon: (nct7904) Add array fan_alarm and vsen_alarm to store the alarms in nct7904_data struct.
  2019-09-19  3:02 [v1,1/1] hwmon: (nct7904) Add array fan_alarm and vsen_alarm to store the alarms in nct7904_data struct Amy.Shih
@ 2019-10-02 13:43 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2019-10-02 13:43 UTC (permalink / raw)
  To: Amy.Shih
  Cc: she90122, oakley.ding, bichan.lu, Jean Delvare, linux-hwmon,
	linux-kernel

On Thu, Sep 19, 2019 at 11:02:05AM +0800, Amy.Shih@advantech.com.tw wrote:
> From: "amy.shih" <amy.shih@advantech.com.tw>
> 
> 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 <amy.shih@advantech.com.tw>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/nct7904.c | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
> index f62dd1882451..b26419dbe840 100644
> --- a/drivers/hwmon/nct7904.c
> +++ b/drivers/hwmon/nct7904.c
> @@ -99,6 +99,8 @@ struct nct7904_data {
>  	u8 enable_dts;
>  	u8 has_dts;
>  	u8 temp_mode; /* 0: TR mode, 1: TD mode */
> +	u8 fan_alarm[2];
> +	u8 vsen_alarm[3];
>  };
>  
>  /* Access functions */
> @@ -214,7 +216,15 @@ static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
>  				       SMI_STS5_REG + (channel >> 3));
>  		if (ret < 0)
>  			return ret;
> -		*val = (ret >> (channel & 0x07)) & 1;
> +		if (!data->fan_alarm[channel >> 3])
> +			data->fan_alarm[channel >> 3] = ret & 0xff;
> +		else
> +			/* If there is new alarm showing up */
> +			data->fan_alarm[channel >> 3] |= (ret & 0xff);
> +		*val = (data->fan_alarm[channel >> 3] >> (channel & 0x07)) & 1;
> +		/* Needs to clean the alarm if alarm existing */
> +		if (*val)
> +			data->fan_alarm[channel >> 3] ^= 1 << (channel & 0x07);
>  		return 0;
>  	default:
>  		return -EOPNOTSUPP;
> @@ -298,7 +308,15 @@ static int nct7904_read_in(struct device *dev, u32 attr, int channel,
>  				       SMI_STS1_REG + (index >> 3));
>  		if (ret < 0)
>  			return ret;
> -		*val = (ret >> (index & 0x07)) & 1;
> +		if (!data->vsen_alarm[index >> 3])
> +			data->vsen_alarm[index >> 3] = ret & 0xff;
> +		else
> +			/* If there is new alarm showing up */
> +			data->vsen_alarm[index >> 3] |= (ret & 0xff);
> +		*val = (data->vsen_alarm[index >> 3] >> (index & 0x07)) & 1;
> +		/* Needs to clean the alarm if alarm existing */
> +		if (*val)
> +			data->vsen_alarm[index >> 3] ^= 1 << (index & 0x07);
>  		return 0;
>  	default:
>  		return -EOPNOTSUPP;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-19  3:02 [v1,1/1] hwmon: (nct7904) Add array fan_alarm and vsen_alarm to store the alarms in nct7904_data struct Amy.Shih
2019-10-02 13:43 ` Guenter Roeck

Linux-Hwmon Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-hwmon/0 linux-hwmon/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-hwmon linux-hwmon/ https://lore.kernel.org/linux-hwmon \
		linux-hwmon@vger.kernel.org
	public-inbox-index linux-hwmon

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-hwmon


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git