/
ctp_rhb_wm1811.c
executable file
·992 lines (855 loc) · 26.2 KB
/
ctp_rhb_wm1811.c
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
/*
* ctp_rhb_wm1811.c - ASoc Machine driver for Intel Cloverview MID platform
*
* Copyright (C) 2011-13 Intel Corp
* Author: Ted Choi<ted.choi@intel.com>
* Author: KP Jeeja<jeeja.kp@intel.com>
* Author: Vaibhav Agarwal <vaibhav.agarwal@intel.com>
* Author: Dharageswari.R<dharageswari.r@intel.com>
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* 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; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/async.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/mfd/wm8994/registers.h>
#include <linux/mfd/wm8994/pdata.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/jack.h>
#include "../codecs/wm8994.h"
#include "ctp_common.h"
#include "ctp_rhb_wm1811.h"
#define MCLK2_FREQ 32768
/* Headset jack detection gpios func(s) */
#define HPDETECT_POLL_INTERVAL msecs_to_jiffies(1000) /* 1sec */
static int aif2_mode;
const char *aif2_mode_text[] = {
"Slave", "Master"
};
static int lineout_mode;
const char *lineout_mode_text[] = {
"Off", "On"
};
static int aif2_digital_mute;
const char *switch_mode_text[] = {
"Off", "On"
};
static int gpio_vps_sound_en;
static const struct soc_enum lineout_mode_enum[] = {
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lineout_mode_text), lineout_mode_text),
};
static int get_lineout_mode(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
ucontrol->value.integer.value[0] = lineout_mode;
return 0;
}
static int set_lineout_mode(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
lineout_mode = ucontrol->value.integer.value[0];
dev_dbg(codec->dev, "set lineout mode : %s\n",
lineout_mode_text[lineout_mode]);
return 0;
}
static int ctp_lineout_switch(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
{
struct snd_soc_codec *codec = w->codec;
dev_dbg(codec->dev, "%s event is %02X", w->name, event);
switch (event) {
case SND_SOC_DAPM_POST_PMU:
gpio_set_value(gpio_vps_sound_en, 1);
dev_dbg(codec->dev, "%s(%d) on\n", __func__, gpio_vps_sound_en);
break;
case SND_SOC_DAPM_PRE_PMD:
gpio_set_value(gpio_vps_sound_en, 0);
dev_dbg(codec->dev, "%s(%d) off\n", __func__, gpio_vps_sound_en);
break;
}
return 0;
}
static const struct soc_enum aif2_mode_enum[] = {
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(aif2_mode_text), aif2_mode_text),
};
static int get_aif2_mode(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
ucontrol->value.integer.value[0] = aif2_mode;
return 0;
}
static int set_aif2_mode(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
if (aif2_mode == ucontrol->value.integer.value[0])
return 0;
aif2_mode = ucontrol->value.integer.value[0];
pr_info("set aif2 mode : %s\n", aif2_mode_text[aif2_mode]);
return 0;
}
static int ctp_bias1_event(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
{
struct snd_soc_codec *codec = w->codec;
int reg = 0;
reg = snd_soc_read(codec, WM8994_POWER_MANAGEMENT_1);
switch (event) {
case SND_SOC_DAPM_POST_PMU:
pr_info("wm1811: %s event is %02X", w->name, event);
snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
WM8994_INPUTS_CLAMP, WM8994_INPUTS_CLAMP);
msleep(200);
snd_soc_update_bits(codec, WM8994_INPUT_MIXER_1,
WM8994_INPUTS_CLAMP, 0);
break;
default:
break;
}
return 0;
}
static const struct soc_enum switch_mode_enum[] = {
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(switch_mode_text), switch_mode_text),
};
static int get_aif2_mute_status(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
ucontrol->value.integer.value[0] = aif2_digital_mute;
return 0;
}
static int set_aif2_mute_status(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
struct snd_soc_codec * codec = card->rtd->codec;
int reg;
aif2_digital_mute = ucontrol->value.integer.value[0];
if (snd_soc_read(codec, WM8994_POWER_MANAGEMENT_6)
& WM8994_AIF2_DACDAT_SRC)
aif2_digital_mute = 0;
if (aif2_digital_mute)
reg = WM8994_AIF1DAC1_MUTE;
else
reg = 0;
snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_1,
WM8994_AIF1DAC1_MUTE, reg);
pr_info("set aif2_digital_mute : %s\n",
switch_mode_text[aif2_digital_mute]);
return 0;
}
struct snd_soc_machine_ops ctp_rhb_ops = {
.ctp_init = ctp_init,
.dai_link = ctp_dai_link,
};
inline void *ctp_get_rhb_ops(void)
{
return &ctp_rhb_ops;
}
EXPORT_SYMBOL(ctp_get_rhb_ops);
/* wm8994 widgets */
static const struct snd_soc_dapm_widget ctp_dapm_widgets[] = {
SND_SOC_DAPM_HP("HP", NULL),
SND_SOC_DAPM_SPK("SPK", NULL),
SND_SOC_DAPM_LINE("LINE", ctp_lineout_switch),
SND_SOC_DAPM_LINE("HDMI", NULL),
SND_SOC_DAPM_MIC("Headset Mic", NULL),
SND_SOC_DAPM_MIC("Main Mic", NULL),
SND_SOC_DAPM_MICBIAS_E("BIAS1 Event", WM8994_POWER_MANAGEMENT_1, 4, 0,
ctp_bias1_event, SND_SOC_DAPM_POST_PMU),
};
/* wm8994 Audio Map */
static const struct snd_soc_dapm_route ctp_audio_map[] = {
{ "HP", NULL, "HPOUT1L" },
{ "HP", NULL, "HPOUT1R" },
{ "SPK", NULL, "SPKOUTLN" },
{ "SPK", NULL, "SPKOUTLP" },
{ "SPK", NULL, "SPKOUTRN" },
{ "SPK", NULL, "SPKOUTRP" },
{ "LINE", NULL, "LINEOUT2N" },
{ "LINE", NULL, "LINEOUT2P" },
{ "HDMI", NULL, "LINEOUT1N" },
{ "HDMI", NULL, "LINEOUT1P" },
{ "IN2LP:VXRN", NULL, "BIAS1 Event" },
{ "IN2LN", NULL, "BIAS1 Event" },
{ "BIAS1 Event", NULL, "Main Mic" },
{ "IN1LP", NULL, "Headset Mic" },
{ "IN1LN", NULL, "Headset Mic" },
};
static int ctp_comms_dai_link_startup(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *str_runtime;
str_runtime = substream->runtime;
WARN(!substream->pcm, "CTP Comms Machine: ERROR NULL substream->pcm\n");
if (!substream->pcm)
return -EINVAL;
/* set the runtime hw parameter with local snd_pcm_hardware struct */
switch (substream->pcm->device) {
case CTP_COMMS_BT_SCO_DEV:
str_runtime->hw = BT_sco_hw_param;
break;
case CTP_COMMS_MSIC_VOIP_DEV:
str_runtime->hw = VOIP_alsa_hw_param;
break;
case CTP_COMMS_IFX_MODEM_DEV:
str_runtime->hw = IFX_modem_alsa_hw_param;
break;
default:
pr_err("CTP Comms Machine: bad PCM Device = %d\n",
substream->pcm->device);
}
return snd_pcm_hw_constraint_integer(str_runtime,
SNDRV_PCM_HW_PARAM_PERIODS);
}
int ctp_startup_fm_xsp(struct snd_pcm_substream *substream)
{
pr_debug("%s - applying rate constraint\n", __func__);
snd_pcm_hw_constraint_list(substream->runtime, 0,
SNDRV_PCM_HW_PARAM_RATE,
&constraints_48000);
return 0;
}
int ctp_set_asp_clk_fmt(struct snd_soc_dai *codec_dai)
{
unsigned int fmt;
int ret;
unsigned int pll_out;
/* WM1811 Master Mode`*/
fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBM_CFM;
/* Set codec DAI configuration */
ret = snd_soc_dai_set_fmt(codec_dai, fmt);
if (ret < 0) {
pr_err("can't set codec DAI configuration %d\n", ret);
return ret;
}
pll_out = 48000 * 256; // LPE send always 48kHz
ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, WM8994_FLL_SRC_MCLK1,
DEFAULT_MCLK, pll_out);
if (ret < 0)
return ret;
ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
pll_out, SND_SOC_CLOCK_IN);
if (ret < 0)
return ret;
return 0;
}
static int ctp_asp_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 = rtd->codec_dai;
return ctp_set_asp_clk_fmt(codec_dai);
}
static int clv_asp_set_params(struct snd_compr_stream *cstream)
{
struct snd_soc_pcm_runtime *rtd = cstream->private_data;
struct snd_soc_dai *codec_dai = rtd->codec_dai;
return ctp_set_asp_clk_fmt(codec_dai);
}
static int ctp_vsp_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 = rtd->codec_dai;
int pll_out = params_rate(params);
int ret, bclk;
switch (pll_out) {
case 8000:
case 16000:
break;
default:
dev_warn(codec_dai->dev, "Unsupported LRCLK %d, falling back to 8000Hz\n",
(int)params_rate(params));
pll_out = 8000;
}
/* Set the codec DAI configuration, aif2_mode:0 is slave */
if (aif2_mode == 0)
ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBS_CFS);
else
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)
return ret;
switch (pll_out) {
case 8000: bclk = 256000; break;
case 16000: bclk = 512000; break;
default:
return -EINVAL;
}
if (aif2_mode == 0) {
ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2,
WM8994_FLL_SRC_BCLK,
bclk, pll_out * 256);
} else {
ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2, WM8994_FLL_SRC_MCLK1,
DEFAULT_MCLK, pll_out * 256);
}
if (ret < 0)
dev_err(codec_dai->dev, "Unable to configure FLL2: %d\n", ret);
ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL2,
pll_out * 256, SND_SOC_CLOCK_IN); //CHECK_OUT? IN?
if (ret < 0)
dev_err(codec_dai->dev, "Unable to switch to FLL2: %d\n", ret);
return 0;
}
static bool playback_stream_status;
static bool capture_stream_status;
static int ctp_btsco_startup(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_codec *codec = rtd->codec;
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
struct wm8994_pdata *pdata = wm8994->pdata;
int base = WM8994_GPIO_8 - WM8994_GPIO_1;
int i;
pr_err("%s: enter\n", __func__);
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
capture_stream_status = 1;
else
playback_stream_status = 1;
for (i = 0; i < 4; i++) {
if (pdata->gpio_defaults[base + i]) {
snd_soc_update_bits(wm8994->codec, WM8994_GPIO_8 + i,
0xffff,
pdata->gpio_defaults[base + i]);
}
}
return 0;
}
static void ctp_btsco_shutdown(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_codec *codec = rtd->codec;
struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
int i;
pr_err("%s: enter, stream=%d\n", __func__, substream->stream);
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
capture_stream_status = 0;
else
playback_stream_status = 0;
if (playback_stream_status || capture_stream_status)
return;
pr_info("%s: set input gpios for AIF3\n", __func__);
for (i = 0; i < 4; i++) {
snd_soc_update_bits(wm8994->codec, WM8994_GPIO_8 + i,
0xffff,
0xA101);
}
return;
}
static int ctp_btsco_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
return 0;
}
static int ctp_comms_dai_link_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 *cpu_dai = rtd->cpu_dai;
struct snd_soc_card *soc_card = rtd->card;
struct ctp_mc_private *ctx = snd_soc_card_get_drvdata(soc_card);
struct comms_mc_private *ctl = &(ctx->comms_ctl);
int ret = 0;
unsigned int tx_mask, rx_mask;
unsigned int nb_slot = 0;
unsigned int slot_width = 0;
unsigned int tristate_offset = 0;
unsigned int device = substream->pcm->device;
pr_debug("ssp_bt_sco_master_mode %d\n", ctl->ssp_bt_sco_master_mode);
pr_debug("ssp_voip_master_mode %d\n", ctl->ssp_voip_master_mode);
pr_debug("ssp_modem_master_mode %d\n", ctl->ssp_modem_master_mode);
switch (device) {
case CTP_COMMS_BT_SCO_DEV:
/*
* set cpu DAI configuration
* frame_format = PSP_FORMAT
* ssp_serial_clk_mode = SSP_CLK_MODE_1
* ssp_frmsync_pol_bit = SSP_FRMS_ACTIVE_HIGH
*/
ret = snd_soc_dai_set_fmt(cpu_dai,
SND_SOC_DAIFMT_I2S |
SSP_DAI_SCMODE_1 |
SND_SOC_DAIFMT_NB_NF |
(ctl->ssp_bt_sco_master_mode ?
SND_SOC_DAIFMT_CBM_CFM : SND_SOC_DAIFMT_CBS_CFS));
if (ret < 0) {
pr_err("MFLD Comms Machine: Set FMT Fails %d\n",
ret);
return -EINVAL;
}
/*
* BT SCO SSP Config
* ssp_active_tx_slots_map = 0x01
* ssp_active_rx_slots_map = 0x01
* frame_rate_divider_control = 1
* data_size = 16
* tristate = 1
* ssp_frmsync_timing_bit = 0
* (NEXT_FRMS_ASS_AFTER_END_OF_T4)
* ssp_frmsync_timing_bit = 1
* (NEXT_FRMS_ASS_WITH_LSB_PREVIOUS_FRM)
* ssp_psp_T2 = 1
* (Dummy start offset = 1 bit clock period)
*/
nb_slot = SSP_BT_SLOT_NB_SLOT;
slot_width = SSP_BT_SLOT_WIDTH;
tx_mask = SSP_BT_SLOT_TX_MASK;
rx_mask = SSP_BT_SLOT_RX_MASK;
if (ctl->ssp_bt_sco_master_mode)
tristate_offset = BIT(TRISTATE_BIT);
else
tristate_offset = BIT(FRAME_SYNC_RELATIVE_TIMING_BIT);
break;
case CTP_COMMS_MSIC_VOIP_DEV:
/*
* set cpu DAI configuration
* frame_format = PSP_FORMAT
* ssp_serial_clk_mode = SSP_CLK_MODE_0
* ssp_frmsync_pol_bit = SSP_FRMS_ACTIVE_LOW
*/
ret = snd_soc_dai_set_fmt(cpu_dai,
SND_SOC_DAIFMT_I2S |
SSP_DAI_SCMODE_0 |
SND_SOC_DAIFMT_NB_IF |
(ctl->ssp_voip_master_mode ?
SND_SOC_DAIFMT_CBM_CFM : SND_SOC_DAIFMT_CBS_CFS));
if (ret < 0) {
pr_err("MFLD Comms Machine: Set FMT Fails %d\n",
ret);
return -EINVAL;
}
/*
* MSIC VOIP SSP Config
* ssp_active_tx_slots_map = 0x01
* ssp_active_rx_slots_map = 0x01
* frame_rate_divider_control = 1
* data_size = 32
* tristate = 1
* ssp_frmsync_timing_bit = 0, for SLAVE
* (NEXT_FRMS_ASS_AFTER_END_OF_T4)
* ssp_frmsync_timing_bit = 1, for MASTER
* (NEXT_FRMS_ASS_WITH_LSB_PREVIOUS_FRM)
*
*
*/
nb_slot = SSP_VOIP_SLOT_NB_SLOT;
slot_width = SSP_VOIP_SLOT_WIDTH;
tx_mask = SSP_VOIP_SLOT_TX_MASK;
rx_mask = SSP_VOIP_SLOT_RX_MASK;
tristate_offset = BIT(TRISTATE_BIT);
break;
case CTP_COMMS_IFX_MODEM_DEV:
/*
* set cpu DAI configuration
* frame_format = PSP_FORMAT
* ssp_serial_clk_mode = SSP_CLK_MODE_0
* ssp_frmsync_pol_bit = SSP_FRMS_ACTIVE_HIGH
*/
ret = snd_soc_dai_set_fmt(cpu_dai,
SND_SOC_DAIFMT_I2S |
SSP_DAI_SCMODE_0 |
SND_SOC_DAIFMT_NB_NF |
(ctl->ssp_modem_master_mode ?
SND_SOC_DAIFMT_CBM_CFM : SND_SOC_DAIFMT_CBS_CFS));
if (ret < 0) {
pr_err("MFLD Comms Machine: Set FMT Fails %d\n", ret);
return -EINVAL;
}
/*
* IFX Modem Mixing SSP Config
* ssp_active_tx_slots_map = 0x01
* ssp_active_rx_slots_map = 0x01
* frame_rate_divider_control = 1
* data_size = 32
* Master:
* tristate = 3
* ssp_frmsync_timing_bit = 1, for MASTER
* (NEXT_FRMS_ASS_WITH_LSB_PREVIOUS_FRM)
* Slave:
* tristate = 1
* ssp_frmsync_timing_bit = 0, for SLAVE
* (NEXT_FRMS_ASS_AFTER_END_OF_T4)
*
*/
nb_slot = SSP_IFX_SLOT_NB_SLOT;
slot_width = SSP_IFX_SLOT_WIDTH;
tx_mask = SSP_IFX_SLOT_TX_MASK;
rx_mask = SSP_IFX_SLOT_RX_MASK;
tristate_offset = BIT(TRISTATE_BIT) |\
BIT(FRAME_SYNC_RELATIVE_TIMING_BIT);
break;
default:
pr_err("CTP Comms Machine: bad PCM Device ID = %d\n",
device);
return -EINVAL;
}
ret = snd_soc_dai_set_tdm_slot(cpu_dai, tx_mask,
rx_mask, nb_slot, slot_width);
if (ret < 0) {
pr_err("CTP Comms Machine: Set TDM Slot Fails %d\n",
ret);
return -EINVAL;
}
ret = snd_soc_dai_set_tristate(cpu_dai, tristate_offset);
if (ret < 0) {
pr_err("CTP Comms Machine: Set Tristate Fails %d\n",
ret);
return -EINVAL;
}
if (device == CTP_COMMS_MSIC_VOIP_DEV) {
pr_debug("Call ctp_vsp_hw_params to enable the PLL Codec\n");
ctp_vsp_hw_params(substream, params);
}
pr_debug("CTP Comms Machine: slot_width = %d\n",
slot_width);
pr_debug("CTP Comms Machine: tx_mask = %d\n",
tx_mask);
pr_debug("CTP Comms Machine: rx_mask = %d\n",
rx_mask);
pr_debug("CTP Comms Machine: tristate_offset = %d\n",
tristate_offset);
return 0;
} /* ctp_comms_dai_link_hw_params*/
static int ctp_comms_dai_link_prepare(struct snd_pcm_substream *substream)
{
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
struct ctp_mc_private *ctx = snd_soc_card_get_drvdata(rtd->card);
struct comms_mc_private *ctl = &(ctx->comms_ctl);
unsigned int device = substream->pcm->device;
pr_debug("%s substream->runtime->rate %d\n",
__func__,
substream->runtime->rate);
/* select clock source (if master) */
/* BT SCO: CPU DAI is master */
/* FM: CPU DAI is master */
/* BT_VOIP: CPU DAI is master */
if (((device == CTP_COMMS_BT_SCO_DEV &&\
ctl->ssp_bt_sco_master_mode) ||
((device == CTP_COMMS_MSIC_VOIP_DEV) &&\
ctl->ssp_voip_master_mode)) ||
(device == CTP_COMMS_IFX_MODEM_DEV &&\
ctl->ssp_modem_master_mode)) {
snd_soc_dai_set_sysclk(cpu_dai, SSP_CLK_ONCHIP,
substream->runtime->rate, 0);
}
return 0;
} /* ctp_comms_dai_link_prepare */
static const struct snd_kcontrol_new ssp_comms_controls[] = {
SOC_DAPM_PIN_SWITCH("HP"),
SOC_DAPM_PIN_SWITCH("SPK"),
SOC_DAPM_PIN_SWITCH("LINE"),
SOC_DAPM_PIN_SWITCH("HDMI"),
SOC_DAPM_PIN_SWITCH("Main Mic"),
SOC_DAPM_PIN_SWITCH("Headset Mic"),
SOC_ENUM_EXT("AIF2 Mode", aif2_mode_enum[0],
get_aif2_mode, set_aif2_mode),
SOC_ENUM_EXT("LineoutSwitch Mode", lineout_mode_enum[0],
get_lineout_mode, set_lineout_mode),
SOC_ENUM_EXT("AIF2 digital mute", switch_mode_enum[0],
get_aif2_mute_status, set_aif2_mute_status),
/* SOC_ENUM_EXT("SSP BT Master Mode",
* ssp_bt_sco_master_mode_enum,
* get_ssp_bt_sco_master_mode,
* set_ssp_bt_sco_master_mode),
* SOC_ENUM_EXT("SSP VOIP Master Mode",
* ssp_voip_master_mode_enum,
* get_ssp_voip_master_mode,
* set_ssp_voip_master_mode),
* SOC_ENUM_EXT("SSP Modem Master Mode",
* ssp_modem_master_mode_enum,
* get_ssp_modem_master_mode,
* set_ssp_modem_master_mode), */
};
int ctp_init(struct snd_soc_pcm_runtime *runtime)
{
int ret;
struct snd_soc_codec *codec = runtime->codec;
struct snd_soc_dapm_context *dapm = &codec->dapm;
struct snd_soc_card *card = runtime->card;
struct ctp_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card);
struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
/* Set codec bias level */
//ctp_set_bias_level(card, dapm, SND_SOC_BIAS_OFF);
//card->dapm.idle_bias_off = true;
codec->dapm.idle_bias_off = false;
/* Add Jack specific widgets */
ret = snd_soc_dapm_new_controls(dapm, ctp_dapm_widgets,
ARRAY_SIZE(ctp_dapm_widgets));
if (ret)
return ret;
/* Set up Jack specific audio path audio_map */
snd_soc_dapm_add_routes(dapm, ctp_audio_map,
ARRAY_SIZE(ctp_audio_map));
/* Add Comms specefic controls */
ctx->comms_ctl.ssp_bt_sco_master_mode = false;
ctx->comms_ctl.ssp_voip_master_mode = false;
ctx->comms_ctl.ssp_modem_master_mode = false;
ret = snd_soc_add_card_controls(card, ssp_comms_controls,
ARRAY_SIZE(ssp_comms_controls));
if (ret) {
pr_err("Add Comms Controls failed %d",
ret);
return ret;
}
ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK2,
MCLK2_FREQ, SND_SOC_CLOCK_IN);
if (ret < 0)
dev_err(codec->dev, "Unable to switch to MCLK2\n");
/* Force AIF1CLK on as it can fix the bt sco mute */
ret = snd_soc_dapm_force_enable_pin(&codec->dapm, "AIF1CLK");
if (ret < 0)
dev_err(codec->dev, "Failed to enable AIF1CLK\n");
snd_soc_dapm_ignore_suspend(&codec->dapm, "SPK");
snd_soc_dapm_ignore_suspend(&codec->dapm, "HP");
snd_soc_dapm_ignore_suspend(&codec->dapm, "Headset Mic");
snd_soc_dapm_ignore_suspend(&codec->dapm, "Main Mic");
snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2DACDAT");
snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3DACDAT");
snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2ADCDAT");
snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF3ADCDAT");
snd_soc_dapm_ignore_suspend(&codec->dapm, "LINE");
snd_soc_dapm_ignore_suspend(&codec->dapm, "HDMI");
snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2 Capture");
snd_soc_dapm_ignore_suspend(&codec->dapm, "AIF2 Playback");
gpio_vps_sound_en = get_gpio_by_name("VPS_SOUND_EN");
if(gpio_vps_sound_en == -1) {
pr_err("fail to get gpio by name (VPS_SOUND_EN)\n");
return -EINVAL;
}
if(gpio_request(gpio_vps_sound_en, "VPS_SOUND_EN")) {
pr_err("fail to request gpio vps_sound_en (%d)\n", gpio_vps_sound_en);
return -EINVAL;
}
gpio_direction_output(gpio_vps_sound_en, 0);
#if 0 /* Temp */
/* Keep the voice call paths active during
suspend. Mark the end points ignore_suspend */
snd_soc_dapm_ignore_suspend(dapm, "EAROUT");
snd_soc_dapm_ignore_suspend(dapm, "HPOUTA");
snd_soc_dapm_ignore_suspend(dapm, "HPOUTB");
snd_soc_dapm_ignore_suspend(dapm, "VSPOUT");
snd_soc_dapm_disable_pin(dapm, "MIC2");
snd_soc_dapm_disable_pin(dapm, "SPKLINEOUT");
snd_soc_dapm_ignore_suspend(dapm, "SPKOUT");
mutex_lock(&codec->mutex);
snd_soc_dapm_sync(dapm);
mutex_unlock(&codec->mutex);
#endif
return ret;
}
// Direct to modem (AIF2)
static struct snd_soc_dai_driver ext_dai[] = {
// AIF2
{
.name = "CSV-Call",
.playback = {
.channels_min = 1,
.channels_max = 2,
.rate_min = 8000,
.rate_max = 16000,
.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
.capture = {
.channels_min = 1,
.channels_max = 2,
.rate_min = 8000,
.rate_max = 16000,
.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
},
// AIF3
{
.name = "BT",
.playback = {
.channels_min = 1,
.channels_max = 2,
.rate_min = 8000,
.rate_max = 16000,
.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
.capture = {
.channels_min = 1,
.channels_max = 2,
.rate_min = 8000,
.rate_max = 16000,
.rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
},
};
static struct snd_soc_ops ctp_asp_ops = {
.startup = ctp_startup_asp,
.hw_params = ctp_asp_hw_params,
};
static struct snd_soc_compr_ops ctp_asp_compr_ops = {
.set_params = clv_asp_set_params,
};
static struct snd_soc_ops ctp_vsp_ops = {
.hw_params = ctp_vsp_hw_params,
};
static struct snd_soc_ops ctp_btsco_ops = {
.startup = ctp_btsco_startup,
.shutdown = ctp_btsco_shutdown,
.hw_params = ctp_btsco_hw_params,
};
static struct snd_soc_ops ctp_comms_dai_link_ops = {
.startup = ctp_comms_dai_link_startup,
.hw_params = ctp_comms_dai_link_hw_params,
.prepare = ctp_comms_dai_link_prepare,
};
static struct snd_soc_ops ctp_comms_voip_dai_link_ops = {
.startup = ctp_comms_dai_link_startup,
.hw_params = ctp_comms_dai_link_hw_params,
.prepare = ctp_comms_dai_link_prepare,
};
static struct snd_soc_dai_link ctp_rhb_dailink[] = {
[CTP_AUD_ASP_DEV] = {
.name = "Cloverview ASP",
.stream_name = "Audio",
.cpu_dai_name = "Headset-cpu-dai",
.codec_dai_name = "wm8994-aif1",
.codec_name = "wm8994-codec",
.platform_name = "sst-platform",
.init = snd_ctp_init,
.ignore_suspend = 1,
.ops = &ctp_asp_ops,
.playback_count = 2,
},
[CTP_AUD_VSP_DEV] = {
.name = "Cloverview VSP",
.stream_name = "Voice",
.cpu_dai_name = "CSV-Call",
.codec_dai_name = "wm8994-aif2",
.codec_name = "wm8994-codec",
.platform_name = "snd-soc-dummy",
.init = NULL,
.ignore_suspend = 1,
.ops = &ctp_vsp_ops,
},
[CTP_AUD_BTSCO_DEV]= {
.name = "Cloverview BTSCO",
.stream_name = "BTSCO",
.cpu_dai_name = "BT",
.codec_dai_name = "wm8994-aif3",
.codec_name = "wm8994-codec",
.platform_name = "snd-soc-dummy",
.init = NULL,
.ignore_suspend = 1,
.ops = &ctp_btsco_ops,
},
/*
[CTP_AUD_COMP_ASP_DEV] = {
.name = "Cloverview Comp ASP",
.stream_name = "Compress-Audio",
.cpu_dai_name = "Virtual-cpu-dai",
.codec_dai_name = "wm8994-aif1",
.codec_name = "wm8994-codec",
.platform_name = "sst-platform",
.init = NULL,
.ignore_suspend = 1,
.compr_ops = &ctp_asp_compr_ops,
},
[CTP_COMMS_BT_SCO_DEV] = {
.name = "Cloverview Comms BT SCO",
.stream_name = "BTSCO",
.cpu_dai_name = SSP_BT_DAI_NAME,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.platform_name = "mid-ssp-dai",
.init = NULL,
.ops = &ctp_comms_dai_link_ops,
},
[CTP_COMMS_MSIC_VOIP_DEV] = {
.name = "Cloverview Comms MSIC VOIP",
.stream_name = "VOIP",
.cpu_dai_name = SSP_BT_DAI_NAME,
.codec_dai_name = "wm8994-aif1",
.codec_name = "wm8994-codec",
.platform_name = "mid-ssp-dai",
.init = NULL,
.ops = &ctp_comms_voip_dai_link_ops,
},
[CTP_COMMS_IFX_MODEM_DEV] = {
.name = "Cloverview Comms IFX MODEM",
.stream_name = "IFX_MODEM_MIXING",
.cpu_dai_name = SSP_MODEM_DAI_NAME,
.codec_dai_name = "snd-soc-dummy-dai",
.codec_name = "snd-soc-dummy",
.platform_name = "mid-ssp-dai",
.init = NULL,
.ops = &ctp_comms_dai_link_ops,
},
[CTP_AUD_VIRTUAL_ASP_DEV] = {
.name = "Cloverview virtual-ASP",
.stream_name = "virtual-stream",
.cpu_dai_name = "Virtual-cpu-dai",
.codec_dai_name = "wm8994-aif1",
.codec_name = "wm8994-codec",
.platform_name = "sst-platform",
.init = NULL,
.ignore_suspend = 1,
.ops = &ctp_asp_ops,
},
*/
};
#if 0
int ctp_hp_detection(struct snd_soc_codec *codec,
struct snd_soc_jack *jack, int enable)
{
return cs42l73_hp_detection(codec, jack, enable);
}
int ctp_bp_detection(struct snd_soc_codec *codec,
struct snd_soc_jack *jack, int enable)
{
return cs42l73_bp_detection(codec, jack, enable);
}
#endif
int ctp_dai_link(struct snd_soc_card *card)
{
int ret_val;
card->dai_link = ctp_rhb_dailink;
card->num_links = ARRAY_SIZE(ctp_rhb_dailink);
ret_val = snd_soc_register_dais(card->dev,
ext_dai, ARRAY_SIZE(ext_dai));
if (ret_val != 0) {
pr_err("Failed to register external DAIs: %d\n", ret_val);
return -1;
}
return 0;
}
MODULE_DESCRIPTION("ASoC Intel(R) Cloverview MID Machine driveri (wm1811)");
MODULE_AUTHOR("Ted Choi<ted.choi@intel.com>");
MODULE_AUTHOR("Jeeja KP<jeeja.kp@intel.com>");
MODULE_AUTHOR("Dharageswari R<dharageswari.r@intel.com>");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("ipc:ctpwm1811-audio");