12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2203db220SDimitris Papastamos /* 3203db220SDimitris Papastamos * wm8991.c -- WM8991 ALSA Soc Audio driver 4203db220SDimitris Papastamos * 5203db220SDimitris Papastamos * Copyright 2007-2010 Wolfson Microelectronics PLC. 6203db220SDimitris Papastamos * Author: Graeme Gregory 79a185b9aSMark Brown * Graeme.Gregory@wolfsonmicro.com 8203db220SDimitris Papastamos */ 9203db220SDimitris Papastamos 10203db220SDimitris Papastamos #include <linux/module.h> 11203db220SDimitris Papastamos #include <linux/moduleparam.h> 12203db220SDimitris Papastamos #include <linux/kernel.h> 13203db220SDimitris Papastamos #include <linux/init.h> 14203db220SDimitris Papastamos #include <linux/delay.h> 15203db220SDimitris Papastamos #include <linux/pm.h> 16203db220SDimitris Papastamos #include <linux/i2c.h> 17a86652e5SMark Brown #include <linux/regmap.h> 18203db220SDimitris Papastamos #include <linux/slab.h> 19203db220SDimitris Papastamos #include <sound/core.h> 20203db220SDimitris Papastamos #include <sound/pcm.h> 21203db220SDimitris Papastamos #include <sound/pcm_params.h> 22203db220SDimitris Papastamos #include <sound/soc.h> 23203db220SDimitris Papastamos #include <sound/soc-dapm.h> 24203db220SDimitris Papastamos #include <sound/initval.h> 25203db220SDimitris Papastamos #include <sound/tlv.h> 26203db220SDimitris Papastamos #include <asm/div64.h> 27203db220SDimitris Papastamos 28203db220SDimitris Papastamos #include "wm8991.h" 29203db220SDimitris Papastamos 30203db220SDimitris Papastamos struct wm8991_priv { 31a86652e5SMark Brown struct regmap *regmap; 32203db220SDimitris Papastamos unsigned int pcmclk; 33203db220SDimitris Papastamos }; 34203db220SDimitris Papastamos 35a86652e5SMark Brown static const struct reg_default wm8991_reg_defaults[] = { 36a86652e5SMark Brown { 1, 0x0000 }, /* R1 - Power Management (1) */ 37a86652e5SMark Brown { 2, 0x6000 }, /* R2 - Power Management (2) */ 38a86652e5SMark Brown { 3, 0x0000 }, /* R3 - Power Management (3) */ 39a86652e5SMark Brown { 4, 0x4050 }, /* R4 - Audio Interface (1) */ 40a86652e5SMark Brown { 5, 0x4000 }, /* R5 - Audio Interface (2) */ 41a86652e5SMark Brown { 6, 0x01C8 }, /* R6 - Clocking (1) */ 42a86652e5SMark Brown { 7, 0x0000 }, /* R7 - Clocking (2) */ 43a86652e5SMark Brown { 8, 0x0040 }, /* R8 - Audio Interface (3) */ 44a86652e5SMark Brown { 9, 0x0040 }, /* R9 - Audio Interface (4) */ 45a86652e5SMark Brown { 10, 0x0004 }, /* R10 - DAC CTRL */ 46a86652e5SMark Brown { 11, 0x00C0 }, /* R11 - Left DAC Digital Volume */ 47a86652e5SMark Brown { 12, 0x00C0 }, /* R12 - Right DAC Digital Volume */ 48a86652e5SMark Brown { 13, 0x0000 }, /* R13 - Digital Side Tone */ 49a86652e5SMark Brown { 14, 0x0100 }, /* R14 - ADC CTRL */ 50a86652e5SMark Brown { 15, 0x00C0 }, /* R15 - Left ADC Digital Volume */ 51a86652e5SMark Brown { 16, 0x00C0 }, /* R16 - Right ADC Digital Volume */ 52a86652e5SMark Brown 53a86652e5SMark Brown { 18, 0x0000 }, /* R18 - GPIO CTRL 1 */ 54a86652e5SMark Brown { 19, 0x1000 }, /* R19 - GPIO1 & GPIO2 */ 55a86652e5SMark Brown { 20, 0x1010 }, /* R20 - GPIO3 & GPIO4 */ 56a86652e5SMark Brown { 21, 0x1010 }, /* R21 - GPIO5 & GPIO6 */ 57a86652e5SMark Brown { 22, 0x8000 }, /* R22 - GPIOCTRL 2 */ 58a86652e5SMark Brown { 23, 0x0800 }, /* R23 - GPIO_POL */ 59a86652e5SMark Brown { 24, 0x008B }, /* R24 - Left Line Input 1&2 Volume */ 60a86652e5SMark Brown { 25, 0x008B }, /* R25 - Left Line Input 3&4 Volume */ 61a86652e5SMark Brown { 26, 0x008B }, /* R26 - Right Line Input 1&2 Volume */ 62a86652e5SMark Brown { 27, 0x008B }, /* R27 - Right Line Input 3&4 Volume */ 63a86652e5SMark Brown { 28, 0x0000 }, /* R28 - Left Output Volume */ 64a86652e5SMark Brown { 29, 0x0000 }, /* R29 - Right Output Volume */ 65a86652e5SMark Brown { 30, 0x0066 }, /* R30 - Line Outputs Volume */ 66a86652e5SMark Brown { 31, 0x0022 }, /* R31 - Out3/4 Volume */ 67a86652e5SMark Brown { 32, 0x0079 }, /* R32 - Left OPGA Volume */ 68a86652e5SMark Brown { 33, 0x0079 }, /* R33 - Right OPGA Volume */ 69a86652e5SMark Brown { 34, 0x0003 }, /* R34 - Speaker Volume */ 70a86652e5SMark Brown { 35, 0x0003 }, /* R35 - ClassD1 */ 71a86652e5SMark Brown 72a86652e5SMark Brown { 37, 0x0100 }, /* R37 - ClassD3 */ 73a86652e5SMark Brown 74a86652e5SMark Brown { 39, 0x0000 }, /* R39 - Input Mixer1 */ 75a86652e5SMark Brown { 40, 0x0000 }, /* R40 - Input Mixer2 */ 76a86652e5SMark Brown { 41, 0x0000 }, /* R41 - Input Mixer3 */ 77a86652e5SMark Brown { 42, 0x0000 }, /* R42 - Input Mixer4 */ 78a86652e5SMark Brown { 43, 0x0000 }, /* R43 - Input Mixer5 */ 79a86652e5SMark Brown { 44, 0x0000 }, /* R44 - Input Mixer6 */ 80a86652e5SMark Brown { 45, 0x0000 }, /* R45 - Output Mixer1 */ 81a86652e5SMark Brown { 46, 0x0000 }, /* R46 - Output Mixer2 */ 82a86652e5SMark Brown { 47, 0x0000 }, /* R47 - Output Mixer3 */ 83a86652e5SMark Brown { 48, 0x0000 }, /* R48 - Output Mixer4 */ 84a86652e5SMark Brown { 49, 0x0000 }, /* R49 - Output Mixer5 */ 85a86652e5SMark Brown { 50, 0x0000 }, /* R50 - Output Mixer6 */ 86a86652e5SMark Brown { 51, 0x0180 }, /* R51 - Out3/4 Mixer */ 87a86652e5SMark Brown { 52, 0x0000 }, /* R52 - Line Mixer1 */ 88a86652e5SMark Brown { 53, 0x0000 }, /* R53 - Line Mixer2 */ 89a86652e5SMark Brown { 54, 0x0000 }, /* R54 - Speaker Mixer */ 90a86652e5SMark Brown { 55, 0x0000 }, /* R55 - Additional Control */ 91a86652e5SMark Brown { 56, 0x0000 }, /* R56 - AntiPOP1 */ 92a86652e5SMark Brown { 57, 0x0000 }, /* R57 - AntiPOP2 */ 93a86652e5SMark Brown { 58, 0x0000 }, /* R58 - MICBIAS */ 94a86652e5SMark Brown 95a86652e5SMark Brown { 60, 0x0008 }, /* R60 - PLL1 */ 96a86652e5SMark Brown { 61, 0x0031 }, /* R61 - PLL2 */ 97a86652e5SMark Brown { 62, 0x0026 }, /* R62 - PLL3 */ 98203db220SDimitris Papastamos }; 99203db220SDimitris Papastamos 100a86652e5SMark Brown static bool wm8991_volatile(struct device *dev, unsigned int reg) 101a86652e5SMark Brown { 102a86652e5SMark Brown switch (reg) { 103a86652e5SMark Brown case WM8991_RESET: 104a86652e5SMark Brown return true; 105a86652e5SMark Brown default: 106a86652e5SMark Brown return false; 107a86652e5SMark Brown } 108a86652e5SMark Brown } 109a86652e5SMark Brown 11098695eabSTakashi Sakamoto static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(in_pga_tlv, -1650, 150, 0); 11198695eabSTakashi Sakamoto static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(out_mix_tlv, -2100, 300, 0); 11298695eabSTakashi Sakamoto static const SNDRV_CTL_TLVD_DECLARE_DB_RANGE(out_pga_tlv, 11398695eabSTakashi Sakamoto 0x00, 0x2f, SNDRV_CTL_TLVD_DB_SCALE_ITEM(SNDRV_CTL_TLVD_DB_GAIN_MUTE, 0, 1), 11498695eabSTakashi Sakamoto 0x30, 0x7f, SNDRV_CTL_TLVD_DB_SCALE_ITEM(-7300, 100, 0), 11598695eabSTakashi Sakamoto ); 11698695eabSTakashi Sakamoto static const SNDRV_CTL_TLVD_DECLARE_DB_RANGE(out_dac_tlv, 11798695eabSTakashi Sakamoto 0x00, 0xbf, SNDRV_CTL_TLVD_DB_SCALE_ITEM(-71625, 375, 1), 11898695eabSTakashi Sakamoto 0xc0, 0xff, SNDRV_CTL_TLVD_DB_SCALE_ITEM(0, 0, 0), 11998695eabSTakashi Sakamoto ); 12098695eabSTakashi Sakamoto static const SNDRV_CTL_TLVD_DECLARE_DB_RANGE(in_adc_tlv, 12198695eabSTakashi Sakamoto 0x00, 0xef, SNDRV_CTL_TLVD_DB_SCALE_ITEM(-71625, 375, 1), 12298695eabSTakashi Sakamoto 0xf0, 0xff, SNDRV_CTL_TLVD_DB_SCALE_ITEM(17625, 0, 0), 12398695eabSTakashi Sakamoto ); 12498695eabSTakashi Sakamoto static const SNDRV_CTL_TLVD_DECLARE_DB_RANGE(out_sidetone_tlv, 12598695eabSTakashi Sakamoto 0x00, 0x0c, SNDRV_CTL_TLVD_DB_SCALE_ITEM(-3600, 300, 0), 12698695eabSTakashi Sakamoto 0x0d, 0x0f, SNDRV_CTL_TLVD_DB_SCALE_ITEM(0, 0, 0), 12798695eabSTakashi Sakamoto ); 128203db220SDimitris Papastamos 129203db220SDimitris Papastamos static int wm899x_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol, 130203db220SDimitris Papastamos struct snd_ctl_elem_value *ucontrol) 131203db220SDimitris Papastamos { 132bf338e5bSKuninori Morimoto struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); 133203db220SDimitris Papastamos int reg = kcontrol->private_value & 0xff; 134203db220SDimitris Papastamos int ret; 135203db220SDimitris Papastamos u16 val; 136203db220SDimitris Papastamos 137203db220SDimitris Papastamos ret = snd_soc_put_volsw(kcontrol, ucontrol); 138203db220SDimitris Papastamos if (ret < 0) 139203db220SDimitris Papastamos return ret; 140203db220SDimitris Papastamos 141203db220SDimitris Papastamos /* now hit the volume update bits (always bit 8) */ 1426d75dfc3SKuninori Morimoto val = snd_soc_component_read(component, reg); 143bf338e5bSKuninori Morimoto return snd_soc_component_write(component, reg, val | 0x0100); 144203db220SDimitris Papastamos } 145203db220SDimitris Papastamos 146203db220SDimitris Papastamos static const char *wm8991_digital_sidetone[] = 147203db220SDimitris Papastamos {"None", "Left ADC", "Right ADC", "Reserved"}; 148203db220SDimitris Papastamos 149d07338b0STakashi Iwai static SOC_ENUM_SINGLE_DECL(wm8991_left_digital_sidetone_enum, 150d07338b0STakashi Iwai WM8991_DIGITAL_SIDE_TONE, 151203db220SDimitris Papastamos WM8991_ADC_TO_DACL_SHIFT, 152203db220SDimitris Papastamos wm8991_digital_sidetone); 153203db220SDimitris Papastamos 154d07338b0STakashi Iwai static SOC_ENUM_SINGLE_DECL(wm8991_right_digital_sidetone_enum, 155d07338b0STakashi Iwai WM8991_DIGITAL_SIDE_TONE, 156203db220SDimitris Papastamos WM8991_ADC_TO_DACR_SHIFT, 157203db220SDimitris Papastamos wm8991_digital_sidetone); 158203db220SDimitris Papastamos 159203db220SDimitris Papastamos static const char *wm8991_adcmode[] = 160203db220SDimitris Papastamos {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"}; 161203db220SDimitris Papastamos 162d07338b0STakashi Iwai static SOC_ENUM_SINGLE_DECL(wm8991_right_adcmode_enum, 163d07338b0STakashi Iwai WM8991_ADC_CTRL, 164203db220SDimitris Papastamos WM8991_ADC_HPF_CUT_SHIFT, 165203db220SDimitris Papastamos wm8991_adcmode); 166203db220SDimitris Papastamos 167203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_snd_controls[] = { 168203db220SDimitris Papastamos /* INMIXL */ 169203db220SDimitris Papastamos SOC_SINGLE("LIN12 PGA Boost", WM8991_INPUT_MIXER3, WM8991_L12MNBST_BIT, 1, 0), 170203db220SDimitris Papastamos SOC_SINGLE("LIN34 PGA Boost", WM8991_INPUT_MIXER3, WM8991_L34MNBST_BIT, 1, 0), 171203db220SDimitris Papastamos /* INMIXR */ 172203db220SDimitris Papastamos SOC_SINGLE("RIN12 PGA Boost", WM8991_INPUT_MIXER3, WM8991_R12MNBST_BIT, 1, 0), 173203db220SDimitris Papastamos SOC_SINGLE("RIN34 PGA Boost", WM8991_INPUT_MIXER3, WM8991_R34MNBST_BIT, 1, 0), 174203db220SDimitris Papastamos 175203db220SDimitris Papastamos /* LOMIX */ 176203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX LIN3 Bypass Volume", WM8991_OUTPUT_MIXER3, 177203db220SDimitris Papastamos WM8991_LLI3LOVOL_SHIFT, WM8991_LLI3LOVOL_MASK, 1, out_mix_tlv), 178203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX RIN12 PGA Bypass Volume", WM8991_OUTPUT_MIXER3, 179203db220SDimitris Papastamos WM8991_LR12LOVOL_SHIFT, WM8991_LR12LOVOL_MASK, 1, out_mix_tlv), 180203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX LIN12 PGA Bypass Volume", WM8991_OUTPUT_MIXER3, 181203db220SDimitris Papastamos WM8991_LL12LOVOL_SHIFT, WM8991_LL12LOVOL_MASK, 1, out_mix_tlv), 182203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX RIN3 Bypass Volume", WM8991_OUTPUT_MIXER5, 183203db220SDimitris Papastamos WM8991_LRI3LOVOL_SHIFT, WM8991_LRI3LOVOL_MASK, 1, out_mix_tlv), 184203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX AINRMUX Bypass Volume", WM8991_OUTPUT_MIXER5, 185203db220SDimitris Papastamos WM8991_LRBLOVOL_SHIFT, WM8991_LRBLOVOL_MASK, 1, out_mix_tlv), 186203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX AINLMUX Bypass Volume", WM8991_OUTPUT_MIXER5, 187203db220SDimitris Papastamos WM8991_LRBLOVOL_SHIFT, WM8991_LRBLOVOL_MASK, 1, out_mix_tlv), 188203db220SDimitris Papastamos 189203db220SDimitris Papastamos /* ROMIX */ 190203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX RIN3 Bypass Volume", WM8991_OUTPUT_MIXER4, 191203db220SDimitris Papastamos WM8991_RRI3ROVOL_SHIFT, WM8991_RRI3ROVOL_MASK, 1, out_mix_tlv), 192203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX LIN12 PGA Bypass Volume", WM8991_OUTPUT_MIXER4, 193203db220SDimitris Papastamos WM8991_RL12ROVOL_SHIFT, WM8991_RL12ROVOL_MASK, 1, out_mix_tlv), 194203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX RIN12 PGA Bypass Volume", WM8991_OUTPUT_MIXER4, 195203db220SDimitris Papastamos WM8991_RR12ROVOL_SHIFT, WM8991_RR12ROVOL_MASK, 1, out_mix_tlv), 196203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX LIN3 Bypass Volume", WM8991_OUTPUT_MIXER6, 197203db220SDimitris Papastamos WM8991_RLI3ROVOL_SHIFT, WM8991_RLI3ROVOL_MASK, 1, out_mix_tlv), 198203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX AINLMUX Bypass Volume", WM8991_OUTPUT_MIXER6, 199203db220SDimitris Papastamos WM8991_RLBROVOL_SHIFT, WM8991_RLBROVOL_MASK, 1, out_mix_tlv), 200203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX AINRMUX Bypass Volume", WM8991_OUTPUT_MIXER6, 201203db220SDimitris Papastamos WM8991_RRBROVOL_SHIFT, WM8991_RRBROVOL_MASK, 1, out_mix_tlv), 202203db220SDimitris Papastamos 203203db220SDimitris Papastamos /* LOUT */ 204203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("LOUT Volume", WM8991_LEFT_OUTPUT_VOLUME, 205203db220SDimitris Papastamos WM8991_LOUTVOL_SHIFT, WM8991_LOUTVOL_MASK, 0, out_pga_tlv), 206203db220SDimitris Papastamos SOC_SINGLE("LOUT ZC", WM8991_LEFT_OUTPUT_VOLUME, WM8991_LOZC_BIT, 1, 0), 207203db220SDimitris Papastamos 208203db220SDimitris Papastamos /* ROUT */ 209203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("ROUT Volume", WM8991_RIGHT_OUTPUT_VOLUME, 210203db220SDimitris Papastamos WM8991_ROUTVOL_SHIFT, WM8991_ROUTVOL_MASK, 0, out_pga_tlv), 211203db220SDimitris Papastamos SOC_SINGLE("ROUT ZC", WM8991_RIGHT_OUTPUT_VOLUME, WM8991_ROZC_BIT, 1, 0), 212203db220SDimitris Papastamos 213203db220SDimitris Papastamos /* LOPGA */ 214203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("LOPGA Volume", WM8991_LEFT_OPGA_VOLUME, 215203db220SDimitris Papastamos WM8991_LOPGAVOL_SHIFT, WM8991_LOPGAVOL_MASK, 0, out_pga_tlv), 216203db220SDimitris Papastamos SOC_SINGLE("LOPGA ZC Switch", WM8991_LEFT_OPGA_VOLUME, 217203db220SDimitris Papastamos WM8991_LOPGAZC_BIT, 1, 0), 218203db220SDimitris Papastamos 219203db220SDimitris Papastamos /* ROPGA */ 220203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("ROPGA Volume", WM8991_RIGHT_OPGA_VOLUME, 221203db220SDimitris Papastamos WM8991_ROPGAVOL_SHIFT, WM8991_ROPGAVOL_MASK, 0, out_pga_tlv), 222203db220SDimitris Papastamos SOC_SINGLE("ROPGA ZC Switch", WM8991_RIGHT_OPGA_VOLUME, 223203db220SDimitris Papastamos WM8991_ROPGAZC_BIT, 1, 0), 224203db220SDimitris Papastamos 225203db220SDimitris Papastamos SOC_SINGLE("LON Mute Switch", WM8991_LINE_OUTPUTS_VOLUME, 226203db220SDimitris Papastamos WM8991_LONMUTE_BIT, 1, 0), 227203db220SDimitris Papastamos SOC_SINGLE("LOP Mute Switch", WM8991_LINE_OUTPUTS_VOLUME, 228203db220SDimitris Papastamos WM8991_LOPMUTE_BIT, 1, 0), 229203db220SDimitris Papastamos SOC_SINGLE("LOP Attenuation Switch", WM8991_LINE_OUTPUTS_VOLUME, 230203db220SDimitris Papastamos WM8991_LOATTN_BIT, 1, 0), 231203db220SDimitris Papastamos SOC_SINGLE("RON Mute Switch", WM8991_LINE_OUTPUTS_VOLUME, 232203db220SDimitris Papastamos WM8991_RONMUTE_BIT, 1, 0), 233203db220SDimitris Papastamos SOC_SINGLE("ROP Mute Switch", WM8991_LINE_OUTPUTS_VOLUME, 234203db220SDimitris Papastamos WM8991_ROPMUTE_BIT, 1, 0), 235203db220SDimitris Papastamos SOC_SINGLE("ROP Attenuation Switch", WM8991_LINE_OUTPUTS_VOLUME, 236203db220SDimitris Papastamos WM8991_ROATTN_BIT, 1, 0), 237203db220SDimitris Papastamos 238203db220SDimitris Papastamos SOC_SINGLE("OUT3 Mute Switch", WM8991_OUT3_4_VOLUME, 239203db220SDimitris Papastamos WM8991_OUT3MUTE_BIT, 1, 0), 240203db220SDimitris Papastamos SOC_SINGLE("OUT3 Attenuation Switch", WM8991_OUT3_4_VOLUME, 241203db220SDimitris Papastamos WM8991_OUT3ATTN_BIT, 1, 0), 242203db220SDimitris Papastamos 243203db220SDimitris Papastamos SOC_SINGLE("OUT4 Mute Switch", WM8991_OUT3_4_VOLUME, 244203db220SDimitris Papastamos WM8991_OUT4MUTE_BIT, 1, 0), 245203db220SDimitris Papastamos SOC_SINGLE("OUT4 Attenuation Switch", WM8991_OUT3_4_VOLUME, 246203db220SDimitris Papastamos WM8991_OUT4ATTN_BIT, 1, 0), 247203db220SDimitris Papastamos 248203db220SDimitris Papastamos SOC_SINGLE("Speaker Mode Switch", WM8991_CLASSD1, 249203db220SDimitris Papastamos WM8991_CDMODE_BIT, 1, 0), 250203db220SDimitris Papastamos 251203db220SDimitris Papastamos SOC_SINGLE("Speaker Output Attenuation Volume", WM8991_SPEAKER_VOLUME, 252203db220SDimitris Papastamos WM8991_SPKVOL_SHIFT, WM8991_SPKVOL_MASK, 0), 253203db220SDimitris Papastamos SOC_SINGLE("Speaker DC Boost Volume", WM8991_CLASSD3, 254203db220SDimitris Papastamos WM8991_DCGAIN_SHIFT, WM8991_DCGAIN_MASK, 0), 255203db220SDimitris Papastamos SOC_SINGLE("Speaker AC Boost Volume", WM8991_CLASSD3, 256203db220SDimitris Papastamos WM8991_ACGAIN_SHIFT, WM8991_ACGAIN_MASK, 0), 257203db220SDimitris Papastamos 258203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("Left DAC Digital Volume", 259203db220SDimitris Papastamos WM8991_LEFT_DAC_DIGITAL_VOLUME, 260203db220SDimitris Papastamos WM8991_DACL_VOL_SHIFT, 261203db220SDimitris Papastamos WM8991_DACL_VOL_MASK, 262203db220SDimitris Papastamos 0, 263203db220SDimitris Papastamos out_dac_tlv), 264203db220SDimitris Papastamos 265203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("Right DAC Digital Volume", 266203db220SDimitris Papastamos WM8991_RIGHT_DAC_DIGITAL_VOLUME, 267203db220SDimitris Papastamos WM8991_DACR_VOL_SHIFT, 268203db220SDimitris Papastamos WM8991_DACR_VOL_MASK, 269203db220SDimitris Papastamos 0, 270203db220SDimitris Papastamos out_dac_tlv), 271203db220SDimitris Papastamos 272203db220SDimitris Papastamos SOC_ENUM("Left Digital Sidetone", wm8991_left_digital_sidetone_enum), 273203db220SDimitris Papastamos SOC_ENUM("Right Digital Sidetone", wm8991_right_digital_sidetone_enum), 274203db220SDimitris Papastamos 275203db220SDimitris Papastamos SOC_SINGLE_TLV("Left Digital Sidetone Volume", WM8991_DIGITAL_SIDE_TONE, 276203db220SDimitris Papastamos WM8991_ADCL_DAC_SVOL_SHIFT, WM8991_ADCL_DAC_SVOL_MASK, 0, 277203db220SDimitris Papastamos out_sidetone_tlv), 278203db220SDimitris Papastamos SOC_SINGLE_TLV("Right Digital Sidetone Volume", WM8991_DIGITAL_SIDE_TONE, 279203db220SDimitris Papastamos WM8991_ADCR_DAC_SVOL_SHIFT, WM8991_ADCR_DAC_SVOL_MASK, 0, 280203db220SDimitris Papastamos out_sidetone_tlv), 281203db220SDimitris Papastamos 282203db220SDimitris Papastamos SOC_SINGLE("ADC Digital High Pass Filter Switch", WM8991_ADC_CTRL, 283203db220SDimitris Papastamos WM8991_ADC_HPF_ENA_BIT, 1, 0), 284203db220SDimitris Papastamos 285203db220SDimitris Papastamos SOC_ENUM("ADC HPF Mode", wm8991_right_adcmode_enum), 286203db220SDimitris Papastamos 287203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("Left ADC Digital Volume", 288203db220SDimitris Papastamos WM8991_LEFT_ADC_DIGITAL_VOLUME, 289203db220SDimitris Papastamos WM8991_ADCL_VOL_SHIFT, 290203db220SDimitris Papastamos WM8991_ADCL_VOL_MASK, 291203db220SDimitris Papastamos 0, 292203db220SDimitris Papastamos in_adc_tlv), 293203db220SDimitris Papastamos 294203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("Right ADC Digital Volume", 295203db220SDimitris Papastamos WM8991_RIGHT_ADC_DIGITAL_VOLUME, 296203db220SDimitris Papastamos WM8991_ADCR_VOL_SHIFT, 297203db220SDimitris Papastamos WM8991_ADCR_VOL_MASK, 298203db220SDimitris Papastamos 0, 299203db220SDimitris Papastamos in_adc_tlv), 300203db220SDimitris Papastamos 301203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("LIN12 Volume", 302203db220SDimitris Papastamos WM8991_LEFT_LINE_INPUT_1_2_VOLUME, 303203db220SDimitris Papastamos WM8991_LIN12VOL_SHIFT, 304203db220SDimitris Papastamos WM8991_LIN12VOL_MASK, 305203db220SDimitris Papastamos 0, 306203db220SDimitris Papastamos in_pga_tlv), 307203db220SDimitris Papastamos 308203db220SDimitris Papastamos SOC_SINGLE("LIN12 ZC Switch", WM8991_LEFT_LINE_INPUT_1_2_VOLUME, 309203db220SDimitris Papastamos WM8991_LI12ZC_BIT, 1, 0), 310203db220SDimitris Papastamos 311203db220SDimitris Papastamos SOC_SINGLE("LIN12 Mute Switch", WM8991_LEFT_LINE_INPUT_1_2_VOLUME, 312203db220SDimitris Papastamos WM8991_LI12MUTE_BIT, 1, 0), 313203db220SDimitris Papastamos 314203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("LIN34 Volume", 315203db220SDimitris Papastamos WM8991_LEFT_LINE_INPUT_3_4_VOLUME, 316203db220SDimitris Papastamos WM8991_LIN34VOL_SHIFT, 317203db220SDimitris Papastamos WM8991_LIN34VOL_MASK, 318203db220SDimitris Papastamos 0, 319203db220SDimitris Papastamos in_pga_tlv), 320203db220SDimitris Papastamos 321203db220SDimitris Papastamos SOC_SINGLE("LIN34 ZC Switch", WM8991_LEFT_LINE_INPUT_3_4_VOLUME, 322203db220SDimitris Papastamos WM8991_LI34ZC_BIT, 1, 0), 323203db220SDimitris Papastamos 324203db220SDimitris Papastamos SOC_SINGLE("LIN34 Mute Switch", WM8991_LEFT_LINE_INPUT_3_4_VOLUME, 325203db220SDimitris Papastamos WM8991_LI34MUTE_BIT, 1, 0), 326203db220SDimitris Papastamos 327203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("RIN12 Volume", 328203db220SDimitris Papastamos WM8991_RIGHT_LINE_INPUT_1_2_VOLUME, 329203db220SDimitris Papastamos WM8991_RIN12VOL_SHIFT, 330203db220SDimitris Papastamos WM8991_RIN12VOL_MASK, 331203db220SDimitris Papastamos 0, 332203db220SDimitris Papastamos in_pga_tlv), 333203db220SDimitris Papastamos 334203db220SDimitris Papastamos SOC_SINGLE("RIN12 ZC Switch", WM8991_RIGHT_LINE_INPUT_1_2_VOLUME, 335203db220SDimitris Papastamos WM8991_RI12ZC_BIT, 1, 0), 336203db220SDimitris Papastamos 337203db220SDimitris Papastamos SOC_SINGLE("RIN12 Mute Switch", WM8991_RIGHT_LINE_INPUT_1_2_VOLUME, 338203db220SDimitris Papastamos WM8991_RI12MUTE_BIT, 1, 0), 339203db220SDimitris Papastamos 340203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("RIN34 Volume", 341203db220SDimitris Papastamos WM8991_RIGHT_LINE_INPUT_3_4_VOLUME, 342203db220SDimitris Papastamos WM8991_RIN34VOL_SHIFT, 343203db220SDimitris Papastamos WM8991_RIN34VOL_MASK, 344203db220SDimitris Papastamos 0, 345203db220SDimitris Papastamos in_pga_tlv), 346203db220SDimitris Papastamos 347203db220SDimitris Papastamos SOC_SINGLE("RIN34 ZC Switch", WM8991_RIGHT_LINE_INPUT_3_4_VOLUME, 348203db220SDimitris Papastamos WM8991_RI34ZC_BIT, 1, 0), 349203db220SDimitris Papastamos 350203db220SDimitris Papastamos SOC_SINGLE("RIN34 Mute Switch", WM8991_RIGHT_LINE_INPUT_3_4_VOLUME, 351203db220SDimitris Papastamos WM8991_RI34MUTE_BIT, 1, 0), 352203db220SDimitris Papastamos }; 353203db220SDimitris Papastamos 354203db220SDimitris Papastamos /* 355203db220SDimitris Papastamos * _DAPM_ Controls 356203db220SDimitris Papastamos */ 357203db220SDimitris Papastamos static int outmixer_event(struct snd_soc_dapm_widget *w, 358203db220SDimitris Papastamos struct snd_kcontrol *kcontrol, int event) 359203db220SDimitris Papastamos { 360bf338e5bSKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 361203db220SDimitris Papastamos u32 reg_shift = kcontrol->private_value & 0xfff; 362203db220SDimitris Papastamos int ret = 0; 363203db220SDimitris Papastamos u16 reg; 364203db220SDimitris Papastamos 365203db220SDimitris Papastamos switch (reg_shift) { 366203db220SDimitris Papastamos case WM8991_SPEAKER_MIXER | (WM8991_LDSPK_BIT << 8): 3676d75dfc3SKuninori Morimoto reg = snd_soc_component_read(component, WM8991_OUTPUT_MIXER1); 368203db220SDimitris Papastamos if (reg & WM8991_LDLO) { 369203db220SDimitris Papastamos printk(KERN_WARNING 370203db220SDimitris Papastamos "Cannot set as Output Mixer 1 LDLO Set\n"); 371203db220SDimitris Papastamos ret = -1; 372203db220SDimitris Papastamos } 373203db220SDimitris Papastamos break; 374203db220SDimitris Papastamos 375203db220SDimitris Papastamos case WM8991_SPEAKER_MIXER | (WM8991_RDSPK_BIT << 8): 3766d75dfc3SKuninori Morimoto reg = snd_soc_component_read(component, WM8991_OUTPUT_MIXER2); 377203db220SDimitris Papastamos if (reg & WM8991_RDRO) { 378203db220SDimitris Papastamos printk(KERN_WARNING 379203db220SDimitris Papastamos "Cannot set as Output Mixer 2 RDRO Set\n"); 380203db220SDimitris Papastamos ret = -1; 381203db220SDimitris Papastamos } 382203db220SDimitris Papastamos break; 383203db220SDimitris Papastamos 384203db220SDimitris Papastamos case WM8991_OUTPUT_MIXER1 | (WM8991_LDLO_BIT << 8): 3856d75dfc3SKuninori Morimoto reg = snd_soc_component_read(component, WM8991_SPEAKER_MIXER); 386203db220SDimitris Papastamos if (reg & WM8991_LDSPK) { 387203db220SDimitris Papastamos printk(KERN_WARNING 388203db220SDimitris Papastamos "Cannot set as Speaker Mixer LDSPK Set\n"); 389203db220SDimitris Papastamos ret = -1; 390203db220SDimitris Papastamos } 391203db220SDimitris Papastamos break; 392203db220SDimitris Papastamos 393203db220SDimitris Papastamos case WM8991_OUTPUT_MIXER2 | (WM8991_RDRO_BIT << 8): 3946d75dfc3SKuninori Morimoto reg = snd_soc_component_read(component, WM8991_SPEAKER_MIXER); 395203db220SDimitris Papastamos if (reg & WM8991_RDSPK) { 396203db220SDimitris Papastamos printk(KERN_WARNING 397203db220SDimitris Papastamos "Cannot set as Speaker Mixer RDSPK Set\n"); 398203db220SDimitris Papastamos ret = -1; 399203db220SDimitris Papastamos } 400203db220SDimitris Papastamos break; 401203db220SDimitris Papastamos } 402203db220SDimitris Papastamos 403203db220SDimitris Papastamos return ret; 404203db220SDimitris Papastamos } 405203db220SDimitris Papastamos 406203db220SDimitris Papastamos /* INMIX dB values */ 40798695eabSTakashi Sakamoto static const SNDRV_CTL_TLVD_DECLARE_DB_SCALE(in_mix_tlv, -1200, 300, 1); 408203db220SDimitris Papastamos 409203db220SDimitris Papastamos /* Left In PGA Connections */ 410203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_lin12_pga_controls[] = { 411203db220SDimitris Papastamos SOC_DAPM_SINGLE("LIN1 Switch", WM8991_INPUT_MIXER2, WM8991_LMN1_BIT, 1, 0), 412203db220SDimitris Papastamos SOC_DAPM_SINGLE("LIN2 Switch", WM8991_INPUT_MIXER2, WM8991_LMP2_BIT, 1, 0), 413203db220SDimitris Papastamos }; 414203db220SDimitris Papastamos 415203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_lin34_pga_controls[] = { 416203db220SDimitris Papastamos SOC_DAPM_SINGLE("LIN3 Switch", WM8991_INPUT_MIXER2, WM8991_LMN3_BIT, 1, 0), 417203db220SDimitris Papastamos SOC_DAPM_SINGLE("LIN4 Switch", WM8991_INPUT_MIXER2, WM8991_LMP4_BIT, 1, 0), 418203db220SDimitris Papastamos }; 419203db220SDimitris Papastamos 420203db220SDimitris Papastamos /* Right In PGA Connections */ 421203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_rin12_pga_controls[] = { 422203db220SDimitris Papastamos SOC_DAPM_SINGLE("RIN1 Switch", WM8991_INPUT_MIXER2, WM8991_RMN1_BIT, 1, 0), 423203db220SDimitris Papastamos SOC_DAPM_SINGLE("RIN2 Switch", WM8991_INPUT_MIXER2, WM8991_RMP2_BIT, 1, 0), 424203db220SDimitris Papastamos }; 425203db220SDimitris Papastamos 426203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_rin34_pga_controls[] = { 427203db220SDimitris Papastamos SOC_DAPM_SINGLE("RIN3 Switch", WM8991_INPUT_MIXER2, WM8991_RMN3_BIT, 1, 0), 428203db220SDimitris Papastamos SOC_DAPM_SINGLE("RIN4 Switch", WM8991_INPUT_MIXER2, WM8991_RMP4_BIT, 1, 0), 429203db220SDimitris Papastamos }; 430203db220SDimitris Papastamos 431203db220SDimitris Papastamos /* INMIXL */ 432203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_inmixl_controls[] = { 433203db220SDimitris Papastamos SOC_DAPM_SINGLE_TLV("Record Left Volume", WM8991_INPUT_MIXER3, 434203db220SDimitris Papastamos WM8991_LDBVOL_SHIFT, WM8991_LDBVOL_MASK, 0, in_mix_tlv), 435203db220SDimitris Papastamos SOC_DAPM_SINGLE_TLV("LIN2 Volume", WM8991_INPUT_MIXER5, WM8991_LI2BVOL_SHIFT, 436203db220SDimitris Papastamos 7, 0, in_mix_tlv), 437203db220SDimitris Papastamos SOC_DAPM_SINGLE("LINPGA12 Switch", WM8991_INPUT_MIXER3, WM8991_L12MNB_BIT, 438203db220SDimitris Papastamos 1, 0), 439203db220SDimitris Papastamos SOC_DAPM_SINGLE("LINPGA34 Switch", WM8991_INPUT_MIXER3, WM8991_L34MNB_BIT, 440203db220SDimitris Papastamos 1, 0), 441203db220SDimitris Papastamos }; 442203db220SDimitris Papastamos 443203db220SDimitris Papastamos /* INMIXR */ 444203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_inmixr_controls[] = { 445203db220SDimitris Papastamos SOC_DAPM_SINGLE_TLV("Record Right Volume", WM8991_INPUT_MIXER4, 446203db220SDimitris Papastamos WM8991_RDBVOL_SHIFT, WM8991_RDBVOL_MASK, 0, in_mix_tlv), 447203db220SDimitris Papastamos SOC_DAPM_SINGLE_TLV("RIN2 Volume", WM8991_INPUT_MIXER6, WM8991_RI2BVOL_SHIFT, 448203db220SDimitris Papastamos 7, 0, in_mix_tlv), 449203db220SDimitris Papastamos SOC_DAPM_SINGLE("RINPGA12 Switch", WM8991_INPUT_MIXER3, WM8991_L12MNB_BIT, 450203db220SDimitris Papastamos 1, 0), 451203db220SDimitris Papastamos SOC_DAPM_SINGLE("RINPGA34 Switch", WM8991_INPUT_MIXER3, WM8991_L34MNB_BIT, 452203db220SDimitris Papastamos 1, 0), 453203db220SDimitris Papastamos }; 454203db220SDimitris Papastamos 455203db220SDimitris Papastamos /* AINLMUX */ 456203db220SDimitris Papastamos static const char *wm8991_ainlmux[] = 457203db220SDimitris Papastamos {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"}; 458203db220SDimitris Papastamos 459d07338b0STakashi Iwai static SOC_ENUM_SINGLE_DECL(wm8991_ainlmux_enum, 460d07338b0STakashi Iwai WM8991_INPUT_MIXER1, WM8991_AINLMODE_SHIFT, 461d07338b0STakashi Iwai wm8991_ainlmux); 462203db220SDimitris Papastamos 463203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_ainlmux_controls = 464203db220SDimitris Papastamos SOC_DAPM_ENUM("Route", wm8991_ainlmux_enum); 465203db220SDimitris Papastamos 466203db220SDimitris Papastamos /* DIFFINL */ 467203db220SDimitris Papastamos 468203db220SDimitris Papastamos /* AINRMUX */ 469203db220SDimitris Papastamos static const char *wm8991_ainrmux[] = 470203db220SDimitris Papastamos {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"}; 471203db220SDimitris Papastamos 472d07338b0STakashi Iwai static SOC_ENUM_SINGLE_DECL(wm8991_ainrmux_enum, 473d07338b0STakashi Iwai WM8991_INPUT_MIXER1, WM8991_AINRMODE_SHIFT, 474d07338b0STakashi Iwai wm8991_ainrmux); 475203db220SDimitris Papastamos 476203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_ainrmux_controls = 477203db220SDimitris Papastamos SOC_DAPM_ENUM("Route", wm8991_ainrmux_enum); 478203db220SDimitris Papastamos 479203db220SDimitris Papastamos /* LOMIX */ 480203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_lomix_controls[] = { 481203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX Right ADC Bypass Switch", WM8991_OUTPUT_MIXER1, 482203db220SDimitris Papastamos WM8991_LRBLO_BIT, 1, 0), 483203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX Left ADC Bypass Switch", WM8991_OUTPUT_MIXER1, 484203db220SDimitris Papastamos WM8991_LLBLO_BIT, 1, 0), 485203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX RIN3 Bypass Switch", WM8991_OUTPUT_MIXER1, 486203db220SDimitris Papastamos WM8991_LRI3LO_BIT, 1, 0), 487203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX LIN3 Bypass Switch", WM8991_OUTPUT_MIXER1, 488203db220SDimitris Papastamos WM8991_LLI3LO_BIT, 1, 0), 489203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX RIN12 PGA Bypass Switch", WM8991_OUTPUT_MIXER1, 490203db220SDimitris Papastamos WM8991_LR12LO_BIT, 1, 0), 491203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX LIN12 PGA Bypass Switch", WM8991_OUTPUT_MIXER1, 492203db220SDimitris Papastamos WM8991_LL12LO_BIT, 1, 0), 493203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX Left DAC Switch", WM8991_OUTPUT_MIXER1, 494203db220SDimitris Papastamos WM8991_LDLO_BIT, 1, 0), 495203db220SDimitris Papastamos }; 496203db220SDimitris Papastamos 497203db220SDimitris Papastamos /* ROMIX */ 498203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_romix_controls[] = { 499203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX Left ADC Bypass Switch", WM8991_OUTPUT_MIXER2, 500203db220SDimitris Papastamos WM8991_RLBRO_BIT, 1, 0), 501203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX Right ADC Bypass Switch", WM8991_OUTPUT_MIXER2, 502203db220SDimitris Papastamos WM8991_RRBRO_BIT, 1, 0), 503203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX LIN3 Bypass Switch", WM8991_OUTPUT_MIXER2, 504203db220SDimitris Papastamos WM8991_RLI3RO_BIT, 1, 0), 505203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX RIN3 Bypass Switch", WM8991_OUTPUT_MIXER2, 506203db220SDimitris Papastamos WM8991_RRI3RO_BIT, 1, 0), 507203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX LIN12 PGA Bypass Switch", WM8991_OUTPUT_MIXER2, 508203db220SDimitris Papastamos WM8991_RL12RO_BIT, 1, 0), 509203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX RIN12 PGA Bypass Switch", WM8991_OUTPUT_MIXER2, 510203db220SDimitris Papastamos WM8991_RR12RO_BIT, 1, 0), 511203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX Right DAC Switch", WM8991_OUTPUT_MIXER2, 512203db220SDimitris Papastamos WM8991_RDRO_BIT, 1, 0), 513203db220SDimitris Papastamos }; 514203db220SDimitris Papastamos 515203db220SDimitris Papastamos /* LONMIX */ 516203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_lonmix_controls[] = { 517203db220SDimitris Papastamos SOC_DAPM_SINGLE("LONMIX Left Mixer PGA Switch", WM8991_LINE_MIXER1, 518203db220SDimitris Papastamos WM8991_LLOPGALON_BIT, 1, 0), 519203db220SDimitris Papastamos SOC_DAPM_SINGLE("LONMIX Right Mixer PGA Switch", WM8991_LINE_MIXER1, 520203db220SDimitris Papastamos WM8991_LROPGALON_BIT, 1, 0), 521203db220SDimitris Papastamos SOC_DAPM_SINGLE("LONMIX Inverted LOP Switch", WM8991_LINE_MIXER1, 522203db220SDimitris Papastamos WM8991_LOPLON_BIT, 1, 0), 523203db220SDimitris Papastamos }; 524203db220SDimitris Papastamos 525203db220SDimitris Papastamos /* LOPMIX */ 526203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_lopmix_controls[] = { 527203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOPMIX Right Mic Bypass Switch", WM8991_LINE_MIXER1, 528203db220SDimitris Papastamos WM8991_LR12LOP_BIT, 1, 0), 529203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOPMIX Left Mic Bypass Switch", WM8991_LINE_MIXER1, 530203db220SDimitris Papastamos WM8991_LL12LOP_BIT, 1, 0), 531203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOPMIX Left Mixer PGA Switch", WM8991_LINE_MIXER1, 532203db220SDimitris Papastamos WM8991_LLOPGALOP_BIT, 1, 0), 533203db220SDimitris Papastamos }; 534203db220SDimitris Papastamos 535203db220SDimitris Papastamos /* RONMIX */ 536203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_ronmix_controls[] = { 537203db220SDimitris Papastamos SOC_DAPM_SINGLE("RONMIX Right Mixer PGA Switch", WM8991_LINE_MIXER2, 538203db220SDimitris Papastamos WM8991_RROPGARON_BIT, 1, 0), 539203db220SDimitris Papastamos SOC_DAPM_SINGLE("RONMIX Left Mixer PGA Switch", WM8991_LINE_MIXER2, 540203db220SDimitris Papastamos WM8991_RLOPGARON_BIT, 1, 0), 541203db220SDimitris Papastamos SOC_DAPM_SINGLE("RONMIX Inverted ROP Switch", WM8991_LINE_MIXER2, 542203db220SDimitris Papastamos WM8991_ROPRON_BIT, 1, 0), 543203db220SDimitris Papastamos }; 544203db220SDimitris Papastamos 545203db220SDimitris Papastamos /* ROPMIX */ 546203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_ropmix_controls[] = { 547203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROPMIX Left Mic Bypass Switch", WM8991_LINE_MIXER2, 548203db220SDimitris Papastamos WM8991_RL12ROP_BIT, 1, 0), 549203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROPMIX Right Mic Bypass Switch", WM8991_LINE_MIXER2, 550203db220SDimitris Papastamos WM8991_RR12ROP_BIT, 1, 0), 551203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROPMIX Right Mixer PGA Switch", WM8991_LINE_MIXER2, 552203db220SDimitris Papastamos WM8991_RROPGAROP_BIT, 1, 0), 553203db220SDimitris Papastamos }; 554203db220SDimitris Papastamos 555203db220SDimitris Papastamos /* OUT3MIX */ 556203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_out3mix_controls[] = { 557203db220SDimitris Papastamos SOC_DAPM_SINGLE("OUT3MIX LIN4RXN Bypass Switch", WM8991_OUT3_4_MIXER, 558203db220SDimitris Papastamos WM8991_LI4O3_BIT, 1, 0), 559203db220SDimitris Papastamos SOC_DAPM_SINGLE("OUT3MIX Left Out PGA Switch", WM8991_OUT3_4_MIXER, 560203db220SDimitris Papastamos WM8991_LPGAO3_BIT, 1, 0), 561203db220SDimitris Papastamos }; 562203db220SDimitris Papastamos 563203db220SDimitris Papastamos /* OUT4MIX */ 564203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_out4mix_controls[] = { 565203db220SDimitris Papastamos SOC_DAPM_SINGLE("OUT4MIX Right Out PGA Switch", WM8991_OUT3_4_MIXER, 566203db220SDimitris Papastamos WM8991_RPGAO4_BIT, 1, 0), 567203db220SDimitris Papastamos SOC_DAPM_SINGLE("OUT4MIX RIN4RXP Bypass Switch", WM8991_OUT3_4_MIXER, 568203db220SDimitris Papastamos WM8991_RI4O4_BIT, 1, 0), 569203db220SDimitris Papastamos }; 570203db220SDimitris Papastamos 571203db220SDimitris Papastamos /* SPKMIX */ 572203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_spkmix_controls[] = { 573203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX LIN2 Bypass Switch", WM8991_SPEAKER_MIXER, 574203db220SDimitris Papastamos WM8991_LI2SPK_BIT, 1, 0), 575203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX LADC Bypass Switch", WM8991_SPEAKER_MIXER, 576203db220SDimitris Papastamos WM8991_LB2SPK_BIT, 1, 0), 577203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX Left Mixer PGA Switch", WM8991_SPEAKER_MIXER, 578203db220SDimitris Papastamos WM8991_LOPGASPK_BIT, 1, 0), 579203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX Left DAC Switch", WM8991_SPEAKER_MIXER, 580203db220SDimitris Papastamos WM8991_LDSPK_BIT, 1, 0), 581203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX Right DAC Switch", WM8991_SPEAKER_MIXER, 582203db220SDimitris Papastamos WM8991_RDSPK_BIT, 1, 0), 583203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX Right Mixer PGA Switch", WM8991_SPEAKER_MIXER, 584203db220SDimitris Papastamos WM8991_ROPGASPK_BIT, 1, 0), 585203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX RADC Bypass Switch", WM8991_SPEAKER_MIXER, 586203db220SDimitris Papastamos WM8991_RL12ROP_BIT, 1, 0), 587203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX RIN2 Bypass Switch", WM8991_SPEAKER_MIXER, 588203db220SDimitris Papastamos WM8991_RI2SPK_BIT, 1, 0), 589203db220SDimitris Papastamos }; 590203db220SDimitris Papastamos 591203db220SDimitris Papastamos static const struct snd_soc_dapm_widget wm8991_dapm_widgets[] = { 592203db220SDimitris Papastamos /* Input Side */ 593203db220SDimitris Papastamos /* Input Lines */ 594203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("LIN1"), 595203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("LIN2"), 596203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("LIN3"), 597203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("LIN4RXN"), 598203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("RIN3"), 599203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("RIN4RXP"), 600203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("RIN1"), 601203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("RIN2"), 602203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("Internal ADC Source"), 603203db220SDimitris Papastamos 6046a077336SMark Brown SND_SOC_DAPM_SUPPLY("INL", WM8991_POWER_MANAGEMENT_2, 6056a077336SMark Brown WM8991_AINL_ENA_BIT, 0, NULL, 0), 6066a077336SMark Brown SND_SOC_DAPM_SUPPLY("INR", WM8991_POWER_MANAGEMENT_2, 6076a077336SMark Brown WM8991_AINR_ENA_BIT, 0, NULL, 0), 6086a077336SMark Brown 609203db220SDimitris Papastamos /* DACs */ 610203db220SDimitris Papastamos SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8991_POWER_MANAGEMENT_2, 611203db220SDimitris Papastamos WM8991_ADCL_ENA_BIT, 0), 612203db220SDimitris Papastamos SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8991_POWER_MANAGEMENT_2, 613203db220SDimitris Papastamos WM8991_ADCR_ENA_BIT, 0), 614203db220SDimitris Papastamos 615203db220SDimitris Papastamos /* Input PGAs */ 616203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("LIN12 PGA", WM8991_POWER_MANAGEMENT_2, WM8991_LIN12_ENA_BIT, 617203db220SDimitris Papastamos 0, &wm8991_dapm_lin12_pga_controls[0], 618203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_lin12_pga_controls)), 619203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("LIN34 PGA", WM8991_POWER_MANAGEMENT_2, WM8991_LIN34_ENA_BIT, 620203db220SDimitris Papastamos 0, &wm8991_dapm_lin34_pga_controls[0], 621203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_lin34_pga_controls)), 622203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("RIN12 PGA", WM8991_POWER_MANAGEMENT_2, WM8991_RIN12_ENA_BIT, 623203db220SDimitris Papastamos 0, &wm8991_dapm_rin12_pga_controls[0], 624203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_rin12_pga_controls)), 625203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("RIN34 PGA", WM8991_POWER_MANAGEMENT_2, WM8991_RIN34_ENA_BIT, 626203db220SDimitris Papastamos 0, &wm8991_dapm_rin34_pga_controls[0], 627203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_rin34_pga_controls)), 628203db220SDimitris Papastamos 629203db220SDimitris Papastamos /* INMIXL */ 6306a077336SMark Brown SND_SOC_DAPM_MIXER("INMIXL", SND_SOC_NOPM, 0, 0, 631203db220SDimitris Papastamos &wm8991_dapm_inmixl_controls[0], 6326a077336SMark Brown ARRAY_SIZE(wm8991_dapm_inmixl_controls)), 633203db220SDimitris Papastamos 634203db220SDimitris Papastamos /* AINLMUX */ 6356a077336SMark Brown SND_SOC_DAPM_MUX("AINLMUX", SND_SOC_NOPM, 0, 0, 6366a077336SMark Brown &wm8991_dapm_ainlmux_controls), 637203db220SDimitris Papastamos 638203db220SDimitris Papastamos /* INMIXR */ 6396a077336SMark Brown SND_SOC_DAPM_MIXER("INMIXR", SND_SOC_NOPM, 0, 0, 640203db220SDimitris Papastamos &wm8991_dapm_inmixr_controls[0], 6416a077336SMark Brown ARRAY_SIZE(wm8991_dapm_inmixr_controls)), 642203db220SDimitris Papastamos 643203db220SDimitris Papastamos /* AINRMUX */ 6446a077336SMark Brown SND_SOC_DAPM_MUX("AINRMUX", SND_SOC_NOPM, 0, 0, 6456a077336SMark Brown &wm8991_dapm_ainrmux_controls), 646203db220SDimitris Papastamos 647203db220SDimitris Papastamos /* Output Side */ 648203db220SDimitris Papastamos /* DACs */ 649203db220SDimitris Papastamos SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8991_POWER_MANAGEMENT_3, 650203db220SDimitris Papastamos WM8991_DACL_ENA_BIT, 0), 651203db220SDimitris Papastamos SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8991_POWER_MANAGEMENT_3, 652203db220SDimitris Papastamos WM8991_DACR_ENA_BIT, 0), 653203db220SDimitris Papastamos 654203db220SDimitris Papastamos /* LOMIX */ 655203db220SDimitris Papastamos SND_SOC_DAPM_MIXER_E("LOMIX", WM8991_POWER_MANAGEMENT_3, WM8991_LOMIX_ENA_BIT, 656203db220SDimitris Papastamos 0, &wm8991_dapm_lomix_controls[0], 657203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_lomix_controls), 658203db220SDimitris Papastamos outmixer_event, SND_SOC_DAPM_PRE_REG), 659203db220SDimitris Papastamos 660203db220SDimitris Papastamos /* LONMIX */ 661203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("LONMIX", WM8991_POWER_MANAGEMENT_3, WM8991_LON_ENA_BIT, 0, 662203db220SDimitris Papastamos &wm8991_dapm_lonmix_controls[0], 663203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_lonmix_controls)), 664203db220SDimitris Papastamos 665203db220SDimitris Papastamos /* LOPMIX */ 666203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("LOPMIX", WM8991_POWER_MANAGEMENT_3, WM8991_LOP_ENA_BIT, 0, 667203db220SDimitris Papastamos &wm8991_dapm_lopmix_controls[0], 668203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_lopmix_controls)), 669203db220SDimitris Papastamos 670203db220SDimitris Papastamos /* OUT3MIX */ 671203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("OUT3MIX", WM8991_POWER_MANAGEMENT_1, WM8991_OUT3_ENA_BIT, 0, 672203db220SDimitris Papastamos &wm8991_dapm_out3mix_controls[0], 673203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_out3mix_controls)), 674203db220SDimitris Papastamos 675203db220SDimitris Papastamos /* SPKMIX */ 676203db220SDimitris Papastamos SND_SOC_DAPM_MIXER_E("SPKMIX", WM8991_POWER_MANAGEMENT_1, WM8991_SPK_ENA_BIT, 0, 677203db220SDimitris Papastamos &wm8991_dapm_spkmix_controls[0], 678203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_spkmix_controls), outmixer_event, 679203db220SDimitris Papastamos SND_SOC_DAPM_PRE_REG), 680203db220SDimitris Papastamos 681203db220SDimitris Papastamos /* OUT4MIX */ 682203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("OUT4MIX", WM8991_POWER_MANAGEMENT_1, WM8991_OUT4_ENA_BIT, 0, 683203db220SDimitris Papastamos &wm8991_dapm_out4mix_controls[0], 684203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_out4mix_controls)), 685203db220SDimitris Papastamos 686203db220SDimitris Papastamos /* ROPMIX */ 687203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("ROPMIX", WM8991_POWER_MANAGEMENT_3, WM8991_ROP_ENA_BIT, 0, 688203db220SDimitris Papastamos &wm8991_dapm_ropmix_controls[0], 689203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_ropmix_controls)), 690203db220SDimitris Papastamos 691203db220SDimitris Papastamos /* RONMIX */ 692203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("RONMIX", WM8991_POWER_MANAGEMENT_3, WM8991_RON_ENA_BIT, 0, 693203db220SDimitris Papastamos &wm8991_dapm_ronmix_controls[0], 694203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_ronmix_controls)), 695203db220SDimitris Papastamos 696203db220SDimitris Papastamos /* ROMIX */ 697203db220SDimitris Papastamos SND_SOC_DAPM_MIXER_E("ROMIX", WM8991_POWER_MANAGEMENT_3, WM8991_ROMIX_ENA_BIT, 698203db220SDimitris Papastamos 0, &wm8991_dapm_romix_controls[0], 699203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_romix_controls), 700203db220SDimitris Papastamos outmixer_event, SND_SOC_DAPM_PRE_REG), 701203db220SDimitris Papastamos 702203db220SDimitris Papastamos /* LOUT PGA */ 703203db220SDimitris Papastamos SND_SOC_DAPM_PGA("LOUT PGA", WM8991_POWER_MANAGEMENT_1, WM8991_LOUT_ENA_BIT, 0, 704203db220SDimitris Papastamos NULL, 0), 705203db220SDimitris Papastamos 706203db220SDimitris Papastamos /* ROUT PGA */ 707203db220SDimitris Papastamos SND_SOC_DAPM_PGA("ROUT PGA", WM8991_POWER_MANAGEMENT_1, WM8991_ROUT_ENA_BIT, 0, 708203db220SDimitris Papastamos NULL, 0), 709203db220SDimitris Papastamos 710203db220SDimitris Papastamos /* LOPGA */ 711203db220SDimitris Papastamos SND_SOC_DAPM_PGA("LOPGA", WM8991_POWER_MANAGEMENT_3, WM8991_LOPGA_ENA_BIT, 0, 712203db220SDimitris Papastamos NULL, 0), 713203db220SDimitris Papastamos 714203db220SDimitris Papastamos /* ROPGA */ 715203db220SDimitris Papastamos SND_SOC_DAPM_PGA("ROPGA", WM8991_POWER_MANAGEMENT_3, WM8991_ROPGA_ENA_BIT, 0, 716203db220SDimitris Papastamos NULL, 0), 717203db220SDimitris Papastamos 718203db220SDimitris Papastamos /* MICBIAS */ 719b6406a80SMark Brown SND_SOC_DAPM_SUPPLY("MICBIAS", WM8991_POWER_MANAGEMENT_1, 720b6406a80SMark Brown WM8991_MICBIAS_ENA_BIT, 0, NULL, 0), 721203db220SDimitris Papastamos 722203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("LON"), 723203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("LOP"), 724203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("OUT3"), 725203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("LOUT"), 726203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("SPKN"), 727203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("SPKP"), 728203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("ROUT"), 729203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("OUT4"), 730203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("ROP"), 731203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("RON"), 732203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("OUT"), 733203db220SDimitris Papastamos 734203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("Internal DAC Sink"), 735203db220SDimitris Papastamos }; 736203db220SDimitris Papastamos 73789824995SMark Brown static const struct snd_soc_dapm_route wm8991_dapm_routes[] = { 738203db220SDimitris Papastamos /* Make DACs turn on when playing even if not mixed into any outputs */ 739203db220SDimitris Papastamos {"Internal DAC Sink", NULL, "Left DAC"}, 740203db220SDimitris Papastamos {"Internal DAC Sink", NULL, "Right DAC"}, 741203db220SDimitris Papastamos 742203db220SDimitris Papastamos /* Make ADCs turn on when recording even if not mixed from any inputs */ 743203db220SDimitris Papastamos {"Left ADC", NULL, "Internal ADC Source"}, 744203db220SDimitris Papastamos {"Right ADC", NULL, "Internal ADC Source"}, 745203db220SDimitris Papastamos 746203db220SDimitris Papastamos /* Input Side */ 7476a077336SMark Brown {"INMIXL", NULL, "INL"}, 7486a077336SMark Brown {"AINLMUX", NULL, "INL"}, 7496a077336SMark Brown {"INMIXR", NULL, "INR"}, 7506a077336SMark Brown {"AINRMUX", NULL, "INR"}, 751203db220SDimitris Papastamos /* LIN12 PGA */ 752203db220SDimitris Papastamos {"LIN12 PGA", "LIN1 Switch", "LIN1"}, 753203db220SDimitris Papastamos {"LIN12 PGA", "LIN2 Switch", "LIN2"}, 754203db220SDimitris Papastamos /* LIN34 PGA */ 755203db220SDimitris Papastamos {"LIN34 PGA", "LIN3 Switch", "LIN3"}, 756203db220SDimitris Papastamos {"LIN34 PGA", "LIN4 Switch", "LIN4RXN"}, 757203db220SDimitris Papastamos /* INMIXL */ 758203db220SDimitris Papastamos {"INMIXL", "Record Left Volume", "LOMIX"}, 759203db220SDimitris Papastamos {"INMIXL", "LIN2 Volume", "LIN2"}, 760203db220SDimitris Papastamos {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"}, 761203db220SDimitris Papastamos {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"}, 762203db220SDimitris Papastamos /* AINLMUX */ 763203db220SDimitris Papastamos {"AINLMUX", "INMIXL Mix", "INMIXL"}, 764203db220SDimitris Papastamos {"AINLMUX", "DIFFINL Mix", "LIN12 PGA"}, 765203db220SDimitris Papastamos {"AINLMUX", "DIFFINL Mix", "LIN34 PGA"}, 766203db220SDimitris Papastamos {"AINLMUX", "RXVOICE Mix", "LIN4RXN"}, 767203db220SDimitris Papastamos {"AINLMUX", "RXVOICE Mix", "RIN4RXP"}, 768203db220SDimitris Papastamos /* ADC */ 769203db220SDimitris Papastamos {"Left ADC", NULL, "AINLMUX"}, 770203db220SDimitris Papastamos 771203db220SDimitris Papastamos /* RIN12 PGA */ 772203db220SDimitris Papastamos {"RIN12 PGA", "RIN1 Switch", "RIN1"}, 773203db220SDimitris Papastamos {"RIN12 PGA", "RIN2 Switch", "RIN2"}, 774203db220SDimitris Papastamos /* RIN34 PGA */ 775203db220SDimitris Papastamos {"RIN34 PGA", "RIN3 Switch", "RIN3"}, 776203db220SDimitris Papastamos {"RIN34 PGA", "RIN4 Switch", "RIN4RXP"}, 777203db220SDimitris Papastamos /* INMIXL */ 778203db220SDimitris Papastamos {"INMIXR", "Record Right Volume", "ROMIX"}, 779203db220SDimitris Papastamos {"INMIXR", "RIN2 Volume", "RIN2"}, 780203db220SDimitris Papastamos {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"}, 781203db220SDimitris Papastamos {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"}, 782203db220SDimitris Papastamos /* AINRMUX */ 783203db220SDimitris Papastamos {"AINRMUX", "INMIXR Mix", "INMIXR"}, 784203db220SDimitris Papastamos {"AINRMUX", "DIFFINR Mix", "RIN12 PGA"}, 785203db220SDimitris Papastamos {"AINRMUX", "DIFFINR Mix", "RIN34 PGA"}, 786203db220SDimitris Papastamos {"AINRMUX", "RXVOICE Mix", "LIN4RXN"}, 787203db220SDimitris Papastamos {"AINRMUX", "RXVOICE Mix", "RIN4RXP"}, 788203db220SDimitris Papastamos /* ADC */ 789203db220SDimitris Papastamos {"Right ADC", NULL, "AINRMUX"}, 790203db220SDimitris Papastamos 791203db220SDimitris Papastamos /* LOMIX */ 792203db220SDimitris Papastamos {"LOMIX", "LOMIX RIN3 Bypass Switch", "RIN3"}, 793203db220SDimitris Papastamos {"LOMIX", "LOMIX LIN3 Bypass Switch", "LIN3"}, 794203db220SDimitris Papastamos {"LOMIX", "LOMIX LIN12 PGA Bypass Switch", "LIN12 PGA"}, 795203db220SDimitris Papastamos {"LOMIX", "LOMIX RIN12 PGA Bypass Switch", "RIN12 PGA"}, 796203db220SDimitris Papastamos {"LOMIX", "LOMIX Right ADC Bypass Switch", "AINRMUX"}, 797203db220SDimitris Papastamos {"LOMIX", "LOMIX Left ADC Bypass Switch", "AINLMUX"}, 798203db220SDimitris Papastamos {"LOMIX", "LOMIX Left DAC Switch", "Left DAC"}, 799203db220SDimitris Papastamos 800203db220SDimitris Papastamos /* ROMIX */ 801203db220SDimitris Papastamos {"ROMIX", "ROMIX RIN3 Bypass Switch", "RIN3"}, 802203db220SDimitris Papastamos {"ROMIX", "ROMIX LIN3 Bypass Switch", "LIN3"}, 803203db220SDimitris Papastamos {"ROMIX", "ROMIX LIN12 PGA Bypass Switch", "LIN12 PGA"}, 804203db220SDimitris Papastamos {"ROMIX", "ROMIX RIN12 PGA Bypass Switch", "RIN12 PGA"}, 805203db220SDimitris Papastamos {"ROMIX", "ROMIX Right ADC Bypass Switch", "AINRMUX"}, 806203db220SDimitris Papastamos {"ROMIX", "ROMIX Left ADC Bypass Switch", "AINLMUX"}, 807203db220SDimitris Papastamos {"ROMIX", "ROMIX Right DAC Switch", "Right DAC"}, 808203db220SDimitris Papastamos 809203db220SDimitris Papastamos /* SPKMIX */ 810203db220SDimitris Papastamos {"SPKMIX", "SPKMIX LIN2 Bypass Switch", "LIN2"}, 811203db220SDimitris Papastamos {"SPKMIX", "SPKMIX RIN2 Bypass Switch", "RIN2"}, 812203db220SDimitris Papastamos {"SPKMIX", "SPKMIX LADC Bypass Switch", "AINLMUX"}, 813203db220SDimitris Papastamos {"SPKMIX", "SPKMIX RADC Bypass Switch", "AINRMUX"}, 814203db220SDimitris Papastamos {"SPKMIX", "SPKMIX Left Mixer PGA Switch", "LOPGA"}, 815203db220SDimitris Papastamos {"SPKMIX", "SPKMIX Right Mixer PGA Switch", "ROPGA"}, 816203db220SDimitris Papastamos {"SPKMIX", "SPKMIX Right DAC Switch", "Right DAC"}, 817203db220SDimitris Papastamos {"SPKMIX", "SPKMIX Left DAC Switch", "Right DAC"}, 818203db220SDimitris Papastamos 819203db220SDimitris Papastamos /* LONMIX */ 820203db220SDimitris Papastamos {"LONMIX", "LONMIX Left Mixer PGA Switch", "LOPGA"}, 821203db220SDimitris Papastamos {"LONMIX", "LONMIX Right Mixer PGA Switch", "ROPGA"}, 822203db220SDimitris Papastamos {"LONMIX", "LONMIX Inverted LOP Switch", "LOPMIX"}, 823203db220SDimitris Papastamos 824203db220SDimitris Papastamos /* LOPMIX */ 825203db220SDimitris Papastamos {"LOPMIX", "LOPMIX Right Mic Bypass Switch", "RIN12 PGA"}, 826203db220SDimitris Papastamos {"LOPMIX", "LOPMIX Left Mic Bypass Switch", "LIN12 PGA"}, 827203db220SDimitris Papastamos {"LOPMIX", "LOPMIX Left Mixer PGA Switch", "LOPGA"}, 828203db220SDimitris Papastamos 829203db220SDimitris Papastamos /* OUT3MIX */ 830203db220SDimitris Papastamos {"OUT3MIX", "OUT3MIX LIN4RXN Bypass Switch", "LIN4RXN"}, 831203db220SDimitris Papastamos {"OUT3MIX", "OUT3MIX Left Out PGA Switch", "LOPGA"}, 832203db220SDimitris Papastamos 833203db220SDimitris Papastamos /* OUT4MIX */ 834203db220SDimitris Papastamos {"OUT4MIX", "OUT4MIX Right Out PGA Switch", "ROPGA"}, 835203db220SDimitris Papastamos {"OUT4MIX", "OUT4MIX RIN4RXP Bypass Switch", "RIN4RXP"}, 836203db220SDimitris Papastamos 837203db220SDimitris Papastamos /* RONMIX */ 838203db220SDimitris Papastamos {"RONMIX", "RONMIX Right Mixer PGA Switch", "ROPGA"}, 839203db220SDimitris Papastamos {"RONMIX", "RONMIX Left Mixer PGA Switch", "LOPGA"}, 840203db220SDimitris Papastamos {"RONMIX", "RONMIX Inverted ROP Switch", "ROPMIX"}, 841203db220SDimitris Papastamos 842203db220SDimitris Papastamos /* ROPMIX */ 843203db220SDimitris Papastamos {"ROPMIX", "ROPMIX Left Mic Bypass Switch", "LIN12 PGA"}, 844203db220SDimitris Papastamos {"ROPMIX", "ROPMIX Right Mic Bypass Switch", "RIN12 PGA"}, 845203db220SDimitris Papastamos {"ROPMIX", "ROPMIX Right Mixer PGA Switch", "ROPGA"}, 846203db220SDimitris Papastamos 847203db220SDimitris Papastamos /* Out Mixer PGAs */ 848203db220SDimitris Papastamos {"LOPGA", NULL, "LOMIX"}, 849203db220SDimitris Papastamos {"ROPGA", NULL, "ROMIX"}, 850203db220SDimitris Papastamos 851203db220SDimitris Papastamos {"LOUT PGA", NULL, "LOMIX"}, 852203db220SDimitris Papastamos {"ROUT PGA", NULL, "ROMIX"}, 853203db220SDimitris Papastamos 854203db220SDimitris Papastamos /* Output Pins */ 855203db220SDimitris Papastamos {"LON", NULL, "LONMIX"}, 856203db220SDimitris Papastamos {"LOP", NULL, "LOPMIX"}, 857203db220SDimitris Papastamos {"OUT", NULL, "OUT3MIX"}, 858203db220SDimitris Papastamos {"LOUT", NULL, "LOUT PGA"}, 859203db220SDimitris Papastamos {"SPKN", NULL, "SPKMIX"}, 860203db220SDimitris Papastamos {"ROUT", NULL, "ROUT PGA"}, 861203db220SDimitris Papastamos {"OUT4", NULL, "OUT4MIX"}, 862203db220SDimitris Papastamos {"ROP", NULL, "ROPMIX"}, 863203db220SDimitris Papastamos {"RON", NULL, "RONMIX"}, 864203db220SDimitris Papastamos }; 865203db220SDimitris Papastamos 866203db220SDimitris Papastamos /* PLL divisors */ 867203db220SDimitris Papastamos struct _pll_div { 868203db220SDimitris Papastamos u32 div2; 869203db220SDimitris Papastamos u32 n; 870203db220SDimitris Papastamos u32 k; 871203db220SDimitris Papastamos }; 872203db220SDimitris Papastamos 873203db220SDimitris Papastamos /* The size in bits of the pll divide multiplied by 10 874203db220SDimitris Papastamos * to allow rounding later */ 875203db220SDimitris Papastamos #define FIXED_PLL_SIZE ((1 << 16) * 10) 876203db220SDimitris Papastamos 877203db220SDimitris Papastamos static void pll_factors(struct _pll_div *pll_div, unsigned int target, 878203db220SDimitris Papastamos unsigned int source) 879203db220SDimitris Papastamos { 880203db220SDimitris Papastamos u64 Kpart; 881203db220SDimitris Papastamos unsigned int K, Ndiv, Nmod; 882203db220SDimitris Papastamos 883203db220SDimitris Papastamos 884203db220SDimitris Papastamos Ndiv = target / source; 885203db220SDimitris Papastamos if (Ndiv < 6) { 886203db220SDimitris Papastamos source >>= 1; 887203db220SDimitris Papastamos pll_div->div2 = 1; 888203db220SDimitris Papastamos Ndiv = target / source; 889203db220SDimitris Papastamos } else 890203db220SDimitris Papastamos pll_div->div2 = 0; 891203db220SDimitris Papastamos 892203db220SDimitris Papastamos if ((Ndiv < 6) || (Ndiv > 12)) 893203db220SDimitris Papastamos printk(KERN_WARNING 894203db220SDimitris Papastamos "WM8991 N value outwith recommended range! N = %d\n", Ndiv); 895203db220SDimitris Papastamos 896203db220SDimitris Papastamos pll_div->n = Ndiv; 897203db220SDimitris Papastamos Nmod = target % source; 898203db220SDimitris Papastamos Kpart = FIXED_PLL_SIZE * (long long)Nmod; 899203db220SDimitris Papastamos 900203db220SDimitris Papastamos do_div(Kpart, source); 901203db220SDimitris Papastamos 902203db220SDimitris Papastamos K = Kpart & 0xFFFFFFFF; 903203db220SDimitris Papastamos 904203db220SDimitris Papastamos /* Check if we need to round */ 905203db220SDimitris Papastamos if ((K % 10) >= 5) 906203db220SDimitris Papastamos K += 5; 907203db220SDimitris Papastamos 908203db220SDimitris Papastamos /* Move down to proper range now rounding is done */ 909203db220SDimitris Papastamos K /= 10; 910203db220SDimitris Papastamos 911203db220SDimitris Papastamos pll_div->k = K; 912203db220SDimitris Papastamos } 913203db220SDimitris Papastamos 914203db220SDimitris Papastamos static int wm8991_set_dai_pll(struct snd_soc_dai *codec_dai, 915203db220SDimitris Papastamos int pll_id, int src, unsigned int freq_in, unsigned int freq_out) 916203db220SDimitris Papastamos { 917203db220SDimitris Papastamos u16 reg; 918bf338e5bSKuninori Morimoto struct snd_soc_component *component = codec_dai->component; 919203db220SDimitris Papastamos struct _pll_div pll_div; 920203db220SDimitris Papastamos 921203db220SDimitris Papastamos if (freq_in && freq_out) { 922203db220SDimitris Papastamos pll_factors(&pll_div, freq_out * 4, freq_in); 923203db220SDimitris Papastamos 924203db220SDimitris Papastamos /* Turn on PLL */ 9256d75dfc3SKuninori Morimoto reg = snd_soc_component_read(component, WM8991_POWER_MANAGEMENT_2); 926203db220SDimitris Papastamos reg |= WM8991_PLL_ENA; 927bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_POWER_MANAGEMENT_2, reg); 928203db220SDimitris Papastamos 929203db220SDimitris Papastamos /* sysclk comes from PLL */ 9306d75dfc3SKuninori Morimoto reg = snd_soc_component_read(component, WM8991_CLOCKING_2); 931bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_CLOCKING_2, reg | WM8991_SYSCLK_SRC); 932203db220SDimitris Papastamos 93325985edcSLucas De Marchi /* set up N , fractional mode and pre-divisor if necessary */ 934bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_PLL1, pll_div.n | WM8991_SDM | 935203db220SDimitris Papastamos (pll_div.div2 ? WM8991_PRESCALE : 0)); 936bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_PLL2, (u8)(pll_div.k>>8)); 937bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_PLL3, (u8)(pll_div.k & 0xFF)); 938203db220SDimitris Papastamos } else { 939203db220SDimitris Papastamos /* Turn on PLL */ 9406d75dfc3SKuninori Morimoto reg = snd_soc_component_read(component, WM8991_POWER_MANAGEMENT_2); 941203db220SDimitris Papastamos reg &= ~WM8991_PLL_ENA; 942bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_POWER_MANAGEMENT_2, reg); 943203db220SDimitris Papastamos } 944203db220SDimitris Papastamos return 0; 945203db220SDimitris Papastamos } 946203db220SDimitris Papastamos 947203db220SDimitris Papastamos /* 948203db220SDimitris Papastamos * Set's ADC and Voice DAC format. 949203db220SDimitris Papastamos */ 950203db220SDimitris Papastamos static int wm8991_set_dai_fmt(struct snd_soc_dai *codec_dai, 951203db220SDimitris Papastamos unsigned int fmt) 952203db220SDimitris Papastamos { 953bf338e5bSKuninori Morimoto struct snd_soc_component *component = codec_dai->component; 954203db220SDimitris Papastamos u16 audio1, audio3; 955203db220SDimitris Papastamos 9566d75dfc3SKuninori Morimoto audio1 = snd_soc_component_read(component, WM8991_AUDIO_INTERFACE_1); 9576d75dfc3SKuninori Morimoto audio3 = snd_soc_component_read(component, WM8991_AUDIO_INTERFACE_3); 958203db220SDimitris Papastamos 959203db220SDimitris Papastamos /* set master/slave audio interface */ 960203db220SDimitris Papastamos switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 961203db220SDimitris Papastamos case SND_SOC_DAIFMT_CBS_CFS: 962203db220SDimitris Papastamos audio3 &= ~WM8991_AIF_MSTR1; 963203db220SDimitris Papastamos break; 964203db220SDimitris Papastamos case SND_SOC_DAIFMT_CBM_CFM: 965203db220SDimitris Papastamos audio3 |= WM8991_AIF_MSTR1; 966203db220SDimitris Papastamos break; 967203db220SDimitris Papastamos default: 968203db220SDimitris Papastamos return -EINVAL; 969203db220SDimitris Papastamos } 970203db220SDimitris Papastamos 971203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_FMT_MASK; 972203db220SDimitris Papastamos 973203db220SDimitris Papastamos /* interface format */ 974203db220SDimitris Papastamos switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 975203db220SDimitris Papastamos case SND_SOC_DAIFMT_I2S: 976203db220SDimitris Papastamos audio1 |= WM8991_AIF_TMF_I2S; 977203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_LRCLK_INV; 978203db220SDimitris Papastamos break; 979203db220SDimitris Papastamos case SND_SOC_DAIFMT_RIGHT_J: 980203db220SDimitris Papastamos audio1 |= WM8991_AIF_TMF_RIGHTJ; 981203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_LRCLK_INV; 982203db220SDimitris Papastamos break; 983203db220SDimitris Papastamos case SND_SOC_DAIFMT_LEFT_J: 984203db220SDimitris Papastamos audio1 |= WM8991_AIF_TMF_LEFTJ; 985203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_LRCLK_INV; 986203db220SDimitris Papastamos break; 987203db220SDimitris Papastamos case SND_SOC_DAIFMT_DSP_A: 988203db220SDimitris Papastamos audio1 |= WM8991_AIF_TMF_DSP; 989203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_LRCLK_INV; 990203db220SDimitris Papastamos break; 991203db220SDimitris Papastamos case SND_SOC_DAIFMT_DSP_B: 992203db220SDimitris Papastamos audio1 |= WM8991_AIF_TMF_DSP | WM8991_AIF_LRCLK_INV; 993203db220SDimitris Papastamos break; 994203db220SDimitris Papastamos default: 995203db220SDimitris Papastamos return -EINVAL; 996203db220SDimitris Papastamos } 997203db220SDimitris Papastamos 998bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_AUDIO_INTERFACE_1, audio1); 999bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_AUDIO_INTERFACE_3, audio3); 1000203db220SDimitris Papastamos return 0; 1001203db220SDimitris Papastamos } 1002203db220SDimitris Papastamos 1003203db220SDimitris Papastamos static int wm8991_set_dai_clkdiv(struct snd_soc_dai *codec_dai, 1004203db220SDimitris Papastamos int div_id, int div) 1005203db220SDimitris Papastamos { 1006bf338e5bSKuninori Morimoto struct snd_soc_component *component = codec_dai->component; 1007203db220SDimitris Papastamos u16 reg; 1008203db220SDimitris Papastamos 1009203db220SDimitris Papastamos switch (div_id) { 1010203db220SDimitris Papastamos case WM8991_MCLK_DIV: 10116d75dfc3SKuninori Morimoto reg = snd_soc_component_read(component, WM8991_CLOCKING_2) & 1012203db220SDimitris Papastamos ~WM8991_MCLK_DIV_MASK; 1013bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_CLOCKING_2, reg | div); 1014203db220SDimitris Papastamos break; 1015203db220SDimitris Papastamos case WM8991_DACCLK_DIV: 10166d75dfc3SKuninori Morimoto reg = snd_soc_component_read(component, WM8991_CLOCKING_2) & 1017203db220SDimitris Papastamos ~WM8991_DAC_CLKDIV_MASK; 1018bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_CLOCKING_2, reg | div); 1019203db220SDimitris Papastamos break; 1020203db220SDimitris Papastamos case WM8991_ADCCLK_DIV: 10216d75dfc3SKuninori Morimoto reg = snd_soc_component_read(component, WM8991_CLOCKING_2) & 1022203db220SDimitris Papastamos ~WM8991_ADC_CLKDIV_MASK; 1023bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_CLOCKING_2, reg | div); 1024203db220SDimitris Papastamos break; 1025203db220SDimitris Papastamos case WM8991_BCLK_DIV: 10266d75dfc3SKuninori Morimoto reg = snd_soc_component_read(component, WM8991_CLOCKING_1) & 1027203db220SDimitris Papastamos ~WM8991_BCLK_DIV_MASK; 1028bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_CLOCKING_1, reg | div); 1029203db220SDimitris Papastamos break; 1030203db220SDimitris Papastamos default: 1031203db220SDimitris Papastamos return -EINVAL; 1032203db220SDimitris Papastamos } 1033203db220SDimitris Papastamos 1034203db220SDimitris Papastamos return 0; 1035203db220SDimitris Papastamos } 1036203db220SDimitris Papastamos 1037203db220SDimitris Papastamos /* 1038203db220SDimitris Papastamos * Set PCM DAI bit size and sample rate. 1039203db220SDimitris Papastamos */ 1040203db220SDimitris Papastamos static int wm8991_hw_params(struct snd_pcm_substream *substream, 1041203db220SDimitris Papastamos struct snd_pcm_hw_params *params, 1042203db220SDimitris Papastamos struct snd_soc_dai *dai) 1043203db220SDimitris Papastamos { 1044bf338e5bSKuninori Morimoto struct snd_soc_component *component = dai->component; 10456d75dfc3SKuninori Morimoto u16 audio1 = snd_soc_component_read(component, WM8991_AUDIO_INTERFACE_1); 1046203db220SDimitris Papastamos 1047203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_WL_MASK; 1048203db220SDimitris Papastamos /* bit size */ 104920a77bbdSMark Brown switch (params_width(params)) { 105020a77bbdSMark Brown case 16: 1051203db220SDimitris Papastamos break; 105220a77bbdSMark Brown case 20: 1053203db220SDimitris Papastamos audio1 |= WM8991_AIF_WL_20BITS; 1054203db220SDimitris Papastamos break; 105520a77bbdSMark Brown case 24: 1056203db220SDimitris Papastamos audio1 |= WM8991_AIF_WL_24BITS; 1057203db220SDimitris Papastamos break; 105820a77bbdSMark Brown case 32: 1059203db220SDimitris Papastamos audio1 |= WM8991_AIF_WL_32BITS; 1060203db220SDimitris Papastamos break; 1061203db220SDimitris Papastamos } 1062203db220SDimitris Papastamos 1063bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_AUDIO_INTERFACE_1, audio1); 1064203db220SDimitris Papastamos return 0; 1065203db220SDimitris Papastamos } 1066203db220SDimitris Papastamos 106726d3c16eSKuninori Morimoto static int wm8991_mute(struct snd_soc_dai *dai, int mute, int direction) 1068203db220SDimitris Papastamos { 1069bf338e5bSKuninori Morimoto struct snd_soc_component *component = dai->component; 1070203db220SDimitris Papastamos u16 val; 1071203db220SDimitris Papastamos 10726d75dfc3SKuninori Morimoto val = snd_soc_component_read(component, WM8991_DAC_CTRL) & ~WM8991_DAC_MUTE; 1073203db220SDimitris Papastamos if (mute) 1074bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_DAC_CTRL, val | WM8991_DAC_MUTE); 1075203db220SDimitris Papastamos else 1076bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_DAC_CTRL, val); 1077203db220SDimitris Papastamos return 0; 1078203db220SDimitris Papastamos } 1079203db220SDimitris Papastamos 1080bf338e5bSKuninori Morimoto static int wm8991_set_bias_level(struct snd_soc_component *component, 1081203db220SDimitris Papastamos enum snd_soc_bias_level level) 1082203db220SDimitris Papastamos { 1083bf338e5bSKuninori Morimoto struct wm8991_priv *wm8991 = snd_soc_component_get_drvdata(component); 1084203db220SDimitris Papastamos u16 val; 1085203db220SDimitris Papastamos 1086203db220SDimitris Papastamos switch (level) { 1087203db220SDimitris Papastamos case SND_SOC_BIAS_ON: 1088203db220SDimitris Papastamos break; 1089203db220SDimitris Papastamos 1090203db220SDimitris Papastamos case SND_SOC_BIAS_PREPARE: 1091203db220SDimitris Papastamos /* VMID=2*50k */ 10926d75dfc3SKuninori Morimoto val = snd_soc_component_read(component, WM8991_POWER_MANAGEMENT_1) & 1093203db220SDimitris Papastamos ~WM8991_VMID_MODE_MASK; 1094bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_POWER_MANAGEMENT_1, val | 0x2); 1095203db220SDimitris Papastamos break; 1096203db220SDimitris Papastamos 1097203db220SDimitris Papastamos case SND_SOC_BIAS_STANDBY: 1098bf338e5bSKuninori Morimoto if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) { 1099a86652e5SMark Brown regcache_sync(wm8991->regmap); 1100203db220SDimitris Papastamos /* Enable all output discharge bits */ 1101bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_ANTIPOP1, WM8991_DIS_LLINE | 1102203db220SDimitris Papastamos WM8991_DIS_RLINE | WM8991_DIS_OUT3 | 1103203db220SDimitris Papastamos WM8991_DIS_OUT4 | WM8991_DIS_LOUT | 1104203db220SDimitris Papastamos WM8991_DIS_ROUT); 1105203db220SDimitris Papastamos 1106203db220SDimitris Papastamos /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */ 1107bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_ANTIPOP2, WM8991_SOFTST | 1108203db220SDimitris Papastamos WM8991_BUFDCOPEN | WM8991_POBCTRL | 1109203db220SDimitris Papastamos WM8991_VMIDTOG); 1110203db220SDimitris Papastamos 1111203db220SDimitris Papastamos /* Delay to allow output caps to discharge */ 1112203db220SDimitris Papastamos msleep(300); 1113203db220SDimitris Papastamos 1114203db220SDimitris Papastamos /* Disable VMIDTOG */ 1115bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_ANTIPOP2, WM8991_SOFTST | 1116203db220SDimitris Papastamos WM8991_BUFDCOPEN | WM8991_POBCTRL); 1117203db220SDimitris Papastamos 1118203db220SDimitris Papastamos /* disable all output discharge bits */ 1119bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_ANTIPOP1, 0); 1120203db220SDimitris Papastamos 1121203db220SDimitris Papastamos /* Enable outputs */ 1122bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_POWER_MANAGEMENT_1, 0x1b00); 1123203db220SDimitris Papastamos 1124203db220SDimitris Papastamos msleep(50); 1125203db220SDimitris Papastamos 1126203db220SDimitris Papastamos /* Enable VMID at 2x50k */ 1127bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_POWER_MANAGEMENT_1, 0x1f02); 1128203db220SDimitris Papastamos 1129203db220SDimitris Papastamos msleep(100); 1130203db220SDimitris Papastamos 1131203db220SDimitris Papastamos /* Enable VREF */ 1132bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_POWER_MANAGEMENT_1, 0x1f03); 1133203db220SDimitris Papastamos 1134203db220SDimitris Papastamos msleep(600); 1135203db220SDimitris Papastamos 1136203db220SDimitris Papastamos /* Enable BUFIOEN */ 1137bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_ANTIPOP2, WM8991_SOFTST | 1138203db220SDimitris Papastamos WM8991_BUFDCOPEN | WM8991_POBCTRL | 1139203db220SDimitris Papastamos WM8991_BUFIOEN); 1140203db220SDimitris Papastamos 1141203db220SDimitris Papastamos /* Disable outputs */ 1142bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_POWER_MANAGEMENT_1, 0x3); 1143203db220SDimitris Papastamos 1144203db220SDimitris Papastamos /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ 1145bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_ANTIPOP2, WM8991_BUFIOEN); 1146203db220SDimitris Papastamos } 1147203db220SDimitris Papastamos 1148203db220SDimitris Papastamos /* VMID=2*250k */ 11496d75dfc3SKuninori Morimoto val = snd_soc_component_read(component, WM8991_POWER_MANAGEMENT_1) & 1150203db220SDimitris Papastamos ~WM8991_VMID_MODE_MASK; 1151bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_POWER_MANAGEMENT_1, val | 0x4); 1152203db220SDimitris Papastamos break; 1153203db220SDimitris Papastamos 1154203db220SDimitris Papastamos case SND_SOC_BIAS_OFF: 1155203db220SDimitris Papastamos /* Enable POBCTRL and SOFT_ST */ 1156bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_ANTIPOP2, WM8991_SOFTST | 1157203db220SDimitris Papastamos WM8991_POBCTRL | WM8991_BUFIOEN); 1158203db220SDimitris Papastamos 1159203db220SDimitris Papastamos /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */ 1160bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_ANTIPOP2, WM8991_SOFTST | 1161203db220SDimitris Papastamos WM8991_BUFDCOPEN | WM8991_POBCTRL | 1162203db220SDimitris Papastamos WM8991_BUFIOEN); 1163203db220SDimitris Papastamos 1164203db220SDimitris Papastamos /* mute DAC */ 11656d75dfc3SKuninori Morimoto val = snd_soc_component_read(component, WM8991_DAC_CTRL); 1166bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_DAC_CTRL, val | WM8991_DAC_MUTE); 1167203db220SDimitris Papastamos 1168203db220SDimitris Papastamos /* Enable any disabled outputs */ 1169bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_POWER_MANAGEMENT_1, 0x1f03); 1170203db220SDimitris Papastamos 1171203db220SDimitris Papastamos /* Disable VMID */ 1172bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_POWER_MANAGEMENT_1, 0x1f01); 1173203db220SDimitris Papastamos 1174203db220SDimitris Papastamos msleep(300); 1175203db220SDimitris Papastamos 1176203db220SDimitris Papastamos /* Enable all output discharge bits */ 1177bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_ANTIPOP1, WM8991_DIS_LLINE | 1178203db220SDimitris Papastamos WM8991_DIS_RLINE | WM8991_DIS_OUT3 | 1179203db220SDimitris Papastamos WM8991_DIS_OUT4 | WM8991_DIS_LOUT | 1180203db220SDimitris Papastamos WM8991_DIS_ROUT); 1181203db220SDimitris Papastamos 1182203db220SDimitris Papastamos /* Disable VREF */ 1183bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_POWER_MANAGEMENT_1, 0x0); 1184203db220SDimitris Papastamos 1185203db220SDimitris Papastamos /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ 1186bf338e5bSKuninori Morimoto snd_soc_component_write(component, WM8991_ANTIPOP2, 0x0); 1187a86652e5SMark Brown regcache_mark_dirty(wm8991->regmap); 1188203db220SDimitris Papastamos break; 1189203db220SDimitris Papastamos } 1190203db220SDimitris Papastamos 1191203db220SDimitris Papastamos return 0; 1192203db220SDimitris Papastamos } 1193203db220SDimitris Papastamos 1194203db220SDimitris Papastamos #define WM8991_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 1195203db220SDimitris Papastamos SNDRV_PCM_FMTBIT_S24_LE) 1196203db220SDimitris Papastamos 119785e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops wm8991_ops = { 1198203db220SDimitris Papastamos .hw_params = wm8991_hw_params, 119926d3c16eSKuninori Morimoto .mute_stream = wm8991_mute, 1200203db220SDimitris Papastamos .set_fmt = wm8991_set_dai_fmt, 1201203db220SDimitris Papastamos .set_clkdiv = wm8991_set_dai_clkdiv, 120226d3c16eSKuninori Morimoto .set_pll = wm8991_set_dai_pll, 120326d3c16eSKuninori Morimoto .no_capture_mute = 1, 1204203db220SDimitris Papastamos }; 1205203db220SDimitris Papastamos 1206203db220SDimitris Papastamos /* 1207203db220SDimitris Papastamos * The WM8991 supports 2 different and mutually exclusive DAI 1208203db220SDimitris Papastamos * configurations. 1209203db220SDimitris Papastamos * 1210203db220SDimitris Papastamos * 1. ADC/DAC on Primary Interface 1211203db220SDimitris Papastamos * 2. ADC on Primary Interface/DAC on secondary 1212203db220SDimitris Papastamos */ 1213203db220SDimitris Papastamos static struct snd_soc_dai_driver wm8991_dai = { 1214203db220SDimitris Papastamos /* ADC/DAC on primary */ 1215203db220SDimitris Papastamos .name = "wm8991", 1216203db220SDimitris Papastamos .id = 1, 1217203db220SDimitris Papastamos .playback = { 1218203db220SDimitris Papastamos .stream_name = "Playback", 1219203db220SDimitris Papastamos .channels_min = 1, 1220203db220SDimitris Papastamos .channels_max = 2, 1221203db220SDimitris Papastamos .rates = SNDRV_PCM_RATE_8000_96000, 1222203db220SDimitris Papastamos .formats = WM8991_FORMATS 1223203db220SDimitris Papastamos }, 1224203db220SDimitris Papastamos .capture = { 1225203db220SDimitris Papastamos .stream_name = "Capture", 1226203db220SDimitris Papastamos .channels_min = 1, 1227203db220SDimitris Papastamos .channels_max = 2, 1228203db220SDimitris Papastamos .rates = SNDRV_PCM_RATE_8000_96000, 1229203db220SDimitris Papastamos .formats = WM8991_FORMATS 1230203db220SDimitris Papastamos }, 1231203db220SDimitris Papastamos .ops = &wm8991_ops 1232203db220SDimitris Papastamos }; 1233203db220SDimitris Papastamos 1234bf338e5bSKuninori Morimoto static const struct snd_soc_component_driver soc_component_dev_wm8991 = { 1235203db220SDimitris Papastamos .set_bias_level = wm8991_set_bias_level, 123689824995SMark Brown .controls = wm8991_snd_controls, 123789824995SMark Brown .num_controls = ARRAY_SIZE(wm8991_snd_controls), 123889824995SMark Brown .dapm_widgets = wm8991_dapm_widgets, 123989824995SMark Brown .num_dapm_widgets = ARRAY_SIZE(wm8991_dapm_widgets), 124089824995SMark Brown .dapm_routes = wm8991_dapm_routes, 124189824995SMark Brown .num_dapm_routes = ARRAY_SIZE(wm8991_dapm_routes), 1242bf338e5bSKuninori Morimoto .suspend_bias_off = 1, 1243bf338e5bSKuninori Morimoto .idle_bias_on = 1, 1244bf338e5bSKuninori Morimoto .use_pmdown_time = 1, 1245bf338e5bSKuninori Morimoto .endianness = 1, 1246a86652e5SMark Brown }; 1247a86652e5SMark Brown 1248a86652e5SMark Brown static const struct regmap_config wm8991_regmap = { 1249a86652e5SMark Brown .reg_bits = 8, 1250a86652e5SMark Brown .val_bits = 16, 1251a86652e5SMark Brown 1252a86652e5SMark Brown .max_register = WM8991_PLL3, 1253a86652e5SMark Brown .volatile_reg = wm8991_volatile, 1254a86652e5SMark Brown .reg_defaults = wm8991_reg_defaults, 1255a86652e5SMark Brown .num_reg_defaults = ARRAY_SIZE(wm8991_reg_defaults), 1256a86652e5SMark Brown .cache_type = REGCACHE_RBTREE, 1257203db220SDimitris Papastamos }; 1258203db220SDimitris Papastamos 125997b0b6e3SStephen Kitt static int wm8991_i2c_probe(struct i2c_client *i2c) 1260203db220SDimitris Papastamos { 1261203db220SDimitris Papastamos struct wm8991_priv *wm8991; 1262a0a05916SMark Brown unsigned int val; 1263203db220SDimitris Papastamos int ret; 1264203db220SDimitris Papastamos 1265046d4f02SMark Brown wm8991 = devm_kzalloc(&i2c->dev, sizeof(*wm8991), GFP_KERNEL); 1266203db220SDimitris Papastamos if (!wm8991) 1267203db220SDimitris Papastamos return -ENOMEM; 1268203db220SDimitris Papastamos 1269a86652e5SMark Brown wm8991->regmap = devm_regmap_init_i2c(i2c, &wm8991_regmap); 1270a86652e5SMark Brown if (IS_ERR(wm8991->regmap)) 1271a86652e5SMark Brown return PTR_ERR(wm8991->regmap); 1272a86652e5SMark Brown 1273203db220SDimitris Papastamos i2c_set_clientdata(i2c, wm8991); 1274203db220SDimitris Papastamos 1275a0a05916SMark Brown ret = regmap_read(wm8991->regmap, WM8991_RESET, &val); 1276a0a05916SMark Brown if (ret != 0) { 1277a0a05916SMark Brown dev_err(&i2c->dev, "Failed to read device ID: %d\n", ret); 1278a0a05916SMark Brown return ret; 1279a0a05916SMark Brown } 1280a0a05916SMark Brown if (val != 0x8991) { 1281a0a05916SMark Brown dev_err(&i2c->dev, "Device with ID %x is not a WM8991\n", val); 1282a0a05916SMark Brown return -EINVAL; 1283a0a05916SMark Brown } 1284a0a05916SMark Brown 1285e4634804SMark Brown ret = regmap_write(wm8991->regmap, WM8991_RESET, 0); 1286e4634804SMark Brown if (ret < 0) { 1287e4634804SMark Brown dev_err(&i2c->dev, "Failed to issue reset: %d\n", ret); 1288e4634804SMark Brown return ret; 1289e4634804SMark Brown } 1290e4634804SMark Brown 1291e4634804SMark Brown regmap_update_bits(wm8991->regmap, WM8991_AUDIO_INTERFACE_4, 1292e4634804SMark Brown WM8991_ALRCGPIO1, WM8991_ALRCGPIO1); 1293e4634804SMark Brown 1294e4634804SMark Brown regmap_update_bits(wm8991->regmap, WM8991_GPIO1_GPIO2, 1295e4634804SMark Brown WM8991_GPIO1_SEL_MASK, 1); 1296e4634804SMark Brown 1297e4634804SMark Brown regmap_update_bits(wm8991->regmap, WM8991_POWER_MANAGEMENT_1, 1298e4634804SMark Brown WM8991_VREF_ENA | WM8991_VMID_MODE_MASK, 1299e4634804SMark Brown WM8991_VREF_ENA | WM8991_VMID_MODE_MASK); 1300e4634804SMark Brown 1301e4634804SMark Brown regmap_update_bits(wm8991->regmap, WM8991_POWER_MANAGEMENT_2, 1302e4634804SMark Brown WM8991_OPCLK_ENA, WM8991_OPCLK_ENA); 1303e4634804SMark Brown 1304e4634804SMark Brown regmap_write(wm8991->regmap, WM8991_DAC_CTRL, 0); 1305e4634804SMark Brown regmap_write(wm8991->regmap, WM8991_LEFT_OUTPUT_VOLUME, 1306e4634804SMark Brown 0x50 | (1<<8)); 1307e4634804SMark Brown regmap_write(wm8991->regmap, WM8991_RIGHT_OUTPUT_VOLUME, 1308e4634804SMark Brown 0x50 | (1<<8)); 1309e4634804SMark Brown 1310bf338e5bSKuninori Morimoto ret = devm_snd_soc_register_component(&i2c->dev, 1311bf338e5bSKuninori Morimoto &soc_component_dev_wm8991, &wm8991_dai, 1); 1312046d4f02SMark Brown 1313203db220SDimitris Papastamos return ret; 1314203db220SDimitris Papastamos } 1315203db220SDimitris Papastamos 1316203db220SDimitris Papastamos static const struct i2c_device_id wm8991_i2c_id[] = { 1317203db220SDimitris Papastamos { "wm8991", 0 }, 1318203db220SDimitris Papastamos { } 1319203db220SDimitris Papastamos }; 1320203db220SDimitris Papastamos MODULE_DEVICE_TABLE(i2c, wm8991_i2c_id); 1321203db220SDimitris Papastamos 1322203db220SDimitris Papastamos static struct i2c_driver wm8991_i2c_driver = { 1323203db220SDimitris Papastamos .driver = { 1324203db220SDimitris Papastamos .name = "wm8991", 1325203db220SDimitris Papastamos }, 1326*9abcd240SUwe Kleine-König .probe = wm8991_i2c_probe, 1327203db220SDimitris Papastamos .id_table = wm8991_i2c_id, 1328203db220SDimitris Papastamos }; 1329203db220SDimitris Papastamos 133038ece8dbSSachin Kamat module_i2c_driver(wm8991_i2c_driver); 1331203db220SDimitris Papastamos 1332203db220SDimitris Papastamos MODULE_DESCRIPTION("ASoC WM8991 driver"); 1333203db220SDimitris Papastamos MODULE_AUTHOR("Graeme Gregory"); 1334203db220SDimitris Papastamos MODULE_LICENSE("GPL"); 1335