linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Titinger <mtitinger@baylibre.com>
To: linux@roeck-us.net, jdelvare@suse.com
Cc: lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org,
	Marc Titinger <mtitinger@baylibre.com>
Subject: [PATCH 2/2] hwmon: ina2xx: give precedence to DT over checking for platform data.
Date: Mon, 26 Oct 2015 17:24:33 +0100	[thread overview]
Message-ID: <1445876673-32180-3-git-send-email-mtitinger@baylibre.com> (raw)
In-Reply-To: <1445876673-32180-1-git-send-email-mtitinger@baylibre.com>
In-Reply-To: <562B7D56.3010700@roeck-us.net>

when checking for the value of the shunt resistor.

Signed-off-by: Marc Titinger <mtitinger@baylibre.com>
---
 drivers/hwmon/ina2xx.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index 3edd163..1946433 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -414,7 +414,6 @@ static const struct attribute_group ina226_group = {
 static int ina2xx_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
-	struct ina2xx_platform_data *pdata;
 	struct device *dev = &client->dev;
 	struct ina2xx_data *data;
 	struct device *hwmon_dev;
@@ -425,14 +424,13 @@ static int ina2xx_probe(struct i2c_client *client,
 	if (!data)
 		return -ENOMEM;
 
-	if (dev_get_platdata(dev)) {
-		pdata = dev_get_platdata(dev);
-		data->rshunt = pdata->shunt_uohms;
-	} else if (!of_property_read_u32(dev->of_node,
-					 "shunt-resistor", &val)) {
-		data->rshunt = val;
-	} else {
-		data->rshunt = INA2XX_RSHUNT_DEFAULT;
+	if (of_property_read_u32(dev->of_node, "shunt-resistor", &val) < 0) {
+		struct ina2xx_platform_data *pdata = dev_get_platdata(dev);
+
+		if (pdata)
+			val = pdata->shunt_uohms;
+		else
+			val = INA2XX_RSHUNT_DEFAULT;
 	}
 
 	/* set the device type */
@@ -440,10 +438,11 @@ static int ina2xx_probe(struct i2c_client *client,
 	data->config = &ina2xx_config[data->kind];
 	data->client = client;
 
-	if (data->rshunt <= 0 ||
-	    data->rshunt > data->config->calibration_factor)
+	if (val <= 0 || val > data->config->calibration_factor)
 		return -ENODEV;
 
+	data->rshunt = val;
+
 	ina2xx_regmap_config.max_register = data->config->registers;
 
 	data->regmap = devm_regmap_init_i2c(client, &ina2xx_regmap_config);
-- 
1.9.1


  parent reply	other threads:[~2015-10-26 16:25 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-19 16:21 [RFC] hwmon: ina2xx: allow for actual measurement bandwidth above 160 Hz Marc Titinger
2015-10-20  1:32 ` Guenter Roeck
2015-10-20  7:58   ` Marc Titinger
2015-10-20  8:20   ` [PATCH v2] " Marc Titinger
2015-10-20 12:54     ` Guenter Roeck
2015-10-20 13:17       ` Marc Titinger
2015-10-20 13:30         ` Guenter Roeck
2015-10-20 13:46           ` Marc Titinger
2015-10-20 17:00             ` Guenter Roeck
2015-10-21  7:46               ` Marc Titinger
2015-10-20 13:52           ` Michael Turquette
2015-10-23 16:13       ` [RFC] hwmon: ina2xx: port to using remap, improve bandwidth Marc Titinger
2015-10-23 16:49         ` kbuild test robot
2015-10-23 16:52         ` Guenter Roeck
2015-10-23 20:35           ` Marc Titinger
2015-10-24  2:21             ` Guenter Roeck
2015-10-24 12:45             ` Guenter Roeck
2015-10-26 16:24               ` [PATCH 0/2] hwmon: ina2xx: convert driver to using regmap Marc Titinger
2015-10-26 16:24               ` [PATCH 1/2] " Marc Titinger
2015-10-27  1:02                 ` Guenter Roeck
2015-10-27  1:12                 ` Guenter Roeck
2015-10-27  9:51                   ` [PATCH v2 " Marc Titinger
2015-10-28  2:47                     ` Guenter Roeck
2015-10-28  9:23                       ` Marc Titinger
2015-10-26 16:24               ` Marc Titinger [this message]
2015-10-27  1:10                 ` [PATCH 2/2] hwmon: ina2xx: give precedence to DT over checking for platform data Guenter Roeck
2015-10-27  9:51                   ` [PATCH v2 " Marc Titinger
2015-10-23 16:55         ` [RFC] hwmon: ina2xx: port to using remap, improve bandwidth kbuild test robot
2015-10-23 20:10         ` kbuild test robot

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=1445876673-32180-3-git-send-email-mtitinger@baylibre.com \
    --to=mtitinger@baylibre.com \
    --cc=jdelvare@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lm-sensors@lm-sensors.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).