ASoC: imx-pcm-rpmsg: Fix warning of incorrect type in assignment
[linux-2.6-microblaze.git] / sound / soc / fsl / imx-pcm-rpmsg.h
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
273 #ifndef _IMX_PCM_RPMSG_H
274 #define _IMX_PCM_RPMSG_H
275
276 #include <linux/pm_qos.h>
277 #include <linux/interrupt.h>
278 #include <sound/dmaengine_pcm.h>
279
280 #define RPMSG_TIMEOUT 1000
281
282 /* RPMSG Command (TYPE A)*/
283 #define TX_OPEN         0x0
284 #define TX_START        0x1
285 #define TX_PAUSE        0x2
286 #define TX_RESTART      0x3
287 #define TX_TERMINATE    0x4
288 #define TX_CLOSE        0x5
289 #define TX_HW_PARAM     0x6
290 #define TX_BUFFER       0x7
291 #define TX_SUSPEND      0x8
292 #define TX_RESUME       0x9
293
294 #define RX_OPEN         0xA
295 #define RX_START        0xB
296 #define RX_PAUSE        0xC
297 #define RX_RESTART      0xD
298 #define RX_TERMINATE    0xE
299 #define RX_CLOSE        0xF
300 #define RX_HW_PARAM     0x10
301 #define RX_BUFFER       0x11
302 #define RX_SUSPEND      0x12
303 #define RX_RESUME       0x13
304 #define SET_CODEC_VALUE 0x14
305 #define GET_CODEC_VALUE 0x15
306 #define TX_POINTER      0x16
307 #define RX_POINTER      0x17
308 /* Total msg numver for type A */
309 #define MSG_TYPE_A_NUM  0x18
310
311 /* RPMSG Command (TYPE C)*/
312 #define TX_PERIOD_DONE  0x0
313 #define RX_PERIOD_DONE  0x1
314 /* Total msg numver for type C */
315 #define MSG_TYPE_C_NUM  0x2
316
317 #define MSG_MAX_NUM     (MSG_TYPE_A_NUM + MSG_TYPE_C_NUM)
318
319 #define MSG_TYPE_A      0x0
320 #define MSG_TYPE_B      0x1
321 #define MSG_TYPE_C      0x2
322
323 #define RESP_NONE               0x0
324 #define RESP_NOT_ALLOWED        0x1
325 #define RESP_SUCCESS            0x2
326 #define RESP_FAILED             0x3
327
328 #define RPMSG_S16_LE            0x0
329 #define RPMSG_S24_LE            0x1
330 #define RPMSG_S32_LE            0x2
331 #define RPMSG_DSD_U16_LE        49  /* SNDRV_PCM_FORMAT_DSD_U16_LE */
332 #define RPMSG_DSD_U24_LE        0x4
333 #define RPMSG_DSD_U32_LE        50  /* SNDRV_PCM_FORMAT_DSD_U32_LE */
334
335 #define RPMSG_CH_LEFT           0x0
336 #define RPMSG_CH_RIGHT          0x1
337 #define RPMSG_CH_STEREO         0x2
338
339 #define WORK_MAX_NUM    0x30
340
341 /* Category define */
342 #define IMX_RMPSG_LIFECYCLE     1
343 #define IMX_RPMSG_PMIC          2
344 #define IMX_RPMSG_AUDIO         3
345 #define IMX_RPMSG_KEY           4
346 #define IMX_RPMSG_GPIO          5
347 #define IMX_RPMSG_RTC           6
348 #define IMX_RPMSG_SENSOR        7
349
350 /* rpmsg version */
351 #define IMX_RMPSG_MAJOR         1
352 #define IMX_RMPSG_MINOR         0
353
354 #define TX SNDRV_PCM_STREAM_PLAYBACK
355 #define RX SNDRV_PCM_STREAM_CAPTURE
356
357 /**
358  * struct rpmsg_head: rpmsg header structure
359  *
360  * @cate: category
361  * @major: major version
362  * @minor: minor version
363  * @type: message type (A/B/C)
364  * @cmd: message command
365  * @reserved: reserved space
366  */
367 struct rpmsg_head {
368         u8 cate;
369         u8 major;
370         u8 minor;
371         u8 type;
372         u8 cmd;
373         u8 reserved[5];
374 } __packed;
375
376 /**
377  * struct param_s: sent rpmsg parameter
378  *
379  * @audioindex: audio instance index
380  * @format: audio format
381  * @channels: audio channel number
382  * @rate: sample rate
383  * @buffer_addr: dma buffer physical address or register for SET_CODEC_VALUE
384  * @buffer_size: dma buffer size or register value for SET_CODEC_VALUE
385  * @period_size: period size
386  * @buffer_tail: current period index
387  */
388 struct param_s {
389         unsigned char audioindex;
390         unsigned char format;
391         unsigned char channels;
392         unsigned int  rate;
393         unsigned int  buffer_addr;
394         unsigned int  buffer_size;
395         unsigned int  period_size;
396         unsigned int  buffer_tail;
397 } __packed;
398
399 /**
400  * struct param_s: send rpmsg parameter
401  *
402  * @audioindex: audio instance index
403  * @resp: response value
404  * @reserved1: reserved space
405  * @buffer_offset: the consumed offset of buffer
406  * @reg_addr: register addr of codec
407  * @reg_data: register value of codec
408  * @reserved2: reserved space
409  * @buffer_tail: current period index
410  */
411 struct param_r {
412         unsigned char audioindex;
413         unsigned char resp;
414         unsigned char reserved1[1];
415         unsigned int  buffer_offset;
416         unsigned int  reg_addr;
417         unsigned int  reg_data;
418         unsigned char reserved2[4];
419         unsigned int  buffer_tail;
420 } __packed;
421
422 /* Struct of sent message */
423 struct rpmsg_s_msg {
424         struct rpmsg_head header;
425         struct param_s    param;
426 };
427
428 /* Struct of received message */
429 struct rpmsg_r_msg {
430         struct rpmsg_head header;
431         struct param_r    param;
432 };
433
434 /* Struct of rpmsg */
435 struct rpmsg_msg {
436         struct rpmsg_s_msg  s_msg;
437         struct rpmsg_r_msg  r_msg;
438 };
439
440 /* Struct of rpmsg for workqueue */
441 struct work_of_rpmsg {
442         struct rpmsg_info   *info;
443         /* Sent msg for each work */
444         struct rpmsg_msg    msg;
445         struct work_struct  work;
446 };
447
448 /* Struct of timer */
449 struct stream_timer {
450         struct timer_list   timer;
451         struct rpmsg_info   *info;
452         struct snd_pcm_substream *substream;
453 };
454
455 typedef void (*dma_callback)(void *arg);
456
457 /**
458  * struct rpmsg_info: rpmsg audio information
459  *
460  * @rpdev: pointer of rpmsg_device
461  * @dev: pointer for imx_pcm_rpmsg device
462  * @cmd_complete: command is finished
463  * @pm_qos_req: request of pm qos
464  * @r_msg: received rpmsg
465  * @msg: array of rpmsg
466  * @notify: notification msg (type C) for TX & RX
467  * @notify_updated: notification flag for TX & RX
468  * @rpmsg_wq: rpmsg workqueue
469  * @work_list: array of work list for workqueue
470  * @work_write_index: write index of work list
471  * @work_read_index: read index of work list
472  * @msg_drop_count: counter of dropped msg for TX & RX
473  * @num_period: period number for TX & RX
474  * @callback_param: parameter for period elapse callback for TX & RX
475  * @callback: period elapse callback for TX & RX
476  * @send_message: function pointer for send message
477  * @lock: spin lock for TX & RX
478  * @wq_lock: lock for work queue
479  * @msg_lock: lock for send message
480  * @stream_timer: timer for tigger workqueue
481  */
482 struct rpmsg_info {
483         struct rpmsg_device      *rpdev;
484         struct device            *dev;
485         struct completion        cmd_complete;
486         struct pm_qos_request    pm_qos_req;
487
488         /* Received msg (global) */
489         struct rpmsg_r_msg       r_msg;
490         struct rpmsg_msg         msg[MSG_MAX_NUM];
491         /* period done */
492         struct rpmsg_msg         notify[2];
493         bool                     notify_updated[2];
494
495         struct workqueue_struct  *rpmsg_wq;
496         struct work_of_rpmsg     work_list[WORK_MAX_NUM];
497         int                      work_write_index;
498         int                      work_read_index;
499         int                      msg_drop_count[2];
500         int                      num_period[2];
501         void                     *callback_param[2];
502         dma_callback             callback[2];
503         int (*send_message)(struct rpmsg_msg *msg, struct rpmsg_info *info);
504         spinlock_t               lock[2]; /* spin lock for resource protection */
505         spinlock_t               wq_lock; /* spin lock for resource protection */
506         struct mutex             msg_lock; /* mutex for resource protection */
507         struct stream_timer      stream_timer[2];
508 };
509
510 #define IMX_PCM_DRV_NAME "imx_pcm_rpmsg"
511
512 #endif /* IMX_PCM_RPMSG_H */