of.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * of.c The helpers for hcd device tree support
  3. *
  4. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  5. * Author: Peter Chen <peter.chen@freescale.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 of
  9. * the License as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/of.h>
  20. #include <linux/usb/of.h>
  21. /**
  22. * usb_of_get_child_node - Find the device node match port number
  23. * @parent: the parent device node
  24. * @portnum: the port number which device is connecting
  25. *
  26. * Find the node from device tree according to its port number.
  27. *
  28. * Return: On success, a pointer to the device node, %NULL on failure.
  29. */
  30. struct device_node *usb_of_get_child_node(struct device_node *parent,
  31. int portnum)
  32. {
  33. struct device_node *node;
  34. u32 port;
  35. for_each_child_of_node(parent, node) {
  36. if (!of_property_read_u32(node, "reg", &port)) {
  37. if (port == portnum)
  38. return node;
  39. }
  40. }
  41. return NULL;
  42. }
  43. EXPORT_SYMBOL_GPL(usb_of_get_child_node);