mt8195-mt6359.c (1ac731c529cd4d6adbce134754b51ff7d822b145) | mt8195-mt6359.c (de9e70137f006855a540f510a2c7dfb8850bedb7) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * mt8195-mt6359.c -- 4 * MT8195-MT6359 ALSA SoC machine driver code 5 * 6 * Copyright (c) 2022 MediaTek Inc. 7 * Author: Trevor Wu <trevor.wu@mediatek.com> 8 * YC Hung <yc.hung@mediatek.com> --- 132 unchanged lines hidden (view full) --- 141#define CKSYS_AUD_TOP_CFG 0x032c 142#define CKSYS_AUD_TOP_MON 0x0330 143 144static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd) 145{ 146 struct snd_soc_component *cmpnt_afe = 147 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 148 struct snd_soc_component *cmpnt_codec = | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * mt8195-mt6359.c -- 4 * MT8195-MT6359 ALSA SoC machine driver code 5 * 6 * Copyright (c) 2022 MediaTek Inc. 7 * Author: Trevor Wu <trevor.wu@mediatek.com> 8 * YC Hung <yc.hung@mediatek.com> --- 132 unchanged lines hidden (view full) --- 141#define CKSYS_AUD_TOP_CFG 0x032c 142#define CKSYS_AUD_TOP_MON 0x0330 143 144static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd) 145{ 146 struct snd_soc_component *cmpnt_afe = 147 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 148 struct snd_soc_component *cmpnt_codec = |
149 asoc_rtd_to_codec(rtd, 0)->component; | 149 snd_soc_rtd_to_codec(rtd, 0)->component; |
150 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 151 struct mt8195_afe_private *afe_priv = afe->platform_priv; 152 struct mtkaif_param *param = &afe_priv->mtkaif_params; 153 int chosen_phase_1, chosen_phase_2, chosen_phase_3; 154 int prev_cycle_1, prev_cycle_2, prev_cycle_3; 155 int test_done_1, test_done_2, test_done_3; 156 int cycle_1, cycle_2, cycle_3; 157 int mtkaif_chosen_phase[MT8195_MTKAIF_MISO_NUM]; --- 144 unchanged lines hidden (view full) --- 302 __func__, param->mtkaif_calibration_ok); 303 304 return 0; 305} 306 307static int mt8195_mt6359_init(struct snd_soc_pcm_runtime *rtd) 308{ 309 struct snd_soc_component *cmpnt_codec = | 150 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 151 struct mt8195_afe_private *afe_priv = afe->platform_priv; 152 struct mtkaif_param *param = &afe_priv->mtkaif_params; 153 int chosen_phase_1, chosen_phase_2, chosen_phase_3; 154 int prev_cycle_1, prev_cycle_2, prev_cycle_3; 155 int test_done_1, test_done_2, test_done_3; 156 int cycle_1, cycle_2, cycle_3; 157 int mtkaif_chosen_phase[MT8195_MTKAIF_MISO_NUM]; --- 144 unchanged lines hidden (view full) --- 302 __func__, param->mtkaif_calibration_ok); 303 304 return 0; 305} 306 307static int mt8195_mt6359_init(struct snd_soc_pcm_runtime *rtd) 308{ 309 struct snd_soc_component *cmpnt_codec = |
310 asoc_rtd_to_codec(rtd, 0)->component; | 310 snd_soc_rtd_to_codec(rtd, 0)->component; |
311 312 /* set mtkaif protocol */ 313 mt6359_set_mtkaif_protocol(cmpnt_codec, 314 MT6359_MTKAIF_PROTOCOL_2_CLK_P2); 315 316 /* mtkaif calibration */ 317 mt8195_mt6359_mtkaif_calibration(rtd); 318 --- 14 unchanged lines hidden (view full) --- 333 .mask = 0, 334 }; 335 static const struct snd_pcm_hw_constraint_list constraints_channels = { 336 .count = ARRAY_SIZE(channels), 337 .list = channels, 338 .mask = 0, 339 }; 340 | 311 312 /* set mtkaif protocol */ 313 mt6359_set_mtkaif_protocol(cmpnt_codec, 314 MT6359_MTKAIF_PROTOCOL_2_CLK_P2); 315 316 /* mtkaif calibration */ 317 mt8195_mt6359_mtkaif_calibration(rtd); 318 --- 14 unchanged lines hidden (view full) --- 333 .mask = 0, 334 }; 335 static const struct snd_pcm_hw_constraint_list constraints_channels = { 336 .count = ARRAY_SIZE(channels), 337 .list = channels, 338 .mask = 0, 339 }; 340 |
341 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); | 341 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
342 struct snd_pcm_runtime *runtime = substream->runtime; 343 int ret; 344 345 ret = snd_pcm_hw_constraint_list(runtime, 0, 346 SNDRV_PCM_HW_PARAM_RATE, 347 &constraints_rates); 348 if (ret < 0) { 349 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); --- 14 unchanged lines hidden (view full) --- 364static const struct snd_soc_ops mt8195_hdmitx_dptx_playback_ops = { 365 .startup = mt8195_hdmitx_dptx_startup, 366}; 367 368static int mt8195_dptx_hw_params(struct snd_pcm_substream *substream, 369 struct snd_pcm_hw_params *params) 370{ 371 struct snd_soc_pcm_runtime *rtd = substream->private_data; | 342 struct snd_pcm_runtime *runtime = substream->runtime; 343 int ret; 344 345 ret = snd_pcm_hw_constraint_list(runtime, 0, 346 SNDRV_PCM_HW_PARAM_RATE, 347 &constraints_rates); 348 if (ret < 0) { 349 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); --- 14 unchanged lines hidden (view full) --- 364static const struct snd_soc_ops mt8195_hdmitx_dptx_playback_ops = { 365 .startup = mt8195_hdmitx_dptx_startup, 366}; 367 368static int mt8195_dptx_hw_params(struct snd_pcm_substream *substream, 369 struct snd_pcm_hw_params *params) 370{ 371 struct snd_soc_pcm_runtime *rtd = substream->private_data; |
372 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); | 372 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); |
373 374 return snd_soc_dai_set_sysclk(cpu_dai, 0, params_rate(params) * 256, 375 SND_SOC_CLOCK_OUT); 376} 377 378static const struct snd_soc_ops mt8195_dptx_ops = { 379 .hw_params = mt8195_dptx_hw_params, 380}; 381 382static int mt8195_dptx_codec_init(struct snd_soc_pcm_runtime *rtd) 383{ 384 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 385 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 386 struct snd_soc_component *cmpnt_codec = | 373 374 return snd_soc_dai_set_sysclk(cpu_dai, 0, params_rate(params) * 256, 375 SND_SOC_CLOCK_OUT); 376} 377 378static const struct snd_soc_ops mt8195_dptx_ops = { 379 .hw_params = mt8195_dptx_hw_params, 380}; 381 382static int mt8195_dptx_codec_init(struct snd_soc_pcm_runtime *rtd) 383{ 384 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 385 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 386 struct snd_soc_component *cmpnt_codec = |
387 asoc_rtd_to_codec(rtd, 0)->component; | 387 snd_soc_rtd_to_codec(rtd, 0)->component; |
388 int ret; 389 390 ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT, 391 &priv->dp_jack); 392 if (ret) 393 return ret; 394 395 return snd_soc_component_set_jack(cmpnt_codec, &priv->dp_jack, NULL); 396} 397 398static int mt8195_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd) 399{ 400 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 401 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 402 struct snd_soc_component *cmpnt_codec = | 388 int ret; 389 390 ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT, 391 &priv->dp_jack); 392 if (ret) 393 return ret; 394 395 return snd_soc_component_set_jack(cmpnt_codec, &priv->dp_jack, NULL); 396} 397 398static int mt8195_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd) 399{ 400 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 401 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 402 struct snd_soc_component *cmpnt_codec = |
403 asoc_rtd_to_codec(rtd, 0)->component; | 403 snd_soc_rtd_to_codec(rtd, 0)->component; |
404 int ret; 405 406 ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, 407 &priv->hdmi_jack); 408 if (ret) 409 return ret; 410 411 return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); --- 25 unchanged lines hidden (view full) --- 437 .mask = 0, 438 }; 439 static const struct snd_pcm_hw_constraint_list constraints_channels = { 440 .count = ARRAY_SIZE(channels), 441 .list = channels, 442 .mask = 0, 443 }; 444 | 404 int ret; 405 406 ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, 407 &priv->hdmi_jack); 408 if (ret) 409 return ret; 410 411 return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); --- 25 unchanged lines hidden (view full) --- 437 .mask = 0, 438 }; 439 static const struct snd_pcm_hw_constraint_list constraints_channels = { 440 .count = ARRAY_SIZE(channels), 441 .list = channels, 442 .mask = 0, 443 }; 444 |
445 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); | 445 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
446 struct snd_pcm_runtime *runtime = substream->runtime; 447 int ret; 448 449 ret = snd_pcm_hw_constraint_list(runtime, 0, 450 SNDRV_PCM_HW_PARAM_RATE, 451 &constraints_rates); 452 if (ret < 0) { 453 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); --- 29 unchanged lines hidden (view full) --- 483 .mask = 0, 484 }; 485 static const struct snd_pcm_hw_constraint_list constraints_channels = { 486 .count = ARRAY_SIZE(channels), 487 .list = channels, 488 .mask = 0, 489 }; 490 | 446 struct snd_pcm_runtime *runtime = substream->runtime; 447 int ret; 448 449 ret = snd_pcm_hw_constraint_list(runtime, 0, 450 SNDRV_PCM_HW_PARAM_RATE, 451 &constraints_rates); 452 if (ret < 0) { 453 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); --- 29 unchanged lines hidden (view full) --- 483 .mask = 0, 484 }; 485 static const struct snd_pcm_hw_constraint_list constraints_channels = { 486 .count = ARRAY_SIZE(channels), 487 .list = channels, 488 .mask = 0, 489 }; 490 |
491 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); | 491 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
492 struct snd_pcm_runtime *runtime = substream->runtime; 493 int ret; 494 495 ret = snd_pcm_hw_constraint_list(runtime, 0, 496 SNDRV_PCM_HW_PARAM_RATE, 497 &constraints_rates); 498 if (ret < 0) { 499 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); --- 15 unchanged lines hidden (view full) --- 515 .startup = mt8195_capture_startup, 516}; 517 518static int mt8195_rt5682_etdm_hw_params(struct snd_pcm_substream *substream, 519 struct snd_pcm_hw_params *params) 520{ 521 struct snd_soc_pcm_runtime *rtd = substream->private_data; 522 struct snd_soc_card *card = rtd->card; | 492 struct snd_pcm_runtime *runtime = substream->runtime; 493 int ret; 494 495 ret = snd_pcm_hw_constraint_list(runtime, 0, 496 SNDRV_PCM_HW_PARAM_RATE, 497 &constraints_rates); 498 if (ret < 0) { 499 dev_err(rtd->dev, "hw_constraint_list rate failed\n"); --- 15 unchanged lines hidden (view full) --- 515 .startup = mt8195_capture_startup, 516}; 517 518static int mt8195_rt5682_etdm_hw_params(struct snd_pcm_substream *substream, 519 struct snd_pcm_hw_params *params) 520{ 521 struct snd_soc_pcm_runtime *rtd = substream->private_data; 522 struct snd_soc_card *card = rtd->card; |
523 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); 524 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); | 523 struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); 524 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); |
525 unsigned int rate = params_rate(params); 526 int bitwidth; 527 int ret; 528 529 bitwidth = snd_pcm_format_width(params_format(params)); 530 if (bitwidth < 0) { 531 dev_err(card->dev, "invalid bit width: %d\n", bitwidth); 532 return bitwidth; --- 25 unchanged lines hidden (view full) --- 558 559static const struct snd_soc_ops mt8195_rt5682_etdm_ops = { 560 .hw_params = mt8195_rt5682_etdm_hw_params, 561}; 562 563static int mt8195_rt5682_init(struct snd_soc_pcm_runtime *rtd) 564{ 565 struct snd_soc_component *cmpnt_codec = | 525 unsigned int rate = params_rate(params); 526 int bitwidth; 527 int ret; 528 529 bitwidth = snd_pcm_format_width(params_format(params)); 530 if (bitwidth < 0) { 531 dev_err(card->dev, "invalid bit width: %d\n", bitwidth); 532 return bitwidth; --- 25 unchanged lines hidden (view full) --- 558 559static const struct snd_soc_ops mt8195_rt5682_etdm_ops = { 560 .hw_params = mt8195_rt5682_etdm_hw_params, 561}; 562 563static int mt8195_rt5682_init(struct snd_soc_pcm_runtime *rtd) 564{ 565 struct snd_soc_component *cmpnt_codec = |
566 asoc_rtd_to_codec(rtd, 0)->component; | 566 snd_soc_rtd_to_codec(rtd, 0)->component; |
567 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 568 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 569 struct snd_soc_jack *jack = &priv->headset_jack; 570 struct snd_soc_component *cmpnt_afe = 571 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 572 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 573 struct mt8195_afe_private *afe_priv = afe->platform_priv; 574 int ret; --- 23 unchanged lines hidden (view full) --- 598 } 599 600 return 0; 601}; 602 603static int mt8195_rt1011_etdm_hw_params(struct snd_pcm_substream *substream, 604 struct snd_pcm_hw_params *params) 605{ | 567 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 568 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 569 struct snd_soc_jack *jack = &priv->headset_jack; 570 struct snd_soc_component *cmpnt_afe = 571 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 572 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 573 struct mt8195_afe_private *afe_priv = afe->platform_priv; 574 int ret; --- 23 unchanged lines hidden (view full) --- 598 } 599 600 return 0; 601}; 602 603static int mt8195_rt1011_etdm_hw_params(struct snd_pcm_substream *substream, 604 struct snd_pcm_hw_params *params) 605{ |
606 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); | 606 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
607 struct snd_soc_dai *codec_dai; 608 struct snd_soc_card *card = rtd->card; 609 int srate, i, ret; 610 611 srate = params_rate(params); 612 613 for_each_rtd_codec_dais(rtd, i, codec_dai) { 614 ret = snd_soc_dai_set_pll(codec_dai, 0, RT1011_PLL1_S_BCLK, --- 16 unchanged lines hidden (view full) --- 631 632static const struct snd_soc_ops mt8195_rt1011_etdm_ops = { 633 .hw_params = mt8195_rt1011_etdm_hw_params, 634}; 635 636static int mt8195_sof_be_hw_params(struct snd_pcm_substream *substream, 637 struct snd_pcm_hw_params *params) 638{ | 607 struct snd_soc_dai *codec_dai; 608 struct snd_soc_card *card = rtd->card; 609 int srate, i, ret; 610 611 srate = params_rate(params); 612 613 for_each_rtd_codec_dais(rtd, i, codec_dai) { 614 ret = snd_soc_dai_set_pll(codec_dai, 0, RT1011_PLL1_S_BCLK, --- 16 unchanged lines hidden (view full) --- 631 632static const struct snd_soc_ops mt8195_rt1011_etdm_ops = { 633 .hw_params = mt8195_rt1011_etdm_hw_params, 634}; 635 636static int mt8195_sof_be_hw_params(struct snd_pcm_substream *substream, 637 struct snd_pcm_hw_params *params) 638{ |
639 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); | 639 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); |
640 struct snd_soc_component *cmpnt_afe = NULL; 641 struct snd_soc_pcm_runtime *runtime; 642 643 /* find afe component */ 644 for_each_card_rtds(rtd->card, runtime) { 645 cmpnt_afe = snd_soc_rtdcom_lookup(runtime, AFE_PCM_NAME); 646 if (cmpnt_afe) 647 break; --- 948 unchanged lines hidden --- | 640 struct snd_soc_component *cmpnt_afe = NULL; 641 struct snd_soc_pcm_runtime *runtime; 642 643 /* find afe component */ 644 for_each_card_rtds(rtd->card, runtime) { 645 cmpnt_afe = snd_soc_rtdcom_lookup(runtime, AFE_PCM_NAME); 646 if (cmpnt_afe) 647 break; --- 948 unchanged lines hidden --- |