of_platform.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * <benh@kernel.crashing.org>
  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. /* Platform devices and busses creation */
  59. extern struct platform_device *of_platform_device_create(struct device_node *np,
  60. const char *bus_id,
  61. struct device *parent);
  62. extern int of_platform_device_destroy(struct device *dev, void *data);
  63. extern int of_platform_bus_probe(struct device_node *root,
  64. const struct of_device_id *matches,
  65. struct device *parent);
  66. #ifdef CONFIG_OF_ADDRESS
  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. static inline int of_platform_populate(struct device_node *root,
  79. const struct of_device_id *matches,
  80. const struct of_dev_auxdata *lookup,
  81. struct device *parent)
  82. {
  83. return -ENODEV;
  84. }
  85. static inline int of_platform_default_populate(struct device_node *root,
  86. const struct of_dev_auxdata *lookup,
  87. struct device *parent)
  88. {
  89. return -ENODEV;
  90. }
  91. static inline void of_platform_depopulate(struct device *parent) { }
  92. static inline int devm_of_platform_populate(struct device *dev)
  93. {
  94. return -ENODEV;
  95. }
  96. static inline void devm_of_platform_depopulate(struct device *dev) { }
  97. #endif
  98. #if defined(CONFIG_OF_DYNAMIC) && defined(CONFIG_OF_ADDRESS)
  99. extern void of_platform_register_reconfig_notifier(void);
  100. #else
  101. static inline void of_platform_register_reconfig_notifier(void) { }
  102. #endif
  103. #endif /* _LINUX_OF_PLATFORM_H */