diff mbox series

[v2,3/3] hwmon: (it87) Add support to detect sensor type AMDTSI

Message ID 20230707123005.956415-4-frank@crawford.emu.id.au (mailing list archive)
State Accepted
Headers show
Series hwmon: (it87) Separate temperature type to separate funtion and detect AMDTSI | expand

Commit Message

Frank Crawford July 7, 2023, 12:29 p.m. UTC
Add test for sensor type AMDTSI which is available on certain recent
chipsets.

Signed-off-by: Frank Crawford <frank@crawford.emu.id.au>
---

v2:
 * Split single patch into multi-patch set following review.

---
 drivers/hwmon/it87.c | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

Comments

Guenter Roeck July 19, 2023, 3 a.m. UTC | #1
On Fri, Jul 07, 2023 at 10:29:52PM +1000, Frank Crawford wrote:
> Add test for sensor type AMDTSI which is available on certain recent
> chipsets.
> 
> Signed-off-by: Frank Crawford <frank@crawford.emu.id.au>

Applied.

Thanks,
Guenter

> ---
> 
> v2:
>  * Split single patch into multi-patch set following review.
> 
> ---
>  drivers/hwmon/it87.c | 35 +++++++++++++++++++++++++++++++----
>  1 file changed, 31 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
> index fb62f2a7017a..ba75f33301ce 100644
> --- a/drivers/hwmon/it87.c
> +++ b/drivers/hwmon/it87.c
> @@ -221,6 +221,10 @@ static bool fix_pwm_polarity;
>   * Super-I/O configuration space.
>   */
>  #define IT87_REG_VID           0x0a
> +
> +/* Interface Selection register on other chips */
> +#define IT87_REG_IFSEL         0x0a
> +
>  /*
>   * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
>   * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
> @@ -1170,14 +1174,37 @@ static int get_temp_type(struct it87_data *data, int index)
>  	 * 0 = disabled
>  	 */
>  	u8 reg, extra;
> -	int type = 0;
> +	int ttype, type = 0;
> +
> +	/* Detect PECI vs. AMDTSI */
> +	ttype = 6;
> +	if ((has_temp_peci(data, index)) || data->type == it8721 ||
> +	    data->type == it8720) {
> +		extra = it87_read_value(data, IT87_REG_IFSEL);
> +		if ((extra & 0x70) == 0x40)
> +			ttype = 5;
> +	}
>  
> -	reg = data->sensor;	/* In case value is updated while used */
> -	extra = data->extra;
> +	reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
> +
> +	/* Per chip special detection */
> +	switch (data->type) {
> +	case it8622:
> +		if (!(reg & 0xc0) && index == 3)
> +			type = ttype;
> +		break;
> +	default:
> +		break;
> +	}
> +
> +	if (type || index >= 3)
> +		return type;
> +
> +	extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
>  
>  	if ((has_temp_peci(data, index) && (reg >> 6 == index + 1)) ||
>  	    (has_temp_old_peci(data, index) && (extra & 0x80)))
> -		type = 6;	/* Intel PECI */
> +		type = ttype;	/* Intel PECI or AMDTSI */
>  	else if (reg & BIT(index))
>  		type = 3;	/* thermal diode */
>  	else if (reg & BIT(index + 3))
diff mbox series

Patch

diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index fb62f2a7017a..ba75f33301ce 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -221,6 +221,10 @@  static bool fix_pwm_polarity;
  * Super-I/O configuration space.
  */
 #define IT87_REG_VID           0x0a
+
+/* Interface Selection register on other chips */
+#define IT87_REG_IFSEL         0x0a
+
 /*
  * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
  * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
@@ -1170,14 +1174,37 @@  static int get_temp_type(struct it87_data *data, int index)
 	 * 0 = disabled
 	 */
 	u8 reg, extra;
-	int type = 0;
+	int ttype, type = 0;
+
+	/* Detect PECI vs. AMDTSI */
+	ttype = 6;
+	if ((has_temp_peci(data, index)) || data->type == it8721 ||
+	    data->type == it8720) {
+		extra = it87_read_value(data, IT87_REG_IFSEL);
+		if ((extra & 0x70) == 0x40)
+			ttype = 5;
+	}
 
-	reg = data->sensor;	/* In case value is updated while used */
-	extra = data->extra;
+	reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
+
+	/* Per chip special detection */
+	switch (data->type) {
+	case it8622:
+		if (!(reg & 0xc0) && index == 3)
+			type = ttype;
+		break;
+	default:
+		break;
+	}
+
+	if (type || index >= 3)
+		return type;
+
+	extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
 
 	if ((has_temp_peci(data, index) && (reg >> 6 == index + 1)) ||
 	    (has_temp_old_peci(data, index) && (extra & 0x80)))
-		type = 6;	/* Intel PECI */
+		type = ttype;	/* Intel PECI or AMDTSI */
 	else if (reg & BIT(index))
 		type = 3;	/* thermal diode */
 	else if (reg & BIT(index + 3))