All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Morgan <macroalpha82@gmail.com>
To: Chen-Yu Tsai <wens@csie.org>
Cc: Jonathan Cameron <jic23@kernel.org>,
	linux-pm@vger.kernel.org, linux-iio@vger.kernel.org,
	andre.przywara@arm.com, lee@kernel.org, sre@kernel.org,
	lars@metafoo.de, Chris Morgan <macromorgan@hotmail.com>
Subject: Re: [PATCH 0/2] Fix Regression with AXP20X for 6.13-rc1
Date: Tue, 4 Mar 2025 12:18:10 -0600	[thread overview]
Message-ID: <67c743e3.050a0220.327e31.55b3@mx.google.com> (raw)
In-Reply-To: <CAGb2v64vn-h02Bn2AKftphpNNcx9h9K3pKvdjuANsDhwiqbsrQ@mail.gmail.com>

On Tue, Dec 17, 2024 at 02:04:37AM +0800, Chen-Yu Tsai wrote:
> On Tue, Dec 17, 2024 at 2:01 AM Chris Morgan <macroalpha82@gmail.com> wrote:
> >
> > On Wed, Dec 11, 2024 at 09:58:26PM +0000, Jonathan Cameron wrote:
> > > On Tue, 10 Dec 2024 16:48:57 -0600
> > > Chris Morgan <macroalpha82@gmail.com> wrote:
> > >
> > > > From: Chris Morgan <macromorgan@hotmail.com>
> > > >
> > > > After performing a git bisect, I identified a commit that broke the
> > > > battery and charger driver for my AXP717 PMIC. This was caused by
> > > > commit e37ec3218870 ("mfd: axp20x: Allow multiple regulators").
> > > >
> > > > After digging into it, it appears when mfd_add_devices was called with
> > > > a platform ID of PLATFORM_DEVID_NONE, the devm_iio_channel_get() call
> > > > made by the various AXP20X power drivers would not be able to generate
> > > > a dev_name(dev) for some reason, and the iio_channel_get() call used in
> > > > the devm_ helper would fall back to making a iio_channel_get_sys()
> > > > call. After the platform ID was updated, now iio_channel_get() is no
> > > > longer falling back to iio_channel_get_sys(). At least this is my
> > > > limited understanding of what happened.
> > >
> > > The dev_name(dev) not getting a name doesn't sound quite right to me.
> > >
> > > Time to look at the ancient creaking ghost that is the iio_map handling.
> > >
> > > struct iio_channel *iio_channel_get(struct device *dev,
> > >                                   const char *channel_name)
> > > {
> > >       const char *name = dev ? dev_name(dev) : NULL;
> > >       struct iio_channel *channel;
> > >
> > >       if (dev) {
> > >               channel = fwnode_iio_channel_get_by_name(dev_fwnode(dev),
> > >                                                        channel_name);
> > >               if (!IS_ERR(channel) || PTR_ERR(channel) != -ENODEV)
> > >                       return channel;
> > >       }
> > >
> > >       return iio_channel_get_sys(name, channel_name);
> > > }
> > > EXPORT_SYMBOL_GPL(iio_channel_get);
> > >
> > > We didn't invent the relevant phandle stuff in DT via the patch you point at
> > > so all that matters is what gets passed to that iio_channel_get_sys()
> > >
> > > So key here is that dev should be set, so we are passing dev_name(dev) into
> > > iio_channel_get_sys()
> > > I'm guessing that changed...
> > >
> > > Ah.  The iio_maps in
> > > https://elixir.bootlin.com/linux/v6.12.4/source/drivers/iio/adc/axp20x_adc.c#L158
> > > are our problem. Those hardcode the consumer_dev name. The fix just changed
> > > those names. Back when this infrastructure was written we were in the world of
> > > board files, so everything was hard coded in them - or in an MFD like this
> > > it was treated as a singleton device.
> > >
> > > So as to how to fix it... Assuming the new device names are the same for all
> > > the mfd parts that make up each pmic, then you should be able to figure out the
> > >  extra the number and build the channel maps to allow you to find the numbered
> > > devices.
> >
> > Is there a way to figure out the device number at runtime? The issue is
> > each time the device attempts to probe and fails, the device number
> > increments, making it a "hitting a moving target" problem.
> 
> The ADC device is a mfd cell or child device of the PMIC mfd device.
> So you should be able to use dev->parent to get it directly? We do
> that at least for the regulator driver.

Sorry to dig up such an old thread. I'm taking a look at this one again
and can confirm passing pdev->dev.parent to devm_iio_channel_get() is
insufficient to get the driver to find the correct ADC channel. Would
there be another/better way to do this other than the
devm_iio_channel_get_sys() as proposed? Or should we be walking the
parent somehow looking for the named ADC channel on each child device
(which would also require a new symbol most likely)?

Thank you,
Chris

> 
> ChenYu
> 
> > Thank you,
> > Chris
> >
> > >
> > > That's a lot lighter change than moving over to DT based phandles for all this.
> > > (which is the modern way to handle it).
> > >
> > > As a cheeky check, just edit those maps to whatever IDs you have and see
> > > if it works.  Probably not an upstreamable solution but will confirm we have
> > > it correct.
> > >
> > > Your patch works because we allow for some fuzzy matching (I can't remember
> > > why) that doesn't use the consumer device name.
> > > That works as long as there is only one instance.  I'm guessing all this
> > > mess came about because someone has a board with two of these devices. On such
> > > a board we need the precise matching including the device name.
> > >
> > > Jonathan
> > >
> > > >
> > > > To fix this, I added a new devm_ helper of devm_iio_channel_get_sys()
> > > > that directly calls iio_channel_get_sys(), and I updated all the
> > > > affected drivers with the new routine. I then no longer experienced
> > > > any issues with the drivers on my devices.
> > > >
> > > > Chris Morgan (2):
> > > >   iio: core: Add devm_ API for iio_channel_get_sys
> > > >   power: supply: axp20x: Use devm_iio_channel_get_sys() for iio chans
> > > >
> > > >  drivers/iio/inkern.c                    | 18 ++++++++++++++++++
> > > >  drivers/power/supply/axp20x_ac_power.c  |  4 ++--
> > > >  drivers/power/supply/axp20x_battery.c   | 16 ++++++++--------
> > > >  drivers/power/supply/axp20x_usb_power.c |  6 +++---
> > > >  include/linux/iio/consumer.h            | 20 ++++++++++++++++++++
> > > >  5 files changed, 51 insertions(+), 13 deletions(-)
> > > >
> > >

  reply	other threads:[~2025-03-04 18:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-10 22:48 [PATCH 0/2] Fix Regression with AXP20X for 6.13-rc1 Chris Morgan
2024-12-10 22:48 ` [PATCH 1/2] iio: core: Add devm_ API for iio_channel_get_sys Chris Morgan
2024-12-10 22:48 ` [PATCH 2/2] power: supply: axp20x: Use devm_iio_channel_get_sys() for iio chans Chris Morgan
2024-12-11 21:58 ` [PATCH 0/2] Fix Regression with AXP20X for 6.13-rc1 Jonathan Cameron
2024-12-11 22:06   ` Jonathan Cameron
2024-12-16 18:01   ` Chris Morgan
2024-12-16 18:04     ` Chen-Yu Tsai
2025-03-04 18:18       ` Chris Morgan [this message]
2025-03-04 23:29         ` Jonathan Cameron
2025-03-06  2:19           ` Chris Morgan
2025-03-08 17:11             ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=67c743e3.050a0220.327e31.55b3@mx.google.com \
    --to=macroalpha82@gmail.com \
    --cc=andre.przywara@arm.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=lee@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=macromorgan@hotmail.com \
    --cc=sre@kernel.org \
    --cc=wens@csie.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.