smd.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #ifndef __QCOM_SMD_H__
  2. #define __QCOM_SMD_H__
  3. #include <linux/device.h>
  4. #include <linux/mod_devicetable.h>
  5. struct qcom_smd;
  6. struct qcom_smd_channel;
  7. struct qcom_smd_lookup;
  8. /**
  9. * struct qcom_smd_id - struct used for matching a smd device
  10. * @name: name of the channel
  11. */
  12. struct qcom_smd_id {
  13. char name[20];
  14. };
  15. /**
  16. * struct qcom_smd_device - smd device struct
  17. * @dev: the device struct
  18. * @channel: handle to the smd channel for this device
  19. */
  20. struct qcom_smd_device {
  21. struct device dev;
  22. struct qcom_smd_channel *channel;
  23. };
  24. typedef int (*qcom_smd_cb_t)(struct qcom_smd_channel *, const void *, size_t);
  25. /**
  26. * struct qcom_smd_driver - smd driver struct
  27. * @driver: underlying device driver
  28. * @smd_match_table: static channel match table
  29. * @probe: invoked when the smd channel is found
  30. * @remove: invoked when the smd channel is closed
  31. * @callback: invoked when an inbound message is received on the channel,
  32. * should return 0 on success or -EBUSY if the data cannot be
  33. * consumed at this time
  34. */
  35. struct qcom_smd_driver {
  36. struct device_driver driver;
  37. const struct qcom_smd_id *smd_match_table;
  38. int (*probe)(struct qcom_smd_device *dev);
  39. void (*remove)(struct qcom_smd_device *dev);
  40. qcom_smd_cb_t callback;
  41. };
  42. #if IS_ENABLED(CONFIG_QCOM_SMD)
  43. int qcom_smd_driver_register(struct qcom_smd_driver *drv);
  44. void qcom_smd_driver_unregister(struct qcom_smd_driver *drv);
  45. struct qcom_smd_channel *qcom_smd_open_channel(struct qcom_smd_channel *channel,
  46. const char *name,
  47. qcom_smd_cb_t cb);
  48. void qcom_smd_close_channel(struct qcom_smd_channel *channel);
  49. void *qcom_smd_get_drvdata(struct qcom_smd_channel *channel);
  50. void qcom_smd_set_drvdata(struct qcom_smd_channel *channel, void *data);
  51. int qcom_smd_send(struct qcom_smd_channel *channel, const void *data, int len);
  52. struct qcom_smd_edge *qcom_smd_register_edge(struct device *parent,
  53. struct device_node *node);
  54. int qcom_smd_unregister_edge(struct qcom_smd_edge *edge);
  55. #else
  56. static inline int qcom_smd_driver_register(struct qcom_smd_driver *drv)
  57. {
  58. return -ENXIO;
  59. }
  60. static inline void qcom_smd_driver_unregister(struct qcom_smd_driver *drv)
  61. {
  62. /* This shouldn't be possible */
  63. WARN_ON(1);
  64. }
  65. static inline struct qcom_smd_channel *
  66. qcom_smd_open_channel(struct qcom_smd_channel *channel,
  67. const char *name,
  68. qcom_smd_cb_t cb)
  69. {
  70. /* This shouldn't be possible */
  71. WARN_ON(1);
  72. return NULL;
  73. }
  74. static inline void qcom_smd_close_channel(struct qcom_smd_channel *channel)
  75. {
  76. /* This shouldn't be possible */
  77. WARN_ON(1);
  78. }
  79. static inline void *qcom_smd_get_drvdata(struct qcom_smd_channel *channel)
  80. {
  81. /* This shouldn't be possible */
  82. WARN_ON(1);
  83. return NULL;
  84. }
  85. static inline void qcom_smd_set_drvdata(struct qcom_smd_channel *channel, void *data)
  86. {
  87. /* This shouldn't be possible */
  88. WARN_ON(1);
  89. }
  90. static inline int qcom_smd_send(struct qcom_smd_channel *channel,
  91. const void *data, int len)
  92. {
  93. /* This shouldn't be possible */
  94. WARN_ON(1);
  95. return -ENXIO;
  96. }
  97. static inline struct qcom_smd_edge *
  98. qcom_smd_register_edge(struct device *parent,
  99. struct device_node *node)
  100. {
  101. return ERR_PTR(-ENXIO);
  102. }
  103. static inline int qcom_smd_unregister_edge(struct qcom_smd_edge *edge)
  104. {
  105. /* This shouldn't be possible */
  106. WARN_ON(1);
  107. return -ENXIO;
  108. }
  109. #endif
  110. #define module_qcom_smd_driver(__smd_driver) \
  111. module_driver(__smd_driver, qcom_smd_driver_register, \
  112. qcom_smd_driver_unregister)
  113. #endif