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