Skip to content

Commit 31e7ad7

Browse files
Tang Yuantiangroeck
authored andcommitted
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 <[email protected]> [Guenter Roeck: Added missing of.h include] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 87438c2 commit 31e7ad7

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
};

Documentation/hwmon/ina2xx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ The INA226 monitors both a shunt voltage drop and bus supply voltage.
4444
The INA230 is a high or low side current shunt and power monitor with an I2C
4545
interface. The INA230 monitors both a shunt voltage drop and bus supply voltage.
4646

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.

drivers/hwmon/ina2xx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/hwmon.h>
3535
#include <linux/hwmon-sysfs.h>
3636
#include <linux/jiffies.h>
37+
#include <linux/of.h>
3738

3839
#include <linux/platform_data/ina2xx.h>
3940

@@ -221,6 +222,7 @@ static int ina2xx_probe(struct i2c_client *client,
221222
struct ina2xx_data *data;
222223
struct ina2xx_platform_data *pdata;
223224
int ret;
225+
u32 val;
224226
long shunt = 10000; /* default shunt value 10mOhms */
225227

226228
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
@@ -234,6 +236,9 @@ static int ina2xx_probe(struct i2c_client *client,
234236
pdata =
235237
(struct ina2xx_platform_data *)client->dev.platform_data;
236238
shunt = pdata->shunt_uohms;
239+
} else if (!of_property_read_u32(client->dev.of_node,
240+
"shunt-resistor", &val)) {
241+
shunt = val;
237242
}
238243

239244
if (shunt <= 0)

0 commit comments

Comments
 (0)