mbox series

[V3,00/15] Add Battery and USB Supply for AXP717

Message ID 20240819164619.556309-1-macroalpha82@gmail.com
Headers show
Series Add Battery and USB Supply for AXP717 | expand

Message

Chris Morgan Aug. 19, 2024, 4:46 p.m. UTC
From: Chris Morgan <macromorgan@hotmail.com>

Add support for monitoring the USB charger and battery charger on the
AXP717 PMIC. This required some driver refactoring of the axp20x USB
and battery charger as the AXP717 is somewhat different but can still
benefit from some common elements.

Note that as of now the charging current now value may be incorrect as
the scale and offsets were not documented in the datasheet. I suspect
the scale is 1 and the offset is somewhere around 450mA though.

Changes from V2:
 - Added constraints for input-current-limit-microamp constraints for
   x-powers,axp20x-usb-power-supply.yaml.
 - Used FIELD_GET() and removed unnecessary -EINVAL per comments from
   Jonathan Cameron.

Changes from V1:
 - Refactored against mainline to remove BOOST pre-requisite.
 - Corrected commit subjects for DT bindings.
 - Split refactoring and AXP717 support into different patches.
 - Added IRQ for VBUS over voltage. There appears to be a bug
   with the VBUS fault IRQ because it is assigned IRQ num 0.
 - Corrected battery driver to report POWER_SUPPLY_PROP_VOLTAGE_MIN
   and POWER_SUPPLY_PROP_VOLTAGE_MAX instead of *_DESIGN.

Chris Morgan (15):
  iio: adc: axp20x_adc: Add adc_en1 and adc_en1 to axp_data
  power: supply: axp20x_battery: Remove design from min and max voltage
  power: supply: axp20x_battery: Make iio and battery config per device
  power: supply: axp20x_usb_power: Make VBUS and IIO config per device
  dt-bindings: power: supply: axp20x: Add input-current-limit-microamp
  power: supply: axp20x_usb_power: add input-current-limit-microamp
  dt-bindings: power: supply: axp20x-battery: Add monitored-battery
  dt-bindings: iio: adc: Add AXP717 compatible
  dt-bindings: power: supply: axp20x: Add AXP717 compatible
  dt-bindings: power: supply: axp20x: Add AXP717 compatible
  mfd: axp20x: Add ADC, BAT, and USB cells for AXP717
  iio: adc: axp20x_adc: add support for AXP717 ADC
  power: supply: axp20x_usb_power: Add support for AXP717
  power: supply: axp20x_battery: add support for AXP717
  arm64: dts: allwinner: h700: Add charger for Anbernic RG35XX

 .../bindings/iio/adc/x-powers,axp209-adc.yaml |  12 +
 .../x-powers,axp20x-battery-power-supply.yaml |   7 +
 .../x-powers,axp20x-usb-power-supply.yaml     |  70 ++-
 .../sun50i-h700-anbernic-rg35xx-2024.dts      |  21 +
 drivers/iio/adc/axp20x_adc.c                  | 182 +++++-
 drivers/mfd/axp20x.c                          |  25 +-
 drivers/power/supply/axp20x_battery.c         | 590 ++++++++++++++++--
 drivers/power/supply/axp20x_usb_power.c       | 353 ++++++++++-
 include/linux/mfd/axp20x.h                    |  27 +
 9 files changed, 1186 insertions(+), 101 deletions(-)

Comments

Krzysztof Kozlowski Aug. 20, 2024, 7:42 a.m. UTC | #1
On Mon, Aug 19, 2024 at 11:46:09AM -0500, Chris Morgan wrote:
> From: Chris Morgan <macromorgan@hotmail.com>
> 
> Allow specifying a hard limit of the maximum input current. Some PMICs
> such as the AXP717 can pull up to 3.25A, so allow a value to be
> specified that clamps this in the event the hardware is not designed
> for it.
> 
> Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
> ---
>  .../x-powers,axp20x-usb-power-supply.yaml     | 69 ++++++++++++++++++-
>  1 file changed, 66 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
> index 34b7959d6772..9cc300e78f60 100644
> --- a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
> +++ b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
> @@ -15,9 +15,6 @@ maintainers:
>    - Chen-Yu Tsai <wens@csie.org>
>    - Sebastian Reichel <sre@kernel.org>
>  
> -allOf:
> -  - $ref: power-supply.yaml#
> -
>  properties:
>    compatible:
>      oneOf:
> @@ -31,8 +28,74 @@ properties:
>            - const: x-powers,axp803-usb-power-supply
>            - const: x-powers,axp813-usb-power-supply
>  
> +  input-current-limit-microamp:
> +    description:
> +      Optional value to clamp the maximum input current limit to for
> +      the device. If omitted, the programmed value from the EFUSE will
> +      be used.

minimum: 100000
maximum: 4000000
(or whatever the values are)

Best regards,
Krzysztof
Chris Morgan Aug. 20, 2024, 8:15 p.m. UTC | #2
On Tue, Aug 20, 2024 at 09:42:06AM +0200, Krzysztof Kozlowski wrote:
> On Mon, Aug 19, 2024 at 11:46:09AM -0500, Chris Morgan wrote:
> > From: Chris Morgan <macromorgan@hotmail.com>
> > 
> > Allow specifying a hard limit of the maximum input current. Some PMICs
> > such as the AXP717 can pull up to 3.25A, so allow a value to be
> > specified that clamps this in the event the hardware is not designed
> > for it.
> > 
> > Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
> > ---
> >  .../x-powers,axp20x-usb-power-supply.yaml     | 69 ++++++++++++++++++-
> >  1 file changed, 66 insertions(+), 3 deletions(-)
> > 
> > diff --git a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
> > index 34b7959d6772..9cc300e78f60 100644
> > --- a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
> > +++ b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
> > @@ -15,9 +15,6 @@ maintainers:
> >    - Chen-Yu Tsai <wens@csie.org>
> >    - Sebastian Reichel <sre@kernel.org>
> >  
> > -allOf:
> > -  - $ref: power-supply.yaml#
> > -
> >  properties:
> >    compatible:
> >      oneOf:
> > @@ -31,8 +28,74 @@ properties:
> >            - const: x-powers,axp803-usb-power-supply
> >            - const: x-powers,axp813-usb-power-supply
> >  
> > +  input-current-limit-microamp:
> > +    description:
> > +      Optional value to clamp the maximum input current limit to for
> > +      the device. If omitted, the programmed value from the EFUSE will
> > +      be used.
> 
> minimum: 100000
> maximum: 4000000
> (or whatever the values are)

It varies based on the compatible string. I've added all of the
restrictions below. Basically all but the axp717 have a table
of values available (as an enum), and the axp717 which is added
in a subsequent commit gets added as a minimum/maximum with a
description noting that steps are in values of 50000.

Thank you.

> 
> Best regards,
> Krzysztof
>
Krzysztof Kozlowski Aug. 21, 2024, 6:37 a.m. UTC | #3
On 20/08/2024 22:15, Chris Morgan wrote:
> On Tue, Aug 20, 2024 at 09:42:06AM +0200, Krzysztof Kozlowski wrote:
>> On Mon, Aug 19, 2024 at 11:46:09AM -0500, Chris Morgan wrote:
>>> From: Chris Morgan <macromorgan@hotmail.com>
>>>
>>> Allow specifying a hard limit of the maximum input current. Some PMICs
>>> such as the AXP717 can pull up to 3.25A, so allow a value to be
>>> specified that clamps this in the event the hardware is not designed
>>> for it.
>>>
>>> Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
>>> ---
>>>  .../x-powers,axp20x-usb-power-supply.yaml     | 69 ++++++++++++++++++-
>>>  1 file changed, 66 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
>>> index 34b7959d6772..9cc300e78f60 100644
>>> --- a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
>>> +++ b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
>>> @@ -15,9 +15,6 @@ maintainers:
>>>    - Chen-Yu Tsai <wens@csie.org>
>>>    - Sebastian Reichel <sre@kernel.org>
>>>  
>>> -allOf:
>>> -  - $ref: power-supply.yaml#
>>> -
>>>  properties:
>>>    compatible:
>>>      oneOf:
>>> @@ -31,8 +28,74 @@ properties:
>>>            - const: x-powers,axp803-usb-power-supply
>>>            - const: x-powers,axp813-usb-power-supply
>>>  
>>> +  input-current-limit-microamp:
>>> +    description:
>>> +      Optional value to clamp the maximum input current limit to for
>>> +      the device. If omitted, the programmed value from the EFUSE will
>>> +      be used.
>>
>> minimum: 100000
>> maximum: 4000000
>> (or whatever the values are)
> 
> It varies based on the compatible string. I've added all of the
> restrictions below. Basically all but the axp717 have a table
> of values available (as an enum), and the axp717 which is added
> in a subsequent commit gets added as a minimum/maximum with a
> description noting that steps are in values of 50000.

And you still need widest constraints here, because there is no final
"else" for all not-matched ifs, right?

Best regards,
Krzysztof
Chris Morgan Aug. 21, 2024, 8:15 p.m. UTC | #4
On Wed, Aug 21, 2024 at 08:37:59AM +0200, Krzysztof Kozlowski wrote:
> On 20/08/2024 22:15, Chris Morgan wrote:
> > On Tue, Aug 20, 2024 at 09:42:06AM +0200, Krzysztof Kozlowski wrote:
> >> On Mon, Aug 19, 2024 at 11:46:09AM -0500, Chris Morgan wrote:
> >>> From: Chris Morgan <macromorgan@hotmail.com>
> >>>
> >>> Allow specifying a hard limit of the maximum input current. Some PMICs
> >>> such as the AXP717 can pull up to 3.25A, so allow a value to be
> >>> specified that clamps this in the event the hardware is not designed
> >>> for it.
> >>>
> >>> Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
> >>> ---
> >>>  .../x-powers,axp20x-usb-power-supply.yaml     | 69 ++++++++++++++++++-
> >>>  1 file changed, 66 insertions(+), 3 deletions(-)
> >>>
> >>> diff --git a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
> >>> index 34b7959d6772..9cc300e78f60 100644
> >>> --- a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
> >>> +++ b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml
> >>> @@ -15,9 +15,6 @@ maintainers:
> >>>    - Chen-Yu Tsai <wens@csie.org>
> >>>    - Sebastian Reichel <sre@kernel.org>
> >>>  
> >>> -allOf:
> >>> -  - $ref: power-supply.yaml#
> >>> -
> >>>  properties:
> >>>    compatible:
> >>>      oneOf:
> >>> @@ -31,8 +28,74 @@ properties:
> >>>            - const: x-powers,axp803-usb-power-supply
> >>>            - const: x-powers,axp813-usb-power-supply
> >>>  
> >>> +  input-current-limit-microamp:
> >>> +    description:
> >>> +      Optional value to clamp the maximum input current limit to for
> >>> +      the device. If omitted, the programmed value from the EFUSE will
> >>> +      be used.
> >>
> >> minimum: 100000
> >> maximum: 4000000
> >> (or whatever the values are)
> > 
> > It varies based on the compatible string. I've added all of the
> > restrictions below. Basically all but the axp717 have a table
> > of values available (as an enum), and the axp717 which is added
> > in a subsequent commit gets added as a minimum/maximum with a
> > description noting that steps are in values of 50000.
> 
> And you still need widest constraints here, because there is no final
> "else" for all not-matched ifs, right?
> 
> Best regards,
> Krzysztof
> 

That makes sense, thank you.
Chris