1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
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.
6 // Copyright(c) 2021 Advanced Micro Devices, Inc.
8 // Authors: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
12 * Machine Driver Legacy Support for ACP HW block
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>
23 #include "acp3x-es83xx/acp3x-es83xx.h"
25 static struct acp_card_drvdata rt5682_rt1019_data
= {
29 .hs_codec_id
= RT5682
,
30 .amp_codec_id
= RT1019
,
31 .dmic_codec_id
= DMIC
,
35 static struct acp_card_drvdata rt5682s_max_data
= {
39 .hs_codec_id
= RT5682S
,
40 .amp_codec_id
= MAX98360A
,
41 .dmic_codec_id
= DMIC
,
45 static struct acp_card_drvdata rt5682s_rt1019_data
= {
49 .hs_codec_id
= RT5682S
,
50 .amp_codec_id
= RT1019
,
51 .dmic_codec_id
= DMIC
,
55 static struct acp_card_drvdata es83xx_rn_data
= {
58 .hs_codec_id
= ES83XX
,
59 .dmic_codec_id
= DMIC
,
62 static struct acp_card_drvdata max_nau8825_data
= {
66 .hs_codec_id
= NAU8825
,
67 .amp_codec_id
= MAX98360A
,
68 .dmic_codec_id
= DMIC
,
73 static struct acp_card_drvdata rt5682s_rt1019_rmb_data
= {
77 .hs_codec_id
= RT5682S
,
78 .amp_codec_id
= RT1019
,
79 .dmic_codec_id
= DMIC
,
84 static struct acp_card_drvdata acp_dmic_data
= {
86 .dmic_codec_id
= DMIC
,
89 static bool acp_asoc_init_ops(struct acp_card_drvdata
*priv
)
93 if (priv
->hs_codec_id
== ES83XX
) {
95 acp3x_es83xx_init_ops(&priv
->ops
);
100 static int acp_asoc_suspend_pre(struct snd_soc_card
*card
)
104 ret
= acp_ops_suspend_pre(card
);
111 static int acp_asoc_resume_post(struct snd_soc_card
*card
)
115 ret
= acp_ops_resume_post(card
);
122 static int acp_asoc_probe(struct platform_device
*pdev
)
124 struct snd_soc_card
*card
= NULL
;
125 struct device
*dev
= &pdev
->dev
;
126 struct snd_soc_acpi_mach
*mach
= dev_get_platdata(&pdev
->dev
);
127 const struct dmi_system_id
*dmi_id
;
128 struct acp_card_drvdata
*acp_card_drvdata
;
131 if (!pdev
->id_entry
) {
136 card
= devm_kzalloc(dev
, sizeof(*card
), GFP_KERNEL
);
142 card
->drvdata
= (struct acp_card_drvdata
*)pdev
->id_entry
->driver_data
;
143 acp_card_drvdata
= card
->drvdata
;
144 acp_card_drvdata
->acpi_mach
= (struct snd_soc_acpi_mach
*)pdev
->dev
.platform_data
;
146 card
->owner
= THIS_MODULE
;
147 card
->name
= pdev
->id_entry
->name
;
149 acp_asoc_init_ops(card
->drvdata
);
151 /* If widgets and controls are not set in specific callback,
152 * they will be added per-codec in acp-mach-common.c
154 ret
= acp_ops_configure_widgets(card
);
157 "Cannot configure widgets for card (%s): %d\n",
161 card
->suspend_pre
= acp_asoc_suspend_pre
;
162 card
->resume_post
= acp_asoc_resume_post
;
164 ret
= acp_ops_probe(card
);
167 "Cannot probe card (%s): %d\n",
171 if (!strcmp(pdev
->name
, "acp-pdm-mach"))
172 acp_card_drvdata
->acp_rev
= *((int *)dev
->platform_data
);
174 acp_card_drvdata
->acp_rev
= mach
->mach_params
.subsystem_rev
;
176 dmi_id
= dmi_first_match(acp_quirk_table
);
177 if (dmi_id
&& dmi_id
->driver_data
)
178 acp_card_drvdata
->tdm_mode
= dmi_id
->driver_data
;
180 ret
= acp_legacy_dai_links_create(card
);
183 "Cannot create dai links for card (%s): %d\n",
188 ret
= devm_snd_soc_register_card(&pdev
->dev
, card
);
191 "devm_snd_soc_register_card(%s) failed: %d\n",
199 static const struct platform_device_id board_ids
[] = {
201 .name
= "acp3xalc56821019",
202 .driver_data
= (kernel_ulong_t
)&rt5682_rt1019_data
,
205 .name
= "acp3xalc5682sm98360",
206 .driver_data
= (kernel_ulong_t
)&rt5682s_max_data
,
209 .name
= "acp3xalc5682s1019",
210 .driver_data
= (kernel_ulong_t
)&rt5682s_rt1019_data
,
213 .name
= "acp3x-es83xx",
214 .driver_data
= (kernel_ulong_t
)&es83xx_rn_data
,
217 .name
= "rmb-nau8825-max",
218 .driver_data
= (kernel_ulong_t
)&max_nau8825_data
,
221 .name
= "rmb-rt5682s-rt1019",
222 .driver_data
= (kernel_ulong_t
)&rt5682s_rt1019_rmb_data
,
225 .name
= "acp-pdm-mach",
226 .driver_data
= (kernel_ulong_t
)&acp_dmic_data
,
230 MODULE_DEVICE_TABLE(platform
, board_ids
);
232 static struct platform_driver acp_asoc_audio
= {
234 .pm
= &snd_soc_pm_ops
,
237 .probe
= acp_asoc_probe
,
238 .id_table
= board_ids
,
241 module_platform_driver(acp_asoc_audio
);
243 MODULE_IMPORT_NS("SND_SOC_AMD_MACH");
244 MODULE_DESCRIPTION("ACP chrome audio support");
245 MODULE_LICENSE("GPL v2");