Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / sound / soc / intel / atom / sst-mfld-dsp.h
1 #ifndef __SST_MFLD_DSP_H__
2 #define __SST_MFLD_DSP_H__
3 /*
4  *  sst_mfld_dsp.h - Intel SST Driver for audio engine
5  *
6  *  Copyright (C) 2008-14 Intel Corporation
7  *  Authors:    Vinod Koul <vinod.koul@linux.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 #define SST_MAX_BIN_BYTES 1024
23
24 #define MAX_DBG_RW_BYTES 80
25 #define MAX_NUM_SCATTER_BUFFERS 8
26 #define MAX_LOOP_BACK_DWORDS 8
27 /* IPC base address and mailbox, timestamp offsets */
28 #define SST_MAILBOX_SIZE 0x0400
29 #define SST_MAILBOX_SEND 0x0000
30 #define SST_TIME_STAMP 0x1800
31 #define SST_TIME_STAMP_MRFLD 0x800
32 #define SST_RESERVED_OFFSET 0x1A00
33 #define SST_SCU_LPE_MAILBOX 0x1000
34 #define SST_LPE_SCU_MAILBOX 0x1400
35 #define SST_SCU_LPE_LOG_BUF (SST_SCU_LPE_MAILBOX+16)
36 #define PROCESS_MSG 0x80
37
38 /* Message ID's for IPC messages */
39 /* Bits B7: SST or IA/SC ; B6-B4: Msg Category; B3-B0: Msg Type */
40
41 /* I2L Firmware/Codec Download msgs */
42 #define IPC_IA_PREP_LIB_DNLD 0x01
43 #define IPC_IA_LIB_DNLD_CMPLT 0x02
44 #define IPC_IA_GET_FW_VERSION 0x04
45 #define IPC_IA_GET_FW_BUILD_INF 0x05
46 #define IPC_IA_GET_FW_INFO 0x06
47 #define IPC_IA_GET_FW_CTXT 0x07
48 #define IPC_IA_SET_FW_CTXT 0x08
49 #define IPC_IA_PREPARE_SHUTDOWN 0x31
50 /* I2L Codec Config/control msgs */
51 #define IPC_PREP_D3 0x10
52 #define IPC_IA_SET_CODEC_PARAMS 0x10
53 #define IPC_IA_GET_CODEC_PARAMS 0x11
54 #define IPC_IA_SET_PPP_PARAMS 0x12
55 #define IPC_IA_GET_PPP_PARAMS 0x13
56 #define IPC_SST_PERIOD_ELAPSED_MRFLD 0xA
57 #define IPC_IA_ALG_PARAMS 0x1A
58 #define IPC_IA_TUNING_PARAMS 0x1B
59 #define IPC_IA_SET_RUNTIME_PARAMS 0x1C
60 #define IPC_IA_SET_PARAMS 0x1
61 #define IPC_IA_GET_PARAMS 0x2
62
63 #define IPC_EFFECTS_CREATE 0xE
64 #define IPC_EFFECTS_DESTROY 0xF
65
66 /* I2L Stream config/control msgs */
67 #define IPC_IA_ALLOC_STREAM_MRFLD 0x2
68 #define IPC_IA_ALLOC_STREAM 0x20 /* Allocate a stream ID */
69 #define IPC_IA_FREE_STREAM_MRFLD 0x03
70 #define IPC_IA_FREE_STREAM 0x21 /* Free the stream ID */
71 #define IPC_IA_SET_STREAM_PARAMS 0x22
72 #define IPC_IA_SET_STREAM_PARAMS_MRFLD 0x12
73 #define IPC_IA_GET_STREAM_PARAMS 0x23
74 #define IPC_IA_PAUSE_STREAM 0x24
75 #define IPC_IA_PAUSE_STREAM_MRFLD 0x4
76 #define IPC_IA_RESUME_STREAM 0x25
77 #define IPC_IA_RESUME_STREAM_MRFLD 0x5
78 #define IPC_IA_DROP_STREAM 0x26
79 #define IPC_IA_DROP_STREAM_MRFLD 0x07
80 #define IPC_IA_DRAIN_STREAM 0x27 /* Short msg with str_id */
81 #define IPC_IA_DRAIN_STREAM_MRFLD 0x8
82 #define IPC_IA_CONTROL_ROUTING 0x29
83 #define IPC_IA_VTSV_UPDATE_MODULES 0x20
84 #define IPC_IA_VTSV_DETECTED 0x21
85
86 #define IPC_IA_START_STREAM_MRFLD 0X06
87 #define IPC_IA_START_STREAM 0x30 /* Short msg with str_id */
88
89 #define IPC_IA_SET_GAIN_MRFLD 0x21
90 /* Debug msgs */
91 #define IPC_IA_DBG_MEM_READ 0x40
92 #define IPC_IA_DBG_MEM_WRITE 0x41
93 #define IPC_IA_DBG_LOOP_BACK 0x42
94 #define IPC_IA_DBG_LOG_ENABLE 0x45
95 #define IPC_IA_DBG_SET_PROBE_PARAMS 0x47
96
97 /* L2I Firmware/Codec Download msgs */
98 #define IPC_IA_FW_INIT_CMPLT 0x81
99 #define IPC_IA_FW_INIT_CMPLT_MRFLD 0x01
100 #define IPC_IA_FW_ASYNC_ERR_MRFLD 0x11
101
102 /* L2I Codec Config/control msgs */
103 #define IPC_SST_FRAGMENT_ELPASED 0x90 /* Request IA more data */
104
105 #define IPC_SST_BUF_UNDER_RUN 0x92 /* PB Under run and stopped */
106 #define IPC_SST_BUF_OVER_RUN 0x93 /* CAP Under run and stopped */
107 #define IPC_SST_DRAIN_END 0x94 /* PB Drain complete and stopped */
108 #define IPC_SST_CHNGE_SSP_PARAMS 0x95 /* PB SSP parameters changed */
109 #define IPC_SST_STREAM_PROCESS_FATAL_ERR 0x96/* error in processing a stream */
110 #define IPC_SST_PERIOD_ELAPSED 0x97 /* period elapsed */
111
112 #define IPC_SST_ERROR_EVENT 0x99 /* Buffer over run occurred */
113 /* L2S messages */
114 #define IPC_SC_DDR_LINK_UP 0xC0
115 #define IPC_SC_DDR_LINK_DOWN 0xC1
116 #define IPC_SC_SET_LPECLK_REQ 0xC2
117 #define IPC_SC_SSP_BIT_BANG 0xC3
118
119 /* L2I Error reporting msgs */
120 #define IPC_IA_MEM_ALLOC_FAIL 0xE0
121 #define IPC_IA_PROC_ERR 0xE1 /* error in processing a
122                                         stream can be used by playback and
123                                         capture modules */
124
125 /* L2I Debug msgs */
126 #define IPC_IA_PRINT_STRING 0xF0
127
128 /* Buffer under-run */
129 #define IPC_IA_BUF_UNDER_RUN_MRFLD 0x0B
130
131 /* Mrfld specific defines:
132  * For asynchronous messages(INIT_CMPLT, PERIOD_ELAPSED, ASYNC_ERROR)
133  * received from FW, the format is:
134  *  - IPC High: pvt_id is set to zero. Always short message.
135  *  - msg_id is in lower 16-bits of IPC low payload.
136  *  - pipe_id is in higher 16-bits of IPC low payload for period_elapsed.
137  *  - error id is in higher 16-bits of IPC low payload for async errors.
138  */
139 #define SST_ASYNC_DRV_ID 0
140
141 /* Command Response or Acknowledge message to any IPC message will have
142  * same message ID and stream ID information which is sent.
143  * There is no specific Ack message ID. The data field is used as response
144  * meaning.
145  */
146 enum ackData {
147         IPC_ACK_SUCCESS = 0,
148         IPC_ACK_FAILURE,
149 };
150
151 enum ipc_ia_msg_id {
152         IPC_CMD = 1,            /*!< Task Control message ID */
153         IPC_SET_PARAMS = 2,/*!< Task Set param message ID */
154         IPC_GET_PARAMS = 3,     /*!< Task Get param message ID */
155         IPC_INVALID = 0xFF,     /*!<Task Get param message ID */
156 };
157
158 enum sst_codec_types {
159         /*  AUDIO/MUSIC CODEC Type Definitions */
160         SST_CODEC_TYPE_UNKNOWN = 0,
161         SST_CODEC_TYPE_PCM,     /* Pass through Audio codec */
162         SST_CODEC_TYPE_MP3,
163         SST_CODEC_TYPE_MP24,
164         SST_CODEC_TYPE_AAC,
165         SST_CODEC_TYPE_AACP,
166         SST_CODEC_TYPE_eAACP,
167 };
168
169 enum stream_type {
170         SST_STREAM_TYPE_NONE = 0,
171         SST_STREAM_TYPE_MUSIC = 1,
172 };
173
174 enum sst_error_codes {
175         /* Error code,response to msgId: Description */
176         /* Common error codes */
177         SST_SUCCESS = 0,        /* Success */
178         SST_ERR_INVALID_STREAM_ID = 1,
179         SST_ERR_INVALID_MSG_ID = 2,
180         SST_ERR_INVALID_STREAM_OP = 3,
181         SST_ERR_INVALID_PARAMS = 4,
182         SST_ERR_INVALID_CODEC = 5,
183         SST_ERR_INVALID_MEDIA_TYPE = 6,
184         SST_ERR_STREAM_ERR = 7,
185
186         SST_ERR_STREAM_IN_USE = 15,
187 };
188
189 struct ipc_dsp_hdr {
190         u16 mod_index_id:8;             /*!< DSP Command ID specific to tasks */
191         u16 pipe_id:8;  /*!< instance of the module in the pipeline */
192         u16 mod_id;             /*!< Pipe_id */
193         u16 cmd_id;             /*!< Module ID = lpe_algo_types_t */
194         u16 length;             /*!< Length of the payload only */
195 } __packed;
196
197 union ipc_header_high {
198         struct {
199                 u32  msg_id:8;      /* Message ID - Max 256 Message Types */
200                 u32  task_id:4;     /* Task ID associated with this comand */
201                 u32  drv_id:4;    /* Identifier for the driver to track*/
202                 u32  rsvd1:8;       /* Reserved */
203                 u32  result:4;      /* Reserved */
204                 u32  res_rqd:1;     /* Response rqd */
205                 u32  large:1;       /* Large Message if large = 1 */
206                 u32  done:1;        /* bit 30 - Done bit */
207                 u32  busy:1;        /* bit 31 - busy bit*/
208         } part;
209         u32 full;
210 } __packed;
211 /* IPC header */
212 union ipc_header_mrfld {
213         struct {
214                 u32 header_low_payload;
215                 union ipc_header_high header_high;
216         } p;
217         u64 full;
218 } __packed;
219 /* CAUTION NOTE: All IPC message body must be multiple of 32 bits.*/
220
221 /* IPC Header */
222 union ipc_header {
223         struct {
224                 u32  msg_id:8; /* Message ID - Max 256 Message Types */
225                 u32  str_id:5;
226                 u32  large:1;   /* Large Message if large = 1 */
227                 u32  reserved:2;        /* Reserved for future use */
228                 u32  data:14;   /* Ack/Info for msg, size of msg in Mailbox */
229                 u32  done:1; /* bit 30 */
230                 u32  busy:1; /* bit 31 */
231         } part;
232         u32 full;
233 } __packed;
234
235 /* Firmware build info */
236 struct sst_fw_build_info {
237         unsigned char  date[16]; /* Firmware build date */
238         unsigned char  time[16]; /* Firmware build time */
239 } __packed;
240
241 /* Firmware Version info */
242 struct snd_sst_fw_version {
243         u8 build;       /* build number*/
244         u8 minor;       /* minor number*/
245         u8 major;       /* major number*/
246         u8 type;        /* build type */
247 };
248
249 struct ipc_header_fw_init {
250         struct snd_sst_fw_version fw_version;/* Firmware version details */
251         struct sst_fw_build_info build_info;
252         u16 result;     /* Fw init result */
253         u8 module_id; /* Module ID in case of error */
254         u8 debug_info; /* Debug info from Module ID in case of fail */
255 } __packed;
256
257 struct snd_sst_tstamp {
258         u64 ring_buffer_counter;        /* PB/CP: Bytes copied from/to DDR. */
259         u64 hardware_counter;       /* PB/CP: Bytes DMAed to/from SSP. */
260         u64 frames_decoded;
261         u64 bytes_decoded;
262         u64 bytes_copied;
263         u32 sampling_frequency;
264         u32 channel_peak[8];
265 } __packed;
266
267 /* Stream type params struture for Alloc stream */
268 struct snd_sst_str_type {
269         u8 codec_type;          /* Codec type */
270         u8 str_type;            /* 1 = voice 2 = music */
271         u8 operation;           /* Playback or Capture */
272         u8 protected_str;       /* 0=Non DRM, 1=DRM */
273         u8 time_slots;
274         u8 reserved;            /* Reserved */
275         u16 result;             /* Result used for acknowledgment */
276 } __packed;
277
278 /* Library info structure */
279 struct module_info {
280         u32 lib_version;
281         u32 lib_type;/*TBD- KLOCKWORK u8 lib_type;*/
282         u32 media_type;
283         u8  lib_name[12];
284         u32 lib_caps;
285         unsigned char  b_date[16]; /* Lib build date */
286         unsigned char  b_time[16]; /* Lib build time */
287 } __packed;
288
289 /* Library slot info */
290 struct lib_slot_info {
291         u8  slot_num; /* 1 or 2 */
292         u8  reserved1;
293         u16 reserved2;
294         u32 iram_size; /* slot size in IRAM */
295         u32 dram_size; /* slot size in DRAM */
296         u32 iram_offset; /* starting offset of slot in IRAM */
297         u32 dram_offset; /* starting offset of slot in DRAM */
298 } __packed;
299
300 struct snd_ppp_mixer_params {
301         __u32                   type; /*Type of the parameter */
302         __u32                   size;
303         __u32                   input_stream_bitmap; /*Input stream Bit Map*/
304 } __packed;
305
306 struct snd_sst_lib_download {
307         struct module_info lib_info; /* library info type, capabilities etc */
308         struct lib_slot_info slot_info; /* slot info to be downloaded */
309         u32 mod_entry_pt;
310 };
311
312 struct snd_sst_lib_download_info {
313         struct snd_sst_lib_download dload_lib;
314         u16 result;     /* Result used for acknowledgment */
315         u8 pvt_id; /* Private ID */
316         u8 reserved;  /* for alignment */
317 };
318 struct snd_pcm_params {
319         u8 num_chan;    /* 1=Mono, 2=Stereo */
320         u8 pcm_wd_sz;   /* 16/24 - bit*/
321         u8 use_offload_path;    /* 0-PCM using period elpased & ALSA interfaces
322                                    1-PCM stream via compressed interface  */
323         u8 reserved2;
324         u32 sfreq;    /* Sampling rate in Hz */
325         u8 channel_map[8];
326 } __packed;
327
328 /* MP3 Music Parameters Message */
329 struct snd_mp3_params {
330         u8  num_chan;   /* 1=Mono, 2=Stereo     */
331         u8  pcm_wd_sz; /* 16/24 - bit*/
332         u8  crc_check; /* crc_check - disable (0) or enable (1) */
333         u8  reserved1; /* unused*/
334         u16 reserved2;  /* Unused */
335 } __packed;
336
337 #define AAC_BIT_STREAM_ADTS             0
338 #define AAC_BIT_STREAM_ADIF             1
339 #define AAC_BIT_STREAM_RAW              2
340
341 /* AAC Music Parameters Message */
342 struct snd_aac_params {
343         u8 num_chan; /* 1=Mono, 2=Stereo*/
344         u8 pcm_wd_sz; /* 16/24 - bit*/
345         u8 bdownsample; /*SBR downsampling 0 - disable 1 -enabled AAC+ only */
346         u8 bs_format; /* input bit stream format adts=0, adif=1, raw=2 */
347         u16  reser2;
348         u32 externalsr; /*sampling rate of basic AAC raw bit stream*/
349         u8 sbr_signalling;/*disable/enable/set automode the SBR tool.AAC+*/
350         u8 reser1;
351         u16  reser3;
352 } __packed;
353
354 /* WMA Music Parameters Message */
355 struct snd_wma_params {
356         u8  num_chan;   /* 1=Mono, 2=Stereo */
357         u8  pcm_wd_sz;  /* 16/24 - bit*/
358         u16 reserved1;
359         u32 brate;      /* Use the hard coded value. */
360         u32 sfreq;      /* Sampling freq eg. 8000, 441000, 48000 */
361         u32 channel_mask;  /* Channel Mask */
362         u16 format_tag; /* Format Tag */
363         u16 block_align;        /* packet size */
364         u16 wma_encode_opt;/* Encoder option */
365         u8 op_align;    /* op align 0- 16 bit, 1- MSB, 2 LSB */
366         u8 reserved;    /* reserved */
367 } __packed;
368
369 /* Codec params struture */
370 union  snd_sst_codec_params {
371         struct snd_pcm_params pcm_params;
372         struct snd_mp3_params mp3_params;
373         struct snd_aac_params aac_params;
374         struct snd_wma_params wma_params;
375 } __packed;
376
377 /* Address and size info of a frame buffer */
378 struct sst_address_info {
379         u32 addr; /* Address at IA */
380         u32 size; /* Size of the buffer */
381 };
382
383 struct snd_sst_alloc_params_ext {
384         __u16 sg_count;
385         __u16 reserved;
386         __u32 frag_size;        /*Number of samples after which period elapsed
387                                   message is sent valid only if path  = 0*/
388         struct sst_address_info  ring_buf_info[8];
389 };
390
391 struct snd_sst_stream_params {
392         union snd_sst_codec_params uc;
393 } __packed;
394
395 struct snd_sst_params {
396         u32 result;
397         u32 stream_id;
398         u8 codec;
399         u8 ops;
400         u8 stream_type;
401         u8 device_type;
402         u8 task;
403         struct snd_sst_stream_params sparams;
404         struct snd_sst_alloc_params_ext aparams;
405 };
406
407 struct snd_sst_alloc_mrfld {
408         u16 codec_type;
409         u8 operation;
410         u8 sg_count;
411         struct sst_address_info ring_buf_info[8];
412         u32 frag_size;
413         u32 ts;
414         struct snd_sst_stream_params codec_params;
415 } __packed;
416
417 /* Alloc stream params structure */
418 struct snd_sst_alloc_params {
419         struct snd_sst_str_type str_type;
420         struct snd_sst_stream_params stream_params;
421         struct snd_sst_alloc_params_ext alloc_params;
422 } __packed;
423
424 /* Alloc stream response message */
425 struct snd_sst_alloc_response {
426         struct snd_sst_str_type str_type; /* Stream type for allocation */
427         struct snd_sst_lib_download lib_dnld; /* Valid only for codec dnld */
428 };
429
430 /* Drop response */
431 struct snd_sst_drop_response {
432         u32 result;
433         u32 bytes;
434 };
435
436 struct snd_sst_async_msg {
437         u32 msg_id; /* Async msg id */
438         u32 payload[0];
439 };
440
441 struct snd_sst_async_err_msg {
442         u32 fw_resp; /* Firmware Result */
443         u32 lib_resp; /*Library result */
444 } __packed;
445
446 struct snd_sst_vol {
447         u32     stream_id;
448         s32     volume;
449         u32     ramp_duration;
450         u32     ramp_type;              /* Ramp type, default=0 */
451 };
452
453 /* Gain library parameters for mrfld
454  * based on DSP command spec v0.82
455  */
456 struct snd_sst_gain_v2 {
457         u16 gain_cell_num;  /* num of gain cells to modify*/
458         u8 cell_nbr_idx; /* instance index*/
459         u8 cell_path_idx; /* pipe-id */
460         u16 module_id; /*module id */
461         u16 left_cell_gain; /* left gain value in dB*/
462         u16 right_cell_gain; /* right gain value in dB*/
463         u16 gain_time_const; /* gain time constant*/
464 } __packed;
465
466 struct snd_sst_mute {
467         u32     stream_id;
468         u32     mute;
469 };
470
471 struct snd_sst_runtime_params {
472         u8 type;
473         u8 str_id;
474         u8 size;
475         u8 rsvd;
476         void *addr;
477 } __packed;
478
479 enum stream_param_type {
480         SST_SET_TIME_SLOT = 0,
481         SST_SET_CHANNEL_INFO = 1,
482         OTHERS = 2, /*reserved for future params*/
483 };
484
485 /* CSV Voice call routing structure */
486 struct snd_sst_control_routing {
487         u8 control; /* 0=start, 1=Stop */
488         u8 reserved[3]; /* Reserved- for 32 bit alignment */
489 };
490
491 struct ipc_post {
492         struct list_head node;
493         union ipc_header header; /* driver specific */
494         bool is_large;
495         bool is_process_reply;
496         union ipc_header_mrfld mrfld_header;
497         char *mailbox_data;
498 };
499
500 struct snd_sst_ctxt_params {
501         u32 address; /* Physical Address in DDR where the context is stored */
502         u32 size; /* size of the context */
503 };
504
505 struct snd_sst_lpe_log_params {
506         u8 dbg_type;
507         u8 module_id;
508         u8 log_level;
509         u8 reserved;
510 } __packed;
511
512 enum snd_sst_bytes_type {
513         SND_SST_BYTES_SET = 0x1,
514         SND_SST_BYTES_GET = 0x2,
515 };
516
517 struct snd_sst_bytes_v2 {
518         u8 type;
519         u8 ipc_msg;
520         u8 block;
521         u8 task_id;
522         u8 pipe_id;
523         u8 rsvd;
524         u16 len;
525         char bytes[0];
526 };
527
528 #define MAX_VTSV_FILES 2
529 struct snd_sst_vtsv_info {
530         struct sst_address_info vfiles[MAX_VTSV_FILES];
531 } __packed;
532
533 #endif /* __SST_MFLD_DSP_H__ */