Skip to contentSkip to conversation

Add Richtek RTQ6056 support

PATCH Superseded cy_huang 2 participants 8 messages Jul 18, 2022 – Jul 19, 2022

Subsystems (2)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

cy_huang

author
#0 lore raw

v7 cover Add Richtek RTQ6056 support

From: ChiYuan Huang <[email protected]>

This patch series is to enable Richtek RTQ6056 support.

The RTQ6056 is a high accuracy current-sense monitor with I2C interface, and the device provides full information for system by reading out the load current and power.

Since v7
- Use 'DEFINE_RUNTIME_DEV_PM_OPS' to replace the explicit declaration of pm_ops.

Since v6
- Remove specific rtq6056 ABI document.
- Update integration time description in general ABI document.
- Remove the redundant blank line.
- To prevent the race condition for attribute wrtie and shunt resistor write, use 'iio_device_claim_direct_mode' API.
- Refine the order for 'action_reset' and 'pm_runtime'.
- Fix text typo in comment like as ohm to Ohm and timea to time.

Since v5
- Fix kernel version text for ABI.

Since v4
- Add '__aligned(8)' for timestamp member.
- Declare timestamp from 'int64_t' to more unified 's64'.

Since v3
- change the node name to be generic 'adc' in binding example.
- Refine pm_runtime API calling order in 'read_channel' API.
- Fix vshunt wrong scale for divider.
- Refine the comment text.
- Use 'devm_add_action_or_reset' to decrease the code usage in probe function.
- Use RUNTIME_PM_OPS to replace SET_RUNTIME_PM_OPS.
- minor fix for the comma.
- Use pm_ptr to replace the direct assigned pm_ops.

Since v2
- Change the resistor property name to be generic 'shunt-resistor-micro-ohms'.
- Rename file from 'rtq6056-adc' to 'rtq6056'.
- Refine the ABI, if generic already defined it, remove it and check the channel report unit.
- Add copyright text.
- include the correct header.
- change the property parsing name.
- To use iio_chan_spec address field.
- Refine each channel separate and shared_by_all.
- Use pm_runtime and pm_runtime_autosuspend.
- Remove the shutdown callback. From the HW suggestion, it's not recommended to use battery as the power supply.
- Check all scale unit (voltage->mV, current->mA, power->milliWatt).
- Use the read_avail to provide the interface for attribute value list.
- Add comma for the last element in the const integer array.
- Refine each ADC label text.
- In read_label callback, replace snprintf to sysfs_emit.

ChiYuan Huang (3):
dt-bindings: iio: adc: Add rtq6056 adc support
iio: adc: Add rtq6056 support
Documentation: ABI: testing: rtq6056: Update ABI docs

 Documentation/ABI/testing/sysfs-bus-iio            |  10 +
 .../bindings/iio/adc/richtek,rtq6056.yaml          |  56 ++
 drivers/iio/adc/Kconfig                            |  15 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/rtq6056.c                          | 663 +++++++++++++++++++++
 5 files changed, 745 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/richtek,rtq6056.yaml
 create mode 100644 drivers/iio/adc/rtq6056.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v7 1/3 dt-bindings: iio: adc: Add rtq6056 adc support

From: ChiYuan Huang <[email protected]>

Add the documentation for Richtek rtq6056.

---
Since v3
- change the node name to be generic 'adc' in binding example.

Since v2
- Change the resistor property name to be generic 'shunt-resistor-micro-ohms'.

---
 .../bindings/iio/adc/richtek,rtq6056.yaml          | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/richtek,rtq6056.yaml
Documentation/devicetree/bindings/iio/adc/richtek,rtq6056.yaml new file +56 -0
new file mode 100644
index 00000000..88e0086
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/adc/richtek,rtq6056.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RTQ6056 Bi-Directional Current and Power Monitor with 16-bit ADC
+
+maintainers:
+  - ChiYuan Huang <[email protected]>
+
+description: |
+  The RTQ6056 is a high accuracy current-sense monitor with I2C and SMBus
+  interface, and the device provides full information for system by reading
+  out the loading current and power.
+
+  The device monitors both of the drops across sense resistor and the BUS
+  voltage, converts into the current in amperes, and power in watts through
+  internal analog-to-digital converter ADC. The programmable calibration,
+  adjustable conversion time, and averaging function are also built in for
+  more design flexibility.
+
+  Datasheet is available at
+  https://www.richtek.com/assets/product_file/RTQ6056/DSQ6056-00.pdf
+
+properties:
+  compatible:
+    const: richtek,rtq6056
+
+  reg:
+    maxItems: 1
+
+  "#io-channel-cells":
+    const: 1
+
+  shunt-resistor-micro-ohms:
+    description: Shunt IN+/IN- sensing node resistor
+
+required:
+  - compatible
+  - reg
+  - "#io-channel-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      adc@40 {
+        compatible = "richtek,rtq6056";
+        reg = <0x40>;
+        #io-channel-cells = <1>;
+      };
+    };
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v7 2/3 iio: adc: Add rtq6056 support

In reply to cy_huang

From: ChiYuan Huang <[email protected]>

Add Richtek rtq6056 supporting.

It can be used for the system to monitor load current and power with 16-bit resolution.

---
Since v7
- Use 'DEFINE_RUNTIME_DEV_PM_OPS' to replace the explicit declaration of pm_ops.

Since v6
- Remove specific rtq6056 ABI document.
- Remove the redundant blank line.
- To prevent the race condition for attribute wrtie and shunt resistor write, use 'iio_device_claim_direct_mode' API.
- Refine the order for 'action_reset' and 'pm_runtime'.
- Fix text typo in comment like as ohm to Ohm and timea to time.

Since v5
- Fix kernel version text for ABI.

Since v4
- Add '__aligned(8)' for timestamp member in buffer_trigger_handler function.
- Declare timestamp from 'int64_t' to more unified 's64'.

Since v3
- Refine pm_runtime API calling order in 'read_channel' API.
- Fix vshunt wrong scale for divider.
- Refine the comment text.
- Use 'devm_add_action_or_reset' to decrease the code usage in probe function.
- Use RUNTIME_PM_OPS to replace SET_RUNTIME_PM_OPS.
- minor fix for the comma.
- Use pm_ptr to replace the direct assigned pm_ops.

Since v2
- Rename file from 'rtq6056-adc' to 'rtq6056'.
- Refine the ABI, if generic already defined it, remove it and check the channel report unit.
- Add copyright text.
- include the correct header.
- change the property parsing name.
- To use iio_chan_spec address field.
- Refine each channel separate and shared_by_all.
- Use pm_runtime and pm_runtime_autosuspend.
- Remove the shutdown callback. From the HW suggestion, it's not recommended to use battery as the power supply.
- Check all scale unit (voltage->mV, current->mA, power->milliWatt).
- Use the read_avail to provide the interface for attribute value list.
- Add comma for the last element in the const integer array.
- Refine each ADC label text.
- In read_label callback, replace snprintf to sysfs_emit.

---
 drivers/iio/adc/Kconfig   |  15 ++
 drivers/iio/adc/Makefile  |   1 +
 drivers/iio/adc/rtq6056.c | 663 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 679 insertions(+)
 create mode 100644 drivers/iio/adc/rtq6056.c
drivers/iio/adc/Kconfig +15 -0
index 48ace74..caebd1a 100644
@@ -908,6 +908,21 @@ config ROCKCHIP_SARADC
 	  To compile this driver as a module, choose M here: the
 	  module will be called rockchip_saradc.
 
+config RICHTEK_RTQ6056
+	tristate "Richtek RTQ6056 Current and Power Monitor ADC"
+	depends on I2C
+	select REGMAP_I2C
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	help
+	  Say yes here to enable RQT6056 ADC support.
+	  RTQ6056 is a high accuracy current-sense monitor with I2C and SMBus
+	  compatible interface, and the device provides full information for
+	  system by reading out the load current and power.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called rtq6056.
+
 config RZG2L_ADC
 	tristate "Renesas RZ/G2L ADC driver"
 	depends on ARCH_RZG2L || COMPILE_TEST
drivers/iio/adc/Makefile +1 -0
index 39d806f..cda7580 100644
@@ -84,6 +84,7 @@ obj-$(CONFIG_QCOM_PM8XXX_XOADC) += qcom-pm8xxx-xoadc.o
 obj-$(CONFIG_RCAR_GYRO_ADC) += rcar-gyroadc.o
 obj-$(CONFIG_RN5T618_ADC) += rn5t618-adc.o
 obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
+obj-$(CONFIG_RICHTEK_RTQ6056) += rtq6056.o
 obj-$(CONFIG_RZG2L_ADC) += rzg2l_adc.o
 obj-$(CONFIG_SC27XX_ADC) += sc27xx_adc.o
 obj-$(CONFIG_SPEAR_ADC) += spear_adc.o
drivers/iio/adc/rtq6056.c new file +663 -0

663 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#4 lore raw

PATCH v7 3/3 Documentation: ABI: testing: rtq6056: Update ABI docs

In reply to cy_huang

From: ChiYuan Huang <[email protected]>

Add documentation for the usage of voltage channel integration time.

---
 Documentation/ABI/testing/sysfs-bus-iio | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +10 -0
index d4ccc68..1f7d327 100644
@@ -2030,3 +2030,13 @@ Description:
 		Available range for the forced calibration value, expressed as:
 
 		- a range specified as "[min step max]"
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_voltageY_integration_time
+KernelVersion:	5.20
+Contact:	[email protected]
+Description:
+		For voltage sensing hardware, there may be different time between
+		channel conversion and sample update. 'Integration time' is used to
+		specify the channel internal conversion time. And sample update
+		interval is equal to average sample count multiple integration time.
+		Unit as microsecond.
Signature · 1 line
2.7.4
maintainer
#7 lore raw
In reply to cy_huang
Quoted 7 lines · On Mon, 18 Jul 2022 13:46:00 +0800 cy_huang <[email protected]> wrote:

From: ChiYuan Huang <[email protected]>

This patch series is to enable Richtek RTQ6056 support.

The RTQ6056 is a high accuracy current-sense monitor with I2C interface, and the device provides full information for system by reading out the load current and power.

If sending a new version without there being any public replies to the previous version please reply to that thread yourself to say you are resending and why. Greatly reduces the chances of me picking up the wrong version!

Quoted 64 lines

Since v7
- Use 'DEFINE_RUNTIME_DEV_PM_OPS' to replace the explicit declaration of pm_ops.

Since v6
- Remove specific rtq6056 ABI document.
- Update integration time description in general ABI document.
- Remove the redundant blank line.
- To prevent the race condition for attribute wrtie and shunt resistor write, use 'iio_device_claim_direct_mode' API.
- Refine the order for 'action_reset' and 'pm_runtime'.
- Fix text typo in comment like as ohm to Ohm and timea to time.

Since v5
- Fix kernel version text for ABI.

Since v4
- Add '__aligned(8)' for timestamp member.
- Declare timestamp from 'int64_t' to more unified 's64'.

Since v3
- change the node name to be generic 'adc' in binding example.
- Refine pm_runtime API calling order in 'read_channel' API.
- Fix vshunt wrong scale for divider.
- Refine the comment text.
- Use 'devm_add_action_or_reset' to decrease the code usage in probe function.
- Use RUNTIME_PM_OPS to replace SET_RUNTIME_PM_OPS.
- minor fix for the comma.
- Use pm_ptr to replace the direct assigned pm_ops.

Since v2
- Change the resistor property name to be generic 'shunt-resistor-micro-ohms'.
- Rename file from 'rtq6056-adc' to 'rtq6056'.
- Refine the ABI, if generic already defined it, remove it and check the channel report unit.
- Add copyright text.
- include the correct header.
- change the property parsing name.
- To use iio_chan_spec address field.
- Refine each channel separate and shared_by_all.
- Use pm_runtime and pm_runtime_autosuspend.
- Remove the shutdown callback. From the HW suggestion, it's not recommended to use battery as the power supply.
- Check all scale unit (voltage->mV, current->mA, power->milliWatt).
- Use the read_avail to provide the interface for attribute value list.
- Add comma for the last element in the const integer array.
- Refine each ADC label text.
- In read_label callback, replace snprintf to sysfs_emit.

ChiYuan Huang (3):
dt-bindings: iio: adc: Add rtq6056 adc support
iio: adc: Add rtq6056 support
Documentation: ABI: testing: rtq6056: Update ABI docs

 Documentation/ABI/testing/sysfs-bus-iio            |  10 +
 .../bindings/iio/adc/richtek,rtq6056.yaml          |  56 ++
 drivers/iio/adc/Kconfig                            |  15 +
 drivers/iio/adc/Makefile                           |   1 +
 drivers/iio/adc/rtq6056.c                          | 663 +++++++++++++++++++++
 5 files changed, 745 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/adc/richtek,rtq6056.yaml
 create mode 100644 drivers/iio/adc/rtq6056.c
maintainer
#5 lore raw

Re: [PATCH v7 3/3] Documentation: ABI: testing: rtq6056: Update ABI docs

In reply to cy_huang
Quoted 17 lines · On Mon, 18 Jul 2022 13:46:03 +0800 cy_huang <[email protected]> wrote:

From: ChiYuan Huang <[email protected]>

Add documentation for the usage of voltage channel integration time.

---
 Documentation/ABI/testing/sysfs-bus-iio | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +0 -0
index d4ccc68..1f7d327 100644
@@ -2030,3 +2030,13 @@ Description:
 		Available range for the forced calibration value, expressed as:
 
 		- a range specified as "[min step max]"

Documentation/ABI/testing/sysfs-bus-iio Description: · line 2042

Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-iio +10 -0
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_voltageY_integration_time
+KernelVersion:	5.20
+Contact:	[email protected]
+Description:
+		For voltage sensing hardware, there may be different time between
+		channel conversion and sample update. 'Integration time' is used to
+		specify the channel internal conversion time. And sample update
+		interval is equal to average sample count multiple integration time.
+		Unit as microsecond.

Whilst I did suggest moving this to this file, I also suggested that it was the wrong interface to use. For similar cases we've used in_voltageY_sampling_frequency in the past because this isn't really an integration time, but rather a reflection of a bunch of other stuff that makes up the conversion time. In IIO we chose a long time ago to use 1/conversion_time as the exposed interface == sampling_frequency

So, unless there is a strong reason to do otherwise, drop the overall sampling_frequency attribute and use per channel ones instead. Then update the main documentation to make this usecase clear. Something in the block
https://elixir.bootlin.com/linux/latest/source/Documentation/ABI/testing/sysfs-bus-iio#L89
like adding the in_voltageY_sampling_frequency entry to the What: list and a sentence at the end that says something like:

"Some devices have separate controls of sampling frequency for individual channels. If multiple channels are enabled in a scan, then the sampling_frequency of the the scan may be computed from the per channel sampling_frequencies."

Not something to put in the documentation, but for devices which do simultaneous sampling it is very unlikely we'll have per channel sampling frequencies so there isn't an ambiguity. The alternative we 'could' consider is to allow both overall sampling_frequency and per channel in_voltageY_sampling_frequency but that is a bad idea because the ABI (and most userspace software) assumes that more specific attributes override the values of more generic ones (rather than them having different meanings as would be the case here).

Jonathan

maintainer
#3 lore raw

Re: [PATCH v7 2/3] iio: adc: Add rtq6056 support

In reply to cy_huang
Quoted 10 lines · On Mon, 18 Jul 2022 13:46:02 +0800 cy_huang <[email protected]> wrote:

From: ChiYuan Huang <[email protected]>

Add Richtek rtq6056 supporting.

It can be used for the system to monitor load current and power with 16-bit resolution.

---

other than the ABI question around integration_time vs sampling_frequency in review of patch 3, this looks good to me.

Thanks,

Jonathan

#6 lore raw

Re: [PATCH v7 3/3] Documentation: ABI: testing: rtq6056: Update ABI docs

In reply to Jonathan Cameron

Jonathan Cameron <[email protected]> 於 2022年7月19日 週二 凌晨12:54寫道:

Quoted 45 lines
Quoted 17 lines · On Mon, 18 Jul 2022 13:46:03 +0800 cy_huang <[email protected]> wrote:

From: ChiYuan Huang <[email protected]>

Add documentation for the usage of voltage channel integration time.

---
 Documentation/ABI/testing/sysfs-bus-iio | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +0 -0
index d4ccc68..1f7d327 100644
@@ -2030,3 +2030,13 @@ Description:
              Available range for the forced calibration value, expressed as:
 
              - a range specified as "[min step max]"

Documentation/ABI/testing/sysfs-bus-iio Description: · line 2042

Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-iio +10 -0
+
+What:                /sys/bus/iio/devices/iio:deviceX/in_voltageY_integration_time
+KernelVersion:       5.20
+Contact:     [email protected]
+Description:
+             For voltage sensing hardware, there may be different time between
+             channel conversion and sample update. 'Integration time' is used to
+             specify the channel internal conversion time. And sample update
+             interval is equal to average sample count multiple integration time.
+             Unit as microsecond.

Whilst I did suggest moving this to this file, I also suggested that it was the wrong interface to use. For similar cases we've used in_voltageY_sampling_frequency in the past because this isn't really an integration time, but rather a reflection of a bunch of other stuff that makes up the conversion time. In IIO we chose a long time ago to use 1/conversion_time as the exposed interface == sampling_frequency

So, unless there is a strong reason to do otherwise, drop the overall sampling_frequency attribute and use per channel ones instead. Then update the main documentation to make this usecase clear. Something in the block
https://elixir.bootlin.com/linux/latest/source/Documentation/ABI/testing/sysfs-bus-iio#L89
like adding the in_voltageY_sampling_frequency entry to the What: list and a sentence at the end that says something like:

Quoted 4 lines

"Some devices have separate controls of sampling frequency for individual channels. If multiple channels are enabled in a scan, then the sampling_frequency of the the scan may be computed from the per channel sampling_frequencies."

From my case, I need to specify in_voltageX_sampling_frequency/in_powerY_sampling_frequency/ in_currentZ_sampling_frequency.

And describe all in the same sentence.
Can I directly copy the sentence that you described above? I read the comment. The sentence that you wrote seems more generic.

If any misunderstanding, please correct me.

Quoted 9 lines

Not something to put in the documentation, but for devices which do simultaneous sampling it is very unlikely we'll have per channel sampling frequencies so there isn't an ambiguity. The alternative we 'could' consider is to allow both overall sampling_frequency and per channel in_voltageY_sampling_frequency but that is a bad idea because the ABI (and most userspace software) assumes that more specific attributes override the values of more generic ones (rather than them having different meanings as would be the case here).

Jonathan