/* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright 2017-2021 NXP * ****************************************************************************** * Communication stack of audio with rpmsg ****************************************************************************** * Packet structure: * A SRTM message consists of a 10 bytes header followed by 0~N bytes of data * * +---------------+-------------------------------+ * | | Content | * +---------------+-------------------------------+ * | Byte Offset | 7 6 5 4 3 2 1 0 | * +---------------+---+---+---+---+---+---+---+---+ * | 0 | Category | * +---------------+---+---+---+---+---+---+---+---+ * | 1 ~ 2 | Version | * +---------------+---+---+---+---+---+---+---+---+ * | 3 | Type | * +---------------+---+---+---+---+---+---+---+---+ * | 4 | Command | * +---------------+---+---+---+---+---+---+---+---+ * | 5 | Reserved0 | * +---------------+---+---+---+---+---+---+---+---+ * | 6 | Reserved1 | * +---------------+---+---+---+---+---+---+---+---+ * | 7 | Reserved2 | * +---------------+---+---+---+---+---+---+---+---+ * | 8 | Reserved3 | * +---------------+---+---+---+---+---+---+---+---+ * | 9 | Reserved4 | * +---------------+---+---+---+---+---+---+---+---+ * | 10 | DATA 0 | * +---------------+---+---+---+---+---+---+---+---+ * : : : : : : : : : : : : : * +---------------+---+---+---+---+---+---+---+---+ * | N + 10 - 1 | DATA N-1 | * +---------------+---+---+---+---+---+---+---+---+ * * +----------+------------+------------------------------------------------+ * | Field | Byte | | * +----------+------------+------------------------------------------------+ * | Category | 0 | The destination category. | * +----------+------------+------------------------------------------------+ * | Version | 1 ~ 2 | The category version of the sender of the | * | | | packet. | * | | | The first byte represent the major version of | * | | | the packet.The second byte represent the minor | * | | | version of the packet. | * +----------+------------+------------------------------------------------+ * | Type | 3 | The message type of current message packet. | * +----------+------------+------------------------------------------------+ * | Command | 4 | The command byte sent to remote processor/SoC. | * +----------+------------+------------------------------------------------+ * | Reserved | 5 ~ 9 | Reserved field for future extension. | * +----------+------------+------------------------------------------------+ * | Data | N | The data payload of the message packet. | * +----------+------------+------------------------------------------------+ * * Audio control: * SRTM Audio Control Category Request Command Table: * +----------+---------+------+---------+-------------------------------+-----------------------+ * | Category | Version | Type | Command | Data | Function | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x00 | Data[0]: Audio Device Index | Open a TX Instance. | * | | | | | Data[1]: format | | * | | | | | Data[2]: channels | | * | | | | | Data[3-6]: samplerate | | * | | | | | Data[7-10]: buffer_addr | | * | | | | | Data[11-14]: buffer_size | | * | | | | | Data[15-18]: period_size | | * | | | | | Data[19-22]: buffer_tail | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x01 | Data[0]: Audio Device Index | Start a TX Instance. | * | | | | | Same as above command | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x02 | Data[0]: Audio Device Index | Pause a TX Instance. | * | | | | | Same as above command | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x03 | Data[0]: Audio Device Index | Resume a TX Instance. | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x04 | Data[0]: Audio Device Index | Stop a TX Instance. | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x05 | Data[0]: Audio Device Index | Close a TX Instance. | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x06 | Data[0]: Audio Device Index | Set Parameters for | * | | | | | Data[1]: format | a TX Instance. | * | | | | | Data[2]: channels | | * | | | | | Data[3-6]: samplerate | | * | | | | | Data[7-22]: reserved | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x07 | Data[0]: Audio Device Index | Set TX Buffer. | * | | | | | Data[1-6]: reserved | | * | | | | | Data[7-10]: buffer_addr | | * | | | | | Data[11-14]: buffer_size | | * | | | | | Data[15-18]: period_size | | * | | | | | Data[19-22]: buffer_tail | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x08 | Data[0]: Audio Device Index | Suspend a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x09 | Data[0]: Audio Device Index | Resume a TX Instance. | * | | | | | Data[1]: format | | * | | | | | Data[2]: channels | | * | | | | | Data[3-6]: samplerate | | * | | | | | Data[7-10]: buffer_addr | | * | | | | | Data[11-14]: buffer_size | | * | | | | | Data[15-18]: period_size | | * | | | | | Data[19-22]: buffer_tail | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x0A | Data[0]: Audio Device Index | Open a RX Instance. | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x0B | Data[0]: Audio Device Index | Start a RX Instance. | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x0C | Data[0]: Audio Device Index | Pause a RX Instance. | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x0D | Data[0]: Audio Device Index | Resume a RX Instance. | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x0E | Data[0]: Audio Device Index | Stop a RX Instance. | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x0F | Data[0]: Audio Device Index | Close a RX Instance. | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x10 | Data[0]: Audio Device Index | Set Parameters for | * | | | | | Data[1]: format | a RX Instance. | * | | | | | Data[2]: channels | | * | | | | | Data[3-6]: samplerate | | * | | | | | Data[7-22]: reserved | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x11 | Data[0]: Audio Device Index | Set RX Buffer. | * | | | | | Data[1-6]: reserved | | * | | | | | Data[7-10]: buffer_addr | | * | | | | | Data[11-14]: buffer_size | | * | | | | | Data[15-18]: period_size | | * | | | | | Data[19-22]: buffer_tail | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x12 | Data[0]: Audio Device Index | Suspend a RX Instance.| * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x13 | Data[0]: Audio Device Index | Resume a RX Instance. | * | | | | | Data[1]: format | | * | | | | | Data[2]: channels | | * | | | | | Data[3-6]: samplerate | | * | | | | | Data[7-10]: buffer_addr | | * | | | | | Data[11-14]: buffer_size | | * | | | | | Data[15-18]: period_size | | * | | | | | Data[19-22]: buffer_tail | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x14 | Data[0]: Audio Device Index | Set register value | * | | | | | Data[1-6]: reserved | to codec | * | | | | | Data[7-10]: register | | * | | | | | Data[11-14]: value | | * | | | | | Data[15-22]: reserved | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x00 | 0x15 | Data[0]: Audio Device Index | Get register value | * | | | | | Data[1-6]: reserved | from codec | * | | | | | Data[7-10]: register | | * | | | | | Data[11-22]: reserved | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * Note 1: See <List of Sample Format> for available value of * Sample Format; * Note 2: See <List of Audio Channels> for available value of Channels; * Note 3: Sample Rate of Set Parameters for an Audio TX Instance * Command and Set Parameters for an Audio RX Instance Command is * in little-endian format. * * SRTM Audio Control Category Response Command Table: * +----------+---------+------+---------+-------------------------------+-----------------------+ * | Category | Version | Type | Command | Data | Function | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x00 | Data[0]: Audio Device Index | Reply for Open | * | | | | | Data[1]: Return code | a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x01 | Data[0]: Audio Device Index | Reply for Start | * | | | | | Data[1]: Return code | a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x02 | Data[0]: Audio Device Index | Reply for Pause | * | | | | | Data[1]: Return code | a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x03 | Data[0]: Audio Device Index | Reply for Resume | * | | | | | Data[1]: Return code | a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x04 | Data[0]: Audio Device Index | Reply for Stop | * | | | | | Data[1]: Return code | a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x05 | Data[0]: Audio Device Index | Reply for Close | * | | | | | Data[1]: Return code | a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x06 | Data[0]: Audio Device Index | Reply for Set Param | * | | | | | Data[1]: Return code | for a TX Instance. | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x07 | Data[0]: Audio Device Index | Reply for Set | * | | | | | Data[1]: Return code | TX Buffer | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x08 | Data[0]: Audio Device Index | Reply for Suspend | * | | | | | Data[1]: Return code | a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x09 | Data[0]: Audio Device Index | Reply for Resume | * | | | | | Data[1]: Return code | a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x0A | Data[0]: Audio Device Index | Reply for Open | * | | | | | Data[1]: Return code | a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x0B | Data[0]: Audio Device Index | Reply for Start | * | | | | | Data[1]: Return code | a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x0C | Data[0]: Audio Device Index | Reply for Pause | * | | | | | Data[1]: Return code | a TX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x0D | Data[0]: Audio Device Index | Reply for Resume | * | | | | | Data[1]: Return code | a RX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x0E | Data[0]: Audio Device Index | Reply for Stop | * | | | | | Data[1]: Return code | a RX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x0F | Data[0]: Audio Device Index | Reply for Close | * | | | | | Data[1]: Return code | a RX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x10 | Data[0]: Audio Device Index | Reply for Set Param | * | | | | | Data[1]: Return code | for a RX Instance. | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x11 | Data[0]: Audio Device Index | Reply for Set | * | | | | | Data[1]: Return code | RX Buffer | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x12 | Data[0]: Audio Device Index | Reply for Suspend | * | | | | | Data[1]: Return code | a RX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x13 | Data[0]: Audio Device Index | Reply for Resume | * | | | | | Data[1]: Return code | a RX Instance | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x14 | Data[0]: Audio Device Index | Reply for Set codec | * | | | | | Data[1]: Return code | register value | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x01 | 0x15 | Data[0]: Audio Device Index | Reply for Get codec | * | | | | | Data[1]: Return code | register value | * | | | | | Data[2-6]: reserved | | * | | | | | Data[7-10]: register | | * | | | | | Data[11-14]: value | | * | | | | | Data[15-22]: reserved | | * +----------+---------+------+---------+-------------------------------+-----------------------+ * * SRTM Audio Control Category Notification Command Table: * +----------+---------+------+---------+-------------------------------+-----------------------+ * | Category | Version | Type | Command | Data | Function | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x02 | 0x00 | Data[0]: Audio Device Index | Notify one TX period | * | | | | | | is finished | * +----------+---------+------+---------+-------------------------------+-----------------------+ * | 0x03 | 0x0100 | 0x02 | 0x01 | Data[0]: Audio Device Index | Notify one RX period | * | | | | | | is finished | * +----------+---------+------+---------+-------------------------------+-----------------------+ * * List of Sample Format: * +------------------+-----------------------+ * | Sample Format | Description | * +------------------+-----------------------+ * | 0x0 | S16_LE | * +------------------+-----------------------+ * | 0x1 | S24_LE | * +------------------+-----------------------+ * * List of Audio Channels * +------------------+-----------------------+ * | Audio Channel | Description | * +------------------+-----------------------+ * | 0x0 | Left Channel | * +------------------+-----------------------+ * | 0x1 | Right Channel | * +------------------+---------------- ------+ * | 0x2 | Left & Right Channel | * +------------------+-----------------------+ * */ #ifndef _IMX_PCM_RPMSG_H #define _IMX_PCM_RPMSG_H #include <linux/pm_qos.h> #include <linux/interrupt.h> #include <sound/dmaengine_pcm.h> #define RPMSG_TIMEOUT … /* RPMSG Command (TYPE A)*/ #define TX_OPEN … #define TX_START … #define TX_PAUSE … #define TX_RESTART … #define TX_TERMINATE … #define TX_CLOSE … #define TX_HW_PARAM … #define TX_BUFFER … #define TX_SUSPEND … #define TX_RESUME … #define RX_OPEN … #define RX_START … #define RX_PAUSE … #define RX_RESTART … #define RX_TERMINATE … #define RX_CLOSE … #define RX_HW_PARAM … #define RX_BUFFER … #define RX_SUSPEND … #define RX_RESUME … #define SET_CODEC_VALUE … #define GET_CODEC_VALUE … #define TX_POINTER … #define RX_POINTER … /* Total msg numver for type A */ #define MSG_TYPE_A_NUM … /* RPMSG Command (TYPE C)*/ #define TX_PERIOD_DONE … #define RX_PERIOD_DONE … /* Total msg numver for type C */ #define MSG_TYPE_C_NUM … #define MSG_MAX_NUM … #define MSG_TYPE_A … #define MSG_TYPE_B … #define MSG_TYPE_C … #define RESP_NONE … #define RESP_NOT_ALLOWED … #define RESP_SUCCESS … #define RESP_FAILED … #define RPMSG_S16_LE … #define RPMSG_S24_LE … #define RPMSG_S32_LE … #define RPMSG_DSD_U16_LE … #define RPMSG_DSD_U24_LE … #define RPMSG_DSD_U32_LE … #define RPMSG_CH_LEFT … #define RPMSG_CH_RIGHT … #define RPMSG_CH_STEREO … #define WORK_MAX_NUM … /* Category define */ #define IMX_RMPSG_LIFECYCLE … #define IMX_RPMSG_PMIC … #define IMX_RPMSG_AUDIO … #define IMX_RPMSG_KEY … #define IMX_RPMSG_GPIO … #define IMX_RPMSG_RTC … #define IMX_RPMSG_SENSOR … /* rpmsg version */ #define IMX_RMPSG_MAJOR … #define IMX_RMPSG_MINOR … #define TX … #define RX … /** * struct rpmsg_head: rpmsg header structure * * @cate: category * @major: major version * @minor: minor version * @type: message type (A/B/C) * @cmd: message command * @reserved: reserved space */ struct rpmsg_head { … } __packed; /** * struct param_s: sent rpmsg parameter * * @audioindex: audio instance index * @format: audio format * @channels: audio channel number * @rate: sample rate * @buffer_addr: dma buffer physical address or register for SET_CODEC_VALUE * @buffer_size: dma buffer size or register value for SET_CODEC_VALUE * @period_size: period size * @buffer_tail: current period index */ struct param_s { … } __packed; /** * struct param_s: send rpmsg parameter * * @audioindex: audio instance index * @resp: response value * @reserved1: reserved space * @buffer_offset: the consumed offset of buffer * @reg_addr: register addr of codec * @reg_data: register value of codec * @reserved2: reserved space * @buffer_tail: current period index */ struct param_r { … } __packed; /* Struct of sent message */ struct rpmsg_s_msg { … }; /* Struct of received message */ struct rpmsg_r_msg { … }; /* Struct of rpmsg */ struct rpmsg_msg { … }; /* Struct of rpmsg for workqueue */ struct work_of_rpmsg { … }; /* Struct of timer */ struct stream_timer { … }; dma_callback; /** * struct rpmsg_info: rpmsg audio information * * @rpdev: pointer of rpmsg_device * @dev: pointer for imx_pcm_rpmsg device * @cmd_complete: command is finished * @pm_qos_req: request of pm qos * @r_msg: received rpmsg * @msg: array of rpmsg * @notify: notification msg (type C) for TX & RX * @notify_updated: notification flag for TX & RX * @rpmsg_wq: rpmsg workqueue * @work_list: array of work list for workqueue * @work_write_index: write index of work list * @work_read_index: read index of work list * @msg_drop_count: counter of dropped msg for TX & RX * @num_period: period number for TX & RX * @callback_param: parameter for period elapse callback for TX & RX * @callback: period elapse callback for TX & RX * @send_message: function pointer for send message * @lock: spin lock for TX & RX * @wq_lock: lock for work queue * @msg_lock: lock for send message * @stream_timer: timer for tigger workqueue */ struct rpmsg_info { … }; #define IMX_PCM_DRV_NAME … #endif /* IMX_PCM_RPMSG_H */