Skip to contentSkip to conversation

power: supply: twl6030/32 charger

PATCH Superseded Andreas Kemnade 2 participants 6 messages Oct 5, 2024

Subsystems (4)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Andreas Kemnade

author maintainer
#0 lore raw

v3 cover power: supply: twl6030/32 charger

Add basic support for the charger in the TWL6030/32. Supported is the USB path. AC path is not handled yet, also there is no entry yet in /sys/class/power_supply with type battery yet.

Without this series, devices will happily drain battery when running on mainline.

Changes in v3:
- define charger in toplevel
- s/bci/charger for twl4030

Changes in v2:
- s/bci/charger in mfd schema
- additionalProperties for charger node
- extended example in mfd schema
- no quotes for compatibles in charger schema
- no example in charger schema
- interrupt description in charger schema
- replace device_is_compatible by driver data
- clang compile fix
- removed alias
- style fixes

Andreas Kemnade (4):
dt-bindings: power: supply: Add TI TWL603X charger
dt-bindings: mfd: twl: add charger node also for TWL603x
power: supply: initial support for TWL6030/32
ARM: dts: ti/omap: use standard node name for twl4030 charger

 .../devicetree/bindings/mfd/ti,twl.yaml       |  30 +-
 .../power/supply/ti,twl6030-charger.yaml      |  48 ++
 arch/arm/boot/dts/ti/omap/twl4030.dtsi        |   2 +-
 drivers/power/supply/Kconfig                  |  10 +
 drivers/power/supply/Makefile                 |   1 +
 drivers/power/supply/twl6030_charger.c        | 580 ++++++++++++++++++
 6 files changed, 668 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/power/supply/ti,twl6030-charger.yaml
 create mode 100644 drivers/power/supply/twl6030_charger.c
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

PATCH v3 1/4 dt-bindings: power: supply: Add TI TWL603X charger

Use a fallback compatible since for especially for generic defensive setup of parameters, both 6030 and 6032 are the same and U-Boot actually uses a generic 6030/32 function to enable the charger.

---
 .../power/supply/ti,twl6030-charger.yaml      | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/ti,twl6030-charger.yaml
Documentation/devicetree/bindings/power/supply/ti,twl6030-charger.yaml new file +48 -0
new file mode 100644
index 0000000000000..fc604d8a469df
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/supply/ti,twl6030-charger.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TWL6030/32 BCI (Battery Charger Interface)
+
+description:
+  The battery charger needs to be configured to do any charging besides of
+  precharging. The GPADC in the PMIC has to be used to get the related
+  voltages.
+
+maintainers:
+  - Andreas Kemnade <[email protected]>
+
+allOf:
+  - $ref: power-supply.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - const: ti,twl6030-charger
+      - items:
+          - const: ti,twl6032-charger
+          - const: ti,twl6030-charger
+
+  interrupts:
+    items:
+      - description: Charger Control Interrupt
+      - description: Charger Fault Interrupt
+
+  io-channels:
+    items:
+      - description: VBUS Voltage Channel
+
+  io-channel-names:
+    items:
+      - const: vusb
+
+  monitored-battery: true
+
+required:
+  - compatible
+  - interrupts
+  - monitored-battery
+
+additionalProperties: false
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

PATCH v3 2/4 dt-bindings: mfd: twl: add charger node also for TWL603x

In reply to Andreas Kemnade

Also the TWL603X devices have a charger, so allow to specify it here.

---
 .../devicetree/bindings/mfd/ti,twl.yaml       | 30 +++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/mfd/ti,twl.yaml +28 -2
index e94b0fd7af0f8..e772d13adbfdc 100644
@@ -54,7 +54,7 @@ allOf:
           $ref: /schemas/iio/adc/ti,twl4030-madc.yaml
           unevaluatedProperties: false
 
-        bci:
+        charger:
           type: object
           $ref: /schemas/power/supply/twl4030-charger.yaml
           unevaluatedProperties: false
@@ -105,6 +105,11 @@ allOf:
             regulator-initial-mode: false
 
       properties:
+        charger:
+          type: object
+          properties:
+            compatible:
+              const: ti,twl6030-charger
         gpadc:
           type: object
           properties:
@@ -136,6 +141,13 @@ allOf:
             regulator-initial-mode: false
 
       properties:
+        charger:
+          type: object
+          properties:
+            compatible:
+              items:
+                - const: ti,twl6032-charger
+                - const: ti,twl6030-charger
         gpadc:
           type: object
           properties:
@@ -169,6 +181,12 @@ properties:
   "#clock-cells":
     const: 1
 
+  charger:
+    type: object
+    additionalProperties: true
+    properties:
+      compatible: true
+
   rtc:
     type: object
     additionalProperties: false
@@ -222,6 +240,14 @@ examples:
         interrupt-controller;
         #interrupt-cells = <1>;
 
+        charger {
+          compatible = "ti,twl6030-charger";
+          interrupts = <2>, <5>;
+          io-channels = <&gpadc 10>;
+          io-channel-names = "vusb";
+          monitored-battery = <&bat>;
+        };
+
         gpadc {
           compatible = "ti,twl6030-gpadc";
           interrupts = <6>;
@@ -259,7 +285,7 @@ examples:
         interrupt-controller;
         #interrupt-cells = <1>;
 
-        bci {
+        charger {
           compatible = "ti,twl4030-bci";
           interrupts = <9>, <2>;
           bci3v1-supply = <&vusb3v1>;
Signature · 1 line
2.39.2
maintainer Reviewed-by on v3 2/4
#3 lore raw

Re: [PATCH v3 2/4] dt-bindings: mfd: twl: add charger node also for TWL603x

Quoted 47 lines · Andreas Kemnade

Also the TWL603X devices have a charger, so allow to specify it here.

---
 .../devicetree/bindings/mfd/ti,twl.yaml       | 30 +++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/mfd/ti,twl.yaml +13 -1
index e94b0fd7af0f8..e772d13adbfdc 100644
@@ -54,7 +54,7 @@ allOf:
           $ref: /schemas/iio/adc/ti,twl4030-madc.yaml
           unevaluatedProperties: false
 
-        bci:
+        charger:
           type: object
           $ref: /schemas/power/supply/twl4030-charger.yaml
           unevaluatedProperties: false
@@ -105,6 +105,11 @@ allOf:
             regulator-initial-mode: false
 
       properties:
+        charger:
+          type: object
+          properties:
+            compatible:
+              const: ti,twl6030-charger
         gpadc:
           type: object
           properties:
@@ -136,6 +141,13 @@ allOf:
             regulator-initial-mode: false
 
       properties:
+        charger:
+          type: object
+          properties:
+            compatible:
+              items:
+                - const: ti,twl6032-charger
+                - const: ti,twl6030-charger
         gpadc:
           type: object
           properties:

Documentation/devicetree/bindings/mfd/ti,twl.yaml properties: · line 188

Quoted 8 lines
Documentation/devicetree/bindings/mfd/ti,twl.yaml +5 -0
@@ -169,6 +181,12 @@ properties:
   "#clock-cells":
     const: 1
 
+  charger:
+    type: object
+    additionalProperties: true
+    properties:
+      compatible: true

I think the behavior you're after is:

required:
- compatible

Because what you have is true when compatible is not present.

With that,

author maintainer
#4 lore raw

PATCH v3 3/4 power: supply: initial support for TWL6030/32

In reply to Andreas Kemnade

Add a driver for the charger in the TWL6030/32. For now it does not report much in sysfs but parameters are set up for USB, charging is enabled with the specified parameters. It stops charging when full and also restarts charging.
This prevents ending up in a system setup where you run out of battery although a charger is plugged in after precharge completed.

Battery voltage behavior was checked via the GPADC.

---
 drivers/power/supply/Kconfig           |  10 +
 drivers/power/supply/Makefile          |   1 +
 drivers/power/supply/twl6030_charger.c | 580 +++++++++++++++++++++++++
 3 files changed, 591 insertions(+)
 create mode 100644 drivers/power/supply/twl6030_charger.c
drivers/power/supply/Kconfig +10 -0
index bcfa63fb9f1e2..9f2eef6787f7a 100644
@@ -493,6 +493,16 @@ config CHARGER_TWL4030
 	help
 	  Say Y here to enable support for TWL4030 Battery Charge Interface.
 
+config CHARGER_TWL6030
+	tristate "OMAP TWL6030 BCI charger driver"
+	depends on IIO && TWL4030_CORE
+	help
+	  Say Y here to enable support for TWL6030/6032 Battery Charge
+	  Interface.
+
+	  This driver can be build as a module. If so, the module will be
+	  called twl6030_charger.
+
 config CHARGER_LP8727
 	tristate "TI/National Semiconductor LP8727 charger driver"
 	depends on I2C
drivers/power/supply/Makefile +1 -0
index 8dcb415453171..59c4a9f40d28a 100644
@@ -69,6 +69,7 @@ obj-$(CONFIG_CHARGER_CPCAP)	+= cpcap-charger.o
 obj-$(CONFIG_CHARGER_ISP1704)	+= isp1704_charger.o
 obj-$(CONFIG_CHARGER_MAX8903)	+= max8903_charger.o
 obj-$(CONFIG_CHARGER_TWL4030)	+= twl4030_charger.o
+obj-$(CONFIG_CHARGER_TWL6030)	+= twl6030_charger.o
 obj-$(CONFIG_CHARGER_LP8727)	+= lp8727_charger.o
 obj-$(CONFIG_CHARGER_LP8788)	+= lp8788-charger.o
 obj-$(CONFIG_CHARGER_GPIO)	+= gpio-charger.o
drivers/power/supply/twl6030_charger.c new file +580 -0

580 lines not on this page · raw message

Signature · 1 line
2.39.2
author maintainer
#5 lore raw

PATCH v3 4/4 ARM: dts: ti/omap: use standard node name for twl4030 charger

In reply to Andreas Kemnade

Use the established node name for the charger.

---
 arch/arm/boot/dts/ti/omap/twl4030.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/ti/omap/twl4030.dtsi +1 -1
index a5d9c5738317a..07b9ca942e78d 100644
@@ -16,7 +16,7 @@ rtc {
 		interrupts = <11>;
 	};
 
-	charger: bci {
+	charger: charger {
 		compatible = "ti,twl4030-bci";
 		interrupts = <9>, <2>;
 		bci3v1-supply = <&vusb3v1>;
Signature · 1 line
2.39.2