xref: /linux/sound/soc/amd/vangogh/acp5x-mach.c (revision 0c38cc1dd17e766eada0aa44be4c1a47bcbb7bc3)
134a0094bSVijendar Mukunda // SPDX-License-Identifier: GPL-2.0+
234a0094bSVijendar Mukunda /*
334a0094bSVijendar Mukunda  * Machine driver for AMD Vangogh platform using NAU8821 & CS35L41
434a0094bSVijendar Mukunda  * codecs.
534a0094bSVijendar Mukunda  *
634a0094bSVijendar Mukunda  * Copyright 2021 Advanced Micro Devices, Inc.
734a0094bSVijendar Mukunda  */
834a0094bSVijendar Mukunda 
934a0094bSVijendar Mukunda #include <sound/soc.h>
1034a0094bSVijendar Mukunda #include <sound/soc-dapm.h>
1134a0094bSVijendar Mukunda #include <linux/module.h>
1234a0094bSVijendar Mukunda #include <linux/io.h>
1334a0094bSVijendar Mukunda #include <sound/pcm.h>
1434a0094bSVijendar Mukunda #include <sound/pcm_params.h>
1534a0094bSVijendar Mukunda 
1634a0094bSVijendar Mukunda #include <sound/jack.h>
1734a0094bSVijendar Mukunda #include <linux/clk.h>
1834a0094bSVijendar Mukunda #include <linux/gpio.h>
1934a0094bSVijendar Mukunda #include <linux/gpio/consumer.h>
2034a0094bSVijendar Mukunda #include <linux/module.h>
2134a0094bSVijendar Mukunda #include <linux/i2c.h>
2234a0094bSVijendar Mukunda #include <linux/input.h>
2334a0094bSVijendar Mukunda #include <linux/io.h>
2434a0094bSVijendar Mukunda #include <linux/acpi.h>
2534a0094bSVijendar Mukunda #include <linux/dmi.h>
2634a0094bSVijendar Mukunda 
2734a0094bSVijendar Mukunda #include "../../codecs/nau8821.h"
2834a0094bSVijendar Mukunda #include "../../codecs/cs35l41.h"
2934a0094bSVijendar Mukunda 
3034a0094bSVijendar Mukunda #include "acp5x.h"
3134a0094bSVijendar Mukunda 
3234a0094bSVijendar Mukunda #define DRV_NAME "acp5x_mach"
3334a0094bSVijendar Mukunda #define DUAL_CHANNEL		2
3434a0094bSVijendar Mukunda #define ACP5X_NUVOTON_CODEC_DAI	"nau8821-hifi"
3534a0094bSVijendar Mukunda #define VG_JUPITER 1
369a617f0eSVijendar Mukunda #define ACP5X_NUVOTON_BCLK 3072000
379a617f0eSVijendar Mukunda #define ACP5X_NAU8821_FREQ_OUT 12288000
3834a0094bSVijendar Mukunda 
3934a0094bSVijendar Mukunda static unsigned long acp5x_machine_id;
4034a0094bSVijendar Mukunda static struct snd_soc_jack vg_headset;
4134a0094bSVijendar Mukunda 
4234a0094bSVijendar Mukunda static struct snd_soc_jack_pin acp5x_nau8821_jack_pins[] = {
4334a0094bSVijendar Mukunda 	{
4434a0094bSVijendar Mukunda 		.pin	= "Headphone",
4534a0094bSVijendar Mukunda 		.mask	= SND_JACK_HEADPHONE,
4634a0094bSVijendar Mukunda 	},
4734a0094bSVijendar Mukunda 	{
4834a0094bSVijendar Mukunda 		.pin	= "Headset Mic",
4934a0094bSVijendar Mukunda 		.mask	= SND_JACK_MICROPHONE,
5034a0094bSVijendar Mukunda 	},
5134a0094bSVijendar Mukunda };
5234a0094bSVijendar Mukunda 
5334a0094bSVijendar Mukunda static int acp5x_8821_init(struct snd_soc_pcm_runtime *rtd)
5434a0094bSVijendar Mukunda {
5534a0094bSVijendar Mukunda 	int ret;
5634a0094bSVijendar Mukunda 	struct snd_soc_card *card = rtd->card;
5734a0094bSVijendar Mukunda 	struct snd_soc_component *component =
5834a0094bSVijendar Mukunda 					asoc_rtd_to_codec(rtd, 0)->component;
5934a0094bSVijendar Mukunda 
6034a0094bSVijendar Mukunda 	/*
6134a0094bSVijendar Mukunda 	 * Headset buttons map to the google Reference headset.
6234a0094bSVijendar Mukunda 	 * These can be configured by userspace.
6334a0094bSVijendar Mukunda 	 */
6434a0094bSVijendar Mukunda 	ret = snd_soc_card_jack_new(card, "Headset Jack",
6534a0094bSVijendar Mukunda 				    SND_JACK_HEADSET | SND_JACK_BTN_0,
6634a0094bSVijendar Mukunda 				    &vg_headset, acp5x_nau8821_jack_pins,
6734a0094bSVijendar Mukunda 				    ARRAY_SIZE(acp5x_nau8821_jack_pins));
6834a0094bSVijendar Mukunda 	if (ret) {
6934a0094bSVijendar Mukunda 		dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
7034a0094bSVijendar Mukunda 		return ret;
7134a0094bSVijendar Mukunda 	}
7234a0094bSVijendar Mukunda 
7334a0094bSVijendar Mukunda 	snd_jack_set_key(vg_headset.jack, SND_JACK_BTN_0, KEY_MEDIA);
7434a0094bSVijendar Mukunda 	nau8821_enable_jack_detect(component, &vg_headset);
7534a0094bSVijendar Mukunda 	return ret;
7634a0094bSVijendar Mukunda }
7734a0094bSVijendar Mukunda 
7834a0094bSVijendar Mukunda static int acp5x_cs35l41_init(struct snd_soc_pcm_runtime *rtd)
7934a0094bSVijendar Mukunda {
8034a0094bSVijendar Mukunda 	return 0;
8134a0094bSVijendar Mukunda }
8234a0094bSVijendar Mukunda 
8334a0094bSVijendar Mukunda static const unsigned int rates[] = {
8434a0094bSVijendar Mukunda 	48000,
8534a0094bSVijendar Mukunda };
8634a0094bSVijendar Mukunda 
8734a0094bSVijendar Mukunda static const struct snd_pcm_hw_constraint_list constraints_rates = {
8834a0094bSVijendar Mukunda 	.count = ARRAY_SIZE(rates),
8934a0094bSVijendar Mukunda 	.list  = rates,
9034a0094bSVijendar Mukunda 	.mask = 0,
9134a0094bSVijendar Mukunda };
9234a0094bSVijendar Mukunda 
9334a0094bSVijendar Mukunda static const unsigned int channels[] = {
9434a0094bSVijendar Mukunda 	2,
9534a0094bSVijendar Mukunda };
9634a0094bSVijendar Mukunda 
9734a0094bSVijendar Mukunda static const struct snd_pcm_hw_constraint_list constraints_channels = {
9834a0094bSVijendar Mukunda 	.count = ARRAY_SIZE(channels),
9934a0094bSVijendar Mukunda 	.list = channels,
10034a0094bSVijendar Mukunda 	.mask = 0,
10134a0094bSVijendar Mukunda };
10234a0094bSVijendar Mukunda 
103*0c38cc1dSVijendar Mukunda static const unsigned int acp5x_nau8821_format[] = {32};
104*0c38cc1dSVijendar Mukunda 
105*0c38cc1dSVijendar Mukunda static struct snd_pcm_hw_constraint_list constraints_sample_bits = {
106*0c38cc1dSVijendar Mukunda 	.list = acp5x_nau8821_format,
107*0c38cc1dSVijendar Mukunda 	.count = ARRAY_SIZE(acp5x_nau8821_format),
108*0c38cc1dSVijendar Mukunda };
109*0c38cc1dSVijendar Mukunda 
11034a0094bSVijendar Mukunda static int acp5x_8821_startup(struct snd_pcm_substream *substream)
11134a0094bSVijendar Mukunda {
11234a0094bSVijendar Mukunda 	struct snd_pcm_runtime *runtime = substream->runtime;
11334a0094bSVijendar Mukunda 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
11434a0094bSVijendar Mukunda 	struct snd_soc_card *card = rtd->card;
11534a0094bSVijendar Mukunda 	struct acp5x_platform_info *machine = snd_soc_card_get_drvdata(card);
11634a0094bSVijendar Mukunda 
11734a0094bSVijendar Mukunda 	machine->play_i2s_instance = I2S_SP_INSTANCE;
11834a0094bSVijendar Mukunda 	machine->cap_i2s_instance = I2S_SP_INSTANCE;
11934a0094bSVijendar Mukunda 
12034a0094bSVijendar Mukunda 	runtime->hw.channels_max = DUAL_CHANNEL;
12134a0094bSVijendar Mukunda 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
12234a0094bSVijendar Mukunda 				   &constraints_channels);
12334a0094bSVijendar Mukunda 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
12434a0094bSVijendar Mukunda 				   &constraints_rates);
125*0c38cc1dSVijendar Mukunda 	snd_pcm_hw_constraint_list(substream->runtime, 0,
126*0c38cc1dSVijendar Mukunda 				   SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
127*0c38cc1dSVijendar Mukunda 				   &constraints_sample_bits);
12834a0094bSVijendar Mukunda 	return 0;
12934a0094bSVijendar Mukunda }
13034a0094bSVijendar Mukunda 
13134a0094bSVijendar Mukunda static int acp5x_nau8821_hw_params(struct snd_pcm_substream *substream,
13234a0094bSVijendar Mukunda 				   struct snd_pcm_hw_params *params)
13334a0094bSVijendar Mukunda {
13434a0094bSVijendar Mukunda 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
13534a0094bSVijendar Mukunda 	struct snd_soc_card *card = rtd->card;
13634a0094bSVijendar Mukunda 	struct snd_soc_dai *codec_dai =
13734a0094bSVijendar Mukunda 			snd_soc_card_get_codec_dai(card,
13834a0094bSVijendar Mukunda 						   ACP5X_NUVOTON_CODEC_DAI);
13934a0094bSVijendar Mukunda 	int ret;
14034a0094bSVijendar Mukunda 
14134a0094bSVijendar Mukunda 	ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_FLL_BLK, 0,
14234a0094bSVijendar Mukunda 				     SND_SOC_CLOCK_IN);
14334a0094bSVijendar Mukunda 	if (ret < 0)
14434a0094bSVijendar Mukunda 		dev_err(card->dev, "can't set FS clock %d\n", ret);
14534a0094bSVijendar Mukunda 	ret = snd_soc_dai_set_pll(codec_dai, 0, 0, snd_soc_params_to_bclk(params),
14634a0094bSVijendar Mukunda 				  params_rate(params) * 256);
14734a0094bSVijendar Mukunda 	if (ret < 0)
14834a0094bSVijendar Mukunda 		dev_err(card->dev, "can't set FLL: %d\n", ret);
14934a0094bSVijendar Mukunda 
15034a0094bSVijendar Mukunda 	return ret;
15134a0094bSVijendar Mukunda }
15234a0094bSVijendar Mukunda 
15334a0094bSVijendar Mukunda static int acp5x_cs35l41_startup(struct snd_pcm_substream *substream)
15434a0094bSVijendar Mukunda {
15534a0094bSVijendar Mukunda 	struct snd_pcm_runtime *runtime = substream->runtime;
15634a0094bSVijendar Mukunda 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
15734a0094bSVijendar Mukunda 	struct snd_soc_card *card = rtd->card;
15834a0094bSVijendar Mukunda 	struct acp5x_platform_info *machine = snd_soc_card_get_drvdata(card);
15934a0094bSVijendar Mukunda 
16034a0094bSVijendar Mukunda 	machine->play_i2s_instance = I2S_HS_INSTANCE;
16134a0094bSVijendar Mukunda 
16234a0094bSVijendar Mukunda 	runtime->hw.channels_max = DUAL_CHANNEL;
16334a0094bSVijendar Mukunda 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
16434a0094bSVijendar Mukunda 				   &constraints_channels);
16534a0094bSVijendar Mukunda 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
16634a0094bSVijendar Mukunda 				   &constraints_rates);
16734a0094bSVijendar Mukunda 	return 0;
16834a0094bSVijendar Mukunda }
16934a0094bSVijendar Mukunda 
17034a0094bSVijendar Mukunda static int acp5x_cs35l41_hw_params(struct snd_pcm_substream *substream,
17134a0094bSVijendar Mukunda 				   struct snd_pcm_hw_params *params)
17234a0094bSVijendar Mukunda {
17334a0094bSVijendar Mukunda 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
17434a0094bSVijendar Mukunda 	struct snd_soc_card *card = rtd->card;
17534a0094bSVijendar Mukunda 	struct snd_soc_dai *codec_dai;
17634a0094bSVijendar Mukunda 	int ret, i;
17734a0094bSVijendar Mukunda 	unsigned int num_codecs = rtd->num_codecs;
17834a0094bSVijendar Mukunda 	unsigned int bclk_val;
17934a0094bSVijendar Mukunda 
18034a0094bSVijendar Mukunda 	for (i = 0; i < num_codecs; i++) {
18134a0094bSVijendar Mukunda 		codec_dai = asoc_rtd_to_codec(rtd, i);
18234a0094bSVijendar Mukunda 		if ((strcmp(codec_dai->name, "spi-VLV1776:00") == 0) ||
18334a0094bSVijendar Mukunda 		    (strcmp(codec_dai->name, "spi-VLV1776:01") == 0)) {
18434a0094bSVijendar Mukunda 			switch (params_rate(params)) {
18534a0094bSVijendar Mukunda 			case 48000:
18634a0094bSVijendar Mukunda 				bclk_val = 1536000;
18734a0094bSVijendar Mukunda 				break;
18834a0094bSVijendar Mukunda 			default:
18934a0094bSVijendar Mukunda 				dev_err(card->dev, "Invalid Samplerate:0x%x\n",
19034a0094bSVijendar Mukunda 					params_rate(params));
19134a0094bSVijendar Mukunda 				return -EINVAL;
19234a0094bSVijendar Mukunda 			}
19334a0094bSVijendar Mukunda 			ret = snd_soc_component_set_sysclk(codec_dai->component,
19434a0094bSVijendar Mukunda 							   0, 0, bclk_val, SND_SOC_CLOCK_IN);
19534a0094bSVijendar Mukunda 			if (ret < 0) {
19634a0094bSVijendar Mukunda 				dev_err(card->dev, "failed to set sysclk for CS35l41 dai\n");
19734a0094bSVijendar Mukunda 				return ret;
19834a0094bSVijendar Mukunda 			}
19934a0094bSVijendar Mukunda 		}
20034a0094bSVijendar Mukunda 	}
20134a0094bSVijendar Mukunda 
20234a0094bSVijendar Mukunda 	return ret;
20334a0094bSVijendar Mukunda }
20434a0094bSVijendar Mukunda 
20534a0094bSVijendar Mukunda static const struct snd_soc_ops acp5x_8821_ops = {
20634a0094bSVijendar Mukunda 	.startup = acp5x_8821_startup,
20734a0094bSVijendar Mukunda 	.hw_params = acp5x_nau8821_hw_params,
20834a0094bSVijendar Mukunda };
20934a0094bSVijendar Mukunda 
21034a0094bSVijendar Mukunda static const struct snd_soc_ops acp5x_cs35l41_play_ops = {
21134a0094bSVijendar Mukunda 	.startup = acp5x_cs35l41_startup,
21234a0094bSVijendar Mukunda 	.hw_params = acp5x_cs35l41_hw_params,
21334a0094bSVijendar Mukunda };
21434a0094bSVijendar Mukunda 
21534a0094bSVijendar Mukunda static struct snd_soc_codec_conf cs35l41_conf[] = {
21634a0094bSVijendar Mukunda 	{
21734a0094bSVijendar Mukunda 		.dlc = COMP_CODEC_CONF("spi-VLV1776:00"),
21834a0094bSVijendar Mukunda 		.name_prefix = "Left",
21934a0094bSVijendar Mukunda 	},
22034a0094bSVijendar Mukunda 	{
22134a0094bSVijendar Mukunda 		.dlc = COMP_CODEC_CONF("spi-VLV1776:01"),
22234a0094bSVijendar Mukunda 		.name_prefix = "Right",
22334a0094bSVijendar Mukunda 	},
22434a0094bSVijendar Mukunda };
22534a0094bSVijendar Mukunda 
22634a0094bSVijendar Mukunda SND_SOC_DAILINK_DEF(acp5x_i2s,
22734a0094bSVijendar Mukunda 		    DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.0")));
22834a0094bSVijendar Mukunda 
22934a0094bSVijendar Mukunda SND_SOC_DAILINK_DEF(acp5x_bt,
23034a0094bSVijendar Mukunda 		    DAILINK_COMP_ARRAY(COMP_CPU("acp5x_i2s_playcap.1")));
23134a0094bSVijendar Mukunda 
23234a0094bSVijendar Mukunda SND_SOC_DAILINK_DEF(nau8821,
23334a0094bSVijendar Mukunda 		    DAILINK_COMP_ARRAY(COMP_CODEC("i2c-NVTN2020:00",
23434a0094bSVijendar Mukunda 						  "nau8821-hifi")));
23534a0094bSVijendar Mukunda 
23634a0094bSVijendar Mukunda SND_SOC_DAILINK_DEF(cs35l41,
23734a0094bSVijendar Mukunda 		    DAILINK_COMP_ARRAY(COMP_CODEC("spi-VLV1776:00", "cs35l41-pcm"),
23834a0094bSVijendar Mukunda 				       COMP_CODEC("spi-VLV1776:01", "cs35l41-pcm")));
23934a0094bSVijendar Mukunda 
24034a0094bSVijendar Mukunda SND_SOC_DAILINK_DEF(platform,
24134a0094bSVijendar Mukunda 		    DAILINK_COMP_ARRAY(COMP_PLATFORM("acp5x_i2s_dma.0")));
24234a0094bSVijendar Mukunda 
24334a0094bSVijendar Mukunda static struct snd_soc_dai_link acp5x_dai[] = {
24434a0094bSVijendar Mukunda 	{
24534a0094bSVijendar Mukunda 		.name = "acp5x-8825-play",
24634a0094bSVijendar Mukunda 		.stream_name = "Playback/Capture",
24734a0094bSVijendar Mukunda 		.dai_fmt = SND_SOC_DAIFMT_I2S  | SND_SOC_DAIFMT_NB_NF |
24834a0094bSVijendar Mukunda 			   SND_SOC_DAIFMT_CBC_CFC,
24934a0094bSVijendar Mukunda 		.dpcm_playback = 1,
25034a0094bSVijendar Mukunda 		.dpcm_capture = 1,
25134a0094bSVijendar Mukunda 		.ops = &acp5x_8821_ops,
25234a0094bSVijendar Mukunda 		.init = acp5x_8821_init,
25334a0094bSVijendar Mukunda 		SND_SOC_DAILINK_REG(acp5x_i2s, nau8821, platform),
25434a0094bSVijendar Mukunda 	},
25534a0094bSVijendar Mukunda 	{
25634a0094bSVijendar Mukunda 		.name = "acp5x-CS35L41-Stereo",
25734a0094bSVijendar Mukunda 		.stream_name = "CS35L41 Stereo Playback",
25834a0094bSVijendar Mukunda 		.dai_fmt = SND_SOC_DAIFMT_I2S  | SND_SOC_DAIFMT_NB_NF |
25934a0094bSVijendar Mukunda 			   SND_SOC_DAIFMT_CBC_CFC,
26034a0094bSVijendar Mukunda 		.dpcm_playback = 1,
26134a0094bSVijendar Mukunda 		.playback_only = 1,
26234a0094bSVijendar Mukunda 		.ops = &acp5x_cs35l41_play_ops,
26334a0094bSVijendar Mukunda 		.init = acp5x_cs35l41_init,
26434a0094bSVijendar Mukunda 		SND_SOC_DAILINK_REG(acp5x_bt, cs35l41, platform),
26534a0094bSVijendar Mukunda 	},
26634a0094bSVijendar Mukunda };
26734a0094bSVijendar Mukunda 
26834a0094bSVijendar Mukunda static int platform_clock_control(struct snd_soc_dapm_widget *w,
26934a0094bSVijendar Mukunda 				  struct snd_kcontrol *k, int  event)
27034a0094bSVijendar Mukunda {
27134a0094bSVijendar Mukunda 	struct snd_soc_dapm_context *dapm = w->dapm;
27234a0094bSVijendar Mukunda 	struct snd_soc_card *card = dapm->card;
27334a0094bSVijendar Mukunda 	struct snd_soc_dai *codec_dai;
27434a0094bSVijendar Mukunda 	int ret = 0;
27534a0094bSVijendar Mukunda 
27634a0094bSVijendar Mukunda 	codec_dai = snd_soc_card_get_codec_dai(card, ACP5X_NUVOTON_CODEC_DAI);
27734a0094bSVijendar Mukunda 	if (!codec_dai) {
27834a0094bSVijendar Mukunda 		dev_err(card->dev, "Codec dai not found\n");
27934a0094bSVijendar Mukunda 		return -EIO;
28034a0094bSVijendar Mukunda 	}
28134a0094bSVijendar Mukunda 
28234a0094bSVijendar Mukunda 	if (SND_SOC_DAPM_EVENT_OFF(event)) {
28334a0094bSVijendar Mukunda 		ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_INTERNAL,
28434a0094bSVijendar Mukunda 					     0, SND_SOC_CLOCK_IN);
28534a0094bSVijendar Mukunda 		if (ret < 0) {
28634a0094bSVijendar Mukunda 			dev_err(card->dev, "set sysclk err = %d\n", ret);
28734a0094bSVijendar Mukunda 			return -EIO;
28834a0094bSVijendar Mukunda 		}
2899a617f0eSVijendar Mukunda 	} else {
2909a617f0eSVijendar Mukunda 		ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_FLL_BLK, 0,
2919a617f0eSVijendar Mukunda 					     SND_SOC_CLOCK_IN);
2929a617f0eSVijendar Mukunda 		if (ret < 0)
2939a617f0eSVijendar Mukunda 			dev_err(codec_dai->dev, "can't set BLK clock %d\n", ret);
2949a617f0eSVijendar Mukunda 		ret = snd_soc_dai_set_pll(codec_dai, 0, 0, ACP5X_NUVOTON_BCLK,
2959a617f0eSVijendar Mukunda 					  ACP5X_NAU8821_FREQ_OUT);
2969a617f0eSVijendar Mukunda 		if (ret < 0)
2979a617f0eSVijendar Mukunda 			dev_err(codec_dai->dev, "can't set FLL: %d\n", ret);
29834a0094bSVijendar Mukunda 	}
29934a0094bSVijendar Mukunda 	return ret;
30034a0094bSVijendar Mukunda }
30134a0094bSVijendar Mukunda 
30234a0094bSVijendar Mukunda static const struct snd_kcontrol_new acp5x_8821_controls[] = {
30334a0094bSVijendar Mukunda 	SOC_DAPM_PIN_SWITCH("Headphone"),
30434a0094bSVijendar Mukunda 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
30534a0094bSVijendar Mukunda 	SOC_DAPM_PIN_SWITCH("Int Mic"),
30634a0094bSVijendar Mukunda };
30734a0094bSVijendar Mukunda 
30834a0094bSVijendar Mukunda static const struct snd_soc_dapm_widget acp5x_8821_widgets[] = {
30934a0094bSVijendar Mukunda 	SND_SOC_DAPM_HP("Headphone", NULL),
31034a0094bSVijendar Mukunda 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
31134a0094bSVijendar Mukunda 	SND_SOC_DAPM_MIC("Int Mic", NULL),
31234a0094bSVijendar Mukunda 	SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
3139a617f0eSVijendar Mukunda 			    platform_clock_control, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
31434a0094bSVijendar Mukunda };
31534a0094bSVijendar Mukunda 
31634a0094bSVijendar Mukunda static const struct snd_soc_dapm_route acp5x_8821_audio_route[] = {
31734a0094bSVijendar Mukunda 	/* HP jack connectors - unknown if we have jack detection */
31834a0094bSVijendar Mukunda 	{ "Headphone", NULL, "HPOL" },
31934a0094bSVijendar Mukunda 	{ "Headphone", NULL, "HPOR" },
32034a0094bSVijendar Mukunda 	{ "MICL", NULL, "Headset Mic" },
32134a0094bSVijendar Mukunda 	{ "MICR", NULL, "Headset Mic" },
32234a0094bSVijendar Mukunda 	{ "DMIC", NULL, "Int Mic" },
32334a0094bSVijendar Mukunda 
32434a0094bSVijendar Mukunda 	{ "Headphone", NULL, "Platform Clock" },
32534a0094bSVijendar Mukunda 	{ "Headset Mic", NULL, "Platform Clock" },
32634a0094bSVijendar Mukunda 	{ "Int Mic", NULL, "Platform Clock" },
32734a0094bSVijendar Mukunda };
32834a0094bSVijendar Mukunda 
32934a0094bSVijendar Mukunda static struct snd_soc_card acp5x_card = {
33034a0094bSVijendar Mukunda 	.name = "acp5x",
33134a0094bSVijendar Mukunda 	.owner = THIS_MODULE,
33234a0094bSVijendar Mukunda 	.dai_link = acp5x_dai,
33334a0094bSVijendar Mukunda 	.num_links = ARRAY_SIZE(acp5x_dai),
33434a0094bSVijendar Mukunda 	.dapm_widgets = acp5x_8821_widgets,
33534a0094bSVijendar Mukunda 	.num_dapm_widgets = ARRAY_SIZE(acp5x_8821_widgets),
33634a0094bSVijendar Mukunda 	.dapm_routes = acp5x_8821_audio_route,
33734a0094bSVijendar Mukunda 	.num_dapm_routes = ARRAY_SIZE(acp5x_8821_audio_route),
33834a0094bSVijendar Mukunda 	.codec_conf = cs35l41_conf,
33934a0094bSVijendar Mukunda 	.num_configs = ARRAY_SIZE(cs35l41_conf),
34034a0094bSVijendar Mukunda 	.controls = acp5x_8821_controls,
34134a0094bSVijendar Mukunda 	.num_controls = ARRAY_SIZE(acp5x_8821_controls),
34234a0094bSVijendar Mukunda };
34334a0094bSVijendar Mukunda 
34434a0094bSVijendar Mukunda 
34534a0094bSVijendar Mukunda static int acp5x_vg_quirk_cb(const struct dmi_system_id *id)
34634a0094bSVijendar Mukunda {
34734a0094bSVijendar Mukunda 	acp5x_machine_id = VG_JUPITER;
34834a0094bSVijendar Mukunda 	return 1;
34934a0094bSVijendar Mukunda }
35034a0094bSVijendar Mukunda 
35134a0094bSVijendar Mukunda static const struct dmi_system_id acp5x_vg_quirk_table[] = {
35234a0094bSVijendar Mukunda 	{
35334a0094bSVijendar Mukunda 		.callback = acp5x_vg_quirk_cb,
35434a0094bSVijendar Mukunda 		.matches = {
35534a0094bSVijendar Mukunda 			DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Valve"),
35634a0094bSVijendar Mukunda 			DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Jupiter"),
35734a0094bSVijendar Mukunda 		}
35834a0094bSVijendar Mukunda 	},
35934a0094bSVijendar Mukunda 	{}
36034a0094bSVijendar Mukunda };
36134a0094bSVijendar Mukunda 
36234a0094bSVijendar Mukunda static int acp5x_probe(struct platform_device *pdev)
36334a0094bSVijendar Mukunda {
36434a0094bSVijendar Mukunda 	int ret;
36534a0094bSVijendar Mukunda 	struct acp5x_platform_info *machine;
36634a0094bSVijendar Mukunda 	struct snd_soc_card *card;
36734a0094bSVijendar Mukunda 
36834a0094bSVijendar Mukunda 	machine = devm_kzalloc(&pdev->dev, sizeof(struct acp5x_platform_info),
36934a0094bSVijendar Mukunda 			       GFP_KERNEL);
37034a0094bSVijendar Mukunda 	if (!machine)
37134a0094bSVijendar Mukunda 		return -ENOMEM;
37234a0094bSVijendar Mukunda 
37334a0094bSVijendar Mukunda 	dmi_check_system(acp5x_vg_quirk_table);
37434a0094bSVijendar Mukunda 	switch(acp5x_machine_id) {
37534a0094bSVijendar Mukunda 	case VG_JUPITER:
37634a0094bSVijendar Mukunda 		card = &acp5x_card;
37734a0094bSVijendar Mukunda 		acp5x_card.dev = &pdev->dev;
37834a0094bSVijendar Mukunda 		break;
37934a0094bSVijendar Mukunda 	default:
38034a0094bSVijendar Mukunda 		return -ENODEV;
38134a0094bSVijendar Mukunda 	}
38234a0094bSVijendar Mukunda 	platform_set_drvdata(pdev, card);
38334a0094bSVijendar Mukunda 	snd_soc_card_set_drvdata(card, machine);
38434a0094bSVijendar Mukunda 
38534a0094bSVijendar Mukunda 	ret = devm_snd_soc_register_card(&pdev->dev, card);
38634a0094bSVijendar Mukunda 	if (ret) {
38734a0094bSVijendar Mukunda 		return dev_err_probe(&pdev->dev, ret,
38834a0094bSVijendar Mukunda 				     "snd_soc_register_card(%s) failed\n",
38934a0094bSVijendar Mukunda 				     acp5x_card.name);
39034a0094bSVijendar Mukunda 	}
39134a0094bSVijendar Mukunda 	return 0;
39234a0094bSVijendar Mukunda }
39334a0094bSVijendar Mukunda 
39434a0094bSVijendar Mukunda static struct platform_driver acp5x_mach_driver = {
39534a0094bSVijendar Mukunda 	.driver = {
39634a0094bSVijendar Mukunda 		.name = "acp5x_mach",
39734a0094bSVijendar Mukunda 		.pm = &snd_soc_pm_ops,
39834a0094bSVijendar Mukunda 	},
39934a0094bSVijendar Mukunda 	.probe = acp5x_probe,
40034a0094bSVijendar Mukunda };
40134a0094bSVijendar Mukunda 
40234a0094bSVijendar Mukunda module_platform_driver(acp5x_mach_driver);
40334a0094bSVijendar Mukunda 
40434a0094bSVijendar Mukunda MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
40534a0094bSVijendar Mukunda MODULE_DESCRIPTION("NAU8821 & CS35L41 audio support");
40634a0094bSVijendar Mukunda MODULE_LICENSE("GPL v2");
40734a0094bSVijendar Mukunda MODULE_ALIAS("platform:" DRV_NAME);
408