bxt-sst.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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. #include <linux/module.h>
  18. #include <linux/delay.h>
  19. #include <linux/firmware.h>
  20. #include <linux/device.h>
  21. #include "../common/sst-dsp.h"
  22. #include "../common/sst-dsp-priv.h"
  23. #include "skl-sst-ipc.h"
  24. #define BXT_BASEFW_TIMEOUT 3000
  25. #define BXT_INIT_TIMEOUT 300
  26. #define BXT_ROM_INIT_TIMEOUT 70
  27. #define BXT_IPC_PURGE_FW 0x01004000
  28. #define BXT_ROM_INIT 0x5
  29. #define BXT_ADSP_SRAM0_BASE 0x80000
  30. /* Firmware status window */
  31. #define BXT_ADSP_FW_STATUS BXT_ADSP_SRAM0_BASE
  32. #define BXT_ADSP_ERROR_CODE (BXT_ADSP_FW_STATUS + 0x4)
  33. #define BXT_ADSP_SRAM1_BASE 0xA0000
  34. #define BXT_INSTANCE_ID 0
  35. #define BXT_BASE_FW_MODULE_ID 0
  36. #define BXT_ADSP_FW_BIN_HDR_OFFSET 0x2000
  37. /* Delay before scheduling D0i3 entry */
  38. #define BXT_D0I3_DELAY 5000
  39. #define BXT_FW_ROM_INIT_RETRY 3
  40. static unsigned int bxt_get_errorcode(struct sst_dsp *ctx)
  41. {
  42. return sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE);
  43. }
  44. static int
  45. bxt_load_library(struct sst_dsp *ctx, struct skl_lib_info *linfo, int lib_count)
  46. {
  47. struct snd_dma_buffer dmab;
  48. struct skl_sst *skl = ctx->thread_context;
  49. struct firmware stripped_fw;
  50. int ret = 0, i, dma_id, stream_tag;
  51. /* library indices start from 1 to N. 0 represents base FW */
  52. for (i = 1; i < lib_count; i++) {
  53. ret = skl_prepare_lib_load(skl, &skl->lib_info[i], &stripped_fw,
  54. BXT_ADSP_FW_BIN_HDR_OFFSET, i);
  55. if (ret < 0)
  56. goto load_library_failed;
  57. stream_tag = ctx->dsp_ops.prepare(ctx->dev, 0x40,
  58. stripped_fw.size, &dmab);
  59. if (stream_tag <= 0) {
  60. dev_err(ctx->dev, "Lib prepare DMA err: %x\n",
  61. stream_tag);
  62. ret = stream_tag;
  63. goto load_library_failed;
  64. }
  65. dma_id = stream_tag - 1;
  66. memcpy(dmab.area, stripped_fw.data, stripped_fw.size);
  67. ctx->dsp_ops.trigger(ctx->dev, true, stream_tag);
  68. ret = skl_sst_ipc_load_library(&skl->ipc, dma_id, i, true);
  69. if (ret < 0)
  70. dev_err(ctx->dev, "IPC Load Lib for %s fail: %d\n",
  71. linfo[i].name, ret);
  72. ctx->dsp_ops.trigger(ctx->dev, false, stream_tag);
  73. ctx->dsp_ops.cleanup(ctx->dev, &dmab, stream_tag);
  74. }
  75. return ret;
  76. load_library_failed:
  77. skl_release_library(linfo, lib_count);
  78. return ret;
  79. }
  80. /*
  81. * First boot sequence has some extra steps. Core 0 waits for power
  82. * status on core 1, so power up core 1 also momentarily, keep it in
  83. * reset/stall and then turn it off
  84. */
  85. static int sst_bxt_prepare_fw(struct sst_dsp *ctx,
  86. const void *fwdata, u32 fwsize)
  87. {
  88. int stream_tag, ret;
  89. stream_tag = ctx->dsp_ops.prepare(ctx->dev, 0x40, fwsize, &ctx->dmab);
  90. if (stream_tag <= 0) {
  91. dev_err(ctx->dev, "Failed to prepare DMA FW loading err: %x\n",
  92. stream_tag);
  93. return stream_tag;
  94. }
  95. ctx->dsp_ops.stream_tag = stream_tag;
  96. memcpy(ctx->dmab.area, fwdata, fwsize);
  97. /* Step 1: Power up core 0 and core1 */
  98. ret = skl_dsp_core_power_up(ctx, SKL_DSP_CORE0_MASK |
  99. SKL_DSP_CORE_MASK(1));
  100. if (ret < 0) {
  101. dev_err(ctx->dev, "dsp core0/1 power up failed\n");
  102. goto base_fw_load_failed;
  103. }
  104. /* Step 2: Purge FW request */
  105. sst_dsp_shim_write(ctx, SKL_ADSP_REG_HIPCI, SKL_ADSP_REG_HIPCI_BUSY |
  106. (BXT_IPC_PURGE_FW | ((stream_tag - 1) << 9)));
  107. /* Step 3: Unset core0 reset state & unstall/run core0 */
  108. ret = skl_dsp_start_core(ctx, SKL_DSP_CORE0_MASK);
  109. if (ret < 0) {
  110. dev_err(ctx->dev, "Start dsp core failed ret: %d\n", ret);
  111. ret = -EIO;
  112. goto base_fw_load_failed;
  113. }
  114. /* Step 4: Wait for DONE Bit */
  115. ret = sst_dsp_register_poll(ctx, SKL_ADSP_REG_HIPCIE,
  116. SKL_ADSP_REG_HIPCIE_DONE,
  117. SKL_ADSP_REG_HIPCIE_DONE,
  118. BXT_INIT_TIMEOUT, "HIPCIE Done");
  119. if (ret < 0) {
  120. dev_err(ctx->dev, "Timeout for Purge Request%d\n", ret);
  121. goto base_fw_load_failed;
  122. }
  123. /* Step 5: power down core1 */
  124. ret = skl_dsp_core_power_down(ctx, SKL_DSP_CORE_MASK(1));
  125. if (ret < 0) {
  126. dev_err(ctx->dev, "dsp core1 power down failed\n");
  127. goto base_fw_load_failed;
  128. }
  129. /* Step 6: Enable Interrupt */
  130. skl_ipc_int_enable(ctx);
  131. skl_ipc_op_int_enable(ctx);
  132. /* Step 7: Wait for ROM init */
  133. ret = sst_dsp_register_poll(ctx, BXT_ADSP_FW_STATUS, SKL_FW_STS_MASK,
  134. SKL_FW_INIT, BXT_ROM_INIT_TIMEOUT, "ROM Load");
  135. if (ret < 0) {
  136. dev_err(ctx->dev, "Timeout for ROM init, ret:%d\n", ret);
  137. goto base_fw_load_failed;
  138. }
  139. return ret;
  140. base_fw_load_failed:
  141. ctx->dsp_ops.cleanup(ctx->dev, &ctx->dmab, stream_tag);
  142. skl_dsp_core_power_down(ctx, SKL_DSP_CORE_MASK(1));
  143. skl_dsp_disable_core(ctx, SKL_DSP_CORE0_MASK);
  144. return ret;
  145. }
  146. static int sst_transfer_fw_host_dma(struct sst_dsp *ctx)
  147. {
  148. int ret;
  149. ctx->dsp_ops.trigger(ctx->dev, true, ctx->dsp_ops.stream_tag);
  150. ret = sst_dsp_register_poll(ctx, BXT_ADSP_FW_STATUS, SKL_FW_STS_MASK,
  151. BXT_ROM_INIT, BXT_BASEFW_TIMEOUT, "Firmware boot");
  152. ctx->dsp_ops.trigger(ctx->dev, false, ctx->dsp_ops.stream_tag);
  153. ctx->dsp_ops.cleanup(ctx->dev, &ctx->dmab, ctx->dsp_ops.stream_tag);
  154. return ret;
  155. }
  156. static int bxt_load_base_firmware(struct sst_dsp *ctx)
  157. {
  158. struct firmware stripped_fw;
  159. struct skl_sst *skl = ctx->thread_context;
  160. int ret, i;
  161. if (ctx->fw == NULL) {
  162. ret = request_firmware(&ctx->fw, ctx->fw_name, ctx->dev);
  163. if (ret < 0) {
  164. dev_err(ctx->dev, "Request firmware failed %d\n", ret);
  165. return ret;
  166. }
  167. }
  168. /* prase uuids on first boot */
  169. if (skl->is_first_boot) {
  170. ret = snd_skl_parse_uuids(ctx, ctx->fw, BXT_ADSP_FW_BIN_HDR_OFFSET, 0);
  171. if (ret < 0)
  172. goto sst_load_base_firmware_failed;
  173. }
  174. stripped_fw.data = ctx->fw->data;
  175. stripped_fw.size = ctx->fw->size;
  176. skl_dsp_strip_extended_manifest(&stripped_fw);
  177. for (i = 0; i < BXT_FW_ROM_INIT_RETRY; i++) {
  178. ret = sst_bxt_prepare_fw(ctx, stripped_fw.data, stripped_fw.size);
  179. if (ret == 0)
  180. break;
  181. }
  182. if (ret < 0) {
  183. dev_err(ctx->dev, "Error code=0x%x: FW status=0x%x\n",
  184. sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE),
  185. sst_dsp_shim_read(ctx, BXT_ADSP_FW_STATUS));
  186. dev_err(ctx->dev, "Core En/ROM load fail:%d\n", ret);
  187. goto sst_load_base_firmware_failed;
  188. }
  189. ret = sst_transfer_fw_host_dma(ctx);
  190. if (ret < 0) {
  191. dev_err(ctx->dev, "Transfer firmware failed %d\n", ret);
  192. dev_info(ctx->dev, "Error code=0x%x: FW status=0x%x\n",
  193. sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE),
  194. sst_dsp_shim_read(ctx, BXT_ADSP_FW_STATUS));
  195. skl_dsp_disable_core(ctx, SKL_DSP_CORE0_MASK);
  196. } else {
  197. dev_dbg(ctx->dev, "Firmware download successful\n");
  198. ret = wait_event_timeout(skl->boot_wait, skl->boot_complete,
  199. msecs_to_jiffies(SKL_IPC_BOOT_MSECS));
  200. if (ret == 0) {
  201. dev_err(ctx->dev, "DSP boot fail, FW Ready timeout\n");
  202. skl_dsp_disable_core(ctx, SKL_DSP_CORE0_MASK);
  203. ret = -EIO;
  204. } else {
  205. ret = 0;
  206. skl->fw_loaded = true;
  207. }
  208. }
  209. return ret;
  210. sst_load_base_firmware_failed:
  211. release_firmware(ctx->fw);
  212. ctx->fw = NULL;
  213. return ret;
  214. }
  215. /*
  216. * Decide the D0i3 state that can be targeted based on the usecase
  217. * ref counts and DSP state
  218. *
  219. * Decision Matrix: (X= dont care; state = target state)
  220. *
  221. * DSP state != SKL_DSP_RUNNING ; state = no d0i3
  222. *
  223. * DSP state == SKL_DSP_RUNNING , the following matrix applies
  224. * non_d0i3 >0; streaming =X; non_streaming =X; state = no d0i3
  225. * non_d0i3 =X; streaming =0; non_streaming =0; state = no d0i3
  226. * non_d0i3 =0; streaming >0; non_streaming =X; state = streaming d0i3
  227. * non_d0i3 =0; streaming =0; non_streaming =X; state = non-streaming d0i3
  228. */
  229. static int bxt_d0i3_target_state(struct sst_dsp *ctx)
  230. {
  231. struct skl_sst *skl = ctx->thread_context;
  232. struct skl_d0i3_data *d0i3 = &skl->d0i3;
  233. if (skl->cores.state[SKL_DSP_CORE0_ID] != SKL_DSP_RUNNING)
  234. return SKL_DSP_D0I3_NONE;
  235. if (d0i3->non_d0i3)
  236. return SKL_DSP_D0I3_NONE;
  237. else if (d0i3->streaming)
  238. return SKL_DSP_D0I3_STREAMING;
  239. else if (d0i3->non_streaming)
  240. return SKL_DSP_D0I3_NON_STREAMING;
  241. else
  242. return SKL_DSP_D0I3_NONE;
  243. }
  244. static void bxt_set_dsp_D0i3(struct work_struct *work)
  245. {
  246. int ret;
  247. struct skl_ipc_d0ix_msg msg;
  248. struct skl_sst *skl = container_of(work,
  249. struct skl_sst, d0i3.work.work);
  250. struct sst_dsp *ctx = skl->dsp;
  251. struct skl_d0i3_data *d0i3 = &skl->d0i3;
  252. int target_state;
  253. dev_dbg(ctx->dev, "In %s:\n", __func__);
  254. /* D0i3 entry allowed only if core 0 alone is running */
  255. if (skl_dsp_get_enabled_cores(ctx) != SKL_DSP_CORE0_MASK) {
  256. dev_warn(ctx->dev,
  257. "D0i3 allowed when only core0 running:Exit\n");
  258. return;
  259. }
  260. target_state = bxt_d0i3_target_state(ctx);
  261. if (target_state == SKL_DSP_D0I3_NONE)
  262. return;
  263. msg.instance_id = 0;
  264. msg.module_id = 0;
  265. msg.wake = 1;
  266. msg.streaming = 0;
  267. if (target_state == SKL_DSP_D0I3_STREAMING)
  268. msg.streaming = 1;
  269. ret = skl_ipc_set_d0ix(&skl->ipc, &msg);
  270. if (ret < 0) {
  271. dev_err(ctx->dev, "Failed to set DSP to D0i3 state\n");
  272. return;
  273. }
  274. /* Set Vendor specific register D0I3C.I3 to enable D0i3*/
  275. if (skl->update_d0i3c)
  276. skl->update_d0i3c(skl->dev, true);
  277. d0i3->state = target_state;
  278. skl->cores.state[SKL_DSP_CORE0_ID] = SKL_DSP_RUNNING_D0I3;
  279. }
  280. static int bxt_schedule_dsp_D0i3(struct sst_dsp *ctx)
  281. {
  282. struct skl_sst *skl = ctx->thread_context;
  283. struct skl_d0i3_data *d0i3 = &skl->d0i3;
  284. /* Schedule D0i3 only if the usecase ref counts are appropriate */
  285. if (bxt_d0i3_target_state(ctx) != SKL_DSP_D0I3_NONE) {
  286. dev_dbg(ctx->dev, "%s: Schedule D0i3\n", __func__);
  287. schedule_delayed_work(&d0i3->work,
  288. msecs_to_jiffies(BXT_D0I3_DELAY));
  289. }
  290. return 0;
  291. }
  292. static int bxt_set_dsp_D0i0(struct sst_dsp *ctx)
  293. {
  294. int ret;
  295. struct skl_ipc_d0ix_msg msg;
  296. struct skl_sst *skl = ctx->thread_context;
  297. dev_dbg(ctx->dev, "In %s:\n", __func__);
  298. /* First Cancel any pending attempt to put DSP to D0i3 */
  299. cancel_delayed_work_sync(&skl->d0i3.work);
  300. /* If DSP is currently in D0i3, bring it to D0i0 */
  301. if (skl->cores.state[SKL_DSP_CORE0_ID] != SKL_DSP_RUNNING_D0I3)
  302. return 0;
  303. dev_dbg(ctx->dev, "Set DSP to D0i0\n");
  304. msg.instance_id = 0;
  305. msg.module_id = 0;
  306. msg.streaming = 0;
  307. msg.wake = 0;
  308. if (skl->d0i3.state == SKL_DSP_D0I3_STREAMING)
  309. msg.streaming = 1;
  310. /* Clear Vendor specific register D0I3C.I3 to disable D0i3*/
  311. if (skl->update_d0i3c)
  312. skl->update_d0i3c(skl->dev, false);
  313. ret = skl_ipc_set_d0ix(&skl->ipc, &msg);
  314. if (ret < 0) {
  315. dev_err(ctx->dev, "Failed to set DSP to D0i0\n");
  316. return ret;
  317. }
  318. skl->cores.state[SKL_DSP_CORE0_ID] = SKL_DSP_RUNNING;
  319. skl->d0i3.state = SKL_DSP_D0I3_NONE;
  320. return 0;
  321. }
  322. static int bxt_set_dsp_D0(struct sst_dsp *ctx, unsigned int core_id)
  323. {
  324. struct skl_sst *skl = ctx->thread_context;
  325. int ret;
  326. struct skl_ipc_dxstate_info dx;
  327. unsigned int core_mask = SKL_DSP_CORE_MASK(core_id);
  328. if (skl->fw_loaded == false) {
  329. skl->boot_complete = false;
  330. ret = bxt_load_base_firmware(ctx);
  331. if (ret < 0) {
  332. dev_err(ctx->dev, "reload fw failed: %d\n", ret);
  333. return ret;
  334. }
  335. if (skl->lib_count > 1) {
  336. ret = bxt_load_library(ctx, skl->lib_info,
  337. skl->lib_count);
  338. if (ret < 0) {
  339. dev_err(ctx->dev, "reload libs failed: %d\n", ret);
  340. return ret;
  341. }
  342. }
  343. skl->cores.state[core_id] = SKL_DSP_RUNNING;
  344. return ret;
  345. }
  346. /* If core 0 is being turned on, turn on core 1 as well */
  347. if (core_id == SKL_DSP_CORE0_ID)
  348. ret = skl_dsp_core_power_up(ctx, core_mask |
  349. SKL_DSP_CORE_MASK(1));
  350. else
  351. ret = skl_dsp_core_power_up(ctx, core_mask);
  352. if (ret < 0)
  353. goto err;
  354. if (core_id == SKL_DSP_CORE0_ID) {
  355. /*
  356. * Enable interrupt after SPA is set and before
  357. * DSP is unstalled
  358. */
  359. skl_ipc_int_enable(ctx);
  360. skl_ipc_op_int_enable(ctx);
  361. skl->boot_complete = false;
  362. }
  363. ret = skl_dsp_start_core(ctx, core_mask);
  364. if (ret < 0)
  365. goto err;
  366. if (core_id == SKL_DSP_CORE0_ID) {
  367. ret = wait_event_timeout(skl->boot_wait,
  368. skl->boot_complete,
  369. msecs_to_jiffies(SKL_IPC_BOOT_MSECS));
  370. /* If core 1 was turned on for booting core 0, turn it off */
  371. skl_dsp_core_power_down(ctx, SKL_DSP_CORE_MASK(1));
  372. if (ret == 0) {
  373. dev_err(ctx->dev, "%s: DSP boot timeout\n", __func__);
  374. dev_err(ctx->dev, "Error code=0x%x: FW status=0x%x\n",
  375. sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE),
  376. sst_dsp_shim_read(ctx, BXT_ADSP_FW_STATUS));
  377. dev_err(ctx->dev, "Failed to set core0 to D0 state\n");
  378. ret = -EIO;
  379. goto err;
  380. }
  381. }
  382. /* Tell FW if additional core in now On */
  383. if (core_id != SKL_DSP_CORE0_ID) {
  384. dx.core_mask = core_mask;
  385. dx.dx_mask = core_mask;
  386. ret = skl_ipc_set_dx(&skl->ipc, BXT_INSTANCE_ID,
  387. BXT_BASE_FW_MODULE_ID, &dx);
  388. if (ret < 0) {
  389. dev_err(ctx->dev, "IPC set_dx for core %d fail: %d\n",
  390. core_id, ret);
  391. goto err;
  392. }
  393. }
  394. skl->cores.state[core_id] = SKL_DSP_RUNNING;
  395. return 0;
  396. err:
  397. if (core_id == SKL_DSP_CORE0_ID)
  398. core_mask |= SKL_DSP_CORE_MASK(1);
  399. skl_dsp_disable_core(ctx, core_mask);
  400. return ret;
  401. }
  402. static int bxt_set_dsp_D3(struct sst_dsp *ctx, unsigned int core_id)
  403. {
  404. int ret;
  405. struct skl_ipc_dxstate_info dx;
  406. struct skl_sst *skl = ctx->thread_context;
  407. unsigned int core_mask = SKL_DSP_CORE_MASK(core_id);
  408. dx.core_mask = core_mask;
  409. dx.dx_mask = SKL_IPC_D3_MASK;
  410. dev_dbg(ctx->dev, "core mask=%x dx_mask=%x\n",
  411. dx.core_mask, dx.dx_mask);
  412. ret = skl_ipc_set_dx(&skl->ipc, BXT_INSTANCE_ID,
  413. BXT_BASE_FW_MODULE_ID, &dx);
  414. if (ret < 0) {
  415. dev_err(ctx->dev,
  416. "Failed to set DSP to D3:core id = %d;Continue reset\n",
  417. core_id);
  418. /*
  419. * In case of D3 failure, re-download the firmware, so set
  420. * fw_loaded to false.
  421. */
  422. skl->fw_loaded = false;
  423. }
  424. if (core_id == SKL_DSP_CORE0_ID) {
  425. /* disable Interrupt */
  426. skl_ipc_op_int_disable(ctx);
  427. skl_ipc_int_disable(ctx);
  428. }
  429. ret = skl_dsp_disable_core(ctx, core_mask);
  430. if (ret < 0) {
  431. dev_err(ctx->dev, "Failed to disable core %d\n", ret);
  432. return ret;
  433. }
  434. skl->cores.state[core_id] = SKL_DSP_RESET;
  435. return 0;
  436. }
  437. static const struct skl_dsp_fw_ops bxt_fw_ops = {
  438. .set_state_D0 = bxt_set_dsp_D0,
  439. .set_state_D3 = bxt_set_dsp_D3,
  440. .set_state_D0i3 = bxt_schedule_dsp_D0i3,
  441. .set_state_D0i0 = bxt_set_dsp_D0i0,
  442. .load_fw = bxt_load_base_firmware,
  443. .get_fw_errcode = bxt_get_errorcode,
  444. .load_library = bxt_load_library,
  445. };
  446. static struct sst_ops skl_ops = {
  447. .irq_handler = skl_dsp_sst_interrupt,
  448. .write = sst_shim32_write,
  449. .read = sst_shim32_read,
  450. .ram_read = sst_memcpy_fromio_32,
  451. .ram_write = sst_memcpy_toio_32,
  452. .free = skl_dsp_free,
  453. };
  454. static struct sst_dsp_device skl_dev = {
  455. .thread = skl_dsp_irq_thread_handler,
  456. .ops = &skl_ops,
  457. };
  458. int bxt_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq,
  459. const char *fw_name, struct skl_dsp_loader_ops dsp_ops,
  460. struct skl_sst **dsp)
  461. {
  462. struct skl_sst *skl;
  463. struct sst_dsp *sst;
  464. int ret;
  465. ret = skl_sst_ctx_init(dev, irq, fw_name, dsp_ops, dsp, &skl_dev);
  466. if (ret < 0) {
  467. dev_err(dev, "%s: no device\n", __func__);
  468. return ret;
  469. }
  470. skl = *dsp;
  471. sst = skl->dsp;
  472. sst->fw_ops = bxt_fw_ops;
  473. sst->addr.lpe = mmio_base;
  474. sst->addr.shim = mmio_base;
  475. sst->addr.sram0_base = BXT_ADSP_SRAM0_BASE;
  476. sst->addr.sram1_base = BXT_ADSP_SRAM1_BASE;
  477. sst->addr.w0_stat_sz = SKL_ADSP_W0_STAT_SZ;
  478. sst->addr.w0_up_sz = SKL_ADSP_W0_UP_SZ;
  479. sst_dsp_mailbox_init(sst, (BXT_ADSP_SRAM0_BASE + SKL_ADSP_W0_STAT_SZ),
  480. SKL_ADSP_W0_UP_SZ, BXT_ADSP_SRAM1_BASE, SKL_ADSP_W1_SZ);
  481. ret = skl_ipc_init(dev, skl);
  482. if (ret) {
  483. skl_dsp_free(sst);
  484. return ret;
  485. }
  486. /* set the D0i3 check */
  487. skl->ipc.ops.check_dsp_lp_on = skl_ipc_check_D0i0;
  488. skl->boot_complete = false;
  489. init_waitqueue_head(&skl->boot_wait);
  490. INIT_DELAYED_WORK(&skl->d0i3.work, bxt_set_dsp_D0i3);
  491. skl->d0i3.state = SKL_DSP_D0I3_NONE;
  492. return skl_dsp_acquire_irq(sst);
  493. }
  494. EXPORT_SYMBOL_GPL(bxt_sst_dsp_init);
  495. int bxt_sst_init_fw(struct device *dev, struct skl_sst *ctx)
  496. {
  497. int ret;
  498. struct sst_dsp *sst = ctx->dsp;
  499. ret = sst->fw_ops.load_fw(sst);
  500. if (ret < 0) {
  501. dev_err(dev, "Load base fw failed: %x\n", ret);
  502. return ret;
  503. }
  504. skl_dsp_init_core_state(sst);
  505. if (ctx->lib_count > 1) {
  506. ret = sst->fw_ops.load_library(sst, ctx->lib_info,
  507. ctx->lib_count);
  508. if (ret < 0) {
  509. dev_err(dev, "Load Library failed : %x\n", ret);
  510. return ret;
  511. }
  512. }
  513. ctx->is_first_boot = false;
  514. return 0;
  515. }
  516. EXPORT_SYMBOL_GPL(bxt_sst_init_fw);
  517. void bxt_sst_dsp_cleanup(struct device *dev, struct skl_sst *ctx)
  518. {
  519. skl_release_library(ctx->lib_info, ctx->lib_count);
  520. if (ctx->dsp->fw)
  521. release_firmware(ctx->dsp->fw);
  522. skl_freeup_uuid_list(ctx);
  523. skl_ipc_free(&ctx->ipc);
  524. ctx->dsp->ops->free(ctx->dsp);
  525. }
  526. EXPORT_SYMBOL_GPL(bxt_sst_dsp_cleanup);
  527. MODULE_LICENSE("GPL v2");
  528. MODULE_DESCRIPTION("Intel Broxton IPC driver");