Skip to content

Commit fd03cf7

Browse files
smaeulbroonie
authored andcommitted
ASoC: sun8i-codec: Add AIF, ADC, and DAC volume controls
This allows changing the volume of each digital input/output independently, and provides the only "master volume" for the DAC. (The ADC also has a gain control on the analog side.) While the hardware supports digital gain up to +72dB, the controls here are limited to +24dB maximum, as any gain above that level makes volume sliders difficult to use, and is extremely likely to cause clipping. Signed-off-by: Samuel Holland <samuel@sholland.org> Link: https://lore.kernel.org/r/20211118033645.43524-1-samuel@sholland.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 335302d commit fd03cf7

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

sound/soc/sunxi/sun8i-codec.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sound/pcm_params.h>
2222
#include <sound/soc.h>
2323
#include <sound/soc-dapm.h>
24+
#include <sound/tlv.h>
2425

2526
#define SUN8I_SYSCLK_CTL 0x00c
2627
#define SUN8I_SYSCLK_CTL_AIF1CLK_ENA 11
@@ -72,6 +73,12 @@
7273
#define SUN8I_AIF1_MXR_SRC_AD0R_MXR_SRC_AIF2DACR 10
7374
#define SUN8I_AIF1_MXR_SRC_AD0R_MXR_SRC_ADCR 9
7475
#define SUN8I_AIF1_MXR_SRC_AD0R_MXR_SRC_AIF2DACL 8
76+
#define SUN8I_AIF1_VOL_CTRL1 0x050
77+
#define SUN8I_AIF1_VOL_CTRL1_AD0L_VOL 8
78+
#define SUN8I_AIF1_VOL_CTRL1_AD0R_VOL 0
79+
#define SUN8I_AIF1_VOL_CTRL3 0x058
80+
#define SUN8I_AIF1_VOL_CTRL3_DA0L_VOL 8
81+
#define SUN8I_AIF1_VOL_CTRL3_DA0R_VOL 0
7582
#define SUN8I_AIF2_ADCDAT_CTRL 0x084
7683
#define SUN8I_AIF2_ADCDAT_CTRL_AIF2_ADCL_ENA 15
7784
#define SUN8I_AIF2_ADCDAT_CTRL_AIF2_ADCR_ENA 14
@@ -91,6 +98,12 @@
9198
#define SUN8I_AIF2_MXR_SRC_ADCR_MXR_SRC_AIF1DA1R 10
9299
#define SUN8I_AIF2_MXR_SRC_ADCR_MXR_SRC_AIF2DACL 9
93100
#define SUN8I_AIF2_MXR_SRC_ADCR_MXR_SRC_ADCR 8
101+
#define SUN8I_AIF2_VOL_CTRL1 0x090
102+
#define SUN8I_AIF2_VOL_CTRL1_ADCL_VOL 8
103+
#define SUN8I_AIF2_VOL_CTRL1_ADCR_VOL 0
104+
#define SUN8I_AIF2_VOL_CTRL2 0x098
105+
#define SUN8I_AIF2_VOL_CTRL2_DACL_VOL 8
106+
#define SUN8I_AIF2_VOL_CTRL2_DACR_VOL 0
94107
#define SUN8I_AIF3_CLK_CTRL_AIF3_CLK_SRC_AIF1 (0x0 << 0)
95108
#define SUN8I_AIF3_CLK_CTRL_AIF3_CLK_SRC_AIF2 (0x1 << 0)
96109
#define SUN8I_AIF3_CLK_CTRL_AIF3_CLK_SRC_AIF1CLK (0x2 << 0)
@@ -102,8 +115,14 @@
102115
#define SUN8I_ADC_DIG_CTRL_ENAD 15
103116
#define SUN8I_ADC_DIG_CTRL_ADOUT_DTS 2
104117
#define SUN8I_ADC_DIG_CTRL_ADOUT_DLY 1
118+
#define SUN8I_ADC_VOL_CTRL 0x104
119+
#define SUN8I_ADC_VOL_CTRL_ADCL_VOL 8
120+
#define SUN8I_ADC_VOL_CTRL_ADCR_VOL 0
105121
#define SUN8I_DAC_DIG_CTRL 0x120
106122
#define SUN8I_DAC_DIG_CTRL_ENDA 15
123+
#define SUN8I_DAC_VOL_CTRL 0x124
124+
#define SUN8I_DAC_VOL_CTRL_DACL_VOL 8
125+
#define SUN8I_DAC_VOL_CTRL_DACR_VOL 0
107126
#define SUN8I_DAC_MXR_SRC 0x130
108127
#define SUN8I_DAC_MXR_SRC_DACL_MXR_SRC_AIF1DA0L 15
109128
#define SUN8I_DAC_MXR_SRC_DACL_MXR_SRC_AIF1DA1L 14
@@ -696,6 +715,41 @@ static struct snd_soc_dai_driver sun8i_codec_dais[] = {
696715
},
697716
};
698717

718+
static const DECLARE_TLV_DB_SCALE(sun8i_codec_vol_scale, -12000, 75, 1);
719+
720+
static const struct snd_kcontrol_new sun8i_codec_controls[] = {
721+
SOC_DOUBLE_TLV("AIF1 AD0 Capture Volume",
722+
SUN8I_AIF1_VOL_CTRL1,
723+
SUN8I_AIF1_VOL_CTRL1_AD0L_VOL,
724+
SUN8I_AIF1_VOL_CTRL1_AD0R_VOL,
725+
0xc0, 0, sun8i_codec_vol_scale),
726+
SOC_DOUBLE_TLV("AIF1 DA0 Playback Volume",
727+
SUN8I_AIF1_VOL_CTRL3,
728+
SUN8I_AIF1_VOL_CTRL3_DA0L_VOL,
729+
SUN8I_AIF1_VOL_CTRL3_DA0R_VOL,
730+
0xc0, 0, sun8i_codec_vol_scale),
731+
SOC_DOUBLE_TLV("AIF2 ADC Capture Volume",
732+
SUN8I_AIF2_VOL_CTRL1,
733+
SUN8I_AIF2_VOL_CTRL1_ADCL_VOL,
734+
SUN8I_AIF2_VOL_CTRL1_ADCR_VOL,
735+
0xc0, 0, sun8i_codec_vol_scale),
736+
SOC_DOUBLE_TLV("AIF2 DAC Playback Volume",
737+
SUN8I_AIF2_VOL_CTRL2,
738+
SUN8I_AIF2_VOL_CTRL2_DACL_VOL,
739+
SUN8I_AIF2_VOL_CTRL2_DACR_VOL,
740+
0xc0, 0, sun8i_codec_vol_scale),
741+
SOC_DOUBLE_TLV("ADC Capture Volume",
742+
SUN8I_ADC_VOL_CTRL,
743+
SUN8I_ADC_VOL_CTRL_ADCL_VOL,
744+
SUN8I_ADC_VOL_CTRL_ADCR_VOL,
745+
0xc0, 0, sun8i_codec_vol_scale),
746+
SOC_DOUBLE_TLV("DAC Playback Volume",
747+
SUN8I_DAC_VOL_CTRL,
748+
SUN8I_DAC_VOL_CTRL_DACL_VOL,
749+
SUN8I_DAC_VOL_CTRL_DACR_VOL,
750+
0xc0, 0, sun8i_codec_vol_scale),
751+
};
752+
699753
static int sun8i_codec_aif_event(struct snd_soc_dapm_widget *w,
700754
struct snd_kcontrol *kcontrol, int event)
701755
{
@@ -1215,6 +1269,8 @@ static int sun8i_codec_component_probe(struct snd_soc_component *component)
12151269
}
12161270

12171271
static const struct snd_soc_component_driver sun8i_soc_component = {
1272+
.controls = sun8i_codec_controls,
1273+
.num_controls = ARRAY_SIZE(sun8i_codec_controls),
12181274
.dapm_widgets = sun8i_codec_dapm_widgets,
12191275
.num_dapm_widgets = ARRAY_SIZE(sun8i_codec_dapm_widgets),
12201276
.dapm_routes = sun8i_codec_dapm_routes,

0 commit comments

Comments
 (0)