Skip to contentSkip to conversation

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

PATCH Guenter Roeck 1 participant 1 message Jun 18, 2013

lore
Share & tools
lore
#0 lore raw

[ resending with copy to lm-sensors mailing list ]

Quoted 35 lines · On Tue, Jun 18, 2013 at 03:42:26PM +0800, [email protected] wrote:

From: Tang Yuantian <[email protected]>

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

---
 Documentation/hwmon/ina2xx | 3 ++-
 drivers/hwmon/ina2xx.c     | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
Documentation/hwmon/ina2xx +2 -1
index 03444f9..6fb8b76 100644
@@ -44,4 +44,5 @@ 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 dts in which
+the property should be shunt-resistor-value.
drivers/hwmon/ina2xx.c +1 -0
index 4958b2f..ae2d27a 100644
@@ -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))

drivers/hwmon/ina2xx.c static int ina2xx_probe(struct i2c_client *client, · line 239

Quoted 5 lines
drivers/hwmon/ina2xx.c +3 -0
@@ -234,6 +235,11 @@ static int ina2xx_probe(struct i2c_client *client,
 		pdata >  		  (struct ina2xx_platform_data *)client->dev.platform_data;
 		shunt = pdata->shunt_uohms;
+	} else if (client->dev.of_node) {
+		ret = of_property_read_u32(client->dev.of_node,
+				"shunt-resistor-value", &val);

Please use "shunt-resistor"; this is what is used in the ina209 driver. Also, you don't have to check if client->dev.of_node is set; of_property_read_u32 does it for you. So you can simplify the code to

	} else if (!of_property_read_u32(client->dev.of_node, "shunt-resistor",
					&val) {
		shunt = val;
	}

You should also add Documentation/devicetree/bindings/i2c/ina2xx.txt and update Documentation/hwmon/ina2xx.

Thanks,
Guenter

Quoted 7 lines
drivers/hwmon/ina2xx.c +2 -0
+		if (ret = 0)
+			shunt = val;
 	}
 
 	if (shunt <= 0)
Signature · 1 line
1.8.0

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors