1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * tegra_asoc_machine.c - Universal ASoC machine driver for NVIDIA Tegra boards.
4  */
5 
6 #include <linux/clk.h>
7 #include <linux/export.h>
8 #include <linux/gpio/consumer.h>
9 #include <linux/module.h>
10 #include <linux/of.h>
11 #include <linux/of_device.h>
12 #include <linux/platform_device.h>
13 #include <linux/slab.h>
14 
15 #include <sound/core.h>
16 #include <sound/jack.h>
17 #include <sound/pcm.h>
18 #include <sound/pcm_params.h>
19 #include <sound/soc.h>
20 
21 #include "tegra_asoc_machine.h"
22 
23 /* Headphones Jack */
24 
25 static struct snd_soc_jack tegra_machine_hp_jack;
26 
27 static struct snd_soc_jack_pin tegra_machine_hp_jack_pins[] = {
28 	{ .pin = "Headphone",  .mask = SND_JACK_HEADPHONE },
29 	{ .pin = "Headphones", .mask = SND_JACK_HEADPHONE },
30 };
31 
32 static struct snd_soc_jack_gpio tegra_machine_hp_jack_gpio = {
33 	.name = "Headphones detection",
34 	.report = SND_JACK_HEADPHONE,
35 	.debounce_time = 150,
36 };
37 
38 /* Headset Jack */
39 
40 static struct snd_soc_jack tegra_machine_headset_jack;
41 
42 static struct snd_soc_jack_pin tegra_machine_headset_jack_pins[] = {
43 	{ .pin = "Headset Mic", .mask = SND_JACK_MICROPHONE },
44 	{ .pin = "Headset Stereophone", .mask = SND_JACK_HEADPHONE },
45 };
46 
47 static struct snd_soc_jack_gpio tegra_machine_headset_jack_gpio = {
48 	.name = "Headset detection",
49 	.report = SND_JACK_HEADSET,
50 	.debounce_time = 150,
51 };
52 
53 /* Mic Jack */
54 
55 static struct snd_soc_jack tegra_machine_mic_jack;
56 
57 static struct snd_soc_jack_pin tegra_machine_mic_jack_pins[] = {
58 	{ .pin = "Mic Jack",    .mask = SND_JACK_MICROPHONE },
59 	{ .pin = "Headset Mic", .mask = SND_JACK_MICROPHONE },
60 };
61 
62 static struct snd_soc_jack_gpio tegra_machine_mic_jack_gpio = {
63 	.name = "Mic detection",
64 	.report = SND_JACK_MICROPHONE,
65 	.debounce_time = 150,
66 };
67 
68 static int tegra_machine_event(struct snd_soc_dapm_widget *w,
69 			       struct snd_kcontrol *k, int event)
70 {
71 	struct snd_soc_dapm_context *dapm = w->dapm;
72 	struct tegra_machine *machine = snd_soc_card_get_drvdata(dapm->card);
73 
74 	if (!strcmp(w->name, "Int Spk") || !strcmp(w->name, "Speakers"))
75 		gpiod_set_value_cansleep(machine->gpiod_spkr_en,
76 					 SND_SOC_DAPM_EVENT_ON(event));
77 
78 	if (!strcmp(w->name, "Mic Jack"))
79 		gpiod_set_value_cansleep(machine->gpiod_ext_mic_en,
80 					 SND_SOC_DAPM_EVENT_ON(event));
81 
82 	if (!strcmp(w->name, "Int Mic"))
83 		gpiod_set_value_cansleep(machine->gpiod_int_mic_en,
84 					 SND_SOC_DAPM_EVENT_ON(event));
85 
86 	if (!strcmp(w->name, "Headphone") || !strcmp(w->name, "Headphone Jack"))
87 		gpiod_set_value_cansleep(machine->gpiod_hp_mute,
88 					 !SND_SOC_DAPM_EVENT_ON(event));
89 
90 	return 0;
91 }
92 
93 static const struct snd_soc_dapm_widget tegra_machine_dapm_widgets[] = {
94 	SND_SOC_DAPM_HP("Headphone Jack", tegra_machine_event),
95 	SND_SOC_DAPM_HP("Headphone", tegra_machine_event),
96 	SND_SOC_DAPM_HP("Headset Stereophone", NULL),
97 	SND_SOC_DAPM_HP("Headphones", NULL),
98 	SND_SOC_DAPM_SPK("Speakers", tegra_machine_event),
99 	SND_SOC_DAPM_SPK("Int Spk", tegra_machine_event),
100 	SND_SOC_DAPM_MIC("Int Mic", tegra_machine_event),
101 	SND_SOC_DAPM_MIC("Mic Jack", tegra_machine_event),
102 	SND_SOC_DAPM_MIC("Internal Mic 1", NULL),
103 	SND_SOC_DAPM_MIC("Internal Mic 2", NULL),
104 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
105 	SND_SOC_DAPM_MIC("Digital Mic", NULL),
106 	SND_SOC_DAPM_MIC("Mic", NULL),
107 	SND_SOC_DAPM_LINE("Line In Jack", NULL),
108 	SND_SOC_DAPM_LINE("Line In", NULL),
109 	SND_SOC_DAPM_LINE("LineIn", NULL),
110 };
111 
112 static const struct snd_kcontrol_new tegra_machine_controls[] = {
113 	SOC_DAPM_PIN_SWITCH("Speakers"),
114 	SOC_DAPM_PIN_SWITCH("Int Spk"),
115 	SOC_DAPM_PIN_SWITCH("Int Mic"),
116 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
117 	SOC_DAPM_PIN_SWITCH("Internal Mic 1"),
118 	SOC_DAPM_PIN_SWITCH("Internal Mic 2"),
119 	SOC_DAPM_PIN_SWITCH("Headphones"),
120 	SOC_DAPM_PIN_SWITCH("Mic Jack"),
121 };
122 
123 int tegra_asoc_machine_init(struct snd_soc_pcm_runtime *rtd)
124 {
125 	struct snd_soc_card *card = rtd->card;
126 	struct tegra_machine *machine = snd_soc_card_get_drvdata(card);
127 	const char *jack_name;
128 	int err;
129 
130 	if (machine->gpiod_hp_det && machine->asoc->add_hp_jack) {
131 		if (machine->asoc->hp_jack_name)
132 			jack_name = machine->asoc->hp_jack_name;
133 		else
134 			jack_name = "Headphones Jack";
135 
136 		err = snd_soc_card_jack_new_pins(card, jack_name,
137 						 SND_JACK_HEADPHONE,
138 						 &tegra_machine_hp_jack,
139 						 tegra_machine_hp_jack_pins,
140 						 ARRAY_SIZE(tegra_machine_hp_jack_pins));
141 		if (err) {
142 			dev_err(rtd->dev,
143 				"Headphones Jack creation failed: %d\n", err);
144 			return err;
145 		}
146 
147 		tegra_machine_hp_jack_gpio.desc = machine->gpiod_hp_det;
148 
149 		err = snd_soc_jack_add_gpios(&tegra_machine_hp_jack, 1,
150 					     &tegra_machine_hp_jack_gpio);
151 		if (err)
152 			dev_err(rtd->dev, "HP GPIOs not added: %d\n", err);
153 	}
154 
155 	if (machine->gpiod_hp_det && machine->asoc->add_headset_jack) {
156 		err = snd_soc_card_jack_new_pins(card, "Headset Jack",
157 						 SND_JACK_HEADSET,
158 						 &tegra_machine_headset_jack,
159 						 tegra_machine_headset_jack_pins,
160 						 ARRAY_SIZE(tegra_machine_headset_jack_pins));
161 		if (err) {
162 			dev_err(rtd->dev,
163 				"Headset Jack creation failed: %d\n", err);
164 			return err;
165 		}
166 
167 		tegra_machine_headset_jack_gpio.desc = machine->gpiod_hp_det;
168 
169 		err = snd_soc_jack_add_gpios(&tegra_machine_headset_jack, 1,
170 					     &tegra_machine_headset_jack_gpio);
171 		if (err)
172 			dev_err(rtd->dev, "Headset GPIOs not added: %d\n", err);
173 	}
174 
175 	if (machine->gpiod_mic_det && machine->asoc->add_mic_jack) {
176 		err = snd_soc_card_jack_new_pins(rtd->card, "Mic Jack",
177 						 SND_JACK_MICROPHONE,
178 						 &tegra_machine_mic_jack,
179 						 tegra_machine_mic_jack_pins,
180 						 ARRAY_SIZE(tegra_machine_mic_jack_pins));
181 		if (err) {
182 			dev_err(rtd->dev, "Mic Jack creation failed: %d\n", err);
183 			return err;
184 		}
185 
186 		tegra_machine_mic_jack_gpio.desc = machine->gpiod_mic_det;
187 
188 		err = snd_soc_jack_add_gpios(&tegra_machine_mic_jack, 1,
189 					     &tegra_machine_mic_jack_gpio);
190 		if (err)
191 			dev_err(rtd->dev, "Mic GPIOs not added: %d\n", err);
192 	}
193 
194 	return 0;
195 }
196 EXPORT_SYMBOL_GPL(tegra_asoc_machine_init);
197 
198 static unsigned int tegra_machine_mclk_rate_128(unsigned int srate)
199 {
200 	return 128 * srate;
201 }
202 
203 static unsigned int tegra_machine_mclk_rate_256(unsigned int srate)
204 {
205 	return 256 * srate;
206 }
207 
208 static unsigned int tegra_machine_mclk_rate_512(unsigned int srate)
209 {
210 	return 512 * srate;
211 }
212 
213 static unsigned int tegra_machine_mclk_rate_12mhz(unsigned int srate)
214 {
215 	unsigned int mclk;
216 
217 	switch (srate) {
218 	case 8000:
219 	case 16000:
220 	case 24000:
221 	case 32000:
222 	case 48000:
223 	case 64000:
224 	case 96000:
225 		mclk = 12288000;
226 		break;
227 	case 11025:
228 	case 22050:
229 	case 44100:
230 	case 88200:
231 		mclk = 11289600;
232 		break;
233 	default:
234 		mclk = 12000000;
235 		break;
236 	}
237 
238 	return mclk;
239 }
240 
241 static int tegra_machine_hw_params(struct snd_pcm_substream *substream,
242 				   struct snd_pcm_hw_params *params)
243 {
244 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
245 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
246 	struct snd_soc_card *card = rtd->card;
247 	struct tegra_machine *machine = snd_soc_card_get_drvdata(card);
248 	unsigned int srate = params_rate(params);
249 	unsigned int mclk = machine->asoc->mclk_rate(srate);
250 	unsigned int clk_id = machine->asoc->mclk_id;
251 	unsigned int new_baseclock;
252 	int err;
253 
254 	switch (srate) {
255 	case 11025:
256 	case 22050:
257 	case 44100:
258 	case 88200:
259 		if (of_machine_is_compatible("nvidia,tegra20"))
260 			new_baseclock = 56448000;
261 		else if (of_machine_is_compatible("nvidia,tegra30"))
262 			new_baseclock = 564480000;
263 		else
264 			new_baseclock = 282240000;
265 		break;
266 	case 8000:
267 	case 16000:
268 	case 32000:
269 	case 48000:
270 	case 64000:
271 	case 96000:
272 		if (of_machine_is_compatible("nvidia,tegra20"))
273 			new_baseclock = 73728000;
274 		else if (of_machine_is_compatible("nvidia,tegra30"))
275 			new_baseclock = 552960000;
276 		else
277 			new_baseclock = 368640000;
278 		break;
279 	default:
280 		dev_err(card->dev, "Invalid sound rate: %u\n", srate);
281 		return -EINVAL;
282 	}
283 
284 	if (new_baseclock != machine->set_baseclock ||
285 	    mclk != machine->set_mclk) {
286 		machine->set_baseclock = 0;
287 		machine->set_mclk = 0;
288 
289 		clk_disable_unprepare(machine->clk_cdev1);
290 
291 		err = clk_set_rate(machine->clk_pll_a, new_baseclock);
292 		if (err) {
293 			dev_err(card->dev, "Can't set pll_a rate: %d\n", err);
294 			return err;
295 		}
296 
297 		err = clk_set_rate(machine->clk_pll_a_out0, mclk);
298 		if (err) {
299 			dev_err(card->dev, "Can't set pll_a_out0 rate: %d\n", err);
300 			return err;
301 		}
302 
303 		/* Don't set cdev1/extern1 rate; it's locked to pll_a_out0 */
304 
305 		err = clk_prepare_enable(machine->clk_cdev1);
306 		if (err) {
307 			dev_err(card->dev, "Can't enable cdev1: %d\n", err);
308 			return err;
309 		}
310 
311 		machine->set_baseclock = new_baseclock;
312 		machine->set_mclk = mclk;
313 	}
314 
315 	err = snd_soc_dai_set_sysclk(codec_dai, clk_id, mclk, SND_SOC_CLOCK_IN);
316 	if (err < 0) {
317 		dev_err(card->dev, "codec_dai clock not set: %d\n", err);
318 		return err;
319 	}
320 
321 	return 0;
322 }
323 
324 static const struct snd_soc_ops tegra_machine_snd_ops = {
325 	.hw_params = tegra_machine_hw_params,
326 };
327 
328 static void tegra_machine_node_release(void *of_node)
329 {
330 	of_node_put(of_node);
331 }
332 
333 static struct device_node *
334 tegra_machine_parse_phandle(struct device *dev, const char *name)
335 {
336 	struct device_node *np;
337 	int err;
338 
339 	np = of_parse_phandle(dev->of_node, name, 0);
340 	if (!np) {
341 		dev_err(dev, "Property '%s' missing or invalid\n", name);
342 		return ERR_PTR(-EINVAL);
343 	}
344 
345 	err = devm_add_action_or_reset(dev, tegra_machine_node_release, np);
346 	if (err)
347 		return ERR_PTR(err);
348 
349 	return np;
350 }
351 
352 static void tegra_machine_unregister_codec(void *pdev)
353 {
354 	platform_device_unregister(pdev);
355 }
356 
357 static int tegra_machine_register_codec(struct device *dev, const char *name)
358 {
359 	struct platform_device *pdev;
360 	int err;
361 
362 	if (!name)
363 		return 0;
364 
365 	pdev = platform_device_register_simple(name, -1, NULL, 0);
366 	if (IS_ERR(pdev))
367 		return PTR_ERR(pdev);
368 
369 	err = devm_add_action_or_reset(dev, tegra_machine_unregister_codec,
370 				       pdev);
371 	if (err)
372 		return err;
373 
374 	return 0;
375 }
376 
377 int tegra_asoc_machine_probe(struct platform_device *pdev)
378 {
379 	struct device_node *np_codec, *np_i2s, *np_ac97;
380 	const struct tegra_asoc_data *asoc;
381 	struct device *dev = &pdev->dev;
382 	struct tegra_machine *machine;
383 	struct snd_soc_card *card;
384 	struct gpio_desc *gpiod;
385 	int err;
386 
387 	machine = devm_kzalloc(dev, sizeof(*machine), GFP_KERNEL);
388 	if (!machine)
389 		return -ENOMEM;
390 
391 	asoc = of_device_get_match_data(dev);
392 	card = asoc->card;
393 	card->dev = dev;
394 
395 	machine->asoc = asoc;
396 	machine->mic_jack = &tegra_machine_mic_jack;
397 	machine->hp_jack_gpio = &tegra_machine_hp_jack_gpio;
398 	snd_soc_card_set_drvdata(card, machine);
399 
400 	gpiod = devm_gpiod_get_optional(dev, "nvidia,hp-mute", GPIOD_OUT_HIGH);
401 	machine->gpiod_hp_mute = gpiod;
402 	if (IS_ERR(gpiod))
403 		return PTR_ERR(gpiod);
404 
405 	gpiod = devm_gpiod_get_optional(dev, "nvidia,hp-det", GPIOD_IN);
406 	machine->gpiod_hp_det = gpiod;
407 	if (IS_ERR(gpiod))
408 		return PTR_ERR(gpiod);
409 
410 	gpiod = devm_gpiod_get_optional(dev, "nvidia,mic-det", GPIOD_IN);
411 	machine->gpiod_mic_det = gpiod;
412 	if (IS_ERR(gpiod))
413 		return PTR_ERR(gpiod);
414 
415 	gpiod = devm_gpiod_get_optional(dev, "nvidia,spkr-en", GPIOD_OUT_LOW);
416 	machine->gpiod_spkr_en = gpiod;
417 	if (IS_ERR(gpiod))
418 		return PTR_ERR(gpiod);
419 
420 	gpiod = devm_gpiod_get_optional(dev, "nvidia,int-mic-en", GPIOD_OUT_LOW);
421 	machine->gpiod_int_mic_en = gpiod;
422 	if (IS_ERR(gpiod))
423 		return PTR_ERR(gpiod);
424 
425 	gpiod = devm_gpiod_get_optional(dev, "nvidia,ext-mic-en", GPIOD_OUT_LOW);
426 	machine->gpiod_ext_mic_en = gpiod;
427 	if (IS_ERR(gpiod))
428 		return PTR_ERR(gpiod);
429 
430 	err = snd_soc_of_parse_card_name(card, "nvidia,model");
431 	if (err)
432 		return err;
433 
434 	if (!card->dapm_routes) {
435 		err = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
436 		if (err)
437 			return err;
438 	}
439 
440 	if (asoc->set_ac97) {
441 		err = tegra_machine_register_codec(dev, asoc->codec_dev_name);
442 		if (err)
443 			return err;
444 
445 		np_ac97 = tegra_machine_parse_phandle(dev, "nvidia,ac97-controller");
446 		if (IS_ERR(np_ac97))
447 			return PTR_ERR(np_ac97);
448 
449 		card->dai_link->cpus->of_node = np_ac97;
450 		card->dai_link->platforms->of_node = np_ac97;
451 	} else {
452 		np_codec = tegra_machine_parse_phandle(dev, "nvidia,audio-codec");
453 		if (IS_ERR(np_codec))
454 			return PTR_ERR(np_codec);
455 
456 		np_i2s = tegra_machine_parse_phandle(dev, "nvidia,i2s-controller");
457 		if (IS_ERR(np_i2s))
458 			return PTR_ERR(np_i2s);
459 
460 		card->dai_link->cpus->of_node = np_i2s;
461 		card->dai_link->codecs->of_node = np_codec;
462 		card->dai_link->platforms->of_node = np_i2s;
463 	}
464 
465 	if (asoc->add_common_controls) {
466 		card->controls = tegra_machine_controls;
467 		card->num_controls = ARRAY_SIZE(tegra_machine_controls);
468 	}
469 
470 	if (asoc->add_common_dapm_widgets) {
471 		card->dapm_widgets = tegra_machine_dapm_widgets;
472 		card->num_dapm_widgets = ARRAY_SIZE(tegra_machine_dapm_widgets);
473 	}
474 
475 	if (asoc->add_common_snd_ops)
476 		card->dai_link->ops = &tegra_machine_snd_ops;
477 
478 	if (!card->owner)
479 		card->owner = THIS_MODULE;
480 	if (!card->driver_name)
481 		card->driver_name = "tegra";
482 
483 	machine->clk_pll_a = devm_clk_get(dev, "pll_a");
484 	if (IS_ERR(machine->clk_pll_a)) {
485 		dev_err(dev, "Can't retrieve clk pll_a\n");
486 		return PTR_ERR(machine->clk_pll_a);
487 	}
488 
489 	machine->clk_pll_a_out0 = devm_clk_get(dev, "pll_a_out0");
490 	if (IS_ERR(machine->clk_pll_a_out0)) {
491 		dev_err(dev, "Can't retrieve clk pll_a_out0\n");
492 		return PTR_ERR(machine->clk_pll_a_out0);
493 	}
494 
495 	machine->clk_cdev1 = devm_clk_get(dev, "mclk");
496 	if (IS_ERR(machine->clk_cdev1)) {
497 		dev_err(dev, "Can't retrieve clk cdev1\n");
498 		return PTR_ERR(machine->clk_cdev1);
499 	}
500 
501 	/*
502 	 * If clock parents are not set in DT, configure here to use clk_out_1
503 	 * as mclk and extern1 as parent for Tegra30 and higher.
504 	 */
505 	if (!of_find_property(dev->of_node, "assigned-clock-parents", NULL) &&
506 	    !of_machine_is_compatible("nvidia,tegra20")) {
507 		struct clk *clk_out_1, *clk_extern1;
508 
509 		dev_warn(dev, "Configuring clocks for a legacy device-tree\n");
510 		dev_warn(dev, "Please update DT to use assigned-clock-parents\n");
511 
512 		clk_extern1 = devm_clk_get(dev, "extern1");
513 		if (IS_ERR(clk_extern1)) {
514 			dev_err(dev, "Can't retrieve clk extern1\n");
515 			return PTR_ERR(clk_extern1);
516 		}
517 
518 		err = clk_set_parent(clk_extern1, machine->clk_pll_a_out0);
519 		if (err < 0) {
520 			dev_err(dev, "Set parent failed for clk extern1\n");
521 			return err;
522 		}
523 
524 		clk_out_1 = devm_clk_get(dev, "pmc_clk_out_1");
525 		if (IS_ERR(clk_out_1)) {
526 			dev_err(dev, "Can't retrieve pmc_clk_out_1\n");
527 			return PTR_ERR(clk_out_1);
528 		}
529 
530 		err = clk_set_parent(clk_out_1, clk_extern1);
531 		if (err < 0) {
532 			dev_err(dev, "Set parent failed for pmc_clk_out_1\n");
533 			return err;
534 		}
535 
536 		machine->clk_cdev1 = clk_out_1;
537 	}
538 
539 	if (asoc->set_ac97) {
540 		/*
541 		 * AC97 rate is fixed at 24.576MHz and is used for both the
542 		 * host controller and the external codec
543 		 */
544 		err = clk_set_rate(machine->clk_pll_a, 73728000);
545 		if (err) {
546 			dev_err(dev, "Can't set pll_a rate: %d\n", err);
547 			return err;
548 		}
549 
550 		err = clk_set_rate(machine->clk_pll_a_out0, 24576000);
551 		if (err) {
552 			dev_err(dev, "Can't set pll_a_out0 rate: %d\n", err);
553 			return err;
554 		}
555 
556 		machine->set_baseclock = 73728000;
557 		machine->set_mclk = 24576000;
558 	}
559 
560 	/*
561 	 * FIXME: There is some unknown dependency between audio MCLK disable
562 	 * and suspend-resume functionality on Tegra30, although audio MCLK is
563 	 * only needed for audio.
564 	 */
565 	err = clk_prepare_enable(machine->clk_cdev1);
566 	if (err) {
567 		dev_err(dev, "Can't enable cdev1: %d\n", err);
568 		return err;
569 	}
570 
571 	err = devm_snd_soc_register_card(dev, card);
572 	if (err)
573 		return err;
574 
575 	return 0;
576 }
577 EXPORT_SYMBOL_GPL(tegra_asoc_machine_probe);
578 
579 /* WM8753 machine */
580 
581 SND_SOC_DAILINK_DEFS(wm8753_hifi,
582 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
583 	DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "wm8753-hifi")),
584 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
585 
586 static struct snd_soc_dai_link tegra_wm8753_dai = {
587 	.name = "WM8753",
588 	.stream_name = "WM8753 PCM",
589 	.dai_fmt = SND_SOC_DAIFMT_I2S |
590 		   SND_SOC_DAIFMT_NB_NF |
591 		   SND_SOC_DAIFMT_CBS_CFS,
592 	SND_SOC_DAILINK_REG(wm8753_hifi),
593 };
594 
595 static struct snd_soc_card snd_soc_tegra_wm8753 = {
596 	.components = "codec:wm8753",
597 	.dai_link = &tegra_wm8753_dai,
598 	.num_links = 1,
599 	.fully_routed = true,
600 };
601 
602 static const struct tegra_asoc_data tegra_wm8753_data = {
603 	.mclk_rate = tegra_machine_mclk_rate_12mhz,
604 	.card = &snd_soc_tegra_wm8753,
605 	.add_common_dapm_widgets = true,
606 	.add_common_snd_ops = true,
607 };
608 
609 /* WM9712 machine */
610 
611 static int tegra_wm9712_init(struct snd_soc_pcm_runtime *rtd)
612 {
613 	return snd_soc_dapm_force_enable_pin(&rtd->card->dapm, "Mic Bias");
614 }
615 
616 SND_SOC_DAILINK_DEFS(wm9712_hifi,
617 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
618 	DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")),
619 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
620 
621 static struct snd_soc_dai_link tegra_wm9712_dai = {
622 	.name = "AC97 HiFi",
623 	.stream_name = "AC97 HiFi",
624 	.init = tegra_wm9712_init,
625 	SND_SOC_DAILINK_REG(wm9712_hifi),
626 };
627 
628 static struct snd_soc_card snd_soc_tegra_wm9712 = {
629 	.components = "codec:wm9712",
630 	.dai_link = &tegra_wm9712_dai,
631 	.num_links = 1,
632 	.fully_routed = true,
633 };
634 
635 static const struct tegra_asoc_data tegra_wm9712_data = {
636 	.card = &snd_soc_tegra_wm9712,
637 	.add_common_dapm_widgets = true,
638 	.codec_dev_name = "wm9712-codec",
639 	.set_ac97 = true,
640 };
641 
642 /* MAX98090 machine */
643 
644 SND_SOC_DAILINK_DEFS(max98090_hifi,
645 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
646 	DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "HiFi")),
647 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
648 
649 static struct snd_soc_dai_link tegra_max98090_dai = {
650 	.name = "max98090",
651 	.stream_name = "max98090 PCM",
652 	.init = tegra_asoc_machine_init,
653 	.dai_fmt = SND_SOC_DAIFMT_I2S |
654 		   SND_SOC_DAIFMT_NB_NF |
655 		   SND_SOC_DAIFMT_CBS_CFS,
656 	SND_SOC_DAILINK_REG(max98090_hifi),
657 };
658 
659 static struct snd_soc_card snd_soc_tegra_max98090 = {
660 	.components = "codec:max98090",
661 	.dai_link = &tegra_max98090_dai,
662 	.num_links = 1,
663 	.fully_routed = true,
664 };
665 
666 static const struct tegra_asoc_data tegra_max98090_data = {
667 	.mclk_rate = tegra_machine_mclk_rate_12mhz,
668 	.card = &snd_soc_tegra_max98090,
669 	.hp_jack_name = "Headphones",
670 	.add_common_dapm_widgets = true,
671 	.add_common_controls = true,
672 	.add_common_snd_ops = true,
673 	.add_mic_jack = true,
674 	.add_hp_jack = true,
675 };
676 
677 /* SGTL5000 machine */
678 
679 SND_SOC_DAILINK_DEFS(sgtl5000_hifi,
680 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
681 	DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "sgtl5000")),
682 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
683 
684 static struct snd_soc_dai_link tegra_sgtl5000_dai = {
685 	.name = "sgtl5000",
686 	.stream_name = "HiFi",
687 	.dai_fmt = SND_SOC_DAIFMT_I2S |
688 		   SND_SOC_DAIFMT_NB_NF |
689 		   SND_SOC_DAIFMT_CBS_CFS,
690 	SND_SOC_DAILINK_REG(sgtl5000_hifi),
691 };
692 
693 static struct snd_soc_card snd_soc_tegra_sgtl5000 = {
694 	.components = "codec:sgtl5000",
695 	.dai_link = &tegra_sgtl5000_dai,
696 	.num_links = 1,
697 	.fully_routed = true,
698 };
699 
700 static const struct tegra_asoc_data tegra_sgtl5000_data = {
701 	.mclk_rate = tegra_machine_mclk_rate_12mhz,
702 	.card = &snd_soc_tegra_sgtl5000,
703 	.add_common_dapm_widgets = true,
704 	.add_common_snd_ops = true,
705 };
706 
707 /* TLV320AIC23 machine */
708 
709 static const struct snd_soc_dapm_widget trimslice_dapm_widgets[] = {
710 	SND_SOC_DAPM_HP("Line Out", NULL),
711 	SND_SOC_DAPM_LINE("Line In", NULL),
712 };
713 
714 static const struct snd_soc_dapm_route trimslice_audio_map[] = {
715 	{"Line Out", NULL, "LOUT"},
716 	{"Line Out", NULL, "ROUT"},
717 
718 	{"LLINEIN", NULL, "Line In"},
719 	{"RLINEIN", NULL, "Line In"},
720 };
721 
722 SND_SOC_DAILINK_DEFS(tlv320aic23_hifi,
723 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
724 	DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "tlv320aic23-hifi")),
725 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
726 
727 static struct snd_soc_dai_link tegra_tlv320aic23_dai = {
728 	.name = "TLV320AIC23",
729 	.stream_name = "AIC23",
730 	.dai_fmt = SND_SOC_DAIFMT_I2S |
731 		   SND_SOC_DAIFMT_NB_NF |
732 		   SND_SOC_DAIFMT_CBS_CFS,
733 	SND_SOC_DAILINK_REG(tlv320aic23_hifi),
734 };
735 
736 static struct snd_soc_card snd_soc_tegra_trimslice = {
737 	.name = "tegra-trimslice",
738 	.components = "codec:tlv320aic23",
739 	.dai_link = &tegra_tlv320aic23_dai,
740 	.num_links = 1,
741 	.dapm_widgets = trimslice_dapm_widgets,
742 	.num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets),
743 	.dapm_routes = trimslice_audio_map,
744 	.num_dapm_routes = ARRAY_SIZE(trimslice_audio_map),
745 	.fully_routed = true,
746 };
747 
748 static const struct tegra_asoc_data tegra_trimslice_data = {
749 	.mclk_rate = tegra_machine_mclk_rate_128,
750 	.card = &snd_soc_tegra_trimslice,
751 	.add_common_snd_ops = true,
752 };
753 
754 /* RT5677 machine */
755 
756 static int tegra_rt5677_init(struct snd_soc_pcm_runtime *rtd)
757 {
758 	struct snd_soc_card *card = rtd->card;
759 	int err;
760 
761 	err = tegra_asoc_machine_init(rtd);
762 	if (err)
763 		return err;
764 
765 	snd_soc_dapm_force_enable_pin(&card->dapm, "MICBIAS1");
766 
767 	return 0;
768 }
769 
770 SND_SOC_DAILINK_DEFS(rt5677_aif1,
771 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
772 	DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "rt5677-aif1")),
773 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
774 
775 static struct snd_soc_dai_link tegra_rt5677_dai = {
776 	.name = "RT5677",
777 	.stream_name = "RT5677 PCM",
778 	.init = tegra_rt5677_init,
779 	.dai_fmt = SND_SOC_DAIFMT_I2S |
780 		   SND_SOC_DAIFMT_NB_NF |
781 		   SND_SOC_DAIFMT_CBS_CFS,
782 	SND_SOC_DAILINK_REG(rt5677_aif1),
783 };
784 
785 static struct snd_soc_card snd_soc_tegra_rt5677 = {
786 	.components = "codec:rt5677",
787 	.dai_link = &tegra_rt5677_dai,
788 	.num_links = 1,
789 	.fully_routed = true,
790 };
791 
792 static const struct tegra_asoc_data tegra_rt5677_data = {
793 	.mclk_rate = tegra_machine_mclk_rate_256,
794 	.card = &snd_soc_tegra_rt5677,
795 	.add_common_dapm_widgets = true,
796 	.add_common_controls = true,
797 	.add_common_snd_ops = true,
798 	.add_mic_jack = true,
799 	.add_hp_jack = true,
800 };
801 
802 /* RT5640 machine */
803 
804 SND_SOC_DAILINK_DEFS(rt5640_aif1,
805 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
806 	DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "rt5640-aif1")),
807 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
808 
809 static struct snd_soc_dai_link tegra_rt5640_dai = {
810 	.name = "RT5640",
811 	.stream_name = "RT5640 PCM",
812 	.init = tegra_asoc_machine_init,
813 	.dai_fmt = SND_SOC_DAIFMT_I2S |
814 		   SND_SOC_DAIFMT_NB_NF |
815 		   SND_SOC_DAIFMT_CBS_CFS,
816 	SND_SOC_DAILINK_REG(rt5640_aif1),
817 };
818 
819 static struct snd_soc_card snd_soc_tegra_rt5640 = {
820 	.components = "codec:rt5640",
821 	.dai_link = &tegra_rt5640_dai,
822 	.num_links = 1,
823 	.fully_routed = true,
824 };
825 
826 static const struct tegra_asoc_data tegra_rt5640_data = {
827 	.mclk_rate = tegra_machine_mclk_rate_256,
828 	.card = &snd_soc_tegra_rt5640,
829 	.add_common_dapm_widgets = true,
830 	.add_common_controls = true,
831 	.add_common_snd_ops = true,
832 	.add_hp_jack = true,
833 };
834 
835 /* RT5632 machine */
836 
837 SND_SOC_DAILINK_DEFS(rt5632_hifi,
838 	DAILINK_COMP_ARRAY(COMP_EMPTY()),
839 	DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "alc5632-hifi")),
840 	DAILINK_COMP_ARRAY(COMP_EMPTY()));
841 
842 static struct snd_soc_dai_link tegra_rt5632_dai = {
843 	.name = "ALC5632",
844 	.stream_name = "ALC5632 PCM",
845 	.init = tegra_rt5677_init,
846 	.dai_fmt = SND_SOC_DAIFMT_I2S |
847 		   SND_SOC_DAIFMT_NB_NF |
848 		   SND_SOC_DAIFMT_CBS_CFS,
849 	SND_SOC_DAILINK_REG(rt5632_hifi),
850 };
851 
852 static struct snd_soc_card snd_soc_tegra_rt5632 = {
853 	.components = "codec:rt5632",
854 	.dai_link = &tegra_rt5632_dai,
855 	.num_links = 1,
856 	.fully_routed = true,
857 };
858 
859 static const struct tegra_asoc_data tegra_rt5632_data = {
860 	.mclk_rate = tegra_machine_mclk_rate_512,
861 	.card = &snd_soc_tegra_rt5632,
862 	.add_common_dapm_widgets = true,
863 	.add_common_controls = true,
864 	.add_common_snd_ops = true,
865 	.add_headset_jack = true,
866 };
867 
868 static const struct of_device_id tegra_machine_of_match[] = {
869 	{ .compatible = "nvidia,tegra-audio-trimslice", .data = &tegra_trimslice_data },
870 	{ .compatible = "nvidia,tegra-audio-max98090", .data = &tegra_max98090_data },
871 	{ .compatible = "nvidia,tegra-audio-sgtl5000", .data = &tegra_sgtl5000_data },
872 	{ .compatible = "nvidia,tegra-audio-wm9712", .data = &tegra_wm9712_data },
873 	{ .compatible = "nvidia,tegra-audio-wm8753", .data = &tegra_wm8753_data },
874 	{ .compatible = "nvidia,tegra-audio-rt5677", .data = &tegra_rt5677_data },
875 	{ .compatible = "nvidia,tegra-audio-rt5640", .data = &tegra_rt5640_data },
876 	{ .compatible = "nvidia,tegra-audio-alc5632", .data = &tegra_rt5632_data },
877 	{},
878 };
879 MODULE_DEVICE_TABLE(of, tegra_machine_of_match);
880 
881 static struct platform_driver tegra_asoc_machine_driver = {
882 	.driver = {
883 		.name = "tegra-audio",
884 		.of_match_table = tegra_machine_of_match,
885 		.pm = &snd_soc_pm_ops,
886 	},
887 	.probe = tegra_asoc_machine_probe,
888 };
889 module_platform_driver(tegra_asoc_machine_driver);
890 
891 MODULE_AUTHOR("Anatol Pomozov <anatol@google.com>");
892 MODULE_AUTHOR("Andrey Danin <danindrey@mail.ru>");
893 MODULE_AUTHOR("Dmitry Osipenko <digetx@gmail.com>");
894 MODULE_AUTHOR("Ion Agorria <ion@agorria.com>");
895 MODULE_AUTHOR("Leon Romanovsky <leon@leon.nu>");
896 MODULE_AUTHOR("Lucas Stach <dev@lynxeye.de>");
897 MODULE_AUTHOR("Marc Dietrich <marvin24@gmx.de>");
898 MODULE_AUTHOR("Marcel Ziswiler <marcel@ziswiler.com>");
899 MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
900 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
901 MODULE_AUTHOR("Svyatoslav Ryhel <clamor95@gmail.com>");
902 MODULE_DESCRIPTION("Tegra machine ASoC driver");
903 MODULE_LICENSE("GPL");
904