-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacific_rt5659.c
More file actions
943 lines (800 loc) · 24.7 KB
/
pacific_rt5659.c
File metadata and controls
943 lines (800 loc) · 24.7 KB
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
/*
* pacific_arizona.c
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*/
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/clk.h>
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/gpio.h>
#include <sound/tlv.h>
#include <linux/input.h>
#include <linux/delay.h>
#include <linux/wakelock.h>
#include <linux/mutex.h>
#include <linux/mfd/arizona/registers.h>
#include <linux/mfd/arizona/core.h>
#include <sound/soc.h>
#include <sound/jack.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/initval.h>
#include <mach/exynos-audio.h>
#ifdef CONFIG_SWITCH
#include <linux/switch.h>
#endif
#include "i2s.h"
#include "i2s-regs.h"
#include "../codecs/rt5659.h"
#define WAKE_LOCK_TIME (HZ * 5) /* 5 sec */
/* PACIFIC use CLKOUT from AP */
#define PACIFIC_MCLK_FREQ 24000000
#ifdef CONFIG_SND_CODEC_CONTROL_MCLK
extern void es325_audio_set_mclk(bool enable, bool forced);
#endif
int rt5659_jack_status_check(void);
struct rt5659_machine_priv {
struct clk *mclk;
struct snd_soc_codec *codec;
struct snd_soc_jack rt5659_hp_jack;
struct snd_soc_jack_gpio rt5659_hp_jack_gpio;
int sub_mic_bias_gpio;
bool jd_status;
struct timer_list jd_check_timer;
struct work_struct jd_check_work;
#ifdef CONFIG_DYNAMIC_MICBIAS_CONTROL_RT5659
bool earmic_enabled;
#endif
struct mutex mutex;
struct wake_lock jack_wake_lock;
int det_delay_time;
};
static struct rt5659_machine_priv pacific_rt5659_priv = {
.rt5659_hp_jack_gpio = {
.name = "headphone detect",
.invert = 1,
.report = SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1
| SND_JACK_BTN_2 | SND_JACK_BTN_3,
.debounce_time = 0,
.wake = true,
.jack_status_check = rt5659_jack_status_check,
},
};
static const struct snd_soc_component_driver pacific_cmpnt = {
.name = "pacific-audio",
};
static const struct snd_kcontrol_new pacific_codec_controls[] = {
};
#ifdef CONFIG_SWITCH
static struct switch_dev rt5659_headset_switch = {
.name = "h2w",
};
/*
static int rt5659_jack_notifier(struct notifier_block *self,
unsigned long action, void *dev)
{
struct snd_soc_jack *jack = dev;
struct snd_soc_codec *codec = jack->codec;
struct snd_soc_card *card = codec->card;
struct rt5659_machine_priv *priv = card->drvdata;
if (jack == &priv->rt5659_hp_jack)
switch_set_state(&rt5659_headset_switch,
rt5659_get_jack_type(codec, action));
return NOTIFY_OK;
}
static struct notifier_block rt5659_jack_detect_nb = {
.notifier_call = rt5659_jack_notifier,
};
*/
#endif
int rt5659_jack_status_check(void)
{
struct snd_soc_codec *codec = pacific_rt5659_priv.codec;
#ifdef CONFIG_DYNAMIC_MICBIAS_CONTROL_RT5659
struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
#endif
int report = 0, ret;
/* prevent suspend to allow user space to respond to switch */
if (codec->card->instantiated)
wake_lock_timeout(&pacific_rt5659_priv.jack_wake_lock, WAKE_LOCK_TIME);
msleep(pacific_rt5659_priv.det_delay_time);
pr_info("%s start\n", __func__);
mutex_lock(&pacific_rt5659_priv.mutex);
if (rt5659_check_jd_status(codec) && !pacific_rt5659_priv.jd_status) {
pacific_rt5659_priv.jd_status = true;
ret = rt5659_get_jack_type(codec, 1);
switch_set_state(&rt5659_headset_switch, ret);
if (ret == 1) {
report |= SND_JACK_HEADSET;
pacific_rt5659_priv.det_delay_time = 50;
} else {
report |= SND_JACK_HEADPHONE;
}
printk("%s: Jack inserted - %d\n", __func__, ret);
} else if (rt5659_check_jd_status(codec) && pacific_rt5659_priv.jd_status) {
pr_info("%s esle if\n", __func__);
#ifdef CONFIG_DYNAMIC_MICBIAS_CONTROL_RT5659
if (!pacific_rt5659_priv.earmic_enabled)
rt5659_dynamic_control_micbias(MIC_BIAS_V2P70V);
#endif
switch (rt5659_button_detect(codec)) {
case 0x8000:
case 0x4000:
case 0x2000:
report |= SND_JACK_BTN_0;
break;
case 0x1000:
case 0x0800:
case 0x0400:
report |= SND_JACK_BTN_1;
break;
case 0x0200:
case 0x0100:
case 0x0080:
report |= SND_JACK_BTN_2;
break;
case 0x0040:
case 0x0020:
case 0x0010:
report |= SND_JACK_BTN_3;
break;
default:
#ifdef CONFIG_DYNAMIC_MICBIAS_CONTROL_RT5659
if (!pacific_rt5659_priv.earmic_enabled)
rt5659_dynamic_control_micbias(rt5659->pdata.dynamic_micb_ctrl_voltage);
#endif
break;
}
if (report)
printk("%s: Jack key pressed - %d\n", __func__, report);
else
printk("%s: Jack key realsed\n", __func__);
report |= SND_JACK_HEADSET;
if (report & (SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 | SND_JACK_BTN_3))
mod_timer(&pacific_rt5659_priv.jd_check_timer, jiffies);
else
del_timer(&pacific_rt5659_priv.jd_check_timer);
} else {
if (pacific_rt5659_priv.jd_status)
printk("%s: Jack removed\n", __func__);
pacific_rt5659_priv.jd_status = false;
rt5659_get_jack_type(codec, 0);
switch_set_state(&rt5659_headset_switch, 0);
pacific_rt5659_priv.det_delay_time = 200;
}
mutex_unlock(&pacific_rt5659_priv.mutex);
return report;
}
/*
static int rt5659_ext_submicbias(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
{
struct snd_soc_card *card = w->dapm->card;
struct rt5659_machine_priv *priv = card->drvdata;
switch (event) {
case SND_SOC_DAPM_PRE_PMU:
gpio_set_value(priv->sub_mic_bias_gpio, 1);
break;
case SND_SOC_DAPM_POST_PMD:
gpio_set_value(priv->sub_mic_bias_gpio, 0);
break;
}
dev_dbg(w->dapm->dev, "Sub Mic BIAS: %d mic_bias_gpio %d %d\n",
event, priv->sub_mic_bias_gpio, gpio_get_value(priv->sub_mic_bias_gpio));
return 0;
}
*/
static const struct snd_kcontrol_new pacific_controls[] = {
SOC_DAPM_PIN_SWITCH("HP"),
SOC_DAPM_PIN_SWITCH("SPK"),
SOC_DAPM_PIN_SWITCH("RCV"),
SOC_DAPM_PIN_SWITCH("Main Mic"),
SOC_DAPM_PIN_SWITCH("Sub Mic"),
SOC_DAPM_PIN_SWITCH("Headset Mic"),
};
const struct snd_soc_dapm_widget rt5659_dapm_widgets[] = {
SND_SOC_DAPM_HP("HP", NULL),
SND_SOC_DAPM_SPK("SPK", NULL),
SND_SOC_DAPM_SPK("RCV", NULL),
SND_SOC_DAPM_MIC("Headset Mic", NULL),
SND_SOC_DAPM_MIC("Main Mic", NULL),
SND_SOC_DAPM_MIC("Sub Mic", NULL),
};
const struct snd_soc_dapm_route pacific_rt5659_dapm_routes[] = {
{ "HP", NULL, "HPOL" },
{ "HP", NULL, "HPOR" },
{ "RCV", NULL, "MONOOUT" },
{ "SPK", NULL, "SPOL" },
{ "SPK", NULL, "SPOR" },
{ "IN1P", NULL, "MICBIAS1" },
{ "IN1P", NULL, "Headset Mic" },
{ "IN1N", NULL, "Headset Mic" },
{ "IN3P", NULL, "MICBIAS3" },
{ "IN3P", NULL, "Sub Mic" },
{ "IN3N", NULL, "Sub Mic" },
{ "IN4P", NULL, "MICBIAS2" },
{ "IN4P", NULL, "Main Mic" },
{ "IN4N", NULL, "Main Mic" },
};
static int pacific_aif_startup(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_card *card = rtd->card;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
dev_info(card->dev, "%s-%d startup ++, playback=%d, capture=%d\n",
rtd->dai_link->name, substream->stream,
codec_dai->playback_active, codec_dai->capture_active);
#ifdef CONFIG_DYNAMIC_MICBIAS_CONTROL_RT5659
if (strcmp(rtd->dai_link->name, "NXP")!=0 && substream->stream == SNDRV_PCM_STREAM_CAPTURE && pacific_rt5659_priv.jd_status) {
pacific_rt5659_priv.earmic_enabled = true;
rt5659_dynamic_control_micbias(MIC_BIAS_V2P70V);
}
#endif
return 0;
}
static void pacific_aif_shutdown(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_card *card = rtd->card;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
#ifdef CONFIG_DYNAMIC_MICBIAS_CONTROL_RT5659
struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(pacific_rt5659_priv.codec);
#endif
dev_info(card->dev, "%s-%d shutdown++ codec_dai[%s]:playback=%d\n",
rtd->dai_link->name, substream->stream,
codec_dai->name, codec_dai->playback_active);
#ifdef CONFIG_DYNAMIC_MICBIAS_CONTROL_RT5659
if (strcmp(rtd->dai_link->name, "NXP")!=0 && substream->stream == SNDRV_PCM_STREAM_CAPTURE && pacific_rt5659_priv.jd_status) {
pacific_rt5659_priv.earmic_enabled = false;
rt5659_dynamic_control_micbias(rt5659->pdata.dynamic_micb_ctrl_voltage);
}
#endif
return;
}
static int pacific_aif1_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_card *card = rtd->card;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
int ret;
dev_info(card->dev, "%s-%d %dch, %dHz, %dbytes\n",
rtd->dai_link->name, substream->stream,
params_channels(params), params_rate(params),
params_buffer_bytes(params));
/* Set Codec DAI configuration */
ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBM_CFM);
if (ret < 0) {
dev_err(card->dev, "Failed to set aif1 codec fmt: %d\n", ret);
return ret;
}
/* Set Codec DAI TDM configuration */
ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 0x3, 2, 32);
if (ret < 0) {
dev_err(card->dev, "Failed to set aif1 codec tdm fmt: %d\n", ret);
return ret;
}
/* Set CPU DAI configuration */
ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBM_CFM);
if (ret < 0) {
dev_err(card->dev, "Failed to set aif1 cpu fmt: %d\n", ret);
return ret;
}
ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_CDCLK,
0, SND_SOC_CLOCK_IN);
if (ret < 0) {
dev_err(card->dev, "Failed to set SAMSUNG_I2S_CDCL: %d\n", ret);
return ret;
}
ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_OPCLK,
0, MOD_OPCLK_PCLK);
if (ret < 0) {
dev_err(card->dev, "Failed to set SAMSUNG_I2S_OPCL: %d\n", ret);
return ret;
}
if (params_rate(params) == 192000) {
ret = snd_soc_dai_set_pll(codec_dai, 0, RT5659_PLL1_S_MCLK,
PACIFIC_MCLK_FREQ, 49152000);
if (ret < 0) {
dev_err(card->dev, "codec_dai pll not set\n");
return ret;
}
ret = snd_soc_dai_set_sysclk(codec_dai, RT5659_SCLK_S_PLL1,
49152000, SND_SOC_CLOCK_IN);
if (ret < 0) {
dev_err(card->dev, "codec_dai clock not set\n");
return ret;
}
} else {
ret = snd_soc_dai_set_pll(codec_dai, 0, RT5659_PLL1_S_MCLK,
PACIFIC_MCLK_FREQ, 24576000);
if (ret < 0) {
dev_err(card->dev, "codec_dai pll not set\n");
return ret;
}
ret = snd_soc_dai_set_sysclk(codec_dai, RT5659_SCLK_S_PLL1,
24576000, SND_SOC_CLOCK_IN);
if (ret < 0) {
dev_err(card->dev, "codec_dai clock not set\n");
return ret;
}
}
return ret;
}
static int pacific_aif1_hw_free(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_card *card = rtd->card;
dev_dbg(card->dev, "%s-%d\n hw_free",
rtd->dai_link->name, substream->stream);
return 0;
}
static int pacific_aif1_prepare(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_card *card = rtd->card;
dev_dbg(card->dev, "%s-%d prepare\n",
rtd->dai_link->name, substream->stream);
return 0;
}
static int pacific_aif1_trigger(struct snd_pcm_substream *substream, int cmd)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_card *card = rtd->card;
dev_dbg(card->dev, "%s-%d trigger\n",
rtd->dai_link->name, substream->stream);
return 0;
}
static struct snd_soc_ops pacific_aif1_ops = {
.startup = pacific_aif_startup,
.shutdown = pacific_aif_shutdown,
.hw_params = pacific_aif1_hw_params,
.hw_free = pacific_aif1_hw_free,
.prepare = pacific_aif1_prepare,
.trigger = pacific_aif1_trigger,
};
static int pacific_aif2_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_card *card = rtd->card;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
int prate, bclk, ret;
dev_info(card->dev, "%s-%d %dch, %dHz\n",
rtd->dai_link->name, substream->stream,
params_channels(params), params_rate(params));
prate = params_rate(params);
switch (prate) {
case 16000:
bclk = 512000;
break;
default:
dev_warn(card->dev,
"Unsupported LRCLK %d, falling back to 16000Hz\n",
(int)params_rate(params));
bclk = 512000;
}
/* Set Codec DAI configuration */
ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS);
if (ret < 0) {
dev_err(card->dev, "Failed to set aif1 codec fmt: %d\n", ret);
return ret;
}
ret = snd_soc_dai_set_pll(codec_dai, 0, RT5659_PLL1_S_MCLK,
PACIFIC_MCLK_FREQ, 24576000);
if (ret < 0) {
dev_err(card->dev, "codec_dai pll not set\n");
return ret;
}
ret = snd_soc_dai_set_sysclk(codec_dai, RT5659_SCLK_S_PLL1,
24576000, SND_SOC_CLOCK_IN);
if (ret < 0) {
dev_err(card->dev, "codec_dai clock not set\n");
return ret;
}
return 0;
}
static struct snd_soc_ops pacific_aif2_ops = {
.startup = pacific_aif_startup,
.shutdown = pacific_aif_shutdown,
.hw_params = pacific_aif2_hw_params,
};
static int pacific_aif3_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_card *card = rtd->card;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
int ret;
dev_info(card->dev, "%s-%d %dch, %dHz\n",
rtd->dai_link->name, substream->stream,
params_channels(params), params_rate(params));
ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBM_CFM);
if (ret < 0) {
dev_err(codec_dai->dev, "Failed to set BT mode: %d\n", ret);
return ret;
}
ret = snd_soc_dai_set_pll(codec_dai, 0, RT5659_PLL1_S_MCLK,
PACIFIC_MCLK_FREQ, 24576000);
if (ret < 0) {
dev_err(card->dev, "codec_dai pll not set\n");
return ret;
}
ret = snd_soc_dai_set_sysclk(codec_dai, RT5659_SCLK_S_PLL1,
24576000, SND_SOC_CLOCK_IN);
if (ret < 0) {
dev_err(card->dev, "codec_dai clock not set\n");
return ret;
}
return 0;
}
static struct snd_soc_ops pacific_aif3_ops = {
.startup = pacific_aif_startup,
.shutdown = pacific_aif_shutdown,
.hw_params = pacific_aif3_hw_params,
};
static struct snd_soc_dai_link pacific_rt5659_dai[] = {
{ /* playback & recording */
.name = "playback-pri",
.stream_name = "playback-pri",
.codec_dai_name = "rt5659-aif1",
.ops = &pacific_aif1_ops,
},
{ /* voice call */
.name = "baseband",
.stream_name = "baseband",
.cpu_dai_name = "snd-soc-dummy-dai",
.platform_name = "snd-soc-dummy",
.codec_dai_name = "rt5659-aif2",
.ops = &pacific_aif2_ops,
.ignore_suspend = 1,
},
{ /* bluetooth sco */
.name = "bluetooth sco",
.stream_name = "bluetooth sco",
.cpu_dai_name = "snd-soc-dummy-dai",
.platform_name = "snd-soc-dummy",
.codec_dai_name = "rt5659-aif3",
.ops = &pacific_aif3_ops,
.ignore_suspend = 1,
},
{ /* deep buffer playback */
.name = "playback-sec",
.stream_name = "playback-sec",
.cpu_dai_name = "samsung-i2s-sec",
.platform_name = "samsung-i2s-sec",
.codec_dai_name = "rt5659-aif1",
.ops = &pacific_aif1_ops,
},
{ /* eax0 playback */
.name = "playback-eax0",
.stream_name = "playback-eax0",
.cpu_dai_name = "samsung-eax.0",
.platform_name = "samsung-eax.0",
.codec_dai_name = "rt5659-aif1",
.ops = &pacific_aif1_ops,
},
{ /* NXP */
.name = "NXP",
.stream_name = "NXP SPEAK",
.cpu_dai_name = "snd-soc-dummy-dai",
.platform_name = "snd-soc-dummy",
.codec_dai_name = "rt5659-aif3",
.ops = &pacific_aif3_ops,
.ignore_suspend = 1,
},
{ /* eax1 playback */
.name = "playback-eax1",
.stream_name = "playback-eax1",
.cpu_dai_name = "samsung-eax.1",
.platform_name = "samsung-eax.1",
.codec_dai_name = "rt5659-aif1",
.ops = &pacific_aif1_ops,
},
{ /* eax2 playback */
.name = "playback-eax2",
.stream_name = "playback-eax2",
.cpu_dai_name = "samsung-eax.2",
.platform_name = "samsung-eax.2",
.codec_dai_name = "rt5659-aif1",
.ops = &pacific_aif1_ops,
},
{ /* eax3playback */
.name = "playback-eax3",
.stream_name = "playback-eax3",
.cpu_dai_name = "samsung-eax.3",
.platform_name = "samsung-eax.3",
.codec_dai_name = "rt5659-aif1",
.ops = &pacific_aif1_ops,
},
};
static int pacific_of_get_pdata(struct snd_soc_card *card)
{
struct device_node *pdata_np;
struct rt5659_machine_priv *priv = card->drvdata;
int ret;
pdata_np = of_find_node_by_path("/audio_pdata");
if (!pdata_np) {
dev_err(card->dev,
"Property 'samsung,audio-pdata' missing or invalid\n");
return -EINVAL;
}
priv->rt5659_hp_jack_gpio.gpio = of_get_named_gpio(pdata_np, "hp_det_gpio", 0);
priv->sub_mic_bias_gpio = of_get_named_gpio(pdata_np, "sub_mic_bias_gpio", 0);
if (priv->sub_mic_bias_gpio >= 0) {
ret = gpio_request(priv->sub_mic_bias_gpio, "MICBIAS_EN_AP");
if (ret)
dev_err(card->dev, "Failed to request gpio: %d\n", ret);
gpio_direction_output(priv->sub_mic_bias_gpio, 0);
}
return 0;
}
static void jd_check_handler(struct work_struct *work)
{
struct snd_soc_codec *codec = pacific_rt5659_priv.codec;
if (!rt5659_check_jd_status(codec)) {
pacific_rt5659_priv.jd_status = false;
rt5659_get_jack_type(codec, 0);
switch_set_state(&rt5659_headset_switch, 0);
snd_soc_jack_report(&pacific_rt5659_priv.rt5659_hp_jack, 0,
pacific_rt5659_priv.rt5659_hp_jack_gpio.report);
del_timer(&pacific_rt5659_priv.jd_check_timer);
}
}
static void jd_check_callback(unsigned long data)
{
schedule_work(&pacific_rt5659_priv.jd_check_work);
if (mod_timer(&pacific_rt5659_priv.jd_check_timer,
jiffies + msecs_to_jiffies(500)))
printk(KERN_INFO "Error in mod_timer\n");
}
static int pacific_late_probe(struct snd_soc_card *card)
{
struct snd_soc_codec *codec = card->rtd[0].codec;
struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
struct snd_soc_dai *cpu_dai = card->rtd[0].cpu_dai;
struct rt5659_machine_priv *priv = card->drvdata;
struct snd_soc_jack *jack = &priv->rt5659_hp_jack;
int ret;
priv->codec = codec;
priv->jd_status = false;
pacific_of_get_pdata(card);
codec_dai->driver->playback.channels_max =
cpu_dai->driver->playback.channels_max;
/* close codec device immediately when pcm is closed */
codec->ignore_pmdown_time = true;
ret = snd_soc_add_codec_controls(codec, pacific_codec_controls,
ARRAY_SIZE(pacific_codec_controls));
if (ret < 0) {
dev_err(codec->dev,
"Failed to add controls to codec: %d\n", ret);
return ret;
}
snd_soc_dapm_ignore_suspend(&card->dapm, "Main Mic");
snd_soc_dapm_ignore_suspend(&card->dapm, "Sub Mic");
snd_soc_dapm_ignore_suspend(&card->dapm, "Headset Mic");
snd_soc_dapm_ignore_suspend(&card->dapm, "RCV");
snd_soc_dapm_ignore_suspend(&card->dapm, "SPK");
snd_soc_dapm_ignore_suspend(&card->dapm, "HP");
snd_soc_dapm_sync(&card->dapm);
snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2 Playback");
snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2 Capture");
snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3 Playback");
snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3 Capture");
snd_soc_dapm_sync(&codec->dapm);
setup_timer(&priv->jd_check_timer, jd_check_callback, 0);
INIT_WORK(&priv->jd_check_work, jd_check_handler);
mutex_init(&priv->mutex);
if (gpio_is_valid(priv->rt5659_hp_jack_gpio.gpio)) {
snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
jack);
#ifdef CONFIG_SWITCH
/*
snd_soc_jack_notifier_register(jack, &rt5659_jack_detect_nb);
*/
#endif
snd_soc_jack_add_gpios(jack, 1, &priv->rt5659_hp_jack_gpio);
snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_MEDIA);
snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
}
priv->det_delay_time = 200;
wake_lock_init(&priv->jack_wake_lock, WAKE_LOCK_SUSPEND, "jack_det");
return 0;
}
static int pacific_start_sysclk(struct snd_soc_card *card)
{
struct rt5659_machine_priv *priv = card->drvdata;
if (priv->mclk) {
clk_enable(priv->mclk);
dev_info(card->dev, "mclk enabled\n");
} else{
#ifdef CONFIG_SND_CODEC_CONTROL_MCLK
es325_audio_set_mclk(true, 0);
#else
exynos5_audio_set_mclk(true, 0);
#endif
}
return 0;
}
static int pacific_stop_sysclk(struct snd_soc_card *card)
{
struct rt5659_machine_priv *priv = card->drvdata;
if (priv->mclk) {
clk_disable(priv->mclk);
dev_info(card->dev, "mclk disbled\n");
} else{
#ifdef CONFIG_SND_CODEC_CONTROL_MCLK
es325_audio_set_mclk(false, 0);
#else
exynos5_audio_set_mclk(false, 0);
#endif
}
return 0;
}
static int pacific_set_bias_level(struct snd_soc_card *card,
struct snd_soc_dapm_context *dapm,
enum snd_soc_bias_level level)
{
struct rt5659_machine_priv *priv = card->drvdata;
if (!priv->codec || dapm != &priv->codec->dapm)
return 0;
switch (level) {
case SND_SOC_BIAS_STANDBY:
if (card->dapm.bias_level == SND_SOC_BIAS_PREPARE)
pacific_stop_sysclk(card);
break;
case SND_SOC_BIAS_PREPARE:
if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY)
pacific_start_sysclk(card);
break;
default:
break;
}
card->dapm.bias_level = level;
dev_dbg(card->dev, "%s: %d\n", __func__, level);
return 0;
}
static int pacific_set_bias_level_post(struct snd_soc_card *card,
struct snd_soc_dapm_context *dapm,
enum snd_soc_bias_level level)
{
dev_dbg(card->dev, "%s: %d\n", __func__, level);
return 0;
}
static int pacific_suspend_post(struct snd_soc_card *card)
{
dev_info(card->dev, "%s: \n", __func__);
return 0;
}
static int pacific_resume_pre(struct snd_soc_card *card)
{
dev_info(card->dev, "%s: \n", __func__);
return 0;
}
static struct snd_soc_card pacific_cards = {
.name = "Pacific ALC5659 Sound",
.owner = THIS_MODULE,
.dai_link = pacific_rt5659_dai,
.num_links = ARRAY_SIZE(pacific_rt5659_dai),
.controls = pacific_controls,
.num_controls = ARRAY_SIZE(pacific_controls),
.dapm_widgets = rt5659_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(rt5659_dapm_widgets),
.dapm_routes = pacific_rt5659_dapm_routes,
.num_dapm_routes = ARRAY_SIZE(pacific_rt5659_dapm_routes),
.late_probe = pacific_late_probe,
.suspend_post = pacific_suspend_post,
.resume_pre = pacific_resume_pre,
.set_bias_level = pacific_set_bias_level,
.set_bias_level_post = pacific_set_bias_level_post,
.drvdata = &pacific_rt5659_priv,
};
static int pacific_audio_probe(struct platform_device *pdev)
{
int n, ret;
struct device_node *np = pdev->dev.of_node;
struct device_node *codec_np, *cpu_np;
struct snd_soc_card *card;
struct snd_soc_dai_link *dai_link;
struct rt5659_machine_priv *priv;
card = &pacific_cards;
dai_link = card->dai_link;
card->dev = &pdev->dev;
priv = card->drvdata;
priv->mclk = devm_clk_get(card->dev, "mclk");
if (IS_ERR(priv->mclk)) {
dev_dbg(card->dev, "%s :Device tree node not found for mclk", __func__);
priv->mclk = NULL;
} else
clk_prepare(priv->mclk);
for (n = 0; n < card->num_links; n++) {
if (!dai_link[n].cpu_name && !dai_link[n].cpu_dai_name) {
cpu_np = of_parse_phandle(np, "samsung,audio-cpu", n);
if (cpu_np) {
dai_link[n].cpu_of_node = cpu_np;
dai_link[n].platform_of_node = cpu_np;
} else
dev_err(&pdev->dev, "Property 'samsung,audio-cpu'"
": dai_link[%d] missing or invalid\n",n);
}
if (!dai_link[n].codec_name) {
codec_np = of_parse_phandle(np, "samsung,audio-codec", n);
if (codec_np)
dai_link[n].codec_of_node = codec_np;
else
dev_err(&pdev->dev, "Property 'samsung,audio-codec'"
": dai_link[%d] missing or invalid\n", n);
}
}
#ifdef CONFIG_SWITCH
/* Addd h2w swith class support */
ret = switch_dev_register(&rt5659_headset_switch);
if (ret < 0) {
dev_err(&pdev->dev, "switch_dev_register() failed: %d\n",
ret);
}
#endif
ret = snd_soc_register_card(card);
if (ret)
dev_err(&pdev->dev, "Failed to register card:%d\n", ret);
else
dev_err(&pdev->dev, "Success register card:%d\n", ret);
return ret;
}
static int pacific_audio_remove(struct platform_device *pdev)
{
struct snd_soc_card *card = platform_get_drvdata(pdev);
struct rt5659_machine_priv *priv = card->drvdata;
snd_soc_unregister_component(card->dev);
snd_soc_unregister_card(card);
if (priv->mclk) {
clk_unprepare(priv->mclk);
devm_clk_put(card->dev, priv->mclk);
}
#ifdef CONFIG_SWITCH
switch_dev_unregister(&rt5659_headset_switch);
#endif
snd_soc_jack_free_gpios(&priv->rt5659_hp_jack, 1,
&priv->rt5659_hp_jack_gpio);
wake_lock_destroy(&priv->jack_wake_lock);
return 0;
}
static const struct of_device_id pacific_arizona_of_match[] = {
{ .compatible = "samsung,pacific-rt5659", },
{ },
};
MODULE_DEVICE_TABLE(of, pacific_arizona_of_match);
static struct platform_driver pacific_audio_driver = {
.driver = {
.name = "pacific-audio",
.owner = THIS_MODULE,
.pm = &snd_soc_pm_ops,
.of_match_table = of_match_ptr(pacific_arizona_of_match),
#ifdef CONFIG_MULTITHREAD_PROBE
.multithread_probe = 1,
#endif
},
.probe = pacific_audio_probe,
.remove = pacific_audio_remove,
};
module_platform_driver(pacific_audio_driver);
MODULE_DESCRIPTION("ALSA SoC PACIFIC RT5659");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:pacific-audio");