Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (ina2xx) Add device tree support to pass the shunt resistor

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>

authored by

Tang Yuantian and committed by
Guenter Roeck
31e7ad74 87438c2c

+30 -1
+22
Documentation/devicetree/bindings/i2c/ina2xx.txt
··· 1 + ina2xx properties 2 + 3 + Required properties: 4 + - compatible: Must be one of the following: 5 + - "ti,ina219" for ina219 6 + - "ti,ina220" for ina220 7 + - "ti,ina226" for ina226 8 + - "ti,ina230" for ina230 9 + - reg: I2C address 10 + 11 + Optional properties: 12 + 13 + - shunt-resistor 14 + Shunt resistor value in micro-Ohm 15 + 16 + Example: 17 + 18 + ina220@44 { 19 + compatible = "ti,ina220"; 20 + reg = <0x44>; 21 + shunt-resistor = <1000>; 22 + };
+3 -1
Documentation/hwmon/ina2xx
··· 44 44 The INA230 is a high or low side current shunt and power monitor with an I2C 45 45 interface. The INA230 monitors both a shunt voltage drop and bus supply voltage. 46 46 47 - The shunt value in micro-ohms can be set via platform data. 47 + The shunt value in micro-ohms can be set via platform data or device tree. 48 + Please refer to the Documentation/devicetree/bindings/i2c/ina2xx.txt for bindings 49 + if the device tree is used.
+5
drivers/hwmon/ina2xx.c
··· 34 34 #include <linux/hwmon.h> 35 35 #include <linux/hwmon-sysfs.h> 36 36 #include <linux/jiffies.h> 37 + #include <linux/of.h> 37 38 38 39 #include <linux/platform_data/ina2xx.h> 39 40 ··· 222 221 struct ina2xx_data *data; 223 222 struct ina2xx_platform_data *pdata; 224 223 int ret; 224 + u32 val; 225 225 long shunt = 10000; /* default shunt value 10mOhms */ 226 226 227 227 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) ··· 236 234 pdata = 237 235 (struct ina2xx_platform_data *)client->dev.platform_data; 238 236 shunt = pdata->shunt_uohms; 237 + } else if (!of_property_read_u32(client->dev.of_node, 238 + "shunt-resistor", &val)) { 239 + shunt = val; 239 240 } 240 241 241 242 if (shunt <= 0)