mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Baskaran Kannan <Baski.Kannan@amd.com>
To: <Mario.Limonciello@amd.com>, <babu.moger@amd.com>,
	<baski.kannan@amd.com>, <clemens@ladisch.de>, <jdelvare@suse.com>,
	<linux@roeck-us.net>, <linux-hwmon@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Cc: Baskaran Kannan <bakannan@amd.com>,
	Baskaran Kannan <Baski.Kannan@amd.com>
Subject: [PATCH] Enable AMD3255 Proc to show negative temperature
Date: Sat, 10 Jun 2023 15:53:57 -0500	[thread overview]
Message-ID: <20230610205357.5658-1-Baski.Kannan@amd.com> (raw)

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


             reply	other threads:[~2023-06-10 20:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-10 20:53 Baskaran Kannan [this message]
2023-06-10 20:58 ` Guenter Roeck
2023-06-10 21:34   ` Randy Dunlap
  -- strict thread matches above, loose matches on Subject: below --
2023-06-09 23:11 Baskaran Kannan
2023-06-09 23:30 ` Randy Dunlap
2023-06-10  2:00 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230610205357.5658-1-Baski.Kannan@amd.com \
    --to=baski.kannan@amd.com \
    --cc=Mario.Limonciello@amd.com \
    --cc=babu.moger@amd.com \
    --cc=bakannan@amd.com \
    --cc=clemens@ladisch.de \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®