mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stephan Gerhold <stephan@gerhold.net>
To: Lee Jones <lee.jones@linaro.org>
Cc: Linus Walleij <linus.walleij@linaro.org>, linux-kernel@vger.kernel.org
Subject: Re: Disabling MFD sub-devices through the device tree
Date: Mon, 2 Sep 2019 17:43:32 +0200	[thread overview]
Message-ID: <20190902154332.GB10870@gerhold.net> (raw)
In-Reply-To: <20190822182624.GA2640@gerhold.net>

On Thu, Aug 22, 2019 at 08:26:33PM +0200, Stephan Gerhold wrote:
> Hi,
> 
> I am looking for a way to disable a MFD sub-device through the device
> tree. Setting status = "disabled" for the device node does not seem to
> have any effect when mfd_add_devices() is used.
> 
> For MFD sub-devices, this was discussed before in [1].
> However, as far as I can tell it was never actually fixed.
> I was thinking about simply skipping creation of the platform device if
> the device node is set to disabled, e.g.:
> 
> --- a/drivers/mfd/mfd-core.c
> +++ b/drivers/mfd/mfd-core.c
> @@ -174,6 +174,9 @@ static int mfd_add_device(struct device *parent, int id,
>  	if (parent->of_node && cell->of_compatible) {
>  		for_each_child_of_node(parent->of_node, np) {
>  			if (of_device_is_compatible(np, cell->of_compatible)) {
> +				if (!of_device_is_available(np))
> +					goto fail_alias;
> +
>  				pdev->dev.of_node = np;
>  				pdev->dev.fwnode = &np->fwnode;
>  				break;
> 
> But I believe this would introduce a rather ugly bug in
> mfd_remove_devices() if the first sub-device is set to disabled:
> It iterates over the children devices to find the base address of the
> allocated "usage count" array, which is then used to free it.
> If the first sub-device is missing, it would free the wrong address.
> 
> (At the moment, the MFD core seems to be built on the assumption that
> all the children devices are actually created...)
> 
> A different approach I have seen in the kernel is to add a check to
> of_device_is_available() in the device drivers of the MFD sub-devices.
> e.g. drivers/power/supply/axp20x_*.c all check of_device_is_available()
> as first thing in their probe() method, and abort probing with -ENODEV
> otherwise.
> 
> On the other hand, duplicating that check in each and every driver
> that you may want to disable eventually doesn't sound like a great idea.
> Especially because this is not necessary if the devices are registered
> directly through the device tree.
> 
> What do you think?
> 
> Thanks,
> Stephan
> 
> [1]: https://www.spinics.net/lists/arm-kernel/msg366309.html

Hi Lee,

do you have any suggestions for this?

Normally, I would just send a proper patch with my proposed solution
above, but I'm not sure what's the best way to handle the problem with
the "usage count" array I described above.

Thanks,
Stephan

      reply	other threads:[~2019-09-02 15:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-22 18:26 Stephan Gerhold
2019-09-02 15:43 ` Stephan Gerhold [this message]

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=20190902154332.GB10870@gerhold.net \
    --to=stephan@gerhold.net \
    --cc=lee.jones@linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®