1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) 2 // 3 // This file is provided under a dual BSD/GPLv2 license. When using or 4 // redistributing this file, you may do so under either license. 5 // 6 // Copyright(c) 2018 Intel Corporation. All rights reserved. 7 // 8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> 9 // 10 11 /* 12 * Hardware interface for audio DSP on Baytrail, Braswell and Cherrytrail. 13 */ 14 15 #include <linux/module.h> 16 #include <sound/sof.h> 17 #include <sound/sof/xtensa.h> 18 #include "../ops.h" 19 #include "shim.h" 20 #include "../sof-audio.h" 21 #include "../../intel/common/soc-intel-quirks.h" 22 23 /* DSP memories */ 24 #define IRAM_OFFSET 0x0C0000 25 #define IRAM_SIZE (80 * 1024) 26 #define DRAM_OFFSET 0x100000 27 #define DRAM_SIZE (160 * 1024) 28 #define SHIM_OFFSET 0x140000 29 #define SHIM_SIZE_BYT 0x100 30 #define SHIM_SIZE_CHT 0x118 31 #define MBOX_OFFSET 0x144000 32 #define MBOX_SIZE 0x1000 33 #define EXCEPT_OFFSET 0x800 34 #define EXCEPT_MAX_HDR_SIZE 0x400 35 36 /* DSP peripherals */ 37 #define DMAC0_OFFSET 0x098000 38 #define DMAC1_OFFSET 0x09c000 39 #define DMAC2_OFFSET 0x094000 40 #define DMAC_SIZE 0x420 41 #define SSP0_OFFSET 0x0a0000 42 #define SSP1_OFFSET 0x0a1000 43 #define SSP2_OFFSET 0x0a2000 44 #define SSP3_OFFSET 0x0a4000 45 #define SSP4_OFFSET 0x0a5000 46 #define SSP5_OFFSET 0x0a6000 47 #define SSP_SIZE 0x100 48 49 #define BYT_STACK_DUMP_SIZE 32 50 51 #define BYT_PCI_BAR_SIZE 0x200000 52 53 #define BYT_PANIC_OFFSET(x) (((x) & GENMASK_ULL(47, 32)) >> 32) 54 55 /* 56 * Debug 57 */ 58 59 #define MBOX_DUMP_SIZE 0x30 60 61 /* BARs */ 62 #define BYT_DSP_BAR 0 63 #define BYT_PCI_BAR 1 64 #define BYT_IMR_BAR 2 65 66 static const struct snd_sof_debugfs_map byt_debugfs[] = { 67 {"dmac0", BYT_DSP_BAR, DMAC0_OFFSET, DMAC_SIZE, 68 SOF_DEBUGFS_ACCESS_ALWAYS}, 69 {"dmac1", BYT_DSP_BAR, DMAC1_OFFSET, DMAC_SIZE, 70 SOF_DEBUGFS_ACCESS_ALWAYS}, 71 {"ssp0", BYT_DSP_BAR, SSP0_OFFSET, SSP_SIZE, 72 SOF_DEBUGFS_ACCESS_ALWAYS}, 73 {"ssp1", BYT_DSP_BAR, SSP1_OFFSET, SSP_SIZE, 74 SOF_DEBUGFS_ACCESS_ALWAYS}, 75 {"ssp2", BYT_DSP_BAR, SSP2_OFFSET, SSP_SIZE, 76 SOF_DEBUGFS_ACCESS_ALWAYS}, 77 {"iram", BYT_DSP_BAR, IRAM_OFFSET, IRAM_SIZE, 78 SOF_DEBUGFS_ACCESS_D0_ONLY}, 79 {"dram", BYT_DSP_BAR, DRAM_OFFSET, DRAM_SIZE, 80 SOF_DEBUGFS_ACCESS_D0_ONLY}, 81 {"shim", BYT_DSP_BAR, SHIM_OFFSET, SHIM_SIZE_BYT, 82 SOF_DEBUGFS_ACCESS_ALWAYS}, 83 }; 84 85 static void byt_host_done(struct snd_sof_dev *sdev); 86 static void byt_dsp_done(struct snd_sof_dev *sdev); 87 static void byt_get_reply(struct snd_sof_dev *sdev); 88 89 /* 90 * Debug 91 */ 92 93 static void byt_get_registers(struct snd_sof_dev *sdev, 94 struct sof_ipc_dsp_oops_xtensa *xoops, 95 struct sof_ipc_panic_info *panic_info, 96 u32 *stack, size_t stack_words) 97 { 98 u32 offset = sdev->dsp_oops_offset; 99 100 /* first read regsisters */ 101 sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops)); 102 103 /* note: variable AR register array is not read */ 104 105 /* then get panic info */ 106 if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) { 107 dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n", 108 xoops->arch_hdr.totalsize); 109 return; 110 } 111 offset += xoops->arch_hdr.totalsize; 112 sof_mailbox_read(sdev, offset, panic_info, sizeof(*panic_info)); 113 114 /* then get the stack */ 115 offset += sizeof(*panic_info); 116 sof_mailbox_read(sdev, offset, stack, stack_words * sizeof(u32)); 117 } 118 119 static void byt_dump(struct snd_sof_dev *sdev, u32 flags) 120 { 121 struct sof_ipc_dsp_oops_xtensa xoops; 122 struct sof_ipc_panic_info panic_info; 123 u32 stack[BYT_STACK_DUMP_SIZE]; 124 u64 status, panic, imrd, imrx; 125 126 /* now try generic SOF status messages */ 127 status = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IPCD); 128 panic = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IPCX); 129 byt_get_registers(sdev, &xoops, &panic_info, stack, 130 BYT_STACK_DUMP_SIZE); 131 snd_sof_get_status(sdev, status, panic, &xoops, &panic_info, stack, 132 BYT_STACK_DUMP_SIZE); 133 134 /* provide some context for firmware debug */ 135 imrx = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IMRX); 136 imrd = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IMRD); 137 dev_err(sdev->dev, 138 "error: ipc host -> DSP: pending %s complete %s raw 0x%llx\n", 139 (panic & SHIM_IPCX_BUSY) ? "yes" : "no", 140 (panic & SHIM_IPCX_DONE) ? "yes" : "no", panic); 141 dev_err(sdev->dev, 142 "error: mask host: pending %s complete %s raw 0x%llx\n", 143 (imrx & SHIM_IMRX_BUSY) ? "yes" : "no", 144 (imrx & SHIM_IMRX_DONE) ? "yes" : "no", imrx); 145 dev_err(sdev->dev, 146 "error: ipc DSP -> host: pending %s complete %s raw 0x%llx\n", 147 (status & SHIM_IPCD_BUSY) ? "yes" : "no", 148 (status & SHIM_IPCD_DONE) ? "yes" : "no", status); 149 dev_err(sdev->dev, 150 "error: mask DSP: pending %s complete %s raw 0x%llx\n", 151 (imrd & SHIM_IMRD_BUSY) ? "yes" : "no", 152 (imrd & SHIM_IMRD_DONE) ? "yes" : "no", imrd); 153 154 } 155 156 /* 157 * IPC Doorbell IRQ handler and thread. 158 */ 159 160 static irqreturn_t byt_irq_handler(int irq, void *context) 161 { 162 struct snd_sof_dev *sdev = context; 163 u64 isr; 164 int ret = IRQ_NONE; 165 166 /* Interrupt arrived, check src */ 167 isr = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_ISRX); 168 if (isr & (SHIM_ISRX_DONE | SHIM_ISRX_BUSY)) 169 ret = IRQ_WAKE_THREAD; 170 171 return ret; 172 } 173 174 static irqreturn_t byt_irq_thread(int irq, void *context) 175 { 176 struct snd_sof_dev *sdev = context; 177 u64 ipcx, ipcd; 178 u64 imrx; 179 180 imrx = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IMRX); 181 ipcx = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IPCX); 182 183 /* reply message from DSP */ 184 if (ipcx & SHIM_BYT_IPCX_DONE && 185 !(imrx & SHIM_IMRX_DONE)) { 186 /* Mask Done interrupt before first */ 187 snd_sof_dsp_update_bits64_unlocked(sdev, BYT_DSP_BAR, 188 SHIM_IMRX, 189 SHIM_IMRX_DONE, 190 SHIM_IMRX_DONE); 191 192 spin_lock_irq(&sdev->ipc_lock); 193 194 /* 195 * handle immediate reply from DSP core. If the msg is 196 * found, set done bit in cmd_done which is called at the 197 * end of message processing function, else set it here 198 * because the done bit can't be set in cmd_done function 199 * which is triggered by msg 200 */ 201 byt_get_reply(sdev); 202 snd_sof_ipc_reply(sdev, ipcx); 203 204 byt_dsp_done(sdev); 205 206 spin_unlock_irq(&sdev->ipc_lock); 207 } 208 209 /* new message from DSP */ 210 ipcd = snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_IPCD); 211 if (ipcd & SHIM_BYT_IPCD_BUSY && 212 !(imrx & SHIM_IMRX_BUSY)) { 213 /* Mask Busy interrupt before return */ 214 snd_sof_dsp_update_bits64_unlocked(sdev, BYT_DSP_BAR, 215 SHIM_IMRX, 216 SHIM_IMRX_BUSY, 217 SHIM_IMRX_BUSY); 218 219 /* Handle messages from DSP Core */ 220 if ((ipcd & SOF_IPC_PANIC_MAGIC_MASK) == SOF_IPC_PANIC_MAGIC) { 221 snd_sof_dsp_panic(sdev, BYT_PANIC_OFFSET(ipcd) + 222 MBOX_OFFSET); 223 } else { 224 snd_sof_ipc_msgs_rx(sdev); 225 } 226 227 byt_host_done(sdev); 228 } 229 230 return IRQ_HANDLED; 231 } 232 233 static int byt_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) 234 { 235 /* send the message */ 236 sof_mailbox_write(sdev, sdev->host_box.offset, msg->msg_data, 237 msg->msg_size); 238 snd_sof_dsp_write64(sdev, BYT_DSP_BAR, SHIM_IPCX, SHIM_BYT_IPCX_BUSY); 239 240 return 0; 241 } 242 243 static void byt_get_reply(struct snd_sof_dev *sdev) 244 { 245 struct snd_sof_ipc_msg *msg = sdev->msg; 246 struct sof_ipc_reply reply; 247 int ret = 0; 248 249 /* 250 * Sometimes, there is unexpected reply ipc arriving. The reply 251 * ipc belongs to none of the ipcs sent from driver. 252 * In this case, the driver must ignore the ipc. 253 */ 254 if (!msg) { 255 dev_warn(sdev->dev, "unexpected ipc interrupt raised!\n"); 256 return; 257 } 258 259 /* get reply */ 260 sof_mailbox_read(sdev, sdev->host_box.offset, &reply, sizeof(reply)); 261 262 if (reply.error < 0) { 263 memcpy(msg->reply_data, &reply, sizeof(reply)); 264 ret = reply.error; 265 } else { 266 /* reply correct size ? */ 267 if (reply.hdr.size != msg->reply_size) { 268 dev_err(sdev->dev, "error: reply expected %zu got %u bytes\n", 269 msg->reply_size, reply.hdr.size); 270 ret = -EINVAL; 271 } 272 273 /* read the message */ 274 if (msg->reply_size > 0) 275 sof_mailbox_read(sdev, sdev->host_box.offset, 276 msg->reply_data, msg->reply_size); 277 } 278 279 msg->reply_error = ret; 280 } 281 282 static int byt_get_mailbox_offset(struct snd_sof_dev *sdev) 283 { 284 return MBOX_OFFSET; 285 } 286 287 static int byt_get_window_offset(struct snd_sof_dev *sdev, u32 id) 288 { 289 return MBOX_OFFSET; 290 } 291 292 static void byt_host_done(struct snd_sof_dev *sdev) 293 { 294 /* clear BUSY bit and set DONE bit - accept new messages */ 295 snd_sof_dsp_update_bits64_unlocked(sdev, BYT_DSP_BAR, SHIM_IPCD, 296 SHIM_BYT_IPCD_BUSY | 297 SHIM_BYT_IPCD_DONE, 298 SHIM_BYT_IPCD_DONE); 299 300 /* unmask busy interrupt */ 301 snd_sof_dsp_update_bits64_unlocked(sdev, BYT_DSP_BAR, SHIM_IMRX, 302 SHIM_IMRX_BUSY, 0); 303 } 304 305 static void byt_dsp_done(struct snd_sof_dev *sdev) 306 { 307 /* clear DONE bit - tell DSP we have completed */ 308 snd_sof_dsp_update_bits64_unlocked(sdev, BYT_DSP_BAR, SHIM_IPCX, 309 SHIM_BYT_IPCX_DONE, 0); 310 311 /* unmask Done interrupt */ 312 snd_sof_dsp_update_bits64_unlocked(sdev, BYT_DSP_BAR, SHIM_IMRX, 313 SHIM_IMRX_DONE, 0); 314 } 315 316 /* 317 * DSP control. 318 */ 319 320 static int byt_run(struct snd_sof_dev *sdev) 321 { 322 int tries = 10; 323 324 /* release stall and wait to unstall */ 325 snd_sof_dsp_update_bits64(sdev, BYT_DSP_BAR, SHIM_CSR, 326 SHIM_BYT_CSR_STALL, 0x0); 327 while (tries--) { 328 if (!(snd_sof_dsp_read64(sdev, BYT_DSP_BAR, SHIM_CSR) & 329 SHIM_BYT_CSR_PWAITMODE)) 330 break; 331 msleep(100); 332 } 333 if (tries < 0) { 334 dev_err(sdev->dev, "error: unable to run DSP firmware\n"); 335 byt_dump(sdev, SOF_DBG_REGS | SOF_DBG_MBOX); 336 return -ENODEV; 337 } 338 339 /* return init core mask */ 340 return 1; 341 } 342 343 static int byt_reset(struct snd_sof_dev *sdev) 344 { 345 /* put DSP into reset, set reset vector and stall */ 346 snd_sof_dsp_update_bits64(sdev, BYT_DSP_BAR, SHIM_CSR, 347 SHIM_BYT_CSR_RST | SHIM_BYT_CSR_VECTOR_SEL | 348 SHIM_BYT_CSR_STALL, 349 SHIM_BYT_CSR_RST | SHIM_BYT_CSR_VECTOR_SEL | 350 SHIM_BYT_CSR_STALL); 351 352 usleep_range(10, 15); 353 354 /* take DSP out of reset and keep stalled for FW loading */ 355 snd_sof_dsp_update_bits64(sdev, BYT_DSP_BAR, SHIM_CSR, 356 SHIM_BYT_CSR_RST, 0); 357 358 return 0; 359 } 360 361 static const char *fixup_tplg_name(struct snd_sof_dev *sdev, 362 const char *sof_tplg_filename, 363 const char *ssp_str) 364 { 365 const char *tplg_filename = NULL; 366 char *filename; 367 char *split_ext; 368 369 filename = devm_kstrdup(sdev->dev, sof_tplg_filename, GFP_KERNEL); 370 if (!filename) 371 return NULL; 372 373 /* this assumes a .tplg extension */ 374 split_ext = strsep(&filename, "."); 375 if (split_ext) { 376 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, 377 "%s-%s.tplg", 378 split_ext, ssp_str); 379 if (!tplg_filename) 380 return NULL; 381 } 382 return tplg_filename; 383 } 384 385 static void byt_machine_select(struct snd_sof_dev *sdev) 386 { 387 struct snd_sof_pdata *sof_pdata = sdev->pdata; 388 const struct sof_dev_desc *desc = sof_pdata->desc; 389 struct snd_soc_acpi_mach *mach; 390 struct platform_device *pdev; 391 const char *tplg_filename; 392 393 mach = snd_soc_acpi_find_machine(desc->machines); 394 if (!mach) { 395 dev_warn(sdev->dev, "warning: No matching ASoC machine driver found\n"); 396 return; 397 } 398 399 pdev = to_platform_device(sdev->dev); 400 if (soc_intel_is_byt_cr(pdev)) { 401 dev_dbg(sdev->dev, 402 "BYT-CR detected, SSP0 used instead of SSP2\n"); 403 404 tplg_filename = fixup_tplg_name(sdev, 405 mach->sof_tplg_filename, 406 "ssp0"); 407 } else { 408 tplg_filename = mach->sof_tplg_filename; 409 } 410 411 if (!tplg_filename) { 412 dev_dbg(sdev->dev, 413 "error: no topology filename\n"); 414 return; 415 } 416 417 sof_pdata->tplg_filename = tplg_filename; 418 mach->mach_params.acpi_ipc_irq_index = desc->irqindex_host_ipc; 419 sof_pdata->machine = mach; 420 } 421 422 static void byt_set_mach_params(const struct snd_soc_acpi_mach *mach, 423 struct device *dev) 424 { 425 struct snd_soc_acpi_mach_params *mach_params; 426 427 mach_params = (struct snd_soc_acpi_mach_params *)&mach->mach_params; 428 mach_params->platform = dev_name(dev); 429 } 430 431 /* Baytrail DAIs */ 432 static struct snd_soc_dai_driver byt_dai[] = { 433 { 434 .name = "ssp0-port", 435 .playback = { 436 .channels_min = 1, 437 .channels_max = 8, 438 }, 439 .capture = { 440 .channels_min = 1, 441 .channels_max = 8, 442 }, 443 }, 444 { 445 .name = "ssp1-port", 446 .playback = { 447 .channels_min = 1, 448 .channels_max = 8, 449 }, 450 .capture = { 451 .channels_min = 1, 452 .channels_max = 8, 453 }, 454 }, 455 { 456 .name = "ssp2-port", 457 .playback = { 458 .channels_min = 1, 459 .channels_max = 8, 460 }, 461 .capture = { 462 .channels_min = 1, 463 .channels_max = 8, 464 } 465 }, 466 { 467 .name = "ssp3-port", 468 .playback = { 469 .channels_min = 1, 470 .channels_max = 8, 471 }, 472 .capture = { 473 .channels_min = 1, 474 .channels_max = 8, 475 }, 476 }, 477 { 478 .name = "ssp4-port", 479 .playback = { 480 .channels_min = 1, 481 .channels_max = 8, 482 }, 483 .capture = { 484 .channels_min = 1, 485 .channels_max = 8, 486 }, 487 }, 488 { 489 .name = "ssp5-port", 490 .playback = { 491 .channels_min = 1, 492 .channels_max = 8, 493 }, 494 .capture = { 495 .channels_min = 1, 496 .channels_max = 8, 497 }, 498 }, 499 }; 500 501 /* 502 * Probe and remove. 503 */ 504 505 #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD) 506 507 static int tangier_pci_probe(struct snd_sof_dev *sdev) 508 { 509 struct snd_sof_pdata *pdata = sdev->pdata; 510 const struct sof_dev_desc *desc = pdata->desc; 511 struct pci_dev *pci = to_pci_dev(sdev->dev); 512 u32 base, size; 513 int ret; 514 515 /* DSP DMA can only access low 31 bits of host memory */ 516 ret = dma_coerce_mask_and_coherent(&pci->dev, DMA_BIT_MASK(31)); 517 if (ret < 0) { 518 dev_err(sdev->dev, "error: failed to set DMA mask %d\n", ret); 519 return ret; 520 } 521 522 /* LPE base */ 523 base = pci_resource_start(pci, desc->resindex_lpe_base) - IRAM_OFFSET; 524 size = BYT_PCI_BAR_SIZE; 525 526 dev_dbg(sdev->dev, "LPE PHY base at 0x%x size 0x%x", base, size); 527 sdev->bar[BYT_DSP_BAR] = devm_ioremap(sdev->dev, base, size); 528 if (!sdev->bar[BYT_DSP_BAR]) { 529 dev_err(sdev->dev, "error: failed to ioremap LPE base 0x%x size 0x%x\n", 530 base, size); 531 return -ENODEV; 532 } 533 dev_dbg(sdev->dev, "LPE VADDR %p\n", sdev->bar[BYT_DSP_BAR]); 534 535 /* IMR base - optional */ 536 if (desc->resindex_imr_base == -1) 537 goto irq; 538 539 base = pci_resource_start(pci, desc->resindex_imr_base); 540 size = pci_resource_len(pci, desc->resindex_imr_base); 541 542 /* some BIOSes don't map IMR */ 543 if (base == 0x55aa55aa || base == 0x0) { 544 dev_info(sdev->dev, "IMR not set by BIOS. Ignoring\n"); 545 goto irq; 546 } 547 548 dev_dbg(sdev->dev, "IMR base at 0x%x size 0x%x", base, size); 549 sdev->bar[BYT_IMR_BAR] = devm_ioremap(sdev->dev, base, size); 550 if (!sdev->bar[BYT_IMR_BAR]) { 551 dev_err(sdev->dev, "error: failed to ioremap IMR base 0x%x size 0x%x\n", 552 base, size); 553 return -ENODEV; 554 } 555 dev_dbg(sdev->dev, "IMR VADDR %p\n", sdev->bar[BYT_IMR_BAR]); 556 557 irq: 558 /* register our IRQ */ 559 sdev->ipc_irq = pci->irq; 560 dev_dbg(sdev->dev, "using IRQ %d\n", sdev->ipc_irq); 561 ret = devm_request_threaded_irq(sdev->dev, sdev->ipc_irq, 562 byt_irq_handler, byt_irq_thread, 563 0, "AudioDSP", sdev); 564 if (ret < 0) { 565 dev_err(sdev->dev, "error: failed to register IRQ %d\n", 566 sdev->ipc_irq); 567 return ret; 568 } 569 570 /* enable Interrupt from both sides */ 571 snd_sof_dsp_update_bits64(sdev, BYT_DSP_BAR, SHIM_IMRX, 0x3, 0x0); 572 snd_sof_dsp_update_bits64(sdev, BYT_DSP_BAR, SHIM_IMRD, 0x3, 0x0); 573 574 /* set default mailbox offset for FW ready message */ 575 sdev->dsp_box.offset = MBOX_OFFSET; 576 577 return ret; 578 } 579 580 const struct snd_sof_dsp_ops sof_tng_ops = { 581 /* device init */ 582 .probe = tangier_pci_probe, 583 584 /* DSP core boot / reset */ 585 .run = byt_run, 586 .reset = byt_reset, 587 588 /* Register IO */ 589 .write = sof_io_write, 590 .read = sof_io_read, 591 .write64 = sof_io_write64, 592 .read64 = sof_io_read64, 593 594 /* Block IO */ 595 .block_read = sof_block_read, 596 .block_write = sof_block_write, 597 598 /* doorbell */ 599 .irq_handler = byt_irq_handler, 600 .irq_thread = byt_irq_thread, 601 602 /* ipc */ 603 .send_msg = byt_send_msg, 604 .fw_ready = sof_fw_ready, 605 .get_mailbox_offset = byt_get_mailbox_offset, 606 .get_window_offset = byt_get_window_offset, 607 608 .ipc_msg_data = intel_ipc_msg_data, 609 .ipc_pcm_params = intel_ipc_pcm_params, 610 611 /* machine driver */ 612 .machine_select = byt_machine_select, 613 .machine_register = sof_machine_register, 614 .machine_unregister = sof_machine_unregister, 615 .set_mach_params = byt_set_mach_params, 616 617 /* debug */ 618 .debug_map = byt_debugfs, 619 .debug_map_count = ARRAY_SIZE(byt_debugfs), 620 .dbg_dump = byt_dump, 621 622 /* stream callbacks */ 623 .pcm_open = intel_pcm_open, 624 .pcm_close = intel_pcm_close, 625 626 /* module loading */ 627 .load_module = snd_sof_parse_module_memcpy, 628 629 /*Firmware loading */ 630 .load_firmware = snd_sof_load_firmware_memcpy, 631 632 /* DAI drivers */ 633 .drv = byt_dai, 634 .num_drv = 3, /* we have only 3 SSPs on byt*/ 635 636 /* ALSA HW info flags */ 637 .hw_info = SNDRV_PCM_INFO_MMAP | 638 SNDRV_PCM_INFO_MMAP_VALID | 639 SNDRV_PCM_INFO_INTERLEAVED | 640 SNDRV_PCM_INFO_PAUSE | 641 SNDRV_PCM_INFO_BATCH, 642 643 .arch_ops = &sof_xtensa_arch_ops, 644 }; 645 EXPORT_SYMBOL_NS(sof_tng_ops, SND_SOC_SOF_MERRIFIELD); 646 647 const struct sof_intel_dsp_desc tng_chip_info = { 648 .cores_num = 1, 649 .cores_mask = 1, 650 }; 651 EXPORT_SYMBOL_NS(tng_chip_info, SND_SOC_SOF_MERRIFIELD); 652 653 #endif /* CONFIG_SND_SOC_SOF_MERRIFIELD */ 654 655 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) 656 657 static const struct snd_sof_debugfs_map cht_debugfs[] = { 658 {"dmac0", BYT_DSP_BAR, DMAC0_OFFSET, DMAC_SIZE, 659 SOF_DEBUGFS_ACCESS_ALWAYS}, 660 {"dmac1", BYT_DSP_BAR, DMAC1_OFFSET, DMAC_SIZE, 661 SOF_DEBUGFS_ACCESS_ALWAYS}, 662 {"dmac2", BYT_DSP_BAR, DMAC2_OFFSET, DMAC_SIZE, 663 SOF_DEBUGFS_ACCESS_ALWAYS}, 664 {"ssp0", BYT_DSP_BAR, SSP0_OFFSET, SSP_SIZE, 665 SOF_DEBUGFS_ACCESS_ALWAYS}, 666 {"ssp1", BYT_DSP_BAR, SSP1_OFFSET, SSP_SIZE, 667 SOF_DEBUGFS_ACCESS_ALWAYS}, 668 {"ssp2", BYT_DSP_BAR, SSP2_OFFSET, SSP_SIZE, 669 SOF_DEBUGFS_ACCESS_ALWAYS}, 670 {"ssp3", BYT_DSP_BAR, SSP3_OFFSET, SSP_SIZE, 671 SOF_DEBUGFS_ACCESS_ALWAYS}, 672 {"ssp4", BYT_DSP_BAR, SSP4_OFFSET, SSP_SIZE, 673 SOF_DEBUGFS_ACCESS_ALWAYS}, 674 {"ssp5", BYT_DSP_BAR, SSP5_OFFSET, SSP_SIZE, 675 SOF_DEBUGFS_ACCESS_ALWAYS}, 676 {"iram", BYT_DSP_BAR, IRAM_OFFSET, IRAM_SIZE, 677 SOF_DEBUGFS_ACCESS_D0_ONLY}, 678 {"dram", BYT_DSP_BAR, DRAM_OFFSET, DRAM_SIZE, 679 SOF_DEBUGFS_ACCESS_D0_ONLY}, 680 {"shim", BYT_DSP_BAR, SHIM_OFFSET, SHIM_SIZE_CHT, 681 SOF_DEBUGFS_ACCESS_ALWAYS}, 682 }; 683 684 static int byt_acpi_probe(struct snd_sof_dev *sdev) 685 { 686 struct snd_sof_pdata *pdata = sdev->pdata; 687 const struct sof_dev_desc *desc = pdata->desc; 688 struct platform_device *pdev = 689 container_of(sdev->dev, struct platform_device, dev); 690 struct resource *mmio; 691 u32 base, size; 692 int ret; 693 694 /* DSP DMA can only access low 31 bits of host memory */ 695 ret = dma_coerce_mask_and_coherent(sdev->dev, DMA_BIT_MASK(31)); 696 if (ret < 0) { 697 dev_err(sdev->dev, "error: failed to set DMA mask %d\n", ret); 698 return ret; 699 } 700 701 /* LPE base */ 702 mmio = platform_get_resource(pdev, IORESOURCE_MEM, 703 desc->resindex_lpe_base); 704 if (mmio) { 705 base = mmio->start; 706 size = resource_size(mmio); 707 } else { 708 dev_err(sdev->dev, "error: failed to get LPE base at idx %d\n", 709 desc->resindex_lpe_base); 710 return -EINVAL; 711 } 712 713 dev_dbg(sdev->dev, "LPE PHY base at 0x%x size 0x%x", base, size); 714 sdev->bar[BYT_DSP_BAR] = devm_ioremap(sdev->dev, base, size); 715 if (!sdev->bar[BYT_DSP_BAR]) { 716 dev_err(sdev->dev, "error: failed to ioremap LPE base 0x%x size 0x%x\n", 717 base, size); 718 return -ENODEV; 719 } 720 dev_dbg(sdev->dev, "LPE VADDR %p\n", sdev->bar[BYT_DSP_BAR]); 721 722 /* TODO: add offsets */ 723 sdev->mmio_bar = BYT_DSP_BAR; 724 sdev->mailbox_bar = BYT_DSP_BAR; 725 726 /* IMR base - optional */ 727 if (desc->resindex_imr_base == -1) 728 goto irq; 729 730 mmio = platform_get_resource(pdev, IORESOURCE_MEM, 731 desc->resindex_imr_base); 732 if (mmio) { 733 base = mmio->start; 734 size = resource_size(mmio); 735 } else { 736 dev_err(sdev->dev, "error: failed to get IMR base at idx %d\n", 737 desc->resindex_imr_base); 738 return -ENODEV; 739 } 740 741 /* some BIOSes don't map IMR */ 742 if (base == 0x55aa55aa || base == 0x0) { 743 dev_info(sdev->dev, "IMR not set by BIOS. Ignoring\n"); 744 goto irq; 745 } 746 747 dev_dbg(sdev->dev, "IMR base at 0x%x size 0x%x", base, size); 748 sdev->bar[BYT_IMR_BAR] = devm_ioremap(sdev->dev, base, size); 749 if (!sdev->bar[BYT_IMR_BAR]) { 750 dev_err(sdev->dev, "error: failed to ioremap IMR base 0x%x size 0x%x\n", 751 base, size); 752 return -ENODEV; 753 } 754 dev_dbg(sdev->dev, "IMR VADDR %p\n", sdev->bar[BYT_IMR_BAR]); 755 756 irq: 757 /* register our IRQ */ 758 sdev->ipc_irq = platform_get_irq(pdev, desc->irqindex_host_ipc); 759 if (sdev->ipc_irq < 0) 760 return sdev->ipc_irq; 761 762 dev_dbg(sdev->dev, "using IRQ %d\n", sdev->ipc_irq); 763 ret = devm_request_threaded_irq(sdev->dev, sdev->ipc_irq, 764 byt_irq_handler, byt_irq_thread, 765 IRQF_SHARED, "AudioDSP", sdev); 766 if (ret < 0) { 767 dev_err(sdev->dev, "error: failed to register IRQ %d\n", 768 sdev->ipc_irq); 769 return ret; 770 } 771 772 /* enable Interrupt from both sides */ 773 snd_sof_dsp_update_bits64(sdev, BYT_DSP_BAR, SHIM_IMRX, 0x3, 0x0); 774 snd_sof_dsp_update_bits64(sdev, BYT_DSP_BAR, SHIM_IMRD, 0x3, 0x0); 775 776 /* set default mailbox offset for FW ready message */ 777 sdev->dsp_box.offset = MBOX_OFFSET; 778 779 return ret; 780 } 781 782 /* baytrail ops */ 783 const struct snd_sof_dsp_ops sof_byt_ops = { 784 /* device init */ 785 .probe = byt_acpi_probe, 786 787 /* DSP core boot / reset */ 788 .run = byt_run, 789 .reset = byt_reset, 790 791 /* Register IO */ 792 .write = sof_io_write, 793 .read = sof_io_read, 794 .write64 = sof_io_write64, 795 .read64 = sof_io_read64, 796 797 /* Block IO */ 798 .block_read = sof_block_read, 799 .block_write = sof_block_write, 800 801 /* doorbell */ 802 .irq_handler = byt_irq_handler, 803 .irq_thread = byt_irq_thread, 804 805 /* ipc */ 806 .send_msg = byt_send_msg, 807 .fw_ready = sof_fw_ready, 808 .get_mailbox_offset = byt_get_mailbox_offset, 809 .get_window_offset = byt_get_window_offset, 810 811 .ipc_msg_data = intel_ipc_msg_data, 812 .ipc_pcm_params = intel_ipc_pcm_params, 813 814 /* machine driver */ 815 .machine_select = byt_machine_select, 816 .machine_register = sof_machine_register, 817 .machine_unregister = sof_machine_unregister, 818 .set_mach_params = byt_set_mach_params, 819 820 /* debug */ 821 .debug_map = byt_debugfs, 822 .debug_map_count = ARRAY_SIZE(byt_debugfs), 823 .dbg_dump = byt_dump, 824 825 /* stream callbacks */ 826 .pcm_open = intel_pcm_open, 827 .pcm_close = intel_pcm_close, 828 829 /* module loading */ 830 .load_module = snd_sof_parse_module_memcpy, 831 832 /*Firmware loading */ 833 .load_firmware = snd_sof_load_firmware_memcpy, 834 835 /* DAI drivers */ 836 .drv = byt_dai, 837 .num_drv = 3, /* we have only 3 SSPs on byt*/ 838 839 /* ALSA HW info flags */ 840 .hw_info = SNDRV_PCM_INFO_MMAP | 841 SNDRV_PCM_INFO_MMAP_VALID | 842 SNDRV_PCM_INFO_INTERLEAVED | 843 SNDRV_PCM_INFO_PAUSE | 844 SNDRV_PCM_INFO_BATCH, 845 846 .arch_ops = &sof_xtensa_arch_ops, 847 }; 848 EXPORT_SYMBOL_NS(sof_byt_ops, SND_SOC_SOF_BAYTRAIL); 849 850 const struct sof_intel_dsp_desc byt_chip_info = { 851 .cores_num = 1, 852 .cores_mask = 1, 853 }; 854 EXPORT_SYMBOL_NS(byt_chip_info, SND_SOC_SOF_BAYTRAIL); 855 856 /* cherrytrail and braswell ops */ 857 const struct snd_sof_dsp_ops sof_cht_ops = { 858 /* device init */ 859 .probe = byt_acpi_probe, 860 861 /* DSP core boot / reset */ 862 .run = byt_run, 863 .reset = byt_reset, 864 865 /* Register IO */ 866 .write = sof_io_write, 867 .read = sof_io_read, 868 .write64 = sof_io_write64, 869 .read64 = sof_io_read64, 870 871 /* Block IO */ 872 .block_read = sof_block_read, 873 .block_write = sof_block_write, 874 875 /* doorbell */ 876 .irq_handler = byt_irq_handler, 877 .irq_thread = byt_irq_thread, 878 879 /* ipc */ 880 .send_msg = byt_send_msg, 881 .fw_ready = sof_fw_ready, 882 .get_mailbox_offset = byt_get_mailbox_offset, 883 .get_window_offset = byt_get_window_offset, 884 885 .ipc_msg_data = intel_ipc_msg_data, 886 .ipc_pcm_params = intel_ipc_pcm_params, 887 888 /* machine driver */ 889 .machine_select = byt_machine_select, 890 .machine_register = sof_machine_register, 891 .machine_unregister = sof_machine_unregister, 892 .set_mach_params = byt_set_mach_params, 893 894 /* debug */ 895 .debug_map = cht_debugfs, 896 .debug_map_count = ARRAY_SIZE(cht_debugfs), 897 .dbg_dump = byt_dump, 898 899 /* stream callbacks */ 900 .pcm_open = intel_pcm_open, 901 .pcm_close = intel_pcm_close, 902 903 /* module loading */ 904 .load_module = snd_sof_parse_module_memcpy, 905 906 /*Firmware loading */ 907 .load_firmware = snd_sof_load_firmware_memcpy, 908 909 /* DAI drivers */ 910 .drv = byt_dai, 911 /* all 6 SSPs may be available for cherrytrail */ 912 .num_drv = ARRAY_SIZE(byt_dai), 913 914 /* ALSA HW info flags */ 915 .hw_info = SNDRV_PCM_INFO_MMAP | 916 SNDRV_PCM_INFO_MMAP_VALID | 917 SNDRV_PCM_INFO_INTERLEAVED | 918 SNDRV_PCM_INFO_PAUSE | 919 SNDRV_PCM_INFO_BATCH, 920 921 .arch_ops = &sof_xtensa_arch_ops, 922 }; 923 EXPORT_SYMBOL_NS(sof_cht_ops, SND_SOC_SOF_BAYTRAIL); 924 925 const struct sof_intel_dsp_desc cht_chip_info = { 926 .cores_num = 1, 927 .cores_mask = 1, 928 }; 929 EXPORT_SYMBOL_NS(cht_chip_info, SND_SOC_SOF_BAYTRAIL); 930 931 #endif /* CONFIG_SND_SOC_SOF_BAYTRAIL */ 932 933 MODULE_LICENSE("Dual BSD/GPL"); 934 MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_HIFI_EP_IPC); 935 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA); 936