[PATCH v2 3/5] mfd: axp20x: Allow multiple regulators

Andre Przywara posted 5 patches 1 year, 4 months ago
[PATCH v2 3/5] mfd: axp20x: Allow multiple regulators
Posted by Andre Przywara 1 year, 4 months ago
At the moment trying to register a second AXP chip makes the probe fail,
as some sysfs registration fails due to a duplicate name:

...
[    3.688215] axp20x-i2c 0-0035: AXP20X driver loaded
[    3.695610] axp20x-i2c 0-0036: AXP20x variant AXP323 found
[    3.706151] sysfs: cannot create duplicate filename '/bus/platform/devices/axp20x-regulator'
[    3.714718] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.12.0-rc1-00026-g50bf2e2c079d-dirty #192
[    3.724020] Hardware name: Avaota A1 (DT)
[    3.728029] Call trace:
[    3.730477]  dump_backtrace+0x94/0xec
[    3.734146]  show_stack+0x18/0x24
[    3.737462]  dump_stack_lvl+0x80/0xf4
[    3.741128]  dump_stack+0x18/0x24
[    3.744444]  sysfs_warn_dup+0x64/0x80
[    3.748109]  sysfs_do_create_link_sd+0xf0/0xf8
[    3.752553]  sysfs_create_link+0x20/0x40
[    3.756476]  bus_add_device+0x64/0x104
[    3.760229]  device_add+0x310/0x760
[    3.763717]  platform_device_add+0x10c/0x238
[    3.767990]  mfd_add_device+0x4ec/0x5c8
[    3.771829]  mfd_add_devices+0x88/0x11c
[    3.775666]  axp20x_device_probe+0x70/0x184
[    3.779851]  axp20x_i2c_probe+0x9c/0xd8
...

This is because we use PLATFORM_DEVID_NONE for the mfd_add_devices()
call, which would number the child devices in the same 0-based way, even
for the second (or any other) instance.

Use PLATFORM_DEVID_AUTO instead, which automatically assigns
non-conflicting device numbers.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/mfd/axp20x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
index 5ceea359289f4..bc08ae4332604 100644
--- a/drivers/mfd/axp20x.c
+++ b/drivers/mfd/axp20x.c
@@ -1419,7 +1419,7 @@ int axp20x_device_probe(struct axp20x_dev *axp20x)
 		}
 	}
 
-	ret = mfd_add_devices(axp20x->dev, -1, axp20x->cells,
+	ret = mfd_add_devices(axp20x->dev, PLATFORM_DEVID_AUTO, axp20x->cells,
 			      axp20x->nr_cells, NULL, 0, NULL);
 
 	if (ret) {
-- 
2.46.2
Re: [PATCH v2 3/5] mfd: axp20x: Allow multiple regulators
Posted by Chris Morgan 1 year, 2 months ago
On Mon, Oct 07, 2024 at 01:14:06AM +0100, Andre Przywara wrote:
> At the moment trying to register a second AXP chip makes the probe fail,
> as some sysfs registration fails due to a duplicate name:
> 
> ...
> [    3.688215] axp20x-i2c 0-0035: AXP20X driver loaded
> [    3.695610] axp20x-i2c 0-0036: AXP20x variant AXP323 found
> [    3.706151] sysfs: cannot create duplicate filename '/bus/platform/devices/axp20x-regulator'
> [    3.714718] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.12.0-rc1-00026-g50bf2e2c079d-dirty #192
> [    3.724020] Hardware name: Avaota A1 (DT)
> [    3.728029] Call trace:
> [    3.730477]  dump_backtrace+0x94/0xec
> [    3.734146]  show_stack+0x18/0x24
> [    3.737462]  dump_stack_lvl+0x80/0xf4
> [    3.741128]  dump_stack+0x18/0x24
> [    3.744444]  sysfs_warn_dup+0x64/0x80
> [    3.748109]  sysfs_do_create_link_sd+0xf0/0xf8
> [    3.752553]  sysfs_create_link+0x20/0x40
> [    3.756476]  bus_add_device+0x64/0x104
> [    3.760229]  device_add+0x310/0x760
> [    3.763717]  platform_device_add+0x10c/0x238
> [    3.767990]  mfd_add_device+0x4ec/0x5c8
> [    3.771829]  mfd_add_devices+0x88/0x11c
> [    3.775666]  axp20x_device_probe+0x70/0x184
> [    3.779851]  axp20x_i2c_probe+0x9c/0xd8
> ...
> 
> This is because we use PLATFORM_DEVID_NONE for the mfd_add_devices()
> call, which would number the child devices in the same 0-based way, even
> for the second (or any other) instance.
> 
> Use PLATFORM_DEVID_AUTO instead, which automatically assigns
> non-conflicting device numbers.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> Reviewed-by: Chen-Yu Tsai <wens@csie.org>
> ---
>  drivers/mfd/axp20x.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
> index 5ceea359289f4..bc08ae4332604 100644
> --- a/drivers/mfd/axp20x.c
> +++ b/drivers/mfd/axp20x.c
> @@ -1419,7 +1419,7 @@ int axp20x_device_probe(struct axp20x_dev *axp20x)
>  		}
>  	}
>  
> -	ret = mfd_add_devices(axp20x->dev, -1, axp20x->cells,
> +	ret = mfd_add_devices(axp20x->dev, PLATFORM_DEVID_AUTO, axp20x->cells,
>  			      axp20x->nr_cells, NULL, 0, NULL);
>  
>  	if (ret) {
> -- 
> 2.46.2
> 

Using git bisect, I found that this patch breaks the CONFIG_AXP20X_ADC
option which is used by some of the battery and charger drivers for the
axp20x PMIC series. My current assumption is that the
devm_iio_channel_get() call made by these drivers worked correctly
previously when the PLATFORM_DEVID_NONE, but now it's not working
anymore. I'm still testing possible solutions for that problem.

Thank you,
Chris
Re: [PATCH v2 3/5] mfd: axp20x: Allow multiple regulators
Posted by Vasily Khoruzhick 1 year, 1 month ago
On Sat, Dec 7, 2024 at 9:45 AM Chris Morgan <macroalpha82@gmail.com> wrote:

> Using git bisect, I found that this patch breaks the CONFIG_AXP20X_ADC
> option which is used by some of the battery and charger drivers for the
> axp20x PMIC series. My current assumption is that the
> devm_iio_channel_get() call made by these drivers worked correctly
> previously when the PLATFORM_DEVID_NONE, but now it's not working
> anymore. I'm still testing possible solutions for that problem.

I confirm that this patch breaks the battery driver on Pinebook (and
likely Pinephone). Reverting it fixes the issue for me.

> Thank you,
> Chris
>
Re: [PATCH v2 3/5] mfd: axp20x: Allow multiple regulators
Posted by Andrey Skvortsov 1 year, 1 month ago
Hi,

On 24-12-27 14:34, Vasily Khoruzhick wrote:
> On Sat, Dec 7, 2024 at 9:45 AM Chris Morgan <macroalpha82@gmail.com> wrote:
> 
> > Using git bisect, I found that this patch breaks the CONFIG_AXP20X_ADC
> > option which is used by some of the battery and charger drivers for the
> > axp20x PMIC series. My current assumption is that the
> > devm_iio_channel_get() call made by these drivers worked correctly
> > previously when the PLATFORM_DEVID_NONE, but now it's not working
> > anymore. I'm still testing possible solutions for that problem.
> 
> I confirm that this patch breaks the battery driver on Pinebook (and
> likely Pinephone). Reverting it fixes the issue for me.
> 

git bisect pointed me to this commit, when I've investigated why
battery power supply stopped working on PinePhone.

The problem is that devm_iio_channel_get() can't get channel by name,
since consumer's name has changed (from "axp20x-battery-power-supply" to
"axp20x-battery-power-supply.4.auto") and axp20x_adc has hardcoded
consumer dev names [1].

For other readers of this thread there is related discussion here. [2]
Chris, do you work on another solution of this problem?

1. https://elixir.bootlin.com/linux/v6.12.4/source/drivers/iio/adc/axp20x_adc.c#L176
2. https://lore.kernel.org/all/20241210224859.58917-1-macroalpha82@gmail.com/#t

-- 
Best regards,
Andrey Skvortsov