Hi, this is the fourth version of the patch that adds inputs to sun4i-codec.
The inputs added are: - FM-In Left and Right - Line-In Left and Right - Mic1-In - Mic2-In Changes compared to v3 are: - Names of the input are not uppercase anymore. - bit index constants are now named as in the A20 user manual v1.4 - added Mic1-In, Mac2-In - added Mic1 and Mic2 Pre-Amplifiers. I successfully tested it using alsamixer, headphones, a radio and my ears. Note that because of missing capturing support I tested only the mixing. Still TODO are: - sun4i_codec_micin_gain_scale should have an entry for 0 dB at 0. How? - maybe the Mic Preamps should be listed in the routes. It works as it is now, though. - right now when I press F4 in alsamixer, the Mic1-In Pre-Amplifier Gain is missing its muting switch. WTF... How does ALSA (or alsamixer) know which controls are "Capture"? Regards, Danny Danny (1): b/sound/soc/sunxi/sun4i-codec.c | 112 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) Signed-off-by: Danny Milosavljevic <[email protected]> --- diff --git a/sound/soc/sunxi/sun4i-codec.c b/sound/soc/sunxi/sun4i-codec.c index bcbf4da..521ab8f 100644 --- a/sound/soc/sunxi/sun4i-codec.c +++ b/sound/soc/sunxi/sun4i-codec.c @@ -57,9 +57,21 @@ #define SUN4I_CODEC_DAC_ACTL_DACAENR (31) #define SUN4I_CODEC_DAC_ACTL_DACAENL (30) #define SUN4I_CODEC_DAC_ACTL_MIXEN (29) +/* bits 27 and 28 are documented as "/" in the user manual */ +#define SUN4I_CODEC_DAC_ACTL_LNG (26) +#define SUN4I_CODEC_DAC_ACTL_FMG (23) +#define SUN4I_CODEC_DAC_ACTL_MICG (20) +#define SUN4I_CODEC_DAC_ACTL_LLNS (19) +#define SUN4I_CODEC_DAC_ACTL_RLNS (18) +#define SUN4I_CODEC_DAC_ACTL_LFMS (17) +#define SUN4I_CODEC_DAC_ACTL_RFMS (16) #define SUN4I_CODEC_DAC_ACTL_LDACLMIXS (15) #define SUN4I_CODEC_DAC_ACTL_RDACRMIXS (14) #define SUN4I_CODEC_DAC_ACTL_LDACRMIXS (13) +#define SUN4I_CODEC_DAC_ACTL_MIC1LS (12) +#define SUN4I_CODEC_DAC_ACTL_MIC1RS (11) +#define SUN4I_CODEC_DAC_ACTL_MIC2LS (10) +#define SUN4I_CODEC_DAC_ACTL_MIC2RS (9) #define SUN4I_CODEC_DAC_ACTL_DACPAS (8) #define SUN4I_CODEC_DAC_ACTL_MIXPAS (7) #define SUN4I_CODEC_DAC_ACTL_PA_MUTE (6) @@ -94,7 +106,19 @@ #define SUN4I_CODEC_DAC_TXCNT (0x30) #define SUN4I_CODEC_ADC_RXCNT (0x34) #define SUN4I_CODEC_AC_SYS_VERI (0x38) + +/* MIC_PHONE_CAL register offsets and bit fields */ #define SUN4I_CODEC_AC_MIC_PHONE_CAL (0x3c) +#define SUN4I_CODEC_AC_MIC_PHONE_CAL_PREG1 (29) +#define SUN4I_CODEC_AC_MIC_PHONE_CAL_PREG2 (26) +/* 25 inclusive to 8 inclusive are documented as "/" */ +/* note: no idea where the output pins for the following are. */ +#define SUN4I_CODEC_AC_MIC_PHONE_CAL_PHONEOUTG (5) +#define SUN4I_CODEC_AC_MIC_PHONE_CAL_PHONEOUTEN (4) +#define SUN4I_CODEC_AC_MIC_PHONE_CAL_PHONEOUTS3 (3) +#define SUN4I_CODEC_AC_MIC_PHONE_CAL_PHONEOUTS2 (2) +#define SUN4I_CODEC_AC_MIC_PHONE_CAL_PHONEOUTS1 (1) +#define SUN4I_CODEC_AC_MIC_PHONE_CAL_PHONEOUTS0 (0) struct sun4i_codec { struct device *dev; @@ -402,16 +426,72 @@ static const struct snd_kcontrol_new sun4i_codec_pa_mute = SUN4I_CODEC_DAC_ACTL_PA_MUTE, 1, 0); static DECLARE_TLV_DB_SCALE(sun4i_codec_pa_volume_scale, -6300, 100, 1); +static DECLARE_TLV_DB_SCALE(sun4i_codec_linein_output_volume_scale, -150, 150, 0); +static DECLARE_TLV_DB_SCALE(sun4i_codec_fmin_output_volume_scale, -450, 150, 0); +static DECLARE_TLV_DB_SCALE(sun4i_codec_micin_output_volume_scale, -450, 150, 0); +/* FIXME raw value 0x00: 0 dB */ +static DECLARE_TLV_DB_SCALE(sun4i_codec_micin_gain_scale, 2400, 300, 0); static const struct snd_kcontrol_new sun4i_codec_widgets[] = { SOC_SINGLE_TLV("PA Volume", SUN4I_CODEC_DAC_ACTL, SUN4I_CODEC_DAC_ACTL_PA_VOL, 0x3F, 0, sun4i_codec_pa_volume_scale), + /* Line-In, FM-In */ + SOC_SINGLE_TLV("Line-In Playback Volume", + SUN4I_CODEC_DAC_ACTL, + SUN4I_CODEC_DAC_ACTL_LNG, + 1, + 0, + sun4i_codec_linein_output_volume_scale), + SOC_SINGLE_TLV("FM-In Playback Volume", + SUN4I_CODEC_DAC_ACTL, + SUN4I_CODEC_DAC_ACTL_FMG, + 3, + 0, + sun4i_codec_fmin_output_volume_scale), + SOC_SINGLE_TLV("Mic-In Playback Volume", + SUN4I_CODEC_DAC_ACTL, + SUN4I_CODEC_DAC_ACTL_MICG, + 7, + 0, + sun4i_codec_micin_output_volume_scale), + SOC_SINGLE_TLV("Mic1-In Pre-Amplifier Gain", + SUN4I_CODEC_AC_MIC_PHONE_CAL, + SUN4I_CODEC_AC_MIC_PHONE_CAL_PREG1, + 7, + 0, + sun4i_codec_micin_gain_scale), + SOC_SINGLE_TLV("Mic2-In Pre-Amplifier Gain", + SUN4I_CODEC_AC_MIC_PHONE_CAL, + SUN4I_CODEC_AC_MIC_PHONE_CAL_PREG2, + 7, + 0, + sun4i_codec_micin_gain_scale), + SOC_SINGLE_TLV("Mic1-In Pre-Amplifier Gain Switch", + SUN4I_CODEC_ADC_ACTL, + SUN4I_CODEC_ADC_ACTL_PREG1EN, + 1, + 0, + NULL), + SOC_SINGLE_TLV("Mic2-In Pre-Amplifier Gain Switch", + SUN4I_CODEC_ADC_ACTL, + SUN4I_CODEC_ADC_ACTL_PREG2EN, + 1, + 0, + NULL), }; static const struct snd_kcontrol_new sun4i_codec_left_mixer_controls[] = { SOC_DAPM_SINGLE("Left DAC Playback Switch", SUN4I_CODEC_DAC_ACTL, SUN4I_CODEC_DAC_ACTL_LDACLMIXS, 1, 0), + SOC_DAPM_SINGLE("Left Line-In Playback Switch", SUN4I_CODEC_DAC_ACTL, + SUN4I_CODEC_DAC_ACTL_LLNS, 1, 0), + SOC_DAPM_SINGLE("Left FM-In Playback Switch", SUN4I_CODEC_DAC_ACTL, + SUN4I_CODEC_DAC_ACTL_LFMS, 1, 0), + SOC_DAPM_SINGLE("Mic1-In Playback Switch", SUN4I_CODEC_DAC_ACTL, + SUN4I_CODEC_DAC_ACTL_MIC1LS, 1, 0), + SOC_DAPM_SINGLE("Mic2-In Playback Switch", SUN4I_CODEC_DAC_ACTL, + SUN4I_CODEC_DAC_ACTL_MIC2LS, 1, 0), }; static const struct snd_kcontrol_new sun4i_codec_right_mixer_controls[] = { @@ -419,6 +499,14 @@ static const struct snd_kcontrol_new sun4i_codec_right_mixer_controls[] = { SUN4I_CODEC_DAC_ACTL_RDACRMIXS, 1, 0), SOC_DAPM_SINGLE("Left DAC Playback Switch", SUN4I_CODEC_DAC_ACTL, SUN4I_CODEC_DAC_ACTL_LDACRMIXS, 1, 0), + SOC_DAPM_SINGLE("Right Line-In Playback Switch", SUN4I_CODEC_DAC_ACTL, + SUN4I_CODEC_DAC_ACTL_RLNS, 1, 0), + SOC_DAPM_SINGLE("Right FM-In Playback Switch", SUN4I_CODEC_DAC_ACTL, + SUN4I_CODEC_DAC_ACTL_RFMS, 1, 0), + SOC_DAPM_SINGLE("Mic1-In Playback Switch", SUN4I_CODEC_DAC_ACTL, + SUN4I_CODEC_DAC_ACTL_MIC1RS, 1, 0), + SOC_DAPM_SINGLE("Mic2-In Playback Switch", SUN4I_CODEC_DAC_ACTL, + SUN4I_CODEC_DAC_ACTL_MIC2RS, 1, 0), }; static const struct snd_kcontrol_new sun4i_codec_pa_mixer_controls[] = { @@ -462,8 +550,16 @@ static const struct snd_soc_dapm_widget sun4i_codec_dapm_widgets[] = { SND_SOC_DAPM_OUTPUT("HP Right"), SND_SOC_DAPM_OUTPUT("HP Left"), + + SND_SOC_DAPM_INPUT("Line-In Right"), + SND_SOC_DAPM_INPUT("Line-In Left"), + SND_SOC_DAPM_INPUT("FM-In Right"), + SND_SOC_DAPM_INPUT("FM-In Left"), + SND_SOC_DAPM_INPUT("Mic1-In"), + SND_SOC_DAPM_INPUT("Mic2-In"), }; +/* {sink, control, source} */ static const struct snd_soc_dapm_route sun4i_codec_dapm_routes[] = { /* Left DAC Routes */ { "Left DAC", NULL, "DAC" }, @@ -490,6 +586,22 @@ static const struct snd_soc_dapm_route sun4i_codec_dapm_routes[] = { { "Pre-Amplifier Mute", "Switch", "Pre-Amplifier" }, { "HP Right", NULL, "Pre-Amplifier Mute" }, { "HP Left", NULL, "Pre-Amplifier Mute" }, + + /* Line-In, FM-In */ + { "Right Mixer", "Right Line-In Playback Switch", "Line-In Right" }, + { "Left Mixer", "Left Line-In Playback Switch", "Line-In Left" }, + { "Right Mixer", "Right FM-In Playback Switch", "FM-In Right" }, + { "Left Mixer", "Left FM-In Playback Switch", "FM-In Left" }, + + /* TODO add Mic preamp */ + + /* Mic1-In */ + { "Right Mixer", "Mic1-In Playback Switch", "Mic1-In" }, + { "Left Mixer", "Mic1-In Playback Switch", "Mic1-In" }, + + /* Mic2-In */ + { "Right Mixer", "Mic2-In Playback Switch", "Mic2-In" }, + { "Left Mixer", "Mic2-In Playback Switch", "Mic2-In" }, }; static struct snd_soc_codec_driver sun4i_codec_codec = { -- You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
