xref: /openbmc/linux/sound/soc/amd/acp/acp-sof-mach.c (revision 6db6b729)
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 	acp_sofdsp_dai_links_create(card);
124 
125 	ret = devm_snd_soc_register_card(&pdev->dev, card);
126 	if (ret) {
127 		dev_err(&pdev->dev,
128 				"devm_snd_soc_register_card(%s) failed: %d\n",
129 				card->name, ret);
130 		return ret;
131 	}
132 
133 	return 0;
134 }
135 
136 static const struct platform_device_id board_ids[] = {
137 	{
138 		.name = "rt5682-rt1019",
139 		.driver_data = (kernel_ulong_t)&sof_rt5682_rt1019_data
140 	},
141 	{
142 		.name = "rt5682-max",
143 		.driver_data = (kernel_ulong_t)&sof_rt5682_max_data
144 	},
145 	{
146 		.name = "rt5682s-max",
147 		.driver_data = (kernel_ulong_t)&sof_rt5682s_max_data
148 	},
149 	{
150 		.name = "rt5682s-rt1019",
151 		.driver_data = (kernel_ulong_t)&sof_rt5682s_rt1019_data
152 	},
153 	{
154 		.name = "nau8825-max",
155 		.driver_data = (kernel_ulong_t)&sof_nau8825_data
156 	},
157 	{
158 		.name = "rt5682s-hs-rt1019",
159 		.driver_data = (kernel_ulong_t)&sof_rt5682s_hs_rt1019_data
160 	},
161 	{
162 		.name = "nau8821-max",
163 		.driver_data = (kernel_ulong_t)&sof_nau8821_max98388_data
164 	},
165 	{ }
166 };
167 static struct platform_driver acp_asoc_audio = {
168 	.driver = {
169 		.name = "sof_mach",
170 		.pm = &snd_soc_pm_ops,
171 	},
172 	.probe = acp_sof_probe,
173 	.id_table = board_ids,
174 };
175 
176 module_platform_driver(acp_asoc_audio);
177 
178 MODULE_IMPORT_NS(SND_SOC_AMD_MACH);
179 MODULE_DESCRIPTION("ACP chrome SOF audio support");
180 MODULE_ALIAS("platform:rt5682-rt1019");
181 MODULE_ALIAS("platform:rt5682-max");
182 MODULE_ALIAS("platform:rt5682s-max");
183 MODULE_ALIAS("platform:rt5682s-rt1019");
184 MODULE_ALIAS("platform:nau8825-max");
185 MODULE_ALIAS("platform:rt5682s-hs-rt1019");
186 MODULE_ALIAS("platform:nau8821-max");
187 MODULE_LICENSE("GPL v2");
188