Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mfd: mfd-core: Add mechanism for removal of a subset of children

Currently, the only way to remove MFD children is with a call to
mfd_remove_devices, which will remove all the children. Under
some circumstances it is useful to remove only a subset of the
child devices. For example if some additional clean up is required
between removal of certain child devices.

To accomplish this a level field is added to mfd_cell, the normal
mfd_remove_devices is modified to not remove devices that are set
to a higher level and a corresponding mfd_remove_devices_late
function is added to remove those children.

See further discussion at:
https://lore.kernel.org/lkml/20200616075834.GF2608702@dell/

Suggested-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>

authored by

Charles Keepax and committed by
Lee Jones
114294d2 4ee1d9dc

+20 -1
+15 -1
drivers/mfd/mfd-core.c
··· 356 356 { 357 357 struct platform_device *pdev; 358 358 const struct mfd_cell *cell; 359 + int *level = data; 359 360 360 361 if (dev->type != &mfd_dev_type) 361 362 return 0; 362 363 363 364 pdev = to_platform_device(dev); 364 365 cell = mfd_get_cell(pdev); 366 + 367 + if (level && cell->level > *level) 368 + return 0; 365 369 366 370 regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies, 367 371 cell->num_parent_supplies); ··· 376 372 return 0; 377 373 } 378 374 375 + void mfd_remove_devices_late(struct device *parent) 376 + { 377 + int level = MFD_DEP_LEVEL_HIGH; 378 + 379 + device_for_each_child_reverse(parent, &level, mfd_remove_devices_fn); 380 + } 381 + EXPORT_SYMBOL(mfd_remove_devices_late); 382 + 379 383 void mfd_remove_devices(struct device *parent) 380 384 { 381 - device_for_each_child_reverse(parent, NULL, mfd_remove_devices_fn); 385 + int level = MFD_DEP_LEVEL_NORMAL; 386 + 387 + device_for_each_child_reverse(parent, &level, mfd_remove_devices_fn); 382 388 } 383 389 EXPORT_SYMBOL(mfd_remove_devices); 384 390
+5
include/linux/mfd/core.h
··· 46 46 #define MFD_CELL_NAME(_name) \ 47 47 MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, false, NULL) 48 48 49 + #define MFD_DEP_LEVEL_NORMAL 0 50 + #define MFD_DEP_LEVEL_HIGH 1 51 + 49 52 struct irq_domain; 50 53 struct property_entry; 51 54 ··· 66 63 struct mfd_cell { 67 64 const char *name; 68 65 int id; 66 + int level; 69 67 70 68 int (*enable)(struct platform_device *dev); 71 69 int (*disable)(struct platform_device *dev); ··· 154 150 } 155 151 156 152 extern void mfd_remove_devices(struct device *parent); 153 + extern void mfd_remove_devices_late(struct device *parent); 157 154 158 155 extern int devm_mfd_add_devices(struct device *dev, int id, 159 156 const struct mfd_cell *cells, int n_devs,