Lines Matching +full:asrc +full:- +full:rate

1 // SPDX-License-Identifier: GPL-2.0
3 // Freescale Generic ASoC Sound Card driver with ASRC
23 #include "imx-audmux.h"
38 * struct codec_priv - CODEC private data
39 * @mclk_freq: Clock rate of MCLK
52 * struct cpu_priv - CPU private data
68 * struct fsl_asoc_card_priv - Freescale Generic ASOC card private data
77 * @sample_rate: Current sample rate
79 * @asrc_rate: ASRC sample rate used by Back-Ends
80 * @asrc_format: ASRC sample format used by Back-Ends
106 * Note: keep all ASRC routes in the second half
107 * to drop them easily for non-ASRC cases.
110 /* 1st half -- Normal DAPM routes */
111 {"Playback", NULL, "CPU-Playback"},
112 {"CPU-Capture", NULL, "Capture"},
113 /* 2nd half -- ASRC DAPM routes */
114 {"CPU-Playback", NULL, "ASRC-Playback"},
115 {"ASRC-Capture", NULL, "CPU-Capture"},
119 /* 1st half -- Normal DAPM routes */
122 /* 2nd half -- ASRC DAPM routes */
123 {"AC97 Playback", NULL, "ASRC-Playback"},
124 {"ASRC-Capture", NULL, "AC97 Capture"},
128 /* 1st half -- Normal DAPM routes */
129 {"Playback", NULL, "CPU-Playback"},
130 /* 2nd half -- ASRC DAPM routes */
131 {"CPU-Playback", NULL, "ASRC-Playback"},
147 return priv->dai_fmt == SND_SOC_DAIFMT_AC97; in fsl_asoc_card_is_ac97()
154 struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); in fsl_asoc_card_hw_params()
155 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in fsl_asoc_card_hw_params()
156 struct codec_priv *codec_priv = &priv->codec_priv; in fsl_asoc_card_hw_params()
157 struct cpu_priv *cpu_priv = &priv->cpu_priv; in fsl_asoc_card_hw_params()
158 struct device *dev = rtd->card->dev; in fsl_asoc_card_hw_params()
162 priv->sample_rate = params_rate(params); in fsl_asoc_card_hw_params()
163 priv->sample_format = params_format(params); in fsl_asoc_card_hw_params()
164 priv->streams |= BIT(substream->stream); in fsl_asoc_card_hw_params()
170 ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), cpu_priv->sysclk_id[tx], in fsl_asoc_card_hw_params()
171 cpu_priv->sysclk_freq[tx], in fsl_asoc_card_hw_params()
172 cpu_priv->sysclk_dir[tx]); in fsl_asoc_card_hw_params()
173 if (ret && ret != -ENOTSUPP) { in fsl_asoc_card_hw_params()
178 if (cpu_priv->slot_width) { in fsl_asoc_card_hw_params()
180 cpu_priv->slot_width); in fsl_asoc_card_hw_params()
181 if (ret && ret != -ENOTSUPP) { in fsl_asoc_card_hw_params()
188 if (codec_priv->pll_id && codec_priv->fll_id) { in fsl_asoc_card_hw_params()
189 if (priv->sample_format == SNDRV_PCM_FORMAT_S24_LE) in fsl_asoc_card_hw_params()
190 pll_out = priv->sample_rate * 384; in fsl_asoc_card_hw_params()
192 pll_out = priv->sample_rate * 256; in fsl_asoc_card_hw_params()
195 codec_priv->pll_id, in fsl_asoc_card_hw_params()
196 codec_priv->mclk_id, in fsl_asoc_card_hw_params()
197 codec_priv->mclk_freq, pll_out); in fsl_asoc_card_hw_params()
204 codec_priv->fll_id, in fsl_asoc_card_hw_params()
207 if (ret && ret != -ENOTSUPP) { in fsl_asoc_card_hw_params()
216 priv->streams &= ~BIT(substream->stream); in fsl_asoc_card_hw_params()
222 struct snd_soc_pcm_runtime *rtd = substream->private_data; in fsl_asoc_card_hw_free()
223 struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); in fsl_asoc_card_hw_free()
224 struct codec_priv *codec_priv = &priv->codec_priv; in fsl_asoc_card_hw_free()
225 struct device *dev = rtd->card->dev; in fsl_asoc_card_hw_free()
228 priv->streams &= ~BIT(substream->stream); in fsl_asoc_card_hw_free()
230 if (!priv->streams && codec_priv->pll_id && codec_priv->fll_id) { in fsl_asoc_card_hw_free()
233 codec_priv->mclk_id, in fsl_asoc_card_hw_free()
242 codec_priv->pll_id, 0, 0, 0); in fsl_asoc_card_hw_free()
243 if (ret && ret != -ENOTSUPP) { in fsl_asoc_card_hw_free()
260 struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); in be_hw_params_fixup()
261 struct snd_interval *rate; in be_hw_params_fixup() local
264 rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); in be_hw_params_fixup()
265 rate->max = rate->min = priv->asrc_rate; in be_hw_params_fixup()
269 snd_mask_set_format(mask, priv->asrc_format); in be_hw_params_fixup()
297 /* DPCM Link between Front-End and Back-End (Optional) */
299 .name = "HiFi-ASRC-FE",
300 .stream_name = "HiFi-ASRC-FE",
307 .name = "HiFi-ASRC-BE",
308 .stream_name = "HiFi-ASRC-BE",
321 struct device *dev = &priv->pdev->dev; in fsl_asoc_card_audmux_init()
326 ret = of_property_read_u32(np, "mux-int-port", &int_port); in fsl_asoc_card_audmux_init()
328 dev_err(dev, "mux-int-port missing or invalid\n"); in fsl_asoc_card_audmux_init()
331 ret = of_property_read_u32(np, "mux-ext-port", &ext_port); in fsl_asoc_card_audmux_init()
333 dev_err(dev, "mux-ext-port missing or invalid\n"); in fsl_asoc_card_audmux_init()
341 int_port--; in fsl_asoc_card_audmux_init()
342 ext_port--; in fsl_asoc_card_audmux_init()
349 switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) { in fsl_asoc_card_audmux_init()
392 return -EINVAL; in fsl_asoc_card_audmux_init()
450 struct snd_soc_dapm_context *dapm = &jack->card->dapm; in hp_jack_event()
469 struct snd_soc_dapm_context *dapm = &jack->card->dapm; in mic_jack_event()
488 &card->rtd_list, struct snd_soc_pcm_runtime, list); in fsl_asoc_card_late_probe()
490 struct codec_priv *codec_priv = &priv->codec_priv; in fsl_asoc_card_late_probe()
491 struct device *dev = card->dev; in fsl_asoc_card_late_probe()
496 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component; in fsl_asoc_card_late_probe()
511 ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id, in fsl_asoc_card_late_probe()
512 codec_priv->mclk_freq, SND_SOC_CLOCK_IN); in fsl_asoc_card_late_probe()
513 if (ret && ret != -ENOTSUPP) { in fsl_asoc_card_late_probe()
524 struct device_node *np = pdev->dev.of_node; in fsl_asoc_card_probe()
537 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in fsl_asoc_card_probe()
539 return -ENOMEM; in fsl_asoc_card_probe()
541 cpu_np = of_parse_phandle(np, "audio-cpu", 0); in fsl_asoc_card_probe()
544 cpu_np = of_parse_phandle(np, "ssi-controller", 0); in fsl_asoc_card_probe()
546 dev_err(&pdev->dev, "CPU phandle missing or invalid\n"); in fsl_asoc_card_probe()
547 ret = -EINVAL; in fsl_asoc_card_probe()
553 dev_err(&pdev->dev, "failed to find CPU DAI device\n"); in fsl_asoc_card_probe()
554 ret = -EINVAL; in fsl_asoc_card_probe()
558 codec_np = of_parse_phandle(np, "audio-codec", 0); in fsl_asoc_card_probe()
565 codec_dev = &codec_i2c->dev; in fsl_asoc_card_probe()
566 codec_dev_name = codec_i2c->name; in fsl_asoc_card_probe()
571 codec_dev = &codec_pdev->dev; in fsl_asoc_card_probe()
572 codec_dev_name = codec_pdev->name; in fsl_asoc_card_probe()
577 asrc_np = of_parse_phandle(np, "audio-asrc", 0); in fsl_asoc_card_probe()
581 /* Get the MCLK rate only, and leave it controlled by CODEC drivers */ in fsl_asoc_card_probe()
586 priv->codec_priv.mclk_freq = clk_get_rate(codec_clk); in fsl_asoc_card_probe()
591 /* Default sample rate and format, will be updated in hw_params() */ in fsl_asoc_card_probe()
592 priv->sample_rate = 44100; in fsl_asoc_card_probe()
593 priv->sample_format = SNDRV_PCM_FORMAT_S16_LE; in fsl_asoc_card_probe()
596 priv->dai_fmt = DAI_FMT_BASE; in fsl_asoc_card_probe()
598 memcpy(priv->dai_link, fsl_asoc_card_dai, in fsl_asoc_card_probe()
599 sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link)); in fsl_asoc_card_probe()
601 priv->card.dapm_routes = audio_map; in fsl_asoc_card_probe()
602 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map); in fsl_asoc_card_probe()
604 if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) { in fsl_asoc_card_probe()
606 priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv.mclk_freq; in fsl_asoc_card_probe()
607 priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv.mclk_freq; in fsl_asoc_card_probe()
608 priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT; in fsl_asoc_card_probe()
609 priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT; in fsl_asoc_card_probe()
610 priv->cpu_priv.slot_width = 32; in fsl_asoc_card_probe()
611 priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; in fsl_asoc_card_probe()
612 } else if (of_device_is_compatible(np, "fsl,imx-audio-cs427x")) { in fsl_asoc_card_probe()
613 codec_dai_name = "cs4271-hifi"; in fsl_asoc_card_probe()
614 priv->codec_priv.mclk_id = CS427x_SYSCLK_MCLK; in fsl_asoc_card_probe()
615 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; in fsl_asoc_card_probe()
616 } else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) { in fsl_asoc_card_probe()
618 priv->codec_priv.mclk_id = SGTL5000_SYSCLK; in fsl_asoc_card_probe()
619 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; in fsl_asoc_card_probe()
620 } else if (of_device_is_compatible(np, "fsl,imx-audio-tlv320aic32x4")) { in fsl_asoc_card_probe()
621 codec_dai_name = "tlv320aic32x4-hifi"; in fsl_asoc_card_probe()
622 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; in fsl_asoc_card_probe()
623 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) { in fsl_asoc_card_probe()
625 priv->codec_priv.mclk_id = WM8962_SYSCLK_MCLK; in fsl_asoc_card_probe()
626 priv->codec_priv.fll_id = WM8962_SYSCLK_FLL; in fsl_asoc_card_probe()
627 priv->codec_priv.pll_id = WM8962_FLL; in fsl_asoc_card_probe()
628 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; in fsl_asoc_card_probe()
629 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8960")) { in fsl_asoc_card_probe()
630 codec_dai_name = "wm8960-hifi"; in fsl_asoc_card_probe()
631 priv->codec_priv.fll_id = WM8960_SYSCLK_AUTO; in fsl_asoc_card_probe()
632 priv->codec_priv.pll_id = WM8960_SYSCLK_AUTO; in fsl_asoc_card_probe()
633 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; in fsl_asoc_card_probe()
634 } else if (of_device_is_compatible(np, "fsl,imx-audio-ac97")) { in fsl_asoc_card_probe()
635 codec_dai_name = "ac97-hifi"; in fsl_asoc_card_probe()
636 priv->dai_fmt = SND_SOC_DAIFMT_AC97; in fsl_asoc_card_probe()
637 priv->card.dapm_routes = audio_map_ac97; in fsl_asoc_card_probe()
638 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_ac97); in fsl_asoc_card_probe()
639 } else if (of_device_is_compatible(np, "fsl,imx-audio-mqs")) { in fsl_asoc_card_probe()
640 codec_dai_name = "fsl-mqs-dai"; in fsl_asoc_card_probe()
641 priv->dai_fmt = SND_SOC_DAIFMT_LEFT_J | in fsl_asoc_card_probe()
644 priv->dai_link[1].dpcm_capture = 0; in fsl_asoc_card_probe()
645 priv->dai_link[2].dpcm_capture = 0; in fsl_asoc_card_probe()
646 priv->card.dapm_routes = audio_map_tx; in fsl_asoc_card_probe()
647 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx); in fsl_asoc_card_probe()
648 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8524")) { in fsl_asoc_card_probe()
649 codec_dai_name = "wm8524-hifi"; in fsl_asoc_card_probe()
650 priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; in fsl_asoc_card_probe()
651 priv->dai_link[1].dpcm_capture = 0; in fsl_asoc_card_probe()
652 priv->dai_link[2].dpcm_capture = 0; in fsl_asoc_card_probe()
653 priv->cpu_priv.slot_width = 32; in fsl_asoc_card_probe()
654 priv->card.dapm_routes = audio_map_tx; in fsl_asoc_card_probe()
655 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx); in fsl_asoc_card_probe()
657 dev_err(&pdev->dev, "unknown Device Tree compatible\n"); in fsl_asoc_card_probe()
658 ret = -EINVAL; in fsl_asoc_card_probe()
675 priv->dai_fmt = daifmt; in fsl_asoc_card_probe()
679 if (priv->dai_fmt & SND_SOC_DAIFMT_CBM_CFM) { in fsl_asoc_card_probe()
680 priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_IN; in fsl_asoc_card_probe()
681 priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_IN; in fsl_asoc_card_probe()
688 dev_err(&pdev->dev, "failed to find codec device\n"); in fsl_asoc_card_probe()
689 ret = -EPROBE_DEFER; in fsl_asoc_card_probe()
698 dev_err(&pdev->dev, "failed to init audmux\n"); in fsl_asoc_card_probe()
702 struct clk *esai_clk = clk_get(&cpu_pdev->dev, "extal"); in fsl_asoc_card_probe()
705 priv->cpu_priv.sysclk_freq[TX] = clk_get_rate(esai_clk); in fsl_asoc_card_probe()
706 priv->cpu_priv.sysclk_freq[RX] = clk_get_rate(esai_clk); in fsl_asoc_card_probe()
708 } else if (PTR_ERR(esai_clk) == -EPROBE_DEFER) { in fsl_asoc_card_probe()
709 ret = -EPROBE_DEFER; in fsl_asoc_card_probe()
713 priv->cpu_priv.sysclk_id[1] = ESAI_HCKT_EXTAL; in fsl_asoc_card_probe()
714 priv->cpu_priv.sysclk_id[0] = ESAI_HCKR_EXTAL; in fsl_asoc_card_probe()
716 priv->cpu_priv.sysclk_id[1] = FSL_SAI_CLK_MAST1; in fsl_asoc_card_probe()
717 priv->cpu_priv.sysclk_id[0] = FSL_SAI_CLK_MAST1; in fsl_asoc_card_probe()
721 priv->pdev = pdev; in fsl_asoc_card_probe()
722 priv->card.dev = &pdev->dev; in fsl_asoc_card_probe()
723 priv->card.owner = THIS_MODULE; in fsl_asoc_card_probe()
724 ret = snd_soc_of_parse_card_name(&priv->card, "model"); in fsl_asoc_card_probe()
726 snprintf(priv->name, sizeof(priv->name), "%s-audio", in fsl_asoc_card_probe()
728 priv->card.name = priv->name; in fsl_asoc_card_probe()
730 priv->card.dai_link = priv->dai_link; in fsl_asoc_card_probe()
731 priv->card.late_probe = fsl_asoc_card_late_probe; in fsl_asoc_card_probe()
732 priv->card.dapm_widgets = fsl_asoc_card_dapm_widgets; in fsl_asoc_card_probe()
733 priv->card.num_dapm_widgets = ARRAY_SIZE(fsl_asoc_card_dapm_widgets); in fsl_asoc_card_probe()
735 /* Drop the second half of DAPM routes -- ASRC */ in fsl_asoc_card_probe()
737 priv->card.num_dapm_routes /= 2; in fsl_asoc_card_probe()
739 if (of_property_read_bool(np, "audio-routing")) { in fsl_asoc_card_probe()
740 ret = snd_soc_of_parse_audio_routing(&priv->card, "audio-routing"); in fsl_asoc_card_probe()
742 dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret); in fsl_asoc_card_probe()
748 priv->dai_link[0].cpus->of_node = cpu_np; in fsl_asoc_card_probe()
749 priv->dai_link[0].codecs->dai_name = codec_dai_name; in fsl_asoc_card_probe()
752 priv->dai_link[0].codecs->of_node = codec_np; in fsl_asoc_card_probe()
756 ret = of_property_read_u32(cpu_np, "cell-index", &idx); in fsl_asoc_card_probe()
758 dev_err(&pdev->dev, in fsl_asoc_card_probe()
763 priv->dai_link[0].codecs->name = in fsl_asoc_card_probe()
764 devm_kasprintf(&pdev->dev, GFP_KERNEL, in fsl_asoc_card_probe()
765 "ac97-codec.%u", in fsl_asoc_card_probe()
767 if (!priv->dai_link[0].codecs->name) { in fsl_asoc_card_probe()
768 ret = -ENOMEM; in fsl_asoc_card_probe()
773 priv->dai_link[0].platforms->of_node = cpu_np; in fsl_asoc_card_probe()
774 priv->dai_link[0].dai_fmt = priv->dai_fmt; in fsl_asoc_card_probe()
775 priv->card.num_links = 1; in fsl_asoc_card_probe()
778 /* DPCM DAI Links only if ASRC exsits */ in fsl_asoc_card_probe()
779 priv->dai_link[1].cpus->of_node = asrc_np; in fsl_asoc_card_probe()
780 priv->dai_link[1].platforms->of_node = asrc_np; in fsl_asoc_card_probe()
781 priv->dai_link[2].codecs->dai_name = codec_dai_name; in fsl_asoc_card_probe()
782 priv->dai_link[2].codecs->of_node = codec_np; in fsl_asoc_card_probe()
783 priv->dai_link[2].codecs->name = in fsl_asoc_card_probe()
784 priv->dai_link[0].codecs->name; in fsl_asoc_card_probe()
785 priv->dai_link[2].cpus->of_node = cpu_np; in fsl_asoc_card_probe()
786 priv->dai_link[2].dai_fmt = priv->dai_fmt; in fsl_asoc_card_probe()
787 priv->card.num_links = 3; in fsl_asoc_card_probe()
789 ret = of_property_read_u32(asrc_np, "fsl,asrc-rate", in fsl_asoc_card_probe()
790 &priv->asrc_rate); in fsl_asoc_card_probe()
792 dev_err(&pdev->dev, "failed to get output rate\n"); in fsl_asoc_card_probe()
793 ret = -EINVAL; in fsl_asoc_card_probe()
797 ret = of_property_read_u32(asrc_np, "fsl,asrc-format", in fsl_asoc_card_probe()
798 &priv->asrc_format); in fsl_asoc_card_probe()
801 ret = of_property_read_u32(asrc_np, "fsl,asrc-width", in fsl_asoc_card_probe()
804 dev_err(&pdev->dev, in fsl_asoc_card_probe()
810 priv->asrc_format = SNDRV_PCM_FORMAT_S24_LE; in fsl_asoc_card_probe()
812 priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE; in fsl_asoc_card_probe()
818 snd_soc_card_set_drvdata(&priv->card, priv); in fsl_asoc_card_probe()
820 ret = devm_snd_soc_register_card(&pdev->dev, &priv->card); in fsl_asoc_card_probe()
822 if (ret != -EPROBE_DEFER) in fsl_asoc_card_probe()
823 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); in fsl_asoc_card_probe()
828 * Properties "hp-det-gpio" and "mic-det-gpio" are optional, and in fsl_asoc_card_probe()
835 if (of_property_read_bool(np, "hp-det-gpio")) { in fsl_asoc_card_probe()
836 ret = asoc_simple_init_jack(&priv->card, &priv->hp_jack, in fsl_asoc_card_probe()
841 snd_soc_jack_notifier_register(&priv->hp_jack.jack, &hp_jack_nb); in fsl_asoc_card_probe()
844 if (of_property_read_bool(np, "mic-det-gpio")) { in fsl_asoc_card_probe()
845 ret = asoc_simple_init_jack(&priv->card, &priv->mic_jack, in fsl_asoc_card_probe()
850 snd_soc_jack_notifier_register(&priv->mic_jack.jack, &mic_jack_nb); in fsl_asoc_card_probe()
856 put_device(&cpu_pdev->dev); in fsl_asoc_card_probe()
864 { .compatible = "fsl,imx-audio-ac97", },
865 { .compatible = "fsl,imx-audio-cs42888", },
866 { .compatible = "fsl,imx-audio-cs427x", },
867 { .compatible = "fsl,imx-audio-tlv320aic32x4", },
868 { .compatible = "fsl,imx-audio-sgtl5000", },
869 { .compatible = "fsl,imx-audio-wm8962", },
870 { .compatible = "fsl,imx-audio-wm8960", },
871 { .compatible = "fsl,imx-audio-mqs", },
872 { .compatible = "fsl,imx-audio-wm8524", },
880 .name = "fsl-asoc-card",
887 MODULE_DESCRIPTION("Freescale Generic ASoC Sound Card driver with ASRC");
889 MODULE_ALIAS("platform:fsl-asoc-card");