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