Skip to content

Commit c336774

Browse files
committed
Remove: widgets and routes isnt for volume controlling
1 parent 1566975 commit c336774

File tree

1 file changed

+133
-24
lines changed

1 file changed

+133
-24
lines changed

ac101.c

Lines changed: 133 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@
3838
#include "ac101.h"
3939

4040
/*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
5253

5354
static bool speaker_double_used = false;
5455
static int double_speaker_val = 0;
@@ -94,7 +95,6 @@ struct ac10x_priv {
9495
struct mutex aifclk_mutex;
9596
u8 aif1_clken;
9697
u8 aif2_clken;
97-
u8 aif3_clken;
9898

9999
/*voltage supply*/
100100
int num_supplies;
@@ -322,12 +322,55 @@ void set_configuration(struct snd_soc_codec *codec)
322322
}
323323
/*headphone calibration clock frequency select*/
324324
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
325364
}
326365

366+
#if _MORE_WIDGETS
327367
static int late_enable_dac(struct snd_soc_dapm_widget *w,
328368
struct snd_kcontrol *kcontrol, int event)
329369
{
330370
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
331374
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
332375
mutex_lock(&ac10x->dac_mutex);
333376
switch (event) {
@@ -359,6 +402,7 @@ static int late_enable_dac(struct snd_soc_dapm_widget *w,
359402
return 0;
360403
}
361404

405+
#if _MORE_WIDGETS
362406
static int late_enable_adc(struct snd_soc_dapm_widget *w,
363407
struct snd_kcontrol *kcontrol, int event)
364408
{
@@ -418,6 +462,9 @@ static int ac10x_headphone_event(struct snd_soc_dapm_widget *w,
418462
struct snd_kcontrol *k, int event)
419463
{
420464
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
421468
switch (event) {
422469
case SND_SOC_DAPM_POST_PMU:
423470
/*open*/
@@ -437,11 +484,14 @@ static int ac10x_headphone_event(struct snd_soc_dapm_widget *w,
437484
}
438485
return 0;
439486
}
440-
487+
#if _MORE_WIDGETS
441488
int ac10x_aif1clk(struct snd_soc_dapm_widget *w,
442489
struct snd_kcontrol *kcontrol, int event)
443490
{
444491
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
445495
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
446496

447497
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,
456506
snd_soc_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_AIF1), (0x1<<MOD_CLK_AIF1));
457507
snd_soc_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_AIF1), (0x1<<MOD_RESET_AIF1));
458508
/*enable systemclk*/
459-
if (ac10x->aif2_clken == 0 && ac10x->aif3_clken == 0)
509+
if (ac10x->aif2_clken == 0)
460510
snd_soc_update_bits(codec, SYSCLK_CTRL, (0x1<<SYSCLK_ENA), (0x1<<SYSCLK_ENA));
461511
}
462512
ac10x->aif1_clken++;
@@ -471,7 +521,7 @@ int ac10x_aif1clk(struct snd_soc_dapm_widget *w,
471521
snd_soc_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_AIF1), (0x0<<MOD_CLK_AIF1));
472522
snd_soc_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_AIF1), (0x0<<MOD_RESET_AIF1));
473523
/*DISABLE systemclk*/
474-
if (ac10x->aif2_clken == 0 && ac10x->aif3_clken == 0)
524+
if (ac10x->aif2_clken == 0)
475525
snd_soc_update_bits(codec, SYSCLK_CTRL, (0x1<<SYSCLK_ENA), (0x0<<SYSCLK_ENA));
476526
}
477527
}
@@ -480,8 +530,7 @@ int ac10x_aif1clk(struct snd_soc_dapm_widget *w,
480530
mutex_unlock(&ac10x->aifclk_mutex);
481531
return 0;
482532
}
483-
484-
533+
#if _MORE_WIDGETS
485534
static int dmic_mux_ev(struct snd_soc_dapm_widget *w,
486535
struct snd_kcontrol *kcontrol, int event)
487536
{
@@ -563,7 +612,7 @@ static const struct snd_kcontrol_new ac10x_controls[] = {
563612
SOC_DOUBLE_TLV("DAC volume", DAC_VOL_CTRL, DAC_VOL_L, DAC_VOL_R, 0xff, 0, dac_vol_tlv),
564613
SOC_DOUBLE_TLV("DAC mixer gain", DAC_MXR_GAIN, DACL_MXR_GAIN, DACR_MXR_GAIN, 0xf, 0, dac_mix_vol_tlv),
565614

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),
567616

568617
/*ADC*/
569618
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[] = {
579628
SOC_SINGLE_TLV("speaker volume", SPKOUT_CTRL, SPK_VOL, 0x1f, 0, speaker_vol_tlv),
580629
SOC_SINGLE_TLV("headphone volume", HPOUT_CTRL, HP_VOL, 0x3f, 0, headphone_vol_tlv),
581630
};
631+
582632
/*AIF1 AD0 OUT */
583633
static const char *aif1out0l_text[] = {
584634
"AIF1_AD0L", "AIF1_AD0R","SUM_AIF1AD0L_AIF1AD0R", "AVE_AIF1AD0L_AIF1AD0R"
@@ -799,7 +849,6 @@ static const struct snd_kcontrol_new adcr_mux =
799849

800850
/*built widget*/
801851
static const struct snd_soc_dapm_widget ac10x_dapm_widgets[] = {
802-
803852
SND_SOC_DAPM_MUX("AIF1OUT0L Mux", AIF1_ADCDAT_CTRL, 15, 0, &aif1out0l_mux),
804853
SND_SOC_DAPM_MUX("AIF1OUT0R Mux", AIF1_ADCDAT_CTRL, 14, 0, &aif1out0r_mux),
805854

@@ -936,6 +985,7 @@ static const struct snd_soc_dapm_route ac10x_dapm_routes[] = {
936985
{"AIF1 AD1L Mixer", "ADCL Switch", "ADCL Mux"},
937986
/*AIF1 AD1R Mixer*/
938987
{"AIF1 AD1R Mixer", "ADCR Switch", "ADCR Mux"},
988+
939989
/*AIF1 DA0 IN 12h*/
940990
{"AIF1IN0L Mux", "AIF1_DA0L", "AIF1DACL"},
941991
{"AIF1IN0L Mux", "AIF1_DA0R", "AIF1DACR"},
@@ -1052,6 +1102,26 @@ static const struct snd_soc_dapm_route ac10x_dapm_routes[] = {
10521102
{"DMICL VIR", NULL, "D_MIC"},
10531103
{"DMICR VIR", NULL, "D_MIC"},
10541104
};
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
10551125

10561126
/* PLL divisors */
10571127
struct pll_div {
@@ -1077,9 +1147,9 @@ struct kv_map {
10771147
};
10781148

10791149
/*
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+
*/
10831153
static const struct pll_div codec_pll_div[] = {
10841154
{128000, 22579200, 1, 529, 1},
10851155
{192000, 22579200, 1, 352, 4},
@@ -1146,6 +1216,28 @@ static int ac10x_aif_mute(struct snd_soc_dai *codec_dai, int mute)
11461216
AC10X_DBG("%s() L%d mute=%d\n", __func__, __LINE__, mute);
11471217

11481218
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
11491241
return 0;
11501242
}
11511243

@@ -1450,10 +1542,25 @@ static int ac10x_set_bias_level(struct snd_soc_codec *codec,
14501542
snd_soc_codec_get_dapm(codec)->bias_level = level;
14511543
return 0;
14521544
}
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+
14531559
static const struct snd_soc_dai_ops ac10x_aif1_dai_ops = {
14541560
.set_sysclk = ac10x_set_dai_sysclk,
14551561
.set_fmt = ac10x_set_dai_fmt,
14561562
.hw_params = ac10x_hw_params,
1563+
.trigger = ac10x_trigger,
14571564
.shutdown = ac10x_aif_shutdown,
14581565
.digital_mute = ac10x_aif_mute,
14591566
.set_pll = ac10x_set_pll,
@@ -1584,7 +1691,9 @@ static int ac10x_codec_probe(struct snd_soc_codec *codec)
15841691
int ret = 0;
15851692
int i = 0;
15861693
struct ac10x_priv *ac10x;
1694+
#if _MORE_WIDGETS
15871695
struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1696+
#endif
15881697

15891698
ac10x = dev_get_drvdata(codec->dev);
15901699
if (ac10x == NULL) {
@@ -1598,7 +1707,6 @@ static int ac10x_codec_probe(struct snd_soc_codec *codec)
15981707
ac10x->adc_enable = 0;
15991708
ac10x->aif1_clken = 0;
16001709
ac10x->aif2_clken = 0;
1601-
ac10x->aif3_clken = 0;
16021710
mutex_init(&ac10x->dac_mutex);
16031711
mutex_init(&ac10x->adc_mutex);
16041712
mutex_init(&ac10x->aifclk_mutex);
@@ -1639,8 +1747,10 @@ static int ac10x_codec_probe(struct snd_soc_codec *codec)
16391747
"will continue without it.\n");
16401748
}
16411749

1750+
#if _MORE_WIDGETS
16421751
snd_soc_dapm_new_controls(dapm, ac10x_dapm_widgets, ARRAY_SIZE(ac10x_dapm_widgets));
16431752
snd_soc_dapm_add_routes(dapm, ac10x_dapm_routes, ARRAY_SIZE(ac10x_dapm_routes));
1753+
#endif
16441754

16451755
return 0;
16461756
}
@@ -1699,7 +1809,6 @@ static int ac10x_codec_resume(struct snd_soc_codec *codec)
16991809
return ret;
17001810
}
17011811

1702-
17031812
ac10x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
17041813
schedule_work(&ac10x->codec_resume);
17051814
return 0;

0 commit comments

Comments
 (0)