Lines Matching +full:parent +full:- +full:child
1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/mfd/mfd-core.c
40 if (!cell->enable) { in mfd_cell_enable()
41 dev_dbg(&pdev->dev, "No .enable() call-back registered\n"); in mfd_cell_enable()
45 return cell->enable(pdev); in mfd_cell_enable()
53 if (!cell->disable) { in mfd_cell_disable()
54 dev_dbg(&pdev->dev, "No .disable() call-back registered\n"); in mfd_cell_disable()
58 return cell->disable(pdev); in mfd_cell_disable()
66 const struct mfd_cell_acpi_match *match = cell->acpi_match; in mfd_acpi_add_device()
67 struct acpi_device *parent, *child; in mfd_acpi_add_device() local
70 parent = ACPI_COMPANION(pdev->dev.parent); in mfd_acpi_add_device()
71 if (!parent) in mfd_acpi_add_device()
75 * MFD child device gets its ACPI handle either from the ACPI device in mfd_acpi_add_device()
76 * directly under the parent that matches the either _HID or _CID, or in mfd_acpi_add_device()
77 * _ADR or it will use the parent handle if is no ID is given. in mfd_acpi_add_device()
83 adev = parent; in mfd_acpi_add_device()
85 if (match->pnpid) { in mfd_acpi_add_device()
88 strlcpy(ids[0].id, match->pnpid, sizeof(ids[0].id)); in mfd_acpi_add_device()
89 list_for_each_entry(child, &parent->children, node) { in mfd_acpi_add_device()
90 if (!acpi_match_device_ids(child, ids)) { in mfd_acpi_add_device()
91 adev = child; in mfd_acpi_add_device()
99 list_for_each_entry(child, &parent->children, node) { in mfd_acpi_add_device()
100 status = acpi_evaluate_integer(child->handle, in mfd_acpi_add_device()
103 if (ACPI_SUCCESS(status) && match->adr == adr) { in mfd_acpi_add_device()
104 adev = child; in mfd_acpi_add_device()
111 ACPI_COMPANION_SET(&pdev->dev, adev); in mfd_acpi_add_device()
131 if (of_entry->np == np) in mfd_match_of_node_to_dev()
132 return -EAGAIN; in mfd_match_of_node_to_dev()
134 if (!cell->use_of_reg) in mfd_match_of_node_to_dev()
135 /* No of_reg defined - allocate first free compatible match */ in mfd_match_of_node_to_dev()
142 return -EAGAIN; in mfd_match_of_node_to_dev()
146 if (cell->of_reg != of_node_addr) in mfd_match_of_node_to_dev()
148 return -EAGAIN; in mfd_match_of_node_to_dev()
153 return -ENOMEM; in mfd_match_of_node_to_dev()
155 of_entry->dev = &pdev->dev; in mfd_match_of_node_to_dev()
156 of_entry->np = np; in mfd_match_of_node_to_dev()
157 list_add_tail(&of_entry->list, &mfd_of_node_list); in mfd_match_of_node_to_dev()
159 pdev->dev.of_node = np; in mfd_match_of_node_to_dev()
160 pdev->dev.fwnode = &np->fwnode; in mfd_match_of_node_to_dev()
165 static int mfd_add_device(struct device *parent, int id, in mfd_add_device() argument
174 int ret = -ENOMEM; in mfd_add_device()
181 platform_id = id + cell->id; in mfd_add_device()
183 pdev = platform_device_alloc(cell->name, platform_id); in mfd_add_device()
187 pdev->mfd_cell = kmemdup(cell, sizeof(*cell), GFP_KERNEL); in mfd_add_device()
188 if (!pdev->mfd_cell) in mfd_add_device()
191 res = kcalloc(cell->num_resources, sizeof(*res), GFP_KERNEL); in mfd_add_device()
195 pdev->dev.parent = parent; in mfd_add_device()
196 pdev->dev.type = &mfd_dev_type; in mfd_add_device()
197 pdev->dev.dma_mask = parent->dma_mask; in mfd_add_device()
198 pdev->dev.dma_parms = parent->dma_parms; in mfd_add_device()
199 pdev->dev.coherent_dma_mask = parent->coherent_dma_mask; in mfd_add_device()
202 &pdev->dev, cell->parent_supplies, in mfd_add_device()
203 parent, cell->parent_supplies, in mfd_add_device()
204 cell->num_parent_supplies); in mfd_add_device()
208 if (IS_ENABLED(CONFIG_OF) && parent->of_node && cell->of_compatible) { in mfd_add_device()
209 for_each_child_of_node(parent->of_node, np) { in mfd_add_device()
210 if (of_device_is_compatible(np, cell->of_compatible)) { in mfd_add_device()
218 if (ret == -EAGAIN) in mfd_add_device()
227 if (!pdev->dev.of_node) in mfd_add_device()
229 cell->name, platform_id); in mfd_add_device()
234 if (cell->pdata_size) { in mfd_add_device()
236 cell->platform_data, cell->pdata_size); in mfd_add_device()
241 if (cell->properties) { in mfd_add_device()
242 ret = platform_device_add_properties(pdev, cell->properties); in mfd_add_device()
247 for (r = 0; r < cell->num_resources; r++) { in mfd_add_device()
248 res[r].name = cell->resources[r].name; in mfd_add_device()
249 res[r].flags = cell->resources[r].flags; in mfd_add_device()
252 if ((cell->resources[r].flags & IORESOURCE_MEM) && mem_base) { in mfd_add_device()
253 res[r].parent = mem_base; in mfd_add_device()
254 res[r].start = mem_base->start + in mfd_add_device()
255 cell->resources[r].start; in mfd_add_device()
256 res[r].end = mem_base->start + in mfd_add_device()
257 cell->resources[r].end; in mfd_add_device()
258 } else if (cell->resources[r].flags & IORESOURCE_IRQ) { in mfd_add_device()
261 WARN_ON(cell->resources[r].start != in mfd_add_device()
262 cell->resources[r].end); in mfd_add_device()
264 domain, cell->resources[r].start); in mfd_add_device()
267 cell->resources[r].start; in mfd_add_device()
269 cell->resources[r].end; in mfd_add_device()
272 res[r].parent = cell->resources[r].parent; in mfd_add_device()
273 res[r].start = cell->resources[r].start; in mfd_add_device()
274 res[r].end = cell->resources[r].end; in mfd_add_device()
277 if (!cell->ignore_resource_conflicts) { in mfd_add_device()
278 if (has_acpi_companion(&pdev->dev)) { in mfd_add_device()
286 ret = platform_device_add_resources(pdev, res, cell->num_resources); in mfd_add_device()
294 if (cell->pm_runtime_no_callbacks) in mfd_add_device()
295 pm_runtime_no_callbacks(&pdev->dev); in mfd_add_device()
303 if (of_entry->dev == &pdev->dev) { in mfd_add_device()
304 list_del(&of_entry->list); in mfd_add_device()
308 regulator_bulk_unregister_supply_alias(&pdev->dev, in mfd_add_device()
309 cell->parent_supplies, in mfd_add_device()
310 cell->num_parent_supplies); in mfd_add_device()
320 * mfd_add_devices - register child devices
322 * @parent: Pointer to parent device.
325 * @cells: Array of (struct mfd_cell)s describing child devices.
326 * @n_devs: Number of child devices to register.
327 * @mem_base: Parent register range resource for child devices.
332 int mfd_add_devices(struct device *parent, int id, in mfd_add_devices() argument
341 ret = mfd_add_device(parent, id, cells + i, mem_base, in mfd_add_devices()
351 mfd_remove_devices(parent); in mfd_add_devices()
363 if (dev->type != &mfd_dev_type) in mfd_remove_devices_fn()
369 if (level && cell->level > *level) in mfd_remove_devices_fn()
372 regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies, in mfd_remove_devices_fn()
373 cell->num_parent_supplies); in mfd_remove_devices_fn()
379 void mfd_remove_devices_late(struct device *parent) in mfd_remove_devices_late() argument
383 device_for_each_child_reverse(parent, &level, mfd_remove_devices_fn); in mfd_remove_devices_late()
387 void mfd_remove_devices(struct device *parent) in mfd_remove_devices() argument
391 device_for_each_child_reverse(parent, &level, mfd_remove_devices_fn); in mfd_remove_devices()
401 * devm_mfd_add_devices - Resource managed version of mfd_add_devices()
404 * All child-devices of the MFD will automatically be removed when it gets
407 * @dev: Pointer to parent device.
410 * @cells: Array of (struct mfd_cell)s describing child devices.
411 * @n_devs: Number of child devices to register.
412 * @mem_base: Parent register range resource for child devices.
427 return -ENOMEM; in devm_mfd_add_devices()