Skip to contentSkip to conversation

Add Richtek RT9471 3A battery charger support

PATCH In review cy_huang 1 participant 5 messages Sep 30, 2022 – Dec 8, 2022

Subsystems (2)
lore
Share & tools
lore

cy_huang

author
#0 lore raw

v8 cover Add Richtek RT9471 3A battery charger support

From: ChiYuan Huang <[email protected]>

This patch set is to add Richtek RT9471 charger support.

The RT9471/D is a highly-integrated 3A switch mode battery charge management and system power path management device for single cell Li-Ion and Li-polymer battery. The low impedance power path optimizes switch-mode operation efficiency, reduces battery charging time and extends battery life during discharging phase.

Since v8:
- revert v7 for adding irq wakeup capable, i2c core already did it.

Since v7:
- Add irq wakeup capable.
- Add missing header 'module.h' for MODULE_DEVICE_TABLE.

Since v6:
- Use 'ATTRIBUTE_GROUPS' macro to simplify the attribute coding.
- Explain more details for sysoff_enable attribute.

Since v5:
- Remove one line wrapper.
- Merge header content into source file, remove header file.
- Remove 'charge_term_enable' sysfs entry and merge it into 'charge_term_current' property control.
- Change MODULE_LICENSE from 'GPL v2' to 'GPL'. Following by the below discussion
https://lore.kernel.org/all/[email protected]/
- Recover all the change in sysfs-class-power.
- New a sysfs-class-power-rt9471 file.
- Remove 'charge_term_enable' sysfs entry, directly integrate it in 'charge_term_current' power supply property control.

Since v4:
- Remove the line for the owner field in driver.
- Add the documentation for sysfs entries.

Since v3:
- Move unevaluatedProperties line after $ref for binding patch.
- Add Reviewed-by tag for binding patch.

Since v2:
- Remove the properties for interrupt controller things in the binding documentation.
- Fix dtc error for typo, it's 'regulator-name', not 'regulator-compatible'.
- Add regulator min/max microamp to allow otg vbus current adjustable in example.
- Specify the active-level for charge-enable-gpios in binding example.
- Fix checkpatch error about 'foo * bar' to 'foo *bar' in psy_device_to_chip function.
- Specify the member name directly for the use of linear range.

ChiYuan Huang (3):
dt-bindings: power: supply: Add Richtek RT9471 battery charger
power: supply: rt9471: Add Richtek RT9471 charger driver
Documentation: power: rt9471: Document exported sysfs entries

 Documentation/ABI/testing/sysfs-class-power-rt9471 |  32 +
 .../bindings/power/supply/richtek,rt9471.yaml      |  73 ++
 drivers/power/supply/Kconfig                       |  16 +
 drivers/power/supply/Makefile                      |   1 +
 drivers/power/supply/rt9471.c                      | 931 +++++++++++++++++++++
 5 files changed, 1053 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-power-rt9471
 create mode 100644 Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml
 create mode 100644 drivers/power/supply/rt9471.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v8 1/3 dt-bindings: power: supply: Add Richtek RT9471 battery charger

From: ChiYuan Huang <[email protected]>

Add bindings for the Richtek RT9471 I2C controlled battery charger.

---
Since v3
- Move unevaluatedProperties line after $ref for binding patch.
- Add Reviewed-by tag for binding patch.

Since v2
- Remove the properties for interrupt controller things in the binding documentation.
- Fix dtc error for typo, it's 'regulator-name', not 'regulator-compatible'.
- Add regulator min/max microamp to allow otg vbus current adjustable in example.
- Specify the active-level for charge-enable-gpios in binding example.

---
 .../bindings/power/supply/richtek,rt9471.yaml      | 73 ++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +73 -0
new file mode 100644
index 00000000..fbb54cf
@@ -0,0 +1,73 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/supply/richtek,rt9471.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Richtek RT9471 3A Single Cell Switching Battery charger
+
+maintainers:
+  - Alina Yu <[email protected]>
+  - ChiYuan Huang <[email protected]>
+
+description: |
+  RT9471 is a switch-mode single cell Li-Ion/Li-Polymer battery charger for
+  portable applications. It supports USB BC1.2 port detection, current and
+  voltage regulations in both charging and boost mode.
+
+  Datasheet is available at
+  https://www.richtek.com/assets/product_file/RT9471=RT9471D/DS9471D-02.pdf
+
+properties:
+  compatible:
+    const: richtek,rt9471
+
+  reg:
+    maxItems: 1
+
+  charge-enable-gpios:
+    description: GPIO used to turn on and off charging.
+    maxItems: 1
+
+  wakeup-source: true
+
+  interrupts:
+    maxItems: 1
+
+  usb-otg-vbus-regulator:
+    type: object
+    $ref: /schemas/regulator/regulator.yaml#
+    unevaluatedProperties: false
+
+required:
+  - compatible
+  - reg
+  - wakeup-source
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/gpio/gpio.h>
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      charger@53 {
+        compatible = "richtek,rt9471";
+        reg = <0x53>;
+        charge-enable-gpios = <&gpio26 1 GPIO_ACTIVE_LOW>;
+        wakeup-source;
+        interrupts-extended = <&gpio_intc 32 IRQ_TYPE_EDGE_FALLING>;
+
+        usb-otg-vbus-regulator {
+          regulator-name = "usb-otg-vbus";
+          regulator-min-microvolt = <4850000>;
+          regulator-max-microvolt = <5300000>;
+          regulator-min-microamp = <500000>;
+          regulator-max-microamp = <1200000>;
+        };
+      };
+    };
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v8 2/3 power: supply: rt9471: Add Richtek RT9471 charger driver

In reply to cy_huang

From: ChiYuan Huang <[email protected]>

Add support for the RT9471 3A 1-Cell Li+ battery charger.

The RT9471 is a highly-integrated 3A switch mode battery charger with low impedance power path to better optimize the charging efficiency.

---
Since v8:
- revert v7 for adding irq wakeup capable, i2c core already did it.

Since v7:
- Add irq wakeup capable.
- Add missing header 'module.h' for MODULE_DEVICE_TABLE.

Since v6:
- Use 'ATTRIBUTE_GROUPS' macro to simplify the attribute coding.

Since v5:
- Remove one line wrapper.
- Merge header content into source file, remove header file.
- Remove 'charge_term_enable' sysfs entry and merge it into 'charge_term_current' property control.
- Change MODULE_LICENSE from 'GPL v2' to 'GPL'. Following by the below discussion
https://lore.kernel.org/all/[email protected]/

Since v4:
- Remove the line for the owner field in driver.

Since v2:
- Fix checkpatch error about 'foo * bar' to 'foo *bar' in psy_device_to_chip function.
- Specify the member name directly for the use of linear range.

---
 drivers/power/supply/Kconfig  |  16 +
 drivers/power/supply/Makefile |   1 +
 drivers/power/supply/rt9471.c | 931 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 948 insertions(+)
 create mode 100644 drivers/power/supply/rt9471.c
drivers/power/supply/Kconfig +16 -0
index 1aa8323..e9b61c2 100644
@@ -772,6 +772,22 @@ config CHARGER_RT9455
 	help
 	  Say Y to enable support for Richtek RT9455 battery charger.
 
+config CHARGER_RT9471
+	tristate "Richtek RT9471 battery charger driver"
+	depends on I2C && GPIOLIB && REGULATOR
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	select LINEAR_RANGES
+	help
+	  This adds support for Richtek RT9471 battery charger. RT9471 is
+	  highly-integrated switch mode battery charger which is system power
+	  patch manageable device for single cell Li-Ion and Li-polymer battery.
+	  It can support BC12 detection on DPDM, and current and voltage
+	  regulation on both charging and boost mode.
+
+	  This driver can also be built as a module. If so, the module will be
+	  called rt9471.
+
 config CHARGER_CROS_USBPD
 	tristate "ChromeOS EC based USBPD charger"
 	depends on CROS_USBPD_NOTIFY
drivers/power/supply/Makefile +1 -0
index 7f02f36..17c8c1a 100644
@@ -57,6 +57,7 @@ obj-$(CONFIG_BATTERY_MAX1721X)	+= max1721x_battery.o
 obj-$(CONFIG_BATTERY_Z2)	+= z2_battery.o
 obj-$(CONFIG_BATTERY_RT5033)	+= rt5033_battery.o
 obj-$(CONFIG_CHARGER_RT9455)	+= rt9455_charger.o
+obj-$(CONFIG_CHARGER_RT9471)	+= rt9471.o
 obj-$(CONFIG_BATTERY_S3C_ADC)	+= s3c_adc_battery.o
 obj-$(CONFIG_BATTERY_TWL4030_MADC)	+= twl4030_madc_battery.o
 obj-$(CONFIG_CHARGER_88PM860X)	+= 88pm860x_charger.o
drivers/power/supply/rt9471.c new file +931 -0

931 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#3 lore raw

PATCH v8 3/3 Documentation: power: rt9471: Document exported sysfs entries

In reply to cy_huang

From: ChiYuan Huang <[email protected]>

Document the settings exported by rt9471 charger driver through sysfs entries:
- sysoff_enable
- port_detect_enable

---
Since v6:
- Explain more details for sysoff_enable attribute.

Since v5:
- Recover all the change in sysfs-class-power.
- New a sysfs-class-power-rt9471 file.
- Remove 'charge_term_enable' sysfs entry, directly integrate it in 'charge_term_current' power supply property control.

---
 Documentation/ABI/testing/sysfs-class-power-rt9471 | 32 ++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-power-rt9471
Documentation/ABI/testing/sysfs-class-power-rt9471 new file +32 -0
new file mode 100644
index 00000000..38227a8
@@ -0,0 +1,32 @@
+What:		/sys/class/power_supply/rt9471-*/sysoff_enable
+Date:		Oct 2022
+KernelVersion:	6.1
+Contact:	ChiYuan Huang <[email protected]>
+Description:
+		This entry allows enabling the sysoff mode of rt9471 charger devices.
+		If enabled and the input is removed, the internal battery FET is turned
+		off to reduce the leakage from the BAT pin. See device datasheet for details.
+		It's commonly used when the product enter shipping stage. After entering
+		shipping mode, only 'VBUS' or 'Power key" pressed can make it leave this
+		mode. 'Disable' also can help to leave it, but it's more like to abort
+		the action before the device really enter shipping mode.
+
+		Access: Read, Write
+		Valid values:
+		- 1: enabled
+		- 0: disabled
+
+What:		/sys/class/power_supply/rt9471-*/port_detect_enable
+Date:		Oct 2022
+KernelVersion:	6.1
+Contact:	ChiYuan Huang <[email protected]>
+Description:
+		This entry allows enabling the USB BC12 port detect function of rt9471 charger
+		devices. If enabled and VBUS is inserted, device will start to do the BC12
+		port detect and report the usb port type when port detect is done. See
+		datasheet for details. Normally controlled when TypeC/USBPD port integrated.
+
+		Access: Read, Write
+		Valid values:
+		- 1: enabled
+		- 0: disabled
Signature · 1 line
2.7.4
#4 lore raw
In reply to cy_huang
Quoted 10 lines · cy_huang

From: ChiYuan Huang <[email protected]>

This patch set is to add Richtek RT9471 charger support.

The RT9471/D is a highly-integrated 3A switch mode battery charge management and system power path management device for single cell Li-Ion and Li-polymer battery. The low impedance power path optimizes switch-mode operation efficiency, reduces battery charging time and extends battery life during discharging phase.

Hi,
This patch series was pending almost 2 month.

For the below question
Does it mean to remove 'sysoff_enable' attribute and no more discussion?
https://lore.kernel.org/lkml/CADiBU39FMkDOrMHXTQF+0JGX2tDn_iVXCb19jM6MopnKmaXOpQ@mail.gmail.com/

v7
https://lore.kernel.org/lkml/[email protected]/
v8
https://lore.kernel.org/lkml/[email protected]/
For v7/v8, it may be my fault.
Because I could not get any reply, that's why I try to find any missing header or code defect to be fixed. I know the version tags make others confused.
I'm sorry about that.

Still hope to get any feedback for the finalized v9 version.

Thanks.

Quoted 58 lines

Since v8:
- revert v7 for adding irq wakeup capable, i2c core already did it.

Since v7:
- Add irq wakeup capable.
- Add missing header 'module.h' for MODULE_DEVICE_TABLE.

Since v6:
- Use 'ATTRIBUTE_GROUPS' macro to simplify the attribute coding.
- Explain more details for sysoff_enable attribute.

Since v5:
- Remove one line wrapper.
- Merge header content into source file, remove header file.
- Remove 'charge_term_enable' sysfs entry and merge it into 'charge_term_current' property control.
- Change MODULE_LICENSE from 'GPL v2' to 'GPL'. Following by the below discussion
https://lore.kernel.org/all/[email protected]/
- Recover all the change in sysfs-class-power.
- New a sysfs-class-power-rt9471 file.
- Remove 'charge_term_enable' sysfs entry, directly integrate it in 'charge_term_current' power supply property control.

Since v4:
- Remove the line for the owner field in driver.
- Add the documentation for sysfs entries.

Since v3:
- Move unevaluatedProperties line after $ref for binding patch.
- Add Reviewed-by tag for binding patch.

Since v2:
- Remove the properties for interrupt controller things in the binding documentation.
- Fix dtc error for typo, it's 'regulator-name', not 'regulator-compatible'.
- Add regulator min/max microamp to allow otg vbus current adjustable in example.
- Specify the active-level for charge-enable-gpios in binding example.
- Fix checkpatch error about 'foo * bar' to 'foo *bar' in psy_device_to_chip function.
- Specify the member name directly for the use of linear range.

ChiYuan Huang (3):
dt-bindings: power: supply: Add Richtek RT9471 battery charger
power: supply: rt9471: Add Richtek RT9471 charger driver
Documentation: power: rt9471: Document exported sysfs entries

 Documentation/ABI/testing/sysfs-class-power-rt9471 |  32 +
 .../bindings/power/supply/richtek,rt9471.yaml      |  73 ++
 drivers/power/supply/Kconfig                       |  16 +
 drivers/power/supply/Makefile                      |   1 +
 drivers/power/supply/rt9471.c                      | 931 +++++++++++++++++++++
 5 files changed, 1053 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-power-rt9471
 create mode 100644 Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml
 create mode 100644 drivers/power/supply/rt9471.c
Signature · 1 line
2.7.4