of_device.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_OF_DEVICE_H
  3. #define _LINUX_OF_DEVICE_H
  4. #include <linux/cpu.h>
  5. #include <linux/platform_device.h>
  6. #include <linux/of_platform.h> /* temporary until merge */
  7. #include <linux/of.h>
  8. #include <linux/mod_devicetable.h>
  9. struct device;
  10. #ifdef CONFIG_OF
  11. extern const struct of_device_id *of_match_device(
  12. const struct of_device_id *matches, const struct device *dev);
  13. /**
  14. * of_driver_match_device - Tell if a driver's of_match_table matches a device.
  15. * @drv: the device_driver structure to test
  16. * @dev: the device structure to match against
  17. */
  18. static inline int of_driver_match_device(struct device *dev,
  19. const struct device_driver *drv)
  20. {
  21. return of_match_device(drv->of_match_table, dev) != NULL;
  22. }
  23. extern int of_device_add(struct platform_device *pdev);
  24. extern int of_device_register(struct platform_device *ofdev);
  25. extern void of_device_unregister(struct platform_device *ofdev);
  26. extern const void *of_device_get_match_data(const struct device *dev);
  27. extern ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len);
  28. extern int of_device_request_module(struct device *dev);
  29. extern void of_device_uevent(struct device *dev, struct kobj_uevent_env *env);
  30. extern int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env);
  31. static inline struct device_node *of_cpu_device_node_get(int cpu)
  32. {
  33. struct device *cpu_dev;
  34. cpu_dev = get_cpu_device(cpu);
  35. if (!cpu_dev)
  36. return of_get_cpu_node(cpu, NULL);
  37. return of_node_get(cpu_dev->of_node);
  38. }
  39. int of_dma_configure_id(struct device *dev,
  40. struct device_node *np,
  41. bool force_dma, const u32 *id);
  42. static inline int of_dma_configure(struct device *dev,
  43. struct device_node *np,
  44. bool force_dma)
  45. {
  46. return of_dma_configure_id(dev, np, force_dma, NULL);
  47. }
  48. #else /* CONFIG_OF */
  49. static inline int of_driver_match_device(struct device *dev,
  50. const struct device_driver *drv)
  51. {
  52. return 0;
  53. }
  54. static inline void of_device_uevent(struct device *dev,
  55. struct kobj_uevent_env *env) { }
  56. static inline const void *of_device_get_match_data(const struct device *dev)
  57. {
  58. return NULL;
  59. }
  60. static inline int of_device_modalias(struct device *dev,
  61. char *str, ssize_t len)
  62. {
  63. return -ENODEV;
  64. }
  65. static inline int of_device_request_module(struct device *dev)
  66. {
  67. return -ENODEV;
  68. }
  69. static inline int of_device_uevent_modalias(struct device *dev,
  70. struct kobj_uevent_env *env)
  71. {
  72. return -ENODEV;
  73. }
  74. static inline const struct of_device_id *of_match_device(
  75. const struct of_device_id *matches, const struct device *dev)
  76. {
  77. return NULL;
  78. }
  79. static inline struct device_node *of_cpu_device_node_get(int cpu)
  80. {
  81. return NULL;
  82. }
  83. static inline int of_dma_configure_id(struct device *dev,
  84. struct device_node *np,
  85. bool force_dma,
  86. const u32 *id)
  87. {
  88. return 0;
  89. }
  90. static inline int of_dma_configure(struct device *dev,
  91. struct device_node *np,
  92. bool force_dma)
  93. {
  94. return 0;
  95. }
  96. #endif /* CONFIG_OF */
  97. #endif /* _LINUX_OF_DEVICE_H */