of_platform.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
  3. * <benh@kernel.crashing.org>
  4. * and Arnd Bergmann, IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. */
  12. #undef DEBUG
  13. #include <linux/string.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/mod_devicetable.h>
  18. #include <linux/pci.h>
  19. #include <linux/of.h>
  20. #include <linux/of_device.h>
  21. #include <linux/of_platform.h>
  22. #include <linux/errno.h>
  23. #include <linux/topology.h>
  24. #include <asm/atomic.h>
  25. struct bus_type of_platform_bus_type = {
  26. .uevent = of_device_uevent,
  27. };
  28. EXPORT_SYMBOL(of_platform_bus_type);
  29. static int __init of_bus_driver_init(void)
  30. {
  31. return of_bus_type_init(&of_platform_bus_type, "of_platform");
  32. }
  33. postcore_initcall(of_bus_driver_init);
  34. /*
  35. * The list of OF IDs below is used for matching bus types in the
  36. * system whose devices are to be exposed as of_platform_devices.
  37. *
  38. * This is the default list valid for most platforms. This file provides
  39. * functions who can take an explicit list if necessary though
  40. *
  41. * The search is always performed recursively looking for children of
  42. * the provided device_node and recursively if such a children matches
  43. * a bus type in the list
  44. */
  45. const struct of_device_id of_default_bus_ids[] = {
  46. { .type = "soc", },
  47. { .compatible = "soc", },
  48. { .type = "plb5", },
  49. { .type = "plb4", },
  50. { .type = "opb", },
  51. { .type = "simple", },
  52. {},
  53. };
  54. static int of_dev_node_match(struct device *dev, void *data)
  55. {
  56. return to_of_device(dev)->dev.of_node == data;
  57. }
  58. struct of_device *of_find_device_by_node(struct device_node *np)
  59. {
  60. struct device *dev;
  61. dev = bus_find_device(&of_platform_bus_type,
  62. NULL, np, of_dev_node_match);
  63. if (dev)
  64. return to_of_device(dev);
  65. return NULL;
  66. }
  67. EXPORT_SYMBOL(of_find_device_by_node);
  68. static int of_dev_phandle_match(struct device *dev, void *data)
  69. {
  70. phandle *ph = data;
  71. return to_of_device(dev)->dev.of_node->phandle == *ph;
  72. }
  73. struct of_device *of_find_device_by_phandle(phandle ph)
  74. {
  75. struct device *dev;
  76. dev = bus_find_device(&of_platform_bus_type,
  77. NULL, &ph, of_dev_phandle_match);
  78. if (dev)
  79. return to_of_device(dev);
  80. return NULL;
  81. }
  82. EXPORT_SYMBOL(of_find_device_by_phandle);