Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: amd: acp: Refactor acp platform device creation

Refactor acp platform device creation logic and remove unused
acp resource (acp_res) structure.

Signed-off-by: Venkata Prasad Potturu <venkataprasad.potturu@amd.com>
Link: https://patch.msgid.link/20250310183201.11979-5-venkataprasad.potturu@amd.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Venkata Prasad Potturu and committed by
Mark Brown
a8b9d2d7 e2cda461

+63 -62
+59 -62
sound/soc/amd/acp/acp-pci.c
··· 26 26 #define ACP3x_REG_START 0x1240000 27 27 #define ACP3x_REG_END 0x125C000 28 28 29 - static struct platform_device *pdev; 30 - 31 - static const struct resource acp_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 int create_acp_platform_devs(struct pci_dev *pci, struct acp_chip_info *chip) 29 + static void acp_fill_platform_dev_info(struct platform_device_info *pdevinfo, 30 + struct device *parent, 31 + struct fwnode_handle *fw_node, 32 + char *name, unsigned int id, 33 + const struct resource *res, 34 + unsigned int num_res, 35 + const void *data, 36 + size_t size_data) 47 37 { 38 + pdevinfo->name = name; 39 + pdevinfo->id = id; 40 + pdevinfo->parent = parent; 41 + pdevinfo->num_res = num_res; 42 + pdevinfo->res = res; 43 + pdevinfo->data = data; 44 + pdevinfo->size_data = size_data; 45 + pdevinfo->fwnode = fw_node; 46 + } 47 + 48 + static int create_acp_platform_devs(struct pci_dev *pci, struct acp_chip_info *chip, u32 addr) 49 + { 50 + struct platform_device_info pdevinfo; 51 + struct device *parent; 48 52 int ret; 49 53 54 + parent = &pci->dev; 55 + 56 + if (chip->is_i2s_config || chip->is_pdm_dev) { 57 + chip->res = devm_kzalloc(&pci->dev, sizeof(struct resource), GFP_KERNEL); 58 + if (!chip->res) { 59 + ret = -ENOMEM; 60 + goto err; 61 + } 62 + chip->res->flags = IORESOURCE_MEM; 63 + chip->res->start = addr; 64 + chip->res->end = addr + (ACP3x_REG_END - ACP3x_REG_START); 65 + memset(&pdevinfo, 0, sizeof(pdevinfo)); 66 + } 67 + 68 + memset(&pdevinfo, 0, sizeof(pdevinfo)); 69 + acp_fill_platform_dev_info(&pdevinfo, parent, NULL, chip->name, 70 + 0, chip->res, 1, chip, sizeof(*chip)); 71 + 72 + chip->acp_plat_dev = platform_device_register_full(&pdevinfo); 73 + if (IS_ERR(chip->acp_plat_dev)) { 74 + dev_err(&pci->dev, 75 + "cannot register %s device\n", pdevinfo.name); 76 + ret = PTR_ERR(chip->acp_plat_dev); 77 + goto err; 78 + } 50 79 if (chip->is_pdm_dev && chip->is_pdm_config) { 51 80 chip->dmic_codec_dev = platform_device_register_data(&pci->dev, 52 81 "dmic-codec", ··· 84 55 if (IS_ERR(chip->dmic_codec_dev)) { 85 56 dev_err(&pci->dev, "failed to create DMIC device\n"); 86 57 ret = PTR_ERR(chip->dmic_codec_dev); 87 - goto err; 58 + goto unregister_acp_plat_dev; 88 59 } 89 60 } 90 61 return 0; 62 + unregister_acp_plat_dev: 63 + platform_device_unregister(chip->acp_plat_dev); 91 64 err: 92 65 return ret; 93 66 } 94 67 95 68 static int acp_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) 96 69 { 97 - struct platform_device_info pdevinfo; 98 70 struct device *dev = &pci->dev; 99 - const struct resource *res_acp; 100 71 struct acp_chip_info *chip; 101 - struct resource *res; 102 - unsigned int flag, addr, num_res, i; 72 + unsigned int flag, addr; 103 73 int ret; 104 74 105 75 flag = snd_amd_acp_find_config(pci); ··· 122 94 123 95 pci_set_master(pci); 124 96 125 - res_acp = acp_res; 126 - num_res = ARRAY_SIZE(acp_res); 127 97 chip->acp_rev = pci->revision; 128 98 switch (pci->revision) { 129 99 case 0x01: ··· 155 129 goto release_regions; 156 130 } 157 131 132 + chip->addr = addr; 133 + 158 134 chip->acp_hw_ops_init(chip); 159 135 ret = acp_hw_init(chip); 160 136 if (ret) ··· 166 138 if (!chip->is_pdm_dev && !chip->is_i2s_config) 167 139 goto skip_pdev_creation; 168 140 169 - ret = create_acp_platform_devs(pci, chip); 141 + ret = create_acp_platform_devs(pci, chip, addr); 170 142 if (ret < 0) { 171 143 dev_err(&pci->dev, "ACP platform devices creation failed\n"); 172 144 goto de_init; 173 145 } 174 146 175 - res = devm_kcalloc(&pci->dev, num_res, sizeof(struct resource), GFP_KERNEL); 176 - if (!res) { 177 - ret = -ENOMEM; 178 - goto de_init; 179 - } 180 - 181 - for (i = 0; i < num_res; i++, res_acp++) { 182 - res[i].name = res_acp->name; 183 - res[i].flags = res_acp->flags; 184 - res[i].start = addr + res_acp->start; 185 - res[i].end = addr + res_acp->end; 186 - if (res_acp->flags == IORESOURCE_IRQ) { 187 - res[i].start = pci->irq; 188 - res[i].end = res[i].start; 189 - } 190 - } 191 - 192 - memset(&pdevinfo, 0, sizeof(pdevinfo)); 193 - 194 - pdevinfo.name = chip->name; 195 - pdevinfo.id = 0; 196 - pdevinfo.parent = &pci->dev; 197 - pdevinfo.num_res = num_res; 198 - pdevinfo.res = &res[0]; 199 - pdevinfo.data = chip; 200 - pdevinfo.size_data = sizeof(*chip); 201 - 202 - pdev = platform_device_register_full(&pdevinfo); 203 - if (IS_ERR(pdev)) { 204 - dev_err(&pci->dev, "cannot register %s device\n", pdevinfo.name); 205 - ret = PTR_ERR(pdev); 206 - goto de_init; 207 - } 147 + chip->chip_pdev = chip->acp_plat_dev; 148 + chip->dev = &chip->acp_plat_dev->dev; 208 149 209 150 skip_pdev_creation: 210 - chip->chip_pdev = pdev; 211 151 dev_set_drvdata(&pci->dev, chip); 212 152 pm_runtime_set_autosuspend_delay(&pci->dev, 2000); 213 153 pm_runtime_use_autosuspend(&pci->dev); ··· 240 244 pm_runtime_get_noresume(&pci->dev); 241 245 if (chip->dmic_codec_dev) 242 246 platform_device_unregister(chip->dmic_codec_dev); 243 - if (pdev) 244 - platform_device_unregister(pdev); 247 + if (chip->acp_plat_dev) 248 + platform_device_unregister(chip->acp_plat_dev); 249 + 245 250 ret = acp_hw_deinit(chip); 246 251 if (ret) 247 252 dev_err(&pci->dev, "ACP de-init failed\n");
+4
sound/soc/amd/acp/amd.h
··· 140 140 141 141 struct acp_chip_info { 142 142 char *name; /* Platform name */ 143 + struct resource *res; 144 + struct device *dev; 143 145 unsigned int acp_rev; /* ACP Revision id */ 144 146 void __iomem *base; /* ACP memory PCI base */ 145 147 struct snd_acp_hw_ops *acp_hw_ops; 146 148 int (*acp_hw_ops_init)(struct acp_chip_info *chip); 147 149 struct platform_device *chip_pdev; 148 150 struct platform_device *dmic_codec_dev; 151 + struct platform_device *acp_plat_dev; 152 + u32 addr; 149 153 unsigned int flag; /* Distinguish b/w Legacy or Only PDM */ 150 154 bool is_pdm_dev; /* flag set to true when ACP PDM controller exists */ 151 155 bool is_pdm_config; /* flag set to true when PDM configuration is selected from BIOS */