1 #ifndef __INTEL_SST_COMMON_H__
2 #define __INTEL_SST_COMMON_H__
4 * intel_sst_common.h - Intel SST Driver for audio engine
6 * Copyright (C) 2008-10 Intel Corporation
7 * Authors: Vinod Koul <vinod.koul@intel.com>
8 * Harsha Priya <priya.harsha@intel.com>
9 * Dharageswari R <dharageswari.r@intel.com>
10 * KP Jeeja <jeeja.kp@intel.com>
11 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; version 2 of the License.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 * Common private declarations for SST
31 #define SST_DRIVER_VERSION "1.2.17"
32 #define SST_VERSION_NUM 0x1217
35 #define SST_DRV_NAME "intel_sst_driver"
36 #define SST_MRST_PCI_ID 0x080A
37 #define SST_MFLD_PCI_ID 0x082F
38 #define PCI_ID_LENGTH 4
39 #define SST_SUSPEND_DELAY 2000
40 #define FW_CONTEXT_MEM (64*1024)
50 #define MAX_ACTIVE_STREAM 3
51 #define MAX_ENC_STREAM 1
52 #define MAX_AM_HANDLES 1
53 #define ALLOC_TIMEOUT 5000
55 #define SST_BLOCK_TIMEOUT 5000
56 #define TARGET_DEV_BLOCK_TIMEOUT 5000
58 #define BLOCK_UNINIT -1
59 #define RX_TIMESLOT_UNINIT -1
61 /* SST register map */
67 #define SST_IPCX 0x38 /* IPC IA-SST */
68 #define SST_IPCD 0x40 /* IPC SST-IA */
69 #define SST_ISRD 0x20 /* dummy register for shim workaround */
70 #define SST_SHIM_SIZE 0X44
72 #define SPI_MODE_ENABLE_BASE_ADDR 0xffae4000
73 #define FW_SIGNATURE_SIZE 4
75 /* PMIC and SST hardware states */
82 enum sst_stream_states {
83 STREAM_UN_INIT = 0, /* Freed/Not used stream */
84 STREAM_RUNNING = 1, /* Running */
85 STREAM_PAUSED = 2, /* Paused stream */
86 STREAM_DECODE = 3, /* stream is in decoding only state */
87 STREAM_INIT = 4, /* stream init, waiting for data */
95 /* SST shim registers to structure mapping */
96 union config_status_reg {
111 union interrupt_reg {
113 u32 done_interrupt:1;
114 u32 busy_interrupt:1;
148 struct sst_stream_bufs {
149 struct list_head node;
157 struct snd_sst_user_cap_list {
158 unsigned int iov_index; /* index of iov */
159 unsigned long iov_offset; /* offset in iov */
160 unsigned long offset; /* offset in kmem */
161 unsigned long size; /* size copied */
162 struct list_head node;
165 This structure is used to block a user/fw data call to another
169 bool condition; /* condition for blocking check */
170 int ret_code; /* ret code when block is released */
171 void *data; /* data to be appsed for block if any */
175 enum snd_sst_buf_type {
176 SST_BUF_USER_STATIC = 1,
177 SST_BUF_USER_DYNAMIC,
179 SST_BUF_MMAP_DYNAMIC,
188 * struct stream_info - structure that holds the stream information
190 * @status : stream current state
191 * @prev : stream prev state
192 * @codec : stream codec
193 * @sst_id : stream id
194 * @ops : stream operation pb/cp/drm...
195 * @bufs: stream buffer list
196 * @lock : stream mutex for protecting state
197 * @pcm_lock : spinlock for pcm path only
198 * @mmapped : is stream mmapped
199 * @sg_index : current stream user buffer index
200 * @cur_ptr : stream user buffer pointer
201 * @buf_entry : current user buffer
202 * @data_blk : stream block for data operations
203 * @ctrl_blk : stream block for ctrl operations
204 * @buf_type : stream user buffer type
205 * @pcm_substream : PCM substream
206 * @period_elapsed : PCM period elapsed callback
207 * @sfreq : stream sampling freq
208 * @decode_ibuf : Decoded i/p buffers pointer
209 * @decode_obuf : Decoded o/p buffers pointer
210 * @decode_isize : Decoded i/p buffers size
211 * @decode_osize : Decoded o/p buffers size
212 * @decode_ibuf_type : Decoded i/p buffer type
213 * @decode_obuf_type : Decoded o/p buffer type
214 * @idecode_alloc : Decode alloc index
215 * @need_draining : stream set for drain
216 * @str_type : stream type
217 * @curr_bytes : current bytes decoded
218 * @cumm_bytes : cummulative bytes decoded
219 * @str_type : stream type
220 * @src : stream source
221 * @device : output device type (medfield only)
222 * @pcm_slot : pcm slot value
230 struct list_head bufs;
231 struct mutex lock; /* mutex */
234 unsigned int sg_index; /* current buf Index */
235 unsigned char __user *cur_ptr; /* Current static bufs */
236 struct snd_sst_buf_entry __user *buf_entry;
237 struct sst_block data_blk; /* stream ops block */
238 struct sst_block ctrl_blk; /* stream control cmd block */
239 enum snd_sst_buf_type buf_type;
241 void (*period_elapsed) (void *pcm_substream);
243 void *decode_ibuf, *decode_obuf;
244 unsigned int decode_isize, decode_osize;
245 u8 decode_ibuf_type, decode_obuf_type;
246 unsigned int idecode_alloc;
247 unsigned int need_draining;
248 unsigned int str_type;
252 enum snd_sst_audio_device_type device;
257 * struct stream_alloc_bloc - this structure is used for blocking the user's
258 * alloc calls to fw's response to alloc calls
260 * @sst_id : session id of blocked stream
261 * @ops_block : ops block struture
263 struct stream_alloc_block {
264 int sst_id; /* session id of blocked stream */
265 struct sst_block ops_block; /* ops block struture */
268 #define SST_FW_SIGN "$SST"
269 #define SST_FW_LIB_SIGN "$LIB"
272 * struct fw_header - FW file headers
274 * @signature : FW signature
275 * @modules : # of modules
276 * @file_format : version of header format
277 * @reserved : reserved fields
280 unsigned char signature[FW_SIGNATURE_SIZE]; /* FW signature */
281 u32 file_size; /* size of fw minus this header */
282 u32 modules; /* # of modules */
283 u32 file_format; /* version of header format */
287 struct fw_module_header {
288 unsigned char signature[FW_SIGNATURE_SIZE]; /* module signature */
289 u32 mod_size; /* size of module */
290 u32 blocks; /* # of blocks */
291 u32 type; /* codec type, pp lib */
295 struct dma_block_info {
296 enum sst_ram_type type; /* IRAM/DRAM */
297 u32 size; /* Bytes */
298 u32 ram_offset; /* Offset in I/DRAM */
299 u32 rsvd; /* Reserved field */
302 struct ioctl_pvt_data {
307 struct sst_ipc_msg_wq {
308 union ipc_header header;
309 char mailbox[SST_MAILBOX_SIZE];
310 struct work_struct wq;
315 enum sst_controls control_op;
316 struct work_struct wq;
320 #define SST_MMAP_PAGES (640*1024 / PAGE_SIZE)
321 #define SST_MMAP_STEP (40*1024 / PAGE_SIZE)
324 * struct intel_sst_drv - driver ops
326 * @pmic_state : pmic state
327 * @pmic_vendor : pmic vendor detected
328 * @sst_state : current sst device state
329 * @pci_id : PCI device id loaded
330 * @shim : SST shim pointer
331 * @mailbox : SST mailbox pointer
332 * @iram : SST IRAM pointer
333 * @dram : SST DRAM pointer
334 * @shim_phy_add : SST shim phy addr
335 * @ipc_dispatch_list : ipc messages dispatched
336 * @ipc_post_msg_wq : wq to post IPC messages context
337 * @ipc_process_msg : wq to process msgs from FW context
338 * @ipc_process_reply : wq to process reply from FW context
339 * @ipc_post_msg : wq to post reply from FW context
340 * @mad_ops : MAD driver operations registered
341 * @mad_wq : MAD driver wq
342 * @post_msg_wq : wq to post IPC messages
343 * @process_msg_wq : wq to process msgs from FW
344 * @process_reply_wq : wq to process reply from FW
345 * @streams : sst stream contexts
346 * @alloc_block : block structure for alloc
347 * @tgt_dev_blk : block structure for target device
348 * @fw_info_blk : block structure for fw info block
349 * @vol_info_blk : block structure for vol info block
350 * @mute_info_blk : block structure for mute info block
351 * @hs_info_blk : block structure for hs info block
352 * @list_lock : sst driver list lock (deprecated)
353 * @list_spin_lock : sst driver spin lock block
354 * @scard_ops : sst card ops
355 * @pci : sst pci device struture
356 * @active_streams : sst active streams
357 * @sst_lock : sst device lock
358 * @stream_lock : sst stream lock
359 * @unique_id : sst unique id
360 * @stream_cnt : total sst active stream count
361 * @pb_streams : total active pb streams
362 * @cp_streams : total active cp streams
363 * @lpe_stalled : lpe stall status
364 * @pmic_port_instance : active pmic port instance
365 * @rx_time_slot_status : active rx slot
366 * @lpaudio_start : lpaudio status
367 * @audio_start : audio status
368 * @devt_d : pointer to /dev/lpe node
369 * @devt_c : pointer to /dev/lpe_ctrl node
370 * @max_streams : max streams allowed
372 struct intel_sst_drv {
378 void __iomem *mailbox;
381 unsigned int shim_phy_add;
382 struct list_head ipc_dispatch_list;
383 struct work_struct ipc_post_msg_wq;
384 struct sst_ipc_msg_wq ipc_process_msg;
385 struct sst_ipc_msg_wq ipc_process_reply;
386 struct sst_ipc_msg_wq ipc_post_msg;
387 struct mad_ops_wq mad_ops;
388 wait_queue_head_t wait_queue;
389 struct workqueue_struct *mad_wq;
390 struct workqueue_struct *post_msg_wq;
391 struct workqueue_struct *process_msg_wq;
392 struct workqueue_struct *process_reply_wq;
394 struct stream_info streams[MAX_NUM_STREAMS];
395 struct stream_alloc_block alloc_block[MAX_ACTIVE_STREAM];
396 struct sst_block tgt_dev_blk, fw_info_blk, ppp_params_blk,
397 vol_info_blk, mute_info_blk, hs_info_blk;
398 struct mutex list_lock;/* mutex for IPC list locking */
399 spinlock_t list_spin_lock; /* mutex for IPC list locking */
400 struct snd_pmic_ops *scard_ops;
402 int active_streams[MAX_NUM_STREAMS];
404 struct mutex sst_lock;
405 struct mutex stream_lock;
406 unsigned int mmap_len;
407 unsigned int unique_id;
408 unsigned int stream_cnt; /* total streams */
409 unsigned int encoded_cnt; /* enocded streams only */
411 unsigned int pb_streams; /* pb streams active */
412 unsigned int cp_streams; /* cp streams active */
413 unsigned int lpe_stalled; /* LPE is stalled or not */
414 unsigned int pmic_port_instance; /*pmic port instance*/
415 int rx_time_slot_status;
416 unsigned int lpaudio_start;
417 /* 1 - LPA stream(MP3 pb) in progress*/
418 unsigned int audio_start;
419 dev_t devt_d, devt_c;
420 unsigned int max_streams;
421 unsigned int *fw_cntx;
422 unsigned int fw_cntx_size;
424 unsigned int fw_downloaded;
427 extern struct intel_sst_drv *sst_drv_ctx;
429 #define CHIP_REV_REG 0xff108000
430 #define CHIP_REV_ADDR 0x78
432 /* misc definitions */
433 #define FW_DWNL_ID 0xFF
434 #define LOOP1 0x11111111
435 #define LOOP2 0x22222222
436 #define LOOP3 0x33333333
437 #define LOOP4 0x44444444
439 #define SST_DEFAULT_PMIC_PORT 1 /*audio port*/
440 /* NOTE: status will have +ve for good cases and -ve for error ones */
441 #define MAX_STREAM_FIELD 255
443 int sst_alloc_stream(char *params, unsigned int stream_ops, u8 codec,
444 unsigned int session_id);
445 int sst_alloc_stream_response(unsigned int str_id,
446 struct snd_sst_alloc_response *response);
447 int sst_stalled(void);
448 int sst_pause_stream(int id);
449 int sst_resume_stream(int id);
450 int sst_enable_rx_timeslot(int status);
451 int sst_drop_stream(int id);
452 int sst_free_stream(int id);
453 int sst_start_stream(int streamID);
454 int sst_play_frame(int streamID);
455 int sst_pcm_play_frame(int str_id, struct sst_stream_bufs *sst_buf);
456 int sst_capture_frame(int streamID);
457 int sst_set_stream_param(int streamID, struct snd_sst_params *str_param);
458 int sst_target_device_select(struct snd_sst_target_device *target_device);
459 int sst_decode(int str_id, struct snd_sst_dbufs *dbufs);
460 int sst_get_decoded_bytes(int str_id, unsigned long long *bytes);
461 int sst_get_fw_info(struct snd_sst_fw_info *info);
462 int sst_get_stream_params(int str_id,
463 struct snd_sst_get_stream_params *get_params);
464 int sst_get_stream(struct snd_sst_params *str_param);
465 int sst_get_stream_allocated(struct snd_sst_params *str_param,
466 struct snd_sst_lib_download **lib_dnld);
467 int sst_drain_stream(int str_id);
468 int sst_get_vol(struct snd_sst_vol *set_vol);
469 int sst_set_vol(struct snd_sst_vol *set_vol);
470 int sst_set_mute(struct snd_sst_mute *set_mute);
473 void sst_post_message(struct work_struct *work);
474 void sst_process_message(struct work_struct *work);
475 void sst_process_reply(struct work_struct *work);
476 void sst_process_mad_ops(struct work_struct *work);
477 void sst_process_mad_jack_detection(struct work_struct *work);
479 long intel_sst_ioctl(struct file *file_ptr, unsigned int cmd,
481 int intel_sst_open(struct inode *i_node, struct file *file_ptr);
482 int intel_sst_open_cntrl(struct inode *i_node, struct file *file_ptr);
483 int intel_sst_release(struct inode *i_node, struct file *file_ptr);
484 int intel_sst_release_cntrl(struct inode *i_node, struct file *file_ptr);
485 int intel_sst_read(struct file *file_ptr, char __user *buf,
486 size_t count, loff_t *ppos);
487 int intel_sst_write(struct file *file_ptr, const char __user *buf,
488 size_t count, loff_t *ppos);
489 int intel_sst_mmap(struct file *fp, struct vm_area_struct *vma);
490 ssize_t intel_sst_aio_write(struct kiocb *kiocb, const struct iovec *iov,
491 unsigned long nr_segs, loff_t offset);
492 ssize_t intel_sst_aio_read(struct kiocb *kiocb, const struct iovec *iov,
493 unsigned long nr_segs, loff_t offset);
495 int sst_load_fw(const struct firmware *fw, void *context);
496 int sst_load_library(struct snd_sst_lib_download *lib, u8 ops);
497 int sst_spi_mode_enable(void);
498 int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx);
500 int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
501 struct sst_block *block);
502 int sst_wait_interruptible_timeout(struct intel_sst_drv *sst_drv_ctx,
503 struct sst_block *block, int timeout);
504 int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx,
505 struct stream_alloc_block *block);
506 int sst_create_large_msg(struct ipc_post **arg);
507 int sst_create_short_msg(struct ipc_post **arg);
508 void sst_wake_up_alloc_block(struct intel_sst_drv *sst_drv_ctx,
509 u8 sst_id, int status, void *data);
510 void sst_clear_interrupt(void);
511 int intel_sst_resume(struct pci_dev *pci);
512 int sst_download_fw(void);
513 void free_stream_context(unsigned int str_id);
514 void sst_clean_stream(struct stream_info *stream);
517 * sst_fill_header - inline to fill sst header
519 * @header : ipc header
520 * @msg : IPC message to be sent
521 * @large : is ipc large msg
522 * @str_id : stream id
524 * this function is an inline function that sets the headers before
527 static inline void sst_fill_header(union ipc_header *header,
528 int msg, int large, int str_id)
530 header->part.msg_id = msg;
531 header->part.str_id = str_id;
532 header->part.large = large;
533 header->part.done = 0;
534 header->part.busy = 1;
535 header->part.data = 0;
539 * sst_assign_pvt_id - assign a pvt id for stream
541 * @sst_drv_ctx : driver context
543 * this inline function assigns a private id for calls that dont have stream
544 * context yet, should be called with lock held
546 static inline unsigned int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx)
548 sst_drv_ctx->unique_id++;
549 if (sst_drv_ctx->unique_id >= MAX_NUM_STREAMS)
550 sst_drv_ctx->unique_id = 1;
551 return sst_drv_ctx->unique_id;
555 * sst_init_stream - this function initialzes stream context
557 * @stream : stream struture
558 * @codec : codec for stream
559 * @sst_id : stream id
560 * @ops : stream operation
561 * @slot : stream pcm slot
562 * @device : device type
564 * this inline function initialzes stream context for allocated stream
566 static inline void sst_init_stream(struct stream_info *stream,
567 int codec, int sst_id, int ops, u8 slot,
568 enum snd_sst_audio_device_type device)
570 stream->status = STREAM_INIT;
571 stream->prev = STREAM_UN_INIT;
572 stream->codec = codec;
573 stream->sst_id = sst_id;
574 stream->str_type = 0;
576 stream->data_blk.on = false;
577 stream->data_blk.condition = false;
578 stream->data_blk.ret_code = 0;
579 stream->data_blk.data = NULL;
580 stream->ctrl_blk.on = false;
581 stream->ctrl_blk.condition = false;
582 stream->ctrl_blk.ret_code = 0;
583 stream->ctrl_blk.data = NULL;
584 stream->need_draining = false;
585 stream->decode_ibuf = NULL;
586 stream->decode_isize = 0;
587 stream->mmapped = false;
588 stream->pcm_slot = slot;
589 stream->device = device;
594 * sst_validate_strid - this function validates the stream id
596 * @str_id : stream id to be validated
598 * returns 0 if valid stream
600 static inline int sst_validate_strid(int str_id)
602 if (str_id <= 0 || str_id > sst_drv_ctx->max_streams) {
603 pr_err("SST ERR: invalid stream id : %d MAX_STREAMS:%d\n",
604 str_id, sst_drv_ctx->max_streams);
610 static inline int sst_shim_write(void __iomem *addr, int offset, int value)
613 if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID)
614 writel(value, addr + SST_ISRD); /*dummy*/
615 writel(value, addr + offset);
619 static inline int sst_shim_read(void __iomem *addr, int offset)
621 return readl(addr + offset);
623 #endif /* __INTEL_SST_COMMON_H__ */