1 // SPDX-License-Identifier: GPL-2.0
3 // Freescale Generic ASoC Sound Card driver with ASRC
5 // Copyright (C) 2014 Freescale Semiconductor, Inc.
7 // Author: Nicolin Chen <nicoleotsuka@gmail.com>
10 #include <linux/i2c.h>
11 #include <linux/module.h>
12 #include <linux/of_platform.h>
13 #if IS_ENABLED(CONFIG_SND_AC97_CODEC)
14 #include <sound/ac97_codec.h>
16 #include <sound/pcm_params.h>
17 #include <sound/soc.h>
18 #include <sound/jack.h>
19 #include <sound/simple_card_utils.h>
23 #include "imx-audmux.h"
25 #include "../codecs/sgtl5000.h"
26 #include "../codecs/wm8962.h"
27 #include "../codecs/wm8960.h"
29 #define CS427x_SYSCLK_MCLK 0
34 /* Default DAI format without Master and Slave flag */
35 #define DAI_FMT_BASE (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF)
38 * struct codec_priv - CODEC private data
39 * @mclk_freq: Clock rate of MCLK
40 * @mclk_id: MCLK (or main clock) id for set_sysclk()
41 * @fll_id: FLL (or secordary clock) id for set_sysclk()
42 * @pll_id: PLL id for set_pll()
45 unsigned long mclk_freq;
52 * struct cpu_priv - CPU private data
53 * @sysclk_freq: SYSCLK rates for set_sysclk()
54 * @sysclk_dir: SYSCLK directions for set_sysclk()
55 * @sysclk_id: SYSCLK ids for set_sysclk()
56 * @slot_width: Slot width of each frame
58 * Note: [1] for tx and [0] for rx
61 unsigned long sysclk_freq[2];
68 * struct fsl_asoc_card_priv - Freescale Generic ASOC card private data
69 * @dai_link: DAI link structure including normal one and DPCM link
70 * @hp_jack: Headphone Jack structure
71 * @mic_jack: Microphone Jack structure
72 * @pdev: platform device pointer
73 * @codec_priv: CODEC private data
74 * @cpu_priv: CPU private data
75 * @card: ASoC card structure
76 * @sample_rate: Current sample rate
77 * @sample_format: Current sample format
78 * @asrc_rate: ASRC sample rate used by Back-Ends
79 * @asrc_format: ASRC sample format used by Back-Ends
80 * @dai_fmt: DAI format between CPU and CODEC
84 struct fsl_asoc_card_priv {
85 struct snd_soc_dai_link dai_link[3];
86 struct asoc_simple_jack hp_jack;
87 struct asoc_simple_jack mic_jack;
88 struct platform_device *pdev;
89 struct codec_priv codec_priv;
90 struct cpu_priv cpu_priv;
91 struct snd_soc_card card;
93 snd_pcm_format_t sample_format;
95 snd_pcm_format_t asrc_format;
101 * This dapm route map exists for DPCM link only.
102 * The other routes shall go through Device Tree.
104 * Note: keep all ASRC routes in the second half
105 * to drop them easily for non-ASRC cases.
107 static const struct snd_soc_dapm_route audio_map[] = {
108 /* 1st half -- Normal DAPM routes */
109 {"Playback", NULL, "CPU-Playback"},
110 {"CPU-Capture", NULL, "Capture"},
111 /* 2nd half -- ASRC DAPM routes */
112 {"CPU-Playback", NULL, "ASRC-Playback"},
113 {"ASRC-Capture", NULL, "CPU-Capture"},
116 static const struct snd_soc_dapm_route audio_map_ac97[] = {
117 /* 1st half -- Normal DAPM routes */
118 {"Playback", NULL, "AC97 Playback"},
119 {"AC97 Capture", NULL, "Capture"},
120 /* 2nd half -- ASRC DAPM routes */
121 {"AC97 Playback", NULL, "ASRC-Playback"},
122 {"ASRC-Capture", NULL, "AC97 Capture"},
125 static const struct snd_soc_dapm_route audio_map_tx[] = {
126 /* 1st half -- Normal DAPM routes */
127 {"Playback", NULL, "CPU-Playback"},
128 /* 2nd half -- ASRC DAPM routes */
129 {"CPU-Playback", NULL, "ASRC-Playback"},
132 /* Add all possible widgets into here without being redundant */
133 static const struct snd_soc_dapm_widget fsl_asoc_card_dapm_widgets[] = {
134 SND_SOC_DAPM_LINE("Line Out Jack", NULL),
135 SND_SOC_DAPM_LINE("Line In Jack", NULL),
136 SND_SOC_DAPM_HP("Headphone Jack", NULL),
137 SND_SOC_DAPM_SPK("Ext Spk", NULL),
138 SND_SOC_DAPM_MIC("Mic Jack", NULL),
139 SND_SOC_DAPM_MIC("AMIC", NULL),
140 SND_SOC_DAPM_MIC("DMIC", NULL),
143 static bool fsl_asoc_card_is_ac97(struct fsl_asoc_card_priv *priv)
145 return priv->dai_fmt == SND_SOC_DAIFMT_AC97;
148 static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream,
149 struct snd_pcm_hw_params *params)
151 struct snd_soc_pcm_runtime *rtd = substream->private_data;
152 struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
153 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
154 struct cpu_priv *cpu_priv = &priv->cpu_priv;
155 struct device *dev = rtd->card->dev;
158 priv->sample_rate = params_rate(params);
159 priv->sample_format = params_format(params);
162 * If codec-dai is DAI Master and all configurations are already in the
163 * set_bias_level(), bypass the remaining settings in hw_params().
164 * Note: (dai_fmt & CBM_CFM) includes CBM_CFM and CBM_CFS.
166 if ((priv->card.set_bias_level &&
167 priv->dai_fmt & SND_SOC_DAIFMT_CBM_CFM) ||
168 fsl_asoc_card_is_ac97(priv))
171 /* Specific configurations of DAIs starts from here */
172 ret = snd_soc_dai_set_sysclk(asoc_rtd_to_cpu(rtd, 0), cpu_priv->sysclk_id[tx],
173 cpu_priv->sysclk_freq[tx],
174 cpu_priv->sysclk_dir[tx]);
175 if (ret && ret != -ENOTSUPP) {
176 dev_err(dev, "failed to set sysclk for cpu dai\n");
180 if (cpu_priv->slot_width) {
181 ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2,
182 cpu_priv->slot_width);
183 if (ret && ret != -ENOTSUPP) {
184 dev_err(dev, "failed to set TDM slot for cpu dai\n");
192 static const struct snd_soc_ops fsl_asoc_card_ops = {
193 .hw_params = fsl_asoc_card_hw_params,
196 static int be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
197 struct snd_pcm_hw_params *params)
199 struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
200 struct snd_interval *rate;
201 struct snd_mask *mask;
203 rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
204 rate->max = rate->min = priv->asrc_rate;
206 mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
208 snd_mask_set_format(mask, priv->asrc_format);
213 SND_SOC_DAILINK_DEFS(hifi,
214 DAILINK_COMP_ARRAY(COMP_EMPTY()),
215 DAILINK_COMP_ARRAY(COMP_EMPTY()),
216 DAILINK_COMP_ARRAY(COMP_EMPTY()));
218 SND_SOC_DAILINK_DEFS(hifi_fe,
219 DAILINK_COMP_ARRAY(COMP_EMPTY()),
220 DAILINK_COMP_ARRAY(COMP_DUMMY()),
221 DAILINK_COMP_ARRAY(COMP_EMPTY()));
223 SND_SOC_DAILINK_DEFS(hifi_be,
224 DAILINK_COMP_ARRAY(COMP_EMPTY()),
225 DAILINK_COMP_ARRAY(COMP_EMPTY()),
226 DAILINK_COMP_ARRAY(COMP_DUMMY()));
228 static struct snd_soc_dai_link fsl_asoc_card_dai[] = {
229 /* Default ASoC DAI Link*/
232 .stream_name = "HiFi",
233 .ops = &fsl_asoc_card_ops,
234 SND_SOC_DAILINK_REG(hifi),
236 /* DPCM Link between Front-End and Back-End (Optional) */
238 .name = "HiFi-ASRC-FE",
239 .stream_name = "HiFi-ASRC-FE",
243 SND_SOC_DAILINK_REG(hifi_fe),
246 .name = "HiFi-ASRC-BE",
247 .stream_name = "HiFi-ASRC-BE",
248 .be_hw_params_fixup = be_hw_params_fixup,
249 .ops = &fsl_asoc_card_ops,
253 SND_SOC_DAILINK_REG(hifi_be),
257 static int fsl_asoc_card_set_bias_level(struct snd_soc_card *card,
258 struct snd_soc_dapm_context *dapm,
259 enum snd_soc_bias_level level)
261 struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card);
262 struct snd_soc_pcm_runtime *rtd;
263 struct snd_soc_dai *codec_dai;
264 struct codec_priv *codec_priv = &priv->codec_priv;
265 struct device *dev = card->dev;
266 unsigned int pll_out;
269 rtd = snd_soc_get_pcm_runtime(card, &card->dai_link[0]);
270 codec_dai = asoc_rtd_to_codec(rtd, 0);
271 if (dapm->dev != codec_dai->dev)
275 case SND_SOC_BIAS_PREPARE:
276 if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
279 if (priv->sample_format == SNDRV_PCM_FORMAT_S24_LE)
280 pll_out = priv->sample_rate * 384;
282 pll_out = priv->sample_rate * 256;
284 ret = snd_soc_dai_set_pll(codec_dai, codec_priv->pll_id,
286 codec_priv->mclk_freq, pll_out);
288 dev_err(dev, "failed to start FLL: %d\n", ret);
292 ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->fll_id,
293 pll_out, SND_SOC_CLOCK_IN);
294 if (ret && ret != -ENOTSUPP) {
295 dev_err(dev, "failed to set SYSCLK: %d\n", ret);
300 case SND_SOC_BIAS_STANDBY:
301 if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
304 ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
305 codec_priv->mclk_freq,
307 if (ret && ret != -ENOTSUPP) {
308 dev_err(dev, "failed to switch away from FLL: %d\n", ret);
312 ret = snd_soc_dai_set_pll(codec_dai, codec_priv->pll_id, 0, 0, 0);
314 dev_err(dev, "failed to stop FLL: %d\n", ret);
326 static int fsl_asoc_card_audmux_init(struct device_node *np,
327 struct fsl_asoc_card_priv *priv)
329 struct device *dev = &priv->pdev->dev;
330 u32 int_ptcr = 0, ext_ptcr = 0;
331 int int_port, ext_port;
334 ret = of_property_read_u32(np, "mux-int-port", &int_port);
336 dev_err(dev, "mux-int-port missing or invalid\n");
339 ret = of_property_read_u32(np, "mux-ext-port", &ext_port);
341 dev_err(dev, "mux-ext-port missing or invalid\n");
346 * The port numbering in the hardware manual starts at 1, while
347 * the AUDMUX API expects it starts at 0.
353 * Use asynchronous mode (6 wires) for all cases except AC97.
354 * If only 4 wires are needed, just set SSI into
355 * synchronous mode and enable 4 PADs in IOMUX.
357 switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
358 case SND_SOC_DAIFMT_CBM_CFM:
359 int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
360 IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
361 IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
362 IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
363 IMX_AUDMUX_V2_PTCR_RFSDIR |
364 IMX_AUDMUX_V2_PTCR_RCLKDIR |
365 IMX_AUDMUX_V2_PTCR_TFSDIR |
366 IMX_AUDMUX_V2_PTCR_TCLKDIR;
368 case SND_SOC_DAIFMT_CBM_CFS:
369 int_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
370 IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
371 IMX_AUDMUX_V2_PTCR_RCLKDIR |
372 IMX_AUDMUX_V2_PTCR_TCLKDIR;
373 ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
374 IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
375 IMX_AUDMUX_V2_PTCR_RFSDIR |
376 IMX_AUDMUX_V2_PTCR_TFSDIR;
378 case SND_SOC_DAIFMT_CBS_CFM:
379 int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
380 IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
381 IMX_AUDMUX_V2_PTCR_RFSDIR |
382 IMX_AUDMUX_V2_PTCR_TFSDIR;
383 ext_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
384 IMX_AUDMUX_V2_PTCR_TCSEL(int_port) |
385 IMX_AUDMUX_V2_PTCR_RCLKDIR |
386 IMX_AUDMUX_V2_PTCR_TCLKDIR;
388 case SND_SOC_DAIFMT_CBS_CFS:
389 ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
390 IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
391 IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
392 IMX_AUDMUX_V2_PTCR_TCSEL(int_port) |
393 IMX_AUDMUX_V2_PTCR_RFSDIR |
394 IMX_AUDMUX_V2_PTCR_RCLKDIR |
395 IMX_AUDMUX_V2_PTCR_TFSDIR |
396 IMX_AUDMUX_V2_PTCR_TCLKDIR;
399 if (!fsl_asoc_card_is_ac97(priv))
403 if (fsl_asoc_card_is_ac97(priv)) {
404 int_ptcr = IMX_AUDMUX_V2_PTCR_SYN |
405 IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
406 IMX_AUDMUX_V2_PTCR_TCLKDIR;
407 ext_ptcr = IMX_AUDMUX_V2_PTCR_SYN |
408 IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
409 IMX_AUDMUX_V2_PTCR_TFSDIR;
412 /* Asynchronous mode can not be set along with RCLKDIR */
413 if (!fsl_asoc_card_is_ac97(priv)) {
415 IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port);
417 ret = imx_audmux_v2_configure_port(int_port, 0,
420 dev_err(dev, "audmux internal port setup failed\n");
425 ret = imx_audmux_v2_configure_port(int_port, int_ptcr,
426 IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port));
428 dev_err(dev, "audmux internal port setup failed\n");
432 if (!fsl_asoc_card_is_ac97(priv)) {
434 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port);
436 ret = imx_audmux_v2_configure_port(ext_port, 0,
439 dev_err(dev, "audmux external port setup failed\n");
444 ret = imx_audmux_v2_configure_port(ext_port, ext_ptcr,
445 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port));
447 dev_err(dev, "audmux external port setup failed\n");
454 static int hp_jack_event(struct notifier_block *nb, unsigned long event,
457 struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
458 struct snd_soc_dapm_context *dapm = &jack->card->dapm;
460 if (event & SND_JACK_HEADPHONE)
461 /* Disable speaker if headphone is plugged in */
462 snd_soc_dapm_disable_pin(dapm, "Ext Spk");
464 snd_soc_dapm_enable_pin(dapm, "Ext Spk");
469 static struct notifier_block hp_jack_nb = {
470 .notifier_call = hp_jack_event,
473 static int mic_jack_event(struct notifier_block *nb, unsigned long event,
476 struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
477 struct snd_soc_dapm_context *dapm = &jack->card->dapm;
479 if (event & SND_JACK_MICROPHONE)
480 /* Disable dmic if microphone is plugged in */
481 snd_soc_dapm_disable_pin(dapm, "DMIC");
483 snd_soc_dapm_enable_pin(dapm, "DMIC");
488 static struct notifier_block mic_jack_nb = {
489 .notifier_call = mic_jack_event,
492 static int fsl_asoc_card_late_probe(struct snd_soc_card *card)
494 struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card);
495 struct snd_soc_pcm_runtime *rtd = list_first_entry(
496 &card->rtd_list, struct snd_soc_pcm_runtime, list);
497 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
498 struct codec_priv *codec_priv = &priv->codec_priv;
499 struct device *dev = card->dev;
502 if (fsl_asoc_card_is_ac97(priv)) {
503 #if IS_ENABLED(CONFIG_SND_AC97_CODEC)
504 struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
505 struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
508 * Use slots 3/4 for S/PDIF so SSI won't try to enable
509 * other slots and send some samples there
510 * due to SLOTREQ bits for S/PDIF received from codec
512 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
513 AC97_EA_SPSA_SLOT_MASK, AC97_EA_SPSA_3_4);
519 ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
520 codec_priv->mclk_freq, SND_SOC_CLOCK_IN);
521 if (ret && ret != -ENOTSUPP) {
522 dev_err(dev, "failed to set sysclk in %s\n", __func__);
529 static int fsl_asoc_card_probe(struct platform_device *pdev)
531 struct device_node *cpu_np, *codec_np, *asrc_np;
532 struct device_node *np = pdev->dev.of_node;
533 struct platform_device *asrc_pdev = NULL;
534 struct platform_device *cpu_pdev;
535 struct fsl_asoc_card_priv *priv;
536 struct device *codec_dev = NULL;
537 const char *codec_dai_name;
538 const char *codec_dev_name;
542 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
546 cpu_np = of_parse_phandle(np, "audio-cpu", 0);
547 /* Give a chance to old DT binding */
549 cpu_np = of_parse_phandle(np, "ssi-controller", 0);
551 dev_err(&pdev->dev, "CPU phandle missing or invalid\n");
556 cpu_pdev = of_find_device_by_node(cpu_np);
558 dev_err(&pdev->dev, "failed to find CPU DAI device\n");
563 codec_np = of_parse_phandle(np, "audio-codec", 0);
565 struct platform_device *codec_pdev;
566 struct i2c_client *codec_i2c;
568 codec_i2c = of_find_i2c_device_by_node(codec_np);
570 codec_dev = &codec_i2c->dev;
571 codec_dev_name = codec_i2c->name;
574 codec_pdev = of_find_device_by_node(codec_np);
576 codec_dev = &codec_pdev->dev;
577 codec_dev_name = codec_pdev->name;
582 asrc_np = of_parse_phandle(np, "audio-asrc", 0);
584 asrc_pdev = of_find_device_by_node(asrc_np);
586 /* Get the MCLK rate only, and leave it controlled by CODEC drivers */
588 struct clk *codec_clk = clk_get(codec_dev, NULL);
590 if (!IS_ERR(codec_clk)) {
591 priv->codec_priv.mclk_freq = clk_get_rate(codec_clk);
596 /* Default sample rate and format, will be updated in hw_params() */
597 priv->sample_rate = 44100;
598 priv->sample_format = SNDRV_PCM_FORMAT_S16_LE;
600 /* Assign a default DAI format, and allow each card to overwrite it */
601 priv->dai_fmt = DAI_FMT_BASE;
603 memcpy(priv->dai_link, fsl_asoc_card_dai,
604 sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link));
606 priv->card.dapm_routes = audio_map;
607 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map);
608 /* Diversify the card configurations */
609 if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) {
610 codec_dai_name = "cs42888";
611 priv->card.set_bias_level = NULL;
612 priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv.mclk_freq;
613 priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv.mclk_freq;
614 priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
615 priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT;
616 priv->cpu_priv.slot_width = 32;
617 priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
618 } else if (of_device_is_compatible(np, "fsl,imx-audio-cs427x")) {
619 codec_dai_name = "cs4271-hifi";
620 priv->codec_priv.mclk_id = CS427x_SYSCLK_MCLK;
621 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
622 } else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) {
623 codec_dai_name = "sgtl5000";
624 priv->codec_priv.mclk_id = SGTL5000_SYSCLK;
625 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
626 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) {
627 codec_dai_name = "wm8962";
628 priv->card.set_bias_level = fsl_asoc_card_set_bias_level;
629 priv->codec_priv.mclk_id = WM8962_SYSCLK_MCLK;
630 priv->codec_priv.fll_id = WM8962_SYSCLK_FLL;
631 priv->codec_priv.pll_id = WM8962_FLL;
632 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
633 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8960")) {
634 codec_dai_name = "wm8960-hifi";
635 priv->card.set_bias_level = fsl_asoc_card_set_bias_level;
636 priv->codec_priv.fll_id = WM8960_SYSCLK_AUTO;
637 priv->codec_priv.pll_id = WM8960_SYSCLK_AUTO;
638 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
639 } else if (of_device_is_compatible(np, "fsl,imx-audio-ac97")) {
640 codec_dai_name = "ac97-hifi";
641 priv->card.set_bias_level = NULL;
642 priv->dai_fmt = SND_SOC_DAIFMT_AC97;
643 priv->card.dapm_routes = audio_map_ac97;
644 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_ac97);
645 } else if (of_device_is_compatible(np, "fsl,imx-audio-mqs")) {
646 codec_dai_name = "fsl-mqs-dai";
647 priv->card.set_bias_level = NULL;
648 priv->dai_fmt = SND_SOC_DAIFMT_LEFT_J |
649 SND_SOC_DAIFMT_CBS_CFS |
650 SND_SOC_DAIFMT_NB_NF;
651 priv->dai_link[1].dpcm_capture = 0;
652 priv->dai_link[2].dpcm_capture = 0;
653 priv->card.dapm_routes = audio_map_tx;
654 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
655 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8524")) {
656 codec_dai_name = "wm8524-hifi";
657 priv->card.set_bias_level = NULL;
658 priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
659 priv->dai_link[1].dpcm_capture = 0;
660 priv->dai_link[2].dpcm_capture = 0;
661 priv->cpu_priv.slot_width = 32;
662 priv->card.dapm_routes = audio_map_tx;
663 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
665 dev_err(&pdev->dev, "unknown Device Tree compatible\n");
670 if (!fsl_asoc_card_is_ac97(priv) && !codec_dev) {
671 dev_err(&pdev->dev, "failed to find codec device\n");
676 /* Common settings for corresponding Freescale CPU DAI driver */
677 if (of_node_name_eq(cpu_np, "ssi")) {
678 /* Only SSI needs to configure AUDMUX */
679 ret = fsl_asoc_card_audmux_init(np, priv);
681 dev_err(&pdev->dev, "failed to init audmux\n");
684 } else if (of_node_name_eq(cpu_np, "esai")) {
685 priv->cpu_priv.sysclk_id[1] = ESAI_HCKT_EXTAL;
686 priv->cpu_priv.sysclk_id[0] = ESAI_HCKR_EXTAL;
687 } else if (of_node_name_eq(cpu_np, "sai")) {
688 priv->cpu_priv.sysclk_id[1] = FSL_SAI_CLK_MAST1;
689 priv->cpu_priv.sysclk_id[0] = FSL_SAI_CLK_MAST1;
692 /* Initialize sound card */
694 priv->card.dev = &pdev->dev;
695 ret = snd_soc_of_parse_card_name(&priv->card, "model");
697 snprintf(priv->name, sizeof(priv->name), "%s-audio",
698 fsl_asoc_card_is_ac97(priv) ? "ac97" : codec_dev_name);
699 priv->card.name = priv->name;
701 priv->card.dai_link = priv->dai_link;
702 priv->card.late_probe = fsl_asoc_card_late_probe;
703 priv->card.dapm_widgets = fsl_asoc_card_dapm_widgets;
704 priv->card.num_dapm_widgets = ARRAY_SIZE(fsl_asoc_card_dapm_widgets);
706 /* Drop the second half of DAPM routes -- ASRC */
708 priv->card.num_dapm_routes /= 2;
710 if (of_property_read_bool(np, "audio-routing")) {
711 ret = snd_soc_of_parse_audio_routing(&priv->card, "audio-routing");
713 dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret);
718 /* Normal DAI Link */
719 priv->dai_link[0].cpus->of_node = cpu_np;
720 priv->dai_link[0].codecs->dai_name = codec_dai_name;
722 if (!fsl_asoc_card_is_ac97(priv))
723 priv->dai_link[0].codecs->of_node = codec_np;
727 ret = of_property_read_u32(cpu_np, "cell-index", &idx);
730 "cannot get CPU index property\n");
734 priv->dai_link[0].codecs->name =
735 devm_kasprintf(&pdev->dev, GFP_KERNEL,
738 if (!priv->dai_link[0].codecs->name) {
744 priv->dai_link[0].platforms->of_node = cpu_np;
745 priv->dai_link[0].dai_fmt = priv->dai_fmt;
746 priv->card.num_links = 1;
749 /* DPCM DAI Links only if ASRC exsits */
750 priv->dai_link[1].cpus->of_node = asrc_np;
751 priv->dai_link[1].platforms->of_node = asrc_np;
752 priv->dai_link[2].codecs->dai_name = codec_dai_name;
753 priv->dai_link[2].codecs->of_node = codec_np;
754 priv->dai_link[2].codecs->name =
755 priv->dai_link[0].codecs->name;
756 priv->dai_link[2].cpus->of_node = cpu_np;
757 priv->dai_link[2].dai_fmt = priv->dai_fmt;
758 priv->card.num_links = 3;
760 ret = of_property_read_u32(asrc_np, "fsl,asrc-rate",
763 dev_err(&pdev->dev, "failed to get output rate\n");
768 ret = of_property_read_u32(asrc_np, "fsl,asrc-format",
771 /* Fallback to old binding; translate to asrc_format */
772 ret = of_property_read_u32(asrc_np, "fsl,asrc-width",
776 "failed to decide output format\n");
781 priv->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
783 priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE;
787 /* Finish card registering */
788 platform_set_drvdata(pdev, priv);
789 snd_soc_card_set_drvdata(&priv->card, priv);
791 ret = devm_snd_soc_register_card(&pdev->dev, &priv->card);
793 if (ret != -EPROBE_DEFER)
794 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
799 * Properties "hp-det-gpio" and "mic-det-gpio" are optional, and
800 * asoc_simple_init_jack uses these properties for creating
801 * Headphone Jack and Microphone Jack.
803 * The notifier is initialized in snd_soc_card_jack_new(), then
804 * snd_soc_jack_notifier_register can be called.
806 if (of_property_read_bool(np, "hp-det-gpio")) {
807 ret = asoc_simple_init_jack(&priv->card, &priv->hp_jack,
808 1, NULL, "Headphone Jack");
812 snd_soc_jack_notifier_register(&priv->hp_jack.jack, &hp_jack_nb);
815 if (of_property_read_bool(np, "mic-det-gpio")) {
816 ret = asoc_simple_init_jack(&priv->card, &priv->mic_jack,
817 0, NULL, "Mic Jack");
821 snd_soc_jack_notifier_register(&priv->mic_jack.jack, &mic_jack_nb);
825 of_node_put(asrc_np);
826 of_node_put(codec_np);
827 put_device(&cpu_pdev->dev);
834 static const struct of_device_id fsl_asoc_card_dt_ids[] = {
835 { .compatible = "fsl,imx-audio-ac97", },
836 { .compatible = "fsl,imx-audio-cs42888", },
837 { .compatible = "fsl,imx-audio-cs427x", },
838 { .compatible = "fsl,imx-audio-sgtl5000", },
839 { .compatible = "fsl,imx-audio-wm8962", },
840 { .compatible = "fsl,imx-audio-wm8960", },
841 { .compatible = "fsl,imx-audio-mqs", },
842 { .compatible = "fsl,imx-audio-wm8524", },
845 MODULE_DEVICE_TABLE(of, fsl_asoc_card_dt_ids);
847 static struct platform_driver fsl_asoc_card_driver = {
848 .probe = fsl_asoc_card_probe,
850 .name = "fsl-asoc-card",
851 .pm = &snd_soc_pm_ops,
852 .of_match_table = fsl_asoc_card_dt_ids,
855 module_platform_driver(fsl_asoc_card_driver);
857 MODULE_DESCRIPTION("Freescale Generic ASoC Sound Card driver with ASRC");
858 MODULE_AUTHOR("Nicolin Chen <nicoleotsuka@gmail.com>");
859 MODULE_ALIAS("platform:fsl-asoc-card");
860 MODULE_LICENSE("GPL");