Add Richtek RT9471 3A battery charger support
Subsystems (2)
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.
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 | 78 ++ drivers/power/supply/Kconfig | 16 + drivers/power/supply/Makefile | 1 + drivers/power/supply/rt9471.c | 952 +++++++++++++++++++++ drivers/power/supply/rt9471.h | 76 ++ 5 files changed, 1123 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
PATCH 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.
--- .../bindings/power/supply/richtek,rt9471.yaml | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +78 -0
@@ -0,0 +1,78 @@ +# 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 + + ceb-gpios: + maxItems: 1 + + wakeup-source: true + + interrupts: + maxItems: 1 + + interrupt-controller: true + + "#interrupt-cells": + const: 1 + + usb-otg-vbus-regulator: + type: object + unevaluatedProperties: false + $ref: /schemas/regulator/regulator.yaml# + +required: + - compatible + - reg + - wakeup-source + - interrupts + - interrupt-controller + - "#interrupt-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + charger@53 { + compatible = "richtek,rt9471"; + reg = <0x53>; + ceb-gpios = <&gpio26 1 0>; + wakeup-source; + interrupts-extended = <&gpio1 32 IRQ_TYPE_EDGE_FALLING>; + interrupt-controller; + #interrupt-cells = <1>; + + usb-otg-vbus-regulator { + regulator-compatible = "usb-otg-vbus"; + regulator-min-microvolt = <4850000>; + regulator-max-microvolt = <5300000>; + }; + }; + };
Signature · 1 line
2.7.4
Re: [PATCH 1/2] dt-bindings: power: supply: Add Richtek RT9471 battery charger
Quoted 4 lines · cy_huang
From: ChiYuan Huang <[email protected]>
Add bindings for the Richtek RT9471 I2C controlled battery charger.
Thank you for your patch. There is something to discuss/improve.
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 29
Quoted 9 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +9
-0+properties: + compatible: + const: richtek,rt9471 + + reg: + maxItems: 1 + + ceb-gpios: + maxItems: 1
This looks not standard, so please provide a description.
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 39
Quoted 10 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +10
-0+ + wakeup-source: true + + interrupts: + maxItems: 1 + + interrupt-controller: true + + "#interrupt-cells": + const: 1
Why a charger driver is a interrupt-controller?
Quoted 17 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +17
-0+ + usb-otg-vbus-regulator: + type: object + unevaluatedProperties: false + $ref: /schemas/regulator/regulator.yaml# + +required: + - compatible + - reg + - wakeup-source + - interrupts + - interrupt-controller + - "#interrupt-cells" + +additionalProperties: false + +examples:
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 66
Quoted 10 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +10
-0+ - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + charger@53 { + compatible = "richtek,rt9471"; + reg = <0x53>; + ceb-gpios = <&gpio26 1 0>;
Isn't the last value a GPIO flag? If yes, use appropriate define.
Best regards,
Krzysztof
Re: [PATCH 1/2] dt-bindings: power: supply: Add Richtek RT9471 battery charger
Krzysztof Kozlowski <[email protected]> 於 2022年8月11日 週四 晚上10:12寫道:
Quoted 9 lines · cy_huang
Quoted 4 lines
From: ChiYuan Huang <[email protected]>
Add bindings for the Richtek RT9471 I2C controlled battery charger.
Thank you for your patch. There is something to discuss/improve.
Quoted 11 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 29
Quoted 9 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +9
-0+properties: + compatible: + const: richtek,rt9471 + + reg: + maxItems: 1 + + ceb-gpios: + maxItems: 1This looks not standard, so please provide a description.
It's the external 'charge enable' pin that's used to control battery charging. The priority is higher than the register 'CHG_EN' control.
In the word, 'b' means it's reverse logic, low to allow charging, high to force disable charging.
description:
External charge enable pin that can force control not to charge the battery. Low to allow charging, high to disable charging.
Quoted 13 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 39
Quoted 11 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +10
-0+ + wakeup-source: true + + interrupts: + maxItems: 1 + + interrupt-controller: true + + "#interrupt-cells": + const: 1Why a charger driver is a interrupt-controller?
There're 32 nested IRQs from RT9471.
The original thought is to make the user easy to bind the interrupt into their driver.
For charger driver, does it mean legacy IRQ handler is more preferred?
Quoted 22 lines
Quoted 22 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +21
-0+ + usb-otg-vbus-regulator: + type: object + unevaluatedProperties: false + $ref: /schemas/regulator/regulator.yaml# + +required: + - compatible + - reg + - wakeup-source + - interrupts + - interrupt-controller + - "#interrupt-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>;
Quoted 8 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 66
Quoted 6 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +6
-0+ #size-cells = <0>; + + charger@53 { + compatible = "richtek,rt9471"; + reg = <0x53>; + ceb-gpios = <&gpio26 1 0>;Isn't the last value a GPIO flag? If yes, use appropriate define.
I already specify GPIOD_OUT_LOW in the gpiod_request flag. Do I need to convert the gpio request code to GPIOD_OUT_HIGH, and specify here as GPIO_ACTIVE_LOW?
Quoted 5 lines
Best regards,
Krzysztof
Re: [PATCH 1/2] dt-bindings: power: supply: Add Richtek RT9471 battery charger
Quoted 21 lines · ChiYuan Huang
Krzysztof Kozlowski <[email protected]> 於 2022年8月11日 週四 晚上10:12寫道:
Quoted 9 lines · cy_huang
Quoted 4 lines
From: ChiYuan Huang <[email protected]>
Add bindings for the Richtek RT9471 I2C controlled battery charger.
Thank you for your patch. There is something to discuss/improve.
Quoted 11 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 29
Quoted 9 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +9
-0+properties: + compatible: + const: richtek,rt9471 + + reg: + maxItems: 1 + + ceb-gpios: + maxItems: 1This looks not standard, so please provide a description.
Quoted 4 lines
It's the external 'charge enable' pin that's used to control battery charging. The priority is higher than the register '
CHG_EN' control.
In the word, 'b' means it's reverse logic, low to allow charging, high to force disable charging.
Isn't this standard enable-gpios property?
Quoted 18 lines
description:
External charge enable pin that can force control not to charge the battery. Low to allow charging, high to disable charging.Quoted 13 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 39
Quoted 11 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +10
-0+ + wakeup-source: true + + interrupts: + maxItems: 1 + + interrupt-controller: true + + "#interrupt-cells": + const: 1Why a charger driver is a interrupt-controller?
Quoted 3 lines
There're 32 nested IRQs from RT9471.
The original thought is to make the user easy to bind the interrupt into their driver.
Bindings are not related to the driver but to hardware...
Quoted 2 lines
For charger driver, does it mean legacy IRQ handler is more preferred?
Who is the consumer of these interrupts? Can you show the DTS with the interrupt consumer?
Quoted 30 lines
Quoted 22 lines
Quoted 22 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +21
-0+ + usb-otg-vbus-regulator: + type: object + unevaluatedProperties: false + $ref: /schemas/regulator/regulator.yaml# + +required: + - compatible + - reg + - wakeup-source + - interrupts + - interrupt-controller + - "#interrupt-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>;Quoted 8 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 66
Quoted 6 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +6
-0+ #size-cells = <0>; + + charger@53 { + compatible = "richtek,rt9471"; + reg = <0x53>; + ceb-gpios = <&gpio26 1 0>;Isn't the last value a GPIO flag? If yes, use appropriate define.
Quoted 1 line
I already specify
GPIOD_OUT_LOWin thegpiod_requestflag.
It is not related to the DTS. Anyway writing "low" for a meaning of high is not correct usually...
Quoted 2 lines
Do I need to convert the gpio request code to
GPIOD_OUT_HIGH, and specify here asGPIO_ACTIVE_LOW?
You need to properly describe the hardware. The polarity of logical signal is defined by DTS, not by driver. It does not make sense to do it in driver. What if on some board the signal is inverted?
Best regards,
Krzysztof
Re: [PATCH 1/2] dt-bindings: power: supply: Add Richtek RT9471 battery charger
Krzysztof Kozlowski <[email protected]> 於 2022年8月12日 週五 下午2:54寫道:
Quoted 23 lines · ChiYuan Huang
Quoted 21 lines
Krzysztof Kozlowski <[email protected]> 於 2022年8月11日 週四 晚上10:12寫道:
Quoted 20 lines · cy_huang
Quoted 4 lines
From: ChiYuan Huang <[email protected]>
Add bindings for the Richtek RT9471 I2C controlled battery charger.
Thank you for your patch. There is something to discuss/improve.
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 29
Quoted 9 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +9
-0+properties: + compatible: + const: richtek,rt9471 + + reg: + maxItems: 1 + + ceb-gpios: + maxItems: 1This looks not standard, so please provide a description.
Quoted 6 lines
Quoted 4 lines
It's the external 'charge enable' pin that's used to control battery charging. The priority is higher than the register '
CHG_EN' control.
In the word, 'b' means it's reverse logic, low to allow charging, high to force disable charging.Isn't this standard enable-gpios property?
Not the same thing, this charger includes power patch control. This gpio is used to 'force disable' charge the battery.
Quoted 19 lines
Quoted 19 lines
description:
External charge enable pin that can force control not to charge the battery. Low to allow charging, high to disable charging.Quoted 13 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 39
Quoted 11 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +10
-0+ + wakeup-source: true + + interrupts: + maxItems: 1 + + interrupt-controller: true + + "#interrupt-cells": + const: 1Why a charger driver is a interrupt-controller?
Quoted 6 lines
Quoted 3 lines
There're 32 nested IRQs from RT9471.
The original thought is to make the user easy to bind the interrupt into their driver.Bindings are not related to the driver but to hardware...
Sorry, I mislead your comment.
Refer to bq2515x.yaml, I think it's better to change this property to 'charge-enable-gpios'.
It's the same usage like as TI charger.
Quoted 41 lines
Quoted 2 lines
For charger driver, does it mean legacy IRQ handler is more preferred?
Who is the consumer of these interrupts? Can you show the DTS with the interrupt consumer?
Quoted 30 lines
Quoted 22 lines
Quoted 22 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +21
-0+ + usb-otg-vbus-regulator: + type: object + unevaluatedProperties: false + $ref: /schemas/regulator/regulator.yaml# + +required: + - compatible + - reg + - wakeup-source + - interrupts + - interrupt-controller + - "#interrupt-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>;Quoted 8 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 66
Quoted 6 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +6
-0+ #size-cells = <0>; + + charger@53 { + compatible = "richtek,rt9471"; + reg = <0x53>; + ceb-gpios = <&gpio26 1 0>;Isn't the last value a GPIO flag? If yes, use appropriate define.
Quoted 1 line
I already specify
GPIOD_OUT_LOWin thegpiod_requestflag.It is not related to the DTS. Anyway writing "low" for a meaning of high is not correct usually...
Quoted 7 lines
Quoted 2 lines
Do I need to convert the gpio request code to
GPIOD_OUT_HIGH, and specify here asGPIO_ACTIVE_LOW?You need to properly describe the hardware. The polarity of logical signal is defined by DTS, not by driver. It does not make sense to do it in driver. What if on some board the signal is inverted?
From our discussion, binding example just keep the active level that the pin is. So 'GPIO_ACTIVE_LOW', thanks.
All of the above will be fixed in the next revision.
Quoted 2 lines
Best regards,
Krzysztof
Re: [PATCH 1/2] dt-bindings: power: supply: Add Richtek RT9471 battery charger
ChiYuan Huang <[email protected]> 於 2022年8月12日 週五 晚上11:57寫道:
Quoted 56 lines
Krzysztof Kozlowski <[email protected]> 於 2022年8月12日 週五 下午2:54寫道:
Quoted 23 lines · ChiYuan Huang
Quoted 21 lines
Krzysztof Kozlowski <[email protected]> 於 2022年8月11日 週四 晚上10:12寫道:
Quoted 20 lines · cy_huang
Quoted 4 lines
From: ChiYuan Huang <[email protected]>
Add bindings for the Richtek RT9471 I2C controlled battery charger.
Thank you for your patch. There is something to discuss/improve.
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 29
Quoted 9 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +9
-0+properties: + compatible: + const: richtek,rt9471 + + reg: + maxItems: 1 + + ceb-gpios: + maxItems: 1This looks not standard, so please provide a description.
Quoted 6 lines
Quoted 4 lines
It's the external 'charge enable' pin that's used to control battery charging. The priority is higher than the register '
CHG_EN' control.
In the word, 'b' means it's reverse logic, low to allow charging, high to force disable charging.Isn't this standard enable-gpios property?
Not the same thing, this charger includes power patch control. This gpio is used to 'force disable' charge the battery.
Quoted 23 lines
Quoted 22 lines
description:
External charge enable pin that can force control not to charge the battery. Low to allow charging, high to disable charging.Quoted 13 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 39
Quoted 11 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +10
-0+ + wakeup-source: true + + interrupts: + maxItems: 1 + + interrupt-controller: true + + "#interrupt-cells": + const: 1Why a charger driver is a interrupt-controller?
There're 32 nested IRQs from RT9471.
The original thought is to make the user easy to bind the interrupt into their driver.
Quoted 12 lines
Quoted 2 lines
Bindings are not related to the driver but to hardware...
Sorry, I mislead your comment.
Refer tobq2515x.yaml, I think it's better to change this property to 'charge-enable-gpios'.
It's the same usage like as TI charger.Quoted 6 lines
Quoted 2 lines
For charger driver, does it mean legacy IRQ handler is more preferred?
Who is the consumer of these interrupts? Can you show the DTS with the interrupt consumer?
Sorry, I forget to reply this question.
Some battery driver may need to know the 'full', 'recharge' , 'ieoc' status. The usage will be like as below
battery {
interrupts-extended = <&rt9471_chg 2 0>, <&rt9471_chg 3 0>, &(rt9471_chg 5 0>; interrupt-names = "chg-done", "chg-recharge", "chg-ieoc";
};
Some gauge HW needs this information to enhance the battery capacity accuracy.
Quoted 49 lines
Quoted 35 lines
Quoted 30 lines
Quoted 22 lines
Quoted 22 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +21
-0+ + usb-otg-vbus-regulator: + type: object + unevaluatedProperties: false + $ref: /schemas/regulator/regulator.yaml# + +required: + - compatible + - reg + - wakeup-source + - interrupts + - interrupt-controller + - "#interrupt-cells" + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>;Quoted 8 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml line 66
Quoted 6 lines
Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml new file +6
-0+ #size-cells = <0>; + + charger@53 { + compatible = "richtek,rt9471"; + reg = <0x53>; + ceb-gpios = <&gpio26 1 0>;Isn't the last value a GPIO flag? If yes, use appropriate define.
Quoted 1 line
I already specify
GPIOD_OUT_LOWin thegpiod_requestflag.It is not related to the DTS. Anyway writing "low" for a meaning of high is not correct usually...
Quoted 7 lines
Quoted 2 lines
Do I need to convert the gpio request code to
GPIOD_OUT_HIGH, and specify here asGPIO_ACTIVE_LOW?You need to properly describe the hardware. The polarity of logical signal is defined by DTS, not by driver. It does not make sense to do it in driver. What if on some board the signal is inverted?
From our discussion, binding example just keep the active level that the pin is. So '
GPIO_ACTIVE_LOW', thanks.All of the above will be fixed in the next revision.
Quoted 2 lines
Best regards,
Krzysztof
Re: [PATCH 1/2] dt-bindings: power: supply: Add Richtek RT9471 battery charger
Quoted 11 lines · ChiYuan Huang
Quoted 7 lines
It's the same usage like as TI charger.
Quoted 6 lines
Quoted 2 lines
For charger driver, does it mean legacy IRQ handler is more preferred?
Who is the consumer of these interrupts? Can you show the DTS with the interrupt consumer?
Sorry, I forget to reply this question.
Some battery driver may need to know the 'full', 'recharge' , 'ieoc' status. The usage will be like as below
Quoted 6 lines
battery {
interrupts-extended = <&rt9471_chg2 0>, <&rt9471_chg3 0>, &(rt9471_chg 5 0>; interrupt-names = "chg-done", "chg-recharge", "chg-ieoc";
};Some gauge HW needs this information to enhance the battery capacity accuracy.
Other supply stack pieces do it via supplies (supplied to/from in include/linux/power_supply.h) and reporting power_supply_changed().
With such explanation, your device is an interrupt source, but it is not an interrupt controller. If your device is interrupt controller, it means someone routes the interrupt line to your device. Physical line.
Best regards,
Krzysztof
Re: [PATCH 1/2] dt-bindings: power: supply: Add Richtek RT9471 battery charger
Krzysztof Kozlowski <[email protected]> 於 2022年8月13日 週六 凌晨2:53寫道:
Quoted 18 lines · ChiYuan Huang
Quoted 16 lines
Quoted 7 lines
It's the same usage like as TI charger.
Quoted 6 lines
Quoted 2 lines
For charger driver, does it mean legacy IRQ handler is more preferred?
Who is the consumer of these interrupts? Can you show the DTS with the interrupt consumer?
Sorry, I forget to reply this question.
Some battery driver may need to know the 'full', 'recharge' , 'ieoc' status. The usage will be like as belowbattery {
interrupts-extended = <&rt9471_chg2 0>, <&rt9471_chg3 0>, &(rt9471_chg 5 0>; interrupt-names = "chg-done", "chg-recharge", "chg-ieoc";
};
Quoted 9 lines
Quoted 1 line
Some gauge HW needs this information to enhance the battery capacity accuracy.
Other supply stack pieces do it via supplies (supplied to/from in
include/linux/power_supply.h) and reportingpower_supply_changed().With such explanation, your device is an interrupt source, but it is not an interrupt controller. If your device is interrupt controller, it means someone routes the interrupt line to your device. Physical line.
Yap, sure. And so on, just use the SW power supply chain to do this kind of event notification.
To remove it, it doesn't affect the internal interrupt request inside the driver.
Just cannot be used for the outer driver to request the events directly.
If so, I think 'interrupt-controller' and even '#interrupt-cells' need to be removed.
OK?
Quoted 2 lines
Best regards,
Krzysztof
Re: [PATCH 1/2] dt-bindings: power: supply: Add Richtek RT9471 battery charger
Quoted 15 lines · ChiYuan Huang
Quoted 9 lines
Quoted 1 line
Some gauge HW needs this information to enhance the battery capacity accuracy.
Other supply stack pieces do it via supplies (supplied to/from in
include/linux/power_supply.h) and reportingpower_supply_changed().With such explanation, your device is an interrupt source, but it is not an interrupt controller. If your device is interrupt controller, it means someone routes the interrupt line to your device. Physical line.
Yap, sure. And so on, just use the SW power supply chain to do this kind of event notification.
To remove it, it doesn't affect the internal interrupt request inside the driver.
Just cannot be used for the outer driver to request the events directly.
Quoted 3 lines
If so, I think 'interrupt-controller' and even '#interrupt-cells' need to be removed.
OK?
Yes, both should be removed. Your device is not an interrupt controller...
Best regards,
Krzysztof
Rob Herring
maintainerRe: [PATCH 1/2] dt-bindings: power: supply: Add Richtek RT9471 battery charger
In reply to cy_huangQuoted 4 lines · cy_huang
From: ChiYuan Huang <[email protected]>
Add bindings for the Richtek RT9471 I2C controlled battery charger.
Quoted 8 lines
Co-developed-by Alina Yu <[email protected]>Signed-off-by Alina Yu <[email protected]>Signed-off-by ChiYuan Huang <[email protected]>--- .../bindings/power/supply/richtek,rt9471.yaml | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/power/supply/richtek,rt9471.example.dtb: charger@53: usb-otg-vbus-regulator: Unevaluated properties are not allowed ('regulator-compatible' was unexpected)
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/power/supply/richtek,rt9471.yaml
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/patch/
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit.
Re: [PATCH 1/2] dt-bindings: power: supply: Add Richtek RT9471 battery charger
Rob Herring <[email protected]> 於 2022年8月12日 週五 晚上11:13寫道:
Quoted 20 lines · cy_huang
Quoted 4 lines
From: ChiYuan Huang <[email protected]>
Add bindings for the Richtek RT9471 I2C controlled battery charger.
Quoted 8 lines
Co-developed-by Alina Yu <[email protected]>Signed-off-by Alina Yu <[email protected]>Signed-off-by ChiYuan Huang <[email protected]>--- .../bindings/power/supply/richtek,rt9471.yaml | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/richtek,rt9471.yamlMy bot found errors running 'make DT_CHECKER_FLAGS=-m
dt_binding_check' on your patch (DT_CHECKER_FLAGSis new in v5.13):yamllint warnings/errors:
Quoted 8 lines
dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/power/supply/richtek,rt9471.example.dtb: charger@53: usb-otg-vbus-regulator: Unevaluated properties are not allowed ('regulator-compatible' was unexpected)
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/power/supply/richtek,rt9471.yamldoc reference errors (make refcheckdocs):
Thanks, after I add 'DT_CHECKER_FLAGS=-m', it also can be found for this error.
This is typo, not 'regulator-compatible', it's 'regulator-name'.
Will be fixed in next revision.
Quoted 11 lines
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
If you already ran 'make
dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:pip3 install dtschema --upgrade
Please check and re-submit.
PATCH 2/2 power: supply: rt9471: Add Richtek RT9471 charger driver
In reply to cy_huangFrom: 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.
--- drivers/power/supply/Kconfig | 16 + drivers/power/supply/Makefile | 1 + drivers/power/supply/rt9471.c | 952 ++++++++++++++++++++++++++++++++++++++++++ drivers/power/supply/rt9471.h | 76 ++++ 4 files changed, 1045 insertions(+) create mode 100644 drivers/power/supply/rt9471.c create mode 100644 drivers/power/supply/rt9471.h
drivers/power/supply/Kconfig +16 -0
@@ -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
@@ -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 +952 -0
952 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
Re: [PATCH 2/2] power: supply: rt9471: Add Richtek RT9471 charger driver
Hi ChiYuan,
Thanks for the patch :)
to 11. elok. 2022 klo 16.43 cy_huang ([email protected]) kirjoitti:
Quoted 13 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.
Co-developed-by Alina Yu <[email protected]>Signed-off-by Alina Yu <[email protected]>Signed-off-by ChiYuan Huang <[email protected]>---
drivers/power/supply/rt9471.c line 120
Quoted 9 lines
drivers/power/supply/rt9471.c new file +9
-0+ +static const struct linear_range rt9471_chg_ranges[RT9471_MAX_RANGES ] = { + [RT9471_RANGE_AICR ] = {50000 ,1 ,63 ,50000 }, + [RT9471_RANGE_MIVR ] = {3900000 ,0 ,15 ,100000 }, + [RT9471_RANGE_IPRE ] = {50000 ,0 ,15 ,50000 }, + [RT9471_RANGE_VCHG ] = {3900000 ,0 ,80 ,10000 }, + [RT9471_RANGE_ICHG ] = {0 ,0 ,63 ,50000 }, + [RT9471_RANGE_IEOC ] = {50000 ,0 ,15 ,50000 }, +};
I just jumped in to ask if that could you please use the field names? Eg.
{ .min = 50000, .min_sel = 1, .max_sel = 63, .step = 50000 },
This would make it less error prone in case someone changes the members in struct linear_range.
Quoted 107 lines
drivers/power/supply/rt9471.c new file +107
-0+ +static int rt9471_set_value_by_field_range (struct rt9471_chip *chip, +enum rt9471_fields field, +enum rt9471_ranges range,int val) +{ +unsigned int sel; + +if (val <0 ) +return -EINVAL ; + +linear_range_get_selector_within (rt9471_chg_ranges + range, val, &sel); + +return regmap_field_write (chip->rm_fields[field], sel); +} + + +static int rt9471_get_value_by_field_range (struct rt9471_chip *chip, +enum rt9471_fields field, +enum rt9471_ranges range,int *val) +{ +unsigned int sel, rvalue; +int ret; + + ret =regmap_field_read (chip->rm_fields[field], &sel); +if (ret) +return ret; + + ret =linear_range_get_value (rt9471_chg_ranges + range, sel, &rvalue); +if (ret) +return ret; + + *val = rvalue; +return 0 ; +} + +static inline int rt9471_set_hiz (struct rt9471_chip *chip,int enable) +{ +return regmap_field_write (chip->rm_fields[F_HZ ], enable); +} + +static inline int rt9471_set_ichg (struct rt9471_chip *chip,int microamp) +{ +return rt9471_set_value_by_field_range (chip,F_ICHG_REG , +RT9471_RANGE_ICHG , microamp); +} + +static inline int rt9471_get_ichg (struct rt9471_chip *chip,int *microamp) +{ +return rt9471_get_value_by_field_range (chip,F_ICHG_REG , +RT9471_RANGE_ICHG , microamp); +} + +static inline int rt9471_set_cv (struct rt9471_chip *chip,int microvolt) +{ +return rt9471_set_value_by_field_range (chip,F_VBAT_REG , +RT9471_RANGE_VCHG , microvolt); +} + +static inline int rt9471_get_cv (struct rt9471_chip *chip,int *microamp) +{ +return rt9471_get_value_by_field_range (chip,F_VBAT_REG , +RT9471_RANGE_VCHG , microamp); +} + +static inline int rt9471_set_mivr (struct rt9471_chip *chip,int microvolt) +{ +return rt9471_set_value_by_field_range (chip,F_MIVR , +RT9471_RANGE_MIVR , microvolt); +} + +static inline int rt9471_get_mivr (struct rt9471_chip *chip,int *microvolt) +{ +return rt9471_get_value_by_field_range (chip,F_MIVR , +RT9471_RANGE_MIVR , microvolt); +} + +static inline int rt9471_set_aicr (struct rt9471_chip *chip,int microamp) +{ +return rt9471_set_value_by_field_range (chip,F_AICR ,RT9471_RANGE_AICR , + microamp); +} + +static inline int rt9471_get_aicr (struct rt9471_chip *chip,int *microamp) +{ +return rt9471_get_value_by_field_range (chip,F_AICR ,RT9471_RANGE_AICR , + microamp); +} + +static inline int rt9471_set_iprechg (struct rt9471_chip *chip,int microamp) +{ +return rt9471_set_value_by_field_range (chip,F_IPRE_CHG , +RT9471_RANGE_IPRE , microamp); +} + +static inline int rt9471_get_iprechg (struct rt9471_chip *chip,int *microamp) +{ +return rt9471_get_value_by_field_range (chip,F_IPRE_CHG , +RT9471_RANGE_IPRE , microamp); +} + +static inline int rt9471_set_ieoc (struct rt9471_chip *chip,int microamp) +{ +return rt9471_set_value_by_field_range (chip,F_IEOC_CHG , +RT9471_RANGE_IEOC , microamp); +} + +static inline int rt9471_get_ieoc (struct rt9471_chip *chip,int *microamp)
drivers/power/supply/rt9471.c line 237
Quoted 10 lines
drivers/power/supply/rt9471.c new file +10
-0+{ +return rt9471_get_value_by_field_range (chip,F_IEOC_CHG , +RT9471_RANGE_IEOC , microamp); +} + +static inline int rt9471_set_chg_enable (struct rt9471_chip *chip,int enable) +{ +return regmap_field_write (chip->rm_fields[F_CHG_EN ], !!enable); +} +
//snip
drivers/power/supply/rt9471.c line 613
Quoted 5 lines
drivers/power/supply/rt9471.c new file +5
-0+ +static inline struct rt9471_chip *psy_device_to_chip (struct device *dev) +{ +return power_supply_get_drvdata (to_power_supply (dev)); +}
While skimming through the rest of the patch... This may just be my personal preference but wrapper functions with just one line are rarely beneficial. In the worst case they just add more lines AND hide the details of what actually is done without any clear benefits. Well, this is just my view so please ignore this comment if wrappers like this are a "subsystem standard"
Other than that the patch looks good to me.
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
Discuss - Estimate - Plan - Report and finally accomplish this:
void do_work(int time) __attribute__ ((const));
Re: [PATCH 2/2] power: supply: rt9471: Add Richtek RT9471 charger driver
Matti Vaittinen <[email protected]> 於 2022年8月15日 週一 下午1:53寫道:
Quoted 32 lines
Hi ChiYuan,
Thanks for the patch :)
to 11. elok. 2022 klo 16.43
cy_huang([email protected]) kirjoitti:Quoted 13 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.
Co-developed-by Alina Yu <[email protected]>Signed-off-by Alina Yu <[email protected]>Signed-off-by ChiYuan Huang <[email protected]>---
drivers/power/supply/rt9471.c line 120
Quoted 9 lines
drivers/power/supply/rt9471.c new file +9
-0+ +static const struct linear_range rt9471_chg_ranges[RT9471_MAX_RANGES ] = { + [RT9471_RANGE_AICR ] = {50000 ,1 ,63 ,50000 }, + [RT9471_RANGE_MIVR ] = {3900000 ,0 ,15 ,100000 }, + [RT9471_RANGE_IPRE ] = {50000 ,0 ,15 ,50000 }, + [RT9471_RANGE_VCHG ] = {3900000 ,0 ,80 ,10000 }, + [RT9471_RANGE_ICHG ] = {0 ,0 ,63 ,50000 }, + [RT9471_RANGE_IEOC ] = {50000 ,0 ,15 ,50000 }, +};I just jumped in to ask if that could you please use the field names? Eg.
{ .min = 50000, .min_sel = 1, .max_sel = 63, .step = 50000 },
Quoted 3 lines
This would make it less error prone in case someone changes the members in struct
linear_range.
Yes, sure, if something changed for this structure, this could be a problem. Thanks for the comment.
Quoted 120 lines
Quoted 107 lines
drivers/power/supply/rt9471.c new file +107
-0+ +static int rt9471_set_value_by_field_range (struct rt9471_chip *chip, +enum rt9471_fields field, +enum rt9471_ranges range,int val) +{ +unsigned int sel; + +if (val <0 ) +return -EINVAL ; + +linear_range_get_selector_within (rt9471_chg_ranges + range, val, &sel); + +return regmap_field_write (chip->rm_fields[field], sel); +} + + +static int rt9471_get_value_by_field_range (struct rt9471_chip *chip, +enum rt9471_fields field, +enum rt9471_ranges range,int *val) +{ +unsigned int sel, rvalue; +int ret; + + ret =regmap_field_read (chip->rm_fields[field], &sel); +if (ret) +return ret; + + ret =linear_range_get_value (rt9471_chg_ranges + range, sel, &rvalue); +if (ret) +return ret; + + *val = rvalue; +return 0 ; +} + +static inline int rt9471_set_hiz (struct rt9471_chip *chip,int enable) +{ +return regmap_field_write (chip->rm_fields[F_HZ ], enable); +} + +static inline int rt9471_set_ichg (struct rt9471_chip *chip,int microamp) +{ +return rt9471_set_value_by_field_range (chip,F_ICHG_REG , +RT9471_RANGE_ICHG , microamp); +} + +static inline int rt9471_get_ichg (struct rt9471_chip *chip,int *microamp) +{ +return rt9471_get_value_by_field_range (chip,F_ICHG_REG , +RT9471_RANGE_ICHG , microamp); +} + +static inline int rt9471_set_cv (struct rt9471_chip *chip,int microvolt) +{ +return rt9471_set_value_by_field_range (chip,F_VBAT_REG , +RT9471_RANGE_VCHG , microvolt); +} + +static inline int rt9471_get_cv (struct rt9471_chip *chip,int *microamp) +{ +return rt9471_get_value_by_field_range (chip,F_VBAT_REG , +RT9471_RANGE_VCHG , microamp); +} + +static inline int rt9471_set_mivr (struct rt9471_chip *chip,int microvolt) +{ +return rt9471_set_value_by_field_range (chip,F_MIVR , +RT9471_RANGE_MIVR , microvolt); +} + +static inline int rt9471_get_mivr (struct rt9471_chip *chip,int *microvolt) +{ +return rt9471_get_value_by_field_range (chip,F_MIVR , +RT9471_RANGE_MIVR , microvolt); +} + +static inline int rt9471_set_aicr (struct rt9471_chip *chip,int microamp) +{ +return rt9471_set_value_by_field_range (chip,F_AICR ,RT9471_RANGE_AICR , + microamp); +} + +static inline int rt9471_get_aicr (struct rt9471_chip *chip,int *microamp) +{ +return rt9471_get_value_by_field_range (chip,F_AICR ,RT9471_RANGE_AICR , + microamp); +} + +static inline int rt9471_set_iprechg (struct rt9471_chip *chip,int microamp) +{ +return rt9471_set_value_by_field_range (chip,F_IPRE_CHG , +RT9471_RANGE_IPRE , microamp); +} + +static inline int rt9471_get_iprechg (struct rt9471_chip *chip,int *microamp) +{ +return rt9471_get_value_by_field_range (chip,F_IPRE_CHG , +RT9471_RANGE_IPRE , microamp); +} + +static inline int rt9471_set_ieoc (struct rt9471_chip *chip,int microamp) +{ +return rt9471_set_value_by_field_range (chip,F_IEOC_CHG , +RT9471_RANGE_IEOC , microamp); +} + +static inline int rt9471_get_ieoc (struct rt9471_chip *chip,int *microamp)drivers/power/supply/rt9471.c line 237
Quoted 10 lines
drivers/power/supply/rt9471.c new file +10
-0+{ +return rt9471_get_value_by_field_range (chip,F_IEOC_CHG , +RT9471_RANGE_IEOC , microamp); +} + +static inline int rt9471_set_chg_enable (struct rt9471_chip *chip,int enable) +{ +return regmap_field_write (chip->rm_fields[F_CHG_EN ], !!enable); +} +//snip
Quoted 13 lines
drivers/power/supply/rt9471.c line 613
Quoted 5 lines
drivers/power/supply/rt9471.c new file +5
-0+ +static inline struct rt9471_chip *psy_device_to_chip (struct device *dev) +{ +return power_supply_get_drvdata (to_power_supply (dev)); +}While skimming through the rest of the patch... This may just be my personal preference but wrapper functions with just one line are rarely beneficial. In the worst case they just add more lines AND hide the details of what actually is done without any clear benefits. Well, this is just my view so please ignore this comment if wrappers like this are a "subsystem standard"
I'm not sure what the 'subsystem standard' is.
I declare it as 'inline' function and the function name to tell the user what I'm doing.
This may be silly. But from my aspect, it makes each property set/get more clear.
Quoted 12 lines
Other than that the patch looks good to me.
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland~~ When things go utterly wrong vim users can always type :help! ~~
Discuss - Estimate - Plan - Report and finally accomplish this:
voiddo_work(int time)__attribute__((const));
Re: [PATCH 2/2] power: supply: rt9471: Add Richtek RT9471 charger driver
ma 15. elok. 2022 klo 9.11 ChiYuan Huang ([email protected]) kirjoitti:
Quoted 29 lines
Matti Vaittinen <[email protected]> 於 2022年8月15日 週一 下午1:53寫道:
Quoted 20 lines
Hi ChiYuan,
Thanks for the patch :)
to 11. elok. 2022 klo 16.43
cy_huang([email protected]) kirjoitti:Quoted 5 lines
From: ChiYuan Huang <[email protected]>
Add support for the RT9471 3A 1-Cell Li+ battery charger.
Quoted 7 lines
The RT9471 is a highly-integrated 3A switch mode battery charger with low impedance power path to better optimize the charging efficiency.
Co-developed-by Alina Yu <[email protected]>Signed-off-by Alina Yu <[email protected]>Signed-off-by ChiYuan Huang <[email protected]>---
Quoted 7 lines
While skimming through the rest of the patch... This may just be my personal preference but wrapper functions with just one line are rarely beneficial. In the worst case they just add more lines AND hide the details of what actually is done without any clear benefits. Well, this is just my view so please ignore this comment if wrappers like this are a "subsystem standard"
Quoted 5 lines
I'm not sure what the 'subsystem standard' is.
I declare it as 'inline' function and the function name to tell the user what I'm doing.
This may be silly. But from my aspect, it makes each property set/get more clear.
I guess this is Ok if the maintainer does not complain. And if he does
- then we at least know the "subsystem standard" ;)
Yours
-- Matti
Signature · 5 lines
Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~