xref: /openbmc/linux/sound/soc/amd/acp/acp-sof-mach.c (revision 6c8c1406)
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/module.h>
20 
21 #include "acp-mach.h"
22 
23 static struct acp_card_drvdata sof_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 sof_rt5682_max_data = {
33 	.hs_cpu_id = I2S_SP,
34 	.amp_cpu_id = I2S_SP,
35 	.dmic_cpu_id = DMIC,
36 	.hs_codec_id = RT5682,
37 	.amp_codec_id = MAX98360A,
38 	.dmic_codec_id = DMIC,
39 };
40 
41 static struct acp_card_drvdata sof_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 sof_rt5682s_max_data = {
51 	.hs_cpu_id = I2S_SP,
52 	.amp_cpu_id = I2S_SP,
53 	.dmic_cpu_id = DMIC,
54 	.hs_codec_id = RT5682S,
55 	.amp_codec_id = MAX98360A,
56 	.dmic_codec_id = DMIC,
57 };
58 
59 static struct acp_card_drvdata sof_nau8825_data = {
60 	.hs_cpu_id = I2S_HS,
61 	.amp_cpu_id = I2S_HS,
62 	.dmic_cpu_id = DMIC,
63 	.hs_codec_id = NAU8825,
64 	.amp_codec_id = MAX98360A,
65 	.dmic_codec_id = DMIC,
66 	.soc_mclk = true,
67 };
68 
69 static struct acp_card_drvdata sof_rt5682s_hs_rt1019_data = {
70 	.hs_cpu_id = I2S_HS,
71 	.amp_cpu_id = I2S_HS,
72 	.dmic_cpu_id = DMIC,
73 	.hs_codec_id = RT5682S,
74 	.amp_codec_id = RT1019,
75 	.dmic_codec_id = DMIC,
76 	.soc_mclk = true,
77 };
78 
79 static const struct snd_kcontrol_new acp_controls[] = {
80 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
81 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
82 	SOC_DAPM_PIN_SWITCH("Spk"),
83 	SOC_DAPM_PIN_SWITCH("Left Spk"),
84 	SOC_DAPM_PIN_SWITCH("Right Spk"),
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_sof_probe(struct platform_device *pdev)
96 {
97 	struct snd_soc_card *card = NULL;
98 	struct device *dev = &pdev->dev;
99 	int ret;
100 
101 	if (!pdev->id_entry)
102 		return -EINVAL;
103 
104 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
105 	if (!card)
106 		return -ENOMEM;
107 
108 	card->dev = dev;
109 	card->owner = THIS_MODULE;
110 	card->name = pdev->id_entry->name;
111 	card->dapm_widgets = acp_widgets;
112 	card->num_dapm_widgets = ARRAY_SIZE(acp_widgets);
113 	card->controls = acp_controls;
114 	card->num_controls = ARRAY_SIZE(acp_controls);
115 	card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
116 
117 	acp_sofdsp_dai_links_create(card);
118 
119 	ret = devm_snd_soc_register_card(&pdev->dev, card);
120 	if (ret) {
121 		dev_err(&pdev->dev,
122 				"devm_snd_soc_register_card(%s) failed: %d\n",
123 				card->name, ret);
124 		return ret;
125 	}
126 
127 	return 0;
128 }
129 
130 static const struct platform_device_id board_ids[] = {
131 	{
132 		.name = "rt5682-rt1019",
133 		.driver_data = (kernel_ulong_t)&sof_rt5682_rt1019_data
134 	},
135 	{
136 		.name = "rt5682-max",
137 		.driver_data = (kernel_ulong_t)&sof_rt5682_max_data
138 	},
139 	{
140 		.name = "rt5682s-max",
141 		.driver_data = (kernel_ulong_t)&sof_rt5682s_max_data
142 	},
143 	{
144 		.name = "rt5682s-rt1019",
145 		.driver_data = (kernel_ulong_t)&sof_rt5682s_rt1019_data
146 	},
147 	{
148 		.name = "nau8825-max",
149 		.driver_data = (kernel_ulong_t)&sof_nau8825_data
150 	},
151 	{
152 		.name = "rt5682s-hs-rt1019",
153 		.driver_data = (kernel_ulong_t)&sof_rt5682s_hs_rt1019_data
154 	},
155 	{ }
156 };
157 static struct platform_driver acp_asoc_audio = {
158 	.driver = {
159 		.name = "sof_mach",
160 		.pm = &snd_soc_pm_ops,
161 	},
162 	.probe = acp_sof_probe,
163 	.id_table = board_ids,
164 };
165 
166 module_platform_driver(acp_asoc_audio);
167 
168 MODULE_IMPORT_NS(SND_SOC_AMD_MACH);
169 MODULE_DESCRIPTION("ACP chrome SOF audio support");
170 MODULE_ALIAS("platform:rt5682-rt1019");
171 MODULE_ALIAS("platform:rt5682-max");
172 MODULE_ALIAS("platform:rt5682s-max");
173 MODULE_ALIAS("platform:rt5682s-rt1019");
174 MODULE_ALIAS("platform:nau8825-max");
175 MODULE_ALIAS("platform:rt5682s-hs-rt1019");
176 MODULE_LICENSE("GPL v2");
177