linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Disabling MFD sub-devices through the device tree
@ 2019-08-22 18:26 Stephan Gerhold
  2019-09-02 15:43 ` Stephan Gerhold
  0 siblings, 1 reply; 2+ messages in thread
From: Stephan Gerhold @ 2019-08-22 18:26 UTC (permalink / raw)
  To: Lee Jones; +Cc: Linus Walleij, linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Disabling MFD sub-devices through the device tree
  2019-08-22 18:26 Disabling MFD sub-devices through the device tree Stephan Gerhold
@ 2019-09-02 15:43 ` Stephan Gerhold
  0 siblings, 0 replies; 2+ messages in thread
From: Stephan Gerhold @ 2019-09-02 15:43 UTC (permalink / raw)
  To: Lee Jones; +Cc: Linus Walleij, linux-kernel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-09-02 15:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22 18:26 Disabling MFD sub-devices through the device tree Stephan Gerhold
2019-09-02 15:43 ` Stephan Gerhold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).