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 const struct snd_kcontrol_new acp_controls[] = {
51 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
52 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
53 	SOC_DAPM_PIN_SWITCH("Spk"),
54 	SOC_DAPM_PIN_SWITCH("Left Spk"),
55 	SOC_DAPM_PIN_SWITCH("Right Spk"),
56 
57 };
58 
59 static const struct snd_soc_dapm_widget acp_widgets[] = {
60 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
61 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
62 	SND_SOC_DAPM_SPK("Spk", NULL),
63 	SND_SOC_DAPM_SPK("Left Spk", NULL),
64 	SND_SOC_DAPM_SPK("Right Spk", NULL),
65 };
66 
67 static int acp_asoc_probe(struct platform_device *pdev)
68 {
69 	struct snd_soc_card *card = NULL;
70 	struct device *dev = &pdev->dev;
71 	int ret;
72 
73 	if (!pdev->id_entry)
74 		return -EINVAL;
75 
76 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
77 	if (!card)
78 		return -ENOMEM;
79 
80 	card->dev = dev;
81 	card->owner = THIS_MODULE;
82 	card->name = pdev->id_entry->name;
83 	card->dapm_widgets = acp_widgets;
84 	card->num_dapm_widgets = ARRAY_SIZE(acp_widgets);
85 	card->controls = acp_controls;
86 	card->num_controls = ARRAY_SIZE(acp_controls);
87 	card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
88 
89 	acp_legacy_dai_links_create(card);
90 
91 	ret = devm_snd_soc_register_card(&pdev->dev, card);
92 	if (ret) {
93 		dev_err(&pdev->dev,
94 				"devm_snd_soc_register_card(%s) failed: %d\n",
95 				card->name, ret);
96 		return ret;
97 	}
98 
99 	return 0;
100 }
101 
102 static const struct platform_device_id board_ids[] = {
103 	{
104 		.name = "acp3xalc56821019",
105 		.driver_data = (kernel_ulong_t)&rt5682_rt1019_data,
106 	},
107 	{
108 		.name = "acp3xalc5682sm98360",
109 		.driver_data = (kernel_ulong_t)&rt5682s_max_data,
110 	},
111 	{
112 		.name = "acp3xalc5682s1019",
113 		.driver_data = (kernel_ulong_t)&rt5682s_rt1019_data,
114 	},
115 	{ }
116 };
117 static struct platform_driver acp_asoc_audio = {
118 	.driver = {
119 		.pm = &snd_soc_pm_ops,
120 		.name = "acp_mach",
121 	},
122 	.probe = acp_asoc_probe,
123 	.id_table = board_ids,
124 };
125 
126 module_platform_driver(acp_asoc_audio);
127 
128 MODULE_IMPORT_NS(SND_SOC_AMD_MACH);
129 MODULE_DESCRIPTION("ACP chrome audio support");
130 MODULE_ALIAS("platform:acp3xalc56821019");
131 MODULE_ALIAS("platform:acp3xalc5682sm98360");
132 MODULE_ALIAS("platform:acp3xalc5682s1019");
133 MODULE_LICENSE("GPL v2");
134