Skip to contentSkip to conversation

Add Richtek RT9471 3A battery charger support

PATCH Superseded cy_huang 2 participants 7 messages Aug 18, 2022

Subsystems (2)

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

cy_huang

author
#0 lore raw

v3 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 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 (2):
dt-bindings: power: supply: Add Richtek RT9471 battery charger
power: supply: rt9471: Add Richtek RT9471 charger driver

 .../bindings/power/supply/richtek,rt9471.yaml      |  73 ++
 drivers/power/supply/Kconfig                       |  16 +
 drivers/power/supply/Makefile                      |   1 +
 drivers/power/supply/rt9471.c                      | 953 +++++++++++++++++++++
 drivers/power/supply/rt9471.h                      |  76 ++
 5 files changed, 1119 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml
 create mode 100644 drivers/power/supply/rt9471.c
 create mode 100644 drivers/power/supply/rt9471.h
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v3 1/2 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 v3 2/2 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 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 | 953 ++++++++++++++++++++++++++++++++++++++++++
 drivers/power/supply/rt9471.h |  76 ++++
 4 files changed, 1046 insertions(+)
 create mode 100644 drivers/power/supply/rt9471.c
 create mode 100644 drivers/power/supply/rt9471.h
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 +953 -0

953 lines not on this page · raw message

drivers/power/supply/rt9471.h new file +76 -0

76 lines not on this page · raw message

Signature · 1 line
2.7.4
#3 lore raw

Re: [PATCH v3 2/2] power: supply: rt9471: Add Richtek RT9471 charger driver

Quoted 16 lines · 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 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/rt9471.c line 722

Quoted 10 lines
drivers/power/supply/rt9471.c new file +10 -0
+
+static DEVICE_ATTR_RW(sysoff_enable);
+static DEVICE_ATTR_RW(charge_term_enable);
+static DEVICE_ATTR_RW(port_detect_enable);
+
+static struct attribute *rt9471_sysfs_entries[] = {
+	&dev_attr_sysoff_enable.attr,
+	&dev_attr_charge_term_enable.attr,
+	&dev_attr_port_detect_enable.attr,
+	NULL

You need to document the sysfs ABI in Documentation.

Quoted 10 lines
drivers/power/supply/rt9471.c new file +10 -0
+};
+
+static const struct attribute_group rt9471_attr_group = {
+	.attrs	= rt9471_sysfs_entries,
+};
+
+static const struct attribute_group *rt9471_attr_groups[] = {
+	&rt9471_attr_group,
+	NULL
+};

(...)

drivers/power/supply/rt9471.c line 942

Quoted 11 lines
drivers/power/supply/rt9471.c new file +11 -0
+
+static const struct of_device_id rt9471_of_device_id[] = {
+	{ .compatible = "richtek,rt9471" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, rt9471_of_device_id);
+
+static struct i2c_driver rt9471_driver = {
+	.driver = {
+		.name = "rt9471",
+		.owner = THIS_MODULE,

You should not need this. Run coccinelle/coccicheck on your driver.

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v3 2/2] power: supply: rt9471: Add Richtek RT9471 charger driver

Krzysztof Kozlowski <[email protected]> 於 2022年8月18日 週四 下午4:09寫道:

Quoted 21 lines · cy_huang
Quoted 16 lines

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 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.

---

(...)

Quoted 12 lines

drivers/power/supply/rt9471.c line 722

Quoted 10 lines
drivers/power/supply/rt9471.c new file +10 -0
+
+static DEVICE_ATTR_RW(sysoff_enable);
+static DEVICE_ATTR_RW(charge_term_enable);
+static DEVICE_ATTR_RW(port_detect_enable);
+
+static struct attribute *rt9471_sysfs_entries[] = {
+     &dev_attr_sysoff_enable.attr,
+     &dev_attr_charge_term_enable.attr,
+     &dev_attr_port_detect_enable.attr,
+     NULL

You need to document the sysfs ABI in Documentation.

Can it be define in 'sysfs-class-power' or a dedicated file called 'sysfs-class-power-rt9471'?
Not sure which one is better.

Quoted 14 lines
Quoted 11 lines
drivers/power/supply/rt9471.c new file +10 -0
+};
+
+static const struct attribute_group rt9471_attr_group = {
+     .attrs  = rt9471_sysfs_entries,
+};
+
+static const struct attribute_group *rt9471_attr_groups[] = {
+     &rt9471_attr_group,
+     NULL
+};

(...)

Quoted 13 lines

drivers/power/supply/rt9471.c line 942

Quoted 11 lines
drivers/power/supply/rt9471.c new file +11 -0
+
+static const struct of_device_id rt9471_of_device_id[] = {
+     { .compatible = "richtek,rt9471" },
+     {}
+};
+MODULE_DEVICE_TABLE(of, rt9471_of_device_id);
+
+static struct i2c_driver rt9471_driver = {
+     .driver = {
+             .name = "rt9471",
+             .owner = THIS_MODULE,

You should not need this. Run coccinelle/coccicheck on your driver.

Yes, I found it. 'module_i2c_driver' already include this owner setting. Just remove it. Thanks.

Quoted 4 lines

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH v3 2/2] power: supply: rt9471: Add Richtek RT9471 charger driver

Quoted 34 lines · ChiYuan Huang

Krzysztof Kozlowski <[email protected]> 於 2022年8月18日 週四 下午4:09寫道:

Quoted 21 lines · cy_huang
Quoted 16 lines

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 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.

---

(...)

Quoted 12 lines

drivers/power/supply/rt9471.c line 722

Quoted 10 lines
drivers/power/supply/rt9471.c new file +10 -0
+
+static DEVICE_ATTR_RW(sysoff_enable);
+static DEVICE_ATTR_RW(charge_term_enable);
+static DEVICE_ATTR_RW(port_detect_enable);
+
+static struct attribute *rt9471_sysfs_entries[] = {
+     &dev_attr_sysoff_enable.attr,
+     &dev_attr_charge_term_enable.attr,
+     &dev_attr_port_detect_enable.attr,
+     NULL

You need to document the sysfs ABI in Documentation.

Quoted 3 lines

Can it be define in 'sysfs-class-power' or a dedicated file called 'sysfs-class-power-rt9471'?
Not sure which one is better.

I don't know what is Sebastian's preference. You can wait for his input or do similarly as last patches reviewed/picked up by him.

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH v3 2/2] power: supply: rt9471: Add Richtek RT9471 charger driver

Krzysztof Kozlowski <[email protected]> 於 2022年8月18日 週四 下午6:18寫道:

Quoted 36 lines · ChiYuan Huang
Quoted 34 lines

Krzysztof Kozlowski <[email protected]> 於 2022年8月18日 週四 下午4:09寫道:

Quoted 33 lines · cy_huang
Quoted 16 lines

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 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/rt9471.c line 722

Quoted 10 lines
drivers/power/supply/rt9471.c new file +10 -0
+
+static DEVICE_ATTR_RW(sysoff_enable);
+static DEVICE_ATTR_RW(charge_term_enable);
+static DEVICE_ATTR_RW(port_detect_enable);
+
+static struct attribute *rt9471_sysfs_entries[] = {
+     &dev_attr_sysoff_enable.attr,
+     &dev_attr_charge_term_enable.attr,
+     &dev_attr_port_detect_enable.attr,
+     NULL

You need to document the sysfs ABI in Documentation.

Quoted 6 lines
Quoted 3 lines

Can it be define in 'sysfs-class-power' or a dedicated file called 'sysfs-class-power-rt9471'?
Not sure which one is better.

I don't know what is Sebastian's preference. You can wait for his input or do similarly as last patches reviewed/picked up by him.

M... OK.
Whatever the preference is, at least, I can prepare the ABI contents first.

Quoted 3 lines

Best regards,
Krzysztof