sst-haswell-dsp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. * Intel Haswell SST DSP driver
  3. *
  4. * Copyright (C) 2013, Intel Corporation. All rights reserved.
  5. *
  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.
  9. *
  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.
  14. *
  15. */
  16. #include <linux/delay.h>
  17. #include <linux/fs.h>
  18. #include <linux/slab.h>
  19. #include <linux/device.h>
  20. #include <linux/sched.h>
  21. #include <linux/export.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/module.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/pci.h>
  27. #include <linux/firmware.h>
  28. #include <linux/pm_runtime.h>
  29. #include "../common/sst-dsp.h"
  30. #include "../common/sst-dsp-priv.h"
  31. #include "../haswell/sst-haswell-ipc.h"
  32. #include <trace/events/hswadsp.h>
  33. #define SST_HSW_FW_SIGNATURE_SIZE 4
  34. #define SST_HSW_FW_SIGN "$SST"
  35. #define SST_HSW_FW_LIB_SIGN "$LIB"
  36. #define SST_WPT_SHIM_OFFSET 0xFB000
  37. #define SST_LP_SHIM_OFFSET 0xE7000
  38. #define SST_WPT_IRAM_OFFSET 0xA0000
  39. #define SST_LP_IRAM_OFFSET 0x80000
  40. #define SST_WPT_DSP_DRAM_OFFSET 0x400000
  41. #define SST_WPT_DSP_IRAM_OFFSET 0x00000
  42. #define SST_LPT_DSP_DRAM_OFFSET 0x400000
  43. #define SST_LPT_DSP_IRAM_OFFSET 0x00000
  44. #define SST_SHIM_PM_REG 0x84
  45. #define SST_HSW_IRAM 1
  46. #define SST_HSW_DRAM 2
  47. #define SST_HSW_REGS 3
  48. struct dma_block_info {
  49. __le32 type; /* IRAM/DRAM */
  50. __le32 size; /* Bytes */
  51. __le32 ram_offset; /* Offset in I/DRAM */
  52. __le32 rsvd; /* Reserved field */
  53. } __attribute__((packed));
  54. struct fw_module_info {
  55. __le32 persistent_size;
  56. __le32 scratch_size;
  57. } __attribute__((packed));
  58. struct fw_header {
  59. unsigned char signature[SST_HSW_FW_SIGNATURE_SIZE]; /* FW signature */
  60. __le32 file_size; /* size of fw minus this header */
  61. __le32 modules; /* # of modules */
  62. __le32 file_format; /* version of header format */
  63. __le32 reserved[4];
  64. } __attribute__((packed));
  65. struct fw_module_header {
  66. unsigned char signature[SST_HSW_FW_SIGNATURE_SIZE]; /* module signature */
  67. __le32 mod_size; /* size of module */
  68. __le32 blocks; /* # of blocks */
  69. __le16 padding;
  70. __le16 type; /* codec type, pp lib */
  71. __le32 entry_point;
  72. struct fw_module_info info;
  73. } __attribute__((packed));
  74. static void hsw_free(struct sst_dsp *sst);
  75. static int hsw_parse_module(struct sst_dsp *dsp, struct sst_fw *fw,
  76. struct fw_module_header *module)
  77. {
  78. struct dma_block_info *block;
  79. struct sst_module *mod;
  80. struct sst_module_template template;
  81. int count, ret;
  82. void __iomem *ram;
  83. /* TODO: allowed module types need to be configurable */
  84. if (module->type != SST_HSW_MODULE_BASE_FW
  85. && module->type != SST_HSW_MODULE_PCM_SYSTEM
  86. && module->type != SST_HSW_MODULE_PCM
  87. && module->type != SST_HSW_MODULE_PCM_REFERENCE
  88. && module->type != SST_HSW_MODULE_PCM_CAPTURE
  89. && module->type != SST_HSW_MODULE_WAVES
  90. && module->type != SST_HSW_MODULE_LPAL)
  91. return 0;
  92. dev_dbg(dsp->dev, "new module sign 0x%s size 0x%x blocks 0x%x type 0x%x\n",
  93. module->signature, module->mod_size,
  94. module->blocks, module->type);
  95. dev_dbg(dsp->dev, " entrypoint 0x%x\n", module->entry_point);
  96. dev_dbg(dsp->dev, " persistent 0x%x scratch 0x%x\n",
  97. module->info.persistent_size, module->info.scratch_size);
  98. memset(&template, 0, sizeof(template));
  99. template.id = module->type;
  100. template.entry = module->entry_point - 4;
  101. template.persistent_size = module->info.persistent_size;
  102. template.scratch_size = module->info.scratch_size;
  103. mod = sst_module_new(fw, &template, NULL);
  104. if (mod == NULL)
  105. return -ENOMEM;
  106. block = (void *)module + sizeof(*module);
  107. for (count = 0; count < module->blocks; count++) {
  108. if (block->size <= 0) {
  109. dev_err(dsp->dev,
  110. "error: block %d size invalid\n", count);
  111. sst_module_free(mod);
  112. return -EINVAL;
  113. }
  114. switch (block->type) {
  115. case SST_HSW_IRAM:
  116. ram = dsp->addr.lpe;
  117. mod->offset =
  118. block->ram_offset + dsp->addr.iram_offset;
  119. mod->type = SST_MEM_IRAM;
  120. break;
  121. case SST_HSW_DRAM:
  122. case SST_HSW_REGS:
  123. ram = dsp->addr.lpe;
  124. mod->offset = block->ram_offset;
  125. mod->type = SST_MEM_DRAM;
  126. break;
  127. default:
  128. dev_err(dsp->dev, "error: bad type 0x%x for block 0x%x\n",
  129. block->type, count);
  130. sst_module_free(mod);
  131. return -EINVAL;
  132. }
  133. mod->size = block->size;
  134. mod->data = (void *)block + sizeof(*block);
  135. mod->data_offset = mod->data - fw->dma_buf;
  136. dev_dbg(dsp->dev, "module block %d type 0x%x "
  137. "size 0x%x ==> ram %p offset 0x%x\n",
  138. count, mod->type, block->size, ram,
  139. block->ram_offset);
  140. ret = sst_module_alloc_blocks(mod);
  141. if (ret < 0) {
  142. dev_err(dsp->dev, "error: could not allocate blocks for module %d\n",
  143. count);
  144. sst_module_free(mod);
  145. return ret;
  146. }
  147. block = (void *)block + sizeof(*block) + block->size;
  148. }
  149. mod->state = SST_MODULE_STATE_LOADED;
  150. return 0;
  151. }
  152. static int hsw_parse_fw_image(struct sst_fw *sst_fw)
  153. {
  154. struct fw_header *header;
  155. struct fw_module_header *module;
  156. struct sst_dsp *dsp = sst_fw->dsp;
  157. int ret, count;
  158. /* Read the header information from the data pointer */
  159. header = (struct fw_header *)sst_fw->dma_buf;
  160. /* verify FW */
  161. if ((strncmp(header->signature, SST_HSW_FW_SIGN, 4) != 0) ||
  162. (sst_fw->size != header->file_size + sizeof(*header))) {
  163. dev_err(dsp->dev, "error: invalid fw sign/filesize mismatch\n");
  164. return -EINVAL;
  165. }
  166. dev_dbg(dsp->dev, "header size=0x%x modules=0x%x fmt=0x%x size=%zu\n",
  167. header->file_size, header->modules,
  168. header->file_format, sizeof(*header));
  169. /* parse each module */
  170. module = (void *)sst_fw->dma_buf + sizeof(*header);
  171. for (count = 0; count < header->modules; count++) {
  172. /* module */
  173. ret = hsw_parse_module(dsp, sst_fw, module);
  174. if (ret < 0) {
  175. dev_err(dsp->dev, "error: invalid module %d\n", count);
  176. return ret;
  177. }
  178. module = (void *)module + sizeof(*module) + module->mod_size;
  179. }
  180. return 0;
  181. }
  182. static irqreturn_t hsw_irq(int irq, void *context)
  183. {
  184. struct sst_dsp *sst = (struct sst_dsp *) context;
  185. u32 isr;
  186. int ret = IRQ_NONE;
  187. spin_lock(&sst->spinlock);
  188. /* Interrupt arrived, check src */
  189. isr = sst_dsp_shim_read_unlocked(sst, SST_ISRX);
  190. if (isr & SST_ISRX_DONE) {
  191. trace_sst_irq_done(isr,
  192. sst_dsp_shim_read_unlocked(sst, SST_IMRX));
  193. /* Mask Done interrupt before return */
  194. sst_dsp_shim_update_bits_unlocked(sst, SST_IMRX,
  195. SST_IMRX_DONE, SST_IMRX_DONE);
  196. ret = IRQ_WAKE_THREAD;
  197. }
  198. if (isr & SST_ISRX_BUSY) {
  199. trace_sst_irq_busy(isr,
  200. sst_dsp_shim_read_unlocked(sst, SST_IMRX));
  201. /* Mask Busy interrupt before return */
  202. sst_dsp_shim_update_bits_unlocked(sst, SST_IMRX,
  203. SST_IMRX_BUSY, SST_IMRX_BUSY);
  204. ret = IRQ_WAKE_THREAD;
  205. }
  206. spin_unlock(&sst->spinlock);
  207. return ret;
  208. }
  209. static void hsw_set_dsp_D3(struct sst_dsp *sst)
  210. {
  211. u32 val;
  212. u32 reg;
  213. /* Disable core clock gating (VDRTCTL2.DCLCGE = 0) */
  214. reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
  215. reg &= ~(SST_VDRTCL2_DCLCGE | SST_VDRTCL2_DTCGE);
  216. writel(reg, sst->addr.pci_cfg + SST_VDRTCTL2);
  217. /* enable power gating and switch off DRAM & IRAM blocks */
  218. val = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
  219. val |= SST_VDRTCL0_DSRAMPGE_MASK |
  220. SST_VDRTCL0_ISRAMPGE_MASK;
  221. val &= ~(SST_VDRTCL0_D3PGD | SST_VDRTCL0_D3SRAMPGD);
  222. writel(val, sst->addr.pci_cfg + SST_VDRTCTL0);
  223. /* switch off audio PLL */
  224. val = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
  225. val |= SST_VDRTCL2_APLLSE_MASK;
  226. writel(val, sst->addr.pci_cfg + SST_VDRTCTL2);
  227. /* disable MCLK(clkctl.smos = 0) */
  228. sst_dsp_shim_update_bits_unlocked(sst, SST_CLKCTL,
  229. SST_CLKCTL_MASK, 0);
  230. /* Set D3 state, delay 50 us */
  231. val = readl(sst->addr.pci_cfg + SST_PMCS);
  232. val |= SST_PMCS_PS_MASK;
  233. writel(val, sst->addr.pci_cfg + SST_PMCS);
  234. udelay(50);
  235. /* Enable core clock gating (VDRTCTL2.DCLCGE = 1), delay 50 us */
  236. reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
  237. reg |= SST_VDRTCL2_DCLCGE | SST_VDRTCL2_DTCGE;
  238. writel(reg, sst->addr.pci_cfg + SST_VDRTCTL2);
  239. udelay(50);
  240. }
  241. static void hsw_reset(struct sst_dsp *sst)
  242. {
  243. /* put DSP into reset and stall */
  244. sst_dsp_shim_update_bits_unlocked(sst, SST_CSR,
  245. SST_CSR_RST | SST_CSR_STALL,
  246. SST_CSR_RST | SST_CSR_STALL);
  247. /* keep in reset for 10ms */
  248. mdelay(10);
  249. /* take DSP out of reset and keep stalled for FW loading */
  250. sst_dsp_shim_update_bits_unlocked(sst, SST_CSR,
  251. SST_CSR_RST | SST_CSR_STALL, SST_CSR_STALL);
  252. }
  253. static int hsw_set_dsp_D0(struct sst_dsp *sst)
  254. {
  255. int tries = 10;
  256. u32 reg, fw_dump_bit;
  257. /* Disable core clock gating (VDRTCTL2.DCLCGE = 0) */
  258. reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
  259. reg &= ~(SST_VDRTCL2_DCLCGE | SST_VDRTCL2_DTCGE);
  260. writel(reg, sst->addr.pci_cfg + SST_VDRTCTL2);
  261. /* Disable D3PG (VDRTCTL0.D3PGD = 1) */
  262. reg = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
  263. reg |= SST_VDRTCL0_D3PGD;
  264. writel(reg, sst->addr.pci_cfg + SST_VDRTCTL0);
  265. /* Set D0 state */
  266. reg = readl(sst->addr.pci_cfg + SST_PMCS);
  267. reg &= ~SST_PMCS_PS_MASK;
  268. writel(reg, sst->addr.pci_cfg + SST_PMCS);
  269. /* check that ADSP shim is enabled */
  270. while (tries--) {
  271. reg = readl(sst->addr.pci_cfg + SST_PMCS) & SST_PMCS_PS_MASK;
  272. if (reg == 0)
  273. goto finish;
  274. msleep(1);
  275. }
  276. return -ENODEV;
  277. finish:
  278. /* select SSP1 19.2MHz base clock, SSP clock 0, turn off Low Power Clock */
  279. sst_dsp_shim_update_bits_unlocked(sst, SST_CSR,
  280. SST_CSR_S1IOCS | SST_CSR_SBCS1 | SST_CSR_LPCS, 0x0);
  281. /* stall DSP core, set clk to 192/96Mhz */
  282. sst_dsp_shim_update_bits_unlocked(sst,
  283. SST_CSR, SST_CSR_STALL | SST_CSR_DCS_MASK,
  284. SST_CSR_STALL | SST_CSR_DCS(4));
  285. /* Set 24MHz MCLK, prevent local clock gating, enable SSP0 clock */
  286. sst_dsp_shim_update_bits_unlocked(sst, SST_CLKCTL,
  287. SST_CLKCTL_MASK | SST_CLKCTL_DCPLCG | SST_CLKCTL_SCOE0,
  288. SST_CLKCTL_MASK | SST_CLKCTL_DCPLCG | SST_CLKCTL_SCOE0);
  289. /* Stall and reset core, set CSR */
  290. hsw_reset(sst);
  291. /* Enable core clock gating (VDRTCTL2.DCLCGE = 1), delay 50 us */
  292. reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
  293. reg |= SST_VDRTCL2_DCLCGE | SST_VDRTCL2_DTCGE;
  294. writel(reg, sst->addr.pci_cfg + SST_VDRTCTL2);
  295. udelay(50);
  296. /* switch on audio PLL */
  297. reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
  298. reg &= ~SST_VDRTCL2_APLLSE_MASK;
  299. writel(reg, sst->addr.pci_cfg + SST_VDRTCTL2);
  300. /* set default power gating control, enable power gating control for all blocks. that is,
  301. can't be accessed, please enable each block before accessing. */
  302. reg = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
  303. reg |= SST_VDRTCL0_DSRAMPGE_MASK | SST_VDRTCL0_ISRAMPGE_MASK;
  304. /* for D0, always enable the block(DSRAM[0]) used for FW dump */
  305. fw_dump_bit = 1 << SST_VDRTCL0_DSRAMPGE_SHIFT;
  306. writel(reg & ~fw_dump_bit, sst->addr.pci_cfg + SST_VDRTCTL0);
  307. /* disable DMA finish function for SSP0 & SSP1 */
  308. sst_dsp_shim_update_bits_unlocked(sst, SST_CSR2, SST_CSR2_SDFD_SSP1,
  309. SST_CSR2_SDFD_SSP1);
  310. /* set on-demond mode on engine 0,1 for all channels */
  311. sst_dsp_shim_update_bits(sst, SST_HMDC,
  312. SST_HMDC_HDDA_E0_ALLCH | SST_HMDC_HDDA_E1_ALLCH,
  313. SST_HMDC_HDDA_E0_ALLCH | SST_HMDC_HDDA_E1_ALLCH);
  314. /* Enable Interrupt from both sides */
  315. sst_dsp_shim_update_bits(sst, SST_IMRX, (SST_IMRX_BUSY | SST_IMRX_DONE),
  316. 0x0);
  317. sst_dsp_shim_update_bits(sst, SST_IMRD, (SST_IMRD_DONE | SST_IMRD_BUSY |
  318. SST_IMRD_SSP0 | SST_IMRD_DMAC), 0x0);
  319. /* clear IPC registers */
  320. sst_dsp_shim_write(sst, SST_IPCX, 0x0);
  321. sst_dsp_shim_write(sst, SST_IPCD, 0x0);
  322. sst_dsp_shim_write(sst, 0x80, 0x6);
  323. sst_dsp_shim_write(sst, 0xe0, 0x300a);
  324. return 0;
  325. }
  326. static void hsw_boot(struct sst_dsp *sst)
  327. {
  328. /* set oportunistic mode on engine 0,1 for all channels */
  329. sst_dsp_shim_update_bits(sst, SST_HMDC,
  330. SST_HMDC_HDDA_E0_ALLCH | SST_HMDC_HDDA_E1_ALLCH, 0);
  331. /* set DSP to RUN */
  332. sst_dsp_shim_update_bits_unlocked(sst, SST_CSR, SST_CSR_STALL, 0x0);
  333. }
  334. static void hsw_stall(struct sst_dsp *sst)
  335. {
  336. /* stall DSP */
  337. sst_dsp_shim_update_bits(sst, SST_CSR,
  338. SST_CSR_24MHZ_LPCS | SST_CSR_STALL,
  339. SST_CSR_STALL | SST_CSR_24MHZ_LPCS);
  340. }
  341. static void hsw_sleep(struct sst_dsp *sst)
  342. {
  343. dev_dbg(sst->dev, "HSW_PM dsp runtime suspend\n");
  344. /* put DSP into reset and stall */
  345. sst_dsp_shim_update_bits(sst, SST_CSR,
  346. SST_CSR_24MHZ_LPCS | SST_CSR_RST | SST_CSR_STALL,
  347. SST_CSR_RST | SST_CSR_STALL | SST_CSR_24MHZ_LPCS);
  348. hsw_set_dsp_D3(sst);
  349. dev_dbg(sst->dev, "HSW_PM dsp runtime suspend exit\n");
  350. }
  351. static int hsw_wake(struct sst_dsp *sst)
  352. {
  353. int ret;
  354. dev_dbg(sst->dev, "HSW_PM dsp runtime resume\n");
  355. ret = hsw_set_dsp_D0(sst);
  356. if (ret < 0)
  357. return ret;
  358. dev_dbg(sst->dev, "HSW_PM dsp runtime resume exit\n");
  359. return 0;
  360. }
  361. struct sst_adsp_memregion {
  362. u32 start;
  363. u32 end;
  364. int blocks;
  365. enum sst_mem_type type;
  366. };
  367. /* lynx point ADSP mem regions */
  368. static const struct sst_adsp_memregion lp_region[] = {
  369. {0x00000, 0x40000, 8, SST_MEM_DRAM}, /* D-SRAM0 - 8 * 32kB */
  370. {0x40000, 0x80000, 8, SST_MEM_DRAM}, /* D-SRAM1 - 8 * 32kB */
  371. {0x80000, 0xE0000, 12, SST_MEM_IRAM}, /* I-SRAM - 12 * 32kB */
  372. };
  373. /* wild cat point ADSP mem regions */
  374. static const struct sst_adsp_memregion wpt_region[] = {
  375. {0x00000, 0xA0000, 20, SST_MEM_DRAM}, /* D-SRAM0,D-SRAM1,D-SRAM2 - 20 * 32kB */
  376. {0xA0000, 0xF0000, 10, SST_MEM_IRAM}, /* I-SRAM - 10 * 32kB */
  377. };
  378. static int hsw_acpi_resource_map(struct sst_dsp *sst, struct sst_pdata *pdata)
  379. {
  380. /* ADSP DRAM & IRAM */
  381. sst->addr.lpe_base = pdata->lpe_base;
  382. sst->addr.lpe = ioremap(pdata->lpe_base, pdata->lpe_size);
  383. if (!sst->addr.lpe)
  384. return -ENODEV;
  385. /* ADSP PCI MMIO config space */
  386. sst->addr.pci_cfg = ioremap(pdata->pcicfg_base, pdata->pcicfg_size);
  387. if (!sst->addr.pci_cfg) {
  388. iounmap(sst->addr.lpe);
  389. return -ENODEV;
  390. }
  391. /* SST Shim */
  392. sst->addr.shim = sst->addr.lpe + sst->addr.shim_offset;
  393. return 0;
  394. }
  395. struct sst_sram_shift {
  396. u32 dev_id; /* SST Device IDs */
  397. u32 iram_shift;
  398. u32 dram_shift;
  399. };
  400. static const struct sst_sram_shift sram_shift[] = {
  401. {SST_DEV_ID_LYNX_POINT, 6, 16}, /* lp */
  402. {SST_DEV_ID_WILDCAT_POINT, 2, 12}, /* wpt */
  403. };
  404. static u32 hsw_block_get_bit(struct sst_mem_block *block)
  405. {
  406. u32 bit = 0, shift = 0, index;
  407. struct sst_dsp *sst = block->dsp;
  408. for (index = 0; index < ARRAY_SIZE(sram_shift); index++) {
  409. if (sram_shift[index].dev_id == sst->id)
  410. break;
  411. }
  412. if (index < ARRAY_SIZE(sram_shift)) {
  413. switch (block->type) {
  414. case SST_MEM_DRAM:
  415. shift = sram_shift[index].dram_shift;
  416. break;
  417. case SST_MEM_IRAM:
  418. shift = sram_shift[index].iram_shift;
  419. break;
  420. default:
  421. shift = 0;
  422. }
  423. } else
  424. shift = 0;
  425. bit = 1 << (block->index + shift);
  426. return bit;
  427. }
  428. /*dummy read a SRAM block.*/
  429. static void sst_mem_block_dummy_read(struct sst_mem_block *block)
  430. {
  431. u32 size;
  432. u8 tmp_buf[4];
  433. struct sst_dsp *sst = block->dsp;
  434. size = block->size > 4 ? 4 : block->size;
  435. memcpy_fromio(tmp_buf, sst->addr.lpe + block->offset, size);
  436. }
  437. /* enable 32kB memory block - locks held by caller */
  438. static int hsw_block_enable(struct sst_mem_block *block)
  439. {
  440. struct sst_dsp *sst = block->dsp;
  441. u32 bit, val;
  442. if (block->users++ > 0)
  443. return 0;
  444. dev_dbg(block->dsp->dev, " enabled block %d:%d at offset 0x%x\n",
  445. block->type, block->index, block->offset);
  446. /* Disable core clock gating (VDRTCTL2.DCLCGE = 0) */
  447. val = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
  448. val &= ~SST_VDRTCL2_DCLCGE;
  449. writel(val, sst->addr.pci_cfg + SST_VDRTCTL2);
  450. val = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
  451. bit = hsw_block_get_bit(block);
  452. writel(val & ~bit, sst->addr.pci_cfg + SST_VDRTCTL0);
  453. /* wait 18 DSP clock ticks */
  454. udelay(10);
  455. /* Enable core clock gating (VDRTCTL2.DCLCGE = 1), delay 50 us */
  456. val = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
  457. val |= SST_VDRTCL2_DCLCGE;
  458. writel(val, sst->addr.pci_cfg + SST_VDRTCTL2);
  459. udelay(50);
  460. /*add a dummy read before the SRAM block is written, otherwise the writing may miss bytes sometimes.*/
  461. sst_mem_block_dummy_read(block);
  462. return 0;
  463. }
  464. /* disable 32kB memory block - locks held by caller */
  465. static int hsw_block_disable(struct sst_mem_block *block)
  466. {
  467. struct sst_dsp *sst = block->dsp;
  468. u32 bit, val;
  469. if (--block->users > 0)
  470. return 0;
  471. dev_dbg(block->dsp->dev, " disabled block %d:%d at offset 0x%x\n",
  472. block->type, block->index, block->offset);
  473. /* Disable core clock gating (VDRTCTL2.DCLCGE = 0) */
  474. val = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
  475. val &= ~SST_VDRTCL2_DCLCGE;
  476. writel(val, sst->addr.pci_cfg + SST_VDRTCTL2);
  477. val = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
  478. bit = hsw_block_get_bit(block);
  479. /* don't disable DSRAM[0], keep it always enable for FW dump*/
  480. if (bit != (1 << SST_VDRTCL0_DSRAMPGE_SHIFT))
  481. writel(val | bit, sst->addr.pci_cfg + SST_VDRTCTL0);
  482. /* wait 18 DSP clock ticks */
  483. udelay(10);
  484. /* Enable core clock gating (VDRTCTL2.DCLCGE = 1), delay 50 us */
  485. val = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
  486. val |= SST_VDRTCL2_DCLCGE;
  487. writel(val, sst->addr.pci_cfg + SST_VDRTCTL2);
  488. udelay(50);
  489. return 0;
  490. }
  491. static const struct sst_block_ops sst_hsw_ops = {
  492. .enable = hsw_block_enable,
  493. .disable = hsw_block_disable,
  494. };
  495. static int hsw_init(struct sst_dsp *sst, struct sst_pdata *pdata)
  496. {
  497. const struct sst_adsp_memregion *region;
  498. struct device *dev;
  499. int ret = -ENODEV, i, j, region_count;
  500. u32 offset, size, fw_dump_bit;
  501. dev = sst->dma_dev;
  502. switch (sst->id) {
  503. case SST_DEV_ID_LYNX_POINT:
  504. region = lp_region;
  505. region_count = ARRAY_SIZE(lp_region);
  506. sst->addr.iram_offset = SST_LP_IRAM_OFFSET;
  507. sst->addr.dsp_iram_offset = SST_LPT_DSP_IRAM_OFFSET;
  508. sst->addr.dsp_dram_offset = SST_LPT_DSP_DRAM_OFFSET;
  509. sst->addr.shim_offset = SST_LP_SHIM_OFFSET;
  510. break;
  511. case SST_DEV_ID_WILDCAT_POINT:
  512. region = wpt_region;
  513. region_count = ARRAY_SIZE(wpt_region);
  514. sst->addr.iram_offset = SST_WPT_IRAM_OFFSET;
  515. sst->addr.dsp_iram_offset = SST_WPT_DSP_IRAM_OFFSET;
  516. sst->addr.dsp_dram_offset = SST_WPT_DSP_DRAM_OFFSET;
  517. sst->addr.shim_offset = SST_WPT_SHIM_OFFSET;
  518. break;
  519. default:
  520. dev_err(dev, "error: failed to get mem resources\n");
  521. return ret;
  522. }
  523. ret = hsw_acpi_resource_map(sst, pdata);
  524. if (ret < 0) {
  525. dev_err(dev, "error: failed to map resources\n");
  526. return ret;
  527. }
  528. /* enable the DSP SHIM */
  529. ret = hsw_set_dsp_D0(sst);
  530. if (ret < 0) {
  531. dev_err(dev, "error: failed to set DSP D0 and reset SHIM\n");
  532. return ret;
  533. }
  534. ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(31));
  535. if (ret)
  536. return ret;
  537. /* register DSP memory blocks - ideally we should get this from ACPI */
  538. for (i = 0; i < region_count; i++) {
  539. offset = region[i].start;
  540. size = (region[i].end - region[i].start) / region[i].blocks;
  541. /* register individual memory blocks */
  542. for (j = 0; j < region[i].blocks; j++) {
  543. sst_mem_block_register(sst, offset, size,
  544. region[i].type, &sst_hsw_ops, j, sst);
  545. offset += size;
  546. }
  547. }
  548. /* always enable the block(DSRAM[0]) used for FW dump */
  549. fw_dump_bit = 1 << SST_VDRTCL0_DSRAMPGE_SHIFT;
  550. /* set default power gating control, enable power gating control for all blocks. that is,
  551. can't be accessed, please enable each block before accessing. */
  552. writel(0xffffffff & ~fw_dump_bit, sst->addr.pci_cfg + SST_VDRTCTL0);
  553. return 0;
  554. }
  555. static void hsw_free(struct sst_dsp *sst)
  556. {
  557. sst_mem_block_unregister_all(sst);
  558. iounmap(sst->addr.lpe);
  559. iounmap(sst->addr.pci_cfg);
  560. }
  561. struct sst_ops haswell_ops = {
  562. .reset = hsw_reset,
  563. .boot = hsw_boot,
  564. .stall = hsw_stall,
  565. .wake = hsw_wake,
  566. .sleep = hsw_sleep,
  567. .write = sst_shim32_write,
  568. .read = sst_shim32_read,
  569. .write64 = sst_shim32_write64,
  570. .read64 = sst_shim32_read64,
  571. .ram_read = sst_memcpy_fromio_32,
  572. .ram_write = sst_memcpy_toio_32,
  573. .irq_handler = hsw_irq,
  574. .init = hsw_init,
  575. .free = hsw_free,
  576. .parse_fw = hsw_parse_fw_image,
  577. };