1 // SPDX-License-Identifier: GPL-2.0
3 * of.c The helpers for hcd device tree support
5 * Copyright (C) 2016 Freescale Semiconductor, Inc.
10 #include <linux/of_platform.h>
11 #include <linux/usb/of.h>
14 * usb_of_get_child_node - Find the device node match port number
15 * @parent: the parent device node
16 * @portnum: the port number which device is connecting
18 * Find the node from device tree according to its port number.
20 * Return: A pointer to the node with incremented refcount if found, or
23 struct device_node *usb_of_get_child_node(struct device_node *parent,
26 struct device_node *node;
29 for_each_child_of_node(parent, node) {
30 if (!of_property_read_u32(node, "reg", &port)) {
38 EXPORT_SYMBOL_GPL(usb_of_get_child_node);
41 * usb_of_get_companion_dev - Find the companion device
42 * @dev: the device pointer to find a companion
44 * Find the companion device from platform bus.
46 * Takes a reference to the returned struct device which needs to be dropped
49 * Return: On success, a pointer to the companion device, %NULL on failure.
51 struct device *usb_of_get_companion_dev(struct device *dev)
53 struct device_node *node;
54 struct platform_device *pdev = NULL;
56 node = of_parse_phandle(dev->of_node, "companion", 0);
58 pdev = of_find_device_by_node(node);
62 return pdev ? &pdev->dev : NULL;
64 EXPORT_SYMBOL_GPL(usb_of_get_companion_dev);