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