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  * Machine Driver Legacy 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 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 rt5682s_max_data = {
35 	.hs_cpu_id = I2S_SP,
36 	.amp_cpu_id = I2S_SP,
37 	.dmic_cpu_id = DMIC,
38 	.hs_codec_id = RT5682S,
39 	.amp_codec_id = MAX98360A,
40 	.dmic_codec_id = DMIC,
41 	.tdm_mode = false,
42 };
43 
44 static struct acp_card_drvdata 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 max_nau8825_data = {
55 	.hs_cpu_id = I2S_HS,
56 	.amp_cpu_id = I2S_HS,
57 	.dmic_cpu_id = DMIC,
58 	.hs_codec_id = NAU8825,
59 	.amp_codec_id = MAX98360A,
60 	.dmic_codec_id = DMIC,
61 	.soc_mclk = true,
62 	.platform = REMBRANDT,
63 	.tdm_mode = false,
64 };
65 
66 static struct acp_card_drvdata rt5682s_rt1019_rmb_data = {
67 	.hs_cpu_id = I2S_HS,
68 	.amp_cpu_id = I2S_HS,
69 	.dmic_cpu_id = DMIC,
70 	.hs_codec_id = RT5682S,
71 	.amp_codec_id = RT1019,
72 	.dmic_codec_id = DMIC,
73 	.soc_mclk = true,
74 	.platform = REMBRANDT,
75 	.tdm_mode = false,
76 };
77 
78 static const struct snd_kcontrol_new acp_controls[] = {
79 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
80 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
81 	SOC_DAPM_PIN_SWITCH("Spk"),
82 	SOC_DAPM_PIN_SWITCH("Left Spk"),
83 	SOC_DAPM_PIN_SWITCH("Right Spk"),
84 
85 };
86 
87 static const struct snd_soc_dapm_widget acp_widgets[] = {
88 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
89 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
90 	SND_SOC_DAPM_SPK("Spk", NULL),
91 	SND_SOC_DAPM_SPK("Left Spk", NULL),
92 	SND_SOC_DAPM_SPK("Right Spk", NULL),
93 };
94 
95 static int acp_asoc_probe(struct platform_device *pdev)
96 {
97 	struct snd_soc_card *card = NULL;
98 	struct device *dev = &pdev->dev;
99 	const struct dmi_system_id *dmi_id;
100 	struct acp_card_drvdata *acp_card_drvdata;
101 	int ret;
102 
103 	if (!pdev->id_entry)
104 		return -EINVAL;
105 
106 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
107 	if (!card)
108 		return -ENOMEM;
109 
110 	card->dev = dev;
111 	card->owner = THIS_MODULE;
112 	card->name = pdev->id_entry->name;
113 	card->dapm_widgets = acp_widgets;
114 	card->num_dapm_widgets = ARRAY_SIZE(acp_widgets);
115 	card->controls = acp_controls;
116 	card->num_controls = ARRAY_SIZE(acp_controls);
117 	card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
118 
119 	acp_card_drvdata = card->drvdata;
120 	dmi_id = dmi_first_match(acp_quirk_table);
121 	if (dmi_id && dmi_id->driver_data)
122 		acp_card_drvdata->tdm_mode = dmi_id->driver_data;
123 
124 	acp_legacy_dai_links_create(card);
125 
126 	ret = devm_snd_soc_register_card(&pdev->dev, card);
127 	if (ret) {
128 		dev_err(&pdev->dev,
129 				"devm_snd_soc_register_card(%s) failed: %d\n",
130 				card->name, ret);
131 		return ret;
132 	}
133 
134 	return 0;
135 }
136 
137 static const struct platform_device_id board_ids[] = {
138 	{
139 		.name = "acp3xalc56821019",
140 		.driver_data = (kernel_ulong_t)&rt5682_rt1019_data,
141 	},
142 	{
143 		.name = "acp3xalc5682sm98360",
144 		.driver_data = (kernel_ulong_t)&rt5682s_max_data,
145 	},
146 	{
147 		.name = "acp3xalc5682s1019",
148 		.driver_data = (kernel_ulong_t)&rt5682s_rt1019_data,
149 	},
150 	{
151 		.name = "rmb-nau8825-max",
152 		.driver_data = (kernel_ulong_t)&max_nau8825_data,
153 	},
154 	{
155 		.name = "rmb-rt5682s-rt1019",
156 		.driver_data = (kernel_ulong_t)&rt5682s_rt1019_rmb_data,
157 	},
158 	{ }
159 };
160 static struct platform_driver acp_asoc_audio = {
161 	.driver = {
162 		.pm = &snd_soc_pm_ops,
163 		.name = "acp_mach",
164 	},
165 	.probe = acp_asoc_probe,
166 	.id_table = board_ids,
167 };
168 
169 module_platform_driver(acp_asoc_audio);
170 
171 MODULE_IMPORT_NS(SND_SOC_AMD_MACH);
172 MODULE_DESCRIPTION("ACP chrome audio support");
173 MODULE_ALIAS("platform:acp3xalc56821019");
174 MODULE_ALIAS("platform:acp3xalc5682sm98360");
175 MODULE_ALIAS("platform:acp3xalc5682s1019");
176 MODULE_ALIAS("platform:rmb-nau8825-max");
177 MODULE_ALIAS("platform:rmb-rt5682s-rt1019");
178 MODULE_LICENSE("GPL v2");
179