mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maud Spierings via B4 Relay <devnull+maudspierings.gocontroll.com@kernel.org>
To: Jean Delvare <jdelvare@suse.com>, Guenter Roeck <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Maud Spierings <maudspierings@gocontroll.com>
Subject: [PATCH] hwmon: (ntc_thermistor) Add min and max temperature attributes
Date: Tue, 04 Mar 2025 09:24:43 +0100	[thread overview]
Message-ID: <20250304-ntc_min_max-v1-1-b08e70e56459@gocontroll.com> (raw)

From: Maud Spierings <maudspierings@gocontroll.com>

Add the min and max temperature attributes as it is trivial for this
driver.

This can help with detecting implausible readings and indicates to users
which range they can actually measure, so they will not set a trip point
at a temperature higher than max or lower than min.

This implementation only works for ntcs, if a ptc gets added this will
have to be changed, but I'm not sure if that is ever the intention.

Signed-off-by: Maud Spierings <maudspierings@gocontroll.com>
---
 drivers/hwmon/ntc_thermistor.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index 0d29c8f97ba7c2f264588b6309b91ca494012ad6..fecee177be5daf304c0521a74f2733f6e42567e0 100644
--- a/drivers/hwmon/ntc_thermistor.c
+++ b/drivers/hwmon/ntc_thermistor.c
@@ -522,6 +522,12 @@ static int ntc_read(struct device *dev, enum hwmon_sensor_types type,
 		case hwmon_temp_type:
 			*val = 4;
 			return 0;
+		case hwmon_temp_min:
+			*val = data->comp[0].temp_c*1000;
+			return 0;
+		case hwmon_temp_max:
+			*val = data->comp[data->n_comp-1].temp_c*1000;
+			return 0;
 		default:
 			break;
 		}
@@ -539,6 +545,8 @@ static umode_t ntc_is_visible(const void *data, enum hwmon_sensor_types type,
 		switch (attr) {
 		case hwmon_temp_input:
 		case hwmon_temp_type:
+		case hwmon_temp_min:
+		case hwmon_temp_max:
 			return 0444;
 		default:
 			break;
@@ -549,7 +557,8 @@ static umode_t ntc_is_visible(const void *data, enum hwmon_sensor_types type,
 
 static const struct hwmon_channel_info * const ntc_info[] = {
 	HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ),
-	HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_TYPE),
+	HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_TYPE | HWMON_T_MIN |
+					 HWMON_T_MAX),
 	NULL
 };
 

---
base-commit: cd3215bbcb9d4321def93fea6cfad4d5b42b9d1d
change-id: 20250304-ntc_min_max-a925e87d0da7

Best regards,
-- 
Maud Spierings <maudspierings@gocontroll.com>



             reply	other threads:[~2025-03-04  8:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04  8:24 Maud Spierings via B4 Relay [this message]
2025-03-04 11:12 ` Guenter Roeck
2025-03-04 11:33   ` Maud Spierings | GOcontroll
2025-03-04 11:54     ` Guenter Roeck
2025-03-04 12:21       ` Maud Spierings | GOcontroll

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=20250304-ntc_min_max-v1-1-b08e70e56459@gocontroll.com \
    --to=devnull+maudspierings.gocontroll.com@kernel.org \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=maudspierings@gocontroll.com \
    /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®