[lkml]   [2019]   [Aug]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
SubjectDisabling MFD sub-devices through the device tree

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;
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

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?



 \ /
  Last update: 2019-08-22 20:27    [W:0.048 / U:9.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site