pci-rmb.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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) 2022 Advanced Micro Devices, Inc. All rights reserved.
  7. //
  8. // Authors: Ajit Kumar Pandey <[email protected]>
  9. /*.
  10. * PCI interface for Rembrandt ACP device
  11. */
  12. #include <linux/module.h>
  13. #include <linux/pci.h>
  14. #include <linux/platform_device.h>
  15. #include <sound/sof.h>
  16. #include <sound/soc-acpi.h>
  17. #include "../ops.h"
  18. #include "../sof-pci-dev.h"
  19. #include "../../amd/mach-config.h"
  20. #include "acp.h"
  21. #include "acp-dsp-offset.h"
  22. #define ACP6x_REG_START 0x1240000
  23. #define ACP6x_REG_END 0x125C000
  24. static struct platform_device *dmic_dev;
  25. static struct platform_device *pdev;
  26. static const struct resource rembrandt_res[] = {
  27. {
  28. .start = 0,
  29. .end = ACP6x_REG_END - ACP6x_REG_START,
  30. .name = "acp_mem",
  31. .flags = IORESOURCE_MEM,
  32. },
  33. {
  34. .start = 0,
  35. .end = 0,
  36. .name = "acp_dai_irq",
  37. .flags = IORESOURCE_IRQ,
  38. },
  39. };
  40. static const struct sof_amd_acp_desc rembrandt_chip_info = {
  41. .rev = 6,
  42. .host_bridge_id = HOST_BRIDGE_RMB,
  43. .i2s_mode = 0x0a,
  44. .pgfsm_base = ACP6X_PGFSM_BASE,
  45. .ext_intr_stat = ACP6X_EXT_INTR_STAT,
  46. .dsp_intr_base = ACP6X_DSP_SW_INTR_BASE,
  47. .sram_pte_offset = ACP6X_SRAM_PTE_OFFSET,
  48. .i2s_pin_config_offset = ACP6X_I2S_PIN_CONFIG,
  49. .hw_semaphore_offset = ACP6X_AXI2DAGB_SEM_0,
  50. .fusion_dsp_offset = ACP6X_DSP_FUSION_RUNSTALL,
  51. };
  52. static const struct sof_dev_desc rembrandt_desc = {
  53. .machines = snd_soc_acpi_amd_rmb_sof_machines,
  54. .resindex_lpe_base = 0,
  55. .resindex_pcicfg_base = -1,
  56. .resindex_imr_base = -1,
  57. .irqindex_host_ipc = -1,
  58. .chip_info = &rembrandt_chip_info,
  59. .ipc_supported_mask = BIT(SOF_IPC),
  60. .ipc_default = SOF_IPC,
  61. .default_fw_path = {
  62. [SOF_IPC] = "amd/sof",
  63. },
  64. .default_tplg_path = {
  65. [SOF_IPC] = "amd/sof-tplg",
  66. },
  67. .default_fw_filename = {
  68. [SOF_IPC] = "sof-rmb.ri",
  69. },
  70. .nocodec_tplg_filename = "sof-acp.tplg",
  71. .ops = &sof_rembrandt_ops,
  72. .ops_init = sof_rembrandt_ops_init,
  73. };
  74. static int acp_pci_rmb_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
  75. {
  76. struct platform_device_info pdevinfo;
  77. struct device *dev = &pci->dev;
  78. const struct resource *res_i2s;
  79. struct resource *res;
  80. unsigned int flag, i, addr;
  81. int ret;
  82. if (pci->revision != ACP_RMB_PCI_ID)
  83. return -ENODEV;
  84. flag = snd_amd_acp_find_config(pci);
  85. if (flag != FLAG_AMD_SOF && flag != FLAG_AMD_SOF_ONLY_DMIC)
  86. return -ENODEV;
  87. ret = sof_pci_probe(pci, pci_id);
  88. if (ret != 0)
  89. return ret;
  90. dmic_dev = platform_device_register_data(dev, "dmic-codec", PLATFORM_DEVID_NONE, NULL, 0);
  91. if (IS_ERR(dmic_dev)) {
  92. dev_err(dev, "failed to create DMIC device\n");
  93. sof_pci_remove(pci);
  94. return PTR_ERR(dmic_dev);
  95. }
  96. /* Register platform device only if flag set to FLAG_AMD_SOF_ONLY_DMIC */
  97. if (flag != FLAG_AMD_SOF_ONLY_DMIC)
  98. return 0;
  99. addr = pci_resource_start(pci, 0);
  100. res = devm_kzalloc(&pci->dev, sizeof(struct resource) * ARRAY_SIZE(rembrandt_res),
  101. GFP_KERNEL);
  102. if (!res) {
  103. platform_device_unregister(dmic_dev);
  104. sof_pci_remove(pci);
  105. return -ENOMEM;
  106. }
  107. res_i2s = rembrandt_res;
  108. for (i = 0; i < ARRAY_SIZE(rembrandt_res); i++, res_i2s++) {
  109. res[i].name = res_i2s->name;
  110. res[i].flags = res_i2s->flags;
  111. res[i].start = addr + res_i2s->start;
  112. res[i].end = addr + res_i2s->end;
  113. if (res_i2s->flags == IORESOURCE_IRQ) {
  114. res[i].start = pci->irq;
  115. res[i].end = res[i].start;
  116. }
  117. }
  118. memset(&pdevinfo, 0, sizeof(pdevinfo));
  119. /*
  120. * We have common PCI driver probe for ACP device but we have to support I2S without SOF
  121. * for some distributions. Register platform device that will be used to support non dsp
  122. * ACP's audio ends points on some machines.
  123. */
  124. pdevinfo.name = "acp_asoc_rembrandt";
  125. pdevinfo.id = 0;
  126. pdevinfo.parent = &pci->dev;
  127. pdevinfo.num_res = ARRAY_SIZE(rembrandt_res);
  128. pdevinfo.res = &res[0];
  129. pdev = platform_device_register_full(&pdevinfo);
  130. if (IS_ERR(pdev)) {
  131. dev_err(&pci->dev, "cannot register %s device\n", pdevinfo.name);
  132. platform_device_unregister(dmic_dev);
  133. sof_pci_remove(pci);
  134. ret = PTR_ERR(pdev);
  135. }
  136. return ret;
  137. };
  138. static void acp_pci_rmb_remove(struct pci_dev *pci)
  139. {
  140. if (dmic_dev)
  141. platform_device_unregister(dmic_dev);
  142. if (pdev)
  143. platform_device_unregister(pdev);
  144. sof_pci_remove(pci);
  145. }
  146. /* PCI IDs */
  147. static const struct pci_device_id rmb_pci_ids[] = {
  148. { PCI_DEVICE(PCI_VENDOR_ID_AMD, ACP_PCI_DEV_ID),
  149. .driver_data = (unsigned long)&rembrandt_desc},
  150. { 0, }
  151. };
  152. MODULE_DEVICE_TABLE(pci, rmb_pci_ids);
  153. /* pci_driver definition */
  154. static struct pci_driver snd_sof_pci_amd_rmb_driver = {
  155. .name = KBUILD_MODNAME,
  156. .id_table = rmb_pci_ids,
  157. .probe = acp_pci_rmb_probe,
  158. .remove = acp_pci_rmb_remove,
  159. };
  160. module_pci_driver(snd_sof_pci_amd_rmb_driver);
  161. MODULE_LICENSE("Dual BSD/GPL");
  162. MODULE_IMPORT_NS(SND_SOC_SOF_AMD_COMMON);
  163. MODULE_IMPORT_NS(SND_SOC_SOF_PCI_DEV);