1458bc729SLiam Girdwood // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) 2458bc729SLiam Girdwood // 3458bc729SLiam Girdwood // This file is provided under a dual BSD/GPLv2 license. When using or 4458bc729SLiam Girdwood // redistributing this file, you may do so under either license. 5458bc729SLiam Girdwood // 6458bc729SLiam Girdwood // Copyright(c) 2018 Intel Corporation. All rights reserved. 7458bc729SLiam Girdwood // 8458bc729SLiam Girdwood // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> 9458bc729SLiam Girdwood // 10458bc729SLiam Girdwood 11458bc729SLiam Girdwood /* 12458bc729SLiam Girdwood * Hardware interface for audio DSP on Broadwell 13458bc729SLiam Girdwood */ 14458bc729SLiam Girdwood 15458bc729SLiam Girdwood #include <linux/module.h> 16458bc729SLiam Girdwood #include <sound/sof.h> 17458bc729SLiam Girdwood #include <sound/sof/xtensa.h> 18458bc729SLiam Girdwood #include "../ops.h" 19458bc729SLiam Girdwood #include "shim.h" 20285880a2SDaniel Baluta #include "../sof-audio.h" 21458bc729SLiam Girdwood 22458bc729SLiam Girdwood /* BARs */ 23458bc729SLiam Girdwood #define BDW_DSP_BAR 0 24458bc729SLiam Girdwood #define BDW_PCI_BAR 1 25458bc729SLiam Girdwood 26458bc729SLiam Girdwood /* 27458bc729SLiam Girdwood * Debug 28458bc729SLiam Girdwood */ 29458bc729SLiam Girdwood 30458bc729SLiam Girdwood /* DSP memories for BDW */ 31458bc729SLiam Girdwood #define IRAM_OFFSET 0xA0000 32458bc729SLiam Girdwood #define BDW_IRAM_SIZE (10 * 32 * 1024) 33458bc729SLiam Girdwood #define DRAM_OFFSET 0x00000 34458bc729SLiam Girdwood #define BDW_DRAM_SIZE (20 * 32 * 1024) 35458bc729SLiam Girdwood #define SHIM_OFFSET 0xFB000 36458bc729SLiam Girdwood #define SHIM_SIZE 0x100 37458bc729SLiam Girdwood #define MBOX_OFFSET 0x9E000 38458bc729SLiam Girdwood #define MBOX_SIZE 0x1000 39458bc729SLiam Girdwood #define MBOX_DUMP_SIZE 0x30 40458bc729SLiam Girdwood #define EXCEPT_OFFSET 0x800 41ff2be865SLiam Girdwood #define EXCEPT_MAX_HDR_SIZE 0x400 42458bc729SLiam Girdwood 43458bc729SLiam Girdwood /* DSP peripherals */ 44458bc729SLiam Girdwood #define DMAC0_OFFSET 0xFE000 45458bc729SLiam Girdwood #define DMAC1_OFFSET 0xFF000 46458bc729SLiam Girdwood #define DMAC_SIZE 0x420 47458bc729SLiam Girdwood #define SSP0_OFFSET 0xFC000 48458bc729SLiam Girdwood #define SSP1_OFFSET 0xFD000 49458bc729SLiam Girdwood #define SSP_SIZE 0x100 50458bc729SLiam Girdwood 51458bc729SLiam Girdwood #define BDW_STACK_DUMP_SIZE 32 52458bc729SLiam Girdwood 53458bc729SLiam Girdwood #define BDW_PANIC_OFFSET(x) ((x) & 0xFFFF) 54458bc729SLiam Girdwood 55458bc729SLiam Girdwood static const struct snd_sof_debugfs_map bdw_debugfs[] = { 56458bc729SLiam Girdwood {"dmac0", BDW_DSP_BAR, DMAC0_OFFSET, DMAC_SIZE, 57458bc729SLiam Girdwood SOF_DEBUGFS_ACCESS_ALWAYS}, 58458bc729SLiam Girdwood {"dmac1", BDW_DSP_BAR, DMAC1_OFFSET, DMAC_SIZE, 59458bc729SLiam Girdwood SOF_DEBUGFS_ACCESS_ALWAYS}, 60458bc729SLiam Girdwood {"ssp0", BDW_DSP_BAR, SSP0_OFFSET, SSP_SIZE, 61458bc729SLiam Girdwood SOF_DEBUGFS_ACCESS_ALWAYS}, 62458bc729SLiam Girdwood {"ssp1", BDW_DSP_BAR, SSP1_OFFSET, SSP_SIZE, 63458bc729SLiam Girdwood SOF_DEBUGFS_ACCESS_ALWAYS}, 64458bc729SLiam Girdwood {"iram", BDW_DSP_BAR, IRAM_OFFSET, BDW_IRAM_SIZE, 65458bc729SLiam Girdwood SOF_DEBUGFS_ACCESS_D0_ONLY}, 66458bc729SLiam Girdwood {"dram", BDW_DSP_BAR, DRAM_OFFSET, BDW_DRAM_SIZE, 67458bc729SLiam Girdwood SOF_DEBUGFS_ACCESS_D0_ONLY}, 68458bc729SLiam Girdwood {"shim", BDW_DSP_BAR, SHIM_OFFSET, SHIM_SIZE, 69458bc729SLiam Girdwood SOF_DEBUGFS_ACCESS_ALWAYS}, 70458bc729SLiam Girdwood }; 71458bc729SLiam Girdwood 72458bc729SLiam Girdwood static void bdw_host_done(struct snd_sof_dev *sdev); 73458bc729SLiam Girdwood static void bdw_dsp_done(struct snd_sof_dev *sdev); 74458bc729SLiam Girdwood static void bdw_get_reply(struct snd_sof_dev *sdev); 75458bc729SLiam Girdwood 76458bc729SLiam Girdwood /* 77458bc729SLiam Girdwood * DSP Control. 78458bc729SLiam Girdwood */ 79458bc729SLiam Girdwood 80458bc729SLiam Girdwood static int bdw_run(struct snd_sof_dev *sdev) 81458bc729SLiam Girdwood { 82458bc729SLiam Girdwood /* set opportunistic mode on engine 0,1 for all channels */ 83458bc729SLiam Girdwood snd_sof_dsp_update_bits(sdev, BDW_DSP_BAR, SHIM_HMDC, 84458bc729SLiam Girdwood SHIM_HMDC_HDDA_E0_ALLCH | 85458bc729SLiam Girdwood SHIM_HMDC_HDDA_E1_ALLCH, 0); 86458bc729SLiam Girdwood 87458bc729SLiam Girdwood /* set DSP to RUN */ 88458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, SHIM_CSR, 89458bc729SLiam Girdwood SHIM_CSR_STALL, 0x0); 90458bc729SLiam Girdwood 91458bc729SLiam Girdwood /* return init core mask */ 92458bc729SLiam Girdwood return 1; 93458bc729SLiam Girdwood } 94458bc729SLiam Girdwood 95458bc729SLiam Girdwood static int bdw_reset(struct snd_sof_dev *sdev) 96458bc729SLiam Girdwood { 97458bc729SLiam Girdwood /* put DSP into reset and stall */ 98458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, SHIM_CSR, 99458bc729SLiam Girdwood SHIM_CSR_RST | SHIM_CSR_STALL, 100458bc729SLiam Girdwood SHIM_CSR_RST | SHIM_CSR_STALL); 101458bc729SLiam Girdwood 102458bc729SLiam Girdwood /* keep in reset for 10ms */ 103458bc729SLiam Girdwood mdelay(10); 104458bc729SLiam Girdwood 105458bc729SLiam Girdwood /* take DSP out of reset and keep stalled for FW loading */ 106458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, SHIM_CSR, 107458bc729SLiam Girdwood SHIM_CSR_RST | SHIM_CSR_STALL, 108458bc729SLiam Girdwood SHIM_CSR_STALL); 109458bc729SLiam Girdwood 110458bc729SLiam Girdwood return 0; 111458bc729SLiam Girdwood } 112458bc729SLiam Girdwood 113458bc729SLiam Girdwood static int bdw_set_dsp_D0(struct snd_sof_dev *sdev) 114458bc729SLiam Girdwood { 115458bc729SLiam Girdwood int tries = 10; 116458bc729SLiam Girdwood u32 reg; 117458bc729SLiam Girdwood 118458bc729SLiam Girdwood /* Disable core clock gating (VDRTCTL2.DCLCGE = 0) */ 119458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_PCI_BAR, PCI_VDRTCTL2, 120458bc729SLiam Girdwood PCI_VDRTCL2_DCLCGE | 121458bc729SLiam Girdwood PCI_VDRTCL2_DTCGE, 0); 122458bc729SLiam Girdwood 123458bc729SLiam Girdwood /* Disable D3PG (VDRTCTL0.D3PGD = 1) */ 124458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_PCI_BAR, PCI_VDRTCTL0, 125458bc729SLiam Girdwood PCI_VDRTCL0_D3PGD, PCI_VDRTCL0_D3PGD); 126458bc729SLiam Girdwood 127458bc729SLiam Girdwood /* Set D0 state */ 128458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_PCI_BAR, PCI_PMCS, 129458bc729SLiam Girdwood PCI_PMCS_PS_MASK, 0); 130458bc729SLiam Girdwood 131458bc729SLiam Girdwood /* check that ADSP shim is enabled */ 132458bc729SLiam Girdwood while (tries--) { 133458bc729SLiam Girdwood reg = readl(sdev->bar[BDW_PCI_BAR] + PCI_PMCS) 134458bc729SLiam Girdwood & PCI_PMCS_PS_MASK; 135458bc729SLiam Girdwood if (reg == 0) 136458bc729SLiam Girdwood goto finish; 137458bc729SLiam Girdwood 138458bc729SLiam Girdwood msleep(20); 139458bc729SLiam Girdwood } 140458bc729SLiam Girdwood 141458bc729SLiam Girdwood return -ENODEV; 142458bc729SLiam Girdwood 143458bc729SLiam Girdwood finish: 144458bc729SLiam Girdwood /* 145458bc729SLiam Girdwood * select SSP1 19.2MHz base clock, SSP clock 0, 146458bc729SLiam Girdwood * turn off Low Power Clock 147458bc729SLiam Girdwood */ 148458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, SHIM_CSR, 149458bc729SLiam Girdwood SHIM_CSR_S1IOCS | SHIM_CSR_SBCS1 | 150458bc729SLiam Girdwood SHIM_CSR_LPCS, 0x0); 151458bc729SLiam Girdwood 152458bc729SLiam Girdwood /* stall DSP core, set clk to 192/96Mhz */ 153458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, 154458bc729SLiam Girdwood SHIM_CSR, SHIM_CSR_STALL | 155458bc729SLiam Girdwood SHIM_CSR_DCS_MASK, 156458bc729SLiam Girdwood SHIM_CSR_STALL | 157458bc729SLiam Girdwood SHIM_CSR_DCS(4)); 158458bc729SLiam Girdwood 159458bc729SLiam Girdwood /* Set 24MHz MCLK, prevent local clock gating, enable SSP0 clock */ 160458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, SHIM_CLKCTL, 161458bc729SLiam Girdwood SHIM_CLKCTL_MASK | 162458bc729SLiam Girdwood SHIM_CLKCTL_DCPLCG | 163458bc729SLiam Girdwood SHIM_CLKCTL_SCOE0, 164458bc729SLiam Girdwood SHIM_CLKCTL_MASK | 165458bc729SLiam Girdwood SHIM_CLKCTL_DCPLCG | 166458bc729SLiam Girdwood SHIM_CLKCTL_SCOE0); 167458bc729SLiam Girdwood 168458bc729SLiam Girdwood /* Stall and reset core, set CSR */ 169458bc729SLiam Girdwood bdw_reset(sdev); 170458bc729SLiam Girdwood 171458bc729SLiam Girdwood /* Enable core clock gating (VDRTCTL2.DCLCGE = 1), delay 50 us */ 172458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_PCI_BAR, PCI_VDRTCTL2, 173458bc729SLiam Girdwood PCI_VDRTCL2_DCLCGE | 174458bc729SLiam Girdwood PCI_VDRTCL2_DTCGE, 175458bc729SLiam Girdwood PCI_VDRTCL2_DCLCGE | 176458bc729SLiam Girdwood PCI_VDRTCL2_DTCGE); 177458bc729SLiam Girdwood 178458bc729SLiam Girdwood usleep_range(50, 55); 179458bc729SLiam Girdwood 180458bc729SLiam Girdwood /* switch on audio PLL */ 181458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_PCI_BAR, PCI_VDRTCTL2, 182458bc729SLiam Girdwood PCI_VDRTCL2_APLLSE_MASK, 0); 183458bc729SLiam Girdwood 184458bc729SLiam Girdwood /* 185458bc729SLiam Girdwood * set default power gating control, enable power gating control for 186458bc729SLiam Girdwood * all blocks. that is, can't be accessed, please enable each block 187458bc729SLiam Girdwood * before accessing. 188458bc729SLiam Girdwood */ 189458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_PCI_BAR, PCI_VDRTCTL0, 190458bc729SLiam Girdwood 0xfffffffC, 0x0); 191458bc729SLiam Girdwood 192458bc729SLiam Girdwood /* disable DMA finish function for SSP0 & SSP1 */ 193458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, SHIM_CSR2, 194458bc729SLiam Girdwood SHIM_CSR2_SDFD_SSP1, 195458bc729SLiam Girdwood SHIM_CSR2_SDFD_SSP1); 196458bc729SLiam Girdwood 197458bc729SLiam Girdwood /* set on-demond mode on engine 0,1 for all channels */ 198458bc729SLiam Girdwood snd_sof_dsp_update_bits(sdev, BDW_DSP_BAR, SHIM_HMDC, 199458bc729SLiam Girdwood SHIM_HMDC_HDDA_E0_ALLCH | 200458bc729SLiam Girdwood SHIM_HMDC_HDDA_E1_ALLCH, 201458bc729SLiam Girdwood SHIM_HMDC_HDDA_E0_ALLCH | 202458bc729SLiam Girdwood SHIM_HMDC_HDDA_E1_ALLCH); 203458bc729SLiam Girdwood 204458bc729SLiam Girdwood /* Enable Interrupt from both sides */ 205458bc729SLiam Girdwood snd_sof_dsp_update_bits(sdev, BDW_DSP_BAR, SHIM_IMRX, 206458bc729SLiam Girdwood (SHIM_IMRX_BUSY | SHIM_IMRX_DONE), 0x0); 207458bc729SLiam Girdwood snd_sof_dsp_update_bits(sdev, BDW_DSP_BAR, SHIM_IMRD, 208458bc729SLiam Girdwood (SHIM_IMRD_DONE | SHIM_IMRD_BUSY | 209458bc729SLiam Girdwood SHIM_IMRD_SSP0 | SHIM_IMRD_DMAC), 0x0); 210458bc729SLiam Girdwood 211458bc729SLiam Girdwood /* clear IPC registers */ 212458bc729SLiam Girdwood snd_sof_dsp_write(sdev, BDW_DSP_BAR, SHIM_IPCX, 0x0); 213458bc729SLiam Girdwood snd_sof_dsp_write(sdev, BDW_DSP_BAR, SHIM_IPCD, 0x0); 214458bc729SLiam Girdwood snd_sof_dsp_write(sdev, BDW_DSP_BAR, 0x80, 0x6); 215458bc729SLiam Girdwood snd_sof_dsp_write(sdev, BDW_DSP_BAR, 0xe0, 0x300a); 216458bc729SLiam Girdwood 217458bc729SLiam Girdwood return 0; 218458bc729SLiam Girdwood } 219458bc729SLiam Girdwood 220458bc729SLiam Girdwood static void bdw_get_registers(struct snd_sof_dev *sdev, 221458bc729SLiam Girdwood struct sof_ipc_dsp_oops_xtensa *xoops, 222458bc729SLiam Girdwood struct sof_ipc_panic_info *panic_info, 223458bc729SLiam Girdwood u32 *stack, size_t stack_words) 224458bc729SLiam Girdwood { 22514104eb6SKai Vehmanen u32 offset = sdev->dsp_oops_offset; 22614104eb6SKai Vehmanen 22714104eb6SKai Vehmanen /* first read registers */ 22814104eb6SKai Vehmanen sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops)); 22914104eb6SKai Vehmanen 23014104eb6SKai Vehmanen /* note: variable AR register array is not read */ 231458bc729SLiam Girdwood 232458bc729SLiam Girdwood /* then get panic info */ 233ff2be865SLiam Girdwood if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) { 234ff2be865SLiam Girdwood dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n", 235ff2be865SLiam Girdwood xoops->arch_hdr.totalsize); 236ff2be865SLiam Girdwood return; 237ff2be865SLiam Girdwood } 23814104eb6SKai Vehmanen offset += xoops->arch_hdr.totalsize; 23914104eb6SKai Vehmanen sof_mailbox_read(sdev, offset, panic_info, sizeof(*panic_info)); 240458bc729SLiam Girdwood 241458bc729SLiam Girdwood /* then get the stack */ 24214104eb6SKai Vehmanen offset += sizeof(*panic_info); 24314104eb6SKai Vehmanen sof_mailbox_read(sdev, offset, stack, stack_words * sizeof(u32)); 244458bc729SLiam Girdwood } 245458bc729SLiam Girdwood 246458bc729SLiam Girdwood static void bdw_dump(struct snd_sof_dev *sdev, u32 flags) 247458bc729SLiam Girdwood { 248458bc729SLiam Girdwood struct sof_ipc_dsp_oops_xtensa xoops; 249458bc729SLiam Girdwood struct sof_ipc_panic_info panic_info; 250458bc729SLiam Girdwood u32 stack[BDW_STACK_DUMP_SIZE]; 2513a9e204dSLiam Girdwood u32 status, panic, imrx, imrd; 252458bc729SLiam Girdwood 253458bc729SLiam Girdwood /* now try generic SOF status messages */ 254458bc729SLiam Girdwood status = snd_sof_dsp_read(sdev, BDW_DSP_BAR, SHIM_IPCD); 255458bc729SLiam Girdwood panic = snd_sof_dsp_read(sdev, BDW_DSP_BAR, SHIM_IPCX); 256458bc729SLiam Girdwood bdw_get_registers(sdev, &xoops, &panic_info, stack, 257458bc729SLiam Girdwood BDW_STACK_DUMP_SIZE); 258458bc729SLiam Girdwood snd_sof_get_status(sdev, status, panic, &xoops, &panic_info, stack, 259458bc729SLiam Girdwood BDW_STACK_DUMP_SIZE); 2603a9e204dSLiam Girdwood 2613a9e204dSLiam Girdwood /* provide some context for firmware debug */ 2623a9e204dSLiam Girdwood imrx = snd_sof_dsp_read(sdev, BDW_DSP_BAR, SHIM_IMRX); 2633a9e204dSLiam Girdwood imrd = snd_sof_dsp_read(sdev, BDW_DSP_BAR, SHIM_IMRD); 2643a9e204dSLiam Girdwood dev_err(sdev->dev, 2653a9e204dSLiam Girdwood "error: ipc host -> DSP: pending %s complete %s raw 0x%8.8x\n", 2667ad03a2cSPierre-Louis Bossart (panic & SHIM_IPCX_BUSY) ? "yes" : "no", 2677ad03a2cSPierre-Louis Bossart (panic & SHIM_IPCX_DONE) ? "yes" : "no", panic); 2683a9e204dSLiam Girdwood dev_err(sdev->dev, 2693a9e204dSLiam Girdwood "error: mask host: pending %s complete %s raw 0x%8.8x\n", 2707ad03a2cSPierre-Louis Bossart (imrx & SHIM_IMRX_BUSY) ? "yes" : "no", 2717ad03a2cSPierre-Louis Bossart (imrx & SHIM_IMRX_DONE) ? "yes" : "no", imrx); 2723a9e204dSLiam Girdwood dev_err(sdev->dev, 2733a9e204dSLiam Girdwood "error: ipc DSP -> host: pending %s complete %s raw 0x%8.8x\n", 2747ad03a2cSPierre-Louis Bossart (status & SHIM_IPCD_BUSY) ? "yes" : "no", 2757ad03a2cSPierre-Louis Bossart (status & SHIM_IPCD_DONE) ? "yes" : "no", status); 2763a9e204dSLiam Girdwood dev_err(sdev->dev, 2773a9e204dSLiam Girdwood "error: mask DSP: pending %s complete %s raw 0x%8.8x\n", 2787ad03a2cSPierre-Louis Bossart (imrd & SHIM_IMRD_BUSY) ? "yes" : "no", 2797ad03a2cSPierre-Louis Bossart (imrd & SHIM_IMRD_DONE) ? "yes" : "no", imrd); 280458bc729SLiam Girdwood } 281458bc729SLiam Girdwood 282458bc729SLiam Girdwood /* 283458bc729SLiam Girdwood * IPC Doorbell IRQ handler and thread. 284458bc729SLiam Girdwood */ 285458bc729SLiam Girdwood 286458bc729SLiam Girdwood static irqreturn_t bdw_irq_handler(int irq, void *context) 287458bc729SLiam Girdwood { 288458bc729SLiam Girdwood struct snd_sof_dev *sdev = context; 289458bc729SLiam Girdwood u32 isr; 290458bc729SLiam Girdwood int ret = IRQ_NONE; 291458bc729SLiam Girdwood 292458bc729SLiam Girdwood /* Interrupt arrived, check src */ 293458bc729SLiam Girdwood isr = snd_sof_dsp_read(sdev, BDW_DSP_BAR, SHIM_ISRX); 294458bc729SLiam Girdwood if (isr & (SHIM_ISRX_DONE | SHIM_ISRX_BUSY)) 295458bc729SLiam Girdwood ret = IRQ_WAKE_THREAD; 296458bc729SLiam Girdwood 297458bc729SLiam Girdwood return ret; 298458bc729SLiam Girdwood } 299458bc729SLiam Girdwood 300458bc729SLiam Girdwood static irqreturn_t bdw_irq_thread(int irq, void *context) 301458bc729SLiam Girdwood { 302458bc729SLiam Girdwood struct snd_sof_dev *sdev = context; 303458bc729SLiam Girdwood u32 ipcx, ipcd, imrx; 304458bc729SLiam Girdwood 305458bc729SLiam Girdwood imrx = snd_sof_dsp_read64(sdev, BDW_DSP_BAR, SHIM_IMRX); 306458bc729SLiam Girdwood ipcx = snd_sof_dsp_read(sdev, BDW_DSP_BAR, SHIM_IPCX); 307458bc729SLiam Girdwood 308458bc729SLiam Girdwood /* reply message from DSP */ 309458bc729SLiam Girdwood if (ipcx & SHIM_IPCX_DONE && 310458bc729SLiam Girdwood !(imrx & SHIM_IMRX_DONE)) { 311458bc729SLiam Girdwood /* Mask Done interrupt before return */ 312458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, 313458bc729SLiam Girdwood SHIM_IMRX, SHIM_IMRX_DONE, 314458bc729SLiam Girdwood SHIM_IMRX_DONE); 315458bc729SLiam Girdwood 3161183e9a6SGuennadi Liakhovetski spin_lock_irq(&sdev->ipc_lock); 3171183e9a6SGuennadi Liakhovetski 318458bc729SLiam Girdwood /* 319458bc729SLiam Girdwood * handle immediate reply from DSP core. If the msg is 320458bc729SLiam Girdwood * found, set done bit in cmd_done which is called at the 321458bc729SLiam Girdwood * end of message processing function, else set it here 322458bc729SLiam Girdwood * because the done bit can't be set in cmd_done function 323458bc729SLiam Girdwood * which is triggered by msg 324458bc729SLiam Girdwood */ 325458bc729SLiam Girdwood bdw_get_reply(sdev); 326458bc729SLiam Girdwood snd_sof_ipc_reply(sdev, ipcx); 327458bc729SLiam Girdwood 328458bc729SLiam Girdwood bdw_dsp_done(sdev); 3291183e9a6SGuennadi Liakhovetski 3301183e9a6SGuennadi Liakhovetski spin_unlock_irq(&sdev->ipc_lock); 331458bc729SLiam Girdwood } 332458bc729SLiam Girdwood 333458bc729SLiam Girdwood ipcd = snd_sof_dsp_read(sdev, BDW_DSP_BAR, SHIM_IPCD); 334458bc729SLiam Girdwood 335458bc729SLiam Girdwood /* new message from DSP */ 336458bc729SLiam Girdwood if (ipcd & SHIM_IPCD_BUSY && 337458bc729SLiam Girdwood !(imrx & SHIM_IMRX_BUSY)) { 338458bc729SLiam Girdwood /* Mask Busy interrupt before return */ 339458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, 340458bc729SLiam Girdwood SHIM_IMRX, SHIM_IMRX_BUSY, 341458bc729SLiam Girdwood SHIM_IMRX_BUSY); 342458bc729SLiam Girdwood 343458bc729SLiam Girdwood /* Handle messages from DSP Core */ 344458bc729SLiam Girdwood if ((ipcd & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC) { 345458bc729SLiam Girdwood snd_sof_dsp_panic(sdev, BDW_PANIC_OFFSET(ipcx) + 346458bc729SLiam Girdwood MBOX_OFFSET); 347458bc729SLiam Girdwood } else { 348458bc729SLiam Girdwood snd_sof_ipc_msgs_rx(sdev); 349458bc729SLiam Girdwood } 350458bc729SLiam Girdwood 351458bc729SLiam Girdwood bdw_host_done(sdev); 352458bc729SLiam Girdwood } 353458bc729SLiam Girdwood 354458bc729SLiam Girdwood return IRQ_HANDLED; 355458bc729SLiam Girdwood } 356458bc729SLiam Girdwood 357458bc729SLiam Girdwood /* 358458bc729SLiam Girdwood * IPC Mailbox IO 359458bc729SLiam Girdwood */ 360458bc729SLiam Girdwood 361458bc729SLiam Girdwood static int bdw_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) 362458bc729SLiam Girdwood { 363458bc729SLiam Girdwood /* send the message */ 364458bc729SLiam Girdwood sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, 365458bc729SLiam Girdwood msg->msg_size); 366458bc729SLiam Girdwood snd_sof_dsp_write(sdev, BDW_DSP_BAR, SHIM_IPCX, SHIM_IPCX_BUSY); 367458bc729SLiam Girdwood 368458bc729SLiam Girdwood return 0; 369458bc729SLiam Girdwood } 370458bc729SLiam Girdwood 371458bc729SLiam Girdwood static void bdw_get_reply(struct snd_sof_dev *sdev) 372458bc729SLiam Girdwood { 373458bc729SLiam Girdwood struct snd_sof_ipc_msg *msg = sdev->msg; 374458bc729SLiam Girdwood struct sof_ipc_reply reply; 375458bc729SLiam Girdwood int ret = 0; 376458bc729SLiam Girdwood 377458bc729SLiam Girdwood /* 378458bc729SLiam Girdwood * Sometimes, there is unexpected reply ipc arriving. The reply 379458bc729SLiam Girdwood * ipc belongs to none of the ipcs sent from driver. 380458bc729SLiam Girdwood * In this case, the driver must ignore the ipc. 381458bc729SLiam Girdwood */ 382458bc729SLiam Girdwood if (!msg) { 383458bc729SLiam Girdwood dev_warn(sdev->dev, "unexpected ipc interrupt raised!\n"); 384458bc729SLiam Girdwood return; 385458bc729SLiam Girdwood } 386458bc729SLiam Girdwood 387458bc729SLiam Girdwood /* get reply */ 388458bc729SLiam Girdwood sof_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); 389458bc729SLiam Girdwood 390458bc729SLiam Girdwood if (reply.error < 0) { 391458bc729SLiam Girdwood memcpy(msg->reply_data, &reply, sizeof(reply)); 392458bc729SLiam Girdwood ret = reply.error; 393458bc729SLiam Girdwood } else { 394458bc729SLiam Girdwood /* reply correct size ? */ 395458bc729SLiam Girdwood if (reply.hdr.size != msg->reply_size) { 396458bc729SLiam Girdwood dev_err(sdev->dev, "error: reply expected %zu got %u bytes\n", 397458bc729SLiam Girdwood msg->reply_size, reply.hdr.size); 398458bc729SLiam Girdwood ret = -EINVAL; 399458bc729SLiam Girdwood } 400458bc729SLiam Girdwood 401458bc729SLiam Girdwood /* read the message */ 402458bc729SLiam Girdwood if (msg->reply_size > 0) 403458bc729SLiam Girdwood sof_mailbox_read(sdev, sdev->host_box.offset, 404458bc729SLiam Girdwood msg->reply_data, msg->reply_size); 405458bc729SLiam Girdwood } 406458bc729SLiam Girdwood 407458bc729SLiam Girdwood msg->reply_error = ret; 408458bc729SLiam Girdwood } 409458bc729SLiam Girdwood 410ddf14b64SDaniel Baluta static int bdw_get_mailbox_offset(struct snd_sof_dev *sdev) 411ddf14b64SDaniel Baluta { 412ddf14b64SDaniel Baluta return MBOX_OFFSET; 413ddf14b64SDaniel Baluta } 414ddf14b64SDaniel Baluta 415ddf14b64SDaniel Baluta static int bdw_get_window_offset(struct snd_sof_dev *sdev, u32 id) 416ddf14b64SDaniel Baluta { 417ddf14b64SDaniel Baluta return MBOX_OFFSET; 418ddf14b64SDaniel Baluta } 419ddf14b64SDaniel Baluta 420458bc729SLiam Girdwood static void bdw_host_done(struct snd_sof_dev *sdev) 421458bc729SLiam Girdwood { 422458bc729SLiam Girdwood /* clear BUSY bit and set DONE bit - accept new messages */ 423458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, SHIM_IPCD, 424458bc729SLiam Girdwood SHIM_IPCD_BUSY | SHIM_IPCD_DONE, 425458bc729SLiam Girdwood SHIM_IPCD_DONE); 426458bc729SLiam Girdwood 427458bc729SLiam Girdwood /* unmask busy interrupt */ 428458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, SHIM_IMRX, 429458bc729SLiam Girdwood SHIM_IMRX_BUSY, 0); 430458bc729SLiam Girdwood } 431458bc729SLiam Girdwood 432458bc729SLiam Girdwood static void bdw_dsp_done(struct snd_sof_dev *sdev) 433458bc729SLiam Girdwood { 434458bc729SLiam Girdwood /* clear DONE bit - tell DSP we have completed */ 435458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, SHIM_IPCX, 436458bc729SLiam Girdwood SHIM_IPCX_DONE, 0); 437458bc729SLiam Girdwood 438458bc729SLiam Girdwood /* unmask Done interrupt */ 439458bc729SLiam Girdwood snd_sof_dsp_update_bits_unlocked(sdev, BDW_DSP_BAR, SHIM_IMRX, 440458bc729SLiam Girdwood SHIM_IMRX_DONE, 0); 441458bc729SLiam Girdwood } 442458bc729SLiam Girdwood 443458bc729SLiam Girdwood /* 444458bc729SLiam Girdwood * Probe and remove. 445458bc729SLiam Girdwood */ 446458bc729SLiam Girdwood static int bdw_probe(struct snd_sof_dev *sdev) 447458bc729SLiam Girdwood { 448458bc729SLiam Girdwood struct snd_sof_pdata *pdata = sdev->pdata; 449458bc729SLiam Girdwood const struct sof_dev_desc *desc = pdata->desc; 450458bc729SLiam Girdwood struct platform_device *pdev = 451458bc729SLiam Girdwood container_of(sdev->dev, struct platform_device, dev); 452458bc729SLiam Girdwood struct resource *mmio; 453458bc729SLiam Girdwood u32 base, size; 454458bc729SLiam Girdwood int ret; 455458bc729SLiam Girdwood 456458bc729SLiam Girdwood /* LPE base */ 457458bc729SLiam Girdwood mmio = platform_get_resource(pdev, IORESOURCE_MEM, 458458bc729SLiam Girdwood desc->resindex_lpe_base); 459458bc729SLiam Girdwood if (mmio) { 460458bc729SLiam Girdwood base = mmio->start; 461458bc729SLiam Girdwood size = resource_size(mmio); 462458bc729SLiam Girdwood } else { 463458bc729SLiam Girdwood dev_err(sdev->dev, "error: failed to get LPE base at idx %d\n", 464458bc729SLiam Girdwood desc->resindex_lpe_base); 465458bc729SLiam Girdwood return -EINVAL; 466458bc729SLiam Girdwood } 467458bc729SLiam Girdwood 468458bc729SLiam Girdwood dev_dbg(sdev->dev, "LPE PHY base at 0x%x size 0x%x", base, size); 469458bc729SLiam Girdwood sdev->bar[BDW_DSP_BAR] = devm_ioremap(sdev->dev, base, size); 470458bc729SLiam Girdwood if (!sdev->bar[BDW_DSP_BAR]) { 471458bc729SLiam Girdwood dev_err(sdev->dev, 472458bc729SLiam Girdwood "error: failed to ioremap LPE base 0x%x size 0x%x\n", 473458bc729SLiam Girdwood base, size); 474458bc729SLiam Girdwood return -ENODEV; 475458bc729SLiam Girdwood } 476458bc729SLiam Girdwood dev_dbg(sdev->dev, "LPE VADDR %p\n", sdev->bar[BDW_DSP_BAR]); 477458bc729SLiam Girdwood 478458bc729SLiam Girdwood /* TODO: add offsets */ 479458bc729SLiam Girdwood sdev->mmio_bar = BDW_DSP_BAR; 480458bc729SLiam Girdwood sdev->mailbox_bar = BDW_DSP_BAR; 481ff2be865SLiam Girdwood sdev->dsp_oops_offset = MBOX_OFFSET; 482458bc729SLiam Girdwood 483458bc729SLiam Girdwood /* PCI base */ 484458bc729SLiam Girdwood mmio = platform_get_resource(pdev, IORESOURCE_MEM, 485458bc729SLiam Girdwood desc->resindex_pcicfg_base); 486458bc729SLiam Girdwood if (mmio) { 487458bc729SLiam Girdwood base = mmio->start; 488458bc729SLiam Girdwood size = resource_size(mmio); 489458bc729SLiam Girdwood } else { 490458bc729SLiam Girdwood dev_err(sdev->dev, "error: failed to get PCI base at idx %d\n", 491458bc729SLiam Girdwood desc->resindex_pcicfg_base); 492458bc729SLiam Girdwood return -ENODEV; 493458bc729SLiam Girdwood } 494458bc729SLiam Girdwood 495458bc729SLiam Girdwood dev_dbg(sdev->dev, "PCI base at 0x%x size 0x%x", base, size); 496458bc729SLiam Girdwood sdev->bar[BDW_PCI_BAR] = devm_ioremap(sdev->dev, base, size); 497458bc729SLiam Girdwood if (!sdev->bar[BDW_PCI_BAR]) { 498458bc729SLiam Girdwood dev_err(sdev->dev, 499458bc729SLiam Girdwood "error: failed to ioremap PCI base 0x%x size 0x%x\n", 500458bc729SLiam Girdwood base, size); 501458bc729SLiam Girdwood return -ENODEV; 502458bc729SLiam Girdwood } 503458bc729SLiam Girdwood dev_dbg(sdev->dev, "PCI VADDR %p\n", sdev->bar[BDW_PCI_BAR]); 504458bc729SLiam Girdwood 505458bc729SLiam Girdwood /* register our IRQ */ 506458bc729SLiam Girdwood sdev->ipc_irq = platform_get_irq(pdev, desc->irqindex_host_ipc); 507cf9441adSStephen Boyd if (sdev->ipc_irq < 0) 508458bc729SLiam Girdwood return sdev->ipc_irq; 509458bc729SLiam Girdwood 510458bc729SLiam Girdwood dev_dbg(sdev->dev, "using IRQ %d\n", sdev->ipc_irq); 511458bc729SLiam Girdwood ret = devm_request_threaded_irq(sdev->dev, sdev->ipc_irq, 512458bc729SLiam Girdwood bdw_irq_handler, bdw_irq_thread, 513458bc729SLiam Girdwood IRQF_SHARED, "AudioDSP", sdev); 514458bc729SLiam Girdwood if (ret < 0) { 515458bc729SLiam Girdwood dev_err(sdev->dev, "error: failed to register IRQ %d\n", 516458bc729SLiam Girdwood sdev->ipc_irq); 517458bc729SLiam Girdwood return ret; 518458bc729SLiam Girdwood } 519458bc729SLiam Girdwood 520458bc729SLiam Girdwood /* enable the DSP SHIM */ 521458bc729SLiam Girdwood ret = bdw_set_dsp_D0(sdev); 522458bc729SLiam Girdwood if (ret < 0) { 523458bc729SLiam Girdwood dev_err(sdev->dev, "error: failed to set DSP D0\n"); 524458bc729SLiam Girdwood return ret; 525458bc729SLiam Girdwood } 526458bc729SLiam Girdwood 527458bc729SLiam Girdwood /* DSP DMA can only access low 31 bits of host memory */ 528458bc729SLiam Girdwood ret = dma_coerce_mask_and_coherent(sdev->dev, DMA_BIT_MASK(31)); 529458bc729SLiam Girdwood if (ret < 0) { 530458bc729SLiam Girdwood dev_err(sdev->dev, "error: failed to set DMA mask %d\n", ret); 531458bc729SLiam Girdwood return ret; 532458bc729SLiam Girdwood } 533458bc729SLiam Girdwood 534458bc729SLiam Girdwood /* set default mailbox */ 535458bc729SLiam Girdwood snd_sof_dsp_mailbox_init(sdev, MBOX_OFFSET, MBOX_SIZE, 0, 0); 536458bc729SLiam Girdwood 537458bc729SLiam Girdwood return ret; 538458bc729SLiam Girdwood } 539458bc729SLiam Girdwood 540285880a2SDaniel Baluta static void bdw_machine_select(struct snd_sof_dev *sdev) 541285880a2SDaniel Baluta { 542285880a2SDaniel Baluta struct snd_sof_pdata *sof_pdata = sdev->pdata; 543285880a2SDaniel Baluta const struct sof_dev_desc *desc = sof_pdata->desc; 544285880a2SDaniel Baluta struct snd_soc_acpi_mach *mach; 545285880a2SDaniel Baluta 546285880a2SDaniel Baluta mach = snd_soc_acpi_find_machine(desc->machines); 547285880a2SDaniel Baluta if (!mach) { 548285880a2SDaniel Baluta dev_warn(sdev->dev, "warning: No matching ASoC machine driver found\n"); 549285880a2SDaniel Baluta return; 550285880a2SDaniel Baluta } 551285880a2SDaniel Baluta 552285880a2SDaniel Baluta sof_pdata->tplg_filename = mach->sof_tplg_filename; 553285880a2SDaniel Baluta mach->mach_params.acpi_ipc_irq_index = desc->irqindex_host_ipc; 554285880a2SDaniel Baluta sof_pdata->machine = mach; 555285880a2SDaniel Baluta } 556285880a2SDaniel Baluta 557285880a2SDaniel Baluta static void bdw_set_mach_params(const struct snd_soc_acpi_mach *mach, 558285880a2SDaniel Baluta struct device *dev) 559285880a2SDaniel Baluta { 560285880a2SDaniel Baluta struct snd_soc_acpi_mach_params *mach_params; 561285880a2SDaniel Baluta 562285880a2SDaniel Baluta mach_params = (struct snd_soc_acpi_mach_params *)&mach->mach_params; 563285880a2SDaniel Baluta mach_params->platform = dev_name(dev); 564285880a2SDaniel Baluta } 565285880a2SDaniel Baluta 566458bc729SLiam Girdwood /* Broadwell DAIs */ 567458bc729SLiam Girdwood static struct snd_soc_dai_driver bdw_dai[] = { 568458bc729SLiam Girdwood { 569458bc729SLiam Girdwood .name = "ssp0-port", 570458bc729SLiam Girdwood }, 571458bc729SLiam Girdwood { 572458bc729SLiam Girdwood .name = "ssp1-port", 573458bc729SLiam Girdwood }, 574458bc729SLiam Girdwood }; 575458bc729SLiam Girdwood 576458bc729SLiam Girdwood /* broadwell ops */ 577458bc729SLiam Girdwood const struct snd_sof_dsp_ops sof_bdw_ops = { 578458bc729SLiam Girdwood /*Device init */ 579458bc729SLiam Girdwood .probe = bdw_probe, 580458bc729SLiam Girdwood 581458bc729SLiam Girdwood /* DSP Core Control */ 582458bc729SLiam Girdwood .run = bdw_run, 583458bc729SLiam Girdwood .reset = bdw_reset, 584458bc729SLiam Girdwood 585458bc729SLiam Girdwood /* Register IO */ 586458bc729SLiam Girdwood .write = sof_io_write, 587458bc729SLiam Girdwood .read = sof_io_read, 588458bc729SLiam Girdwood .write64 = sof_io_write64, 589458bc729SLiam Girdwood .read64 = sof_io_read64, 590458bc729SLiam Girdwood 591458bc729SLiam Girdwood /* Block IO */ 592458bc729SLiam Girdwood .block_read = sof_block_read, 593458bc729SLiam Girdwood .block_write = sof_block_write, 594458bc729SLiam Girdwood 595458bc729SLiam Girdwood /* ipc */ 596458bc729SLiam Girdwood .send_msg = bdw_send_msg, 597ddf14b64SDaniel Baluta .fw_ready = sof_fw_ready, 598ddf14b64SDaniel Baluta .get_mailbox_offset = bdw_get_mailbox_offset, 599ddf14b64SDaniel Baluta .get_window_offset = bdw_get_window_offset, 600458bc729SLiam Girdwood 601458bc729SLiam Girdwood .ipc_msg_data = intel_ipc_msg_data, 602458bc729SLiam Girdwood .ipc_pcm_params = intel_ipc_pcm_params, 603458bc729SLiam Girdwood 604285880a2SDaniel Baluta /* machine driver */ 605285880a2SDaniel Baluta .machine_select = bdw_machine_select, 606285880a2SDaniel Baluta .machine_register = sof_machine_register, 607285880a2SDaniel Baluta .machine_unregister = sof_machine_unregister, 608285880a2SDaniel Baluta .set_mach_params = bdw_set_mach_params, 609285880a2SDaniel Baluta 610458bc729SLiam Girdwood /* debug */ 611458bc729SLiam Girdwood .debug_map = bdw_debugfs, 612458bc729SLiam Girdwood .debug_map_count = ARRAY_SIZE(bdw_debugfs), 613458bc729SLiam Girdwood .dbg_dump = bdw_dump, 614458bc729SLiam Girdwood 615458bc729SLiam Girdwood /* stream callbacks */ 616458bc729SLiam Girdwood .pcm_open = intel_pcm_open, 617458bc729SLiam Girdwood .pcm_close = intel_pcm_close, 618458bc729SLiam Girdwood 619458bc729SLiam Girdwood /* Module loading */ 620458bc729SLiam Girdwood .load_module = snd_sof_parse_module_memcpy, 621458bc729SLiam Girdwood 622458bc729SLiam Girdwood /*Firmware loading */ 623458bc729SLiam Girdwood .load_firmware = snd_sof_load_firmware_memcpy, 624458bc729SLiam Girdwood 625458bc729SLiam Girdwood /* DAI drivers */ 626458bc729SLiam Girdwood .drv = bdw_dai, 62727e322faSPierre-Louis Bossart .num_drv = ARRAY_SIZE(bdw_dai), 62827e322faSPierre-Louis Bossart 62927e322faSPierre-Louis Bossart /* ALSA HW info flags */ 63027e322faSPierre-Louis Bossart .hw_info = SNDRV_PCM_INFO_MMAP | 63127e322faSPierre-Louis Bossart SNDRV_PCM_INFO_MMAP_VALID | 63227e322faSPierre-Louis Bossart SNDRV_PCM_INFO_INTERLEAVED | 63327e322faSPierre-Louis Bossart SNDRV_PCM_INFO_PAUSE | 6344c02a7bdSPierre-Louis Bossart SNDRV_PCM_INFO_BATCH, 635458bc729SLiam Girdwood }; 636458bc729SLiam Girdwood EXPORT_SYMBOL(sof_bdw_ops); 637458bc729SLiam Girdwood 638458bc729SLiam Girdwood const struct sof_intel_dsp_desc bdw_chip_info = { 639458bc729SLiam Girdwood .cores_num = 1, 640458bc729SLiam Girdwood .cores_mask = 1, 641458bc729SLiam Girdwood }; 642458bc729SLiam Girdwood EXPORT_SYMBOL(bdw_chip_info); 643458bc729SLiam Girdwood 644458bc729SLiam Girdwood MODULE_LICENSE("Dual BSD/GPL"); 645