linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wei Ni <wni@nvidia.com>
To: edubezval@gmail.com, khali@linux-fr.org, linux@roeck-us.net,
	swarren@wwwdotorg.org
Cc: lm-sensors@lm-sensors.org, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org, lightning314 <wni@nvidia.com>
Subject: [PATCH v3 2/4] hwmon: lm90: expose to thermal fw via DT nodes
Date: Mon, 25 Aug 2014 14:29:46 +0800	[thread overview]
Message-ID: <1408948188-4181-3-git-send-email-wni@nvidia.com> (raw)
In-Reply-To: <1408948188-4181-1-git-send-email-wni@nvidia.com>

From: lightning314 <wni@nvidia.com>

This patch adds to lm90 temperature sensor the possibility
to expose itself as thermal zone device, registered on the
thermal framework.

The thermal zone is built only if a device tree node
describing a thermal zone for this sensor is present
inside the lm90 DT node. Otherwise, the driver behavior
will be the same.

Signed-off-by: Wei Ni <wni@nvidia.com>
---
 drivers/hwmon/lm90.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index cb33dcf..2a385c5 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -96,6 +96,8 @@
 #include <linux/sysfs.h>
 #include <linux/interrupt.h>
 #include <linux/regulator/consumer.h>
+#include <linux/of.h>
+#include <linux/thermal.h>
 
 /*
  * Addresses to scan
@@ -119,6 +121,13 @@ static const unsigned short normal_i2c[] = {
 enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680,
 	max6646, w83l771, max6696, sa56004, g781, tmp451 };
 
+enum sensor_id {
+	LOCAL = 0,
+	REMOTE,
+	REMOTE2,
+	SENSOR_ID_END,
+};
+
 /*
  * The LM90 registers
  */
@@ -368,6 +377,7 @@ struct lm90_data {
 	struct i2c_client *client;
 	struct device *hwmon_dev;
 	const struct attribute_group *groups[6];
+	struct thermal_zone_device *tz[SENSOR_ID_END];
 	struct mutex update_lock;
 	struct regulator *regulator;
 	char valid; /* zero until following fields are valid */
@@ -874,6 +884,24 @@ static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
 	return sprintf(buf, "%d\n", read_temp11(dev, attr->index));
 }
 
+static int lm90_read_local_temp(void *dev, long *temp)
+{
+	*temp = read_temp11(dev, LOCAL_TEMP);
+	return 0;
+}
+
+static int lm90_read_remote_temp(void *dev, long *temp)
+{
+	*temp = read_temp11(dev, REMOTE_TEMP);
+	return 0;
+}
+
+static int lm90_read_remote2_temp(void *dev, long *temp)
+{
+	*temp = read_temp11(dev, REMOTE2_TEMP);
+	return 0;
+}
+
 static int write_temp11(struct device *dev, int nr, int index, long val)
 {
 	struct {
@@ -1653,6 +1681,33 @@ static int lm90_probe(struct i2c_client *client,
 		}
 	}
 
+	data->tz[LOCAL] = thermal_zone_of_sensor_register(&client->dev,
+							LOCAL,
+							&client->dev,
+							lm90_read_local_temp,
+							NULL);
+	if (IS_ERR(data->tz[LOCAL]))
+		data->tz[LOCAL] = NULL;
+
+	data->tz[REMOTE] = thermal_zone_of_sensor_register(&client->dev,
+							REMOTE,
+							&client->dev,
+							lm90_read_remote_temp,
+							NULL);
+	if (IS_ERR(data->tz[REMOTE]))
+		data->tz[REMOTE] = NULL;
+
+	if (data->flags & LM90_HAVE_TEMP3) {
+		data->tz[REMOTE2] = thermal_zone_of_sensor_register(
+							&client->dev,
+							REMOTE2,
+							&client->dev,
+							lm90_read_remote2_temp,
+							NULL);
+		if (IS_ERR(data->tz[REMOTE2]))
+			data->tz[REMOTE2] = NULL;
+	}
+
 	return 0;
 
 exit_unregister:
@@ -1668,8 +1723,11 @@ exit_restore:
 
 static int lm90_remove(struct i2c_client *client)
 {
+	int i;
 	struct lm90_data *data = i2c_get_clientdata(client);
 
+	for (i = 0; i < SENSOR_ID_END; i++)
+		thermal_zone_of_sensor_unregister(&client->dev, data->tz[i]);
 	hwmon_device_unregister(data->hwmon_dev);
 	device_remove_file(&client->dev, &dev_attr_pec);
 	lm90_restore_conf(client, data);
-- 
1.8.1.5

  parent reply	other threads:[~2014-08-25  6:29 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-25  6:29 [PATCH v3 0/4] expose lm90 to thermal fw Wei Ni
     [not found] ` <1408948188-4181-1-git-send-email-wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-25  6:29   ` [PATCH v3 1/4] hwmon: (lm90) split set&show temp as common codes Wei Ni
     [not found]     ` <1408948188-4181-2-git-send-email-wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-25 12:23       ` Mikko Perttunen
     [not found]         ` <53FB2AAA.30601-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-26  2:27           ` Wei Ni
     [not found]             ` <53FBF09F.8050502-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-26 12:17               ` Eduardo Valentin
2014-08-26 16:37                 ` Stephen Warren
     [not found]                   ` <53FCB7C6.8000503-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2014-08-27  2:25                     ` Wei Ni
2014-08-25  6:29 ` Wei Ni [this message]
2014-08-25  6:29 ` [PATCH v3 3/4] thermal: add more description for thermal-zones Wei Ni
     [not found]   ` <1408948188-4181-4-git-send-email-wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-25 11:07     ` Eduardo Valentin
2014-08-26  2:17       ` Wei Ni
     [not found]         ` <53FBEE39.2020001-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-26 12:12           ` Eduardo Valentin
2014-08-27  2:54             ` Wei Ni
2014-08-27 13:32               ` Eduardo Valentin
2014-08-28  1:50                 ` Wei Ni
     [not found]                   ` <53FE8AC9.2070907-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-28 13:21                     ` Eduardo Valentin
2014-08-29  3:03                       ` Wei Ni
     [not found]                         ` <53FFED7B.6010508-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-29 11:32                           ` edubezval-Re5JQEeQqe8AvxtiuMwx3w
     [not found]                             ` <CAC-25o-9OQ-wfpCJmgDGB0kqDHwUc15XX7Ay7Pes6UmpJakUkQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-09-01 10:26                               ` Wei Ni
     [not found]                                 ` <540449BC.2050807-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-09-05  9:41                                   ` Wei Ni
     [not found]                                     ` <54098538.1000505-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-30 19:43                                       ` Eduardo Valentin
2014-09-10  8:14                                         ` Wei Ni
2014-09-10 14:10                                           ` Eduardo Valentin
2014-08-26  3:03       ` Wei Ni
2014-08-26 12:08         ` Eduardo Valentin
2014-08-27  2:31           ` Wei Ni
2014-08-25  6:29 ` [PATCH v3 4/4] ARM: tegra: dalmore: add thermal zones for nct1008 Wei Ni
     [not found]   ` <1408948188-4181-5-git-send-email-wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2014-08-25 11:08     ` Eduardo Valentin
2014-08-26  2:21       ` Wei Ni
2014-08-25 11:10     ` Eduardo Valentin
2014-08-26  2:24       ` Wei Ni

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=1408948188-4181-3-git-send-email-wni@nvidia.com \
    --to=wni@nvidia.com \
    --cc=edubezval@gmail.com \
    --cc=khali@linux-fr.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lm-sensors@lm-sensors.org \
    --cc=swarren@wwwdotorg.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).