xref: /linux/sound/soc/amd/acp3x-rt5682-max9836.c (revision 9c04b5a48fca1facff07f28ba6d87de900238beb)
16b8e4e7dSAkshu Agrawal // SPDX-License-Identifier: GPL-2.0+
26b8e4e7dSAkshu Agrawal //
36b8e4e7dSAkshu Agrawal // Machine driver for AMD ACP Audio engine using DA7219 & MAX98357 codec.
46b8e4e7dSAkshu Agrawal //
56b8e4e7dSAkshu Agrawal //Copyright 2016 Advanced Micro Devices, Inc.
66b8e4e7dSAkshu Agrawal 
76b8e4e7dSAkshu Agrawal #include <sound/core.h>
86b8e4e7dSAkshu Agrawal #include <sound/soc.h>
96b8e4e7dSAkshu Agrawal #include <sound/pcm.h>
106b8e4e7dSAkshu Agrawal #include <sound/pcm_params.h>
116b8e4e7dSAkshu Agrawal #include <sound/soc-dapm.h>
126b8e4e7dSAkshu Agrawal #include <sound/jack.h>
136b8e4e7dSAkshu Agrawal #include <linux/clk.h>
146b8e4e7dSAkshu Agrawal #include <linux/gpio.h>
1572c3b2b0SAkshu Agrawal #include <linux/gpio/consumer.h>
166b8e4e7dSAkshu Agrawal #include <linux/module.h>
176b8e4e7dSAkshu Agrawal #include <linux/i2c.h>
186b8e4e7dSAkshu Agrawal #include <linux/input.h>
1914beacccSYueHaibing #include <linux/io.h>
206b8e4e7dSAkshu Agrawal #include <linux/acpi.h>
216b8e4e7dSAkshu Agrawal 
226b8e4e7dSAkshu Agrawal #include "raven/acp3x.h"
236b8e4e7dSAkshu Agrawal #include "../codecs/rt5682.h"
246b8e4e7dSAkshu Agrawal 
256b8e4e7dSAkshu Agrawal #define PCO_PLAT_CLK 48000000
266b8e4e7dSAkshu Agrawal #define RT5682_PLL_FREQ (48000 * 512)
276b8e4e7dSAkshu Agrawal #define DUAL_CHANNEL		2
286b8e4e7dSAkshu Agrawal 
296b8e4e7dSAkshu Agrawal static struct snd_soc_jack pco_jack;
306b8e4e7dSAkshu Agrawal static struct clk *rt5682_dai_wclk;
316b8e4e7dSAkshu Agrawal static struct clk *rt5682_dai_bclk;
3272c3b2b0SAkshu Agrawal static struct gpio_desc *dmic_sel;
336b8e4e7dSAkshu Agrawal 
346b8e4e7dSAkshu Agrawal static int acp3x_5682_init(struct snd_soc_pcm_runtime *rtd)
356b8e4e7dSAkshu Agrawal {
366b8e4e7dSAkshu Agrawal 	int ret;
376b8e4e7dSAkshu Agrawal 	struct snd_soc_card *card = rtd->card;
38b09b22fcSKuninori Morimoto 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
396b8e4e7dSAkshu Agrawal 	struct snd_soc_component *component = codec_dai->component;
406b8e4e7dSAkshu Agrawal 
416b8e4e7dSAkshu Agrawal 	dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
426b8e4e7dSAkshu Agrawal 
436b8e4e7dSAkshu Agrawal 	/* set rt5682 dai fmt */
446b8e4e7dSAkshu Agrawal 	ret =  snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
456b8e4e7dSAkshu Agrawal 			| SND_SOC_DAIFMT_NB_NF
466b8e4e7dSAkshu Agrawal 			| SND_SOC_DAIFMT_CBM_CFM);
476b8e4e7dSAkshu Agrawal 	if (ret < 0) {
486b8e4e7dSAkshu Agrawal 		dev_err(rtd->card->dev,
496b8e4e7dSAkshu Agrawal 				"Failed to set rt5682 dai fmt: %d\n", ret);
506b8e4e7dSAkshu Agrawal 		return ret;
516b8e4e7dSAkshu Agrawal 	}
526b8e4e7dSAkshu Agrawal 
536b8e4e7dSAkshu Agrawal 	/* set codec PLL */
546b8e4e7dSAkshu Agrawal 	ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL2, RT5682_PLL2_S_MCLK,
556b8e4e7dSAkshu Agrawal 				  PCO_PLAT_CLK, RT5682_PLL_FREQ);
566b8e4e7dSAkshu Agrawal 	if (ret < 0) {
576b8e4e7dSAkshu Agrawal 		dev_err(rtd->dev, "can't set rt5682 PLL: %d\n", ret);
586b8e4e7dSAkshu Agrawal 		return ret;
596b8e4e7dSAkshu Agrawal 	}
606b8e4e7dSAkshu Agrawal 
616b8e4e7dSAkshu Agrawal 	/* Set codec sysclk */
626b8e4e7dSAkshu Agrawal 	ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL2,
636b8e4e7dSAkshu Agrawal 			RT5682_PLL_FREQ, SND_SOC_CLOCK_IN);
646b8e4e7dSAkshu Agrawal 	if (ret < 0) {
656b8e4e7dSAkshu Agrawal 		dev_err(rtd->dev,
666b8e4e7dSAkshu Agrawal 			"Failed to set rt5682 SYSCLK: %d\n", ret);
676b8e4e7dSAkshu Agrawal 		return ret;
686b8e4e7dSAkshu Agrawal 	}
696b8e4e7dSAkshu Agrawal 
706b8e4e7dSAkshu Agrawal 	/* Set tdm/i2s1 master bclk ratio */
716b8e4e7dSAkshu Agrawal 	ret = snd_soc_dai_set_bclk_ratio(codec_dai, 64);
726b8e4e7dSAkshu Agrawal 	if (ret < 0) {
736b8e4e7dSAkshu Agrawal 		dev_err(rtd->dev,
746b8e4e7dSAkshu Agrawal 			"Failed to set rt5682 tdm bclk ratio: %d\n", ret);
756b8e4e7dSAkshu Agrawal 		return ret;
766b8e4e7dSAkshu Agrawal 	}
776b8e4e7dSAkshu Agrawal 
786b8e4e7dSAkshu Agrawal 	rt5682_dai_wclk = clk_get(component->dev, "rt5682-dai-wclk");
796b8e4e7dSAkshu Agrawal 	rt5682_dai_bclk = clk_get(component->dev, "rt5682-dai-bclk");
806b8e4e7dSAkshu Agrawal 
816b8e4e7dSAkshu Agrawal 	ret = snd_soc_card_jack_new(card, "Headset Jack",
826b8e4e7dSAkshu Agrawal 				SND_JACK_HEADSET | SND_JACK_LINEOUT |
836b8e4e7dSAkshu Agrawal 				SND_JACK_BTN_0 | SND_JACK_BTN_1 |
846b8e4e7dSAkshu Agrawal 				SND_JACK_BTN_2 | SND_JACK_BTN_3,
856b8e4e7dSAkshu Agrawal 				&pco_jack, NULL, 0);
866b8e4e7dSAkshu Agrawal 	if (ret) {
876b8e4e7dSAkshu Agrawal 		dev_err(card->dev, "HP jack creation failed %d\n", ret);
886b8e4e7dSAkshu Agrawal 		return ret;
896b8e4e7dSAkshu Agrawal 	}
906b8e4e7dSAkshu Agrawal 
916b8e4e7dSAkshu Agrawal 	snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
928dbcfcfcSAkshu Agrawal 	snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
938dbcfcfcSAkshu Agrawal 	snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
948dbcfcfcSAkshu Agrawal 	snd_jack_set_key(pco_jack.jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
956b8e4e7dSAkshu Agrawal 
966b8e4e7dSAkshu Agrawal 	ret = snd_soc_component_set_jack(component, &pco_jack, NULL);
976b8e4e7dSAkshu Agrawal 	if (ret) {
986b8e4e7dSAkshu Agrawal 		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
996b8e4e7dSAkshu Agrawal 		return ret;
1006b8e4e7dSAkshu Agrawal 	}
1016b8e4e7dSAkshu Agrawal 
1026b8e4e7dSAkshu Agrawal 	return ret;
1036b8e4e7dSAkshu Agrawal }
1046b8e4e7dSAkshu Agrawal 
1056b8e4e7dSAkshu Agrawal static int rt5682_clk_enable(struct snd_pcm_substream *substream)
1066b8e4e7dSAkshu Agrawal {
1076b8e4e7dSAkshu Agrawal 	int ret = 0;
108ded00543SKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1096b8e4e7dSAkshu Agrawal 
1106b8e4e7dSAkshu Agrawal 	/* RT5682 will support only 48K output with 48M mclk */
1116b8e4e7dSAkshu Agrawal 	clk_set_rate(rt5682_dai_wclk, 48000);
1126b8e4e7dSAkshu Agrawal 	clk_set_rate(rt5682_dai_bclk, 48000 * 64);
1136b8e4e7dSAkshu Agrawal 	ret = clk_prepare_enable(rt5682_dai_wclk);
1146b8e4e7dSAkshu Agrawal 	if (ret < 0) {
1156b8e4e7dSAkshu Agrawal 		dev_err(rtd->dev, "can't enable wclk %d\n", ret);
1166b8e4e7dSAkshu Agrawal 		return ret;
1176b8e4e7dSAkshu Agrawal 	}
1186b8e4e7dSAkshu Agrawal 
1196b8e4e7dSAkshu Agrawal 	return ret;
1206b8e4e7dSAkshu Agrawal }
1216b8e4e7dSAkshu Agrawal 
1226b8e4e7dSAkshu Agrawal static void rt5682_clk_disable(void)
1236b8e4e7dSAkshu Agrawal {
1246b8e4e7dSAkshu Agrawal 	clk_disable_unprepare(rt5682_dai_wclk);
1256b8e4e7dSAkshu Agrawal }
1266b8e4e7dSAkshu Agrawal 
1276b8e4e7dSAkshu Agrawal static const unsigned int channels[] = {
1286b8e4e7dSAkshu Agrawal 	DUAL_CHANNEL,
1296b8e4e7dSAkshu Agrawal };
1306b8e4e7dSAkshu Agrawal 
1316b8e4e7dSAkshu Agrawal static const unsigned int rates[] = {
1326b8e4e7dSAkshu Agrawal 	48000,
1336b8e4e7dSAkshu Agrawal };
1346b8e4e7dSAkshu Agrawal 
1356b8e4e7dSAkshu Agrawal static const struct snd_pcm_hw_constraint_list constraints_rates = {
1366b8e4e7dSAkshu Agrawal 	.count = ARRAY_SIZE(rates),
1376b8e4e7dSAkshu Agrawal 	.list  = rates,
1386b8e4e7dSAkshu Agrawal 	.mask = 0,
1396b8e4e7dSAkshu Agrawal };
1406b8e4e7dSAkshu Agrawal 
1416b8e4e7dSAkshu Agrawal static const struct snd_pcm_hw_constraint_list constraints_channels = {
1426b8e4e7dSAkshu Agrawal 	.count = ARRAY_SIZE(channels),
1436b8e4e7dSAkshu Agrawal 	.list = channels,
1446b8e4e7dSAkshu Agrawal 	.mask = 0,
1456b8e4e7dSAkshu Agrawal };
1466b8e4e7dSAkshu Agrawal 
1476b8e4e7dSAkshu Agrawal static int acp3x_5682_startup(struct snd_pcm_substream *substream)
1486b8e4e7dSAkshu Agrawal {
1496b8e4e7dSAkshu Agrawal 	struct snd_pcm_runtime *runtime = substream->runtime;
150ded00543SKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1516b8e4e7dSAkshu Agrawal 	struct snd_soc_card *card = rtd->card;
1526b8e4e7dSAkshu Agrawal 	struct acp3x_platform_info *machine = snd_soc_card_get_drvdata(card);
1536b8e4e7dSAkshu Agrawal 
1546b8e4e7dSAkshu Agrawal 	machine->play_i2s_instance = I2S_SP_INSTANCE;
1556b8e4e7dSAkshu Agrawal 	machine->cap_i2s_instance = I2S_SP_INSTANCE;
1566b8e4e7dSAkshu Agrawal 
1576b8e4e7dSAkshu Agrawal 	runtime->hw.channels_max = DUAL_CHANNEL;
1586b8e4e7dSAkshu Agrawal 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
1596b8e4e7dSAkshu Agrawal 				   &constraints_channels);
1606b8e4e7dSAkshu Agrawal 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1616b8e4e7dSAkshu Agrawal 				   &constraints_rates);
1626b8e4e7dSAkshu Agrawal 	return rt5682_clk_enable(substream);
1636b8e4e7dSAkshu Agrawal }
1646b8e4e7dSAkshu Agrawal 
1656b8e4e7dSAkshu Agrawal static int acp3x_max_startup(struct snd_pcm_substream *substream)
1666b8e4e7dSAkshu Agrawal {
1676b8e4e7dSAkshu Agrawal 	struct snd_pcm_runtime *runtime = substream->runtime;
168ded00543SKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1696b8e4e7dSAkshu Agrawal 	struct snd_soc_card *card = rtd->card;
1706b8e4e7dSAkshu Agrawal 	struct acp3x_platform_info *machine = snd_soc_card_get_drvdata(card);
1716b8e4e7dSAkshu Agrawal 
1726b8e4e7dSAkshu Agrawal 	machine->play_i2s_instance = I2S_BT_INSTANCE;
1736b8e4e7dSAkshu Agrawal 
1746b8e4e7dSAkshu Agrawal 	runtime->hw.channels_max = DUAL_CHANNEL;
1756b8e4e7dSAkshu Agrawal 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
1766b8e4e7dSAkshu Agrawal 				   &constraints_channels);
1776b8e4e7dSAkshu Agrawal 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1786b8e4e7dSAkshu Agrawal 				   &constraints_rates);
1796b8e4e7dSAkshu Agrawal 	return rt5682_clk_enable(substream);
1806b8e4e7dSAkshu Agrawal }
1816b8e4e7dSAkshu Agrawal 
18272c3b2b0SAkshu Agrawal static int acp3x_ec_dmic0_startup(struct snd_pcm_substream *substream)
1836b8e4e7dSAkshu Agrawal {
184ded00543SKuninori Morimoto 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1856b8e4e7dSAkshu Agrawal 	struct snd_soc_card *card = rtd->card;
186b09b22fcSKuninori Morimoto 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
1876b8e4e7dSAkshu Agrawal 	struct acp3x_platform_info *machine = snd_soc_card_get_drvdata(card);
1886b8e4e7dSAkshu Agrawal 
1896b8e4e7dSAkshu Agrawal 	machine->cap_i2s_instance = I2S_BT_INSTANCE;
1906b8e4e7dSAkshu Agrawal 	snd_soc_dai_set_bclk_ratio(codec_dai, 64);
19172c3b2b0SAkshu Agrawal 
19272c3b2b0SAkshu Agrawal 	return rt5682_clk_enable(substream);
19372c3b2b0SAkshu Agrawal }
19472c3b2b0SAkshu Agrawal 
195b7a742cfSAkshu Agrawal static int dmic_switch;
196b7a742cfSAkshu Agrawal 
197b7a742cfSAkshu Agrawal static int dmic_get(struct snd_kcontrol *kcontrol,
198b7a742cfSAkshu Agrawal 			 struct snd_ctl_elem_value *ucontrol)
19972c3b2b0SAkshu Agrawal {
200b7a742cfSAkshu Agrawal 	ucontrol->value.integer.value[0] = dmic_switch;
201b7a742cfSAkshu Agrawal 	return 0;
202b7a742cfSAkshu Agrawal }
20372c3b2b0SAkshu Agrawal 
204b7a742cfSAkshu Agrawal static int dmic_set(struct snd_kcontrol *kcontrol,
205b7a742cfSAkshu Agrawal 			 struct snd_ctl_elem_value *ucontrol)
206b7a742cfSAkshu Agrawal {
207b7a742cfSAkshu Agrawal 	if (dmic_sel) {
208b7a742cfSAkshu Agrawal 		dmic_switch = ucontrol->value.integer.value[0];
209b7a742cfSAkshu Agrawal 		gpiod_set_value(dmic_sel, dmic_switch);
210b7a742cfSAkshu Agrawal 	}
211b7a742cfSAkshu Agrawal 	return 0;
2126b8e4e7dSAkshu Agrawal }
2136b8e4e7dSAkshu Agrawal 
2146b8e4e7dSAkshu Agrawal static void rt5682_shutdown(struct snd_pcm_substream *substream)
2156b8e4e7dSAkshu Agrawal {
2166b8e4e7dSAkshu Agrawal 	rt5682_clk_disable();
2176b8e4e7dSAkshu Agrawal }
2186b8e4e7dSAkshu Agrawal 
2196b8e4e7dSAkshu Agrawal static const struct snd_soc_ops acp3x_5682_ops = {
2206b8e4e7dSAkshu Agrawal 	.startup = acp3x_5682_startup,
2216b8e4e7dSAkshu Agrawal 	.shutdown = rt5682_shutdown,
2226b8e4e7dSAkshu Agrawal };
2236b8e4e7dSAkshu Agrawal 
2246b8e4e7dSAkshu Agrawal static const struct snd_soc_ops acp3x_max_play_ops = {
2256b8e4e7dSAkshu Agrawal 	.startup = acp3x_max_startup,
2266b8e4e7dSAkshu Agrawal 	.shutdown = rt5682_shutdown,
2276b8e4e7dSAkshu Agrawal };
2286b8e4e7dSAkshu Agrawal 
22972c3b2b0SAkshu Agrawal static const struct snd_soc_ops acp3x_ec_cap0_ops = {
23072c3b2b0SAkshu Agrawal 	.startup = acp3x_ec_dmic0_startup,
23172c3b2b0SAkshu Agrawal 	.shutdown = rt5682_shutdown,
23272c3b2b0SAkshu Agrawal };
23372c3b2b0SAkshu Agrawal 
2346b8e4e7dSAkshu Agrawal SND_SOC_DAILINK_DEF(acp3x_i2s,
2356b8e4e7dSAkshu Agrawal 	DAILINK_COMP_ARRAY(COMP_CPU("acp3x_i2s_playcap.0")));
2366b8e4e7dSAkshu Agrawal SND_SOC_DAILINK_DEF(acp3x_bt,
2376b8e4e7dSAkshu Agrawal 	DAILINK_COMP_ARRAY(COMP_CPU("acp3x_i2s_playcap.2")));
2386b8e4e7dSAkshu Agrawal 
2396b8e4e7dSAkshu Agrawal SND_SOC_DAILINK_DEF(rt5682,
2406b8e4e7dSAkshu Agrawal 	DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1")));
2416b8e4e7dSAkshu Agrawal SND_SOC_DAILINK_DEF(max,
2426b8e4e7dSAkshu Agrawal 	DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00", "HiFi")));
2436b8e4e7dSAkshu Agrawal SND_SOC_DAILINK_DEF(cros_ec,
2446b8e4e7dSAkshu Agrawal 	DAILINK_COMP_ARRAY(COMP_CODEC("GOOG0013:00", "EC Codec I2S RX")));
2456b8e4e7dSAkshu Agrawal 
2466b8e4e7dSAkshu Agrawal SND_SOC_DAILINK_DEF(platform,
2476b8e4e7dSAkshu Agrawal 	DAILINK_COMP_ARRAY(COMP_PLATFORM("acp3x_rv_i2s_dma.0")));
2486b8e4e7dSAkshu Agrawal 
2496b8e4e7dSAkshu Agrawal static struct snd_soc_dai_link acp3x_dai_5682_98357[] = {
2506b8e4e7dSAkshu Agrawal 	{
2516b8e4e7dSAkshu Agrawal 		.name = "acp3x-5682-play",
2526b8e4e7dSAkshu Agrawal 		.stream_name = "Playback",
2536b8e4e7dSAkshu Agrawal 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
2546b8e4e7dSAkshu Agrawal 				| SND_SOC_DAIFMT_CBM_CFM,
2556b8e4e7dSAkshu Agrawal 		.init = acp3x_5682_init,
2566b8e4e7dSAkshu Agrawal 		.dpcm_playback = 1,
2576b8e4e7dSAkshu Agrawal 		.dpcm_capture = 1,
2586b8e4e7dSAkshu Agrawal 		.ops = &acp3x_5682_ops,
2596b8e4e7dSAkshu Agrawal 		SND_SOC_DAILINK_REG(acp3x_i2s, rt5682, platform),
2606b8e4e7dSAkshu Agrawal 	},
2616b8e4e7dSAkshu Agrawal 	{
2626b8e4e7dSAkshu Agrawal 		.name = "acp3x-max98357-play",
2636b8e4e7dSAkshu Agrawal 		.stream_name = "HiFi Playback",
2646b8e4e7dSAkshu Agrawal 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
2656b8e4e7dSAkshu Agrawal 				| SND_SOC_DAIFMT_CBM_CFM,
2666b8e4e7dSAkshu Agrawal 		.dpcm_playback = 1,
2676b8e4e7dSAkshu Agrawal 		.ops = &acp3x_max_play_ops,
2686b8e4e7dSAkshu Agrawal 		SND_SOC_DAILINK_REG(acp3x_bt, max, platform),
2696b8e4e7dSAkshu Agrawal 	},
2706b8e4e7dSAkshu Agrawal 	{
27172c3b2b0SAkshu Agrawal 		.name = "acp3x-ec-dmic0-capture",
27272c3b2b0SAkshu Agrawal 		.stream_name = "Capture DMIC0",
2736b8e4e7dSAkshu Agrawal 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
2746b8e4e7dSAkshu Agrawal 				| SND_SOC_DAIFMT_CBS_CFS,
2756b8e4e7dSAkshu Agrawal 		.dpcm_capture = 1,
27672c3b2b0SAkshu Agrawal 		.ops = &acp3x_ec_cap0_ops,
27772c3b2b0SAkshu Agrawal 		SND_SOC_DAILINK_REG(acp3x_bt, cros_ec, platform),
27872c3b2b0SAkshu Agrawal 	},
2796b8e4e7dSAkshu Agrawal };
2806b8e4e7dSAkshu Agrawal 
281b7a742cfSAkshu Agrawal static const char * const dmic_mux_text[] = {
282b7a742cfSAkshu Agrawal 	"Front Mic",
283b7a742cfSAkshu Agrawal 	"Rear Mic",
284b7a742cfSAkshu Agrawal };
285b7a742cfSAkshu Agrawal 
286b7a742cfSAkshu Agrawal static SOC_ENUM_SINGLE_DECL(
287b7a742cfSAkshu Agrawal 		acp3x_dmic_enum, SND_SOC_NOPM, 0, dmic_mux_text);
288b7a742cfSAkshu Agrawal 
289b7a742cfSAkshu Agrawal static const struct snd_kcontrol_new acp3x_dmic_mux_control =
290b7a742cfSAkshu Agrawal 	SOC_DAPM_ENUM_EXT("DMIC Select Mux", acp3x_dmic_enum,
291b7a742cfSAkshu Agrawal 			  dmic_get, dmic_set);
292b7a742cfSAkshu Agrawal 
293*9c04b5a4SRavulapati Vishnu vardhan rao static const struct snd_soc_dapm_widget acp3x_5682_widgets[] = {
2946b8e4e7dSAkshu Agrawal 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
2956b8e4e7dSAkshu Agrawal 	SND_SOC_DAPM_SPK("Spk", NULL),
2966b8e4e7dSAkshu Agrawal 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
297b7a742cfSAkshu Agrawal 	SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0,
298b7a742cfSAkshu Agrawal 			 &acp3x_dmic_mux_control),
2996b8e4e7dSAkshu Agrawal };
3006b8e4e7dSAkshu Agrawal 
301*9c04b5a4SRavulapati Vishnu vardhan rao static const struct snd_soc_dapm_route acp3x_5682_audio_route[] = {
3026b8e4e7dSAkshu Agrawal 	{"Headphone Jack", NULL, "HPOL"},
3036b8e4e7dSAkshu Agrawal 	{"Headphone Jack", NULL, "HPOR"},
3046b8e4e7dSAkshu Agrawal 	{"IN1P", NULL, "Headset Mic"},
3056b8e4e7dSAkshu Agrawal 	{"Spk", NULL, "Speaker"},
306b7a742cfSAkshu Agrawal 	{"Dmic Mux", "Front Mic", "DMIC"},
307b7a742cfSAkshu Agrawal 	{"Dmic Mux", "Rear Mic", "DMIC"},
3086b8e4e7dSAkshu Agrawal };
3096b8e4e7dSAkshu Agrawal 
310*9c04b5a4SRavulapati Vishnu vardhan rao static const struct snd_kcontrol_new acp3x_5682_mc_controls[] = {
3116b8e4e7dSAkshu Agrawal 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
3126b8e4e7dSAkshu Agrawal 	SOC_DAPM_PIN_SWITCH("Spk"),
3136b8e4e7dSAkshu Agrawal 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
3146b8e4e7dSAkshu Agrawal };
3156b8e4e7dSAkshu Agrawal 
316*9c04b5a4SRavulapati Vishnu vardhan rao static struct snd_soc_card acp3x_5682 = {
3176b8e4e7dSAkshu Agrawal 	.name = "acp3xalc5682m98357",
3186b8e4e7dSAkshu Agrawal 	.owner = THIS_MODULE,
3196b8e4e7dSAkshu Agrawal 	.dai_link = acp3x_dai_5682_98357,
3206b8e4e7dSAkshu Agrawal 	.num_links = ARRAY_SIZE(acp3x_dai_5682_98357),
321*9c04b5a4SRavulapati Vishnu vardhan rao 	.dapm_widgets = acp3x_5682_widgets,
322*9c04b5a4SRavulapati Vishnu vardhan rao 	.num_dapm_widgets = ARRAY_SIZE(acp3x_5682_widgets),
323*9c04b5a4SRavulapati Vishnu vardhan rao 	.dapm_routes = acp3x_5682_audio_route,
324*9c04b5a4SRavulapati Vishnu vardhan rao 	.num_dapm_routes = ARRAY_SIZE(acp3x_5682_audio_route),
325*9c04b5a4SRavulapati Vishnu vardhan rao 	.controls = acp3x_5682_mc_controls,
326*9c04b5a4SRavulapati Vishnu vardhan rao 	.num_controls = ARRAY_SIZE(acp3x_5682_mc_controls),
3276b8e4e7dSAkshu Agrawal };
3286b8e4e7dSAkshu Agrawal 
3296b8e4e7dSAkshu Agrawal static int acp3x_probe(struct platform_device *pdev)
3306b8e4e7dSAkshu Agrawal {
3316b8e4e7dSAkshu Agrawal 	int ret;
3326b8e4e7dSAkshu Agrawal 	struct snd_soc_card *card;
3336b8e4e7dSAkshu Agrawal 	struct acp3x_platform_info *machine;
3346b8e4e7dSAkshu Agrawal 
3356b8e4e7dSAkshu Agrawal 	machine = devm_kzalloc(&pdev->dev, sizeof(*machine), GFP_KERNEL);
3366b8e4e7dSAkshu Agrawal 	if (!machine)
3376b8e4e7dSAkshu Agrawal 		return -ENOMEM;
3386b8e4e7dSAkshu Agrawal 
339*9c04b5a4SRavulapati Vishnu vardhan rao 	card = &acp3x_5682;
340*9c04b5a4SRavulapati Vishnu vardhan rao 	acp3x_5682.dev = &pdev->dev;
3416b8e4e7dSAkshu Agrawal 	platform_set_drvdata(pdev, card);
3426b8e4e7dSAkshu Agrawal 	snd_soc_card_set_drvdata(card, machine);
34372c3b2b0SAkshu Agrawal 
34472c3b2b0SAkshu Agrawal 	dmic_sel = devm_gpiod_get(&pdev->dev, "dmic", GPIOD_OUT_LOW);
34572c3b2b0SAkshu Agrawal 	if (IS_ERR(dmic_sel)) {
346d7729c40SAkshu Agrawal 		dev_err(&pdev->dev, "DMIC gpio failed err=%ld\n",
34772c3b2b0SAkshu Agrawal 			PTR_ERR(dmic_sel));
34872c3b2b0SAkshu Agrawal 		return PTR_ERR(dmic_sel);
34972c3b2b0SAkshu Agrawal 	}
35072c3b2b0SAkshu Agrawal 
351*9c04b5a4SRavulapati Vishnu vardhan rao 	ret = devm_snd_soc_register_card(&pdev->dev, &acp3x_5682);
3526b8e4e7dSAkshu Agrawal 	if (ret) {
3536b8e4e7dSAkshu Agrawal 		dev_err(&pdev->dev,
3546b8e4e7dSAkshu Agrawal 				"devm_snd_soc_register_card(%s) failed: %d\n",
355*9c04b5a4SRavulapati Vishnu vardhan rao 				acp3x_5682.name, ret);
3566b8e4e7dSAkshu Agrawal 		return ret;
3576b8e4e7dSAkshu Agrawal 	}
3586b8e4e7dSAkshu Agrawal 	return 0;
3596b8e4e7dSAkshu Agrawal }
3606b8e4e7dSAkshu Agrawal 
3616b8e4e7dSAkshu Agrawal static const struct acpi_device_id acp3x_audio_acpi_match[] = {
3626b8e4e7dSAkshu Agrawal 	{ "AMDI5682", 0 },
3636b8e4e7dSAkshu Agrawal 	{},
3646b8e4e7dSAkshu Agrawal };
3656b8e4e7dSAkshu Agrawal MODULE_DEVICE_TABLE(acpi, acp3x_audio_acpi_match);
3666b8e4e7dSAkshu Agrawal 
3676b8e4e7dSAkshu Agrawal static struct platform_driver acp3x_audio = {
3686b8e4e7dSAkshu Agrawal 	.driver = {
3696b8e4e7dSAkshu Agrawal 		.name = "acp3x-alc5682-max98357",
3706b8e4e7dSAkshu Agrawal 		.acpi_match_table = ACPI_PTR(acp3x_audio_acpi_match),
3716b8e4e7dSAkshu Agrawal 		.pm = &snd_soc_pm_ops,
3726b8e4e7dSAkshu Agrawal 	},
3736b8e4e7dSAkshu Agrawal 	.probe = acp3x_probe,
3746b8e4e7dSAkshu Agrawal };
3756b8e4e7dSAkshu Agrawal 
3766b8e4e7dSAkshu Agrawal module_platform_driver(acp3x_audio);
3776b8e4e7dSAkshu Agrawal 
3786b8e4e7dSAkshu Agrawal MODULE_AUTHOR("akshu.agrawal@amd.com");
3796b8e4e7dSAkshu Agrawal MODULE_DESCRIPTION("ALC5682 & MAX98357 audio support");
3806b8e4e7dSAkshu Agrawal MODULE_LICENSE("GPL v2");
381