Lines Matching +full:tdm +full:- +full:data +full:- +full:out
1 // SPDX-License-Identifier: GPL-2.0
3 // mt8192-mt6359-rt1015-rt5682.c --
4 // MT8192-MT6359-RT1015-RT6358 ALSA SoC machine driver
22 #include "../common/mtk-afe-platform-driver.h"
23 #include "mt8192-afe-common.h"
24 #include "mt8192-afe-clk.h"
25 #include "mt8192-afe-gpio.h"
29 #define RT1015_CODEC_DAI "rt1015-aif"
30 #define RT1015_DEV0_NAME "rt1015.1-0028"
31 #define RT1015_DEV1_NAME "rt1015.1-0029"
62 struct snd_soc_card *card = rtd->card; in mt8192_rt1015_i2s_hw_params()
76 dev_err(card->dev, "failed to set pll\n"); in mt8192_rt1015_i2s_hw_params()
85 dev_err(card->dev, "failed to set sysclk\n"); in mt8192_rt1015_i2s_hw_params()
97 struct snd_soc_card *card = rtd->card; in mt8192_rt5682x_i2s_hw_params()
108 dev_err(card->dev, "invalid bit width: %d\n", bitwidth); in mt8192_rt5682x_i2s_hw_params()
114 dev_err(card->dev, "failed to set tdm slot\n"); in mt8192_rt5682x_i2s_hw_params()
123 dev_err(card->dev, "failed to set pll\n"); in mt8192_rt5682x_i2s_hw_params()
132 dev_err(card->dev, "failed to set sysclk\n"); in mt8192_rt5682x_i2s_hw_params()
152 asoc_rtd_to_codec(rtd, 0)->component; in mt8192_mt6359_mtkaif_calibration()
154 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mt8192_mt6359_mtkaif_calibration()
164 dev_info(afe->dev, "%s(), start\n", __func__); in mt8192_mt6359_mtkaif_calibration()
166 pm_runtime_get_sync(afe->dev); in mt8192_mt6359_mtkaif_calibration()
167 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 1); in mt8192_mt6359_mtkaif_calibration()
168 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 0); in mt8192_mt6359_mtkaif_calibration()
169 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 1); in mt8192_mt6359_mtkaif_calibration()
170 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 0); in mt8192_mt6359_mtkaif_calibration()
175 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38); in mt8192_mt6359_mtkaif_calibration()
176 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x39); in mt8192_mt6359_mtkaif_calibration()
179 regmap_update_bits(afe_priv->topckgen, in mt8192_mt6359_mtkaif_calibration()
183 afe_priv->mtkaif_calibration_num_phase = 42; /* mt6359: 0 ~ 42 */ in mt8192_mt6359_mtkaif_calibration()
184 afe_priv->mtkaif_chosen_phase[0] = -1; in mt8192_mt6359_mtkaif_calibration()
185 afe_priv->mtkaif_chosen_phase[1] = -1; in mt8192_mt6359_mtkaif_calibration()
186 afe_priv->mtkaif_chosen_phase[2] = -1; in mt8192_mt6359_mtkaif_calibration()
189 phase <= afe_priv->mtkaif_calibration_num_phase && in mt8192_mt6359_mtkaif_calibration()
195 regmap_update_bits(afe_priv->topckgen, in mt8192_mt6359_mtkaif_calibration()
201 cycle_1 = -1; in mt8192_mt6359_mtkaif_calibration()
202 cycle_2 = -1; in mt8192_mt6359_mtkaif_calibration()
203 cycle_3 = -1; in mt8192_mt6359_mtkaif_calibration()
208 regmap_read(afe_priv->topckgen, in mt8192_mt6359_mtkaif_calibration()
225 dev_err(afe->dev, "%s(), test fail, cycle_1 %d, cycle_2 %d, cycle_3 %d, monitor 0x%x\n", in mt8192_mt6359_mtkaif_calibration()
240 afe_priv->mtkaif_chosen_phase[0] < 0) { in mt8192_mt6359_mtkaif_calibration()
241 afe_priv->mtkaif_chosen_phase[0] = phase - 1; in mt8192_mt6359_mtkaif_calibration()
242 afe_priv->mtkaif_phase_cycle[0] = prev_cycle_1; in mt8192_mt6359_mtkaif_calibration()
246 afe_priv->mtkaif_chosen_phase[1] < 0) { in mt8192_mt6359_mtkaif_calibration()
247 afe_priv->mtkaif_chosen_phase[1] = phase - 1; in mt8192_mt6359_mtkaif_calibration()
248 afe_priv->mtkaif_phase_cycle[1] = prev_cycle_2; in mt8192_mt6359_mtkaif_calibration()
252 afe_priv->mtkaif_chosen_phase[2] < 0) { in mt8192_mt6359_mtkaif_calibration()
253 afe_priv->mtkaif_chosen_phase[2] = phase - 1; in mt8192_mt6359_mtkaif_calibration()
254 afe_priv->mtkaif_phase_cycle[2] = prev_cycle_3; in mt8192_mt6359_mtkaif_calibration()
257 regmap_update_bits(afe_priv->topckgen, in mt8192_mt6359_mtkaif_calibration()
260 if (afe_priv->mtkaif_chosen_phase[0] >= 0 && in mt8192_mt6359_mtkaif_calibration()
261 afe_priv->mtkaif_chosen_phase[1] >= 0 && in mt8192_mt6359_mtkaif_calibration()
262 afe_priv->mtkaif_chosen_phase[2] >= 0) in mt8192_mt6359_mtkaif_calibration()
266 if (afe_priv->mtkaif_chosen_phase[0] < 0) in mt8192_mt6359_mtkaif_calibration()
269 chosen_phase_1 = afe_priv->mtkaif_chosen_phase[0]; in mt8192_mt6359_mtkaif_calibration()
271 if (afe_priv->mtkaif_chosen_phase[1] < 0) in mt8192_mt6359_mtkaif_calibration()
274 chosen_phase_2 = afe_priv->mtkaif_chosen_phase[1]; in mt8192_mt6359_mtkaif_calibration()
276 if (afe_priv->mtkaif_chosen_phase[2] < 0) in mt8192_mt6359_mtkaif_calibration()
279 chosen_phase_3 = afe_priv->mtkaif_chosen_phase[2]; in mt8192_mt6359_mtkaif_calibration()
287 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38); in mt8192_mt6359_mtkaif_calibration()
291 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 1); in mt8192_mt6359_mtkaif_calibration()
292 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 0); in mt8192_mt6359_mtkaif_calibration()
293 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 1); in mt8192_mt6359_mtkaif_calibration()
294 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 0); in mt8192_mt6359_mtkaif_calibration()
295 pm_runtime_put(afe->dev); in mt8192_mt6359_mtkaif_calibration()
297 dev_info(afe->dev, "%s(), mtkaif_chosen_phase[0/1/2]:%d/%d/%d\n", in mt8192_mt6359_mtkaif_calibration()
299 afe_priv->mtkaif_chosen_phase[0], in mt8192_mt6359_mtkaif_calibration()
300 afe_priv->mtkaif_chosen_phase[1], in mt8192_mt6359_mtkaif_calibration()
301 afe_priv->mtkaif_chosen_phase[2]); in mt8192_mt6359_mtkaif_calibration()
311 asoc_rtd_to_codec(rtd, 0)->component; in mt8192_mt6359_init()
313 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mt8192_mt6359_init()
318 afe_priv->mtkaif_protocol = MTKAIF_PROTOCOL_2_CLK_P2; in mt8192_mt6359_init()
332 asoc_rtd_to_codec(rtd, 0)->component; in mt8192_rt5682_init()
333 struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card); in mt8192_rt5682_init()
334 struct snd_soc_jack *jack = &priv->headset_jack; in mt8192_rt5682_init()
339 dev_err(rtd->dev, "Failed to set up shared clocks\n"); in mt8192_rt5682_init()
343 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", in mt8192_rt5682_init()
350 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); in mt8192_rt5682_init()
354 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); in mt8192_rt5682_init()
355 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); in mt8192_rt5682_init()
356 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); in mt8192_rt5682_init()
357 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); in mt8192_rt5682_init()
365 asoc_rtd_to_codec(rtd, 0)->component; in mt8192_mt6359_hdmi_init()
366 struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card); in mt8192_mt6359_hdmi_init()
369 ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, in mt8192_mt6359_hdmi_init()
370 &priv->hdmi_jack); in mt8192_mt6359_hdmi_init()
372 dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); in mt8192_mt6359_hdmi_init()
376 return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); in mt8192_mt6359_hdmi_init()
412 struct snd_pcm_runtime *runtime = substream->runtime; in mt8192_mt6359_cap1_startup()
419 dev_err(rtd->dev, "hw_constraint_list channels failed\n"); in mt8192_mt6359_cap1_startup()
427 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); in mt8192_mt6359_cap1_startup()
459 struct snd_pcm_runtime *runtime = substream->runtime; in mt8192_mt6359_rt5682_startup()
466 dev_err(rtd->dev, "hw_constraint_list channels failed\n"); in mt8192_mt6359_rt5682_startup()
474 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); in mt8192_mt6359_rt5682_startup()
599 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
600 "mt6359-snd-codec-aif1"),
601 COMP_CODEC("dmic-codec",
602 "dmic-hifi")),
607 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
608 "mt6359-snd-codec-aif2")),
681 SND_SOC_DAILINK_DEFS(tdm,
682 DAILINK_COMP_ARRAY(COMP_CPU("TDM")),
683 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")),
1020 .name = "TDM",
1030 SND_SOC_DAILINK_REG(tdm),
1040 SND_SOC_DAPM_OUTPUT("TDM Out"),
1051 /* TDM */
1052 { "TDM Out", NULL, "TDM" },
1130 if (node && strcmp(link->name, link_name) == 0) { in mt8192_mt6359_card_set_be_link()
1131 ret = snd_soc_of_get_dai_link_codecs(card->dev, node, link); in mt8192_mt6359_card_set_be_link()
1133 dev_err_probe(card->dev, ret, "get dai link codecs fail\n"); in mt8192_mt6359_card_set_be_link()
1149 card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev); in mt8192_mt6359_dev_probe()
1151 return -EINVAL; in mt8192_mt6359_dev_probe()
1152 card->dev = &pdev->dev; in mt8192_mt6359_dev_probe()
1154 if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682_OF_NAME)) in mt8192_mt6359_dev_probe()
1155 card->name = RT1015P_RT5682_CARD_NAME; in mt8192_mt6359_dev_probe()
1156 else if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682S_OF_NAME)) in mt8192_mt6359_dev_probe()
1157 card->name = RT1015P_RT5682S_CARD_NAME; in mt8192_mt6359_dev_probe()
1159 dev_dbg(&pdev->dev, "No need to set card name\n"); in mt8192_mt6359_dev_probe()
1161 hdmi_codec = of_parse_phandle(pdev->dev.of_node, "mediatek,hdmi-codec", 0); in mt8192_mt6359_dev_probe()
1163 dev_dbg(&pdev->dev, "The machine has no hdmi-codec\n"); in mt8192_mt6359_dev_probe()
1165 platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0); in mt8192_mt6359_dev_probe()
1167 ret = -EINVAL; in mt8192_mt6359_dev_probe()
1168 dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n"); in mt8192_mt6359_dev_probe()
1172 speaker_codec = of_get_child_by_name(pdev->dev.of_node, "speaker-codecs"); in mt8192_mt6359_dev_probe()
1174 ret = -EINVAL; in mt8192_mt6359_dev_probe()
1175 dev_err_probe(&pdev->dev, ret, "Property 'speaker-codecs' missing or invalid\n"); in mt8192_mt6359_dev_probe()
1179 headset_codec = of_get_child_by_name(pdev->dev.of_node, "headset-codec"); in mt8192_mt6359_dev_probe()
1181 ret = -EINVAL; in mt8192_mt6359_dev_probe()
1182 dev_err_probe(&pdev->dev, ret, "Property 'headset-codec' missing or invalid\n"); in mt8192_mt6359_dev_probe()
1189 dev_err_probe(&pdev->dev, ret, "%s set speaker_codec fail\n", in mt8192_mt6359_dev_probe()
1190 dai_link->name); in mt8192_mt6359_dev_probe()
1196 dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", in mt8192_mt6359_dev_probe()
1197 dai_link->name); in mt8192_mt6359_dev_probe()
1203 dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", in mt8192_mt6359_dev_probe()
1204 dai_link->name); in mt8192_mt6359_dev_probe()
1208 if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) { in mt8192_mt6359_dev_probe()
1209 dai_link->codecs->of_node = hdmi_codec; in mt8192_mt6359_dev_probe()
1210 dai_link->ignore = 0; in mt8192_mt6359_dev_probe()
1213 if (strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0) in mt8192_mt6359_dev_probe()
1214 dai_link->ops = &mt8192_rt1015_i2s_ops; in mt8192_mt6359_dev_probe()
1216 if (!dai_link->platforms->name) in mt8192_mt6359_dev_probe()
1217 dai_link->platforms->of_node = platform_node; in mt8192_mt6359_dev_probe()
1220 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in mt8192_mt6359_dev_probe()
1222 ret = -ENOMEM; in mt8192_mt6359_dev_probe()
1227 ret = mt8192_afe_gpio_init(&pdev->dev); in mt8192_mt6359_dev_probe()
1229 dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__); in mt8192_mt6359_dev_probe()
1233 ret = devm_snd_soc_register_card(&pdev->dev, card); in mt8192_mt6359_dev_probe()
1235 dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func__); in mt8192_mt6359_dev_probe()
1252 .data = &mt8192_mt6359_rt1015_rt5682_card,
1256 .data = &mt8192_mt6359_rt1015p_rt5682x_card,
1260 .data = &mt8192_mt6359_rt1015p_rt5682x_card,
1285 MODULE_DESCRIPTION("MT8192-MT6359 ALSA SoC machine driver");