bxt-sst.c 17 KB

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