Lines Matching +full:bt +full:- +full:pcm +full:- +full:int +full:- +full:params

1 // SPDX-License-Identifier: GPL-2.0
3 // mt8183-mt6358.c --
4 // MT8183-MT6358-TS3A227-MAX98357 ALSA SoC machine driver
18 #include "../common/mtk-afe-platform-driver.h"
19 #include "mt8183-afe-common.h"
21 #define RT1015_CODEC_DAI "rt1015-aif"
22 #define RT1015_DEV0_NAME "rt1015.6-0028"
23 #define RT1015_DEV1_NAME "rt1015.6-0029"
43 static int mt8183_mt6358_i2s_hw_params(struct snd_pcm_substream *substream, in mt8183_mt6358_i2s_hw_params()
44 struct snd_pcm_hw_params *params) in mt8183_mt6358_i2s_hw_params() argument
47 unsigned int rate = params_rate(params); in mt8183_mt6358_i2s_hw_params()
48 unsigned int mclk_fs_ratio = 128; in mt8183_mt6358_i2s_hw_params()
49 unsigned int mclk_fs = rate * mclk_fs_ratio; in mt8183_mt6358_i2s_hw_params()
59 static int
61 struct snd_pcm_hw_params *params) in mt8183_mt6358_rt1015_i2s_hw_params() argument
64 unsigned int rate = params_rate(params); in mt8183_mt6358_rt1015_i2s_hw_params()
65 unsigned int mclk_fs_ratio = 128; in mt8183_mt6358_rt1015_i2s_hw_params()
66 unsigned int mclk_fs = rate * mclk_fs_ratio; in mt8183_mt6358_rt1015_i2s_hw_params()
67 struct snd_soc_card *card = rtd->card; in mt8183_mt6358_rt1015_i2s_hw_params()
69 int ret, i; in mt8183_mt6358_rt1015_i2s_hw_params()
75 dev_err(card->dev, "failed to set pll\n"); in mt8183_mt6358_rt1015_i2s_hw_params()
82 dev_err(card->dev, "failed to set sysclk\n"); in mt8183_mt6358_rt1015_i2s_hw_params()
95 static int mt8183_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, in mt8183_i2s_hw_params_fixup()
96 struct snd_pcm_hw_params *params) in mt8183_i2s_hw_params_fixup() argument
98 dev_dbg(rtd->dev, "%s(), fix format to S32_LE\n", __func__); in mt8183_i2s_hw_params_fixup()
101 snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), in mt8183_i2s_hw_params_fixup()
102 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); in mt8183_i2s_hw_params_fixup()
104 params_set_format(params, SNDRV_PCM_FORMAT_S32_LE); in mt8183_i2s_hw_params_fixup()
108 static int mt8183_rt1015_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, in mt8183_rt1015_i2s_hw_params_fixup()
109 struct snd_pcm_hw_params *params) in mt8183_rt1015_i2s_hw_params_fixup() argument
111 dev_dbg(rtd->dev, "%s(), fix format to S24_LE\n", __func__); in mt8183_rt1015_i2s_hw_params_fixup()
114 snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), in mt8183_rt1015_i2s_hw_params_fixup()
115 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); in mt8183_rt1015_i2s_hw_params_fixup()
117 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); in mt8183_rt1015_i2s_hw_params_fixup()
121 static int
124 static const unsigned int rates[] = { in mt8183_mt6358_startup()
132 static const unsigned int channels[] = { in mt8183_mt6358_startup()
141 struct snd_pcm_runtime *runtime = substream->runtime; in mt8183_mt6358_startup()
145 runtime->hw.channels_max = 2; in mt8183_mt6358_startup()
150 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; in mt8183_mt6358_startup()
160 static int
164 static const unsigned int rates[] = { in mt8183_mt6358_ts3a227_max98357_bt_sco_startup()
172 static const unsigned int channels[] = { in mt8183_mt6358_ts3a227_max98357_bt_sco_startup()
181 struct snd_pcm_runtime *runtime = substream->runtime; in mt8183_mt6358_ts3a227_max98357_bt_sco_startup()
185 runtime->hw.channels_max = 1; in mt8183_mt6358_ts3a227_max98357_bt_sco_startup()
190 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; in mt8183_mt6358_ts3a227_max98357_bt_sco_startup()
249 DAILINK_COMP_ARRAY(COMP_CODEC("mt6358-sound", "mt6358-snd-codec-aif1")),
253 DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")),
258 DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")),
264 DAILINK_COMP_ARRAY(COMP_CODEC("bt-sco", "bt-sco-pcm-wb")),
295 DAILINK_COMP_ARRAY(COMP_CODEC("bt-sco", "bt-sco-pcm-wb")),
300 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")),
303 static int mt8183_mt6358_tdm_startup(struct snd_pcm_substream *substream) in mt8183_mt6358_tdm_startup()
307 snd_soc_card_get_drvdata(rtd->card); in mt8183_mt6358_tdm_startup()
308 int ret; in mt8183_mt6358_tdm_startup()
310 if (IS_ERR(priv->pin_states[PIN_TDM_OUT_ON])) in mt8183_mt6358_tdm_startup()
311 return PTR_ERR(priv->pin_states[PIN_TDM_OUT_ON]); in mt8183_mt6358_tdm_startup()
313 ret = pinctrl_select_state(priv->pinctrl, in mt8183_mt6358_tdm_startup()
314 priv->pin_states[PIN_TDM_OUT_ON]); in mt8183_mt6358_tdm_startup()
316 dev_err(rtd->card->dev, "%s failed to select state %d\n", in mt8183_mt6358_tdm_startup()
326 snd_soc_card_get_drvdata(rtd->card); in mt8183_mt6358_tdm_shutdown()
327 int ret; in mt8183_mt6358_tdm_shutdown()
329 if (IS_ERR(priv->pin_states[PIN_TDM_OUT_OFF])) in mt8183_mt6358_tdm_shutdown()
332 ret = pinctrl_select_state(priv->pinctrl, in mt8183_mt6358_tdm_shutdown()
333 priv->pin_states[PIN_TDM_OUT_OFF]); in mt8183_mt6358_tdm_shutdown()
335 dev_err(rtd->card->dev, "%s failed to select state %d\n", in mt8183_mt6358_tdm_shutdown()
344 static int
349 struct snd_soc_card *card = rtd->card; in mt8183_mt6358_ts3a227_max98357_wov_startup()
353 return pinctrl_select_state(priv->pinctrl, in mt8183_mt6358_ts3a227_max98357_wov_startup()
354 priv->pin_states[PIN_WOV]); in mt8183_mt6358_ts3a227_max98357_wov_startup()
362 struct snd_soc_card *card = rtd->card; in mt8183_mt6358_ts3a227_max98357_wov_shutdown()
365 int ret; in mt8183_mt6358_ts3a227_max98357_wov_shutdown()
367 ret = pinctrl_select_state(priv->pinctrl, in mt8183_mt6358_ts3a227_max98357_wov_shutdown()
368 priv->pin_states[PIN_STATE_DEFAULT]); in mt8183_mt6358_ts3a227_max98357_wov_shutdown()
370 dev_err(card->dev, "%s failed to select state %d\n", in mt8183_mt6358_ts3a227_max98357_wov_shutdown()
379 static int
383 snd_soc_card_get_drvdata(rtd->card); in mt8183_mt6358_ts3a227_max98357_hdmi_init()
384 int ret; in mt8183_mt6358_ts3a227_max98357_hdmi_init()
386 ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, in mt8183_mt6358_ts3a227_max98357_hdmi_init()
387 &priv->hdmi_jack); in mt8183_mt6358_ts3a227_max98357_hdmi_init()
391 return snd_soc_component_set_jack(snd_soc_rtd_to_codec(rtd, 0)->component, in mt8183_mt6358_ts3a227_max98357_hdmi_init()
392 &priv->hdmi_jack, NULL); in mt8183_mt6358_ts3a227_max98357_hdmi_init()
395 static int mt8183_bt_init(struct snd_soc_pcm_runtime *rtd) in mt8183_bt_init()
400 int ret; in mt8183_bt_init()
404 dev_err(rtd->dev, "Failed to set up shared clocks\n"); in mt8183_bt_init()
410 static int mt8183_i2s2_init(struct snd_soc_pcm_runtime *rtd) in mt8183_i2s2_init()
415 int ret; in mt8183_i2s2_init()
419 dev_err(rtd->dev, "Failed to set up shared clocks\n"); in mt8183_i2s2_init()
520 .name = "PCM 1",
526 .name = "PCM 2",
669 static int
672 int ret; in mt8183_mt6358_ts3a227_max98357_headset_init()
674 snd_soc_card_get_drvdata(component->card); in mt8183_mt6358_ts3a227_max98357_headset_init()
677 ret = snd_soc_card_jack_new_pins(component->card, in mt8183_mt6358_ts3a227_max98357_headset_init()
682 &priv->headset_jack, in mt8183_mt6358_ts3a227_max98357_headset_init()
688 ret = ts3a227e_enable_jack_detect(component, &priv->headset_jack); in mt8183_mt6358_ts3a227_max98357_headset_init()
698 static int
705 int ret, i; in mt8183_mt6358_ts3a227_max98357_dev_probe()
707 platform_node = of_parse_phandle(pdev->dev.of_node, in mt8183_mt6358_ts3a227_max98357_dev_probe()
710 dev_err(&pdev->dev, "Property 'platform' missing or invalid\n"); in mt8183_mt6358_ts3a227_max98357_dev_probe()
711 return -EINVAL; in mt8183_mt6358_ts3a227_max98357_dev_probe()
714 card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev); in mt8183_mt6358_ts3a227_max98357_dev_probe()
717 return -EINVAL; in mt8183_mt6358_ts3a227_max98357_dev_probe()
719 card->dev = &pdev->dev; in mt8183_mt6358_ts3a227_max98357_dev_probe()
721 ec_codec = of_parse_phandle(pdev->dev.of_node, "mediatek,ec-codec", 0); in mt8183_mt6358_ts3a227_max98357_dev_probe()
722 hdmi_codec = of_parse_phandle(pdev->dev.of_node, in mt8183_mt6358_ts3a227_max98357_dev_probe()
723 "mediatek,hdmi-codec", 0); in mt8183_mt6358_ts3a227_max98357_dev_probe()
726 if (ec_codec && strcmp(dai_link->name, "Wake on Voice") == 0) { in mt8183_mt6358_ts3a227_max98357_dev_probe()
727 dai_link->cpus[0].name = NULL; in mt8183_mt6358_ts3a227_max98357_dev_probe()
728 dai_link->cpus[0].of_node = ec_codec; in mt8183_mt6358_ts3a227_max98357_dev_probe()
729 dai_link->cpus[0].dai_name = NULL; in mt8183_mt6358_ts3a227_max98357_dev_probe()
730 dai_link->codecs[0].name = NULL; in mt8183_mt6358_ts3a227_max98357_dev_probe()
731 dai_link->codecs[0].of_node = ec_codec; in mt8183_mt6358_ts3a227_max98357_dev_probe()
732 dai_link->codecs[0].dai_name = "Wake on Voice"; in mt8183_mt6358_ts3a227_max98357_dev_probe()
733 dai_link->platforms[0].of_node = ec_codec; in mt8183_mt6358_ts3a227_max98357_dev_probe()
734 dai_link->ignore = 0; in mt8183_mt6358_ts3a227_max98357_dev_probe()
737 if (strcmp(dai_link->name, "I2S3") == 0) { in mt8183_mt6358_ts3a227_max98357_dev_probe()
740 dai_link->be_hw_params_fixup = in mt8183_mt6358_ts3a227_max98357_dev_probe()
742 dai_link->ops = &mt8183_mt6358_i2s_ops; in mt8183_mt6358_ts3a227_max98357_dev_probe()
743 dai_link->cpus = i2s3_max98357a_cpus; in mt8183_mt6358_ts3a227_max98357_dev_probe()
744 dai_link->num_cpus = in mt8183_mt6358_ts3a227_max98357_dev_probe()
746 dai_link->codecs = i2s3_max98357a_codecs; in mt8183_mt6358_ts3a227_max98357_dev_probe()
747 dai_link->num_codecs = in mt8183_mt6358_ts3a227_max98357_dev_probe()
749 dai_link->platforms = i2s3_max98357a_platforms; in mt8183_mt6358_ts3a227_max98357_dev_probe()
750 dai_link->num_platforms = in mt8183_mt6358_ts3a227_max98357_dev_probe()
753 dai_link->be_hw_params_fixup = in mt8183_mt6358_ts3a227_max98357_dev_probe()
755 dai_link->ops = &mt8183_mt6358_rt1015_i2s_ops; in mt8183_mt6358_ts3a227_max98357_dev_probe()
756 dai_link->cpus = i2s3_rt1015_cpus; in mt8183_mt6358_ts3a227_max98357_dev_probe()
757 dai_link->num_cpus = in mt8183_mt6358_ts3a227_max98357_dev_probe()
759 dai_link->codecs = i2s3_rt1015_codecs; in mt8183_mt6358_ts3a227_max98357_dev_probe()
760 dai_link->num_codecs = in mt8183_mt6358_ts3a227_max98357_dev_probe()
762 dai_link->platforms = i2s3_rt1015_platforms; in mt8183_mt6358_ts3a227_max98357_dev_probe()
763 dai_link->num_platforms = in mt8183_mt6358_ts3a227_max98357_dev_probe()
766 dai_link->be_hw_params_fixup = in mt8183_mt6358_ts3a227_max98357_dev_probe()
768 dai_link->ops = &mt8183_mt6358_i2s_ops; in mt8183_mt6358_ts3a227_max98357_dev_probe()
769 dai_link->cpus = i2s3_rt1015p_cpus; in mt8183_mt6358_ts3a227_max98357_dev_probe()
770 dai_link->num_cpus = in mt8183_mt6358_ts3a227_max98357_dev_probe()
772 dai_link->codecs = i2s3_rt1015p_codecs; in mt8183_mt6358_ts3a227_max98357_dev_probe()
773 dai_link->num_codecs = in mt8183_mt6358_ts3a227_max98357_dev_probe()
775 dai_link->platforms = i2s3_rt1015p_platforms; in mt8183_mt6358_ts3a227_max98357_dev_probe()
776 dai_link->num_platforms = in mt8183_mt6358_ts3a227_max98357_dev_probe()
782 if (strcmp(dai_link->name, "I2S2") == 0 || in mt8183_mt6358_ts3a227_max98357_dev_probe()
783 strcmp(dai_link->name, "I2S3") == 0) in mt8183_mt6358_ts3a227_max98357_dev_probe()
784 dai_link->dai_fmt = SND_SOC_DAIFMT_LEFT_J | in mt8183_mt6358_ts3a227_max98357_dev_probe()
789 if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) { in mt8183_mt6358_ts3a227_max98357_dev_probe()
790 dai_link->codecs->of_node = hdmi_codec; in mt8183_mt6358_ts3a227_max98357_dev_probe()
791 dai_link->ignore = 0; in mt8183_mt6358_ts3a227_max98357_dev_probe()
794 if (!dai_link->platforms->name) in mt8183_mt6358_ts3a227_max98357_dev_probe()
795 dai_link->platforms->of_node = platform_node; in mt8183_mt6358_ts3a227_max98357_dev_probe()
799 of_parse_phandle(pdev->dev.of_node, in mt8183_mt6358_ts3a227_max98357_dev_probe()
800 "mediatek,headset-codec", 0); in mt8183_mt6358_ts3a227_max98357_dev_probe()
802 card->aux_dev = &mt8183_mt6358_ts3a227_max98357_headset_dev; in mt8183_mt6358_ts3a227_max98357_dev_probe()
803 card->num_aux_devs = 1; in mt8183_mt6358_ts3a227_max98357_dev_probe()
806 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in mt8183_mt6358_ts3a227_max98357_dev_probe()
808 ret = -ENOMEM; in mt8183_mt6358_ts3a227_max98357_dev_probe()
814 priv->pinctrl = devm_pinctrl_get(&pdev->dev); in mt8183_mt6358_ts3a227_max98357_dev_probe()
815 if (IS_ERR(priv->pinctrl)) { in mt8183_mt6358_ts3a227_max98357_dev_probe()
816 dev_err(&pdev->dev, "%s devm_pinctrl_get failed\n", in mt8183_mt6358_ts3a227_max98357_dev_probe()
818 ret = PTR_ERR(priv->pinctrl); in mt8183_mt6358_ts3a227_max98357_dev_probe()
823 priv->pin_states[i] = pinctrl_lookup_state(priv->pinctrl, in mt8183_mt6358_ts3a227_max98357_dev_probe()
825 if (IS_ERR(priv->pin_states[i])) { in mt8183_mt6358_ts3a227_max98357_dev_probe()
826 ret = PTR_ERR(priv->pin_states[i]); in mt8183_mt6358_ts3a227_max98357_dev_probe()
827 dev_info(&pdev->dev, "%s Can't find pin state %s %d\n", in mt8183_mt6358_ts3a227_max98357_dev_probe()
832 if (!IS_ERR(priv->pin_states[PIN_TDM_OUT_OFF])) { in mt8183_mt6358_ts3a227_max98357_dev_probe()
833 ret = pinctrl_select_state(priv->pinctrl, in mt8183_mt6358_ts3a227_max98357_dev_probe()
834 priv->pin_states[PIN_TDM_OUT_OFF]); in mt8183_mt6358_ts3a227_max98357_dev_probe()
836 dev_info(&pdev->dev, in mt8183_mt6358_ts3a227_max98357_dev_probe()
841 if (!IS_ERR(priv->pin_states[PIN_STATE_DEFAULT])) { in mt8183_mt6358_ts3a227_max98357_dev_probe()
842 ret = pinctrl_select_state(priv->pinctrl, in mt8183_mt6358_ts3a227_max98357_dev_probe()
843 priv->pin_states[PIN_STATE_DEFAULT]); in mt8183_mt6358_ts3a227_max98357_dev_probe()
845 dev_info(&pdev->dev, in mt8183_mt6358_ts3a227_max98357_dev_probe()
850 ret = devm_snd_soc_register_card(&pdev->dev, card); in mt8183_mt6358_ts3a227_max98357_dev_probe()
896 MODULE_DESCRIPTION("MT8183-MT6358-TS3A227-MAX98357 ALSA SoC machine driver");