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