From: Wei Ni <wni@nvidia.com>
To: khali@linux-fr.org, swarren@wwwdotorg.org
Cc: linux@roeck-us.net, MLongnecker@nvidia.com,
linux-arm-kernel@lists.infradead.org, lm-sensors@lm-sensors.org,
linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org,
Wei Ni <wni@nvidia.com>
Subject: [PATCH 1/2] hwmon: (lm90) Add power control
Date: Wed, 7 Aug 2013 14:52:37 +0800 [thread overview]
Message-ID: <1375858358-15070-2-git-send-email-wni@nvidia.com> (raw)
In-Reply-To: <1375858358-15070-1-git-send-email-wni@nvidia.com>
The device lm90 can be controlled by the vdd rail.
Adding the power control support to power on/off the vdd rail.
And make sure that power is enabled before accessing the device.
Signed-off-by: Wei Ni <wni@nvidia.com>
---
drivers/hwmon/lm90.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index cdff742..eeb0115 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -89,6 +89,8 @@
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/sysfs.h>
+#include <linux/delay.h>
+#include <linux/regulator/consumer.h>
/*
* Addresses to scan
@@ -179,6 +181,8 @@ enum chips { lm90, adm1032, lm99, lm86, max6657, max6659, adt7461, max6680,
#define LM90_HAVE_TEMP3 (1 << 6) /* 3rd temperature sensor */
#define LM90_HAVE_BROKEN_ALERT (1 << 7) /* Broken alert */
+#define POWER_ON_DELAY 20 /*ms*/
+
/*
* Driver data (common to all clients)
*/
@@ -302,6 +306,7 @@ static const struct lm90_params lm90_params[] = {
struct lm90_data {
struct device *hwmon_dev;
struct mutex update_lock;
+ struct regulator *lm90_reg;
char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */
int kind;
@@ -1391,6 +1396,48 @@ static void lm90_init_client(struct i2c_client *client)
i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
}
+static int lm90_power_control(struct i2c_client *client, bool is_enable)
+{
+ struct lm90_data *data = i2c_get_clientdata(client);
+ int ret;
+
+ mutex_lock(&data->update_lock);
+
+ if (!data->lm90_reg) {
+ data->lm90_reg = regulator_get(&client->dev, "vdd");
+ if (IS_ERR_OR_NULL(data->lm90_reg)) {
+ if (PTR_ERR(data->lm90_reg) == -ENODEV)
+ dev_info(&client->dev,
+ "No regulator found for vdd. Assuming vdd is always powered.");
+ else
+ dev_warn(&client->dev,
+ "Error [%ld] in getting the regulator handle for vdd.\n",
+ PTR_ERR(data->lm90_reg));
+ data->lm90_reg = NULL;
+ mutex_unlock(&data->update_lock);
+ return -ENODEV;
+ }
+ }
+ if (is_enable) {
+ ret = regulator_enable(data->lm90_reg);
+ msleep(POWER_ON_DELAY);
+ } else {
+ ret = regulator_disable(data->lm90_reg);
+ }
+
+ if (ret < 0)
+ dev_err(&client->dev,
+ "Error in %s rail vdd, error %d\n",
+ (is_enable) ? "enabling" : "disabling", ret);
+ else
+ dev_info(&client->dev, "success in %s rail vdd\n",
+ (is_enable) ? "enabling" : "disabling");
+
+ mutex_unlock(&data->update_lock);
+
+ return ret;
+}
+
static int lm90_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -1406,6 +1453,10 @@ static int lm90_probe(struct i2c_client *client,
i2c_set_clientdata(client, data);
mutex_init(&data->update_lock);
+ err = lm90_power_control(client, true);
+ if (err < 0)
+ return err;
+
/* Set the device type */
data->kind = id->driver_data;
if (data->kind == adm1032) {
@@ -1483,6 +1534,7 @@ static int lm90_remove(struct i2c_client *client)
hwmon_device_unregister(data->hwmon_dev);
lm90_remove_files(client, data);
lm90_restore_conf(client, data);
+ lm90_power_control(client, false);
return 0;
}
--
1.7.9.5
next prev parent reply other threads:[~2013-08-07 6:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-07 6:52 [PATCH 0/2] Add power control for lm90 Wei Ni
2013-08-07 6:52 ` Wei Ni [this message]
[not found] ` <1375858358-15070-2-git-send-email-wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-08-07 7:03 ` [PATCH 1/2] hwmon: (lm90) Add power control Guenter Roeck
[not found] ` <5201F138.3080906-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2013-08-07 7:15 ` Wei Ni
2013-08-07 7:27 ` Alexander Shiyan
[not found] ` <1375860442.896960598-syZRKAW8O9ZsdVUOrk1QfQ@public.gmane.org>
2013-08-07 7:32 ` Wei Ni
[not found] ` <5201F811.9050602-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-08-07 7:50 ` Guenter Roeck
2013-08-07 8:07 ` Wei Ni
[not found] ` <52020047.1080705-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-08-07 8:45 ` Alexander Shiyan
[not found] ` <1375865105.562600640-y1D/hCXJdYBsdVUOrk1QfQ@public.gmane.org>
2013-08-07 9:35 ` Wei Ni
[not found] ` <520214C9.1010200-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-08-07 16:06 ` Stephen Warren
[not found] ` <52027086.1090608-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-08-07 16:44 ` Guenter Roeck
2013-08-07 7:45 ` Guenter Roeck
2013-08-07 6:52 ` [PATCH 2/2] ARM: dt: t114 dalmore: add dt entry for nct1008 Wei Ni
[not found] ` <1375858358-15070-3-git-send-email-wni-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2013-08-07 16:03 ` Stephen Warren
[not found] ` <52026FEE.9070003-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2013-08-08 2:36 ` 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=1375858358-15070-2-git-send-email-wni@nvidia.com \
--to=wni@nvidia.com \
--cc=MLongnecker@nvidia.com \
--cc=khali@linux-fr.org \
--cc=linux-arm-kernel@lists.infradead.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