38
38
#include "ac101.h"
39
39
40
40
/*Default initialize configuration*/
41
- #define SPEAKER_DOUBLE_USED 1
42
- #define D_SPEAKER_VOL 0x1b
43
- #define S_SPEAKER_VOL 0x19
44
- #define HEADPHONE_VOL 0x3b
45
- #define EARPIECE_VOL 0x1e
46
- #define MAINMIC_GAIN 0x4
47
- #define HDSETMIC_GAIN 0x4
48
- #define DMIC_USED 0
49
- #define ADC_DIGITAL_GAIN 0xb0b0
50
- #define AGC_USED 0
51
- #define DRC_USED 1
41
+ #define SPEAKER_DOUBLE_USED 1
42
+ #define D_SPEAKER_VOL 0x1b
43
+ #define S_SPEAKER_VOL 0x19
44
+ #define HEADPHONE_VOL 0x3b
45
+ #define EARPIECE_VOL 0x1e
46
+ #define MAINMIC_GAIN 0x4
47
+ #define HDSETMIC_GAIN 0x4
48
+ #define DMIC_USED 0
49
+ #define ADC_DIGITAL_GAIN 0xb0b0
50
+ #define AGC_USED 0
51
+ #define DRC_USED 1
52
+ #define _MORE_WIDGETS 0
52
53
53
54
static bool speaker_double_used = false;
54
55
static int double_speaker_val = 0 ;
@@ -94,7 +95,6 @@ struct ac10x_priv {
94
95
struct mutex aifclk_mutex ;
95
96
u8 aif1_clken ;
96
97
u8 aif2_clken ;
97
- u8 aif3_clken ;
98
98
99
99
/*voltage supply*/
100
100
int num_supplies ;
@@ -322,12 +322,55 @@ void set_configuration(struct snd_soc_codec *codec)
322
322
}
323
323
/*headphone calibration clock frequency select*/
324
324
snd_soc_update_bits (codec , SPKOUT_CTRL , (0x7 <<HPCALICKS ), (0x7 <<HPCALICKS ));
325
+
326
+ #if ! _MORE_WIDGETS
327
+ /* I2S1 DAC Timeslot 0 data <- I2S1 DAC channel 0 */
328
+ // "AIF1IN0L Mux" <= "AIF1DACL"
329
+ // "AIF1IN0R Mux" <= "AIF1DACR"
330
+ snd_soc_update_bits (codec , AIF1_DACDAT_CTRL , 0x3 << AIF1_DA0L_SRC , 0x0 << AIF1_DA0L_SRC );
331
+ snd_soc_update_bits (codec , AIF1_DACDAT_CTRL , 0x3 << AIF1_DA0R_SRC , 0x0 << AIF1_DA0R_SRC );
332
+ /* Timeslot 0 Left & Right Channel enable */
333
+ snd_soc_update_bits (codec , AIF1_DACDAT_CTRL , 0x3 << AIF1_DA0R_ENA , 0x3 << AIF1_DA0R_ENA );
334
+
335
+ /* DAC Digital Mixer Source Select <- I2S1 DA0 */
336
+ // "DACL Mixer" += "AIF1IN0L Mux"
337
+ // "DACR Mixer" += "AIF1IN0R Mux"
338
+ snd_soc_update_bits (codec , DAC_MXR_SRC , 0xF << DACL_MXR_ADCL , 0x8 << DACL_MXR_ADCL );
339
+ snd_soc_update_bits (codec , DAC_MXR_SRC , 0xF << DACR_MXR_ADCR , 0x8 << DACR_MXR_ADCR );
340
+ /* Internal DAC Analog Left & Right Channel enable */
341
+ snd_soc_update_bits (codec , OMIXER_DACA_CTRL , 0x3 << DACALEN , 0x3 << DACALEN );
342
+
343
+ /* Output Mixer Source Select */
344
+ // "Left Output Mixer" += "DACL Mixer"
345
+ // "Right Output Mixer" += "DACR Mixer"
346
+ snd_soc_update_bits (codec , OMIXER_SR , 0x1 << LMIXMUTEDACL , 0x1 << LMIXMUTEDACL );
347
+ snd_soc_update_bits (codec , OMIXER_SR , 0x1 << RMIXMUTEDACR , 0x1 << RMIXMUTEDACR );
348
+ /* Left & Right Analog Output Mixer enable */
349
+ snd_soc_update_bits (codec , OMIXER_DACA_CTRL , 0x3 << LMIXEN , 0x3 << LMIXEN );
350
+
351
+ /* Headphone Ouput Control */
352
+ // "HP_R Mux" <= "DACR Mixer"
353
+ // "HP_L Mux" <= "DACL Mixer"
354
+ snd_soc_update_bits (codec , HPOUT_CTRL , 0x1 << LHPS , 0x0 << LHPS );
355
+ snd_soc_update_bits (codec , HPOUT_CTRL , 0x1 << RHPS , 0x0 << RHPS );
356
+
357
+ /* Speaker Output Control */
358
+ // "SPK_L Mux" <= "SPK_LR Adder"
359
+ // "SPK_R Mux" <= "SPK_LR Adder"
360
+ snd_soc_update_bits (codec , SPKOUT_CTRL , (0x1 << LSPKS ) | (0x1 << RSPKS ), (0x1 << LSPKS ) | (0x1 << RSPKS ));
361
+ /* Enable Left & Right Speaker */
362
+ snd_soc_update_bits (codec , SPKOUT_CTRL , (0x1 << LSPK_EN ) | (0x1 << RSPK_EN ), (0x1 << LSPK_EN ) | (0x1 << RSPK_EN ));
363
+ #endif
325
364
}
326
365
366
+ #if _MORE_WIDGETS
327
367
static int late_enable_dac (struct snd_soc_dapm_widget * w ,
328
368
struct snd_kcontrol * kcontrol , int event )
329
369
{
330
370
struct snd_soc_codec * codec = snd_soc_dapm_to_codec (w -> dapm );
371
+ #else
372
+ static int late_enable_dac (struct snd_soc_codec * codec , int event ) {
373
+ #endif
331
374
struct ac10x_priv * ac10x = snd_soc_codec_get_drvdata (codec );
332
375
mutex_lock (& ac10x -> dac_mutex );
333
376
switch (event ) {
@@ -359,6 +402,7 @@ static int late_enable_dac(struct snd_soc_dapm_widget *w,
359
402
return 0 ;
360
403
}
361
404
405
+ #if _MORE_WIDGETS
362
406
static int late_enable_adc (struct snd_soc_dapm_widget * w ,
363
407
struct snd_kcontrol * kcontrol , int event )
364
408
{
@@ -418,6 +462,9 @@ static int ac10x_headphone_event(struct snd_soc_dapm_widget *w,
418
462
struct snd_kcontrol * k , int event )
419
463
{
420
464
struct snd_soc_codec * codec = snd_soc_dapm_to_codec (w -> dapm );
465
+ #else
466
+ static int ac10x_headphone_event (struct snd_soc_codec * codec , int event ) {
467
+ #endif
421
468
switch (event ) {
422
469
case SND_SOC_DAPM_POST_PMU :
423
470
/*open*/
@@ -437,11 +484,14 @@ static int ac10x_headphone_event(struct snd_soc_dapm_widget *w,
437
484
}
438
485
return 0 ;
439
486
}
440
-
487
+ #if _MORE_WIDGETS
441
488
int ac10x_aif1clk (struct snd_soc_dapm_widget * w ,
442
489
struct snd_kcontrol * kcontrol , int event )
443
490
{
444
491
struct snd_soc_codec * codec = snd_soc_dapm_to_codec (w -> dapm );
492
+ #else
493
+ static int ac10x_aif1clk (struct snd_soc_codec * codec , int event ) {
494
+ #endif
445
495
struct ac10x_priv * ac10x = snd_soc_codec_get_drvdata (codec );
446
496
447
497
AC10X_DBG ("%s() L%d event=%d pre_up/%d post_down/%d\n" , __func__ , __LINE__ ,
@@ -456,7 +506,7 @@ int ac10x_aif1clk(struct snd_soc_dapm_widget *w,
456
506
snd_soc_update_bits (codec , MOD_CLK_ENA , (0x1 <<MOD_CLK_AIF1 ), (0x1 <<MOD_CLK_AIF1 ));
457
507
snd_soc_update_bits (codec , MOD_RST_CTRL , (0x1 <<MOD_RESET_AIF1 ), (0x1 <<MOD_RESET_AIF1 ));
458
508
/*enable systemclk*/
459
- if (ac10x -> aif2_clken == 0 && ac10x -> aif3_clken == 0 )
509
+ if (ac10x -> aif2_clken == 0 )
460
510
snd_soc_update_bits (codec , SYSCLK_CTRL , (0x1 <<SYSCLK_ENA ), (0x1 <<SYSCLK_ENA ));
461
511
}
462
512
ac10x -> aif1_clken ++ ;
@@ -471,7 +521,7 @@ int ac10x_aif1clk(struct snd_soc_dapm_widget *w,
471
521
snd_soc_update_bits (codec , MOD_CLK_ENA , (0x1 <<MOD_CLK_AIF1 ), (0x0 <<MOD_CLK_AIF1 ));
472
522
snd_soc_update_bits (codec , MOD_RST_CTRL , (0x1 <<MOD_RESET_AIF1 ), (0x0 <<MOD_RESET_AIF1 ));
473
523
/*DISABLE systemclk*/
474
- if (ac10x -> aif2_clken == 0 && ac10x -> aif3_clken == 0 )
524
+ if (ac10x -> aif2_clken == 0 )
475
525
snd_soc_update_bits (codec , SYSCLK_CTRL , (0x1 <<SYSCLK_ENA ), (0x0 <<SYSCLK_ENA ));
476
526
}
477
527
}
@@ -480,8 +530,7 @@ int ac10x_aif1clk(struct snd_soc_dapm_widget *w,
480
530
mutex_unlock (& ac10x -> aifclk_mutex );
481
531
return 0 ;
482
532
}
483
-
484
-
533
+ #if _MORE_WIDGETS
485
534
static int dmic_mux_ev (struct snd_soc_dapm_widget * w ,
486
535
struct snd_kcontrol * kcontrol , int event )
487
536
{
@@ -563,7 +612,7 @@ static const struct snd_kcontrol_new ac10x_controls[] = {
563
612
SOC_DOUBLE_TLV ("DAC volume" , DAC_VOL_CTRL , DAC_VOL_L , DAC_VOL_R , 0xff , 0 , dac_vol_tlv ),
564
613
SOC_DOUBLE_TLV ("DAC mixer gain" , DAC_MXR_GAIN , DACL_MXR_GAIN , DACR_MXR_GAIN , 0xf , 0 , dac_mix_vol_tlv ),
565
614
566
- SOC_SINGLE_TLV ("digital volume" , DAC_DBG_CTRL , DVC , 0x3f , 0 , dig_vol_tlv ),
615
+ SOC_SINGLE_TLV ("digital volume" , DAC_DBG_CTRL , DVC , 0x3f , 1 , dig_vol_tlv ),
567
616
568
617
/*ADC*/
569
618
SOC_DOUBLE_TLV ("ADC input gain" , ADC_APC_CTRL , ADCLG , ADCRG , 0x7 , 0 , adc_input_vol_tlv ),
@@ -579,6 +628,7 @@ static const struct snd_kcontrol_new ac10x_controls[] = {
579
628
SOC_SINGLE_TLV ("speaker volume" , SPKOUT_CTRL , SPK_VOL , 0x1f , 0 , speaker_vol_tlv ),
580
629
SOC_SINGLE_TLV ("headphone volume" , HPOUT_CTRL , HP_VOL , 0x3f , 0 , headphone_vol_tlv ),
581
630
};
631
+
582
632
/*AIF1 AD0 OUT */
583
633
static const char * aif1out0l_text [] = {
584
634
"AIF1_AD0L" , "AIF1_AD0R" ,"SUM_AIF1AD0L_AIF1AD0R" , "AVE_AIF1AD0L_AIF1AD0R"
@@ -799,7 +849,6 @@ static const struct snd_kcontrol_new adcr_mux =
799
849
800
850
/*built widget*/
801
851
static const struct snd_soc_dapm_widget ac10x_dapm_widgets [] = {
802
-
803
852
SND_SOC_DAPM_MUX ("AIF1OUT0L Mux" , AIF1_ADCDAT_CTRL , 15 , 0 , & aif1out0l_mux ),
804
853
SND_SOC_DAPM_MUX ("AIF1OUT0R Mux" , AIF1_ADCDAT_CTRL , 14 , 0 , & aif1out0r_mux ),
805
854
@@ -936,6 +985,7 @@ static const struct snd_soc_dapm_route ac10x_dapm_routes[] = {
936
985
{"AIF1 AD1L Mixer" , "ADCL Switch" , "ADCL Mux" },
937
986
/*AIF1 AD1R Mixer*/
938
987
{"AIF1 AD1R Mixer" , "ADCR Switch" , "ADCR Mux" },
988
+
939
989
/*AIF1 DA0 IN 12h*/
940
990
{"AIF1IN0L Mux" , "AIF1_DA0L" , "AIF1DACL" },
941
991
{"AIF1IN0L Mux" , "AIF1_DA0R" , "AIF1DACR" },
@@ -1052,6 +1102,26 @@ static const struct snd_soc_dapm_route ac10x_dapm_routes[] = {
1052
1102
{"DMICL VIR" , NULL , "D_MIC" },
1053
1103
{"DMICR VIR" , NULL , "D_MIC" },
1054
1104
};
1105
+ #else // !_MORE_WIDGETS
1106
+ #if 0
1107
+ static const DECLARE_TLV_DB_SCALE (dac_vol_tlv , -11925 , 75 , 0 ) ;
1108
+ static const DECLARE_TLV_DB_SCALE (dac_mix_vol_tlv , -600 , 600 , 0 ) ;
1109
+ static const DECLARE_TLV_DB_SCALE (dig_vol_tlv , -7308 , 116 , 0 ) ;
1110
+ #endif
1111
+ static const DECLARE_TLV_DB_SCALE (speaker_vol_tlv , -4800 , 150 , 0 ) ;
1112
+ static const DECLARE_TLV_DB_SCALE (headphone_vol_tlv , -6300 , 100 , 0 ) ;
1113
+
1114
+ static const struct snd_kcontrol_new ac10x_controls [] = {
1115
+ /*DAC*/
1116
+ #if 0
1117
+ SOC_DOUBLE_TLV ("DAC volume" , DAC_VOL_CTRL , DAC_VOL_L , DAC_VOL_R , 0xff , 0 , dac_vol_tlv ),
1118
+ SOC_DOUBLE_TLV ("DAC mixer gain" , DAC_MXR_GAIN , DACL_MXR_GAIN , DACR_MXR_GAIN , 0xf , 0 , dac_mix_vol_tlv ),
1119
+ SOC_SINGLE_TLV ("digital volume" , DAC_DBG_CTRL , DVC , 0x3f , 1 , dig_vol_tlv ),
1120
+ #endif
1121
+ SOC_SINGLE_TLV ("speaker volume" , SPKOUT_CTRL , SPK_VOL , 0x1f , 0 , speaker_vol_tlv ),
1122
+ SOC_SINGLE_TLV ("headphone volume" , HPOUT_CTRL , HP_VOL , 0x3f , 0 , headphone_vol_tlv ),
1123
+ };
1124
+ #endif
1055
1125
1056
1126
/* PLL divisors */
1057
1127
struct pll_div {
@@ -1077,9 +1147,9 @@ struct kv_map {
1077
1147
};
1078
1148
1079
1149
/*
1080
- * Note : pll code from original tdm/i2s driver.
1081
- * freq_out = freq_in * N/(m*(2k+1)) , k=1,N=N_i+N_f,N_f=factor*0.2;
1082
- */
1150
+ * Note : pll code from original tdm/i2s driver.
1151
+ * freq_out = freq_in * N/(m*(2k+1)) , k=1,N=N_i+N_f,N_f=factor*0.2;
1152
+ */
1083
1153
static const struct pll_div codec_pll_div [] = {
1084
1154
{128000 , 22579200 , 1 , 529 , 1 },
1085
1155
{192000 , 22579200 , 1 , 352 , 4 },
@@ -1146,6 +1216,28 @@ static int ac10x_aif_mute(struct snd_soc_dai *codec_dai, int mute)
1146
1216
AC10X_DBG ("%s() L%d mute=%d\n" , __func__ , __LINE__ , mute );
1147
1217
1148
1218
snd_soc_write (codec , DAC_VOL_CTRL , mute ? 0 : 0xA0A0 );
1219
+
1220
+ #if !_MORE_WIDGETS
1221
+ if (!mute ) {
1222
+ ac10x_aif1clk (codec , SND_SOC_DAPM_PRE_PMU );
1223
+ late_enable_dac (codec , SND_SOC_DAPM_PRE_PMU );
1224
+ ac10x_headphone_event (codec , SND_SOC_DAPM_POST_PMU );
1225
+ if (drc_used ) {
1226
+ drc_enable (codec ,1 );
1227
+ }
1228
+ } else {
1229
+ struct ac10x_priv * ac10x = snd_soc_codec_get_drvdata (codec );
1230
+
1231
+ if (drc_used ) {
1232
+ drc_enable (codec ,0 );
1233
+ }
1234
+ ac10x_headphone_event (codec , SND_SOC_DAPM_PRE_PMD );
1235
+ late_enable_dac (codec , SND_SOC_DAPM_POST_PMD );
1236
+
1237
+ ac10x -> aif1_clken = 1 ;
1238
+ ac10x_aif1clk (codec , SND_SOC_DAPM_POST_PMD );
1239
+ }
1240
+ #endif
1149
1241
return 0 ;
1150
1242
}
1151
1243
@@ -1450,10 +1542,25 @@ static int ac10x_set_bias_level(struct snd_soc_codec *codec,
1450
1542
snd_soc_codec_get_dapm (codec )-> bias_level = level ;
1451
1543
return 0 ;
1452
1544
}
1545
+
1546
+ static int ac10x_trigger (struct snd_pcm_substream * substream , int cmd ,
1547
+ struct snd_soc_dai * dai )
1548
+ {
1549
+ struct snd_soc_codec * codec = dai -> codec ;
1550
+ struct ac10x_priv * ac10x = snd_soc_codec_get_drvdata (codec );
1551
+ int ret = 0 ;
1552
+
1553
+ AC10X_DBG ("%s() stream=%d cmd=%d\n" ,
1554
+ __FUNCTION__ , substream -> stream , cmd );
1555
+
1556
+ return 0 ;
1557
+ }
1558
+
1453
1559
static const struct snd_soc_dai_ops ac10x_aif1_dai_ops = {
1454
1560
.set_sysclk = ac10x_set_dai_sysclk ,
1455
1561
.set_fmt = ac10x_set_dai_fmt ,
1456
1562
.hw_params = ac10x_hw_params ,
1563
+ .trigger = ac10x_trigger ,
1457
1564
.shutdown = ac10x_aif_shutdown ,
1458
1565
.digital_mute = ac10x_aif_mute ,
1459
1566
.set_pll = ac10x_set_pll ,
@@ -1584,7 +1691,9 @@ static int ac10x_codec_probe(struct snd_soc_codec *codec)
1584
1691
int ret = 0 ;
1585
1692
int i = 0 ;
1586
1693
struct ac10x_priv * ac10x ;
1694
+ #if _MORE_WIDGETS
1587
1695
struct snd_soc_dapm_context * dapm = snd_soc_codec_get_dapm (codec );
1696
+ #endif
1588
1697
1589
1698
ac10x = dev_get_drvdata (codec -> dev );
1590
1699
if (ac10x == NULL ) {
@@ -1598,7 +1707,6 @@ static int ac10x_codec_probe(struct snd_soc_codec *codec)
1598
1707
ac10x -> adc_enable = 0 ;
1599
1708
ac10x -> aif1_clken = 0 ;
1600
1709
ac10x -> aif2_clken = 0 ;
1601
- ac10x -> aif3_clken = 0 ;
1602
1710
mutex_init (& ac10x -> dac_mutex );
1603
1711
mutex_init (& ac10x -> adc_mutex );
1604
1712
mutex_init (& ac10x -> aifclk_mutex );
@@ -1639,8 +1747,10 @@ static int ac10x_codec_probe(struct snd_soc_codec *codec)
1639
1747
"will continue without it.\n" );
1640
1748
}
1641
1749
1750
+ #if _MORE_WIDGETS
1642
1751
snd_soc_dapm_new_controls (dapm , ac10x_dapm_widgets , ARRAY_SIZE (ac10x_dapm_widgets ));
1643
1752
snd_soc_dapm_add_routes (dapm , ac10x_dapm_routes , ARRAY_SIZE (ac10x_dapm_routes ));
1753
+ #endif
1644
1754
1645
1755
return 0 ;
1646
1756
}
@@ -1699,7 +1809,6 @@ static int ac10x_codec_resume(struct snd_soc_codec *codec)
1699
1809
return ret ;
1700
1810
}
1701
1811
1702
-
1703
1812
ac10x_set_bias_level (codec , SND_SOC_BIAS_STANDBY );
1704
1813
schedule_work (& ac10x -> codec_resume );
1705
1814
return 0 ;
0 commit comments