ASoC: Intel: bxtn: Store the FW/Library context at boot
[sfrench/cifs-2.6.git] / sound / soc / intel / skylake / bxt-sst.c
1 /*
2  *  bxt-sst.c - DSP library functions for BXT platform
3  *
4  *  Copyright (C) 2015-16 Intel Corp
5  *  Author:Rafal Redzimski <rafal.f.redzimski@intel.com>
6  *         Jeeja KP <jeeja.kp@intel.com>
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; version 2 of the License.
11  *
12  *  This program is distributed in the hope that it will be useful, but
13  *  WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  General Public License for more details.
16  */
17
18 #include <linux/module.h>
19 #include <linux/delay.h>
20 #include <linux/firmware.h>
21 #include <linux/device.h>
22
23 #include "../common/sst-dsp.h"
24 #include "../common/sst-dsp-priv.h"
25 #include "skl-sst-ipc.h"
26
27 #define BXT_BASEFW_TIMEOUT      3000
28 #define BXT_INIT_TIMEOUT        500
29 #define BXT_IPC_PURGE_FW        0x01004000
30
31 #define BXT_ROM_INIT            0x5
32 #define BXT_ADSP_SRAM0_BASE     0x80000
33
34 /* Firmware status window */
35 #define BXT_ADSP_FW_STATUS      BXT_ADSP_SRAM0_BASE
36 #define BXT_ADSP_ERROR_CODE     (BXT_ADSP_FW_STATUS + 0x4)
37
38 #define BXT_ADSP_SRAM1_BASE     0xA0000
39
40 #define BXT_INSTANCE_ID 0
41 #define BXT_BASE_FW_MODULE_ID 0
42
43 #define BXT_ADSP_FW_BIN_HDR_OFFSET 0x2000
44
45 /* Delay before scheduling D0i3 entry */
46 #define BXT_D0I3_DELAY 5000
47
48 static unsigned int bxt_get_errorcode(struct sst_dsp *ctx)
49 {
50          return sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE);
51 }
52
53 static void sst_bxt_release_library(struct skl_lib_info *linfo, int lib_count)
54 {
55         int i;
56
57         for (i = 1; i < lib_count; i++) {
58                 if (linfo[i].fw) {
59                         release_firmware(linfo[i].fw);
60                         linfo[i].fw = NULL;
61                 }
62         }
63 }
64
65 static int
66 bxt_load_library(struct sst_dsp *ctx, struct skl_lib_info *linfo, int lib_count)
67 {
68         struct snd_dma_buffer dmab;
69         struct skl_sst *skl = ctx->thread_context;
70         struct firmware stripped_fw;
71         int ret = 0, i, dma_id, stream_tag;
72
73         /* library indices start from 1 to N. 0 represents base FW */
74         for (i = 1; i < lib_count; i++) {
75                 if (linfo[i].fw == NULL) {
76                         ret = request_firmware(&linfo[i].fw, linfo[i].name,
77                                                 ctx->dev);
78                         if (ret < 0) {
79                                 dev_err(ctx->dev, "Request lib %s failed:%d\n",
80                                         linfo[i].name, ret);
81                                 goto load_library_failed;
82                         }
83                 }
84
85                 if (skl->is_first_boot) {
86                         ret = snd_skl_parse_uuids(ctx, linfo[i].fw,
87                                         BXT_ADSP_FW_BIN_HDR_OFFSET, i);
88                         if (ret < 0)
89                                 goto load_library_failed;
90                 }
91
92                 stripped_fw.data = linfo[i].fw->data;
93                 stripped_fw.size = linfo[i].fw->size;
94                 skl_dsp_strip_extended_manifest(&stripped_fw);
95
96                 stream_tag = ctx->dsp_ops.prepare(ctx->dev, 0x40,
97                                         stripped_fw.size, &dmab);
98                 if (stream_tag <= 0) {
99                         dev_err(ctx->dev, "Lib prepare DMA err: %x\n",
100                                         stream_tag);
101                         ret = stream_tag;
102                         goto load_library_failed;
103                 }
104
105                 dma_id = stream_tag - 1;
106                 memcpy(dmab.area, stripped_fw.data, stripped_fw.size);
107
108                 ctx->dsp_ops.trigger(ctx->dev, true, stream_tag);
109                 ret = skl_sst_ipc_load_library(&skl->ipc, dma_id, i);
110                 if (ret < 0)
111                         dev_err(ctx->dev, "IPC Load Lib for %s fail: %d\n",
112                                         linfo[i].name, ret);
113
114                 ctx->dsp_ops.trigger(ctx->dev, false, stream_tag);
115                 ctx->dsp_ops.cleanup(ctx->dev, &dmab, stream_tag);
116         }
117
118         return ret;
119
120 load_library_failed:
121         sst_bxt_release_library(linfo, lib_count);
122         return ret;
123 }
124
125 /*
126  * First boot sequence has some extra steps. Core 0 waits for power
127  * status on core 1, so power up core 1 also momentarily, keep it in
128  * reset/stall and then turn it off
129  */
130 static int sst_bxt_prepare_fw(struct sst_dsp *ctx,
131                         const void *fwdata, u32 fwsize)
132 {
133         int stream_tag, ret;
134
135         stream_tag = ctx->dsp_ops.prepare(ctx->dev, 0x40, fwsize, &ctx->dmab);
136         if (stream_tag <= 0) {
137                 dev_err(ctx->dev, "Failed to prepare DMA FW loading err: %x\n",
138                                 stream_tag);
139                 return stream_tag;
140         }
141
142         ctx->dsp_ops.stream_tag = stream_tag;
143         memcpy(ctx->dmab.area, fwdata, fwsize);
144
145         /* Step 1: Power up core 0 and core1 */
146         ret = skl_dsp_core_power_up(ctx, SKL_DSP_CORE0_MASK |
147                                 SKL_DSP_CORE_MASK(1));
148         if (ret < 0) {
149                 dev_err(ctx->dev, "dsp core0/1 power up failed\n");
150                 goto base_fw_load_failed;
151         }
152
153         /* Step 2: Purge FW request */
154         sst_dsp_shim_write(ctx, SKL_ADSP_REG_HIPCI, SKL_ADSP_REG_HIPCI_BUSY |
155                                 (BXT_IPC_PURGE_FW | ((stream_tag - 1) << 9)));
156
157         /* Step 3: Unset core0 reset state & unstall/run core0 */
158         ret = skl_dsp_start_core(ctx, SKL_DSP_CORE0_MASK);
159         if (ret < 0) {
160                 dev_err(ctx->dev, "Start dsp core failed ret: %d\n", ret);
161                 ret = -EIO;
162                 goto base_fw_load_failed;
163         }
164
165         /* Step 4: Wait for DONE Bit */
166         ret = sst_dsp_register_poll(ctx, SKL_ADSP_REG_HIPCIE,
167                                         SKL_ADSP_REG_HIPCIE_DONE,
168                                         SKL_ADSP_REG_HIPCIE_DONE,
169                                         BXT_INIT_TIMEOUT, "HIPCIE Done");
170         if (ret < 0) {
171                 dev_err(ctx->dev, "Timout for Purge Request%d\n", ret);
172                 goto base_fw_load_failed;
173         }
174
175         /* Step 5: power down core1 */
176         ret = skl_dsp_core_power_down(ctx, SKL_DSP_CORE_MASK(1));
177         if (ret < 0) {
178                 dev_err(ctx->dev, "dsp core1 power down failed\n");
179                 goto base_fw_load_failed;
180         }
181
182         /* Step 6: Enable Interrupt */
183         skl_ipc_int_enable(ctx);
184         skl_ipc_op_int_enable(ctx);
185
186         /* Step 7: Wait for ROM init */
187         ret = sst_dsp_register_poll(ctx, BXT_ADSP_FW_STATUS, SKL_FW_STS_MASK,
188                         SKL_FW_INIT, BXT_INIT_TIMEOUT, "ROM Load");
189         if (ret < 0) {
190                 dev_err(ctx->dev, "Timeout for ROM init, ret:%d\n", ret);
191                 goto base_fw_load_failed;
192         }
193
194         return ret;
195
196 base_fw_load_failed:
197         ctx->dsp_ops.cleanup(ctx->dev, &ctx->dmab, stream_tag);
198         skl_dsp_core_power_down(ctx, SKL_DSP_CORE_MASK(1));
199         skl_dsp_disable_core(ctx, SKL_DSP_CORE0_MASK);
200         return ret;
201 }
202
203 static int sst_transfer_fw_host_dma(struct sst_dsp *ctx)
204 {
205         int ret;
206
207         ctx->dsp_ops.trigger(ctx->dev, true, ctx->dsp_ops.stream_tag);
208         ret = sst_dsp_register_poll(ctx, BXT_ADSP_FW_STATUS, SKL_FW_STS_MASK,
209                         BXT_ROM_INIT, BXT_BASEFW_TIMEOUT, "Firmware boot");
210
211         ctx->dsp_ops.trigger(ctx->dev, false, ctx->dsp_ops.stream_tag);
212         ctx->dsp_ops.cleanup(ctx->dev, &ctx->dmab, ctx->dsp_ops.stream_tag);
213
214         return ret;
215 }
216
217 static int bxt_load_base_firmware(struct sst_dsp *ctx)
218 {
219         struct firmware stripped_fw;
220         struct skl_sst *skl = ctx->thread_context;
221         int ret;
222
223         if (ctx->fw == NULL) {
224                 ret = request_firmware(&ctx->fw, ctx->fw_name, ctx->dev);
225                 if (ret < 0) {
226                         dev_err(ctx->dev, "Request firmware failed %d\n", ret);
227                         return ret;
228                 }
229         }
230
231         /* prase uuids on first boot */
232         if (skl->is_first_boot) {
233                 ret = snd_skl_parse_uuids(ctx, ctx->fw, BXT_ADSP_FW_BIN_HDR_OFFSET, 0);
234                 if (ret < 0)
235                         goto sst_load_base_firmware_failed;
236         }
237
238         stripped_fw.data = ctx->fw->data;
239         stripped_fw.size = ctx->fw->size;
240         skl_dsp_strip_extended_manifest(&stripped_fw);
241
242         ret = sst_bxt_prepare_fw(ctx, stripped_fw.data, stripped_fw.size);
243         /* Retry Enabling core and ROM load. Retry seemed to help */
244         if (ret < 0) {
245                 ret = sst_bxt_prepare_fw(ctx, stripped_fw.data, stripped_fw.size);
246                 if (ret < 0) {
247                         dev_err(ctx->dev, "Error code=0x%x: FW status=0x%x\n",
248                         sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE),
249                         sst_dsp_shim_read(ctx, BXT_ADSP_FW_STATUS));
250
251                         dev_err(ctx->dev, "Core En/ROM load fail:%d\n", ret);
252                         goto sst_load_base_firmware_failed;
253                 }
254         }
255
256         ret = sst_transfer_fw_host_dma(ctx);
257         if (ret < 0) {
258                 dev_err(ctx->dev, "Transfer firmware failed %d\n", ret);
259                 dev_info(ctx->dev, "Error code=0x%x: FW status=0x%x\n",
260                         sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE),
261                         sst_dsp_shim_read(ctx, BXT_ADSP_FW_STATUS));
262
263                 skl_dsp_disable_core(ctx, SKL_DSP_CORE0_MASK);
264         } else {
265                 dev_dbg(ctx->dev, "Firmware download successful\n");
266                 ret = wait_event_timeout(skl->boot_wait, skl->boot_complete,
267                                         msecs_to_jiffies(SKL_IPC_BOOT_MSECS));
268                 if (ret == 0) {
269                         dev_err(ctx->dev, "DSP boot fail, FW Ready timeout\n");
270                         skl_dsp_disable_core(ctx, SKL_DSP_CORE0_MASK);
271                         ret = -EIO;
272                 } else {
273                         ret = 0;
274                         skl->fw_loaded = true;
275                 }
276         }
277
278         return ret;
279
280 sst_load_base_firmware_failed:
281         release_firmware(ctx->fw);
282         ctx->fw = NULL;
283         return ret;
284 }
285
286 /*
287  * Decide the D0i3 state that can be targeted based on the usecase
288  * ref counts and DSP state
289  *
290  * Decision Matrix:  (X= dont care; state = target state)
291  *
292  * DSP state != SKL_DSP_RUNNING ; state = no d0i3
293  *
294  * DSP state == SKL_DSP_RUNNING , the following matrix applies
295  * non_d0i3 >0; streaming =X; non_streaming =X; state = no d0i3
296  * non_d0i3 =X; streaming =0; non_streaming =0; state = no d0i3
297  * non_d0i3 =0; streaming >0; non_streaming =X; state = streaming d0i3
298  * non_d0i3 =0; streaming =0; non_streaming =X; state = non-streaming d0i3
299  */
300 static int bxt_d0i3_target_state(struct sst_dsp *ctx)
301 {
302         struct skl_sst *skl = ctx->thread_context;
303         struct skl_d0i3_data *d0i3 = &skl->d0i3;
304
305         if (skl->cores.state[SKL_DSP_CORE0_ID] != SKL_DSP_RUNNING)
306                 return SKL_DSP_D0I3_NONE;
307
308         if (d0i3->non_d0i3)
309                 return SKL_DSP_D0I3_NONE;
310         else if (d0i3->streaming)
311                 return SKL_DSP_D0I3_STREAMING;
312         else if (d0i3->non_streaming)
313                 return SKL_DSP_D0I3_NON_STREAMING;
314         else
315                 return SKL_DSP_D0I3_NONE;
316 }
317
318 static void bxt_set_dsp_D0i3(struct work_struct *work)
319 {
320         int ret;
321         struct skl_ipc_d0ix_msg msg;
322         struct skl_sst *skl = container_of(work,
323                         struct skl_sst, d0i3.work.work);
324         struct sst_dsp *ctx = skl->dsp;
325         struct skl_d0i3_data *d0i3 = &skl->d0i3;
326         int target_state;
327
328         dev_dbg(ctx->dev, "In %s:\n", __func__);
329
330         /* D0i3 entry allowed only if core 0 alone is running */
331         if (skl_dsp_get_enabled_cores(ctx) !=  SKL_DSP_CORE0_MASK) {
332                 dev_warn(ctx->dev,
333                                 "D0i3 allowed when only core0 running:Exit\n");
334                 return;
335         }
336
337         target_state = bxt_d0i3_target_state(ctx);
338         if (target_state == SKL_DSP_D0I3_NONE)
339                 return;
340
341         msg.instance_id = 0;
342         msg.module_id = 0;
343         msg.wake = 1;
344         msg.streaming = 0;
345         if (target_state == SKL_DSP_D0I3_STREAMING)
346                 msg.streaming = 1;
347
348         ret =  skl_ipc_set_d0ix(&skl->ipc, &msg);
349
350         if (ret < 0) {
351                 dev_err(ctx->dev, "Failed to set DSP to D0i3 state\n");
352                 return;
353         }
354
355         /* Set Vendor specific register D0I3C.I3 to enable D0i3*/
356         if (skl->update_d0i3c)
357                 skl->update_d0i3c(skl->dev, true);
358
359         d0i3->state = target_state;
360         skl->cores.state[SKL_DSP_CORE0_ID] = SKL_DSP_RUNNING_D0I3;
361 }
362
363 static int bxt_schedule_dsp_D0i3(struct sst_dsp *ctx)
364 {
365         struct skl_sst *skl = ctx->thread_context;
366         struct skl_d0i3_data *d0i3 = &skl->d0i3;
367
368         /* Schedule D0i3 only if the usecase ref counts are appropriate */
369         if (bxt_d0i3_target_state(ctx) != SKL_DSP_D0I3_NONE) {
370
371                 dev_dbg(ctx->dev, "%s: Schedule D0i3\n", __func__);
372
373                 schedule_delayed_work(&d0i3->work,
374                                 msecs_to_jiffies(BXT_D0I3_DELAY));
375         }
376
377         return 0;
378 }
379
380 static int bxt_set_dsp_D0i0(struct sst_dsp *ctx)
381 {
382         int ret;
383         struct skl_ipc_d0ix_msg msg;
384         struct skl_sst *skl = ctx->thread_context;
385
386         dev_dbg(ctx->dev, "In %s:\n", __func__);
387
388         /* First Cancel any pending attempt to put DSP to D0i3 */
389         cancel_delayed_work_sync(&skl->d0i3.work);
390
391         /* If DSP is currently in D0i3, bring it to D0i0 */
392         if (skl->cores.state[SKL_DSP_CORE0_ID] != SKL_DSP_RUNNING_D0I3)
393                 return 0;
394
395         dev_dbg(ctx->dev, "Set DSP to D0i0\n");
396
397         msg.instance_id = 0;
398         msg.module_id = 0;
399         msg.streaming = 0;
400         msg.wake = 0;
401
402         if (skl->d0i3.state == SKL_DSP_D0I3_STREAMING)
403                 msg.streaming = 1;
404
405         /* Clear Vendor specific register D0I3C.I3 to disable D0i3*/
406         if (skl->update_d0i3c)
407                 skl->update_d0i3c(skl->dev, false);
408
409         ret =  skl_ipc_set_d0ix(&skl->ipc, &msg);
410         if (ret < 0) {
411                 dev_err(ctx->dev, "Failed to set DSP to D0i0\n");
412                 return ret;
413         }
414
415         skl->cores.state[SKL_DSP_CORE0_ID] = SKL_DSP_RUNNING;
416         skl->d0i3.state = SKL_DSP_D0I3_NONE;
417
418         return 0;
419 }
420
421 static int bxt_set_dsp_D0(struct sst_dsp *ctx, unsigned int core_id)
422 {
423         struct skl_sst *skl = ctx->thread_context;
424         int ret;
425         struct skl_ipc_dxstate_info dx;
426         unsigned int core_mask = SKL_DSP_CORE_MASK(core_id);
427
428         if (skl->fw_loaded == false) {
429                 skl->boot_complete = false;
430                 ret = bxt_load_base_firmware(ctx);
431                 if (ret < 0) {
432                         dev_err(ctx->dev, "reload fw failed: %d\n", ret);
433                         return ret;
434                 }
435
436                 if (skl->lib_count > 1) {
437                         ret = bxt_load_library(ctx, skl->lib_info,
438                                                 skl->lib_count);
439                         if (ret < 0) {
440                                 dev_err(ctx->dev, "reload libs failed: %d\n", ret);
441                                 return ret;
442                         }
443                 }
444                 return ret;
445         }
446
447         /* If core 0 is being turned on, turn on core 1 as well */
448         if (core_id == SKL_DSP_CORE0_ID)
449                 ret = skl_dsp_core_power_up(ctx, core_mask |
450                                 SKL_DSP_CORE_MASK(1));
451         else
452                 ret = skl_dsp_core_power_up(ctx, core_mask);
453
454         if (ret < 0)
455                 goto err;
456
457         if (core_id == SKL_DSP_CORE0_ID) {
458
459                 /*
460                  * Enable interrupt after SPA is set and before
461                  * DSP is unstalled
462                  */
463                 skl_ipc_int_enable(ctx);
464                 skl_ipc_op_int_enable(ctx);
465                 skl->boot_complete = false;
466         }
467
468         ret = skl_dsp_start_core(ctx, core_mask);
469         if (ret < 0)
470                 goto err;
471
472         if (core_id == SKL_DSP_CORE0_ID) {
473                 ret = wait_event_timeout(skl->boot_wait,
474                                 skl->boot_complete,
475                                 msecs_to_jiffies(SKL_IPC_BOOT_MSECS));
476
477         /* If core 1 was turned on for booting core 0, turn it off */
478                 skl_dsp_core_power_down(ctx, SKL_DSP_CORE_MASK(1));
479                 if (ret == 0) {
480                         dev_err(ctx->dev, "%s: DSP boot timeout\n", __func__);
481                         dev_err(ctx->dev, "Error code=0x%x: FW status=0x%x\n",
482                                 sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE),
483                                 sst_dsp_shim_read(ctx, BXT_ADSP_FW_STATUS));
484                         dev_err(ctx->dev, "Failed to set core0 to D0 state\n");
485                         ret = -EIO;
486                         goto err;
487                 }
488         }
489
490         /* Tell FW if additional core in now On */
491
492         if (core_id != SKL_DSP_CORE0_ID) {
493                 dx.core_mask = core_mask;
494                 dx.dx_mask = core_mask;
495
496                 ret = skl_ipc_set_dx(&skl->ipc, BXT_INSTANCE_ID,
497                                         BXT_BASE_FW_MODULE_ID, &dx);
498                 if (ret < 0) {
499                         dev_err(ctx->dev, "IPC set_dx for core %d fail: %d\n",
500                                                                 core_id, ret);
501                         goto err;
502                 }
503         }
504
505         skl->cores.state[core_id] = SKL_DSP_RUNNING;
506         return 0;
507 err:
508         if (core_id == SKL_DSP_CORE0_ID)
509                 core_mask |= SKL_DSP_CORE_MASK(1);
510         skl_dsp_disable_core(ctx, core_mask);
511
512         return ret;
513 }
514
515 static int bxt_set_dsp_D3(struct sst_dsp *ctx, unsigned int core_id)
516 {
517         int ret;
518         struct skl_ipc_dxstate_info dx;
519         struct skl_sst *skl = ctx->thread_context;
520         unsigned int core_mask = SKL_DSP_CORE_MASK(core_id);
521
522         dx.core_mask = core_mask;
523         dx.dx_mask = SKL_IPC_D3_MASK;
524
525         dev_dbg(ctx->dev, "core mask=%x dx_mask=%x\n",
526                         dx.core_mask, dx.dx_mask);
527
528         ret = skl_ipc_set_dx(&skl->ipc, BXT_INSTANCE_ID,
529                                 BXT_BASE_FW_MODULE_ID, &dx);
530         if (ret < 0)
531                 dev_err(ctx->dev,
532                 "Failed to set DSP to D3:core id = %d;Continue reset\n",
533                 core_id);
534
535         ret = skl_dsp_disable_core(ctx, core_mask);
536         if (ret < 0) {
537                 dev_err(ctx->dev, "Failed to disable core %d\n", ret);
538                 return ret;
539         }
540         skl->cores.state[core_id] = SKL_DSP_RESET;
541         return 0;
542 }
543
544 static struct skl_dsp_fw_ops bxt_fw_ops = {
545         .set_state_D0 = bxt_set_dsp_D0,
546         .set_state_D3 = bxt_set_dsp_D3,
547         .set_state_D0i3 = bxt_schedule_dsp_D0i3,
548         .set_state_D0i0 = bxt_set_dsp_D0i0,
549         .load_fw = bxt_load_base_firmware,
550         .get_fw_errcode = bxt_get_errorcode,
551         .load_library = bxt_load_library,
552 };
553
554 static struct sst_ops skl_ops = {
555         .irq_handler = skl_dsp_sst_interrupt,
556         .write = sst_shim32_write,
557         .read = sst_shim32_read,
558         .ram_read = sst_memcpy_fromio_32,
559         .ram_write = sst_memcpy_toio_32,
560         .free = skl_dsp_free,
561 };
562
563 static struct sst_dsp_device skl_dev = {
564         .thread = skl_dsp_irq_thread_handler,
565         .ops = &skl_ops,
566 };
567
568 int bxt_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq,
569                         const char *fw_name, struct skl_dsp_loader_ops dsp_ops,
570                         struct skl_sst **dsp)
571 {
572         struct skl_sst *skl;
573         struct sst_dsp *sst;
574         int ret;
575
576         skl = devm_kzalloc(dev, sizeof(*skl), GFP_KERNEL);
577         if (skl == NULL)
578                 return -ENOMEM;
579
580         skl->dev = dev;
581         skl_dev.thread_context = skl;
582         INIT_LIST_HEAD(&skl->uuid_list);
583
584         skl->dsp = skl_dsp_ctx_init(dev, &skl_dev, irq);
585         if (!skl->dsp) {
586                 dev_err(skl->dev, "skl_dsp_ctx_init failed\n");
587                 return -ENODEV;
588         }
589
590         sst = skl->dsp;
591         sst->fw_name = fw_name;
592         sst->dsp_ops = dsp_ops;
593         sst->fw_ops = bxt_fw_ops;
594         sst->addr.lpe = mmio_base;
595         sst->addr.shim = mmio_base;
596
597         sst_dsp_mailbox_init(sst, (BXT_ADSP_SRAM0_BASE + SKL_ADSP_W0_STAT_SZ),
598                         SKL_ADSP_W0_UP_SZ, BXT_ADSP_SRAM1_BASE, SKL_ADSP_W1_SZ);
599
600         INIT_LIST_HEAD(&sst->module_list);
601         ret = skl_ipc_init(dev, skl);
602         if (ret)
603                 return ret;
604
605         /* set the D0i3 check */
606         skl->ipc.ops.check_dsp_lp_on = skl_ipc_check_D0i0;
607
608         skl->cores.count = 2;
609         skl->boot_complete = false;
610         init_waitqueue_head(&skl->boot_wait);
611         skl->is_first_boot = true;
612         INIT_DELAYED_WORK(&skl->d0i3.work, bxt_set_dsp_D0i3);
613         skl->d0i3.state = SKL_DSP_D0I3_NONE;
614
615         if (dsp)
616                 *dsp = skl;
617
618         return 0;
619 }
620 EXPORT_SYMBOL_GPL(bxt_sst_dsp_init);
621
622 int bxt_sst_init_fw(struct device *dev, struct skl_sst *ctx)
623 {
624         int ret;
625         struct sst_dsp *sst = ctx->dsp;
626
627         ret = sst->fw_ops.load_fw(sst);
628         if (ret < 0) {
629                 dev_err(dev, "Load base fw failed: %x\n", ret);
630                 return ret;
631         }
632
633         skl_dsp_init_core_state(sst);
634
635         if (ctx->lib_count > 1) {
636                 ret = sst->fw_ops.load_library(sst, ctx->lib_info,
637                                                 ctx->lib_count);
638                 if (ret < 0) {
639                         dev_err(dev, "Load Library failed : %x\n", ret);
640                         return ret;
641                 }
642         }
643         ctx->is_first_boot = false;
644
645         return 0;
646 }
647 EXPORT_SYMBOL_GPL(bxt_sst_init_fw);
648
649 void bxt_sst_dsp_cleanup(struct device *dev, struct skl_sst *ctx)
650 {
651
652         sst_bxt_release_library(ctx->lib_info, ctx->lib_count);
653         if (ctx->dsp->fw)
654                 release_firmware(ctx->dsp->fw);
655         skl_freeup_uuid_list(ctx);
656         skl_ipc_free(&ctx->ipc);
657         ctx->dsp->cl_dev.ops.cl_cleanup_controller(ctx->dsp);
658
659         if (ctx->dsp->addr.lpe)
660                 iounmap(ctx->dsp->addr.lpe);
661
662         ctx->dsp->ops->free(ctx->dsp);
663 }
664 EXPORT_SYMBOL_GPL(bxt_sst_dsp_cleanup);
665
666 MODULE_LICENSE("GPL v2");
667 MODULE_DESCRIPTION("Intel Broxton IPC driver");