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. 7 // 8 // Authors: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com> 9 // 10 11 /* 12 * Hardware interface for Renoir ACP block 13 */ 14 15 #include <linux/platform_device.h> 16 #include <linux/module.h> 17 #include <linux/err.h> 18 #include <linux/io.h> 19 #include <sound/pcm_params.h> 20 #include <sound/soc.h> 21 #include <sound/soc-dai.h> 22 #include <linux/dma-mapping.h> 23 24 #include "amd.h" 25 #include "acp-mach.h" 26 27 #define DRV_NAME "acp_asoc_renoir" 28 29 static struct acp_resource rsrc = { 30 .offset = 20, 31 .no_of_ctrls = 1, 32 .irqp_used = 0, 33 .irq_reg_offset = 0x1800, 34 .i2s_pin_cfg_offset = 0x1400, 35 .i2s_mode = 0x04, 36 .scratch_reg_offset = 0x12800, 37 .sram_pte_offset = 0x02052800, 38 }; 39 40 static struct snd_soc_acpi_codecs amp_rt1019 = { 41 .num_codecs = 1, 42 .codecs = {"10EC1019"} 43 }; 44 45 static struct snd_soc_acpi_codecs amp_max = { 46 .num_codecs = 1, 47 .codecs = {"MX98360A"} 48 }; 49 50 static struct snd_soc_acpi_mach snd_soc_acpi_amd_acp_machines[] = { 51 { 52 .id = "10EC5682", 53 .drv_name = "acp3xalc56821019", 54 .machine_quirk = snd_soc_acpi_codec_list, 55 .quirk_data = &_rt1019, 56 }, 57 { 58 .id = "RTL5682", 59 .drv_name = "acp3xalc5682sm98360", 60 .machine_quirk = snd_soc_acpi_codec_list, 61 .quirk_data = &_max, 62 }, 63 { 64 .id = "RTL5682", 65 .drv_name = "acp3xalc5682s1019", 66 .machine_quirk = snd_soc_acpi_codec_list, 67 .quirk_data = &_rt1019, 68 }, 69 { 70 .id = "AMDI1019", 71 .drv_name = "renoir-acp", 72 }, 73 { 74 .id = "ESSX8336", 75 .drv_name = "acp3x-es83xx", 76 }, 77 {}, 78 }; 79 80 static struct snd_soc_dai_driver acp_renoir_dai[] = { 81 { 82 .name = "acp-i2s-sp", 83 .id = I2S_SP_INSTANCE, 84 .playback = { 85 .stream_name = "I2S SP Playback", 86 .rates = SNDRV_PCM_RATE_8000_96000, 87 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | 88 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_LE, 89 .channels_min = 2, 90 .channels_max = 8, 91 .rate_min = 8000, 92 .rate_max = 96000, 93 }, 94 .capture = { 95 .stream_name = "I2S SP Capture", 96 .rates = SNDRV_PCM_RATE_8000_48000, 97 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | 98 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_LE, 99 .channels_min = 2, 100 .channels_max = 2, 101 .rate_min = 8000, 102 .rate_max = 48000, 103 }, 104 .ops = &asoc_acp_cpu_dai_ops, 105 }, 106 { 107 .name = "acp-i2s-bt", 108 .id = I2S_BT_INSTANCE, 109 .playback = { 110 .stream_name = "I2S BT Playback", 111 .rates = SNDRV_PCM_RATE_8000_96000, 112 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | 113 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_LE, 114 .channels_min = 2, 115 .channels_max = 8, 116 .rate_min = 8000, 117 .rate_max = 96000, 118 }, 119 .capture = { 120 .stream_name = "I2S BT Capture", 121 .rates = SNDRV_PCM_RATE_8000_48000, 122 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | 123 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S32_LE, 124 .channels_min = 2, 125 .channels_max = 2, 126 .rate_min = 8000, 127 .rate_max = 48000, 128 }, 129 .ops = &asoc_acp_cpu_dai_ops, 130 }, 131 { 132 .name = "acp-pdm-dmic", 133 .id = DMIC_INSTANCE, 134 .capture = { 135 .rates = SNDRV_PCM_RATE_8000_48000, 136 .formats = SNDRV_PCM_FMTBIT_S32_LE, 137 .channels_min = 2, 138 .channels_max = 2, 139 .rate_min = 8000, 140 .rate_max = 48000, 141 }, 142 .ops = &acp_dmic_dai_ops, 143 }, 144 }; 145 146 147 static int renoir_audio_probe(struct platform_device *pdev) 148 { 149 struct device *dev = &pdev->dev; 150 struct acp_chip_info *chip; 151 struct acp_dev_data *adata; 152 struct resource *res; 153 int ret; 154 155 chip = dev_get_platdata(&pdev->dev); 156 if (!chip || !chip->base) { 157 dev_err(&pdev->dev, "ACP chip data is NULL\n"); 158 return -ENODEV; 159 } 160 161 if (chip->acp_rev != ACP3X_DEV) { 162 dev_err(&pdev->dev, "Un-supported ACP Revision %d\n", chip->acp_rev); 163 return -ENODEV; 164 } 165 166 adata = devm_kzalloc(dev, sizeof(struct acp_dev_data), GFP_KERNEL); 167 if (!adata) 168 return -ENOMEM; 169 170 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "acp_mem"); 171 if (!res) { 172 dev_err(&pdev->dev, "IORESOURCE_MEM FAILED\n"); 173 return -ENODEV; 174 } 175 176 adata->acp_base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); 177 if (!adata->acp_base) 178 return -ENOMEM; 179 180 ret = platform_get_irq_byname(pdev, "acp_dai_irq"); 181 if (ret < 0) 182 return ret; 183 adata->i2s_irq = ret; 184 185 adata->dev = dev; 186 adata->dai_driver = acp_renoir_dai; 187 adata->num_dai = ARRAY_SIZE(acp_renoir_dai); 188 adata->rsrc = &rsrc; 189 adata->platform = RENOIR; 190 adata->flag = chip->flag; 191 192 adata->machines = snd_soc_acpi_amd_acp_machines; 193 acp_machine_select(adata); 194 195 dev_set_drvdata(dev, adata); 196 acp_enable_interrupts(adata); 197 acp_platform_register(dev); 198 199 return 0; 200 } 201 202 static void renoir_audio_remove(struct platform_device *pdev) 203 { 204 struct device *dev = &pdev->dev; 205 struct acp_dev_data *adata = dev_get_drvdata(dev); 206 207 acp_disable_interrupts(adata); 208 acp_platform_unregister(dev); 209 } 210 211 static struct platform_driver renoir_driver = { 212 .probe = renoir_audio_probe, 213 .remove_new = renoir_audio_remove, 214 .driver = { 215 .name = "acp_asoc_renoir", 216 }, 217 }; 218 219 module_platform_driver(renoir_driver); 220 221 MODULE_DESCRIPTION("AMD ACP Renoir Driver"); 222 MODULE_IMPORT_NS(SND_SOC_ACP_COMMON); 223 MODULE_LICENSE("Dual BSD/GPL"); 224 MODULE_ALIAS("platform:" DRV_NAME); 225