blob: 040362fa1124ff5deb4f6311d69345676d0be236 [file] [log] [blame]
Nicolin Chen708b4352014-07-30 19:27:38 +08001/*
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 */
41struct 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()
Nicolin Chencb3fc1f2014-10-24 16:48:13 -070054 * @slot_width: Slot width of each frame
Nicolin Chen708b4352014-07-30 19:27:38 +080055 *
56 * Note: [1] for tx and [0] for rx
57 */
58struct cpu_priv {
59 unsigned long sysclk_freq[2];
60 u32 sysclk_dir[2];
61 u32 sysclk_id[2];
Nicolin Chencb3fc1f2014-10-24 16:48:13 -070062 u32 slot_width;
Nicolin Chen708b4352014-07-30 19:27:38 +080063};
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
81struct 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 */
99static 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 */
107static 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
117static 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
Nicolin Chen41282922014-10-24 16:48:11 -0700130 /*
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)
Nicolin Chen708b4352014-07-30 19:27:38 +0800136 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
Nicolin Chencb3fc1f2014-10-24 16:48:13 -0700147 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
Nicolin Chen708b4352014-07-30 19:27:38 +0800156 return 0;
157}
158
159static struct snd_soc_ops fsl_asoc_card_ops = {
160 .hw_params = fsl_asoc_card_hw_params,
161};
162
163static 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
180static 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
209static 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
275static 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
383static 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
401static 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;
Nicolin Chen114bb132015-08-12 13:06:12 -0700410 const char *codec_dai_name;
Nicolin Chen708b4352014-07-30 19:27:38 +0800411 u32 width;
412 int ret;
413
414 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
415 if (!priv)
416 return -ENOMEM;
417
418 cpu_np = of_parse_phandle(np, "audio-cpu", 0);
419 /* Give a chance to old DT binding */
420 if (!cpu_np)
421 cpu_np = of_parse_phandle(np, "ssi-controller", 0);
422 codec_np = of_parse_phandle(np, "audio-codec", 0);
423 if (!cpu_np || !codec_np) {
424 dev_err(&pdev->dev, "phandle missing or invalid\n");
425 ret = -EINVAL;
426 goto fail;
427 }
428
429 cpu_pdev = of_find_device_by_node(cpu_np);
430 if (!cpu_pdev) {
431 dev_err(&pdev->dev, "failed to find CPU DAI device\n");
432 ret = -EINVAL;
433 goto fail;
434 }
435
436 codec_dev = of_find_i2c_device_by_node(codec_np);
437 if (!codec_dev) {
438 dev_err(&pdev->dev, "failed to find codec platform device\n");
439 ret = -EINVAL;
440 goto fail;
441 }
442
443 asrc_np = of_parse_phandle(np, "audio-asrc", 0);
444 if (asrc_np)
445 asrc_pdev = of_find_device_by_node(asrc_np);
446
447 /* Get the MCLK rate only, and leave it controlled by CODEC drivers */
448 codec_clk = clk_get(&codec_dev->dev, NULL);
449 if (!IS_ERR(codec_clk)) {
450 priv->codec_priv.mclk_freq = clk_get_rate(codec_clk);
451 clk_put(codec_clk);
452 }
453
454 /* Default sample rate and format, will be updated in hw_params() */
455 priv->sample_rate = 44100;
456 priv->sample_format = SNDRV_PCM_FORMAT_S16_LE;
457
458 /* Assign a default DAI format, and allow each card to overwrite it */
459 priv->dai_fmt = DAI_FMT_BASE;
460
461 /* Diversify the card configurations */
462 if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) {
Nicolin Chen114bb132015-08-12 13:06:12 -0700463 codec_dai_name = "cs42888";
Nicolin Chen708b4352014-07-30 19:27:38 +0800464 priv->card.set_bias_level = NULL;
465 priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv.mclk_freq;
466 priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv.mclk_freq;
467 priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
468 priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT;
Nicolin Chencb3fc1f2014-10-24 16:48:13 -0700469 priv->cpu_priv.slot_width = 32;
Nicolin Chen708b4352014-07-30 19:27:38 +0800470 priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
471 } else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) {
Nicolin Chen114bb132015-08-12 13:06:12 -0700472 codec_dai_name = "sgtl5000";
Nicolin Chen708b4352014-07-30 19:27:38 +0800473 priv->codec_priv.mclk_id = SGTL5000_SYSCLK;
474 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
475 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) {
Nicolin Chen114bb132015-08-12 13:06:12 -0700476 codec_dai_name = "wm8962";
Nicolin Chen708b4352014-07-30 19:27:38 +0800477 priv->card.set_bias_level = fsl_asoc_card_set_bias_level;
478 priv->codec_priv.mclk_id = WM8962_SYSCLK_MCLK;
479 priv->codec_priv.fll_id = WM8962_SYSCLK_FLL;
480 priv->codec_priv.pll_id = WM8962_FLL;
481 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
482 } else {
483 dev_err(&pdev->dev, "unknown Device Tree compatible\n");
484 return -EINVAL;
485 }
486
487 /* Common settings for corresponding Freescale CPU DAI driver */
488 if (strstr(cpu_np->name, "ssi")) {
489 /* Only SSI needs to configure AUDMUX */
490 ret = fsl_asoc_card_audmux_init(np, priv);
491 if (ret) {
492 dev_err(&pdev->dev, "failed to init audmux\n");
Shengjiu Wang5f376712014-08-18 16:38:39 +0800493 goto asrc_fail;
Nicolin Chen708b4352014-07-30 19:27:38 +0800494 }
495 } else if (strstr(cpu_np->name, "esai")) {
496 priv->cpu_priv.sysclk_id[1] = ESAI_HCKT_EXTAL;
497 priv->cpu_priv.sysclk_id[0] = ESAI_HCKR_EXTAL;
498 } else if (strstr(cpu_np->name, "sai")) {
499 priv->cpu_priv.sysclk_id[1] = FSL_SAI_CLK_MAST1;
500 priv->cpu_priv.sysclk_id[0] = FSL_SAI_CLK_MAST1;
501 }
502
503 sprintf(priv->name, "%s-audio", codec_dev->name);
504
505 /* Initialize sound card */
506 priv->pdev = pdev;
507 priv->card.dev = &pdev->dev;
508 priv->card.name = priv->name;
509 priv->card.dai_link = priv->dai_link;
510 priv->card.dapm_routes = audio_map;
511 priv->card.late_probe = fsl_asoc_card_late_probe;
512 priv->card.num_dapm_routes = ARRAY_SIZE(audio_map);
513 priv->card.dapm_widgets = fsl_asoc_card_dapm_widgets;
514 priv->card.num_dapm_widgets = ARRAY_SIZE(fsl_asoc_card_dapm_widgets);
515
516 memcpy(priv->dai_link, fsl_asoc_card_dai,
517 sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link));
518
Nicolin Chen31858782015-02-14 17:22:50 -0800519 ret = snd_soc_of_parse_audio_routing(&priv->card, "audio-routing");
520 if (ret) {
521 dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret);
522 goto asrc_fail;
523 }
524
Nicolin Chen708b4352014-07-30 19:27:38 +0800525 /* Normal DAI Link */
526 priv->dai_link[0].cpu_of_node = cpu_np;
527 priv->dai_link[0].codec_of_node = codec_np;
Nicolin Chen114bb132015-08-12 13:06:12 -0700528 priv->dai_link[0].codec_dai_name = codec_dai_name;
Nicolin Chen708b4352014-07-30 19:27:38 +0800529 priv->dai_link[0].platform_of_node = cpu_np;
530 priv->dai_link[0].dai_fmt = priv->dai_fmt;
531 priv->card.num_links = 1;
532
533 if (asrc_pdev) {
534 /* DPCM DAI Links only if ASRC exsits */
535 priv->dai_link[1].cpu_of_node = asrc_np;
536 priv->dai_link[1].platform_of_node = asrc_np;
Nicolin Chen114bb132015-08-12 13:06:12 -0700537 priv->dai_link[2].codec_dai_name = codec_dai_name;
Nicolin Chen708b4352014-07-30 19:27:38 +0800538 priv->dai_link[2].codec_of_node = codec_np;
539 priv->dai_link[2].cpu_of_node = cpu_np;
540 priv->dai_link[2].dai_fmt = priv->dai_fmt;
541 priv->card.num_links = 3;
542
543 ret = of_property_read_u32(asrc_np, "fsl,asrc-rate",
544 &priv->asrc_rate);
545 if (ret) {
546 dev_err(&pdev->dev, "failed to get output rate\n");
547 ret = -EINVAL;
Shengjiu Wang5f376712014-08-18 16:38:39 +0800548 goto asrc_fail;
Nicolin Chen708b4352014-07-30 19:27:38 +0800549 }
550
551 ret = of_property_read_u32(asrc_np, "fsl,asrc-width", &width);
552 if (ret) {
553 dev_err(&pdev->dev, "failed to get output rate\n");
554 ret = -EINVAL;
Shengjiu Wang5f376712014-08-18 16:38:39 +0800555 goto asrc_fail;
Nicolin Chen708b4352014-07-30 19:27:38 +0800556 }
557
558 if (width == 24)
559 priv->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
560 else
561 priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE;
562 }
563
564 /* Finish card registering */
565 platform_set_drvdata(pdev, priv);
566 snd_soc_card_set_drvdata(&priv->card, priv);
567
568 ret = devm_snd_soc_register_card(&pdev->dev, &priv->card);
569 if (ret)
570 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
571
Shengjiu Wang5f376712014-08-18 16:38:39 +0800572asrc_fail:
573 of_node_put(asrc_np);
Nicolin Chen708b4352014-07-30 19:27:38 +0800574fail:
575 of_node_put(codec_np);
Nicolin Chen708b4352014-07-30 19:27:38 +0800576 of_node_put(cpu_np);
577
578 return ret;
579}
580
581static const struct of_device_id fsl_asoc_card_dt_ids[] = {
582 { .compatible = "fsl,imx-audio-cs42888", },
583 { .compatible = "fsl,imx-audio-sgtl5000", },
584 { .compatible = "fsl,imx-audio-wm8962", },
585 {}
586};
587
588static struct platform_driver fsl_asoc_card_driver = {
589 .probe = fsl_asoc_card_probe,
590 .driver = {
591 .name = "fsl-asoc-card",
592 .pm = &snd_soc_pm_ops,
593 .of_match_table = fsl_asoc_card_dt_ids,
594 },
595};
596module_platform_driver(fsl_asoc_card_driver);
597
598MODULE_DESCRIPTION("Freescale Generic ASoC Sound Card driver with ASRC");
599MODULE_AUTHOR("Nicolin Chen <nicoleotsuka@gmail.com>");
600MODULE_ALIAS("platform:fsl-asoc-card");
601MODULE_LICENSE("GPL");