]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - sound/soc/intel/sst/sst.h
ASoC: Intel: mrfld- add ACPI module
[mirror_ubuntu-bionic-kernel.git] / sound / soc / intel / sst / sst.h
1 /*
2 * sst.h - Intel SST Driver for audio engine
3 *
4 * Copyright (C) 2008-14 Intel Corporation
5 * Authors: Vinod Koul <vinod.koul@intel.com>
6 * Harsha Priya <priya.harsha@intel.com>
7 * Dharageswari R <dharageswari.r@intel.com>
8 * KP Jeeja <jeeja.kp@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 *
22 * Common private declarations for SST
23 */
24 #ifndef __SST_H__
25 #define __SST_H__
26
27 #include <linux/firmware.h>
28
29 /* driver names */
30 #define SST_DRV_NAME "intel_sst_driver"
31 #define SST_MRFLD_PCI_ID 0x119A
32 #define SST_BYT_ACPI_ID 0x80860F28
33
34 #define SST_SUSPEND_DELAY 2000
35 #define FW_CONTEXT_MEM (64*1024)
36 #define SST_ICCM_BOUNDARY 4
37 #define SST_CONFIG_SSP_SIGN 0x7ffe8001
38
39 #define MRFLD_FW_VIRTUAL_BASE 0xC0000000
40 #define MRFLD_FW_DDR_BASE_OFFSET 0x0
41 #define MRFLD_FW_FEATURE_BASE_OFFSET 0x4
42 #define MRFLD_FW_BSS_RESET_BIT 0
43
44 extern const struct dev_pm_ops intel_sst_pm;
45 enum sst_states {
46 SST_FW_LOADING = 1,
47 SST_FW_RUNNING,
48 SST_RESET,
49 SST_SHUTDOWN,
50 };
51
52 enum sst_algo_ops {
53 SST_SET_ALGO = 0,
54 SST_GET_ALGO = 1,
55 };
56
57 #define SST_BLOCK_TIMEOUT 1000
58
59 #define FW_SIGNATURE_SIZE 4
60
61 /* stream states */
62 enum sst_stream_states {
63 STREAM_UN_INIT = 0, /* Freed/Not used stream */
64 STREAM_RUNNING = 1, /* Running */
65 STREAM_PAUSED = 2, /* Paused stream */
66 STREAM_DECODE = 3, /* stream is in decoding only state */
67 STREAM_INIT = 4, /* stream init, waiting for data */
68 STREAM_RESET = 5, /* force reset on recovery */
69 };
70
71 enum sst_ram_type {
72 SST_IRAM = 1,
73 SST_DRAM = 2,
74 SST_DDR = 5,
75 SST_CUSTOM_INFO = 7, /* consists of FW binary information */
76 };
77
78 /* SST shim registers to structure mapping */
79 union interrupt_reg {
80 struct {
81 u64 done_interrupt:1;
82 u64 busy_interrupt:1;
83 u64 rsvd:62;
84 } part;
85 u64 full;
86 };
87
88 union sst_pisr_reg {
89 struct {
90 u32 pssp0:1;
91 u32 pssp1:1;
92 u32 rsvd0:3;
93 u32 dmac:1;
94 u32 rsvd1:26;
95 } part;
96 u32 full;
97 };
98
99 union sst_pimr_reg {
100 struct {
101 u32 ssp0:1;
102 u32 ssp1:1;
103 u32 rsvd0:3;
104 u32 dmac:1;
105 u32 rsvd1:10;
106 u32 ssp0_sc:1;
107 u32 ssp1_sc:1;
108 u32 rsvd2:3;
109 u32 dmac_sc:1;
110 u32 rsvd3:10;
111 } part;
112 u32 full;
113 };
114
115 union config_status_reg_mrfld {
116 struct {
117 u64 lpe_reset:1;
118 u64 lpe_reset_vector:1;
119 u64 runstall:1;
120 u64 pwaitmode:1;
121 u64 clk_sel:3;
122 u64 rsvd2:1;
123 u64 sst_clk:3;
124 u64 xt_snoop:1;
125 u64 rsvd3:4;
126 u64 clk_sel1:6;
127 u64 clk_enable:3;
128 u64 rsvd4:6;
129 u64 slim0baseclk:1;
130 u64 rsvd:32;
131 } part;
132 u64 full;
133 };
134
135 union interrupt_reg_mrfld {
136 struct {
137 u64 done_interrupt:1;
138 u64 busy_interrupt:1;
139 u64 rsvd:62;
140 } part;
141 u64 full;
142 };
143
144 union sst_imr_reg_mrfld {
145 struct {
146 u64 done_interrupt:1;
147 u64 busy_interrupt:1;
148 u64 rsvd:62;
149 } part;
150 u64 full;
151 };
152
153 /**
154 * struct sst_block - This structure is used to block a user/fw data call to another
155 * fw/user call
156 *
157 * @condition: condition for blocking check
158 * @ret_code: ret code when block is released
159 * @data: data ptr
160 * @size: size of data
161 * @on: block condition
162 * @msg_id: msg_id = msgid in mfld/ctp, mrfld = NULL
163 * @drv_id: str_id in mfld/ctp, = drv_id in mrfld
164 * @node: list head node
165 */
166 struct sst_block {
167 bool condition;
168 int ret_code;
169 void *data;
170 u32 size;
171 bool on;
172 u32 msg_id;
173 u32 drv_id;
174 struct list_head node;
175 };
176
177 /**
178 * struct stream_info - structure that holds the stream information
179 *
180 * @status : stream current state
181 * @prev : stream prev state
182 * @ops : stream operation pb/cp/drm...
183 * @bufs: stream buffer list
184 * @lock : stream mutex for protecting state
185 * @pcm_substream : PCM substream
186 * @period_elapsed : PCM period elapsed callback
187 * @sfreq : stream sampling freq
188 * @str_type : stream type
189 * @cumm_bytes : cummulative bytes decoded
190 * @str_type : stream type
191 * @src : stream source
192 */
193 struct stream_info {
194 unsigned int status;
195 unsigned int prev;
196 unsigned int ops;
197 struct mutex lock;
198
199 void *pcm_substream;
200 void (*period_elapsed)(void *pcm_substream);
201
202 unsigned int sfreq;
203 u32 cumm_bytes;
204
205 void *compr_cb_param;
206 void (*compr_cb)(void *compr_cb_param);
207
208 void *drain_cb_param;
209 void (*drain_notify)(void *drain_cb_param);
210
211 unsigned int num_ch;
212 unsigned int pipe_id;
213 unsigned int str_id;
214 unsigned int task_id;
215 };
216
217 #define SST_FW_SIGN "$SST"
218 #define SST_FW_LIB_SIGN "$LIB"
219
220 /**
221 * struct sst_fw_header - FW file headers
222 *
223 * @signature : FW signature
224 * @file_size: size of fw image
225 * @modules : # of modules
226 * @file_format : version of header format
227 * @reserved : reserved fields
228 */
229 struct sst_fw_header {
230 unsigned char signature[FW_SIGNATURE_SIZE];
231 u32 file_size;
232 u32 modules;
233 u32 file_format;
234 u32 reserved[4];
235 };
236
237 /**
238 * struct fw_module_header - module header in FW
239 *
240 * @signature: module signature
241 * @mod_size: size of module
242 * @blocks: block count
243 * @type: block type
244 * @entry_point: module netry point
245 */
246 struct fw_module_header {
247 unsigned char signature[FW_SIGNATURE_SIZE];
248 u32 mod_size;
249 u32 blocks;
250 u32 type;
251 u32 entry_point;
252 };
253
254 /**
255 * struct fw_block_info - block header for FW
256 *
257 * @type: block ram type I/D
258 * @size: size of block
259 * @ram_offset: offset in ram
260 */
261 struct fw_block_info {
262 enum sst_ram_type type;
263 u32 size;
264 u32 ram_offset;
265 u32 rsvd;
266 };
267
268 struct sst_runtime_param {
269 struct snd_sst_runtime_params param;
270 };
271
272 struct sst_sg_list {
273 struct scatterlist *src;
274 struct scatterlist *dst;
275 int list_len;
276 unsigned int sg_idx;
277 };
278
279 struct sst_memcpy_list {
280 struct list_head memcpylist;
281 void *dstn;
282 const void *src;
283 u32 size;
284 bool is_io;
285 };
286
287 /*Firmware Module Information*/
288 enum sst_lib_dwnld_status {
289 SST_LIB_NOT_FOUND = 0,
290 SST_LIB_FOUND,
291 SST_LIB_DOWNLOADED,
292 };
293
294 struct sst_module_info {
295 const char *name; /*Library name*/
296 u32 id; /*Module ID*/
297 u32 entry_pt; /*Module entry point*/
298 u8 status; /*module status*/
299 u8 rsvd1;
300 u16 rsvd2;
301 };
302
303 /*
304 * Structure for managing the Library Region(1.5MB)
305 * in DDR in Merrifield
306 */
307 struct sst_mem_mgr {
308 phys_addr_t current_base;
309 int avail;
310 unsigned int count;
311 };
312
313 struct sst_ipc_reg {
314 int ipcx;
315 int ipcd;
316 };
317
318 struct sst_shim_regs64 {
319 u64 csr;
320 u64 pisr;
321 u64 pimr;
322 u64 isrx;
323 u64 isrd;
324 u64 imrx;
325 u64 imrd;
326 u64 ipcx;
327 u64 ipcd;
328 u64 isrsc;
329 u64 isrlpesc;
330 u64 imrsc;
331 u64 imrlpesc;
332 u64 ipcsc;
333 u64 ipclpesc;
334 u64 clkctl;
335 u64 csr2;
336 };
337
338 /**
339 * struct intel_sst_drv - driver ops
340 *
341 * @sst_state : current sst device state
342 * @dev_id : device identifier, pci_id for pci devices and acpi_id for acpi
343 * devices
344 * @shim : SST shim pointer
345 * @mailbox : SST mailbox pointer
346 * @iram : SST IRAM pointer
347 * @dram : SST DRAM pointer
348 * @pdata : SST info passed as a part of pci platform data
349 * @shim_phy_add : SST shim phy addr
350 * @shim_regs64: Struct to save shim registers
351 * @ipc_dispatch_list : ipc messages dispatched
352 * @rx_list : to copy the process_reply/process_msg from DSP
353 * @ipc_post_msg_wq : wq to post IPC messages context
354 * @mad_ops : MAD driver operations registered
355 * @mad_wq : MAD driver wq
356 * @post_msg_wq : wq to post IPC messages
357 * @streams : sst stream contexts
358 * @list_lock : sst driver list lock (deprecated)
359 * @ipc_spin_lock : spin lock to handle audio shim access and ipc queue
360 * @block_lock : spin lock to add block to block_list and assign pvt_id
361 * @rx_msg_lock : spin lock to handle the rx messages from the DSP
362 * @scard_ops : sst card ops
363 * @pci : sst pci device struture
364 * @dev : pointer to current device struct
365 * @sst_lock : sst device lock
366 * @pvt_id : sst private id
367 * @stream_cnt : total sst active stream count
368 * @pb_streams : total active pb streams
369 * @cp_streams : total active cp streams
370 * @audio_start : audio status
371 * @qos : PM Qos struct
372 * firmware_name : Firmware / Library name
373 */
374 struct intel_sst_drv {
375 int sst_state;
376 int irq_num;
377 unsigned int dev_id;
378 void __iomem *ddr;
379 void __iomem *shim;
380 void __iomem *mailbox;
381 void __iomem *iram;
382 void __iomem *dram;
383 unsigned int mailbox_add;
384 unsigned int iram_base;
385 unsigned int dram_base;
386 unsigned int shim_phy_add;
387 unsigned int iram_end;
388 unsigned int dram_end;
389 unsigned int ddr_end;
390 unsigned int ddr_base;
391 unsigned int mailbox_recv_offset;
392 struct sst_shim_regs64 *shim_regs64;
393 struct list_head block_list;
394 struct list_head ipc_dispatch_list;
395 struct sst_platform_info *pdata;
396 struct list_head rx_list;
397 struct work_struct ipc_post_msg_wq;
398 wait_queue_head_t wait_queue;
399 struct workqueue_struct *post_msg_wq;
400 unsigned int tstamp;
401 /* str_id 0 is not used */
402 struct stream_info streams[MAX_NUM_STREAMS+1];
403 spinlock_t ipc_spin_lock;
404 spinlock_t block_lock;
405 spinlock_t rx_msg_lock;
406 struct pci_dev *pci;
407 struct device *dev;
408 volatile long unsigned pvt_id;
409 struct mutex sst_lock;
410 unsigned int stream_cnt;
411 unsigned int csr_value;
412 void *fw_in_mem;
413 struct sst_sg_list fw_sg_list, library_list;
414 struct intel_sst_ops *ops;
415 struct sst_info info;
416 struct pm_qos_request *qos;
417 unsigned int use_dma;
418 unsigned int use_lli;
419 atomic_t fw_clear_context;
420 bool lib_dwnld_reqd;
421 struct list_head memcpy_list;
422 struct sst_ipc_reg ipc_reg;
423 struct sst_mem_mgr lib_mem_mgr;
424 /*
425 * Holder for firmware name. Due to async call it needs to be
426 * persistent till worker thread gets called
427 */
428 char firmware_name[20];
429 };
430
431 /* misc definitions */
432 #define FW_DWNL_ID 0x01
433
434 struct intel_sst_ops {
435 irqreturn_t (*interrupt)(int, void *);
436 irqreturn_t (*irq_thread)(int, void *);
437 void (*clear_interrupt)(struct intel_sst_drv *ctx);
438 int (*start)(struct intel_sst_drv *ctx);
439 int (*reset)(struct intel_sst_drv *ctx);
440 void (*process_reply)(struct intel_sst_drv *ctx, struct ipc_post *msg);
441 int (*post_message)(struct intel_sst_drv *ctx,
442 struct ipc_post *msg, bool sync);
443 void (*process_message)(struct ipc_post *msg);
444 void (*set_bypass)(bool set);
445 int (*save_dsp_context)(struct intel_sst_drv *sst);
446 void (*restore_dsp_context)(void);
447 int (*alloc_stream)(struct intel_sst_drv *ctx, void *params);
448 void (*post_download)(struct intel_sst_drv *sst);
449 };
450
451 int sst_pause_stream(struct intel_sst_drv *sst_drv_ctx, int id);
452 int sst_resume_stream(struct intel_sst_drv *sst_drv_ctx, int id);
453 int sst_drop_stream(struct intel_sst_drv *sst_drv_ctx, int id);
454 int sst_free_stream(struct intel_sst_drv *sst_drv_ctx, int id);
455 int sst_start_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
456 int sst_send_byte_stream_mrfld(struct intel_sst_drv *ctx,
457 struct snd_sst_bytes_v2 *sbytes);
458 int sst_set_stream_param(int str_id, struct snd_sst_params *str_param);
459 int sst_set_metadata(int str_id, char *params);
460 int sst_get_stream(struct intel_sst_drv *sst_drv_ctx,
461 struct snd_sst_params *str_param);
462 int sst_get_stream_allocated(struct intel_sst_drv *ctx,
463 struct snd_sst_params *str_param,
464 struct snd_sst_lib_download **lib_dnld);
465 int sst_drain_stream(struct intel_sst_drv *sst_drv_ctx,
466 int str_id, bool partial_drain);
467 int sst_post_message_mrfld(struct intel_sst_drv *ctx,
468 struct ipc_post *msg, bool sync);
469 void sst_process_reply_mrfld(struct intel_sst_drv *ctx, struct ipc_post *msg);
470 int sst_start_mrfld(struct intel_sst_drv *ctx);
471 int intel_sst_reset_dsp_mrfld(struct intel_sst_drv *ctx);
472 void intel_sst_clear_intr_mrfld(struct intel_sst_drv *ctx);
473
474 int sst_load_fw(struct intel_sst_drv *ctx);
475 int sst_load_library(struct snd_sst_lib_download *lib, u8 ops);
476 void sst_post_download_mrfld(struct intel_sst_drv *ctx);
477 int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx);
478 void sst_memcpy_free_resources(struct intel_sst_drv *ctx);
479
480 int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
481 struct sst_block *block);
482 int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx,
483 struct sst_block *block);
484 int sst_create_ipc_msg(struct ipc_post **arg, bool large);
485 int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id);
486 void sst_clean_stream(struct stream_info *stream);
487 int intel_sst_register_compress(struct intel_sst_drv *sst);
488 int intel_sst_remove_compress(struct intel_sst_drv *sst);
489 void sst_cdev_fragment_elapsed(struct intel_sst_drv *ctx, int str_id);
490 int sst_send_sync_msg(int ipc, int str_id);
491 int sst_get_num_channel(struct snd_sst_params *str_param);
492 int sst_get_sfreq(struct snd_sst_params *str_param);
493 int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params);
494 void sst_restore_fw_context(void);
495 struct sst_block *sst_create_block(struct intel_sst_drv *ctx,
496 u32 msg_id, u32 drv_id);
497 int sst_create_block_and_ipc_msg(struct ipc_post **arg, bool large,
498 struct intel_sst_drv *sst_drv_ctx, struct sst_block **block,
499 u32 msg_id, u32 drv_id);
500 int sst_free_block(struct intel_sst_drv *ctx, struct sst_block *freed);
501 int sst_wake_up_block(struct intel_sst_drv *ctx, int result,
502 u32 drv_id, u32 ipc, void *data, u32 size);
503 int sst_request_firmware_async(struct intel_sst_drv *ctx);
504 int sst_driver_ops(struct intel_sst_drv *sst);
505 struct sst_platform_info *sst_get_acpi_driver_data(const char *hid);
506 void sst_firmware_load_cb(const struct firmware *fw, void *context);
507 int sst_prepare_and_post_msg(struct intel_sst_drv *sst,
508 int task_id, int ipc_msg, int cmd_id, int pipe_id,
509 size_t mbox_data_len, const void *mbox_data, void **data,
510 bool large, bool fill_dsp, bool sync, bool response);
511
512 void sst_process_pending_msg(struct work_struct *work);
513 int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx);
514 void sst_init_stream(struct stream_info *stream,
515 int codec, int sst_id, int ops, u8 slot);
516 int sst_validate_strid(struct intel_sst_drv *sst_drv_ctx, int str_id);
517 struct stream_info *get_stream_info(struct intel_sst_drv *sst_drv_ctx,
518 int str_id);
519 int get_stream_id_mrfld(struct intel_sst_drv *sst_drv_ctx,
520 u32 pipe_id);
521 u32 relocate_imr_addr_mrfld(u32 base_addr);
522 void sst_add_to_dispatch_list_and_post(struct intel_sst_drv *sst,
523 struct ipc_post *msg);
524 int sst_pm_runtime_put(struct intel_sst_drv *sst_drv);
525 int sst_shim_write(void __iomem *addr, int offset, int value);
526 u32 sst_shim_read(void __iomem *addr, int offset);
527 u64 sst_reg_read64(void __iomem *addr, int offset);
528 int sst_shim_write64(void __iomem *addr, int offset, u64 value);
529 u64 sst_shim_read64(void __iomem *addr, int offset);
530 void sst_set_fw_state_locked(
531 struct intel_sst_drv *sst_drv_ctx, int sst_state);
532 void sst_fill_header_mrfld(union ipc_header_mrfld *header,
533 int msg, int task_id, int large, int drv_id);
534 void sst_fill_header_dsp(struct ipc_dsp_hdr *dsp, int msg,
535 int pipe_id, int len);
536
537 int sst_register(struct device *);
538 int sst_unregister(struct device *);
539
540 int sst_alloc_drv_context(struct intel_sst_drv **ctx,
541 struct device *dev, unsigned int dev_id);
542 int sst_context_init(struct intel_sst_drv *ctx);
543 void sst_context_cleanup(struct intel_sst_drv *ctx);
544 void sst_configure_runtime_pm(struct intel_sst_drv *ctx);
545 #endif