imx-pcm-rpmsg.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright 2017-2021 NXP
  4. *
  5. ******************************************************************************
  6. * Communication stack of audio with rpmsg
  7. ******************************************************************************
  8. * Packet structure:
  9. * A SRTM message consists of a 10 bytes header followed by 0~N bytes of data
  10. *
  11. * +---------------+-------------------------------+
  12. * | | Content |
  13. * +---------------+-------------------------------+
  14. * | Byte Offset | 7 6 5 4 3 2 1 0 |
  15. * +---------------+---+---+---+---+---+---+---+---+
  16. * | 0 | Category |
  17. * +---------------+---+---+---+---+---+---+---+---+
  18. * | 1 ~ 2 | Version |
  19. * +---------------+---+---+---+---+---+---+---+---+
  20. * | 3 | Type |
  21. * +---------------+---+---+---+---+---+---+---+---+
  22. * | 4 | Command |
  23. * +---------------+---+---+---+---+---+---+---+---+
  24. * | 5 | Reserved0 |
  25. * +---------------+---+---+---+---+---+---+---+---+
  26. * | 6 | Reserved1 |
  27. * +---------------+---+---+---+---+---+---+---+---+
  28. * | 7 | Reserved2 |
  29. * +---------------+---+---+---+---+---+---+---+---+
  30. * | 8 | Reserved3 |
  31. * +---------------+---+---+---+---+---+---+---+---+
  32. * | 9 | Reserved4 |
  33. * +---------------+---+---+---+---+---+---+---+---+
  34. * | 10 | DATA 0 |
  35. * +---------------+---+---+---+---+---+---+---+---+
  36. * : : : : : : : : : : : : :
  37. * +---------------+---+---+---+---+---+---+---+---+
  38. * | N + 10 - 1 | DATA N-1 |
  39. * +---------------+---+---+---+---+---+---+---+---+
  40. *
  41. * +----------+------------+------------------------------------------------+
  42. * | Field | Byte | |
  43. * +----------+------------+------------------------------------------------+
  44. * | Category | 0 | The destination category. |
  45. * +----------+------------+------------------------------------------------+
  46. * | Version | 1 ~ 2 | The category version of the sender of the |
  47. * | | | packet. |
  48. * | | | The first byte represent the major version of |
  49. * | | | the packet.The second byte represent the minor |
  50. * | | | version of the packet. |
  51. * +----------+------------+------------------------------------------------+
  52. * | Type | 3 | The message type of current message packet. |
  53. * +----------+------------+------------------------------------------------+
  54. * | Command | 4 | The command byte sent to remote processor/SoC. |
  55. * +----------+------------+------------------------------------------------+
  56. * | Reserved | 5 ~ 9 | Reserved field for future extension. |
  57. * +----------+------------+------------------------------------------------+
  58. * | Data | N | The data payload of the message packet. |
  59. * +----------+------------+------------------------------------------------+
  60. *
  61. * Audio control:
  62. * SRTM Audio Control Category Request Command Table:
  63. * +----------+---------+------+---------+-------------------------------+-----------------------+
  64. * | Category | Version | Type | Command | Data | Function |
  65. * +----------+---------+------+---------+-------------------------------+-----------------------+
  66. * | 0x03 | 0x0100 | 0x00 | 0x00 | Data[0]: Audio Device Index | Open a TX Instance. |
  67. * | | | | | Data[1]: format | |
  68. * | | | | | Data[2]: channels | |
  69. * | | | | | Data[3-6]: samplerate | |
  70. * | | | | | Data[7-10]: buffer_addr | |
  71. * | | | | | Data[11-14]: buffer_size | |
  72. * | | | | | Data[15-18]: period_size | |
  73. * | | | | | Data[19-22]: buffer_tail | |
  74. * +----------+---------+------+---------+-------------------------------+-----------------------+
  75. * | 0x03 | 0x0100 | 0x00 | 0x01 | Data[0]: Audio Device Index | Start a TX Instance. |
  76. * | | | | | Same as above command | |
  77. * +----------+---------+------+---------+-------------------------------+-----------------------+
  78. * | 0x03 | 0x0100 | 0x00 | 0x02 | Data[0]: Audio Device Index | Pause a TX Instance. |
  79. * | | | | | Same as above command | |
  80. * +----------+---------+------+---------+-------------------------------+-----------------------+
  81. * | 0x03 | 0x0100 | 0x00 | 0x03 | Data[0]: Audio Device Index | Resume a TX Instance. |
  82. * +----------+---------+------+---------+-------------------------------+-----------------------+
  83. * | 0x03 | 0x0100 | 0x00 | 0x04 | Data[0]: Audio Device Index | Stop a TX Instance. |
  84. * +----------+---------+------+---------+-------------------------------+-----------------------+
  85. * | 0x03 | 0x0100 | 0x00 | 0x05 | Data[0]: Audio Device Index | Close a TX Instance. |
  86. * +----------+---------+------+---------+-------------------------------+-----------------------+
  87. * | 0x03 | 0x0100 | 0x00 | 0x06 | Data[0]: Audio Device Index | Set Parameters for |
  88. * | | | | | Data[1]: format | a TX Instance. |
  89. * | | | | | Data[2]: channels | |
  90. * | | | | | Data[3-6]: samplerate | |
  91. * | | | | | Data[7-22]: reserved | |
  92. * +----------+---------+------+---------+-------------------------------+-----------------------+
  93. * | 0x03 | 0x0100 | 0x00 | 0x07 | Data[0]: Audio Device Index | Set TX Buffer. |
  94. * | | | | | Data[1-6]: reserved | |
  95. * | | | | | Data[7-10]: buffer_addr | |
  96. * | | | | | Data[11-14]: buffer_size | |
  97. * | | | | | Data[15-18]: period_size | |
  98. * | | | | | Data[19-22]: buffer_tail | |
  99. * +----------+---------+------+---------+-------------------------------+-----------------------+
  100. * | 0x03 | 0x0100 | 0x00 | 0x08 | Data[0]: Audio Device Index | Suspend a TX Instance |
  101. * +----------+---------+------+---------+-------------------------------+-----------------------+
  102. * | 0x03 | 0x0100 | 0x00 | 0x09 | Data[0]: Audio Device Index | Resume a TX Instance. |
  103. * | | | | | Data[1]: format | |
  104. * | | | | | Data[2]: channels | |
  105. * | | | | | Data[3-6]: samplerate | |
  106. * | | | | | Data[7-10]: buffer_addr | |
  107. * | | | | | Data[11-14]: buffer_size | |
  108. * | | | | | Data[15-18]: period_size | |
  109. * | | | | | Data[19-22]: buffer_tail | |
  110. * +----------+---------+------+---------+-------------------------------+-----------------------+
  111. * | 0x03 | 0x0100 | 0x00 | 0x0A | Data[0]: Audio Device Index | Open a RX Instance. |
  112. * +----------+---------+------+---------+-------------------------------+-----------------------+
  113. * | 0x03 | 0x0100 | 0x00 | 0x0B | Data[0]: Audio Device Index | Start a RX Instance. |
  114. * +----------+---------+------+---------+-------------------------------+-----------------------+
  115. * | 0x03 | 0x0100 | 0x00 | 0x0C | Data[0]: Audio Device Index | Pause a RX Instance. |
  116. * +----------+---------+------+---------+-------------------------------+-----------------------+
  117. * | 0x03 | 0x0100 | 0x00 | 0x0D | Data[0]: Audio Device Index | Resume a RX Instance. |
  118. * +----------+---------+------+---------+-------------------------------+-----------------------+
  119. * | 0x03 | 0x0100 | 0x00 | 0x0E | Data[0]: Audio Device Index | Stop a RX Instance. |
  120. * +----------+---------+------+---------+-------------------------------+-----------------------+
  121. * | 0x03 | 0x0100 | 0x00 | 0x0F | Data[0]: Audio Device Index | Close a RX Instance. |
  122. * +----------+---------+------+---------+-------------------------------+-----------------------+
  123. * | 0x03 | 0x0100 | 0x00 | 0x10 | Data[0]: Audio Device Index | Set Parameters for |
  124. * | | | | | Data[1]: format | a RX Instance. |
  125. * | | | | | Data[2]: channels | |
  126. * | | | | | Data[3-6]: samplerate | |
  127. * | | | | | Data[7-22]: reserved | |
  128. * +----------+---------+------+---------+-------------------------------+-----------------------+
  129. * | 0x03 | 0x0100 | 0x00 | 0x11 | Data[0]: Audio Device Index | Set RX Buffer. |
  130. * | | | | | Data[1-6]: reserved | |
  131. * | | | | | Data[7-10]: buffer_addr | |
  132. * | | | | | Data[11-14]: buffer_size | |
  133. * | | | | | Data[15-18]: period_size | |
  134. * | | | | | Data[19-22]: buffer_tail | |
  135. * +----------+---------+------+---------+-------------------------------+-----------------------+
  136. * | 0x03 | 0x0100 | 0x00 | 0x12 | Data[0]: Audio Device Index | Suspend a RX Instance.|
  137. * +----------+---------+------+---------+-------------------------------+-----------------------+
  138. * | 0x03 | 0x0100 | 0x00 | 0x13 | Data[0]: Audio Device Index | Resume a RX Instance. |
  139. * | | | | | Data[1]: format | |
  140. * | | | | | Data[2]: channels | |
  141. * | | | | | Data[3-6]: samplerate | |
  142. * | | | | | Data[7-10]: buffer_addr | |
  143. * | | | | | Data[11-14]: buffer_size | |
  144. * | | | | | Data[15-18]: period_size | |
  145. * | | | | | Data[19-22]: buffer_tail | |
  146. * +----------+---------+------+---------+-------------------------------+-----------------------+
  147. * | 0x03 | 0x0100 | 0x00 | 0x14 | Data[0]: Audio Device Index | Set register value |
  148. * | | | | | Data[1-6]: reserved | to codec |
  149. * | | | | | Data[7-10]: register | |
  150. * | | | | | Data[11-14]: value | |
  151. * | | | | | Data[15-22]: reserved | |
  152. * +----------+---------+------+---------+-------------------------------+-----------------------+
  153. * | 0x03 | 0x0100 | 0x00 | 0x15 | Data[0]: Audio Device Index | Get register value |
  154. * | | | | | Data[1-6]: reserved | from codec |
  155. * | | | | | Data[7-10]: register | |
  156. * | | | | | Data[11-22]: reserved | |
  157. * +----------+---------+------+---------+-------------------------------+-----------------------+
  158. * Note 1: See <List of Sample Format> for available value of
  159. * Sample Format;
  160. * Note 2: See <List of Audio Channels> for available value of Channels;
  161. * Note 3: Sample Rate of Set Parameters for an Audio TX Instance
  162. * Command and Set Parameters for an Audio RX Instance Command is
  163. * in little-endian format.
  164. *
  165. * SRTM Audio Control Category Response Command Table:
  166. * +----------+---------+------+---------+-------------------------------+-----------------------+
  167. * | Category | Version | Type | Command | Data | Function |
  168. * +----------+---------+------+---------+-------------------------------+-----------------------+
  169. * | 0x03 | 0x0100 | 0x01 | 0x00 | Data[0]: Audio Device Index | Reply for Open |
  170. * | | | | | Data[1]: Return code | a TX Instance |
  171. * +----------+---------+------+---------+-------------------------------+-----------------------+
  172. * | 0x03 | 0x0100 | 0x01 | 0x01 | Data[0]: Audio Device Index | Reply for Start |
  173. * | | | | | Data[1]: Return code | a TX Instance |
  174. * +----------+---------+------+---------+-------------------------------+-----------------------+
  175. * | 0x03 | 0x0100 | 0x01 | 0x02 | Data[0]: Audio Device Index | Reply for Pause |
  176. * | | | | | Data[1]: Return code | a TX Instance |
  177. * +----------+---------+------+---------+-------------------------------+-----------------------+
  178. * | 0x03 | 0x0100 | 0x01 | 0x03 | Data[0]: Audio Device Index | Reply for Resume |
  179. * | | | | | Data[1]: Return code | a TX Instance |
  180. * +----------+---------+------+---------+-------------------------------+-----------------------+
  181. * | 0x03 | 0x0100 | 0x01 | 0x04 | Data[0]: Audio Device Index | Reply for Stop |
  182. * | | | | | Data[1]: Return code | a TX Instance |
  183. * +----------+---------+------+---------+-------------------------------+-----------------------+
  184. * | 0x03 | 0x0100 | 0x01 | 0x05 | Data[0]: Audio Device Index | Reply for Close |
  185. * | | | | | Data[1]: Return code | a TX Instance |
  186. * +----------+---------+------+---------+-------------------------------+-----------------------+
  187. * | 0x03 | 0x0100 | 0x01 | 0x06 | Data[0]: Audio Device Index | Reply for Set Param |
  188. * | | | | | Data[1]: Return code | for a TX Instance. |
  189. * +----------+---------+------+---------+-------------------------------+-----------------------+
  190. * | 0x03 | 0x0100 | 0x01 | 0x07 | Data[0]: Audio Device Index | Reply for Set |
  191. * | | | | | Data[1]: Return code | TX Buffer |
  192. * +----------+---------+------+---------+-------------------------------+-----------------------+
  193. * | 0x03 | 0x0100 | 0x01 | 0x08 | Data[0]: Audio Device Index | Reply for Suspend |
  194. * | | | | | Data[1]: Return code | a TX Instance |
  195. * +----------+---------+------+---------+-------------------------------+-----------------------+
  196. * | 0x03 | 0x0100 | 0x01 | 0x09 | Data[0]: Audio Device Index | Reply for Resume |
  197. * | | | | | Data[1]: Return code | a TX Instance |
  198. * +----------+---------+------+---------+-------------------------------+-----------------------+
  199. * | 0x03 | 0x0100 | 0x01 | 0x0A | Data[0]: Audio Device Index | Reply for Open |
  200. * | | | | | Data[1]: Return code | a TX Instance |
  201. * +----------+---------+------+---------+-------------------------------+-----------------------+
  202. * | 0x03 | 0x0100 | 0x01 | 0x0B | Data[0]: Audio Device Index | Reply for Start |
  203. * | | | | | Data[1]: Return code | a TX Instance |
  204. * +----------+---------+------+---------+-------------------------------+-----------------------+
  205. * | 0x03 | 0x0100 | 0x01 | 0x0C | Data[0]: Audio Device Index | Reply for Pause |
  206. * | | | | | Data[1]: Return code | a TX Instance |
  207. * +----------+---------+------+---------+-------------------------------+-----------------------+
  208. * | 0x03 | 0x0100 | 0x01 | 0x0D | Data[0]: Audio Device Index | Reply for Resume |
  209. * | | | | | Data[1]: Return code | a RX Instance |
  210. * +----------+---------+------+---------+-------------------------------+-----------------------+
  211. * | 0x03 | 0x0100 | 0x01 | 0x0E | Data[0]: Audio Device Index | Reply for Stop |
  212. * | | | | | Data[1]: Return code | a RX Instance |
  213. * +----------+---------+------+---------+-------------------------------+-----------------------+
  214. * | 0x03 | 0x0100 | 0x01 | 0x0F | Data[0]: Audio Device Index | Reply for Close |
  215. * | | | | | Data[1]: Return code | a RX Instance |
  216. * +----------+---------+------+---------+-------------------------------+-----------------------+
  217. * | 0x03 | 0x0100 | 0x01 | 0x10 | Data[0]: Audio Device Index | Reply for Set Param |
  218. * | | | | | Data[1]: Return code | for a RX Instance. |
  219. * +----------+---------+------+---------+-------------------------------+-----------------------+
  220. * | 0x03 | 0x0100 | 0x01 | 0x11 | Data[0]: Audio Device Index | Reply for Set |
  221. * | | | | | Data[1]: Return code | RX Buffer |
  222. * +----------+---------+------+---------+-------------------------------+-----------------------+
  223. * | 0x03 | 0x0100 | 0x01 | 0x12 | Data[0]: Audio Device Index | Reply for Suspend |
  224. * | | | | | Data[1]: Return code | a RX Instance |
  225. * +----------+---------+------+---------+-------------------------------+-----------------------+
  226. * | 0x03 | 0x0100 | 0x01 | 0x13 | Data[0]: Audio Device Index | Reply for Resume |
  227. * | | | | | Data[1]: Return code | a RX Instance |
  228. * +----------+---------+------+---------+-------------------------------+-----------------------+
  229. * | 0x03 | 0x0100 | 0x01 | 0x14 | Data[0]: Audio Device Index | Reply for Set codec |
  230. * | | | | | Data[1]: Return code | register value |
  231. * +----------+---------+------+---------+-------------------------------+-----------------------+
  232. * | 0x03 | 0x0100 | 0x01 | 0x15 | Data[0]: Audio Device Index | Reply for Get codec |
  233. * | | | | | Data[1]: Return code | register value |
  234. * | | | | | Data[2-6]: reserved | |
  235. * | | | | | Data[7-10]: register | |
  236. * | | | | | Data[11-14]: value | |
  237. * | | | | | Data[15-22]: reserved | |
  238. * +----------+---------+------+---------+-------------------------------+-----------------------+
  239. *
  240. * SRTM Audio Control Category Notification Command Table:
  241. * +----------+---------+------+---------+-------------------------------+-----------------------+
  242. * | Category | Version | Type | Command | Data | Function |
  243. * +----------+---------+------+---------+-------------------------------+-----------------------+
  244. * | 0x03 | 0x0100 | 0x02 | 0x00 | Data[0]: Audio Device Index | Notify one TX period |
  245. * | | | | | | is finished |
  246. * +----------+---------+------+---------+-------------------------------+-----------------------+
  247. * | 0x03 | 0x0100 | 0x02 | 0x01 | Data[0]: Audio Device Index | Notify one RX period |
  248. * | | | | | | is finished |
  249. * +----------+---------+------+---------+-------------------------------+-----------------------+
  250. *
  251. * List of Sample Format:
  252. * +------------------+-----------------------+
  253. * | Sample Format | Description |
  254. * +------------------+-----------------------+
  255. * | 0x0 | S16_LE |
  256. * +------------------+-----------------------+
  257. * | 0x1 | S24_LE |
  258. * +------------------+-----------------------+
  259. *
  260. * List of Audio Channels
  261. * +------------------+-----------------------+
  262. * | Audio Channel | Description |
  263. * +------------------+-----------------------+
  264. * | 0x0 | Left Channel |
  265. * +------------------+-----------------------+
  266. * | 0x1 | Right Channel |
  267. * +------------------+---------------- ------+
  268. * | 0x2 | Left & Right Channel |
  269. * +------------------+-----------------------+
  270. *
  271. */
  272. #ifndef _IMX_PCM_RPMSG_H
  273. #define _IMX_PCM_RPMSG_H
  274. #include <linux/pm_qos.h>
  275. #include <linux/interrupt.h>
  276. #include <sound/dmaengine_pcm.h>
  277. #define RPMSG_TIMEOUT 1000
  278. /* RPMSG Command (TYPE A)*/
  279. #define TX_OPEN 0x0
  280. #define TX_START 0x1
  281. #define TX_PAUSE 0x2
  282. #define TX_RESTART 0x3
  283. #define TX_TERMINATE 0x4
  284. #define TX_CLOSE 0x5
  285. #define TX_HW_PARAM 0x6
  286. #define TX_BUFFER 0x7
  287. #define TX_SUSPEND 0x8
  288. #define TX_RESUME 0x9
  289. #define RX_OPEN 0xA
  290. #define RX_START 0xB
  291. #define RX_PAUSE 0xC
  292. #define RX_RESTART 0xD
  293. #define RX_TERMINATE 0xE
  294. #define RX_CLOSE 0xF
  295. #define RX_HW_PARAM 0x10
  296. #define RX_BUFFER 0x11
  297. #define RX_SUSPEND 0x12
  298. #define RX_RESUME 0x13
  299. #define SET_CODEC_VALUE 0x14
  300. #define GET_CODEC_VALUE 0x15
  301. #define TX_POINTER 0x16
  302. #define RX_POINTER 0x17
  303. /* Total msg numver for type A */
  304. #define MSG_TYPE_A_NUM 0x18
  305. /* RPMSG Command (TYPE C)*/
  306. #define TX_PERIOD_DONE 0x0
  307. #define RX_PERIOD_DONE 0x1
  308. /* Total msg numver for type C */
  309. #define MSG_TYPE_C_NUM 0x2
  310. #define MSG_MAX_NUM (MSG_TYPE_A_NUM + MSG_TYPE_C_NUM)
  311. #define MSG_TYPE_A 0x0
  312. #define MSG_TYPE_B 0x1
  313. #define MSG_TYPE_C 0x2
  314. #define RESP_NONE 0x0
  315. #define RESP_NOT_ALLOWED 0x1
  316. #define RESP_SUCCESS 0x2
  317. #define RESP_FAILED 0x3
  318. #define RPMSG_S16_LE 0x0
  319. #define RPMSG_S24_LE 0x1
  320. #define RPMSG_S32_LE 0x2
  321. #define RPMSG_DSD_U16_LE 49 /* SNDRV_PCM_FORMAT_DSD_U16_LE */
  322. #define RPMSG_DSD_U24_LE 0x4
  323. #define RPMSG_DSD_U32_LE 50 /* SNDRV_PCM_FORMAT_DSD_U32_LE */
  324. #define RPMSG_CH_LEFT 0x0
  325. #define RPMSG_CH_RIGHT 0x1
  326. #define RPMSG_CH_STEREO 0x2
  327. #define WORK_MAX_NUM 0x30
  328. /* Category define */
  329. #define IMX_RMPSG_LIFECYCLE 1
  330. #define IMX_RPMSG_PMIC 2
  331. #define IMX_RPMSG_AUDIO 3
  332. #define IMX_RPMSG_KEY 4
  333. #define IMX_RPMSG_GPIO 5
  334. #define IMX_RPMSG_RTC 6
  335. #define IMX_RPMSG_SENSOR 7
  336. /* rpmsg version */
  337. #define IMX_RMPSG_MAJOR 1
  338. #define IMX_RMPSG_MINOR 0
  339. #define TX SNDRV_PCM_STREAM_PLAYBACK
  340. #define RX SNDRV_PCM_STREAM_CAPTURE
  341. /**
  342. * struct rpmsg_head: rpmsg header structure
  343. *
  344. * @cate: category
  345. * @major: major version
  346. * @minor: minor version
  347. * @type: message type (A/B/C)
  348. * @cmd: message command
  349. * @reserved: reserved space
  350. */
  351. struct rpmsg_head {
  352. u8 cate;
  353. u8 major;
  354. u8 minor;
  355. u8 type;
  356. u8 cmd;
  357. u8 reserved[5];
  358. } __packed;
  359. /**
  360. * struct param_s: sent rpmsg parameter
  361. *
  362. * @audioindex: audio instance index
  363. * @format: audio format
  364. * @channels: audio channel number
  365. * @rate: sample rate
  366. * @buffer_addr: dma buffer physical address or register for SET_CODEC_VALUE
  367. * @buffer_size: dma buffer size or register value for SET_CODEC_VALUE
  368. * @period_size: period size
  369. * @buffer_tail: current period index
  370. */
  371. struct param_s {
  372. unsigned char audioindex;
  373. unsigned char format;
  374. unsigned char channels;
  375. unsigned int rate;
  376. unsigned int buffer_addr;
  377. unsigned int buffer_size;
  378. unsigned int period_size;
  379. unsigned int buffer_tail;
  380. } __packed;
  381. /**
  382. * struct param_s: send rpmsg parameter
  383. *
  384. * @audioindex: audio instance index
  385. * @resp: response value
  386. * @reserved1: reserved space
  387. * @buffer_offset: the consumed offset of buffer
  388. * @reg_addr: register addr of codec
  389. * @reg_data: register value of codec
  390. * @reserved2: reserved space
  391. * @buffer_tail: current period index
  392. */
  393. struct param_r {
  394. unsigned char audioindex;
  395. unsigned char resp;
  396. unsigned char reserved1[1];
  397. unsigned int buffer_offset;
  398. unsigned int reg_addr;
  399. unsigned int reg_data;
  400. unsigned char reserved2[4];
  401. unsigned int buffer_tail;
  402. } __packed;
  403. /* Struct of sent message */
  404. struct rpmsg_s_msg {
  405. struct rpmsg_head header;
  406. struct param_s param;
  407. };
  408. /* Struct of received message */
  409. struct rpmsg_r_msg {
  410. struct rpmsg_head header;
  411. struct param_r param;
  412. };
  413. /* Struct of rpmsg */
  414. struct rpmsg_msg {
  415. struct rpmsg_s_msg s_msg;
  416. struct rpmsg_r_msg r_msg;
  417. };
  418. /* Struct of rpmsg for workqueue */
  419. struct work_of_rpmsg {
  420. struct rpmsg_info *info;
  421. /* Sent msg for each work */
  422. struct rpmsg_msg msg;
  423. struct work_struct work;
  424. };
  425. /* Struct of timer */
  426. struct stream_timer {
  427. struct timer_list timer;
  428. struct rpmsg_info *info;
  429. struct snd_pcm_substream *substream;
  430. };
  431. typedef void (*dma_callback)(void *arg);
  432. /**
  433. * struct rpmsg_info: rpmsg audio information
  434. *
  435. * @rpdev: pointer of rpmsg_device
  436. * @dev: pointer for imx_pcm_rpmsg device
  437. * @cmd_complete: command is finished
  438. * @pm_qos_req: request of pm qos
  439. * @r_msg: received rpmsg
  440. * @msg: array of rpmsg
  441. * @notify: notification msg (type C) for TX & RX
  442. * @notify_updated: notification flag for TX & RX
  443. * @rpmsg_wq: rpmsg workqueue
  444. * @work_list: array of work list for workqueue
  445. * @work_write_index: write index of work list
  446. * @work_read_index: read index of work list
  447. * @msg_drop_count: counter of dropped msg for TX & RX
  448. * @num_period: period number for TX & RX
  449. * @callback_param: parameter for period elapse callback for TX & RX
  450. * @callback: period elapse callback for TX & RX
  451. * @send_message: function pointer for send message
  452. * @lock: spin lock for TX & RX
  453. * @wq_lock: lock for work queue
  454. * @msg_lock: lock for send message
  455. * @stream_timer: timer for tigger workqueue
  456. */
  457. struct rpmsg_info {
  458. struct rpmsg_device *rpdev;
  459. struct device *dev;
  460. struct completion cmd_complete;
  461. struct pm_qos_request pm_qos_req;
  462. /* Received msg (global) */
  463. struct rpmsg_r_msg r_msg;
  464. struct rpmsg_msg msg[MSG_MAX_NUM];
  465. /* period done */
  466. struct rpmsg_msg notify[2];
  467. bool notify_updated[2];
  468. struct workqueue_struct *rpmsg_wq;
  469. struct work_of_rpmsg work_list[WORK_MAX_NUM];
  470. int work_write_index;
  471. int work_read_index;
  472. int msg_drop_count[2];
  473. int num_period[2];
  474. void *callback_param[2];
  475. dma_callback callback[2];
  476. int (*send_message)(struct rpmsg_msg *msg, struct rpmsg_info *info);
  477. spinlock_t lock[2]; /* spin lock for resource protection */
  478. spinlock_t wq_lock; /* spin lock for resource protection */
  479. struct mutex msg_lock; /* mutex for resource protection */
  480. struct stream_timer stream_timer[2];
  481. };
  482. #define IMX_PCM_DRV_NAME "imx_pcm_rpmsg"
  483. #endif /* IMX_PCM_RPMSG_H */