Re: [PATCH 06/10] mfd: axp20x: Add support for AXP192

From: Lee Jones
Date: Mon Jun 27 2022 - 08:03:22 EST


On Fri, 03 Jun 2022, Aidan MacDonald wrote:

> The AXP192 PMIC is similar to the AXP202/AXP209, but with different
> regulators, additional GPIOs, and a different IRQ register layout.
>
> Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@xxxxxxxxx>
> ---
> drivers/mfd/axp20x-i2c.c | 2 +
> drivers/mfd/axp20x.c | 150 +++++++++++++++++++++++++++++++++++++
> include/linux/mfd/axp20x.h | 84 +++++++++++++++++++++
> 3 files changed, 236 insertions(+)
>
> diff --git a/drivers/mfd/axp20x-i2c.c b/drivers/mfd/axp20x-i2c.c
> index 00ab48018d8d..9ada58fad77f 100644
> --- a/drivers/mfd/axp20x-i2c.c
> +++ b/drivers/mfd/axp20x-i2c.c
> @@ -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 },
> diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
> index 8161a5dc68e8..7f64e5c83fe2 100644
> --- a/drivers/mfd/axp20x.c
> +++ b/drivers/mfd/axp20x.c
> @@ -34,6 +34,7 @@
>
> static const char * const axp20x_model_names[] = {
> "AXP152",
> + "AXP192",
> "AXP202",
> "AXP209",
> "AXP221",
> @@ -92,6 +93,35 @@ static const struct regmap_access_table axp20x_volatile_table = {
> .n_yes_ranges = ARRAY_SIZE(axp20x_volatile_ranges),
> };
>
> +static const struct regmap_range axp192_writeable_ranges[] = {
> + regmap_reg_range(AXP192_DATACACHE(0), AXP192_DATACACHE(5)),
> + regmap_reg_range(AXP192_PWR_OUT_CTRL, AXP192_IRQ5_STATE),
> + regmap_reg_range(AXP20X_DCDC_MODE, AXP192_N_RSTO_CTRL),
> + regmap_reg_range(AXP20X_CC_CTRL, AXP20X_CC_CTRL),
> +};
> +
> +static const struct regmap_range axp192_volatile_ranges[] = {
> + regmap_reg_range(AXP20X_PWR_INPUT_STATUS, AXP192_USB_OTG_STATUS),
> + regmap_reg_range(AXP192_IRQ1_STATE, AXP192_IRQ4_STATE),
> + regmap_reg_range(AXP192_IRQ5_STATE, AXP192_IRQ5_STATE),
> + regmap_reg_range(AXP20X_ACIN_V_ADC_H, AXP20X_IPSOUT_V_HIGH_L),
> + regmap_reg_range(AXP20X_TIMER_CTRL, AXP20X_TIMER_CTRL),
> + regmap_reg_range(AXP192_GPIO2_0_STATE, AXP192_GPIO2_0_STATE),
> + regmap_reg_range(AXP192_GPIO4_3_STATE, AXP192_GPIO4_3_STATE),
> + regmap_reg_range(AXP192_N_RSTO_CTRL, AXP192_N_RSTO_CTRL),
> + regmap_reg_range(AXP20X_CHRG_CC_31_24, AXP20X_CC_CTRL),
> +};
> +
> +static const struct regmap_access_table axp192_writeable_table = {
> + .yes_ranges = axp192_writeable_ranges,
> + .n_yes_ranges = ARRAY_SIZE(axp192_writeable_ranges),
> +};
> +
> +static const struct regmap_access_table axp192_volatile_table = {
> + .yes_ranges = axp192_volatile_ranges,
> + .n_yes_ranges = ARRAY_SIZE(axp192_volatile_ranges),
> +};
> +
> /* AXP22x ranges are shared with the AXP809, as they cover the same range */
> static const struct regmap_range axp22x_writeable_ranges[] = {
> regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ5_STATE),
> @@ -173,6 +203,25 @@ static const struct resource axp152_pek_resources[] = {
> DEFINE_RES_IRQ_NAMED(AXP152_IRQ_PEK_FAL_EDGE, "PEK_DBF"),
> };
>
> +static const struct resource axp192_gpio_resources[] = {
> + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_GPIO0_INPUT, "GPIO0"),
> + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_GPIO1_INPUT, "GPIO1"),
> + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_GPIO2_INPUT, "GPIO2"),
> +};
> +
> +static const struct resource axp192_ac_power_supply_resources[] = {
> + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_ACIN_PLUGIN, "ACIN_PLUGIN"),
> + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_ACIN_REMOVAL, "ACIN_REMOVAL"),
> + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_ACIN_OVER_V, "ACIN_OVER_V"),
> +};
> +
> +static const struct resource axp192_usb_power_supply_resources[] = {
> + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_PLUGIN, "VBUS_PLUGIN"),
> + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_REMOVAL, "VBUS_REMOVAL"),
> + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_VALID, "VBUS_VALID"),
> + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_NOT_VALID, "VBUS_NOT_VALID"),
> +};
> +
> static const struct resource axp20x_ac_power_supply_resources[] = {
> DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_ACIN_PLUGIN, "ACIN_PLUGIN"),
> DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_ACIN_REMOVAL, "ACIN_REMOVAL"),
> @@ -245,6 +294,15 @@ static const struct regmap_config axp152_regmap_config = {
> .cache_type = REGCACHE_RBTREE,
> };
>
> +static const struct regmap_config axp192_regmap_config = {
> + .reg_bits = 8,
> + .val_bits = 8,
> + .wr_table = &axp192_writeable_table,
> + .volatile_table = &axp192_volatile_table,
> + .max_register = AXP20X_CC_CTRL,
> + .cache_type = REGCACHE_RBTREE,
> +};
> +
> static const struct regmap_config axp20x_regmap_config = {
> .reg_bits = 8,
> .val_bits = 8,
> @@ -304,6 +362,55 @@ static const struct regmap_irq axp152_regmap_irqs[] = {
> INIT_REGMAP_IRQ(AXP152, GPIO0_INPUT, 2, 0),
> };
>
> +static const struct regmap_irq axp192_regmap_irqs[] = {
> + INIT_REGMAP_IRQ(AXP192, ACIN_OVER_V, 0, 7),
> + INIT_REGMAP_IRQ(AXP192, ACIN_PLUGIN, 0, 6),
> + INIT_REGMAP_IRQ(AXP192, ACIN_REMOVAL, 0, 5),
> + INIT_REGMAP_IRQ(AXP192, VBUS_OVER_V, 0, 4),
> + INIT_REGMAP_IRQ(AXP192, VBUS_PLUGIN, 0, 3),
> + INIT_REGMAP_IRQ(AXP192, VBUS_REMOVAL, 0, 2),
> + INIT_REGMAP_IRQ(AXP192, VBUS_V_LOW, 0, 1),
> + INIT_REGMAP_IRQ(AXP192, BATT_PLUGIN, 1, 7),
> + INIT_REGMAP_IRQ(AXP192, BATT_REMOVAL, 1, 6),
> + INIT_REGMAP_IRQ(AXP192, BATT_ENT_ACT_MODE, 1, 5),
> + INIT_REGMAP_IRQ(AXP192, BATT_EXIT_ACT_MODE, 1, 4),
> + INIT_REGMAP_IRQ(AXP192, CHARG, 1, 3),
> + INIT_REGMAP_IRQ(AXP192, CHARG_DONE, 1, 2),
> + INIT_REGMAP_IRQ(AXP192, BATT_TEMP_HIGH, 1, 1),
> + INIT_REGMAP_IRQ(AXP192, BATT_TEMP_LOW, 1, 0),
> + INIT_REGMAP_IRQ(AXP192, DIE_TEMP_HIGH, 2, 7),
> + INIT_REGMAP_IRQ(AXP192, CHARG_I_LOW, 2, 6),
> + INIT_REGMAP_IRQ(AXP192, DCDC1_V_LONG, 2, 5),
> + INIT_REGMAP_IRQ(AXP192, DCDC2_V_LONG, 2, 4),
> + INIT_REGMAP_IRQ(AXP192, DCDC3_V_LONG, 2, 3),
> + INIT_REGMAP_IRQ(AXP192, PEK_SHORT, 2, 1),
> + INIT_REGMAP_IRQ(AXP192, PEK_LONG, 2, 0),
> + INIT_REGMAP_IRQ(AXP192, N_OE_PWR_ON, 3, 7),
> + INIT_REGMAP_IRQ(AXP192, N_OE_PWR_OFF, 3, 6),
> + INIT_REGMAP_IRQ(AXP192, VBUS_VALID, 3, 5),
> + INIT_REGMAP_IRQ(AXP192, VBUS_NOT_VALID, 3, 4),
> + INIT_REGMAP_IRQ(AXP192, VBUS_SESS_VALID, 3, 3),
> + INIT_REGMAP_IRQ(AXP192, VBUS_SESS_END, 3, 2),
> + INIT_REGMAP_IRQ(AXP192, LOW_PWR_LVL, 3, 0),
> + INIT_REGMAP_IRQ(AXP192, TIMER, 4, 7),
> + INIT_REGMAP_IRQ(AXP192, GPIO2_INPUT, 4, 2),
> + INIT_REGMAP_IRQ(AXP192, GPIO1_INPUT, 4, 1),
> + INIT_REGMAP_IRQ(AXP192, GPIO0_INPUT, 4, 0),
> +};
> +
> +static int axp192_get_irq_reg(unsigned int base_reg, int i)

Nit: If you have to respin this set, please rename 'i'.

Unless used as an iterator, 'i' is a terrible variable name.

> +{
> + /* 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
> + return AXP192_IRQ5_STATE;
> +}
> +
> static const struct regmap_irq axp20x_regmap_irqs[] = {
> INIT_REGMAP_IRQ(AXP20X, ACIN_OVER_V, 0, 7),
> INIT_REGMAP_IRQ(AXP20X, ACIN_PLUGIN, 0, 6),
> @@ -514,6 +621,19 @@ static const struct regmap_irq_chip axp152_regmap_irq_chip = {
> .num_regs = 3,
> };
>
> +static const struct regmap_irq_chip axp192_regmap_irq_chip = {
> + .name = "axp192_irq_chip",
> + .status_base = AXP192_IRQ1_STATE,
> + .ack_base = AXP192_IRQ1_STATE,
> + .mask_base = AXP192_IRQ1_EN,
> + .mask_invert = true,
> + .init_ack_masked = true,
> + .irqs = axp192_regmap_irqs,
> + .num_irqs = ARRAY_SIZE(axp192_regmap_irqs),
> + .num_regs = 5,
> + .get_irq_reg = axp192_get_irq_reg,
> +};
> +
> static const struct regmap_irq_chip axp20x_regmap_irq_chip = {
> .name = "axp20x_irq_chip",
> .status_base = AXP20X_IRQ1_STATE,
> @@ -588,6 +708,30 @@ static const struct regmap_irq_chip axp809_regmap_irq_chip = {
> .num_regs = 5,
> };
>
> +static const struct mfd_cell axp192_cells[] = {
> + {
> + .name = "axp192-gpio",
> + .of_compatible = "x-powers,axp192-gpio",
> + .num_resources = ARRAY_SIZE(axp192_gpio_resources),
> + .resources = axp192_gpio_resources,
> + }, {
> + .name = "axp20x-regulator",

Nit: Is it possible to put one line entries at the bottom?

And format like this:

{ .name = "axp20x-regulator" }

> + }, {
> + .name = "axp192-adc",
> + .of_compatible = "x-powers,axp192-adc",
> + }, {
> + .name = "axp20x-ac-power-supply",
> + .of_compatible = "x-powers,axp202-ac-power-supply",
> + .num_resources = ARRAY_SIZE(axp192_ac_power_supply_resources),
> + .resources = axp192_ac_power_supply_resources,
> + }, {
> + .name = "axp20x-usb-power-supply",
> + .of_compatible = "x-powers,axp192-usb-power-supply",
> + .num_resources = ARRAY_SIZE(axp192_usb_power_supply_resources),
> + .resources = axp192_usb_power_supply_resources,
> + }
> +};

For my own reference (apply this as-is to your sign-off block):

Acked-for-MFD-by: Lee Jones <lee.jones@xxxxxxxxxx>

--
Lee Jones [李琼斯]
Principal Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog