tsif_api.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /**
  2. * TSIF driver
  3. *
  4. * Kernel API
  5. *
  6. * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 and
  10. * only version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #ifndef _TSIF_API_H_
  19. #define _TSIF_API_H_
  20. /**
  21. * Theory of operation
  22. *
  23. * TSIF driver maintains internal cyclic data buffer where
  24. * received TSIF packets are stored. Size of buffer, in packets,
  25. * and its address, may be obtained by tsif_get_info().
  26. *
  27. * TSIF stream delivered to the client that should register with
  28. * TSIF driver using tsif_attach()
  29. *
  30. * Producer-consumer pattern used. TSIF driver act as producer,
  31. * writing data to the buffer; clientis consumer.
  32. * 2 indexes maintained by the TSIF driver:
  33. * - wi (write index) points to the next item to be written by
  34. * TSIF
  35. * - ri (read index) points to the next item available for read
  36. * by the client.
  37. * Write index advanced by the TSIF driver when new data
  38. * received;
  39. * Read index advanced only when client tell so to the TSIF
  40. * driver by tsif_reclaim_packets()
  41. *
  42. * Consumer may directly access data TSIF buffer between ri and
  43. * wi. When ri==wi, buffer is empty.
  44. *
  45. * TSIF driver notifies client about any change by calling
  46. * notify function. Client should use tsif_get_state() to query
  47. * new state.
  48. */
  49. /* bytes in TSIF packet. not customizable */
  50. #define TSIF_PKT_SIZE (192)
  51. /**
  52. * tsif_pkt_status - get TSIF packet status
  53. *
  54. * @pkt: TSIF packet location
  55. *
  56. * Return last DWORD of packet, containing status.
  57. * Status dword consists of:
  58. * - 3 low bytes TTS
  59. * - 1 byte (last byte of packet) with status bits
  60. */
  61. static inline u32 tsif_pkt_status(void *pkt)
  62. {
  63. u32 *x = pkt;
  64. return x[TSIF_PKT_SIZE / sizeof(u32) - 1];
  65. }
  66. /**
  67. * Status dword parts for status returned by @tsif_pkt_status
  68. */
  69. #define TSIF_STATUS_TTS(x) ((x) & 0xffffff)
  70. #define TSIF_STATUS_VALID(x) ((x) & (1<<24))
  71. #define TSIF_STATUS_FIRST(x) ((x) & (1<<25))
  72. #define TSIF_STATUS_OVFLW(x) ((x) & (1<<26))
  73. #define TSIF_STATUS_ERROR(x) ((x) & (1<<27))
  74. #define TSIF_STATUS_NULL(x) ((x) & (1<<28))
  75. #define TSIF_STATUS_TIMEO(x) ((x) & (1<<30))
  76. /**
  77. * enum tsif_state - TSIF device state
  78. * @tsif_state_stopped: Idle state, data acquisition not running
  79. * @tsif_state_running: Data acquisition in progress
  80. * @tsif_state_flushing: Device is flushing
  81. *
  82. * State transition diagram:
  83. *
  84. * init -> tsif_state_stopped
  85. *
  86. * tsif_state_stopped:
  87. * - open -> tsif_state_running
  88. *
  89. * tsif_state_running:
  90. * - close -> tsif_state_flushing
  91. *
  92. * tsif_state_flushing:
  93. * - flushed -> tsif_state_stopped
  94. */
  95. enum tsif_state {
  96. tsif_state_stopped = 0,
  97. tsif_state_running = 1,
  98. tsif_state_flushing = 2,
  99. tsif_state_error = 3,
  100. };
  101. /**
  102. * tsif_get_active - return active tsif hardware instance
  103. *
  104. * Return TSIF instance to use (selected by CONFIG_MSM_USE_TSIF1)
  105. */
  106. int tsif_get_active(void);
  107. /**
  108. * tsif_attach - Attach to the device.
  109. * @id: TSIF device ID, used to identify TSIF instance.
  110. * @notify: client callback, called when
  111. * any client visible TSIF state changed.
  112. * This includes new data available and device state change
  113. * @data: client data, will be passed to @notify
  114. *
  115. * Return TSIF cookie or error code
  116. *
  117. * Should be called prior to any other tsif_XXX function.
  118. */
  119. void *tsif_attach(int id, void (*notify)(void *client_data), void *client_data);
  120. /**
  121. * tsif_detach - detach from device
  122. * @cookie: TSIF cookie previously obtained with tsif_attach()
  123. */
  124. void tsif_detach(void *cookie);
  125. /**
  126. * tsif_get_info - get data buffer info
  127. * @cookie: TSIF cookie previously obtained with tsif_attach()
  128. * @pdata: if not NULL, TSIF data buffer will be stored there
  129. * @psize: if not NULL, TSIF data buffer size, in packets,
  130. * will be stored there
  131. *
  132. * Data buffer information should be queried after each tsif_start() before
  133. * using data; since data buffer will be re-allocated on tsif_start()
  134. */
  135. void tsif_get_info(void *cookie, void **pdata, int *psize);
  136. /**
  137. * tsif_set_mode - set TSIF mode
  138. * @cookie: TSIF cookie previously obtained with tsif_attach()
  139. * @mode: desired mode of operation
  140. *
  141. * Return error code
  142. *
  143. * Mode may be changed only when TSIF device is stopped.
  144. */
  145. int tsif_set_mode(void *cookie, int mode);
  146. /**
  147. * tsif_set_time_limit - set TSIF time limit
  148. * @cookie: TSIF cookie previously obtained with tsif_attach()
  149. * @value: desired time limit, 0 to disable
  150. *
  151. * Return error code
  152. *
  153. * Time limit may be changed only when TSIF device is stopped.
  154. */
  155. int tsif_set_time_limit(void *cookie, u32 value);
  156. /**
  157. * tsif_set_buf_config - configure data buffer
  158. *
  159. * @cookie: TSIF cookie previously obtained with tsif_attach()
  160. * @pkts_in_chunk: requested number of packets per chunk
  161. * @chunks_in_buf: requested number of chunks in buffer
  162. *
  163. * Return error code
  164. *
  165. * Parameter selection criteria:
  166. *
  167. * - @pkts_in_chunk defines size of DMA transfer and, in turn, time between
  168. * consecutive DMA transfers. Increase @pkts_in_chunk reduces chance for
  169. * hardware overflow. If TSIF stats reports overflows, increase it.
  170. *
  171. * - @chunks_in_buf * @pkts_in_chunk defines total buffer size. Increase this
  172. * parameter if client latency is large and TSIF reports "soft drop" in its
  173. * stats
  174. */
  175. int tsif_set_buf_config(void *cookie, u32 pkts_in_chunk, u32 chunks_in_buf);
  176. /**
  177. * tsif_get_state - query current data buffer information
  178. * @cookie: TSIF cookie previously obtained with tsif_attach()
  179. * @ri: if not NULL, read index will be stored here
  180. * @wi: if not NULL, write index will be stored here
  181. * @state: if not NULL, state will be stored here
  182. */
  183. void tsif_get_state(void *cookie, int *ri, int *wi, enum tsif_state *state);
  184. /**
  185. * tsif_set_clk_inverse - set whether to inverse the clock signal.
  186. * @cookie: TSIF cookie previously obtained with tsif_attach()
  187. * @inverse: 1 to inverse the clock, 0 otherwise. Default is 0.
  188. *
  189. * Return error code
  190. *
  191. * Setting may be changed only when TSIF device is stopped.
  192. */
  193. int tsif_set_clk_inverse(void *cookie, int inverse);
  194. /**
  195. * tsif_set_data_inverse - set whether to inverse the data signal.
  196. * @cookie: TSIF cookie previously obtained with tsif_attach()
  197. * @inverse: 1 to inverse the clock, 0 otherwise. Default is 0.
  198. *
  199. * Return error code
  200. *
  201. * Setting may be changed only when TSIF device is stopped.
  202. */
  203. int tsif_set_data_inverse(void *cookie, int inverse);
  204. /**
  205. * tsif_set_sync_inverse - set whether to inverse the sync signal.
  206. * @cookie: TSIF cookie previously obtained with tsif_attach()
  207. * @inverse: 1 to inverse the clock, 0 otherwise. Default is 0.
  208. *
  209. * Return error code
  210. *
  211. * Setting may be changed only when TSIF device is stopped.
  212. */
  213. int tsif_set_sync_inverse(void *cookie, int inverse);
  214. /**
  215. * tsif_set_enable_inverse - set whether to inverse the enable signal.
  216. * @cookie: TSIF cookie previously obtained with tsif_attach()
  217. * @inverse: 1 to inverse the clock, 0 otherwise. Default is 0.
  218. *
  219. * Return error code
  220. *
  221. * Setting may be changed only when TSIF device is stopped.
  222. */
  223. int tsif_set_enable_inverse(void *cookie, int inverse);
  224. /**
  225. * tsif_start - start data acquisition
  226. * @cookie: TSIF cookie previously obtained with tsif_attach()
  227. *
  228. * Return error code
  229. */
  230. int tsif_start(void *cookie);
  231. /**
  232. * tsif_stop - stop data acquisition
  233. * @cookie: TSIF cookie previously obtained with tsif_attach()
  234. *
  235. * Data buffer allocated during this function call; thus client should
  236. * query data buffer info using tsif_get_info() and reset its data pointers.
  237. */
  238. void tsif_stop(void *cookie);
  239. /**
  240. * tsif_get_ref_clk_counter - return the TSIF clock reference (TCR) counter.
  241. * @cookie: TSIF cookie previously obtained with tsif_attach()
  242. * @tcr_counter: the value of TCR counter
  243. *
  244. * Return error code
  245. *
  246. * TCR increments at a rate equal to 27 MHz/256 = 105.47 kHz.
  247. */
  248. int tsif_get_ref_clk_counter(void *cookie, u32 *tcr_counter);
  249. /**
  250. * tsif_reclaim_packets - inform that buffer space may be reclaimed
  251. * @cookie: TSIF cookie previously obtained with tsif_attach()
  252. * @ri: new value for read index
  253. */
  254. void tsif_reclaim_packets(void *cookie, int ri);
  255. #endif /* _TSIF_API_H_ */