2 * Freescale Generic ASoC Sound Card driver with ASRC
4 * Copyright (C) 2014 Freescale Semiconductor, Inc.
6 * Author: Nicolin Chen <nicoleotsuka@gmail.com>
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
13 #include <linux/clk.h>
14 #include <linux/i2c.h>
15 #include <linux/module.h>
16 #include <linux/of_platform.h>
17 #if IS_ENABLED(CONFIG_SND_AC97_CODEC)
18 #include <sound/ac97_codec.h>
20 #include <sound/pcm_params.h>
21 #include <sound/soc.h>
25 #include "imx-audmux.h"
27 #include "../codecs/sgtl5000.h"
28 #include "../codecs/wm8962.h"
29 #include "../codecs/wm8960.h"
31 #define CS427x_SYSCLK_MCLK 0
36 /* Default DAI format without Master and Slave flag */
37 #define DAI_FMT_BASE (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF)
42 * @mclk_freq: Clock rate of MCLK
43 * @mclk_id: MCLK (or main clock) id for set_sysclk()
44 * @fll_id: FLL (or secordary clock) id for set_sysclk()
45 * @pll_id: PLL id for set_pll()
48 unsigned long mclk_freq
;
57 * @sysclk_freq[2]: SYSCLK rates for set_sysclk()
58 * @sysclk_dir[2]: SYSCLK directions for set_sysclk()
59 * @sysclk_id[2]: SYSCLK ids for set_sysclk()
60 * @slot_width: Slot width of each frame
62 * Note: [1] for tx and [0] for rx
65 unsigned long sysclk_freq
[2];
72 * Freescale Generic ASOC card private data
74 * @dai_link[3]: DAI link structure including normal one and DPCM link
75 * @pdev: platform device pointer
76 * @codec_priv: CODEC private data
77 * @cpu_priv: CPU private data
78 * @card: ASoC card structure
79 * @sample_rate: Current sample rate
80 * @sample_format: Current sample format
81 * @asrc_rate: ASRC sample rate used by Back-Ends
82 * @asrc_format: ASRC sample format used by Back-Ends
83 * @dai_fmt: DAI format between CPU and CODEC
87 struct fsl_asoc_card_priv
{
88 struct snd_soc_dai_link dai_link
[3];
89 struct platform_device
*pdev
;
90 struct codec_priv codec_priv
;
91 struct cpu_priv cpu_priv
;
92 struct snd_soc_card card
;
102 * This dapm route map exsits for DPCM link only.
103 * The other routes shall go through Device Tree.
105 * Note: keep all ASRC routes in the second half
106 * to drop them easily for non-ASRC cases.
108 static const struct snd_soc_dapm_route audio_map
[] = {
109 /* 1st half -- Normal DAPM routes */
110 {"Playback", NULL
, "CPU-Playback"},
111 {"CPU-Capture", NULL
, "Capture"},
112 /* 2nd half -- ASRC DAPM routes */
113 {"CPU-Playback", NULL
, "ASRC-Playback"},
114 {"ASRC-Capture", NULL
, "CPU-Capture"},
117 static const struct snd_soc_dapm_route audio_map_ac97
[] = {
118 /* 1st half -- Normal DAPM routes */
119 {"Playback", NULL
, "AC97 Playback"},
120 {"AC97 Capture", NULL
, "Capture"},
121 /* 2nd half -- ASRC DAPM routes */
122 {"AC97 Playback", NULL
, "ASRC-Playback"},
123 {"ASRC-Capture", NULL
, "AC97 Capture"},
126 /* Add all possible widgets into here without being redundant */
127 static const struct snd_soc_dapm_widget fsl_asoc_card_dapm_widgets
[] = {
128 SND_SOC_DAPM_LINE("Line Out Jack", NULL
),
129 SND_SOC_DAPM_LINE("Line In Jack", NULL
),
130 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
131 SND_SOC_DAPM_SPK("Ext Spk", NULL
),
132 SND_SOC_DAPM_MIC("Mic Jack", NULL
),
133 SND_SOC_DAPM_MIC("AMIC", NULL
),
134 SND_SOC_DAPM_MIC("DMIC", NULL
),
137 static bool fsl_asoc_card_is_ac97(struct fsl_asoc_card_priv
*priv
)
139 return priv
->dai_fmt
== SND_SOC_DAIFMT_AC97
;
142 static int fsl_asoc_card_hw_params(struct snd_pcm_substream
*substream
,
143 struct snd_pcm_hw_params
*params
)
145 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
146 struct fsl_asoc_card_priv
*priv
= snd_soc_card_get_drvdata(rtd
->card
);
147 bool tx
= substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
;
148 struct cpu_priv
*cpu_priv
= &priv
->cpu_priv
;
149 struct device
*dev
= rtd
->card
->dev
;
152 priv
->sample_rate
= params_rate(params
);
153 priv
->sample_format
= params_format(params
);
156 * If codec-dai is DAI Master and all configurations are already in the
157 * set_bias_level(), bypass the remaining settings in hw_params().
158 * Note: (dai_fmt & CBM_CFM) includes CBM_CFM and CBM_CFS.
160 if ((priv
->card
.set_bias_level
&&
161 priv
->dai_fmt
& SND_SOC_DAIFMT_CBM_CFM
) ||
162 fsl_asoc_card_is_ac97(priv
))
165 /* Specific configurations of DAIs starts from here */
166 ret
= snd_soc_dai_set_sysclk(rtd
->cpu_dai
, cpu_priv
->sysclk_id
[tx
],
167 cpu_priv
->sysclk_freq
[tx
],
168 cpu_priv
->sysclk_dir
[tx
]);
170 dev_err(dev
, "failed to set sysclk for cpu dai\n");
174 if (cpu_priv
->slot_width
) {
175 ret
= snd_soc_dai_set_tdm_slot(rtd
->cpu_dai
, 0x3, 0x3, 2,
176 cpu_priv
->slot_width
);
178 dev_err(dev
, "failed to set TDM slot for cpu dai\n");
186 static struct snd_soc_ops fsl_asoc_card_ops
= {
187 .hw_params
= fsl_asoc_card_hw_params
,
190 static int be_hw_params_fixup(struct snd_soc_pcm_runtime
*rtd
,
191 struct snd_pcm_hw_params
*params
)
193 struct fsl_asoc_card_priv
*priv
= snd_soc_card_get_drvdata(rtd
->card
);
194 struct snd_interval
*rate
;
195 struct snd_mask
*mask
;
197 rate
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
198 rate
->max
= rate
->min
= priv
->asrc_rate
;
200 mask
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
202 snd_mask_set(mask
, priv
->asrc_format
);
207 static struct snd_soc_dai_link fsl_asoc_card_dai
[] = {
208 /* Default ASoC DAI Link*/
211 .stream_name
= "HiFi",
212 .ops
= &fsl_asoc_card_ops
,
214 /* DPCM Link between Front-End and Back-End (Optional) */
216 .name
= "HiFi-ASRC-FE",
217 .stream_name
= "HiFi-ASRC-FE",
218 .codec_name
= "snd-soc-dummy",
219 .codec_dai_name
= "snd-soc-dummy-dai",
225 .name
= "HiFi-ASRC-BE",
226 .stream_name
= "HiFi-ASRC-BE",
227 .platform_name
= "snd-soc-dummy",
228 .be_hw_params_fixup
= be_hw_params_fixup
,
229 .ops
= &fsl_asoc_card_ops
,
236 static int fsl_asoc_card_set_bias_level(struct snd_soc_card
*card
,
237 struct snd_soc_dapm_context
*dapm
,
238 enum snd_soc_bias_level level
)
240 struct fsl_asoc_card_priv
*priv
= snd_soc_card_get_drvdata(card
);
241 struct snd_soc_pcm_runtime
*rtd
;
242 struct snd_soc_dai
*codec_dai
;
243 struct codec_priv
*codec_priv
= &priv
->codec_priv
;
244 struct device
*dev
= card
->dev
;
245 unsigned int pll_out
;
248 rtd
= snd_soc_get_pcm_runtime(card
, card
->dai_link
[0].name
);
249 codec_dai
= rtd
->codec_dai
;
250 if (dapm
->dev
!= codec_dai
->dev
)
254 case SND_SOC_BIAS_PREPARE
:
255 if (dapm
->bias_level
!= SND_SOC_BIAS_STANDBY
)
258 if (priv
->sample_format
== SNDRV_PCM_FORMAT_S24_LE
)
259 pll_out
= priv
->sample_rate
* 384;
261 pll_out
= priv
->sample_rate
* 256;
263 ret
= snd_soc_dai_set_pll(codec_dai
, codec_priv
->pll_id
,
265 codec_priv
->mclk_freq
, pll_out
);
267 dev_err(dev
, "failed to start FLL: %d\n", ret
);
271 ret
= snd_soc_dai_set_sysclk(codec_dai
, codec_priv
->fll_id
,
272 pll_out
, SND_SOC_CLOCK_IN
);
274 dev_err(dev
, "failed to set SYSCLK: %d\n", ret
);
279 case SND_SOC_BIAS_STANDBY
:
280 if (dapm
->bias_level
!= SND_SOC_BIAS_PREPARE
)
283 ret
= snd_soc_dai_set_sysclk(codec_dai
, codec_priv
->mclk_id
,
284 codec_priv
->mclk_freq
,
287 dev_err(dev
, "failed to switch away from FLL: %d\n", ret
);
291 ret
= snd_soc_dai_set_pll(codec_dai
, codec_priv
->pll_id
, 0, 0, 0);
293 dev_err(dev
, "failed to stop FLL: %d\n", ret
);
305 static int fsl_asoc_card_audmux_init(struct device_node
*np
,
306 struct fsl_asoc_card_priv
*priv
)
308 struct device
*dev
= &priv
->pdev
->dev
;
309 u32 int_ptcr
= 0, ext_ptcr
= 0;
310 int int_port
, ext_port
;
313 ret
= of_property_read_u32(np
, "mux-int-port", &int_port
);
315 dev_err(dev
, "mux-int-port missing or invalid\n");
318 ret
= of_property_read_u32(np
, "mux-ext-port", &ext_port
);
320 dev_err(dev
, "mux-ext-port missing or invalid\n");
325 * The port numbering in the hardware manual starts at 1, while
326 * the AUDMUX API expects it starts at 0.
332 * Use asynchronous mode (6 wires) for all cases except AC97.
333 * If only 4 wires are needed, just set SSI into
334 * synchronous mode and enable 4 PADs in IOMUX.
336 switch (priv
->dai_fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
337 case SND_SOC_DAIFMT_CBM_CFM
:
338 int_ptcr
= IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port
) |
339 IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port
) |
340 IMX_AUDMUX_V2_PTCR_TFSEL(ext_port
) |
341 IMX_AUDMUX_V2_PTCR_TCSEL(ext_port
) |
342 IMX_AUDMUX_V2_PTCR_RFSDIR
|
343 IMX_AUDMUX_V2_PTCR_RCLKDIR
|
344 IMX_AUDMUX_V2_PTCR_TFSDIR
|
345 IMX_AUDMUX_V2_PTCR_TCLKDIR
;
347 case SND_SOC_DAIFMT_CBM_CFS
:
348 int_ptcr
= IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port
) |
349 IMX_AUDMUX_V2_PTCR_TCSEL(ext_port
) |
350 IMX_AUDMUX_V2_PTCR_RCLKDIR
|
351 IMX_AUDMUX_V2_PTCR_TCLKDIR
;
352 ext_ptcr
= IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port
) |
353 IMX_AUDMUX_V2_PTCR_TFSEL(int_port
) |
354 IMX_AUDMUX_V2_PTCR_RFSDIR
|
355 IMX_AUDMUX_V2_PTCR_TFSDIR
;
357 case SND_SOC_DAIFMT_CBS_CFM
:
358 int_ptcr
= IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port
) |
359 IMX_AUDMUX_V2_PTCR_TFSEL(ext_port
) |
360 IMX_AUDMUX_V2_PTCR_RFSDIR
|
361 IMX_AUDMUX_V2_PTCR_TFSDIR
;
362 ext_ptcr
= IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port
) |
363 IMX_AUDMUX_V2_PTCR_TCSEL(int_port
) |
364 IMX_AUDMUX_V2_PTCR_RCLKDIR
|
365 IMX_AUDMUX_V2_PTCR_TCLKDIR
;
367 case SND_SOC_DAIFMT_CBS_CFS
:
368 ext_ptcr
= IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port
) |
369 IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port
) |
370 IMX_AUDMUX_V2_PTCR_TFSEL(int_port
) |
371 IMX_AUDMUX_V2_PTCR_TCSEL(int_port
) |
372 IMX_AUDMUX_V2_PTCR_RFSDIR
|
373 IMX_AUDMUX_V2_PTCR_RCLKDIR
|
374 IMX_AUDMUX_V2_PTCR_TFSDIR
|
375 IMX_AUDMUX_V2_PTCR_TCLKDIR
;
378 if (!fsl_asoc_card_is_ac97(priv
))
382 if (fsl_asoc_card_is_ac97(priv
)) {
383 int_ptcr
= IMX_AUDMUX_V2_PTCR_SYN
|
384 IMX_AUDMUX_V2_PTCR_TCSEL(ext_port
) |
385 IMX_AUDMUX_V2_PTCR_TCLKDIR
;
386 ext_ptcr
= IMX_AUDMUX_V2_PTCR_SYN
|
387 IMX_AUDMUX_V2_PTCR_TFSEL(int_port
) |
388 IMX_AUDMUX_V2_PTCR_TFSDIR
;
391 /* Asynchronous mode can not be set along with RCLKDIR */
392 if (!fsl_asoc_card_is_ac97(priv
)) {
394 IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port
);
396 ret
= imx_audmux_v2_configure_port(int_port
, 0,
399 dev_err(dev
, "audmux internal port setup failed\n");
404 ret
= imx_audmux_v2_configure_port(int_port
, int_ptcr
,
405 IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port
));
407 dev_err(dev
, "audmux internal port setup failed\n");
411 if (!fsl_asoc_card_is_ac97(priv
)) {
413 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port
);
415 ret
= imx_audmux_v2_configure_port(ext_port
, 0,
418 dev_err(dev
, "audmux external port setup failed\n");
423 ret
= imx_audmux_v2_configure_port(ext_port
, ext_ptcr
,
424 IMX_AUDMUX_V2_PDCR_RXDSEL(int_port
));
426 dev_err(dev
, "audmux external port setup failed\n");
433 static int fsl_asoc_card_late_probe(struct snd_soc_card
*card
)
435 struct fsl_asoc_card_priv
*priv
= snd_soc_card_get_drvdata(card
);
436 struct snd_soc_pcm_runtime
*rtd
= list_first_entry(
437 &card
->rtd_list
, struct snd_soc_pcm_runtime
, list
);
438 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
439 struct codec_priv
*codec_priv
= &priv
->codec_priv
;
440 struct device
*dev
= card
->dev
;
443 if (fsl_asoc_card_is_ac97(priv
)) {
444 #if IS_ENABLED(CONFIG_SND_AC97_CODEC)
445 struct snd_soc_codec
*codec
= rtd
->codec
;
446 struct snd_ac97
*ac97
= snd_soc_codec_get_drvdata(codec
);
449 * Use slots 3/4 for S/PDIF so SSI won't try to enable
450 * other slots and send some samples there
451 * due to SLOTREQ bits for S/PDIF received from codec
453 snd_ac97_update_bits(ac97
, AC97_EXTENDED_STATUS
,
454 AC97_EA_SPSA_SLOT_MASK
, AC97_EA_SPSA_3_4
);
460 ret
= snd_soc_dai_set_sysclk(codec_dai
, codec_priv
->mclk_id
,
461 codec_priv
->mclk_freq
, SND_SOC_CLOCK_IN
);
463 dev_err(dev
, "failed to set sysclk in %s\n", __func__
);
470 static int fsl_asoc_card_probe(struct platform_device
*pdev
)
472 struct device_node
*cpu_np
, *codec_np
, *asrc_np
;
473 struct device_node
*np
= pdev
->dev
.of_node
;
474 struct platform_device
*asrc_pdev
= NULL
;
475 struct platform_device
*cpu_pdev
;
476 struct fsl_asoc_card_priv
*priv
;
477 struct i2c_client
*codec_dev
;
478 const char *codec_dai_name
;
482 priv
= devm_kzalloc(&pdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
486 cpu_np
= of_parse_phandle(np
, "audio-cpu", 0);
487 /* Give a chance to old DT binding */
489 cpu_np
= of_parse_phandle(np
, "ssi-controller", 0);
491 dev_err(&pdev
->dev
, "CPU phandle missing or invalid\n");
496 cpu_pdev
= of_find_device_by_node(cpu_np
);
498 dev_err(&pdev
->dev
, "failed to find CPU DAI device\n");
503 codec_np
= of_parse_phandle(np
, "audio-codec", 0);
505 codec_dev
= of_find_i2c_device_by_node(codec_np
);
509 asrc_np
= of_parse_phandle(np
, "audio-asrc", 0);
511 asrc_pdev
= of_find_device_by_node(asrc_np
);
513 /* Get the MCLK rate only, and leave it controlled by CODEC drivers */
515 struct clk
*codec_clk
= clk_get(&codec_dev
->dev
, NULL
);
517 if (!IS_ERR(codec_clk
)) {
518 priv
->codec_priv
.mclk_freq
= clk_get_rate(codec_clk
);
523 /* Default sample rate and format, will be updated in hw_params() */
524 priv
->sample_rate
= 44100;
525 priv
->sample_format
= SNDRV_PCM_FORMAT_S16_LE
;
527 /* Assign a default DAI format, and allow each card to overwrite it */
528 priv
->dai_fmt
= DAI_FMT_BASE
;
530 /* Diversify the card configurations */
531 if (of_device_is_compatible(np
, "fsl,imx-audio-cs42888")) {
532 codec_dai_name
= "cs42888";
533 priv
->card
.set_bias_level
= NULL
;
534 priv
->cpu_priv
.sysclk_freq
[TX
] = priv
->codec_priv
.mclk_freq
;
535 priv
->cpu_priv
.sysclk_freq
[RX
] = priv
->codec_priv
.mclk_freq
;
536 priv
->cpu_priv
.sysclk_dir
[TX
] = SND_SOC_CLOCK_OUT
;
537 priv
->cpu_priv
.sysclk_dir
[RX
] = SND_SOC_CLOCK_OUT
;
538 priv
->cpu_priv
.slot_width
= 32;
539 priv
->dai_fmt
|= SND_SOC_DAIFMT_CBS_CFS
;
540 } else if (of_device_is_compatible(np
, "fsl,imx-audio-cs427x")) {
541 codec_dai_name
= "cs4271-hifi";
542 priv
->codec_priv
.mclk_id
= CS427x_SYSCLK_MCLK
;
543 priv
->dai_fmt
|= SND_SOC_DAIFMT_CBM_CFM
;
544 } else if (of_device_is_compatible(np
, "fsl,imx-audio-sgtl5000")) {
545 codec_dai_name
= "sgtl5000";
546 priv
->codec_priv
.mclk_id
= SGTL5000_SYSCLK
;
547 priv
->dai_fmt
|= SND_SOC_DAIFMT_CBM_CFM
;
548 } else if (of_device_is_compatible(np
, "fsl,imx-audio-wm8962")) {
549 codec_dai_name
= "wm8962";
550 priv
->card
.set_bias_level
= fsl_asoc_card_set_bias_level
;
551 priv
->codec_priv
.mclk_id
= WM8962_SYSCLK_MCLK
;
552 priv
->codec_priv
.fll_id
= WM8962_SYSCLK_FLL
;
553 priv
->codec_priv
.pll_id
= WM8962_FLL
;
554 priv
->dai_fmt
|= SND_SOC_DAIFMT_CBM_CFM
;
555 } else if (of_device_is_compatible(np
, "fsl,imx-audio-wm8960")) {
556 codec_dai_name
= "wm8960-hifi";
557 priv
->card
.set_bias_level
= fsl_asoc_card_set_bias_level
;
558 priv
->codec_priv
.fll_id
= WM8960_SYSCLK_AUTO
;
559 priv
->codec_priv
.pll_id
= WM8960_SYSCLK_AUTO
;
560 priv
->dai_fmt
|= SND_SOC_DAIFMT_CBM_CFM
;
561 } else if (of_device_is_compatible(np
, "fsl,imx-audio-ac97")) {
562 codec_dai_name
= "ac97-hifi";
563 priv
->card
.set_bias_level
= NULL
;
564 priv
->dai_fmt
= SND_SOC_DAIFMT_AC97
;
566 dev_err(&pdev
->dev
, "unknown Device Tree compatible\n");
571 if (!fsl_asoc_card_is_ac97(priv
) && !codec_dev
) {
572 dev_err(&pdev
->dev
, "failed to find codec device\n");
577 /* Common settings for corresponding Freescale CPU DAI driver */
578 if (strstr(cpu_np
->name
, "ssi")) {
579 /* Only SSI needs to configure AUDMUX */
580 ret
= fsl_asoc_card_audmux_init(np
, priv
);
582 dev_err(&pdev
->dev
, "failed to init audmux\n");
585 } else if (strstr(cpu_np
->name
, "esai")) {
586 priv
->cpu_priv
.sysclk_id
[1] = ESAI_HCKT_EXTAL
;
587 priv
->cpu_priv
.sysclk_id
[0] = ESAI_HCKR_EXTAL
;
588 } else if (strstr(cpu_np
->name
, "sai")) {
589 priv
->cpu_priv
.sysclk_id
[1] = FSL_SAI_CLK_MAST1
;
590 priv
->cpu_priv
.sysclk_id
[0] = FSL_SAI_CLK_MAST1
;
593 snprintf(priv
->name
, sizeof(priv
->name
), "%s-audio",
594 fsl_asoc_card_is_ac97(priv
) ? "ac97" :
597 /* Initialize sound card */
599 priv
->card
.dev
= &pdev
->dev
;
600 priv
->card
.name
= priv
->name
;
601 priv
->card
.dai_link
= priv
->dai_link
;
602 priv
->card
.dapm_routes
= fsl_asoc_card_is_ac97(priv
) ?
603 audio_map_ac97
: audio_map
;
604 priv
->card
.late_probe
= fsl_asoc_card_late_probe
;
605 priv
->card
.num_dapm_routes
= ARRAY_SIZE(audio_map
);
606 priv
->card
.dapm_widgets
= fsl_asoc_card_dapm_widgets
;
607 priv
->card
.num_dapm_widgets
= ARRAY_SIZE(fsl_asoc_card_dapm_widgets
);
609 /* Drop the second half of DAPM routes -- ASRC */
611 priv
->card
.num_dapm_routes
/= 2;
613 memcpy(priv
->dai_link
, fsl_asoc_card_dai
,
614 sizeof(struct snd_soc_dai_link
) * ARRAY_SIZE(priv
->dai_link
));
616 ret
= snd_soc_of_parse_audio_routing(&priv
->card
, "audio-routing");
618 dev_err(&pdev
->dev
, "failed to parse audio-routing: %d\n", ret
);
622 /* Normal DAI Link */
623 priv
->dai_link
[0].cpu_of_node
= cpu_np
;
624 priv
->dai_link
[0].codec_dai_name
= codec_dai_name
;
626 if (!fsl_asoc_card_is_ac97(priv
))
627 priv
->dai_link
[0].codec_of_node
= codec_np
;
631 ret
= of_property_read_u32(cpu_np
, "cell-index", &idx
);
634 "cannot get CPU index property\n");
638 priv
->dai_link
[0].codec_name
=
639 devm_kasprintf(&pdev
->dev
, GFP_KERNEL
,
644 priv
->dai_link
[0].platform_of_node
= cpu_np
;
645 priv
->dai_link
[0].dai_fmt
= priv
->dai_fmt
;
646 priv
->card
.num_links
= 1;
649 /* DPCM DAI Links only if ASRC exsits */
650 priv
->dai_link
[1].cpu_of_node
= asrc_np
;
651 priv
->dai_link
[1].platform_of_node
= asrc_np
;
652 priv
->dai_link
[2].codec_dai_name
= codec_dai_name
;
653 priv
->dai_link
[2].codec_of_node
= codec_np
;
654 priv
->dai_link
[2].codec_name
=
655 priv
->dai_link
[0].codec_name
;
656 priv
->dai_link
[2].cpu_of_node
= cpu_np
;
657 priv
->dai_link
[2].dai_fmt
= priv
->dai_fmt
;
658 priv
->card
.num_links
= 3;
660 ret
= of_property_read_u32(asrc_np
, "fsl,asrc-rate",
663 dev_err(&pdev
->dev
, "failed to get output rate\n");
668 ret
= of_property_read_u32(asrc_np
, "fsl,asrc-width", &width
);
670 dev_err(&pdev
->dev
, "failed to get output rate\n");
676 priv
->asrc_format
= SNDRV_PCM_FORMAT_S24_LE
;
678 priv
->asrc_format
= SNDRV_PCM_FORMAT_S16_LE
;
681 /* Finish card registering */
682 platform_set_drvdata(pdev
, priv
);
683 snd_soc_card_set_drvdata(&priv
->card
, priv
);
685 ret
= devm_snd_soc_register_card(&pdev
->dev
, &priv
->card
);
687 dev_err(&pdev
->dev
, "snd_soc_register_card failed (%d)\n", ret
);
690 of_node_put(asrc_np
);
691 of_node_put(codec_np
);
698 static const struct of_device_id fsl_asoc_card_dt_ids
[] = {
699 { .compatible
= "fsl,imx-audio-ac97", },
700 { .compatible
= "fsl,imx-audio-cs42888", },
701 { .compatible
= "fsl,imx-audio-cs427x", },
702 { .compatible
= "fsl,imx-audio-sgtl5000", },
703 { .compatible
= "fsl,imx-audio-wm8962", },
704 { .compatible
= "fsl,imx-audio-wm8960", },
707 MODULE_DEVICE_TABLE(of
, fsl_asoc_card_dt_ids
);
709 static struct platform_driver fsl_asoc_card_driver
= {
710 .probe
= fsl_asoc_card_probe
,
712 .name
= "fsl-asoc-card",
713 .pm
= &snd_soc_pm_ops
,
714 .of_match_table
= fsl_asoc_card_dt_ids
,
717 module_platform_driver(fsl_asoc_card_driver
);
719 MODULE_DESCRIPTION("Freescale Generic ASoC Sound Card driver with ASRC");
720 MODULE_AUTHOR("Nicolin Chen <nicoleotsuka@gmail.com>");
721 MODULE_ALIAS("platform:fsl-asoc-card");
722 MODULE_LICENSE("GPL");