2 * Intel Baytrail SST IPC Support
3 * Copyright (c) 2014, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/list.h>
18 #include <linux/device.h>
19 #include <linux/wait.h>
20 #include <linux/spinlock.h>
21 #include <linux/workqueue.h>
22 #include <linux/export.h>
23 #include <linux/slab.h>
24 #include <linux/delay.h>
25 #include <linux/platform_device.h>
26 #include <linux/kthread.h>
27 #include <linux/firmware.h>
29 #include <asm/div64.h>
31 #include "sst-baytrail-ipc.h"
33 #include "sst-dsp-priv.h"
35 /* IPC message timeout */
36 #define IPC_TIMEOUT_MSECS 300
37 #define IPC_BOOT_MSECS 200
39 #define IPC_EMPTY_LIST_SIZE 8
42 #define IPC_HEADER_MSG_ID_MASK 0xff
43 #define IPC_HEADER_MSG_ID(x) ((x) & IPC_HEADER_MSG_ID_MASK)
44 #define IPC_HEADER_STR_ID_SHIFT 8
45 #define IPC_HEADER_STR_ID_MASK 0x1f
46 #define IPC_HEADER_STR_ID(x) (((x) & 0x1f) << IPC_HEADER_STR_ID_SHIFT)
47 #define IPC_HEADER_LARGE_SHIFT 13
48 #define IPC_HEADER_LARGE(x) (((x) & 0x1) << IPC_HEADER_LARGE_SHIFT)
49 #define IPC_HEADER_DATA_SHIFT 16
50 #define IPC_HEADER_DATA_MASK 0x3fff
51 #define IPC_HEADER_DATA(x) (((x) & 0x3fff) << IPC_HEADER_DATA_SHIFT)
53 /* mask for differentiating between notification and reply message */
54 #define IPC_NOTIFICATION (0x1 << 7)
56 /* I2L Stream config/control msgs */
57 #define IPC_IA_ALLOC_STREAM 0x20
58 #define IPC_IA_FREE_STREAM 0x21
59 #define IPC_IA_PAUSE_STREAM 0x24
60 #define IPC_IA_RESUME_STREAM 0x25
61 #define IPC_IA_DROP_STREAM 0x26
62 #define IPC_IA_START_STREAM 0x30
64 /* notification messages */
65 #define IPC_IA_FW_INIT_CMPLT 0x81
66 #define IPC_SST_PERIOD_ELAPSED 0x97
68 /* IPC messages between host and ADSP */
69 struct sst_byt_address_info
{
74 struct sst_byt_str_type
{
84 struct sst_byt_pcm_params
{
93 struct sst_byt_frames_info
{
97 struct sst_byt_address_info ring_buf_info
[8];
100 struct sst_byt_alloc_params
{
101 struct sst_byt_str_type str_type
;
102 struct sst_byt_pcm_params pcm_params
;
103 struct sst_byt_frames_info frame_info
;
106 struct sst_byt_alloc_response
{
107 struct sst_byt_str_type str_type
;
111 struct sst_byt_start_stream_params
{
115 struct sst_byt_tstamp
{
116 u64 ring_buffer_counter
;
117 u64 hardware_counter
;
121 u32 sampling_frequency
;
125 struct sst_byt_fw_version
{
132 struct sst_byt_fw_build_info
{
137 struct sst_byt_fw_init
{
138 struct sst_byt_fw_version fw_version
;
139 struct sst_byt_fw_build_info build_info
;
145 /* driver internal IPC message structure */
147 struct list_head list
;
150 /* direction wrt host CPU */
151 char tx_data
[SST_BYT_IPC_MAX_PAYLOAD_SIZE
];
153 char rx_data
[SST_BYT_IPC_MAX_PAYLOAD_SIZE
];
156 wait_queue_head_t waitq
;
162 struct sst_byt_stream
;
165 /* stream infomation */
166 struct sst_byt_stream
{
167 struct list_head node
;
170 struct sst_byt_alloc_params request
;
171 struct sst_byt_alloc_response reply
;
179 /* driver callback */
180 u32 (*notify_position
)(struct sst_byt_stream
*stream
, void *data
);
184 /* SST Baytrail IPC data */
190 struct list_head stream_list
;
193 wait_queue_head_t boot_wait
;
198 struct list_head tx_list
;
199 struct list_head rx_list
;
200 struct list_head empty_list
;
201 wait_queue_head_t wait_txq
;
202 struct task_struct
*tx_thread
;
203 struct kthread_worker kworker
;
204 struct kthread_work kwork
;
205 struct ipc_message
*msg
;
208 static inline u64
sst_byt_header(int msg_id
, int data
, bool large
, int str_id
)
212 header
= IPC_HEADER_MSG_ID(msg_id
) |
213 IPC_HEADER_STR_ID(str_id
) |
214 IPC_HEADER_LARGE(large
) |
215 IPC_HEADER_DATA(data
) |
221 static inline u16
sst_byt_header_msg_id(u64 header
)
223 return header
& IPC_HEADER_MSG_ID_MASK
;
226 static inline u8
sst_byt_header_str_id(u64 header
)
228 return (header
>> IPC_HEADER_STR_ID_SHIFT
) & IPC_HEADER_STR_ID_MASK
;
231 static inline u16
sst_byt_header_data(u64 header
)
233 return (header
>> IPC_HEADER_DATA_SHIFT
) & IPC_HEADER_DATA_MASK
;
236 static struct sst_byt_stream
*sst_byt_get_stream(struct sst_byt
*byt
,
239 struct sst_byt_stream
*stream
;
241 list_for_each_entry(stream
, &byt
->stream_list
, node
) {
242 if (stream
->str_id
== stream_id
)
249 static void sst_byt_ipc_shim_dbg(struct sst_byt
*byt
, const char *text
)
251 struct sst_dsp
*sst
= byt
->dsp
;
252 u64 isr
, ipcd
, imrx
, ipcx
;
254 ipcx
= sst_dsp_shim_read64_unlocked(sst
, SST_IPCX
);
255 isr
= sst_dsp_shim_read64_unlocked(sst
, SST_ISRX
);
256 ipcd
= sst_dsp_shim_read64_unlocked(sst
, SST_IPCD
);
257 imrx
= sst_dsp_shim_read64_unlocked(sst
, SST_IMRX
);
260 "ipc: --%s-- ipcx 0x%llx isr 0x%llx ipcd 0x%llx imrx 0x%llx\n",
261 text
, ipcx
, isr
, ipcd
, imrx
);
264 /* locks held by caller */
265 static struct ipc_message
*sst_byt_msg_get_empty(struct sst_byt
*byt
)
267 struct ipc_message
*msg
= NULL
;
269 if (!list_empty(&byt
->empty_list
)) {
270 msg
= list_first_entry(&byt
->empty_list
,
271 struct ipc_message
, list
);
272 list_del(&msg
->list
);
278 static void sst_byt_ipc_tx_msgs(struct kthread_work
*work
)
280 struct sst_byt
*byt
=
281 container_of(work
, struct sst_byt
, kwork
);
282 struct ipc_message
*msg
;
286 spin_lock_irqsave(&byt
->dsp
->spinlock
, flags
);
287 if (list_empty(&byt
->tx_list
)) {
288 spin_unlock_irqrestore(&byt
->dsp
->spinlock
, flags
);
292 /* if the DSP is busy we will TX messages after IRQ */
293 ipcx
= sst_dsp_shim_read64_unlocked(byt
->dsp
, SST_IPCX
);
294 if (ipcx
& SST_BYT_IPCX_BUSY
) {
295 spin_unlock_irqrestore(&byt
->dsp
->spinlock
, flags
);
299 msg
= list_first_entry(&byt
->tx_list
, struct ipc_message
, list
);
301 list_move(&msg
->list
, &byt
->rx_list
);
303 /* send the message */
304 if (msg
->header
& IPC_HEADER_LARGE(true))
305 sst_dsp_outbox_write(byt
->dsp
, msg
->tx_data
, msg
->tx_size
);
306 sst_dsp_shim_write64_unlocked(byt
->dsp
, SST_IPCX
, msg
->header
);
308 spin_unlock_irqrestore(&byt
->dsp
->spinlock
, flags
);
311 static inline void sst_byt_tx_msg_reply_complete(struct sst_byt
*byt
,
312 struct ipc_message
*msg
)
314 msg
->complete
= true;
317 list_add_tail(&msg
->list
, &byt
->empty_list
);
319 wake_up(&msg
->waitq
);
322 static void sst_byt_drop_all(struct sst_byt
*byt
)
324 struct ipc_message
*msg
, *tmp
;
327 /* drop all TX and Rx messages before we stall + reset DSP */
328 spin_lock_irqsave(&byt
->dsp
->spinlock
, flags
);
329 list_for_each_entry_safe(msg
, tmp
, &byt
->tx_list
, list
) {
330 list_move(&msg
->list
, &byt
->empty_list
);
333 list_for_each_entry_safe(msg
, tmp
, &byt
->rx_list
, list
) {
334 list_move(&msg
->list
, &byt
->empty_list
);
337 spin_unlock_irqrestore(&byt
->dsp
->spinlock
, flags
);
340 static int sst_byt_tx_wait_done(struct sst_byt
*byt
, struct ipc_message
*msg
,
346 /* wait for DSP completion */
347 ret
= wait_event_timeout(msg
->waitq
, msg
->complete
,
348 msecs_to_jiffies(IPC_TIMEOUT_MSECS
));
350 spin_lock_irqsave(&byt
->dsp
->spinlock
, flags
);
352 list_del(&msg
->list
);
353 sst_byt_ipc_shim_dbg(byt
, "message timeout");
358 /* copy the data returned from DSP */
360 memcpy(rx_data
, msg
->rx_data
, msg
->rx_size
);
364 list_add_tail(&msg
->list
, &byt
->empty_list
);
365 spin_unlock_irqrestore(&byt
->dsp
->spinlock
, flags
);
369 static int sst_byt_ipc_tx_message(struct sst_byt
*byt
, u64 header
,
370 void *tx_data
, size_t tx_bytes
,
371 void *rx_data
, size_t rx_bytes
, int wait
)
374 struct ipc_message
*msg
;
376 spin_lock_irqsave(&byt
->dsp
->spinlock
, flags
);
378 msg
= sst_byt_msg_get_empty(byt
);
380 spin_unlock_irqrestore(&byt
->dsp
->spinlock
, flags
);
384 msg
->header
= header
;
385 msg
->tx_size
= tx_bytes
;
386 msg
->rx_size
= rx_bytes
;
389 msg
->complete
= false;
392 /* msg content = lower 32-bit of the header + data */
393 *(u32
*)msg
->tx_data
= (u32
)(header
& (u32
)-1);
394 memcpy(msg
->tx_data
+ sizeof(u32
), tx_data
, tx_bytes
);
395 msg
->tx_size
+= sizeof(u32
);
398 list_add_tail(&msg
->list
, &byt
->tx_list
);
399 spin_unlock_irqrestore(&byt
->dsp
->spinlock
, flags
);
401 queue_kthread_work(&byt
->kworker
, &byt
->kwork
);
404 return sst_byt_tx_wait_done(byt
, msg
, rx_data
);
409 static inline int sst_byt_ipc_tx_msg_wait(struct sst_byt
*byt
, u64 header
,
410 void *tx_data
, size_t tx_bytes
,
411 void *rx_data
, size_t rx_bytes
)
413 return sst_byt_ipc_tx_message(byt
, header
, tx_data
, tx_bytes
,
414 rx_data
, rx_bytes
, 1);
417 static inline int sst_byt_ipc_tx_msg_nowait(struct sst_byt
*byt
, u64 header
,
418 void *tx_data
, size_t tx_bytes
)
420 return sst_byt_ipc_tx_message(byt
, header
, tx_data
, tx_bytes
,
424 static struct ipc_message
*sst_byt_reply_find_msg(struct sst_byt
*byt
,
427 struct ipc_message
*msg
= NULL
, *_msg
;
430 /* match reply to message sent based on msg and stream IDs */
431 mask
= IPC_HEADER_MSG_ID_MASK
|
432 IPC_HEADER_STR_ID_MASK
<< IPC_HEADER_STR_ID_SHIFT
;
435 if (list_empty(&byt
->rx_list
)) {
437 "ipc: rx list is empty but received 0x%llx\n", header
);
441 list_for_each_entry(_msg
, &byt
->rx_list
, list
) {
442 if ((_msg
->header
& mask
) == header
) {
452 static void sst_byt_stream_update(struct sst_byt
*byt
, struct ipc_message
*msg
)
454 struct sst_byt_stream
*stream
;
455 u64 header
= msg
->header
;
456 u8 stream_id
= sst_byt_header_str_id(header
);
457 u8 stream_msg
= sst_byt_header_msg_id(header
);
459 stream
= sst_byt_get_stream(byt
, stream_id
);
463 switch (stream_msg
) {
464 case IPC_IA_DROP_STREAM
:
465 case IPC_IA_PAUSE_STREAM
:
466 case IPC_IA_FREE_STREAM
:
467 stream
->running
= false;
469 case IPC_IA_START_STREAM
:
470 case IPC_IA_RESUME_STREAM
:
471 stream
->running
= true;
476 static int sst_byt_process_reply(struct sst_byt
*byt
, u64 header
)
478 struct ipc_message
*msg
;
480 msg
= sst_byt_reply_find_msg(byt
, header
);
484 if (header
& IPC_HEADER_LARGE(true)) {
485 msg
->rx_size
= sst_byt_header_data(header
);
486 sst_dsp_inbox_read(byt
->dsp
, msg
->rx_data
, msg
->rx_size
);
489 /* update any stream states */
490 sst_byt_stream_update(byt
, msg
);
492 list_del(&msg
->list
);
494 sst_byt_tx_msg_reply_complete(byt
, msg
);
499 static void sst_byt_fw_ready(struct sst_byt
*byt
, u64 header
)
501 dev_dbg(byt
->dev
, "ipc: DSP is ready 0x%llX\n", header
);
503 byt
->boot_complete
= true;
504 wake_up(&byt
->boot_wait
);
507 static int sst_byt_process_notification(struct sst_byt
*byt
,
508 unsigned long *flags
)
510 struct sst_dsp
*sst
= byt
->dsp
;
511 struct sst_byt_stream
*stream
;
513 u8 msg_id
, stream_id
;
516 header
= sst_dsp_shim_read64_unlocked(sst
, SST_IPCD
);
517 msg_id
= sst_byt_header_msg_id(header
);
520 case IPC_SST_PERIOD_ELAPSED
:
521 stream_id
= sst_byt_header_str_id(header
);
522 stream
= sst_byt_get_stream(byt
, stream_id
);
523 if (stream
&& stream
->running
&& stream
->notify_position
) {
524 spin_unlock_irqrestore(&sst
->spinlock
, *flags
);
525 stream
->notify_position(stream
, stream
->pdata
);
526 spin_lock_irqsave(&sst
->spinlock
, *flags
);
529 case IPC_IA_FW_INIT_CMPLT
:
530 sst_byt_fw_ready(byt
, header
);
537 static irqreturn_t
sst_byt_irq_thread(int irq
, void *context
)
539 struct sst_dsp
*sst
= (struct sst_dsp
*) context
;
540 struct sst_byt
*byt
= sst_dsp_get_thread_context(sst
);
544 spin_lock_irqsave(&sst
->spinlock
, flags
);
546 header
= sst_dsp_shim_read64_unlocked(sst
, SST_IPCD
);
547 if (header
& SST_BYT_IPCD_BUSY
) {
548 if (header
& IPC_NOTIFICATION
) {
549 /* message from ADSP */
550 sst_byt_process_notification(byt
, &flags
);
552 /* reply from ADSP */
553 sst_byt_process_reply(byt
, header
);
556 * clear IPCD BUSY bit and set DONE bit. Tell DSP we have
557 * processed the message and can accept new. Clear data part
560 sst_dsp_shim_update_bits64_unlocked(sst
, SST_IPCD
,
561 SST_BYT_IPCD_DONE
| SST_BYT_IPCD_BUSY
|
562 IPC_HEADER_DATA(IPC_HEADER_DATA_MASK
),
564 /* unmask message request interrupts */
565 sst_dsp_shim_update_bits64_unlocked(sst
, SST_IMRX
,
566 SST_BYT_IMRX_REQUEST
, 0);
569 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
571 /* continue to send any remaining messages... */
572 queue_kthread_work(&byt
->kworker
, &byt
->kwork
);
578 struct sst_byt_stream
*sst_byt_stream_new(struct sst_byt
*byt
, int id
,
579 u32 (*notify_position
)(struct sst_byt_stream
*stream
, void *data
),
582 struct sst_byt_stream
*stream
;
583 struct sst_dsp
*sst
= byt
->dsp
;
586 stream
= kzalloc(sizeof(*stream
), GFP_KERNEL
);
590 spin_lock_irqsave(&sst
->spinlock
, flags
);
591 list_add(&stream
->node
, &byt
->stream_list
);
592 stream
->notify_position
= notify_position
;
593 stream
->pdata
= data
;
596 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
601 int sst_byt_stream_set_bits(struct sst_byt
*byt
, struct sst_byt_stream
*stream
,
604 stream
->request
.pcm_params
.pcm_wd_sz
= bits
;
608 int sst_byt_stream_set_channels(struct sst_byt
*byt
,
609 struct sst_byt_stream
*stream
, u8 channels
)
611 stream
->request
.pcm_params
.num_chan
= channels
;
615 int sst_byt_stream_set_rate(struct sst_byt
*byt
, struct sst_byt_stream
*stream
,
618 stream
->request
.pcm_params
.sfreq
= rate
;
622 /* stream sonfiguration */
623 int sst_byt_stream_type(struct sst_byt
*byt
, struct sst_byt_stream
*stream
,
624 int codec_type
, int stream_type
, int operation
)
626 stream
->request
.str_type
.codec_type
= codec_type
;
627 stream
->request
.str_type
.str_type
= stream_type
;
628 stream
->request
.str_type
.operation
= operation
;
629 stream
->request
.str_type
.time_slots
= 0xc;
634 int sst_byt_stream_buffer(struct sst_byt
*byt
, struct sst_byt_stream
*stream
,
635 uint32_t buffer_addr
, uint32_t buffer_size
)
637 stream
->request
.frame_info
.num_entries
= 1;
638 stream
->request
.frame_info
.ring_buf_info
[0].addr
= buffer_addr
;
639 stream
->request
.frame_info
.ring_buf_info
[0].size
= buffer_size
;
640 /* calculate bytes per 4 ms fragment */
641 stream
->request
.frame_info
.frag_size
=
642 stream
->request
.pcm_params
.sfreq
*
643 stream
->request
.pcm_params
.num_chan
*
644 stream
->request
.pcm_params
.pcm_wd_sz
/ 8 *
649 int sst_byt_stream_commit(struct sst_byt
*byt
, struct sst_byt_stream
*stream
)
651 struct sst_byt_alloc_params
*str_req
= &stream
->request
;
652 struct sst_byt_alloc_response
*reply
= &stream
->reply
;
656 header
= sst_byt_header(IPC_IA_ALLOC_STREAM
,
657 sizeof(*str_req
) + sizeof(u32
),
658 true, stream
->str_id
);
659 ret
= sst_byt_ipc_tx_msg_wait(byt
, header
, str_req
, sizeof(*str_req
),
660 reply
, sizeof(*reply
));
662 dev_err(byt
->dev
, "ipc: error stream commit failed\n");
666 stream
->commited
= true;
671 int sst_byt_stream_free(struct sst_byt
*byt
, struct sst_byt_stream
*stream
)
675 struct sst_dsp
*sst
= byt
->dsp
;
678 if (!stream
->commited
)
681 header
= sst_byt_header(IPC_IA_FREE_STREAM
, 0, false, stream
->str_id
);
682 ret
= sst_byt_ipc_tx_msg_wait(byt
, header
, NULL
, 0, NULL
, 0);
684 dev_err(byt
->dev
, "ipc: free stream %d failed\n",
689 stream
->commited
= false;
691 spin_lock_irqsave(&sst
->spinlock
, flags
);
692 list_del(&stream
->node
);
694 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
699 static int sst_byt_stream_operations(struct sst_byt
*byt
, int type
,
700 int stream_id
, int wait
)
704 header
= sst_byt_header(type
, 0, false, stream_id
);
706 return sst_byt_ipc_tx_msg_wait(byt
, header
, NULL
, 0, NULL
, 0);
708 return sst_byt_ipc_tx_msg_nowait(byt
, header
, NULL
, 0);
711 /* stream ALSA trigger operations */
712 int sst_byt_stream_start(struct sst_byt
*byt
, struct sst_byt_stream
*stream
,
715 struct sst_byt_start_stream_params start_stream
;
721 start_stream
.byte_offset
= start_offset
;
722 header
= sst_byt_header(IPC_IA_START_STREAM
,
723 sizeof(start_stream
) + sizeof(u32
),
724 true, stream
->str_id
);
725 tx_msg
= &start_stream
;
726 size
= sizeof(start_stream
);
728 ret
= sst_byt_ipc_tx_msg_nowait(byt
, header
, tx_msg
, size
);
730 dev_err(byt
->dev
, "ipc: error failed to start stream %d\n",
736 int sst_byt_stream_stop(struct sst_byt
*byt
, struct sst_byt_stream
*stream
)
740 /* don't stop streams that are not commited */
741 if (!stream
->commited
)
744 ret
= sst_byt_stream_operations(byt
, IPC_IA_DROP_STREAM
,
747 dev_err(byt
->dev
, "ipc: error failed to stop stream %d\n",
752 int sst_byt_stream_pause(struct sst_byt
*byt
, struct sst_byt_stream
*stream
)
756 ret
= sst_byt_stream_operations(byt
, IPC_IA_PAUSE_STREAM
,
759 dev_err(byt
->dev
, "ipc: error failed to pause stream %d\n",
765 int sst_byt_stream_resume(struct sst_byt
*byt
, struct sst_byt_stream
*stream
)
769 ret
= sst_byt_stream_operations(byt
, IPC_IA_RESUME_STREAM
,
772 dev_err(byt
->dev
, "ipc: error failed to resume stream %d\n",
778 int sst_byt_get_dsp_position(struct sst_byt
*byt
,
779 struct sst_byt_stream
*stream
, int buffer_size
)
781 struct sst_dsp
*sst
= byt
->dsp
;
782 struct sst_byt_tstamp fw_tstamp
;
783 u8 str_id
= stream
->str_id
;
786 tstamp_offset
= SST_BYT_TIMESTAMP_OFFSET
+ str_id
* sizeof(fw_tstamp
);
787 memcpy_fromio(&fw_tstamp
,
788 sst
->addr
.lpe
+ tstamp_offset
, sizeof(fw_tstamp
));
790 return do_div(fw_tstamp
.ring_buffer_counter
, buffer_size
);
793 static int msg_empty_list_init(struct sst_byt
*byt
)
795 struct ipc_message
*msg
;
798 byt
->msg
= kzalloc(sizeof(*msg
) * IPC_EMPTY_LIST_SIZE
, GFP_KERNEL
);
799 if (byt
->msg
== NULL
)
802 for (i
= 0; i
< IPC_EMPTY_LIST_SIZE
; i
++) {
803 init_waitqueue_head(&byt
->msg
[i
].waitq
);
804 list_add(&byt
->msg
[i
].list
, &byt
->empty_list
);
810 struct sst_dsp
*sst_byt_get_dsp(struct sst_byt
*byt
)
815 static struct sst_dsp_device byt_dev
= {
816 .thread
= sst_byt_irq_thread
,
820 int sst_byt_dsp_suspend_late(struct device
*dev
, struct sst_pdata
*pdata
)
822 struct sst_byt
*byt
= pdata
->dsp
;
824 dev_dbg(byt
->dev
, "dsp reset\n");
825 sst_dsp_reset(byt
->dsp
);
826 sst_byt_drop_all(byt
);
827 dev_dbg(byt
->dev
, "dsp in reset\n");
829 dev_dbg(byt
->dev
, "free all blocks and unload fw\n");
830 sst_fw_unload(byt
->fw
);
834 EXPORT_SYMBOL_GPL(sst_byt_dsp_suspend_late
);
836 int sst_byt_dsp_boot(struct device
*dev
, struct sst_pdata
*pdata
)
838 struct sst_byt
*byt
= pdata
->dsp
;
841 dev_dbg(byt
->dev
, "reload dsp fw\n");
843 sst_dsp_reset(byt
->dsp
);
845 ret
= sst_fw_reload(byt
->fw
);
847 dev_err(dev
, "error: failed to reload firmware\n");
851 /* wait for DSP boot completion */
852 byt
->boot_complete
= false;
853 sst_dsp_boot(byt
->dsp
);
854 dev_dbg(byt
->dev
, "dsp booting...\n");
858 EXPORT_SYMBOL_GPL(sst_byt_dsp_boot
);
860 int sst_byt_dsp_wait_for_ready(struct device
*dev
, struct sst_pdata
*pdata
)
862 struct sst_byt
*byt
= pdata
->dsp
;
865 dev_dbg(byt
->dev
, "wait for dsp reboot\n");
867 err
= wait_event_timeout(byt
->boot_wait
, byt
->boot_complete
,
868 msecs_to_jiffies(IPC_BOOT_MSECS
));
870 dev_err(byt
->dev
, "ipc: error DSP boot timeout\n");
874 dev_dbg(byt
->dev
, "dsp rebooted\n");
877 EXPORT_SYMBOL_GPL(sst_byt_dsp_wait_for_ready
);
879 int sst_byt_dsp_init(struct device
*dev
, struct sst_pdata
*pdata
)
882 struct sst_fw
*byt_sst_fw
;
883 struct sst_byt_fw_init init
;
886 dev_dbg(dev
, "initialising Byt DSP IPC\n");
888 byt
= devm_kzalloc(dev
, sizeof(*byt
), GFP_KERNEL
);
893 INIT_LIST_HEAD(&byt
->stream_list
);
894 INIT_LIST_HEAD(&byt
->tx_list
);
895 INIT_LIST_HEAD(&byt
->rx_list
);
896 INIT_LIST_HEAD(&byt
->empty_list
);
897 init_waitqueue_head(&byt
->boot_wait
);
898 init_waitqueue_head(&byt
->wait_txq
);
900 err
= msg_empty_list_init(byt
);
904 /* start the IPC message thread */
905 init_kthread_worker(&byt
->kworker
);
906 byt
->tx_thread
= kthread_run(kthread_worker_fn
,
909 if (IS_ERR(byt
->tx_thread
)) {
910 err
= PTR_ERR(byt
->tx_thread
);
911 dev_err(byt
->dev
, "error failed to create message TX task\n");
914 init_kthread_work(&byt
->kwork
, sst_byt_ipc_tx_msgs
);
916 byt_dev
.thread_context
= byt
;
919 byt
->dsp
= sst_dsp_new(dev
, &byt_dev
, pdata
);
920 if (byt
->dsp
== NULL
) {
925 /* keep the DSP in reset state for base FW loading */
926 sst_dsp_reset(byt
->dsp
);
928 byt_sst_fw
= sst_fw_new(byt
->dsp
, pdata
->fw
, byt
);
929 if (byt_sst_fw
== NULL
) {
931 dev_err(dev
, "error: failed to load firmware\n");
935 /* wait for DSP boot completion */
936 sst_dsp_boot(byt
->dsp
);
937 err
= wait_event_timeout(byt
->boot_wait
, byt
->boot_complete
,
938 msecs_to_jiffies(IPC_BOOT_MSECS
));
941 dev_err(byt
->dev
, "ipc: error DSP boot timeout\n");
945 /* show firmware information */
946 sst_dsp_inbox_read(byt
->dsp
, &init
, sizeof(init
));
947 dev_info(byt
->dev
, "FW version: %02x.%02x.%02x.%02x\n",
948 init
.fw_version
.major
, init
.fw_version
.minor
,
949 init
.fw_version
.build
, init
.fw_version
.type
);
950 dev_info(byt
->dev
, "Build type: %x\n", init
.fw_version
.type
);
951 dev_info(byt
->dev
, "Build date: %s %s\n",
952 init
.build_info
.date
, init
.build_info
.time
);
955 byt
->fw
= byt_sst_fw
;
960 sst_dsp_reset(byt
->dsp
);
961 sst_fw_free(byt_sst_fw
);
963 sst_dsp_free(byt
->dsp
);
965 kthread_stop(byt
->tx_thread
);
971 EXPORT_SYMBOL_GPL(sst_byt_dsp_init
);
973 void sst_byt_dsp_free(struct device
*dev
, struct sst_pdata
*pdata
)
975 struct sst_byt
*byt
= pdata
->dsp
;
977 sst_dsp_reset(byt
->dsp
);
978 sst_fw_free_all(byt
->dsp
);
979 sst_dsp_free(byt
->dsp
);
980 kthread_stop(byt
->tx_thread
);
983 EXPORT_SYMBOL_GPL(sst_byt_dsp_free
);