From patchwork Wed Aug 7 06:52:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Ni X-Patchwork-Id: 2839930 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D31FE9F498 for ; Wed, 7 Aug 2013 06:55:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D223C20165 for ; Wed, 7 Aug 2013 06:55:25 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DBDB72015A for ; Wed, 7 Aug 2013 06:55:24 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6xe4-0007rD-RU; Wed, 07 Aug 2013 06:54:57 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6xds-0005g7-Iw; Wed, 07 Aug 2013 06:54:44 +0000 Received: from hqemgate16.nvidia.com ([216.228.121.65]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V6xdZ-0005dP-HB for linux-arm-kernel@lists.infradead.org; Wed, 07 Aug 2013 06:54:27 +0000 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com id ; Tue, 06 Aug 2013 23:53:21 -0700 Received: from hqemhub01.nvidia.com ([172.20.12.94]) by hqnvupgp07.nvidia.com (PGP Universal service); Tue, 06 Aug 2013 23:54:02 -0700 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Tue, 06 Aug 2013 23:54:02 -0700 Received: from hkemhub01.nvidia.com (10.18.67.12) by hqemhub01.nvidia.com (172.20.150.30) with Microsoft SMTP Server (TLS) id 8.3.298.1; Tue, 6 Aug 2013 23:54:00 -0700 Received: from niwei-ubuntu.nvidia.com (10.18.67.5) by hkemhub01.nvidia.com (10.18.67.12) with Microsoft SMTP Server id 8.3.298.1; Wed, 7 Aug 2013 14:52:37 +0800 From: Wei Ni To: , Subject: [PATCH 1/2] hwmon: (lm90) Add power control Date: Wed, 7 Aug 2013 14:52:37 +0800 Message-ID: <1375858358-15070-2-git-send-email-wni@nvidia.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1375858358-15070-1-git-send-email-wni@nvidia.com> References: <1375858358-15070-1-git-send-email-wni@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130807_025425_812019_B07FBC17 X-CRM114-Status: GOOD ( 16.50 ) X-Spam-Score: -1.9 (-) Cc: Wei Ni , linux-kernel@vger.kernel.org, lm-sensors@lm-sensors.org, MLongnecker@nvidia.com, linux@roeck-us.net, linux-tegra@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #include #include +#include +#include /* * 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; }