134a0094bSVijendar Mukunda // SPDX-License-Identifier: GPL-2.0+ 234a0094bSVijendar Mukunda /* 3dba22efdSCristian Ciocaltea * Machine driver for AMD Vangogh platform using either 4dba22efdSCristian 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" 32dba22efdSCristian Ciocaltea #define ACP5X_MAX98388_COMP_LNAME "i2c-ADS8388:00" 33dba22efdSCristian Ciocaltea #define ACP5X_MAX98388_COMP_RNAME "i2c-ADS8388:01" 34dba22efdSCristian 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 { 95d4f23dcdSKuninori Morimoto struct snd_soc_component *component = snd_soc_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; 147d4f23dcdSKuninori Morimoto struct snd_soc_pcm_runtime *rtd = snd_soc_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 { 168d4f23dcdSKuninori Morimoto struct snd_soc_pcm_runtime *rtd = snd_soc_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 173871861f6SPierre-Louis Bossart if (!dai) 174871861f6SPierre-Louis Bossart return -EINVAL; 175871861f6SPierre-Louis Bossart 176ddd42a12SLucas Tanure ret = snd_soc_dai_set_sysclk(dai, NAU8821_CLK_FLL_BLK, 0, SND_SOC_CLOCK_IN); 17734a0094bSVijendar Mukunda if (ret < 0) 17834a0094bSVijendar Mukunda dev_err(card->dev, "can't set FS clock %d\n", ret); 1799490fbb8SLucas Tanure 1809490fbb8SLucas Tanure bclk = snd_soc_params_to_bclk(params); 1819490fbb8SLucas Tanure if (bclk < 0) { 1829490fbb8SLucas Tanure dev_err(dai->dev, "Fail to get BCLK rate: %d\n", bclk); 1839490fbb8SLucas Tanure return bclk; 1849490fbb8SLucas Tanure } 1859490fbb8SLucas Tanure 1869490fbb8SLucas Tanure ret = snd_soc_dai_set_pll(dai, 0, 0, bclk, params_rate(params) * 256); 18734a0094bSVijendar Mukunda if (ret < 0) 18834a0094bSVijendar Mukunda dev_err(card->dev, "can't set FLL: %d\n", ret); 18934a0094bSVijendar Mukunda 19034a0094bSVijendar Mukunda return ret; 19134a0094bSVijendar Mukunda } 19234a0094bSVijendar Mukunda 193ab89aa0dSLucas Tanure static const struct snd_soc_ops acp5x_8821_ops = { 194ab89aa0dSLucas Tanure .startup = acp5x_8821_startup, 195ab89aa0dSLucas Tanure .hw_params = acp5x_nau8821_hw_params, 196ab89aa0dSLucas Tanure }; 197ab89aa0dSLucas Tanure 19834a0094bSVijendar Mukunda static int acp5x_cs35l41_startup(struct snd_pcm_substream *substream) 19934a0094bSVijendar Mukunda { 200d4f23dcdSKuninori Morimoto struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 201ddd42a12SLucas Tanure struct acp5x_platform_info *machine = snd_soc_card_get_drvdata(rtd->card); 202ddd42a12SLucas Tanure struct snd_pcm_runtime *runtime = substream->runtime; 20334a0094bSVijendar Mukunda 20434a0094bSVijendar Mukunda machine->play_i2s_instance = I2S_HS_INSTANCE; 20534a0094bSVijendar Mukunda 20634a0094bSVijendar Mukunda runtime->hw.channels_max = DUAL_CHANNEL; 20734a0094bSVijendar Mukunda snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 20834a0094bSVijendar Mukunda &constraints_channels); 20934a0094bSVijendar Mukunda snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 21034a0094bSVijendar Mukunda &constraints_rates); 211ddd42a12SLucas Tanure 21234a0094bSVijendar Mukunda return 0; 21334a0094bSVijendar Mukunda } 21434a0094bSVijendar Mukunda 21534a0094bSVijendar Mukunda static int acp5x_cs35l41_hw_params(struct snd_pcm_substream *substream, 21634a0094bSVijendar Mukunda struct snd_pcm_hw_params *params) 21734a0094bSVijendar Mukunda { 218d4f23dcdSKuninori Morimoto struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 219a719afe6SLucas Tanure unsigned int bclk, rate = params_rate(params); 220a719afe6SLucas Tanure struct snd_soc_component *comp; 221ddd42a12SLucas Tanure int ret, i; 22234a0094bSVijendar Mukunda 223a719afe6SLucas Tanure switch (rate) { 22434a0094bSVijendar Mukunda case 48000: 225a719afe6SLucas Tanure bclk = 1536000; 22634a0094bSVijendar Mukunda break; 22734a0094bSVijendar Mukunda default: 228a719afe6SLucas Tanure bclk = 0; 229a719afe6SLucas Tanure break; 230a719afe6SLucas Tanure } 231a719afe6SLucas Tanure 232a719afe6SLucas Tanure for_each_rtd_components(rtd, i, comp) { 233c10955e4SLucas Tanure if (!(strcmp(comp->name, ACP5X_CS35L41_COMP_LNAME)) || 234c10955e4SLucas Tanure !(strcmp(comp->name, ACP5X_CS35L41_COMP_RNAME))) { 235a719afe6SLucas Tanure if (!bclk) { 236a719afe6SLucas Tanure dev_err(comp->dev, "Invalid sample rate: 0x%x\n", rate); 23734a0094bSVijendar Mukunda return -EINVAL; 23834a0094bSVijendar Mukunda } 239a719afe6SLucas Tanure 240a719afe6SLucas Tanure ret = snd_soc_component_set_sysclk(comp, 0, 0, bclk, SND_SOC_CLOCK_IN); 241a719afe6SLucas Tanure if (ret) { 242a719afe6SLucas Tanure dev_err(comp->dev, "failed to set SYSCLK: %d\n", ret); 24334a0094bSVijendar Mukunda return ret; 24434a0094bSVijendar Mukunda } 24534a0094bSVijendar Mukunda } 24634a0094bSVijendar Mukunda } 24734a0094bSVijendar Mukunda 248a719afe6SLucas Tanure return 0; 24934a0094bSVijendar Mukunda } 25034a0094bSVijendar Mukunda 25134a0094bSVijendar Mukunda static const struct snd_soc_ops acp5x_cs35l41_play_ops = { 25234a0094bSVijendar Mukunda .startup = acp5x_cs35l41_startup, 25334a0094bSVijendar Mukunda .hw_params = acp5x_cs35l41_hw_params, 25434a0094bSVijendar Mukunda }; 25534a0094bSVijendar Mukunda 256e9023248SLucas Tanure static struct snd_soc_codec_conf acp5x_cs35l41_conf[] = { 25734a0094bSVijendar Mukunda { 258c10955e4SLucas Tanure .dlc = COMP_CODEC_CONF(ACP5X_CS35L41_COMP_LNAME), 25934a0094bSVijendar Mukunda .name_prefix = "Left", 26034a0094bSVijendar Mukunda }, 26134a0094bSVijendar Mukunda { 262c10955e4SLucas Tanure .dlc = COMP_CODEC_CONF(ACP5X_CS35L41_COMP_RNAME), 26334a0094bSVijendar Mukunda .name_prefix = "Right", 26434a0094bSVijendar Mukunda }, 26534a0094bSVijendar Mukunda }; 26634a0094bSVijendar Mukunda 267c10955e4SLucas Tanure SND_SOC_DAILINK_DEF(cs35l41, DAILINK_COMP_ARRAY(COMP_CODEC(ACP5X_CS35L41_COMP_LNAME, 268c10955e4SLucas Tanure ACP5X_CS35L41_DAI_NAME), 269c10955e4SLucas Tanure COMP_CODEC(ACP5X_CS35L41_COMP_RNAME, 270c10955e4SLucas Tanure ACP5X_CS35L41_DAI_NAME))); 27134a0094bSVijendar Mukunda 272e9023248SLucas Tanure static struct snd_soc_dai_link acp5x_8821_35l41_dai[] = { 27334a0094bSVijendar Mukunda { 2745363d730SVijendar Mukunda .name = "acp5x-8821-play", 27534a0094bSVijendar Mukunda .stream_name = "Playback/Capture", 276ddd42a12SLucas Tanure .dai_fmt = SND_SOC_DAIFMT_I2S | 277ddd42a12SLucas Tanure SND_SOC_DAIFMT_NB_NF | 27834a0094bSVijendar Mukunda SND_SOC_DAIFMT_CBC_CFC, 27934a0094bSVijendar Mukunda .dpcm_playback = 1, 28034a0094bSVijendar Mukunda .dpcm_capture = 1, 28134a0094bSVijendar Mukunda .ops = &acp5x_8821_ops, 28234a0094bSVijendar Mukunda .init = acp5x_8821_init, 28334a0094bSVijendar Mukunda SND_SOC_DAILINK_REG(acp5x_i2s, nau8821, platform), 28434a0094bSVijendar Mukunda }, 28534a0094bSVijendar Mukunda { 28634a0094bSVijendar Mukunda .name = "acp5x-CS35L41-Stereo", 28734a0094bSVijendar Mukunda .stream_name = "CS35L41 Stereo Playback", 288ddd42a12SLucas Tanure .dai_fmt = SND_SOC_DAIFMT_I2S | 289ddd42a12SLucas Tanure SND_SOC_DAIFMT_NB_NF | 29034a0094bSVijendar Mukunda SND_SOC_DAIFMT_CBC_CFC, 29134a0094bSVijendar Mukunda .dpcm_playback = 1, 29234a0094bSVijendar Mukunda .playback_only = 1, 29334a0094bSVijendar Mukunda .ops = &acp5x_cs35l41_play_ops, 29434a0094bSVijendar Mukunda SND_SOC_DAILINK_REG(acp5x_bt, cs35l41, platform), 29534a0094bSVijendar Mukunda }, 29634a0094bSVijendar Mukunda }; 29734a0094bSVijendar Mukunda 298e9023248SLucas Tanure static const struct snd_soc_dapm_widget acp5x_8821_35l41_widgets[] = { 29934a0094bSVijendar Mukunda SND_SOC_DAPM_HP("Headphone", NULL), 30034a0094bSVijendar Mukunda SND_SOC_DAPM_MIC("Headset Mic", NULL), 30134a0094bSVijendar Mukunda SND_SOC_DAPM_MIC("Int Mic", NULL), 30234a0094bSVijendar Mukunda SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, 303ddd42a12SLucas Tanure platform_clock_control, 304ddd42a12SLucas Tanure SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 30534a0094bSVijendar Mukunda }; 30634a0094bSVijendar Mukunda 307e9023248SLucas Tanure static const struct snd_soc_dapm_route acp5x_8821_35l41_audio_route[] = { 30834a0094bSVijendar Mukunda /* HP jack connectors - unknown if we have jack detection */ 30934a0094bSVijendar Mukunda { "Headphone", NULL, "HPOL" }, 31034a0094bSVijendar Mukunda { "Headphone", NULL, "HPOR" }, 31134a0094bSVijendar Mukunda { "MICL", NULL, "Headset Mic" }, 31234a0094bSVijendar Mukunda { "MICR", NULL, "Headset Mic" }, 31334a0094bSVijendar Mukunda { "DMIC", NULL, "Int Mic" }, 31434a0094bSVijendar Mukunda 31534a0094bSVijendar Mukunda { "Headphone", NULL, "Platform Clock" }, 31634a0094bSVijendar Mukunda { "Headset Mic", NULL, "Platform Clock" }, 31734a0094bSVijendar Mukunda { "Int Mic", NULL, "Platform Clock" }, 31834a0094bSVijendar Mukunda }; 31934a0094bSVijendar Mukunda 320e9023248SLucas Tanure static struct snd_soc_card acp5x_8821_35l41_card = { 32134a0094bSVijendar Mukunda .name = "acp5x", 32234a0094bSVijendar Mukunda .owner = THIS_MODULE, 323e9023248SLucas Tanure .dai_link = acp5x_8821_35l41_dai, 324e9023248SLucas Tanure .num_links = ARRAY_SIZE(acp5x_8821_35l41_dai), 325e9023248SLucas Tanure .dapm_widgets = acp5x_8821_35l41_widgets, 326e9023248SLucas Tanure .num_dapm_widgets = ARRAY_SIZE(acp5x_8821_35l41_widgets), 327e9023248SLucas Tanure .dapm_routes = acp5x_8821_35l41_audio_route, 328e9023248SLucas Tanure .num_dapm_routes = ARRAY_SIZE(acp5x_8821_35l41_audio_route), 329e9023248SLucas Tanure .codec_conf = acp5x_cs35l41_conf, 330e9023248SLucas Tanure .num_configs = ARRAY_SIZE(acp5x_cs35l41_conf), 33134a0094bSVijendar Mukunda .controls = acp5x_8821_controls, 33234a0094bSVijendar Mukunda .num_controls = ARRAY_SIZE(acp5x_8821_controls), 33334a0094bSVijendar Mukunda }; 33434a0094bSVijendar Mukunda 335dba22efdSCristian Ciocaltea static int acp5x_max98388_startup(struct snd_pcm_substream *substream) 336dba22efdSCristian Ciocaltea { 337d4f23dcdSKuninori Morimoto struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 338dba22efdSCristian Ciocaltea struct acp5x_platform_info *machine = snd_soc_card_get_drvdata(rtd->card); 339dba22efdSCristian Ciocaltea struct snd_pcm_runtime *runtime = substream->runtime; 340dba22efdSCristian Ciocaltea 341dba22efdSCristian Ciocaltea machine->play_i2s_instance = I2S_HS_INSTANCE; 342dba22efdSCristian Ciocaltea 343dba22efdSCristian Ciocaltea runtime->hw.channels_max = DUAL_CHANNEL; 344dba22efdSCristian Ciocaltea snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 345dba22efdSCristian Ciocaltea &constraints_channels); 346dba22efdSCristian Ciocaltea snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 347dba22efdSCristian Ciocaltea &constraints_rates); 348dba22efdSCristian Ciocaltea return 0; 349dba22efdSCristian Ciocaltea } 350dba22efdSCristian Ciocaltea 351dba22efdSCristian Ciocaltea static const struct snd_soc_ops acp5x_max98388_play_ops = { 352dba22efdSCristian Ciocaltea .startup = acp5x_max98388_startup, 353dba22efdSCristian Ciocaltea }; 354dba22efdSCristian Ciocaltea 355dba22efdSCristian Ciocaltea static struct snd_soc_codec_conf acp5x_max98388_conf[] = { 356dba22efdSCristian Ciocaltea { 357dba22efdSCristian Ciocaltea .dlc = COMP_CODEC_CONF(ACP5X_MAX98388_COMP_LNAME), 358dba22efdSCristian Ciocaltea .name_prefix = "Left", 359dba22efdSCristian Ciocaltea }, 360dba22efdSCristian Ciocaltea { 361dba22efdSCristian Ciocaltea .dlc = COMP_CODEC_CONF(ACP5X_MAX98388_COMP_RNAME), 362dba22efdSCristian Ciocaltea .name_prefix = "Right", 363dba22efdSCristian Ciocaltea }, 364dba22efdSCristian Ciocaltea }; 365dba22efdSCristian Ciocaltea 366dba22efdSCristian Ciocaltea SND_SOC_DAILINK_DEF(max98388, DAILINK_COMP_ARRAY(COMP_CODEC(ACP5X_MAX98388_COMP_LNAME, 367dba22efdSCristian Ciocaltea ACP5X_MAX98388_DAI_NAME), 368dba22efdSCristian Ciocaltea COMP_CODEC(ACP5X_MAX98388_COMP_RNAME, 369dba22efdSCristian Ciocaltea ACP5X_MAX98388_DAI_NAME))); 370dba22efdSCristian Ciocaltea 371dba22efdSCristian Ciocaltea static struct snd_soc_dai_link acp5x_8821_98388_dai[] = { 372dba22efdSCristian Ciocaltea { 373dba22efdSCristian Ciocaltea .name = "acp5x-8821-play", 374dba22efdSCristian Ciocaltea .stream_name = "Playback/Capture", 375dba22efdSCristian Ciocaltea .dai_fmt = SND_SOC_DAIFMT_I2S | 376dba22efdSCristian Ciocaltea SND_SOC_DAIFMT_NB_NF | 377dba22efdSCristian Ciocaltea SND_SOC_DAIFMT_CBC_CFC, 378dba22efdSCristian Ciocaltea .dpcm_playback = 1, 379dba22efdSCristian Ciocaltea .dpcm_capture = 1, 380dba22efdSCristian Ciocaltea .ops = &acp5x_8821_ops, 381dba22efdSCristian Ciocaltea .init = acp5x_8821_init, 382dba22efdSCristian Ciocaltea SND_SOC_DAILINK_REG(acp5x_i2s, nau8821, platform), 383dba22efdSCristian Ciocaltea }, 384dba22efdSCristian Ciocaltea { 385dba22efdSCristian Ciocaltea .name = "acp5x-max98388-play", 386dba22efdSCristian Ciocaltea .stream_name = "MAX98388 Playback", 387dba22efdSCristian Ciocaltea .dai_fmt = SND_SOC_DAIFMT_I2S | 388dba22efdSCristian Ciocaltea SND_SOC_DAIFMT_NB_NF | 389dba22efdSCristian Ciocaltea SND_SOC_DAIFMT_CBC_CFC, 390dba22efdSCristian Ciocaltea .dpcm_playback = 1, 391dba22efdSCristian Ciocaltea .playback_only = 1, 392dba22efdSCristian Ciocaltea .ops = &acp5x_max98388_play_ops, 393dba22efdSCristian Ciocaltea SND_SOC_DAILINK_REG(acp5x_bt, max98388, platform), 394dba22efdSCristian Ciocaltea }, 395dba22efdSCristian Ciocaltea }; 396dba22efdSCristian Ciocaltea 397dba22efdSCristian Ciocaltea static const struct snd_soc_dapm_widget acp5x_8821_98388_widgets[] = { 398dba22efdSCristian Ciocaltea SND_SOC_DAPM_HP("Headphone", NULL), 399dba22efdSCristian Ciocaltea SND_SOC_DAPM_MIC("Headset Mic", NULL), 400dba22efdSCristian Ciocaltea SND_SOC_DAPM_MIC("Int Mic", NULL), 401dba22efdSCristian Ciocaltea SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0, 402dba22efdSCristian Ciocaltea platform_clock_control, 403dba22efdSCristian Ciocaltea SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 404dba22efdSCristian Ciocaltea SND_SOC_DAPM_SPK("SPK", NULL), 405dba22efdSCristian Ciocaltea }; 406dba22efdSCristian Ciocaltea 407dba22efdSCristian Ciocaltea static const struct snd_soc_dapm_route acp5x_8821_98388_route[] = { 408dba22efdSCristian Ciocaltea { "Headphone", NULL, "HPOL" }, 409dba22efdSCristian Ciocaltea { "Headphone", NULL, "HPOR" }, 410dba22efdSCristian Ciocaltea { "MICL", NULL, "Headset Mic" }, 411dba22efdSCristian Ciocaltea { "MICR", NULL, "Headset Mic" }, 412dba22efdSCristian Ciocaltea { "DMIC", NULL, "Int Mic" }, 413dba22efdSCristian Ciocaltea 414dba22efdSCristian Ciocaltea { "Headphone", NULL, "Platform Clock" }, 415dba22efdSCristian Ciocaltea { "Headset Mic", NULL, "Platform Clock" }, 416dba22efdSCristian Ciocaltea { "Int Mic", NULL, "Platform Clock" }, 417dba22efdSCristian Ciocaltea 418dba22efdSCristian Ciocaltea { "SPK", NULL, "Left BE_OUT" }, 419dba22efdSCristian Ciocaltea { "SPK", NULL, "Right BE_OUT" }, 420dba22efdSCristian Ciocaltea }; 421dba22efdSCristian Ciocaltea 422dba22efdSCristian Ciocaltea static struct snd_soc_card acp5x_8821_98388_card = { 423dba22efdSCristian Ciocaltea .name = "acp5x-max98388", 424dba22efdSCristian Ciocaltea .owner = THIS_MODULE, 425dba22efdSCristian Ciocaltea .dai_link = acp5x_8821_98388_dai, 426dba22efdSCristian Ciocaltea .num_links = ARRAY_SIZE(acp5x_8821_98388_dai), 427dba22efdSCristian Ciocaltea .dapm_widgets = acp5x_8821_98388_widgets, 428dba22efdSCristian Ciocaltea .num_dapm_widgets = ARRAY_SIZE(acp5x_8821_98388_widgets), 429dba22efdSCristian Ciocaltea .dapm_routes = acp5x_8821_98388_route, 430dba22efdSCristian Ciocaltea .num_dapm_routes = ARRAY_SIZE(acp5x_8821_98388_route), 431dba22efdSCristian Ciocaltea .codec_conf = acp5x_max98388_conf, 432dba22efdSCristian Ciocaltea .num_configs = ARRAY_SIZE(acp5x_max98388_conf), 433dba22efdSCristian Ciocaltea .controls = acp5x_8821_controls, 434dba22efdSCristian Ciocaltea .num_controls = ARRAY_SIZE(acp5x_8821_controls), 435dba22efdSCristian Ciocaltea }; 436dba22efdSCristian Ciocaltea 43734a0094bSVijendar Mukunda static const struct dmi_system_id acp5x_vg_quirk_table[] = { 43834a0094bSVijendar Mukunda { 43934a0094bSVijendar Mukunda .matches = { 44034a0094bSVijendar Mukunda DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Valve"), 44134a0094bSVijendar Mukunda DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Jupiter"), 442*ddd1ee12SCristian Ciocaltea }, 443*ddd1ee12SCristian Ciocaltea .driver_data = (void *)&acp5x_8821_35l41_card, 444*ddd1ee12SCristian Ciocaltea }, 445*ddd1ee12SCristian Ciocaltea { 446*ddd1ee12SCristian Ciocaltea .matches = { 447*ddd1ee12SCristian Ciocaltea DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Valve"), 448*ddd1ee12SCristian Ciocaltea DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Galileo"), 449*ddd1ee12SCristian Ciocaltea }, 450*ddd1ee12SCristian Ciocaltea .driver_data = (void *)&acp5x_8821_98388_card, 45134a0094bSVijendar Mukunda }, 45234a0094bSVijendar Mukunda {} 45334a0094bSVijendar Mukunda }; 45434a0094bSVijendar Mukunda 45534a0094bSVijendar Mukunda static int acp5x_probe(struct platform_device *pdev) 45634a0094bSVijendar Mukunda { 4573dd26e27SCristian Ciocaltea const struct dmi_system_id *dmi_id; 45834a0094bSVijendar Mukunda struct acp5x_platform_info *machine; 459ddd42a12SLucas Tanure struct device *dev = &pdev->dev; 46034a0094bSVijendar Mukunda struct snd_soc_card *card; 461ddd42a12SLucas Tanure int ret; 46234a0094bSVijendar Mukunda 4633dd26e27SCristian Ciocaltea dmi_id = dmi_first_match(acp5x_vg_quirk_table); 464*ddd1ee12SCristian Ciocaltea if (!dmi_id || !dmi_id->driver_data) 4653dd26e27SCristian Ciocaltea return -ENODEV; 4663dd26e27SCristian Ciocaltea 46750e81116SLucas Tanure machine = devm_kzalloc(dev, sizeof(*machine), GFP_KERNEL); 46834a0094bSVijendar Mukunda if (!machine) 46934a0094bSVijendar Mukunda return -ENOMEM; 47034a0094bSVijendar Mukunda 471*ddd1ee12SCristian Ciocaltea card = dmi_id->driver_data; 472ddd42a12SLucas Tanure card->dev = dev; 47334a0094bSVijendar Mukunda platform_set_drvdata(pdev, card); 47434a0094bSVijendar Mukunda snd_soc_card_set_drvdata(card, machine); 47534a0094bSVijendar Mukunda 476ddd42a12SLucas Tanure ret = devm_snd_soc_register_card(dev, card); 477ddd42a12SLucas Tanure if (ret) 478ddd42a12SLucas Tanure return dev_err_probe(dev, ret, "Register card (%s) failed\n", card->name); 479ddd42a12SLucas Tanure 48034a0094bSVijendar Mukunda return 0; 48134a0094bSVijendar Mukunda } 48234a0094bSVijendar Mukunda 48334a0094bSVijendar Mukunda static struct platform_driver acp5x_mach_driver = { 48434a0094bSVijendar Mukunda .driver = { 485a0cb05cbSCristian Ciocaltea .name = DRV_NAME, 48634a0094bSVijendar Mukunda .pm = &snd_soc_pm_ops, 48734a0094bSVijendar Mukunda }, 48834a0094bSVijendar Mukunda .probe = acp5x_probe, 48934a0094bSVijendar Mukunda }; 49034a0094bSVijendar Mukunda 49134a0094bSVijendar Mukunda module_platform_driver(acp5x_mach_driver); 49234a0094bSVijendar Mukunda 49334a0094bSVijendar Mukunda MODULE_AUTHOR("Vijendar.Mukunda@amd.com"); 494dba22efdSCristian Ciocaltea MODULE_DESCRIPTION("NAU8821/CS35L41 & NAU8821/MAX98388 audio support"); 49534a0094bSVijendar Mukunda MODULE_LICENSE("GPL v2"); 49634a0094bSVijendar Mukunda MODULE_ALIAS("platform:" DRV_NAME); 497