Lines Matching +full:sai +full:- +full:mclk +full:- +full:direction +full:- +full:output
1 // SPDX-License-Identifier: GPL-2.0
23 #include "imx-audmux.h"
33 #define DRIVER_NAME "fsl-asoc-card"
44 * struct codec_priv - CODEC private data
45 * @mclk: Main clock of the CODEC
46 * @mclk_freq: Clock rate of MCLK
47 * @free_freq: Clock rate of MCLK for hw_free()
48 * @mclk_id: MCLK (or main clock) id for set_sysclk()
53 struct clk *mclk; member
62 * struct cpu_priv - CPU private data
80 * struct fsl_asoc_card_priv - Freescale Generic ASOC card private data
91 * @asrc_rate: ASRC sample rate used by Back-Ends
92 * @asrc_format: ASRC sample format used by Back-Ends
119 * to drop them easily for non-ASRC cases.
122 /* 1st half -- Normal DAPM routes */
123 {"Playback", NULL, "CPU-Playback"},
124 {"CPU-Capture", NULL, "Capture"},
125 /* 2nd half -- ASRC DAPM routes */
126 {"CPU-Playback", NULL, "ASRC-Playback"},
127 {"ASRC-Capture", NULL, "CPU-Capture"},
131 /* 1st half -- Normal DAPM routes */
134 /* 2nd half -- ASRC DAPM routes */
135 {"CPU AC97 Playback", NULL, "ASRC-Playback"},
136 {"ASRC-Capture", NULL, "CPU AC97 Capture"},
140 /* 1st half -- Normal DAPM routes */
141 {"Playback", NULL, "CPU-Playback"},
142 /* 2nd half -- ASRC DAPM routes */
143 {"CPU-Playback", NULL, "ASRC-Playback"},
147 /* 1st half -- Normal DAPM routes */
148 {"CPU-Capture", NULL, "Capture"},
149 /* 2nd half -- ASRC DAPM routes */
150 {"ASRC-Capture", NULL, "CPU-Capture"},
166 return priv->dai_fmt == SND_SOC_DAIFMT_AC97; in fsl_asoc_card_is_ac97()
173 struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); in fsl_asoc_card_hw_params()
174 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in fsl_asoc_card_hw_params()
177 struct cpu_priv *cpu_priv = &priv->cpu_priv; in fsl_asoc_card_hw_params()
178 struct device *dev = rtd->card->dev; in fsl_asoc_card_hw_params()
183 priv->sample_rate = params_rate(params); in fsl_asoc_card_hw_params()
184 priv->sample_format = params_format(params); in fsl_asoc_card_hw_params()
185 priv->streams |= BIT(substream->stream); in fsl_asoc_card_hw_params()
191 ret = snd_soc_dai_set_sysclk(snd_soc_rtd_to_cpu(rtd, 0), cpu_priv->sysclk_id[tx], in fsl_asoc_card_hw_params()
192 cpu_priv->sysclk_freq[tx], in fsl_asoc_card_hw_params()
193 cpu_priv->sysclk_dir[tx]); in fsl_asoc_card_hw_params()
194 if (ret && ret != -ENOTSUPP) { in fsl_asoc_card_hw_params()
199 if (cpu_priv->slot_width) { in fsl_asoc_card_hw_params()
200 if (!cpu_priv->slot_num) in fsl_asoc_card_hw_params()
201 cpu_priv->slot_num = 2; in fsl_asoc_card_hw_params()
204 cpu_priv->slot_num, in fsl_asoc_card_hw_params()
205 cpu_priv->slot_width); in fsl_asoc_card_hw_params()
206 if (ret && ret != -ENOTSUPP) { in fsl_asoc_card_hw_params()
214 codec_priv = &priv->codec_priv[codec_idx]; in fsl_asoc_card_hw_params()
216 if (codec_priv->pll_id >= 0 && codec_priv->fll_id >= 0) { in fsl_asoc_card_hw_params()
217 if (priv->sample_format == SNDRV_PCM_FORMAT_S24_LE) in fsl_asoc_card_hw_params()
218 pll_out = priv->sample_rate * 384; in fsl_asoc_card_hw_params()
220 pll_out = priv->sample_rate * 256; in fsl_asoc_card_hw_params()
223 codec_priv->pll_id, in fsl_asoc_card_hw_params()
224 codec_priv->mclk_id, in fsl_asoc_card_hw_params()
225 codec_priv->mclk_freq, pll_out); in fsl_asoc_card_hw_params()
232 codec_priv->fll_id, in fsl_asoc_card_hw_params()
235 if (ret && ret != -ENOTSUPP) { in fsl_asoc_card_hw_params()
245 priv->streams &= ~BIT(substream->stream); in fsl_asoc_card_hw_params()
252 struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); in fsl_asoc_card_hw_free()
255 struct device *dev = rtd->card->dev; in fsl_asoc_card_hw_free()
259 priv->streams &= ~BIT(substream->stream); in fsl_asoc_card_hw_free()
262 codec_priv = &priv->codec_priv[codec_idx]; in fsl_asoc_card_hw_free()
264 if (!priv->streams && codec_priv->pll_id >= 0 && codec_priv->fll_id >= 0) { in fsl_asoc_card_hw_free()
267 codec_priv->mclk_id, in fsl_asoc_card_hw_free()
268 codec_priv->free_freq, in fsl_asoc_card_hw_free()
276 codec_priv->pll_id, 0, 0, 0); in fsl_asoc_card_hw_free()
277 if (ret && ret != -ENOTSUPP) { in fsl_asoc_card_hw_free()
295 struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card); in be_hw_params_fixup()
300 rate->max = rate->min = priv->asrc_rate; in be_hw_params_fixup()
304 snd_mask_set_format(mask, priv->asrc_format); in be_hw_params_fixup()
316 /* DPCM Link between Front-End and Back-End (Optional) */
318 .name = "HiFi-ASRC-FE",
319 .stream_name = "HiFi-ASRC-FE",
325 .name = "HiFi-ASRC-BE",
326 .stream_name = "HiFi-ASRC-BE",
338 struct device *dev = &priv->pdev->dev; in fsl_asoc_card_audmux_init()
343 ret = of_property_read_u32(np, "mux-int-port", &int_port); in fsl_asoc_card_audmux_init()
345 dev_err(dev, "mux-int-port missing or invalid\n"); in fsl_asoc_card_audmux_init()
348 ret = of_property_read_u32(np, "mux-ext-port", &ext_port); in fsl_asoc_card_audmux_init()
350 dev_err(dev, "mux-ext-port missing or invalid\n"); in fsl_asoc_card_audmux_init()
358 int_port--; in fsl_asoc_card_audmux_init()
359 ext_port--; in fsl_asoc_card_audmux_init()
366 switch (priv->dai_fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { in fsl_asoc_card_audmux_init()
409 return -EINVAL; in fsl_asoc_card_audmux_init()
468 struct device *dev = &priv->pdev->dev; in fsl_asoc_card_spdif_init()
469 struct device_node *np = dev->of_node; in fsl_asoc_card_spdif_init()
473 return -EINVAL; in fsl_asoc_card_spdif_init()
476 priv->dai_link[0].playback_only = true; in fsl_asoc_card_spdif_init()
477 priv->dai_link[0].capture_only = true; in fsl_asoc_card_spdif_init()
483 if (of_device_is_compatible(codec_np[i], "linux,spdif-dit")) { in fsl_asoc_card_spdif_init()
484 priv->dai_link[0].capture_only = false; in fsl_asoc_card_spdif_init()
485 codec_dai_name[i] = "dit-hifi"; in fsl_asoc_card_spdif_init()
486 } else if (of_device_is_compatible(codec_np[i], "linux,spdif-dir")) { in fsl_asoc_card_spdif_init()
487 priv->dai_link[0].playback_only = false; in fsl_asoc_card_spdif_init()
488 codec_dai_name[i] = "dir-hifi"; in fsl_asoc_card_spdif_init()
495 if (of_property_read_bool(np, "spdif-out")) in fsl_asoc_card_spdif_init()
496 priv->dai_link[0].capture_only = false; in fsl_asoc_card_spdif_init()
497 if (of_property_read_bool(np, "spdif-in")) in fsl_asoc_card_spdif_init()
498 priv->dai_link[0].playback_only = false; in fsl_asoc_card_spdif_init()
501 if (priv->dai_link[0].playback_only && priv->dai_link[0].capture_only) { in fsl_asoc_card_spdif_init()
503 return -EINVAL; in fsl_asoc_card_spdif_init()
506 if (priv->dai_link[0].playback_only) { in fsl_asoc_card_spdif_init()
507 priv->dai_link[1].dpcm_capture = false; in fsl_asoc_card_spdif_init()
508 priv->dai_link[2].dpcm_capture = false; in fsl_asoc_card_spdif_init()
509 priv->card.dapm_routes = audio_map_tx; in fsl_asoc_card_spdif_init()
510 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx); in fsl_asoc_card_spdif_init()
511 } else if (priv->dai_link[0].capture_only) { in fsl_asoc_card_spdif_init()
512 priv->dai_link[1].dpcm_playback = false; in fsl_asoc_card_spdif_init()
513 priv->dai_link[2].dpcm_playback = false; in fsl_asoc_card_spdif_init()
514 priv->card.dapm_routes = audio_map_rx; in fsl_asoc_card_spdif_init()
515 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_rx); in fsl_asoc_card_spdif_init()
520 priv->card.dapm_routes = NULL; in fsl_asoc_card_spdif_init()
521 priv->card.num_dapm_routes = 0; in fsl_asoc_card_spdif_init()
525 priv->dai_link[0].num_codecs = 2; in fsl_asoc_card_spdif_init()
526 priv->dai_link[2].num_codecs = 2; in fsl_asoc_card_spdif_init()
536 struct snd_soc_dapm_context *dapm = &jack->card->dapm; in hp_jack_event()
553 struct snd_soc_dapm_context *dapm = &jack->card->dapm; in mic_jack_event()
570 &card->rtd_list, struct snd_soc_pcm_runtime, list); in fsl_asoc_card_late_probe()
573 struct device *dev = card->dev; in fsl_asoc_card_late_probe()
579 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; in fsl_asoc_card_late_probe()
595 codec_priv = &priv->codec_priv[codec_idx]; in fsl_asoc_card_late_probe()
597 ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id, in fsl_asoc_card_late_probe()
598 codec_priv->mclk_freq, SND_SOC_CLOCK_IN); in fsl_asoc_card_late_probe()
599 if (ret && ret != -ENOTSUPP) { in fsl_asoc_card_late_probe()
604 if (!IS_ERR_OR_NULL(codec_priv->mclk)) in fsl_asoc_card_late_probe()
605 clk_prepare_enable(codec_priv->mclk); in fsl_asoc_card_late_probe()
616 struct device_node *np = pdev->dev.of_node; in fsl_asoc_card_probe()
631 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in fsl_asoc_card_probe()
633 return -ENOMEM; in fsl_asoc_card_probe()
635 priv->pdev = pdev; in fsl_asoc_card_probe()
637 cpu_np = of_parse_phandle(np, "audio-cpu", 0); in fsl_asoc_card_probe()
640 cpu_np = of_parse_phandle(np, "ssi-controller", 0); in fsl_asoc_card_probe()
642 cpu_np = of_parse_phandle(np, "spdif-controller", 0); in fsl_asoc_card_probe()
644 dev_err(&pdev->dev, "CPU phandle missing or invalid\n"); in fsl_asoc_card_probe()
645 ret = -EINVAL; in fsl_asoc_card_probe()
651 dev_err(&pdev->dev, "failed to find CPU DAI device\n"); in fsl_asoc_card_probe()
652 ret = -EINVAL; in fsl_asoc_card_probe()
656 codec_np[0] = of_parse_phandle(np, "audio-codec", 0); in fsl_asoc_card_probe()
657 codec_np[1] = of_parse_phandle(np, "audio-codec", 1); in fsl_asoc_card_probe()
666 codec_dev[codec_idx] = &codec_i2c->dev; in fsl_asoc_card_probe()
667 codec_dev_name[codec_idx] = codec_i2c->name; in fsl_asoc_card_probe()
672 codec_dev[codec_idx] = &codec_pdev->dev; in fsl_asoc_card_probe()
673 codec_dev_name[codec_idx] = codec_pdev->name; in fsl_asoc_card_probe()
679 asrc_np = of_parse_phandle(np, "audio-asrc", 0); in fsl_asoc_card_probe()
683 /* Get the MCLK rate only, and leave it controlled by CODEC drivers */ in fsl_asoc_card_probe()
689 priv->codec_priv[codec_idx].mclk_freq = clk_get_rate(codec_clk); in fsl_asoc_card_probe()
696 priv->sample_rate = 44100; in fsl_asoc_card_probe()
697 priv->sample_format = SNDRV_PCM_FORMAT_S16_LE; in fsl_asoc_card_probe()
700 priv->dai_fmt = DAI_FMT_BASE; in fsl_asoc_card_probe()
702 memcpy(priv->dai_link, fsl_asoc_card_dai, in fsl_asoc_card_probe()
703 sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link)); in fsl_asoc_card_probe()
706 * "DPCM Link Front-End": 1 cpus, 1 codecs (dummy), 1 platforms in fsl_asoc_card_probe()
707 * "DPCM Link Back-End": 1 cpus, 2 codecs in fsl_asoc_card_probe()
710 dlc = devm_kcalloc(&pdev->dev, 10, sizeof(*dlc), GFP_KERNEL); in fsl_asoc_card_probe()
712 ret = -ENOMEM; in fsl_asoc_card_probe()
716 priv->dai_link[0].cpus = &dlc[0]; in fsl_asoc_card_probe()
717 priv->dai_link[0].num_cpus = 1; in fsl_asoc_card_probe()
718 priv->dai_link[0].codecs = &dlc[1]; in fsl_asoc_card_probe()
719 priv->dai_link[0].num_codecs = 1; in fsl_asoc_card_probe()
720 priv->dai_link[0].platforms = &dlc[3]; in fsl_asoc_card_probe()
721 priv->dai_link[0].num_platforms = 1; in fsl_asoc_card_probe()
723 priv->dai_link[1].cpus = &dlc[4]; in fsl_asoc_card_probe()
724 priv->dai_link[1].num_cpus = 1; in fsl_asoc_card_probe()
725 priv->dai_link[1].codecs = &dlc[5]; in fsl_asoc_card_probe()
726 priv->dai_link[1].num_codecs = 0; /* dummy */ in fsl_asoc_card_probe()
727 priv->dai_link[1].platforms = &dlc[6]; in fsl_asoc_card_probe()
728 priv->dai_link[1].num_platforms = 1; in fsl_asoc_card_probe()
730 priv->dai_link[2].cpus = &dlc[7]; in fsl_asoc_card_probe()
731 priv->dai_link[2].num_cpus = 1; in fsl_asoc_card_probe()
732 priv->dai_link[2].codecs = &dlc[8]; in fsl_asoc_card_probe()
733 priv->dai_link[2].num_codecs = 1; in fsl_asoc_card_probe()
735 priv->card.dapm_routes = audio_map; in fsl_asoc_card_probe()
736 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map); in fsl_asoc_card_probe()
737 priv->card.driver_name = DRIVER_NAME; in fsl_asoc_card_probe()
740 priv->codec_priv[codec_idx].fll_id = -1; in fsl_asoc_card_probe()
741 priv->codec_priv[codec_idx].pll_id = -1; in fsl_asoc_card_probe()
745 if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) { in fsl_asoc_card_probe()
747 priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv[0].mclk_freq; in fsl_asoc_card_probe()
748 priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv[0].mclk_freq; in fsl_asoc_card_probe()
749 priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT; in fsl_asoc_card_probe()
750 priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT; in fsl_asoc_card_probe()
751 priv->cpu_priv.slot_width = 32; in fsl_asoc_card_probe()
752 priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC; in fsl_asoc_card_probe()
753 } else if (of_device_is_compatible(np, "fsl,imx-audio-cs427x")) { in fsl_asoc_card_probe()
754 codec_dai_name[0] = "cs4271-hifi"; in fsl_asoc_card_probe()
755 priv->codec_priv[0].mclk_id = CS427x_SYSCLK_MCLK; in fsl_asoc_card_probe()
756 priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; in fsl_asoc_card_probe()
757 } else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) { in fsl_asoc_card_probe()
759 priv->codec_priv[0].mclk_id = SGTL5000_SYSCLK; in fsl_asoc_card_probe()
760 priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; in fsl_asoc_card_probe()
761 } else if (of_device_is_compatible(np, "fsl,imx-audio-tlv320aic32x4")) { in fsl_asoc_card_probe()
762 codec_dai_name[0] = "tlv320aic32x4-hifi"; in fsl_asoc_card_probe()
763 priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; in fsl_asoc_card_probe()
764 } else if (of_device_is_compatible(np, "fsl,imx-audio-tlv320aic31xx")) { in fsl_asoc_card_probe()
765 codec_dai_name[0] = "tlv320dac31xx-hifi"; in fsl_asoc_card_probe()
766 priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; in fsl_asoc_card_probe()
767 priv->dai_link[1].dpcm_capture = 0; in fsl_asoc_card_probe()
768 priv->dai_link[2].dpcm_capture = 0; in fsl_asoc_card_probe()
769 priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT; in fsl_asoc_card_probe()
770 priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT; in fsl_asoc_card_probe()
771 priv->card.dapm_routes = audio_map_tx; in fsl_asoc_card_probe()
772 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx); in fsl_asoc_card_probe()
773 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) { in fsl_asoc_card_probe()
775 priv->codec_priv[0].mclk_id = WM8962_SYSCLK_MCLK; in fsl_asoc_card_probe()
776 priv->codec_priv[0].fll_id = WM8962_SYSCLK_FLL; in fsl_asoc_card_probe()
777 priv->codec_priv[0].pll_id = WM8962_FLL; in fsl_asoc_card_probe()
778 priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; in fsl_asoc_card_probe()
779 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8960")) { in fsl_asoc_card_probe()
780 codec_dai_name[0] = "wm8960-hifi"; in fsl_asoc_card_probe()
781 priv->codec_priv[0].fll_id = WM8960_SYSCLK_AUTO; in fsl_asoc_card_probe()
782 priv->codec_priv[0].pll_id = WM8960_SYSCLK_AUTO; in fsl_asoc_card_probe()
783 priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; in fsl_asoc_card_probe()
784 } else if (of_device_is_compatible(np, "fsl,imx-audio-ac97")) { in fsl_asoc_card_probe()
785 codec_dai_name[0] = "ac97-hifi"; in fsl_asoc_card_probe()
786 priv->dai_fmt = SND_SOC_DAIFMT_AC97; in fsl_asoc_card_probe()
787 priv->card.dapm_routes = audio_map_ac97; in fsl_asoc_card_probe()
788 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_ac97); in fsl_asoc_card_probe()
789 } else if (of_device_is_compatible(np, "fsl,imx-audio-mqs")) { in fsl_asoc_card_probe()
790 codec_dai_name[0] = "fsl-mqs-dai"; in fsl_asoc_card_probe()
791 priv->dai_fmt = SND_SOC_DAIFMT_LEFT_J | in fsl_asoc_card_probe()
794 priv->dai_link[1].dpcm_capture = 0; in fsl_asoc_card_probe()
795 priv->dai_link[2].dpcm_capture = 0; in fsl_asoc_card_probe()
796 priv->card.dapm_routes = audio_map_tx; in fsl_asoc_card_probe()
797 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx); in fsl_asoc_card_probe()
798 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8524")) { in fsl_asoc_card_probe()
799 codec_dai_name[0] = "wm8524-hifi"; in fsl_asoc_card_probe()
800 priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC; in fsl_asoc_card_probe()
801 priv->dai_link[1].dpcm_capture = 0; in fsl_asoc_card_probe()
802 priv->dai_link[2].dpcm_capture = 0; in fsl_asoc_card_probe()
803 priv->cpu_priv.slot_width = 32; in fsl_asoc_card_probe()
804 priv->card.dapm_routes = audio_map_tx; in fsl_asoc_card_probe()
805 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx); in fsl_asoc_card_probe()
806 } else if (of_device_is_compatible(np, "fsl,imx-audio-si476x")) { in fsl_asoc_card_probe()
807 codec_dai_name[0] = "si476x-codec"; in fsl_asoc_card_probe()
808 priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC; in fsl_asoc_card_probe()
809 priv->card.dapm_routes = audio_map_rx; in fsl_asoc_card_probe()
810 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_rx); in fsl_asoc_card_probe()
811 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8958")) { in fsl_asoc_card_probe()
812 codec_dai_name[0] = "wm8994-aif1"; in fsl_asoc_card_probe()
813 priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; in fsl_asoc_card_probe()
814 priv->codec_priv[0].mclk_id = WM8994_FLL_SRC_MCLK1; in fsl_asoc_card_probe()
815 priv->codec_priv[0].fll_id = WM8994_SYSCLK_FLL1; in fsl_asoc_card_probe()
816 priv->codec_priv[0].pll_id = WM8994_FLL1; in fsl_asoc_card_probe()
817 priv->codec_priv[0].free_freq = priv->codec_priv[0].mclk_freq; in fsl_asoc_card_probe()
818 priv->card.dapm_routes = NULL; in fsl_asoc_card_probe()
819 priv->card.num_dapm_routes = 0; in fsl_asoc_card_probe()
820 } else if (of_device_is_compatible(np, "fsl,imx-audio-nau8822")) { in fsl_asoc_card_probe()
821 codec_dai_name[0] = "nau8822-hifi"; in fsl_asoc_card_probe()
822 priv->codec_priv[0].mclk_id = NAU8822_CLK_MCLK; in fsl_asoc_card_probe()
823 priv->codec_priv[0].fll_id = NAU8822_CLK_PLL; in fsl_asoc_card_probe()
824 priv->codec_priv[0].pll_id = NAU8822_CLK_PLL; in fsl_asoc_card_probe()
825 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; in fsl_asoc_card_probe()
827 priv->codec_priv[0].mclk = devm_clk_get(codec_dev[0], NULL); in fsl_asoc_card_probe()
828 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8904")) { in fsl_asoc_card_probe()
829 codec_dai_name[0] = "wm8904-hifi"; in fsl_asoc_card_probe()
830 priv->codec_priv[0].mclk_id = WM8904_FLL_MCLK; in fsl_asoc_card_probe()
831 priv->codec_priv[0].fll_id = WM8904_CLK_FLL; in fsl_asoc_card_probe()
832 priv->codec_priv[0].pll_id = WM8904_FLL_MCLK; in fsl_asoc_card_probe()
833 priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; in fsl_asoc_card_probe()
834 } else if (of_device_is_compatible(np, "fsl,imx-audio-spdif")) { in fsl_asoc_card_probe()
839 dev_err(&pdev->dev, "unknown Device Tree compatible\n"); in fsl_asoc_card_probe()
840 ret = -EINVAL; in fsl_asoc_card_probe()
845 * Allow setting mclk-id from the device-tree node. Otherwise, the in fsl_asoc_card_probe()
848 for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) { in fsl_asoc_card_probe()
849 of_property_read_u32_index(np, "mclk-id", codec_idx, in fsl_asoc_card_probe()
850 &priv->codec_priv[codec_idx].mclk_id); in fsl_asoc_card_probe()
860 for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) { in fsl_asoc_card_probe()
875 priv->dai_fmt = daifmt; in fsl_asoc_card_probe()
878 /* Change direction according to format */ in fsl_asoc_card_probe()
879 if (priv->dai_fmt & SND_SOC_DAIFMT_CBP_CFP) { in fsl_asoc_card_probe()
880 priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_IN; in fsl_asoc_card_probe()
881 priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_IN; in fsl_asoc_card_probe()
889 dev_dbg(&pdev->dev, "failed to find codec device\n"); in fsl_asoc_card_probe()
890 ret = -EPROBE_DEFER; in fsl_asoc_card_probe()
899 dev_err(&pdev->dev, "failed to init audmux\n"); in fsl_asoc_card_probe()
903 struct clk *esai_clk = clk_get(&cpu_pdev->dev, "extal"); in fsl_asoc_card_probe()
906 priv->cpu_priv.sysclk_freq[TX] = clk_get_rate(esai_clk); in fsl_asoc_card_probe()
907 priv->cpu_priv.sysclk_freq[RX] = clk_get_rate(esai_clk); in fsl_asoc_card_probe()
909 } else if (PTR_ERR(esai_clk) == -EPROBE_DEFER) { in fsl_asoc_card_probe()
910 ret = -EPROBE_DEFER; in fsl_asoc_card_probe()
914 priv->cpu_priv.sysclk_id[1] = ESAI_HCKT_EXTAL; in fsl_asoc_card_probe()
915 priv->cpu_priv.sysclk_id[0] = ESAI_HCKR_EXTAL; in fsl_asoc_card_probe()
916 } else if (of_node_name_eq(cpu_np, "sai")) { in fsl_asoc_card_probe()
917 priv->cpu_priv.sysclk_id[1] = FSL_SAI_CLK_MAST1; in fsl_asoc_card_probe()
918 priv->cpu_priv.sysclk_id[0] = FSL_SAI_CLK_MAST1; in fsl_asoc_card_probe()
922 priv->card.dev = &pdev->dev; in fsl_asoc_card_probe()
923 priv->card.owner = THIS_MODULE; in fsl_asoc_card_probe()
924 ret = snd_soc_of_parse_card_name(&priv->card, "model"); in fsl_asoc_card_probe()
926 snprintf(priv->name, sizeof(priv->name), "%s-audio", in fsl_asoc_card_probe()
928 priv->card.name = priv->name; in fsl_asoc_card_probe()
930 priv->card.dai_link = priv->dai_link; in fsl_asoc_card_probe()
931 priv->card.late_probe = fsl_asoc_card_late_probe; in fsl_asoc_card_probe()
932 priv->card.dapm_widgets = fsl_asoc_card_dapm_widgets; in fsl_asoc_card_probe()
933 priv->card.num_dapm_widgets = ARRAY_SIZE(fsl_asoc_card_dapm_widgets); in fsl_asoc_card_probe()
935 /* Drop the second half of DAPM routes -- ASRC */ in fsl_asoc_card_probe()
937 priv->card.num_dapm_routes /= 2; in fsl_asoc_card_probe()
939 if (of_property_read_bool(np, "audio-routing")) { in fsl_asoc_card_probe()
940 ret = snd_soc_of_parse_audio_routing(&priv->card, "audio-routing"); in fsl_asoc_card_probe()
942 dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret); in fsl_asoc_card_probe()
948 priv->dai_link[0].cpus->of_node = cpu_np; in fsl_asoc_card_probe()
949 for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) { in fsl_asoc_card_probe()
950 codec_comp->dai_name = codec_dai_name[codec_idx]; in fsl_asoc_card_probe()
955 priv->dai_link[0].codecs[0].name = snd_soc_dummy_dlc.name; in fsl_asoc_card_probe()
958 for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) { in fsl_asoc_card_probe()
959 codec_comp->of_node = codec_np[codec_idx]; in fsl_asoc_card_probe()
964 ret = of_property_read_u32(cpu_np, "cell-index", &idx); in fsl_asoc_card_probe()
966 dev_err(&pdev->dev, in fsl_asoc_card_probe()
971 priv->dai_link[0].codecs[0].name = in fsl_asoc_card_probe()
972 devm_kasprintf(&pdev->dev, GFP_KERNEL, in fsl_asoc_card_probe()
973 "ac97-codec.%u", in fsl_asoc_card_probe()
975 if (!priv->dai_link[0].codecs[0].name) { in fsl_asoc_card_probe()
976 ret = -ENOMEM; in fsl_asoc_card_probe()
981 priv->dai_link[0].platforms->of_node = cpu_np; in fsl_asoc_card_probe()
982 priv->dai_link[0].dai_fmt = priv->dai_fmt; in fsl_asoc_card_probe()
983 priv->card.num_links = 1; in fsl_asoc_card_probe()
987 priv->dai_link[1].cpus->of_node = asrc_np; in fsl_asoc_card_probe()
988 priv->dai_link[1].platforms->of_node = asrc_np; in fsl_asoc_card_probe()
989 for_each_link_codecs((&(priv->dai_link[2])), codec_idx, codec_comp) { in fsl_asoc_card_probe()
990 codec_comp->dai_name = priv->dai_link[0].codecs[codec_idx].dai_name; in fsl_asoc_card_probe()
991 codec_comp->of_node = priv->dai_link[0].codecs[codec_idx].of_node; in fsl_asoc_card_probe()
992 codec_comp->name = priv->dai_link[0].codecs[codec_idx].name; in fsl_asoc_card_probe()
994 priv->dai_link[2].cpus->of_node = cpu_np; in fsl_asoc_card_probe()
995 priv->dai_link[2].dai_fmt = priv->dai_fmt; in fsl_asoc_card_probe()
996 priv->card.num_links = 3; in fsl_asoc_card_probe()
998 ret = of_property_read_u32(asrc_np, "fsl,asrc-rate", in fsl_asoc_card_probe()
999 &priv->asrc_rate); in fsl_asoc_card_probe()
1001 dev_err(&pdev->dev, "failed to get output rate\n"); in fsl_asoc_card_probe()
1002 ret = -EINVAL; in fsl_asoc_card_probe()
1006 ret = of_property_read_u32(asrc_np, "fsl,asrc-format", &asrc_fmt); in fsl_asoc_card_probe()
1007 priv->asrc_format = (__force snd_pcm_format_t)asrc_fmt; in fsl_asoc_card_probe()
1010 ret = of_property_read_u32(asrc_np, "fsl,asrc-width", in fsl_asoc_card_probe()
1013 dev_err(&pdev->dev, in fsl_asoc_card_probe()
1014 "failed to decide output format\n"); in fsl_asoc_card_probe()
1019 priv->asrc_format = SNDRV_PCM_FORMAT_S24_LE; in fsl_asoc_card_probe()
1021 priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE; in fsl_asoc_card_probe()
1027 snd_soc_card_set_drvdata(&priv->card, priv); in fsl_asoc_card_probe()
1029 ret = devm_snd_soc_register_card(&pdev->dev, &priv->card); in fsl_asoc_card_probe()
1031 dev_err_probe(&pdev->dev, ret, "snd_soc_register_card failed\n"); in fsl_asoc_card_probe()
1036 * Properties "hp-det-gpio" and "mic-det-gpio" are optional, and in fsl_asoc_card_probe()
1043 if (of_property_read_bool(np, "hp-det-gpio")) { in fsl_asoc_card_probe()
1044 ret = simple_util_init_jack(&priv->card, &priv->hp_jack, in fsl_asoc_card_probe()
1049 snd_soc_jack_notifier_register(&priv->hp_jack.jack, &hp_jack_nb); in fsl_asoc_card_probe()
1052 if (of_property_read_bool(np, "mic-det-gpio")) { in fsl_asoc_card_probe()
1053 ret = simple_util_init_jack(&priv->card, &priv->mic_jack, in fsl_asoc_card_probe()
1058 snd_soc_jack_notifier_register(&priv->mic_jack.jack, &mic_jack_nb); in fsl_asoc_card_probe()
1065 put_device(&cpu_pdev->dev); in fsl_asoc_card_probe()
1073 { .compatible = "fsl,imx-audio-ac97", },
1074 { .compatible = "fsl,imx-audio-cs42888", },
1075 { .compatible = "fsl,imx-audio-cs427x", },
1076 { .compatible = "fsl,imx-audio-tlv320aic32x4", },
1077 { .compatible = "fsl,imx-audio-tlv320aic31xx", },
1078 { .compatible = "fsl,imx-audio-sgtl5000", },
1079 { .compatible = "fsl,imx-audio-wm8962", },
1080 { .compatible = "fsl,imx-audio-wm8960", },
1081 { .compatible = "fsl,imx-audio-mqs", },
1082 { .compatible = "fsl,imx-audio-wm8524", },
1083 { .compatible = "fsl,imx-audio-si476x", },
1084 { .compatible = "fsl,imx-audio-wm8958", },
1085 { .compatible = "fsl,imx-audio-nau8822", },
1086 { .compatible = "fsl,imx-audio-wm8904", },
1087 { .compatible = "fsl,imx-audio-spdif", },