xref: /linux/sound/soc/fsl/fsl-asoc-card.c (revision c2a96b7f187fb6a455836d4a6e113947ff11de97)
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Freescale Generic ASoC Sound Card driver with ASRC
4 //
5 // Copyright (C) 2014 Freescale Semiconductor, Inc.
6 //
7 // Author: Nicolin Chen <nicoleotsuka@gmail.com>
8 
9 #include <linux/clk.h>
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>
15 #endif
16 #include <sound/pcm_params.h>
17 #include <sound/soc.h>
18 #include <sound/jack.h>
19 #include <sound/simple_card_utils.h>
20 
21 #include "fsl_esai.h"
22 #include "fsl_sai.h"
23 #include "imx-audmux.h"
24 
25 #include "../codecs/sgtl5000.h"
26 #include "../codecs/wm8962.h"
27 #include "../codecs/wm8960.h"
28 #include "../codecs/wm8994.h"
29 #include "../codecs/tlv320aic31xx.h"
30 #include "../codecs/nau8822.h"
31 #include "../codecs/wm8904.h"
32 
33 #define DRIVER_NAME "fsl-asoc-card"
34 
35 #define CS427x_SYSCLK_MCLK 0
36 
37 #define RX 0
38 #define TX 1
39 
40 /* Default DAI format without Master and Slave flag */
41 #define DAI_FMT_BASE (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF)
42 
43 /**
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()
49  * @fll_id: FLL (or secordary clock) id for set_sysclk()
50  * @pll_id: PLL id for set_pll()
51  */
52 struct codec_priv {
53 	struct clk *mclk;
54 	unsigned long mclk_freq;
55 	unsigned long free_freq;
56 	u32 mclk_id;
57 	int fll_id;
58 	int pll_id;
59 };
60 
61 /**
62  * struct cpu_priv - CPU private data
63  * @sysclk_freq: SYSCLK rates for set_sysclk()
64  * @sysclk_dir: SYSCLK directions for set_sysclk()
65  * @sysclk_id: SYSCLK ids for set_sysclk()
66  * @slot_width: Slot width of each frame
67  * @slot_num: Number of slots of each frame
68  *
69  * Note: [1] for tx and [0] for rx
70  */
71 struct cpu_priv {
72 	unsigned long sysclk_freq[2];
73 	u32 sysclk_dir[2];
74 	u32 sysclk_id[2];
75 	u32 slot_width;
76 	u32 slot_num;
77 };
78 
79 /**
80  * struct fsl_asoc_card_priv - Freescale Generic ASOC card private data
81  * @dai_link: DAI link structure including normal one and DPCM link
82  * @hp_jack: Headphone Jack structure
83  * @mic_jack: Microphone Jack structure
84  * @pdev: platform device pointer
85  * @codec_priv: CODEC private data
86  * @cpu_priv: CPU private data
87  * @card: ASoC card structure
88  * @streams: Mask of current active streams
89  * @sample_rate: Current sample rate
90  * @sample_format: Current sample format
91  * @asrc_rate: ASRC sample rate used by Back-Ends
92  * @asrc_format: ASRC sample format used by Back-Ends
93  * @dai_fmt: DAI format between CPU and CODEC
94  * @name: Card name
95  */
96 
97 struct fsl_asoc_card_priv {
98 	struct snd_soc_dai_link dai_link[3];
99 	struct simple_util_jack hp_jack;
100 	struct simple_util_jack mic_jack;
101 	struct platform_device *pdev;
102 	struct codec_priv codec_priv[2];
103 	struct cpu_priv cpu_priv;
104 	struct snd_soc_card card;
105 	u8 streams;
106 	u32 sample_rate;
107 	snd_pcm_format_t sample_format;
108 	u32 asrc_rate;
109 	snd_pcm_format_t asrc_format;
110 	u32 dai_fmt;
111 	char name[32];
112 };
113 
114 /*
115  * This dapm route map exists for DPCM link only.
116  * The other routes shall go through Device Tree.
117  *
118  * Note: keep all ASRC routes in the second half
119  *	 to drop them easily for non-ASRC cases.
120  */
121 static const struct snd_soc_dapm_route audio_map[] = {
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"},
128 };
129 
130 static const struct snd_soc_dapm_route audio_map_ac97[] = {
131 	/* 1st half -- Normal DAPM routes */
132 	{"AC97 Playback",  NULL, "CPU AC97 Playback"},
133 	{"CPU AC97 Capture",  NULL, "AC97 Capture"},
134 	/* 2nd half -- ASRC DAPM routes */
135 	{"CPU AC97 Playback",  NULL, "ASRC-Playback"},
136 	{"ASRC-Capture",  NULL, "CPU AC97 Capture"},
137 };
138 
139 static const struct snd_soc_dapm_route audio_map_tx[] = {
140 	/* 1st half -- Normal DAPM routes */
141 	{"Playback",  NULL, "CPU-Playback"},
142 	/* 2nd half -- ASRC DAPM routes */
143 	{"CPU-Playback",  NULL, "ASRC-Playback"},
144 };
145 
146 static const struct snd_soc_dapm_route audio_map_rx[] = {
147 	/* 1st half -- Normal DAPM routes */
148 	{"CPU-Capture",  NULL, "Capture"},
149 	/* 2nd half -- ASRC DAPM routes */
150 	{"ASRC-Capture",  NULL, "CPU-Capture"},
151 };
152 
153 /* Add all possible widgets into here without being redundant */
154 static const struct snd_soc_dapm_widget fsl_asoc_card_dapm_widgets[] = {
155 	SND_SOC_DAPM_LINE("Line Out Jack", NULL),
156 	SND_SOC_DAPM_LINE("Line In Jack", NULL),
157 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
158 	SND_SOC_DAPM_SPK("Ext Spk", NULL),
159 	SND_SOC_DAPM_MIC("Mic Jack", NULL),
160 	SND_SOC_DAPM_MIC("AMIC", NULL),
161 	SND_SOC_DAPM_MIC("DMIC", NULL),
162 };
163 
164 static bool fsl_asoc_card_is_ac97(struct fsl_asoc_card_priv *priv)
165 {
166 	return priv->dai_fmt == SND_SOC_DAIFMT_AC97;
167 }
168 
169 static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream,
170 				   struct snd_pcm_hw_params *params)
171 {
172 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
173 	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
174 	bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
175 	struct codec_priv *codec_priv;
176 	struct snd_soc_dai *codec_dai;
177 	struct cpu_priv *cpu_priv = &priv->cpu_priv;
178 	struct device *dev = rtd->card->dev;
179 	unsigned int pll_out;
180 	int codec_idx;
181 	int ret;
182 
183 	priv->sample_rate = params_rate(params);
184 	priv->sample_format = params_format(params);
185 	priv->streams |= BIT(substream->stream);
186 
187 	if (fsl_asoc_card_is_ac97(priv))
188 		return 0;
189 
190 	/* Specific configurations of DAIs starts from here */
191 	ret = snd_soc_dai_set_sysclk(snd_soc_rtd_to_cpu(rtd, 0), cpu_priv->sysclk_id[tx],
192 				     cpu_priv->sysclk_freq[tx],
193 				     cpu_priv->sysclk_dir[tx]);
194 	if (ret && ret != -ENOTSUPP) {
195 		dev_err(dev, "failed to set sysclk for cpu dai\n");
196 		goto fail;
197 	}
198 
199 	if (cpu_priv->slot_width) {
200 		if (!cpu_priv->slot_num)
201 			cpu_priv->slot_num = 2;
202 
203 		ret = snd_soc_dai_set_tdm_slot(snd_soc_rtd_to_cpu(rtd, 0), 0x3, 0x3,
204 					       cpu_priv->slot_num,
205 					       cpu_priv->slot_width);
206 		if (ret && ret != -ENOTSUPP) {
207 			dev_err(dev, "failed to set TDM slot for cpu dai\n");
208 			goto fail;
209 		}
210 	}
211 
212 	/* Specific configuration for PLL */
213 	for_each_rtd_codec_dais(rtd, codec_idx, codec_dai) {
214 		codec_priv = &priv->codec_priv[codec_idx];
215 
216 		if (codec_priv->pll_id >= 0 && codec_priv->fll_id >= 0) {
217 			if (priv->sample_format == SNDRV_PCM_FORMAT_S24_LE)
218 				pll_out = priv->sample_rate * 384;
219 			else
220 				pll_out = priv->sample_rate * 256;
221 
222 			ret = snd_soc_dai_set_pll(codec_dai,
223 						codec_priv->pll_id,
224 						codec_priv->mclk_id,
225 						codec_priv->mclk_freq, pll_out);
226 			if (ret) {
227 				dev_err(dev, "failed to start FLL: %d\n", ret);
228 				goto fail;
229 			}
230 
231 			ret = snd_soc_dai_set_sysclk(codec_dai,
232 						codec_priv->fll_id,
233 						pll_out, SND_SOC_CLOCK_IN);
234 
235 			if (ret && ret != -ENOTSUPP) {
236 				dev_err(dev, "failed to set SYSCLK: %d\n", ret);
237 				goto fail;
238 			}
239 		}
240 	}
241 
242 	return 0;
243 
244 fail:
245 	priv->streams &= ~BIT(substream->stream);
246 	return ret;
247 }
248 
249 static int fsl_asoc_card_hw_free(struct snd_pcm_substream *substream)
250 {
251 	struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
252 	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
253 	struct codec_priv *codec_priv;
254 	struct snd_soc_dai *codec_dai;
255 	struct device *dev = rtd->card->dev;
256 	int codec_idx;
257 	int ret;
258 
259 	priv->streams &= ~BIT(substream->stream);
260 
261 	for_each_rtd_codec_dais(rtd, codec_idx, codec_dai) {
262 		codec_priv = &priv->codec_priv[codec_idx];
263 
264 		if (!priv->streams && codec_priv->pll_id >= 0 && codec_priv->fll_id >= 0) {
265 			/* Force freq to be free_freq to avoid error message in codec */
266 			ret = snd_soc_dai_set_sysclk(codec_dai,
267 						codec_priv->mclk_id,
268 						codec_priv->free_freq,
269 						SND_SOC_CLOCK_IN);
270 			if (ret) {
271 				dev_err(dev, "failed to switch away from FLL: %d\n", ret);
272 				return ret;
273 			}
274 
275 			ret = snd_soc_dai_set_pll(codec_dai,
276 						codec_priv->pll_id, 0, 0, 0);
277 			if (ret && ret != -ENOTSUPP) {
278 				dev_err(dev, "failed to stop FLL: %d\n", ret);
279 				return ret;
280 			}
281 		}
282 	}
283 
284 	return 0;
285 }
286 
287 static const struct snd_soc_ops fsl_asoc_card_ops = {
288 	.hw_params = fsl_asoc_card_hw_params,
289 	.hw_free = fsl_asoc_card_hw_free,
290 };
291 
292 static int be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd,
293 			      struct snd_pcm_hw_params *params)
294 {
295 	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(rtd->card);
296 	struct snd_interval *rate;
297 	struct snd_mask *mask;
298 
299 	rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
300 	rate->max = rate->min = priv->asrc_rate;
301 
302 	mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
303 	snd_mask_none(mask);
304 	snd_mask_set_format(mask, priv->asrc_format);
305 
306 	return 0;
307 }
308 
309 SND_SOC_DAILINK_DEFS(hifi,
310 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
311 	DAILINK_COMP_ARRAY(COMP_EMPTY(), COMP_EMPTY()),
312 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
313 
314 SND_SOC_DAILINK_DEFS(hifi_fe,
315 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
316 	DAILINK_COMP_ARRAY(COMP_DUMMY()),
317 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
318 
319 SND_SOC_DAILINK_DEFS(hifi_be,
320 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
321 	DAILINK_COMP_ARRAY(COMP_EMPTY(), COMP_EMPTY()));
322 
323 static const struct snd_soc_dai_link fsl_asoc_card_dai[] = {
324 	/* Default ASoC DAI Link*/
325 	{
326 		.name = "HiFi",
327 		.stream_name = "HiFi",
328 		.ops = &fsl_asoc_card_ops,
329 		SND_SOC_DAILINK_REG(hifi),
330 	},
331 	/* DPCM Link between Front-End and Back-End (Optional) */
332 	{
333 		.name = "HiFi-ASRC-FE",
334 		.stream_name = "HiFi-ASRC-FE",
335 		.dpcm_playback = 1,
336 		.dpcm_capture = 1,
337 		.dynamic = 1,
338 		SND_SOC_DAILINK_REG(hifi_fe),
339 	},
340 	{
341 		.name = "HiFi-ASRC-BE",
342 		.stream_name = "HiFi-ASRC-BE",
343 		.be_hw_params_fixup = be_hw_params_fixup,
344 		.ops = &fsl_asoc_card_ops,
345 		.dpcm_playback = 1,
346 		.dpcm_capture = 1,
347 		.no_pcm = 1,
348 		SND_SOC_DAILINK_REG(hifi_be),
349 	},
350 };
351 
352 static int fsl_asoc_card_audmux_init(struct device_node *np,
353 				     struct fsl_asoc_card_priv *priv)
354 {
355 	struct device *dev = &priv->pdev->dev;
356 	u32 int_ptcr = 0, ext_ptcr = 0;
357 	int int_port, ext_port;
358 	int ret;
359 
360 	ret = of_property_read_u32(np, "mux-int-port", &int_port);
361 	if (ret) {
362 		dev_err(dev, "mux-int-port missing or invalid\n");
363 		return ret;
364 	}
365 	ret = of_property_read_u32(np, "mux-ext-port", &ext_port);
366 	if (ret) {
367 		dev_err(dev, "mux-ext-port missing or invalid\n");
368 		return ret;
369 	}
370 
371 	/*
372 	 * The port numbering in the hardware manual starts at 1, while
373 	 * the AUDMUX API expects it starts at 0.
374 	 */
375 	int_port--;
376 	ext_port--;
377 
378 	/*
379 	 * Use asynchronous mode (6 wires) for all cases except AC97.
380 	 * If only 4 wires are needed, just set SSI into
381 	 * synchronous mode and enable 4 PADs in IOMUX.
382 	 */
383 	switch (priv->dai_fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
384 	case SND_SOC_DAIFMT_CBP_CFP:
385 		int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
386 			   IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
387 			   IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
388 			   IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
389 			   IMX_AUDMUX_V2_PTCR_RFSDIR |
390 			   IMX_AUDMUX_V2_PTCR_RCLKDIR |
391 			   IMX_AUDMUX_V2_PTCR_TFSDIR |
392 			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
393 		break;
394 	case SND_SOC_DAIFMT_CBP_CFC:
395 		int_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | ext_port) |
396 			   IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
397 			   IMX_AUDMUX_V2_PTCR_RCLKDIR |
398 			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
399 		ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
400 			   IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
401 			   IMX_AUDMUX_V2_PTCR_RFSDIR |
402 			   IMX_AUDMUX_V2_PTCR_TFSDIR;
403 		break;
404 	case SND_SOC_DAIFMT_CBC_CFP:
405 		int_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | ext_port) |
406 			   IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
407 			   IMX_AUDMUX_V2_PTCR_RFSDIR |
408 			   IMX_AUDMUX_V2_PTCR_TFSDIR;
409 		ext_ptcr = IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
410 			   IMX_AUDMUX_V2_PTCR_TCSEL(int_port) |
411 			   IMX_AUDMUX_V2_PTCR_RCLKDIR |
412 			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
413 		break;
414 	case SND_SOC_DAIFMT_CBC_CFC:
415 		ext_ptcr = IMX_AUDMUX_V2_PTCR_RFSEL(8 | int_port) |
416 			   IMX_AUDMUX_V2_PTCR_RCSEL(8 | int_port) |
417 			   IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
418 			   IMX_AUDMUX_V2_PTCR_TCSEL(int_port) |
419 			   IMX_AUDMUX_V2_PTCR_RFSDIR |
420 			   IMX_AUDMUX_V2_PTCR_RCLKDIR |
421 			   IMX_AUDMUX_V2_PTCR_TFSDIR |
422 			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
423 		break;
424 	default:
425 		if (!fsl_asoc_card_is_ac97(priv))
426 			return -EINVAL;
427 	}
428 
429 	if (fsl_asoc_card_is_ac97(priv)) {
430 		int_ptcr = IMX_AUDMUX_V2_PTCR_SYN |
431 			   IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
432 			   IMX_AUDMUX_V2_PTCR_TCLKDIR;
433 		ext_ptcr = IMX_AUDMUX_V2_PTCR_SYN |
434 			   IMX_AUDMUX_V2_PTCR_TFSEL(int_port) |
435 			   IMX_AUDMUX_V2_PTCR_TFSDIR;
436 	}
437 
438 	/* Asynchronous mode can not be set along with RCLKDIR */
439 	if (!fsl_asoc_card_is_ac97(priv)) {
440 		unsigned int pdcr =
441 				IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port);
442 
443 		ret = imx_audmux_v2_configure_port(int_port, 0,
444 						   pdcr);
445 		if (ret) {
446 			dev_err(dev, "audmux internal port setup failed\n");
447 			return ret;
448 		}
449 	}
450 
451 	ret = imx_audmux_v2_configure_port(int_port, int_ptcr,
452 					   IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port));
453 	if (ret) {
454 		dev_err(dev, "audmux internal port setup failed\n");
455 		return ret;
456 	}
457 
458 	if (!fsl_asoc_card_is_ac97(priv)) {
459 		unsigned int pdcr =
460 				IMX_AUDMUX_V2_PDCR_RXDSEL(int_port);
461 
462 		ret = imx_audmux_v2_configure_port(ext_port, 0,
463 						   pdcr);
464 		if (ret) {
465 			dev_err(dev, "audmux external port setup failed\n");
466 			return ret;
467 		}
468 	}
469 
470 	ret = imx_audmux_v2_configure_port(ext_port, ext_ptcr,
471 					   IMX_AUDMUX_V2_PDCR_RXDSEL(int_port));
472 	if (ret) {
473 		dev_err(dev, "audmux external port setup failed\n");
474 		return ret;
475 	}
476 
477 	return 0;
478 }
479 
480 static int fsl_asoc_card_spdif_init(struct device_node *codec_np[],
481 				    struct device_node *cpu_np,
482 				    const char *codec_dai_name[],
483 				    struct fsl_asoc_card_priv *priv)
484 {
485 	struct device *dev = &priv->pdev->dev;
486 	struct device_node *np = dev->of_node;
487 
488 	if (!of_node_name_eq(cpu_np, "spdif")) {
489 		dev_err(dev, "CPU phandle invalid, should be an SPDIF device\n");
490 		return -EINVAL;
491 	}
492 
493 	priv->dai_link[0].playback_only = true;
494 	priv->dai_link[0].capture_only = true;
495 
496 	for (int i = 0; i < 2; i++) {
497 		if (!codec_np[i])
498 			break;
499 
500 		if (of_device_is_compatible(codec_np[i], "linux,spdif-dit")) {
501 			priv->dai_link[0].capture_only = false;
502 			codec_dai_name[i] = "dit-hifi";
503 		} else if (of_device_is_compatible(codec_np[i], "linux,spdif-dir")) {
504 			priv->dai_link[0].playback_only = false;
505 			codec_dai_name[i] = "dir-hifi";
506 		}
507 	}
508 
509 	// Old SPDIF DT binding
510 	if (!codec_np[0]) {
511 		codec_dai_name[0] = snd_soc_dummy_dlc.dai_name;
512 		if (of_property_read_bool(np, "spdif-out"))
513 			priv->dai_link[0].capture_only = false;
514 		if (of_property_read_bool(np, "spdif-in"))
515 			priv->dai_link[0].playback_only = false;
516 	}
517 
518 	if (priv->dai_link[0].playback_only && priv->dai_link[0].capture_only) {
519 		dev_err(dev, "no enabled S/PDIF DAI link\n");
520 		return -EINVAL;
521 	}
522 
523 	if (priv->dai_link[0].playback_only) {
524 		priv->dai_link[1].dpcm_capture = false;
525 		priv->dai_link[2].dpcm_capture = false;
526 		priv->card.dapm_routes = audio_map_tx;
527 		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
528 	} else if (priv->dai_link[0].capture_only) {
529 		priv->dai_link[1].dpcm_playback = false;
530 		priv->dai_link[2].dpcm_playback = false;
531 		priv->card.dapm_routes = audio_map_rx;
532 		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_rx);
533 	}
534 
535 	// No DAPM routes with old bindings and dummy codec
536 	if (!codec_np[0]) {
537 		priv->card.dapm_routes = NULL;
538 		priv->card.num_dapm_routes = 0;
539 	}
540 
541 	if (codec_np[0] && codec_np[1]) {
542 		priv->dai_link[0].num_codecs = 2;
543 		priv->dai_link[2].num_codecs = 2;
544 	}
545 
546 	return 0;
547 }
548 
549 static int hp_jack_event(struct notifier_block *nb, unsigned long event,
550 			 void *data)
551 {
552 	struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
553 	struct snd_soc_dapm_context *dapm = &jack->card->dapm;
554 
555 	if (event & SND_JACK_HEADPHONE)
556 		/* Disable speaker if headphone is plugged in */
557 		return snd_soc_dapm_disable_pin(dapm, "Ext Spk");
558 	else
559 		return snd_soc_dapm_enable_pin(dapm, "Ext Spk");
560 }
561 
562 static struct notifier_block hp_jack_nb = {
563 	.notifier_call = hp_jack_event,
564 };
565 
566 static int mic_jack_event(struct notifier_block *nb, unsigned long event,
567 			  void *data)
568 {
569 	struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
570 	struct snd_soc_dapm_context *dapm = &jack->card->dapm;
571 
572 	if (event & SND_JACK_MICROPHONE)
573 		/* Disable dmic if microphone is plugged in */
574 		return snd_soc_dapm_disable_pin(dapm, "DMIC");
575 	else
576 		return snd_soc_dapm_enable_pin(dapm, "DMIC");
577 }
578 
579 static struct notifier_block mic_jack_nb = {
580 	.notifier_call = mic_jack_event,
581 };
582 
583 static int fsl_asoc_card_late_probe(struct snd_soc_card *card)
584 {
585 	struct fsl_asoc_card_priv *priv = snd_soc_card_get_drvdata(card);
586 	struct snd_soc_pcm_runtime *rtd = list_first_entry(
587 			&card->rtd_list, struct snd_soc_pcm_runtime, list);
588 	struct snd_soc_dai *codec_dai;
589 	struct codec_priv *codec_priv;
590 	struct device *dev = card->dev;
591 	int codec_idx;
592 	int ret;
593 
594 	if (fsl_asoc_card_is_ac97(priv)) {
595 #if IS_ENABLED(CONFIG_SND_AC97_CODEC)
596 		struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
597 		struct snd_ac97 *ac97 = snd_soc_component_get_drvdata(component);
598 
599 		/*
600 		 * Use slots 3/4 for S/PDIF so SSI won't try to enable
601 		 * other slots and send some samples there
602 		 * due to SLOTREQ bits for S/PDIF received from codec
603 		 */
604 		snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
605 				     AC97_EA_SPSA_SLOT_MASK, AC97_EA_SPSA_3_4);
606 #endif
607 
608 		return 0;
609 	}
610 
611 	for_each_rtd_codec_dais(rtd, codec_idx, codec_dai) {
612 		codec_priv = &priv->codec_priv[codec_idx];
613 
614 		ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
615 					codec_priv->mclk_freq, SND_SOC_CLOCK_IN);
616 		if (ret && ret != -ENOTSUPP) {
617 			dev_err(dev, "failed to set sysclk in %s\n", __func__);
618 			return ret;
619 		}
620 
621 		if (!IS_ERR_OR_NULL(codec_priv->mclk))
622 			clk_prepare_enable(codec_priv->mclk);
623 	}
624 
625 	return 0;
626 }
627 
628 static int fsl_asoc_card_probe(struct platform_device *pdev)
629 {
630 	struct device_node *cpu_np, *asrc_np;
631 	struct snd_soc_dai_link_component *codec_comp;
632 	struct device_node *codec_np[2];
633 	struct device_node *np = pdev->dev.of_node;
634 	struct platform_device *asrc_pdev = NULL;
635 	struct device_node *bitclkprovider = NULL;
636 	struct device_node *frameprovider = NULL;
637 	struct platform_device *cpu_pdev;
638 	struct fsl_asoc_card_priv *priv;
639 	struct device *codec_dev[2] = { NULL, NULL };
640 	const char *codec_dai_name[2];
641 	const char *codec_dev_name[2];
642 	u32 asrc_fmt = 0;
643 	int codec_idx;
644 	u32 width;
645 	int ret;
646 
647 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
648 	if (!priv)
649 		return -ENOMEM;
650 
651 	priv->pdev = pdev;
652 
653 	cpu_np = of_parse_phandle(np, "audio-cpu", 0);
654 	/* Give a chance to old DT bindings */
655 	if (!cpu_np)
656 		cpu_np = of_parse_phandle(np, "ssi-controller", 0);
657 	if (!cpu_np)
658 		cpu_np = of_parse_phandle(np, "spdif-controller", 0);
659 	if (!cpu_np) {
660 		dev_err(&pdev->dev, "CPU phandle missing or invalid\n");
661 		ret = -EINVAL;
662 		goto fail;
663 	}
664 
665 	cpu_pdev = of_find_device_by_node(cpu_np);
666 	if (!cpu_pdev) {
667 		dev_err(&pdev->dev, "failed to find CPU DAI device\n");
668 		ret = -EINVAL;
669 		goto fail;
670 	}
671 
672 	codec_np[0] = of_parse_phandle(np, "audio-codec", 0);
673 	codec_np[1] = of_parse_phandle(np, "audio-codec", 1);
674 
675 	for (codec_idx = 0; codec_idx < 2; codec_idx++) {
676 		if (codec_np[codec_idx]) {
677 			struct platform_device *codec_pdev;
678 			struct i2c_client *codec_i2c;
679 
680 			codec_i2c = of_find_i2c_device_by_node(codec_np[codec_idx]);
681 			if (codec_i2c) {
682 				codec_dev[codec_idx] = &codec_i2c->dev;
683 				codec_dev_name[codec_idx] = codec_i2c->name;
684 			}
685 			if (!codec_dev[codec_idx]) {
686 				codec_pdev = of_find_device_by_node(codec_np[codec_idx]);
687 				if (codec_pdev) {
688 					codec_dev[codec_idx] = &codec_pdev->dev;
689 					codec_dev_name[codec_idx] = codec_pdev->name;
690 				}
691 			}
692 		}
693 	}
694 
695 	asrc_np = of_parse_phandle(np, "audio-asrc", 0);
696 	if (asrc_np)
697 		asrc_pdev = of_find_device_by_node(asrc_np);
698 
699 	/* Get the MCLK rate only, and leave it controlled by CODEC drivers */
700 	for (codec_idx = 0; codec_idx < 2; codec_idx++) {
701 		if (codec_dev[codec_idx]) {
702 			struct clk *codec_clk = clk_get(codec_dev[codec_idx], NULL);
703 
704 			if (!IS_ERR(codec_clk)) {
705 				priv->codec_priv[codec_idx].mclk_freq = clk_get_rate(codec_clk);
706 				clk_put(codec_clk);
707 			}
708 		}
709 	}
710 
711 	/* Default sample rate and format, will be updated in hw_params() */
712 	priv->sample_rate = 44100;
713 	priv->sample_format = SNDRV_PCM_FORMAT_S16_LE;
714 
715 	/* Assign a default DAI format, and allow each card to overwrite it */
716 	priv->dai_fmt = DAI_FMT_BASE;
717 
718 	memcpy(priv->dai_link, fsl_asoc_card_dai,
719 	       sizeof(struct snd_soc_dai_link) * ARRAY_SIZE(priv->dai_link));
720 	priv->dai_link[0].num_codecs = 1;
721 	priv->dai_link[2].num_codecs = 1;
722 
723 	priv->card.dapm_routes = audio_map;
724 	priv->card.num_dapm_routes = ARRAY_SIZE(audio_map);
725 	priv->card.driver_name = DRIVER_NAME;
726 
727 	for (codec_idx = 0; codec_idx < 2; codec_idx++) {
728 		priv->codec_priv[codec_idx].fll_id = -1;
729 		priv->codec_priv[codec_idx].pll_id = -1;
730 	}
731 
732 	/* Diversify the card configurations */
733 	if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) {
734 		codec_dai_name[0] = "cs42888";
735 		priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv[0].mclk_freq;
736 		priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv[0].mclk_freq;
737 		priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
738 		priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT;
739 		priv->cpu_priv.slot_width = 32;
740 		priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
741 	} else if (of_device_is_compatible(np, "fsl,imx-audio-cs427x")) {
742 		codec_dai_name[0] = "cs4271-hifi";
743 		priv->codec_priv[0].mclk_id = CS427x_SYSCLK_MCLK;
744 		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
745 	} else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) {
746 		codec_dai_name[0] = "sgtl5000";
747 		priv->codec_priv[0].mclk_id = SGTL5000_SYSCLK;
748 		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
749 	} else if (of_device_is_compatible(np, "fsl,imx-audio-tlv320aic32x4")) {
750 		codec_dai_name[0] = "tlv320aic32x4-hifi";
751 		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
752 	} else if (of_device_is_compatible(np, "fsl,imx-audio-tlv320aic31xx")) {
753 		codec_dai_name[0] = "tlv320dac31xx-hifi";
754 		priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
755 		priv->dai_link[1].dpcm_capture = 0;
756 		priv->dai_link[2].dpcm_capture = 0;
757 		priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_OUT;
758 		priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_OUT;
759 		priv->card.dapm_routes = audio_map_tx;
760 		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
761 	} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) {
762 		codec_dai_name[0] = "wm8962";
763 		priv->codec_priv[0].mclk_id = WM8962_SYSCLK_MCLK;
764 		priv->codec_priv[0].fll_id = WM8962_SYSCLK_FLL;
765 		priv->codec_priv[0].pll_id = WM8962_FLL;
766 		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
767 	} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8960")) {
768 		codec_dai_name[0] = "wm8960-hifi";
769 		priv->codec_priv[0].fll_id = WM8960_SYSCLK_AUTO;
770 		priv->codec_priv[0].pll_id = WM8960_SYSCLK_AUTO;
771 		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
772 	} else if (of_device_is_compatible(np, "fsl,imx-audio-ac97")) {
773 		codec_dai_name[0] = "ac97-hifi";
774 		priv->dai_fmt = SND_SOC_DAIFMT_AC97;
775 		priv->card.dapm_routes = audio_map_ac97;
776 		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_ac97);
777 	} else if (of_device_is_compatible(np, "fsl,imx-audio-mqs")) {
778 		codec_dai_name[0] = "fsl-mqs-dai";
779 		priv->dai_fmt = SND_SOC_DAIFMT_LEFT_J |
780 				SND_SOC_DAIFMT_CBC_CFC |
781 				SND_SOC_DAIFMT_NB_NF;
782 		priv->dai_link[1].dpcm_capture = 0;
783 		priv->dai_link[2].dpcm_capture = 0;
784 		priv->card.dapm_routes = audio_map_tx;
785 		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
786 	} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8524")) {
787 		codec_dai_name[0] = "wm8524-hifi";
788 		priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
789 		priv->dai_link[1].dpcm_capture = 0;
790 		priv->dai_link[2].dpcm_capture = 0;
791 		priv->cpu_priv.slot_width = 32;
792 		priv->card.dapm_routes = audio_map_tx;
793 		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
794 	} else if (of_device_is_compatible(np, "fsl,imx-audio-si476x")) {
795 		codec_dai_name[0] = "si476x-codec";
796 		priv->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
797 		priv->card.dapm_routes = audio_map_rx;
798 		priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_rx);
799 	} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8958")) {
800 		codec_dai_name[0] = "wm8994-aif1";
801 		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
802 		priv->codec_priv[0].mclk_id = WM8994_FLL_SRC_MCLK1;
803 		priv->codec_priv[0].fll_id = WM8994_SYSCLK_FLL1;
804 		priv->codec_priv[0].pll_id = WM8994_FLL1;
805 		priv->codec_priv[0].free_freq = priv->codec_priv[0].mclk_freq;
806 		priv->card.dapm_routes = NULL;
807 		priv->card.num_dapm_routes = 0;
808 	} else if (of_device_is_compatible(np, "fsl,imx-audio-nau8822")) {
809 		codec_dai_name[0] = "nau8822-hifi";
810 		priv->codec_priv[0].mclk_id = NAU8822_CLK_MCLK;
811 		priv->codec_priv[0].fll_id = NAU8822_CLK_PLL;
812 		priv->codec_priv[0].pll_id = NAU8822_CLK_PLL;
813 		priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
814 		if (codec_dev[0])
815 			priv->codec_priv[0].mclk = devm_clk_get(codec_dev[0], NULL);
816 	} else if (of_device_is_compatible(np, "fsl,imx-audio-wm8904")) {
817 		codec_dai_name[0] = "wm8904-hifi";
818 		priv->codec_priv[0].mclk_id = WM8904_FLL_MCLK;
819 		priv->codec_priv[0].fll_id = WM8904_CLK_FLL;
820 		priv->codec_priv[0].pll_id = WM8904_FLL_MCLK;
821 		priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
822 	} else if (of_device_is_compatible(np, "fsl,imx-audio-spdif")) {
823 		ret = fsl_asoc_card_spdif_init(codec_np, cpu_np, codec_dai_name, priv);
824 		if (ret)
825 			goto asrc_fail;
826 	} else {
827 		dev_err(&pdev->dev, "unknown Device Tree compatible\n");
828 		ret = -EINVAL;
829 		goto asrc_fail;
830 	}
831 
832 	/*
833 	 * Allow setting mclk-id from the device-tree node. Otherwise, the
834 	 * default value for each card configuration is used.
835 	 */
836 	for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) {
837 		of_property_read_u32_index(np, "mclk-id", codec_idx,
838 					&priv->codec_priv[codec_idx].mclk_id);
839 	}
840 
841 	/* Format info from DT is optional. */
842 	snd_soc_daifmt_parse_clock_provider_as_phandle(np, NULL, &bitclkprovider, &frameprovider);
843 	if (bitclkprovider || frameprovider) {
844 		unsigned int daifmt = snd_soc_daifmt_parse_format(np, NULL);
845 		bool codec_bitclkprovider = false;
846 		bool codec_frameprovider = false;
847 
848 		for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) {
849 			if (bitclkprovider && codec_np[codec_idx] == bitclkprovider)
850 				codec_bitclkprovider = true;
851 			if (frameprovider && codec_np[codec_idx] == frameprovider)
852 				codec_frameprovider = true;
853 		}
854 
855 		if (codec_bitclkprovider)
856 			daifmt |= (codec_frameprovider) ?
857 				SND_SOC_DAIFMT_CBP_CFP : SND_SOC_DAIFMT_CBP_CFC;
858 		else
859 			daifmt |= (codec_frameprovider) ?
860 				SND_SOC_DAIFMT_CBC_CFP : SND_SOC_DAIFMT_CBC_CFC;
861 
862 		/* Override dai_fmt with value from DT */
863 		priv->dai_fmt = daifmt;
864 	}
865 
866 	/* Change direction according to format */
867 	if (priv->dai_fmt & SND_SOC_DAIFMT_CBP_CFP) {
868 		priv->cpu_priv.sysclk_dir[TX] = SND_SOC_CLOCK_IN;
869 		priv->cpu_priv.sysclk_dir[RX] = SND_SOC_CLOCK_IN;
870 	}
871 
872 	of_node_put(bitclkprovider);
873 	of_node_put(frameprovider);
874 
875 	if (!fsl_asoc_card_is_ac97(priv) && !codec_dev[0]
876 	    && codec_dai_name[0] != snd_soc_dummy_dlc.dai_name) {
877 		dev_dbg(&pdev->dev, "failed to find codec device\n");
878 		ret = -EPROBE_DEFER;
879 		goto asrc_fail;
880 	}
881 
882 	/* Common settings for corresponding Freescale CPU DAI driver */
883 	if (of_node_name_eq(cpu_np, "ssi")) {
884 		/* Only SSI needs to configure AUDMUX */
885 		ret = fsl_asoc_card_audmux_init(np, priv);
886 		if (ret) {
887 			dev_err(&pdev->dev, "failed to init audmux\n");
888 			goto asrc_fail;
889 		}
890 	} else if (of_node_name_eq(cpu_np, "esai")) {
891 		struct clk *esai_clk = clk_get(&cpu_pdev->dev, "extal");
892 
893 		if (!IS_ERR(esai_clk)) {
894 			priv->cpu_priv.sysclk_freq[TX] = clk_get_rate(esai_clk);
895 			priv->cpu_priv.sysclk_freq[RX] = clk_get_rate(esai_clk);
896 			clk_put(esai_clk);
897 		} else if (PTR_ERR(esai_clk) == -EPROBE_DEFER) {
898 			ret = -EPROBE_DEFER;
899 			goto asrc_fail;
900 		}
901 
902 		priv->cpu_priv.sysclk_id[1] = ESAI_HCKT_EXTAL;
903 		priv->cpu_priv.sysclk_id[0] = ESAI_HCKR_EXTAL;
904 	} else if (of_node_name_eq(cpu_np, "sai")) {
905 		priv->cpu_priv.sysclk_id[1] = FSL_SAI_CLK_MAST1;
906 		priv->cpu_priv.sysclk_id[0] = FSL_SAI_CLK_MAST1;
907 	}
908 
909 	/* Initialize sound card */
910 	priv->card.dev = &pdev->dev;
911 	priv->card.owner = THIS_MODULE;
912 	ret = snd_soc_of_parse_card_name(&priv->card, "model");
913 	if (ret) {
914 		snprintf(priv->name, sizeof(priv->name), "%s-audio",
915 			 fsl_asoc_card_is_ac97(priv) ? "ac97" : codec_dev_name[0]);
916 		priv->card.name = priv->name;
917 	}
918 	priv->card.dai_link = priv->dai_link;
919 	priv->card.late_probe = fsl_asoc_card_late_probe;
920 	priv->card.dapm_widgets = fsl_asoc_card_dapm_widgets;
921 	priv->card.num_dapm_widgets = ARRAY_SIZE(fsl_asoc_card_dapm_widgets);
922 
923 	/* Drop the second half of DAPM routes -- ASRC */
924 	if (!asrc_pdev)
925 		priv->card.num_dapm_routes /= 2;
926 
927 	if (of_property_read_bool(np, "audio-routing")) {
928 		ret = snd_soc_of_parse_audio_routing(&priv->card, "audio-routing");
929 		if (ret) {
930 			dev_err(&pdev->dev, "failed to parse audio-routing: %d\n", ret);
931 			goto asrc_fail;
932 		}
933 	}
934 
935 	/* Normal DAI Link */
936 	priv->dai_link[0].cpus->of_node = cpu_np;
937 	for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) {
938 		codec_comp->dai_name = codec_dai_name[codec_idx];
939 	}
940 
941 	// Old SPDIF DT binding support
942 	if (codec_dai_name[0] == snd_soc_dummy_dlc.dai_name)
943 		priv->dai_link[0].codecs[0].name = snd_soc_dummy_dlc.name;
944 
945 	if (!fsl_asoc_card_is_ac97(priv)) {
946 		for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) {
947 			codec_comp->of_node = codec_np[codec_idx];
948 		}
949 	} else {
950 		u32 idx;
951 
952 		ret = of_property_read_u32(cpu_np, "cell-index", &idx);
953 		if (ret) {
954 			dev_err(&pdev->dev,
955 				"cannot get CPU index property\n");
956 			goto asrc_fail;
957 		}
958 
959 		priv->dai_link[0].codecs[0].name =
960 				devm_kasprintf(&pdev->dev, GFP_KERNEL,
961 					       "ac97-codec.%u",
962 					       (unsigned int)idx);
963 		if (!priv->dai_link[0].codecs[0].name) {
964 			ret = -ENOMEM;
965 			goto asrc_fail;
966 		}
967 	}
968 
969 	priv->dai_link[0].platforms->of_node = cpu_np;
970 	priv->dai_link[0].dai_fmt = priv->dai_fmt;
971 	priv->card.num_links = 1;
972 
973 	if (asrc_pdev) {
974 		/* DPCM DAI Links only if ASRC exists */
975 		priv->dai_link[1].cpus->of_node = asrc_np;
976 		priv->dai_link[1].platforms->of_node = asrc_np;
977 		for_each_link_codecs((&(priv->dai_link[2])), codec_idx, codec_comp) {
978 			codec_comp->dai_name = priv->dai_link[0].codecs[codec_idx].dai_name;
979 			codec_comp->of_node = priv->dai_link[0].codecs[codec_idx].of_node;
980 			codec_comp->name = priv->dai_link[0].codecs[codec_idx].name;
981 		}
982 		priv->dai_link[2].cpus->of_node = cpu_np;
983 		priv->dai_link[2].dai_fmt = priv->dai_fmt;
984 		priv->card.num_links = 3;
985 
986 		ret = of_property_read_u32(asrc_np, "fsl,asrc-rate",
987 					   &priv->asrc_rate);
988 		if (ret) {
989 			dev_err(&pdev->dev, "failed to get output rate\n");
990 			ret = -EINVAL;
991 			goto asrc_fail;
992 		}
993 
994 		ret = of_property_read_u32(asrc_np, "fsl,asrc-format", &asrc_fmt);
995 		priv->asrc_format = (__force snd_pcm_format_t)asrc_fmt;
996 		if (ret) {
997 			/* Fallback to old binding; translate to asrc_format */
998 			ret = of_property_read_u32(asrc_np, "fsl,asrc-width",
999 						   &width);
1000 			if (ret) {
1001 				dev_err(&pdev->dev,
1002 					"failed to decide output format\n");
1003 				goto asrc_fail;
1004 			}
1005 
1006 			if (width == 24)
1007 				priv->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
1008 			else
1009 				priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE;
1010 		}
1011 	}
1012 
1013 	/* Finish card registering */
1014 	platform_set_drvdata(pdev, priv);
1015 	snd_soc_card_set_drvdata(&priv->card, priv);
1016 
1017 	ret = devm_snd_soc_register_card(&pdev->dev, &priv->card);
1018 	if (ret) {
1019 		dev_err_probe(&pdev->dev, ret, "snd_soc_register_card failed\n");
1020 		goto asrc_fail;
1021 	}
1022 
1023 	/*
1024 	 * Properties "hp-det-gpio" and "mic-det-gpio" are optional, and
1025 	 * simple_util_init_jack() uses these properties for creating
1026 	 * Headphone Jack and Microphone Jack.
1027 	 *
1028 	 * The notifier is initialized in snd_soc_card_jack_new(), then
1029 	 * snd_soc_jack_notifier_register can be called.
1030 	 */
1031 	if (of_property_read_bool(np, "hp-det-gpio")) {
1032 		ret = simple_util_init_jack(&priv->card, &priv->hp_jack,
1033 					    1, NULL, "Headphone Jack");
1034 		if (ret)
1035 			goto asrc_fail;
1036 
1037 		snd_soc_jack_notifier_register(&priv->hp_jack.jack, &hp_jack_nb);
1038 	}
1039 
1040 	if (of_property_read_bool(np, "mic-det-gpio")) {
1041 		ret = simple_util_init_jack(&priv->card, &priv->mic_jack,
1042 					    0, NULL, "Mic Jack");
1043 		if (ret)
1044 			goto asrc_fail;
1045 
1046 		snd_soc_jack_notifier_register(&priv->mic_jack.jack, &mic_jack_nb);
1047 	}
1048 
1049 asrc_fail:
1050 	of_node_put(asrc_np);
1051 	of_node_put(codec_np[0]);
1052 	of_node_put(codec_np[1]);
1053 	put_device(&cpu_pdev->dev);
1054 fail:
1055 	of_node_put(cpu_np);
1056 
1057 	return ret;
1058 }
1059 
1060 static const struct of_device_id fsl_asoc_card_dt_ids[] = {
1061 	{ .compatible = "fsl,imx-audio-ac97", },
1062 	{ .compatible = "fsl,imx-audio-cs42888", },
1063 	{ .compatible = "fsl,imx-audio-cs427x", },
1064 	{ .compatible = "fsl,imx-audio-tlv320aic32x4", },
1065 	{ .compatible = "fsl,imx-audio-tlv320aic31xx", },
1066 	{ .compatible = "fsl,imx-audio-sgtl5000", },
1067 	{ .compatible = "fsl,imx-audio-wm8962", },
1068 	{ .compatible = "fsl,imx-audio-wm8960", },
1069 	{ .compatible = "fsl,imx-audio-mqs", },
1070 	{ .compatible = "fsl,imx-audio-wm8524", },
1071 	{ .compatible = "fsl,imx-audio-si476x", },
1072 	{ .compatible = "fsl,imx-audio-wm8958", },
1073 	{ .compatible = "fsl,imx-audio-nau8822", },
1074 	{ .compatible = "fsl,imx-audio-wm8904", },
1075 	{ .compatible = "fsl,imx-audio-spdif", },
1076 	{}
1077 };
1078 MODULE_DEVICE_TABLE(of, fsl_asoc_card_dt_ids);
1079 
1080 static struct platform_driver fsl_asoc_card_driver = {
1081 	.probe = fsl_asoc_card_probe,
1082 	.driver = {
1083 		.name = DRIVER_NAME,
1084 		.pm = &snd_soc_pm_ops,
1085 		.of_match_table = fsl_asoc_card_dt_ids,
1086 	},
1087 };
1088 module_platform_driver(fsl_asoc_card_driver);
1089 
1090 MODULE_DESCRIPTION("Freescale Generic ASoC Sound Card driver with ASRC");
1091 MODULE_AUTHOR("Nicolin Chen <nicoleotsuka@gmail.com>");
1092 MODULE_ALIAS("platform:" DRIVER_NAME);
1093 MODULE_LICENSE("GPL");
1094