devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] hwmon: (ina2xx) Add device tree support to pass the shunt resistor
@ 2013-06-19  6:50 Yuantian.Tang
  2013-06-19 15:43 ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: Yuantian.Tang @ 2013-06-19  6:50 UTC (permalink / raw)
  To: linux; +Cc: Tang Yuantian, devicetree-discuss, linux-doc, lm-sensors

From: Tang Yuantian <yuantian.tang@freescale.com>

Adding another way that is device tree to pass the shunt resistor
value to driver except for platform data.

Signed-off-by: Tang Yuantian <Yuantian.Tang@freescale.com>
---
v2:
	- add device tree bindings file
	- refine the code per Guenter's suggestion

 Documentation/devicetree/bindings/i2c/ina2xx.txt | 22 ++++++++++++++++++++++
 Documentation/hwmon/ina2xx                       |  4 +++-
 drivers/hwmon/ina2xx.c                           |  4 ++++
 3 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/i2c/ina2xx.txt

diff --git a/Documentation/devicetree/bindings/i2c/ina2xx.txt b/Documentation/devicetree/bindings/i2c/ina2xx.txt
new file mode 100644
index 0000000..a2ad85d
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/ina2xx.txt
@@ -0,0 +1,22 @@
+ina2xx properties
+
+Required properties:
+- compatible: Must be one of the following:
+	- "ti,ina219" for ina219
+	- "ti,ina220" for ina220
+	- "ti,ina226" for ina226
+	- "ti,ina230" for ina230
+- reg: I2C address
+
+Optional properties:
+
+- shunt-resistor
+	Shunt resistor value in micro-Ohm
+
+Example:
+
+ina220@44 {
+	compatible = "ti,ina220";
+	reg = <0x44>;
+	shunt-resistor = <1000>;
+};
diff --git a/Documentation/hwmon/ina2xx b/Documentation/hwmon/ina2xx
index 03444f9..4223c2d 100644
--- a/Documentation/hwmon/ina2xx
+++ b/Documentation/hwmon/ina2xx
@@ -44,4 +44,6 @@ The INA226 monitors both a shunt voltage drop and bus supply voltage.
 The INA230 is a high or low side current shunt and power monitor with an I2C
 interface. The INA230 monitors both a shunt voltage drop and bus supply voltage.
 
-The shunt value in micro-ohms can be set via platform data.
+The shunt value in micro-ohms can be set via platform data or device tree.
+Please refer to the Documentation/devicetree/bindings/i2c/ina2xx.txt for bindings
+if the device tree is used.
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index 4958b2f..a52d5f0 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -221,6 +221,7 @@ static int ina2xx_probe(struct i2c_client *client,
 	struct ina2xx_data *data;
 	struct ina2xx_platform_data *pdata;
 	int ret;
+	u32 val;
 	long shunt = 10000; /* default shunt value 10mOhms */
 
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
@@ -234,6 +235,9 @@ static int ina2xx_probe(struct i2c_client *client,
 		pdata =
 		  (struct ina2xx_platform_data *)client->dev.platform_data;
 		shunt = pdata->shunt_uohms;
+	} else if (!of_property_read_u32(client->dev.of_node,
+				"shunt-resistor", &val)) {
+			shunt = val;
 	}
 
 	if (shunt <= 0)
-- 
1.8.0



_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] hwmon: (ina2xx) Add device tree support to pass the shunt resistor
  2013-06-19  6:50 [PATCH v2] hwmon: (ina2xx) Add device tree support to pass the shunt resistor Yuantian.Tang
@ 2013-06-19 15:43 ` Guenter Roeck
  2013-06-20  2:27   ` Tang Yuantian-B29983
  0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2013-06-19 15:43 UTC (permalink / raw)
  To: Yuantian.Tang; +Cc: khali, lm-sensors, devicetree-discuss, linux-doc

On Wed, Jun 19, 2013 at 02:50:20PM +0800, Yuantian.Tang@freescale.com wrote:
> From: Tang Yuantian <yuantian.tang@freescale.com>
> 
> Adding another way that is device tree to pass the shunt resistor
> value to driver except for platform data.
> 
> Signed-off-by: Tang Yuantian <Yuantian.Tang@freescale.com>

I noticed that of.h include was missing. No need to re-send; I added it myself.
Applied to -next.

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH v2] hwmon: (ina2xx) Add device tree support to pass the shunt resistor
  2013-06-19 15:43 ` Guenter Roeck
@ 2013-06-20  2:27   ` Tang Yuantian-B29983
  2013-06-20  2:40     ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: Tang Yuantian-B29983 @ 2013-06-20  2:27 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: khali@linux-fr.org, lm-sensors@lm-sensors.org,
	devicetree-discuss@lists.ozlabs.org, linux-doc@vger.kernel.org



> -----Original Message-----
> From: Guenter Roeck [mailto:linux@roeck-us.net]
> Sent: 2013年6月19日 星期三 23:43
> To: Tang Yuantian-B29983
> Cc: khali@linux-fr.org; lm-sensors@lm-sensors.org; devicetree-
> discuss@lists.ozlabs.org; linux-doc@vger.kernel.org
> Subject: Re: [PATCH v2] hwmon: (ina2xx) Add device tree support to pass
> the shunt resistor
> 
> On Wed, Jun 19, 2013 at 02:50:20PM +0800, Yuantian.Tang@freescale.com
> wrote:
> > From: Tang Yuantian <yuantian.tang@freescale.com>
> >
> > Adding another way that is device tree to pass the shunt resistor
> > value to driver except for platform data.
> >
> > Signed-off-by: Tang Yuantian <Yuantian.Tang@freescale.com>
> 
> I noticed that of.h include was missing. No need to re-send; I added it
> myself.
> Applied to -next.
> 

Thanks for your help. Of.h is already included in i2c.h.
If it is really needed, I should have seen the warning or error when compile.
Including it explicitly is also a good point.

Regards,
Yuantian

> Thanks,
> Guenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] hwmon: (ina2xx) Add device tree support to pass the shunt resistor
  2013-06-20  2:27   ` Tang Yuantian-B29983
@ 2013-06-20  2:40     ` Guenter Roeck
  2013-06-20  2:45       ` Tang Yuantian-B29983
  0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2013-06-20  2:40 UTC (permalink / raw)
  To: Tang Yuantian-B29983
  Cc: khali@linux-fr.org, lm-sensors@lm-sensors.org,
	devicetree-discuss@lists.ozlabs.org, linux-doc@vger.kernel.org

On Thu, Jun 20, 2013 at 02:27:18AM +0000, Tang Yuantian-B29983 wrote:
> 
> 
> > -----Original Message-----
> > From: Guenter Roeck [mailto:linux@roeck-us.net]
> > Sent: 2013年6月19日 星期三 23:43
> > To: Tang Yuantian-B29983
> > Cc: khali@linux-fr.org; lm-sensors@lm-sensors.org; devicetree-
> > discuss@lists.ozlabs.org; linux-doc@vger.kernel.org
> > Subject: Re: [PATCH v2] hwmon: (ina2xx) Add device tree support to pass
> > the shunt resistor
> > 
> > On Wed, Jun 19, 2013 at 02:50:20PM +0800, Yuantian.Tang@freescale.com
> > wrote:
> > > From: Tang Yuantian <yuantian.tang@freescale.com>
> > >
> > > Adding another way that is device tree to pass the shunt resistor
> > > value to driver except for platform data.
> > >
> > > Signed-off-by: Tang Yuantian <Yuantian.Tang@freescale.com>
> > 
> > I noticed that of.h include was missing. No need to re-send; I added it
> > myself.
> > Applied to -next.
> > 
> 
> Thanks for your help. Of.h is already included in i2c.h.
> If it is really needed, I should have seen the warning or error when compile.
> Including it explicitly is also a good point.
> 
Common rule is to include a file if its definitions are used. We can not rely
on some other file including it for us, since it is not guaranteed that this
will always be the case.

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH v2] hwmon: (ina2xx) Add device tree support to pass the shunt resistor
  2013-06-20  2:40     ` Guenter Roeck
@ 2013-06-20  2:45       ` Tang Yuantian-B29983
  0 siblings, 0 replies; 5+ messages in thread
From: Tang Yuantian-B29983 @ 2013-06-20  2:45 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: khali@linux-fr.org, lm-sensors@lm-sensors.org,
	devicetree-discuss@lists.ozlabs.org, linux-doc@vger.kernel.org


> -----Original Message-----
> From: Guenter Roeck [mailto:linux@roeck-us.net]
> Sent: 2013年6月20日 星期四 10:40
> To: Tang Yuantian-B29983
> Cc: khali@linux-fr.org; lm-sensors@lm-sensors.org; devicetree-
> discuss@lists.ozlabs.org; linux-doc@vger.kernel.org
> Subject: Re: [PATCH v2] hwmon: (ina2xx) Add device tree support to pass
> the shunt resistor
> 
> On Thu, Jun 20, 2013 at 02:27:18AM +0000, Tang Yuantian-B29983 wrote:
> >
> >
> > > -----Original Message-----
> > > From: Guenter Roeck [mailto:linux@roeck-us.net]
> > > Sent: 2013年6月19日 星期三 23:43
> > > To: Tang Yuantian-B29983
> > > Cc: khali@linux-fr.org; lm-sensors@lm-sensors.org; devicetree-
> > > discuss@lists.ozlabs.org; linux-doc@vger.kernel.org
> > > Subject: Re: [PATCH v2] hwmon: (ina2xx) Add device tree support to
> > > pass the shunt resistor
> > >
> > > On Wed, Jun 19, 2013 at 02:50:20PM +0800,
> > > Yuantian.Tang@freescale.com
> > > wrote:
> > > > From: Tang Yuantian <yuantian.tang@freescale.com>
> > > >
> > > > Adding another way that is device tree to pass the shunt resistor
> > > > value to driver except for platform data.
> > > >
> > > > Signed-off-by: Tang Yuantian <Yuantian.Tang@freescale.com>
> > >
> > > I noticed that of.h include was missing. No need to re-send; I added
> > > it myself.
> > > Applied to -next.
> > >
> >
> > Thanks for your help. Of.h is already included in i2c.h.
> > If it is really needed, I should have seen the warning or error when
> compile.
> > Including it explicitly is also a good point.
> >
> Common rule is to include a file if its definitions are used. We can not
> rely on some other file including it for us, since it is not guaranteed
> that this will always be the case.
> 
Good point, I will follow this rule. Thanks,

Thanks,
Yuantian

> Thanks,
> Guenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-06-20  2:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-19  6:50 [PATCH v2] hwmon: (ina2xx) Add device tree support to pass the shunt resistor Yuantian.Tang
2013-06-19 15:43 ` Guenter Roeck
2013-06-20  2:27   ` Tang Yuantian-B29983
2013-06-20  2:40     ` Guenter Roeck
2013-06-20  2:45       ` Tang Yuantian-B29983

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).