bgcom.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #ifndef BGCOM_H
  14. #define BGCOM_H
  15. #define BGCOM_REG_TZ_TO_MASTER_STATUS 0x01
  16. #define BGCOM_REG_TZ_TO_MASTER_DATA 0x03
  17. #define BGCOM_REG_SLAVE_STATUS 0x05
  18. #define BGCOM_REG_TIMESTAMP 0x07
  19. #define BGCOM_REG_SLAVE_STATUS_AUTO_CLEAR 0x09
  20. #define BGCOM_REG_FIFO_FILL 0x0B
  21. #define BGCOM_REG_FIFO_SIZE 0x0D
  22. #define BGCOM_REG_TZ_TO_SLAVE_COMMAND 0x0E
  23. #define BGCOM_REG_TZ_TO_SLAVE_DATA 0x10
  24. #define BGCOM_REG_MASTER_STATUS 0x12
  25. #define BGCOM_REG_MASTER_COMMAND 0x14
  26. #define BGCOM_REG_MSG_WR_REG_4 0x16
  27. #define BGCOM_REG_TO_SLAVE_FIFO 0x40
  28. #define BGCOM_REG_TO_MASTER_FIFO 0x41
  29. #define BGCOM_REG_TO_SLAVE_AHB 0x42
  30. #define BGCOM_REG_TO_MASTER_AHB 0x43
  31. /* Enum to define the bgcom SPI state */
  32. enum bgcom_spi_state {
  33. BGCOM_SPI_FREE = 0,
  34. BGCOM_SPI_BUSY,
  35. };
  36. /* Enums to identify Blackghost events */
  37. enum bgcom_event_type {
  38. BGCOM_EVENT_NONE = 0,
  39. BGCOM_EVENT_APPLICATION_RUNNING,
  40. BGCOM_EVENT_TO_SLAVE_FIFO_READY,
  41. BGCOM_EVENT_TO_MASTER_FIFO_READY,
  42. BGCOM_EVENT_AHB_READY,
  43. BGCOM_EVENT_TO_MASTER_FIFO_USED,
  44. BGCOM_EVENT_TO_SLAVE_FIFO_FREE,
  45. BGCOM_EVENT_TIMESTAMP_UPDATE,
  46. BGCOM_EVENT_RESET_OCCURRED,
  47. BGCOM_EVENT_ERROR_WRITE_FIFO_OVERRUN,
  48. BGCOM_EVENT_ERROR_WRITE_FIFO_BUS_ERR,
  49. BGCOM_EVENT_ERROR_WRITE_FIFO_ACCESS,
  50. BGCOM_EVENT_ERROR_READ_FIFO_UNDERRUN,
  51. BGCOM_EVENT_ERROR_READ_FIFO_BUS_ERR,
  52. BGCOM_EVENT_ERROR_READ_FIFO_ACCESS,
  53. BGCOM_EVENT_ERROR_TRUNCATED_READ,
  54. BGCOM_EVENT_ERROR_TRUNCATED_WRITE,
  55. BGCOM_EVENT_ERROR_AHB_ILLEGAL_ADDRESS,
  56. BGCOM_EVENT_ERROR_AHB_BUS_ERR,
  57. BGCOM_EVENT_ERROR_UNKNOWN,
  58. };
  59. /* Event specific data */
  60. union bgcom_event_data_type {
  61. uint32_t unused;
  62. bool application_running; /* BGCOM_EVENT_APPLICATION_RUNNING */
  63. bool to_slave_fifo_ready; /* BGCOM_EVENT_TO_SLAVE_FIFO_READY */
  64. bool to_master_fifo_ready; /* BGCOM_EVENT_TO_MASTER_FIFO_READY */
  65. bool ahb_ready; /* BGCOM_EVENT_AHB_READY */
  66. uint16_t to_slave_fifo_free; /* BGCOM_EVENT_TO_SLAVE_FIFO_FREE */
  67. struct fifo_event_data {
  68. uint16_t to_master_fifo_used;
  69. void *data;
  70. } fifo_data;
  71. };
  72. /* Client specific data */
  73. struct bgcom_open_config_type {
  74. /** Private data pointer for client to maintain context.
  75. * This data is passed back to client in the notification callbacks.
  76. */
  77. void *priv;
  78. /* Notification callbacks to notify the BG events */
  79. void (*bgcom_notification_cb)(void *handle, void *priv,
  80. enum bgcom_event_type event,
  81. union bgcom_event_data_type *event_data);
  82. };
  83. /**
  84. * bgcom_open() - opens a channel to interact with Blackghost
  85. * @open_config: pointer to the open configuration structure
  86. *
  87. * Open a new connection to blackghost
  88. *
  89. * Return a handle on success or NULL on error
  90. */
  91. void *bgcom_open(struct bgcom_open_config_type *open_config);
  92. /**
  93. * bgcom_close() - close the exsting with Blackghost
  94. * @handle: pointer to the handle, provided by bgcom at
  95. * bgcom_open
  96. *
  97. * Open a new connection to blackghost
  98. *
  99. * Return 0 on success or error on invalid handle
  100. */
  101. int bgcom_close(void **handle);
  102. /**
  103. * bgcom_reg_read() - Read from the one or more contiguous registers from BG
  104. * @handle: BGCOM handle associated with the channel
  105. * @reg_start_addr : 8 bit start address of the registers to read from
  106. * @num_regs : Number of contiguous registers to read, starting
  107. * from reg_start_addr.
  108. * @read_buf : Buffer to read from the registers.
  109. * Return 0 on success or -Ve on error
  110. */
  111. int bgcom_reg_read(void *handle, uint8_t reg_start_addr,
  112. uint32_t num_regs, void *read_buf);
  113. /**
  114. * Write into the one or more contiguous registers.
  115. *
  116. * @param[in] handle BGCOM handle associated with the channel.
  117. * @param[in] reg_start_addr 8bit start address of the registers to write into.
  118. * @param[in] num_regs Number of contiguous registers to write, starting
  119. * from reg_start_addr.
  120. * @param[in] write_buf Buffer to write into the registers.
  121. *
  122. * @return
  123. * 0 if function is successful,
  124. * Otherwise returns error code.
  125. *
  126. * @sideeffects Causes the Blackghost SPI slave to wakeup. Depending up on
  127. * the operation, it may also wakeup the complete Blackghost.
  128. */
  129. /**
  130. * bgcom_reg_write() - Write to the one or more contiguous registers on BG
  131. * @handle: BGCOM handle associated with the channel
  132. * @reg_start_addr : 8 bit start address of the registers to read from
  133. * @num_regs : Number of contiguous registers to write, starting
  134. * from reg_start_addr.
  135. * @write_buf : Buffer to be written to the registers.
  136. * Return 0 on success or -Ve on error
  137. */
  138. int bgcom_reg_write(void *handle, uint8_t reg_start_addr,
  139. uint8_t num_regs, void *write_buf);
  140. /**
  141. * bgcom_fifo_read() - Read data from the TO_MASTER_FIFO.
  142. * @handle: BGCOM handle associated with the channel
  143. * @num_words : number of words to read from FIFO
  144. * @read_buf : Buffer read from FIFO.
  145. * Return 0 on success or -Ve on error
  146. */
  147. int bgcom_fifo_read(void *handle, uint32_t num_words,
  148. void *read_buf);
  149. /**
  150. * bgcom_fifo_write() - Write data to the TO_SLAVE_FIFO.
  151. * @handle: BGCOM handle associated with the channel
  152. * @num_words : number of words to write on FIFO
  153. * @write_buf : Buffer written to FIFO.
  154. * Return 0 on success or -Ve on error
  155. */
  156. int bgcom_fifo_write(void *handle, uint32_t num_words,
  157. void *write_buf);
  158. /**
  159. * bgcom_ahb_read() - Read data from the AHB memory.
  160. * @handle: BGCOM handle associated with the channel
  161. * @ahb_start_addr : Memory start address from where to read
  162. * @num_words : number of words to read from AHB
  163. * @read_buf : Buffer read from FIFO.
  164. * Return 0 on success or -Ve on error
  165. */
  166. int bgcom_ahb_read(void *handle, uint32_t ahb_start_addr,
  167. uint32_t num_words, void *read_buf);
  168. /**
  169. * bgcom_ahb_write() - Write data to the AHB memory.
  170. * @handle: BGCOM handle associated with the channel
  171. * @ahb_start_addr : Memory start address from where to start write
  172. * @num_words : number of words to read from AHB
  173. * @write_buf : Buffer to write in AHB.
  174. * Return 0 on success or -Ve on error
  175. */
  176. int bgcom_ahb_write(void *handle, uint32_t ahb_start_addr,
  177. uint32_t num_words, void *write_buf);
  178. /**
  179. * bgcom_suspend() - Suspends the channel.
  180. * @handle: BGCOM handle associated with the channel
  181. * Return 0 on success or -Ve on error
  182. */
  183. int bgcom_suspend(void *handle);
  184. /**
  185. * bgcom_resume() - Resumes the channel.
  186. * @handle: BGCOM handle associated with the channel
  187. * Return 0 on success or -Ve on error
  188. */
  189. int bgcom_resume(void *handle);
  190. int bgcom_set_spi_state(enum bgcom_spi_state state);
  191. void bgcom_bgdown_handler(void);
  192. #endif /* BGCOM_H */