Add support for AXP192 PMIC
Subsystems (10)
v3 cover Add support for AXP192 PMIC
Changes in v3:
* Update pinctrl driver to address Andy Shevchenko's review comments from v1, and fix a few other issues.
* Add gpio-ranges property and example snippet to gpio DT bindings.
* Update commit message of patch 01/16 to point out that all register addresses are obtained using sub_irq_reg().
* Document ccc_table in axp20x_battery. Also update commit message to note a small fix that is part of that patch.
* Drop axp20x_adc consolidation patch in favor of using separate adc_raw functions. It's a minor code size optimization that may not be worth the effort due to implementation complexity.
* Use the FIELD_GET macro in axp20x_adc to further clarify intent.
* Fix a typo in the regulator driver where an AXP20X regulator ID was mistakenly used instead of an AXP192 regulator ID. Also carry over an Acked-by: tag from v1. Hope that's okay.
* Accumulate Acked-by: tags from v1 on DT patches.
* Accumulate Acked-by: tags from v2.
Note that regmap maintainer Mark Brown has said the first two patches to regmap-irq aren't suitable for inclusion into the kernel in their current state. I'm including them for v3 so the series remains testable.
Changes in v2:
* Do a little cleanup of axp20x_adc suggested by Jonathan Cameron
* Consolidate ADC read functions in axp20x_adc
* Drop the axp192's read_label callback in axp20x_adc
* Clean up the axp192-gpio dt bindings
* Rewrite a problematic bit of code in axp20x_usb_power reported by kernel test robot
* Support AXP192 in axp20x_battery
* Split up regmap-irq changes to two separate patches
Cover letter from v1:
Hi all,
This patch series adds support for the X-Powers AXP192 PMIC to the AXP20x driver framework.
The first patch is a small change to regmap-irq to support the AXP192's unusual IRQ register layout. It isn't possible to include all of the IRQ registers in one regmap-irq chip without this.
The rest of the changes are pretty straightforward, I think the only notable parts are the axp20x_adc driver where there seems to be some opportunities for code reuse (the axp192 is nearly a duplicate of the axp20x) and the addition of a new pinctrl driver for the axp192, since the axp20x pinctrl driver was not very easy to adapt.
Aidan MacDonald (16):
regmap-irq: Use sub_irq_reg() to calculate unmask register address
regmap-irq: Add get_irq_reg to support unusual register layouts
dt-bindings: mfd: add bindings for AXP192 MFD device
dt-bindings: iio: adc: axp209: Add AXP192 compatible
dt-bindings: power: supply: axp20x: Add AXP192 compatible
dt-bindings: gpio: Add AXP192 GPIO bindings
dt-bindings: power: axp20x-battery: Add AXP192 compatible
mfd: axp20x: Add support for AXP192
regulator: axp20x: Add support for AXP192
iio: adc: axp20x_adc: Minor code cleanups
iio: adc: axp20x_adc: Add support for AXP192
power: supply: axp20x_usb_power: Add support for AXP192
pinctrl: Add AXP192 pin control driver
power: axp20x_battery: Add constant charge current table
power: axp20x_battery: Support battery status without fuel gauge
power: axp20x_battery: Add support for AXP192
.../bindings/gpio/x-powers,axp192-gpio.yaml | 68 +++ .../bindings/iio/adc/x-powers,axp209-adc.yaml | 18 + .../bindings/mfd/x-powers,axp152.yaml | 1 + .../x-powers,axp20x-battery-power-supply.yaml | 1 + .../x-powers,axp20x-usb-power-supply.yaml | 1 + drivers/base/regmap/regmap-irq.c | 19 +- drivers/iio/adc/axp20x_adc.c | 359 +++++++++-- drivers/mfd/axp20x-i2c.c | 2 + drivers/mfd/axp20x.c | 153 +++++ drivers/pinctrl/Kconfig | 14 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-axp192.c | 562 ++++++++++++++++++ drivers/power/supply/axp20x_battery.c | 143 ++++- drivers/power/supply/axp20x_usb_power.c | 80 ++- drivers/regulator/axp20x-regulator.c | 101 +++- include/linux/mfd/axp20x.h | 84 +++ include/linux/regmap.h | 5 + 17 files changed, 1529 insertions(+), 83 deletions(-) create mode 100644 Documentation/devicetree/bindings/gpio/x-powers,axp192-gpio.yaml create mode 100644 drivers/pinctrl/pinctrl-axp192.c
Signature · 1 line
2.35.1
PATCH v3 1/16 regmap-irq: Use sub_irq_reg() to calculate unmask register address
Call sub_irq_reg() instead of calculating the offset of the register to avoid relying on the fact that sub_irq_reg() is a linear function of "base_reg" and "i".
Unmask registers were the only type that didn't use sub_irq_reg() for address calculation; thus, sub_irq_reg() is now the only method used to obtain register addresses.
This prepares for allowing drivers to override the default sub_irq_reg implementation if the default behavior is unsuitable.
--- drivers/base/regmap/regmap-irq.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/base/regmap/regmap-irq.c +5 -8
@@ -97,7 +97,6 @@ static void regmap_irq_sync_unlock(struct irq_data *data)struct regmap *map = d->map;int i, j, ret;u32 reg; -u32 unmask_offset;u32 val;if (d->chip->runtime_pm) {
@@ -141,11 +140,11 @@ static void regmap_irq_sync_unlock(struct irq_data *data)dev_err (d->map->dev,"Failed to sync unmasks in %x\n" , reg); - unmask_offset = d->chip->unmask_base - - d->chip->mask_base; +/* clear mask with unmask_base register */ + reg =sub_irq_reg (d, d->chip->unmask_base, i); ret =regmap_irq_update_bits (d, - reg + unmask_offset, + reg, d->mask_buf_def[i], d->mask_buf[i]); }else {
@@ -632,7 +631,6 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,int ret = -ENOMEM ;int num_type_reg;u32 reg; -u32 unmask_offset;if (chip->num_regs <=0 )return -EINVAL ;
@@ -773,10 +771,9 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode, ret =regmap_irq_update_bits (d, reg, d->mask_buf[i], ~d->mask_buf[i]); else if (d->chip->unmask_base) { - unmask_offset = d->chip->unmask_base - - d->chip->mask_base; + reg =sub_irq_reg (d, d->chip->unmask_base, i); ret =regmap_irq_update_bits (d, - reg + unmask_offset, + reg, d->mask_buf[i], d->mask_buf[i]); } else
Signature · 1 line
2.35.1
PATCH v3 2/16 regmap-irq: Add get_irq_reg to support unusual register layouts
In reply to Aidan MacDonaldAdd a new callback, get_irq_reg, for regmap IRQ chips, to support devices with unusual register layouts. This is required in the rare cases where the offset of an IRQ register is not constant with respect to the base register. This is probably best illustrated with an example (taken from the AXP192 PMIC):
mask status
IRQ0 0x40 0x44
IRQ1 0x41 0x45
IRQ2 0x42 0x46
IRQ3 0x43 0x47
IRQ4 0x4a 0x4dIf we set mask_base = 0x40 and status_base = 0x44, the offsets of each register relative to the base are:
mask status
IRQ0 0 0
IRQ1 1 1
IRQ2 2 2
IRQ3 3 3
IRQ4 10 9The existing mapping mechanisms can't include IRQ4 in the same irqchip as IRQ0-3 because the offset of IRQ4's register depends on which type of register we're asking for, ie. which base register is used.
The get_irq_reg callback allows drivers to specify an arbitrary mapping of (base register, register index) pairs to register addresses, instead of the default linear mapping "base_register + register_index". This allows unusual layouts, like the one above, to be handled using a single regmap IRQ chip.
The drawback is that when get_irq_reg is used, it's impossible to use bulk reads for status registers even if some of them are contiguous, because the mapping is opaque to regmap-irq. This should be acceptable for the case of a few infrequently-polled status registers.
--- drivers/base/regmap/regmap-irq.c | 6 ++++-- include/linux/regmap.h | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-)
drivers/base/regmap/regmap-irq.c +4 -2
@@ -55,7 +55,9 @@ static int sub_irq_reg(struct regmap_irq_chip_data *data,unsigned int offset;int reg =0 ; -if (!chip->sub_reg_offsets || !chip->not_fixed_stride) { +if (chip->get_irq_reg) { + reg = chip->get_irq_reg (base_reg, i); + }else if (!chip->sub_reg_offsets || !chip->not_fixed_stride) {/* Assume linear mapping */ reg = base_reg + (i * map->reg_stride * data->irq_reg_stride); }else {
@@ -479,7 +481,7 @@ static irqreturn_t regmap_irq_thread(int irq, void *d) } }else if (!map->use_single_read && map->reg_stride ==1 && - data->irq_reg_stride ==1 ) { + data->irq_reg_stride ==1 && !chip->get_irq_reg) {u8 *buf8 = data->status_reg_buf;u16 *buf16 = data->status_reg_buf;
include/linux/regmap.h +5 -0
@@ -1495,6 +1495,10 @@ struct regmap_irq_sub_irq_map {* after handling the interrupts in regmap_irq_handler(). * @set_type_virt: Driver specific callback to extend regmap_irq_set_type() * and configure virt regs. +* @get_irq_reg: Callback to map a register index in range [0, num_regs[ +* to a register, relative to a specific base register. This +* is mainly useful for devices where the register offsets +* change depending on the base register. * @irq_drv_data: Driver specific IRQ data which is passed as parameter when * driver specific pre/post interrupt handler is called. *
@@ -1545,6 +1549,7 @@ struct regmap_irq_chip {int (*handle_post_irq)(void *irq_drv_data);int (*set_type_virt)(unsigned int **buf,unsigned int type,unsigned long hwirq,int reg); +int (*get_irq_reg)(unsigned int base_reg,int i);void *irq_drv_data; };
Signature · 1 line
2.35.1
PATCH v3 3/16 dt-bindings: mfd: add bindings for AXP192 MFD device
In reply to Aidan MacDonaldThe AXP192 is another X-Powers PMIC similar to the existing ones.
--- Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml +1 -0
@@ -84,6 +84,7 @@ properties: oneOf: - enum: - x-powers,axp152 + - x-powers,axp192 - x-powers,axp202 - x-powers,axp209 - x-powers,axp221
Signature · 1 line
2.35.1
Re: [PATCH v3 03/16] dt-bindings: mfd: add bindings for AXP192 MFD device
Quoted 5 lines · Aidan MacDonald
The AXP192 is another X-Powers PMIC similar to the existing ones.
Acked-by Rob Herring <[email protected]>Signed-off-by Aidan MacDonald <[email protected]>
PATCH v3 4/16 dt-bindings: iio: adc: axp209: Add AXP192 compatible
In reply to Aidan MacDonaldThe AXP192 is identical to the AXP20x, except for two additional GPIO ADC channels.
--- .../bindings/iio/adc/x-powers,axp209-adc.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml +18 -0
@@ -14,6 +14,23 @@ description: | Device is a child of an axp209 multifunction device ADC channels and their indexes per variant: + AXP192 + ------ + 0 | acin_v + 1 | acin_i + 2 | vbus_v + 3 | vbus_i + 4 | pmic_temp + 5 | gpio0_v + 6 | gpio1_v + 7 | gpio2_v + 8 | gpio3_v + 9 | ipsout_v + 10 | batt_v + 11 | batt_chrg_i + 12 | batt_dischrg_i + 13 | ts_v + AXP209 ------ 0 | acin_v
@@ -50,6 +67,7 @@ description: | properties: compatible: oneOf: + - const: x-powers,axp192-adc - const: x-powers,axp209-adc - const: x-powers,axp221-adc - const: x-powers,axp813-adc
Signature · 1 line
2.35.1
Re: [PATCH v3 04/16] dt-bindings: iio: adc: axp209: Add AXP192 compatible
Quoted 6 lines · Aidan MacDonald
The AXP192 is identical to the AXP20x, except for two additional GPIO ADC channels.
Acked-by Rob Herring <[email protected]>Signed-off-by Aidan MacDonald <[email protected]>
PATCH v3 5/16 dt-bindings: power: supply: axp20x: Add AXP192 compatible
In reply to Aidan MacDonaldThe AXP192's USB power supply is similar to the AXP202 but it has different USB current limits.
--- .../bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml +1 -0
@@ -22,6 +22,7 @@ properties: compatible: oneOf: - enum: + - x-powers,axp192-usb-power-supply - x-powers,axp202-usb-power-supply - x-powers,axp221-usb-power-supply - x-powers,axp223-usb-power-supply
Signature · 1 line
2.35.1
Re: [PATCH v3 05/16] dt-bindings: power: supply: axp20x: Add AXP192 compatible
Quoted 3 lines · Aidan MacDonald
The AXP192's USB power supply is similar to the AXP202 but it has different USB current limits.
Should also mention the different register offset for VBUS status.
ChenYu
Quoted 22 lines
Acked-by Rob Herring <[email protected]>Signed-off-by Aidan MacDonald <[email protected]>--- .../bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml +1
-1@@ -22,6 +22,7 @@ properties: compatible: oneOf: - enum: + - x-powers,axp192-usb-power-supply - x-powers,axp202-usb-power-supply - x-powers,axp221-usb-power-supply - x-powers,axp223-usb-power-supply --2.35.1
PATCH v3 6/16 dt-bindings: gpio: Add AXP192 GPIO bindings
In reply to Aidan MacDonaldThe AXP192 PMIC is different enough from the PMICs supported by the AXP20x GPIO driver to warrant a separate driver. The AXP192 driver also supports interrupts and pinconf settings.
--- .../bindings/gpio/x-powers,axp192-gpio.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/x-powers,axp192-gpio.yaml
Documentation/devicetree/bindings/gpio/x-powers,axp192-gpio.yaml new file +68 -0
@@ -0,0 +1,68 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/gpio/x-powers,axp192-gpio.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: X-Powers AXP192 GPIO Device Tree Bindings + +maintainers: + - Chen-Yu Tsai <[email protected]> + +properties: + compatible: + const: x-powers,axp192-gpio + + gpio-controller: true + + "#gpio-cells": + const: 2 + description: > + The first cell is the pin number and the second is the GPIO flags. + + gpio-ranges: + maxItems: 1 + +patternProperties: + "-pins$": + $ref: /schemas/pinctrl/pinmux-node.yaml# + + properties: + pins: + items: + enum: + - GPIO0 + - GPIO1 + - GPIO2 + - GPIO3 + - GPIO4 + - N_RSTO + + function: + enum: + - output + - input + - ldo + - pwm + - adc + - low_output + - floating + - ext_chg_ctl + - ldo_status + +required: + - compatible + - "#gpio-cells" + - gpio-controller + - gpio-ranges + +additionalProperties: false + +examples: + - | + pinctrl0: gpio@0 { + compatible = "x-powers,axp192-gpio"; + gpio-controller; + #gpio-cells = <2>; + gpio-ranges = <&pinctrl0 0 0 6>; + };
Signature · 1 line
2.35.1
Re: [PATCH v3 06/16] dt-bindings: gpio: Add AXP192 GPIO bindings
Quoted 69 lines · Aidan MacDonald
The AXP192 PMIC is different enough from the PMICs supported by the AXP20x GPIO driver to warrant a separate driver. The AXP192 driver also supports interrupts and pinconf settings.
Signed-off-by Aidan MacDonald <[email protected]>--- .../bindings/gpio/x-powers,axp192-gpio.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/x-powers,axp192-gpio.yamlDocumentation/devicetree/bindings/gpio/x-powers,axp192-gpio.yaml new file +53
-0@@ -0,0 +1,68 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/gpio/x-powers,axp192-gpio.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: X-Powers AXP192 GPIO Device Tree Bindings + +maintainers: + - Chen-Yu Tsai <[email protected]> + +properties: + compatible: + const: x-powers,axp192-gpio + + gpio-controller: true + + "#gpio-cells": + const: 2 + description: > + The first cell is the pin number and the second is the GPIO flags. + + gpio-ranges: + maxItems: 1 + +patternProperties: + "-pins$": + $ref: /schemas/pinctrl/pinmux-node.yaml# + + properties: + pins: + items: + enum: + - GPIO0 + - GPIO1 + - GPIO2 + - GPIO3 + - GPIO4 + - N_RSTO + + function: + enum: + - output + - input + - ldo + - pwm + - adc + - low_output + - floating + - ext_chg_ctl + - ldo_status + +required:
Documentation/devicetree/bindings/gpio/x-powers,axp192-gpio.yaml line 63
Quoted 10 lines
Documentation/devicetree/bindings/gpio/x-powers,axp192-gpio.yaml new file +10
-0+ - compatible + - "#gpio-cells" + - gpio-controller + - gpio-ranges + +additionalProperties: false + +examples: + - | + pinctrl0: gpio@0 {
Unit address without reg, that's not a valid DTS.
Documentation/devicetree/bindings/gpio/x-powers,axp192-gpio.yaml line 68
Quoted 5 lines
Documentation/devicetree/bindings/gpio/x-powers,axp192-gpio.yaml new file +5
-0+ compatible = "x-powers,axp192-gpio"; + gpio-controller; + #gpio-cells = <2>; + gpio-ranges = <&pinctrl0 0 0 6>; + };
Best regards,
Krzysztof
Rob Herring
maintainerRe: [PATCH v3 06/16] dt-bindings: gpio: Add AXP192 GPIO bindings
In reply to Aidan MacDonaldQuoted 10 lines · Aidan MacDonald
The AXP192 PMIC is different enough from the PMICs supported by the AXP20x GPIO driver to warrant a separate driver. The AXP192 driver also supports interrupts and pinconf settings.
Signed-off-by Aidan MacDonald <[email protected]>--- .../bindings/gpio/x-powers,axp192-gpio.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/x-powers,axp192-gpio.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:
Documentation/devicetree/bindings/gpio/x-powers,axp192-gpio.example.dts:18.26-23.11: Warning (unit_address_vs_reg): /example-0/gpio@0: node has a unit name, but no reg or ranges property
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.
PATCH v3 7/16 dt-bindings: power: axp20x-battery: Add AXP192 compatible
In reply to Aidan MacDonaldThe AXP192's battery charger is similar to the others supported by the axp20x_battery driver.
--- .../power/supply/x-powers,axp20x-battery-power-supply.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml +1 -0
@@ -20,6 +20,7 @@ allOf: properties: compatible: oneOf: + - const: x-powers,axp192-battery-power-supply - const: x-powers,axp202-battery-power-supply - const: x-powers,axp209-battery-power-supply - const: x-powers,axp221-battery-power-supply
Signature · 1 line
2.35.1
PATCH v3 8/16 mfd: axp20x: Add support for AXP192
In reply to Aidan MacDonaldThe AXP192 PMIC is similar to the AXP202/AXP209, but with different regulators, additional GPIOs, and a different IRQ register layout.
--- drivers/mfd/axp20x-i2c.c | 2 + drivers/mfd/axp20x.c | 153 +++++++++++++++++++++++++++++++++++++ include/linux/mfd/axp20x.h | 84 ++++++++++++++++++++ 3 files changed, 239 insertions(+)
drivers/mfd/axp20x-i2c.c +2 -0
@@ -62,6 +62,7 @@ static int axp20x_i2c_remove(struct i2c_client *i2c)#ifdef CONFIG_OF static const struct of_device_id axp20x_i2c_of_match[] = { { .compatible ="x-powers,axp152" , .data = (void *)AXP152_ID }, + { .compatible ="x-powers,axp192" , .data = (void *)AXP192_ID }, { .compatible ="x-powers,axp202" , .data = (void *)AXP202_ID }, { .compatible ="x-powers,axp209" , .data = (void *)AXP209_ID }, { .compatible = "x-powers,axp221", .data = (void *)AXP221_ID },
@@ -75,6 +76,7 @@ MODULE_DEVICE_TABLE(of, axp20x_i2c_of_match);static const struct i2c_device_id axp20x_i2c_id[] = { {"axp152" ,0 }, + {"axp192" ,0 }, {"axp202" ,0 }, {"axp209" ,0 }, {"axp221" ,0 },
drivers/mfd/axp20x.c +153 -0
201 lines not on this page · raw message
include/linux/mfd/axp20x.h +84 -0
138 lines not on this page · raw message
Signature · 1 line
2.35.1
Re: [PATCH v3 08/16] mfd: axp20x: Add support for AXP192
Quoted 3 lines · Aidan MacDonald
The AXP192 PMIC is similar to the AXP202/AXP209, but with different regulators, additional GPIOs, and a different IRQ register layout.
...
drivers/mfd/axp20x.c static const struct regmap_irq axp152_regmap_irqs[] = { · line 410
Quoted 11 lines
drivers/mfd/axp20x.c +10
-0+static int axp192_get_irq_reg (unsigned int base_reg,int i) +{ +/* linear mapping for IRQ1 to IRQ4 */ +if (i <4 ) +return base_reg + i; + +/* handle IRQ5 separately */ +if (base_reg ==AXP192_IRQ1_EN ) +return AXP192_IRQ5_EN ; +else
Redundant 'else'.
Quoted 2 lines
drivers/mfd/axp20x.c +2
-0+return AXP192_IRQ5_STATE ; +}
...
include/linux/mfd/axp20x.h enum axp20x_variants { · line 335
Quoted 10 lines
include/linux/mfd/axp20x.h +9
-0+enum { +AXP192_DCDC1 =0 , +AXP192_DCDC2 , +AXP192_DCDC3 , +AXP192_LDO1 , +AXP192_LDO2 , +AXP192_LDO3 , +AXP192_LDO_IO0 , +AXP192_REG_ID_MAX ,
Comma is not needed for a terminator.
Quoted 1 line
+};
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 9/16 regulator: axp20x: Add support for AXP192
In reply to Aidan MacDonaldAdd support for the AXP192 PMIC.
--- drivers/regulator/axp20x-regulator.c | 101 ++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 9 deletions(-)
drivers/regulator/axp20x-regulator.c +92 -9
@@ -27,6 +27,29 @@#include <linux/regulator/machine.h> #include <linux/regulator/of_regulator.h> +#define AXP192_GPIO0_FUNC_MASK GENMASK(2, 0) + +#define AXP192_IO_ENABLED 0x02 +#define AXP192_IO_DISABLED 0x06 + +#define AXP192_WORKMODE_DCDC1_MASK BIT_MASK(3) +#define AXP192_WORKMODE_DCDC2_MASK BIT_MASK(2) +#define AXP192_WORKMODE_DCDC3_MASK BIT_MASK(1) + +#define AXP192_DCDC1_V_OUT_MASK GENMASK(6, 0) +#define AXP192_DCDC2_V_OUT_MASK GENMASK(5, 0) +#define AXP192_DCDC3_V_OUT_MASK GENMASK(6, 0) +#define AXP192_LDO2_V_OUT_MASK GENMASK(7, 4) +#define AXP192_LDO3_V_OUT_MASK GENMASK(3, 0) +#define AXP192_LDO_IO0_V_OUT_MASK GENMASK(7, 4) + +#define AXP192_PWR_OUT_EXTEN_MASK BIT_MASK(6) +#define AXP192_PWR_OUT_DCDC2_MASK BIT_MASK(4) +#define AXP192_PWR_OUT_LDO3_MASK BIT_MASK(3) +#define AXP192_PWR_OUT_LDO2_MASK BIT_MASK(2) +#define AXP192_PWR_OUT_DCDC3_MASK BIT_MASK(1) +#define AXP192_PWR_OUT_DCDC1_MASK BIT_MASK(0) +#define AXP20X_GPIO0_FUNC_MASK GENMASK(3, 0)#define AXP20X_GPIO1_FUNC_MASK GENMASK(3, 0)
@@ -375,25 +398,32 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)switch (axp20x->variant) {case AXP209_ID : -if (id ==AXP20X_DCDC2 ) { +if (id ==AXP20X_LDO3 ) { slew_rates = axp209_dcdc2_ldo3_slew_rates; rate_count =ARRAY_SIZE (axp209_dcdc2_ldo3_slew_rates); reg =AXP20X_DCDC2_LDO3_V_RAMP ; - mask =AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE_MASK | -AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN_MASK ; + mask =AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE_MASK | +AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN_MASK ; enable = (ramp >0 ) ? -AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN :0 ; +AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN :0 ;break ; } -if (id ==AXP20X_LDO3 ) { + fallthrough; + +case AXP192_ID : +/* +* AXP192 and AXP209 share the same DCDC2 ramp configuration +*/ +if ((axp20x->variant ==AXP209_ID && id ==AXP20X_DCDC2 ) || + (axp20x->variant ==AXP192_ID && id ==AXP192_DCDC2 )) { slew_rates = axp209_dcdc2_ldo3_slew_rates; rate_count =ARRAY_SIZE (axp209_dcdc2_ldo3_slew_rates); reg =AXP20X_DCDC2_LDO3_V_RAMP ; - mask =AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE_MASK | -AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN_MASK ; + mask =AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE_MASK | +AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN_MASK ; enable = (ramp >0 ) ? -AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN :0 ; +AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN :0 ;break ; }
@@ -401,6 +431,7 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)break ; fallthrough; +default :/* Not supported for this regulator */ return -ENOTSUPP ;
@@ -415,7 +446,8 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)if (ramp > slew_rates[i])break ; -if (id ==AXP20X_DCDC2 ) +if ((axp20x->variant ==AXP209_ID && id ==AXP20X_DCDC2 ) || + (axp20x->variant ==AXP192_ID && id ==AXP192_DCDC2 )) cfg =AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE (i);else cfg =AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE (i);
@@ -511,6 +543,29 @@ static const struct regulator_ops axp20x_ops_sw = { .is_enabled = regulator_is_enabled_regmap, }; +static const struct regulator_desc axp192_regulators[] = { +AXP_DESC (AXP192 ,DCDC1 ,"dcdc1" ,"vin1" ,700 ,3500 ,25 , +AXP192_DCDC1_V_OUT ,AXP192_DCDC1_V_OUT_MASK , +AXP192_PWR_OUT_CTRL ,AXP192_PWR_OUT_DCDC1_MASK ), +AXP_DESC (AXP192 ,DCDC2 ,"dcdc2" ,"vin2" ,700 ,2275 ,25 , +AXP192_DCDC2_V_OUT ,AXP192_DCDC2_V_OUT_MASK , +AXP192_PWR_OUT_CTRL ,AXP192_PWR_OUT_DCDC2_MASK ), +AXP_DESC (AXP192 ,DCDC3 ,"dcdc3" ,"vin3" ,700 ,3500 ,25 , +AXP192_DCDC3_V_OUT ,AXP192_DCDC3_V_OUT_MASK , +AXP192_PWR_OUT_CTRL ,AXP192_PWR_OUT_DCDC3_MASK ), +AXP_DESC_FIXED (AXP192 ,LDO1 ,"ldo1" ,"acin" ,1250 ), +AXP_DESC (AXP192 ,LDO2 ,"ldo2" ,"ldoin" ,1800 ,3300 ,100 , +AXP192_LDO2_3_V_OUT ,AXP192_LDO2_V_OUT_MASK , +AXP192_PWR_OUT_CTRL ,AXP192_PWR_OUT_LDO2_MASK ), +AXP_DESC (AXP192 ,LDO3 ,"ldo3" ,"ldoin" ,1800 ,3300 ,100 , +AXP192_LDO2_3_V_OUT ,AXP192_LDO3_V_OUT_MASK , +AXP192_PWR_OUT_CTRL ,AXP192_PWR_OUT_LDO3_MASK ), +AXP_DESC_IO (AXP192 ,LDO_IO0 ,"ldo_io0" ,"ips" ,700 ,3300 ,100 , +AXP192_LDO_IO0_V_OUT ,AXP192_LDO_IO0_V_OUT_MASK , +AXP192_GPIO0_CTRL ,AXP192_GPIO0_FUNC_MASK , +AXP192_IO_ENABLED ,AXP192_IO_DISABLED ), +}; +static const struct linear_range axp20x_ldo4_ranges[] = { REGULATOR_LINEAR_RANGE(1250000, AXP20X_LDO4_V_OUT_1250mV_START,
@@ -1008,6 +1063,12 @@ static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq)u32 min, max, def, step;switch (axp20x->variant) { +case AXP192_ID : + min =900 ; + max =2025 ; + def =1500 ; + step =75 ; +break ;case AXP202_ID :case AXP209_ID : min =750 ;
@@ -1100,6 +1161,24 @@ static int axp20x_set_dcdc_workmode(struct regulator_dev *rdev, int id, u32 workunsigned int mask;switch (axp20x->variant) { +case AXP192_ID : +switch (id) { +case AXP192_DCDC1 : + mask =AXP192_WORKMODE_DCDC1_MASK ; +break ; +case AXP192_DCDC2 : + mask =AXP192_WORKMODE_DCDC2_MASK ; +break ; +case AXP192_DCDC3 : + mask =AXP192_WORKMODE_DCDC3_MASK ; +break ; +default : +return -EINVAL ; + } + + workmode <<=ffs (mask) -1 ; +break ; +case AXP202_ID :case AXP209_ID :if ((id !=AXP20X_DCDC2 ) && (id !=AXP20X_DCDC3 ))
@@ -1220,6 +1299,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev)bool drivevbus = false;switch (axp20x->variant) { +case AXP192_ID : + regulators = axp192_regulators; + nregulators =AXP192_REG_ID_MAX ; +break ;case AXP202_ID :case AXP209_ID : regulators = axp20x_regulators;
Signature · 1 line
2.35.1
Re: [PATCH v3 09/16] regulator: axp20x: Add support for AXP192
Quoted 2 lines · Aidan MacDonald
Add support for the AXP192 PMIC.
...
drivers/regulator/axp20x-regulator.c static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp) · line 437
Quoted 8 lines
drivers/regulator/axp20x-regulator.c +1
-0@@ -401,6 +431,7 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)break ; fallthrough; +default :/* Not supported for this regulator */ return -ENOTSUPP ;
Stray change?
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 10/16 iio: adc: axp20x_adc: Minor code cleanups
In reply to Aidan MacDonaldThe code may be clearer if parameters are not re-purposed to hold temporary results like register values, so introduce local variables as necessary to avoid that. Also, use the common FIELD_PREP macro instead of a hand-rolled version.
--- drivers/iio/adc/axp20x_adc.c | 61 +++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 28 deletions(-)
drivers/iio/adc/axp20x_adc.c +33 -28
@@ -15,6 +15,7 @@#include <linux/property.h> #include <linux/regmap.h> #include <linux/thermal.h> +#include <linux/bitfield.h> #include <linux/iio/iio.h> #include <linux/iio/driver.h>
@@ -22,20 +23,20 @@#include <linux/mfd/axp20x.h> #define AXP20X_ADC_EN1_MASK GENMASK(7, 0) -#define AXP20X_ADC_EN2_MASK (GENMASK(3, 2) | BIT(7)) +#define AXP22X_ADC_EN1_MASK (GENMASK(7, 5) | BIT(0))#define AXP20X_GPIO10_IN_RANGE_GPIO0 BIT(0)#define AXP20X_GPIO10_IN_RANGE_GPIO1 BIT(1) -#define AXP20X_GPIO10_IN_RANGE_GPIO0_VAL (x) ((x) & BIT(0)) -#define AXP20X_GPIO10_IN_RANGE_GPIO1_VAL (x) (((x) & BIT(0)) << 1)#define AXP20X_ADC_RATE_MASK GENMASK(7, 6) -#define AXP813_V_I_ADC_RATE_MASK GENMASK(5, 4) -#define AXP813_ADC_RATE_MASK (AXP20X_ADC_RATE_MASK | AXP813_V_I_ADC_RATE_MASK)#define AXP20X_ADC_RATE_HZ (x) ((ilog2((x) / 25) << 6) & AXP20X_ADC_RATE_MASK) +#define AXP22X_ADC_RATE_HZ (x) ((ilog2((x) / 100) << 6) & AXP20X_ADC_RATE_MASK) + +#define AXP813_V_I_ADC_RATE_MASK GENMASK(5, 4) +#define AXP813_ADC_RATE_MASK (AXP20X_ADC_RATE_MASK | AXP813_V_I_ADC_RATE_MASK)#define AXP813_TS_GPIO0_ADC_RATE_HZ (x) AXP20X_ADC_RATE_HZ(x)#define AXP813_V_I_ADC_RATE_HZ (x) ((ilog2((x) / 100) << 4) & AXP813_V_I_ADC_RATE_MASK)#define AXP813_ADC_RATE_HZ (x) (AXP20X_ADC_RATE_HZ(x) | AXP813_V_I_ADC_RATE_HZ(x))
@@ -234,7 +235,7 @@ static int axp20x_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { struct axp20x_adc_iio *info = iio_priv(indio_dev); -int size =12 ; +int ret, size;/* * N.B.: Unlike the Chinese datasheets tell, the charging current is
@@ -246,10 +247,11 @@ static int axp20x_adc_raw(struct iio_dev *indio_dev,else size =12 ; - *val =axp20x_read_variable_width (info->regmap, chan->address, size); -if (*val <0 ) -return *val; + ret =axp20x_read_variable_width (info->regmap, chan->address, size); +if (ret <0 ) +return ret; + *val = ret;return IIO_VAL_INT ; }
@@ -257,11 +259,13 @@ static int axp22x_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { struct axp20x_adc_iio *info = iio_priv(indio_dev); +int ret; - *val =axp20x_read_variable_width (info->regmap, chan->address,12 ); -if (*val <0 ) -return *val; + ret =axp20x_read_variable_width (info->regmap, chan->address,12 ); +if (ret <0 ) +return ret; + *val = ret;return IIO_VAL_INT ; }
@@ -269,11 +273,13 @@ static int axp813_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { struct axp20x_adc_iio *info = iio_priv(indio_dev); +int ret; - *val =axp20x_read_variable_width (info->regmap, chan->address,12 ); -if (*val <0 ) -return *val; + ret =axp20x_read_variable_width (info->regmap, chan->address,12 ); +if (ret <0 ) +return ret; + *val = ret;return IIO_VAL_INT ; }
@@ -443,27 +449,27 @@ static int axp20x_adc_offset_voltage(struct iio_dev *indio_dev, int channel, int *val) {struct axp20x_adc_iio *info =iio_priv (indio_dev); +unsigned int regval;int ret; - ret =regmap_read (info->regmap,AXP20X_GPIO10_IN_RANGE , val); + ret =regmap_read (info->regmap,AXP20X_GPIO10_IN_RANGE , ®val);if (ret <0 )return ret;switch (channel) {case AXP20X_GPIO0_V : - *val &=AXP20X_GPIO10_IN_RANGE_GPIO0 ; + regval =FIELD_GET (AXP20X_GPIO10_IN_RANGE_GPIO0 , regval);break ;case AXP20X_GPIO1_V : - *val &=AXP20X_GPIO10_IN_RANGE_GPIO1 ; + regval =FIELD_GET (AXP20X_GPIO10_IN_RANGE_GPIO1 , regval);break ;default :return -EINVAL ; } - *val = *val ?700000 :0 ; - + *val = regval ?700000 :0 ;return IIO_VAL_INT ; }
@@ -548,7 +554,7 @@ static int axp20x_write_raw(struct iio_dev *indio_dev, long mask) {struct axp20x_adc_iio *info =iio_priv (indio_dev); -unsigned int reg, regval; +unsigned int regmask, regval;/* * The AXP20X PMIC allows the user to choose between 0V and 0.7V offsets
@@ -560,25 +566,24 @@ static int axp20x_write_raw(struct iio_dev *indio_dev,if (val !=0 && val !=700000 )return -EINVAL ; - val = val ?1 :0 ; + regval = val ?1 :0 ;switch (chan->channel) {case AXP20X_GPIO0_V : - reg =AXP20X_GPIO10_IN_RANGE_GPIO0 ; - regval =AXP20X_GPIO10_IN_RANGE_GPIO0_VAL (val); + regmask =AXP20X_GPIO10_IN_RANGE_GPIO0 ; + regval =FIELD_PREP (AXP20X_GPIO10_IN_RANGE_GPIO0 , regval);break ;case AXP20X_GPIO1_V : - reg =AXP20X_GPIO10_IN_RANGE_GPIO1 ; - regval =AXP20X_GPIO10_IN_RANGE_GPIO1_VAL (val); + regmask =AXP20X_GPIO10_IN_RANGE_GPIO1 ; + regval =FIELD_PREP (AXP20X_GPIO10_IN_RANGE_GPIO1 , regval);break ;default :return -EINVAL ; } -return regmap_update_bits (info->regmap,AXP20X_GPIO10_IN_RANGE , reg, - regval); +return regmap_update_bits (info->regmap,AXP20X_GPIO10_IN_RANGE , regmask, regval); }static const struct iio_info axp20x_adc_iio_info = {
Signature · 1 line
2.35.1
Re: [PATCH v3 10/16] iio: adc: axp20x_adc: Minor code cleanups
Quoted 17 lines · Aidan MacDonald
The code may be clearer if parameters are not re-purposed to hold temporary results like register values, so introduce local variables as necessary to avoid that. Also, use the common
FIELD_PREPmacro instead of a hand-rolled version.Suggested-by Jonathan Cameron <[email protected]>Signed-off-by Aidan MacDonald <[email protected]>--- drivers/iio/adc/axp20x_adc.c | 61 +++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 28 deletions(-)drivers/iio/adc/axp20x_adc.c +0
-0
drivers/iio/adc/axp20x_adc.c line 18
Quoted 4 lines
drivers/iio/adc/axp20x_adc.c +1
-0@@ -15,6 +15,7 @@#include <linux/property.h> #include <linux/regmap.h> #include <linux/thermal.h> +#include <linux/bitfield.h>
Sort this group of headers alphabetically please.
Quoted 16 lines
drivers/iio/adc/axp20x_adc.c +1
-3#include <linux/iio/iio.h> #include <linux/iio/driver.h> @@ -22,20 +23,20 @@#include <linux/mfd/axp20x.h> #define AXP20X_ADC_EN1_MASK GENMASK(7, 0) -#define AXP20X_ADC_EN2_MASK (GENMASK(3, 2) | BIT(7)) +#define AXP22X_ADC_EN1_MASK (GENMASK(7, 5) | BIT(0))#define AXP20X_GPIO10_IN_RANGE_GPIO0 BIT(0)#define AXP20X_GPIO10_IN_RANGE_GPIO1 BIT(1) -#define AXP20X_GPIO10_IN_RANGE_GPIO0_VAL (x) ((x) & BIT(0)) -#define AXP20X_GPIO10_IN_RANGE_GPIO1_VAL (x) (((x) & BIT(0)) << 1)
drivers/iio/adc/axp20x_adc.c line 39
Quoted 10 lines
drivers/iio/adc/axp20x_adc.c +4
-2#define AXP20X_ADC_RATE_MASK GENMASK(7, 6) -#define AXP813_V_I_ADC_RATE_MASK GENMASK(5, 4) -#define AXP813_ADC_RATE_MASK (AXP20X_ADC_RATE_MASK | AXP813_V_I_ADC_RATE_MASK)#define AXP20X_ADC_RATE_HZ (x) ((ilog2((x) / 25) << 6) & AXP20X_ADC_RATE_MASK) +#define AXP22X_ADC_RATE_HZ (x) ((ilog2((x) / 100) << 6) & AXP20X_ADC_RATE_MASK) + +#define AXP813_V_I_ADC_RATE_MASK GENMASK(5, 4) +#define AXP813_ADC_RATE_MASK (AXP20X_ADC_RATE_MASK | AXP813_V_I_ADC_RATE_MASK)
Please also mention "grouping macros based on chip type" in the commit log.
Otherwise,
Re: [PATCH v3 10/16] iio: adc: axp20x_adc: Minor code cleanups
Quoted 55 lines · On Sun, 19 Jun 2022 11:56:56 +0800 Chen-Yu Tsai <[email protected]> wrote:
Quoted 17 lines · Aidan MacDonald
The code may be clearer if parameters are not re-purposed to hold temporary results like register values, so introduce local variables as necessary to avoid that. Also, use the common
FIELD_PREPmacro instead of a hand-rolled version.Suggested-by Jonathan Cameron <[email protected]>Signed-off-by Aidan MacDonald <[email protected]>--- drivers/iio/adc/axp20x_adc.c | 61 +++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 28 deletions(-)drivers/iio/adc/axp20x_adc.c +0
-0drivers/iio/adc/axp20x_adc.c line 18
Quoted 4 lines
drivers/iio/adc/axp20x_adc.c +1
-0@@ -15,6 +15,7 @@#include <linux/property.h> #include <linux/regmap.h> #include <linux/thermal.h> +#include <linux/bitfield.h> Sort this group of headers alphabetically please.
Quoted 16 lines
drivers/iio/adc/axp20x_adc.c +1
-3#include <linux/iio/iio.h> #include <linux/iio/driver.h> @@ -22,20 +23,20 @@#include <linux/mfd/axp20x.h> #define AXP20X_ADC_EN1_MASK GENMASK(7, 0) -#define AXP20X_ADC_EN2_MASK (GENMASK(3, 2) | BIT(7)) +#define AXP22X_ADC_EN1_MASK (GENMASK(7, 5) | BIT(0))#define AXP20X_GPIO10_IN_RANGE_GPIO0 BIT(0)#define AXP20X_GPIO10_IN_RANGE_GPIO1 BIT(1) -#define AXP20X_GPIO10_IN_RANGE_GPIO0_VAL (x) ((x) & BIT(0)) -#define AXP20X_GPIO10_IN_RANGE_GPIO1_VAL (x) (((x) & BIT(0)) << 1)drivers/iio/adc/axp20x_adc.c line 39
Quoted 10 lines
drivers/iio/adc/axp20x_adc.c +4
-2#define AXP20X_ADC_RATE_MASK GENMASK(7, 6) -#define AXP813_V_I_ADC_RATE_MASK GENMASK(5, 4) -#define AXP813_ADC_RATE_MASK (AXP20X_ADC_RATE_MASK | AXP813_V_I_ADC_RATE_MASK)#define AXP20X_ADC_RATE_HZ (x) ((ilog2((x) / 25) << 6) & AXP20X_ADC_RATE_MASK) +#define AXP22X_ADC_RATE_HZ (x) ((ilog2((x) / 100) << 6) & AXP20X_ADC_RATE_MASK) + +#define AXP813_V_I_ADC_RATE_MASK GENMASK(5, 4) +#define AXP813_ADC_RATE_MASK (AXP20X_ADC_RATE_MASK | AXP813_V_I_ADC_RATE_MASK)Please also mention "grouping macros based on chip type" in the commit log.
Quoted 3 lines
Otherwise,
Reviewed-by Chen-Yu Tsai <[email protected]>
With Chen-Yu's suggested changes,
Thanks,
Jonathan
Re: [PATCH v3 10/16] iio: adc: axp20x_adc: Minor code cleanups
In reply to Aidan MacDonaldQuoted 4 lines · Aidan MacDonald
The code may be clearer if parameters are not re-purposed to hold temporary results like register values, so introduce local variables as necessary to avoid that. Also, use the common
FIELD_PREPmacro
FIELD_PREP()
Quoted 1 line
instead of a hand-rolled version.
...
Quoted 4 lines
#include <
linux/property.h>
#include <linux/regmap.h>
#include <linux/thermal.h>
+#include <linux/bitfield.h>
Keep it sorted?
...
drivers/iio/adc/axp20x_adc.c static int axp20x_write_raw(struct iio_dev *indio_dev, · line 569
Quoted 3 lines
drivers/iio/adc/axp20x_adc.c +1
-1- val = val ?1 :0 ; + regval = val ?1 :0 ;
I think you may drop these two lines (including blank line) and...
drivers/iio/adc/axp20x_adc.c static int axp20x_write_raw(struct iio_dev *indio_dev, · line 574
Quoted 6 lines
switch (chan->channel) { case AXP20X_GPIO0_V:drivers/iio/adc/axp20x_adc.c +2
-2- reg =AXP20X_GPIO10_IN_RANGE_GPIO0 ; - regval =AXP20X_GPIO10_IN_RANGE_GPIO0_VAL (val); + regmask =AXP20X_GPIO10_IN_RANGE_GPIO0 ; + regval =FIELD_PREP (AXP20X_GPIO10_IN_RANGE_GPIO0 , regval);
...use !!val as an argument here...
drivers/iio/adc/axp20x_adc.c static int axp20x_write_raw(struct iio_dev *indio_dev, · line 579
Quoted 7 lines
break; case AXP20X_GPIO1_V:drivers/iio/adc/axp20x_adc.c +2
-2- reg =AXP20X_GPIO10_IN_RANGE_GPIO1 ; - regval =AXP20X_GPIO10_IN_RANGE_GPIO1_VAL (val); + regmask =AXP20X_GPIO10_IN_RANGE_GPIO1 ; + regval =FIELD_PREP (AXP20X_GPIO10_IN_RANGE_GPIO1 , regval);
...and here.
Quoted 5 lines
break;
default:
return -EINVAL;
}Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 11/16 iio: adc: axp20x_adc: Add support for AXP192
In reply to Aidan MacDonaldThe AXP192 is identical to the AXP20x, except for the addition of two more GPIO ADC channels.
--- drivers/iio/adc/axp20x_adc.c | 298 +++++++++++++++++++++++++++++++++-- 1 file changed, 289 insertions(+), 9 deletions(-)
drivers/iio/adc/axp20x_adc.c +289 -9
@@ -22,11 +22,19 @@#include <linux/iio/machine.h> #include <linux/mfd/axp20x.h> +#define AXP192_ADC_EN1_MASK GENMASK(7, 0) +#define AXP192_ADC_EN2_MASK (GENMASK(3, 0) | BIT(7)) +#define AXP20X_ADC_EN1_MASK GENMASK(7, 0)#define AXP20X_ADC_EN2_MASK (GENMASK(3, 2) | BIT(7))#define AXP22X_ADC_EN1_MASK (GENMASK(7, 5) | BIT(0)) +#define AXP192_GPIO30_IN_RANGE_GPIO0 BIT(0) +#define AXP192_GPIO30_IN_RANGE_GPIO1 BIT(1) +#define AXP192_GPIO30_IN_RANGE_GPIO2 BIT(2) +#define AXP192_GPIO30_IN_RANGE_GPIO3 BIT(3) +#define AXP20X_GPIO10_IN_RANGE_GPIO0 BIT(0)#define AXP20X_GPIO10_IN_RANGE_GPIO1 BIT(1)
@@ -71,6 +79,25 @@ struct axp20x_adc_iio {const struct axp_data *data; }; +enum axp192_adc_channel_v { +AXP192_ACIN_V =0 , +AXP192_VBUS_V , +AXP192_TS_IN , +AXP192_GPIO0_V , +AXP192_GPIO1_V , +AXP192_GPIO2_V , +AXP192_GPIO3_V , +AXP192_IPSOUT_V , +AXP192_BATT_V , +}; + +enum axp192_adc_channel_i { +AXP192_ACIN_I =0 , +AXP192_VBUS_I , +AXP192_BATT_CHRG_I , +AXP192_BATT_DISCHRG_I , +}; +enum axp20x_adc_channel_v {AXP20X_ACIN_V =0 ,AXP20X_VBUS_V ,
@@ -158,6 +185,43 @@ static struct iio_map axp22x_maps[] = {* The only exception is for the battery. batt_v will be in_voltage6_raw and * charge current in_current6_raw and discharge current will be in_current7_raw. */ +static const struct iio_chan_spec axp192_adc_channels[] = { +AXP20X_ADC_CHANNEL (AXP192_ACIN_V ,"acin_v" ,IIO_VOLTAGE , +AXP20X_ACIN_V_ADC_H ), +AXP20X_ADC_CHANNEL (AXP192_ACIN_I ,"acin_i" ,IIO_CURRENT , +AXP20X_ACIN_I_ADC_H ), +AXP20X_ADC_CHANNEL (AXP192_VBUS_V ,"vbus_v" ,IIO_VOLTAGE , +AXP20X_VBUS_V_ADC_H ), +AXP20X_ADC_CHANNEL (AXP192_VBUS_I ,"vbus_i" ,IIO_CURRENT , +AXP20X_VBUS_I_ADC_H ), + { + .type =IIO_TEMP , + .address =AXP20X_TEMP_ADC_H , + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | +BIT (IIO_CHAN_INFO_SCALE ) | +BIT (IIO_CHAN_INFO_OFFSET ), + .datasheet_name ="pmic_temp" , + }, +AXP20X_ADC_CHANNEL_OFFSET (AXP192_GPIO0_V ,"gpio0_v" ,IIO_VOLTAGE , +AXP20X_GPIO0_V_ADC_H ), +AXP20X_ADC_CHANNEL_OFFSET (AXP192_GPIO1_V ,"gpio1_v" ,IIO_VOLTAGE , +AXP20X_GPIO1_V_ADC_H ), +AXP20X_ADC_CHANNEL_OFFSET (AXP192_GPIO2_V ,"gpio2_v" ,IIO_VOLTAGE , +AXP192_GPIO2_V_ADC_H ), +AXP20X_ADC_CHANNEL_OFFSET (AXP192_GPIO3_V ,"gpio3_v" ,IIO_VOLTAGE , +AXP192_GPIO3_V_ADC_H ), +AXP20X_ADC_CHANNEL (AXP192_IPSOUT_V ,"ipsout_v" ,IIO_VOLTAGE , +AXP20X_IPSOUT_V_HIGH_H ), +AXP20X_ADC_CHANNEL (AXP192_BATT_V ,"batt_v" ,IIO_VOLTAGE , +AXP20X_BATT_V_H ), +AXP20X_ADC_CHANNEL (AXP192_BATT_CHRG_I ,"batt_chrg_i" ,IIO_CURRENT , +AXP20X_BATT_CHRG_I_H ), +AXP20X_ADC_CHANNEL (AXP192_BATT_DISCHRG_I ,"batt_dischrg_i" ,IIO_CURRENT , +AXP20X_BATT_DISCHRG_I_H ), +AXP20X_ADC_CHANNEL (AXP192_TS_IN ,"ts_v" ,IIO_VOLTAGE , +AXP20X_TS_IN_H ), +}; +static const struct iio_chan_spec axp20x_adc_channels[] = {AXP20X_ADC_CHANNEL (AXP20X_ACIN_V ,"acin_v" ,IIO_VOLTAGE ,AXP20X_ACIN_V_ADC_H ),
@@ -231,6 +295,27 @@ static const struct iio_chan_spec axp813_adc_channels[] = { AXP288_TS_ADC_H), }; +static int axp192_adc_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int *val) +{ +struct axp20x_adc_iio *info =iio_priv (indio_dev); +int ret, size; + +if (chan->type ==IIO_CURRENT && + (chan->channel ==AXP192_BATT_CHRG_I || + chan->channel ==AXP192_BATT_DISCHRG_I )) + size =13 ; +else + size =12 ; + + ret =axp20x_read_variable_width (info->regmap, chan->address, size); +if (ret <0 ) +return ret; + + *val = ret; +return IIO_VAL_INT ; +} +static int axp20x_adc_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val) {
@@ -283,6 +368,44 @@ static int axp813_adc_raw(struct iio_dev *indio_dev,return IIO_VAL_INT ; } +static int axp192_adc_scale_voltage (int channel,int *val,int *val2) +{ +switch (channel) { +case AXP192_ACIN_V : +case AXP192_VBUS_V : + *val =1 ; + *val2 =700000 ; +return IIO_VAL_INT_PLUS_MICRO ; + +case AXP192_GPIO0_V : +case AXP192_GPIO1_V : +case AXP192_GPIO2_V : +case AXP192_GPIO3_V : + *val =0 ; + *val2 =500000 ; +return IIO_VAL_INT_PLUS_MICRO ; + +case AXP192_BATT_V : + *val =1 ; + *val2 =100000 ; +return IIO_VAL_INT_PLUS_MICRO ; + +case AXP192_IPSOUT_V : + *val =1 ; + *val2 =400000 ; +return IIO_VAL_INT_PLUS_MICRO ; + +case AXP192_TS_IN : +/* 0.8 mV per LSB */ + *val =0 ; + *val2 =800000 ; +return IIO_VAL_INT_PLUS_MICRO ; + +default : +return -EINVAL ; + } +} +static int axp20x_adc_scale_voltage (int channel,int *val,int *val2) {switch (channel) {
@@ -386,6 +509,29 @@ static int axp20x_adc_scale_current(int channel, int *val, int *val2) } } +static int axp192_adc_scale (struct iio_chan_spec const *chan,int *val, +int *val2) +{ +switch (chan->type) { +case IIO_VOLTAGE : +return axp192_adc_scale_voltage (chan->channel, val, val2); + +case IIO_CURRENT : +/* +* AXP192 current channels are identical to the AXP20x, +* therefore we can re-use the scaling function. +*/ +return axp20x_adc_scale_current (chan->channel, val, val2); + +case IIO_TEMP : + *val =100 ; +return IIO_VAL_INT ; + +default : +return -EINVAL ; + } +} +static int axp20x_adc_scale (struct iio_chan_spec const *chan,int *val,int *val2) {
@@ -445,6 +591,42 @@ static int axp813_adc_scale(struct iio_chan_spec const *chan, int *val, } } +static int axp192_adc_offset_voltage (struct iio_dev *indio_dev,int channel, +int *val) +{ +struct axp20x_adc_iio *info =iio_priv (indio_dev); +unsigned int regval; +int ret; + + ret =regmap_read (info->regmap,AXP192_GPIO30_IN_RANGE , ®val); +if (ret <0 ) +return ret; + +switch (channel) { +case AXP192_GPIO0_V : + regval =FIELD_GET (AXP192_GPIO30_IN_RANGE_GPIO0 , regval); +break ; + +case AXP192_GPIO1_V : + regval =FIELD_GET (AXP192_GPIO30_IN_RANGE_GPIO1 , regval); +break ; + +case AXP192_GPIO2_V : + regval =FIELD_GET (AXP192_GPIO30_IN_RANGE_GPIO2 , regval); +break ; + +case AXP192_GPIO3_V : + regval =FIELD_GET (AXP192_GPIO30_IN_RANGE_GPIO3 , regval); +break ; + +default : +return -EINVAL ; + } + + *val = regval ?700000 :0 ; +return IIO_VAL_INT ; +} +static int axp20x_adc_offset_voltage (struct iio_dev *indio_dev,int channel,int *val) {
@@ -473,6 +655,22 @@ static int axp20x_adc_offset_voltage(struct iio_dev *indio_dev, int channel,return IIO_VAL_INT ; } +static int axp192_adc_offset (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int *val) +{ +switch (chan->type) { +case IIO_VOLTAGE : +return axp192_adc_offset_voltage (indio_dev, chan->channel, val); + +case IIO_TEMP : + *val =-1447 ; +return IIO_VAL_INT ; + +default : +return -EINVAL ; + } +} +static int axp20x_adc_offset (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val) {
@@ -489,6 +687,25 @@ static int axp20x_adc_offset(struct iio_dev *indio_dev, } } +static int axp192_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int *val, +int *val2,long mask) +{ +switch (mask) { +case IIO_CHAN_INFO_OFFSET : +return axp192_adc_offset (indio_dev, chan, val); + +case IIO_CHAN_INFO_SCALE : +return axp192_adc_scale (chan, val, val2); + +case IIO_CHAN_INFO_RAW : +return axp192_adc_raw (indio_dev, chan, val); + +default : +return -EINVAL ; + } +} +static int axp20x_read_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2,long mask)
@@ -549,6 +766,53 @@ static int axp813_read_raw(struct iio_dev *indio_dev, } } +static int axp192_write_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int val,int val2, +long mask) +{ +struct axp20x_adc_iio *info =iio_priv (indio_dev); +unsigned int regmask, regval; + +/* +* The AXP192 PMIC allows the user to choose between 0V and 0.7V offsets +* for (independently) GPIO0-3 when in ADC mode. +*/ +if (mask !=IIO_CHAN_INFO_OFFSET ) +return -EINVAL ; + +if (val !=0 && val !=700000 ) +return -EINVAL ; + + regval = val ?1 :0 ; + +switch (chan->channel) { +case AXP192_GPIO0_V : + regmask =AXP192_GPIO30_IN_RANGE_GPIO0 ; + regval =FIELD_PREP (AXP192_GPIO30_IN_RANGE_GPIO0 , regval); +break ; + +case AXP192_GPIO1_V : + regmask =AXP192_GPIO30_IN_RANGE_GPIO1 ; + regval =FIELD_PREP (AXP192_GPIO30_IN_RANGE_GPIO1 , regval); +break ; + +case AXP192_GPIO2_V : + regmask =AXP192_GPIO30_IN_RANGE_GPIO2 ; + regval =FIELD_PREP (AXP192_GPIO30_IN_RANGE_GPIO2 , regval); +break ; + +case AXP192_GPIO3_V : + regmask =AXP192_GPIO30_IN_RANGE_GPIO3 ; + regval =FIELD_PREP (AXP192_GPIO30_IN_RANGE_GPIO3 , regval); +break ; + +default : +return -EINVAL ; + } + +return regmap_update_bits (info->regmap,AXP192_GPIO30_IN_RANGE , regmask, regval); +} +static int axp20x_write_raw (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int val,int val2,long mask)
@@ -586,6 +850,11 @@ static int axp20x_write_raw(struct iio_dev *indio_dev,return regmap_update_bits (info->regmap,AXP20X_GPIO10_IN_RANGE , regmask, regval); } +static const struct iio_info axp192_adc_iio_info = { + .read_raw = axp192_read_raw, + .write_raw = axp192_write_raw, +}; +static const struct iio_info axp20x_adc_iio_info = { .read_raw = axp20x_read_raw, .write_raw = axp20x_write_raw,
@@ -625,19 +894,29 @@ struct axp_data {int num_channels;struct iio_chan_spec const *channels;unsigned long adc_en1_mask; +unsigned long adc_en2_mask;int (*adc_rate)(struct axp20x_adc_iio *info,int rate); -bool adc_en2;struct iio_map *maps; }; +static const struct axp_data axp192_data = { + .iio_info = &axp192_adc_iio_info, + .num_channels =ARRAY_SIZE (axp192_adc_channels), + .channels = axp192_adc_channels, + .adc_en1_mask =AXP192_ADC_EN1_MASK , + .adc_en2_mask =AXP192_ADC_EN2_MASK , + .adc_rate = axp20x_adc_rate, + .maps = axp20x_maps, +}; +static const struct axp_data axp20x_data = { .iio_info = &axp20x_adc_iio_info, .num_channels =ARRAY_SIZE (axp20x_adc_channels), .channels = axp20x_adc_channels, .adc_en1_mask =AXP20X_ADC_EN1_MASK , + .adc_en2_mask =AXP20X_ADC_EN2_MASK , .adc_rate = axp20x_adc_rate, - .adc_en2 = true, .maps = axp20x_maps, };
@@ -647,7 +926,6 @@ static const struct axp_data axp22x_data = { .channels = axp22x_adc_channels, .adc_en1_mask = AXP22X_ADC_EN1_MASK, .adc_rate = axp22x_adc_rate, - .adc_en2 = false, .maps = axp22x_maps, };
@@ -657,11 +935,11 @@ static const struct axp_data axp813_data = { .channels = axp813_adc_channels, .adc_en1_mask = AXP22X_ADC_EN1_MASK, .adc_rate = axp813_adc_rate, - .adc_en2 = false, .maps = axp22x_maps, };static const struct of_device_id axp20x_adc_of_match[] = { + { .compatible ="x-powers,axp192-adc" , .data = (void *)&axp192_data, }, { .compatible ="x-powers,axp209-adc" , .data = (void *)&axp20x_data, }, { .compatible ="x-powers,axp221-adc" , .data = (void *)&axp22x_data, }, { .compatible ="x-powers,axp813-adc" , .data = (void *)&axp813_data, },
@@ -670,6 +948,7 @@ static const struct of_device_id axp20x_adc_of_match[] = {MODULE_DEVICE_TABLE (of, axp20x_adc_of_match);static const struct platform_device_id axp20x_adc_id_match[] = { + { .name ="axp192-adc" , .driver_data = (kernel_ulong_t)&axp192_data, }, { .name ="axp20x-adc" , .driver_data = (kernel_ulong_t)&axp20x_data, }, { .name ="axp22x-adc" , .driver_data = (kernel_ulong_t)&axp22x_data, }, { .name ="axp813-adc" , .driver_data = (kernel_ulong_t)&axp813_data, },
@@ -715,10 +994,11 @@ static int axp20x_probe(struct platform_device *pdev)/* Enable the ADCs on IP */ regmap_write (info->regmap,AXP20X_ADC_EN1 , info->data->adc_en1_mask); -if (info->data->adc_en2) -/* Enable GPIO0/1 and internal temperature ADCs */ +if (info->data->adc_en2_mask) +/* Enable GPIO and internal temperature ADCs */ regmap_update_bits (info->regmap,AXP20X_ADC_EN2 , -AXP20X_ADC_EN2_MASK ,AXP20X_ADC_EN2_MASK ); + info->data->adc_en2_mask, + info->data->adc_en2_mask);/* Configure ADCs rate */ info->data->adc_rate (info,100 );
@@ -743,7 +1023,7 @@ static int axp20x_probe(struct platform_device *pdev) fail_map:regmap_write (info->regmap,AXP20X_ADC_EN1 ,0 ); -if (info->data->adc_en2) +if (info->data->adc_en2_mask)regmap_write (info->regmap,AXP20X_ADC_EN2 ,0 );return ret;
@@ -759,7 +1039,7 @@ static int axp20x_remove(struct platform_device *pdev)regmap_write (info->regmap,AXP20X_ADC_EN1 ,0 ); -if (info->data->adc_en2) +if (info->data->adc_en2_mask)regmap_write (info->regmap,AXP20X_ADC_EN2 ,0 );return 0 ;
Signature · 1 line
2.35.1
Re: [PATCH v3 11/16] iio: adc: axp20x_adc: Add support for AXP192
Quoted 3 lines · Aidan MacDonald
The AXP192 is identical to the AXP20x, except for the addition of two more GPIO ADC channels.
...
Quoted 9 lines
drivers/iio/adc/axp20x_adc.c +9
-0+static int axp192_write_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int val,int val2, +long mask) +{ +struct axp20x_adc_iio *info =iio_priv (indio_dev); +unsigned int regmask, regval; + +/* +* The AXP192 PMIC allows the user to choose between 0V and 0.7V offsets
drivers/iio/adc/axp20x_adc.c static int axp813_read_raw(struct iio_dev *indio_dev, · line 787
Quoted 10 lines
drivers/iio/adc/axp20x_adc.c +9
-0+* for (independently) GPIO0-3 when in ADC mode. +*/ +if (mask !=IIO_CHAN_INFO_OFFSET ) +return -EINVAL ; + +if (val !=0 && val !=700000 ) +return -EINVAL ; + regval = val ?1 :0 ; +
As per comment against the previous patch use !!val directly?
Quoted 27 lines
drivers/iio/adc/axp20x_adc.c +27
-0+switch (chan->channel) { +case AXP192_GPIO0_V : + regmask =AXP192_GPIO30_IN_RANGE_GPIO0 ; + regval =FIELD_PREP (AXP192_GPIO30_IN_RANGE_GPIO0 , regval); +break ; + +case AXP192_GPIO1_V : + regmask =AXP192_GPIO30_IN_RANGE_GPIO1 ; + regval =FIELD_PREP (AXP192_GPIO30_IN_RANGE_GPIO1 , regval); +break ; + +case AXP192_GPIO2_V : + regmask =AXP192_GPIO30_IN_RANGE_GPIO2 ; + regval =FIELD_PREP (AXP192_GPIO30_IN_RANGE_GPIO2 , regval); +break ; + +case AXP192_GPIO3_V : + regmask =AXP192_GPIO30_IN_RANGE_GPIO3 ; + regval =FIELD_PREP (AXP192_GPIO30_IN_RANGE_GPIO3 , regval); +break ; + +default : +return -EINVAL ; + } + +return regmap_update_bits (info->regmap,AXP192_GPIO30_IN_RANGE , regmask, regval); +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 11/16] iio: adc: axp20x_adc: Add support for AXP192
In reply to Aidan MacDonaldQuoted 4 lines · On Sat, 18 Jun 2022 22:40:04 +0100 Aidan MacDonald…
The AXP192 is identical to the AXP20x, except for the addition of two more GPIO ADC channels.
Signed-off-by Aidan MacDonald <[email protected]>
Hi Aidan,
Looking at this again, I'd have a slight preference for doing the switch to adc_en2_mask as a precursor patch.
Still, not a big thing (and I should have raised it earlier!) so up to you. Either way
Thanks,
Jonathan
Re: [PATCH v3 11/16] iio: adc: axp20x_adc: Add support for AXP192
Quoted 11 lines · Jonathan Cameron
Quoted 4 lines · On Sat, 18 Jun 2022 22:40:04 +0100 Aidan MacDonald…
The AXP192 is identical to the AXP20x, except for the addition of two more GPIO ADC channels.
Signed-off-by Aidan MacDonald <[email protected]>Hi Aidan,
Looking at this again, I'd have a slight preference for doing the switch to
adc_en2_maskas a precursor patch.
I might as well, it's a bit cleaner that way.
Quoted 9 lines
Still, not a big thing (and I should have raised it earlier!) so up to you. Either way
Reviewed-by Jonathan Cameron <[email protected]>Thanks,
Jonathan
PATCH v3 12/16 power: supply: axp20x_usb_power: Add support for AXP192
In reply to Aidan MacDonaldThe AXP192 is mostly the same as the AXP202 but has a different current limit.
--- drivers/power/supply/axp20x_usb_power.c | 80 +++++++++++++++++++++---- 1 file changed, 69 insertions(+), 11 deletions(-)
drivers/power/supply/axp20x_usb_power.c +69 -11
@@ -48,6 +48,9 @@#define AXP813_VBUS_CLIMIT_2000mA 2#define AXP813_VBUS_CLIMIT_2500mA 3 +#define AXP192_VBUS_CLIMIT_EN BIT(1) +#define AXP192_VBUS_CLIMIT_100mA BIT(0) +#define AXP20X_ADC_EN1_VBUS_CURR BIT(2)#define AXP20X_ADC_EN1_VBUS_VOLT BIT(3)
@@ -121,6 +124,24 @@ static void axp20x_usb_power_poll_vbus(struct work_struct *work)mod_delayed_work (system_power_efficient_wq, &power->vbus_detect,DEBOUNCE_TIME ); } +static int axp192_get_current_max (struct axp20x_usb_power *power,int *val) +{ +unsigned int v; +int ret =regmap_read (power->regmap,AXP20X_VBUS_IPSOUT_MGMT , &v); + +if (ret) +return ret; + +if (!(v &AXP192_VBUS_CLIMIT_EN )) + *val =-1 ; +else if (v & AXP192_VBUS_CLIMIT_100mA) + *val =100000 ; +else + *val =500000 ; + +return 0 ; +} +static int axp20x_get_current_max (struct axp20x_usb_power *power,int *val) {unsigned int v;
@@ -179,7 +200,7 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { struct axp20x_usb_power *power = power_supply_get_drvdata(psy); -unsigned int input, v; +unsigned int input, v, reg;int ret;switch (psp) {
@@ -215,6 +236,8 @@ static int axp20x_usb_power_get_property(struct power_supply *psy,case POWER_SUPPLY_PROP_CURRENT_MAX :if (power->axp20x_id ==AXP813_ID )return axp813_get_current_max (power, &val->intval); +else if (power->axp20x_id ==AXP192_ID ) +return axp192_get_current_max (power, &val->intval);return axp20x_get_current_max (power, &val->intval);case POWER_SUPPLY_PROP_CURRENT_NOW :if (IS_ENABLED (CONFIG_AXP20X_ADC )) {
@@ -256,16 +279,20 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, val->intval =POWER_SUPPLY_HEALTH_GOOD ; -if (power->axp20x_id ==AXP202_ID ) { - ret =regmap_read (power->regmap, -AXP20X_USB_OTG_STATUS , &v); -if (ret) -return ret; +if (power->axp20x_id ==AXP192_ID ) + reg =AXP192_USB_OTG_STATUS ; +else if (power->axp20x_id ==AXP202_ID ) + reg =AXP20X_USB_OTG_STATUS ; +else +/* Other chips do not have an OTG status register */ +break ; -if (!(v &AXP20X_USB_STATUS_VBUS_VALID )) - val->intval = -POWER_SUPPLY_HEALTH_UNSPEC_FAILURE ; - } + ret =regmap_read (power->regmap, reg, &v); +if (ret) +return ret; + +if (!(v &AXP20X_USB_STATUS_VBUS_VALID )) + val->intval =POWER_SUPPLY_HEALTH_UNSPEC_FAILURE ;break ;case POWER_SUPPLY_PROP_PRESENT : val->intval = !!(input &AXP20X_PWR_STATUS_VBUS_PRESENT );
@@ -316,6 +343,24 @@ static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power,return -EINVAL ; } +static int axp192_usb_power_set_current_max (struct axp20x_usb_power *power, +int intval) +{ +int val =AXP192_VBUS_CLIMIT_EN ; +const int mask =AXP192_VBUS_CLIMIT_EN | AXP192_VBUS_CLIMIT_100mA; + +switch (intval) { +case 100000 : + val |= AXP192_VBUS_CLIMIT_100mA; + fallthrough; +case 500000 : +return regmap_update_bits (power->regmap, +AXP20X_VBUS_IPSOUT_MGMT , mask, val); +default : +return -EINVAL ; + } +} +static int axp813_usb_power_set_current_max (struct axp20x_usb_power *power,int intval) {
@@ -383,6 +428,9 @@ static int axp20x_usb_power_set_property(struct power_supply *psy,if (power->axp20x_id ==AXP813_ID )return axp813_usb_power_set_current_max (power, val->intval); +else if (power->axp20x_id ==AXP192_ID ) +return axp192_usb_power_set_current_max (power, + val->intval);return axp20x_usb_power_set_current_max (power, val->intval);default :
@@ -468,6 +516,13 @@ struct axp_data {enum axp20x_variants axp20x_id; }; +static const struct axp_data axp192_data = { + .power_desc = &axp20x_usb_power_desc, + .irq_names = axp20x_irq_names, + .num_irq_names =ARRAY_SIZE (axp20x_irq_names), + .axp20x_id =AXP192_ID , +}; +static const struct axp_data axp202_data = { .power_desc = &axp20x_usb_power_desc, .irq_names = axp20x_irq_names,
@@ -600,7 +655,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)if (ret)return ret; -if (power->axp20x_id ==AXP202_ID ) { +if (power->axp20x_id ==AXP192_ID || power->axp20x_id ==AXP202_ID ) {/* Enable vbus valid checking */ ret = regmap_update_bits(power->regmap, AXP20X_VBUS_MON, AXP20X_VBUS_MON_VBUS_VALID,
@@ -659,6 +714,9 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)static const struct of_device_id axp20x_usb_power_match[] = { { + .compatible ="x-powers,axp192-usb-power-supply" , + .data = &axp192_data, + }, { .compatible ="x-powers,axp202-usb-power-supply" , .data = &axp202_data, }, {
Signature · 1 line
2.35.1
Re: [PATCH v3 12/16] power: supply: axp20x_usb_power: Add support for AXP192
Quoted 73 lines · Aidan MacDonald
The AXP192 is mostly the same as the AXP202 but has a different current limit.
Signed-off-by Aidan MacDonald <[email protected]>--- drivers/power/supply/axp20x_usb_power.c | 80 +++++++++++++++++++++---- 1 file changed, 69 insertions(+), 11 deletions(-)drivers/power/supply/axp20x_usb_power.c +24
-3@@ -48,6 +48,9 @@#define AXP813_VBUS_CLIMIT_2000mA 2#define AXP813_VBUS_CLIMIT_2500mA 3 +#define AXP192_VBUS_CLIMIT_EN BIT(1) +#define AXP192_VBUS_CLIMIT_100mA BIT(0) +#define AXP20X_ADC_EN1_VBUS_CURR BIT(2)#define AXP20X_ADC_EN1_VBUS_VOLT BIT(3)@@ -121,6 +124,24 @@ static void axp20x_usb_power_poll_vbus(struct work_struct *work)mod_delayed_work (system_power_efficient_wq, &power->vbus_detect,DEBOUNCE_TIME ); } +static int axp192_get_current_max (struct axp20x_usb_power *power,int *val) +{ +unsigned int v; +int ret =regmap_read (power->regmap,AXP20X_VBUS_IPSOUT_MGMT , &v); + +if (ret) +return ret; + +if (!(v &AXP192_VBUS_CLIMIT_EN )) + *val =-1 ; +else if (v & AXP192_VBUS_CLIMIT_100mA) + *val =100000 ; +else + *val =500000 ; + +return 0 ; +} +static int axp20x_get_current_max (struct axp20x_usb_power *power,int *val) {unsigned int v;@@ -179,7 +200,7 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { struct axp20x_usb_power *power = power_supply_get_drvdata(psy); -unsigned int input, v; +unsigned int input, v, reg;int ret;switch (psp) {@@ -215,6 +236,8 @@ static int axp20x_usb_power_get_property(struct power_supply *psy,case POWER_SUPPLY_PROP_CURRENT_MAX :if (power->axp20x_id ==AXP813_ID )return axp813_get_current_max (power, &val->intval); +else if (power->axp20x_id ==AXP192_ID ) +return axp192_get_current_max (power, &val->intval);return axp20x_get_current_max (power, &val->intval);case POWER_SUPPLY_PROP_CURRENT_NOW :if (IS_ENABLED (CONFIG_AXP20X_ADC )) {@@ -256,16 +279,20 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, val->intval =POWER_SUPPLY_HEALTH_GOOD ; -if (power->axp20x_id ==AXP202_ID ) { - ret = regmap_read(power->regmap,
drivers/power/supply/axp20x_usb_power.c static int axp20x_usb_power_get_property(struct power_supply *psy, · line 288
Quoted 10 lines
drivers/power/supply/axp20x_usb_power.c +7
-3- AXP20X_USB_OTG_STATUS, &v); -if (ret) -return ret; +if (power->axp20x_id ==AXP192_ID ) + reg =AXP192_USB_OTG_STATUS ; +else if (power->axp20x_id ==AXP202_ID ) + reg =AXP20X_USB_OTG_STATUS ; +else +/* Other chips do not have an OTG status register */ +break ;
Nit: put the comment on the same line as the break, trailing it.
Otherwise,
Re: [PATCH v3 12/16] power: supply: axp20x_usb_power: Add support for AXP192
In reply to Aidan MacDonaldQuoted 3 lines · Aidan MacDonald
The AXP192 is mostly the same as the AXP202 but has a different current limit.
...
drivers/power/supply/axp20x_usb_power.c static void axp20x_usb_power_poll_vbus(struct work_struct *work) · line 133
Quoted 4 lines
drivers/power/supply/axp20x_usb_power.c +4
-0+int ret =regmap_read (power->regmap,AXP20X_VBUS_IPSOUT_MGMT , &v); + +if (ret) +return ret;
Please, split assignment, so it will be like
int ret;
ret = ...
if (ret)
...
drivers/power/supply/axp20x_usb_power.c static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, · line 355
Quoted 11 lines
drivers/power/supply/axp20x_usb_power.c +10
-0+static int axp192_usb_power_set_current_max (struct axp20x_usb_power *power, +int intval) +{ +int val =AXP192_VBUS_CLIMIT_EN ; +const int mask =AXP192_VBUS_CLIMIT_EN | AXP192_VBUS_CLIMIT_100mA; + +switch (intval) { +case 100000 : + val |= AXP192_VBUS_CLIMIT_100mA; + fallthrough;
It's harder to part and error prone, can't you simply call a regmap_update_bits with different arguments?
With this suggestion consider the defaults like these:
const int mask = AXP192_VBUS_CLIMIT_EN | AXP192_VBUS_CLIMIT_100mA;
int val = mask;Then use val & ~AXP192_VBUS_CLIMIT_100mA in the below case.
Quoted 7 lines
drivers/power/supply/axp20x_usb_power.c +7
-0+case 500000 : +return regmap_update_bits (power->regmap, +AXP20X_VBUS_IPSOUT_MGMT , mask, val); +default : +return -EINVAL ; + } +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 13/16 pinctrl: Add AXP192 pin control driver
In reply to Aidan MacDonaldThe AXP192 PMIC's GPIO registers are much different from the GPIO registers of the AXP20x and AXP813 PMICs supported by the existing pinctrl-axp209 driver. It makes more sense to add a new driver for the AXP192, rather than add support in the existing axp20x driver.
The pinctrl-axp192 driver is considerably more flexible in terms of register layout and should be able to support other X-Powers PMICs. Interrupts and pull down resistor configuration are supported too.
--- drivers/pinctrl/Kconfig | 14 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-axp192.c | 562 +++++++++++++++++++++++++++++++ 3 files changed, 577 insertions(+) create mode 100644 drivers/pinctrl/pinctrl-axp192.c
drivers/pinctrl/Kconfig +14 -0
@@ -113,6 +113,20 @@ config PINCTRL_AT91PIO4 Say Y here to enable the at91 pinctrl/gpio driver for Atmel PIO4 controller available on sama5d2 SoC. +config PINCTRL_AXP192 + tristate "X-Powers AXP192 PMIC pinctrl and GPIO Support" + depends on MFD_AXP20X + depends on OF + select PINMUX + select GENERIC_PINCONF + select GPIOLIB + help + AXP PMICs provides multiple GPIOs that can be muxed for different + functions. This driver bundles a pinctrl driver to select the function + muxing and a GPIO driver to handle the GPIO when the GPIO function is + selected. + Say Y to enable pinctrl and GPIO support for the AXP192 PMIC. + config PINCTRL_AXP209 tristate "X-Powers AXP209 PMIC pinctrl and GPIO Support" depends on MFD_AXP20X
drivers/pinctrl/Makefile +1 -0
@@ -15,6 +15,7 @@ obj-$(CONFIG_PINCTRL_ARTPEC6) += pinctrl-artpec6.o obj-$(CONFIG_PINCTRL_AS3722) += pinctrl-as3722.o obj-$(CONFIG_PINCTRL_AT91) += pinctrl-at91.o obj-$(CONFIG_PINCTRL_AT91PIO4) += pinctrl-at91-pio4.o +obj-$(CONFIG_PINCTRL_AXP192) += pinctrl-axp192.o obj-$(CONFIG_PINCTRL_AXP209) += pinctrl-axp209.o obj-$(CONFIG_PINCTRL_BM1880) += pinctrl-bm1880.o obj-$(CONFIG_PINCTRL_DA850_PUPD) += pinctrl-da850-pupd.o
drivers/pinctrl/pinctrl-axp192.c new file +562 -0
562 lines not on this page · raw message
Signature · 1 line
2.35.1
Re: [PATCH v3 13/16] pinctrl: Add AXP192 pin control driver
Quoted 7 lines · Aidan MacDonald
drivers/pinctrl/Kconfig +0
-0@@ -113,6 +113,20 @@ config PINCTRL_AT91PIO4 Say Y here to enable the at91 pinctrl/gpio driver for Atmel PIO4 controller available on sama5d2 SoC.
drivers/pinctrl/Kconfig config PINCTRL_AT91PIO4 · line 124
Quoted 10 lines
drivers/pinctrl/Kconfig +9
-0+config PINCTRL_AXP192 + tristate "X-Powers AXP192 PMIC pinctrl and GPIO Support" + depends on MFD_AXP20X + depends on OF + select PINMUX + select GENERIC_PINCONF + select GPIOLIB + help + AXP PMICs provides multiple GPIOs that can be muxed for different
provide
Quoted 4 lines
drivers/pinctrl/Kconfig +4
-0+ functions. This driver bundles a pinctrl driver to select the function + muxing and a GPIO driver to handle the GPIO when the GPIO function is + selected. + Say Y to enable pinctrl and GPIO support for the AXP192 PMIC.
Signature · 1 line
~Randy
Re: [PATCH v3 13/16] pinctrl: Add AXP192 pin control driver
In reply to Aidan MacDonaldQuoted 9 lines · Aidan MacDonald
The AXP192 PMIC's GPIO registers are much different from the GPIO registers of the AXP20x and AXP813 PMICs supported by the existing pinctrl-axp209 driver. It makes more sense to add a new driver for the AXP192, rather than add support in the existing axp20x driver.
The pinctrl-axp192 driver is considerably more flexible in terms of register layout and should be able to support other X-Powers PMICs. Interrupts and pull down resistor configuration are supported too.
...
drivers/pinctrl/Kconfig config PINCTRL_AT91PIO4 · line 119
Quoted 6 lines
drivers/pinctrl/Kconfig +4
-0+config PINCTRL_AXP192 + tristate "X-Powers AXP192 PMIC pinctrl and GPIO Support" + depends on MFD_AXP20X + depends on OF
Why?
Quoted 3 lines
drivers/pinctrl/Kconfig +3
-0+ select PINMUX + select GENERIC_PINCONF + select GPIOLIB
...
drivers/pinctrl/pinctrl-axp192.c line 18
Quoted 2 lines
drivers/pinctrl/pinctrl-axp192.c new file +2
-0+#include <linux/of.h> +#include <linux/of_device.h>
Why?
...
drivers/pinctrl/pinctrl-axp192.c line 42
Quoted 3 lines
drivers/pinctrl/pinctrl-axp192.c new file +3
-0+struct axp192_pctl_function { +const char *name; +/* Mux value written to the control register to select the function (-1 if unsupported) */
Comment is misleading. -1 can't be a value of unsigned type.
Quoted 4 lines
drivers/pinctrl/pinctrl-axp192.c new file +4
-0+const u8 *muxvals; +const char *const *groups; +unsigned int ngroups; +};
...
drivers/pinctrl/pinctrl-axp192.c line 62
Quoted 10 lines
drivers/pinctrl/pinctrl-axp192.c new file +10
-0+struct axp192_pctl_desc { +unsigned int npins; +const struct pinctrl_pin_desc *pins; +/* Description of the function control register for each pin */ +const struct axp192_pctl_reg_info *ctrl_regs; +/* Description of the output signal register for each pin */ +const struct axp192_pctl_reg_info *out_regs; +/* Description of the input signal register for each pin */ +const struct axp192_pctl_reg_info *in_regs; +/* Description of the pull down resistor config register for each pin */
Can you just convert these comments to a kernel-doc?
Quoted 5 lines
drivers/pinctrl/pinctrl-axp192.c new file +5
-0+const struct axp192_pctl_reg_info *pull_down_regs; + +unsigned int nfunctions; +const struct axp192_pctl_function *functions; +};
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ +
One blank line is enough.
...
drivers/pinctrl/pinctrl-axp192.c line 315
Quoted 7 lines
drivers/pinctrl/pinctrl-axp192.c new file +6
-0+switch (param) { +case PIN_CONFIG_BIAS_DISABLE : + ret =axp192_pinconf_get_pull_down (pctldev, pin); +if (ret <0 ) +return ret; +else if (ret !=0 )
1. Redundant 'else'
2. if (ret > 0)
drivers/pinctrl/pinctrl-axp192.c line 323
Quoted 8 lines
drivers/pinctrl/pinctrl-axp192.c new file +8
-0+return -EINVAL ; +break ; + +case PIN_CONFIG_BIAS_PULL_DOWN : + ret =axp192_pinconf_get_pull_down (pctldev, pin); +if (ret <0 ) +return ret; +else if (ret ==0 )
Ditto.
Looking at this I would rather expect the function to return something defined, than 0, non-0.
Quoted 6 lines
drivers/pinctrl/pinctrl-axp192.c new file +5
-0+return -EINVAL ; +break ; +default : +return -ENOTSUPP ; + }
...
Quoted 1 line
+ for (cfg = 0; cfg <
num_configs; ++cfg) {
cfg++ will work the same way and easier to read.
Quoted 207 lines
drivers/pinctrl/pinctrl-axp192.c new file +207
-0+switch (pinconf_to_config_param (configs[cfg])) { +case PIN_CONFIG_BIAS_DISABLE : + ret =axp192_pinconf_set_pull_down (pctldev, pin,0 ); +if (ret) +return ret; +break ; + +case PIN_CONFIG_BIAS_PULL_DOWN : + ret =axp192_pinconf_set_pull_down (pctldev, pin,1 ); +if (ret) +return ret; +break ; + +default : +return -ENOTSUPP ; + } + } + +return 0 ; +} + +static const struct pinconf_ops axp192_conf_ops = { + .is_generic = true, + .pin_config_get = axp192_pinconf_get, + .pin_config_set = axp192_pinconf_set, + .pin_config_group_get = axp192_pinconf_get, + .pin_config_group_set = axp192_pinconf_set, +}; + +static int axp192_pmx_set (struct pinctrl_dev *pctldev,unsigned int offset,u8 config) +{ +struct axp192_pctl *pctl =pinctrl_dev_get_drvdata (pctldev); +const struct axp192_pctl_reg_info *reginfo = &pctl->desc->ctrl_regs[offset]; +unsigned int regval = config << (ffs (reginfo->mask) -1 ); + +return regmap_update_bits (pctl->regmap, reginfo->reg, reginfo->mask, regval); +} + +static int axp192_pmx_func_cnt (struct pinctrl_dev *pctldev) +{ +struct axp192_pctl *pctl =pinctrl_dev_get_drvdata (pctldev); + +return pctl->desc->nfunctions; +} + +static const char *axp192_pmx_func_name (struct pinctrl_dev *pctldev,unsigned int selector) +{ +struct axp192_pctl *pctl =pinctrl_dev_get_drvdata (pctldev); + +return pctl->desc->functions[selector].name; +} + +static int axp192_pmx_func_groups (struct pinctrl_dev *pctldev,unsigned int selector, +const char *const **groups,unsigned int *num_groups) +{ +struct axp192_pctl *pctl =pinctrl_dev_get_drvdata (pctldev); + + *groups = pctl->desc->functions[selector].groups; + *num_groups = pctl->desc->functions[selector].ngroups; + +return 0 ; +} + +static int axp192_pmx_set_mux (struct pinctrl_dev *pctldev, +unsigned int function,unsigned int group) +{ +struct axp192_pctl *pctl =pinctrl_dev_get_drvdata (pctldev); +const u8 *muxvals = pctl->desc->functions[function].muxvals; + +if (muxvals[group] ==U8_MAX ) +return -EINVAL ; + +/* +* Switching to LDO or PWM function will enable LDO/PWM output, so it's +* better to ignore these requests and let the regulator or PWM drivers +* handle muxing to avoid interfering with them. +*/ +if (function ==AXP192_FUNC_LDO || function ==AXP192_FUNC_PWM ) +return 0 ; + +return axp192_pmx_set (pctldev, group, muxvals[group]); +} + +static int axp192_pmx_gpio_set_direction (struct pinctrl_dev *pctldev, +struct pinctrl_gpio_range *range, +unsigned int offset,bool input) +{ +struct axp192_pctl *pctl =pinctrl_dev_get_drvdata (pctldev); +const u8 *muxvals = input ? pctl->desc->functions[AXP192_FUNC_INPUT ].muxvals + : pctl->desc->functions[AXP192_FUNC_OUTPUT ].muxvals; + +return axp192_pmx_set (pctldev, offset, muxvals[offset]); +} + +static const struct pinmux_ops axp192_pmx_ops = { + .get_functions_count = axp192_pmx_func_cnt, + .get_function_name = axp192_pmx_func_name, + .get_function_groups = axp192_pmx_func_groups, + .set_mux = axp192_pmx_set_mux, + .gpio_set_direction = axp192_pmx_gpio_set_direction, + .strict = true, +}; + +static int axp192_groups_cnt (struct pinctrl_dev *pctldev) +{ +struct axp192_pctl *pctl =pinctrl_dev_get_drvdata (pctldev); + +return pctl->desc->npins; +} + +static const char *axp192_group_name (struct pinctrl_dev *pctldev,unsigned int selector) +{ +struct axp192_pctl *pctl =pinctrl_dev_get_drvdata (pctldev); + +return pctl->desc->pins[selector].name; +} + +static int axp192_group_pins (struct pinctrl_dev *pctldev,unsigned int selector, +const unsigned int **pins,unsigned int *num_pins) +{ +struct axp192_pctl *pctl =pinctrl_dev_get_drvdata (pctldev); + + *pins = &pctl->desc->pins[selector].number; + *num_pins =1 ; + +return 0 ; +} + +static const struct pinctrl_ops axp192_pctrl_ops = { + .dt_node_to_map = pinconf_generic_dt_node_to_map_group, + .dt_free_map = pinconf_generic_dt_free_map, + .get_groups_count = axp192_groups_cnt, + .get_group_name = axp192_group_name, + .get_group_pins = axp192_group_pins, +}; + +static int axp192_pctl_probe (struct platform_device *pdev) +{ +struct axp20x_dev *axp20x =dev_get_drvdata (pdev->dev.parent); +struct axp192_pctl *pctl; +struct pinctrl_desc *pctrl_desc; +int ret, i; + + pctl =devm_kzalloc (&pdev->dev,sizeof (*pctl),GFP_KERNEL ); +if (!pctl) +return -ENOMEM ; + + pctl->desc =device_get_match_data (&pdev->dev); + pctl->regmap = axp20x->regmap; + pctl->regmap_irqc = axp20x->regmap_irqc; + pctl->dev = &pdev->dev; + + pctl->chip.base =-1 ; + pctl->chip.can_sleep = true; + pctl->chip.request = gpiochip_generic_request; + pctl->chip.free = gpiochip_generic_free; + pctl->chip.parent = &pdev->dev; + pctl->chip.label =dev_name (&pdev->dev); + pctl->chip.owner =THIS_MODULE ; + pctl->chip.get = axp192_gpio_get; + pctl->chip.get_direction = axp192_gpio_get_direction; + pctl->chip.set = axp192_gpio_set; + pctl->chip.direction_input = axp192_gpio_direction_input; + pctl->chip.direction_output = axp192_gpio_direction_output; + pctl->chip.to_irq = axp192_gpio_to_irq; + pctl->chip.ngpio = pctl->desc->npins; + + pctl->irqs =devm_kcalloc (&pdev->dev, pctl->desc->npins,sizeof (int ),GFP_KERNEL ); +if (!pctl->irqs) +return -ENOMEM ; + +for (i =0 ; i < pctl->desc->npins; ++i) { + ret =platform_get_irq_byname_optional (pdev, pctl->desc->pins[i].name); +if (ret >0 ) + pctl->irqs[i] = ret; + } + +platform_set_drvdata (pdev, pctl); + + pctrl_desc =devm_kzalloc (&pdev->dev,sizeof (*pctrl_desc),GFP_KERNEL ); +if (!pctrl_desc) +return -ENOMEM ; + + pctrl_desc->name =dev_name (&pdev->dev); + pctrl_desc->owner =THIS_MODULE ; + pctrl_desc->pins = pctl->desc->pins; + pctrl_desc->npins = pctl->desc->npins; + pctrl_desc->pctlops = &axp192_pctrl_ops; + pctrl_desc->pmxops = &axp192_pmx_ops; + pctrl_desc->confops = &axp192_conf_ops; + + pctl->pctl_dev =devm_pinctrl_register (&pdev->dev, pctrl_desc, pctl); +if (IS_ERR (pctl->pctl_dev)) +dev_err_probe (&pdev->dev,PTR_ERR (pctl->pctl_dev), +"couldn't register pinctrl driver\n" ); + + ret =devm_gpiochip_add_data (&pdev->dev, &pctl->chip, pctl); +if (ret) +dev_err_probe (&pdev->dev, ret,"Failed to register GPIO chip\n" ); + +return 0 ; +} + +static const struct of_device_id axp192_pctl_match[] = { + { .compatible ="x-powers,axp192-gpio" , .data = &axp192_data, }, + { } +};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 13/16] pinctrl: Add AXP192 pin control driver
Quoted 2 lines · Andy Shevchenko
On Sat, Jun 18, 2022 at 11:40 PM Aidan MacDonald
<[email protected]> wrote:
Hit 'Send' accidentally, here is the rest of the review, including previous comments.
...
Quoted 13 lines
drivers/pinctrl/Kconfig config PINCTRL_AT91PIO4 · line 119
Quoted 6 lines
drivers/pinctrl/Kconfig +4
-0+config PINCTRL_AXP192 + tristate "X-Powers AXP192 PMIC pinctrl and GPIO Support" + depends on MFD_AXP20X + depends on OFWhy?
drivers/pinctrl/Kconfig config PINCTRL_AT91PIO4 · line 122
Quoted 3 lines
drivers/pinctrl/Kconfig +3
-0+ select PINMUX + select GENERIC_PINCONF + select GPIOLIB
Quoted 6 lines
...
drivers/pinctrl/pinctrl-axp192.c line 18
Quoted 2 lines
drivers/pinctrl/pinctrl-axp192.c new file +2
-0+#include <linux/of.h> +#include <linux/of_device.h> Why?
Perhaps you missed mod_devicetable.h.
Quoted 75 lines
...
drivers/pinctrl/pinctrl-axp192.c line 42
Quoted 3 lines
drivers/pinctrl/pinctrl-axp192.c new file +3
-0+struct axp192_pctl_function { +const char *name; +/* Mux value written to the control register to select the function (-1 if unsupported) */ Comment is misleading. -1 can't be a value of unsigned type.
Quoted 4 lines
drivers/pinctrl/pinctrl-axp192.c new file +4
-0+const u8 *muxvals; +const char *const *groups; +unsigned int ngroups; +};...
drivers/pinctrl/pinctrl-axp192.c line 62
Quoted 10 lines
drivers/pinctrl/pinctrl-axp192.c new file +10
-0+struct axp192_pctl_desc { +unsigned int npins; +const struct pinctrl_pin_desc *pins; +/* Description of the function control register for each pin */ +const struct axp192_pctl_reg_info *ctrl_regs; +/* Description of the output signal register for each pin */ +const struct axp192_pctl_reg_info *out_regs; +/* Description of the input signal register for each pin */ +const struct axp192_pctl_reg_info *in_regs; +/* Description of the pull down resistor config register for each pin */ Can you just convert these comments to a kernel-doc?
Quoted 5 lines
drivers/pinctrl/pinctrl-axp192.c new file +5
-0+const struct axp192_pctl_reg_info *pull_down_regs; + +unsigned int nfunctions; +const struct axp192_pctl_function *functions; +};...
Review
Quoted 2 lines
(quoted diff) +2
-0+ +One blank line is enough.
...
drivers/pinctrl/pinctrl-axp192.c line 315
Quoted 7 lines
drivers/pinctrl/pinctrl-axp192.c new file +6
-0+switch (param) { +case PIN_CONFIG_BIAS_DISABLE : + ret =axp192_pinconf_get_pull_down (pctldev, pin); +if (ret <0 ) +return ret; +else if (ret !=0 )1. Redundant 'else'
2. if (ret > 0)drivers/pinctrl/pinctrl-axp192.c line 323
Quoted 8 lines
drivers/pinctrl/pinctrl-axp192.c new file +8
-0+return -EINVAL ; +break ; + +case PIN_CONFIG_BIAS_PULL_DOWN : + ret =axp192_pinconf_get_pull_down (pctldev, pin); +if (ret <0 ) +return ret; +else if (ret ==0 )Ditto.
Looking at this I would rather expect the function to return something defined, than 0, non-0.
drivers/pinctrl/pinctrl-axp192.c line 329
Quoted 6 lines
drivers/pinctrl/pinctrl-axp192.c new file +5
-0+return -EINVAL ; +break ; +default : +return -ENOTSUPP ; + }
Quoted 5 lines
...
Quoted 1 line
+ for (cfg = 0; cfg <
num_configs; ++cfg) {cfg++ will work the same way and easier to read.
...
You may make some lines shorter by introducing here
struct device *dev = &pdev->dev;
Quoted 1 line
Quoted 1 line
+ struct
axp20x_dev*axp20x =dev_get_drvdata(pdev->dev.parent);
dev->parent
and so on...
...
Quoted 4 lines
drivers/pinctrl/pinctrl-axp192.c line 536
Quoted 4 lines
drivers/pinctrl/pinctrl-axp192.c new file +4
-0+ pctl->pctl_dev =devm_pinctrl_register (&pdev->dev, pctrl_desc, pctl); +if (IS_ERR (pctl->pctl_dev)) +dev_err_probe (&pdev->dev,PTR_ERR (pctl->pctl_dev), +"couldn't register pinctrl driver\n" );
With the above it probably fits one line.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 13/16] pinctrl: Add AXP192 pin control driver
In reply to Aidan MacDonaldHi,
As Linus suggested you could have a look at devm_gpio_regmap_register() with a custom xlate() callback and some improvements. But I've never worked with pinctrl so I might be wrong. See below.
Quoted 6 lines
+static int
axp192_gpio_get(struct gpio_chip *chip, unsigned int offset)drivers/pinctrl/pinctrl-axp192.c new file +3
-0+{ +struct axp192_pctl *pctl =gpiochip_get_data (chip); + const struct axp192_pctl_reg_info *reginfo =&pctl->desc->in_regs[offset];
drivers/pinctrl/pinctrl-axp192.c line 225
Quoted 9 lines
drivers/pinctrl/pinctrl-axp192.c new file +9
-0+unsigned int val; +int ret; + + ret =regmap_read (pctl->regmap, reginfo->reg, &val); +if (ret) +return ret; + +return !!(val & reginfo->mask); +}
This should work.
Quoted 18 lines
(quoted diff) +2
-0+ +static int axp192_gpio_get_direction(struct gpio_chip *chip, unsignedint offset)
drivers/pinctrl/pinctrl-axp192.c new file +3
-0+{ +struct axp192_pctl *pctl =gpiochip_get_data (chip); + const struct axp192_pctl_reg_info *reginfo =&pctl->desc->ctrl_regs[offset];
(quoted diff) +1
-0+ const u8 *input_muxvals =pctl->desc->functions[AXP192_FUNC_INPUT].muxvals;
drivers/pinctrl/pinctrl-axp192.c new file +8
-0+unsigned int val; +int ret; + + ret =regmap_read (pctl->regmap, reginfo->reg, &val); +if (ret) +return ret; + + if ((val & reginfo->mask) == (input_muxvals[offset] <<(
ffs(reginfo->mask)- 1)))
drivers/pinctrl/pinctrl-axp192.c line 240
Quoted 1 line
drivers/pinctrl/pinctrl-axp192.c new file +1
-0+return GPIO_LINE_DIRECTION_IN ;
This isn't supported (yet) in gpio-regmap...
Quoted 17 lines
drivers/pinctrl/pinctrl-axp192.c new file +5
-0+ +return GPIO_LINE_DIRECTION_OUT ; +} + +static void axp192_gpio_set(struct gpio_chip *chip, unsigned intoffset, int value)
drivers/pinctrl/pinctrl-axp192.c new file +3
-0+{ +struct axp192_pctl *pctl =gpiochip_get_data (chip); + const struct axp192_pctl_reg_info *reginfo =&pctl->desc->out_regs[offset];
(quoted diff) +2
-0+ + regmap_update_bits(pctl->regmap, reginfo->reg, reginfo->mask, value?
reginfo->mask: 0);drivers/pinctrl/pinctrl-axp192.c new file +3
-0+} + +static int axp192_gpio_direction_input(struct gpio_chip *chip,unsigned int offset)
drivers/pinctrl/pinctrl-axp192.c line 256
Quoted 3 lines
drivers/pinctrl/pinctrl-axp192.c new file +3
-0+{ +return pinctrl_gpio_direction_input (chip->base + offset); +}
..as well as this.
Review
Quoted 5 lines
(quoted diff) +2
-0+ +static int axp192_gpio_direction_output(struct gpio_chip *chip,unsigned int offset, int value)
(quoted diff) +2
-0+{ + chip->set(chip, offset, value);
Why don't you call pinctrl_gpio_direction_output() here?
I *think* what is needed for gpio-regmap to support this is:
- support values and masks for the direction, for now, we only support single bits.
- support the pinctrl_gpio_direction_{input,output} calls
-michael
Re: [PATCH v3 13/16] pinctrl: Add AXP192 pin control driver
Quoted 65 lines · Michael Walle
Hi,
As Linus suggested you could have a look at
devm_gpio_regmap_register()with a customxlate()callback and some improvements. But I've never worked with pinctrl so I might be wrong. See below.drivers/pinctrl/pinctrl-axp192.c line 225
Quoted 13 lines
drivers/pinctrl/pinctrl-axp192.c new file +13
-0+static int axp192_gpio_get (struct gpio_chip *chip,unsigned int offset) +{ +struct axp192_pctl *pctl =gpiochip_get_data (chip); +const struct axp192_pctl_reg_info *reginfo = &pctl->desc->in_regs[offset]; +unsigned int val; +int ret; + + ret =regmap_read (pctl->regmap, reginfo->reg, &val); +if (ret) +return ret; + +return !!(val & reginfo->mask); +}This should work.
Quoted 17 lines
(quoted diff) +2
-0+ +static int axp192_gpio_get_direction(struct gpio_chip *chip, unsignedint offset)
drivers/pinctrl/pinctrl-axp192.c new file +3
-0+{ +struct axp192_pctl *pctl =gpiochip_get_data (chip); + const struct axp192_pctl_reg_info *reginfo =&pctl->desc->ctrl_regs[offset];
drivers/pinctrl/pinctrl-axp192.c new file +9
-0+const u8 *input_muxvals = pctl->desc->functions[AXP192_FUNC_INPUT ].muxvals; +unsigned int val; +int ret; + + ret =regmap_read (pctl->regmap, reginfo->reg, &val); +if (ret) +return ret; + + if ((val & reginfo->mask) == (input_muxvals[offset] <<(
ffs(reginfo->mask)- 1)))drivers/pinctrl/pinctrl-axp192.c line 240
Quoted 1 line
drivers/pinctrl/pinctrl-axp192.c new file +1
-0+return GPIO_LINE_DIRECTION_IN ;This isn't supported (yet) in gpio-regmap...
Quoted 16 lines
drivers/pinctrl/pinctrl-axp192.c new file +5
-0+ +return GPIO_LINE_DIRECTION_OUT ; +} + +static void axp192_gpio_set(struct gpio_chip *chip, unsigned intoffset, int value)
drivers/pinctrl/pinctrl-axp192.c new file +5
-0+{ +struct axp192_pctl *pctl =gpiochip_get_data (chip); +const struct axp192_pctl_reg_info *reginfo = &pctl->desc->out_regs[offset]; + + regmap_update_bits(pctl->regmap, reginfo->reg, reginfo->mask, value?
reginfo->mask: 0);drivers/pinctrl/pinctrl-axp192.c new file +3
-0+} + +static int axp192_gpio_direction_input(struct gpio_chip *chip,unsigned int offset)
drivers/pinctrl/pinctrl-axp192.c line 256
Quoted 3 lines
drivers/pinctrl/pinctrl-axp192.c new file +3
-0+{ +return pinctrl_gpio_direction_input (chip->base + offset); +}..as well as this.
Quoted 7 lines
Review
Quoted 5 lines
(quoted diff) +2
-0+ +static int axp192_gpio_direction_output(struct gpio_chip *chip,unsigned int offset, int value)
(quoted diff) +2
-0+{ + chip->set(chip, offset, value);Why don't you call
pinctrl_gpio_direction_output()here?
Probably because I copied this from pinctrl-axp209. I'll fix it in the next version.
Quoted 8 lines
I *think* what is needed for gpio-regmap to support this is:
- support values and masks for the direction, for now, we only support single bits.
- support the pinctrl_gpio_direction_{input,output} calls-michael
That sounds about right, thanks for taking a look.
Re: [PATCH v3 13/16] pinctrl: Add AXP192 pin control driver
Am 2022-06-27 15:12, schrieb Aidan MacDonald:
Quoted 8 lines
Quoted 6 lines
I *think* what is needed for gpio-regmap to support this is:
- support values and masks for the direction, for now, we only support single bits.
- support the pinctrl_gpio_direction_{input,output} calls-michael
That sounds about right, thanks for taking a look.
I thought you were trying to add these to gpio-regmap? Unless I'm missing something, that should be easy enough.
-michael
Re: [PATCH v3 13/16] pinctrl: Add AXP192 pin control driver
Quoted 7 lines · Michael Walle
Am 2022-06-27 15:12, schrieb Aidan MacDonald:
Quoted 5 lines
Quoted 5 lines
I *think* what is needed for gpio-regmap to support this is:
- support values and masks for the direction, for now, we only support single bits.
- support the pinctrl_gpio_direction_{input,output} calls
-michael
Quoted 6 lines
Quoted 1 line
That sounds about right, thanks for taking a look.
I thought you were trying to add these to gpio-regmap? Unless I'm missing something, that should be easy enough.
-michael
Yeah, I can send patches this weekend. One detail I missed was the to_irq() part, so I'm going to add a hook for that too.
The alternative is using hierarchical IRQ domains, but that seems like a lot of added complication when to_irq() works just as well.
PATCH v3 14/16 power: axp20x_battery: Add constant charge current table
In reply to Aidan MacDonaldAdd a table-based lookup method for constant charge current, which is necessary when the setting cannot be represented as a linear range.
This also replaces the hard-coded 300 mA default ccc setting if the DT-specified value is unsupported; the minimum value for the device is now set exactly instead of relying on the value being rounded down to a supported value.
--- drivers/power/supply/axp20x_battery.c | 60 +++++++++++++++++++++------ 1 file changed, 48 insertions(+), 12 deletions(-)
drivers/power/supply/axp20x_battery.c +48 -12
@@ -61,6 +61,14 @@ struct axp20x_batt_ps;struct axp_data {int ccc_scale;int ccc_offset; +/* +* Lookup table for constant charge current, if provided this is used +* instead of ccc_scale/ccc_offset. +* +* The table is indexed by the field AXP20X_CHRG_CTRL1_TGT_CURR so it +* must have AXP20X_CHRG_CTRL1_TGT_CURR+1 elements. +*/ +const int *ccc_table;bool has_fg_valid;int (*get_max_voltage)(struct axp20x_batt_ps *batt,int *val);int (*set_max_voltage)(struct axp20x_batt_ps *batt,int val);
@@ -176,7 +184,10 @@ static int axp20x_get_constant_charge_current(struct axp20x_batt_ps *axp, *val &=AXP20X_CHRG_CTRL1_TGT_CURR ; - *val = *val * axp->data->ccc_scale + axp->data->ccc_offset; +if (axp->data->ccc_table) + *val = axp->data->ccc_table[*val]; +else + *val = *val * axp->data->ccc_scale + axp->data->ccc_offset;return 0 ; }
@@ -389,16 +400,36 @@ static int axp20x_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt, AXP20X_CHRG_CTRL1_TGT_VOLT, val); } +static int axp20x_get_constant_charge_current_sel (struct axp20x_batt_ps *axp_batt, +int charge_current) +{ +int i; + +if (axp_batt->data->ccc_table) { +for (i =AXP20X_CHRG_CTRL1_TGT_CURR ; i >=0 ; --i) { +if (axp_batt->data->ccc_table[i] <= charge_current) +return i; + } + +return -EINVAL ; + } + + i = (charge_current - axp_batt->data->ccc_offset) / axp_batt->data->ccc_scale; + +if (i >AXP20X_CHRG_CTRL1_TGT_CURR || i <0 ) +return -EINVAL ; + +return i; +} +static int axp20x_set_constant_charge_current (struct axp20x_batt_ps *axp_batt,int charge_current) {if (charge_current > axp_batt->max_ccc)return -EINVAL ; - charge_current = (charge_current - axp_batt->data->ccc_offset) / - axp_batt->data->ccc_scale; - -if (charge_current >AXP20X_CHRG_CTRL1_TGT_CURR || charge_current <0 ) + charge_current =axp20x_get_constant_charge_current_sel (axp_batt, charge_current); +if (charge_current <0 )return -EINVAL ; return regmap_update_bits(axp_batt->regmap, AXP20X_CHRG_CTRL1,
@@ -410,14 +441,14 @@ static int axp20x_set_max_constant_charge_current(struct axp20x_batt_ps *axp, {bool lower_max = false; - charge_current = (charge_current - axp->data->ccc_offset) / - axp->data->ccc_scale; - -if (charge_current >AXP20X_CHRG_CTRL1_TGT_CURR || charge_current <0 ) + charge_current =axp20x_get_constant_charge_current_sel (axp, charge_current); +if (charge_current <0 )return -EINVAL ; - charge_current = charge_current * axp->data->ccc_scale + - axp->data->ccc_offset; +if (axp->data->ccc_table) + charge_current = axp->data->ccc_table[charge_current]; +else + charge_current = charge_current * axp->data->ccc_scale + axp->data->ccc_offset;if (charge_current > axp->max_ccc) dev_warn(axp->dev,
@@ -629,7 +660,12 @@ static int axp20x_power_probe(struct platform_device *pdev) ccc)) {dev_err (&pdev->dev,"couldn't set constant charge current from DT: fallback to minimum value\n" ); - ccc =300000 ; + +if (axp20x_batt->data->ccc_table) + ccc = axp20x_batt->data->ccc_table[0 ]; +else + ccc = axp20x_batt->data->ccc_offset; + axp20x_batt->max_ccc = ccc;axp20x_set_constant_charge_current (axp20x_batt, ccc); }
Signature · 1 line
2.35.1
Re: [PATCH v3 14/16] power: axp20x_battery: Add constant charge current table
Quoted 9 lines · Aidan MacDonald
Add a table-based lookup method for constant charge current, which is necessary when the setting cannot be represented as a linear range.
This also replaces the hard-coded 300 mA default ccc setting if the DT-specified value is unsupported; the minimum value for the device is now set exactly instead of relying on the value being rounded down to a supported value.
...
drivers/power/supply/axp20x_battery.c static int axp20x_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt, · line 409
Quoted 7 lines
drivers/power/supply/axp20x_battery.c +7
-0+static int axp20x_get_constant_charge_current_sel (struct axp20x_batt_ps *axp_batt, +int charge_current) +{ +int i; + +if (axp_batt->data->ccc_table) { +for (i =AXP20X_CHRG_CTRL1_TGT_CURR ; i >=0 ; --i) {
i-- should give the same result.
drivers/power/supply/axp20x_battery.c static int axp20x_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt,
Quoted 10 lines
drivers/power/supply/axp20x_battery.c +8
-0+if (axp_batt->data->ccc_table[i] <= charge_current) +return i; + } + +return -EINVAL ; + } + i = (charge_current - axp_batt->data->ccc_offset) / axp_batt->data->ccc_scale; +
No need to have a blank line here.
Quoted 5 lines
drivers/power/supply/axp20x_battery.c +5
-0+if (i >AXP20X_CHRG_CTRL1_TGT_CURR || i <0 ) +return -EINVAL ; + +return i; +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v3 15/16 power: axp20x_battery: Support battery status without fuel gauge
In reply to Aidan MacDonaldAdd a "has_fg" flag to indicate that the chip has a fuel gauge. Report battery full status on chips with no fuel gauge using the battery voltage.
--- drivers/power/supply/axp20x_battery.c | 34 ++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
drivers/power/supply/axp20x_battery.c +33 -1
@@ -69,6 +69,7 @@ struct axp_data {* must have AXP20X_CHRG_CTRL1_TGT_CURR+1 elements. */ const int *ccc_table; +bool has_fg;bool has_fg_valid;int (*get_max_voltage)(struct axp20x_batt_ps *batt,int *val);int (*set_max_voltage)(struct axp20x_batt_ps *batt,int val);
@@ -197,7 +198,7 @@ static int axp20x_battery_get_prop(struct power_supply *psy, union power_supply_propval *val) {struct axp20x_batt_ps *axp20x_batt =power_supply_get_drvdata (psy); -int ret =0 , reg, val1; +int ret =0 , reg, val1, val2;switch (psp) {case POWER_SUPPLY_PROP_PRESENT :
@@ -231,6 +232,34 @@ static int axp20x_battery_get_prop(struct power_supply *psy,return 0 ; } +/* +* If the chip does not have a fuel gauge, we check battery full status +* using voltage instead. +*/ +if (!axp20x_batt->data->has_fg) { + ret = axp20x_batt->data->get_max_voltage (axp20x_batt, &val1); +if (ret) +return ret; + + ret =iio_read_channel_processed (axp20x_batt->batt_v, &val2); +if (ret) +return ret; + +/* IIO subsystem reports voltage in mV but we need uV */ + val2 *=1000 ; + +/* +* According to the AXP192 datasheet, charging will restart if +* the battery voltage drops below V_rch = V_tgt - 0.1 V, so we +* report the battery is full if its voltage is at least V_rch. +*/ +if (val2 >= val1 -100000 ) + val->intval =POWER_SUPPLY_STATUS_FULL ; +else + val->intval =POWER_SUPPLY_STATUS_NOT_CHARGING ; +break ; + } + ret =regmap_read (axp20x_batt->regmap,AXP20X_FG_RES , &val1);if (ret)return ret;
@@ -553,6 +582,7 @@ static const struct power_supply_desc axp20x_batt_ps_desc = {static const struct axp_data axp209_data = { .ccc_scale =100000 , .ccc_offset =300000 , + .has_fg = true, .get_max_voltage = axp20x_battery_get_max_voltage, .set_max_voltage = axp20x_battery_set_max_voltage, };
@@ -560,6 +590,7 @@ static const struct axp_data axp209_data = {static const struct axp_data axp221_data = { .ccc_scale =150000 , .ccc_offset =300000 , + .has_fg = true, .has_fg_valid = true, .get_max_voltage = axp22x_battery_get_max_voltage, .set_max_voltage = axp22x_battery_set_max_voltage,
@@ -568,6 +599,7 @@ static const struct axp_data axp221_data = {static const struct axp_data axp813_data = { .ccc_scale =200000 , .ccc_offset =200000 , + .has_fg = true, .has_fg_valid = true, .get_max_voltage = axp813_battery_get_max_voltage, .set_max_voltage = axp20x_battery_set_max_voltage,
Signature · 1 line
2.35.1
PATCH v3 16/16 power: axp20x_battery: Add support for AXP192
In reply to Aidan MacDonaldThe AXP192 has a battery charger similar to other X-Powers PMICs, but unlike the other supported devices, it does not have a fuel gauge and can't report battery capacity directly.
--- drivers/power/supply/axp20x_battery.c | 49 +++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-)
drivers/power/supply/axp20x_battery.c +46 -3
@@ -545,6 +545,19 @@ static int axp20x_battery_set_prop(struct power_supply *psy, } } +static enum power_supply_property axp192_battery_props[] = { +POWER_SUPPLY_PROP_PRESENT , +POWER_SUPPLY_PROP_ONLINE , +POWER_SUPPLY_PROP_STATUS , +POWER_SUPPLY_PROP_VOLTAGE_NOW , +POWER_SUPPLY_PROP_CURRENT_NOW , +POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT , +POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX , +POWER_SUPPLY_PROP_HEALTH , +POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN , +POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN , +}; +static enum power_supply_property axp20x_battery_props[] = {POWER_SUPPLY_PROP_PRESENT ,POWER_SUPPLY_PROP_ONLINE ,
@@ -569,6 +582,16 @@ static int axp20x_battery_prop_writeable(struct power_supply *psy, psp ==POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX ; } +static const struct power_supply_desc axp192_batt_ps_desc = { + .name ="axp192-battery" , + .type =POWER_SUPPLY_TYPE_BATTERY , + .properties = axp192_battery_props, + .num_properties =ARRAY_SIZE (axp192_battery_props), + .property_is_writeable = axp20x_battery_prop_writeable, + .get_property = axp20x_battery_get_prop, + .set_property = axp20x_battery_set_prop, +}; +static const struct power_supply_desc axp20x_batt_ps_desc = { .name ="axp20x-battery" , .type =POWER_SUPPLY_TYPE_BATTERY ,
@@ -579,6 +602,19 @@ static const struct power_supply_desc axp20x_batt_ps_desc = { .set_property = axp20x_battery_set_prop, }; +static const int axp192_ccc_table[AXP20X_CHRG_CTRL1_TGT_CURR +1 ] = { +100000 ,190000 ,280000 ,360000 , +450000 ,550000 ,630000 ,700000 , +780000 ,880000 ,960000 ,1000000 , +1080000 ,1160000 ,1240000 ,1320000 , +}; + +static const struct axp_data axp192_data = { + .ccc_table = axp192_ccc_table, + .get_max_voltage = axp20x_battery_get_max_voltage, + .set_max_voltage = axp20x_battery_set_max_voltage, +}; +static const struct axp_data axp209_data = { .ccc_scale =100000 , .ccc_offset =300000 ,
@@ -607,6 +643,9 @@ static const struct axp_data axp813_data = {static const struct of_device_id axp20x_battery_ps_id[] = { { + .compatible ="x-powers,axp192-battery-power-supply" , + .data = (void *)&axp192_data, + }, { .compatible ="x-powers,axp209-battery-power-supply" , .data = (void *)&axp209_data, }, {
@@ -624,6 +663,7 @@ static int axp20x_power_probe(struct platform_device *pdev)struct axp20x_batt_ps *axp20x_batt;struct power_supply_config psy_cfg = {};struct power_supply_battery_info *info; +const struct power_supply_desc *ps_desc;struct device *dev = &pdev->dev;if (!of_device_is_available (pdev->dev.of_node))
@@ -667,9 +707,12 @@ static int axp20x_power_probe(struct platform_device *pdev) axp20x_batt->data = (struct axp_data *)of_device_get_match_data (dev); - axp20x_batt->batt =devm_power_supply_register (&pdev->dev, - &axp20x_batt_ps_desc, - &psy_cfg); +if (!axp20x_batt->data->has_fg) + ps_desc = &axp192_batt_ps_desc; +else + ps_desc = &axp20x_batt_ps_desc; + + axp20x_batt->batt =devm_power_supply_register (&pdev->dev, ps_desc, &psy_cfg);if (IS_ERR (axp20x_batt->batt)) {dev_err (&pdev->dev,"failed to register power supply: %ld\n" ,PTR_ERR (axp20x_batt->batt));
Signature · 1 line
2.35.1
A message that is not in the archive (sent off-list or not yet received): CAHp75VfrzQFq4u0vMtPM7LRYNcQQC-padQ1yyFijbpWx8_LwBQ@mail.gmail.com
Jonathan Cameron
maintainerQuoted 5 lines · On Sun, 19 Jun 2022 00:43:07 +0200 Andy Shevchenko <[email protected]>…
Quoted 2 lines · Aidan MacDonald
Changes in v3:
Quoted 7 lines
Quoted 2 lines
* Update pinctrl driver to address Andy Shevchenko's review comments from v1, and fix a few other
I believe I gave more comments than just against pin control driver. Even though, some comments are still not addressed in the series, including pin control. Am I mistaken?
Hi Andy,
Maybe, it's a question of clarity/misunderstanding? You had some 'global' comments at the end of the pinctrl review. Perhaps not clear enough you meant they should apply to the rest of the patch series (and more generally to the driver being modified I think).
Just guessing!
Jonathan
Quoted 94 lines
Quoted 93 lines
* Add gpio-ranges property and example snippet to gpio DT bindings.
* Update commit message of patch 01/16 to point out that all register addresses are obtained usingsub_irq_reg().
* Documentccc_tableinaxp20x_battery. Also update commit message to note a small fix that is part of that patch.
* Dropaxp20x_adcconsolidation patch in favor of using separateadc_rawfunctions. It's a minor code size optimization that may not be worth the effort due to implementation complexity.
* Use theFIELD_GETmacro inaxp20x_adcto further clarify intent.
* Fix a typo in the regulator driver where an AXP20X regulator ID was mistakenly used instead of an AXP192 regulator ID. Also carry over an Acked-by: tag from v1. Hope that's okay.
* Accumulate Acked-by: tags from v1 on DT patches.
* Accumulate Acked-by: tags from v2.Note that regmap maintainer Mark Brown has said the first two patches to regmap-irq aren't suitable for inclusion into the kernel in their current state. I'm including them for v3 so the series remains testable.
Changes in v2:
* Do a little cleanup of
axp20x_adcsuggested by Jonathan Cameron
* Consolidate ADC read functions inaxp20x_adc
* Drop the axp192'sread_labelcallback inaxp20x_adc
* Clean up the axp192-gpio dt bindings
* Rewrite a problematic bit of code inaxp20x_usb_powerreported by kernel test robot
* Support AXP192 inaxp20x_battery
* Split up regmap-irq changes to two separate patchesCover letter from v1:
Hi all,
This patch series adds support for the X-Powers AXP192 PMIC to the AXP20x driver framework.
The first patch is a small change to regmap-irq to support the AXP192's unusual IRQ register layout. It isn't possible to include all of the IRQ registers in one regmap-irq chip without this.
The rest of the changes are pretty straightforward, I think the only notable parts are the
axp20x_adcdriver where there seems to be some opportunities for code reuse (the axp192 is nearly a duplicate of the axp20x) and the addition of a new pinctrl driver for the axp192, since the axp20x pinctrl driver was not very easy to adapt.Aidan MacDonald (16):
regmap-irq: Usesub_irq_reg()to calculate unmask register address
regmap-irq: Addget_irq_regto support unusual register layouts
dt-bindings: mfd: add bindings for AXP192 MFD device
dt-bindings: iio: adc: axp209: Add AXP192 compatible
dt-bindings: power: supply: axp20x: Add AXP192 compatible
dt-bindings: gpio: Add AXP192 GPIO bindings
dt-bindings: power: axp20x-battery: Add AXP192 compatible
mfd: axp20x: Add support for AXP192
regulator: axp20x: Add support for AXP192
iio: adc:axp20x_adc: Minor code cleanups
iio: adc:axp20x_adc: Add support for AXP192
power: supply:axp20x_usb_power: Add support for AXP192
pinctrl: Add AXP192 pin control driver
power:axp20x_battery: Add constant charge current table
power:axp20x_battery: Support battery status without fuel gauge
power:axp20x_battery: Add support for AXP192.../bindings/gpio/x-powers,axp192-gpio.yaml | 68 +++ .../bindings/iio/adc/x-powers,axp209-adc.yaml | 18 + .../bindings/mfd/x-powers,axp152.yaml | 1 + .../x-powers,axp20x-battery-power-supply.yaml | 1 + .../x-powers,axp20x-usb-power-supply.yaml | 1 + drivers/base/regmap/regmap-irq.c | 19 +- drivers/iio/adc/axp20x_adc.c | 359 +++++++++-- drivers/mfd/axp20x-i2c.c | 2 + drivers/mfd/axp20x.c | 153 +++++ drivers/pinctrl/Kconfig | 14 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-axp192.c | 562 ++++++++++++++++++ drivers/power/supply/axp20x_battery.c | 143 ++++- drivers/power/supply/axp20x_usb_power.c | 80 ++- drivers/regulator/axp20x-regulator.c | 101 +++- include/linux/mfd/axp20x.h | 84 +++ include/linux/regmap.h | 5 + 17 files changed, 1529 insertions(+), 83 deletions(-) create mode 100644 Documentation/devicetree/ bindings/gpio/x-powers,axp192-gpio.yaml create mode 100644 drivers/pinctrl/pinctrl-axp192.c--
2.35.1
Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Sun, 19 Jun 2022 00:43:07 +0200 Andy Shevchenko <[email protected]>…
Quoted 4 lines · Aidan MacDonald
Changes in v3:
* Update pinctrl driver to address Andy Shevchenko's review comments from v1, and fix a few other
I believe I gave more comments than just against pin control driver. Even though, some comments are still not addressed in the series, including pin control. Am I mistaken?
Quoted 6 lines
Hi Andy,
Maybe, it's a question of clarity/misunderstanding? You had some 'global' comments at the end of the pinctrl review. Perhaps not clear enough you meant they should apply to the rest of the patch series (and more generally to the driver being modified I think).
Yeah, I think that is.
I don't remember if we have somewhere a documentation on how to respond to the review comments, in which the point of addressing comment everywhere in the series, and not only in the place(s) where it was given.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 22 lines · Andy Shevchenko
Quoted 14 lines · Jonathan Cameron
Quoted 11 lines · On Sun, 19 Jun 2022 00:43:07 +0200 Andy Shevchenko <[email protected]>…
Quoted 4 lines · Aidan MacDonald
Changes in v3:
* Update pinctrl driver to address Andy Shevchenko's review comments from v1, and fix a few other
I believe I gave more comments than just against pin control driver. Even though, some comments are still not addressed in the series, including pin control. Am I mistaken?
Quoted 6 lines
Hi Andy,
Maybe, it's a question of clarity/misunderstanding? You had some 'global' comments at the end of the pinctrl review. Perhaps not clear enough you meant they should apply to the rest of the patch series (and more generally to the driver being modified I think).
Quoted 5 lines
Yeah, I think that is.
I don't remember if we have somewhere a documentation on how to respond to the review comments, in which the point of addressing comment everywhere in the series, and not only in the place(s) where it was given.
That's exactly it, I was only looking at the pinctrl patch since that's the one you replied to, and didn't think to check the other patches for similar cases even though that's obvious in retrospect. Sorry for any confusion.