arm64: dts: qcom: sm8550: add TRNG node
[linux-modified.git] / sound / soc / qcom / qdsp6 / q6apm.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __Q6APM_H__
3 #define __Q6APM_H__
4 #include <linux/types.h>
5 #include <linux/slab.h>
6 #include <linux/wait.h>
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/sched.h>
10 #include <linux/of.h>
11 #include <linux/delay.h>
12 #include <sound/soc.h>
13 #include <linux/of_platform.h>
14 #include <linux/jiffies.h>
15 #include <linux/soc/qcom/apr.h>
16 #include "audioreach.h"
17
18 #define APM_PORT_MAX            127
19 #define APM_PORT_MAX_AUDIO_CHAN_CNT 8
20 #define PCM_CHANNEL_NULL 0
21 #define PCM_CHANNEL_FL    1     /* Front left channel. */
22 #define PCM_CHANNEL_FR    2     /* Front right channel. */
23 #define PCM_CHANNEL_FC    3     /* Front center channel. */
24 #define PCM_CHANNEL_LS   4      /* Left surround channel. */
25 #define PCM_CHANNEL_RS   5      /* Right surround channel. */
26 #define PCM_CHANNEL_LFE  6      /* Low frequency effect channel. */
27 #define PCM_CHANNEL_CS   7      /* Center surround channel; Rear center ch */
28 #define PCM_CHANNEL_LB   8      /* Left back channel; Rear left channel. */
29 #define PCM_CHANNEL_RB   9      /* Right back channel; Rear right channel. */
30 #define PCM_CHANNELS   10       /* Top surround channel. */
31
32 #define APM_TIMESTAMP_FLAG      0x80000000
33 #define FORMAT_LINEAR_PCM       0x0000
34 /* APM client callback events */
35 #define APM_CMD_EOS                             0x0003
36 #define APM_CLIENT_EVENT_CMD_EOS_DONE           0x1003
37 #define APM_CMD_CLOSE                           0x0004
38 #define APM_CLIENT_EVENT_CMD_CLOSE_DONE         0x1004
39 #define APM_CLIENT_EVENT_CMD_RUN_DONE           0x1008
40 #define APM_CLIENT_EVENT_DATA_WRITE_DONE        0x1009
41 #define APM_CLIENT_EVENT_DATA_READ_DONE         0x100a
42 #define APM_WRITE_TOKEN_MASK                   GENMASK(15, 0)
43 #define APM_WRITE_TOKEN_LEN_MASK               GENMASK(31, 16)
44 #define APM_WRITE_TOKEN_LEN_SHIFT              16
45
46 #define APM_MAX_SESSIONS                        8
47 #define APM_LAST_BUFFER_FLAG                    BIT(30)
48 #define NO_TIMESTAMP                            0xFF00
49
50 struct q6apm {
51         struct device *dev;
52         gpr_port_t *port;
53         gpr_device_t *gdev;
54         /* For Graph OPEN/START/STOP/CLOSE operations */
55         wait_queue_head_t wait;
56         struct gpr_ibasic_rsp_result_t result;
57
58         struct mutex cmd_lock;
59         struct mutex lock;
60         uint32_t state;
61
62         struct list_head widget_list;
63         struct idr graph_idr;
64         struct idr graph_info_idr;
65         struct idr sub_graphs_idr;
66         struct idr containers_idr;
67         struct idr modules_idr;
68 };
69
70 struct audio_buffer {
71         phys_addr_t phys;
72         uint32_t size;          /* size of buffer */
73 };
74
75 struct audioreach_graph_data {
76         struct audio_buffer *buf;
77         uint32_t num_periods;
78         uint32_t dsp_buf;
79         uint32_t mem_map_handle;
80 };
81
82 struct audioreach_graph {
83         struct audioreach_graph_info *info;
84         uint32_t id;
85         int state;
86         int start_count;
87         /* Cached Graph data */
88         void *graph;
89         struct kref refcount;
90         struct q6apm *apm;
91 };
92
93 typedef void (*q6apm_cb) (uint32_t opcode, uint32_t token,
94                           void *payload, void *priv);
95 struct q6apm_graph {
96         void *priv;
97         q6apm_cb cb;
98         uint32_t id;
99         struct device *dev;
100         struct q6apm *apm;
101         gpr_port_t *port;
102         struct audioreach_graph_data rx_data;
103         struct audioreach_graph_data tx_data;
104         struct gpr_ibasic_rsp_result_t result;
105         wait_queue_head_t cmd_wait;
106         struct mutex lock;
107         struct audioreach_graph *ar_graph;
108         struct audioreach_graph_info *info;
109 };
110
111 /* Graph Operations */
112 struct q6apm_graph *q6apm_graph_open(struct device *dev, q6apm_cb cb,
113                                      void *priv, int graph_id);
114 int q6apm_graph_close(struct q6apm_graph *graph);
115 int q6apm_graph_prepare(struct q6apm_graph *graph);
116 int q6apm_graph_start(struct q6apm_graph *graph);
117 int q6apm_graph_stop(struct q6apm_graph *graph);
118 int q6apm_graph_flush(struct q6apm_graph *graph);
119
120 /* Media Format */
121 int q6apm_graph_media_format_pcm(struct q6apm_graph *graph,
122                                  struct audioreach_module_config *cfg);
123
124 int q6apm_graph_media_format_shmem(struct q6apm_graph *graph,
125                                    struct audioreach_module_config *cfg);
126
127 /* read/write related */
128 int q6apm_read(struct q6apm_graph *graph);
129 int q6apm_write_async(struct q6apm_graph *graph, uint32_t len, uint32_t msw_ts,
130                       uint32_t lsw_ts, uint32_t wflags);
131
132 /* Memory Map related */
133 int q6apm_map_memory_regions(struct q6apm_graph *graph,
134                              unsigned int dir, phys_addr_t phys,
135                              size_t period_sz, unsigned int periods);
136 int q6apm_unmap_memory_regions(struct q6apm_graph *graph,
137                                unsigned int dir);
138 /* Helpers */
139 int q6apm_send_cmd_sync(struct q6apm *apm, struct gpr_pkt *pkt,
140                         uint32_t rsp_opcode);
141
142 /* Callback for graph specific */
143 struct audioreach_module *q6apm_find_module_by_mid(struct q6apm_graph *graph,
144                                                     uint32_t mid);
145 int q6apm_graph_get_rx_shmem_module_iid(struct q6apm_graph *graph);
146
147 bool q6apm_is_adsp_ready(void);
148
149 int q6apm_enable_compress_module(struct device *dev, struct q6apm_graph *graph, bool en);
150 int q6apm_remove_initial_silence(struct device *dev, struct q6apm_graph *graph, uint32_t samples);
151 int q6apm_remove_trailing_silence(struct device *dev, struct q6apm_graph *graph, uint32_t samples);
152 int q6apm_set_real_module_id(struct device *dev, struct q6apm_graph *graph, uint32_t codec_id);
153 #endif /* __APM_GRAPH_ */