Skip to contentSkip to conversation

hwmon: Add support for INA233

PATCH Applied Leo Yang 3 participants 8 messages Jan 16, 2025 – Mar 17, 2025

Subsystems (4)
lore
Share & tools
lore

Leo Yang

author maintainer
#0 lore raw

v4 cover hwmon: Add support for INA233

Support ina233 driver with binding documents.
---
Change in v4:
1. Change ti,current-lsb-microamp to
ti,maximum-expected-current-microamp.
- Link to v3: https://lore.kernel.org/linux-hwmon/[email protected]/
---
Change in v3:
1. Modify the content of MAINTAINER file.
2. Modify the content of binding.
3. Current_LSB is an unsigned integer, so coefficient m cannot be
negative after calculation, simplifying the calculation step.
4. Current_LSB uses microamp unit suffix, change code to read_u32.
5. Some typo fixes.
- Link to v2: https://lore.kernel.org/linux-hwmon/[email protected]/
---
Change in v2:
1. Merge the binding files into ti,ina2xx.yaml.
2. Fix typo and non-sense dev_err.
3. Improve program logic.
4. pmbus_driver_info changed to be allocated in probe.
- Link to v1: https://lore.kernel.org/linux-hwmon/[email protected]/
---
Change in v1:
1. Change to pmbus standard practice of getting MFR_READ_VSHUNT
through vmon.
2. Change the way MFR_CALIBRATION is hard-coded to be obtained by
calculation.
- Link to origin: https://lore.kernel.org/linux-hwmon/[email protected]/
---

Leo Yang (2):
dt-bindings: hwmon: ti,ina2xx: Add INA233 device
hwmon: Add driver for TI INA233 Current and Power Monitor

 .../devicetree/bindings/hwmon/ti,ina2xx.yaml  |  30 +++
 Documentation/hwmon/ina233.rst                |  75 +++++++
 MAINTAINERS                                   |   7 +
 drivers/hwmon/pmbus/Kconfig                   |   9 +
 drivers/hwmon/pmbus/Makefile                  |   1 +
 drivers/hwmon/pmbus/ina233.c                  | 191 ++++++++++++++++++
 6 files changed, 313 insertions(+)
 create mode 100644 Documentation/hwmon/ina233.rst
 create mode 100644 drivers/hwmon/pmbus/ina233.c
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH v4 1/2 dt-bindings: hwmon: ti,ina2xx: Add INA233 device

Add TI INA233 Current and Power Monitor bindings.

---
 .../devicetree/bindings/hwmon/ti,ina2xx.yaml  | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +30 -0
index 05a9cb36cd82..7372e282765b 100644
@@ -27,6 +27,7 @@ properties:
       - ti,ina226
       - ti,ina230
       - ti,ina231
+      - ti,ina233
       - ti,ina237
       - ti,ina238
       - ti,ina260
@@ -75,12 +76,41 @@ properties:
       the alert polarity to active-high.
     $ref: /schemas/types.yaml#/definitions/flag
 
+  ti,maximum-expected-current-microamp:
+    description: |
+      This value indicates the maximum current in microamps that you can
+      expect to measure with ina233 in your circuit.
+
+      This value will be used to calculate the Current_LSB and current/power
+      coefficient for the pmbus and to calibrate the IC.
+    minimum: 32768
+    maximum: 4294967295
+    default: 32768000
+
 required:
   - compatible
   - reg
 
 allOf:
   - $ref: hwmon-common.yaml#
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - silergy,sy24655
+              - ti,ina209
+              - ti,ina219
+              - ti,ina220
+              - ti,ina226
+              - ti,ina230
+              - ti,ina231
+              - ti,ina237
+              - ti,ina238
+              - ti,ina260
+    then:
+      properties:
+        ti,maximum-expected-current-microamp: false
 
 unevaluatedProperties: false
 
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v4 1/2] dt-bindings: hwmon: ti,ina2xx: Add INA233 device

Quoted 22 lines · Leo Yang

Add TI INA233 Current and Power Monitor bindings.

---
 .../devicetree/bindings/hwmon/ti,ina2xx.yaml  | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +1 -0
index 05a9cb36cd82..7372e282765b 100644
@@ -27,6 +27,7 @@ properties:
       - ti,ina226
       - ti,ina230
       - ti,ina231
+      - ti,ina233
       - ti,ina237
       - ti,ina238
       - ti,ina260
@@ -75,12 +76,41 @@ properties:
       the alert polarity to active-high.
     $ref: /schemas/types.yaml#/definitions/flag

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml properties: · line 87

Quoted 10 lines
Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +9 -0
 
+  ti,maximum-expected-current-microamp:
+    description: |
+      This value indicates the maximum current in microamps that you can
+      expect to measure with ina233 in your circuit.
+
+      This value will be used to calculate the Current_LSB and current/power
+      coefficient for the pmbus and to calibrate the IC.
+    minimum: 32768
+    maximum: 4294967295

Uh, are these real values measurable by the device? The last one looks like UINT_MAX.

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml properties: · line 88

Quoted 1 line
Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +1 -0
+    default: 32768000

Default is 32 A? For what applications is this sensor used?

Best regards,
Krzysztof

author maintainer
#3 lore raw

Re: [PATCH v4 1/2] dt-bindings: hwmon: ti,ina2xx: Add INA233 device

Hi Krzysztof,

Quoted 8 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml properties: · line 87

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +4 -0
+      This value will be used to calculate the Current_LSB and current/power
+      coefficient for the pmbus and to calibrate the IC.
+    minimum: 32768
+    maximum: 4294967295

Uh, are these real values measurable by the device? The last one looks like UINT_MAX.

According to the spec I don't see a definition of the upper limit of the current measurement, it all depends on how low the shunt resistance can be, so I'll use the upper limit of the u32 as the maximum for now, even though it's unlikely that this number will be present in the actual circuit.

Quoted 5 lines
Quoted 2 lines

+ default: 32768000

Default is 32 A? For what applications is this sensor used?

According to spec 8.2.2.1 Programming the Calibration Register example, a Current_LSB with a maximum expected current of 15A is approximately 457.7uA.
The example shows that a Current_LSB of 500 or 1000uA/bit can be used. So I choose 1000uA as the default value here, this value corresponds to the expected maximum current which is 32A (with some loss of accuracy to
have a larger measurement range), and yes maybe the user doesn't
need such a large current, so the accuracy-sensitive use of the scene can be adjusted according to the actual measurement range of the expected maximum current, I'm trying to retain some flexibility for the user.

Thank you for all your suggestions, they are very useful and I have gained a lot from them.

Best Regards,

Leo Yang

#4 lore raw

Re: [PATCH v4 1/2] dt-bindings: hwmon: ti,ina2xx: Add INA233 device

Quoted 23 lines · Leo Yang

Hi Krzysztof,

Quoted 8 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml properties: · line 87

Quoted 5 lines
Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml +4 -0
+      This value will be used to calculate the Current_LSB and current/power
+      coefficient for the pmbus and to calibrate the IC.
+    minimum: 32768
+    maximum: 4294967295

Uh, are these real values measurable by the device? The last one looks like UINT_MAX.

According to the spec I don't see a definition of the upper limit of the current measurement, it all depends on how low the shunt resistance can be, so I'll use the upper limit of the u32 as the maximum for now, even though it's unlikely that this number will be present in the actual circuit.

Quoted 5 lines
Quoted 2 lines

+ default: 32768000

Default is 32 A? For what applications is this sensor used?

Quoted 12 lines

According to spec 8.2.2.1 Programming the Calibration Register example, a Current_LSB with a maximum expected current of 15A is approximately 457.7uA.
The example shows that a Current_LSB of 500 or 1000uA/bit can be used. So I choose 1000uA as the default value here, this value corresponds to the expected maximum current which is 32A (with some loss of accuracy to
have a larger measurement range), and yes maybe the user doesn't
need such a large current, so the accuracy-sensitive use of the scene can be adjusted according to the actual measurement range of the expected maximum current, I'm trying to retain some flexibility for the user.

Datasheet indeed does not describe actual limits, expect 5 mA on the pin, but that depends on shunt resistor, so fine with me:

Best regards,
Krzysztof

author maintainer
#6 lore raw

PATCH v4 2/2 hwmon: Add driver for TI INA233 Current and Power Monitor

In reply to Leo Yang

Driver for Texas Instruments INA233 Current and Power Monitor With I2C-, SMBus-, and PMBus-Compatible Interface

---
 Documentation/hwmon/ina233.rst |  75 +++++++++++++
 MAINTAINERS                    |   7 ++
 drivers/hwmon/pmbus/Kconfig    |   9 ++
 drivers/hwmon/pmbus/Makefile   |   1 +
 drivers/hwmon/pmbus/ina233.c   | 191 +++++++++++++++++++++++++++++++++
 5 files changed, 283 insertions(+)
 create mode 100644 Documentation/hwmon/ina233.rst
 create mode 100644 drivers/hwmon/pmbus/ina233.c
Documentation/hwmon/ina233.rst new file +75 -0
new file mode 100644
index 000000000000..42323162e6db
@@ -0,0 +1,75 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+Kernel driver ina233
+====================
+
+Supported chips:
+
+  * TI INA233
+
+    Prefix: 'ina233'
+
+  * Datasheet
+
+    Publicly available at the TI website : https://www.ti.com/lit/ds/symlink/ina233.pdf
+
+Author: Leo Yang <[email protected]>
+
+Usage Notes
+-----------
+
+The shunt resistor value can be configured by a device tree property;
+see Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml for details.
+
+
+Description
+-----------
+
+This driver supports hardware monitoring for TI INA233.
+
+The driver is a client driver to the core PMBus driver. Please see
+Documentation/hwmon/pmbus.rst for details on PMBus client drivers.
+
+The driver provides the following attributes for input voltage:
+
+**in1_input**
+
+**in1_label**
+
+**in1_max**
+
+**in1_max_alarm**
+
+**in1_min**
+
+**in1_min_alarm**
+
+The driver provides the following attributes for shunt voltage:
+
+**in2_input**
+
+**in2_label**
+
+The driver provides the following attributes for output voltage:
+
+**in3_input**
+
+**in3_label**
+
+**in3_alarm**
+
+The driver provides the following attributes for output current:
+
+**curr1_input**
+
+**curr1_label**
+
+**curr1_max**
+
+**curr1_max_alarm**
+
+The driver provides the following attributes for input power:
+
+**power1_input**
+
+**power1_label**
MAINTAINERS +7 -0
index c575de4903db..ae67eeebd80e 100644
@@ -11226,6 +11226,13 @@ L:	[email protected]
 S:	Orphan
 F:	drivers/video/fbdev/imsttfb.c
 
+INA233 HARDWARE MONITOR DRIVERS
+M:	Leo Yang <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/hwmon/ina233.rst
+F:	drivers/hwmon/pmbus/ina233.c
+
 INDEX OF FURTHER KERNEL DOCUMENTATION
 M:	Carlos Bilbao <[email protected]>
 S:	Maintained
drivers/hwmon/pmbus/Kconfig +9 -0
index f6d352841953..55db0ddc94ed 100644
@@ -124,6 +124,15 @@ config SENSORS_DPS920AB
 	  This driver can also be built as a module. If so, the module will
 	  be called dps920ab.
 
+config SENSORS_INA233
+	tristate "Texas Instruments INA233 and compatibles"
+	help
+	  If you say yes here you get hardware monitoring support for Texas
+	  Instruments INA233.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called ina233.
+
 config SENSORS_INSPUR_IPSPS
 	tristate "INSPUR Power System Power Supply"
 	help
drivers/hwmon/pmbus/Makefile +1 -0
index d00bcc758b97..3c4b06fb939e 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_SENSORS_DELTA_AHE50DC_FAN) += delta-ahe50dc-fan.o
 obj-$(CONFIG_SENSORS_FSP_3Y)	+= fsp-3y.o
 obj-$(CONFIG_SENSORS_IBM_CFFPS)	+= ibm-cffps.o
 obj-$(CONFIG_SENSORS_DPS920AB)	+= dps920ab.o
+obj-$(CONFIG_SENSORS_INA233)	+= ina233.o
 obj-$(CONFIG_SENSORS_INSPUR_IPSPS) += inspur-ipsps.o
 obj-$(CONFIG_SENSORS_IR35221)	+= ir35221.o
 obj-$(CONFIG_SENSORS_IR36021)	+= ir36021.o
drivers/hwmon/pmbus/ina233.c new file +191 -0

191 lines not on this page · raw message

Signature · 1 line
2.39.2
maintainer Applied
#7 lore raw

Re: [PATCH v4 2/2] hwmon: Add driver for TI INA233 Current and Power Monitor

Quoted 4 lines · Leo Yang

Driver for Texas Instruments INA233 Current and Power Monitor With I2C-, SMBus-, and PMBus-Compatible Interface

Applied.

Thanks,
Guenter