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