of_platform.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. #ifndef _LINUX_OF_PLATFORM_H
  3. #define _LINUX_OF_PLATFORM_H
  4. /*
  5. * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
  6. * <[email protected]>
  7. */
  8. #include <linux/device.h>
  9. #include <linux/mod_devicetable.h>
  10. #include <linux/pm.h>
  11. #include <linux/of_device.h>
  12. #include <linux/platform_device.h>
  13. /**
  14. * struct of_dev_auxdata - lookup table entry for device names & platform_data
  15. * @compatible: compatible value of node to match against node
  16. * @phys_addr: Start address of registers to match against node
  17. * @name: Name to assign for matching nodes
  18. * @platform_data: platform_data to assign for matching nodes
  19. *
  20. * This lookup table allows the caller of of_platform_populate() to override
  21. * the names of devices when creating devices from the device tree. The table
  22. * should be terminated with an empty entry. It also allows the platform_data
  23. * pointer to be set.
  24. *
  25. * The reason for this functionality is that some Linux infrastructure uses
  26. * the device name to look up a specific device, but the Linux-specific names
  27. * are not encoded into the device tree, so the kernel needs to provide specific
  28. * values.
  29. *
  30. * Note: Using an auxdata lookup table should be considered a last resort when
  31. * converting a platform to use the DT. Normally the automatically generated
  32. * device name will not matter, and drivers should obtain data from the device
  33. * node instead of from an anonymous platform_data pointer.
  34. */
  35. struct of_dev_auxdata {
  36. char *compatible;
  37. resource_size_t phys_addr;
  38. char *name;
  39. void *platform_data;
  40. };
  41. /* Macro to simplify populating a lookup table */
  42. #define OF_DEV_AUXDATA(_compat,_phys,_name,_pdata) \
  43. { .compatible = _compat, .phys_addr = _phys, .name = _name, \
  44. .platform_data = _pdata }
  45. extern const struct of_device_id of_default_bus_match_table[];
  46. /* Platform drivers register/unregister */
  47. extern struct platform_device *of_device_alloc(struct device_node *np,
  48. const char *bus_id,
  49. struct device *parent);
  50. #ifdef CONFIG_OF
  51. extern struct platform_device *of_find_device_by_node(struct device_node *np);
  52. #else
  53. static inline struct platform_device *of_find_device_by_node(struct device_node *np)
  54. {
  55. return NULL;
  56. }
  57. #endif
  58. extern int of_platform_bus_probe(struct device_node *root,
  59. const struct of_device_id *matches,
  60. struct device *parent);
  61. #ifdef CONFIG_OF_ADDRESS
  62. /* Platform devices and busses creation */
  63. extern struct platform_device *of_platform_device_create(struct device_node *np,
  64. const char *bus_id,
  65. struct device *parent);
  66. extern int of_platform_device_destroy(struct device *dev, void *data);
  67. extern int of_platform_populate(struct device_node *root,
  68. const struct of_device_id *matches,
  69. const struct of_dev_auxdata *lookup,
  70. struct device *parent);
  71. extern int of_platform_default_populate(struct device_node *root,
  72. const struct of_dev_auxdata *lookup,
  73. struct device *parent);
  74. extern void of_platform_depopulate(struct device *parent);
  75. extern int devm_of_platform_populate(struct device *dev);
  76. extern void devm_of_platform_depopulate(struct device *dev);
  77. #else
  78. /* Platform devices and busses creation */
  79. static inline struct platform_device *of_platform_device_create(struct device_node *np,
  80. const char *bus_id,
  81. struct device *parent)
  82. {
  83. return NULL;
  84. }
  85. static inline int of_platform_device_destroy(struct device *dev, void *data)
  86. {
  87. return -ENODEV;
  88. }
  89. static inline int of_platform_populate(struct device_node *root,
  90. const struct of_device_id *matches,
  91. const struct of_dev_auxdata *lookup,
  92. struct device *parent)
  93. {
  94. return -ENODEV;
  95. }
  96. static inline int of_platform_default_populate(struct device_node *root,
  97. const struct of_dev_auxdata *lookup,
  98. struct device *parent)
  99. {
  100. return -ENODEV;
  101. }
  102. static inline void of_platform_depopulate(struct device *parent) { }
  103. static inline int devm_of_platform_populate(struct device *dev)
  104. {
  105. return -ENODEV;
  106. }
  107. static inline void devm_of_platform_depopulate(struct device *dev) { }
  108. #endif
  109. #if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
  110. extern void of_platform_register_reconfig_notifier(void);
  111. #else
  112. static inline void of_platform_register_reconfig_notifier(void) { }
  113. #endif
  114. #endif /* _LINUX_OF_PLATFORM_H */