mbox series

[V3,0/4] hwmon: ina3221: Add selective summation support

Message ID 20230921130818.21247-1-jonathanh@nvidia.com
Headers show
Series hwmon: ina3221: Add selective summation support | expand

Message

Jon Hunter Sept. 21, 2023, 1:08 p.m. UTC
The current INA3221 driver always sums the shunt voltage for all enabled
channels regardless of the shunt-resistor used for each channel. Summing
the shunt-voltage for channels is only meaningful if the shunt resistor
is the same for each channel. This series adds device-tree support to
allow which channels are summed in device-tree.

Changes since V2:
- Added note to binding-doc to indicate that input channels must be
  explicitly disabled.
- Corrected ordering of properties in the binding-doc
- Updated license for the binding-doc to be dual licensed.
- Changed newly added property from 'summation-bypass' to
  summation-disable'.
- Documented type for the new 'summation-disable' property.
- Corrected spelling and comments as per the feedback received.
- Used debugfs instead of sysfs for exposing the 'summation-disable'
  status for each input channel.
- Populated missing instances for the ina3221 device for Tegra234
  boards.
- Populated ina219 device for the NVIDIA IGX board (not strictly
  related to this series but related to populating all
  power-sensors for Tegra234 boards)

Changes since V1:
- Added yaml conversion patch for binding-doc
- Added binding-doc documentation patch for new property
- Added patch to populate ina3221 devices for Tegra234.

Jon Hunter (2):
  dt-bindings: hwmon: ina3221: Add ti,summation-disable
  arm64: tegra: Add power-sensors for Tegra234 boards

Ninad Malwade (2):
  dt-bindings: hwmon: ina3221: Convert to json-schema
  hwmon: ina3221: Add support for channel summation disable

 .../devicetree/bindings/hwmon/ina3221.txt     |  54 --------
 .../devicetree/bindings/hwmon/ti,ina3221.yaml | 117 ++++++++++++++++++
 .../boot/dts/nvidia/tegra234-p3701-0008.dtsi  |  33 +++++
 .../arm64/boot/dts/nvidia/tegra234-p3701.dtsi |  53 ++++++++
 .../arm64/boot/dts/nvidia/tegra234-p3767.dtsi |  29 +++++
 drivers/hwmon/ina3221.c                       |  30 ++++-
 6 files changed, 259 insertions(+), 57 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/hwmon/ina3221.txt
 create mode 100644 Documentation/devicetree/bindings/hwmon/ti,ina3221.yaml

Comments

Rob Herring Sept. 22, 2023, 9:06 p.m. UTC | #1
On Thu, Sep 21, 2023 at 02:08:16PM +0100, Jon Hunter wrote:
> The INA3221 has a critical alert pin that can be controlled by the
> summation control function. This function adds the single
> shunt-voltage conversions for the desired channels in order to
> compare the combined sum to the programmed limit. The Shunt-Voltage
> Sum Limit register contains the programmed value that is compared
> to the value in the Shunt-Voltage Sum register in order to
> determine if the total summed limit is exceeded. If the
> shunt-voltage sum limit value is exceeded, the critical alert pin
> pulls low.
> 
> For the summation limit to have a meaningful value, it is necessary
> to use the same shunt-resistor value on all included channels. Add a new
> vendor specific property, 'ti,summation-disable', to allow specific
> channels to be excluded from the summation control function if the shunt
> resistor is different to other channels or the channel should not be
> considered for triggering the critical alert pin.

You are adding this feature to the driver, but requiring a new property 
to disable it. So what happens with an existing user (old DT) and a 
kernel with the new feature?

Rob
Jon Hunter Sept. 25, 2023, 10:46 a.m. UTC | #2
On 22/09/2023 22:01, Rob Herring wrote:
> On Thu, Sep 21, 2023 at 02:08:15PM +0100, Jon Hunter wrote:
>> From: Ninad Malwade <nmalwade@nvidia.com>
>>
>> Convert the TI INA3221 bindings from the free-form text format to
>> json-schema.
>>
>> Note that the INA3221 input channels default to enabled in the chip.
>> Unless channels are explicitly disabled in device-tree, input
>> channels will be enabled.
>>
>> Signed-off-by: Thierry Reding <treding@nvidia.com>
>> Signed-off-by: Ninad Malwade <nmalwade@nvidia.com>
>> Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
>> ---
>>   .../devicetree/bindings/hwmon/ina3221.txt     | 54 ----------
>>   .../devicetree/bindings/hwmon/ti,ina3221.yaml | 98 +++++++++++++++++++
>>   2 files changed, 98 insertions(+), 54 deletions(-)
>>   delete mode 100644 Documentation/devicetree/bindings/hwmon/ina3221.txt
>>   create mode 100644 Documentation/devicetree/bindings/hwmon/ti,ina3221.yaml


...

>> +examples:
>> +  - |
>> +    i2c {
>> +        #address-cells = <1>;
>> +        #size-cells = <0>;
>> +
>> +        power-sensor@40 {
>> +            compatible = "ti,ina3221";
>> +            reg = <0x40>;
>> +            #address-cells = <1>;
>> +            #size-cells = <0>;
>> +
>> +            input@0 {
>> +                reg = <0x0>;
>> +                status = "disabled";
> 
> Examples should be enabled.


Yes normally that would be the case. However, per the discussion with 
Guenter and the comment in the changelog, for this device channels are 
enabled in the chip by default. And so to disable them, we need to 
explicitly disable in device-tree.

Jon
Jon Hunter Sept. 25, 2023, 10:50 a.m. UTC | #3
On 22/09/2023 22:06, Rob Herring wrote:
> On Thu, Sep 21, 2023 at 02:08:16PM +0100, Jon Hunter wrote:
>> The INA3221 has a critical alert pin that can be controlled by the
>> summation control function. This function adds the single
>> shunt-voltage conversions for the desired channels in order to
>> compare the combined sum to the programmed limit. The Shunt-Voltage
>> Sum Limit register contains the programmed value that is compared
>> to the value in the Shunt-Voltage Sum register in order to
>> determine if the total summed limit is exceeded. If the
>> shunt-voltage sum limit value is exceeded, the critical alert pin
>> pulls low.
>>
>> For the summation limit to have a meaningful value, it is necessary
>> to use the same shunt-resistor value on all included channels. Add a new
>> vendor specific property, 'ti,summation-disable', to allow specific
>> channels to be excluded from the summation control function if the shunt
>> resistor is different to other channels or the channel should not be
>> considered for triggering the critical alert pin.
> 
> You are adding this feature to the driver, but requiring a new property
> to disable it. So what happens with an existing user (old DT) and a
> kernel with the new feature?


Not exactly. The summation support has always been supported in the 
driver and is enabled (if the shunt resistors for all channels are the 
same). What we want to do is support summation but only for a subset of 
channels which is not supported today. So this new property allows us to 
explicitly tell the driver not to include a specific channel in the 
summation.

Jon