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>
33 #include <linux/pm_runtime.h>
34 #include <sound/asound.h>
36 #include "sst-haswell-ipc.h"
37 #include "../common/sst-dsp.h"
38 #include "../common/sst-dsp-priv.h"
39 #include "../common/sst-ipc.h"
41 /* Global Message - Generic */
42 #define IPC_GLB_TYPE_SHIFT 24
43 #define IPC_GLB_TYPE_MASK (0x1f << IPC_GLB_TYPE_SHIFT)
44 #define IPC_GLB_TYPE(x) (x << IPC_GLB_TYPE_SHIFT)
46 /* Global Message - Reply */
47 #define IPC_GLB_REPLY_SHIFT 0
48 #define IPC_GLB_REPLY_MASK (0x1f << IPC_GLB_REPLY_SHIFT)
49 #define IPC_GLB_REPLY_TYPE(x) (x << IPC_GLB_REPLY_TYPE_SHIFT)
51 /* Stream Message - Generic */
52 #define IPC_STR_TYPE_SHIFT 20
53 #define IPC_STR_TYPE_MASK (0xf << IPC_STR_TYPE_SHIFT)
54 #define IPC_STR_TYPE(x) (x << IPC_STR_TYPE_SHIFT)
55 #define IPC_STR_ID_SHIFT 16
56 #define IPC_STR_ID_MASK (0xf << IPC_STR_ID_SHIFT)
57 #define IPC_STR_ID(x) (x << IPC_STR_ID_SHIFT)
59 /* Stream Message - Reply */
60 #define IPC_STR_REPLY_SHIFT 0
61 #define IPC_STR_REPLY_MASK (0x1f << IPC_STR_REPLY_SHIFT)
63 /* Stream Stage Message - Generic */
64 #define IPC_STG_TYPE_SHIFT 12
65 #define IPC_STG_TYPE_MASK (0xf << IPC_STG_TYPE_SHIFT)
66 #define IPC_STG_TYPE(x) (x << IPC_STG_TYPE_SHIFT)
67 #define IPC_STG_ID_SHIFT 10
68 #define IPC_STG_ID_MASK (0x3 << IPC_STG_ID_SHIFT)
69 #define IPC_STG_ID(x) (x << IPC_STG_ID_SHIFT)
71 /* Stream Stage Message - Reply */
72 #define IPC_STG_REPLY_SHIFT 0
73 #define IPC_STG_REPLY_MASK (0x1f << IPC_STG_REPLY_SHIFT)
75 /* Debug Log Message - Generic */
76 #define IPC_LOG_OP_SHIFT 20
77 #define IPC_LOG_OP_MASK (0xf << IPC_LOG_OP_SHIFT)
78 #define IPC_LOG_OP_TYPE(x) (x << IPC_LOG_OP_SHIFT)
79 #define IPC_LOG_ID_SHIFT 16
80 #define IPC_LOG_ID_MASK (0xf << IPC_LOG_ID_SHIFT)
81 #define IPC_LOG_ID(x) (x << IPC_LOG_ID_SHIFT)
84 #define IPC_MODULE_OPERATION_SHIFT 20
85 #define IPC_MODULE_OPERATION_MASK (0xf << IPC_MODULE_OPERATION_SHIFT)
86 #define IPC_MODULE_OPERATION(x) (x << IPC_MODULE_OPERATION_SHIFT)
88 #define IPC_MODULE_ID_SHIFT 16
89 #define IPC_MODULE_ID_MASK (0xf << IPC_MODULE_ID_SHIFT)
90 #define IPC_MODULE_ID(x) (x << IPC_MODULE_ID_SHIFT)
92 /* IPC message timeout (msecs) */
93 #define IPC_TIMEOUT_MSECS 300
94 #define IPC_BOOT_MSECS 200
95 #define IPC_MSG_WAIT 0
96 #define IPC_MSG_NOWAIT 1
98 /* Firmware Ready Message */
99 #define IPC_FW_READY (0x1 << 29)
100 #define IPC_STATUS_MASK (0x3 << 30)
102 #define IPC_EMPTY_LIST_SIZE 8
103 #define IPC_MAX_STREAMS 4
106 #define IPC_MAX_MAILBOX_BYTES 256
108 #define INVALID_STREAM_HW_ID 0xffffffff
110 /* Global Message - Types and Replies */
112 IPC_GLB_GET_FW_VERSION
= 0, /* Retrieves firmware version */
113 IPC_GLB_PERFORMANCE_MONITOR
= 1, /* Performance monitoring actions */
114 IPC_GLB_ALLOCATE_STREAM
= 3, /* Request to allocate new stream */
115 IPC_GLB_FREE_STREAM
= 4, /* Request to free stream */
116 IPC_GLB_GET_FW_CAPABILITIES
= 5, /* Retrieves firmware capabilities */
117 IPC_GLB_STREAM_MESSAGE
= 6, /* Message directed to stream or its stages */
118 /* Request to store firmware context during D0->D3 transition */
119 IPC_GLB_REQUEST_DUMP
= 7,
120 /* Request to restore firmware context during D3->D0 transition */
121 IPC_GLB_RESTORE_CONTEXT
= 8,
122 IPC_GLB_GET_DEVICE_FORMATS
= 9, /* Set device format */
123 IPC_GLB_SET_DEVICE_FORMATS
= 10, /* Get device format */
124 IPC_GLB_SHORT_REPLY
= 11,
125 IPC_GLB_ENTER_DX_STATE
= 12,
126 IPC_GLB_GET_MIXER_STREAM_INFO
= 13, /* Request mixer stream params */
127 IPC_GLB_DEBUG_LOG_MESSAGE
= 14, /* Message to or from the debug logger. */
128 IPC_GLB_MODULE_OPERATION
= 15, /* Message to loadable fw module */
129 IPC_GLB_REQUEST_TRANSFER
= 16, /* < Request Transfer for host */
130 IPC_GLB_MAX_IPC_MESSAGE_TYPE
= 17, /* Maximum message number */
134 IPC_GLB_REPLY_SUCCESS
= 0, /* The operation was successful. */
135 IPC_GLB_REPLY_ERROR_INVALID_PARAM
= 1, /* Invalid parameter was passed. */
136 IPC_GLB_REPLY_UNKNOWN_MESSAGE_TYPE
= 2, /* Uknown message type was resceived. */
137 IPC_GLB_REPLY_OUT_OF_RESOURCES
= 3, /* No resources to satisfy the request. */
138 IPC_GLB_REPLY_BUSY
= 4, /* The system or resource is busy. */
139 IPC_GLB_REPLY_PENDING
= 5, /* The action was scheduled for processing. */
140 IPC_GLB_REPLY_FAILURE
= 6, /* Critical error happened. */
141 IPC_GLB_REPLY_INVALID_REQUEST
= 7, /* Request can not be completed. */
142 IPC_GLB_REPLY_STAGE_UNINITIALIZED
= 8, /* Processing stage was uninitialized. */
143 IPC_GLB_REPLY_NOT_FOUND
= 9, /* Required resource can not be found. */
144 IPC_GLB_REPLY_SOURCE_NOT_STARTED
= 10, /* Source was not started. */
147 enum ipc_module_operation
{
148 IPC_MODULE_NOTIFICATION
= 0,
149 IPC_MODULE_ENABLE
= 1,
150 IPC_MODULE_DISABLE
= 2,
151 IPC_MODULE_GET_PARAMETER
= 3,
152 IPC_MODULE_SET_PARAMETER
= 4,
153 IPC_MODULE_GET_INFO
= 5,
154 IPC_MODULE_MAX_MESSAGE
157 /* Stream Message - Types */
158 enum ipc_str_operation
{
162 IPC_STR_STAGE_MESSAGE
= 3,
163 IPC_STR_NOTIFICATION
= 4,
167 /* Stream Stage Message Types */
168 enum ipc_stg_operation
{
169 IPC_STG_GET_VOLUME
= 0,
171 IPC_STG_SET_WRITE_POSITION
,
172 IPC_STG_SET_FX_ENABLE
,
173 IPC_STG_SET_FX_DISABLE
,
174 IPC_STG_SET_FX_GET_PARAM
,
175 IPC_STG_SET_FX_SET_PARAM
,
176 IPC_STG_SET_FX_GET_INFO
,
177 IPC_STG_MUTE_LOOPBACK
,
181 /* Stream Stage Message Types For Notification*/
182 enum ipc_stg_operation_notify
{
183 IPC_POSITION_CHANGED
= 0,
188 enum ipc_glitch_type
{
189 IPC_GLITCH_UNDERRUN
= 1,
190 IPC_GLITCH_DECODER_ERROR
,
191 IPC_GLITCH_DOUBLED_WRITE_POS
,
196 enum ipc_debug_operation
{
197 IPC_DEBUG_ENABLE_LOG
= 0,
198 IPC_DEBUG_DISABLE_LOG
= 1,
199 IPC_DEBUG_REQUEST_LOG_DUMP
= 2,
200 IPC_DEBUG_NOTIFY_LOG_DUMP
= 3,
201 IPC_DEBUG_MAX_DEBUG_LOG
205 struct sst_hsw_ipc_fw_ready
{
211 u8 fw_info
[IPC_MAX_MAILBOX_BYTES
- 5 * sizeof(u32
)];
212 } __attribute__((packed
));
214 struct sst_hsw_stream
;
217 /* Stream infomation */
218 struct sst_hsw_stream
{
220 struct sst_hsw_ipc_stream_alloc_req request
;
221 struct sst_hsw_ipc_stream_alloc_reply reply
;
222 struct sst_hsw_ipc_stream_free_req free_req
;
225 u32 mute_volume
[SST_HSW_NO_CHANNELS
];
226 u32 mute
[SST_HSW_NO_CHANNELS
];
234 /* Notification work */
235 struct work_struct notify_work
;
238 /* Position info from DSP */
239 struct sst_hsw_ipc_stream_set_position wpos
;
240 struct sst_hsw_ipc_stream_get_position rpos
;
241 struct sst_hsw_ipc_stream_glitch_position glitch
;
244 struct sst_hsw_ipc_volume_req vol_req
;
246 /* driver callback */
247 u32 (*notify_position
)(struct sst_hsw_stream
*stream
, void *data
);
250 /* record the fw read position when playback */
251 snd_pcm_uframes_t old_position
;
253 struct list_head node
;
256 /* FW log ring information */
257 struct sst_hsw_log_stream
{
259 unsigned char *dma_area
;
260 unsigned char *ring_descr
;
264 /* Notification work */
265 struct work_struct notify_work
;
266 wait_queue_head_t readers_wait_q
;
267 struct mutex rw_mutex
;
274 u32 config
[SST_HSW_FW_LOG_CONFIG_DWORDS
];
279 /* SST Haswell IPC data */
283 struct platform_device
*pdev_pcm
;
286 struct sst_hsw_ipc_fw_ready fw_ready
;
287 struct sst_hsw_ipc_fw_version version
;
289 struct sst_fw
*sst_fw
;
292 struct list_head stream_list
;
295 struct sst_hsw_ipc_stream_info_reply mixer_info
;
296 enum sst_hsw_volume_curve curve_type
;
298 u32 mute
[SST_HSW_NO_CHANNELS
];
299 u32 mute_volume
[SST_HSW_NO_CHANNELS
];
302 struct sst_hsw_ipc_dx_reply dx
;
304 dma_addr_t dx_context_paddr
;
305 enum sst_hsw_device_id dx_dev
;
306 enum sst_hsw_device_mclk dx_mclk
;
307 enum sst_hsw_device_mode dx_mode
;
308 u32 dx_clock_divider
;
311 wait_queue_head_t boot_wait
;
316 struct sst_generic_ipc ipc
;
319 struct sst_hsw_log_stream log_stream
;
321 /* flags bit field to track module state when resume from RTD3,
322 * each bit represent state (enabled/disabled) of single module */
323 u32 enabled_modules_rtd3
;
325 /* buffer to store parameter lines */
326 u32 param_idx_w
; /* write index */
327 u32 param_idx_r
; /* read index */
328 u8 param_buf
[WAVES_PARAM_LINES
][WAVES_PARAM_COUNT
];
331 #define CREATE_TRACE_POINTS
332 #include <trace/events/hswadsp.h>
334 static inline u32
msg_get_global_type(u32 msg
)
336 return (msg
& IPC_GLB_TYPE_MASK
) >> IPC_GLB_TYPE_SHIFT
;
339 static inline u32
msg_get_global_reply(u32 msg
)
341 return (msg
& IPC_GLB_REPLY_MASK
) >> IPC_GLB_REPLY_SHIFT
;
344 static inline u32
msg_get_stream_type(u32 msg
)
346 return (msg
& IPC_STR_TYPE_MASK
) >> IPC_STR_TYPE_SHIFT
;
349 static inline u32
msg_get_stage_type(u32 msg
)
351 return (msg
& IPC_STG_TYPE_MASK
) >> IPC_STG_TYPE_SHIFT
;
354 static inline u32
msg_get_stream_id(u32 msg
)
356 return (msg
& IPC_STR_ID_MASK
) >> IPC_STR_ID_SHIFT
;
359 static inline u32
msg_get_notify_reason(u32 msg
)
361 return (msg
& IPC_STG_TYPE_MASK
) >> IPC_STG_TYPE_SHIFT
;
364 static inline u32
msg_get_module_operation(u32 msg
)
366 return (msg
& IPC_MODULE_OPERATION_MASK
) >> IPC_MODULE_OPERATION_SHIFT
;
369 static inline u32
msg_get_module_id(u32 msg
)
371 return (msg
& IPC_MODULE_ID_MASK
) >> IPC_MODULE_ID_SHIFT
;
374 u32
create_channel_map(enum sst_hsw_channel_config config
)
377 case SST_HSW_CHANNEL_CONFIG_MONO
:
378 return (0xFFFFFFF0 | SST_HSW_CHANNEL_CENTER
);
379 case SST_HSW_CHANNEL_CONFIG_STEREO
:
380 return (0xFFFFFF00 | SST_HSW_CHANNEL_LEFT
381 | (SST_HSW_CHANNEL_RIGHT
<< 4));
382 case SST_HSW_CHANNEL_CONFIG_2_POINT_1
:
383 return (0xFFFFF000 | SST_HSW_CHANNEL_LEFT
384 | (SST_HSW_CHANNEL_RIGHT
<< 4)
385 | (SST_HSW_CHANNEL_LFE
<< 8 ));
386 case SST_HSW_CHANNEL_CONFIG_3_POINT_0
:
387 return (0xFFFFF000 | SST_HSW_CHANNEL_LEFT
388 | (SST_HSW_CHANNEL_CENTER
<< 4)
389 | (SST_HSW_CHANNEL_RIGHT
<< 8));
390 case SST_HSW_CHANNEL_CONFIG_3_POINT_1
:
391 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
392 | (SST_HSW_CHANNEL_CENTER
<< 4)
393 | (SST_HSW_CHANNEL_RIGHT
<< 8)
394 | (SST_HSW_CHANNEL_LFE
<< 12));
395 case SST_HSW_CHANNEL_CONFIG_QUATRO
:
396 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
397 | (SST_HSW_CHANNEL_RIGHT
<< 4)
398 | (SST_HSW_CHANNEL_LEFT_SURROUND
<< 8)
399 | (SST_HSW_CHANNEL_RIGHT_SURROUND
<< 12));
400 case SST_HSW_CHANNEL_CONFIG_4_POINT_0
:
401 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
402 | (SST_HSW_CHANNEL_CENTER
<< 4)
403 | (SST_HSW_CHANNEL_RIGHT
<< 8)
404 | (SST_HSW_CHANNEL_CENTER_SURROUND
<< 12));
405 case SST_HSW_CHANNEL_CONFIG_5_POINT_0
:
406 return (0xFFF00000 | SST_HSW_CHANNEL_LEFT
407 | (SST_HSW_CHANNEL_CENTER
<< 4)
408 | (SST_HSW_CHANNEL_RIGHT
<< 8)
409 | (SST_HSW_CHANNEL_LEFT_SURROUND
<< 12)
410 | (SST_HSW_CHANNEL_RIGHT_SURROUND
<< 16));
411 case SST_HSW_CHANNEL_CONFIG_5_POINT_1
:
412 return (0xFF000000 | SST_HSW_CHANNEL_CENTER
413 | (SST_HSW_CHANNEL_LEFT
<< 4)
414 | (SST_HSW_CHANNEL_RIGHT
<< 8)
415 | (SST_HSW_CHANNEL_LEFT_SURROUND
<< 12)
416 | (SST_HSW_CHANNEL_RIGHT_SURROUND
<< 16)
417 | (SST_HSW_CHANNEL_LFE
<< 20));
418 case SST_HSW_CHANNEL_CONFIG_DUAL_MONO
:
419 return (0xFFFFFF00 | SST_HSW_CHANNEL_LEFT
420 | (SST_HSW_CHANNEL_LEFT
<< 4));
426 static struct sst_hsw_stream
*get_stream_by_id(struct sst_hsw
*hsw
,
429 struct sst_hsw_stream
*stream
;
431 list_for_each_entry(stream
, &hsw
->stream_list
, node
) {
432 if (stream
->reply
.stream_hw_id
== stream_id
)
439 static void hsw_fw_ready(struct sst_hsw
*hsw
, u32 header
)
441 struct sst_hsw_ipc_fw_ready fw_ready
;
443 u8 fw_info
[IPC_MAX_MAILBOX_BYTES
- 5 * sizeof(u32
)];
444 char *tmp
[5], *pinfo
;
447 offset
= (header
& 0x1FFFFFFF) << 3;
449 dev_dbg(hsw
->dev
, "ipc: DSP is ready 0x%8.8x offset %d\n",
452 /* copy data from the DSP FW ready offset */
453 sst_dsp_read(hsw
->dsp
, &fw_ready
, offset
, sizeof(fw_ready
));
455 sst_dsp_mailbox_init(hsw
->dsp
, fw_ready
.inbox_offset
,
456 fw_ready
.inbox_size
, fw_ready
.outbox_offset
,
457 fw_ready
.outbox_size
);
459 hsw
->boot_complete
= true;
460 wake_up(&hsw
->boot_wait
);
462 dev_dbg(hsw
->dev
, " mailbox upstream 0x%x - size 0x%x\n",
463 fw_ready
.inbox_offset
, fw_ready
.inbox_size
);
464 dev_dbg(hsw
->dev
, " mailbox downstream 0x%x - size 0x%x\n",
465 fw_ready
.outbox_offset
, fw_ready
.outbox_size
);
466 if (fw_ready
.fw_info_size
< sizeof(fw_ready
.fw_info
)) {
467 fw_ready
.fw_info
[fw_ready
.fw_info_size
] = 0;
468 dev_dbg(hsw
->dev
, " Firmware info: %s \n", fw_ready
.fw_info
);
470 /* log the FW version info got from the mailbox here. */
471 memcpy(fw_info
, fw_ready
.fw_info
, fw_ready
.fw_info_size
);
473 for (i
= 0; i
< ARRAY_SIZE(tmp
); i
++)
474 tmp
[i
] = strsep(&pinfo
, " ");
475 dev_info(hsw
->dev
, "FW loaded, mailbox readback FW info: type %s, - "
476 "version: %s.%s, build %s, source commit id: %s\n",
477 tmp
[0], tmp
[1], tmp
[2], tmp
[3], tmp
[4]);
481 static void hsw_notification_work(struct work_struct
*work
)
483 struct sst_hsw_stream
*stream
= container_of(work
,
484 struct sst_hsw_stream
, notify_work
);
485 struct sst_hsw_ipc_stream_glitch_position
*glitch
= &stream
->glitch
;
486 struct sst_hsw_ipc_stream_get_position
*pos
= &stream
->rpos
;
487 struct sst_hsw
*hsw
= stream
->hsw
;
490 reason
= msg_get_notify_reason(stream
->header
);
494 trace_ipc_notification("DSP stream under/overrun",
495 stream
->reply
.stream_hw_id
);
496 sst_dsp_inbox_read(hsw
->dsp
, glitch
, sizeof(*glitch
));
498 dev_err(hsw
->dev
, "glitch %d pos 0x%x write pos 0x%x\n",
499 glitch
->glitch_type
, glitch
->present_pos
,
503 case IPC_POSITION_CHANGED
:
504 trace_ipc_notification("DSP stream position changed for",
505 stream
->reply
.stream_hw_id
);
506 sst_dsp_inbox_read(hsw
->dsp
, pos
, sizeof(*pos
));
508 if (stream
->notify_position
)
509 stream
->notify_position(stream
, stream
->pdata
);
513 dev_err(hsw
->dev
, "error: unknown notification 0x%x\n",
518 /* tell DSP that notification has been handled */
519 sst_dsp_shim_update_bits(hsw
->dsp
, SST_IPCD
,
520 SST_IPCD_BUSY
| SST_IPCD_DONE
, SST_IPCD_DONE
);
522 /* unmask busy interrupt */
523 sst_dsp_shim_update_bits(hsw
->dsp
, SST_IMRX
, SST_IMRX_BUSY
, 0);
526 static void hsw_stream_update(struct sst_hsw
*hsw
, struct ipc_message
*msg
)
528 struct sst_hsw_stream
*stream
;
529 u32 header
= msg
->header
& ~(IPC_STATUS_MASK
| IPC_GLB_REPLY_MASK
);
530 u32 stream_id
= msg_get_stream_id(header
);
531 u32 stream_msg
= msg_get_stream_type(header
);
533 stream
= get_stream_by_id(hsw
, stream_id
);
537 switch (stream_msg
) {
538 case IPC_STR_STAGE_MESSAGE
:
539 case IPC_STR_NOTIFICATION
:
542 trace_ipc_notification("stream reset", stream
->reply
.stream_hw_id
);
545 stream
->running
= false;
546 trace_ipc_notification("stream paused",
547 stream
->reply
.stream_hw_id
);
550 stream
->running
= true;
551 trace_ipc_notification("stream running",
552 stream
->reply
.stream_hw_id
);
557 static int hsw_process_reply(struct sst_hsw
*hsw
, u32 header
)
559 struct ipc_message
*msg
;
560 u32 reply
= msg_get_global_reply(header
);
562 trace_ipc_reply("processing -->", header
);
564 msg
= sst_ipc_reply_find_msg(&hsw
->ipc
, header
);
566 trace_ipc_error("error: can't find message header", header
);
570 /* first process the header */
572 case IPC_GLB_REPLY_PENDING
:
573 trace_ipc_pending_reply("received", header
);
575 hsw
->ipc
.pending
= true;
577 case IPC_GLB_REPLY_SUCCESS
:
579 trace_ipc_pending_reply("completed", header
);
580 sst_dsp_inbox_read(hsw
->dsp
, msg
->rx_data
,
582 hsw
->ipc
.pending
= false;
584 /* copy data from the DSP */
585 sst_dsp_outbox_read(hsw
->dsp
, msg
->rx_data
,
589 /* these will be rare - but useful for debug */
590 case IPC_GLB_REPLY_UNKNOWN_MESSAGE_TYPE
:
591 trace_ipc_error("error: unknown message type", header
);
592 msg
->errno
= -EBADMSG
;
594 case IPC_GLB_REPLY_OUT_OF_RESOURCES
:
595 trace_ipc_error("error: out of resources", header
);
596 msg
->errno
= -ENOMEM
;
598 case IPC_GLB_REPLY_BUSY
:
599 trace_ipc_error("error: reply busy", header
);
602 case IPC_GLB_REPLY_FAILURE
:
603 trace_ipc_error("error: reply failure", header
);
604 msg
->errno
= -EINVAL
;
606 case IPC_GLB_REPLY_STAGE_UNINITIALIZED
:
607 trace_ipc_error("error: stage uninitialized", header
);
608 msg
->errno
= -EINVAL
;
610 case IPC_GLB_REPLY_NOT_FOUND
:
611 trace_ipc_error("error: reply not found", header
);
612 msg
->errno
= -EINVAL
;
614 case IPC_GLB_REPLY_SOURCE_NOT_STARTED
:
615 trace_ipc_error("error: source not started", header
);
616 msg
->errno
= -EINVAL
;
618 case IPC_GLB_REPLY_INVALID_REQUEST
:
619 trace_ipc_error("error: invalid request", header
);
620 msg
->errno
= -EINVAL
;
622 case IPC_GLB_REPLY_ERROR_INVALID_PARAM
:
623 trace_ipc_error("error: invalid parameter", header
);
624 msg
->errno
= -EINVAL
;
627 trace_ipc_error("error: unknown reply", header
);
628 msg
->errno
= -EINVAL
;
632 /* update any stream states */
633 if (msg_get_global_type(header
) == IPC_GLB_STREAM_MESSAGE
)
634 hsw_stream_update(hsw
, msg
);
636 /* wake up and return the error if we have waiters on this message ? */
637 list_del(&msg
->list
);
638 sst_ipc_tx_msg_reply_complete(&hsw
->ipc
, msg
);
643 static int hsw_module_message(struct sst_hsw
*hsw
, u32 header
)
645 u32 operation
, module_id
;
648 operation
= msg_get_module_operation(header
);
649 module_id
= msg_get_module_id(header
);
650 dev_dbg(hsw
->dev
, "received module message header: 0x%8.8x\n",
652 dev_dbg(hsw
->dev
, "operation: 0x%8.8x module_id: 0x%8.8x\n",
653 operation
, module_id
);
656 case IPC_MODULE_NOTIFICATION
:
657 dev_dbg(hsw
->dev
, "module notification received");
661 handled
= hsw_process_reply(hsw
, header
);
668 static int hsw_stream_message(struct sst_hsw
*hsw
, u32 header
)
670 u32 stream_msg
, stream_id
, stage_type
;
671 struct sst_hsw_stream
*stream
;
674 stream_msg
= msg_get_stream_type(header
);
675 stream_id
= msg_get_stream_id(header
);
676 stage_type
= msg_get_stage_type(header
);
678 stream
= get_stream_by_id(hsw
, stream_id
);
682 stream
->header
= header
;
684 switch (stream_msg
) {
685 case IPC_STR_STAGE_MESSAGE
:
686 dev_err(hsw
->dev
, "error: stage msg not implemented 0x%8.8x\n",
689 case IPC_STR_NOTIFICATION
:
690 schedule_work(&stream
->notify_work
);
693 /* handle pending message complete request */
694 handled
= hsw_process_reply(hsw
, header
);
701 static int hsw_log_message(struct sst_hsw
*hsw
, u32 header
)
703 u32 operation
= (header
& IPC_LOG_OP_MASK
) >> IPC_LOG_OP_SHIFT
;
704 struct sst_hsw_log_stream
*stream
= &hsw
->log_stream
;
707 if (operation
!= IPC_DEBUG_REQUEST_LOG_DUMP
) {
709 "error: log msg not implemented 0x%8.8x\n", header
);
713 mutex_lock(&stream
->rw_mutex
);
714 stream
->last_pos
= stream
->curr_pos
;
716 hsw
->dsp
, &stream
->curr_pos
, sizeof(stream
->curr_pos
));
717 mutex_unlock(&stream
->rw_mutex
);
719 schedule_work(&stream
->notify_work
);
724 static int hsw_process_notification(struct sst_hsw
*hsw
)
726 struct sst_dsp
*sst
= hsw
->dsp
;
730 header
= sst_dsp_shim_read_unlocked(sst
, SST_IPCD
);
731 type
= msg_get_global_type(header
);
733 trace_ipc_request("processing -->", header
);
735 /* FW Ready is a special case */
736 if (!hsw
->boot_complete
&& header
& IPC_FW_READY
) {
737 hsw_fw_ready(hsw
, header
);
742 case IPC_GLB_GET_FW_VERSION
:
743 case IPC_GLB_ALLOCATE_STREAM
:
744 case IPC_GLB_FREE_STREAM
:
745 case IPC_GLB_GET_FW_CAPABILITIES
:
746 case IPC_GLB_REQUEST_DUMP
:
747 case IPC_GLB_GET_DEVICE_FORMATS
:
748 case IPC_GLB_SET_DEVICE_FORMATS
:
749 case IPC_GLB_ENTER_DX_STATE
:
750 case IPC_GLB_GET_MIXER_STREAM_INFO
:
751 case IPC_GLB_MAX_IPC_MESSAGE_TYPE
:
752 case IPC_GLB_RESTORE_CONTEXT
:
753 case IPC_GLB_SHORT_REPLY
:
754 dev_err(hsw
->dev
, "error: message type %d header 0x%x\n",
757 case IPC_GLB_STREAM_MESSAGE
:
758 handled
= hsw_stream_message(hsw
, header
);
760 case IPC_GLB_DEBUG_LOG_MESSAGE
:
761 handled
= hsw_log_message(hsw
, header
);
763 case IPC_GLB_MODULE_OPERATION
:
764 handled
= hsw_module_message(hsw
, header
);
767 dev_err(hsw
->dev
, "error: unexpected type %d hdr 0x%8.8x\n",
775 static irqreturn_t
hsw_irq_thread(int irq
, void *context
)
777 struct sst_dsp
*sst
= (struct sst_dsp
*) context
;
778 struct sst_hsw
*hsw
= sst_dsp_get_thread_context(sst
);
779 struct sst_generic_ipc
*ipc
= &hsw
->ipc
;
783 spin_lock_irqsave(&sst
->spinlock
, flags
);
785 ipcx
= sst_dsp_ipc_msg_rx(hsw
->dsp
);
786 ipcd
= sst_dsp_shim_read_unlocked(sst
, SST_IPCD
);
788 /* reply message from DSP */
789 if (ipcx
& SST_IPCX_DONE
) {
791 /* Handle Immediate reply from DSP Core */
792 hsw_process_reply(hsw
, ipcx
);
794 /* clear DONE bit - tell DSP we have completed */
795 sst_dsp_shim_update_bits_unlocked(sst
, SST_IPCX
,
798 /* unmask Done interrupt */
799 sst_dsp_shim_update_bits_unlocked(sst
, SST_IMRX
,
803 /* new message from DSP */
804 if (ipcd
& SST_IPCD_BUSY
) {
806 /* Handle Notification and Delayed reply from DSP Core */
807 hsw_process_notification(hsw
);
809 /* clear BUSY bit and set DONE bit - accept new messages */
810 sst_dsp_shim_update_bits_unlocked(sst
, SST_IPCD
,
811 SST_IPCD_BUSY
| SST_IPCD_DONE
, SST_IPCD_DONE
);
813 /* unmask busy interrupt */
814 sst_dsp_shim_update_bits_unlocked(sst
, SST_IMRX
,
818 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
820 /* continue to send any remaining messages... */
821 queue_kthread_work(&ipc
->kworker
, &ipc
->kwork
);
826 int sst_hsw_fw_get_version(struct sst_hsw
*hsw
,
827 struct sst_hsw_ipc_fw_version
*version
)
831 ret
= sst_ipc_tx_message_wait(&hsw
->ipc
,
832 IPC_GLB_TYPE(IPC_GLB_GET_FW_VERSION
),
833 NULL
, 0, version
, sizeof(*version
));
835 dev_err(hsw
->dev
, "error: get version failed\n");
841 int sst_hsw_stream_get_volume(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
842 u32 stage_id
, u32 channel
, u32
*volume
)
847 sst_dsp_read(hsw
->dsp
, volume
,
848 stream
->reply
.volume_register_address
[channel
],
855 int sst_hsw_stream_set_volume(struct sst_hsw
*hsw
,
856 struct sst_hsw_stream
*stream
, u32 stage_id
, u32 channel
, u32 volume
)
858 struct sst_hsw_ipc_volume_req
*req
;
862 trace_ipc_request("set stream volume", stream
->reply
.stream_hw_id
);
864 if (channel
>= 2 && channel
!= SST_HSW_CHANNELS_ALL
)
867 header
= IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE
) |
868 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE
);
869 header
|= (stream
->reply
.stream_hw_id
<< IPC_STR_ID_SHIFT
);
870 header
|= (IPC_STG_SET_VOLUME
<< IPC_STG_TYPE_SHIFT
);
871 header
|= (stage_id
<< IPC_STG_ID_SHIFT
);
873 req
= &stream
->vol_req
;
874 req
->target_volume
= volume
;
876 /* set both at same time ? */
877 if (channel
== SST_HSW_CHANNELS_ALL
) {
878 if (hsw
->mute
[0] && hsw
->mute
[1]) {
879 hsw
->mute_volume
[0] = hsw
->mute_volume
[1] = volume
;
881 } else if (hsw
->mute
[0])
883 else if (hsw
->mute
[1])
886 req
->channel
= SST_HSW_CHANNELS_ALL
;
888 /* set only 1 channel */
889 if (hsw
->mute
[channel
]) {
890 hsw
->mute_volume
[channel
] = volume
;
893 req
->channel
= channel
;
896 ret
= sst_ipc_tx_message_wait(&hsw
->ipc
, header
, req
,
897 sizeof(*req
), NULL
, 0);
899 dev_err(hsw
->dev
, "error: set stream volume failed\n");
906 int sst_hsw_mixer_get_volume(struct sst_hsw
*hsw
, u32 stage_id
, u32 channel
,
912 sst_dsp_read(hsw
->dsp
, volume
,
913 hsw
->mixer_info
.volume_register_address
[channel
],
919 /* global mixer volume */
920 int sst_hsw_mixer_set_volume(struct sst_hsw
*hsw
, u32 stage_id
, u32 channel
,
923 struct sst_hsw_ipc_volume_req req
;
927 trace_ipc_request("set mixer volume", volume
);
929 if (channel
>= 2 && channel
!= SST_HSW_CHANNELS_ALL
)
932 /* set both at same time ? */
933 if (channel
== SST_HSW_CHANNELS_ALL
) {
934 if (hsw
->mute
[0] && hsw
->mute
[1]) {
935 hsw
->mute_volume
[0] = hsw
->mute_volume
[1] = volume
;
937 } else if (hsw
->mute
[0])
939 else if (hsw
->mute
[1])
942 req
.channel
= SST_HSW_CHANNELS_ALL
;
944 /* set only 1 channel */
945 if (hsw
->mute
[channel
]) {
946 hsw
->mute_volume
[channel
] = volume
;
949 req
.channel
= channel
;
952 header
= IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE
) |
953 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE
);
954 header
|= (hsw
->mixer_info
.mixer_hw_id
<< IPC_STR_ID_SHIFT
);
955 header
|= (IPC_STG_SET_VOLUME
<< IPC_STG_TYPE_SHIFT
);
956 header
|= (stage_id
<< IPC_STG_ID_SHIFT
);
958 req
.curve_duration
= hsw
->curve_duration
;
959 req
.curve_type
= hsw
->curve_type
;
960 req
.target_volume
= volume
;
962 ret
= sst_ipc_tx_message_wait(&hsw
->ipc
, header
, &req
,
963 sizeof(req
), NULL
, 0);
965 dev_err(hsw
->dev
, "error: set mixer volume failed\n");
973 struct sst_hsw_stream
*sst_hsw_stream_new(struct sst_hsw
*hsw
, int id
,
974 u32 (*notify_position
)(struct sst_hsw_stream
*stream
, void *data
),
977 struct sst_hsw_stream
*stream
;
978 struct sst_dsp
*sst
= hsw
->dsp
;
981 stream
= kzalloc(sizeof(*stream
), GFP_KERNEL
);
985 spin_lock_irqsave(&sst
->spinlock
, flags
);
986 stream
->reply
.stream_hw_id
= INVALID_STREAM_HW_ID
;
987 list_add(&stream
->node
, &hsw
->stream_list
);
988 stream
->notify_position
= notify_position
;
989 stream
->pdata
= data
;
991 stream
->host_id
= id
;
993 /* work to process notification messages */
994 INIT_WORK(&stream
->notify_work
, hsw_notification_work
);
995 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
1000 int sst_hsw_stream_free(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
)
1004 struct sst_dsp
*sst
= hsw
->dsp
;
1005 unsigned long flags
;
1008 dev_warn(hsw
->dev
, "warning: stream is NULL, no stream to free, ignore it.\n");
1012 /* dont free DSP streams that are not commited */
1013 if (!stream
->commited
)
1016 trace_ipc_request("stream free", stream
->host_id
);
1018 stream
->free_req
.stream_id
= stream
->reply
.stream_hw_id
;
1019 header
= IPC_GLB_TYPE(IPC_GLB_FREE_STREAM
);
1021 ret
= sst_ipc_tx_message_wait(&hsw
->ipc
, header
, &stream
->free_req
,
1022 sizeof(stream
->free_req
), NULL
, 0);
1024 dev_err(hsw
->dev
, "error: free stream %d failed\n",
1025 stream
->free_req
.stream_id
);
1029 trace_hsw_stream_free_req(stream
, &stream
->free_req
);
1032 cancel_work_sync(&stream
->notify_work
);
1033 spin_lock_irqsave(&sst
->spinlock
, flags
);
1034 list_del(&stream
->node
);
1036 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
1041 int sst_hsw_stream_set_bits(struct sst_hsw
*hsw
,
1042 struct sst_hsw_stream
*stream
, enum sst_hsw_bitdepth bits
)
1044 if (stream
->commited
) {
1045 dev_err(hsw
->dev
, "error: stream committed for set bits\n");
1049 stream
->request
.format
.bitdepth
= bits
;
1053 int sst_hsw_stream_set_channels(struct sst_hsw
*hsw
,
1054 struct sst_hsw_stream
*stream
, int channels
)
1056 if (stream
->commited
) {
1057 dev_err(hsw
->dev
, "error: stream committed for set channels\n");
1061 stream
->request
.format
.ch_num
= channels
;
1065 int sst_hsw_stream_set_rate(struct sst_hsw
*hsw
,
1066 struct sst_hsw_stream
*stream
, int rate
)
1068 if (stream
->commited
) {
1069 dev_err(hsw
->dev
, "error: stream committed for set rate\n");
1073 stream
->request
.format
.frequency
= rate
;
1077 int sst_hsw_stream_set_map_config(struct sst_hsw
*hsw
,
1078 struct sst_hsw_stream
*stream
, u32 map
,
1079 enum sst_hsw_channel_config config
)
1081 if (stream
->commited
) {
1082 dev_err(hsw
->dev
, "error: stream committed for set map\n");
1086 stream
->request
.format
.map
= map
;
1087 stream
->request
.format
.config
= config
;
1091 int sst_hsw_stream_set_style(struct sst_hsw
*hsw
,
1092 struct sst_hsw_stream
*stream
, enum sst_hsw_interleaving style
)
1094 if (stream
->commited
) {
1095 dev_err(hsw
->dev
, "error: stream committed for set style\n");
1099 stream
->request
.format
.style
= style
;
1103 int sst_hsw_stream_set_valid(struct sst_hsw
*hsw
,
1104 struct sst_hsw_stream
*stream
, u32 bits
)
1106 if (stream
->commited
) {
1107 dev_err(hsw
->dev
, "error: stream committed for set valid bits\n");
1111 stream
->request
.format
.valid_bit
= bits
;
1115 /* Stream Configuration */
1116 int sst_hsw_stream_format(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1117 enum sst_hsw_stream_path_id path_id
,
1118 enum sst_hsw_stream_type stream_type
,
1119 enum sst_hsw_stream_format format_id
)
1121 if (stream
->commited
) {
1122 dev_err(hsw
->dev
, "error: stream committed for set format\n");
1126 stream
->request
.path_id
= path_id
;
1127 stream
->request
.stream_type
= stream_type
;
1128 stream
->request
.format_id
= format_id
;
1130 trace_hsw_stream_alloc_request(stream
, &stream
->request
);
1135 int sst_hsw_stream_buffer(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1136 u32 ring_pt_address
, u32 num_pages
,
1137 u32 ring_size
, u32 ring_offset
, u32 ring_first_pfn
)
1139 if (stream
->commited
) {
1140 dev_err(hsw
->dev
, "error: stream committed for buffer\n");
1144 stream
->request
.ringinfo
.ring_pt_address
= ring_pt_address
;
1145 stream
->request
.ringinfo
.num_pages
= num_pages
;
1146 stream
->request
.ringinfo
.ring_size
= ring_size
;
1147 stream
->request
.ringinfo
.ring_offset
= ring_offset
;
1148 stream
->request
.ringinfo
.ring_first_pfn
= ring_first_pfn
;
1150 trace_hsw_stream_buffer(stream
);
1155 int sst_hsw_stream_set_module_info(struct sst_hsw
*hsw
,
1156 struct sst_hsw_stream
*stream
, struct sst_module_runtime
*runtime
)
1158 struct sst_hsw_module_map
*map
= &stream
->request
.map
;
1159 struct sst_dsp
*dsp
= sst_hsw_get_dsp(hsw
);
1160 struct sst_module
*module
= runtime
->module
;
1162 if (stream
->commited
) {
1163 dev_err(hsw
->dev
, "error: stream committed for set module\n");
1167 /* only support initial module atm */
1168 map
->module_entries_count
= 1;
1169 map
->module_entries
[0].module_id
= module
->id
;
1170 map
->module_entries
[0].entry_point
= module
->entry
;
1172 stream
->request
.persistent_mem
.offset
=
1173 sst_dsp_get_offset(dsp
, runtime
->persistent_offset
, SST_MEM_DRAM
);
1174 stream
->request
.persistent_mem
.size
= module
->persistent_size
;
1176 stream
->request
.scratch_mem
.offset
=
1177 sst_dsp_get_offset(dsp
, dsp
->scratch_offset
, SST_MEM_DRAM
);
1178 stream
->request
.scratch_mem
.size
= dsp
->scratch_size
;
1180 dev_dbg(hsw
->dev
, "module %d runtime %d using:\n", module
->id
,
1182 dev_dbg(hsw
->dev
, " persistent offset 0x%x bytes 0x%x\n",
1183 stream
->request
.persistent_mem
.offset
,
1184 stream
->request
.persistent_mem
.size
);
1185 dev_dbg(hsw
->dev
, " scratch offset 0x%x bytes 0x%x\n",
1186 stream
->request
.scratch_mem
.offset
,
1187 stream
->request
.scratch_mem
.size
);
1192 int sst_hsw_stream_commit(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
)
1194 struct sst_hsw_ipc_stream_alloc_req
*str_req
= &stream
->request
;
1195 struct sst_hsw_ipc_stream_alloc_reply
*reply
= &stream
->reply
;
1200 dev_warn(hsw
->dev
, "warning: stream is NULL, no stream to commit, ignore it.\n");
1204 if (stream
->commited
) {
1205 dev_warn(hsw
->dev
, "warning: stream is already committed, ignore it.\n");
1209 trace_ipc_request("stream alloc", stream
->host_id
);
1211 header
= IPC_GLB_TYPE(IPC_GLB_ALLOCATE_STREAM
);
1213 ret
= sst_ipc_tx_message_wait(&hsw
->ipc
, header
, str_req
,
1214 sizeof(*str_req
), reply
, sizeof(*reply
));
1216 dev_err(hsw
->dev
, "error: stream commit failed\n");
1220 stream
->commited
= 1;
1221 trace_hsw_stream_alloc_reply(stream
);
1226 snd_pcm_uframes_t
sst_hsw_stream_get_old_position(struct sst_hsw
*hsw
,
1227 struct sst_hsw_stream
*stream
)
1229 return stream
->old_position
;
1232 void sst_hsw_stream_set_old_position(struct sst_hsw
*hsw
,
1233 struct sst_hsw_stream
*stream
, snd_pcm_uframes_t val
)
1235 stream
->old_position
= val
;
1238 bool sst_hsw_stream_get_silence_start(struct sst_hsw
*hsw
,
1239 struct sst_hsw_stream
*stream
)
1241 return stream
->play_silence
;
1244 void sst_hsw_stream_set_silence_start(struct sst_hsw
*hsw
,
1245 struct sst_hsw_stream
*stream
, bool val
)
1247 stream
->play_silence
= val
;
1250 /* Stream Information - these calls could be inline but we want the IPC
1251 ABI to be opaque to client PCM drivers to cope with any future ABI changes */
1252 int sst_hsw_mixer_get_info(struct sst_hsw
*hsw
)
1254 struct sst_hsw_ipc_stream_info_reply
*reply
;
1258 reply
= &hsw
->mixer_info
;
1259 header
= IPC_GLB_TYPE(IPC_GLB_GET_MIXER_STREAM_INFO
);
1261 trace_ipc_request("get global mixer info", 0);
1263 ret
= sst_ipc_tx_message_wait(&hsw
->ipc
, header
, NULL
, 0,
1264 reply
, sizeof(*reply
));
1266 dev_err(hsw
->dev
, "error: get stream info failed\n");
1270 trace_hsw_mixer_info_reply(reply
);
1275 /* Send stream command */
1276 static int sst_hsw_stream_operations(struct sst_hsw
*hsw
, int type
,
1277 int stream_id
, int wait
)
1281 header
= IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE
) | IPC_STR_TYPE(type
);
1282 header
|= (stream_id
<< IPC_STR_ID_SHIFT
);
1285 return sst_ipc_tx_message_wait(&hsw
->ipc
, header
,
1288 return sst_ipc_tx_message_nowait(&hsw
->ipc
, header
, NULL
, 0);
1291 /* Stream ALSA trigger operations */
1292 int sst_hsw_stream_pause(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1298 dev_warn(hsw
->dev
, "warning: stream is NULL, no stream to pause, ignore it.\n");
1302 trace_ipc_request("stream pause", stream
->reply
.stream_hw_id
);
1304 ret
= sst_hsw_stream_operations(hsw
, IPC_STR_PAUSE
,
1305 stream
->reply
.stream_hw_id
, wait
);
1307 dev_err(hsw
->dev
, "error: failed to pause stream %d\n",
1308 stream
->reply
.stream_hw_id
);
1313 int sst_hsw_stream_resume(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1319 dev_warn(hsw
->dev
, "warning: stream is NULL, no stream to resume, ignore it.\n");
1323 trace_ipc_request("stream resume", stream
->reply
.stream_hw_id
);
1325 ret
= sst_hsw_stream_operations(hsw
, IPC_STR_RESUME
,
1326 stream
->reply
.stream_hw_id
, wait
);
1328 dev_err(hsw
->dev
, "error: failed to resume stream %d\n",
1329 stream
->reply
.stream_hw_id
);
1334 int sst_hsw_stream_reset(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
)
1336 int ret
, tries
= 10;
1339 dev_warn(hsw
->dev
, "warning: stream is NULL, no stream to reset, ignore it.\n");
1343 /* dont reset streams that are not commited */
1344 if (!stream
->commited
)
1347 /* wait for pause to complete before we reset the stream */
1348 while (stream
->running
&& tries
--)
1351 dev_err(hsw
->dev
, "error: reset stream %d still running\n",
1352 stream
->reply
.stream_hw_id
);
1356 trace_ipc_request("stream reset", stream
->reply
.stream_hw_id
);
1358 ret
= sst_hsw_stream_operations(hsw
, IPC_STR_RESET
,
1359 stream
->reply
.stream_hw_id
, 1);
1361 dev_err(hsw
->dev
, "error: failed to reset stream %d\n",
1362 stream
->reply
.stream_hw_id
);
1366 /* Stream pointer positions */
1367 u32
sst_hsw_get_dsp_position(struct sst_hsw
*hsw
,
1368 struct sst_hsw_stream
*stream
)
1372 sst_dsp_read(hsw
->dsp
, &rpos
,
1373 stream
->reply
.read_position_register_address
, sizeof(rpos
));
1378 /* Stream presentation (monotonic) positions */
1379 u64
sst_hsw_get_dsp_presentation_position(struct sst_hsw
*hsw
,
1380 struct sst_hsw_stream
*stream
)
1384 sst_dsp_read(hsw
->dsp
, &ppos
,
1385 stream
->reply
.presentation_position_register_address
,
1391 /* physical BE config */
1392 int sst_hsw_device_set_config(struct sst_hsw
*hsw
,
1393 enum sst_hsw_device_id dev
, enum sst_hsw_device_mclk mclk
,
1394 enum sst_hsw_device_mode mode
, u32 clock_divider
)
1396 struct sst_hsw_ipc_device_config_req config
;
1400 trace_ipc_request("set device config", dev
);
1402 hsw
->dx_dev
= config
.ssp_interface
= dev
;
1403 hsw
->dx_mclk
= config
.clock_frequency
= mclk
;
1404 hsw
->dx_mode
= config
.mode
= mode
;
1405 hsw
->dx_clock_divider
= config
.clock_divider
= clock_divider
;
1406 if (mode
== SST_HSW_DEVICE_TDM_CLOCK_MASTER
)
1407 config
.channels
= 4;
1409 config
.channels
= 2;
1411 trace_hsw_device_config_req(&config
);
1413 header
= IPC_GLB_TYPE(IPC_GLB_SET_DEVICE_FORMATS
);
1415 ret
= sst_ipc_tx_message_wait(&hsw
->ipc
, header
, &config
,
1416 sizeof(config
), NULL
, 0);
1418 dev_err(hsw
->dev
, "error: set device formats failed\n");
1422 EXPORT_SYMBOL_GPL(sst_hsw_device_set_config
);
1425 int sst_hsw_dx_set_state(struct sst_hsw
*hsw
,
1426 enum sst_hsw_dx_state state
, struct sst_hsw_ipc_dx_reply
*dx
)
1431 header
= IPC_GLB_TYPE(IPC_GLB_ENTER_DX_STATE
);
1434 trace_ipc_request("PM enter Dx state", state
);
1436 ret
= sst_ipc_tx_message_wait(&hsw
->ipc
, header
, &state_
,
1437 sizeof(state_
), dx
, sizeof(*dx
));
1439 dev_err(hsw
->dev
, "ipc: error set dx state %d failed\n", state
);
1443 for (item
= 0; item
< dx
->entries_no
; item
++) {
1445 "Item[%d] offset[%x] - size[%x] - source[%x]\n",
1446 item
, dx
->mem_info
[item
].offset
,
1447 dx
->mem_info
[item
].size
,
1448 dx
->mem_info
[item
].source
);
1450 dev_dbg(hsw
->dev
, "ipc: got %d entry numbers for state %d\n",
1451 dx
->entries_no
, state
);
1456 struct sst_module_runtime
*sst_hsw_runtime_module_create(struct sst_hsw
*hsw
,
1457 int mod_id
, int offset
)
1459 struct sst_dsp
*dsp
= hsw
->dsp
;
1460 struct sst_module
*module
;
1461 struct sst_module_runtime
*runtime
;
1464 module
= sst_module_get_from_id(dsp
, mod_id
);
1465 if (module
== NULL
) {
1466 dev_err(dsp
->dev
, "error: failed to get module %d for pcm\n",
1471 runtime
= sst_module_runtime_new(module
, mod_id
, NULL
);
1472 if (runtime
== NULL
) {
1473 dev_err(dsp
->dev
, "error: failed to create module %d runtime\n",
1478 err
= sst_module_runtime_alloc_blocks(runtime
, offset
);
1480 dev_err(dsp
->dev
, "error: failed to alloc blocks for module %d runtime\n",
1482 sst_module_runtime_free(runtime
);
1486 dev_dbg(dsp
->dev
, "runtime id %d created for module %d\n", runtime
->id
,
1491 void sst_hsw_runtime_module_free(struct sst_module_runtime
*runtime
)
1493 sst_module_runtime_free_blocks(runtime
);
1494 sst_module_runtime_free(runtime
);
1498 static int sst_hsw_dx_state_dump(struct sst_hsw
*hsw
)
1500 struct sst_dsp
*sst
= hsw
->dsp
;
1501 u32 item
, offset
, size
;
1504 trace_ipc_request("PM state dump. Items #", SST_HSW_MAX_DX_REGIONS
);
1506 if (hsw
->dx
.entries_no
> SST_HSW_MAX_DX_REGIONS
) {
1508 "error: number of FW context regions greater than %d\n",
1509 SST_HSW_MAX_DX_REGIONS
);
1510 memset(&hsw
->dx
, 0, sizeof(hsw
->dx
));
1514 ret
= sst_dsp_dma_get_channel(sst
, 0);
1516 dev_err(hsw
->dev
, "error: cant allocate dma channel %d\n", ret
);
1520 /* set on-demond mode on engine 0 channel 3 */
1521 sst_dsp_shim_update_bits(sst
, SST_HMDC
,
1522 SST_HMDC_HDDA_E0_ALLCH
| SST_HMDC_HDDA_E1_ALLCH
,
1523 SST_HMDC_HDDA_E0_ALLCH
| SST_HMDC_HDDA_E1_ALLCH
);
1525 for (item
= 0; item
< hsw
->dx
.entries_no
; item
++) {
1526 if (hsw
->dx
.mem_info
[item
].source
== SST_HSW_DX_TYPE_MEMORY_DUMP
1527 && hsw
->dx
.mem_info
[item
].offset
> DSP_DRAM_ADDR_OFFSET
1528 && hsw
->dx
.mem_info
[item
].offset
<
1529 DSP_DRAM_ADDR_OFFSET
+ SST_HSW_DX_CONTEXT_SIZE
) {
1531 offset
= hsw
->dx
.mem_info
[item
].offset
1532 - DSP_DRAM_ADDR_OFFSET
;
1533 size
= (hsw
->dx
.mem_info
[item
].size
+ 3) & (~3);
1535 ret
= sst_dsp_dma_copyfrom(sst
, hsw
->dx_context_paddr
+ offset
,
1536 sst
->addr
.lpe_base
+ offset
, size
);
1539 "error: FW context dump failed\n");
1540 memset(&hsw
->dx
, 0, sizeof(hsw
->dx
));
1547 sst_dsp_dma_put_channel(sst
);
1551 static int sst_hsw_dx_state_restore(struct sst_hsw
*hsw
)
1553 struct sst_dsp
*sst
= hsw
->dsp
;
1554 u32 item
, offset
, size
;
1557 for (item
= 0; item
< hsw
->dx
.entries_no
; item
++) {
1558 if (hsw
->dx
.mem_info
[item
].source
== SST_HSW_DX_TYPE_MEMORY_DUMP
1559 && hsw
->dx
.mem_info
[item
].offset
> DSP_DRAM_ADDR_OFFSET
1560 && hsw
->dx
.mem_info
[item
].offset
<
1561 DSP_DRAM_ADDR_OFFSET
+ SST_HSW_DX_CONTEXT_SIZE
) {
1563 offset
= hsw
->dx
.mem_info
[item
].offset
1564 - DSP_DRAM_ADDR_OFFSET
;
1565 size
= (hsw
->dx
.mem_info
[item
].size
+ 3) & (~3);
1567 ret
= sst_dsp_dma_copyto(sst
, sst
->addr
.lpe_base
+ offset
,
1568 hsw
->dx_context_paddr
+ offset
, size
);
1571 "error: FW context restore failed\n");
1580 int sst_hsw_dsp_load(struct sst_hsw
*hsw
)
1582 struct sst_dsp
*dsp
= hsw
->dsp
;
1583 struct sst_fw
*sst_fw
, *t
;
1586 dev_dbg(hsw
->dev
, "loading audio DSP....");
1588 ret
= sst_dsp_wake(dsp
);
1590 dev_err(hsw
->dev
, "error: failed to wake audio DSP\n");
1594 ret
= sst_dsp_dma_get_channel(dsp
, 0);
1596 dev_err(hsw
->dev
, "error: cant allocate dma channel %d\n", ret
);
1600 list_for_each_entry_safe_reverse(sst_fw
, t
, &dsp
->fw_list
, list
) {
1601 ret
= sst_fw_reload(sst_fw
);
1603 dev_err(hsw
->dev
, "error: SST FW reload failed\n");
1604 sst_dsp_dma_put_channel(dsp
);
1608 ret
= sst_block_alloc_scratch(hsw
->dsp
);
1612 sst_dsp_dma_put_channel(dsp
);
1616 static int sst_hsw_dsp_restore(struct sst_hsw
*hsw
)
1618 struct sst_dsp
*dsp
= hsw
->dsp
;
1621 dev_dbg(hsw
->dev
, "restoring audio DSP....");
1623 ret
= sst_dsp_dma_get_channel(dsp
, 0);
1625 dev_err(hsw
->dev
, "error: cant allocate dma channel %d\n", ret
);
1629 ret
= sst_hsw_dx_state_restore(hsw
);
1631 dev_err(hsw
->dev
, "error: SST FW context restore failed\n");
1632 sst_dsp_dma_put_channel(dsp
);
1635 sst_dsp_dma_put_channel(dsp
);
1637 /* wait for DSP boot completion */
1643 int sst_hsw_dsp_runtime_suspend(struct sst_hsw
*hsw
)
1647 dev_dbg(hsw
->dev
, "audio dsp runtime suspend\n");
1649 ret
= sst_hsw_dx_set_state(hsw
, SST_HSW_DX_STATE_D3
, &hsw
->dx
);
1653 sst_dsp_stall(hsw
->dsp
);
1655 ret
= sst_hsw_dx_state_dump(hsw
);
1659 sst_ipc_drop_all(&hsw
->ipc
);
1664 int sst_hsw_dsp_runtime_sleep(struct sst_hsw
*hsw
)
1666 struct sst_fw
*sst_fw
, *t
;
1667 struct sst_dsp
*dsp
= hsw
->dsp
;
1669 list_for_each_entry_safe(sst_fw
, t
, &dsp
->fw_list
, list
) {
1670 sst_fw_unload(sst_fw
);
1672 sst_block_free_scratch(dsp
);
1674 hsw
->boot_complete
= false;
1681 int sst_hsw_dsp_runtime_resume(struct sst_hsw
*hsw
)
1683 struct device
*dev
= hsw
->dev
;
1686 dev_dbg(dev
, "audio dsp runtime resume\n");
1688 if (hsw
->boot_complete
)
1689 return 1; /* tell caller no action is required */
1691 ret
= sst_hsw_dsp_restore(hsw
);
1693 dev_err(dev
, "error: audio DSP boot failure\n");
1695 sst_hsw_init_module_state(hsw
);
1697 ret
= wait_event_timeout(hsw
->boot_wait
, hsw
->boot_complete
,
1698 msecs_to_jiffies(IPC_BOOT_MSECS
));
1700 dev_err(hsw
->dev
, "error: audio DSP boot timeout IPCD 0x%x IPCX 0x%x\n",
1701 sst_dsp_shim_read_unlocked(hsw
->dsp
, SST_IPCD
),
1702 sst_dsp_shim_read_unlocked(hsw
->dsp
, SST_IPCX
));
1706 /* Set ADSP SSP port settings - sadly the FW does not store SSP port
1707 settings as part of the PM context. */
1708 ret
= sst_hsw_device_set_config(hsw
, hsw
->dx_dev
, hsw
->dx_mclk
,
1709 hsw
->dx_mode
, hsw
->dx_clock_divider
);
1711 dev_err(dev
, "error: SSP re-initialization failed\n");
1717 struct sst_dsp
*sst_hsw_get_dsp(struct sst_hsw
*hsw
)
1722 void sst_hsw_init_module_state(struct sst_hsw
*hsw
)
1724 struct sst_module
*module
;
1725 enum sst_hsw_module_id id
;
1727 /* the base fw contains several modules */
1728 for (id
= SST_HSW_MODULE_BASE_FW
; id
< SST_HSW_MAX_MODULE_ID
; id
++) {
1729 module
= sst_module_get_from_id(hsw
->dsp
, id
);
1731 /* module waves is active only after being enabled */
1732 if (id
== SST_HSW_MODULE_WAVES
)
1733 module
->state
= SST_MODULE_STATE_INITIALIZED
;
1735 module
->state
= SST_MODULE_STATE_ACTIVE
;
1740 bool sst_hsw_is_module_loaded(struct sst_hsw
*hsw
, u32 module_id
)
1742 struct sst_module
*module
;
1744 module
= sst_module_get_from_id(hsw
->dsp
, module_id
);
1745 if (module
== NULL
|| module
->state
== SST_MODULE_STATE_UNLOADED
)
1751 bool sst_hsw_is_module_active(struct sst_hsw
*hsw
, u32 module_id
)
1753 struct sst_module
*module
;
1755 module
= sst_module_get_from_id(hsw
->dsp
, module_id
);
1756 if (module
!= NULL
&& module
->state
== SST_MODULE_STATE_ACTIVE
)
1762 void sst_hsw_set_module_enabled_rtd3(struct sst_hsw
*hsw
, u32 module_id
)
1764 hsw
->enabled_modules_rtd3
|= (1 << module_id
);
1767 void sst_hsw_set_module_disabled_rtd3(struct sst_hsw
*hsw
, u32 module_id
)
1769 hsw
->enabled_modules_rtd3
&= ~(1 << module_id
);
1772 bool sst_hsw_is_module_enabled_rtd3(struct sst_hsw
*hsw
, u32 module_id
)
1774 return hsw
->enabled_modules_rtd3
& (1 << module_id
);
1777 void sst_hsw_reset_param_buf(struct sst_hsw
*hsw
)
1779 hsw
->param_idx_w
= 0;
1780 hsw
->param_idx_r
= 0;
1781 memset((void *)hsw
->param_buf
, 0, sizeof(hsw
->param_buf
));
1784 int sst_hsw_store_param_line(struct sst_hsw
*hsw
, u8
*buf
)
1786 /* save line to the first available position of param buffer */
1787 if (hsw
->param_idx_w
> WAVES_PARAM_LINES
- 1) {
1788 dev_warn(hsw
->dev
, "warning: param buffer overflow!\n");
1791 memcpy(hsw
->param_buf
[hsw
->param_idx_w
], buf
, WAVES_PARAM_COUNT
);
1796 int sst_hsw_load_param_line(struct sst_hsw
*hsw
, u8
*buf
)
1800 /* read the first matching line from param buffer */
1801 while (hsw
->param_idx_r
< WAVES_PARAM_LINES
) {
1802 id
= hsw
->param_buf
[hsw
->param_idx_r
][0];
1805 memcpy(buf
, hsw
->param_buf
[hsw
->param_idx_r
],
1810 if (hsw
->param_idx_r
> WAVES_PARAM_LINES
- 1) {
1811 dev_dbg(hsw
->dev
, "end of buffer, roll to the beginning\n");
1812 hsw
->param_idx_r
= 0;
1818 int sst_hsw_launch_param_buf(struct sst_hsw
*hsw
)
1822 if (!sst_hsw_is_module_active(hsw
, SST_HSW_MODULE_WAVES
)) {
1823 dev_dbg(hsw
->dev
, "module waves is not active\n");
1827 /* put all param lines to DSP through ipc */
1828 for (idx
= 0; idx
< hsw
->param_idx_w
; idx
++) {
1829 ret
= sst_hsw_module_set_param(hsw
,
1830 SST_HSW_MODULE_WAVES
, 0, hsw
->param_buf
[idx
][0],
1831 WAVES_PARAM_COUNT
, hsw
->param_buf
[idx
]);
1838 int sst_hsw_module_load(struct sst_hsw
*hsw
,
1839 u32 module_id
, u32 instance_id
, char *name
)
1842 const struct firmware
*fw
= NULL
;
1843 struct sst_fw
*hsw_sst_fw
;
1844 struct sst_module
*module
;
1845 struct device
*dev
= hsw
->dev
;
1846 struct sst_dsp
*dsp
= hsw
->dsp
;
1848 dev_dbg(dev
, "sst_hsw_module_load id=%d, name='%s'", module_id
, name
);
1850 module
= sst_module_get_from_id(dsp
, module_id
);
1851 if (module
== NULL
) {
1852 /* loading for the first time */
1853 if (module_id
== SST_HSW_MODULE_BASE_FW
) {
1854 /* for base module: use fw requested in acpi probe */
1855 fw
= dsp
->pdata
->fw
;
1857 dev_err(dev
, "request Base fw failed\n");
1861 /* try and load any other optional modules if they are
1862 * available. Use dev_info instead of dev_err in case
1863 * request firmware failed */
1864 ret
= request_firmware(&fw
, name
, dev
);
1866 dev_info(dev
, "fw image %s not available(%d)\n",
1871 hsw_sst_fw
= sst_fw_new(dsp
, fw
, hsw
);
1872 if (hsw_sst_fw
== NULL
) {
1873 dev_err(dev
, "error: failed to load firmware\n");
1877 module
= sst_module_get_from_id(dsp
, module_id
);
1878 if (module
== NULL
) {
1879 dev_err(dev
, "error: no module %d in firmware %s\n",
1883 dev_info(dev
, "module %d (%s) already loaded\n",
1886 /* release fw, but base fw should be released by acpi driver */
1887 if (fw
&& module_id
!= SST_HSW_MODULE_BASE_FW
)
1888 release_firmware(fw
);
1893 int sst_hsw_module_enable(struct sst_hsw
*hsw
,
1894 u32 module_id
, u32 instance_id
)
1898 struct sst_hsw_ipc_module_config config
;
1899 struct sst_module
*module
;
1900 struct sst_module_runtime
*runtime
;
1901 struct device
*dev
= hsw
->dev
;
1902 struct sst_dsp
*dsp
= hsw
->dsp
;
1904 if (!sst_hsw_is_module_loaded(hsw
, module_id
)) {
1905 dev_dbg(dev
, "module %d not loaded\n", module_id
);
1909 if (sst_hsw_is_module_active(hsw
, module_id
)) {
1910 dev_info(dev
, "module %d already enabled\n", module_id
);
1914 module
= sst_module_get_from_id(dsp
, module_id
);
1915 if (module
== NULL
) {
1916 dev_err(dev
, "module %d not valid\n", module_id
);
1920 runtime
= sst_module_runtime_get_from_id(module
, module_id
);
1921 if (runtime
== NULL
) {
1922 dev_err(dev
, "runtime %d not valid", module_id
);
1926 header
= IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION
) |
1927 IPC_MODULE_OPERATION(IPC_MODULE_ENABLE
) |
1928 IPC_MODULE_ID(module_id
);
1929 dev_dbg(dev
, "module enable header: %x\n", header
);
1931 config
.map
.module_entries_count
= 1;
1932 config
.map
.module_entries
[0].module_id
= module
->id
;
1933 config
.map
.module_entries
[0].entry_point
= module
->entry
;
1935 config
.persistent_mem
.offset
=
1936 sst_dsp_get_offset(dsp
,
1937 runtime
->persistent_offset
, SST_MEM_DRAM
);
1938 config
.persistent_mem
.size
= module
->persistent_size
;
1940 config
.scratch_mem
.offset
=
1941 sst_dsp_get_offset(dsp
,
1942 dsp
->scratch_offset
, SST_MEM_DRAM
);
1943 config
.scratch_mem
.size
= module
->scratch_size
;
1944 dev_dbg(dev
, "mod %d enable p:%d @ %x, s:%d @ %x, ep: %x",
1945 config
.map
.module_entries
[0].module_id
,
1946 config
.persistent_mem
.size
,
1947 config
.persistent_mem
.offset
,
1948 config
.scratch_mem
.size
, config
.scratch_mem
.offset
,
1949 config
.map
.module_entries
[0].entry_point
);
1951 ret
= sst_ipc_tx_message_wait(&hsw
->ipc
, header
,
1952 &config
, sizeof(config
), NULL
, 0);
1954 dev_err(dev
, "ipc: module enable failed - %d\n", ret
);
1956 module
->state
= SST_MODULE_STATE_ACTIVE
;
1961 int sst_hsw_module_disable(struct sst_hsw
*hsw
,
1962 u32 module_id
, u32 instance_id
)
1966 struct sst_module
*module
;
1967 struct device
*dev
= hsw
->dev
;
1968 struct sst_dsp
*dsp
= hsw
->dsp
;
1970 if (!sst_hsw_is_module_loaded(hsw
, module_id
)) {
1971 dev_dbg(dev
, "module %d not loaded\n", module_id
);
1975 if (!sst_hsw_is_module_active(hsw
, module_id
)) {
1976 dev_info(dev
, "module %d already disabled\n", module_id
);
1980 module
= sst_module_get_from_id(dsp
, module_id
);
1981 if (module
== NULL
) {
1982 dev_err(dev
, "module %d not valid\n", module_id
);
1986 header
= IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION
) |
1987 IPC_MODULE_OPERATION(IPC_MODULE_DISABLE
) |
1988 IPC_MODULE_ID(module_id
);
1990 ret
= sst_ipc_tx_message_wait(&hsw
->ipc
, header
, NULL
, 0, NULL
, 0);
1992 dev_err(dev
, "module disable failed - %d\n", ret
);
1994 module
->state
= SST_MODULE_STATE_INITIALIZED
;
1999 int sst_hsw_module_set_param(struct sst_hsw
*hsw
,
2000 u32 module_id
, u32 instance_id
, u32 parameter_id
,
2001 u32 param_size
, char *param
)
2004 unsigned char *data
= NULL
;
2006 u32 payload_size
= 0, transfer_parameter_size
= 0;
2007 dma_addr_t dma_addr
= 0;
2008 struct sst_hsw_transfer_parameter
*parameter
;
2009 struct device
*dev
= hsw
->dev
;
2011 header
= IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION
) |
2012 IPC_MODULE_OPERATION(IPC_MODULE_SET_PARAMETER
) |
2013 IPC_MODULE_ID(module_id
);
2014 dev_dbg(dev
, "sst_hsw_module_set_param header=%x\n", header
);
2016 payload_size
= param_size
+
2017 sizeof(struct sst_hsw_transfer_parameter
) -
2018 sizeof(struct sst_hsw_transfer_list
);
2019 dev_dbg(dev
, "parameter size : %d\n", param_size
);
2020 dev_dbg(dev
, "payload size : %d\n", payload_size
);
2022 if (payload_size
<= SST_HSW_IPC_MAX_SHORT_PARAMETER_SIZE
) {
2023 /* short parameter, mailbox can contain data */
2024 dev_dbg(dev
, "transfer parameter size : %d\n",
2025 transfer_parameter_size
);
2027 transfer_parameter_size
= ALIGN(payload_size
, 4);
2028 dev_dbg(dev
, "transfer parameter aligned size : %d\n",
2029 transfer_parameter_size
);
2031 parameter
= kzalloc(transfer_parameter_size
, GFP_KERNEL
);
2032 if (parameter
== NULL
)
2035 memcpy(parameter
->data
, param
, param_size
);
2037 dev_warn(dev
, "transfer parameter size too large!");
2041 parameter
->parameter_id
= parameter_id
;
2042 parameter
->data_size
= param_size
;
2044 ret
= sst_ipc_tx_message_wait(&hsw
->ipc
, header
,
2045 parameter
, transfer_parameter_size
, NULL
, 0);
2047 dev_err(dev
, "ipc: module set parameter failed - %d\n", ret
);
2052 dma_free_coherent(hsw
->dsp
->dma_dev
,
2053 param_size
, (void *)data
, dma_addr
);
2058 static struct sst_dsp_device hsw_dev
= {
2059 .thread
= hsw_irq_thread
,
2060 .ops
= &haswell_ops
,
2063 static void hsw_tx_msg(struct sst_generic_ipc
*ipc
, struct ipc_message
*msg
)
2065 /* send the message */
2066 sst_dsp_outbox_write(ipc
->dsp
, msg
->tx_data
, msg
->tx_size
);
2067 sst_dsp_ipc_msg_tx(ipc
->dsp
, msg
->header
);
2070 static void hsw_shim_dbg(struct sst_generic_ipc
*ipc
, const char *text
)
2072 struct sst_dsp
*sst
= ipc
->dsp
;
2073 u32 isr
, ipcd
, imrx
, ipcx
;
2075 ipcx
= sst_dsp_shim_read_unlocked(sst
, SST_IPCX
);
2076 isr
= sst_dsp_shim_read_unlocked(sst
, SST_ISRX
);
2077 ipcd
= sst_dsp_shim_read_unlocked(sst
, SST_IPCD
);
2078 imrx
= sst_dsp_shim_read_unlocked(sst
, SST_IMRX
);
2081 "ipc: --%s-- ipcx 0x%8.8x isr 0x%8.8x ipcd 0x%8.8x imrx 0x%8.8x\n",
2082 text
, ipcx
, isr
, ipcd
, imrx
);
2085 static void hsw_tx_data_copy(struct ipc_message
*msg
, char *tx_data
,
2088 memcpy(msg
->tx_data
, tx_data
, tx_size
);
2091 static u64
hsw_reply_msg_match(u64 header
, u64
*mask
)
2093 /* clear reply bits & status bits */
2094 header
&= ~(IPC_STATUS_MASK
| IPC_GLB_REPLY_MASK
);
2100 static bool hsw_is_dsp_busy(struct sst_dsp
*dsp
)
2104 ipcx
= sst_dsp_shim_read_unlocked(dsp
, SST_IPCX
);
2105 return (ipcx
& (SST_IPCX_BUSY
| SST_IPCX_DONE
));
2108 int sst_hsw_dsp_init(struct device
*dev
, struct sst_pdata
*pdata
)
2110 struct sst_hsw_ipc_fw_version version
;
2111 struct sst_hsw
*hsw
;
2112 struct sst_generic_ipc
*ipc
;
2115 dev_dbg(dev
, "initialising Audio DSP IPC\n");
2117 hsw
= devm_kzalloc(dev
, sizeof(*hsw
), GFP_KERNEL
);
2125 ipc
->ops
.tx_msg
= hsw_tx_msg
;
2126 ipc
->ops
.shim_dbg
= hsw_shim_dbg
;
2127 ipc
->ops
.tx_data_copy
= hsw_tx_data_copy
;
2128 ipc
->ops
.reply_msg_match
= hsw_reply_msg_match
;
2129 ipc
->ops
.is_dsp_busy
= hsw_is_dsp_busy
;
2131 ipc
->tx_data_max_size
= IPC_MAX_MAILBOX_BYTES
;
2132 ipc
->rx_data_max_size
= IPC_MAX_MAILBOX_BYTES
;
2134 ret
= sst_ipc_init(ipc
);
2138 INIT_LIST_HEAD(&hsw
->stream_list
);
2139 init_waitqueue_head(&hsw
->boot_wait
);
2140 hsw_dev
.thread_context
= hsw
;
2143 hsw
->dsp
= sst_dsp_new(dev
, &hsw_dev
, pdata
);
2144 if (hsw
->dsp
== NULL
) {
2149 ipc
->dsp
= hsw
->dsp
;
2151 /* allocate DMA buffer for context storage */
2152 hsw
->dx_context
= dma_alloc_coherent(hsw
->dsp
->dma_dev
,
2153 SST_HSW_DX_CONTEXT_SIZE
, &hsw
->dx_context_paddr
, GFP_KERNEL
);
2154 if (hsw
->dx_context
== NULL
) {
2159 /* keep the DSP in reset state for base FW loading */
2160 sst_dsp_reset(hsw
->dsp
);
2162 /* load base module and other modules in base firmware image */
2163 ret
= sst_hsw_module_load(hsw
, SST_HSW_MODULE_BASE_FW
, 0, "Base");
2167 /* try to load module waves */
2168 sst_hsw_module_load(hsw
, SST_HSW_MODULE_WAVES
, 0, "intel/IntcPP01.bin");
2170 /* allocate scratch mem regions */
2171 ret
= sst_block_alloc_scratch(hsw
->dsp
);
2175 /* init param buffer */
2176 sst_hsw_reset_param_buf(hsw
);
2178 /* wait for DSP boot completion */
2179 sst_dsp_boot(hsw
->dsp
);
2180 ret
= wait_event_timeout(hsw
->boot_wait
, hsw
->boot_complete
,
2181 msecs_to_jiffies(IPC_BOOT_MSECS
));
2184 dev_err(hsw
->dev
, "error: audio DSP boot timeout IPCD 0x%x IPCX 0x%x\n",
2185 sst_dsp_shim_read_unlocked(hsw
->dsp
, SST_IPCD
),
2186 sst_dsp_shim_read_unlocked(hsw
->dsp
, SST_IPCX
));
2190 /* init module state after boot */
2191 sst_hsw_init_module_state(hsw
);
2193 /* get the FW version */
2194 sst_hsw_fw_get_version(hsw
, &version
);
2196 /* get the globalmixer */
2197 ret
= sst_hsw_mixer_get_info(hsw
);
2199 dev_err(hsw
->dev
, "error: failed to get stream info\n");
2207 sst_dsp_reset(hsw
->dsp
);
2208 sst_fw_free_all(hsw
->dsp
);
2210 dma_free_coherent(hsw
->dsp
->dma_dev
, SST_HSW_DX_CONTEXT_SIZE
,
2211 hsw
->dx_context
, hsw
->dx_context_paddr
);
2213 sst_dsp_free(hsw
->dsp
);
2219 EXPORT_SYMBOL_GPL(sst_hsw_dsp_init
);
2221 void sst_hsw_dsp_free(struct device
*dev
, struct sst_pdata
*pdata
)
2223 struct sst_hsw
*hsw
= pdata
->dsp
;
2225 sst_dsp_reset(hsw
->dsp
);
2226 sst_fw_free_all(hsw
->dsp
);
2227 dma_free_coherent(hsw
->dsp
->dma_dev
, SST_HSW_DX_CONTEXT_SIZE
,
2228 hsw
->dx_context
, hsw
->dx_context_paddr
);
2229 sst_dsp_free(hsw
->dsp
);
2230 sst_ipc_fini(&hsw
->ipc
);
2232 EXPORT_SYMBOL_GPL(sst_hsw_dsp_free
);