xref: /linux/sound/soc/amd/acp/acp-legacy-mach.c (revision a4eb44a6435d6d8f9e642407a4a06f65eb90ca04)
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 	.gpio_spkr_en = EN_SPKR_GPIO_GB,
31 };
32 
33 static const struct snd_kcontrol_new acp_controls[] = {
34 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
35 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
36 	SOC_DAPM_PIN_SWITCH("Spk"),
37 	SOC_DAPM_PIN_SWITCH("Left Spk"),
38 	SOC_DAPM_PIN_SWITCH("Right Spk"),
39 
40 };
41 
42 static const struct snd_soc_dapm_widget acp_widgets[] = {
43 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
44 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
45 	SND_SOC_DAPM_SPK("Spk", event_spkr_handler),
46 	SND_SOC_DAPM_SPK("Left Spk", event_spkr_handler),
47 	SND_SOC_DAPM_SPK("Right Spk", event_spkr_handler),
48 };
49 
50 static int acp_asoc_probe(struct platform_device *pdev)
51 {
52 	struct snd_soc_card *card = NULL;
53 	struct device *dev = &pdev->dev;
54 	unsigned int spkr_gpio;
55 	int ret;
56 
57 	if (!pdev->id_entry)
58 		return -EINVAL;
59 
60 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
61 	if (!card)
62 		return -ENOMEM;
63 
64 	card->dev = dev;
65 	card->owner = THIS_MODULE;
66 	card->name = pdev->id_entry->name;
67 	card->dapm_widgets = acp_widgets;
68 	card->num_dapm_widgets = ARRAY_SIZE(acp_widgets);
69 	card->controls = acp_controls;
70 	card->num_controls = ARRAY_SIZE(acp_controls);
71 	card->drvdata = (struct acp_card_drvdata *)pdev->id_entry->driver_data;
72 	spkr_gpio = ((struct acp_card_drvdata *)(card->drvdata))->gpio_spkr_en;
73 
74 	acp_legacy_dai_links_create(card);
75 
76 	if (gpio_is_valid(spkr_gpio)) {
77 		ret = devm_gpio_request(dev, spkr_gpio, "spkren");
78 		if (ret) {
79 			dev_err(dev, "(%s) gpio request failed: %d\n",
80 				__func__, ret);
81 			return ret;
82 		}
83 		gpio_direction_output(spkr_gpio, 0);
84 	}
85 
86 	ret = devm_snd_soc_register_card(&pdev->dev, card);
87 	if (ret) {
88 		dev_err(&pdev->dev,
89 				"devm_snd_soc_register_card(%s) failed: %d\n",
90 				card->name, ret);
91 		return ret;
92 	}
93 
94 	return 0;
95 }
96 
97 static const struct platform_device_id board_ids[] = {
98 	{
99 		.name = "rn_rt5682_rt1019",
100 		.driver_data = (kernel_ulong_t)&rt5682_rt1019_data,
101 	},
102 	{ }
103 };
104 static struct platform_driver acp_asoc_audio = {
105 	.driver = {
106 		.name = "acp_mach",
107 	},
108 	.probe = acp_asoc_probe,
109 	.id_table = board_ids,
110 };
111 
112 module_platform_driver(acp_asoc_audio);
113 
114 MODULE_IMPORT_NS(SND_SOC_AMD_MACH);
115 MODULE_DESCRIPTION("ACP chrome audio support");
116 MODULE_ALIAS("platform:rn_rt5682_rt1019");
117 MODULE_LICENSE("GPL v2");
118