Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __Q6APM_H__
0003 #define __Q6APM_H__
0004 #include <linux/types.h>
0005 #include <linux/slab.h>
0006 #include <linux/wait.h>
0007 #include <linux/kernel.h>
0008 #include <linux/module.h>
0009 #include <linux/sched.h>
0010 #include <linux/of.h>
0011 #include <linux/delay.h>
0012 #include <sound/soc.h>
0013 #include <linux/of_platform.h>
0014 #include <linux/jiffies.h>
0015 #include <linux/soc/qcom/apr.h>
0016 #include <dt-bindings/sound/qcom,q6dsp-lpass-ports.h>
0017 #include "audioreach.h"
0018 
0019 #define APM_PORT_MAX        127
0020 #define APM_PORT_MAX_AUDIO_CHAN_CNT 8
0021 #define PCM_CHANNEL_NULL 0
0022 #define PCM_CHANNEL_FL    1 /* Front left channel. */
0023 #define PCM_CHANNEL_FR    2 /* Front right channel. */
0024 #define PCM_CHANNEL_FC    3 /* Front center channel. */
0025 #define PCM_CHANNEL_LS   4  /* Left surround channel. */
0026 #define PCM_CHANNEL_RS   5  /* Right surround channel. */
0027 #define PCM_CHANNEL_LFE  6  /* Low frequency effect channel. */
0028 #define PCM_CHANNEL_CS   7  /* Center surround channel; Rear center ch */
0029 #define PCM_CHANNEL_LB   8  /* Left back channel; Rear left channel. */
0030 #define PCM_CHANNEL_RB   9  /* Right back channel; Rear right channel. */
0031 #define PCM_CHANNELS   10   /* Top surround channel. */
0032 
0033 #define APM_TIMESTAMP_FLAG  0x80000000
0034 #define FORMAT_LINEAR_PCM   0x0000
0035 /* APM client callback events */
0036 #define APM_CMD_EOS             0x0003
0037 #define APM_CLIENT_EVENT_CMD_EOS_DONE       0x1003
0038 #define APM_CMD_CLOSE               0x0004
0039 #define APM_CLIENT_EVENT_CMD_CLOSE_DONE     0x1004
0040 #define APM_CLIENT_EVENT_CMD_RUN_DONE       0x1008
0041 #define APM_CLIENT_EVENT_DATA_WRITE_DONE    0x1009
0042 #define APM_CLIENT_EVENT_DATA_READ_DONE     0x100a
0043 #define APM_WRITE_TOKEN_MASK                   GENMASK(15, 0)
0044 #define APM_WRITE_TOKEN_LEN_MASK               GENMASK(31, 16)
0045 #define APM_WRITE_TOKEN_LEN_SHIFT              16
0046 
0047 #define APM_MAX_SESSIONS            8
0048 
0049 struct q6apm {
0050     struct device *dev;
0051     gpr_port_t *port;
0052     gpr_device_t *gdev;
0053     /* For Graph OPEN/START/STOP/CLOSE operations */
0054     wait_queue_head_t wait;
0055     struct gpr_ibasic_rsp_result_t result;
0056 
0057     struct mutex cmd_lock;
0058     struct mutex lock;
0059     uint32_t state;
0060 
0061     struct idr graph_idr;
0062     struct idr graph_info_idr;
0063     struct idr sub_graphs_idr;
0064     struct idr containers_idr;
0065     struct idr modules_idr;
0066 };
0067 
0068 struct audio_buffer {
0069     phys_addr_t phys;
0070     uint32_t size;      /* size of buffer */
0071 };
0072 
0073 struct audioreach_graph_data {
0074     struct audio_buffer *buf;
0075     uint32_t num_periods;
0076     uint32_t dsp_buf;
0077     uint32_t mem_map_handle;
0078 };
0079 
0080 struct audioreach_graph {
0081     struct audioreach_graph_info *info;
0082     uint32_t id;
0083     int state;
0084     int start_count;
0085     /* Cached Graph data */
0086     void *graph;
0087     struct kref refcount;
0088     struct q6apm *apm;
0089 };
0090 
0091 typedef void (*q6apm_cb) (uint32_t opcode, uint32_t token,
0092               void *payload, void *priv);
0093 struct q6apm_graph {
0094     void *priv;
0095     q6apm_cb cb;
0096     uint32_t id;
0097     struct device *dev;
0098     struct q6apm *apm;
0099     gpr_port_t *port;
0100     struct audioreach_graph_data rx_data;
0101     struct audioreach_graph_data tx_data;
0102     struct gpr_ibasic_rsp_result_t result;
0103     wait_queue_head_t cmd_wait;
0104     struct mutex lock;
0105     struct audioreach_graph *ar_graph;
0106     struct audioreach_graph_info *info;
0107 };
0108 
0109 /* Graph Operations */
0110 struct q6apm_graph *q6apm_graph_open(struct device *dev, q6apm_cb cb,
0111                      void *priv, int graph_id);
0112 int q6apm_graph_close(struct q6apm_graph *graph);
0113 int q6apm_graph_prepare(struct q6apm_graph *graph);
0114 int q6apm_graph_start(struct q6apm_graph *graph);
0115 int q6apm_graph_stop(struct q6apm_graph *graph);
0116 int q6apm_graph_flush(struct q6apm_graph *graph);
0117 
0118 /* Media Format */
0119 int q6apm_graph_media_format_pcm(struct q6apm_graph *graph,
0120                  struct audioreach_module_config *cfg);
0121 
0122 int q6apm_graph_media_format_shmem(struct q6apm_graph *graph,
0123                    struct audioreach_module_config *cfg);
0124 
0125 /* read/write related */
0126 int q6apm_send_eos_nowait(struct q6apm_graph *graph);
0127 int q6apm_read(struct q6apm_graph *graph);
0128 int q6apm_write_async(struct q6apm_graph *graph, uint32_t len, uint32_t msw_ts,
0129               uint32_t lsw_ts, uint32_t wflags);
0130 
0131 /* Memory Map related */
0132 int q6apm_map_memory_regions(struct q6apm_graph *graph,
0133                  unsigned int dir, phys_addr_t phys,
0134                  size_t period_sz, unsigned int periods);
0135 int q6apm_unmap_memory_regions(struct q6apm_graph *graph,
0136                    unsigned int dir);
0137 /* Helpers */
0138 int q6apm_send_cmd_sync(struct q6apm *apm, struct gpr_pkt *pkt,
0139             uint32_t rsp_opcode);
0140 
0141 /* Callback for graph specific */
0142 struct audioreach_module *q6apm_find_module_by_mid(struct q6apm_graph *graph,
0143                             uint32_t mid);
0144 
0145 void q6apm_set_fe_dai_ops(struct snd_soc_dai_driver *dai_drv);
0146 int q6apm_connect_sub_graphs(struct q6apm *apm, u32 src_sgid, u32 dst_sgid,
0147                  bool connect);
0148 bool q6apm_is_sub_graphs_connected(struct q6apm *apm, u32 src_sgid,
0149                    u32 dst_sgid);
0150 int q6apm_graph_get_rx_shmem_module_iid(struct q6apm_graph *graph);
0151 
0152 #endif /* __APM_GRAPH_ */