greybus.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Greybus driver and device API
  4. *
  5. * Copyright 2014-2015 Google Inc.
  6. * Copyright 2014-2015 Linaro Ltd.
  7. */
  8. #ifndef __LINUX_GREYBUS_H
  9. #define __LINUX_GREYBUS_H
  10. #ifdef __KERNEL__
  11. #include <linux/kernel.h>
  12. #include <linux/types.h>
  13. #include <linux/list.h>
  14. #include <linux/slab.h>
  15. #include <linux/device.h>
  16. #include <linux/module.h>
  17. #include <linux/pm_runtime.h>
  18. #include <linux/idr.h>
  19. #include <linux/greybus/greybus_id.h>
  20. #include <linux/greybus/greybus_manifest.h>
  21. #include <linux/greybus/greybus_protocols.h>
  22. #include <linux/greybus/manifest.h>
  23. #include <linux/greybus/hd.h>
  24. #include <linux/greybus/svc.h>
  25. #include <linux/greybus/control.h>
  26. #include <linux/greybus/module.h>
  27. #include <linux/greybus/interface.h>
  28. #include <linux/greybus/bundle.h>
  29. #include <linux/greybus/connection.h>
  30. #include <linux/greybus/operation.h>
  31. /* Matches up with the Greybus Protocol specification document */
  32. #define GREYBUS_VERSION_MAJOR 0x00
  33. #define GREYBUS_VERSION_MINOR 0x01
  34. #define GREYBUS_ID_MATCH_DEVICE \
  35. (GREYBUS_ID_MATCH_VENDOR | GREYBUS_ID_MATCH_PRODUCT)
  36. #define GREYBUS_DEVICE(v, p) \
  37. .match_flags = GREYBUS_ID_MATCH_DEVICE, \
  38. .vendor = (v), \
  39. .product = (p),
  40. #define GREYBUS_DEVICE_CLASS(c) \
  41. .match_flags = GREYBUS_ID_MATCH_CLASS, \
  42. .class = (c),
  43. /* Maximum number of CPorts */
  44. #define CPORT_ID_MAX 4095 /* UniPro max id is 4095 */
  45. #define CPORT_ID_BAD U16_MAX
  46. struct greybus_driver {
  47. const char *name;
  48. int (*probe)(struct gb_bundle *bundle,
  49. const struct greybus_bundle_id *id);
  50. void (*disconnect)(struct gb_bundle *bundle);
  51. const struct greybus_bundle_id *id_table;
  52. struct device_driver driver;
  53. };
  54. #define to_greybus_driver(d) container_of(d, struct greybus_driver, driver)
  55. static inline void greybus_set_drvdata(struct gb_bundle *bundle, void *data)
  56. {
  57. dev_set_drvdata(&bundle->dev, data);
  58. }
  59. static inline void *greybus_get_drvdata(struct gb_bundle *bundle)
  60. {
  61. return dev_get_drvdata(&bundle->dev);
  62. }
  63. /* Don't call these directly, use the module_greybus_driver() macro instead */
  64. int greybus_register_driver(struct greybus_driver *driver,
  65. struct module *module, const char *mod_name);
  66. void greybus_deregister_driver(struct greybus_driver *driver);
  67. /* define to get proper THIS_MODULE and KBUILD_MODNAME values */
  68. #define greybus_register(driver) \
  69. greybus_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
  70. #define greybus_deregister(driver) \
  71. greybus_deregister_driver(driver)
  72. /**
  73. * module_greybus_driver() - Helper macro for registering a Greybus driver
  74. * @__greybus_driver: greybus_driver structure
  75. *
  76. * Helper macro for Greybus drivers to set up proper module init / exit
  77. * functions. Replaces module_init() and module_exit() and keeps people from
  78. * printing pointless things to the kernel log when their driver is loaded.
  79. */
  80. #define module_greybus_driver(__greybus_driver) \
  81. module_driver(__greybus_driver, greybus_register, greybus_deregister)
  82. int greybus_disabled(void);
  83. void gb_debugfs_init(void);
  84. void gb_debugfs_cleanup(void);
  85. struct dentry *gb_debugfs_get(void);
  86. extern struct bus_type greybus_bus_type;
  87. extern struct device_type greybus_hd_type;
  88. extern struct device_type greybus_module_type;
  89. extern struct device_type greybus_interface_type;
  90. extern struct device_type greybus_control_type;
  91. extern struct device_type greybus_bundle_type;
  92. extern struct device_type greybus_svc_type;
  93. static inline int is_gb_host_device(const struct device *dev)
  94. {
  95. return dev->type == &greybus_hd_type;
  96. }
  97. static inline int is_gb_module(const struct device *dev)
  98. {
  99. return dev->type == &greybus_module_type;
  100. }
  101. static inline int is_gb_interface(const struct device *dev)
  102. {
  103. return dev->type == &greybus_interface_type;
  104. }
  105. static inline int is_gb_control(const struct device *dev)
  106. {
  107. return dev->type == &greybus_control_type;
  108. }
  109. static inline int is_gb_bundle(const struct device *dev)
  110. {
  111. return dev->type == &greybus_bundle_type;
  112. }
  113. static inline int is_gb_svc(const struct device *dev)
  114. {
  115. return dev->type == &greybus_svc_type;
  116. }
  117. static inline bool cport_id_valid(struct gb_host_device *hd, u16 cport_id)
  118. {
  119. return cport_id != CPORT_ID_BAD && cport_id < hd->num_cports;
  120. }
  121. #endif /* __KERNEL__ */
  122. #endif /* __LINUX_GREYBUS_H */