xref: /linux/sound/soc/amd/acp/acp-sof-mach.c (revision 42b16d3ac371a2fac9b6f08fd75f23f34ba3955a)
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, 2023 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 };
32 
33 static struct acp_card_drvdata sof_rt5682_max_data = {
34 	.hs_cpu_id = I2S_SP,
35 	.amp_cpu_id = I2S_SP,
36 	.dmic_cpu_id = DMIC,
37 	.hs_codec_id = RT5682,
38 	.amp_codec_id = MAX98360A,
39 	.dmic_codec_id = DMIC,
40 };
41 
42 static struct acp_card_drvdata sof_rt5682s_rt1019_data = {
43 	.hs_cpu_id = I2S_SP,
44 	.amp_cpu_id = I2S_SP,
45 	.dmic_cpu_id = DMIC,
46 	.hs_codec_id = RT5682S,
47 	.amp_codec_id = RT1019,
48 	.dmic_codec_id = DMIC,
49 	.platform = RENOIR,
50 };
51 
52 static struct acp_card_drvdata sof_rt5682s_max_data = {
53 	.hs_cpu_id = I2S_SP,
54 	.amp_cpu_id = I2S_SP,
55 	.dmic_cpu_id = DMIC,
56 	.hs_codec_id = RT5682S,
57 	.amp_codec_id = MAX98360A,
58 	.dmic_codec_id = DMIC,
59 	.platform = RENOIR,
60 };
61 
62 static struct acp_card_drvdata sof_nau8825_data = {
63 	.hs_cpu_id = I2S_HS,
64 	.amp_cpu_id = I2S_HS,
65 	.dmic_cpu_id = DMIC,
66 	.hs_codec_id = NAU8825,
67 	.amp_codec_id = MAX98360A,
68 	.dmic_codec_id = DMIC,
69 	.platform = REMBRANDT,
70 	.soc_mclk = true,
71 };
72 
73 static struct acp_card_drvdata sof_rt5682s_hs_rt1019_data = {
74 	.hs_cpu_id = I2S_HS,
75 	.amp_cpu_id = I2S_HS,
76 	.dmic_cpu_id = DMIC,
77 	.hs_codec_id = RT5682S,
78 	.amp_codec_id = RT1019,
79 	.dmic_codec_id = DMIC,
80 	.platform = REMBRANDT,
81 	.soc_mclk = true,
82 };
83 
84 static struct acp_card_drvdata sof_nau8821_max98388_data = {
85 	.hs_cpu_id = I2S_SP,
86 	.amp_cpu_id = I2S_HS,
87 	.bt_cpu_id = I2S_BT,
88 	.hs_codec_id = NAU8821,
89 	.amp_codec_id = MAX98388,
90 	.soc_mclk = true,
91 };
92 
acp_sof_probe(struct platform_device * pdev)93 static int acp_sof_probe(struct platform_device *pdev)
94 {
95 	struct snd_soc_card *card = NULL;
96 	struct device *dev = &pdev->dev;
97 	const struct dmi_system_id *dmi_id;
98 	struct acp_card_drvdata *acp_card_drvdata;
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->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
112 	/* Widgets and controls added per-codec in acp-mach-common.c */
113 
114 	acp_card_drvdata = card->drvdata;
115 	dmi_id = dmi_first_match(acp_quirk_table);
116 	if (dmi_id && dmi_id->driver_data)
117 		acp_card_drvdata->tdm_mode = dmi_id->driver_data;
118 
119 	ret = acp_sofdsp_dai_links_create(card);
120 	if (ret)
121 		return dev_err_probe(&pdev->dev, ret, "Failed to create DAI links\n");
122 
123 	ret = devm_snd_soc_register_card(&pdev->dev, card);
124 	if (ret)
125 		return dev_err_probe(&pdev->dev, ret,
126 				     "Failed to register card(%s)\n", card->name);
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 		.name = "nau8821-max",
157 		.driver_data = (kernel_ulong_t)&sof_nau8821_max98388_data
158 	},
159 	{ }
160 };
161 MODULE_DEVICE_TABLE(platform, board_ids);
162 
163 static struct platform_driver acp_asoc_audio = {
164 	.driver = {
165 		.name = "sof_mach",
166 		.pm = &snd_soc_pm_ops,
167 	},
168 	.probe = acp_sof_probe,
169 	.id_table = board_ids,
170 };
171 
172 module_platform_driver(acp_asoc_audio);
173 
174 MODULE_IMPORT_NS(SND_SOC_AMD_MACH);
175 MODULE_DESCRIPTION("ACP SOF Machine Driver");
176 MODULE_LICENSE("GPL v2");
177