[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20190902154332.GB10870@gerhold.net>
Date: Mon, 2 Sep 2019 17:43:32 +0200
From: Stephan Gerhold <stephan@...hold.net>
To: Lee Jones <lee.jones@...aro.org>
Cc: Linus Walleij <linus.walleij@...aro.org>,
linux-kernel@...r.kernel.org
Subject: Re: Disabling MFD sub-devices through the device tree
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
Powered by blists - more mailing lists