xref: /linux/sound/soc/amd/vangogh/acp5x-mach.c (revision dba22efd0d177a23c6da2a161e9a1ad29718924c)
134a0094bSVijendar Mukunda // SPDX-License-Identifier: GPL-2.0+
234a0094bSVijendar Mukunda /*
3*dba22efdSCristian Ciocaltea  * Machine driver for AMD Vangogh platform using either
4*dba22efdSCristian Ciocaltea  * NAU8821 & CS35L41 or NAU8821 & MAX98388 codecs.
534a0094bSVijendar Mukunda  *
634a0094bSVijendar Mukunda  * Copyright 2021 Advanced Micro Devices, Inc.
734a0094bSVijendar Mukunda  */
888f5870dSLucas Tanure 
9ddd42a12SLucas Tanure #include <linux/acpi.h>
10ddd42a12SLucas Tanure #include <linux/dmi.h>
1134a0094bSVijendar Mukunda #include <linux/gpio/consumer.h>
1234a0094bSVijendar Mukunda #include <linux/i2c.h>
1388f5870dSLucas Tanure #include <linux/input-event-codes.h>
14ddd42a12SLucas Tanure #include <linux/module.h>
15ddd42a12SLucas Tanure #include <sound/jack.h>
16ddd42a12SLucas Tanure #include <sound/pcm_params.h>
17ddd42a12SLucas Tanure #include <sound/soc.h>
18ddd42a12SLucas Tanure #include <sound/soc-dapm.h>
1934a0094bSVijendar Mukunda 
2034a0094bSVijendar Mukunda #include "../../codecs/nau8821.h"
2134a0094bSVijendar Mukunda #include "acp5x.h"
2234a0094bSVijendar Mukunda 
2334a0094bSVijendar Mukunda #define DRV_NAME			"acp5x_mach"
2434a0094bSVijendar Mukunda #define DUAL_CHANNEL			2
25c10955e4SLucas Tanure #define ACP5X_NAU8821_BCLK		3072000
269a617f0eSVijendar Mukunda #define ACP5X_NAU8821_FREQ_OUT		12288000
27c10955e4SLucas Tanure #define ACP5X_NAU8821_COMP_NAME 	"i2c-NVTN2020:00"
28c10955e4SLucas Tanure #define ACP5X_NAU8821_DAI_NAME		"nau8821-hifi"
29c10955e4SLucas Tanure #define ACP5X_CS35L41_COMP_LNAME	"spi-VLV1776:00"
30c10955e4SLucas Tanure #define ACP5X_CS35L41_COMP_RNAME	"spi-VLV1776:01"
31c10955e4SLucas Tanure #define ACP5X_CS35L41_DAI_NAME		"cs35l41-pcm"
32*dba22efdSCristian Ciocaltea #define ACP5X_MAX98388_COMP_LNAME	"i2c-ADS8388:00"
33*dba22efdSCristian Ciocaltea #define ACP5X_MAX98388_COMP_RNAME	"i2c-ADS8388:01"
34*dba22efdSCristian Ciocaltea #define ACP5X_MAX98388_DAI_NAME		"max98388-aif1"
3534a0094bSVijendar Mukunda 
3634a0094bSVijendar Mukunda static struct snd_soc_jack vg_headset;
3734a0094bSVijendar Mukunda 
38ab89aa0dSLucas Tanure SND_SOC_DAILINK_DEF(platform,  DAILINK_COMP_ARRAY(COMP_PLATFORM("acp5x_i2s_dma.0")));
39ab89aa0dSLucas Tanure SND_SOC_DAILINK_DEF(acp5x_i2s, DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.0")));
40ab89aa0dSLucas Tanure SND_SOC_DAILINK_DEF(acp5x_bt,  DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.1")));
41c10955e4SLucas Tanure SND_SOC_DAILINK_DEF(nau8821,   DAILINK_COMP_ARRAY(COMP_CODEC(ACP5X_NAU8821_COMP_NAME,
42c10955e4SLucas Tanure 							     ACP5X_NAU8821_DAI_NAME)));
43ab89aa0dSLucas Tanure 
4434a0094bSVijendar Mukunda static struct snd_soc_jack_pin acp5x_nau8821_jack_pins[] = {
4534a0094bSVijendar Mukunda 	{
4634a0094bSVijendar Mukunda 		.pin	= "Headphone",
4734a0094bSVijendar Mukunda 		.mask	= SND_JACK_HEADPHONE,
4834a0094bSVijendar Mukunda 	},
4934a0094bSVijendar Mukunda 	{
5034a0094bSVijendar Mukunda 		.pin	= "Headset Mic",
5134a0094bSVijendar Mukunda 		.mask	= SND_JACK_MICROPHONE,
5234a0094bSVijendar Mukunda 	},
5334a0094bSVijendar Mukunda };
5434a0094bSVijendar Mukunda 
55ab89aa0dSLucas Tanure static const struct snd_kcontrol_new acp5x_8821_controls[] = {
56ab89aa0dSLucas Tanure 	SOC_DAPM_PIN_SWITCH("Headphone"),
57ab89aa0dSLucas Tanure 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
58ab89aa0dSLucas Tanure 	SOC_DAPM_PIN_SWITCH("Int Mic"),
59ab89aa0dSLucas Tanure };
60ab89aa0dSLucas Tanure 
61ab89aa0dSLucas Tanure static int platform_clock_control(struct snd_soc_dapm_widget *w,
62ab89aa0dSLucas Tanure 				  struct snd_kcontrol *k, int event)
63ab89aa0dSLucas Tanure {
64ab89aa0dSLucas Tanure 	struct snd_soc_dapm_context *dapm = w->dapm;
65ab89aa0dSLucas Tanure 	struct snd_soc_card *card = dapm->card;
66ab89aa0dSLucas Tanure 	struct snd_soc_dai *dai;
67ab89aa0dSLucas Tanure 	int ret = 0;
68ab89aa0dSLucas Tanure 
69c10955e4SLucas Tanure 	dai = snd_soc_card_get_codec_dai(card, ACP5X_NAU8821_DAI_NAME);
70ab89aa0dSLucas Tanure 	if (!dai) {
71ab89aa0dSLucas Tanure 		dev_err(card->dev, "Codec dai not found\n");
72ab89aa0dSLucas Tanure 		return -EIO;
73ab89aa0dSLucas Tanure 	}
74ab89aa0dSLucas Tanure 
75ab89aa0dSLucas Tanure 	if (SND_SOC_DAPM_EVENT_OFF(event)) {
76ab89aa0dSLucas Tanure 		ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN);
77ab89aa0dSLucas Tanure 		if (ret < 0) {
78ab89aa0dSLucas Tanure 			dev_err(card->dev, "set sysclk err = %d\n", ret);
79ab89aa0dSLucas Tanure 			return -EIO;
80ab89aa0dSLucas Tanure 		}
81ab89aa0dSLucas Tanure 	} else {
82ab89aa0dSLucas Tanure 		ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_FLL_BLK, 0, SND_SOC_CLOCK_IN);
83ab89aa0dSLucas Tanure 		if (ret < 0)
84ab89aa0dSLucas Tanure 			dev_err(dai->dev, "can't set BLK clock %d\n", ret);
85c10955e4SLucas Tanure 		ret = snd_soc_dai_set_pll(dai, 0, 0, ACP5X_NAU8821_BCLK, ACP5X_NAU8821_FREQ_OUT);
86ab89aa0dSLucas Tanure 		if (ret < 0)
87ab89aa0dSLucas Tanure 			dev_err(dai->dev, "can't set FLL: %d\n", ret);
88ab89aa0dSLucas Tanure 	}
89ab89aa0dSLucas Tanure 
90ab89aa0dSLucas Tanure 	return ret;
91ab89aa0dSLucas Tanure }
92ab89aa0dSLucas Tanure 
9334a0094bSVijendar Mukunda static int acp5x_8821_init(struct snd_soc_pcm_runtime *rtd)
9434a0094bSVijendar Mukunda {
95ddd42a12SLucas Tanure 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
9634a0094bSVijendar Mukunda 	int ret;
9734a0094bSVijendar Mukunda 
9834a0094bSVijendar Mukunda 	/*
9934a0094bSVijendar Mukunda 	 * Headset buttons map to the google Reference headset.
10034a0094bSVijendar Mukunda 	 * These can be configured by userspace.
10134a0094bSVijendar Mukunda 	 */
102ddd42a12SLucas Tanure 	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
10334a0094bSVijendar Mukunda 					 SND_JACK_HEADSET | SND_JACK_BTN_0,
10434a0094bSVijendar Mukunda 					 &vg_headset, acp5x_nau8821_jack_pins,
10534a0094bSVijendar Mukunda 					 ARRAY_SIZE(acp5x_nau8821_jack_pins));
10634a0094bSVijendar Mukunda 	if (ret) {
10734a0094bSVijendar Mukunda 		dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
10834a0094bSVijendar Mukunda 		return ret;
10934a0094bSVijendar Mukunda 	}
11034a0094bSVijendar Mukunda 
11134a0094bSVijendar Mukunda 	snd_jack_set_key(vg_headset.jack, SND_JACK_BTN_0, KEY_MEDIA);
11234a0094bSVijendar Mukunda 	nau8821_enable_jack_detect(component, &vg_headset);
113ddd42a12SLucas Tanure 
11434a0094bSVijendar Mukunda 	return ret;
11534a0094bSVijendar Mukunda }
11634a0094bSVijendar Mukunda 
11734a0094bSVijendar Mukunda static const unsigned int rates[] = {
11834a0094bSVijendar Mukunda 	48000,
11934a0094bSVijendar Mukunda };
12034a0094bSVijendar Mukunda 
12134a0094bSVijendar Mukunda static const struct snd_pcm_hw_constraint_list constraints_rates = {
12234a0094bSVijendar Mukunda 	.count = ARRAY_SIZE(rates),
12334a0094bSVijendar Mukunda 	.list  = rates,
12434a0094bSVijendar Mukunda 	.mask = 0,
12534a0094bSVijendar Mukunda };
12634a0094bSVijendar Mukunda 
12734a0094bSVijendar Mukunda static const unsigned int channels[] = {
12834a0094bSVijendar Mukunda 	2,
12934a0094bSVijendar Mukunda };
13034a0094bSVijendar Mukunda 
13134a0094bSVijendar Mukunda static const struct snd_pcm_hw_constraint_list constraints_channels = {
13234a0094bSVijendar Mukunda 	.count = ARRAY_SIZE(channels),
13334a0094bSVijendar Mukunda 	.list = channels,
13434a0094bSVijendar Mukunda 	.mask = 0,
13534a0094bSVijendar Mukunda };
13634a0094bSVijendar Mukunda 
1370c38cc1dSVijendar Mukunda static const unsigned int acp5x_nau8821_format[] = {32};
1380c38cc1dSVijendar Mukunda 
1390c38cc1dSVijendar Mukunda static struct snd_pcm_hw_constraint_list constraints_sample_bits = {
1400c38cc1dSVijendar Mukunda 	.list = acp5x_nau8821_format,
1410c38cc1dSVijendar Mukunda 	.count = ARRAY_SIZE(acp5x_nau8821_format),
1420c38cc1dSVijendar Mukunda };
1430c38cc1dSVijendar Mukunda 
14434a0094bSVijendar Mukunda static int acp5x_8821_startup(struct snd_pcm_substream *substream)
14534a0094bSVijendar Mukunda {
14634a0094bSVijendar Mukunda 	struct snd_pcm_runtime *runtime = substream->runtime;
147a2253ec7SZhen Ni 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
148ddd42a12SLucas Tanure 	struct acp5x_platform_info *machine = snd_soc_card_get_drvdata(rtd->card);
14934a0094bSVijendar Mukunda 
15034a0094bSVijendar Mukunda 	machine->play_i2s_instance = I2S_SP_INSTANCE;
15134a0094bSVijendar Mukunda 	machine->cap_i2s_instance = I2S_SP_INSTANCE;
15234a0094bSVijendar Mukunda 
15334a0094bSVijendar Mukunda 	runtime->hw.channels_max = DUAL_CHANNEL;
15434a0094bSVijendar Mukunda 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
15534a0094bSVijendar Mukunda 				   &constraints_channels);
15634a0094bSVijendar Mukunda 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
15734a0094bSVijendar Mukunda 				   &constraints_rates);
1580c38cc1dSVijendar Mukunda 	snd_pcm_hw_constraint_list(substream->runtime, 0,
1590c38cc1dSVijendar Mukunda 				   SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
1600c38cc1dSVijendar Mukunda 				   &constraints_sample_bits);
161ddd42a12SLucas Tanure 
16234a0094bSVijendar Mukunda 	return 0;
16334a0094bSVijendar Mukunda }
16434a0094bSVijendar Mukunda 
16534a0094bSVijendar Mukunda static int acp5x_nau8821_hw_params(struct snd_pcm_substream *substream,
16634a0094bSVijendar Mukunda 				   struct snd_pcm_hw_params *params)
16734a0094bSVijendar Mukunda {
168a2253ec7SZhen Ni 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
16934a0094bSVijendar Mukunda 	struct snd_soc_card *card = rtd->card;
170c10955e4SLucas Tanure 	struct snd_soc_dai *dai = snd_soc_card_get_codec_dai(card, ACP5X_NAU8821_DAI_NAME);
1719490fbb8SLucas Tanure 	int ret, bclk;
17234a0094bSVijendar Mukunda 
173ddd42a12SLucas Tanure 	ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_FLL_BLK, 0, SND_SOC_CLOCK_IN);
17434a0094bSVijendar Mukunda 	if (ret < 0)
17534a0094bSVijendar Mukunda 		dev_err(card->dev, "can't set FS clock %d\n", ret);
1769490fbb8SLucas Tanure 
1779490fbb8SLucas Tanure 	bclk = snd_soc_params_to_bclk(params);
1789490fbb8SLucas Tanure 	if (bclk < 0) {
1799490fbb8SLucas Tanure 		dev_err(dai->dev, "Fail to get BCLK rate: %d\n", bclk);
1809490fbb8SLucas Tanure 		return bclk;
1819490fbb8SLucas Tanure 	}
1829490fbb8SLucas Tanure 
1839490fbb8SLucas Tanure 	ret = snd_soc_dai_set_pll(dai, 0, 0, bclk, params_rate(params) * 256);
18434a0094bSVijendar Mukunda 	if (ret < 0)
18534a0094bSVijendar Mukunda 		dev_err(card->dev, "can't set FLL: %d\n", ret);
18634a0094bSVijendar Mukunda 
18734a0094bSVijendar Mukunda 	return ret;
18834a0094bSVijendar Mukunda }
18934a0094bSVijendar Mukunda 
190ab89aa0dSLucas Tanure static const struct snd_soc_ops acp5x_8821_ops = {
191ab89aa0dSLucas Tanure 	.startup = acp5x_8821_startup,
192ab89aa0dSLucas Tanure 	.hw_params = acp5x_nau8821_hw_params,
193ab89aa0dSLucas Tanure };
194ab89aa0dSLucas Tanure 
19534a0094bSVijendar Mukunda static int acp5x_cs35l41_startup(struct snd_pcm_substream *substream)
19634a0094bSVijendar Mukunda {
197a2253ec7SZhen Ni 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
198ddd42a12SLucas Tanure 	struct acp5x_platform_info *machine = snd_soc_card_get_drvdata(rtd->card);
199ddd42a12SLucas Tanure 	struct snd_pcm_runtime *runtime = substream->runtime;
20034a0094bSVijendar Mukunda 
20134a0094bSVijendar Mukunda 	machine->play_i2s_instance = I2S_HS_INSTANCE;
20234a0094bSVijendar Mukunda 
20334a0094bSVijendar Mukunda 	runtime->hw.channels_max = DUAL_CHANNEL;
20434a0094bSVijendar Mukunda 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
20534a0094bSVijendar Mukunda 				   &constraints_channels);
20634a0094bSVijendar Mukunda 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
20734a0094bSVijendar Mukunda 				   &constraints_rates);
208ddd42a12SLucas Tanure 
20934a0094bSVijendar Mukunda 	return 0;
21034a0094bSVijendar Mukunda }
21134a0094bSVijendar Mukunda 
21234a0094bSVijendar Mukunda static int acp5x_cs35l41_hw_params(struct snd_pcm_substream *substream,
21334a0094bSVijendar Mukunda 				   struct snd_pcm_hw_params *params)
21434a0094bSVijendar Mukunda {
215a2253ec7SZhen Ni 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
216a719afe6SLucas Tanure 	unsigned int bclk, rate = params_rate(params);
217a719afe6SLucas Tanure 	struct snd_soc_component *comp;
218ddd42a12SLucas Tanure 	int ret, i;
21934a0094bSVijendar Mukunda 
220a719afe6SLucas Tanure 	switch (rate) {
22134a0094bSVijendar Mukunda 	case 48000:
222a719afe6SLucas Tanure 		bclk = 1536000;
22334a0094bSVijendar Mukunda 		break;
22434a0094bSVijendar Mukunda 	default:
225a719afe6SLucas Tanure 		bclk = 0;
226a719afe6SLucas Tanure 		break;
227a719afe6SLucas Tanure 	}
228a719afe6SLucas Tanure 
229a719afe6SLucas Tanure 	for_each_rtd_components(rtd, i, comp) {
230c10955e4SLucas Tanure 		if (!(strcmp(comp->name, ACP5X_CS35L41_COMP_LNAME)) ||
231c10955e4SLucas Tanure 		    !(strcmp(comp->name, ACP5X_CS35L41_COMP_RNAME))) {
232a719afe6SLucas Tanure 			if (!bclk) {
233a719afe6SLucas Tanure 				dev_err(comp->dev, "Invalid sample rate: 0x%x\n", rate);
23434a0094bSVijendar Mukunda 				return -EINVAL;
23534a0094bSVijendar Mukunda 			}
236a719afe6SLucas Tanure 
237a719afe6SLucas Tanure 			ret = snd_soc_component_set_sysclk(comp, 0, 0, bclk, SND_SOC_CLOCK_IN);
238a719afe6SLucas Tanure 			if (ret) {
239a719afe6SLucas Tanure 				dev_err(comp->dev, "failed to set SYSCLK: %d\n", ret);
24034a0094bSVijendar Mukunda 				return ret;
24134a0094bSVijendar Mukunda 			}
24234a0094bSVijendar Mukunda 		}
24334a0094bSVijendar Mukunda 	}
24434a0094bSVijendar Mukunda 
245a719afe6SLucas Tanure 	return 0;
24634a0094bSVijendar Mukunda }
24734a0094bSVijendar Mukunda 
24834a0094bSVijendar Mukunda static const struct snd_soc_ops acp5x_cs35l41_play_ops = {
24934a0094bSVijendar Mukunda 	.startup = acp5x_cs35l41_startup,
25034a0094bSVijendar Mukunda 	.hw_params = acp5x_cs35l41_hw_params,
25134a0094bSVijendar Mukunda };
25234a0094bSVijendar Mukunda 
253e9023248SLucas Tanure static struct snd_soc_codec_conf acp5x_cs35l41_conf[] = {
25434a0094bSVijendar Mukunda 	{
255c10955e4SLucas Tanure 		.dlc = COMP_CODEC_CONF(ACP5X_CS35L41_COMP_LNAME),
25634a0094bSVijendar Mukunda 		.name_prefix = "Left",
25734a0094bSVijendar Mukunda 	},
25834a0094bSVijendar Mukunda 	{
259c10955e4SLucas Tanure 		.dlc = COMP_CODEC_CONF(ACP5X_CS35L41_COMP_RNAME),
26034a0094bSVijendar Mukunda 		.name_prefix = "Right",
26134a0094bSVijendar Mukunda 	},
26234a0094bSVijendar Mukunda };
26334a0094bSVijendar Mukunda 
264c10955e4SLucas Tanure SND_SOC_DAILINK_DEF(cs35l41, DAILINK_COMP_ARRAY(COMP_CODEC(ACP5X_CS35L41_COMP_LNAME,
265c10955e4SLucas Tanure 							   ACP5X_CS35L41_DAI_NAME),
266c10955e4SLucas Tanure 						COMP_CODEC(ACP5X_CS35L41_COMP_RNAME,
267c10955e4SLucas Tanure 							   ACP5X_CS35L41_DAI_NAME)));
26834a0094bSVijendar Mukunda 
269e9023248SLucas Tanure static struct snd_soc_dai_link acp5x_8821_35l41_dai[] = {
27034a0094bSVijendar Mukunda 	{
2715363d730SVijendar Mukunda 		.name = "acp5x-8821-play",
27234a0094bSVijendar Mukunda 		.stream_name = "Playback/Capture",
273ddd42a12SLucas Tanure 		.dai_fmt = SND_SOC_DAIFMT_I2S |
274ddd42a12SLucas Tanure 			   SND_SOC_DAIFMT_NB_NF |
27534a0094bSVijendar Mukunda 			   SND_SOC_DAIFMT_CBC_CFC,
27634a0094bSVijendar Mukunda 		.dpcm_playback = 1,
27734a0094bSVijendar Mukunda 		.dpcm_capture = 1,
27834a0094bSVijendar Mukunda 		.ops = &acp5x_8821_ops,
27934a0094bSVijendar Mukunda 		.init = acp5x_8821_init,
28034a0094bSVijendar Mukunda 		SND_SOC_DAILINK_REG(acp5x_i2s, nau8821, platform),
28134a0094bSVijendar Mukunda 	},
28234a0094bSVijendar Mukunda 	{
28334a0094bSVijendar Mukunda 		.name = "acp5x-CS35L41-Stereo",
28434a0094bSVijendar Mukunda 		.stream_name = "CS35L41 Stereo Playback",
285ddd42a12SLucas Tanure 		.dai_fmt = SND_SOC_DAIFMT_I2S |
286ddd42a12SLucas Tanure 			   SND_SOC_DAIFMT_NB_NF |
28734a0094bSVijendar Mukunda 			   SND_SOC_DAIFMT_CBC_CFC,
28834a0094bSVijendar Mukunda 		.dpcm_playback = 1,
28934a0094bSVijendar Mukunda 		.playback_only = 1,
29034a0094bSVijendar Mukunda 		.ops = &acp5x_cs35l41_play_ops,
29134a0094bSVijendar Mukunda 		SND_SOC_DAILINK_REG(acp5x_bt, cs35l41, platform),
29234a0094bSVijendar Mukunda 	},
29334a0094bSVijendar Mukunda };
29434a0094bSVijendar Mukunda 
295e9023248SLucas Tanure static const struct snd_soc_dapm_widget acp5x_8821_35l41_widgets[] = {
29634a0094bSVijendar Mukunda 	SND_SOC_DAPM_HP("Headphone", NULL),
29734a0094bSVijendar Mukunda 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
29834a0094bSVijendar Mukunda 	SND_SOC_DAPM_MIC("Int Mic", NULL),
29934a0094bSVijendar Mukunda 	SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
300ddd42a12SLucas Tanure 			    platform_clock_control,
301ddd42a12SLucas Tanure 			    SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
30234a0094bSVijendar Mukunda };
30334a0094bSVijendar Mukunda 
304e9023248SLucas Tanure static const struct snd_soc_dapm_route acp5x_8821_35l41_audio_route[] = {
30534a0094bSVijendar Mukunda 	/* HP jack connectors - unknown if we have jack detection */
30634a0094bSVijendar Mukunda 	{ "Headphone", NULL, "HPOL" },
30734a0094bSVijendar Mukunda 	{ "Headphone", NULL, "HPOR" },
30834a0094bSVijendar Mukunda 	{ "MICL", NULL, "Headset Mic" },
30934a0094bSVijendar Mukunda 	{ "MICR", NULL, "Headset Mic" },
31034a0094bSVijendar Mukunda 	{ "DMIC", NULL, "Int Mic" },
31134a0094bSVijendar Mukunda 
31234a0094bSVijendar Mukunda 	{ "Headphone", NULL, "Platform Clock" },
31334a0094bSVijendar Mukunda 	{ "Headset Mic", NULL, "Platform Clock" },
31434a0094bSVijendar Mukunda 	{ "Int Mic", NULL, "Platform Clock" },
31534a0094bSVijendar Mukunda };
31634a0094bSVijendar Mukunda 
317e9023248SLucas Tanure static struct snd_soc_card acp5x_8821_35l41_card = {
31834a0094bSVijendar Mukunda 	.name = "acp5x",
31934a0094bSVijendar Mukunda 	.owner = THIS_MODULE,
320e9023248SLucas Tanure 	.dai_link = acp5x_8821_35l41_dai,
321e9023248SLucas Tanure 	.num_links = ARRAY_SIZE(acp5x_8821_35l41_dai),
322e9023248SLucas Tanure 	.dapm_widgets = acp5x_8821_35l41_widgets,
323e9023248SLucas Tanure 	.num_dapm_widgets = ARRAY_SIZE(acp5x_8821_35l41_widgets),
324e9023248SLucas Tanure 	.dapm_routes = acp5x_8821_35l41_audio_route,
325e9023248SLucas Tanure 	.num_dapm_routes = ARRAY_SIZE(acp5x_8821_35l41_audio_route),
326e9023248SLucas Tanure 	.codec_conf = acp5x_cs35l41_conf,
327e9023248SLucas Tanure 	.num_configs = ARRAY_SIZE(acp5x_cs35l41_conf),
32834a0094bSVijendar Mukunda 	.controls = acp5x_8821_controls,
32934a0094bSVijendar Mukunda 	.num_controls = ARRAY_SIZE(acp5x_8821_controls),
33034a0094bSVijendar Mukunda };
33134a0094bSVijendar Mukunda 
332*dba22efdSCristian Ciocaltea static int acp5x_max98388_startup(struct snd_pcm_substream *substream)
333*dba22efdSCristian Ciocaltea {
334*dba22efdSCristian Ciocaltea 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
335*dba22efdSCristian Ciocaltea 	struct acp5x_platform_info *machine = snd_soc_card_get_drvdata(rtd->card);
336*dba22efdSCristian Ciocaltea 	struct snd_pcm_runtime *runtime = substream->runtime;
337*dba22efdSCristian Ciocaltea 
338*dba22efdSCristian Ciocaltea 	machine->play_i2s_instance = I2S_HS_INSTANCE;
339*dba22efdSCristian Ciocaltea 
340*dba22efdSCristian Ciocaltea 	runtime->hw.channels_max = DUAL_CHANNEL;
341*dba22efdSCristian Ciocaltea 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
342*dba22efdSCristian Ciocaltea 				   &constraints_channels);
343*dba22efdSCristian Ciocaltea 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
344*dba22efdSCristian Ciocaltea 				   &constraints_rates);
345*dba22efdSCristian Ciocaltea 	return 0;
346*dba22efdSCristian Ciocaltea }
347*dba22efdSCristian Ciocaltea 
348*dba22efdSCristian Ciocaltea static const struct snd_soc_ops acp5x_max98388_play_ops = {
349*dba22efdSCristian Ciocaltea 	.startup = acp5x_max98388_startup,
350*dba22efdSCristian Ciocaltea };
351*dba22efdSCristian Ciocaltea 
352*dba22efdSCristian Ciocaltea static struct snd_soc_codec_conf acp5x_max98388_conf[] = {
353*dba22efdSCristian Ciocaltea 	{
354*dba22efdSCristian Ciocaltea 		.dlc = COMP_CODEC_CONF(ACP5X_MAX98388_COMP_LNAME),
355*dba22efdSCristian Ciocaltea 		.name_prefix = "Left",
356*dba22efdSCristian Ciocaltea 	},
357*dba22efdSCristian Ciocaltea 	{
358*dba22efdSCristian Ciocaltea 		.dlc = COMP_CODEC_CONF(ACP5X_MAX98388_COMP_RNAME),
359*dba22efdSCristian Ciocaltea 		.name_prefix = "Right",
360*dba22efdSCristian Ciocaltea 	},
361*dba22efdSCristian Ciocaltea };
362*dba22efdSCristian Ciocaltea 
363*dba22efdSCristian Ciocaltea SND_SOC_DAILINK_DEF(max98388, DAILINK_COMP_ARRAY(COMP_CODEC(ACP5X_MAX98388_COMP_LNAME,
364*dba22efdSCristian Ciocaltea 							    ACP5X_MAX98388_DAI_NAME),
365*dba22efdSCristian Ciocaltea 						 COMP_CODEC(ACP5X_MAX98388_COMP_RNAME,
366*dba22efdSCristian Ciocaltea 							    ACP5X_MAX98388_DAI_NAME)));
367*dba22efdSCristian Ciocaltea 
368*dba22efdSCristian Ciocaltea static struct snd_soc_dai_link acp5x_8821_98388_dai[] = {
369*dba22efdSCristian Ciocaltea 	{
370*dba22efdSCristian Ciocaltea 		.name = "acp5x-8821-play",
371*dba22efdSCristian Ciocaltea 		.stream_name = "Playback/Capture",
372*dba22efdSCristian Ciocaltea 		.dai_fmt = SND_SOC_DAIFMT_I2S |
373*dba22efdSCristian Ciocaltea 			   SND_SOC_DAIFMT_NB_NF |
374*dba22efdSCristian Ciocaltea 			   SND_SOC_DAIFMT_CBC_CFC,
375*dba22efdSCristian Ciocaltea 		.dpcm_playback = 1,
376*dba22efdSCristian Ciocaltea 		.dpcm_capture = 1,
377*dba22efdSCristian Ciocaltea 		.ops = &acp5x_8821_ops,
378*dba22efdSCristian Ciocaltea 		.init = acp5x_8821_init,
379*dba22efdSCristian Ciocaltea 		SND_SOC_DAILINK_REG(acp5x_i2s, nau8821, platform),
380*dba22efdSCristian Ciocaltea 	},
381*dba22efdSCristian Ciocaltea 	{
382*dba22efdSCristian Ciocaltea 		.name = "acp5x-max98388-play",
383*dba22efdSCristian Ciocaltea 		.stream_name = "MAX98388 Playback",
384*dba22efdSCristian Ciocaltea 		.dai_fmt = SND_SOC_DAIFMT_I2S |
385*dba22efdSCristian Ciocaltea 			   SND_SOC_DAIFMT_NB_NF |
386*dba22efdSCristian Ciocaltea 			   SND_SOC_DAIFMT_CBC_CFC,
387*dba22efdSCristian Ciocaltea 		.dpcm_playback = 1,
388*dba22efdSCristian Ciocaltea 		.playback_only = 1,
389*dba22efdSCristian Ciocaltea 		.ops = &acp5x_max98388_play_ops,
390*dba22efdSCristian Ciocaltea 		SND_SOC_DAILINK_REG(acp5x_bt, max98388, platform),
391*dba22efdSCristian Ciocaltea 	},
392*dba22efdSCristian Ciocaltea };
393*dba22efdSCristian Ciocaltea 
394*dba22efdSCristian Ciocaltea static const struct snd_soc_dapm_widget acp5x_8821_98388_widgets[] = {
395*dba22efdSCristian Ciocaltea 	SND_SOC_DAPM_HP("Headphone", NULL),
396*dba22efdSCristian Ciocaltea 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
397*dba22efdSCristian Ciocaltea 	SND_SOC_DAPM_MIC("Int Mic", NULL),
398*dba22efdSCristian Ciocaltea 	SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
399*dba22efdSCristian Ciocaltea 			    platform_clock_control,
400*dba22efdSCristian Ciocaltea 			    SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
401*dba22efdSCristian Ciocaltea 	SND_SOC_DAPM_SPK("SPK", NULL),
402*dba22efdSCristian Ciocaltea };
403*dba22efdSCristian Ciocaltea 
404*dba22efdSCristian Ciocaltea static const struct snd_soc_dapm_route acp5x_8821_98388_route[] = {
405*dba22efdSCristian Ciocaltea 	{ "Headphone", NULL, "HPOL" },
406*dba22efdSCristian Ciocaltea 	{ "Headphone", NULL, "HPOR" },
407*dba22efdSCristian Ciocaltea 	{ "MICL", NULL, "Headset Mic" },
408*dba22efdSCristian Ciocaltea 	{ "MICR", NULL, "Headset Mic" },
409*dba22efdSCristian Ciocaltea 	{ "DMIC", NULL, "Int Mic" },
410*dba22efdSCristian Ciocaltea 
411*dba22efdSCristian Ciocaltea 	{ "Headphone", NULL, "Platform Clock" },
412*dba22efdSCristian Ciocaltea 	{ "Headset Mic", NULL, "Platform Clock" },
413*dba22efdSCristian Ciocaltea 	{ "Int Mic", NULL, "Platform Clock" },
414*dba22efdSCristian Ciocaltea 
415*dba22efdSCristian Ciocaltea 	{ "SPK", NULL, "Left BE_OUT" },
416*dba22efdSCristian Ciocaltea 	{ "SPK", NULL, "Right BE_OUT" },
417*dba22efdSCristian Ciocaltea };
418*dba22efdSCristian Ciocaltea 
419*dba22efdSCristian Ciocaltea static struct snd_soc_card acp5x_8821_98388_card = {
420*dba22efdSCristian Ciocaltea 	.name = "acp5x-max98388",
421*dba22efdSCristian Ciocaltea 	.owner = THIS_MODULE,
422*dba22efdSCristian Ciocaltea 	.dai_link = acp5x_8821_98388_dai,
423*dba22efdSCristian Ciocaltea 	.num_links = ARRAY_SIZE(acp5x_8821_98388_dai),
424*dba22efdSCristian Ciocaltea 	.dapm_widgets = acp5x_8821_98388_widgets,
425*dba22efdSCristian Ciocaltea 	.num_dapm_widgets = ARRAY_SIZE(acp5x_8821_98388_widgets),
426*dba22efdSCristian Ciocaltea 	.dapm_routes = acp5x_8821_98388_route,
427*dba22efdSCristian Ciocaltea 	.num_dapm_routes = ARRAY_SIZE(acp5x_8821_98388_route),
428*dba22efdSCristian Ciocaltea 	.codec_conf = acp5x_max98388_conf,
429*dba22efdSCristian Ciocaltea 	.num_configs = ARRAY_SIZE(acp5x_max98388_conf),
430*dba22efdSCristian Ciocaltea 	.controls = acp5x_8821_controls,
431*dba22efdSCristian Ciocaltea 	.num_controls = ARRAY_SIZE(acp5x_8821_controls),
432*dba22efdSCristian Ciocaltea };
433*dba22efdSCristian Ciocaltea 
43434a0094bSVijendar Mukunda static const struct dmi_system_id acp5x_vg_quirk_table[] = {
43534a0094bSVijendar Mukunda 	{
43634a0094bSVijendar Mukunda 		.matches = {
43734a0094bSVijendar Mukunda 			DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Valve"),
43834a0094bSVijendar Mukunda 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Jupiter"),
43934a0094bSVijendar Mukunda 		}
44034a0094bSVijendar Mukunda 	},
44134a0094bSVijendar Mukunda 	{}
44234a0094bSVijendar Mukunda };
44334a0094bSVijendar Mukunda 
44434a0094bSVijendar Mukunda static int acp5x_probe(struct platform_device *pdev)
44534a0094bSVijendar Mukunda {
4463dd26e27SCristian Ciocaltea 	const struct dmi_system_id *dmi_id;
44734a0094bSVijendar Mukunda 	struct acp5x_platform_info *machine;
448ddd42a12SLucas Tanure 	struct device *dev = &pdev->dev;
44934a0094bSVijendar Mukunda 	struct snd_soc_card *card;
450ddd42a12SLucas Tanure 	int ret;
45134a0094bSVijendar Mukunda 
452*dba22efdSCristian Ciocaltea 	card = (struct snd_soc_card *)device_get_match_data(dev);
453*dba22efdSCristian Ciocaltea 	if (!card) {
454*dba22efdSCristian Ciocaltea 		/*
455*dba22efdSCristian Ciocaltea 		 * This is normally the result of directly probing the driver
456*dba22efdSCristian Ciocaltea 		 * in pci-acp5x through platform_device_register_full(), which
457*dba22efdSCristian Ciocaltea 		 * is necessary for the CS35L41 variant, as it doesn't support
458*dba22efdSCristian Ciocaltea 		 * ACPI probing and relies on DMI quirks.
459*dba22efdSCristian Ciocaltea 		 */
4603dd26e27SCristian Ciocaltea 		dmi_id = dmi_first_match(acp5x_vg_quirk_table);
4613dd26e27SCristian Ciocaltea 		if (!dmi_id)
4623dd26e27SCristian Ciocaltea 			return -ENODEV;
4633dd26e27SCristian Ciocaltea 
4643dd26e27SCristian Ciocaltea 		card = &acp5x_8821_35l41_card;
465*dba22efdSCristian Ciocaltea 	}
4663dd26e27SCristian Ciocaltea 
46750e81116SLucas Tanure 	machine = devm_kzalloc(dev, sizeof(*machine), GFP_KERNEL);
46834a0094bSVijendar Mukunda 	if (!machine)
46934a0094bSVijendar Mukunda 		return -ENOMEM;
47034a0094bSVijendar Mukunda 
471ddd42a12SLucas Tanure 	card->dev = dev;
47234a0094bSVijendar Mukunda 	platform_set_drvdata(pdev, card);
47334a0094bSVijendar Mukunda 	snd_soc_card_set_drvdata(card, machine);
47434a0094bSVijendar Mukunda 
475ddd42a12SLucas Tanure 	ret = devm_snd_soc_register_card(dev, card);
476ddd42a12SLucas Tanure 	if (ret)
477ddd42a12SLucas Tanure 		return dev_err_probe(dev, ret, "Register card (%s) failed\n", card->name);
478ddd42a12SLucas Tanure 
47934a0094bSVijendar Mukunda 	return 0;
48034a0094bSVijendar Mukunda }
48134a0094bSVijendar Mukunda 
482*dba22efdSCristian Ciocaltea static const struct acpi_device_id acp5x_acpi_match[] = {
483*dba22efdSCristian Ciocaltea 	{ "AMDI8821", (kernel_ulong_t)&acp5x_8821_98388_card },
484*dba22efdSCristian Ciocaltea 	{},
485*dba22efdSCristian Ciocaltea };
486*dba22efdSCristian Ciocaltea MODULE_DEVICE_TABLE(acpi, acp5x_acpi_match);
487*dba22efdSCristian Ciocaltea 
48834a0094bSVijendar Mukunda static struct platform_driver acp5x_mach_driver = {
48934a0094bSVijendar Mukunda 	.driver = {
490a0cb05cbSCristian Ciocaltea 		.name = DRV_NAME,
49134a0094bSVijendar Mukunda 		.pm = &snd_soc_pm_ops,
492*dba22efdSCristian Ciocaltea 		.acpi_match_table = acp5x_acpi_match,
49334a0094bSVijendar Mukunda 	},
49434a0094bSVijendar Mukunda 	.probe = acp5x_probe,
49534a0094bSVijendar Mukunda };
49634a0094bSVijendar Mukunda 
49734a0094bSVijendar Mukunda module_platform_driver(acp5x_mach_driver);
49834a0094bSVijendar Mukunda 
49934a0094bSVijendar Mukunda MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
500*dba22efdSCristian Ciocaltea MODULE_DESCRIPTION("NAU8821/CS35L41 & NAU8821/MAX98388 audio support");
50134a0094bSVijendar Mukunda MODULE_LICENSE("GPL v2");
50234a0094bSVijendar Mukunda MODULE_ALIAS("platform:" DRV_NAME);
503