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 * SOF Machine Driver Support for ACP HW block 13 */ 14 15 #include <sound/core.h> 16 #include <sound/pcm_params.h> 17 #include <sound/soc-acpi.h> 18 #include <sound/soc-dapm.h> 19 #include <linux/dmi.h> 20 #include <linux/module.h> 21 22 #include "acp-mach.h" 23 24 static struct acp_card_drvdata sof_rt5682_rt1019_data = { 25 .hs_cpu_id = I2S_SP, 26 .amp_cpu_id = I2S_SP, 27 .dmic_cpu_id = DMIC, 28 .hs_codec_id = RT5682, 29 .amp_codec_id = RT1019, 30 .dmic_codec_id = DMIC, 31 .tdm_mode = false, 32 }; 33 34 static struct acp_card_drvdata sof_rt5682_max_data = { 35 .hs_cpu_id = I2S_SP, 36 .amp_cpu_id = I2S_SP, 37 .dmic_cpu_id = DMIC, 38 .hs_codec_id = RT5682, 39 .amp_codec_id = MAX98360A, 40 .dmic_codec_id = DMIC, 41 .tdm_mode = false, 42 }; 43 44 static struct acp_card_drvdata sof_rt5682s_rt1019_data = { 45 .hs_cpu_id = I2S_SP, 46 .amp_cpu_id = I2S_SP, 47 .dmic_cpu_id = DMIC, 48 .hs_codec_id = RT5682S, 49 .amp_codec_id = RT1019, 50 .dmic_codec_id = DMIC, 51 .tdm_mode = false, 52 }; 53 54 static struct acp_card_drvdata sof_rt5682s_max_data = { 55 .hs_cpu_id = I2S_SP, 56 .amp_cpu_id = I2S_SP, 57 .dmic_cpu_id = DMIC, 58 .hs_codec_id = RT5682S, 59 .amp_codec_id = MAX98360A, 60 .dmic_codec_id = DMIC, 61 .tdm_mode = false, 62 }; 63 64 static struct acp_card_drvdata sof_nau8825_data = { 65 .hs_cpu_id = I2S_HS, 66 .amp_cpu_id = I2S_HS, 67 .dmic_cpu_id = DMIC, 68 .hs_codec_id = NAU8825, 69 .amp_codec_id = MAX98360A, 70 .dmic_codec_id = DMIC, 71 .soc_mclk = true, 72 .tdm_mode = false, 73 }; 74 75 static struct acp_card_drvdata sof_rt5682s_hs_rt1019_data = { 76 .hs_cpu_id = I2S_HS, 77 .amp_cpu_id = I2S_HS, 78 .dmic_cpu_id = DMIC, 79 .hs_codec_id = RT5682S, 80 .amp_codec_id = RT1019, 81 .dmic_codec_id = DMIC, 82 .soc_mclk = true, 83 .tdm_mode = false, 84 }; 85 86 static struct acp_card_drvdata sof_nau8821_max98388_data = { 87 .hs_cpu_id = I2S_SP, 88 .amp_cpu_id = I2S_HS, 89 .dmic_cpu_id = NONE, 90 .hs_codec_id = NAU8821, 91 .amp_codec_id = MAX98388, 92 .dmic_codec_id = NONE, 93 .soc_mclk = true, 94 .tdm_mode = false, 95 }; 96 97 static int acp_sof_probe(struct platform_device *pdev) 98 { 99 struct snd_soc_card *card = NULL; 100 struct device *dev = &pdev->dev; 101 const struct dmi_system_id *dmi_id; 102 struct acp_card_drvdata *acp_card_drvdata; 103 int ret; 104 105 if (!pdev->id_entry) 106 return -EINVAL; 107 108 card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); 109 if (!card) 110 return -ENOMEM; 111 112 card->dev = dev; 113 card->owner = THIS_MODULE; 114 card->name = pdev->id_entry->name; 115 card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data; 116 /* Widgets and controls added per-codec in acp-mach-common.c */ 117 118 acp_card_drvdata = card->drvdata; 119 dmi_id = dmi_first_match(acp_quirk_table); 120 if (dmi_id && dmi_id->driver_data) 121 acp_card_drvdata->tdm_mode = dmi_id->driver_data; 122 123 ret = acp_sofdsp_dai_links_create(card); 124 if (ret) 125 return dev_err_probe(&pdev->dev, ret, "Failed to create DAI links\n"); 126 127 ret = devm_snd_soc_register_card(&pdev->dev, card); 128 if (ret) 129 return dev_err_probe(&pdev->dev, ret, 130 "Failed to register card(%s)\n", card->name); 131 return 0; 132 } 133 134 static const struct platform_device_id board_ids[] = { 135 { 136 .name = "rt5682-rt1019", 137 .driver_data = (kernel_ulong_t)&sof_rt5682_rt1019_data 138 }, 139 { 140 .name = "rt5682-max", 141 .driver_data = (kernel_ulong_t)&sof_rt5682_max_data 142 }, 143 { 144 .name = "rt5682s-max", 145 .driver_data = (kernel_ulong_t)&sof_rt5682s_max_data 146 }, 147 { 148 .name = "rt5682s-rt1019", 149 .driver_data = (kernel_ulong_t)&sof_rt5682s_rt1019_data 150 }, 151 { 152 .name = "nau8825-max", 153 .driver_data = (kernel_ulong_t)&sof_nau8825_data 154 }, 155 { 156 .name = "rt5682s-hs-rt1019", 157 .driver_data = (kernel_ulong_t)&sof_rt5682s_hs_rt1019_data 158 }, 159 { 160 .name = "nau8821-max", 161 .driver_data = (kernel_ulong_t)&sof_nau8821_max98388_data 162 }, 163 { } 164 }; 165 static struct platform_driver acp_asoc_audio = { 166 .driver = { 167 .name = "sof_mach", 168 .pm = &snd_soc_pm_ops, 169 }, 170 .probe = acp_sof_probe, 171 .id_table = board_ids, 172 }; 173 174 module_platform_driver(acp_asoc_audio); 175 176 MODULE_IMPORT_NS(SND_SOC_AMD_MACH); 177 MODULE_DESCRIPTION("ACP chrome SOF audio support"); 178 MODULE_ALIAS("platform:rt5682-rt1019"); 179 MODULE_ALIAS("platform:rt5682-max"); 180 MODULE_ALIAS("platform:rt5682s-max"); 181 MODULE_ALIAS("platform:rt5682s-rt1019"); 182 MODULE_ALIAS("platform:nau8825-max"); 183 MODULE_ALIAS("platform:rt5682s-hs-rt1019"); 184 MODULE_ALIAS("platform:nau8821-max"); 185 MODULE_LICENSE("GPL v2"); 186