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 .default_fw_path = "amd/sof", 58 .default_tplg_path = "amd/sof-tplg", 59 .default_fw_filename = "sof-rn.ri", 60 .nocodec_tplg_filename = "sof-acp.tplg", 61 .ops = &sof_renoir_ops, 62 }; 63 64 static int acp_pci_rn_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) 65 { 66 struct platform_device_info pdevinfo; 67 struct device *dev = &pci->dev; 68 const struct resource *res_i2s; 69 struct resource *res; 70 unsigned int flag, i, addr; 71 int ret; 72 73 flag = snd_amd_acp_find_config(pci); 74 if (flag != FLAG_AMD_SOF && flag != FLAG_AMD_SOF_ONLY_DMIC) 75 return -ENODEV; 76 77 ret = sof_pci_probe(pci, pci_id); 78 if (ret != 0) 79 return ret; 80 81 dmic_dev = platform_device_register_data(dev, "dmic-codec", PLATFORM_DEVID_NONE, NULL, 0); 82 if (IS_ERR(dmic_dev)) { 83 dev_err(dev, "failed to create DMIC device\n"); 84 sof_pci_remove(pci); 85 return PTR_ERR(dmic_dev); 86 } 87 88 /* Register platform device only if flag set to FLAG_AMD_SOF_ONLY_DMIC */ 89 if (flag != FLAG_AMD_SOF_ONLY_DMIC) 90 return 0; 91 92 addr = pci_resource_start(pci, 0); 93 res = devm_kzalloc(&pci->dev, sizeof(struct resource) * ARRAY_SIZE(renoir_res), GFP_KERNEL); 94 if (!res) { 95 sof_pci_remove(pci); 96 return -ENOMEM; 97 } 98 99 res_i2s = renoir_res; 100 for (i = 0; i < ARRAY_SIZE(renoir_res); i++, res_i2s++) { 101 res[i].name = res_i2s->name; 102 res[i].flags = res_i2s->flags; 103 res[i].start = addr + res_i2s->start; 104 res[i].end = addr + res_i2s->end; 105 if (res_i2s->flags == IORESOURCE_IRQ) { 106 res[i].start = pci->irq; 107 res[i].end = res[i].start; 108 } 109 } 110 111 memset(&pdevinfo, 0, sizeof(pdevinfo)); 112 113 /* 114 * We have common PCI driver probe for ACP device but we have to support I2S without SOF 115 * for some distributions. Register platform device that will be used to support non dsp 116 * ACP's audio ends points on some machines. 117 */ 118 119 pdevinfo.name = "acp_asoc_renoir"; 120 pdevinfo.id = 0; 121 pdevinfo.parent = &pci->dev; 122 pdevinfo.num_res = ARRAY_SIZE(renoir_res); 123 pdevinfo.res = &res[0]; 124 125 pdev = platform_device_register_full(&pdevinfo); 126 if (IS_ERR(pdev)) { 127 dev_err(&pci->dev, "cannot register %s device\n", pdevinfo.name); 128 sof_pci_remove(pci); 129 platform_device_unregister(dmic_dev); 130 ret = PTR_ERR(pdev); 131 } 132 133 return ret; 134 }; 135 136 static void acp_pci_rn_remove(struct pci_dev *pci) 137 { 138 if (dmic_dev) 139 platform_device_unregister(dmic_dev); 140 if (pdev) 141 platform_device_unregister(pdev); 142 143 return sof_pci_remove(pci); 144 } 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 154 /* pci_driver definition */ 155 static struct pci_driver snd_sof_pci_amd_rn_driver = { 156 .name = KBUILD_MODNAME, 157 .id_table = rn_pci_ids, 158 .probe = acp_pci_rn_probe, 159 .remove = acp_pci_rn_remove, 160 }; 161 module_pci_driver(snd_sof_pci_amd_rn_driver); 162 163 MODULE_LICENSE("Dual BSD/GPL"); 164 MODULE_IMPORT_NS(SND_SOC_SOF_AMD_COMMON); 165 MODULE_IMPORT_NS(SND_SOC_SOF_PCI_DEV); 166