ASoC: constify snd_pcm_ops structures
[cascardo/linux.git] / sound / soc / intel / atom / sst-atom-controls.h
1 /*
2  *  sst-atom-controls.h - Intel MID Platform driver header file
3  *
4  *  Copyright (C) 2013-14 Intel Corp
5  *  Author: Ramesh Babu <ramesh.babu.koul@intel.com>
6  *      Omair M Abdullah <omair.m.abdullah@intel.com>
7  *      Samreen Nilofer <samreen.nilofer@intel.com>
8  *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; version 2 of the License.
13  *
14  *  This program is distributed in the hope that it will be useful, but
15  *  WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  General Public License for more details.
18  *
19  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20  *
21  */
22
23 #ifndef __SST_ATOM_CONTROLS_H__
24 #define __SST_ATOM_CONTROLS_H__
25
26 #include <sound/soc.h>
27 #include <sound/tlv.h>
28
29 enum {
30         MERR_DPCM_AUDIO = 0,
31         MERR_DPCM_DEEP_BUFFER,
32         MERR_DPCM_COMPR,
33 };
34
35 /* define a bit for each mixer input */
36 #define SST_MIX_IP(x)           (x)
37
38 #define SST_IP_CODEC0           SST_MIX_IP(2)
39 #define SST_IP_CODEC1           SST_MIX_IP(3)
40 #define SST_IP_LOOP0            SST_MIX_IP(4)
41 #define SST_IP_LOOP1            SST_MIX_IP(5)
42 #define SST_IP_LOOP2            SST_MIX_IP(6)
43 #define SST_IP_PROBE            SST_MIX_IP(7)
44 #define SST_IP_VOIP             SST_MIX_IP(12)
45 #define SST_IP_PCM0             SST_MIX_IP(13)
46 #define SST_IP_PCM1             SST_MIX_IP(14)
47 #define SST_IP_MEDIA0           SST_MIX_IP(17)
48 #define SST_IP_MEDIA1           SST_MIX_IP(18)
49 #define SST_IP_MEDIA2           SST_MIX_IP(19)
50 #define SST_IP_MEDIA3           SST_MIX_IP(20)
51
52 #define SST_IP_LAST             SST_IP_MEDIA3
53
54 #define SST_SWM_INPUT_COUNT     (SST_IP_LAST + 1)
55 #define SST_CMD_SWM_MAX_INPUTS  6
56
57 #define SST_PATH_ID_SHIFT       8
58 #define SST_DEFAULT_LOCATION_ID 0xFFFF
59 #define SST_DEFAULT_CELL_NBR    0xFF
60 #define SST_DEFAULT_MODULE_ID   0xFFFF
61
62 /*
63  * Audio DSP Path Ids. Specified by the audio DSP FW
64  */
65 enum sst_path_index {
66         SST_PATH_INDEX_CODEC_OUT0               = (0x02 << SST_PATH_ID_SHIFT),
67         SST_PATH_INDEX_CODEC_OUT1               = (0x03 << SST_PATH_ID_SHIFT),
68
69         SST_PATH_INDEX_SPROT_LOOP_OUT           = (0x04 << SST_PATH_ID_SHIFT),
70         SST_PATH_INDEX_MEDIA_LOOP1_OUT          = (0x05 << SST_PATH_ID_SHIFT),
71         SST_PATH_INDEX_MEDIA_LOOP2_OUT          = (0x06 << SST_PATH_ID_SHIFT),
72
73         SST_PATH_INDEX_VOIP_OUT                 = (0x0C << SST_PATH_ID_SHIFT),
74         SST_PATH_INDEX_PCM0_OUT                 = (0x0D << SST_PATH_ID_SHIFT),
75         SST_PATH_INDEX_PCM1_OUT                 = (0x0E << SST_PATH_ID_SHIFT),
76         SST_PATH_INDEX_PCM2_OUT                 = (0x0F << SST_PATH_ID_SHIFT),
77
78         SST_PATH_INDEX_MEDIA0_OUT               = (0x12 << SST_PATH_ID_SHIFT),
79         SST_PATH_INDEX_MEDIA1_OUT               = (0x13 << SST_PATH_ID_SHIFT),
80
81
82         /* Start of input paths */
83         SST_PATH_INDEX_CODEC_IN0                = (0x82 << SST_PATH_ID_SHIFT),
84         SST_PATH_INDEX_CODEC_IN1                = (0x83 << SST_PATH_ID_SHIFT),
85
86         SST_PATH_INDEX_SPROT_LOOP_IN            = (0x84 << SST_PATH_ID_SHIFT),
87         SST_PATH_INDEX_MEDIA_LOOP1_IN           = (0x85 << SST_PATH_ID_SHIFT),
88         SST_PATH_INDEX_MEDIA_LOOP2_IN           = (0x86 << SST_PATH_ID_SHIFT),
89
90         SST_PATH_INDEX_VOIP_IN                  = (0x8C << SST_PATH_ID_SHIFT),
91
92         SST_PATH_INDEX_PCM0_IN                  = (0x8D << SST_PATH_ID_SHIFT),
93         SST_PATH_INDEX_PCM1_IN                  = (0x8E << SST_PATH_ID_SHIFT),
94
95         SST_PATH_INDEX_MEDIA0_IN                = (0x8F << SST_PATH_ID_SHIFT),
96         SST_PATH_INDEX_MEDIA1_IN                = (0x90 << SST_PATH_ID_SHIFT),
97         SST_PATH_INDEX_MEDIA2_IN                = (0x91 << SST_PATH_ID_SHIFT),
98
99         SST_PATH_INDEX_MEDIA3_IN                = (0x9C << SST_PATH_ID_SHIFT),
100
101         SST_PATH_INDEX_RESERVED                 = (0xFF << SST_PATH_ID_SHIFT),
102 };
103
104 /*
105  * path IDs
106  */
107 enum sst_swm_inputs {
108         SST_SWM_IN_CODEC0       = (SST_PATH_INDEX_CODEC_IN0       | SST_DEFAULT_CELL_NBR),
109         SST_SWM_IN_CODEC1       = (SST_PATH_INDEX_CODEC_IN1       | SST_DEFAULT_CELL_NBR),
110         SST_SWM_IN_SPROT_LOOP   = (SST_PATH_INDEX_SPROT_LOOP_IN   | SST_DEFAULT_CELL_NBR),
111         SST_SWM_IN_MEDIA_LOOP1  = (SST_PATH_INDEX_MEDIA_LOOP1_IN  | SST_DEFAULT_CELL_NBR),
112         SST_SWM_IN_MEDIA_LOOP2  = (SST_PATH_INDEX_MEDIA_LOOP2_IN  | SST_DEFAULT_CELL_NBR),
113         SST_SWM_IN_VOIP         = (SST_PATH_INDEX_VOIP_IN         | SST_DEFAULT_CELL_NBR),
114         SST_SWM_IN_PCM0         = (SST_PATH_INDEX_PCM0_IN         | SST_DEFAULT_CELL_NBR),
115         SST_SWM_IN_PCM1         = (SST_PATH_INDEX_PCM1_IN         | SST_DEFAULT_CELL_NBR),
116         SST_SWM_IN_MEDIA0       = (SST_PATH_INDEX_MEDIA0_IN       | SST_DEFAULT_CELL_NBR), /* Part of Media Mixer */
117         SST_SWM_IN_MEDIA1       = (SST_PATH_INDEX_MEDIA1_IN       | SST_DEFAULT_CELL_NBR), /* Part of Media Mixer */
118         SST_SWM_IN_MEDIA2       = (SST_PATH_INDEX_MEDIA2_IN       | SST_DEFAULT_CELL_NBR), /* Part of Media Mixer */
119         SST_SWM_IN_MEDIA3       = (SST_PATH_INDEX_MEDIA3_IN       | SST_DEFAULT_CELL_NBR), /* Part of Media Mixer */
120         SST_SWM_IN_END          = (SST_PATH_INDEX_RESERVED        | SST_DEFAULT_CELL_NBR)
121 };
122
123 /*
124  * path IDs
125  */
126 enum sst_swm_outputs {
127         SST_SWM_OUT_CODEC0      = (SST_PATH_INDEX_CODEC_OUT0      | SST_DEFAULT_CELL_NBR),
128         SST_SWM_OUT_CODEC1      = (SST_PATH_INDEX_CODEC_OUT1      | SST_DEFAULT_CELL_NBR),
129         SST_SWM_OUT_SPROT_LOOP  = (SST_PATH_INDEX_SPROT_LOOP_OUT  | SST_DEFAULT_CELL_NBR),
130         SST_SWM_OUT_MEDIA_LOOP1 = (SST_PATH_INDEX_MEDIA_LOOP1_OUT | SST_DEFAULT_CELL_NBR),
131         SST_SWM_OUT_MEDIA_LOOP2 = (SST_PATH_INDEX_MEDIA_LOOP2_OUT | SST_DEFAULT_CELL_NBR),
132         SST_SWM_OUT_VOIP        = (SST_PATH_INDEX_VOIP_OUT        | SST_DEFAULT_CELL_NBR),
133         SST_SWM_OUT_PCM0        = (SST_PATH_INDEX_PCM0_OUT        | SST_DEFAULT_CELL_NBR),
134         SST_SWM_OUT_PCM1        = (SST_PATH_INDEX_PCM1_OUT        | SST_DEFAULT_CELL_NBR),
135         SST_SWM_OUT_PCM2        = (SST_PATH_INDEX_PCM2_OUT        | SST_DEFAULT_CELL_NBR),
136         SST_SWM_OUT_MEDIA0      = (SST_PATH_INDEX_MEDIA0_OUT      | SST_DEFAULT_CELL_NBR), /* Part of Media Mixer */
137         SST_SWM_OUT_MEDIA1      = (SST_PATH_INDEX_MEDIA1_OUT      | SST_DEFAULT_CELL_NBR), /* Part of Media Mixer */
138         SST_SWM_OUT_END         = (SST_PATH_INDEX_RESERVED        | SST_DEFAULT_CELL_NBR),
139 };
140
141 enum sst_ipc_msg {
142         SST_IPC_IA_CMD = 1,
143         SST_IPC_IA_SET_PARAMS,
144         SST_IPC_IA_GET_PARAMS,
145 };
146
147 enum sst_cmd_type {
148         SST_CMD_BYTES_SET = 1,
149         SST_CMD_BYTES_GET = 2,
150 };
151
152 enum sst_task {
153         SST_TASK_SBA = 1,
154         SST_TASK_MMX = 3,
155 };
156
157 enum sst_type {
158         SST_TYPE_CMD = 1,
159         SST_TYPE_PARAMS,
160 };
161
162 enum sst_flag {
163         SST_FLAG_BLOCKED = 1,
164         SST_FLAG_NONBLOCK,
165 };
166
167 /*
168  * Enumeration for indexing the gain cells in VB_SET_GAIN DSP command
169  */
170 enum sst_gain_index {
171         /* GAIN IDs for SB task start here */
172         SST_GAIN_INDEX_CODEC_OUT0,
173         SST_GAIN_INDEX_CODEC_OUT1,
174         SST_GAIN_INDEX_CODEC_IN0,
175         SST_GAIN_INDEX_CODEC_IN1,
176
177         SST_GAIN_INDEX_SPROT_LOOP_OUT,
178         SST_GAIN_INDEX_MEDIA_LOOP1_OUT,
179         SST_GAIN_INDEX_MEDIA_LOOP2_OUT,
180
181         SST_GAIN_INDEX_PCM0_IN_LEFT,
182         SST_GAIN_INDEX_PCM0_IN_RIGHT,
183
184         SST_GAIN_INDEX_PCM1_OUT_LEFT,
185         SST_GAIN_INDEX_PCM1_OUT_RIGHT,
186         SST_GAIN_INDEX_PCM1_IN_LEFT,
187         SST_GAIN_INDEX_PCM1_IN_RIGHT,
188         SST_GAIN_INDEX_PCM2_OUT_LEFT,
189
190         SST_GAIN_INDEX_PCM2_OUT_RIGHT,
191         SST_GAIN_INDEX_VOIP_OUT,
192         SST_GAIN_INDEX_VOIP_IN,
193
194         /* Gain IDs for MMX task start here */
195         SST_GAIN_INDEX_MEDIA0_IN_LEFT,
196         SST_GAIN_INDEX_MEDIA0_IN_RIGHT,
197         SST_GAIN_INDEX_MEDIA1_IN_LEFT,
198         SST_GAIN_INDEX_MEDIA1_IN_RIGHT,
199
200         SST_GAIN_INDEX_MEDIA2_IN_LEFT,
201         SST_GAIN_INDEX_MEDIA2_IN_RIGHT,
202
203         SST_GAIN_INDEX_GAIN_END
204 };
205
206 /*
207  * Audio DSP module IDs specified by FW spec
208  * TODO: Update with all modules
209  */
210 enum sst_module_id {
211         SST_MODULE_ID_PCM                 = 0x0001,
212         SST_MODULE_ID_MP3                 = 0x0002,
213         SST_MODULE_ID_MP24                = 0x0003,
214         SST_MODULE_ID_AAC                 = 0x0004,
215         SST_MODULE_ID_AACP                = 0x0005,
216         SST_MODULE_ID_EAACP               = 0x0006,
217         SST_MODULE_ID_WMA9                = 0x0007,
218         SST_MODULE_ID_WMA10               = 0x0008,
219         SST_MODULE_ID_WMA10P              = 0x0009,
220         SST_MODULE_ID_RA                  = 0x000A,
221         SST_MODULE_ID_DDAC3               = 0x000B,
222         SST_MODULE_ID_TRUE_HD             = 0x000C,
223         SST_MODULE_ID_HD_PLUS             = 0x000D,
224
225         SST_MODULE_ID_SRC                 = 0x0064,
226         SST_MODULE_ID_DOWNMIX             = 0x0066,
227         SST_MODULE_ID_GAIN_CELL           = 0x0067,
228         SST_MODULE_ID_SPROT               = 0x006D,
229         SST_MODULE_ID_BASS_BOOST          = 0x006E,
230         SST_MODULE_ID_STEREO_WDNG         = 0x006F,
231         SST_MODULE_ID_AV_REMOVAL          = 0x0070,
232         SST_MODULE_ID_MIC_EQ              = 0x0071,
233         SST_MODULE_ID_SPL                 = 0x0072,
234         SST_MODULE_ID_ALGO_VTSV           = 0x0073,
235         SST_MODULE_ID_NR                  = 0x0076,
236         SST_MODULE_ID_BWX                 = 0x0077,
237         SST_MODULE_ID_DRP                 = 0x0078,
238         SST_MODULE_ID_MDRP                = 0x0079,
239
240         SST_MODULE_ID_ANA                 = 0x007A,
241         SST_MODULE_ID_AEC                 = 0x007B,
242         SST_MODULE_ID_NR_SNS              = 0x007C,
243         SST_MODULE_ID_SER                 = 0x007D,
244         SST_MODULE_ID_AGC                 = 0x007E,
245
246         SST_MODULE_ID_CNI                 = 0x007F,
247         SST_MODULE_ID_CONTEXT_ALGO_AWARE  = 0x0080,
248         SST_MODULE_ID_FIR_24              = 0x0081,
249         SST_MODULE_ID_IIR_24              = 0x0082,
250
251         SST_MODULE_ID_ASRC                = 0x0083,
252         SST_MODULE_ID_TONE_GEN            = 0x0084,
253         SST_MODULE_ID_BMF                 = 0x0086,
254         SST_MODULE_ID_EDL                 = 0x0087,
255         SST_MODULE_ID_GLC                 = 0x0088,
256
257         SST_MODULE_ID_FIR_16              = 0x0089,
258         SST_MODULE_ID_IIR_16              = 0x008A,
259         SST_MODULE_ID_DNR                 = 0x008B,
260
261         SST_MODULE_ID_VIRTUALIZER         = 0x008C,
262         SST_MODULE_ID_VISUALIZATION       = 0x008D,
263         SST_MODULE_ID_LOUDNESS_OPTIMIZER  = 0x008E,
264         SST_MODULE_ID_REVERBERATION       = 0x008F,
265
266         SST_MODULE_ID_CNI_TX              = 0x0090,
267         SST_MODULE_ID_REF_LINE            = 0x0091,
268         SST_MODULE_ID_VOLUME              = 0x0092,
269         SST_MODULE_ID_FILT_DCR            = 0x0094,
270         SST_MODULE_ID_SLV                 = 0x009A,
271         SST_MODULE_ID_NLF                 = 0x009B,
272         SST_MODULE_ID_TNR                 = 0x009C,
273         SST_MODULE_ID_WNR                 = 0x009D,
274
275         SST_MODULE_ID_LOG                 = 0xFF00,
276
277         SST_MODULE_ID_TASK                = 0xFFFF,
278 };
279
280 enum sst_cmd {
281         SBA_IDLE                = 14,
282         SBA_VB_SET_SPEECH_PATH  = 26,
283         MMX_SET_GAIN            = 33,
284         SBA_VB_SET_GAIN         = 33,
285         FBA_VB_RX_CNI           = 35,
286         MMX_SET_GAIN_TIMECONST  = 36,
287         SBA_VB_SET_TIMECONST    = 36,
288         SBA_VB_START            = 85,
289         SBA_SET_SWM             = 114,
290         SBA_SET_MDRP            = 116,
291         SBA_HW_SET_SSP          = 117,
292         SBA_SET_MEDIA_LOOP_MAP  = 118,
293         SBA_SET_MEDIA_PATH      = 119,
294         MMX_SET_MEDIA_PATH      = 119,
295         SBA_VB_LPRO             = 126,
296         SBA_VB_SET_FIR          = 128,
297         SBA_VB_SET_IIR          = 129,
298         SBA_SET_SSP_SLOT_MAP    = 130,
299 };
300
301 enum sst_dsp_switch {
302         SST_SWITCH_OFF = 0,
303         SST_SWITCH_ON = 3,
304 };
305
306 enum sst_path_switch {
307         SST_PATH_OFF = 0,
308         SST_PATH_ON = 1,
309 };
310
311 enum sst_swm_state {
312         SST_SWM_OFF = 0,
313         SST_SWM_ON = 3,
314 };
315
316 #define SST_FILL_LOCATION_IDS(dst, cell_idx, pipe_id)           do {    \
317                 dst.location_id.p.cell_nbr_idx = (cell_idx);            \
318                 dst.location_id.p.path_id = (pipe_id);                  \
319         } while (0)
320 #define SST_FILL_LOCATION_ID(dst, loc_id)                               (\
321         dst.location_id.f = (loc_id))
322 #define SST_FILL_MODULE_ID(dst, mod_id)                                 (\
323         dst.module_id = (mod_id))
324
325 #define SST_FILL_DESTINATION1(dst, id)                          do {    \
326                 SST_FILL_LOCATION_ID(dst, (id) & 0xFFFF);               \
327                 SST_FILL_MODULE_ID(dst, ((id) & 0xFFFF0000) >> 16);     \
328         } while (0)
329 #define SST_FILL_DESTINATION2(dst, loc_id, mod_id)              do {    \
330                 SST_FILL_LOCATION_ID(dst, loc_id);                      \
331                 SST_FILL_MODULE_ID(dst, mod_id);                        \
332         } while (0)
333 #define SST_FILL_DESTINATION3(dst, cell_idx, path_id, mod_id)   do {    \
334                 SST_FILL_LOCATION_IDS(dst, cell_idx, path_id);          \
335                 SST_FILL_MODULE_ID(dst, mod_id);                        \
336         } while (0)
337
338 #define SST_FILL_DESTINATION(level, dst, ...)                           \
339         SST_FILL_DESTINATION##level(dst, __VA_ARGS__)
340 #define SST_FILL_DEFAULT_DESTINATION(dst)                               \
341         SST_FILL_DESTINATION(2, dst, SST_DEFAULT_LOCATION_ID, SST_DEFAULT_MODULE_ID)
342
343 struct sst_destination_id {
344         union sst_location_id {
345                 struct {
346                         u8 cell_nbr_idx;        /* module index */
347                         u8 path_id;             /* pipe_id */
348                 } __packed      p;              /* part */
349                 u16             f;              /* full */
350         } __packed location_id;
351         u16        module_id;
352 } __packed;
353 struct sst_dsp_header {
354         struct sst_destination_id dst;
355         u16 command_id;
356         u16 length;
357 } __packed;
358
359 /*
360  *
361  * Common Commands
362  *
363  */
364 struct sst_cmd_generic {
365         struct sst_dsp_header header;
366 } __packed;
367
368 struct swm_input_ids {
369         struct sst_destination_id input_id;
370 } __packed;
371
372 struct sst_cmd_set_swm {
373         struct sst_dsp_header header;
374         struct sst_destination_id output_id;
375         u16    switch_state;
376         u16    nb_inputs;
377         struct swm_input_ids input[SST_CMD_SWM_MAX_INPUTS];
378 } __packed;
379
380 struct sst_cmd_set_media_path {
381         struct sst_dsp_header header;
382         u16    switch_state;
383 } __packed;
384
385 struct pcm_cfg {
386                 u8 s_length:2;
387                 u8 rate:3;
388                 u8 format:3;
389 } __packed;
390
391 struct sst_cmd_set_speech_path {
392         struct sst_dsp_header header;
393         u16    switch_state;
394         struct {
395                 u16 rsvd:8;
396                 struct pcm_cfg cfg;
397         } config;
398 } __packed;
399
400 struct gain_cell {
401         struct sst_destination_id dest;
402         s16 cell_gain_left;
403         s16 cell_gain_right;
404         u16 gain_time_constant;
405 } __packed;
406
407 #define NUM_GAIN_CELLS 1
408 struct sst_cmd_set_gain_dual {
409         struct sst_dsp_header header;
410         u16    gain_cell_num;
411         struct gain_cell cell_gains[NUM_GAIN_CELLS];
412 } __packed;
413 struct sst_cmd_set_params {
414         struct sst_destination_id dst;
415         u16 command_id;
416         char params[0];
417 } __packed;
418
419
420 struct sst_cmd_sba_vb_start {
421         struct sst_dsp_header header;
422 } __packed;
423
424 union sba_media_loop_params {
425         struct {
426                 u16 rsvd:8;
427                 struct pcm_cfg cfg;
428         } part;
429         u16 full;
430 } __packed;
431
432 struct sst_cmd_sba_set_media_loop_map {
433         struct  sst_dsp_header header;
434         u16     switch_state;
435         union   sba_media_loop_params param;
436         u16     map;
437 } __packed;
438
439 struct sst_cmd_tone_stop {
440         struct  sst_dsp_header header;
441         u16     switch_state;
442 } __packed;
443
444 enum sst_ssp_mode {
445         SSP_MODE_MASTER = 0,
446         SSP_MODE_SLAVE = 1,
447 };
448
449 enum sst_ssp_pcm_mode {
450         SSP_PCM_MODE_NORMAL = 0,
451         SSP_PCM_MODE_NETWORK = 1,
452 };
453
454 enum sst_ssp_duplex {
455         SSP_DUPLEX = 0,
456         SSP_RX = 1,
457         SSP_TX = 2,
458 };
459
460 enum sst_ssp_fs_frequency {
461         SSP_FS_8_KHZ = 0,
462         SSP_FS_16_KHZ = 1,
463         SSP_FS_44_1_KHZ = 2,
464         SSP_FS_48_KHZ = 3,
465 };
466
467 enum sst_ssp_fs_polarity {
468         SSP_FS_ACTIVE_LOW = 0,
469         SSP_FS_ACTIVE_HIGH = 1,
470 };
471
472 enum sst_ssp_protocol {
473         SSP_MODE_PCM = 0,
474         SSP_MODE_I2S = 1,
475 };
476
477 enum sst_ssp_port_id {
478         SSP_MODEM = 0,
479         SSP_BT = 1,
480         SSP_FM = 2,
481         SSP_CODEC = 3,
482 };
483
484 struct sst_cmd_sba_hw_set_ssp {
485         struct sst_dsp_header header;
486         u16 selection;                  /* 0:SSP0(def), 1:SSP1, 2:SSP2 */
487
488         u16 switch_state;
489
490         u16 nb_bits_per_slots:6;        /* 0-32 bits, 24 (def) */
491         u16 nb_slots:4;                 /* 0-8: slots per frame  */
492         u16 mode:3;                     /* 0:Master, 1: Slave  */
493         u16 duplex:3;
494
495         u16 active_tx_slot_map:8;       /* Bit map, 0:off, 1:on */
496         u16 reserved1:8;
497
498         u16 active_rx_slot_map:8;       /* Bit map 0: Off, 1:On */
499         u16 reserved2:8;
500
501         u16 frame_sync_frequency;
502
503         u16 frame_sync_polarity:8;
504         u16 data_polarity:8;
505
506         u16 frame_sync_width;           /* 1 to N clocks */
507         u16 ssp_protocol:8;
508         u16 start_delay:8;              /* Start delay in terms of clock ticks */
509 } __packed;
510
511 #define SST_MAX_TDM_SLOTS 8
512
513 struct sst_param_sba_ssp_slot_map {
514         struct sst_dsp_header header;
515
516         u16 param_id;
517         u16 param_len;
518         u16 ssp_index;
519
520         u8 rx_slot_map[SST_MAX_TDM_SLOTS];
521         u8 tx_slot_map[SST_MAX_TDM_SLOTS];
522 } __packed;
523
524 enum {
525         SST_PROBE_EXTRACTOR = 0,
526         SST_PROBE_INJECTOR = 1,
527 };
528
529 /**** widget defines *****/
530
531 #define SST_MODULE_GAIN 1
532 #define SST_MODULE_ALGO 2
533
534 #define SST_FMT_MONO 0
535 #define SST_FMT_STEREO 3
536
537 /* physical SSP numbers */
538 enum {
539         SST_SSP0 = 0,
540         SST_SSP1,
541         SST_SSP2,
542         SST_SSP_LAST = SST_SSP2,
543 };
544
545 #define SST_NUM_SSPS            (SST_SSP_LAST + 1)      /* physical SSPs */
546 #define SST_MAX_SSP_MUX         2                       /* single SSP muxed between pipes */
547 #define SST_MAX_SSP_DOMAINS     2                       /* domains present in each pipe */
548
549 struct sst_module {
550         struct snd_kcontrol *kctl;
551         struct list_head node;
552 };
553
554 struct sst_ssp_config {
555         u8 ssp_id;
556         u8 bits_per_slot;
557         u8 slots;
558         u8 ssp_mode;
559         u8 pcm_mode;
560         u8 duplex;
561         u8 ssp_protocol;
562         u8 fs_frequency;
563         u8 active_slot_map;
564         u8 start_delay;
565         u16 fs_width;
566         u8 frame_sync_polarity;
567         u8 data_polarity;
568 };
569
570 struct sst_ssp_cfg {
571         const u8 ssp_number;
572         const int *mux_shift;
573         const int (*domain_shift)[SST_MAX_SSP_MUX];
574         const struct sst_ssp_config (*ssp_config)[SST_MAX_SSP_MUX][SST_MAX_SSP_DOMAINS];
575 };
576
577 struct sst_ids {
578         u16 location_id;
579         u16 module_id;
580         u8  task_id;
581         u8  format;
582         u8  reg;
583         const char *parent_wname;
584         struct snd_soc_dapm_widget *parent_w;
585         struct list_head algo_list;
586         struct list_head gain_list;
587         const struct sst_pcm_format *pcm_fmt;
588 };
589
590
591 #define SST_AIF_IN(wname, wevent)                                                       \
592 {       .id = snd_soc_dapm_aif_in, .name = wname, .sname = NULL,                        \
593         .reg = SND_SOC_NOPM, .shift = 0,                                        \
594         .on_val = 1, .off_val = 0,                                                      \
595         .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD,   \
596         .priv = (void *)&(struct sst_ids) { .task_id = 0, .location_id = 0 }            \
597 }
598
599 #define SST_AIF_OUT(wname, wevent)                                                      \
600 {       .id = snd_soc_dapm_aif_out, .name = wname, .sname = NULL,                       \
601         .reg = SND_SOC_NOPM, .shift = 0,                                                \
602         .on_val = 1, .off_val = 0,                                                      \
603         .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD,   \
604         .priv = (void *)&(struct sst_ids) { .task_id = 0, .location_id = 0 }            \
605 }
606
607 #define SST_INPUT(wname, wevent)                                                        \
608 {       .id = snd_soc_dapm_input, .name = wname, .sname = NULL,                         \
609         .reg = SND_SOC_NOPM, .shift = 0,                                                \
610         .on_val = 1, .off_val = 0,                                                      \
611         .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD,   \
612         .priv = (void *)&(struct sst_ids) { .task_id = 0, .location_id = 0 }            \
613 }
614
615 #define SST_OUTPUT(wname, wevent)                                                       \
616 {       .id = snd_soc_dapm_output, .name = wname, .sname = NULL,                        \
617         .reg = SND_SOC_NOPM, .shift = 0,                                                \
618         .on_val = 1, .off_val = 0,                                                      \
619         .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD,   \
620         .priv = (void *)&(struct sst_ids) { .task_id = 0, .location_id = 0 }            \
621 }
622
623 #define SST_DAPM_OUTPUT(wname, wloc_id, wtask_id, wformat, wevent)                      \
624 {       .id = snd_soc_dapm_output, .name = wname, .sname = NULL,                        \
625         .reg = SND_SOC_NOPM, .shift = 0,                                                \
626         .on_val = 1, .off_val = 0,                                                      \
627         .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD,   \
628         .priv = (void *)&(struct sst_ids) { .location_id = wloc_id, .task_id = wtask_id,\
629                                                 .pcm_fmt = wformat, }                   \
630 }
631
632 #define SST_PATH(wname, wtask, wloc_id, wevent, wflags)                                 \
633 {       .id = snd_soc_dapm_pga, .name = wname, .reg = SND_SOC_NOPM, .shift = 0,         \
634         .kcontrol_news = NULL, .num_kcontrols = 0,                              \
635         .on_val = 1, .off_val = 0,                                                      \
636         .event = wevent, .event_flags = wflags,                                         \
637         .priv = (void *)&(struct sst_ids) { .task_id = wtask, .location_id = wloc_id, } \
638 }
639
640 #define SST_LINKED_PATH(wname, wtask, wloc_id, linked_wname, wevent, wflags)            \
641 {       .id = snd_soc_dapm_pga, .name = wname, .reg = SND_SOC_NOPM, .shift = 0,         \
642         .kcontrol_news = NULL, .num_kcontrols = 0,                              \
643         .on_val = 1, .off_val = 0,                                                      \
644         .event = wevent, .event_flags = wflags,                                         \
645         .priv = (void *)&(struct sst_ids) { .task_id = wtask, .location_id = wloc_id,   \
646                                         .parent_wname = linked_wname}                   \
647 }
648
649 #define SST_PATH_MEDIA_LOOP(wname, wtask, wloc_id, wformat, wevent, wflags)             \
650 {       .id = snd_soc_dapm_pga, .name = wname, .reg = SND_SOC_NOPM, .shift = 0,         \
651         .kcontrol_news = NULL, .num_kcontrols = 0,                         \
652         .event = wevent, .event_flags = wflags,                                         \
653         .priv = (void *)&(struct sst_ids) { .task_id = wtask, .location_id = wloc_id,   \
654                                             .format = wformat,}                         \
655 }
656
657 /* output is triggered before input */
658 #define SST_PATH_INPUT(name, task_id, loc_id, event)                                    \
659         SST_PATH(name, task_id, loc_id, event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)
660
661 #define SST_PATH_LINKED_INPUT(name, task_id, loc_id, linked_wname, event)               \
662         SST_LINKED_PATH(name, task_id, loc_id, linked_wname, event,                     \
663                                         SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD)
664
665 #define SST_PATH_OUTPUT(name, task_id, loc_id, event)                                   \
666         SST_PATH(name, task_id, loc_id, event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD)
667
668 #define SST_PATH_LINKED_OUTPUT(name, task_id, loc_id, linked_wname, event)              \
669         SST_LINKED_PATH(name, task_id, loc_id, linked_wname, event,                     \
670                                         SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD)
671
672 #define SST_PATH_MEDIA_LOOP_OUTPUT(name, task_id, loc_id, format, event)                \
673         SST_PATH_MEDIA_LOOP(name, task_id, loc_id, format, event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD)
674
675
676 #define SST_SWM_MIXER(wname, wreg, wtask, wloc_id, wcontrols, wevent)                   \
677 {       .id = snd_soc_dapm_mixer, .name = wname, .reg = SND_SOC_NOPM, .shift = 0,       \
678         .kcontrol_news = wcontrols, .num_kcontrols = ARRAY_SIZE(wcontrols),\
679         .event = wevent, .event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD |  \
680                                         SND_SOC_DAPM_POST_REG,                          \
681         .priv = (void *)&(struct sst_ids) { .task_id = wtask, .location_id = wloc_id,   \
682                                             .reg = wreg }                               \
683 }
684
685 enum sst_gain_kcontrol_type {
686         SST_GAIN_TLV,
687         SST_GAIN_MUTE,
688         SST_GAIN_RAMP_DURATION,
689 };
690
691 struct sst_gain_mixer_control {
692         bool stereo;
693         enum sst_gain_kcontrol_type type;
694         struct sst_gain_value *gain_val;
695         int max;
696         int min;
697         u16 instance_id;
698         u16 module_id;
699         u16 pipe_id;
700         u16 task_id;
701         char pname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
702         struct snd_soc_dapm_widget *w;
703 };
704
705 struct sst_gain_value {
706         u16 ramp_duration;
707         s16 l_gain;
708         s16 r_gain;
709         bool mute;
710 };
711 #define SST_GAIN_VOLUME_DEFAULT         (-1440)
712 #define SST_GAIN_RAMP_DURATION_DEFAULT  5 /* timeconstant */
713 #define SST_GAIN_MUTE_DEFAULT           true
714
715 #define SST_GAIN_KCONTROL_TLV(xname, xhandler_get, xhandler_put, \
716                               xmod, xpipe, xinstance, xtask, tlv_array, xgain_val, \
717                               xmin, xmax, xpname) \
718         .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
719         .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
720                   SNDRV_CTL_ELEM_ACCESS_READWRITE, \
721         .tlv.p = (tlv_array), \
722         .info = sst_gain_ctl_info,\
723         .get = xhandler_get, .put = xhandler_put, \
724         .private_value = (unsigned long)&(struct sst_gain_mixer_control) \
725         { .stereo = true, .max = xmax, .min = xmin, .type = SST_GAIN_TLV, \
726           .module_id = xmod, .pipe_id = xpipe, .task_id = xtask,\
727           .instance_id = xinstance, .gain_val = xgain_val, .pname = xpname}
728
729 #define SST_GAIN_KCONTROL_INT(xname, xhandler_get, xhandler_put, \
730                               xmod, xpipe, xinstance, xtask, xtype, xgain_val, \
731                               xmin, xmax, xpname) \
732         .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
733         .info = sst_gain_ctl_info, \
734         .get = xhandler_get, .put = xhandler_put, \
735         .private_value = (unsigned long)&(struct sst_gain_mixer_control) \
736         { .stereo = false, .max = xmax, .min = xmin, .type = xtype, \
737           .module_id = xmod, .pipe_id = xpipe, .task_id = xtask,\
738           .instance_id = xinstance, .gain_val = xgain_val, .pname =  xpname}
739
740 #define SST_GAIN_KCONTROL_BOOL(xname, xhandler_get, xhandler_put,\
741                                xmod, xpipe, xinstance, xtask, xgain_val, xpname) \
742         .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
743         .info = snd_soc_info_bool_ext, \
744         .get = xhandler_get, .put = xhandler_put, \
745         .private_value = (unsigned long)&(struct sst_gain_mixer_control) \
746         { .stereo = false, .type = SST_GAIN_MUTE, \
747           .module_id = xmod, .pipe_id = xpipe, .task_id = xtask,\
748           .instance_id = xinstance, .gain_val = xgain_val, .pname = xpname}
749 #define SST_CONTROL_NAME(xpname, xmname, xinstance, xtype) \
750         xpname " " xmname " " #xinstance " " xtype
751
752 #define SST_COMBO_CONTROL_NAME(xpname, xmname, xinstance, xtype, xsubmodule) \
753         xpname " " xmname " " #xinstance " " xtype " " xsubmodule
754
755 /*
756  * 3 Controls for each Gain module
757  * e.g. - pcm0_in Gain 0 Volume
758  *      - pcm0_in Gain 0 Ramp Delay
759  *      - pcm0_in Gain 0 Switch
760  */
761 #define SST_GAIN_KCONTROLS(xpname, xmname, xmin_gain, xmax_gain, xmin_tc, xmax_tc, \
762                            xhandler_get, xhandler_put, \
763                            xmod, xpipe, xinstance, xtask, tlv_array, xgain_val) \
764         { SST_GAIN_KCONTROL_INT(SST_CONTROL_NAME(xpname, xmname, xinstance, "Ramp Delay"), \
765                 xhandler_get, xhandler_put, xmod, xpipe, xinstance, xtask, SST_GAIN_RAMP_DURATION, \
766                 xgain_val, xmin_tc, xmax_tc, xpname) }, \
767         { SST_GAIN_KCONTROL_BOOL(SST_CONTROL_NAME(xpname, xmname, xinstance, "Switch"), \
768                 xhandler_get, xhandler_put, xmod, xpipe, xinstance, xtask, \
769                 xgain_val, xpname) } ,\
770         { SST_GAIN_KCONTROL_TLV(SST_CONTROL_NAME(xpname, xmname, xinstance, "Volume"), \
771                 xhandler_get, xhandler_put, xmod, xpipe, xinstance, xtask, tlv_array, \
772                 xgain_val, xmin_gain, xmax_gain, xpname) }
773
774 #define SST_GAIN_TC_MIN         5
775 #define SST_GAIN_TC_MAX         5000
776 #define SST_GAIN_MIN_VALUE      -1440 /* in 0.1 DB units */
777 #define SST_GAIN_MAX_VALUE      360
778
779 enum sst_algo_kcontrol_type {
780         SST_ALGO_PARAMS,
781         SST_ALGO_BYPASS,
782 };
783
784 struct sst_algo_control {
785         enum sst_algo_kcontrol_type type;
786         int max;
787         u16 module_id;
788         u16 pipe_id;
789         u16 task_id;
790         u16 cmd_id;
791         bool bypass;
792         unsigned char *params;
793         struct snd_soc_dapm_widget *w;
794 };
795
796 /* size of the control = size of params + size of length field */
797 #define SST_ALGO_CTL_VALUE(xcount, xtype, xpipe, xmod, xtask, xcmd)                     \
798         (struct sst_algo_control){                                                      \
799                 .max = xcount + sizeof(u16), .type = xtype, .module_id = xmod,                  \
800                 .pipe_id = xpipe, .task_id = xtask, .cmd_id = xcmd,                     \
801         }
802
803 #define SST_ALGO_KCONTROL(xname, xcount, xmod, xpipe,                                   \
804                           xtask, xcmd, xtype, xinfo, xget, xput)                        \
805 {       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,                                            \
806         .name =  xname,                                                                 \
807         .info = xinfo, .get = xget, .put = xput,                                        \
808         .private_value = (unsigned long)&                                               \
809                         SST_ALGO_CTL_VALUE(xcount, xtype, xpipe,                        \
810                                            xmod, xtask, xcmd),                          \
811 }
812
813 #define SST_ALGO_KCONTROL_BYTES(xpname, xmname, xcount, xmod,                           \
814                                 xpipe, xinstance, xtask, xcmd)                          \
815         SST_ALGO_KCONTROL(SST_CONTROL_NAME(xpname, xmname, xinstance, "params"),        \
816                           xcount, xmod, xpipe, xtask, xcmd, SST_ALGO_PARAMS,            \
817                           sst_algo_bytes_ctl_info,                                      \
818                           sst_algo_control_get, sst_algo_control_set)
819
820 #define SST_ALGO_KCONTROL_BOOL(xpname, xmname, xmod, xpipe, xinstance, xtask)           \
821         SST_ALGO_KCONTROL(SST_CONTROL_NAME(xpname, xmname, xinstance, "bypass"),        \
822                           0, xmod, xpipe, xtask, 0, SST_ALGO_BYPASS,                    \
823                           snd_soc_info_bool_ext,                                        \
824                           sst_algo_control_get, sst_algo_control_set)
825
826 #define SST_ALGO_BYPASS_PARAMS(xpname, xmname, xcount, xmod, xpipe,                     \
827                                 xinstance, xtask, xcmd)                                 \
828         SST_ALGO_KCONTROL_BOOL(xpname, xmname, xmod, xpipe, xinstance, xtask),          \
829         SST_ALGO_KCONTROL_BYTES(xpname, xmname, xcount, xmod, xpipe, xinstance, xtask, xcmd)
830
831 #define SST_COMBO_ALGO_KCONTROL_BYTES(xpname, xmname, xsubmod, xcount, xmod,            \
832                                       xpipe, xinstance, xtask, xcmd)                    \
833         SST_ALGO_KCONTROL(SST_COMBO_CONTROL_NAME(xpname, xmname, xinstance, "params",   \
834                                                  xsubmod),                              \
835                           xcount, xmod, xpipe, xtask, xcmd, SST_ALGO_PARAMS,            \
836                           sst_algo_bytes_ctl_info,                                      \
837                           sst_algo_control_get, sst_algo_control_set)
838
839
840 struct sst_enum {
841         bool tx;
842         unsigned short reg;
843         unsigned int max;
844         const char * const *texts;
845         struct snd_soc_dapm_widget *w;
846 };
847
848 /* only 4 slots/channels supported atm */
849 #define SST_SSP_SLOT_ENUM(s_ch_no, is_tx, xtexts) \
850         (struct sst_enum){ .reg = s_ch_no, .tx = is_tx, .max = 4+1, .texts = xtexts, }
851
852 #define SST_SLOT_CTL_NAME(xpname, xmname, s_ch_name) \
853         xpname " " xmname " " s_ch_name
854
855 #define SST_SSP_SLOT_CTL(xpname, xmname, s_ch_name, s_ch_no, is_tx, xtexts, xget, xput) \
856 {       .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
857         .name = SST_SLOT_CTL_NAME(xpname, xmname, s_ch_name), \
858         .info = sst_slot_enum_info, \
859         .get = xget, .put = xput, \
860         .private_value = (unsigned long)&SST_SSP_SLOT_ENUM(s_ch_no, is_tx, xtexts), \
861 }
862
863 #define SST_MUX_CTL_NAME(xpname, xinstance) \
864         xpname " " #xinstance
865
866 #define SST_SSP_MUX_ENUM(xreg, xshift, xtexts) \
867         (struct soc_enum) SOC_ENUM_DOUBLE(xreg, xshift, xshift, ARRAY_SIZE(xtexts), xtexts)
868
869 #define SST_SSP_MUX_CTL(xpname, xinstance, xreg, xshift, xtexts) \
870         SOC_DAPM_ENUM(SST_MUX_CTL_NAME(xpname, xinstance), \
871                           SST_SSP_MUX_ENUM(xreg, xshift, xtexts))
872
873 int sst_fill_ssp_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
874                                 unsigned int rx_mask, int slots, int slot_width);
875 int sst_fill_ssp_config(struct snd_soc_dai *dai, unsigned int fmt);
876 void sst_fill_ssp_defaults(struct snd_soc_dai *dai);
877
878 #endif