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 <AjitKumar.Pandey@amd.com> 9 10 /* 11 * PCI interface for Renoir ACP device 12 */ 13 14 #include <linux/module.h> 15 #include <linux/pci.h> 16 #include <linux/platform_device.h> 17 #include <sound/sof.h> 18 #include <sound/soc-acpi.h> 19 20 #include "../ops.h" 21 #include "../sof-pci-dev.h" 22 #include "../../amd/mach-config.h" 23 #include "acp.h" 24 25 #define ACP3x_REG_START 0x1240000 26 #define ACP3x_REG_END 0x125C000 27 28 static struct platform_device *dmic_dev; 29 static struct platform_device *pdev; 30 31 static const struct resource renoir_res[] = { 32 { 33 .start = 0, 34 .end = ACP3x_REG_END - ACP3x_REG_START, 35 .name = "acp_mem", 36 .flags = IORESOURCE_MEM, 37 }, 38 { 39 .start = 0, 40 .end = 0, 41 .name = "acp_dai_irq", 42 .flags = IORESOURCE_IRQ, 43 }, 44 }; 45 46 static const struct sof_amd_acp_desc renoir_chip_info = { 47 .host_bridge_id = HOST_BRIDGE_CZN, 48 }; 49 50 static const struct sof_dev_desc renoir_desc = { 51 .machines = snd_soc_acpi_amd_sof_machines, 52 .resindex_lpe_base = 0, 53 .resindex_pcicfg_base = -1, 54 .resindex_imr_base = -1, 55 .irqindex_host_ipc = -1, 56 .chip_info = &renoir_chip_info, 57 .ipc_supported_mask = BIT(SOF_IPC), 58 .ipc_default = SOF_IPC, 59 .default_fw_path = { 60 [SOF_IPC] = "amd/sof", 61 }, 62 .default_tplg_path = { 63 [SOF_IPC] = "amd/sof-tplg", 64 }, 65 .default_fw_filename = { 66 [SOF_IPC] = "sof-rn.ri", 67 }, 68 .nocodec_tplg_filename = "sof-acp.tplg", 69 .ops = &sof_renoir_ops, 70 }; 71 72 static int acp_pci_rn_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) 73 { 74 struct platform_device_info pdevinfo; 75 struct device *dev = &pci->dev; 76 const struct resource *res_i2s; 77 struct resource *res; 78 unsigned int flag, i, addr; 79 int ret; 80 81 flag = snd_amd_acp_find_config(pci); 82 if (flag != FLAG_AMD_SOF && flag != FLAG_AMD_SOF_ONLY_DMIC) 83 return -ENODEV; 84 85 ret = sof_pci_probe(pci, pci_id); 86 if (ret != 0) 87 return ret; 88 89 dmic_dev = platform_device_register_data(dev, "dmic-codec", PLATFORM_DEVID_NONE, NULL, 0); 90 if (IS_ERR(dmic_dev)) { 91 dev_err(dev, "failed to create DMIC device\n"); 92 sof_pci_remove(pci); 93 return PTR_ERR(dmic_dev); 94 } 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 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 return -ENOMEM; 105 } 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 119 memset(&pdevinfo, 0, sizeof(pdevinfo)); 120 121 /* 122 * We have common PCI driver probe for ACP device but we have to support I2S without SOF 123 * for some distributions. Register platform device that will be used to support non dsp 124 * ACP's audio ends points on some machines. 125 */ 126 127 pdevinfo.name = "acp_asoc_renoir"; 128 pdevinfo.id = 0; 129 pdevinfo.parent = &pci->dev; 130 pdevinfo.num_res = ARRAY_SIZE(renoir_res); 131 pdevinfo.res = &res[0]; 132 133 pdev = platform_device_register_full(&pdevinfo); 134 if (IS_ERR(pdev)) { 135 dev_err(&pci->dev, "cannot register %s device\n", pdevinfo.name); 136 sof_pci_remove(pci); 137 platform_device_unregister(dmic_dev); 138 ret = PTR_ERR(pdev); 139 } 140 141 return ret; 142 }; 143 144 static void acp_pci_rn_remove(struct pci_dev *pci) 145 { 146 if (dmic_dev) 147 platform_device_unregister(dmic_dev); 148 if (pdev) 149 platform_device_unregister(pdev); 150 151 return sof_pci_remove(pci); 152 } 153 154 /* PCI IDs */ 155 static const struct pci_device_id rn_pci_ids[] = { 156 { PCI_DEVICE(PCI_VENDOR_ID_AMD, ACP_PCI_DEV_ID), 157 .driver_data = (unsigned long)&renoir_desc}, 158 { 0, } 159 }; 160 MODULE_DEVICE_TABLE(pci, rn_pci_ids); 161 162 /* pci_driver definition */ 163 static struct pci_driver snd_sof_pci_amd_rn_driver = { 164 .name = KBUILD_MODNAME, 165 .id_table = rn_pci_ids, 166 .probe = acp_pci_rn_probe, 167 .remove = acp_pci_rn_remove, 168 }; 169 module_pci_driver(snd_sof_pci_amd_rn_driver); 170 171 MODULE_LICENSE("Dual BSD/GPL"); 172 MODULE_IMPORT_NS(SND_SOC_SOF_AMD_COMMON); 173 MODULE_IMPORT_NS(SND_SOC_SOF_PCI_DEV); 174