OSDN Git Service

Merge android-4.4-p.203 (40ef73d) into msm-4.4
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / sound / q6lsm.h
1 /*
2  * Copyright (c) 2013-2017, 2019 Linux Foundation. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 and
6  * only version 2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13 #ifndef __Q6LSM_H__
14 #define __Q6LSM_H__
15
16 #include <linux/list.h>
17 #include <linux/msm_ion.h>
18 #include <sound/apr_audio-v2.h>
19 #include <sound/lsm_params.h>
20 #include <linux/qdsp6v2/apr.h>
21
22 #define MAX_NUM_CONFIDENCE 20
23
24 #define ADM_LSM_PORT_ID 0xADCB
25
26 #define LSM_MAX_NUM_CHANNELS 8
27
28 typedef void (*lsm_app_cb)(uint32_t opcode, uint32_t token,
29                        uint32_t *payload, uint16_t client_size, void *priv);
30
31 struct lsm_sound_model {
32         dma_addr_t      phys;
33         void            *data;
34         size_t          size; /* size of buffer */
35         uint32_t        actual_size; /* actual number of bytes read by DSP */
36         struct ion_handle *handle;
37         struct ion_client *client;
38         uint32_t        mem_map_handle;
39 };
40
41 struct snd_lsm_event_status_v2 {
42         uint16_t status;
43         uint16_t payload_size;
44         uint8_t  confidence_value[0];
45 };
46
47 struct lsm_lab_buffer {
48         dma_addr_t phys;
49         void *data;
50         size_t size;
51         struct ion_handle *handle;
52         struct ion_client *client;
53         uint32_t mem_map_handle;
54 };
55
56 struct lsm_hw_params {
57         u16 sample_rate;
58         u16 sample_size;
59         u32 buf_sz;
60         u32 period_count;
61         u16 num_chs;
62 };
63
64 struct lsm_client {
65         int             session;
66         lsm_app_cb      cb;
67         atomic_t        cmd_state;
68         void            *priv;
69         struct apr_svc  *apr;
70         struct apr_svc  *mmap_apr;
71         struct mutex    cmd_lock;
72         struct lsm_sound_model sound_model;
73         wait_queue_head_t cmd_wait;
74         uint32_t        cmd_err_code;
75         uint16_t        mode;
76         uint16_t        connect_to_port;
77         uint8_t         num_confidence_levels;
78         uint8_t         *confidence_levels;
79         bool            opened;
80         bool            started;
81         dma_addr_t      lsm_cal_phy_addr;
82         uint32_t        lsm_cal_size;
83         uint32_t        app_id;
84         bool            lab_enable;
85         bool            lab_started;
86         struct lsm_lab_buffer *lab_buffer;
87         struct lsm_hw_params hw_params;
88         bool            use_topology;
89         int             session_state;
90         bool            poll_enable;
91         int             perf_mode;
92         uint32_t        event_mode;
93 };
94
95 struct lsm_stream_cmd_open_tx {
96         struct apr_hdr  hdr;
97         uint16_t        app_id;
98         uint16_t        reserved;
99         uint32_t        sampling_rate;
100 } __packed;
101
102 struct lsm_stream_cmd_open_tx_v2 {
103         struct apr_hdr hdr;
104         uint32_t        topology_id;
105 } __packed;
106
107 struct lsm_custom_topologies {
108         struct apr_hdr hdr;
109         uint32_t data_payload_addr_lsw;
110         uint32_t data_payload_addr_msw;
111         uint32_t mem_map_handle;
112         uint32_t buffer_size;
113 } __packed;
114
115 struct lsm_session_cmd_set_params_v2 {
116         struct apr_hdr apr_hdr;
117         uint32_t payload_size;
118         struct mem_mapping_hdr mem_hdr;
119         u32 param_data[0];
120 } __packed;
121
122 struct lsm_session_cmd_set_params_v3 {
123         struct apr_hdr apr_hdr;
124         struct mem_mapping_hdr mem_hdr;
125         uint32_t payload_size;
126         u32 param_data[0];
127 } __packed;
128
129 struct lsm_param_op_mode {
130         uint32_t        minor_version;
131         uint16_t        mode;
132         uint16_t        reserved;
133 } __packed;
134
135 struct lsm_param_connect_to_port {
136         uint32_t        minor_version;
137         /* AFE port id that receives voice wake up data */
138         uint16_t        port_id;
139         uint16_t        reserved;
140 } __packed;
141
142 struct lsm_param_poll_enable {
143         uint32_t        minor_version;
144         /* indicates to voice wakeup that HW MAD/SW polling is enabled or not */
145         uint32_t        polling_enable;
146 } __packed;
147
148 struct lsm_param_fwk_mode_cfg {
149         uint32_t        minor_version;
150         uint32_t        mode;
151 } __packed;
152
153 struct lsm_param_media_fmt {
154         uint32_t        minor_version;
155         uint32_t        sample_rate;
156         uint16_t        num_channels;
157         uint16_t        bit_width;
158         uint8_t         channel_mapping[LSM_MAX_NUM_CHANNELS];
159 } __packed;
160
161 struct lsm_param_confidence_levels {
162         uint8_t num_confidence_levels;
163         uint8_t confidence_levels[0];
164 } __packed;
165
166 struct lsm_param_epd_thres {
167         uint32_t        minor_version;
168         uint32_t        epd_begin;
169         uint32_t        epd_end;
170 } __packed;
171
172 struct lsm_param_gain {
173         uint32_t        minor_version;
174         uint16_t        gain;
175         uint16_t        reserved;
176 } __packed;
177
178 struct lsm_cmd_reg_snd_model {
179         struct apr_hdr  hdr;
180         uint32_t        model_size;
181         uint32_t        model_addr_lsw;
182         uint32_t        model_addr_msw;
183         uint32_t        mem_map_handle;
184 } __packed;
185
186 struct lsm_param_lab_enable {
187         uint16_t enable;
188         uint16_t reserved;
189 } __packed;
190
191 struct lsm_param_lab_config {
192         uint32_t minor_version;
193         uint32_t wake_up_latency_ms;
194 } __packed;
195
196 struct lsm_cmd_read {
197         struct apr_hdr hdr;
198         uint32_t buf_addr_lsw;
199         uint32_t buf_addr_msw;
200         uint32_t mem_map_handle;
201         uint32_t buf_size;
202 } __packed;
203
204 struct lsm_cmd_read_done {
205         struct apr_hdr hdr;
206         uint32_t status;
207         uint32_t buf_addr_lsw;
208         uint32_t buf_addr_msw;
209         uint32_t mem_map_handle;
210         uint32_t total_size;
211         uint32_t offset;
212         uint32_t timestamp_lsw;
213         uint32_t timestamp_msw;
214         uint32_t flags;
215 } __packed;
216
217 struct lsm_client *q6lsm_client_alloc(lsm_app_cb cb, void *priv);
218 void q6lsm_client_free(struct lsm_client *client);
219 int q6lsm_open(struct lsm_client *client, uint16_t app_id);
220 int q6lsm_start(struct lsm_client *client, bool wait);
221 int q6lsm_stop(struct lsm_client *client, bool wait);
222 int q6lsm_snd_model_buf_alloc(struct lsm_client *client, size_t len,
223                               bool allocate_module_data);
224 int q6lsm_snd_model_buf_free(struct lsm_client *client);
225 int q6lsm_close(struct lsm_client *client);
226 int q6lsm_register_sound_model(struct lsm_client *client,
227                                enum lsm_detection_mode mode,
228                                bool detectfailure);
229 int q6lsm_set_data(struct lsm_client *client,
230                    enum lsm_detection_mode mode,
231                    bool detectfailure);
232 int q6lsm_deregister_sound_model(struct lsm_client *client);
233 void set_lsm_port(int);
234 int get_lsm_port(void);
235 int q6lsm_lab_control(struct lsm_client *client, u32 enable);
236 int q6lsm_stop_lab(struct lsm_client *client);
237 int q6lsm_read(struct lsm_client *client, struct lsm_cmd_read *read);
238 int q6lsm_lab_buffer_alloc(struct lsm_client *client, bool alloc);
239 int q6lsm_set_one_param(struct lsm_client *client,
240                         struct lsm_params_info *p_info, void *data,
241                         uint32_t param_type);
242 void q6lsm_sm_set_param_data(struct lsm_client *client,
243                 struct lsm_params_info *p_info,
244                 size_t *offset);
245 int q6lsm_set_port_connected(struct lsm_client *client);
246 int q6lsm_set_fwk_mode_cfg(struct lsm_client *client, uint32_t event_mode);
247 int q6lsm_set_media_fmt_params(struct lsm_client *client);
248 #endif /* __Q6LSM_H__ */