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