Skip to contentSkip to conversation

hwmon: (adm1275): Add device tree param for shunt resistor

PATCH Superseded Kun Yi 2 participants 3 messages Sep 28, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kun Yi

author
#0 lore raw

PATCH 1/1 hwmon: (adm1275): Add device tree param for shunt resistor

The ADM series of hotswap controllers support extending the current measurement range by using a sensing resistor value other than the typical 1 mOhm. For example, using a 0.5 mOhm sensing resistor doubles the maximal current can be measured.

Current driver assumes a shunt resistor value of 1 mOhm in calculation, meaning for other resistor values, hwmon will report scaled current/power measurements. This patch adds a device tree parameter so that individual boards can configure its shunt resistor value.

---
 .../devicetree/bindings/hwmon/adm1275.txt     | 19 +++++++++++++++++++
 Documentation/hwmon/adm1275                   |  3 +++
 drivers/hwmon/pmbus/adm1275.c                 | 15 +++++++++++++--
 3 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adm1275.txt
Documentation/devicetree/bindings/hwmon/adm1275.txt new file +19 -0
new file mode 100644
index 000000000000..a182fa195ed1
@@ -0,0 +1,19 @@
+adm1275 properties
+
+Required properties:
+- compatible: Must be one of the supported compatible strings in
+  Documentation/hwmon/adm1275
+- reg: I2C address
+
+Optional properties:
+
+- shunt-resistor-micro-ohms
+	Shunt resistor value in micro-Ohm
+
+Example:
+
+adm1272@10 {
+	compatible = "adi,adm1272";
+	reg = <0x10>;
+	shunt-resistor-micro-ohms = <500>;
+};
Documentation/hwmon/adm1275 +3 -0
index 39033538eb03..5e277b0d91ce 100644
@@ -58,6 +58,9 @@ The ADM1075, unlike many other PMBus devices, does not support internal voltage
 or current scaling. Reported voltages, currents, and power are raw measurements,
 and will typically have to be scaled.
 
+The shunt value in micro-ohms can be set via device tree at compile-time. Please
+refer to the Documentation/devicetree/bindings/hwmon/adm1275.txt for bindings
+if the device tree is used.
 
 Platform data support
 ---------------------
drivers/hwmon/pmbus/adm1275.c +13 -2
index 13600fa79e7f..f569372c9204 100644
@@ -373,6 +373,7 @@ static int adm1275_probe(struct i2c_client *client,
 	const struct coefficients *coefficients;
 	int vindex = -1, voindex = -1, cindex = -1, pindex = -1;
 	int tindex = -1;
+	u32 shunt;
 
 	if (!i2c_check_functionality(client->adapter,
 				     I2C_FUNC_SMBUS_READ_BYTE_DATA
@@ -421,6 +422,13 @@ static int adm1275_probe(struct i2c_client *client,
 	if (!data)
 		return -ENOMEM;
 
+	if (of_property_read_u32(client->dev.of_node,
+				 "shunt-resistor-micro-ohms", &shunt))
+		shunt = 1000; /* 1 mOhm if not set via DT */
+
+	if (shunt == 0)
+		return -EINVAL;
+
 	data->id = mid->driver_data;
 
 	info = &data->info;
@@ -654,12 +662,15 @@ static int adm1275_probe(struct i2c_client *client,
 		info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R;
 	}
 	if (cindex >= 0) {
-		info->m[PSC_CURRENT_OUT] = coefficients[cindex].m;
+		/* Scale current with sense resistor value */
+		info->m[PSC_CURRENT_OUT] =
+			coefficients[cindex].m * shunt / 1000;
 		info->b[PSC_CURRENT_OUT] = coefficients[cindex].b;
 		info->R[PSC_CURRENT_OUT] = coefficients[cindex].R;
 	}
 	if (pindex >= 0) {
-		info->m[PSC_POWER] = coefficients[pindex].m;
+		info->m[PSC_POWER] =
+			coefficients[pindex].m * shunt / 1000;
 		info->b[PSC_POWER] = coefficients[pindex].b;
 		info->R[PSC_POWER] = coefficients[pindex].R;
 	}
Signature · 1 line
2.19.0.605.g01d371f741-goog
maintainer
#1 lore raw
Quoted 10 lines · Kun Yi

The ADM series of hotswap controllers support extending the current measurement range by using a sensing resistor value other than the typical 1 mOhm. For example, using a 0.5 mOhm sensing resistor doubles the maximal current can be measured.

Current driver assumes a shunt resistor value of 1 mOhm in calculation, meaning for other resistor values, hwmon will report scaled current/power measurements. This patch adds a device tree parameter so that individual boards can configure its shunt resistor value.

Please copy DT maintainers for all DT changes.

Quoted 14 lines
---
 .../devicetree/bindings/hwmon/adm1275.txt     | 19 +++++++++++++++++++
 Documentation/hwmon/adm1275                   |  3 +++
 drivers/hwmon/pmbus/adm1275.c                 | 15 +++++++++++++--
 3 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adm1275.txt
Documentation/devicetree/bindings/hwmon/adm1275.txt new file +0 -0
new file mode 100644
index 000000000000..a182fa195ed1

Documentation/devicetree/bindings/hwmon/adm1275.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/adm1275.txt new file +5 -0
@@ -0,0 +1,19 @@
+adm1275 properties
+
+Required properties:
+- compatible: Must be one of the supported compatible strings in
+  Documentation/hwmon/adm1275

It would be more appropriate to list those here as devicetree properties. The information in Documentation/hwmon/adm1275 does not include the "adi," prefix.

Thanks,
Guenter

Quoted 75 lines
Documentation/devicetree/bindings/hwmon/adm1275.txt new file +14 -0
+- reg: I2C address
+
+Optional properties:
+
+- shunt-resistor-micro-ohms
+	Shunt resistor value in micro-Ohm
+
+Example:
+
+adm1272@10 {
+	compatible = "adi,adm1272";
+	reg = <0x10>;
+	shunt-resistor-micro-ohms = <500>;
+};
Documentation/hwmon/adm1275 +3 -0
index 39033538eb03..5e277b0d91ce 100644
@@ -58,6 +58,9 @@ The ADM1075, unlike many other PMBus devices, does not support internal voltage
 or current scaling. Reported voltages, currents, and power are raw measurements,
 and will typically have to be scaled.
 
+The shunt value in micro-ohms can be set via device tree at compile-time. Please
+refer to the Documentation/devicetree/bindings/hwmon/adm1275.txt for bindings
+if the device tree is used.
 
 Platform data support
 ---------------------
drivers/hwmon/pmbus/adm1275.c +13 -2
index 13600fa79e7f..f569372c9204 100644
@@ -373,6 +373,7 @@ static int adm1275_probe(struct i2c_client *client,
 	const struct coefficients *coefficients;
 	int vindex = -1, voindex = -1, cindex = -1, pindex = -1;
 	int tindex = -1;
+	u32 shunt;
 
 	if (!i2c_check_functionality(client->adapter,
 				     I2C_FUNC_SMBUS_READ_BYTE_DATA
@@ -421,6 +422,13 @@ static int adm1275_probe(struct i2c_client *client,
 	if (!data)
 		return -ENOMEM;
 
+	if (of_property_read_u32(client->dev.of_node,
+				 "shunt-resistor-micro-ohms", &shunt))
+		shunt = 1000; /* 1 mOhm if not set via DT */
+
+	if (shunt == 0)
+		return -EINVAL;
+
 	data->id = mid->driver_data;
 
 	info = &data->info;
@@ -654,12 +662,15 @@ static int adm1275_probe(struct i2c_client *client,
 		info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R;
 	}
 	if (cindex >= 0) {
-		info->m[PSC_CURRENT_OUT] = coefficients[cindex].m;
+		/* Scale current with sense resistor value */
+		info->m[PSC_CURRENT_OUT] =
+			coefficients[cindex].m * shunt / 1000;
 		info->b[PSC_CURRENT_OUT] = coefficients[cindex].b;
 		info->R[PSC_CURRENT_OUT] = coefficients[cindex].R;
 	}
 	if (pindex >= 0) {
-		info->m[PSC_POWER] = coefficients[pindex].m;
+		info->m[PSC_POWER] =
+			coefficients[pindex].m * shunt / 1000;
 		info->b[PSC_POWER] = coefficients[pindex].b;
 		info->R[PSC_POWER] = coefficients[pindex].R;
 	}
Signature · 1 line
2.19.0.605.g01d371f741-goog
author
#2 lore raw

Thanks. I changed the documentation piece and submitted v2.

Quoted 122 lines · Guenter Roeck
Quoted 10 lines · Kun Yi

The ADM series of hotswap controllers support extending the current measurement range by using a sensing resistor value other than the typical 1 mOhm. For example, using a 0.5 mOhm sensing resistor doubles the maximal current can be measured.

Current driver assumes a shunt resistor value of 1 mOhm in calculation, meaning for other resistor values, hwmon will report scaled current/power measurements. This patch adds a device tree parameter so that individual boards can configure its shunt resistor value.

Please copy DT maintainers for all DT changes.

Review

Quoted 9 lines
---
 .../devicetree/bindings/hwmon/adm1275.txt     | 19 +++++++++++++++++++
 Documentation/hwmon/adm1275                   |  3 +++
 drivers/hwmon/pmbus/adm1275.c                 | 15 +++++++++++++--
 3 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adm1275.txt
(quoted diff) +0 -0

b/Documentation/devicetree/bindings/hwmon/adm1275.txt

Documentation/devicetree/bindings/hwmon/adm1275.txt line 5

Quoted 10 lines

new file mode 100644
index 000000000000..a182fa195ed1

Documentation/devicetree/bindings/hwmon/adm1275.txt new file +5 -0
@@ -0,0 +1,19 @@
+adm1275 properties
+
+Required properties:
+- compatible: Must be one of the supported compatible strings in
+  Documentation/hwmon/adm1275

It would be more appropriate to list those here as devicetree properties. The information in Documentation/hwmon/adm1275 does not include the "adi," prefix.

Thanks,
Guenter

Documentation/hwmon/adm1275 The ADM1075, unlike many other PMBus devices, does not

Quoted 19 lines
Documentation/devicetree/bindings/hwmon/adm1275.txt new file +14 -0
+- reg: I2C address
+
+Optional properties:
+
+- shunt-resistor-micro-ohms
+     Shunt resistor value in micro-Ohm
+
+Example:
+
+adm1272@10 {
+     compatible = "adi,adm1272";
+     reg = <0x10>;
+     shunt-resistor-micro-ohms = <500>;
+};
Documentation/hwmon/adm1275 +0 -0
index 39033538eb03..5e277b0d91ce 100644
@@ -58,6 +58,9 @@ The ADM1075, unlike many other PMBus devices, does not

support internal voltage

Documentation/hwmon/adm1275 The ADM1075, unlike many other PMBus devices, does not · line 58

Quoted 1 line
Documentation/hwmon/adm1275 +0 -0
 or current scaling. Reported voltages, currents, and power are raw

measurements,

Documentation/hwmon/adm1275 The ADM1075, unlike many other PMBus devices, does not support internal voltage

Quoted 3 lines
Documentation/hwmon/adm1275 +1 -0
 and will typically have to be scaled.
 
+The shunt value in micro-ohms can be set via device tree at

compile-time. Please

Documentation/hwmon/adm1275 The ADM1075, unlike many other PMBus devices, does not · line 62

Quoted 1 line
Documentation/hwmon/adm1275 +1 -0
+refer to the Documentation/devicetree/bindings/hwmon/adm1275.txt for

bindings

Review

Quoted 5 lines
Documentation/hwmon/adm1275 +1 -0
+if the device tree is used.
 
 Platform data support
 ---------------------
(quoted diff) +0 -0

b/drivers/hwmon/pmbus/adm1275.c

Quoted 46 lines

index 13600fa79e7f..f569372c9204 100644

drivers/hwmon/pmbus/adm1275.c +13 -3
@@ -373,6 +373,7 @@ static int adm1275_probe(struct i2c_client *client,
      const struct coefficients *coefficients;
      int vindex = -1, voindex = -1, cindex = -1, pindex = -1;
      int tindex = -1;
+     u32 shunt;
 
      if (!i2c_check_functionality(client->adapter,
                                   I2C_FUNC_SMBUS_READ_BYTE_DATA
@@ -421,6 +422,13 @@ static int adm1275_probe(struct i2c_client *client,
      if (!data)
              return -ENOMEM;
 
+     if (of_property_read_u32(client->dev.of_node,
+                              "shunt-resistor-micro-ohms", &shunt))
+             shunt = 1000; /* 1 mOhm if not set via DT */
+
+     if (shunt == 0)
+             return -EINVAL;
+
      data->id = mid->driver_data;
 
      info = &data->info;
@@ -654,12 +662,15 @@ static int adm1275_probe(struct i2c_client *client,
              info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R;
      }
      if (cindex >= 0) {
-             info->m[PSC_CURRENT_OUT] = coefficients[cindex].m;
+             /* Scale current with sense resistor value */
+             info->m[PSC_CURRENT_OUT] =
+                     coefficients[cindex].m * shunt / 1000;
              info->b[PSC_CURRENT_OUT] = coefficients[cindex].b;
              info->R[PSC_CURRENT_OUT] = coefficients[cindex].R;
      }
      if (pindex >= 0) {
-             info->m[PSC_POWER] = coefficients[pindex].m;
+             info->m[PSC_POWER] =
+                     coefficients[pindex].m * shunt / 1000;
              info->b[PSC_POWER] = coefficients[pindex].b;
              info->R[PSC_POWER] = coefficients[pindex].R;
      }
--

2.19.0.605.g01d371f741-goog

Signature · 2 lines
Regards,
Kun