diff mbox series

[v1,2/2] hwmon: (lm90) Implement set_trips() callback

Message ID 20210620161223.16844-3-digetx@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show
Series Support temperature trips by HWMON core and LM90 driver | expand

Commit Message

Dmitry Osipenko June 20, 2021, 4:12 p.m. UTC
Implement set_trips() callback in order to operatively notify thermal
core about temperature changes. Thermal core will take control over the
LM90 temperature limits only if LM90 is attached to thermal zone in a
device-tree and sensor interrupt is provided, otherwise old behaviour
is unchanged.

Currently only NVIDIA Tegra boards are specifying interrupt for LM90
sensors and only couple of boards use sensor for passive cooling of CPU,
otherwise sensor isn't actively used. Hence this change doesn't bring
any visible effects to userspace, it merely improves thermal device
capabilities of the LM90 driver.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/hwmon/lm90.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
diff mbox series

Patch

diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index b53f17511b05..7180af611dfb 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -1406,6 +1406,35 @@  static int lm90_write(struct device *dev, enum hwmon_sensor_types type,
 	}
 }
 
+static int lm90_set_trips(struct device *dev, int channel, int low, int high)
+{
+	struct lm90_data *data = dev_get_drvdata(dev);
+	struct i2c_client *client = data->client;
+	int err;
+
+	/*
+	 * It makes sense to set temperature trips only if interrupt is
+	 * provided since the whole point of temperature trips is to get
+	 * a quick notification about temperature changes.
+	 */
+	if (!client->irq)
+		return 0;
+
+	/* prevent integer overflow of temperature calculations */
+	low  = max(low, -255000);
+	high = min(high, 255000);
+
+	err = lm90_temp_write(dev, hwmon_temp_min, channel, low);
+	if (err < 0)
+		return err;
+
+	err = lm90_temp_write(dev, hwmon_temp_max, channel, high);
+	if (err < 0)
+		return err;
+
+	return 0;
+}
+
 static umode_t lm90_is_visible(const void *data, enum hwmon_sensor_types type,
 			       u32 attr, int channel)
 {
@@ -1804,6 +1833,7 @@  static const struct hwmon_ops lm90_ops = {
 	.is_visible = lm90_is_visible,
 	.read = lm90_read,
 	.write = lm90_write,
+	.set_trips = lm90_set_trips,
 };
 
 static int lm90_probe(struct i2c_client *client)