111c02690SShunli Wang // SPDX-License-Identifier: GPL-2.0 211c02690SShunli Wang // 311c02690SShunli Wang // mt8183-mt6358.c -- 411c02690SShunli Wang // MT8183-MT6358-TS3A227-MAX98357 ALSA SoC machine driver 511c02690SShunli Wang // 611c02690SShunli Wang // Copyright (c) 2018 MediaTek Inc. 711c02690SShunli Wang // Author: Shunli Wang <shunli.wang@mediatek.com> 811c02690SShunli Wang 911c02690SShunli Wang #include <linux/module.h> 10f4fb4fefSTzung-Bi Shih #include <linux/of_device.h> 114dae01c2STzung-Bi Shih #include <linux/pinctrl/consumer.h> 12*88abbf62STzung-Bi Shih #include <sound/hdmi-codec.h> 134dae01c2STzung-Bi Shih #include <sound/jack.h> 1411c02690SShunli Wang #include <sound/pcm_params.h> 1511c02690SShunli Wang #include <sound/soc.h> 1611c02690SShunli Wang 17f4fb4fefSTzung-Bi Shih #include "../../codecs/rt1015.h" 1811c02690SShunli Wang #include "../../codecs/ts3a227e.h" 194dae01c2STzung-Bi Shih #include "mt8183-afe-common.h" 2011c02690SShunli Wang 21f4fb4fefSTzung-Bi Shih #define RT1015_CODEC_DAI "rt1015-aif" 22f4fb4fefSTzung-Bi Shih #define RT1015_DEV0_NAME "rt1015.6-0028" 23f4fb4fefSTzung-Bi Shih #define RT1015_DEV1_NAME "rt1015.6-0029" 24f4fb4fefSTzung-Bi Shih 2596ed7698STzung-Bi Shih enum PINCTRL_PIN_STATE { 2696ed7698STzung-Bi Shih PIN_STATE_DEFAULT = 0, 2796ed7698STzung-Bi Shih PIN_TDM_OUT_ON, 2896ed7698STzung-Bi Shih PIN_TDM_OUT_OFF, 292cc3cd5fSTzung-Bi Shih PIN_WOV, 3096ed7698STzung-Bi Shih PIN_STATE_MAX 3196ed7698STzung-Bi Shih }; 3296ed7698STzung-Bi Shih 3396ed7698STzung-Bi Shih static const char * const mt8183_pin_str[PIN_STATE_MAX] = { 342cc3cd5fSTzung-Bi Shih "default", "aud_tdm_out_on", "aud_tdm_out_off", "wov", 3596ed7698STzung-Bi Shih }; 3696ed7698STzung-Bi Shih 3796ed7698STzung-Bi Shih struct mt8183_mt6358_ts3a227_max98357_priv { 3896ed7698STzung-Bi Shih struct pinctrl *pinctrl; 3996ed7698STzung-Bi Shih struct pinctrl_state *pin_states[PIN_STATE_MAX]; 40*88abbf62STzung-Bi Shih struct snd_soc_jack headset_jack, hdmi_jack; 4196ed7698STzung-Bi Shih }; 4296ed7698STzung-Bi Shih 4311c02690SShunli Wang static int mt8183_mt6358_i2s_hw_params(struct snd_pcm_substream *substream, 4411c02690SShunli Wang struct snd_pcm_hw_params *params) 4511c02690SShunli Wang { 4611c02690SShunli Wang struct snd_soc_pcm_runtime *rtd = substream->private_data; 4711c02690SShunli Wang unsigned int rate = params_rate(params); 4811c02690SShunli Wang unsigned int mclk_fs_ratio = 128; 4911c02690SShunli Wang unsigned int mclk_fs = rate * mclk_fs_ratio; 5011c02690SShunli Wang 51c8ac8212SKuninori Morimoto return snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), 5211c02690SShunli Wang 0, mclk_fs, SND_SOC_CLOCK_OUT); 5311c02690SShunli Wang } 5411c02690SShunli Wang 5511c02690SShunli Wang static const struct snd_soc_ops mt8183_mt6358_i2s_ops = { 5611c02690SShunli Wang .hw_params = mt8183_mt6358_i2s_hw_params, 5711c02690SShunli Wang }; 5811c02690SShunli Wang 59f4fb4fefSTzung-Bi Shih static int 60f4fb4fefSTzung-Bi Shih mt8183_mt6358_rt1015_i2s_hw_params(struct snd_pcm_substream *substream, 61f4fb4fefSTzung-Bi Shih struct snd_pcm_hw_params *params) 62f4fb4fefSTzung-Bi Shih { 63f4fb4fefSTzung-Bi Shih struct snd_soc_pcm_runtime *rtd = substream->private_data; 64f4fb4fefSTzung-Bi Shih unsigned int rate = params_rate(params); 65f4fb4fefSTzung-Bi Shih unsigned int mclk_fs_ratio = 128; 66f4fb4fefSTzung-Bi Shih unsigned int mclk_fs = rate * mclk_fs_ratio; 67f4fb4fefSTzung-Bi Shih struct snd_soc_card *card = rtd->card; 68f4fb4fefSTzung-Bi Shih struct snd_soc_dai *codec_dai; 69f4fb4fefSTzung-Bi Shih int ret, i; 70f4fb4fefSTzung-Bi Shih 71f4fb4fefSTzung-Bi Shih for_each_rtd_codec_dais(rtd, i, codec_dai) { 72f4fb4fefSTzung-Bi Shih ret = snd_soc_dai_set_bclk_ratio(codec_dai, 64); 73f4fb4fefSTzung-Bi Shih if (ret < 0) { 74f4fb4fefSTzung-Bi Shih dev_err(card->dev, "failed to set bclk ratio\n"); 75f4fb4fefSTzung-Bi Shih return ret; 76f4fb4fefSTzung-Bi Shih } 77f4fb4fefSTzung-Bi Shih 78f4fb4fefSTzung-Bi Shih ret = snd_soc_dai_set_pll(codec_dai, 0, RT1015_PLL_S_BCLK, 79f4fb4fefSTzung-Bi Shih rate * 64, rate * 256); 80f4fb4fefSTzung-Bi Shih if (ret < 0) { 81f4fb4fefSTzung-Bi Shih dev_err(card->dev, "failed to set pll\n"); 82f4fb4fefSTzung-Bi Shih return ret; 83f4fb4fefSTzung-Bi Shih } 84f4fb4fefSTzung-Bi Shih 85f4fb4fefSTzung-Bi Shih ret = snd_soc_dai_set_sysclk(codec_dai, RT1015_SCLK_S_PLL, 86f4fb4fefSTzung-Bi Shih rate * 256, SND_SOC_CLOCK_IN); 87f4fb4fefSTzung-Bi Shih if (ret < 0) { 88f4fb4fefSTzung-Bi Shih dev_err(card->dev, "failed to set sysclk\n"); 89f4fb4fefSTzung-Bi Shih return ret; 90f4fb4fefSTzung-Bi Shih } 91f4fb4fefSTzung-Bi Shih } 92f4fb4fefSTzung-Bi Shih 93f4fb4fefSTzung-Bi Shih return snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), 94f4fb4fefSTzung-Bi Shih 0, mclk_fs, SND_SOC_CLOCK_OUT); 95f4fb4fefSTzung-Bi Shih } 96f4fb4fefSTzung-Bi Shih 97f4fb4fefSTzung-Bi Shih static const struct snd_soc_ops mt8183_mt6358_rt1015_i2s_ops = { 98f4fb4fefSTzung-Bi Shih .hw_params = mt8183_mt6358_rt1015_i2s_hw_params, 99f4fb4fefSTzung-Bi Shih }; 100f4fb4fefSTzung-Bi Shih 10111c02690SShunli Wang static int mt8183_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 10211c02690SShunli Wang struct snd_pcm_hw_params *params) 10311c02690SShunli Wang { 10411c02690SShunli Wang dev_dbg(rtd->dev, "%s(), fix format to 32bit\n", __func__); 10511c02690SShunli Wang 10611c02690SShunli Wang /* fix BE i2s format to 32bit, clean param mask first */ 10711c02690SShunli Wang snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 10811c02690SShunli Wang 0, SNDRV_PCM_FORMAT_LAST); 10911c02690SShunli Wang 11011c02690SShunli Wang params_set_format(params, SNDRV_PCM_FORMAT_S32_LE); 11111c02690SShunli Wang return 0; 11211c02690SShunli Wang } 11311c02690SShunli Wang 114f4fb4fefSTzung-Bi Shih static int mt8183_rt1015_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 115f4fb4fefSTzung-Bi Shih struct snd_pcm_hw_params *params) 116f4fb4fefSTzung-Bi Shih { 117f4fb4fefSTzung-Bi Shih dev_dbg(rtd->dev, "%s(), fix format to 32bit\n", __func__); 118f4fb4fefSTzung-Bi Shih 119f4fb4fefSTzung-Bi Shih /* fix BE i2s format to 32bit, clean param mask first */ 120f4fb4fefSTzung-Bi Shih snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 121f4fb4fefSTzung-Bi Shih 0, SNDRV_PCM_FORMAT_LAST); 122f4fb4fefSTzung-Bi Shih 123f4fb4fefSTzung-Bi Shih params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); 124f4fb4fefSTzung-Bi Shih return 0; 125f4fb4fefSTzung-Bi Shih } 126f4fb4fefSTzung-Bi Shih 1271df1e545STzung-Bi Shih static int 1281df1e545STzung-Bi Shih mt8183_mt6358_ts3a227_max98357_bt_sco_startup( 1291df1e545STzung-Bi Shih struct snd_pcm_substream *substream) 1301df1e545STzung-Bi Shih { 1311df1e545STzung-Bi Shih static const unsigned int rates[] = { 1321df1e545STzung-Bi Shih 8000, 16000 1331df1e545STzung-Bi Shih }; 1341df1e545STzung-Bi Shih static const struct snd_pcm_hw_constraint_list constraints_rates = { 1351df1e545STzung-Bi Shih .count = ARRAY_SIZE(rates), 1361df1e545STzung-Bi Shih .list = rates, 1371df1e545STzung-Bi Shih .mask = 0, 1381df1e545STzung-Bi Shih }; 1391df1e545STzung-Bi Shih static const unsigned int channels[] = { 1401df1e545STzung-Bi Shih 1, 1411df1e545STzung-Bi Shih }; 1421df1e545STzung-Bi Shih static const struct snd_pcm_hw_constraint_list constraints_channels = { 1431df1e545STzung-Bi Shih .count = ARRAY_SIZE(channels), 1441df1e545STzung-Bi Shih .list = channels, 1451df1e545STzung-Bi Shih .mask = 0, 1461df1e545STzung-Bi Shih }; 1471df1e545STzung-Bi Shih 1481df1e545STzung-Bi Shih struct snd_pcm_runtime *runtime = substream->runtime; 1491df1e545STzung-Bi Shih 1501df1e545STzung-Bi Shih snd_pcm_hw_constraint_list(runtime, 0, 1511df1e545STzung-Bi Shih SNDRV_PCM_HW_PARAM_RATE, &constraints_rates); 1521df1e545STzung-Bi Shih runtime->hw.channels_max = 1; 1531df1e545STzung-Bi Shih snd_pcm_hw_constraint_list(runtime, 0, 1541df1e545STzung-Bi Shih SNDRV_PCM_HW_PARAM_CHANNELS, 1551df1e545STzung-Bi Shih &constraints_channels); 1561df1e545STzung-Bi Shih 1571df1e545STzung-Bi Shih runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; 1581df1e545STzung-Bi Shih snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16); 1591df1e545STzung-Bi Shih 1601df1e545STzung-Bi Shih return 0; 1611df1e545STzung-Bi Shih } 1621df1e545STzung-Bi Shih 1631df1e545STzung-Bi Shih static const struct snd_soc_ops mt8183_mt6358_ts3a227_max98357_bt_sco_ops = { 1641df1e545STzung-Bi Shih .startup = mt8183_mt6358_ts3a227_max98357_bt_sco_startup, 1651df1e545STzung-Bi Shih }; 1661df1e545STzung-Bi Shih 167fa284fd0SKuninori Morimoto /* FE */ 168fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(playback1, 169fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("DL1")), 170fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 171fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 172fa284fd0SKuninori Morimoto 173fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(playback2, 174fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("DL2")), 175fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 176fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 177fa284fd0SKuninori Morimoto 178fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(playback3, 179fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("DL3")), 180fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 181fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 182fa284fd0SKuninori Morimoto 183fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(capture1, 184fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("UL1")), 185fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 186fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 187fa284fd0SKuninori Morimoto 188fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(capture2, 189fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("UL2")), 190fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 191fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 192fa284fd0SKuninori Morimoto 193fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(capture3, 194fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("UL3")), 195fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 196fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 197fa284fd0SKuninori Morimoto 198fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(capture_mono, 199fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("UL_MONO_1")), 200fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 201fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 202fa284fd0SKuninori Morimoto 203fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(playback_hdmi, 204fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("HDMI")), 205fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 206fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 207fa284fd0SKuninori Morimoto 2082cc3cd5fSTzung-Bi Shih SND_SOC_DAILINK_DEFS(wake_on_voice, 2092cc3cd5fSTzung-Bi Shih DAILINK_COMP_ARRAY(COMP_DUMMY()), 2102cc3cd5fSTzung-Bi Shih DAILINK_COMP_ARRAY(COMP_DUMMY()), 2112cc3cd5fSTzung-Bi Shih DAILINK_COMP_ARRAY(COMP_EMPTY())); 2122cc3cd5fSTzung-Bi Shih 213fa284fd0SKuninori Morimoto /* BE */ 214fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(primary_codec, 215fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("ADDA")), 216fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CODEC("mt6358-sound", "mt6358-snd-codec-aif1")), 217fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 218fa284fd0SKuninori Morimoto 219fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(pcm1, 220fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")), 221fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 222fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 223fa284fd0SKuninori Morimoto 224fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(pcm2, 225fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")), 226fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 227fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 228fa284fd0SKuninori Morimoto 229fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(i2s0, 230fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("I2S0")), 231fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CODEC("bt-sco", "bt-sco-pcm")), 232fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 233fa284fd0SKuninori Morimoto 234fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(i2s1, 235fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("I2S1")), 236fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 237fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 238fa284fd0SKuninori Morimoto 239fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(i2s2, 240fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("I2S2")), 241fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_DUMMY()), 242fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 243fa284fd0SKuninori Morimoto 244f4fb4fefSTzung-Bi Shih SND_SOC_DAILINK_DEFS(i2s3_max98357a, 245fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("I2S3")), 246fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CODEC("max98357a", "HiFi")), 247fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 248fa284fd0SKuninori Morimoto 249f4fb4fefSTzung-Bi Shih SND_SOC_DAILINK_DEFS(i2s3_rt1015, 250f4fb4fefSTzung-Bi Shih DAILINK_COMP_ARRAY(COMP_CPU("I2S3")), 251f4fb4fefSTzung-Bi Shih DAILINK_COMP_ARRAY(COMP_CODEC(RT1015_DEV0_NAME, RT1015_CODEC_DAI), 252f4fb4fefSTzung-Bi Shih COMP_CODEC(RT1015_DEV1_NAME, RT1015_CODEC_DAI)), 253f4fb4fefSTzung-Bi Shih DAILINK_COMP_ARRAY(COMP_EMPTY())); 254f4fb4fefSTzung-Bi Shih 255fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(i2s5, 256fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("I2S5")), 257fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CODEC("bt-sco", "bt-sco-pcm")), 258fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 259fa284fd0SKuninori Morimoto 260fa284fd0SKuninori Morimoto SND_SOC_DAILINK_DEFS(tdm, 261fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_CPU("TDM")), 262f2024dc5STzung-Bi Shih DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")), 263fa284fd0SKuninori Morimoto DAILINK_COMP_ARRAY(COMP_EMPTY())); 264fa284fd0SKuninori Morimoto 2656191cbdeSJiaxin Yu static int mt8183_mt6358_tdm_startup(struct snd_pcm_substream *substream) 2666191cbdeSJiaxin Yu { 2676191cbdeSJiaxin Yu struct snd_soc_pcm_runtime *rtd = substream->private_data; 2686191cbdeSJiaxin Yu struct mt8183_mt6358_ts3a227_max98357_priv *priv = 2696191cbdeSJiaxin Yu snd_soc_card_get_drvdata(rtd->card); 2706191cbdeSJiaxin Yu int ret; 2716191cbdeSJiaxin Yu 2726191cbdeSJiaxin Yu if (IS_ERR(priv->pin_states[PIN_TDM_OUT_ON])) 2736191cbdeSJiaxin Yu return PTR_ERR(priv->pin_states[PIN_TDM_OUT_ON]); 2746191cbdeSJiaxin Yu 2756191cbdeSJiaxin Yu ret = pinctrl_select_state(priv->pinctrl, 2766191cbdeSJiaxin Yu priv->pin_states[PIN_TDM_OUT_ON]); 2776191cbdeSJiaxin Yu if (ret) 2786191cbdeSJiaxin Yu dev_err(rtd->card->dev, "%s failed to select state %d\n", 2796191cbdeSJiaxin Yu __func__, ret); 2806191cbdeSJiaxin Yu 2816191cbdeSJiaxin Yu return ret; 2826191cbdeSJiaxin Yu } 2836191cbdeSJiaxin Yu 2846191cbdeSJiaxin Yu static void mt8183_mt6358_tdm_shutdown(struct snd_pcm_substream *substream) 2856191cbdeSJiaxin Yu { 2866191cbdeSJiaxin Yu struct snd_soc_pcm_runtime *rtd = substream->private_data; 2876191cbdeSJiaxin Yu struct mt8183_mt6358_ts3a227_max98357_priv *priv = 2886191cbdeSJiaxin Yu snd_soc_card_get_drvdata(rtd->card); 2896191cbdeSJiaxin Yu int ret; 2906191cbdeSJiaxin Yu 2916191cbdeSJiaxin Yu if (IS_ERR(priv->pin_states[PIN_TDM_OUT_OFF])) 2926191cbdeSJiaxin Yu return; 2936191cbdeSJiaxin Yu 2946191cbdeSJiaxin Yu ret = pinctrl_select_state(priv->pinctrl, 2956191cbdeSJiaxin Yu priv->pin_states[PIN_TDM_OUT_OFF]); 2966191cbdeSJiaxin Yu if (ret) 2976191cbdeSJiaxin Yu dev_err(rtd->card->dev, "%s failed to select state %d\n", 2986191cbdeSJiaxin Yu __func__, ret); 2996191cbdeSJiaxin Yu } 3006191cbdeSJiaxin Yu 3016191cbdeSJiaxin Yu static struct snd_soc_ops mt8183_mt6358_tdm_ops = { 3026191cbdeSJiaxin Yu .startup = mt8183_mt6358_tdm_startup, 3036191cbdeSJiaxin Yu .shutdown = mt8183_mt6358_tdm_shutdown, 3046191cbdeSJiaxin Yu }; 3056191cbdeSJiaxin Yu 3062cc3cd5fSTzung-Bi Shih static int 3072cc3cd5fSTzung-Bi Shih mt8183_mt6358_ts3a227_max98357_wov_startup( 3082cc3cd5fSTzung-Bi Shih struct snd_pcm_substream *substream) 3092cc3cd5fSTzung-Bi Shih { 3102cc3cd5fSTzung-Bi Shih struct snd_soc_pcm_runtime *rtd = substream->private_data; 3112cc3cd5fSTzung-Bi Shih struct snd_soc_card *card = rtd->card; 3122cc3cd5fSTzung-Bi Shih struct mt8183_mt6358_ts3a227_max98357_priv *priv = 3132cc3cd5fSTzung-Bi Shih snd_soc_card_get_drvdata(card); 3142cc3cd5fSTzung-Bi Shih 3152cc3cd5fSTzung-Bi Shih return pinctrl_select_state(priv->pinctrl, 3162cc3cd5fSTzung-Bi Shih priv->pin_states[PIN_WOV]); 3172cc3cd5fSTzung-Bi Shih } 3182cc3cd5fSTzung-Bi Shih 3192cc3cd5fSTzung-Bi Shih static void 3202cc3cd5fSTzung-Bi Shih mt8183_mt6358_ts3a227_max98357_wov_shutdown( 3212cc3cd5fSTzung-Bi Shih struct snd_pcm_substream *substream) 3222cc3cd5fSTzung-Bi Shih { 3232cc3cd5fSTzung-Bi Shih struct snd_soc_pcm_runtime *rtd = substream->private_data; 3242cc3cd5fSTzung-Bi Shih struct snd_soc_card *card = rtd->card; 3252cc3cd5fSTzung-Bi Shih struct mt8183_mt6358_ts3a227_max98357_priv *priv = 3262cc3cd5fSTzung-Bi Shih snd_soc_card_get_drvdata(card); 3272cc3cd5fSTzung-Bi Shih int ret; 3282cc3cd5fSTzung-Bi Shih 3292cc3cd5fSTzung-Bi Shih ret = pinctrl_select_state(priv->pinctrl, 3302cc3cd5fSTzung-Bi Shih priv->pin_states[PIN_STATE_DEFAULT]); 3312cc3cd5fSTzung-Bi Shih if (ret) 3322cc3cd5fSTzung-Bi Shih dev_err(card->dev, "%s failed to select state %d\n", 3332cc3cd5fSTzung-Bi Shih __func__, ret); 3342cc3cd5fSTzung-Bi Shih } 3352cc3cd5fSTzung-Bi Shih 3362cc3cd5fSTzung-Bi Shih static const struct snd_soc_ops mt8183_mt6358_ts3a227_max98357_wov_ops = { 3372cc3cd5fSTzung-Bi Shih .startup = mt8183_mt6358_ts3a227_max98357_wov_startup, 3382cc3cd5fSTzung-Bi Shih .shutdown = mt8183_mt6358_ts3a227_max98357_wov_shutdown, 3392cc3cd5fSTzung-Bi Shih }; 3402cc3cd5fSTzung-Bi Shih 341*88abbf62STzung-Bi Shih static int 342*88abbf62STzung-Bi Shih mt8183_mt6358_ts3a227_max98357_hdmi_init(struct snd_soc_pcm_runtime *rtd) 343*88abbf62STzung-Bi Shih { 344*88abbf62STzung-Bi Shih struct mt8183_mt6358_ts3a227_max98357_priv *priv = 345*88abbf62STzung-Bi Shih snd_soc_card_get_drvdata(rtd->card); 346*88abbf62STzung-Bi Shih int ret; 347*88abbf62STzung-Bi Shih 348*88abbf62STzung-Bi Shih ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, 349*88abbf62STzung-Bi Shih &priv->hdmi_jack, NULL, 0); 350*88abbf62STzung-Bi Shih if (ret) 351*88abbf62STzung-Bi Shih return ret; 352*88abbf62STzung-Bi Shih 353*88abbf62STzung-Bi Shih return hdmi_codec_set_jack_detect(asoc_rtd_to_codec(rtd, 0)->component, 354*88abbf62STzung-Bi Shih &priv->hdmi_jack); 355*88abbf62STzung-Bi Shih } 356*88abbf62STzung-Bi Shih 357f4fb4fefSTzung-Bi Shih static struct snd_soc_dai_link mt8183_mt6358_ts3a227_dai_links[] = { 35811c02690SShunli Wang /* FE */ 35911c02690SShunli Wang { 36011c02690SShunli Wang .name = "Playback_1", 36111c02690SShunli Wang .stream_name = "Playback_1", 36211c02690SShunli Wang .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 36311c02690SShunli Wang SND_SOC_DPCM_TRIGGER_PRE}, 36411c02690SShunli Wang .dynamic = 1, 36511c02690SShunli Wang .dpcm_playback = 1, 366fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(playback1), 36711c02690SShunli Wang }, 36811c02690SShunli Wang { 36911c02690SShunli Wang .name = "Playback_2", 37011c02690SShunli Wang .stream_name = "Playback_2", 37111c02690SShunli Wang .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 37211c02690SShunli Wang SND_SOC_DPCM_TRIGGER_PRE}, 37311c02690SShunli Wang .dynamic = 1, 37411c02690SShunli Wang .dpcm_playback = 1, 3751df1e545STzung-Bi Shih .ops = &mt8183_mt6358_ts3a227_max98357_bt_sco_ops, 376fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(playback2), 37711c02690SShunli Wang }, 37811c02690SShunli Wang { 37911c02690SShunli Wang .name = "Playback_3", 38011c02690SShunli Wang .stream_name = "Playback_3", 38111c02690SShunli Wang .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 38211c02690SShunli Wang SND_SOC_DPCM_TRIGGER_PRE}, 38311c02690SShunli Wang .dynamic = 1, 38411c02690SShunli Wang .dpcm_playback = 1, 385fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(playback3), 38611c02690SShunli Wang }, 38711c02690SShunli Wang { 38811c02690SShunli Wang .name = "Capture_1", 38911c02690SShunli Wang .stream_name = "Capture_1", 39011c02690SShunli Wang .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 39111c02690SShunli Wang SND_SOC_DPCM_TRIGGER_PRE}, 39211c02690SShunli Wang .dynamic = 1, 39311c02690SShunli Wang .dpcm_capture = 1, 3941df1e545STzung-Bi Shih .ops = &mt8183_mt6358_ts3a227_max98357_bt_sco_ops, 395fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(capture1), 39611c02690SShunli Wang }, 39711c02690SShunli Wang { 39811c02690SShunli Wang .name = "Capture_2", 39911c02690SShunli Wang .stream_name = "Capture_2", 40011c02690SShunli Wang .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 40111c02690SShunli Wang SND_SOC_DPCM_TRIGGER_PRE}, 40211c02690SShunli Wang .dynamic = 1, 40311c02690SShunli Wang .dpcm_capture = 1, 404fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(capture2), 40511c02690SShunli Wang }, 40611c02690SShunli Wang { 40711c02690SShunli Wang .name = "Capture_3", 40811c02690SShunli Wang .stream_name = "Capture_3", 40911c02690SShunli Wang .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 41011c02690SShunli Wang SND_SOC_DPCM_TRIGGER_PRE}, 41111c02690SShunli Wang .dynamic = 1, 41211c02690SShunli Wang .dpcm_capture = 1, 413fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(capture3), 41411c02690SShunli Wang }, 41511c02690SShunli Wang { 41611c02690SShunli Wang .name = "Capture_Mono_1", 41711c02690SShunli Wang .stream_name = "Capture_Mono_1", 41811c02690SShunli Wang .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 41911c02690SShunli Wang SND_SOC_DPCM_TRIGGER_PRE}, 42011c02690SShunli Wang .dynamic = 1, 42111c02690SShunli Wang .dpcm_capture = 1, 422fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(capture_mono), 42311c02690SShunli Wang }, 42411c02690SShunli Wang { 42511c02690SShunli Wang .name = "Playback_HDMI", 42611c02690SShunli Wang .stream_name = "Playback_HDMI", 42711c02690SShunli Wang .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 42811c02690SShunli Wang SND_SOC_DPCM_TRIGGER_PRE}, 42911c02690SShunli Wang .dynamic = 1, 43011c02690SShunli Wang .dpcm_playback = 1, 431fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(playback_hdmi), 43211c02690SShunli Wang }, 4332cc3cd5fSTzung-Bi Shih { 4342cc3cd5fSTzung-Bi Shih .name = "Wake on Voice", 4352cc3cd5fSTzung-Bi Shih .stream_name = "Wake on Voice", 4362cc3cd5fSTzung-Bi Shih .ignore_suspend = 1, 4372cc3cd5fSTzung-Bi Shih .ignore = 1, 4382cc3cd5fSTzung-Bi Shih SND_SOC_DAILINK_REG(wake_on_voice), 4392cc3cd5fSTzung-Bi Shih .ops = &mt8183_mt6358_ts3a227_max98357_wov_ops, 4402cc3cd5fSTzung-Bi Shih }, 4412cc3cd5fSTzung-Bi Shih 44211c02690SShunli Wang /* BE */ 44311c02690SShunli Wang { 44411c02690SShunli Wang .name = "Primary Codec", 44511c02690SShunli Wang .no_pcm = 1, 44611c02690SShunli Wang .dpcm_playback = 1, 44711c02690SShunli Wang .dpcm_capture = 1, 44811c02690SShunli Wang .ignore_suspend = 1, 449fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(primary_codec), 45011c02690SShunli Wang }, 45111c02690SShunli Wang { 45211c02690SShunli Wang .name = "PCM 1", 45311c02690SShunli Wang .no_pcm = 1, 45411c02690SShunli Wang .dpcm_playback = 1, 45511c02690SShunli Wang .dpcm_capture = 1, 45611c02690SShunli Wang .ignore_suspend = 1, 457fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(pcm1), 45811c02690SShunli Wang }, 45911c02690SShunli Wang { 46011c02690SShunli Wang .name = "PCM 2", 46111c02690SShunli Wang .no_pcm = 1, 46211c02690SShunli Wang .dpcm_playback = 1, 46311c02690SShunli Wang .dpcm_capture = 1, 46411c02690SShunli Wang .ignore_suspend = 1, 465fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(pcm2), 46611c02690SShunli Wang }, 46711c02690SShunli Wang { 46811c02690SShunli Wang .name = "I2S0", 46911c02690SShunli Wang .no_pcm = 1, 47011c02690SShunli Wang .dpcm_capture = 1, 47111c02690SShunli Wang .ignore_suspend = 1, 47211c02690SShunli Wang .be_hw_params_fixup = mt8183_i2s_hw_params_fixup, 47311c02690SShunli Wang .ops = &mt8183_mt6358_i2s_ops, 474fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(i2s0), 47511c02690SShunli Wang }, 47611c02690SShunli Wang { 47711c02690SShunli Wang .name = "I2S1", 47811c02690SShunli Wang .no_pcm = 1, 47911c02690SShunli Wang .dpcm_playback = 1, 48011c02690SShunli Wang .ignore_suspend = 1, 48111c02690SShunli Wang .be_hw_params_fixup = mt8183_i2s_hw_params_fixup, 48211c02690SShunli Wang .ops = &mt8183_mt6358_i2s_ops, 483fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(i2s1), 48411c02690SShunli Wang }, 48511c02690SShunli Wang { 48611c02690SShunli Wang .name = "I2S2", 48711c02690SShunli Wang .no_pcm = 1, 48811c02690SShunli Wang .dpcm_capture = 1, 48911c02690SShunli Wang .ignore_suspend = 1, 49011c02690SShunli Wang .be_hw_params_fixup = mt8183_i2s_hw_params_fixup, 49111c02690SShunli Wang .ops = &mt8183_mt6358_i2s_ops, 492fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(i2s2), 49311c02690SShunli Wang }, 49411c02690SShunli Wang { 49511c02690SShunli Wang .name = "I2S3", 49611c02690SShunli Wang .no_pcm = 1, 49711c02690SShunli Wang .dpcm_playback = 1, 49811c02690SShunli Wang .ignore_suspend = 1, 49911c02690SShunli Wang }, 50011c02690SShunli Wang { 50111c02690SShunli Wang .name = "I2S5", 50211c02690SShunli Wang .no_pcm = 1, 50311c02690SShunli Wang .dpcm_playback = 1, 50411c02690SShunli Wang .ignore_suspend = 1, 50511c02690SShunli Wang .be_hw_params_fixup = mt8183_i2s_hw_params_fixup, 50611c02690SShunli Wang .ops = &mt8183_mt6358_i2s_ops, 507fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(i2s5), 50811c02690SShunli Wang }, 50911c02690SShunli Wang { 51011c02690SShunli Wang .name = "TDM", 51111c02690SShunli Wang .no_pcm = 1, 5128e58c521SJiaxin Yu .dai_fmt = SND_SOC_DAIFMT_I2S | 5138e58c521SJiaxin Yu SND_SOC_DAIFMT_IB_IF | 5148e58c521SJiaxin Yu SND_SOC_DAIFMT_CBM_CFM, 51511c02690SShunli Wang .dpcm_playback = 1, 51611c02690SShunli Wang .ignore_suspend = 1, 5176191cbdeSJiaxin Yu .be_hw_params_fixup = mt8183_i2s_hw_params_fixup, 5186191cbdeSJiaxin Yu .ops = &mt8183_mt6358_tdm_ops, 519*88abbf62STzung-Bi Shih .init = mt8183_mt6358_ts3a227_max98357_hdmi_init, 520fa284fd0SKuninori Morimoto SND_SOC_DAILINK_REG(tdm), 52111c02690SShunli Wang }, 52211c02690SShunli Wang }; 52311c02690SShunli Wang 52411c02690SShunli Wang static struct snd_soc_card mt8183_mt6358_ts3a227_max98357_card = { 52511c02690SShunli Wang .name = "mt8183_mt6358_ts3a227_max98357", 52611c02690SShunli Wang .owner = THIS_MODULE, 527f4fb4fefSTzung-Bi Shih .dai_link = mt8183_mt6358_ts3a227_dai_links, 528f4fb4fefSTzung-Bi Shih .num_links = ARRAY_SIZE(mt8183_mt6358_ts3a227_dai_links), 529f4fb4fefSTzung-Bi Shih }; 530f4fb4fefSTzung-Bi Shih 531f4fb4fefSTzung-Bi Shih static struct snd_soc_codec_conf mt8183_mt6358_ts3a227_rt1015_amp_conf[] = { 532f4fb4fefSTzung-Bi Shih { 533f4fb4fefSTzung-Bi Shih .dlc = COMP_CODEC_CONF(RT1015_DEV0_NAME), 534f4fb4fefSTzung-Bi Shih .name_prefix = "Left", 535f4fb4fefSTzung-Bi Shih }, 536f4fb4fefSTzung-Bi Shih { 537f4fb4fefSTzung-Bi Shih .dlc = COMP_CODEC_CONF(RT1015_DEV1_NAME), 538f4fb4fefSTzung-Bi Shih .name_prefix = "Right", 539f4fb4fefSTzung-Bi Shih }, 540f4fb4fefSTzung-Bi Shih }; 541f4fb4fefSTzung-Bi Shih 542f4fb4fefSTzung-Bi Shih static struct snd_soc_card mt8183_mt6358_ts3a227_rt1015_card = { 543f4fb4fefSTzung-Bi Shih .name = "mt8183_mt6358_ts3a227_rt1015", 544f4fb4fefSTzung-Bi Shih .owner = THIS_MODULE, 545f4fb4fefSTzung-Bi Shih .dai_link = mt8183_mt6358_ts3a227_dai_links, 546f4fb4fefSTzung-Bi Shih .num_links = ARRAY_SIZE(mt8183_mt6358_ts3a227_dai_links), 547f4fb4fefSTzung-Bi Shih .codec_conf = mt8183_mt6358_ts3a227_rt1015_amp_conf, 548f4fb4fefSTzung-Bi Shih .num_configs = ARRAY_SIZE(mt8183_mt6358_ts3a227_rt1015_amp_conf), 54911c02690SShunli Wang }; 55011c02690SShunli Wang 55111c02690SShunli Wang static int 55211c02690SShunli Wang mt8183_mt6358_ts3a227_max98357_headset_init(struct snd_soc_component *component) 55311c02690SShunli Wang { 55411c02690SShunli Wang int ret; 55595d779b4STzung-Bi Shih struct mt8183_mt6358_ts3a227_max98357_priv *priv = 55695d779b4STzung-Bi Shih snd_soc_card_get_drvdata(component->card); 55711c02690SShunli Wang 55811c02690SShunli Wang /* Enable Headset and 4 Buttons Jack detection */ 559f4fb4fefSTzung-Bi Shih ret = snd_soc_card_jack_new(component->card, 56011c02690SShunli Wang "Headset Jack", 56111c02690SShunli Wang SND_JACK_HEADSET | 56211c02690SShunli Wang SND_JACK_BTN_0 | SND_JACK_BTN_1 | 56311c02690SShunli Wang SND_JACK_BTN_2 | SND_JACK_BTN_3, 56495d779b4STzung-Bi Shih &priv->headset_jack, 565108d0d40STzung-Bi Shih NULL, 0); 56611c02690SShunli Wang if (ret) 56711c02690SShunli Wang return ret; 56811c02690SShunli Wang 56995d779b4STzung-Bi Shih ret = ts3a227e_enable_jack_detect(component, &priv->headset_jack); 57011c02690SShunli Wang 57111c02690SShunli Wang return ret; 57211c02690SShunli Wang } 57311c02690SShunli Wang 574fc347483STzung-Bi Shih static struct snd_soc_aux_dev mt8183_mt6358_ts3a227_max98357_headset_dev = { 575fc347483STzung-Bi Shih .dlc = COMP_EMPTY(), 576fc347483STzung-Bi Shih .init = mt8183_mt6358_ts3a227_max98357_headset_init, 577fc347483STzung-Bi Shih }; 578fc347483STzung-Bi Shih 57911c02690SShunli Wang static int 58011c02690SShunli Wang mt8183_mt6358_ts3a227_max98357_dev_probe(struct platform_device *pdev) 58111c02690SShunli Wang { 582f4fb4fefSTzung-Bi Shih struct snd_soc_card *card; 583f2024dc5STzung-Bi Shih struct device_node *platform_node, *ec_codec, *hdmi_codec; 58411c02690SShunli Wang struct snd_soc_dai_link *dai_link; 5856191cbdeSJiaxin Yu struct mt8183_mt6358_ts3a227_max98357_priv *priv; 586f4fb4fefSTzung-Bi Shih const struct of_device_id *match; 587f4fb4fefSTzung-Bi Shih int ret, i; 58811c02690SShunli Wang 58911c02690SShunli Wang platform_node = of_parse_phandle(pdev->dev.of_node, 59011c02690SShunli Wang "mediatek,platform", 0); 59111c02690SShunli Wang if (!platform_node) { 59211c02690SShunli Wang dev_err(&pdev->dev, "Property 'platform' missing or invalid\n"); 59311c02690SShunli Wang return -EINVAL; 59411c02690SShunli Wang } 59511c02690SShunli Wang 596f4fb4fefSTzung-Bi Shih match = of_match_device(pdev->dev.driver->of_match_table, &pdev->dev); 597f4fb4fefSTzung-Bi Shih if (!match || !match->data) 598f4fb4fefSTzung-Bi Shih return -EINVAL; 599f4fb4fefSTzung-Bi Shih 600f4fb4fefSTzung-Bi Shih card = (struct snd_soc_card *)match->data; 601f4fb4fefSTzung-Bi Shih card->dev = &pdev->dev; 602f4fb4fefSTzung-Bi Shih 6032cc3cd5fSTzung-Bi Shih ec_codec = of_parse_phandle(pdev->dev.of_node, "mediatek,ec-codec", 0); 604f2024dc5STzung-Bi Shih hdmi_codec = of_parse_phandle(pdev->dev.of_node, 605f2024dc5STzung-Bi Shih "mediatek,hdmi-codec", 0); 6062cc3cd5fSTzung-Bi Shih 60711c02690SShunli Wang for_each_card_prelinks(card, i, dai_link) { 6082cc3cd5fSTzung-Bi Shih if (ec_codec && strcmp(dai_link->name, "Wake on Voice") == 0) { 6092cc3cd5fSTzung-Bi Shih dai_link->cpus[0].name = NULL; 6102cc3cd5fSTzung-Bi Shih dai_link->cpus[0].of_node = ec_codec; 6112cc3cd5fSTzung-Bi Shih dai_link->cpus[0].dai_name = NULL; 6122cc3cd5fSTzung-Bi Shih dai_link->codecs[0].name = NULL; 6132cc3cd5fSTzung-Bi Shih dai_link->codecs[0].of_node = ec_codec; 6142cc3cd5fSTzung-Bi Shih dai_link->codecs[0].dai_name = "Wake on Voice"; 6152cc3cd5fSTzung-Bi Shih dai_link->platforms[0].of_node = ec_codec; 6162cc3cd5fSTzung-Bi Shih dai_link->ignore = 0; 61711c02690SShunli Wang } 618f4fb4fefSTzung-Bi Shih 619f4fb4fefSTzung-Bi Shih if (strcmp(dai_link->name, "I2S3") == 0) { 620f4fb4fefSTzung-Bi Shih if (card == &mt8183_mt6358_ts3a227_max98357_card) { 621f4fb4fefSTzung-Bi Shih dai_link->be_hw_params_fixup = 622f4fb4fefSTzung-Bi Shih mt8183_i2s_hw_params_fixup; 623f4fb4fefSTzung-Bi Shih dai_link->ops = &mt8183_mt6358_i2s_ops; 624f4fb4fefSTzung-Bi Shih dai_link->cpus = i2s3_max98357a_cpus; 625f4fb4fefSTzung-Bi Shih dai_link->num_cpus = 626f4fb4fefSTzung-Bi Shih ARRAY_SIZE(i2s3_max98357a_cpus); 627f4fb4fefSTzung-Bi Shih dai_link->codecs = i2s3_max98357a_codecs; 628f4fb4fefSTzung-Bi Shih dai_link->num_codecs = 629f4fb4fefSTzung-Bi Shih ARRAY_SIZE(i2s3_max98357a_codecs); 630f4fb4fefSTzung-Bi Shih dai_link->platforms = i2s3_max98357a_platforms; 631f4fb4fefSTzung-Bi Shih dai_link->num_platforms = 632f4fb4fefSTzung-Bi Shih ARRAY_SIZE(i2s3_max98357a_platforms); 633f4fb4fefSTzung-Bi Shih } else if (card == &mt8183_mt6358_ts3a227_rt1015_card) { 634f4fb4fefSTzung-Bi Shih dai_link->be_hw_params_fixup = 635f4fb4fefSTzung-Bi Shih mt8183_rt1015_i2s_hw_params_fixup; 636f4fb4fefSTzung-Bi Shih dai_link->ops = &mt8183_mt6358_rt1015_i2s_ops; 637f4fb4fefSTzung-Bi Shih dai_link->cpus = i2s3_rt1015_cpus; 638f4fb4fefSTzung-Bi Shih dai_link->num_cpus = 639f4fb4fefSTzung-Bi Shih ARRAY_SIZE(i2s3_rt1015_cpus); 640f4fb4fefSTzung-Bi Shih dai_link->codecs = i2s3_rt1015_codecs; 641f4fb4fefSTzung-Bi Shih dai_link->num_codecs = 642f4fb4fefSTzung-Bi Shih ARRAY_SIZE(i2s3_rt1015_codecs); 643f4fb4fefSTzung-Bi Shih dai_link->platforms = i2s3_rt1015_platforms; 644f4fb4fefSTzung-Bi Shih dai_link->num_platforms = 645f4fb4fefSTzung-Bi Shih ARRAY_SIZE(i2s3_rt1015_platforms); 646f4fb4fefSTzung-Bi Shih } 647f4fb4fefSTzung-Bi Shih } 648f4fb4fefSTzung-Bi Shih 649f2024dc5STzung-Bi Shih if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) 650f2024dc5STzung-Bi Shih dai_link->codecs->of_node = hdmi_codec; 651f2024dc5STzung-Bi Shih 652f4fb4fefSTzung-Bi Shih if (!dai_link->platforms->name) 653f4fb4fefSTzung-Bi Shih dai_link->platforms->of_node = platform_node; 6542cc3cd5fSTzung-Bi Shih } 65511c02690SShunli Wang 656b812cd58SKuninori Morimoto mt8183_mt6358_ts3a227_max98357_headset_dev.dlc.of_node = 65711c02690SShunli Wang of_parse_phandle(pdev->dev.of_node, 65811c02690SShunli Wang "mediatek,headset-codec", 0); 659b812cd58SKuninori Morimoto if (mt8183_mt6358_ts3a227_max98357_headset_dev.dlc.of_node) { 660a962a809STzung-Bi Shih card->aux_dev = &mt8183_mt6358_ts3a227_max98357_headset_dev; 661a962a809STzung-Bi Shih card->num_aux_devs = 1; 66211c02690SShunli Wang } 66311c02690SShunli Wang 6646191cbdeSJiaxin Yu priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 6656191cbdeSJiaxin Yu if (!priv) 6666191cbdeSJiaxin Yu return -ENOMEM; 6676191cbdeSJiaxin Yu 6686191cbdeSJiaxin Yu snd_soc_card_set_drvdata(card, priv); 6696191cbdeSJiaxin Yu 6706191cbdeSJiaxin Yu priv->pinctrl = devm_pinctrl_get(&pdev->dev); 6716191cbdeSJiaxin Yu if (IS_ERR(priv->pinctrl)) { 6726191cbdeSJiaxin Yu dev_err(&pdev->dev, "%s devm_pinctrl_get failed\n", 67311c02690SShunli Wang __func__); 6746191cbdeSJiaxin Yu return PTR_ERR(priv->pinctrl); 6756191cbdeSJiaxin Yu } 6766191cbdeSJiaxin Yu 6776191cbdeSJiaxin Yu for (i = 0; i < PIN_STATE_MAX; i++) { 6786191cbdeSJiaxin Yu priv->pin_states[i] = pinctrl_lookup_state(priv->pinctrl, 6796191cbdeSJiaxin Yu mt8183_pin_str[i]); 6806191cbdeSJiaxin Yu if (IS_ERR(priv->pin_states[i])) { 6816191cbdeSJiaxin Yu ret = PTR_ERR(priv->pin_states[i]); 6826191cbdeSJiaxin Yu dev_info(&pdev->dev, "%s Can't find pin state %s %d\n", 6836191cbdeSJiaxin Yu __func__, mt8183_pin_str[i], ret); 6846191cbdeSJiaxin Yu } 6856191cbdeSJiaxin Yu } 6866191cbdeSJiaxin Yu 6876191cbdeSJiaxin Yu if (!IS_ERR(priv->pin_states[PIN_TDM_OUT_OFF])) { 6886191cbdeSJiaxin Yu ret = pinctrl_select_state(priv->pinctrl, 6896191cbdeSJiaxin Yu priv->pin_states[PIN_TDM_OUT_OFF]); 6906191cbdeSJiaxin Yu if (ret) 6916191cbdeSJiaxin Yu dev_info(&pdev->dev, 6926191cbdeSJiaxin Yu "%s failed to select state %d\n", 6936191cbdeSJiaxin Yu __func__, ret); 6946191cbdeSJiaxin Yu } 6956191cbdeSJiaxin Yu 6966191cbdeSJiaxin Yu if (!IS_ERR(priv->pin_states[PIN_STATE_DEFAULT])) { 6976191cbdeSJiaxin Yu ret = pinctrl_select_state(priv->pinctrl, 6986191cbdeSJiaxin Yu priv->pin_states[PIN_STATE_DEFAULT]); 6996191cbdeSJiaxin Yu if (ret) 7006191cbdeSJiaxin Yu dev_info(&pdev->dev, 7016191cbdeSJiaxin Yu "%s failed to select state %d\n", 7026191cbdeSJiaxin Yu __func__, ret); 70311c02690SShunli Wang } 70411c02690SShunli Wang 70563ba8e4dSTzung-Bi Shih return devm_snd_soc_register_card(&pdev->dev, card); 70611c02690SShunli Wang } 70711c02690SShunli Wang 70811c02690SShunli Wang #ifdef CONFIG_OF 70911c02690SShunli Wang static const struct of_device_id mt8183_mt6358_ts3a227_max98357_dt_match[] = { 710f4fb4fefSTzung-Bi Shih { 711f4fb4fefSTzung-Bi Shih .compatible = "mediatek,mt8183_mt6358_ts3a227_max98357", 712f4fb4fefSTzung-Bi Shih .data = &mt8183_mt6358_ts3a227_max98357_card, 713f4fb4fefSTzung-Bi Shih }, 714f4fb4fefSTzung-Bi Shih { 715f4fb4fefSTzung-Bi Shih .compatible = "mediatek,mt8183_mt6358_ts3a227_rt1015", 716f4fb4fefSTzung-Bi Shih .data = &mt8183_mt6358_ts3a227_rt1015_card, 717f4fb4fefSTzung-Bi Shih }, 71811c02690SShunli Wang {} 71911c02690SShunli Wang }; 72011c02690SShunli Wang #endif 72111c02690SShunli Wang 72211c02690SShunli Wang static struct platform_driver mt8183_mt6358_ts3a227_max98357_driver = { 72311c02690SShunli Wang .driver = { 724f4fb4fefSTzung-Bi Shih .name = "mt8183_mt6358_ts3a227", 72511c02690SShunli Wang #ifdef CONFIG_OF 72611c02690SShunli Wang .of_match_table = mt8183_mt6358_ts3a227_max98357_dt_match, 72711c02690SShunli Wang #endif 72811c02690SShunli Wang }, 72911c02690SShunli Wang .probe = mt8183_mt6358_ts3a227_max98357_dev_probe, 73011c02690SShunli Wang }; 73111c02690SShunli Wang 73211c02690SShunli Wang module_platform_driver(mt8183_mt6358_ts3a227_max98357_driver); 73311c02690SShunli Wang 73411c02690SShunli Wang /* Module information */ 73511c02690SShunli Wang MODULE_DESCRIPTION("MT8183-MT6358-TS3A227-MAX98357 ALSA SoC machine driver"); 73611c02690SShunli Wang MODULE_AUTHOR("Shunli Wang <shunli.wang@mediatek.com>"); 73711c02690SShunli Wang MODULE_LICENSE("GPL v2"); 73811c02690SShunli Wang MODULE_ALIAS("mt8183_mt6358_ts3a227_max98357 soc card"); 739