xref: /linux/sound/soc/fsl/imx-pcm-rpmsg.h (revision a387040a)
13c00ecebSShengjiu Wang /* SPDX-License-Identifier: GPL-2.0+ */
23c00ecebSShengjiu Wang /*
33c00ecebSShengjiu Wang  * Copyright 2017-2021  NXP
43c00ecebSShengjiu Wang  *
53c00ecebSShengjiu Wang  ******************************************************************************
63c00ecebSShengjiu Wang  * Communication stack of audio with rpmsg
73c00ecebSShengjiu Wang  ******************************************************************************
83c00ecebSShengjiu Wang  * Packet structure:
93c00ecebSShengjiu Wang  *   A SRTM message consists of a 10 bytes header followed by 0~N bytes of data
103c00ecebSShengjiu Wang  *
113c00ecebSShengjiu Wang  *   +---------------+-------------------------------+
123c00ecebSShengjiu Wang  *   |               |            Content            |
133c00ecebSShengjiu Wang  *   +---------------+-------------------------------+
143c00ecebSShengjiu Wang  *   |  Byte Offset  | 7   6   5   4   3   2   1   0 |
153c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
163c00ecebSShengjiu Wang  *   |       0       |           Category            |
173c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
183c00ecebSShengjiu Wang  *   |     1 ~ 2     |           Version             |
193c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
203c00ecebSShengjiu Wang  *   |       3       |             Type              |
213c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
223c00ecebSShengjiu Wang  *   |       4       |           Command             |
233c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
243c00ecebSShengjiu Wang  *   |       5       |           Reserved0           |
253c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
263c00ecebSShengjiu Wang  *   |       6       |           Reserved1           |
273c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
283c00ecebSShengjiu Wang  *   |       7       |           Reserved2           |
293c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
303c00ecebSShengjiu Wang  *   |       8       |           Reserved3           |
313c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
323c00ecebSShengjiu Wang  *   |       9       |           Reserved4           |
333c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
343c00ecebSShengjiu Wang  *   |       10      |            DATA 0             |
353c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
363c00ecebSShengjiu Wang  *   :   :   :   :   :   :   :   :   :   :   :   :   :
373c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
383c00ecebSShengjiu Wang  *   |   N + 10 - 1  |            DATA N-1           |
393c00ecebSShengjiu Wang  *   +---------------+---+---+---+---+---+---+---+---+
403c00ecebSShengjiu Wang  *
413c00ecebSShengjiu Wang  *   +----------+------------+------------------------------------------------+
423c00ecebSShengjiu Wang  *   |  Field   |    Byte    |                                                |
433c00ecebSShengjiu Wang  *   +----------+------------+------------------------------------------------+
443c00ecebSShengjiu Wang  *   | Category |     0      | The destination category.                      |
453c00ecebSShengjiu Wang  *   +----------+------------+------------------------------------------------+
463c00ecebSShengjiu Wang  *   | Version  |   1 ~ 2    | The category version of the sender of the      |
473c00ecebSShengjiu Wang  *   |          |            | packet.                                        |
483c00ecebSShengjiu Wang  *   |          |            | The first byte represent the major version of  |
493c00ecebSShengjiu Wang  *   |          |            | the packet.The second byte represent the minor |
503c00ecebSShengjiu Wang  *   |          |            | version of the packet.                         |
513c00ecebSShengjiu Wang  *   +----------+------------+------------------------------------------------+
523c00ecebSShengjiu Wang  *   |  Type    |     3      | The message type of current message packet.    |
533c00ecebSShengjiu Wang  *   +----------+------------+------------------------------------------------+
543c00ecebSShengjiu Wang  *   | Command  |     4      | The command byte sent to remote processor/SoC. |
553c00ecebSShengjiu Wang  *   +----------+------------+------------------------------------------------+
563c00ecebSShengjiu Wang  *   | Reserved |   5 ~ 9    | Reserved field for future extension.           |
573c00ecebSShengjiu Wang  *   +----------+------------+------------------------------------------------+
583c00ecebSShengjiu Wang  *   | Data     |     N      | The data payload of the message packet.        |
593c00ecebSShengjiu Wang  *   +----------+------------+------------------------------------------------+
603c00ecebSShengjiu Wang  *
613c00ecebSShengjiu Wang  * Audio control:
623c00ecebSShengjiu Wang  *   SRTM Audio Control Category Request Command Table:
633c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
643c00ecebSShengjiu Wang  *   | Category | Version | Type | Command | Data                          | Function              |
653c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
663c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x00   | Data[0]: Audio Device Index   | Open a TX Instance.   |
673c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]:     format           |                       |
683c00ecebSShengjiu Wang  *   |          |         |      |         | Data[2]:     channels         |                       |
693c00ecebSShengjiu Wang  *   |          |         |      |         | Data[3-6]:   samplerate       |                       |
703c00ecebSShengjiu Wang  *   |          |         |      |         | Data[7-10]:  buffer_addr      |                       |
713c00ecebSShengjiu Wang  *   |          |         |      |         | Data[11-14]: buffer_size      |                       |
723c00ecebSShengjiu Wang  *   |          |         |      |         | Data[15-18]: period_size      |                       |
733c00ecebSShengjiu Wang  *   |          |         |      |         | Data[19-22]: buffer_tail      |                       |
743c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
753c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x01   | Data[0]: Audio Device Index   | Start a TX Instance.  |
763c00ecebSShengjiu Wang  *   |          |         |      |         | Same as above command         |                       |
773c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
783c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x02   | Data[0]: Audio Device Index   | Pause a TX Instance.  |
793c00ecebSShengjiu Wang  *   |          |         |      |         | Same as above command         |                       |
803c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
813c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x03   | Data[0]: Audio Device Index   | Resume a TX Instance. |
823c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
833c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x04   | Data[0]: Audio Device Index   | Stop a TX Instance.   |
843c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
853c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x05   | Data[0]: Audio Device Index   | Close a TX Instance.  |
863c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
873c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x06   | Data[0]: Audio Device Index   | Set Parameters for    |
883c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]:     format           | a TX Instance.        |
893c00ecebSShengjiu Wang  *   |          |         |      |         | Data[2]:     channels         |                       |
903c00ecebSShengjiu Wang  *   |          |         |      |         | Data[3-6]:   samplerate       |                       |
913c00ecebSShengjiu Wang  *   |          |         |      |         | Data[7-22]:  reserved         |                       |
923c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
933c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x07   | Data[0]: Audio Device Index   | Set TX Buffer.        |
943c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1-6]:   reserved         |                       |
953c00ecebSShengjiu Wang  *   |          |         |      |         | Data[7-10]:  buffer_addr      |                       |
963c00ecebSShengjiu Wang  *   |          |         |      |         | Data[11-14]: buffer_size      |                       |
973c00ecebSShengjiu Wang  *   |          |         |      |         | Data[15-18]: period_size      |                       |
983c00ecebSShengjiu Wang  *   |          |         |      |         | Data[19-22]: buffer_tail      |                       |
993c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1003c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x08   | Data[0]: Audio Device Index   | Suspend a TX Instance |
1013c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1023c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x09   | Data[0]: Audio Device Index   | Resume a TX Instance. |
1033c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]:     format           |                       |
1043c00ecebSShengjiu Wang  *   |          |         |      |         | Data[2]:     channels         |                       |
1053c00ecebSShengjiu Wang  *   |          |         |      |         | Data[3-6]:   samplerate       |                       |
1063c00ecebSShengjiu Wang  *   |          |         |      |         | Data[7-10]:  buffer_addr      |                       |
1073c00ecebSShengjiu Wang  *   |          |         |      |         | Data[11-14]: buffer_size      |                       |
1083c00ecebSShengjiu Wang  *   |          |         |      |         | Data[15-18]: period_size      |                       |
1093c00ecebSShengjiu Wang  *   |          |         |      |         | Data[19-22]: buffer_tail      |                       |
1103c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1113c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x0A   | Data[0]: Audio Device Index   | Open a RX Instance.   |
1123c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1133c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x0B   | Data[0]: Audio Device Index   | Start a RX Instance.  |
1143c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1153c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x0C   | Data[0]: Audio Device Index   | Pause a RX Instance.  |
1163c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1173c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x0D   | Data[0]: Audio Device Index   | Resume a RX Instance. |
1183c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1193c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x0E   | Data[0]: Audio Device Index   | Stop a RX Instance.   |
1203c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1213c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x0F   | Data[0]: Audio Device Index   | Close a RX Instance.  |
1223c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1233c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x10   | Data[0]: Audio Device Index   | Set Parameters for    |
1243c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]:     format           | a RX Instance.        |
1253c00ecebSShengjiu Wang  *   |          |         |      |         | Data[2]:     channels         |                       |
1263c00ecebSShengjiu Wang  *   |          |         |      |         | Data[3-6]:   samplerate       |                       |
1273c00ecebSShengjiu Wang  *   |          |         |      |         | Data[7-22]:  reserved         |                       |
1283c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1293c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x11   | Data[0]: Audio Device Index   | Set RX Buffer.        |
1303c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1-6]:   reserved         |                       |
1313c00ecebSShengjiu Wang  *   |          |         |      |         | Data[7-10]:  buffer_addr      |                       |
1323c00ecebSShengjiu Wang  *   |          |         |      |         | Data[11-14]: buffer_size      |                       |
1333c00ecebSShengjiu Wang  *   |          |         |      |         | Data[15-18]: period_size      |                       |
1343c00ecebSShengjiu Wang  *   |          |         |      |         | Data[19-22]: buffer_tail      |                       |
1353c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1363c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x12   | Data[0]: Audio Device Index   | Suspend a RX Instance.|
1373c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1383c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x13   | Data[0]: Audio Device Index   | Resume a RX Instance. |
1393c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]:     format           |                       |
1403c00ecebSShengjiu Wang  *   |          |         |      |         | Data[2]:     channels         |                       |
1413c00ecebSShengjiu Wang  *   |          |         |      |         | Data[3-6]:   samplerate       |                       |
1423c00ecebSShengjiu Wang  *   |          |         |      |         | Data[7-10]:  buffer_addr      |                       |
1433c00ecebSShengjiu Wang  *   |          |         |      |         | Data[11-14]: buffer_size      |                       |
1443c00ecebSShengjiu Wang  *   |          |         |      |         | Data[15-18]: period_size      |                       |
1453c00ecebSShengjiu Wang  *   |          |         |      |         | Data[19-22]: buffer_tail      |                       |
1463c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1473c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x14   | Data[0]: Audio Device Index   | Set register value    |
1483c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1-6]:   reserved         | to codec              |
1493c00ecebSShengjiu Wang  *   |          |         |      |         | Data[7-10]:  register         |                       |
1503c00ecebSShengjiu Wang  *   |          |         |      |         | Data[11-14]: value            |                       |
1513c00ecebSShengjiu Wang  *   |          |         |      |         | Data[15-22]: reserved         |                       |
1523c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1533c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x00 |  0x15   | Data[0]: Audio Device Index   | Get register value    |
1543c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1-6]:   reserved         | from codec            |
1553c00ecebSShengjiu Wang  *   |          |         |      |         | Data[7-10]:  register         |                       |
1563c00ecebSShengjiu Wang  *   |          |         |      |         | Data[11-22]: reserved         |                       |
1573c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1583c00ecebSShengjiu Wang  *   Note 1: See <List of Sample Format> for available value of
1593c00ecebSShengjiu Wang  *           Sample Format;
1603c00ecebSShengjiu Wang  *   Note 2: See <List of Audio Channels> for available value of Channels;
1613c00ecebSShengjiu Wang  *   Note 3: Sample Rate of Set Parameters for an Audio TX Instance
1623c00ecebSShengjiu Wang  *           Command and Set Parameters for an Audio RX Instance Command is
1633c00ecebSShengjiu Wang  *           in little-endian format.
1643c00ecebSShengjiu Wang  *
1653c00ecebSShengjiu Wang  *   SRTM Audio Control Category Response Command Table:
1663c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1673c00ecebSShengjiu Wang  *   | Category | Version | Type | Command | Data                          | Function              |
1683c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1693c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x00   | Data[0]: Audio Device Index   | Reply for Open        |
1703c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a TX Instance         |
1713c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1723c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x01   | Data[0]: Audio Device Index   | Reply for Start       |
1733c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a TX Instance         |
1743c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1753c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x02   | Data[0]: Audio Device Index   | Reply for Pause       |
1763c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a TX Instance         |
1773c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1783c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x03   | Data[0]: Audio Device Index   | Reply for Resume      |
1793c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a TX Instance         |
1803c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1813c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x04   | Data[0]: Audio Device Index   | Reply for Stop        |
1823c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a TX Instance         |
1833c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1843c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x05   | Data[0]: Audio Device Index   | Reply for Close       |
1853c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a TX Instance         |
1863c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1873c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x06   | Data[0]: Audio Device Index   | Reply for Set Param   |
1883c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | for a TX Instance.    |
1893c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1903c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x07   | Data[0]: Audio Device Index   | Reply for Set         |
1913c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | TX Buffer             |
1923c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1933c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x08   | Data[0]: Audio Device Index   | Reply for Suspend     |
1943c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a TX Instance         |
1953c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1963c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x09   | Data[0]: Audio Device Index   | Reply for Resume      |
1973c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a TX Instance         |
1983c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
1993c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x0A   | Data[0]: Audio Device Index   | Reply for Open        |
2003c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a TX Instance         |
2013c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2023c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x0B   | Data[0]: Audio Device Index   | Reply for Start       |
2033c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a TX Instance         |
2043c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2053c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x0C   | Data[0]: Audio Device Index   | Reply for Pause       |
2063c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a TX Instance         |
2073c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2083c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x0D   | Data[0]: Audio Device Index   | Reply for Resume      |
2093c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a RX Instance         |
2103c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2113c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x0E   | Data[0]: Audio Device Index   | Reply for Stop        |
2123c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a RX Instance         |
2133c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2143c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x0F   | Data[0]: Audio Device Index   | Reply for Close       |
2153c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a RX Instance         |
2163c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2173c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x10   | Data[0]: Audio Device Index   | Reply for Set Param   |
2183c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | for a RX Instance.    |
2193c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2203c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x11   | Data[0]: Audio Device Index   | Reply for Set         |
2213c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | RX Buffer             |
2223c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2233c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x12   | Data[0]: Audio Device Index   | Reply for Suspend     |
2243c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a RX Instance         |
2253c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2263c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x13   | Data[0]: Audio Device Index   | Reply for Resume      |
2273c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | a RX Instance         |
2283c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2293c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x14   | Data[0]: Audio Device Index   | Reply for Set codec   |
2303c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | register value        |
2313c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2323c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x01 |  0x15   | Data[0]: Audio Device Index   | Reply for Get codec   |
2333c00ecebSShengjiu Wang  *   |          |         |      |         | Data[1]: Return code          | register value        |
2343c00ecebSShengjiu Wang  *   |          |         |      |         | Data[2-6]:   reserved         |                       |
2353c00ecebSShengjiu Wang  *   |          |         |      |         | Data[7-10]:  register         |                       |
2363c00ecebSShengjiu Wang  *   |          |         |      |         | Data[11-14]: value            |                       |
2373c00ecebSShengjiu Wang  *   |          |         |      |         | Data[15-22]: reserved         |                       |
2383c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2393c00ecebSShengjiu Wang  *
2403c00ecebSShengjiu Wang  *   SRTM Audio Control Category Notification Command Table:
2413c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2423c00ecebSShengjiu Wang  *   | Category | Version | Type | Command | Data                          | Function              |
2433c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2443c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x02 |  0x00   | Data[0]: Audio Device Index   | Notify one TX period  |
2453c00ecebSShengjiu Wang  *   |          |         |      |         |                               | is finished           |
2463c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2473c00ecebSShengjiu Wang  *   |  0x03    | 0x0100  | 0x02 |  0x01   | Data[0]: Audio Device Index   | Notify one RX period  |
2483c00ecebSShengjiu Wang  *   |          |         |      |         |                               | is finished           |
2493c00ecebSShengjiu Wang  *   +----------+---------+------+---------+-------------------------------+-----------------------+
2503c00ecebSShengjiu Wang  *
2513c00ecebSShengjiu Wang  *   List of Sample Format:
2523c00ecebSShengjiu Wang  *   +------------------+-----------------------+
2533c00ecebSShengjiu Wang  *   | Sample Format    |   Description         |
2543c00ecebSShengjiu Wang  *   +------------------+-----------------------+
2553c00ecebSShengjiu Wang  *   |       0x0        | S16_LE                |
2563c00ecebSShengjiu Wang  *   +------------------+-----------------------+
2573c00ecebSShengjiu Wang  *   |       0x1        | S24_LE                |
2583c00ecebSShengjiu Wang  *   +------------------+-----------------------+
2593c00ecebSShengjiu Wang  *
2603c00ecebSShengjiu Wang  *   List of Audio Channels
2613c00ecebSShengjiu Wang  *   +------------------+-----------------------+
2623c00ecebSShengjiu Wang  *   |  Audio Channel   |   Description         |
2633c00ecebSShengjiu Wang  *   +------------------+-----------------------+
2643c00ecebSShengjiu Wang  *   |       0x0        | Left Channel          |
2653c00ecebSShengjiu Wang  *   +------------------+-----------------------+
2663c00ecebSShengjiu Wang  *   |       0x1        | Right Channel         |
2673c00ecebSShengjiu Wang  *   +------------------+---------------- ------+
2683c00ecebSShengjiu Wang  *   |       0x2        | Left & Right Channel  |
2693c00ecebSShengjiu Wang  *   +------------------+-----------------------+
2703c00ecebSShengjiu Wang  *
2713c00ecebSShengjiu Wang  */
2723c00ecebSShengjiu Wang 
2733c00ecebSShengjiu Wang #ifndef _IMX_PCM_RPMSG_H
2743c00ecebSShengjiu Wang #define _IMX_PCM_RPMSG_H
2753c00ecebSShengjiu Wang 
2763c00ecebSShengjiu Wang #include <linux/pm_qos.h>
2773c00ecebSShengjiu Wang #include <linux/interrupt.h>
2783c00ecebSShengjiu Wang #include <sound/dmaengine_pcm.h>
2793c00ecebSShengjiu Wang 
2803c00ecebSShengjiu Wang #define RPMSG_TIMEOUT 1000
2813c00ecebSShengjiu Wang 
2823c00ecebSShengjiu Wang /* RPMSG Command (TYPE A)*/
2833c00ecebSShengjiu Wang #define TX_OPEN		0x0
2843c00ecebSShengjiu Wang #define	TX_START	0x1
2853c00ecebSShengjiu Wang #define	TX_PAUSE	0x2
2863c00ecebSShengjiu Wang #define	TX_RESTART	0x3
2873c00ecebSShengjiu Wang #define	TX_TERMINATE	0x4
2883c00ecebSShengjiu Wang #define	TX_CLOSE	0x5
2893c00ecebSShengjiu Wang #define TX_HW_PARAM	0x6
2903c00ecebSShengjiu Wang #define	TX_BUFFER	0x7
2913c00ecebSShengjiu Wang #define	TX_SUSPEND	0x8
2923c00ecebSShengjiu Wang #define	TX_RESUME	0x9
2933c00ecebSShengjiu Wang 
2943c00ecebSShengjiu Wang #define	RX_OPEN		0xA
2953c00ecebSShengjiu Wang #define	RX_START	0xB
2963c00ecebSShengjiu Wang #define	RX_PAUSE	0xC
2973c00ecebSShengjiu Wang #define	RX_RESTART	0xD
2983c00ecebSShengjiu Wang #define	RX_TERMINATE	0xE
2993c00ecebSShengjiu Wang #define	RX_CLOSE	0xF
3003c00ecebSShengjiu Wang #define	RX_HW_PARAM	0x10
3013c00ecebSShengjiu Wang #define	RX_BUFFER	0x11
3023c00ecebSShengjiu Wang #define	RX_SUSPEND	0x12
3033c00ecebSShengjiu Wang #define	RX_RESUME	0x13
3043c00ecebSShengjiu Wang #define SET_CODEC_VALUE 0x14
3053c00ecebSShengjiu Wang #define GET_CODEC_VALUE 0x15
3063c00ecebSShengjiu Wang #define	TX_POINTER	0x16
3073c00ecebSShengjiu Wang #define	RX_POINTER	0x17
3083c00ecebSShengjiu Wang /* Total msg numver for type A */
3093c00ecebSShengjiu Wang #define MSG_TYPE_A_NUM  0x18
3103c00ecebSShengjiu Wang 
3113c00ecebSShengjiu Wang /* RPMSG Command (TYPE C)*/
3123c00ecebSShengjiu Wang #define	TX_PERIOD_DONE	0x0
3133c00ecebSShengjiu Wang #define	RX_PERIOD_DONE	0x1
3143c00ecebSShengjiu Wang /* Total msg numver for type C */
3153c00ecebSShengjiu Wang #define MSG_TYPE_C_NUM  0x2
3163c00ecebSShengjiu Wang 
3173c00ecebSShengjiu Wang #define MSG_MAX_NUM     (MSG_TYPE_A_NUM + MSG_TYPE_C_NUM)
3183c00ecebSShengjiu Wang 
3193c00ecebSShengjiu Wang #define MSG_TYPE_A	0x0
3203c00ecebSShengjiu Wang #define MSG_TYPE_B	0x1
3213c00ecebSShengjiu Wang #define MSG_TYPE_C	0x2
3223c00ecebSShengjiu Wang 
3233c00ecebSShengjiu Wang #define RESP_NONE		0x0
3243c00ecebSShengjiu Wang #define RESP_NOT_ALLOWED	0x1
3253c00ecebSShengjiu Wang #define	RESP_SUCCESS		0x2
3263c00ecebSShengjiu Wang #define	RESP_FAILED		0x3
3273c00ecebSShengjiu Wang 
3283c00ecebSShengjiu Wang #define	RPMSG_S16_LE		0x0
3293c00ecebSShengjiu Wang #define	RPMSG_S24_LE		0x1
3303c00ecebSShengjiu Wang #define	RPMSG_S32_LE		0x2
331*a387040aSShengjiu Wang #define	RPMSG_DSD_U16_LE	49  /* SNDRV_PCM_FORMAT_DSD_U16_LE */
3323c00ecebSShengjiu Wang #define	RPMSG_DSD_U24_LE	0x4
333*a387040aSShengjiu Wang #define	RPMSG_DSD_U32_LE	50  /* SNDRV_PCM_FORMAT_DSD_U32_LE */
3343c00ecebSShengjiu Wang 
3353c00ecebSShengjiu Wang #define	RPMSG_CH_LEFT		0x0
3363c00ecebSShengjiu Wang #define	RPMSG_CH_RIGHT		0x1
3373c00ecebSShengjiu Wang #define	RPMSG_CH_STEREO		0x2
3383c00ecebSShengjiu Wang 
3393c00ecebSShengjiu Wang #define WORK_MAX_NUM    0x30
3403c00ecebSShengjiu Wang 
3413c00ecebSShengjiu Wang /* Category define */
3423c00ecebSShengjiu Wang #define IMX_RMPSG_LIFECYCLE     1
3433c00ecebSShengjiu Wang #define IMX_RPMSG_PMIC          2
3443c00ecebSShengjiu Wang #define IMX_RPMSG_AUDIO         3
3453c00ecebSShengjiu Wang #define IMX_RPMSG_KEY           4
3463c00ecebSShengjiu Wang #define IMX_RPMSG_GPIO          5
3473c00ecebSShengjiu Wang #define IMX_RPMSG_RTC           6
3483c00ecebSShengjiu Wang #define IMX_RPMSG_SENSOR        7
3493c00ecebSShengjiu Wang 
3503c00ecebSShengjiu Wang /* rpmsg version */
3513c00ecebSShengjiu Wang #define IMX_RMPSG_MAJOR         1
3523c00ecebSShengjiu Wang #define IMX_RMPSG_MINOR         0
3533c00ecebSShengjiu Wang 
3543c00ecebSShengjiu Wang #define TX SNDRV_PCM_STREAM_PLAYBACK
3553c00ecebSShengjiu Wang #define RX SNDRV_PCM_STREAM_CAPTURE
3563c00ecebSShengjiu Wang 
3573c00ecebSShengjiu Wang /**
3583c00ecebSShengjiu Wang  * struct rpmsg_head: rpmsg header structure
3593c00ecebSShengjiu Wang  *
3603c00ecebSShengjiu Wang  * @cate: category
3613c00ecebSShengjiu Wang  * @major: major version
3623c00ecebSShengjiu Wang  * @minor: minor version
3633c00ecebSShengjiu Wang  * @type: message type (A/B/C)
3643c00ecebSShengjiu Wang  * @cmd: message command
3653c00ecebSShengjiu Wang  * @reserved: reserved space
3663c00ecebSShengjiu Wang  */
3673c00ecebSShengjiu Wang struct rpmsg_head {
3683c00ecebSShengjiu Wang 	u8 cate;
3693c00ecebSShengjiu Wang 	u8 major;
3703c00ecebSShengjiu Wang 	u8 minor;
3713c00ecebSShengjiu Wang 	u8 type;
3723c00ecebSShengjiu Wang 	u8 cmd;
3733c00ecebSShengjiu Wang 	u8 reserved[5];
3743c00ecebSShengjiu Wang } __packed;
3753c00ecebSShengjiu Wang 
3763c00ecebSShengjiu Wang /**
3773c00ecebSShengjiu Wang  * struct param_s: sent rpmsg parameter
3783c00ecebSShengjiu Wang  *
3793c00ecebSShengjiu Wang  * @audioindex: audio instance index
3803c00ecebSShengjiu Wang  * @format: audio format
3813c00ecebSShengjiu Wang  * @channels: audio channel number
3823c00ecebSShengjiu Wang  * @rate: sample rate
3833c00ecebSShengjiu Wang  * @buffer_addr: dma buffer physical address or register for SET_CODEC_VALUE
3843c00ecebSShengjiu Wang  * @buffer_size: dma buffer size or register value for SET_CODEC_VALUE
3853c00ecebSShengjiu Wang  * @period_size: period size
3863c00ecebSShengjiu Wang  * @buffer_tail: current period index
3873c00ecebSShengjiu Wang  */
3883c00ecebSShengjiu Wang struct param_s {
3893c00ecebSShengjiu Wang 	unsigned char audioindex;
3903c00ecebSShengjiu Wang 	unsigned char format;
3913c00ecebSShengjiu Wang 	unsigned char channels;
3923c00ecebSShengjiu Wang 	unsigned int  rate;
3933c00ecebSShengjiu Wang 	unsigned int  buffer_addr;
3943c00ecebSShengjiu Wang 	unsigned int  buffer_size;
3953c00ecebSShengjiu Wang 	unsigned int  period_size;
3963c00ecebSShengjiu Wang 	unsigned int  buffer_tail;
3973c00ecebSShengjiu Wang } __packed;
3983c00ecebSShengjiu Wang 
3993c00ecebSShengjiu Wang /**
4003c00ecebSShengjiu Wang  * struct param_s: send rpmsg parameter
4013c00ecebSShengjiu Wang  *
4023c00ecebSShengjiu Wang  * @audioindex: audio instance index
4033c00ecebSShengjiu Wang  * @resp: response value
4043c00ecebSShengjiu Wang  * @reserved1: reserved space
4053c00ecebSShengjiu Wang  * @buffer_offset: the consumed offset of buffer
4063c00ecebSShengjiu Wang  * @reg_addr: register addr of codec
4073c00ecebSShengjiu Wang  * @reg_data: register value of codec
4083c00ecebSShengjiu Wang  * @reserved2: reserved space
4093c00ecebSShengjiu Wang  * @buffer_tail: current period index
4103c00ecebSShengjiu Wang  */
4113c00ecebSShengjiu Wang struct param_r {
4123c00ecebSShengjiu Wang 	unsigned char audioindex;
4133c00ecebSShengjiu Wang 	unsigned char resp;
4143c00ecebSShengjiu Wang 	unsigned char reserved1[1];
4153c00ecebSShengjiu Wang 	unsigned int  buffer_offset;
4163c00ecebSShengjiu Wang 	unsigned int  reg_addr;
4173c00ecebSShengjiu Wang 	unsigned int  reg_data;
4183c00ecebSShengjiu Wang 	unsigned char reserved2[4];
4193c00ecebSShengjiu Wang 	unsigned int  buffer_tail;
4203c00ecebSShengjiu Wang } __packed;
4213c00ecebSShengjiu Wang 
4223c00ecebSShengjiu Wang /* Struct of sent message */
4233c00ecebSShengjiu Wang struct rpmsg_s_msg {
4243c00ecebSShengjiu Wang 	struct rpmsg_head header;
4253c00ecebSShengjiu Wang 	struct param_s    param;
4263c00ecebSShengjiu Wang };
4273c00ecebSShengjiu Wang 
4283c00ecebSShengjiu Wang /* Struct of received message */
4293c00ecebSShengjiu Wang struct rpmsg_r_msg {
4303c00ecebSShengjiu Wang 	struct rpmsg_head header;
4313c00ecebSShengjiu Wang 	struct param_r    param;
4323c00ecebSShengjiu Wang };
4333c00ecebSShengjiu Wang 
4343c00ecebSShengjiu Wang /* Struct of rpmsg */
4353c00ecebSShengjiu Wang struct rpmsg_msg {
4363c00ecebSShengjiu Wang 	struct rpmsg_s_msg  s_msg;
4373c00ecebSShengjiu Wang 	struct rpmsg_r_msg  r_msg;
4383c00ecebSShengjiu Wang };
4393c00ecebSShengjiu Wang 
4403c00ecebSShengjiu Wang /* Struct of rpmsg for workqueue */
4413c00ecebSShengjiu Wang struct work_of_rpmsg {
4423c00ecebSShengjiu Wang 	struct rpmsg_info   *info;
4433c00ecebSShengjiu Wang 	/* Sent msg for each work */
4443c00ecebSShengjiu Wang 	struct rpmsg_msg    msg;
4453c00ecebSShengjiu Wang 	struct work_struct  work;
4463c00ecebSShengjiu Wang };
4473c00ecebSShengjiu Wang 
4483c00ecebSShengjiu Wang /* Struct of timer */
4493c00ecebSShengjiu Wang struct stream_timer {
4503c00ecebSShengjiu Wang 	struct timer_list   timer;
4513c00ecebSShengjiu Wang 	struct rpmsg_info   *info;
4523c00ecebSShengjiu Wang 	struct snd_pcm_substream *substream;
4533c00ecebSShengjiu Wang };
4543c00ecebSShengjiu Wang 
4553c00ecebSShengjiu Wang typedef void (*dma_callback)(void *arg);
4563c00ecebSShengjiu Wang 
4573c00ecebSShengjiu Wang /**
4583c00ecebSShengjiu Wang  * struct rpmsg_info: rpmsg audio information
4593c00ecebSShengjiu Wang  *
4603c00ecebSShengjiu Wang  * @rpdev: pointer of rpmsg_device
4613c00ecebSShengjiu Wang  * @dev: pointer for imx_pcm_rpmsg device
4623c00ecebSShengjiu Wang  * @cmd_complete: command is finished
4633c00ecebSShengjiu Wang  * @pm_qos_req: request of pm qos
4643c00ecebSShengjiu Wang  * @r_msg: received rpmsg
4653c00ecebSShengjiu Wang  * @msg: array of rpmsg
4663c00ecebSShengjiu Wang  * @notify: notification msg (type C) for TX & RX
4673c00ecebSShengjiu Wang  * @notify_updated: notification flag for TX & RX
4683c00ecebSShengjiu Wang  * @rpmsg_wq: rpmsg workqueue
4693c00ecebSShengjiu Wang  * @work_list: array of work list for workqueue
4703c00ecebSShengjiu Wang  * @work_write_index: write index of work list
4713c00ecebSShengjiu Wang  * @work_read_index: read index of work list
4723c00ecebSShengjiu Wang  * @msg_drop_count: counter of dropped msg for TX & RX
4733c00ecebSShengjiu Wang  * @num_period: period number for TX & RX
4743c00ecebSShengjiu Wang  * @callback_param: parameter for period elapse callback for TX & RX
4753c00ecebSShengjiu Wang  * @callback: period elapse callback for TX & RX
4763c00ecebSShengjiu Wang  * @send_message: function pointer for send message
4773c00ecebSShengjiu Wang  * @lock: spin lock for TX & RX
4783c00ecebSShengjiu Wang  * @wq_lock: lock for work queue
4793c00ecebSShengjiu Wang  * @msg_lock: lock for send message
4803c00ecebSShengjiu Wang  * @stream_timer: timer for tigger workqueue
4813c00ecebSShengjiu Wang  */
4823c00ecebSShengjiu Wang struct rpmsg_info {
4833c00ecebSShengjiu Wang 	struct rpmsg_device      *rpdev;
4843c00ecebSShengjiu Wang 	struct device            *dev;
4853c00ecebSShengjiu Wang 	struct completion        cmd_complete;
4863c00ecebSShengjiu Wang 	struct pm_qos_request    pm_qos_req;
4873c00ecebSShengjiu Wang 
4883c00ecebSShengjiu Wang 	/* Received msg (global) */
4893c00ecebSShengjiu Wang 	struct rpmsg_r_msg       r_msg;
4903c00ecebSShengjiu Wang 	struct rpmsg_msg         msg[MSG_MAX_NUM];
4913c00ecebSShengjiu Wang 	/* period done */
4923c00ecebSShengjiu Wang 	struct rpmsg_msg         notify[2];
4933c00ecebSShengjiu Wang 	bool                     notify_updated[2];
4943c00ecebSShengjiu Wang 
4953c00ecebSShengjiu Wang 	struct workqueue_struct  *rpmsg_wq;
4963c00ecebSShengjiu Wang 	struct work_of_rpmsg	 work_list[WORK_MAX_NUM];
4973c00ecebSShengjiu Wang 	int                      work_write_index;
4983c00ecebSShengjiu Wang 	int                      work_read_index;
4993c00ecebSShengjiu Wang 	int                      msg_drop_count[2];
5003c00ecebSShengjiu Wang 	int                      num_period[2];
5013c00ecebSShengjiu Wang 	void                     *callback_param[2];
5023c00ecebSShengjiu Wang 	dma_callback             callback[2];
5033c00ecebSShengjiu Wang 	int (*send_message)(struct rpmsg_msg *msg, struct rpmsg_info *info);
5043c00ecebSShengjiu Wang 	spinlock_t               lock[2]; /* spin lock for resource protection */
5053c00ecebSShengjiu Wang 	spinlock_t               wq_lock; /* spin lock for resource protection */
5063c00ecebSShengjiu Wang 	struct mutex             msg_lock; /* mutex for resource protection */
5073c00ecebSShengjiu Wang 	struct stream_timer      stream_timer[2];
5083c00ecebSShengjiu Wang };
5093c00ecebSShengjiu Wang 
5103c00ecebSShengjiu Wang #define IMX_PCM_DRV_NAME "imx_pcm_rpmsg"
5113c00ecebSShengjiu Wang 
5123c00ecebSShengjiu Wang #endif /* IMX_PCM_RPMSG_H */
513