pci-rn.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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) 2021 Advanced Micro Devices, Inc. All rights reserved.
  7. //
  8. // Authors: Ajit Kumar Pandey <[email protected]>
  9. /*
  10. * PCI interface for Renoir 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 ACP3x_REG_START 0x1240000
  23. #define ACP3x_REG_END 0x125C000
  24. static struct platform_device *dmic_dev;
  25. static struct platform_device *pdev;
  26. static const struct resource renoir_res[] = {
  27. {
  28. .start = 0,
  29. .end = ACP3x_REG_END - ACP3x_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 renoir_chip_info = {
  41. .rev = 3,
  42. .host_bridge_id = HOST_BRIDGE_CZN,
  43. .i2s_mode = 0x04,
  44. .pgfsm_base = ACP3X_PGFSM_BASE,
  45. .ext_intr_stat = ACP3X_EXT_INTR_STAT,
  46. .dsp_intr_base = ACP3X_DSP_SW_INTR_BASE,
  47. .sram_pte_offset = ACP3X_SRAM_PTE_OFFSET,
  48. .i2s_pin_config_offset = ACP3X_I2S_PIN_CONFIG,
  49. .hw_semaphore_offset = ACP3X_AXI2DAGB_SEM_0,
  50. .acp_clkmux_sel = ACP3X_CLKMUX_SEL,
  51. };
  52. static const struct sof_dev_desc renoir_desc = {
  53. .machines = snd_soc_acpi_amd_sof_machines,
  54. .use_acpi_target_states = true,
  55. .resindex_lpe_base = 0,
  56. .resindex_pcicfg_base = -1,
  57. .resindex_imr_base = -1,
  58. .irqindex_host_ipc = -1,
  59. .chip_info = &renoir_chip_info,
  60. .ipc_supported_mask = BIT(SOF_IPC),
  61. .ipc_default = SOF_IPC,
  62. .default_fw_path = {
  63. [SOF_IPC] = "amd/sof",
  64. },
  65. .default_tplg_path = {
  66. [SOF_IPC] = "amd/sof-tplg",
  67. },
  68. .default_fw_filename = {
  69. [SOF_IPC] = "sof-rn.ri",
  70. },
  71. .nocodec_tplg_filename = "sof-acp.tplg",
  72. .ops = &sof_renoir_ops,
  73. .ops_init = sof_renoir_ops_init,
  74. };
  75. static int acp_pci_rn_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
  76. {
  77. struct platform_device_info pdevinfo;
  78. struct device *dev = &pci->dev;
  79. const struct resource *res_i2s;
  80. struct resource *res;
  81. unsigned int flag, i, addr;
  82. int ret;
  83. if (pci->revision != ACP_RN_PCI_ID)
  84. return -ENODEV;
  85. flag = snd_amd_acp_find_config(pci);
  86. if (flag != FLAG_AMD_SOF && flag != FLAG_AMD_SOF_ONLY_DMIC)
  87. return -ENODEV;
  88. ret = sof_pci_probe(pci, pci_id);
  89. if (ret != 0)
  90. return ret;
  91. dmic_dev = platform_device_register_data(dev, "dmic-codec", PLATFORM_DEVID_NONE, NULL, 0);
  92. if (IS_ERR(dmic_dev)) {
  93. dev_err(dev, "failed to create DMIC device\n");
  94. sof_pci_remove(pci);
  95. return PTR_ERR(dmic_dev);
  96. }
  97. /* Register platform device only if flag set to FLAG_AMD_SOF_ONLY_DMIC */
  98. if (flag != FLAG_AMD_SOF_ONLY_DMIC)
  99. return 0;
  100. addr = pci_resource_start(pci, 0);
  101. res = devm_kzalloc(&pci->dev, sizeof(struct resource) * ARRAY_SIZE(renoir_res), GFP_KERNEL);
  102. if (!res) {
  103. sof_pci_remove(pci);
  104. platform_device_unregister(dmic_dev);
  105. return -ENOMEM;
  106. }
  107. res_i2s = renoir_res;
  108. for (i = 0; i < ARRAY_SIZE(renoir_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_renoir";
  125. pdevinfo.id = 0;
  126. pdevinfo.parent = &pci->dev;
  127. pdevinfo.num_res = ARRAY_SIZE(renoir_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. sof_pci_remove(pci);
  133. platform_device_unregister(dmic_dev);
  134. ret = PTR_ERR(pdev);
  135. }
  136. return ret;
  137. };
  138. static void acp_pci_rn_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. return sof_pci_remove(pci);
  145. }
  146. /* PCI IDs */
  147. static const struct pci_device_id rn_pci_ids[] = {
  148. { PCI_DEVICE(PCI_VENDOR_ID_AMD, ACP_PCI_DEV_ID),
  149. .driver_data = (unsigned long)&renoir_desc},
  150. { 0, }
  151. };
  152. MODULE_DEVICE_TABLE(pci, rn_pci_ids);
  153. /* pci_driver definition */
  154. static struct pci_driver snd_sof_pci_amd_rn_driver = {
  155. .name = KBUILD_MODNAME,
  156. .id_table = rn_pci_ids,
  157. .probe = acp_pci_rn_probe,
  158. .remove = acp_pci_rn_remove,
  159. .driver = {
  160. .pm = &sof_pci_pm,
  161. },
  162. };
  163. module_pci_driver(snd_sof_pci_amd_rn_driver);
  164. MODULE_LICENSE("Dual BSD/GPL");
  165. MODULE_IMPORT_NS(SND_SOC_SOF_AMD_COMMON);
  166. MODULE_IMPORT_NS(SND_SOC_SOF_PCI_DEV);