xref: /openbmc/linux/sound/soc/fsl/fsl-asoc-card.c (revision 0da85d1e)
1 /*
2  * Freescale Generic ASoC Sound Card driver with ASRC
3  *
4  * Copyright (C) 2014 Freescale Semiconductor, Inc.
5  *
6  * Author: Nicolin Chen <nicoleotsuka@gmail.com>
7  *
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.
11  */
12 
13 #include <linux/clk.h>
14 #include <linux/i2c.h>
15 #include <linux/module.h>
16 #include <linux/of_platform.h>
17 #include <sound/pcm_params.h>
18 #include <sound/soc.h>
19 
20 #include "fsl_esai.h"
21 #include "fsl_sai.h"
22 #include "imx-audmux.h"
23 
24 #include "../codecs/sgtl5000.h"
25 #include "../codecs/wm8962.h"
26 
27 #define RX 0
28 #define TX 1
29 
30 /* Default DAI format without Master and Slave flag */
31 #define DAI_FMT_BASE (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF)
32 
33 /**
34  * CODEC private data
35  *
36  * @mclk_freq: Clock rate of MCLK
37  * @mclk_id: MCLK (or main clock) id for set_sysclk()
38  * @fll_id: FLL (or secordary clock) id for set_sysclk()
39  * @pll_id: PLL id for set_pll()
40  */
41 struct codec_priv {
42 	unsigned long mclk_freq;
43 	u32 mclk_id;
44 	u32 fll_id;
45 	u32 pll_id;
46 };
47 
48 /**
49  * CPU private data
50  *
51  * @sysclk_freq[2]: SYSCLK rates for set_sysclk()
52  * @sysclk_dir[2]: SYSCLK directions for set_sysclk()
53  * @sysclk_id[2]: SYSCLK ids for set_sysclk()
54  * @slot_width: Slot width of each frame
55  *
56  * Note: [1] for tx and [0] for rx
57  */
58 struct cpu_priv {
59 	unsigned long sysclk_freq[2];
60 	u32 sysclk_dir[2];
61 	u32 sysclk_id[2];
62 	u32 slot_width;
63 };
64 
65 /**
66  * Freescale Generic ASOC card private data
67  *
68  * @dai_link[3]: DAI link structure including normal one and DPCM link
69  * @pdev: platform device pointer
70  * @codec_priv: CODEC private data
71  * @cpu_priv: CPU private data
72  * @card: ASoC card structure
73  * @sample_rate: Current sample rate
74  * @sample_format: Current sample format
75  * @asrc_rate: ASRC sample rate used by Back-Ends
76  * @asrc_format: ASRC sample format used by Back-Ends
77  * @dai_fmt: DAI format between CPU and CODEC
78  * @name: Card name
79  */
80 
81 struct fsl_asoc_card_priv {
82 	struct snd_soc_dai_link dai_link[3];
83 	struct platform_device *pdev;
84 	struct codec_priv codec_priv;
85 	struct cpu_priv cpu_priv;
86 	struct snd_soc_card card;
87 	u32 sample_rate;
88 	u32 sample_format;
89 	u32 asrc_rate;
90 	u32 asrc_format;
91 	u32 dai_fmt;
92 	char name[32];
93 };
94 
95 /**
96  * This dapm route map exsits for DPCM link only.
97  * The other routes shall go through Device Tree.
98  */
99 static const struct snd_soc_dapm_route audio_map[] = {
100 	{"CPU-Playback",  NULL, "ASRC-Playback"},
101 	{"Playback",  NULL, "CPU-Playback"},
102 	{"ASRC-Capture",  NULL, "CPU-Capture"},
103 	{"CPU-Capture",  NULL, "Capture"},
104 };
105 
106 /* Add all possible widgets into here without being redundant */
107 static const struct snd_soc_dapm_widget fsl_asoc_card_dapm_widgets[] = {
108 	SND_SOC_DAPM_LINE("Line Out Jack", NULL),
109 	SND_SOC_DAPM_LINE("Line In Jack", NULL),
110 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
111 	SND_SOC_DAPM_SPK("Ext Spk", NULL),
112 	SND_SOC_DAPM_MIC("Mic Jack", NULL),
113 	SND_SOC_DAPM_MIC("AMIC", NULL),
114 	SND_SOC_DAPM_MIC("DMIC", NULL),
115 };
116 
117 static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream,
118 				   struct snd_pcm_hw_params *params)
119 {
120 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
121 	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
122 	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
123 	struct cpu_priv *cpu_priv = &priv->cpu_priv;
124 	struct device *dev = rtd->card->dev;
125 	int ret;
126 
127 	priv->sample_rate = params_rate(params);
128 	priv->sample_format = params_format(params);
129 
130 	/*
131 	 * If codec-dai is DAI Master and all configurations are already in the
132 	 * set_bias_level(), bypass the remaining settings in hw_params().
133 	 * Note: (dai_fmt & CBM_CFM) includes CBM_CFM and CBM_CFS.
134 	 */
135 	if (priv->card.set_bias_level && priv->dai_fmt & SND_SOC_DAIFMT_CBM_CFM)
136 		return 0;
137 
138 	/* Specific configurations of DAIs starts from here */
139 	ret = snd_soc_dai_set_sysclk(rtd->cpu_dai, cpu_priv->sysclk_id[tx],
140 				     cpu_priv->sysclk_freq[tx],
141 				     cpu_priv->sysclk_dir[tx]);
142 	if (ret) {
143 		dev_err(dev, "failed to set sysclk for cpu dai\n");
144 		return ret;
145 	}
146 
147 	if (cpu_priv->slot_width) {
148 		ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2,
149 					       cpu_priv->slot_width);
150 		if (ret) {
151 			dev_err(dev, "failed to set TDM slot for cpu dai\n");
152 			return ret;
153 		}
154 	}
155 
156 	return 0;
157 }
158 
159 static struct snd_soc_ops fsl_asoc_card_ops = {
160 	.hw_params = fsl_asoc_card_hw_params,
161 };
162 
163 static int be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
164 			      struct snd_pcm_hw_params *params)
165 {
166 	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
167 	struct snd_interval *rate;
168 	struct snd_mask *mask;
169 
170 	rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
171 	rate->max = rate->min = priv->asrc_rate;
172 
173 	mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
174 	snd_mask_none(mask);
175 	snd_mask_set(mask, priv->asrc_format);
176 
177 	return 0;
178 }
179 
180 static struct snd_soc_dai_link fsl_asoc_card_dai[] = {
181 	/* Default ASoC DAI Link*/
182 	{
183 		.name = "HiFi",
184 		.stream_name = "HiFi",
185 		.ops = &fsl_asoc_card_ops,
186 	},
187 	/* DPCM Link between Front-End and Back-End (Optional) */
188 	{
189 		.name = "HiFi-ASRC-FE",
190 		.stream_name = "HiFi-ASRC-FE",
191 		.codec_name = "snd-soc-dummy",
192 		.codec_dai_name = "snd-soc-dummy-dai",
193 		.dpcm_playback = 1,
194 		.dpcm_capture = 1,
195 		.dynamic = 1,
196 	},
197 	{
198 		.name = "HiFi-ASRC-BE",
199 		.stream_name = "HiFi-ASRC-BE",
200 		.platform_name = "snd-soc-dummy",
201 		.be_hw_params_fixup = be_hw_params_fixup,
202 		.ops = &fsl_asoc_card_ops,
203 		.dpcm_playback = 1,
204 		.dpcm_capture = 1,
205 		.no_pcm = 1,
206 	},
207 };
208 
209 static int fsl_asoc_card_set_bias_level(struct snd_soc_card *card,
210 					struct snd_soc_dapm_context *dapm,
211 					enum snd_soc_bias_level level)
212 {
213 	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card);
214 	struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
215 	struct codec_priv *codec_priv = &priv->codec_priv;
216 	struct device *dev = card->dev;
217 	unsigned int pll_out;
218 	int ret;
219 
220 	if (dapm->dev != codec_dai->dev)
221 		return 0;
222 
223 	switch (level) {
224 	case SND_SOC_BIAS_PREPARE:
225 		if (dapm->bias_level != SND_SOC_BIAS_STANDBY)
226 			break;
227 
228 		if (priv->sample_format == SNDRV_PCM_FORMAT_S24_LE)
229 			pll_out = priv->sample_rate * 384;
230 		else
231 			pll_out = priv->sample_rate * 256;
232 
233 		ret = snd_soc_dai_set_pll(codec_dai, codec_priv->pll_id,
234 					  codec_priv->mclk_id,
235 					  codec_priv->mclk_freq, pll_out);
236 		if (ret) {
237 			dev_err(dev, "failed to start FLL: %d\n", ret);
238 			return ret;
239 		}
240 
241 		ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->fll_id,
242 					     pll_out, SND_SOC_CLOCK_IN);
243 		if (ret) {
244 			dev_err(dev, "failed to set SYSCLK: %d\n", ret);
245 			return ret;
246 		}
247 		break;
248 
249 	case SND_SOC_BIAS_STANDBY:
250 		if (dapm->bias_level != SND_SOC_BIAS_PREPARE)
251 			break;
252 
253 		ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
254 					     codec_priv->mclk_freq,
255 					     SND_SOC_CLOCK_IN);
256 		if (ret) {
257 			dev_err(dev, "failed to switch away from FLL: %d\n", ret);
258 			return ret;
259 		}
260 
261 		ret = snd_soc_dai_set_pll(codec_dai, codec_priv->pll_id, 0, 0, 0);
262 		if (ret) {
263 			dev_err(dev, "failed to stop FLL: %d\n", ret);
264 			return ret;
265 		}
266 		break;
267 
268 	default:
269 		break;
270 	}
271 
272 	return 0;
273 }
274 
275 static int fsl_asoc_card_audmux_init(struct device_node *np,
276 				     struct fsl_asoc_card_priv *priv)
277 {
278 	struct device *dev = &priv->pdev->dev;
279 	u32 int_ptcr = 0, ext_ptcr = 0;
280 	int int_port, ext_port;
281 	int ret;
282 
283 	ret = of_property_read_u32(np, "mux-int-port", &int_port);
284 	if (ret) {
285 		dev_err(dev, "mux-int-port missing or invalid\n");
286 		return ret;
287 	}
288 	ret = of_property_read_u32(np, "mux-ext-port", &ext_port);
289 	if (ret) {
290 		dev_err(dev, "mux-ext-port missing or invalid\n");
291 		return ret;
292 	}
293 
294 	/*
295 	 * The port numbering in the hardware manual starts at 1, while
296 	 * the AUDMUX API expects it starts at 0.
297 	 */
298 	int_port--;
299 	ext_port--;
300 
301 	/*
302 	 * Use asynchronous mode (6 wires) for all cases.
303 	 * If only 4 wires are needed, just set SSI into
304 	 * synchronous mode and enable 4 PADs in IOMUX.
305 	 */
306 	switch (priv->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
307 	case SND_SOC_DAIFMT_CBM_CFM:
308 		int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
309 			   IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
310 			   IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
311 			   IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
312 			   IMX_AUDMUX_V2_PTCR_RFSDIR |
313 			   IMX_AUDMUX_V2_PTCR_RCLKDIR |
314 			   IMX_AUDMUX_V2_PTCR_TFSDIR |
315 			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
316 		break;
317 	case SND_SOC_DAIFMT_CBM_CFS:
318 		int_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
319 			   IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
320 			   IMX_AUDMUX_V2_PTCR_RCLKDIR |
321 			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
322 		ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
323 			   IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
324 			   IMX_AUDMUX_V2_PTCR_RFSDIR |
325 			   IMX_AUDMUX_V2_PTCR_TFSDIR;
326 		break;
327 	case SND_SOC_DAIFMT_CBS_CFM:
328 		int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
329 			   IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
330 			   IMX_AUDMUX_V2_PTCR_RFSDIR |
331 			   IMX_AUDMUX_V2_PTCR_TFSDIR;
332 		ext_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
333 			   IMX_AUDMUX_V2_PTCR_TCSEL(int_port) |
334 			   IMX_AUDMUX_V2_PTCR_RCLKDIR |
335 			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
336 		break;
337 	case SND_SOC_DAIFMT_CBS_CFS:
338 		ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
339 			   IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
340 			   IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
341 			   IMX_AUDMUX_V2_PTCR_TCSEL(int_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;
346 		break;
347 	default:
348 		return -EINVAL;
349 	}
350 
351 	/* Asynchronous mode can not be set along with RCLKDIR */
352 	ret = imx_audmux_v2_configure_port(int_port, 0,
353 					   IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port));
354 	if (ret) {
355 		dev_err(dev, "audmux internal port setup failed\n");
356 		return ret;
357 	}
358 
359 	ret = imx_audmux_v2_configure_port(int_port, int_ptcr,
360 					   IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port));
361 	if (ret) {
362 		dev_err(dev, "audmux internal port setup failed\n");
363 		return ret;
364 	}
365 
366 	ret = imx_audmux_v2_configure_port(ext_port, 0,
367 					   IMX_AUDMUX_V2_PDCR_RXDSEL(int_port));
368 	if (ret) {
369 		dev_err(dev, "audmux external port setup failed\n");
370 		return ret;
371 	}
372 
373 	ret = imx_audmux_v2_configure_port(ext_port, ext_ptcr,
374 					   IMX_AUDMUX_V2_PDCR_RXDSEL(int_port));
375 	if (ret) {
376 		dev_err(dev, "audmux external port setup failed\n");
377 		return ret;
378 	}
379 
380 	return 0;
381 }
382 
383 static int fsl_asoc_card_late_probe(struct snd_soc_card *card)
384 {
385 	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card);
386 	struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
387 	struct codec_priv *codec_priv = &priv->codec_priv;
388 	struct device *dev = card->dev;
389 	int ret;
390 
391 	ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
392 				     codec_priv->mclk_freq, SND_SOC_CLOCK_IN);
393 	if (ret) {
394 		dev_err(dev, "failed to set sysclk in %s\n", __func__);
395 		return ret;
396 	}
397 
398 	return 0;
399 }
400 
401 static int fsl_asoc_card_probe(struct platform_device *pdev)
402 {
403 	struct device_node *cpu_np, *codec_np, *asrc_np;
404 	struct device_node *np = pdev->dev.of_node;
405 	struct platform_device *asrc_pdev = NULL;
406 	struct platform_device *cpu_pdev;
407 	struct fsl_asoc_card_priv *priv;
408 	struct i2c_client *codec_dev;
409 	struct clk *codec_clk;
410 	u32 width;
411 	int ret;
412 
413 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
414 	if (!priv)
415 		return -ENOMEM;
416 
417 	cpu_np = of_parse_phandle(np, "audio-cpu", 0);
418 	/* Give a chance to old DT binding */
419 	if (!cpu_np)
420 		cpu_np = of_parse_phandle(np, "ssi-controller", 0);
421 	codec_np = of_parse_phandle(np, "audio-codec", 0);
422 	if (!cpu_np || !codec_np) {
423 		dev_err(&pdev->dev, "phandle missing or invalid\n");
424 		ret = -EINVAL;
425 		goto fail;
426 	}
427 
428 	cpu_pdev = of_find_device_by_node(cpu_np);
429 	if (!cpu_pdev) {
430 		dev_err(&pdev->dev, "failed to find CPU DAI device\n");
431 		ret = -EINVAL;
432 		goto fail;
433 	}
434 
435 	codec_dev = of_find_i2c_device_by_node(codec_np);
436 	if (!codec_dev) {
437 		dev_err(&pdev->dev, "failed to find codec platform device\n");
438 		ret = -EINVAL;
439 		goto fail;
440 	}
441 
442 	asrc_np = of_parse_phandle(np, "audio-asrc", 0);
443 	if (asrc_np)
444 		asrc_pdev = of_find_device_by_node(asrc_np);
445 
446 	/* Get the MCLK rate only, and leave it controlled by CODEC drivers */
447 	codec_clk = clk_get(&codec_dev->dev, NULL);
448 	if (!IS_ERR(codec_clk)) {
449 		priv->codec_priv.mclk_freq = clk_get_rate(codec_clk);
450 		clk_put(codec_clk);
451 	}
452 
453 	/* Default sample rate and format, will be updated in hw_params() */
454 	priv->sample_rate = 44100;
455 	priv->sample_format = SNDRV_PCM_FORMAT_S16_LE;
456 
457 	/* Assign a default DAI format, and allow each card to overwrite it */
458 	priv->dai_fmt = DAI_FMT_BASE;
459 
460 	/* Diversify the card configurations */
461 	if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) {
462 		priv->card.set_bias_level = NULL;
463 		priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv.mclk_freq;
464 		priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv.mclk_freq;
465 		priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
466 		priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT;
467 		priv->cpu_priv.slot_width = 32;
468 		priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
469 	} else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) {
470 		priv->codec_priv.mclk_id = SGTL5000_SYSCLK;
471 		priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
472 	} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) {
473 		priv->card.set_bias_level = fsl_asoc_card_set_bias_level;
474 		priv->codec_priv.mclk_id = WM8962_SYSCLK_MCLK;
475 		priv->codec_priv.fll_id = WM8962_SYSCLK_FLL;
476 		priv->codec_priv.pll_id = WM8962_FLL;
477 		priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
478 	} else {
479 		dev_err(&pdev->dev, "unknown Device Tree compatible\n");
480 		return -EINVAL;
481 	}
482 
483 	/* Common settings for corresponding Freescale CPU DAI driver */
484 	if (strstr(cpu_np->name, "ssi")) {
485 		/* Only SSI needs to configure AUDMUX */
486 		ret = fsl_asoc_card_audmux_init(np, priv);
487 		if (ret) {
488 			dev_err(&pdev->dev, "failed to init audmux\n");
489 			goto asrc_fail;
490 		}
491 	} else if (strstr(cpu_np->name, "esai")) {
492 		priv->cpu_priv.sysclk_id[1] = ESAI_HCKT_EXTAL;
493 		priv->cpu_priv.sysclk_id[0] = ESAI_HCKR_EXTAL;
494 	} else if (strstr(cpu_np->name, "sai")) {
495 		priv->cpu_priv.sysclk_id[1] = FSL_SAI_CLK_MAST1;
496 		priv->cpu_priv.sysclk_id[0] = FSL_SAI_CLK_MAST1;
497 	}
498 
499 	sprintf(priv->name, "%s-audio", codec_dev->name);
500 
501 	/* Initialize sound card */
502 	priv->pdev = pdev;
503 	priv->card.dev = &pdev->dev;
504 	priv->card.name = priv->name;
505 	priv->card.dai_link = priv->dai_link;
506 	priv->card.dapm_routes = audio_map;
507 	priv->card.late_probe = fsl_asoc_card_late_probe;
508 	priv->card.num_dapm_routes = ARRAY_SIZE(audio_map);
509 	priv->card.dapm_widgets = fsl_asoc_card_dapm_widgets;
510 	priv->card.num_dapm_widgets = ARRAY_SIZE(fsl_asoc_card_dapm_widgets);
511 
512 	memcpy(priv->dai_link, fsl_asoc_card_dai,
513 	       sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link));
514 
515 	ret = snd_soc_of_parse_audio_routing(&priv->card, "audio-routing");
516 	if (ret) {
517 		dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret);
518 		goto asrc_fail;
519 	}
520 
521 	/* Normal DAI Link */
522 	priv->dai_link[0].cpu_of_node = cpu_np;
523 	priv->dai_link[0].codec_of_node = codec_np;
524 	priv->dai_link[0].codec_dai_name = codec_dev->name;
525 	priv->dai_link[0].platform_of_node = cpu_np;
526 	priv->dai_link[0].dai_fmt = priv->dai_fmt;
527 	priv->card.num_links = 1;
528 
529 	if (asrc_pdev) {
530 		/* DPCM DAI Links only if ASRC exsits */
531 		priv->dai_link[1].cpu_of_node = asrc_np;
532 		priv->dai_link[1].platform_of_node = asrc_np;
533 		priv->dai_link[2].codec_dai_name = codec_dev->name;
534 		priv->dai_link[2].codec_of_node = codec_np;
535 		priv->dai_link[2].cpu_of_node = cpu_np;
536 		priv->dai_link[2].dai_fmt = priv->dai_fmt;
537 		priv->card.num_links = 3;
538 
539 		ret = of_property_read_u32(asrc_np, "fsl,asrc-rate",
540 					   &priv->asrc_rate);
541 		if (ret) {
542 			dev_err(&pdev->dev, "failed to get output rate\n");
543 			ret = -EINVAL;
544 			goto asrc_fail;
545 		}
546 
547 		ret = of_property_read_u32(asrc_np, "fsl,asrc-width", &width);
548 		if (ret) {
549 			dev_err(&pdev->dev, "failed to get output rate\n");
550 			ret = -EINVAL;
551 			goto asrc_fail;
552 		}
553 
554 		if (width == 24)
555 			priv->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
556 		else
557 			priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE;
558 	}
559 
560 	/* Finish card registering */
561 	platform_set_drvdata(pdev, priv);
562 	snd_soc_card_set_drvdata(&priv->card, priv);
563 
564 	ret = devm_snd_soc_register_card(&pdev->dev, &priv->card);
565 	if (ret)
566 		dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
567 
568 asrc_fail:
569 	of_node_put(asrc_np);
570 fail:
571 	of_node_put(codec_np);
572 	of_node_put(cpu_np);
573 
574 	return ret;
575 }
576 
577 static const struct of_device_id fsl_asoc_card_dt_ids[] = {
578 	{ .compatible = "fsl,imx-audio-cs42888", },
579 	{ .compatible = "fsl,imx-audio-sgtl5000", },
580 	{ .compatible = "fsl,imx-audio-wm8962", },
581 	{}
582 };
583 
584 static struct platform_driver fsl_asoc_card_driver = {
585 	.probe = fsl_asoc_card_probe,
586 	.driver = {
587 		.name = "fsl-asoc-card",
588 		.pm = &snd_soc_pm_ops,
589 		.of_match_table = fsl_asoc_card_dt_ids,
590 	},
591 };
592 module_platform_driver(fsl_asoc_card_driver);
593 
594 MODULE_DESCRIPTION("Freescale Generic ASoC Sound Card driver with ASRC");
595 MODULE_AUTHOR("Nicolin Chen <nicoleotsuka@gmail.com>");
596 MODULE_ALIAS("platform:fsl-asoc-card");
597 MODULE_LICENSE("GPL");
598