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 int acp_asoc_probe(struct platform_device *pdev)
79 {
80 	struct snd_soc_card *card = NULL;
81 	struct device *dev = &pdev->dev;
82 	const struct dmi_system_id *dmi_id;
83 	struct acp_card_drvdata *acp_card_drvdata;
84 	int ret;
85 
86 	if (!pdev->id_entry)
87 		return -EINVAL;
88 
89 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
90 	if (!card)
91 		return -ENOMEM;
92 
93 	card->dev = dev;
94 	card->owner = THIS_MODULE;
95 	card->name = pdev->id_entry->name;
96 	card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
97 	/* Widgets and controls added per-codec in acp-mach-common.c */
98 
99 	acp_card_drvdata = card->drvdata;
100 	dmi_id = dmi_first_match(acp_quirk_table);
101 	if (dmi_id && dmi_id->driver_data)
102 		acp_card_drvdata->tdm_mode = dmi_id->driver_data;
103 
104 	acp_legacy_dai_links_create(card);
105 
106 	ret = devm_snd_soc_register_card(&pdev->dev, card);
107 	if (ret) {
108 		dev_err(&pdev->dev,
109 				"devm_snd_soc_register_card(%s) failed: %d\n",
110 				card->name, ret);
111 		return ret;
112 	}
113 
114 	return 0;
115 }
116 
117 static const struct platform_device_id board_ids[] = {
118 	{
119 		.name = "acp3xalc56821019",
120 		.driver_data = (kernel_ulong_t)&rt5682_rt1019_data,
121 	},
122 	{
123 		.name = "acp3xalc5682sm98360",
124 		.driver_data = (kernel_ulong_t)&rt5682s_max_data,
125 	},
126 	{
127 		.name = "acp3xalc5682s1019",
128 		.driver_data = (kernel_ulong_t)&rt5682s_rt1019_data,
129 	},
130 	{
131 		.name = "rmb-nau8825-max",
132 		.driver_data = (kernel_ulong_t)&max_nau8825_data,
133 	},
134 	{
135 		.name = "rmb-rt5682s-rt1019",
136 		.driver_data = (kernel_ulong_t)&rt5682s_rt1019_rmb_data,
137 	},
138 	{ }
139 };
140 MODULE_DEVICE_TABLE(platform, board_ids);
141 
142 static struct platform_driver acp_asoc_audio = {
143 	.driver = {
144 		.pm = &snd_soc_pm_ops,
145 		.name = "acp_mach",
146 	},
147 	.probe = acp_asoc_probe,
148 	.id_table = board_ids,
149 };
150 
151 module_platform_driver(acp_asoc_audio);
152 
153 MODULE_IMPORT_NS(SND_SOC_AMD_MACH);
154 MODULE_DESCRIPTION("ACP chrome audio support");
155 MODULE_ALIAS("platform:acp3xalc56821019");
156 MODULE_ALIAS("platform:acp3xalc5682sm98360");
157 MODULE_ALIAS("platform:acp3xalc5682s1019");
158 MODULE_ALIAS("platform:rmb-nau8825-max");
159 MODULE_ALIAS("platform:rmb-rt5682s-rt1019");
160 MODULE_LICENSE("GPL v2");
161