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 = NONE,
27 	.hs_codec_id = RT5682,
28 	.amp_codec_id = RT1019,
29 	.dmic_codec_id = NONE,
30 };
31 
32 static const struct snd_kcontrol_new acp_controls[] = {
33 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
34 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
35 	SOC_DAPM_PIN_SWITCH("Spk"),
36 	SOC_DAPM_PIN_SWITCH("Left Spk"),
37 	SOC_DAPM_PIN_SWITCH("Right Spk"),
38 
39 };
40 
41 static const struct snd_soc_dapm_widget acp_widgets[] = {
42 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
43 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
44 	SND_SOC_DAPM_SPK("Spk", NULL),
45 	SND_SOC_DAPM_SPK("Left Spk", NULL),
46 	SND_SOC_DAPM_SPK("Right Spk", NULL),
47 };
48 
49 static int acp_asoc_probe(struct platform_device *pdev)
50 {
51 	struct snd_soc_card *card = NULL;
52 	struct device *dev = &pdev->dev;
53 	int ret;
54 
55 	if (!pdev->id_entry)
56 		return -EINVAL;
57 
58 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
59 	if (!card)
60 		return -ENOMEM;
61 
62 	card->dev = dev;
63 	card->owner = THIS_MODULE;
64 	card->name = pdev->id_entry->name;
65 	card->dapm_widgets = acp_widgets;
66 	card->num_dapm_widgets = ARRAY_SIZE(acp_widgets);
67 	card->controls = acp_controls;
68 	card->num_controls = ARRAY_SIZE(acp_controls);
69 	card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
70 
71 	acp_legacy_dai_links_create(card);
72 
73 	ret = devm_snd_soc_register_card(&pdev->dev, card);
74 	if (ret) {
75 		dev_err(&pdev->dev,
76 				"devm_snd_soc_register_card(%s) failed: %d\n",
77 				card->name, ret);
78 		return ret;
79 	}
80 
81 	return 0;
82 }
83 
84 static const struct platform_device_id board_ids[] = {
85 	{
86 		.name = "rn_rt5682_rt1019",
87 		.driver_data = (kernel_ulong_t)&rt5682_rt1019_data,
88 	},
89 	{ }
90 };
91 static struct platform_driver acp_asoc_audio = {
92 	.driver = {
93 		.name = "acp_mach",
94 	},
95 	.probe = acp_asoc_probe,
96 	.id_table = board_ids,
97 };
98 
99 module_platform_driver(acp_asoc_audio);
100 
101 MODULE_IMPORT_NS(SND_SOC_AMD_MACH);
102 MODULE_DESCRIPTION("ACP chrome audio support");
103 MODULE_ALIAS("platform:rn_rt5682_rt1019");
104 MODULE_LICENSE("GPL v2");
105