xref: /openbmc/linux/sound/soc/amd/acp/acp-sof-mach.c (revision d184cc91)
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 	.gpio_spkr_en = EN_SPKR_GPIO_GB,
31 };
32 
33 static struct acp_card_drvdata sof_rt5682_max_data = {
34 	.hs_cpu_id = I2S_SP,
35 	.amp_cpu_id = I2S_SP,
36 	.dmic_cpu_id = DMIC,
37 	.hs_codec_id = RT5682,
38 	.amp_codec_id = MAX98360A,
39 	.dmic_codec_id = DMIC,
40 	.gpio_spkr_en = EN_SPKR_GPIO_NK,
41 };
42 
43 static struct acp_card_drvdata sof_rt5682s_max_data = {
44 	.hs_cpu_id = I2S_SP,
45 	.amp_cpu_id = I2S_SP,
46 	.dmic_cpu_id = DMIC,
47 	.hs_codec_id = RT5682S,
48 	.amp_codec_id = MAX98360A,
49 	.dmic_codec_id = DMIC,
50 	.gpio_spkr_en = EN_SPKR_GPIO_NK,
51 };
52 
53 static const struct snd_kcontrol_new acp_controls[] = {
54 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
55 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
56 	SOC_DAPM_PIN_SWITCH("Spk"),
57 	SOC_DAPM_PIN_SWITCH("Left Spk"),
58 	SOC_DAPM_PIN_SWITCH("Right Spk"),
59 };
60 
61 static const struct snd_soc_dapm_widget acp_widgets[] = {
62 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
63 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
64 	SND_SOC_DAPM_SPK("Spk", event_spkr_handler),
65 	SND_SOC_DAPM_SPK("Left Spk", event_spkr_handler),
66 	SND_SOC_DAPM_SPK("Right Spk", event_spkr_handler),
67 };
68 
69 static int acp_sof_probe(struct platform_device *pdev)
70 {
71 	struct snd_soc_card *card = NULL;
72 	struct device *dev = &pdev->dev;
73 	unsigned int spkr_gpio;
74 	int ret;
75 
76 	if (!pdev->id_entry)
77 		return -EINVAL;
78 
79 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
80 	if (!card)
81 		return -ENOMEM;
82 
83 	card->dev = dev;
84 	card->owner = THIS_MODULE;
85 	card->name = pdev->id_entry->name;
86 	card->dapm_widgets = acp_widgets;
87 	card->num_dapm_widgets = ARRAY_SIZE(acp_widgets);
88 	card->controls = acp_controls;
89 	card->num_controls = ARRAY_SIZE(acp_controls);
90 	card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
91 	spkr_gpio = ((struct acp_card_drvdata *)(card->drvdata))->gpio_spkr_en;
92 
93 	acp_sofdsp_dai_links_create(card);
94 
95 	if (gpio_is_valid(spkr_gpio)) {
96 		ret = devm_gpio_request(dev, spkr_gpio, "spkren");
97 		if (ret) {
98 			dev_err(dev, "(%s) gpio request failed: %d\n",
99 				__func__, ret);
100 			return ret;
101 		}
102 		gpio_direction_output(spkr_gpio, 0);
103 	}
104 
105 	ret = devm_snd_soc_register_card(&pdev->dev, card);
106 	if (ret) {
107 		dev_err(&pdev->dev,
108 				"devm_snd_soc_register_card(%s) failed: %d\n",
109 				card->name, ret);
110 		return ret;
111 	}
112 
113 	return 0;
114 }
115 
116 static const struct platform_device_id board_ids[] = {
117 	{
118 		.name = "rt5682-rt1019",
119 		.driver_data = (kernel_ulong_t)&sof_rt5682_rt1019_data
120 	},
121 	{
122 		.name = "rt5682-max",
123 		.driver_data = (kernel_ulong_t)&sof_rt5682_max_data
124 	},
125 	{
126 		.name = "rt5682s-max",
127 		.driver_data = (kernel_ulong_t)&sof_rt5682s_max_data
128 	},
129 	{ }
130 };
131 static struct platform_driver acp_asoc_audio = {
132 	.driver = {
133 		.name = "sof_mach",
134 	},
135 	.probe = acp_sof_probe,
136 	.id_table = board_ids,
137 };
138 
139 module_platform_driver(acp_asoc_audio);
140 
141 MODULE_IMPORT_NS(SND_SOC_AMD_MACH);
142 MODULE_DESCRIPTION("ACP chrome SOF audio support");
143 MODULE_ALIAS("platform:rt5682-rt1019");
144 MODULE_ALIAS("platform:rt5682-max");
145 MODULE_ALIAS("platform:rt5682s-max");
146 MODULE_LICENSE("GPL v2");
147