Lines Matching +full:root +full:- +full:node
1 // SPDX-License-Identifier: GPL-2.0+
16 #include <linux/dma-mapping.h>
28 * of_find_device_by_node - Find the platform_device associated with a node
29 * @np: Pointer to device tree node
47 BUG_ON(ofdev->dev.of_node == NULL); in of_device_add()
51 ofdev->name = dev_name(&ofdev->dev); in of_device_add()
52 ofdev->id = PLATFORM_DEVID_NONE; in of_device_add()
55 * If this device has not binding numa node in devicetree, that is in of_device_add()
57 * device is on the same node as the parent. in of_device_add()
59 set_dev_node(&ofdev->dev, of_node_to_nid(ofdev->dev.of_node)); in of_device_add()
61 return device_add(&ofdev->dev); in of_device_add()
66 device_initialize(&pdev->dev); in of_device_register()
73 device_unregister(&ofdev->dev); in of_device_unregister()
79 { .compatible = "operating-points-v2", },
85 * each applicable node.
92 * of_device_alloc - Allocate and initialize an of_device
93 * @np: device node to assign to device
120 dev->num_resources = num_reg; in of_device_alloc()
121 dev->resource = res; in of_device_alloc()
129 device_set_node(&dev->dev, of_fwnode_handle(of_node_get(np))); in of_device_alloc()
130 dev->dev.parent = parent ? : &platform_bus; in of_device_alloc()
133 dev_set_name(&dev->dev, "%s", bus_id); in of_device_alloc()
135 of_device_make_bus_id(&dev->dev); in of_device_alloc()
142 * of_platform_device_create_pdata - Alloc, initialize and register an of_device
143 * @np: pointer to node to create device for
169 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); in of_platform_device_create_pdata()
170 if (!dev->dev.dma_mask) in of_platform_device_create_pdata()
171 dev->dev.dma_mask = &dev->dev.coherent_dma_mask; in of_platform_device_create_pdata()
172 dev->dev.bus = &platform_bus_type; in of_platform_device_create_pdata()
173 dev->dev.platform_data = platform_data; in of_platform_device_create_pdata()
174 of_msi_configure(&dev->dev, dev->dev.of_node); in of_platform_device_create_pdata()
189 * of_platform_device_create - Alloc, initialize and register an of_device
190 * @np: pointer to node to create device for
206 static struct amba_device *of_amba_device_create(struct device_node *node, in of_amba_device_create() argument
214 pr_debug("Creating amba device %pOF\n", node); in of_amba_device_create()
216 if (!of_device_is_available(node) || in of_amba_device_create()
217 of_node_test_and_set_flag(node, OF_POPULATED)) in of_amba_device_create()
225 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); in of_amba_device_create()
226 dev->dev.dma_mask = &dev->dev.coherent_dma_mask; in of_amba_device_create()
229 device_set_node(&dev->dev, of_fwnode_handle(node)); in of_amba_device_create()
230 dev->dev.parent = parent ? : &platform_bus; in of_amba_device_create()
231 dev->dev.platform_data = platform_data; in of_amba_device_create()
233 dev_set_name(&dev->dev, "%s", bus_id); in of_amba_device_create()
235 of_device_make_bus_id(&dev->dev); in of_amba_device_create()
238 of_property_read_u32(node, "arm,primecell-periphid", &dev->periphid); in of_amba_device_create()
240 ret = of_address_to_resource(node, 0, &dev->res); in of_amba_device_create()
243 ret, node); in of_amba_device_create()
250 ret, node); in of_amba_device_create()
259 of_node_clear_flag(node, OF_POPULATED); in of_amba_device_create()
263 static struct amba_device *of_amba_device_create(struct device_node *node, in of_amba_device_create() argument
273 * of_dev_lookup() - Given a device node, lookup the preferred Linux name
286 for (; auxdata->compatible; auxdata++) { in of_dev_lookup()
287 if (!of_device_is_compatible(np, auxdata->compatible)) in of_dev_lookup()
291 if (res.start != auxdata->phys_addr) in of_dev_lookup()
293 pr_debug("%pOF: devname=%s\n", np, auxdata->name); in of_dev_lookup()
302 for (; auxdata->compatible; auxdata++) { in of_dev_lookup()
303 if (!of_device_is_compatible(np, auxdata->compatible)) in of_dev_lookup()
305 if (!auxdata->phys_addr && !auxdata->name) { in of_dev_lookup()
315 * of_platform_bus_create() - Create a device for a node and its children.
316 * @bus: device node of the bus to instantiate
338 pr_debug("%s() - skipping %pOF, no compatible prop\n", in of_platform_bus_create()
345 pr_debug("%s() - skipping %pOF node\n", __func__, bus); in of_platform_bus_create()
350 pr_debug("%s() - skipping %pOF, already populated\n", in of_platform_bus_create()
357 bus_id = auxdata->name; in of_platform_bus_create()
358 platform_data = auxdata->platform_data; in of_platform_bus_create()
376 rc = of_platform_bus_create(child, matches, lookup, &dev->dev, strict); in of_platform_bus_create()
385 * of_platform_bus_probe() - Probe the device-tree for platform buses
386 * @root: parent of the first level to probe or NULL for the root of the tree
390 * Note that children of the provided root are not instantiated as devices
391 * unless the specified root itself matches the bus list and is not NULL.
393 int of_platform_bus_probe(struct device_node *root, in of_platform_bus_probe() argument
399 root = root ? of_node_get(root) : of_find_node_by_path("/"); in of_platform_bus_probe()
400 if (!root) in of_platform_bus_probe()
401 return -EINVAL; in of_platform_bus_probe()
404 pr_debug(" starting at: %pOF\n", root); in of_platform_bus_probe()
407 if (of_match_node(matches, root)) { in of_platform_bus_probe()
408 rc = of_platform_bus_create(root, matches, NULL, parent, false); in of_platform_bus_probe()
410 for_each_child_of_node_scoped(root, child) { in of_platform_bus_probe()
419 of_node_put(root); in of_platform_bus_probe()
425 * of_platform_populate() - Populate platform_devices from device tree data
426 * @root: parent of the first level to probe or NULL for the root of the tree
434 * and it is suitable for creating devices which are children of the root
435 * node (of_platform_bus_probe will only create children of the root which
443 int of_platform_populate(struct device_node *root, in of_platform_populate() argument
450 root = root ? of_node_get(root) : of_find_node_by_path("/"); in of_platform_populate()
451 if (!root) in of_platform_populate()
452 return -EINVAL; in of_platform_populate()
455 pr_debug(" starting at: %pOF\n", root); in of_platform_populate()
458 for_each_child_of_node_scoped(root, child) { in of_platform_populate()
465 of_node_set_flag(root, OF_POPULATED_BUS); in of_platform_populate()
467 of_node_put(root); in of_platform_populate()
472 int of_platform_default_populate(struct device_node *root, in of_platform_default_populate() argument
477 { .compatible = "simple-bus", }, in of_platform_default_populate()
478 { .compatible = "simple-mfd", }, in of_platform_default_populate()
481 { .compatible = "arm,amba-bus", }, in of_platform_default_populate()
486 return of_platform_populate(root, match_table, lookup, parent); in of_platform_default_populate()
492 { .compatible = "qcom,rmtfs-mem" },
493 { .compatible = "qcom,cmd-db" },
496 { .compatible = "nvmem-rmem" },
497 { .compatible = "google,open-dice" },
503 struct device_node *node; in of_platform_default_populate_init() local
513 /* Check if we have a MacOS display without a node spec */ in of_platform_default_populate_init()
514 if (of_property_present(of_chosen, "linux,bootx-noscreen")) { in of_platform_default_populate_init()
516 * The old code tried to work out which node was the MacOS in of_platform_default_populate_init()
518 * lack of a node spec only happens with old BootX versions in of_platform_default_populate_init()
522 dev = platform_device_alloc("bootx-noscreen", 0); in of_platform_default_populate_init()
524 return -ENOMEM; in of_platform_default_populate_init()
537 for_each_node_by_type(node, "display") { in of_platform_default_populate_init()
538 if (!of_property_read_bool(node, "linux,opened") || in of_platform_default_populate_init()
539 !of_property_read_bool(node, "linux,boot-display")) in of_platform_default_populate_init()
541 dev = of_platform_device_create(node, "of-display", NULL); in of_platform_default_populate_init()
542 of_node_put(node); in of_platform_default_populate_init()
544 return -ENOMEM; in of_platform_default_populate_init()
545 boot_display = node; in of_platform_default_populate_init()
549 for_each_node_by_type(node, "display") { in of_platform_default_populate_init()
551 const char *of_display_format = "of-display.%d"; in of_platform_default_populate_init()
553 if (!of_property_read_bool(node, "linux,opened") || node == boot_display) in of_platform_default_populate_init()
557 of_platform_device_create(node, buf, NULL); in of_platform_default_populate_init()
563 * platform_devices for every node in /reserved-memory with a in of_platform_default_populate_init()
566 for_each_matching_node(node, reserved_mem_matches) in of_platform_default_populate_init()
567 of_platform_device_create(node, NULL, NULL); in of_platform_default_populate_init()
569 node = of_find_node_by_path("/firmware"); in of_platform_default_populate_init()
570 if (node) { in of_platform_default_populate_init()
571 of_platform_default_populate(node, NULL, NULL); in of_platform_default_populate_init()
572 of_node_put(node); in of_platform_default_populate_init()
575 node = of_get_compatible_child(of_chosen, "simple-framebuffer"); in of_platform_default_populate_init()
576 if (node) { in of_platform_default_populate_init()
578 * Since a "simple-framebuffer" device is already added in of_platform_default_populate_init()
588 of_platform_device_create(node, NULL, NULL); in of_platform_default_populate_init()
589 of_node_put(node); in of_platform_default_populate_init()
610 if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) in of_platform_device_destroy()
614 if (of_node_check_flag(dev->of_node, OF_POPULATED_BUS)) in of_platform_device_destroy()
617 of_node_clear_flag(dev->of_node, OF_POPULATED); in of_platform_device_destroy()
618 of_node_clear_flag(dev->of_node, OF_POPULATED_BUS); in of_platform_device_destroy()
620 if (dev->bus == &platform_bus_type) in of_platform_device_destroy()
623 else if (dev->bus == &amba_bustype) in of_platform_device_destroy()
632 * of_platform_depopulate() - Remove devices populated from device tree
638 * leaving others - eg. manually created - unharmed).
642 if (parent->of_node && of_node_check_flag(parent->of_node, OF_POPULATED_BUS)) { in of_platform_depopulate()
644 of_node_clear_flag(parent->of_node, OF_POPULATED_BUS); in of_platform_depopulate()
655 * devm_of_platform_populate() - Populate platform_devices from device tree data
669 return -EINVAL; in devm_of_platform_populate()
674 return -ENOMEM; in devm_of_platform_populate()
676 ret = of_platform_populate(dev->of_node, NULL, NULL, dev); in devm_of_platform_populate()
701 * devm_of_platform_depopulate() - Remove devices populated from device tree
707 * leaving others - eg. manually created - unharmed).
731 parent = rd->dn->parent; in of_platform_notify()
732 /* verify that the parent is a bus (or the root node) */ in of_platform_notify()
738 if (of_node_check_flag(rd->dn, OF_POPULATED)) in of_platform_notify()
745 rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE; in of_platform_notify()
748 pdev = of_platform_device_create(rd->dn, NULL, in of_platform_notify()
749 pdev_parent ? &pdev_parent->dev : NULL); in of_platform_notify()
754 __func__, rd->dn); in of_platform_notify()
756 return notifier_from_errno(-EINVAL); in of_platform_notify()
763 if (!of_node_check_flag(rd->dn, OF_POPULATED)) in of_platform_notify()
766 /* find our device by node */ in of_platform_notify()
767 pdev = of_find_device_by_node(rd->dn); in of_platform_notify()
772 of_platform_device_destroy(&pdev->dev, &children_left); in of_platform_notify()