xref: /openbmc/linux/sound/soc/amd/acp/acp-sof-mach.c (revision 7c8e4a25)
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 const struct snd_kcontrol_new acp_controls[] = {
60 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
61 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
62 	SOC_DAPM_PIN_SWITCH("Spk"),
63 	SOC_DAPM_PIN_SWITCH("Left Spk"),
64 	SOC_DAPM_PIN_SWITCH("Right Spk"),
65 };
66 
67 static const struct snd_soc_dapm_widget acp_widgets[] = {
68 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
69 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
70 	SND_SOC_DAPM_SPK("Spk", NULL),
71 	SND_SOC_DAPM_SPK("Left Spk", NULL),
72 	SND_SOC_DAPM_SPK("Right Spk", NULL),
73 };
74 
75 static int acp_sof_probe(struct platform_device *pdev)
76 {
77 	struct snd_soc_card *card = NULL;
78 	struct device *dev = &pdev->dev;
79 	int ret;
80 
81 	if (!pdev->id_entry)
82 		return -EINVAL;
83 
84 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
85 	if (!card)
86 		return -ENOMEM;
87 
88 	card->dev = dev;
89 	card->owner = THIS_MODULE;
90 	card->name = pdev->id_entry->name;
91 	card->dapm_widgets = acp_widgets;
92 	card->num_dapm_widgets = ARRAY_SIZE(acp_widgets);
93 	card->controls = acp_controls;
94 	card->num_controls = ARRAY_SIZE(acp_controls);
95 	card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
96 
97 	acp_sofdsp_dai_links_create(card);
98 
99 	ret = devm_snd_soc_register_card(&pdev->dev, card);
100 	if (ret) {
101 		dev_err(&pdev->dev,
102 				"devm_snd_soc_register_card(%s) failed: %d\n",
103 				card->name, ret);
104 		return ret;
105 	}
106 
107 	return 0;
108 }
109 
110 static const struct platform_device_id board_ids[] = {
111 	{
112 		.name = "rt5682-rt1019",
113 		.driver_data = (kernel_ulong_t)&sof_rt5682_rt1019_data
114 	},
115 	{
116 		.name = "rt5682-max",
117 		.driver_data = (kernel_ulong_t)&sof_rt5682_max_data
118 	},
119 	{
120 		.name = "rt5682s-max",
121 		.driver_data = (kernel_ulong_t)&sof_rt5682s_max_data
122 	},
123 	{
124 		.name = "rt5682s-rt1019",
125 		.driver_data = (kernel_ulong_t)&sof_rt5682s_rt1019_data
126 	},
127 	{ }
128 };
129 static struct platform_driver acp_asoc_audio = {
130 	.driver = {
131 		.name = "sof_mach",
132 		.pm = &snd_soc_pm_ops,
133 	},
134 	.probe = acp_sof_probe,
135 	.id_table = board_ids,
136 };
137 
138 module_platform_driver(acp_asoc_audio);
139 
140 MODULE_IMPORT_NS(SND_SOC_AMD_MACH);
141 MODULE_DESCRIPTION("ACP chrome SOF audio support");
142 MODULE_ALIAS("platform:rt5682-rt1019");
143 MODULE_ALIAS("platform:rt5682-max");
144 MODULE_ALIAS("platform:rt5682s-max");
145 MODULE_ALIAS("platform:rt5682s-rt1019");
146 MODULE_LICENSE("GPL v2");
147