Lines Matching +full:mt8192 +full:- +full:topckgen
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 "../common/mtk-soc-card.h"
24 #include "../common/mtk-soundcard-driver.h"
25 #include "mt8192-afe-common.h"
26 #include "mt8192-afe-clk.h"
27 #include "mt8192-afe-gpio.h"
31 #define RT1015_CODEC_DAI "rt1015-aif"
32 #define RT1015_DEV0_NAME "rt1015.1-0028"
33 #define RT1015_DEV1_NAME "rt1015.1-0029"
65 struct snd_soc_card *card = rtd->card; in mt8192_rt1015_i2s_hw_params()
79 dev_err(card->dev, "failed to set pll\n"); in mt8192_rt1015_i2s_hw_params()
88 dev_err(card->dev, "failed to set sysclk\n"); in mt8192_rt1015_i2s_hw_params()
100 struct snd_soc_card *card = rtd->card; in mt8192_rt5682x_i2s_hw_params()
111 dev_err(card->dev, "invalid bit width: %d\n", bitwidth); in mt8192_rt5682x_i2s_hw_params()
117 dev_err(card->dev, "failed to set tdm slot\n"); in mt8192_rt5682x_i2s_hw_params()
126 dev_err(card->dev, "failed to set pll\n"); in mt8192_rt5682x_i2s_hw_params()
135 dev_err(card->dev, "failed to set sysclk\n"); in mt8192_rt5682x_i2s_hw_params()
155 snd_soc_rtd_to_codec(rtd, 0)->component; in mt8192_mt6359_mtkaif_calibration()
157 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mt8192_mt6359_mtkaif_calibration()
167 pm_runtime_get_sync(afe->dev); in mt8192_mt6359_mtkaif_calibration()
168 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 1); in mt8192_mt6359_mtkaif_calibration()
169 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA, 0); in mt8192_mt6359_mtkaif_calibration()
170 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 1); in mt8192_mt6359_mtkaif_calibration()
171 mt8192_afe_gpio_request(afe->dev, true, MT8192_DAI_ADDA_CH34, 0); in mt8192_mt6359_mtkaif_calibration()
176 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38); in mt8192_mt6359_mtkaif_calibration()
177 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x39); in mt8192_mt6359_mtkaif_calibration()
180 regmap_update_bits(afe_priv->topckgen, in mt8192_mt6359_mtkaif_calibration()
184 afe_priv->mtkaif_calibration_num_phase = 42; /* mt6359: 0 ~ 42 */ in mt8192_mt6359_mtkaif_calibration()
185 afe_priv->mtkaif_chosen_phase[0] = -1; in mt8192_mt6359_mtkaif_calibration()
186 afe_priv->mtkaif_chosen_phase[1] = -1; in mt8192_mt6359_mtkaif_calibration()
187 afe_priv->mtkaif_chosen_phase[2] = -1; in mt8192_mt6359_mtkaif_calibration()
190 phase <= afe_priv->mtkaif_calibration_num_phase && in mt8192_mt6359_mtkaif_calibration()
196 regmap_update_bits(afe_priv->topckgen, in mt8192_mt6359_mtkaif_calibration()
202 cycle_1 = -1; in mt8192_mt6359_mtkaif_calibration()
203 cycle_2 = -1; in mt8192_mt6359_mtkaif_calibration()
204 cycle_3 = -1; in mt8192_mt6359_mtkaif_calibration()
209 regmap_read(afe_priv->topckgen, in mt8192_mt6359_mtkaif_calibration()
226 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()
241 afe_priv->mtkaif_chosen_phase[0] < 0) { in mt8192_mt6359_mtkaif_calibration()
242 afe_priv->mtkaif_chosen_phase[0] = phase - 1; in mt8192_mt6359_mtkaif_calibration()
243 afe_priv->mtkaif_phase_cycle[0] = prev_cycle_1; in mt8192_mt6359_mtkaif_calibration()
247 afe_priv->mtkaif_chosen_phase[1] < 0) { in mt8192_mt6359_mtkaif_calibration()
248 afe_priv->mtkaif_chosen_phase[1] = phase - 1; in mt8192_mt6359_mtkaif_calibration()
249 afe_priv->mtkaif_phase_cycle[1] = prev_cycle_2; in mt8192_mt6359_mtkaif_calibration()
253 afe_priv->mtkaif_chosen_phase[2] < 0) { in mt8192_mt6359_mtkaif_calibration()
254 afe_priv->mtkaif_chosen_phase[2] = phase - 1; in mt8192_mt6359_mtkaif_calibration()
255 afe_priv->mtkaif_phase_cycle[2] = prev_cycle_3; in mt8192_mt6359_mtkaif_calibration()
258 regmap_update_bits(afe_priv->topckgen, in mt8192_mt6359_mtkaif_calibration()
261 if (afe_priv->mtkaif_chosen_phase[0] >= 0 && in mt8192_mt6359_mtkaif_calibration()
262 afe_priv->mtkaif_chosen_phase[1] >= 0 && in mt8192_mt6359_mtkaif_calibration()
263 afe_priv->mtkaif_chosen_phase[2] >= 0) in mt8192_mt6359_mtkaif_calibration()
267 if (afe_priv->mtkaif_chosen_phase[0] < 0) in mt8192_mt6359_mtkaif_calibration()
270 chosen_phase_1 = afe_priv->mtkaif_chosen_phase[0]; in mt8192_mt6359_mtkaif_calibration()
272 if (afe_priv->mtkaif_chosen_phase[1] < 0) in mt8192_mt6359_mtkaif_calibration()
275 chosen_phase_2 = afe_priv->mtkaif_chosen_phase[1]; in mt8192_mt6359_mtkaif_calibration()
277 if (afe_priv->mtkaif_chosen_phase[2] < 0) in mt8192_mt6359_mtkaif_calibration()
280 chosen_phase_3 = afe_priv->mtkaif_chosen_phase[2]; in mt8192_mt6359_mtkaif_calibration()
288 regmap_update_bits(afe->regmap, AFE_AUD_PAD_TOP, 0xff, 0x38); in mt8192_mt6359_mtkaif_calibration()
292 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 1); in mt8192_mt6359_mtkaif_calibration()
293 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA, 0); in mt8192_mt6359_mtkaif_calibration()
294 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 1); in mt8192_mt6359_mtkaif_calibration()
295 mt8192_afe_gpio_request(afe->dev, false, MT8192_DAI_ADDA_CH34, 0); in mt8192_mt6359_mtkaif_calibration()
296 pm_runtime_put(afe->dev); in mt8192_mt6359_mtkaif_calibration()
298 dev_dbg(afe->dev, "%s(), mtkaif_chosen_phase[0/1/2]:%d/%d/%d\n", in mt8192_mt6359_mtkaif_calibration()
300 afe_priv->mtkaif_chosen_phase[0], in mt8192_mt6359_mtkaif_calibration()
301 afe_priv->mtkaif_chosen_phase[1], in mt8192_mt6359_mtkaif_calibration()
302 afe_priv->mtkaif_chosen_phase[2]); in mt8192_mt6359_mtkaif_calibration()
312 snd_soc_rtd_to_codec(rtd, 0)->component; in mt8192_mt6359_init()
314 struct mt8192_afe_private *afe_priv = afe->platform_priv; in mt8192_mt6359_init()
319 afe_priv->mtkaif_protocol = MTKAIF_PROTOCOL_2_CLK_P2; in mt8192_mt6359_init()
329 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); in mt8192_rt5682_init()
330 struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8192_JACK_HEADSET]; in mt8192_rt5682_init()
335 snd_soc_rtd_to_codec(rtd, 0)->component; in mt8192_rt5682_init()
340 dev_err(rtd->dev, "Failed to set up shared clocks\n"); in mt8192_rt5682_init()
344 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", in mt8192_rt5682_init()
351 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); in mt8192_rt5682_init()
355 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); in mt8192_rt5682_init()
356 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); in mt8192_rt5682_init()
357 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); in mt8192_rt5682_init()
358 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); in mt8192_rt5682_init()
365 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); in mt8192_mt6359_hdmi_init()
366 struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8192_JACK_HDMI]; in mt8192_mt6359_hdmi_init()
368 snd_soc_rtd_to_codec(rtd, 0)->component; in mt8192_mt6359_hdmi_init()
371 ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, jack); in mt8192_mt6359_hdmi_init()
373 dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); in mt8192_mt6359_hdmi_init()
506 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
507 "mt6359-snd-codec-aif1"),
508 COMP_CODEC("dmic-codec",
509 "dmic-hifi")),
514 DAILINK_COMP_ARRAY(COMP_CODEC("mt6359-sound",
515 "mt6359-snd-codec-aif2")),
590 DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "i2s-hifi")),
1037 if (node && strcmp(link->name, link_name) == 0) { in mt8192_mt6359_card_set_be_link()
1038 ret = snd_soc_of_get_dai_link_codecs(card->dev, node, link); in mt8192_mt6359_card_set_be_link()
1040 dev_err_probe(card->dev, ret, "get dai link codecs fail\n"); in mt8192_mt6359_card_set_be_link()
1050 struct mtk_platform_card_data *card_data = soc_card_data->card_data; in mt8192_mt6359_legacy_probe()
1051 struct snd_soc_card *card = card_data->card; in mt8192_mt6359_legacy_probe()
1052 struct device *dev = card->dev; in mt8192_mt6359_legacy_probe()
1057 hdmi_codec = of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0); in mt8192_mt6359_legacy_probe()
1059 dev_dbg(dev, "The machine has no hdmi-codec\n"); in mt8192_mt6359_legacy_probe()
1061 speaker_codec = of_get_child_by_name(dev->of_node, "speaker-codecs"); in mt8192_mt6359_legacy_probe()
1063 ret = -EINVAL; in mt8192_mt6359_legacy_probe()
1064 dev_err_probe(dev, ret, "Property 'speaker-codecs' missing or invalid\n"); in mt8192_mt6359_legacy_probe()
1068 headset_codec = of_get_child_by_name(dev->of_node, "headset-codec"); in mt8192_mt6359_legacy_probe()
1070 ret = -EINVAL; in mt8192_mt6359_legacy_probe()
1071 dev_err_probe(dev, ret, "Property 'headset-codec' missing or invalid\n"); in mt8192_mt6359_legacy_probe()
1079 dai_link->name); in mt8192_mt6359_legacy_probe()
1086 dai_link->name); in mt8192_mt6359_legacy_probe()
1093 dai_link->name); in mt8192_mt6359_legacy_probe()
1097 if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) { in mt8192_mt6359_legacy_probe()
1098 dai_link->codecs->of_node = hdmi_codec; in mt8192_mt6359_legacy_probe()
1099 dai_link->ignore = 0; in mt8192_mt6359_legacy_probe()
1102 if (dai_link->num_codecs && dai_link->codecs[0].dai_name && in mt8192_mt6359_legacy_probe()
1103 strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0) in mt8192_mt6359_legacy_probe()
1104 dai_link->ops = &mt8192_rt1015_i2s_ops; in mt8192_mt6359_legacy_probe()
1117 struct mtk_platform_card_data *card_data = soc_card_data->card_data; in mt8192_mt6359_soc_card_probe()
1118 struct snd_soc_card *card = card_data->card; in mt8192_mt6359_soc_card_probe()
1130 if (dai_link->num_codecs && dai_link->codecs[0].dai_name && in mt8192_mt6359_soc_card_probe()
1131 strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0) in mt8192_mt6359_soc_card_probe()
1132 dai_link->ops = &mt8192_rt1015_i2s_ops; in mt8192_mt6359_soc_card_probe()
1135 ret = mt8192_afe_gpio_init(card->dev); in mt8192_mt6359_soc_card_probe()
1137 return dev_err_probe(card->dev, ret, "%s init gpio error\n", __func__); in mt8192_mt6359_soc_card_probe()
1244 MODULE_DESCRIPTION("MT8192-MT6359 ALSA SoC machine driver");