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

1 // SPDX-License-Identifier: GPL-2.0
3 // mt8183-da7219-max98357.c
4 // -- MT8183-DA7219-MAX98357 ALSA SoC machine driver
19 #include "../common/mtk-afe-platform-driver.h"
20 #include "mt8183-afe-common.h"
22 #define DA7219_CODEC_DAI "da7219-hifi"
23 #define DA7219_DEV_NAME "da7219.5-001a"
24 #define RT1015_CODEC_DAI "rt1015-aif"
25 #define RT1015_DEV0_NAME "rt1015.6-0028"
26 #define RT1015_DEV1_NAME "rt1015.6-0029"
47 static int mt8183_mt6358_i2s_hw_params(struct snd_pcm_substream *substream, in mt8183_mt6358_i2s_hw_params()
48 struct snd_pcm_hw_params *params) in mt8183_mt6358_i2s_hw_params() argument
51 unsigned int rate = params_rate(params); in mt8183_mt6358_i2s_hw_params()
52 unsigned int mclk_fs_ratio = 128; in mt8183_mt6358_i2s_hw_params()
53 unsigned int mclk_fs = rate * mclk_fs_ratio; in mt8183_mt6358_i2s_hw_params()
63 static int mt8183_da7219_i2s_hw_params(struct snd_pcm_substream *substream, in mt8183_da7219_i2s_hw_params()
64 struct snd_pcm_hw_params *params) in mt8183_da7219_i2s_hw_params() argument
68 unsigned int rate = params_rate(params); in mt8183_da7219_i2s_hw_params()
69 unsigned int mclk_fs_ratio = 256; in mt8183_da7219_i2s_hw_params()
70 unsigned int mclk_fs = rate * mclk_fs_ratio; in mt8183_da7219_i2s_hw_params()
71 unsigned int freq; in mt8183_da7219_i2s_hw_params()
72 int ret = 0, j; in mt8183_da7219_i2s_hw_params()
77 dev_err(rtd->dev, "failed to set cpu dai sysclk\n"); in mt8183_da7219_i2s_hw_params()
80 if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { in mt8183_da7219_i2s_hw_params()
86 dev_err(rtd->dev, "failed to set sysclk\n"); in mt8183_da7219_i2s_hw_params()
97 dev_err(rtd->dev, "failed to start PLL: %d\n", in mt8183_da7219_i2s_hw_params()
105 static int mt8183_da7219_hw_free(struct snd_pcm_substream *substream) in mt8183_da7219_hw_free()
109 int ret = 0, j; in mt8183_da7219_hw_free()
112 if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { in mt8183_da7219_hw_free()
116 dev_err(rtd->dev, "failed to stop PLL: %d\n", in mt8183_da7219_hw_free()
131 static int
133 struct snd_pcm_hw_params *params) in mt8183_da7219_rt1015_i2s_hw_params() argument
136 unsigned int rate = params_rate(params); in mt8183_da7219_rt1015_i2s_hw_params()
138 int ret = 0, i; in mt8183_da7219_rt1015_i2s_hw_params()
141 if (!strcmp(codec_dai->component->name, RT1015_DEV0_NAME) || in mt8183_da7219_rt1015_i2s_hw_params()
142 !strcmp(codec_dai->component->name, RT1015_DEV1_NAME)) { in mt8183_da7219_rt1015_i2s_hw_params()
147 dev_err(rtd->dev, "failed to set pll\n"); in mt8183_da7219_rt1015_i2s_hw_params()
156 dev_err(rtd->dev, "failed to set sysclk\n"); in mt8183_da7219_rt1015_i2s_hw_params()
162 return mt8183_da7219_i2s_hw_params(substream, params); in mt8183_da7219_rt1015_i2s_hw_params()
170 static int mt8183_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, in mt8183_i2s_hw_params_fixup()
171 struct snd_pcm_hw_params *params) in mt8183_i2s_hw_params_fixup() argument
174 snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), in mt8183_i2s_hw_params_fixup()
175 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); in mt8183_i2s_hw_params_fixup()
177 params_set_format(params, SNDRV_PCM_FORMAT_S32_LE); in mt8183_i2s_hw_params_fixup()
182 static int mt8183_rt1015_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, in mt8183_rt1015_i2s_hw_params_fixup()
183 struct snd_pcm_hw_params *params) in mt8183_rt1015_i2s_hw_params_fixup() argument
186 snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), in mt8183_rt1015_i2s_hw_params_fixup()
187 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); in mt8183_rt1015_i2s_hw_params_fixup()
189 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); in mt8183_rt1015_i2s_hw_params_fixup()
194 static int
198 static const unsigned int rates[] = { in mt8183_da7219_max98357_startup()
206 static const unsigned int channels[] = { in mt8183_da7219_max98357_startup()
215 struct snd_pcm_runtime *runtime = substream->runtime; in mt8183_da7219_max98357_startup()
219 runtime->hw.channels_max = 2; in mt8183_da7219_max98357_startup()
224 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; in mt8183_da7219_max98357_startup()
234 static int
238 static const unsigned int rates[] = { in mt8183_da7219_max98357_bt_sco_startup()
246 static const unsigned int channels[] = { in mt8183_da7219_max98357_bt_sco_startup()
255 struct snd_pcm_runtime *runtime = substream->runtime; in mt8183_da7219_max98357_bt_sco_startup()
259 runtime->hw.channels_max = 1; in mt8183_da7219_max98357_bt_sco_startup()
264 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE; in mt8183_da7219_max98357_bt_sco_startup()
318 DAILINK_COMP_ARRAY(COMP_CODEC("mt6358-sound", "mt6358-snd-codec-aif1")),
322 DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")),
327 DAILINK_COMP_ARRAY(COMP_CPU("PCM 2")),
333 DAILINK_COMP_ARRAY(COMP_CODEC("bt-sco", "bt-sco-pcm")),
367 DAILINK_COMP_ARRAY(COMP_CODEC("bt-sco", "bt-sco-pcm")),
372 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")),
375 static int mt8183_da7219_max98357_hdmi_init(struct snd_soc_pcm_runtime *rtd) in mt8183_da7219_max98357_hdmi_init()
378 snd_soc_card_get_drvdata(rtd->card); in mt8183_da7219_max98357_hdmi_init()
379 int ret; in mt8183_da7219_max98357_hdmi_init()
381 ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, in mt8183_da7219_max98357_hdmi_init()
382 &priv->hdmi_jack); in mt8183_da7219_max98357_hdmi_init()
386 return snd_soc_component_set_jack(snd_soc_rtd_to_codec(rtd, 0)->component, in mt8183_da7219_max98357_hdmi_init()
387 &priv->hdmi_jack, NULL); in mt8183_da7219_max98357_hdmi_init()
390 static int mt8183_bt_init(struct snd_soc_pcm_runtime *rtd) in mt8183_bt_init()
395 int ret; in mt8183_bt_init()
399 dev_err(rtd->dev, "Failed to set up shared clocks\n"); in mt8183_bt_init()
405 static int mt8183_da7219_init(struct snd_soc_pcm_runtime *rtd) in mt8183_da7219_init()
410 int ret; in mt8183_da7219_init()
414 dev_err(rtd->dev, "Failed to set up shared clocks\n"); in mt8183_da7219_init()
506 .name = "PCM 1",
512 .name = "PCM 2",
576 static int
579 int ret; in mt8183_da7219_max98357_headset_init()
581 snd_soc_card_get_drvdata(component->card); in mt8183_da7219_max98357_headset_init()
584 ret = snd_soc_card_jack_new_pins(component->card, in mt8183_da7219_max98357_headset_init()
590 &priv->headset_jack, in mt8183_da7219_max98357_headset_init()
597 priv->headset_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); in mt8183_da7219_max98357_headset_init()
599 priv->headset_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP); in mt8183_da7219_max98357_headset_init()
601 priv->headset_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); in mt8183_da7219_max98357_headset_init()
603 priv->headset_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); in mt8183_da7219_max98357_headset_init()
605 snd_soc_component_set_jack(component, &priv->headset_jack, NULL); in mt8183_da7219_max98357_headset_init()
617 .dlc = COMP_CODEC_CONF("mt6358-sound"),
663 .dlc = COMP_CODEC_CONF("mt6358-sound"),
735 static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev) in mt8183_da7219_max98357_dev_probe()
742 int ret, i; in mt8183_da7219_max98357_dev_probe()
744 platform_node = of_parse_phandle(pdev->dev.of_node, in mt8183_da7219_max98357_dev_probe()
747 dev_err(&pdev->dev, "Property 'platform' missing or invalid\n"); in mt8183_da7219_max98357_dev_probe()
748 return -EINVAL; in mt8183_da7219_max98357_dev_probe()
751 card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev); in mt8183_da7219_max98357_dev_probe()
753 ret = -EINVAL; in mt8183_da7219_max98357_dev_probe()
757 card->dev = &pdev->dev; in mt8183_da7219_max98357_dev_probe()
759 hdmi_codec = of_parse_phandle(pdev->dev.of_node, in mt8183_da7219_max98357_dev_probe()
760 "mediatek,hdmi-codec", 0); in mt8183_da7219_max98357_dev_probe()
763 if (strcmp(dai_link->name, "I2S3") == 0) { in mt8183_da7219_max98357_dev_probe()
765 dai_link->be_hw_params_fixup = in mt8183_da7219_max98357_dev_probe()
767 dai_link->ops = &mt8183_da7219_i2s_ops; in mt8183_da7219_max98357_dev_probe()
768 dai_link->cpus = i2s3_max98357a_cpus; in mt8183_da7219_max98357_dev_probe()
769 dai_link->num_cpus = in mt8183_da7219_max98357_dev_probe()
771 dai_link->codecs = i2s3_max98357a_codecs; in mt8183_da7219_max98357_dev_probe()
772 dai_link->num_codecs = in mt8183_da7219_max98357_dev_probe()
774 dai_link->platforms = i2s3_max98357a_platforms; in mt8183_da7219_max98357_dev_probe()
775 dai_link->num_platforms = in mt8183_da7219_max98357_dev_probe()
778 dai_link->be_hw_params_fixup = in mt8183_da7219_max98357_dev_probe()
780 dai_link->ops = &mt8183_da7219_rt1015_i2s_ops; in mt8183_da7219_max98357_dev_probe()
781 dai_link->cpus = i2s3_rt1015_cpus; in mt8183_da7219_max98357_dev_probe()
782 dai_link->num_cpus = in mt8183_da7219_max98357_dev_probe()
784 dai_link->codecs = i2s3_rt1015_codecs; in mt8183_da7219_max98357_dev_probe()
785 dai_link->num_codecs = in mt8183_da7219_max98357_dev_probe()
787 dai_link->platforms = i2s3_rt1015_platforms; in mt8183_da7219_max98357_dev_probe()
788 dai_link->num_platforms = in mt8183_da7219_max98357_dev_probe()
791 dai_link->be_hw_params_fixup = in mt8183_da7219_max98357_dev_probe()
793 dai_link->ops = &mt8183_da7219_i2s_ops; in mt8183_da7219_max98357_dev_probe()
794 dai_link->cpus = i2s3_rt1015p_cpus; in mt8183_da7219_max98357_dev_probe()
795 dai_link->num_cpus = in mt8183_da7219_max98357_dev_probe()
797 dai_link->codecs = i2s3_rt1015p_codecs; in mt8183_da7219_max98357_dev_probe()
798 dai_link->num_codecs = in mt8183_da7219_max98357_dev_probe()
800 dai_link->platforms = i2s3_rt1015p_platforms; in mt8183_da7219_max98357_dev_probe()
801 dai_link->num_platforms = in mt8183_da7219_max98357_dev_probe()
806 if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) { in mt8183_da7219_max98357_dev_probe()
807 dai_link->codecs->of_node = hdmi_codec; in mt8183_da7219_max98357_dev_probe()
808 dai_link->ignore = 0; in mt8183_da7219_max98357_dev_probe()
811 if (!dai_link->platforms->name) in mt8183_da7219_max98357_dev_probe()
812 dai_link->platforms->of_node = platform_node; in mt8183_da7219_max98357_dev_probe()
816 of_parse_phandle(pdev->dev.of_node, in mt8183_da7219_max98357_dev_probe()
817 "mediatek,headset-codec", 0); in mt8183_da7219_max98357_dev_probe()
819 dev_err(&pdev->dev, in mt8183_da7219_max98357_dev_probe()
820 "Property 'mediatek,headset-codec' missing/invalid\n"); in mt8183_da7219_max98357_dev_probe()
821 ret = -EINVAL; in mt8183_da7219_max98357_dev_probe()
825 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in mt8183_da7219_max98357_dev_probe()
827 ret = -ENOMEM; in mt8183_da7219_max98357_dev_probe()
833 pinctrl = devm_pinctrl_get_select(&pdev->dev, PINCTRL_STATE_DEFAULT); in mt8183_da7219_max98357_dev_probe()
836 dev_err(&pdev->dev, "%s failed to select default state %d\n", in mt8183_da7219_max98357_dev_probe()
841 ret = devm_snd_soc_register_card(&pdev->dev, card); in mt8183_da7219_max98357_dev_probe()
884 MODULE_DESCRIPTION("MT8183-DA7219-MAX98357 ALSA SoC machine driver");