Lines Matching +full:device +full:- +full:tree
1 // SPDX-License-Identifier: GPL-2.0+
15 #include <linux/device.h>
16 #include <linux/dma-mapping.h>
28 { .compatible = "simple-bus", },
29 { .compatible = "simple-mfd", },
32 { .compatible = "arm,amba-bus", },
38 * of_find_device_by_node - Find the platform_device associated with a node
39 * @np: Pointer to device tree node
41 * Takes a reference to the embedded struct device which needs to be dropped
48 struct device *dev; in of_find_device_by_node()
57 BUG_ON(ofdev->dev.of_node == NULL); in of_device_add()
61 ofdev->name = dev_name(&ofdev->dev); in of_device_add()
62 ofdev->id = PLATFORM_DEVID_NONE; in of_device_add()
65 * If this device has not binding numa node in devicetree, that is in of_device_add()
67 * device is on the same node as the parent. in of_device_add()
69 set_dev_node(&ofdev->dev, of_node_to_nid(ofdev->dev.of_node)); in of_device_add()
71 return device_add(&ofdev->dev); in of_device_add()
76 device_initialize(&pdev->dev); in of_device_register()
83 device_unregister(&ofdev->dev); in of_device_unregister()
89 { .compatible = "operating-points-v2", },
94 * The following routines scan a subtree and registers a device for
98 * mechanism for creating devices from device tree nodes.
102 * of_device_alloc - Allocate and initialize an of_device
103 * @np: device node to assign to device
104 * @bus_id: Name to assign to the device. May be null to use default name.
105 * @parent: Parent device.
109 struct device *parent) in of_device_alloc()
130 dev->num_resources = num_reg; in of_device_alloc()
131 dev->resource = res; in of_device_alloc()
138 /* setup generic device info */ in of_device_alloc()
139 device_set_node(&dev->dev, of_fwnode_handle(of_node_get(np))); in of_device_alloc()
140 dev->dev.parent = parent ? : &platform_bus; in of_device_alloc()
143 dev_set_name(&dev->dev, "%s", bus_id); in of_device_alloc()
145 of_device_make_bus_id(&dev->dev); in of_device_alloc()
152 * of_platform_device_create_pdata - Alloc, initialize and register an of_device
153 * @np: pointer to node to create device for
154 * @bus_id: name to assign device
156 * @parent: Linux device model parent device.
158 * Return: Pointer to created platform device, or NULL if a device was not
165 struct device *parent) in of_platform_device_create_pdata()
177 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); in of_platform_device_create_pdata()
178 if (!dev->dev.dma_mask) in of_platform_device_create_pdata()
179 dev->dev.dma_mask = &dev->dev.coherent_dma_mask; in of_platform_device_create_pdata()
180 dev->dev.bus = &platform_bus_type; in of_platform_device_create_pdata()
181 dev->dev.platform_data = platform_data; in of_platform_device_create_pdata()
182 of_msi_configure(&dev->dev, dev->dev.of_node); in of_platform_device_create_pdata()
197 * of_platform_device_create - Alloc, initialize and register an of_device
198 * @np: pointer to node to create device for
199 * @bus_id: name to assign device
200 * @parent: Linux device model parent device.
202 * Return: Pointer to created platform device, or NULL if a device was not
207 struct device *parent) in of_platform_device_create()
217 struct device *parent) in of_amba_device_create()
222 pr_debug("Creating amba device %pOF\n", node); in of_amba_device_create()
233 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); in of_amba_device_create()
234 dev->dev.dma_mask = &dev->dev.coherent_dma_mask; in of_amba_device_create()
236 /* setup generic device info */ in of_amba_device_create()
237 device_set_node(&dev->dev, of_fwnode_handle(node)); in of_amba_device_create()
238 dev->dev.parent = parent ? : &platform_bus; in of_amba_device_create()
239 dev->dev.platform_data = platform_data; in of_amba_device_create()
241 dev_set_name(&dev->dev, "%s", bus_id); in of_amba_device_create()
243 of_device_make_bus_id(&dev->dev); in of_amba_device_create()
246 of_property_read_u32(node, "arm,primecell-periphid", &dev->periphid); in of_amba_device_create()
248 ret = of_address_to_resource(node, 0, &dev->res); in of_amba_device_create()
274 struct device *parent) in of_amba_device_create()
281 * of_dev_lookup() - Given a device node, lookup the preferred Linux name
294 for (; auxdata->compatible; auxdata++) { in of_dev_lookup()
295 if (!of_device_is_compatible(np, auxdata->compatible)) in of_dev_lookup()
299 if (res.start != auxdata->phys_addr) in of_dev_lookup()
301 pr_debug("%pOF: devname=%s\n", np, auxdata->name); in of_dev_lookup()
310 for (; auxdata->compatible; auxdata++) { in of_dev_lookup()
311 if (!of_device_is_compatible(np, auxdata->compatible)) in of_dev_lookup()
313 if (!auxdata->phys_addr && !auxdata->name) { in of_dev_lookup()
323 * of_platform_bus_create() - Create a device for a node and its children.
324 * @bus: device node of the bus to instantiate
326 * @lookup: auxdata table for matching id and platform_data with device nodes
327 * @parent: parent for new device, or NULL for top level.
336 struct device *parent, bool strict) in of_platform_bus_create()
347 pr_debug("%s() - skipping %pOF, no compatible prop\n", in of_platform_bus_create()
354 pr_debug("%s() - skipping %pOF node\n", __func__, bus); in of_platform_bus_create()
359 pr_debug("%s() - skipping %pOF, already populated\n", in of_platform_bus_create()
366 bus_id = auxdata->name; in of_platform_bus_create()
367 platform_data = auxdata->platform_data; in of_platform_bus_create()
373 * device tree files. in of_platform_bus_create()
385 rc = of_platform_bus_create(child, matches, lookup, &dev->dev, strict); in of_platform_bus_create()
396 * of_platform_bus_probe() - Probe the device-tree for platform buses
397 * @root: parent of the first level to probe or NULL for the root of the tree
406 struct device *parent) in of_platform_bus_probe()
413 return -EINVAL; in of_platform_bus_probe()
437 * of_platform_populate() - Populate platform_devices from device tree data
438 * @root: parent of the first level to probe or NULL for the root of the tree
440 * @lookup: auxdata table for matching id and platform_data with device nodes
443 * Similar to of_platform_bus_probe(), this function walks the device tree
445 * convention of requiring all device nodes to have a 'compatible' property,
458 struct device *parent) in of_platform_populate()
465 return -EINVAL; in of_platform_populate()
489 struct device *parent) in of_platform_default_populate()
498 { .compatible = "qcom,rmtfs-mem" },
499 { .compatible = "qcom,cmd-db" },
502 { .compatible = "nvmem-rmem" },
503 { .compatible = "google,open-dice" },
514 return -ENODEV; in of_platform_default_populate_init()
523 if (of_property_present(of_chosen, "linux,bootx-noscreen")) { in of_platform_default_populate_init()
531 dev = platform_device_alloc("bootx-noscreen", 0); in of_platform_default_populate_init()
533 return -ENOMEM; in of_platform_default_populate_init()
542 * For OF framebuffers, first create the device for the boot display, in of_platform_default_populate_init()
548 !of_get_property(node, "linux,boot-display", NULL)) in of_platform_default_populate_init()
550 dev = of_platform_device_create(node, "of-display", NULL); in of_platform_default_populate_init()
553 return -ENOMEM; in of_platform_default_populate_init()
560 const char *of_display_format = "of-display.%d"; in of_platform_default_populate_init()
572 * platform_devices for every node in /reserved-memory with a in of_platform_default_populate_init()
584 node = of_get_compatible_child(of_chosen, "simple-framebuffer"); in of_platform_default_populate_init()
587 * Since a "simple-framebuffer" device is already added in of_platform_default_populate_init()
589 * to prevent it from registering another device for the in of_platform_default_populate_init()
616 int of_platform_device_destroy(struct device *dev, void *data) in of_platform_device_destroy()
618 /* Do not touch devices not populated from the device tree */ in of_platform_device_destroy()
619 if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED)) in of_platform_device_destroy()
623 if (of_node_check_flag(dev->of_node, OF_POPULATED_BUS)) in of_platform_device_destroy()
626 of_node_clear_flag(dev->of_node, OF_POPULATED); in of_platform_device_destroy()
627 of_node_clear_flag(dev->of_node, OF_POPULATED_BUS); in of_platform_device_destroy()
629 if (dev->bus == &platform_bus_type) in of_platform_device_destroy()
632 else if (dev->bus == &amba_bustype) in of_platform_device_destroy()
641 * of_platform_depopulate() - Remove devices populated from device tree
642 * @parent: device which children will be removed
645 * of the given device (and, recursively, their children) that have been
646 * created from their respective device tree nodes (and only those,
647 * leaving others - eg. manually created - unharmed).
649 void of_platform_depopulate(struct device *parent) in of_platform_depopulate()
651 if (parent->of_node && of_node_check_flag(parent->of_node, OF_POPULATED_BUS)) { in of_platform_depopulate()
653 of_node_clear_flag(parent->of_node, OF_POPULATED_BUS); in of_platform_depopulate()
658 static void devm_of_platform_populate_release(struct device *dev, void *res) in devm_of_platform_populate_release()
660 of_platform_depopulate(*(struct device **)res); in devm_of_platform_populate_release()
664 * devm_of_platform_populate() - Populate platform_devices from device tree data
665 * @dev: device that requested to populate from device tree data
668 * of_platform_depopulate() when the device is unbound from the bus.
672 int devm_of_platform_populate(struct device *dev) in devm_of_platform_populate()
674 struct device **ptr; in devm_of_platform_populate()
678 return -EINVAL; in devm_of_platform_populate()
683 return -ENOMEM; in devm_of_platform_populate()
685 ret = of_platform_populate(dev->of_node, NULL, NULL, dev); in devm_of_platform_populate()
697 static int devm_of_platform_match(struct device *dev, void *res, void *data) in devm_of_platform_match()
699 struct device **ptr = res; in devm_of_platform_match()
710 * devm_of_platform_depopulate() - Remove devices populated from device tree
711 * @dev: device that requested to depopulate from device tree data
714 * of the given device (and, recursively, their children) that have been
715 * created from their respective device tree nodes (and only those,
716 * leaving others - eg. manually created - unharmed).
718 void devm_of_platform_depopulate(struct device *dev) in devm_of_platform_depopulate()
740 if (!of_node_check_flag(rd->dn->parent, OF_POPULATED_BUS)) in of_platform_notify()
744 if (of_node_check_flag(rd->dn, OF_POPULATED)) in of_platform_notify()
748 * Clear the flag before adding the device so that fw_devlink in of_platform_notify()
749 * doesn't skip adding consumers to this device. in of_platform_notify()
751 rd->dn->fwnode.flags &= ~FWNODE_FLAG_NOT_DEVICE; in of_platform_notify()
752 /* pdev_parent may be NULL when no bus platform device */ in of_platform_notify()
753 pdev_parent = of_find_device_by_node(rd->dn->parent); in of_platform_notify()
754 pdev = of_platform_device_create(rd->dn, NULL, in of_platform_notify()
755 pdev_parent ? &pdev_parent->dev : NULL); in of_platform_notify()
760 __func__, rd->dn); in of_platform_notify()
762 return notifier_from_errno(-EINVAL); in of_platform_notify()
769 if (!of_node_check_flag(rd->dn, OF_POPULATED)) in of_platform_notify()
772 /* find our device by node */ in of_platform_notify()
773 pdev = of_find_device_by_node(rd->dn); in of_platform_notify()
778 of_platform_device_destroy(&pdev->dev, &children_left); in of_platform_notify()