xref: /openbmc/linux/sound/soc/amd/acp/acp-sof-mach.c (revision e021ae7f)
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 const struct snd_kcontrol_new acp_controls[] = {
87 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
88 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
89 	SOC_DAPM_PIN_SWITCH("Spk"),
90 	SOC_DAPM_PIN_SWITCH("Left Spk"),
91 	SOC_DAPM_PIN_SWITCH("Right Spk"),
92 };
93 
94 static const struct snd_soc_dapm_widget acp_widgets[] = {
95 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
96 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
97 	SND_SOC_DAPM_SPK("Spk", NULL),
98 	SND_SOC_DAPM_SPK("Left Spk", NULL),
99 	SND_SOC_DAPM_SPK("Right Spk", NULL),
100 };
101 
102 static int acp_sof_probe(struct platform_device *pdev)
103 {
104 	struct snd_soc_card *card = NULL;
105 	struct device *dev = &pdev->dev;
106 	const struct dmi_system_id *dmi_id;
107 	struct acp_card_drvdata *acp_card_drvdata;
108 	int ret;
109 
110 	if (!pdev->id_entry)
111 		return -EINVAL;
112 
113 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
114 	if (!card)
115 		return -ENOMEM;
116 
117 	card->dev = dev;
118 	card->owner = THIS_MODULE;
119 	card->name = pdev->id_entry->name;
120 	card->dapm_widgets = acp_widgets;
121 	card->num_dapm_widgets = ARRAY_SIZE(acp_widgets);
122 	card->controls = acp_controls;
123 	card->num_controls = ARRAY_SIZE(acp_controls);
124 	card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
125 
126 	acp_card_drvdata = card->drvdata;
127 	dmi_id = dmi_first_match(acp_quirk_table);
128 	if (dmi_id && dmi_id->driver_data)
129 		acp_card_drvdata->tdm_mode = dmi_id->driver_data;
130 
131 	acp_sofdsp_dai_links_create(card);
132 
133 	ret = devm_snd_soc_register_card(&pdev->dev, card);
134 	if (ret) {
135 		dev_err(&pdev->dev,
136 				"devm_snd_soc_register_card(%s) failed: %d\n",
137 				card->name, ret);
138 		return ret;
139 	}
140 
141 	return 0;
142 }
143 
144 static const struct platform_device_id board_ids[] = {
145 	{
146 		.name = "rt5682-rt1019",
147 		.driver_data = (kernel_ulong_t)&sof_rt5682_rt1019_data
148 	},
149 	{
150 		.name = "rt5682-max",
151 		.driver_data = (kernel_ulong_t)&sof_rt5682_max_data
152 	},
153 	{
154 		.name = "rt5682s-max",
155 		.driver_data = (kernel_ulong_t)&sof_rt5682s_max_data
156 	},
157 	{
158 		.name = "rt5682s-rt1019",
159 		.driver_data = (kernel_ulong_t)&sof_rt5682s_rt1019_data
160 	},
161 	{
162 		.name = "nau8825-max",
163 		.driver_data = (kernel_ulong_t)&sof_nau8825_data
164 	},
165 	{
166 		.name = "rt5682s-hs-rt1019",
167 		.driver_data = (kernel_ulong_t)&sof_rt5682s_hs_rt1019_data
168 	},
169 	{ }
170 };
171 static struct platform_driver acp_asoc_audio = {
172 	.driver = {
173 		.name = "sof_mach",
174 		.pm = &snd_soc_pm_ops,
175 	},
176 	.probe = acp_sof_probe,
177 	.id_table = board_ids,
178 };
179 
180 module_platform_driver(acp_asoc_audio);
181 
182 MODULE_IMPORT_NS(SND_SOC_AMD_MACH);
183 MODULE_DESCRIPTION("ACP chrome SOF audio support");
184 MODULE_ALIAS("platform:rt5682-rt1019");
185 MODULE_ALIAS("platform:rt5682-max");
186 MODULE_ALIAS("platform:rt5682s-max");
187 MODULE_ALIAS("platform:rt5682s-rt1019");
188 MODULE_ALIAS("platform:nau8825-max");
189 MODULE_ALIAS("platform:rt5682s-hs-rt1019");
190 MODULE_LICENSE("GPL v2");
191