2 * Intel SST Haswell/Broadwell IPC Support
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/list.h>
20 #include <linux/device.h>
21 #include <linux/wait.h>
22 #include <linux/spinlock.h>
23 #include <linux/workqueue.h>
24 #include <linux/export.h>
25 #include <linux/slab.h>
26 #include <linux/delay.h>
27 #include <linux/sched.h>
28 #include <linux/platform_device.h>
29 #include <linux/kthread.h>
30 #include <linux/firmware.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/debugfs.h>
34 #include "sst-haswell-ipc.h"
36 #include "sst-dsp-priv.h"
38 /* Global Message - Generic */
39 #define IPC_GLB_TYPE_SHIFT 24
40 #define IPC_GLB_TYPE_MASK (0x1f << IPC_GLB_TYPE_SHIFT)
41 #define IPC_GLB_TYPE(x) (x << IPC_GLB_TYPE_SHIFT)
43 /* Global Message - Reply */
44 #define IPC_GLB_REPLY_SHIFT 0
45 #define IPC_GLB_REPLY_MASK (0x1f << IPC_GLB_REPLY_SHIFT)
46 #define IPC_GLB_REPLY_TYPE(x) (x << IPC_GLB_REPLY_TYPE_SHIFT)
48 /* Stream Message - Generic */
49 #define IPC_STR_TYPE_SHIFT 20
50 #define IPC_STR_TYPE_MASK (0xf << IPC_STR_TYPE_SHIFT)
51 #define IPC_STR_TYPE(x) (x << IPC_STR_TYPE_SHIFT)
52 #define IPC_STR_ID_SHIFT 16
53 #define IPC_STR_ID_MASK (0xf << IPC_STR_ID_SHIFT)
54 #define IPC_STR_ID(x) (x << IPC_STR_ID_SHIFT)
56 /* Stream Message - Reply */
57 #define IPC_STR_REPLY_SHIFT 0
58 #define IPC_STR_REPLY_MASK (0x1f << IPC_STR_REPLY_SHIFT)
60 /* Stream Stage Message - Generic */
61 #define IPC_STG_TYPE_SHIFT 12
62 #define IPC_STG_TYPE_MASK (0xf << IPC_STG_TYPE_SHIFT)
63 #define IPC_STG_TYPE(x) (x << IPC_STG_TYPE_SHIFT)
64 #define IPC_STG_ID_SHIFT 10
65 #define IPC_STG_ID_MASK (0x3 << IPC_STG_ID_SHIFT)
66 #define IPC_STG_ID(x) (x << IPC_STG_ID_SHIFT)
68 /* Stream Stage Message - Reply */
69 #define IPC_STG_REPLY_SHIFT 0
70 #define IPC_STG_REPLY_MASK (0x1f << IPC_STG_REPLY_SHIFT)
72 /* Debug Log Message - Generic */
73 #define IPC_LOG_OP_SHIFT 20
74 #define IPC_LOG_OP_MASK (0xf << IPC_LOG_OP_SHIFT)
75 #define IPC_LOG_OP_TYPE(x) (x << IPC_LOG_OP_SHIFT)
76 #define IPC_LOG_ID_SHIFT 16
77 #define IPC_LOG_ID_MASK (0xf << IPC_LOG_ID_SHIFT)
78 #define IPC_LOG_ID(x) (x << IPC_LOG_ID_SHIFT)
80 /* IPC message timeout (msecs) */
81 #define IPC_TIMEOUT_MSECS 300
82 #define IPC_BOOT_MSECS 200
83 #define IPC_MSG_WAIT 0
84 #define IPC_MSG_NOWAIT 1
86 /* Firmware Ready Message */
87 #define IPC_FW_READY (0x1 << 29)
88 #define IPC_STATUS_MASK (0x3 << 30)
90 #define IPC_EMPTY_LIST_SIZE 8
91 #define IPC_MAX_STREAMS 4
94 #define IPC_MAX_MAILBOX_BYTES 256
96 /* Global Message - Types and Replies */
98 IPC_GLB_GET_FW_VERSION
= 0, /* Retrieves firmware version */
99 IPC_GLB_PERFORMANCE_MONITOR
= 1, /* Performance monitoring actions */
100 IPC_GLB_ALLOCATE_STREAM
= 3, /* Request to allocate new stream */
101 IPC_GLB_FREE_STREAM
= 4, /* Request to free stream */
102 IPC_GLB_GET_FW_CAPABILITIES
= 5, /* Retrieves firmware capabilities */
103 IPC_GLB_STREAM_MESSAGE
= 6, /* Message directed to stream or its stages */
104 /* Request to store firmware context during D0->D3 transition */
105 IPC_GLB_REQUEST_DUMP
= 7,
106 /* Request to restore firmware context during D3->D0 transition */
107 IPC_GLB_RESTORE_CONTEXT
= 8,
108 IPC_GLB_GET_DEVICE_FORMATS
= 9, /* Set device format */
109 IPC_GLB_SET_DEVICE_FORMATS
= 10, /* Get device format */
110 IPC_GLB_SHORT_REPLY
= 11,
111 IPC_GLB_ENTER_DX_STATE
= 12,
112 IPC_GLB_GET_MIXER_STREAM_INFO
= 13, /* Request mixer stream params */
113 IPC_GLB_DEBUG_LOG_MESSAGE
= 14, /* Message to or from the debug logger. */
114 IPC_GLB_REQUEST_TRANSFER
= 16, /* < Request Transfer for host */
115 IPC_GLB_MAX_IPC_MESSAGE_TYPE
= 17, /* Maximum message number */
119 IPC_GLB_REPLY_SUCCESS
= 0, /* The operation was successful. */
120 IPC_GLB_REPLY_ERROR_INVALID_PARAM
= 1, /* Invalid parameter was passed. */
121 IPC_GLB_REPLY_UNKNOWN_MESSAGE_TYPE
= 2, /* Uknown message type was resceived. */
122 IPC_GLB_REPLY_OUT_OF_RESOURCES
= 3, /* No resources to satisfy the request. */
123 IPC_GLB_REPLY_BUSY
= 4, /* The system or resource is busy. */
124 IPC_GLB_REPLY_PENDING
= 5, /* The action was scheduled for processing. */
125 IPC_GLB_REPLY_FAILURE
= 6, /* Critical error happened. */
126 IPC_GLB_REPLY_INVALID_REQUEST
= 7, /* Request can not be completed. */
127 IPC_GLB_REPLY_STAGE_UNINITIALIZED
= 8, /* Processing stage was uninitialized. */
128 IPC_GLB_REPLY_NOT_FOUND
= 9, /* Required resource can not be found. */
129 IPC_GLB_REPLY_SOURCE_NOT_STARTED
= 10, /* Source was not started. */
132 /* Stream Message - Types */
133 enum ipc_str_operation
{
137 IPC_STR_STAGE_MESSAGE
= 3,
138 IPC_STR_NOTIFICATION
= 4,
142 /* Stream Stage Message Types */
143 enum ipc_stg_operation
{
144 IPC_STG_GET_VOLUME
= 0,
146 IPC_STG_SET_WRITE_POSITION
,
147 IPC_STG_SET_FX_ENABLE
,
148 IPC_STG_SET_FX_DISABLE
,
149 IPC_STG_SET_FX_GET_PARAM
,
150 IPC_STG_SET_FX_SET_PARAM
,
151 IPC_STG_SET_FX_GET_INFO
,
152 IPC_STG_MUTE_LOOPBACK
,
156 /* Stream Stage Message Types For Notification*/
157 enum ipc_stg_operation_notify
{
158 IPC_POSITION_CHANGED
= 0,
163 enum ipc_glitch_type
{
164 IPC_GLITCH_UNDERRUN
= 1,
165 IPC_GLITCH_DECODER_ERROR
,
166 IPC_GLITCH_DOUBLED_WRITE_POS
,
171 enum ipc_debug_operation
{
172 IPC_DEBUG_ENABLE_LOG
= 0,
173 IPC_DEBUG_DISABLE_LOG
= 1,
174 IPC_DEBUG_REQUEST_LOG_DUMP
= 2,
175 IPC_DEBUG_NOTIFY_LOG_DUMP
= 3,
176 IPC_DEBUG_MAX_DEBUG_LOG
180 struct sst_hsw_ipc_fw_ready
{
187 } __attribute__((packed
));
190 struct list_head list
;
193 /* direction wrt host CPU */
194 char tx_data
[IPC_MAX_MAILBOX_BYTES
];
196 char rx_data
[IPC_MAX_MAILBOX_BYTES
];
199 wait_queue_head_t waitq
;
206 struct sst_hsw_stream
;
209 /* Stream infomation */
210 struct sst_hsw_stream
{
212 struct sst_hsw_ipc_stream_alloc_req request
;
213 struct sst_hsw_ipc_stream_alloc_reply reply
;
214 struct sst_hsw_ipc_stream_free_req free_req
;
217 u32 mute_volume
[SST_HSW_NO_CHANNELS
];
218 u32 mute
[SST_HSW_NO_CHANNELS
];
226 /* Notification work */
227 struct work_struct notify_work
;
230 /* Position info from DSP */
231 struct sst_hsw_ipc_stream_set_position wpos
;
232 struct sst_hsw_ipc_stream_get_position rpos
;
233 struct sst_hsw_ipc_stream_glitch_position glitch
;
236 struct sst_hsw_ipc_volume_req vol_req
;
238 /* driver callback */
239 u32 (*notify_position
)(struct sst_hsw_stream
*stream
, void *data
);
242 struct list_head node
;
245 /* FW log ring information */
246 struct sst_hsw_log_stream
{
248 unsigned char *dma_area
;
249 unsigned char *ring_descr
;
253 /* Notification work */
254 struct work_struct notify_work
;
255 wait_queue_head_t readers_wait_q
;
256 struct mutex rw_mutex
;
263 u32 config
[SST_HSW_FW_LOG_CONFIG_DWORDS
];
268 /* SST Haswell IPC data */
272 struct platform_device
*pdev_pcm
;
275 struct sst_hsw_ipc_fw_ready fw_ready
;
276 struct sst_hsw_ipc_fw_version version
;
277 struct sst_module
*scratch
;
281 struct list_head stream_list
;
284 struct sst_hsw_ipc_stream_info_reply mixer_info
;
285 enum sst_hsw_volume_curve curve_type
;
287 u32 mute
[SST_HSW_NO_CHANNELS
];
288 u32 mute_volume
[SST_HSW_NO_CHANNELS
];
291 struct sst_hsw_ipc_dx_reply dx
;
294 wait_queue_head_t boot_wait
;
299 struct list_head tx_list
;
300 struct list_head rx_list
;
301 struct list_head empty_list
;
302 wait_queue_head_t wait_txq
;
303 struct task_struct
*tx_thread
;
304 struct kthread_worker kworker
;
305 struct kthread_work kwork
;
307 struct ipc_message
*msg
;
310 struct sst_hsw_log_stream log_stream
;
313 #define CREATE_TRACE_POINTS
314 #include <trace/events/hswadsp.h>
316 static inline u32
msg_get_global_type(u32 msg
)
318 return (msg
& IPC_GLB_TYPE_MASK
) >> IPC_GLB_TYPE_SHIFT
;
321 static inline u32
msg_get_global_reply(u32 msg
)
323 return (msg
& IPC_GLB_REPLY_MASK
) >> IPC_GLB_REPLY_SHIFT
;
326 static inline u32
msg_get_stream_type(u32 msg
)
328 return (msg
& IPC_STR_TYPE_MASK
) >> IPC_STR_TYPE_SHIFT
;
331 static inline u32
msg_get_stage_type(u32 msg
)
333 return (msg
& IPC_STG_TYPE_MASK
) >> IPC_STG_TYPE_SHIFT
;
336 static inline u32
msg_set_stage_type(u32 msg
, u32 type
)
338 return (msg
& ~IPC_STG_TYPE_MASK
) +
339 (type
<< IPC_STG_TYPE_SHIFT
);
342 static inline u32
msg_get_stream_id(u32 msg
)
344 return (msg
& IPC_STR_ID_MASK
) >> IPC_STR_ID_SHIFT
;
347 static inline u32
msg_get_notify_reason(u32 msg
)
349 return (msg
& IPC_STG_TYPE_MASK
) >> IPC_STG_TYPE_SHIFT
;
352 u32
create_channel_map(enum sst_hsw_channel_config config
)
355 case SST_HSW_CHANNEL_CONFIG_MONO
:
356 return (0xFFFFFFF0 | SST_HSW_CHANNEL_CENTER
);
357 case SST_HSW_CHANNEL_CONFIG_STEREO
:
358 return (0xFFFFFF00 | SST_HSW_CHANNEL_LEFT
359 | (SST_HSW_CHANNEL_RIGHT
<< 4));
360 case SST_HSW_CHANNEL_CONFIG_2_POINT_1
:
361 return (0xFFFFF000 | SST_HSW_CHANNEL_LEFT
362 | (SST_HSW_CHANNEL_RIGHT
<< 4)
363 | (SST_HSW_CHANNEL_LFE
<< 8 ));
364 case SST_HSW_CHANNEL_CONFIG_3_POINT_0
:
365 return (0xFFFFF000 | SST_HSW_CHANNEL_LEFT
366 | (SST_HSW_CHANNEL_CENTER
<< 4)
367 | (SST_HSW_CHANNEL_RIGHT
<< 8));
368 case SST_HSW_CHANNEL_CONFIG_3_POINT_1
:
369 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
370 | (SST_HSW_CHANNEL_CENTER
<< 4)
371 | (SST_HSW_CHANNEL_RIGHT
<< 8)
372 | (SST_HSW_CHANNEL_LFE
<< 12));
373 case SST_HSW_CHANNEL_CONFIG_QUATRO
:
374 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
375 | (SST_HSW_CHANNEL_RIGHT
<< 4)
376 | (SST_HSW_CHANNEL_LEFT_SURROUND
<< 8)
377 | (SST_HSW_CHANNEL_RIGHT_SURROUND
<< 12));
378 case SST_HSW_CHANNEL_CONFIG_4_POINT_0
:
379 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
380 | (SST_HSW_CHANNEL_CENTER
<< 4)
381 | (SST_HSW_CHANNEL_RIGHT
<< 8)
382 | (SST_HSW_CHANNEL_CENTER_SURROUND
<< 12));
383 case SST_HSW_CHANNEL_CONFIG_5_POINT_0
:
384 return (0xFFF00000 | SST_HSW_CHANNEL_LEFT
385 | (SST_HSW_CHANNEL_CENTER
<< 4)
386 | (SST_HSW_CHANNEL_RIGHT
<< 8)
387 | (SST_HSW_CHANNEL_LEFT_SURROUND
<< 12)
388 | (SST_HSW_CHANNEL_RIGHT_SURROUND
<< 16));
389 case SST_HSW_CHANNEL_CONFIG_5_POINT_1
:
390 return (0xFF000000 | SST_HSW_CHANNEL_CENTER
391 | (SST_HSW_CHANNEL_LEFT
<< 4)
392 | (SST_HSW_CHANNEL_RIGHT
<< 8)
393 | (SST_HSW_CHANNEL_LEFT_SURROUND
<< 12)
394 | (SST_HSW_CHANNEL_RIGHT_SURROUND
<< 16)
395 | (SST_HSW_CHANNEL_LFE
<< 20));
396 case SST_HSW_CHANNEL_CONFIG_DUAL_MONO
:
397 return (0xFFFFFF00 | SST_HSW_CHANNEL_LEFT
398 | (SST_HSW_CHANNEL_LEFT
<< 4));
404 static struct sst_hsw_stream
*get_stream_by_id(struct sst_hsw
*hsw
,
407 struct sst_hsw_stream
*stream
;
409 list_for_each_entry(stream
, &hsw
->stream_list
, node
) {
410 if (stream
->reply
.stream_hw_id
== stream_id
)
417 static void ipc_shim_dbg(struct sst_hsw
*hsw
, const char *text
)
419 struct sst_dsp
*sst
= hsw
->dsp
;
420 u32 isr
, ipcd
, imrx
, ipcx
;
422 ipcx
= sst_dsp_shim_read_unlocked(sst
, SST_IPCX
);
423 isr
= sst_dsp_shim_read_unlocked(sst
, SST_ISRX
);
424 ipcd
= sst_dsp_shim_read_unlocked(sst
, SST_IPCD
);
425 imrx
= sst_dsp_shim_read_unlocked(sst
, SST_IMRX
);
427 dev_err(hsw
->dev
, "ipc: --%s-- ipcx 0x%8.8x isr 0x%8.8x ipcd 0x%8.8x imrx 0x%8.8x\n",
428 text
, ipcx
, isr
, ipcd
, imrx
);
431 /* locks held by caller */
432 static struct ipc_message
*msg_get_empty(struct sst_hsw
*hsw
)
434 struct ipc_message
*msg
= NULL
;
436 if (!list_empty(&hsw
->empty_list
)) {
437 msg
= list_first_entry(&hsw
->empty_list
, struct ipc_message
,
439 list_del(&msg
->list
);
445 static void ipc_tx_msgs(struct kthread_work
*work
)
447 struct sst_hsw
*hsw
=
448 container_of(work
, struct sst_hsw
, kwork
);
449 struct ipc_message
*msg
;
453 spin_lock_irqsave(&hsw
->dsp
->spinlock
, flags
);
455 if (list_empty(&hsw
->tx_list
) || hsw
->pending
) {
456 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
460 /* if the DSP is busy we will TX messages after IRQ */
461 ipcx
= sst_dsp_shim_read_unlocked(hsw
->dsp
, SST_IPCX
);
462 if (ipcx
& SST_IPCX_BUSY
) {
463 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
467 msg
= list_first_entry(&hsw
->tx_list
, struct ipc_message
, list
);
469 list_move(&msg
->list
, &hsw
->rx_list
);
471 /* send the message */
472 sst_dsp_outbox_write(hsw
->dsp
, msg
->tx_data
, msg
->tx_size
);
473 sst_dsp_ipc_msg_tx(hsw
->dsp
, msg
->header
| SST_IPCX_BUSY
);
475 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
478 /* locks held by caller */
479 static void tx_msg_reply_complete(struct sst_hsw
*hsw
, struct ipc_message
*msg
)
481 msg
->complete
= true;
482 trace_ipc_reply("completed", msg
->header
);
485 list_add_tail(&msg
->list
, &hsw
->empty_list
);
487 wake_up(&msg
->waitq
);
490 static int tx_wait_done(struct sst_hsw
*hsw
, struct ipc_message
*msg
,
496 /* wait for DSP completion (in all cases atm inc pending) */
497 ret
= wait_event_timeout(msg
->waitq
, msg
->complete
,
498 msecs_to_jiffies(IPC_TIMEOUT_MSECS
));
500 spin_lock_irqsave(&hsw
->dsp
->spinlock
, flags
);
502 ipc_shim_dbg(hsw
, "message timeout");
504 trace_ipc_error("error message timeout for", msg
->header
);
508 /* copy the data returned from DSP */
510 memcpy(rx_data
, msg
->rx_data
, msg
->rx_size
);
514 list_add_tail(&msg
->list
, &hsw
->empty_list
);
515 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
519 static int ipc_tx_message(struct sst_hsw
*hsw
, u32 header
, void *tx_data
,
520 size_t tx_bytes
, void *rx_data
, size_t rx_bytes
, int wait
)
522 struct ipc_message
*msg
;
525 spin_lock_irqsave(&hsw
->dsp
->spinlock
, flags
);
527 msg
= msg_get_empty(hsw
);
529 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
534 memcpy(msg
->tx_data
, tx_data
, tx_bytes
);
536 msg
->header
= header
;
537 msg
->tx_size
= tx_bytes
;
538 msg
->rx_size
= rx_bytes
;
541 msg
->pending
= false;
542 msg
->complete
= false;
544 list_add_tail(&msg
->list
, &hsw
->tx_list
);
545 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
547 queue_kthread_work(&hsw
->kworker
, &hsw
->kwork
);
550 return tx_wait_done(hsw
, msg
, rx_data
);
555 static inline int ipc_tx_message_wait(struct sst_hsw
*hsw
, u32 header
,
556 void *tx_data
, size_t tx_bytes
, void *rx_data
, size_t rx_bytes
)
558 return ipc_tx_message(hsw
, header
, tx_data
, tx_bytes
, rx_data
,
562 static inline int ipc_tx_message_nowait(struct sst_hsw
*hsw
, u32 header
,
563 void *tx_data
, size_t tx_bytes
)
565 return ipc_tx_message(hsw
, header
, tx_data
, tx_bytes
, NULL
, 0, 0);
568 static void hsw_fw_ready(struct sst_hsw
*hsw
, u32 header
)
570 struct sst_hsw_ipc_fw_ready fw_ready
;
573 offset
= (header
& 0x1FFFFFFF) << 3;
575 dev_dbg(hsw
->dev
, "ipc: DSP is ready 0x%8.8x offset %d\n",
578 /* copy data from the DSP FW ready offset */
579 sst_dsp_read(hsw
->dsp
, &fw_ready
, offset
, sizeof(fw_ready
));
581 sst_dsp_mailbox_init(hsw
->dsp
, fw_ready
.inbox_offset
,
582 fw_ready
.inbox_size
, fw_ready
.outbox_offset
,
583 fw_ready
.outbox_size
);
585 hsw
->boot_complete
= true;
586 wake_up(&hsw
->boot_wait
);
588 dev_dbg(hsw
->dev
, " mailbox upstream 0x%x - size 0x%x\n",
589 fw_ready
.inbox_offset
, fw_ready
.inbox_size
);
590 dev_dbg(hsw
->dev
, " mailbox downstream 0x%x - size 0x%x\n",
591 fw_ready
.outbox_offset
, fw_ready
.outbox_size
);
594 static void hsw_notification_work(struct work_struct
*work
)
596 struct sst_hsw_stream
*stream
= container_of(work
,
597 struct sst_hsw_stream
, notify_work
);
598 struct sst_hsw_ipc_stream_glitch_position
*glitch
= &stream
->glitch
;
599 struct sst_hsw_ipc_stream_get_position
*pos
= &stream
->rpos
;
600 struct sst_hsw
*hsw
= stream
->hsw
;
603 reason
= msg_get_notify_reason(stream
->header
);
607 trace_ipc_notification("DSP stream under/overrun",
608 stream
->reply
.stream_hw_id
);
609 sst_dsp_inbox_read(hsw
->dsp
, glitch
, sizeof(*glitch
));
611 dev_err(hsw
->dev
, "glitch %d pos 0x%x write pos 0x%x\n",
612 glitch
->glitch_type
, glitch
->present_pos
,
616 case IPC_POSITION_CHANGED
:
617 trace_ipc_notification("DSP stream position changed for",
618 stream
->reply
.stream_hw_id
);
619 sst_dsp_inbox_read(hsw
->dsp
, pos
, sizeof(*pos
));
621 if (stream
->notify_position
)
622 stream
->notify_position(stream
, stream
->pdata
);
626 dev_err(hsw
->dev
, "error: unknown notification 0x%x\n",
631 /* tell DSP that notification has been handled */
632 sst_dsp_shim_update_bits_unlocked(hsw
->dsp
, SST_IPCD
,
633 SST_IPCD_BUSY
| SST_IPCD_DONE
, SST_IPCD_DONE
);
635 /* unmask busy interrupt */
636 sst_dsp_shim_update_bits_unlocked(hsw
->dsp
, SST_IMRX
, SST_IMRX_BUSY
, 0);
639 static struct ipc_message
*reply_find_msg(struct sst_hsw
*hsw
, u32 header
)
641 struct ipc_message
*msg
;
643 /* clear reply bits & status bits */
644 header
&= ~(IPC_STATUS_MASK
| IPC_GLB_REPLY_MASK
);
646 if (list_empty(&hsw
->rx_list
)) {
647 dev_err(hsw
->dev
, "error: rx list empty but received 0x%x\n",
652 list_for_each_entry(msg
, &hsw
->rx_list
, list
) {
653 if (msg
->header
== header
)
660 static void hsw_stream_update(struct sst_hsw
*hsw
, struct ipc_message
*msg
)
662 struct sst_hsw_stream
*stream
;
663 u32 header
= msg
->header
& ~(IPC_STATUS_MASK
| IPC_GLB_REPLY_MASK
);
664 u32 stream_id
= msg_get_stream_id(header
);
665 u32 stream_msg
= msg_get_stream_type(header
);
667 stream
= get_stream_by_id(hsw
, stream_id
);
671 switch (stream_msg
) {
672 case IPC_STR_STAGE_MESSAGE
:
673 case IPC_STR_NOTIFICATION
:
677 stream
->running
= false;
678 trace_ipc_notification("stream paused",
679 stream
->reply
.stream_hw_id
);
682 stream
->running
= true;
683 trace_ipc_notification("stream running",
684 stream
->reply
.stream_hw_id
);
689 static int hsw_process_reply(struct sst_hsw
*hsw
, u32 header
)
691 struct ipc_message
*msg
;
692 u32 reply
= msg_get_global_reply(header
);
694 trace_ipc_reply("processing -->", header
);
696 msg
= reply_find_msg(hsw
, header
);
698 trace_ipc_error("error: can't find message header", header
);
702 /* first process the header */
704 case IPC_GLB_REPLY_PENDING
:
705 trace_ipc_pending_reply("received", header
);
709 case IPC_GLB_REPLY_SUCCESS
:
711 trace_ipc_pending_reply("completed", header
);
712 sst_dsp_inbox_read(hsw
->dsp
, msg
->rx_data
,
714 hsw
->pending
= false;
716 /* copy data from the DSP */
717 sst_dsp_outbox_read(hsw
->dsp
, msg
->rx_data
,
721 /* these will be rare - but useful for debug */
722 case IPC_GLB_REPLY_UNKNOWN_MESSAGE_TYPE
:
723 trace_ipc_error("error: unknown message type", header
);
724 msg
->errno
= -EBADMSG
;
726 case IPC_GLB_REPLY_OUT_OF_RESOURCES
:
727 trace_ipc_error("error: out of resources", header
);
728 msg
->errno
= -ENOMEM
;
730 case IPC_GLB_REPLY_BUSY
:
731 trace_ipc_error("error: reply busy", header
);
734 case IPC_GLB_REPLY_FAILURE
:
735 trace_ipc_error("error: reply failure", header
);
736 msg
->errno
= -EINVAL
;
738 case IPC_GLB_REPLY_STAGE_UNINITIALIZED
:
739 trace_ipc_error("error: stage uninitialized", header
);
740 msg
->errno
= -EINVAL
;
742 case IPC_GLB_REPLY_NOT_FOUND
:
743 trace_ipc_error("error: reply not found", header
);
744 msg
->errno
= -EINVAL
;
746 case IPC_GLB_REPLY_SOURCE_NOT_STARTED
:
747 trace_ipc_error("error: source not started", header
);
748 msg
->errno
= -EINVAL
;
750 case IPC_GLB_REPLY_INVALID_REQUEST
:
751 trace_ipc_error("error: invalid request", header
);
752 msg
->errno
= -EINVAL
;
754 case IPC_GLB_REPLY_ERROR_INVALID_PARAM
:
755 trace_ipc_error("error: invalid parameter", header
);
756 msg
->errno
= -EINVAL
;
759 trace_ipc_error("error: unknown reply", header
);
760 msg
->errno
= -EINVAL
;
764 /* update any stream states */
765 hsw_stream_update(hsw
, msg
);
767 /* wake up and return the error if we have waiters on this message ? */
768 list_del(&msg
->list
);
769 tx_msg_reply_complete(hsw
, msg
);
774 static int hsw_stream_message(struct sst_hsw
*hsw
, u32 header
)
776 u32 stream_msg
, stream_id
, stage_type
;
777 struct sst_hsw_stream
*stream
;
780 stream_msg
= msg_get_stream_type(header
);
781 stream_id
= msg_get_stream_id(header
);
782 stage_type
= msg_get_stage_type(header
);
784 stream
= get_stream_by_id(hsw
, stream_id
);
788 stream
->header
= header
;
790 switch (stream_msg
) {
791 case IPC_STR_STAGE_MESSAGE
:
792 dev_err(hsw
->dev
, "error: stage msg not implemented 0x%8.8x\n",
795 case IPC_STR_NOTIFICATION
:
796 schedule_work(&stream
->notify_work
);
799 /* handle pending message complete request */
800 handled
= hsw_process_reply(hsw
, header
);
807 static int hsw_log_message(struct sst_hsw
*hsw
, u32 header
)
809 u32 operation
= (header
& IPC_LOG_OP_MASK
) >> IPC_LOG_OP_SHIFT
;
810 struct sst_hsw_log_stream
*stream
= &hsw
->log_stream
;
813 if (operation
!= IPC_DEBUG_REQUEST_LOG_DUMP
) {
815 "error: log msg not implemented 0x%8.8x\n", header
);
819 mutex_lock(&stream
->rw_mutex
);
820 stream
->last_pos
= stream
->curr_pos
;
822 hsw
->dsp
, &stream
->curr_pos
, sizeof(stream
->curr_pos
));
823 mutex_unlock(&stream
->rw_mutex
);
825 schedule_work(&stream
->notify_work
);
830 static int hsw_process_notification(struct sst_hsw
*hsw
)
832 struct sst_dsp
*sst
= hsw
->dsp
;
836 header
= sst_dsp_shim_read_unlocked(sst
, SST_IPCD
);
837 type
= msg_get_global_type(header
);
839 trace_ipc_request("processing -->", header
);
841 /* FW Ready is a special case */
842 if (!hsw
->boot_complete
&& header
& IPC_FW_READY
) {
843 hsw_fw_ready(hsw
, header
);
848 case IPC_GLB_GET_FW_VERSION
:
849 case IPC_GLB_ALLOCATE_STREAM
:
850 case IPC_GLB_FREE_STREAM
:
851 case IPC_GLB_GET_FW_CAPABILITIES
:
852 case IPC_GLB_REQUEST_DUMP
:
853 case IPC_GLB_GET_DEVICE_FORMATS
:
854 case IPC_GLB_SET_DEVICE_FORMATS
:
855 case IPC_GLB_ENTER_DX_STATE
:
856 case IPC_GLB_GET_MIXER_STREAM_INFO
:
857 case IPC_GLB_MAX_IPC_MESSAGE_TYPE
:
858 case IPC_GLB_RESTORE_CONTEXT
:
859 case IPC_GLB_SHORT_REPLY
:
860 dev_err(hsw
->dev
, "error: message type %d header 0x%x\n",
863 case IPC_GLB_STREAM_MESSAGE
:
864 handled
= hsw_stream_message(hsw
, header
);
866 case IPC_GLB_DEBUG_LOG_MESSAGE
:
867 handled
= hsw_log_message(hsw
, header
);
870 dev_err(hsw
->dev
, "error: unexpected type %d hdr 0x%8.8x\n",
878 static irqreturn_t
hsw_irq_thread(int irq
, void *context
)
880 struct sst_dsp
*sst
= (struct sst_dsp
*) context
;
881 struct sst_hsw
*hsw
= sst_dsp_get_thread_context(sst
);
886 spin_lock_irqsave(&sst
->spinlock
, flags
);
888 ipcx
= sst_dsp_ipc_msg_rx(hsw
->dsp
);
889 ipcd
= sst_dsp_shim_read_unlocked(sst
, SST_IPCD
);
891 /* reply message from DSP */
892 if (ipcx
& SST_IPCX_DONE
) {
894 /* Handle Immediate reply from DSP Core */
895 handled
= hsw_process_reply(hsw
, ipcx
);
898 /* clear DONE bit - tell DSP we have completed */
899 sst_dsp_shim_update_bits_unlocked(sst
, SST_IPCX
,
902 /* unmask Done interrupt */
903 sst_dsp_shim_update_bits_unlocked(sst
, SST_IMRX
,
908 /* new message from DSP */
909 if (ipcd
& SST_IPCD_BUSY
) {
911 /* Handle Notification and Delayed reply from DSP Core */
912 handled
= hsw_process_notification(hsw
);
914 /* clear BUSY bit and set DONE bit - accept new messages */
916 sst_dsp_shim_update_bits_unlocked(sst
, SST_IPCD
,
917 SST_IPCD_BUSY
| SST_IPCD_DONE
, SST_IPCD_DONE
);
919 /* unmask busy interrupt */
920 sst_dsp_shim_update_bits_unlocked(sst
, SST_IMRX
,
925 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
927 /* continue to send any remaining messages... */
928 queue_kthread_work(&hsw
->kworker
, &hsw
->kwork
);
933 int sst_hsw_fw_get_version(struct sst_hsw
*hsw
,
934 struct sst_hsw_ipc_fw_version
*version
)
938 ret
= ipc_tx_message_wait(hsw
, IPC_GLB_TYPE(IPC_GLB_GET_FW_VERSION
),
939 NULL
, 0, version
, sizeof(*version
));
941 dev_err(hsw
->dev
, "error: get version failed\n");
947 int sst_hsw_stream_mute(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
948 u32 stage_id
, u32 channel
)
952 ret
= sst_hsw_stream_get_volume(hsw
, stream
, stage_id
, channel
,
953 &stream
->mute_volume
[channel
]);
957 ret
= sst_hsw_stream_set_volume(hsw
, stream
, stage_id
, channel
, 0);
959 dev_err(hsw
->dev
, "error: can't unmute stream %d channel %d\n",
960 stream
->reply
.stream_hw_id
, channel
);
964 stream
->mute
[channel
] = 1;
968 int sst_hsw_stream_unmute(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
969 u32 stage_id
, u32 channel
)
974 stream
->mute
[channel
] = 0;
975 ret
= sst_hsw_stream_set_volume(hsw
, stream
, stage_id
, channel
,
976 stream
->mute_volume
[channel
]);
978 dev_err(hsw
->dev
, "error: can't unmute stream %d channel %d\n",
979 stream
->reply
.stream_hw_id
, channel
);
986 int sst_hsw_stream_get_volume(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
987 u32 stage_id
, u32 channel
, u32
*volume
)
992 sst_dsp_read(hsw
->dsp
, volume
,
993 stream
->reply
.volume_register_address
[channel
],
999 int sst_hsw_stream_set_volume_curve(struct sst_hsw
*hsw
,
1000 struct sst_hsw_stream
*stream
, u64 curve_duration
,
1001 enum sst_hsw_volume_curve curve
)
1003 /* curve duration in steps of 100ns */
1004 stream
->vol_req
.curve_duration
= curve_duration
;
1005 stream
->vol_req
.curve_type
= curve
;
1011 int sst_hsw_stream_set_volume(struct sst_hsw
*hsw
,
1012 struct sst_hsw_stream
*stream
, u32 stage_id
, u32 channel
, u32 volume
)
1014 struct sst_hsw_ipc_volume_req
*req
;
1018 trace_ipc_request("set stream volume", stream
->reply
.stream_hw_id
);
1023 if (stream
->mute
[channel
]) {
1024 stream
->mute_volume
[channel
] = volume
;
1028 header
= IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE
) |
1029 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE
);
1030 header
|= (stream
->reply
.stream_hw_id
<< IPC_STR_ID_SHIFT
);
1031 header
|= (IPC_STG_SET_VOLUME
<< IPC_STG_TYPE_SHIFT
);
1032 header
|= (stage_id
<< IPC_STG_ID_SHIFT
);
1034 req
= &stream
->vol_req
;
1035 req
->channel
= channel
;
1036 req
->target_volume
= volume
;
1038 ret
= ipc_tx_message_wait(hsw
, header
, req
, sizeof(*req
), NULL
, 0);
1040 dev_err(hsw
->dev
, "error: set stream volume failed\n");
1047 int sst_hsw_mixer_mute(struct sst_hsw
*hsw
, u32 stage_id
, u32 channel
)
1051 ret
= sst_hsw_mixer_get_volume(hsw
, stage_id
, channel
,
1052 &hsw
->mute_volume
[channel
]);
1056 ret
= sst_hsw_mixer_set_volume(hsw
, stage_id
, channel
, 0);
1058 dev_err(hsw
->dev
, "error: failed to unmute mixer channel %d\n",
1063 hsw
->mute
[channel
] = 1;
1067 int sst_hsw_mixer_unmute(struct sst_hsw
*hsw
, u32 stage_id
, u32 channel
)
1071 ret
= sst_hsw_mixer_set_volume(hsw
, stage_id
, channel
,
1072 hsw
->mixer_info
.volume_register_address
[channel
]);
1074 dev_err(hsw
->dev
, "error: failed to unmute mixer channel %d\n",
1079 hsw
->mute
[channel
] = 0;
1083 int sst_hsw_mixer_get_volume(struct sst_hsw
*hsw
, u32 stage_id
, u32 channel
,
1089 sst_dsp_read(hsw
->dsp
, volume
,
1090 hsw
->mixer_info
.volume_register_address
[channel
],
1096 int sst_hsw_mixer_set_volume_curve(struct sst_hsw
*hsw
,
1097 u64 curve_duration
, enum sst_hsw_volume_curve curve
)
1099 /* curve duration in steps of 100ns */
1100 hsw
->curve_duration
= curve_duration
;
1101 hsw
->curve_type
= curve
;
1106 /* global mixer volume */
1107 int sst_hsw_mixer_set_volume(struct sst_hsw
*hsw
, u32 stage_id
, u32 channel
,
1110 struct sst_hsw_ipc_volume_req req
;
1114 trace_ipc_request("set mixer volume", volume
);
1116 /* set both at same time ? */
1118 if (hsw
->mute
[0] && hsw
->mute
[1]) {
1119 hsw
->mute_volume
[0] = hsw
->mute_volume
[1] = volume
;
1121 } else if (hsw
->mute
[0])
1123 else if (hsw
->mute
[1])
1126 req
.channel
= 0xffffffff;
1128 /* set only 1 channel */
1129 if (hsw
->mute
[channel
]) {
1130 hsw
->mute_volume
[channel
] = volume
;
1133 req
.channel
= channel
;
1136 header
= IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE
) |
1137 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE
);
1138 header
|= (hsw
->mixer_info
.mixer_hw_id
<< IPC_STR_ID_SHIFT
);
1139 header
|= (IPC_STG_SET_VOLUME
<< IPC_STG_TYPE_SHIFT
);
1140 header
|= (stage_id
<< IPC_STG_ID_SHIFT
);
1142 req
.curve_duration
= hsw
->curve_duration
;
1143 req
.curve_type
= hsw
->curve_type
;
1144 req
.target_volume
= volume
;
1146 ret
= ipc_tx_message_wait(hsw
, header
, &req
, sizeof(req
), NULL
, 0);
1148 dev_err(hsw
->dev
, "error: set mixer volume failed\n");
1156 struct sst_hsw_stream
*sst_hsw_stream_new(struct sst_hsw
*hsw
, int id
,
1157 u32 (*notify_position
)(struct sst_hsw_stream
*stream
, void *data
),
1160 struct sst_hsw_stream
*stream
;
1161 struct sst_dsp
*sst
= hsw
->dsp
;
1162 unsigned long flags
;
1164 stream
= kzalloc(sizeof(*stream
), GFP_KERNEL
);
1168 spin_lock_irqsave(&sst
->spinlock
, flags
);
1169 list_add(&stream
->node
, &hsw
->stream_list
);
1170 stream
->notify_position
= notify_position
;
1171 stream
->pdata
= data
;
1173 stream
->host_id
= id
;
1175 /* work to process notification messages */
1176 INIT_WORK(&stream
->notify_work
, hsw_notification_work
);
1177 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
1182 int sst_hsw_stream_free(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
)
1186 struct sst_dsp
*sst
= hsw
->dsp
;
1187 unsigned long flags
;
1189 /* dont free DSP streams that are not commited */
1190 if (!stream
->commited
)
1193 trace_ipc_request("stream free", stream
->host_id
);
1195 stream
->free_req
.stream_id
= stream
->reply
.stream_hw_id
;
1196 header
= IPC_GLB_TYPE(IPC_GLB_FREE_STREAM
);
1198 ret
= ipc_tx_message_wait(hsw
, header
, &stream
->free_req
,
1199 sizeof(stream
->free_req
), NULL
, 0);
1201 dev_err(hsw
->dev
, "error: free stream %d failed\n",
1202 stream
->free_req
.stream_id
);
1206 trace_hsw_stream_free_req(stream
, &stream
->free_req
);
1209 cancel_work_sync(&stream
->notify_work
);
1210 spin_lock_irqsave(&sst
->spinlock
, flags
);
1211 list_del(&stream
->node
);
1213 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
1218 int sst_hsw_stream_set_bits(struct sst_hsw
*hsw
,
1219 struct sst_hsw_stream
*stream
, enum sst_hsw_bitdepth bits
)
1221 if (stream
->commited
) {
1222 dev_err(hsw
->dev
, "error: stream committed for set bits\n");
1226 stream
->request
.format
.bitdepth
= bits
;
1230 int sst_hsw_stream_set_channels(struct sst_hsw
*hsw
,
1231 struct sst_hsw_stream
*stream
, int channels
)
1233 if (stream
->commited
) {
1234 dev_err(hsw
->dev
, "error: stream committed for set channels\n");
1238 /* stereo is only supported atm */
1242 stream
->request
.format
.ch_num
= channels
;
1246 int sst_hsw_stream_set_rate(struct sst_hsw
*hsw
,
1247 struct sst_hsw_stream
*stream
, int rate
)
1249 if (stream
->commited
) {
1250 dev_err(hsw
->dev
, "error: stream committed for set rate\n");
1254 stream
->request
.format
.frequency
= rate
;
1258 int sst_hsw_stream_set_map_config(struct sst_hsw
*hsw
,
1259 struct sst_hsw_stream
*stream
, u32 map
,
1260 enum sst_hsw_channel_config config
)
1262 if (stream
->commited
) {
1263 dev_err(hsw
->dev
, "error: stream committed for set map\n");
1267 stream
->request
.format
.map
= map
;
1268 stream
->request
.format
.config
= config
;
1272 int sst_hsw_stream_set_style(struct sst_hsw
*hsw
,
1273 struct sst_hsw_stream
*stream
, enum sst_hsw_interleaving style
)
1275 if (stream
->commited
) {
1276 dev_err(hsw
->dev
, "error: stream committed for set style\n");
1280 stream
->request
.format
.style
= style
;
1284 int sst_hsw_stream_set_valid(struct sst_hsw
*hsw
,
1285 struct sst_hsw_stream
*stream
, u32 bits
)
1287 if (stream
->commited
) {
1288 dev_err(hsw
->dev
, "error: stream committed for set valid bits\n");
1292 stream
->request
.format
.valid_bit
= bits
;
1296 /* Stream Configuration */
1297 int sst_hsw_stream_format(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1298 enum sst_hsw_stream_path_id path_id
,
1299 enum sst_hsw_stream_type stream_type
,
1300 enum sst_hsw_stream_format format_id
)
1302 if (stream
->commited
) {
1303 dev_err(hsw
->dev
, "error: stream committed for set format\n");
1307 stream
->request
.path_id
= path_id
;
1308 stream
->request
.stream_type
= stream_type
;
1309 stream
->request
.format_id
= format_id
;
1311 trace_hsw_stream_alloc_request(stream
, &stream
->request
);
1316 int sst_hsw_stream_buffer(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1317 u32 ring_pt_address
, u32 num_pages
,
1318 u32 ring_size
, u32 ring_offset
, u32 ring_first_pfn
)
1320 if (stream
->commited
) {
1321 dev_err(hsw
->dev
, "error: stream committed for buffer\n");
1325 stream
->request
.ringinfo
.ring_pt_address
= ring_pt_address
;
1326 stream
->request
.ringinfo
.num_pages
= num_pages
;
1327 stream
->request
.ringinfo
.ring_size
= ring_size
;
1328 stream
->request
.ringinfo
.ring_offset
= ring_offset
;
1329 stream
->request
.ringinfo
.ring_first_pfn
= ring_first_pfn
;
1331 trace_hsw_stream_buffer(stream
);
1336 int sst_hsw_stream_set_module_info(struct sst_hsw
*hsw
,
1337 struct sst_hsw_stream
*stream
, enum sst_hsw_module_id module_id
,
1340 struct sst_hsw_module_map
*map
= &stream
->request
.map
;
1342 if (stream
->commited
) {
1343 dev_err(hsw
->dev
, "error: stream committed for set module\n");
1347 /* only support initial module atm */
1348 map
->module_entries_count
= 1;
1349 map
->module_entries
[0].module_id
= module_id
;
1350 map
->module_entries
[0].entry_point
= entry_point
;
1355 int sst_hsw_stream_set_pmemory_info(struct sst_hsw
*hsw
,
1356 struct sst_hsw_stream
*stream
, u32 offset
, u32 size
)
1358 if (stream
->commited
) {
1359 dev_err(hsw
->dev
, "error: stream committed for set pmem\n");
1363 stream
->request
.persistent_mem
.offset
= offset
;
1364 stream
->request
.persistent_mem
.size
= size
;
1369 int sst_hsw_stream_set_smemory_info(struct sst_hsw
*hsw
,
1370 struct sst_hsw_stream
*stream
, u32 offset
, u32 size
)
1372 if (stream
->commited
) {
1373 dev_err(hsw
->dev
, "error: stream committed for set smem\n");
1377 stream
->request
.scratch_mem
.offset
= offset
;
1378 stream
->request
.scratch_mem
.size
= size
;
1383 int sst_hsw_stream_commit(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
)
1385 struct sst_hsw_ipc_stream_alloc_req
*str_req
= &stream
->request
;
1386 struct sst_hsw_ipc_stream_alloc_reply
*reply
= &stream
->reply
;
1390 trace_ipc_request("stream alloc", stream
->host_id
);
1392 header
= IPC_GLB_TYPE(IPC_GLB_ALLOCATE_STREAM
);
1394 ret
= ipc_tx_message_wait(hsw
, header
, str_req
, sizeof(*str_req
),
1395 reply
, sizeof(*reply
));
1397 dev_err(hsw
->dev
, "error: stream commit failed\n");
1401 stream
->commited
= 1;
1402 trace_hsw_stream_alloc_reply(stream
);
1407 /* Stream Information - these calls could be inline but we want the IPC
1408 ABI to be opaque to client PCM drivers to cope with any future ABI changes */
1409 int sst_hsw_stream_get_hw_id(struct sst_hsw
*hsw
,
1410 struct sst_hsw_stream
*stream
)
1412 return stream
->reply
.stream_hw_id
;
1415 int sst_hsw_stream_get_mixer_id(struct sst_hsw
*hsw
,
1416 struct sst_hsw_stream
*stream
)
1418 return stream
->reply
.mixer_hw_id
;
1421 u32
sst_hsw_stream_get_read_reg(struct sst_hsw
*hsw
,
1422 struct sst_hsw_stream
*stream
)
1424 return stream
->reply
.read_position_register_address
;
1427 u32
sst_hsw_stream_get_pointer_reg(struct sst_hsw
*hsw
,
1428 struct sst_hsw_stream
*stream
)
1430 return stream
->reply
.presentation_position_register_address
;
1433 u32
sst_hsw_stream_get_peak_reg(struct sst_hsw
*hsw
,
1434 struct sst_hsw_stream
*stream
, u32 channel
)
1439 return stream
->reply
.peak_meter_register_address
[channel
];
1442 u32
sst_hsw_stream_get_vol_reg(struct sst_hsw
*hsw
,
1443 struct sst_hsw_stream
*stream
, u32 channel
)
1448 return stream
->reply
.volume_register_address
[channel
];
1451 int sst_hsw_mixer_get_info(struct sst_hsw
*hsw
)
1453 struct sst_hsw_ipc_stream_info_reply
*reply
;
1457 reply
= &hsw
->mixer_info
;
1458 header
= IPC_GLB_TYPE(IPC_GLB_GET_MIXER_STREAM_INFO
);
1460 trace_ipc_request("get global mixer info", 0);
1462 ret
= ipc_tx_message_wait(hsw
, header
, NULL
, 0, reply
, sizeof(*reply
));
1464 dev_err(hsw
->dev
, "error: get stream info failed\n");
1468 trace_hsw_mixer_info_reply(reply
);
1473 /* Send stream command */
1474 static int sst_hsw_stream_operations(struct sst_hsw
*hsw
, int type
,
1475 int stream_id
, int wait
)
1479 header
= IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE
) | IPC_STR_TYPE(type
);
1480 header
|= (stream_id
<< IPC_STR_ID_SHIFT
);
1483 return ipc_tx_message_wait(hsw
, header
, NULL
, 0, NULL
, 0);
1485 return ipc_tx_message_nowait(hsw
, header
, NULL
, 0);
1488 /* Stream ALSA trigger operations */
1489 int sst_hsw_stream_pause(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1494 trace_ipc_request("stream pause", stream
->reply
.stream_hw_id
);
1496 ret
= sst_hsw_stream_operations(hsw
, IPC_STR_PAUSE
,
1497 stream
->reply
.stream_hw_id
, wait
);
1499 dev_err(hsw
->dev
, "error: failed to pause stream %d\n",
1500 stream
->reply
.stream_hw_id
);
1505 int sst_hsw_stream_resume(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1510 trace_ipc_request("stream resume", stream
->reply
.stream_hw_id
);
1512 ret
= sst_hsw_stream_operations(hsw
, IPC_STR_RESUME
,
1513 stream
->reply
.stream_hw_id
, wait
);
1515 dev_err(hsw
->dev
, "error: failed to resume stream %d\n",
1516 stream
->reply
.stream_hw_id
);
1521 int sst_hsw_stream_reset(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
)
1523 int ret
, tries
= 10;
1525 /* dont reset streams that are not commited */
1526 if (!stream
->commited
)
1529 /* wait for pause to complete before we reset the stream */
1530 while (stream
->running
&& tries
--)
1533 dev_err(hsw
->dev
, "error: reset stream %d still running\n",
1534 stream
->reply
.stream_hw_id
);
1538 trace_ipc_request("stream reset", stream
->reply
.stream_hw_id
);
1540 ret
= sst_hsw_stream_operations(hsw
, IPC_STR_RESET
,
1541 stream
->reply
.stream_hw_id
, 1);
1543 dev_err(hsw
->dev
, "error: failed to reset stream %d\n",
1544 stream
->reply
.stream_hw_id
);
1548 /* Stream pointer positions */
1549 u32
sst_hsw_get_dsp_position(struct sst_hsw
*hsw
,
1550 struct sst_hsw_stream
*stream
)
1554 sst_dsp_read(hsw
->dsp
, &rpos
,
1555 stream
->reply
.read_position_register_address
, sizeof(rpos
));
1560 /* Stream presentation (monotonic) positions */
1561 u64
sst_hsw_get_dsp_presentation_position(struct sst_hsw
*hsw
,
1562 struct sst_hsw_stream
*stream
)
1566 sst_dsp_read(hsw
->dsp
, &ppos
,
1567 stream
->reply
.presentation_position_register_address
,
1573 int sst_hsw_stream_set_write_position(struct sst_hsw
*hsw
,
1574 struct sst_hsw_stream
*stream
, u32 stage_id
, u32 position
)
1579 trace_stream_write_position(stream
->reply
.stream_hw_id
, position
);
1581 header
= IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE
) |
1582 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE
);
1583 header
|= (stream
->reply
.stream_hw_id
<< IPC_STR_ID_SHIFT
);
1584 header
|= (IPC_STG_SET_WRITE_POSITION
<< IPC_STG_TYPE_SHIFT
);
1585 header
|= (stage_id
<< IPC_STG_ID_SHIFT
);
1586 stream
->wpos
.position
= position
;
1588 ret
= ipc_tx_message_nowait(hsw
, header
, &stream
->wpos
,
1589 sizeof(stream
->wpos
));
1591 dev_err(hsw
->dev
, "error: stream %d set position %d failed\n",
1592 stream
->reply
.stream_hw_id
, position
);
1597 /* physical BE config */
1598 int sst_hsw_device_set_config(struct sst_hsw
*hsw
,
1599 enum sst_hsw_device_id dev
, enum sst_hsw_device_mclk mclk
,
1600 enum sst_hsw_device_mode mode
, u32 clock_divider
)
1602 struct sst_hsw_ipc_device_config_req config
;
1606 trace_ipc_request("set device config", dev
);
1608 config
.ssp_interface
= dev
;
1609 config
.clock_frequency
= mclk
;
1611 config
.clock_divider
= clock_divider
;
1613 trace_hsw_device_config_req(&config
);
1615 header
= IPC_GLB_TYPE(IPC_GLB_SET_DEVICE_FORMATS
);
1617 ret
= ipc_tx_message_wait(hsw
, header
, &config
, sizeof(config
),
1620 dev_err(hsw
->dev
, "error: set device formats failed\n");
1624 EXPORT_SYMBOL_GPL(sst_hsw_device_set_config
);
1627 int sst_hsw_dx_set_state(struct sst_hsw
*hsw
,
1628 enum sst_hsw_dx_state state
, struct sst_hsw_ipc_dx_reply
*dx
)
1633 header
= IPC_GLB_TYPE(IPC_GLB_ENTER_DX_STATE
);
1636 trace_ipc_request("PM enter Dx state", state
);
1638 ret
= ipc_tx_message_wait(hsw
, header
, &state_
, sizeof(state_
),
1641 dev_err(hsw
->dev
, "ipc: error set dx state %d failed\n", state
);
1645 dev_dbg(hsw
->dev
, "ipc: got %d entry numbers for state %d\n",
1646 dx
->entries_no
, state
);
1648 memcpy(&hsw
->dx
, dx
, sizeof(*dx
));
1652 /* Used to save state into hsw->dx_reply */
1653 int sst_hsw_dx_get_state(struct sst_hsw
*hsw
, u32 item
,
1654 u32
*offset
, u32
*size
, u32
*source
)
1656 struct sst_hsw_ipc_dx_memory_item
*dx_mem
;
1657 struct sst_hsw_ipc_dx_reply
*dx_reply
;
1660 dx_reply
= &hsw
->dx
;
1661 entry_no
= dx_reply
->entries_no
;
1663 trace_ipc_request("PM get Dx state", entry_no
);
1665 if (item
>= entry_no
)
1668 dx_mem
= &dx_reply
->mem_info
[item
];
1669 *offset
= dx_mem
->offset
;
1670 *size
= dx_mem
->size
;
1671 *source
= dx_mem
->source
;
1676 static int msg_empty_list_init(struct sst_hsw
*hsw
)
1680 hsw
->msg
= kzalloc(sizeof(struct ipc_message
) *
1681 IPC_EMPTY_LIST_SIZE
, GFP_KERNEL
);
1682 if (hsw
->msg
== NULL
)
1685 for (i
= 0; i
< IPC_EMPTY_LIST_SIZE
; i
++) {
1686 init_waitqueue_head(&hsw
->msg
[i
].waitq
);
1687 list_add(&hsw
->msg
[i
].list
, &hsw
->empty_list
);
1693 void sst_hsw_set_scratch_module(struct sst_hsw
*hsw
,
1694 struct sst_module
*scratch
)
1696 hsw
->scratch
= scratch
;
1699 struct sst_dsp
*sst_hsw_get_dsp(struct sst_hsw
*hsw
)
1704 static struct sst_dsp_device hsw_dev
= {
1705 .thread
= hsw_irq_thread
,
1706 .ops
= &haswell_ops
,
1709 int sst_hsw_dsp_init(struct device
*dev
, struct sst_pdata
*pdata
)
1711 struct sst_hsw_ipc_fw_version version
;
1712 struct sst_hsw
*hsw
;
1713 struct sst_fw
*hsw_sst_fw
;
1716 dev_dbg(dev
, "initialising Audio DSP IPC\n");
1718 hsw
= devm_kzalloc(dev
, sizeof(*hsw
), GFP_KERNEL
);
1723 INIT_LIST_HEAD(&hsw
->stream_list
);
1724 INIT_LIST_HEAD(&hsw
->tx_list
);
1725 INIT_LIST_HEAD(&hsw
->rx_list
);
1726 INIT_LIST_HEAD(&hsw
->empty_list
);
1727 init_waitqueue_head(&hsw
->boot_wait
);
1728 init_waitqueue_head(&hsw
->wait_txq
);
1730 ret
= msg_empty_list_init(hsw
);
1734 /* start the IPC message thread */
1735 init_kthread_worker(&hsw
->kworker
);
1736 hsw
->tx_thread
= kthread_run(kthread_worker_fn
,
1737 &hsw
->kworker
, "%s",
1738 dev_name(hsw
->dev
));
1739 if (IS_ERR(hsw
->tx_thread
)) {
1740 ret
= PTR_ERR(hsw
->tx_thread
);
1741 dev_err(hsw
->dev
, "error: failed to create message TX task\n");
1744 init_kthread_work(&hsw
->kwork
, ipc_tx_msgs
);
1746 hsw_dev
.thread_context
= hsw
;
1749 hsw
->dsp
= sst_dsp_new(dev
, &hsw_dev
, pdata
);
1750 if (hsw
->dsp
== NULL
) {
1755 /* keep the DSP in reset state for base FW loading */
1756 sst_dsp_reset(hsw
->dsp
);
1758 hsw_sst_fw
= sst_fw_new(hsw
->dsp
, pdata
->fw
, hsw
);
1760 if (hsw_sst_fw
== NULL
) {
1762 dev_err(dev
, "error: failed to load firmware\n");
1766 /* wait for DSP boot completion */
1767 sst_dsp_boot(hsw
->dsp
);
1768 ret
= wait_event_timeout(hsw
->boot_wait
, hsw
->boot_complete
,
1769 msecs_to_jiffies(IPC_BOOT_MSECS
));
1772 dev_err(hsw
->dev
, "error: ADSP boot timeout\n");
1776 /* get the FW version */
1777 sst_hsw_fw_get_version(hsw
, &version
);
1778 dev_info(hsw
->dev
, "FW loaded: type %d - version: %d.%d build %d\n",
1779 version
.type
, version
.major
, version
.minor
, version
.build
);
1781 /* get the globalmixer */
1782 ret
= sst_hsw_mixer_get_info(hsw
);
1784 dev_err(hsw
->dev
, "error: failed to get stream info\n");
1792 sst_dsp_reset(hsw
->dsp
);
1793 sst_fw_free(hsw_sst_fw
);
1795 sst_dsp_free(hsw
->dsp
);
1797 kthread_stop(hsw
->tx_thread
);
1803 EXPORT_SYMBOL_GPL(sst_hsw_dsp_init
);
1805 void sst_hsw_dsp_free(struct device
*dev
, struct sst_pdata
*pdata
)
1807 struct sst_hsw
*hsw
= pdata
->dsp
;
1809 sst_dsp_reset(hsw
->dsp
);
1810 sst_fw_free_all(hsw
->dsp
);
1811 sst_dsp_free(hsw
->dsp
);
1812 kfree(hsw
->scratch
);
1813 kthread_stop(hsw
->tx_thread
);
1816 EXPORT_SYMBOL_GPL(sst_hsw_dsp_free
);