From: "Stéphan Kochen" <stephan-j6uo2F6POYhmR6Xm/wNWPw@public.gmane.org>
To: Jean Delvare <jdelvare-IBi9RG/b67k@public.gmane.org>
Cc: "Stéphan Kochen"
<stephan-j6uo2F6POYhmR6Xm/wNWPw@public.gmane.org>,
"Rob Herring" <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
"Pawel Moll" <pawel.moll-5wv7dgnIgG8@public.gmane.org>,
"Mark Rutland" <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
"Ian Campbell"
<ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org>,
"Kumar Gala" <galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
"Guenter Roeck" <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>,
lm-sensors-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH 2/3] lm90: initialize parameters from devicetree
Date: Thu, 21 Jan 2016 20:34:36 +0100 [thread overview]
Message-ID: <1453404877-17897-3-git-send-email-stephan@kochen.nl> (raw)
In-Reply-To: <1453404877-17897-1-git-send-email-stephan-j6uo2F6POYhmR6Xm/wNWPw@public.gmane.org>
Allow a device tree to set initial temperature sensor parameters.
Userspace can still override actual values through sysfs.
Signed-off-by: Stéphan Kochen <stephan-j6uo2F6POYhmR6Xm/wNWPw@public.gmane.org>
---
Documentation/devicetree/bindings/hwmon/lm90.txt | 40 +++++++++++++++++
drivers/hwmon/lm90.c | 55 ++++++++++++++++++++++--
2 files changed, 92 insertions(+), 3 deletions(-)
diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt b/Documentation/devicetree/bindings/hwmon/lm90.txt
index e863248..045e94b 100644
--- a/Documentation/devicetree/bindings/hwmon/lm90.txt
+++ b/Documentation/devicetree/bindings/hwmon/lm90.txt
@@ -33,6 +33,38 @@ Optional properties:
LM90 "-ALERT" pin output.
See interrupt-controller/interrupts.txt for the format.
+- update-interval: Interval at which temperatures are sampled,
+ Type: unsigned in milliseconds.
+ Size: one cell
+
+- local-low: Valid temperature range for the chip internal sensor,
+ local-high: outside which the alert will be set. Values are in
+ local-critical: millicelcius.
+ Type: signed
+ Size: one cell
+
+- remote-low: Valid temperature range for the external sensor,
+ remote-high: outside which the alert will be set. Values are in
+ remote-critical: millicelciius.
+ Type: signed
+ Size: one cell
+
+- remote-offset: Where available, an external sensor temperature offset.
+ Type: signed
+ Size: one cell
+
+- local-emergency: On max6659, max6695 and max6696, a configurable
+ remote-emergency: 3rd upper bound on temperature.
+ Type: signed
+ Size: one cell
+
+- remote2-low: On max6695 and max6696, a second external sensor.
+ remote2-high:
+ remote2-critical:
+ remote2-emergency:
+ Type: signed
+ Size: one cell
+
Example LM90 node:
temp-sensor {
@@ -41,4 +73,12 @@ temp-sensor {
vcc-supply = <&palmas_ldo6_reg>;
interrupt-parent = <&gpio>;
interrupts = <TEGRA_GPIO(O, 4) IRQ_TYPE_LEVEL_LOW>;
+ update-interval = <500>;
+ local-low = <5000>;
+ local-high = <80000>;
+ local-critical = <90000>;
+ remote-low = <5000>;
+ remote-high = <80000>;
+ remote-critical = <90000>;
+ remote-offset = <(-62125)>;
}
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 88daf72..8ae8791 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -93,6 +93,7 @@
#include <linux/hwmon.h>
#include <linux/err.h>
#include <linux/mutex.h>
+#include <linux/of.h>
#include <linux/sysfs.h>
#include <linux/interrupt.h>
#include <linux/regulator/consumer.h>
@@ -1504,8 +1505,16 @@ static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data)
static void lm90_init_client(struct lm90_data *data)
{
struct i2c_client *client = data->client;
+ struct device *dev = &client->dev;
u8 config, convrate;
+ u32 ms;
+#ifdef CONFIG_OF
+ s32 temp;
+#endif
+ /*
+ * Save old conversion rate.
+ */
if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) {
dev_warn(&client->dev, "Failed to read convrate register!\n");
convrate = LM90_DEF_CONVRATE_RVAL;
@@ -1515,14 +1524,24 @@ static void lm90_init_client(struct lm90_data *data)
/*
* Start the conversions.
*/
- lm90_set_convrate_locked(data, 500); /* 500ms / 2Hz */
+#ifdef CONFIG_OF
+ if (of_property_read_u32(dev->of_node, "update-interval", &ms) < 0)
+#endif
+ ms = 500; /* default rate: 2Hz */
+ lm90_set_convrate_locked(data, ms);
+
+ /*
+ * Save old config
+ */
if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) {
- dev_warn(&client->dev, "Initialization failed!\n");
+ dev_warn(dev, "Initialization failed!\n");
return;
}
data->config_orig = config;
- /* Check Temperature Range Select */
+ /*
+ * Check Temperature Range Select
+ */
if (data->kind == adt7461 || data->kind == tmp451) {
if (config & 0x04)
data->flags |= LM90_FLAG_ADT7461_EXT;
@@ -1545,6 +1564,36 @@ static void lm90_init_client(struct lm90_data *data)
config &= 0xBF; /* run */
if (config != data->config_orig) /* Only write if changed */
i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
+
+#ifdef CONFIG_OF
+ /*
+ * Set initial values from devicetree
+ */
+#define INIT_REG(_property, _index, _bits) { \
+ if (of_property_read_s32(dev->of_node, _property, &temp) == 0) \
+ lm90_set_temp##_bits##_locked(data, _index, temp); \
+}
+ INIT_REG("local-low", LOCAL_LOW, 8);
+ INIT_REG("local-high", LOCAL_HIGH, 8);
+ INIT_REG("local-critical", LOCAL_CRIT, 8);
+ INIT_REG("remote-low", REMOTE_LOW, 11);
+ INIT_REG("remote-high", REMOTE_HIGH, 11);
+ INIT_REG("remote-critical", REMOTE_CRIT, 8);
+ if (data->flags & LM90_HAVE_OFFSET) {
+ INIT_REG("remote-offset", REMOTE_OFFSET, 11);
+ }
+ if (data->flags & LM90_HAVE_EMERGENCY) {
+ INIT_REG("local-emergency", LOCAL_EMERG, 8);
+ INIT_REG("remote-emergency", REMOTE_EMERG, 8);
+ }
+ if (data->flags & LM90_HAVE_TEMP3) {
+ INIT_REG("remote2-low", REMOTE2_LOW, 11);
+ INIT_REG("remote2-high", REMOTE2_HIGH, 11);
+ INIT_REG("remote2-critical", REMOTE2_CRIT, 8);
+ INIT_REG("remote2-emergency", REMOTE2_EMERG, 8);
+ }
+#undef INIT_REG
+#endif
}
static bool lm90_is_tripped(struct i2c_client *client, u16 *status)
--
2.5.0
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-01-21 19:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-21 19:34 [PATCH 0/3] lm90: device tree and thermal zone support Stéphan Kochen
[not found] ` <1453404877-17897-1-git-send-email-stephan-j6uo2F6POYhmR6Xm/wNWPw@public.gmane.org>
2016-01-21 19:34 ` [PATCH 1/3] lm90: separate register accessors from sysfs Stéphan Kochen
[not found] ` <1453404877-17897-2-git-send-email-stephan-j6uo2F6POYhmR6Xm/wNWPw@public.gmane.org>
2016-01-22 14:42 ` Guenter Roeck
[not found] ` <56A23FD2.9040009-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2016-01-22 22:00 ` Stéphan Kochen
[not found] ` <20160122220056.GA21534-3Ql6wuUqVi7fKcxHm0zdRv8+0UxHXcjY@public.gmane.org>
2016-01-25 9:41 ` [lm-sensors] " Jean Delvare
2016-01-21 19:34 ` Stéphan Kochen [this message]
[not found] ` <1453404877-17897-3-git-send-email-stephan-j6uo2F6POYhmR6Xm/wNWPw@public.gmane.org>
2016-01-22 14:53 ` [PATCH 2/3] lm90: initialize parameters from devicetree Guenter Roeck
[not found] ` <56A24278.8050909-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2016-01-22 22:32 ` Stéphan Kochen
2016-01-23 2:53 ` Guenter Roeck
[not found] ` <56A2EB3E.4080002-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2016-01-27 21:18 ` Interrupt driven thermal OF sensors (was: [PATCH 2/3] lm90: initialize parameters from devicetree) Stéphan Kochen
2016-01-28 5:05 ` Interrupt driven thermal OF sensors Guenter Roeck
2016-01-29 0:16 ` Stéphan Kochen
2016-01-21 19:34 ` [PATCH 3/3] lm90: register with thermal zones Stéphan Kochen
[not found] ` <1453404877-17897-4-git-send-email-stephan-j6uo2F6POYhmR6Xm/wNWPw@public.gmane.org>
2016-01-22 22:45 ` Rob Herring
2016-01-22 23:02 ` Stéphan Kochen
[not found] ` <20160122230239.GA22301-3Ql6wuUqVi7fKcxHm0zdRv8+0UxHXcjY@public.gmane.org>
2016-01-22 23:11 ` Rob Herring
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=1453404877-17897-3-git-send-email-stephan@kochen.nl \
--to=stephan-j6uo2f6poyhmr6xm/wnwpw@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org \
--cc=jdelvare-IBi9RG/b67k@public.gmane.org \
--cc=linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org \
--cc=lm-sensors-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=pawel.moll-5wv7dgnIgG8@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/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;
as well as URLs for NNTP newsgroup(s).