]> Pileus Git - ~andy/linux/commitdiff
hwmon: (ina2xx) Add device tree support to pass the shunt resistor
authorTang Yuantian <yuantian.tang@freescale.com>
Wed, 19 Jun 2013 06:50:20 +0000 (14:50 +0800)
committerGuenter Roeck <linux@roeck-us.net>
Thu, 27 Jun 2013 17:31:42 +0000 (10:31 -0700)
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>
[Guenter Roeck: Added missing of.h include]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Documentation/devicetree/bindings/i2c/ina2xx.txt [new file with mode: 0644]
Documentation/hwmon/ina2xx
drivers/hwmon/ina2xx.c

diff --git a/Documentation/devicetree/bindings/i2c/ina2xx.txt b/Documentation/devicetree/bindings/i2c/ina2xx.txt
new file mode 100644 (file)
index 0000000..a2ad85d
--- /dev/null
@@ -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>;
+};
index 03444f9d833fa4a6e19bc1bec8385cc6f1a00df7..4223c2d3b508be75e5764e67fe979b23aec90cc7 100644 (file)
@@ -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.
index 4958b2f89dcefff53354e18c6c37f6f356f6eeb2..d917a2d8c30ffde4183382d8370bef781dd0e824 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/hwmon.h>
 #include <linux/hwmon-sysfs.h>
 #include <linux/jiffies.h>
+#include <linux/of.h>
 
 #include <linux/platform_data/ina2xx.h>
 
@@ -221,6 +222,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 +236,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)