[PATCH] Enable AMD3255 Proc to show negative temperature

Baskaran Kannan posted 1 patch 2 years, 8 months ago
drivers/hwmon/k10temp.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
[PATCH] Enable AMD3255 Proc to show negative temperature
Posted by Baskaran Kannan 2 years, 8 months ago
From: Baskaran Kannan <bakannan@amd.com>

Signed-off-by: Baskaran Kannan <Baski.Kannan@amd.com>
---
 drivers/hwmon/k10temp.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
index 489ad0b1bc74..a79aac0596e5 100644
--- a/drivers/hwmon/k10temp.c
+++ b/drivers/hwmon/k10temp.c
@@ -77,6 +77,12 @@ static DEFINE_MUTEX(nb_smu_ind_mutex);
 #define ZEN_CUR_TEMP_RANGE_SEL_MASK		BIT(19)
 #define ZEN_CUR_TEMP_TJ_SEL_MASK		GENMASK(17, 16)
 
+/* 
+ * AMD's Industrial processor 3255 supports temperature from -40 deg to 105 deg Celsius.
+ * Do not round off to zero for negative Tctl or Tdie values.
+ */
+#define AMD_I3255_STR				"3255"
+
 struct k10temp_data {
 	struct pci_dev *pdev;
 	void (*read_htcreg)(struct pci_dev *pdev, u32 *regval);
@@ -86,6 +92,7 @@ struct k10temp_data {
 	u32 show_temp;
 	bool is_zen;
 	u32 ccd_offset;
+	bool disp_negative; /*Flag set for AMD i3255. Family 17h, Model 0x0-0xf */
 };
 
 #define TCTL_BIT	0
@@ -204,9 +211,15 @@ static int k10temp_read_temp(struct device *dev, u32 attr, int channel,
 		switch (channel) {
 		case 0:		/* Tctl */
 			*val = get_raw_temp(data);
+			if (*val < 0 && (data->disp_negative == false) ){
+				*val = 0;
+			}
 			break;
 		case 1:		/* Tdie */
 			*val = get_raw_temp(data) - data->temp_offset;
+			if (*val < 0 && (data->disp_negative == false) ){
+				*val = 0;
+			}
 			break;
 		case 2 ... 13:		/* Tccd{1-12} */
 			amd_smn_read(amd_pci_dev_to_node_id(data->pdev),
@@ -401,6 +414,11 @@ static int k10temp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	data->pdev = pdev;
 	data->show_temp |= BIT(TCTL_BIT);	/* Always show Tctl */
 
+	if (boot_cpu_data.x86 == 0x17 &&
+		strstr(boot_cpu_data.x86_model_id, AMD_I3255_STR)) {
+		data->disp_negative = true;
+	}
+
 	if (boot_cpu_data.x86 == 0x15 &&
 	    ((boot_cpu_data.x86_model & 0xf0) == 0x60 ||
 	     (boot_cpu_data.x86_model & 0xf0) == 0x70)) {
-- 
2.25.1
Re: [PATCH] Enable AMD3255 Proc to show negative temperature
Posted by Guenter Roeck 2 years, 8 months ago
On 6/10/23 13:53, Baskaran Kannan wrote:
> From: Baskaran Kannan <bakannan@amd.com>
> 
> Signed-off-by: Baskaran Kannan <Baski.Kannan@amd.com>

Please resubmit and either make the changes you were asked to make,
or explain why you did not follow them.

Guenter

> ---
>   drivers/hwmon/k10temp.c | 18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
> 
> diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
> index 489ad0b1bc74..a79aac0596e5 100644
> --- a/drivers/hwmon/k10temp.c
> +++ b/drivers/hwmon/k10temp.c
> @@ -77,6 +77,12 @@ static DEFINE_MUTEX(nb_smu_ind_mutex);
>   #define ZEN_CUR_TEMP_RANGE_SEL_MASK		BIT(19)
>   #define ZEN_CUR_TEMP_TJ_SEL_MASK		GENMASK(17, 16)
>   
> +/*
> + * AMD's Industrial processor 3255 supports temperature from -40 deg to 105 deg Celsius.
> + * Do not round off to zero for negative Tctl or Tdie values.
> + */
> +#define AMD_I3255_STR				"3255"
> +
>   struct k10temp_data {
>   	struct pci_dev *pdev;
>   	void (*read_htcreg)(struct pci_dev *pdev, u32 *regval);
> @@ -86,6 +92,7 @@ struct k10temp_data {
>   	u32 show_temp;
>   	bool is_zen;
>   	u32 ccd_offset;
> +	bool disp_negative; /*Flag set for AMD i3255. Family 17h, Model 0x0-0xf */
>   };
>   
>   #define TCTL_BIT	0
> @@ -204,9 +211,15 @@ static int k10temp_read_temp(struct device *dev, u32 attr, int channel,
>   		switch (channel) {
>   		case 0:		/* Tctl */
>   			*val = get_raw_temp(data);
> +			if (*val < 0 && (data->disp_negative == false) ){
> +				*val = 0;
> +			}
>   			break;
>   		case 1:		/* Tdie */
>   			*val = get_raw_temp(data) - data->temp_offset;
> +			if (*val < 0 && (data->disp_negative == false) ){
> +				*val = 0;
> +			}
>   			break;
>   		case 2 ... 13:		/* Tccd{1-12} */
>   			amd_smn_read(amd_pci_dev_to_node_id(data->pdev),
> @@ -401,6 +414,11 @@ static int k10temp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>   	data->pdev = pdev;
>   	data->show_temp |= BIT(TCTL_BIT);	/* Always show Tctl */
>   
> +	if (boot_cpu_data.x86 == 0x17 &&
> +		strstr(boot_cpu_data.x86_model_id, AMD_I3255_STR)) {
> +		data->disp_negative = true;
> +	}
> +
>   	if (boot_cpu_data.x86 == 0x15 &&
>   	    ((boot_cpu_data.x86_model & 0xf0) == 0x60 ||
>   	     (boot_cpu_data.x86_model & 0xf0) == 0x70)) {
Re: [PATCH] Enable AMD3255 Proc to show negative temperature
Posted by Randy Dunlap 2 years, 8 months ago

On 6/10/23 13:58, Guenter Roeck wrote:
> On 6/10/23 13:53, Baskaran Kannan wrote:
>> From: Baskaran Kannan <bakannan@amd.com>
>>
>> Signed-off-by: Baskaran Kannan <Baski.Kannan@amd.com>
> 
> Please resubmit and either make the changes you were asked to make,
> or explain why you did not follow them.
> 

I don't know if anyone asked you to change the Subject: line, but you
should look at the output of
$ git log  --oneline dirvers/hwmon/

to see appropriate Subject: lines.

thanks.
-- 
~Randy