1203db220SDimitris Papastamos /* 2203db220SDimitris Papastamos * wm8991.c -- WM8991 ALSA Soc Audio driver 3203db220SDimitris Papastamos * 4203db220SDimitris Papastamos * Copyright 2007-2010 Wolfson Microelectronics PLC. 5203db220SDimitris Papastamos * Author: Graeme Gregory 69a185b9aSMark Brown * Graeme.Gregory@wolfsonmicro.com 7203db220SDimitris Papastamos * 8203db220SDimitris Papastamos * This program is free software; you can redistribute it and/or modify it 9203db220SDimitris Papastamos * under the terms of the GNU General Public License as published by the 10203db220SDimitris Papastamos * Free Software Foundation; either version 2 of the License, or (at your 11203db220SDimitris Papastamos * option) any later version. 12203db220SDimitris Papastamos */ 13203db220SDimitris Papastamos 14203db220SDimitris Papastamos #include <linux/module.h> 15203db220SDimitris Papastamos #include <linux/moduleparam.h> 16203db220SDimitris Papastamos #include <linux/kernel.h> 17203db220SDimitris Papastamos #include <linux/init.h> 18203db220SDimitris Papastamos #include <linux/delay.h> 19203db220SDimitris Papastamos #include <linux/pm.h> 20203db220SDimitris Papastamos #include <linux/i2c.h> 21203db220SDimitris Papastamos #include <linux/platform_device.h> 22203db220SDimitris Papastamos #include <linux/slab.h> 23203db220SDimitris Papastamos #include <sound/core.h> 24203db220SDimitris Papastamos #include <sound/pcm.h> 25203db220SDimitris Papastamos #include <sound/pcm_params.h> 26203db220SDimitris Papastamos #include <sound/soc.h> 27203db220SDimitris Papastamos #include <sound/soc-dapm.h> 28203db220SDimitris Papastamos #include <sound/initval.h> 29203db220SDimitris Papastamos #include <sound/tlv.h> 30203db220SDimitris Papastamos #include <asm/div64.h> 31203db220SDimitris Papastamos 32203db220SDimitris Papastamos #include "wm8991.h" 33203db220SDimitris Papastamos 34203db220SDimitris Papastamos struct wm8991_priv { 35203db220SDimitris Papastamos enum snd_soc_control_type control_type; 36203db220SDimitris Papastamos unsigned int pcmclk; 37203db220SDimitris Papastamos }; 38203db220SDimitris Papastamos 39203db220SDimitris Papastamos static const u16 wm8991_reg_defs[] = { 40203db220SDimitris Papastamos 0x8991, /* R0 - Reset */ 41203db220SDimitris Papastamos 0x0000, /* R1 - Power Management (1) */ 42203db220SDimitris Papastamos 0x6000, /* R2 - Power Management (2) */ 43203db220SDimitris Papastamos 0x0000, /* R3 - Power Management (3) */ 44203db220SDimitris Papastamos 0x4050, /* R4 - Audio Interface (1) */ 45203db220SDimitris Papastamos 0x4000, /* R5 - Audio Interface (2) */ 46203db220SDimitris Papastamos 0x01C8, /* R6 - Clocking (1) */ 47203db220SDimitris Papastamos 0x0000, /* R7 - Clocking (2) */ 48203db220SDimitris Papastamos 0x0040, /* R8 - Audio Interface (3) */ 49203db220SDimitris Papastamos 0x0040, /* R9 - Audio Interface (4) */ 50203db220SDimitris Papastamos 0x0004, /* R10 - DAC CTRL */ 51203db220SDimitris Papastamos 0x00C0, /* R11 - Left DAC Digital Volume */ 52203db220SDimitris Papastamos 0x00C0, /* R12 - Right DAC Digital Volume */ 53203db220SDimitris Papastamos 0x0000, /* R13 - Digital Side Tone */ 54203db220SDimitris Papastamos 0x0100, /* R14 - ADC CTRL */ 55203db220SDimitris Papastamos 0x00C0, /* R15 - Left ADC Digital Volume */ 56203db220SDimitris Papastamos 0x00C0, /* R16 - Right ADC Digital Volume */ 57203db220SDimitris Papastamos 0x0000, /* R17 */ 58203db220SDimitris Papastamos 0x0000, /* R18 - GPIO CTRL 1 */ 59203db220SDimitris Papastamos 0x1000, /* R19 - GPIO1 & GPIO2 */ 60203db220SDimitris Papastamos 0x1010, /* R20 - GPIO3 & GPIO4 */ 61203db220SDimitris Papastamos 0x1010, /* R21 - GPIO5 & GPIO6 */ 62203db220SDimitris Papastamos 0x8000, /* R22 - GPIOCTRL 2 */ 63203db220SDimitris Papastamos 0x0800, /* R23 - GPIO_POL */ 64203db220SDimitris Papastamos 0x008B, /* R24 - Left Line Input 1&2 Volume */ 65203db220SDimitris Papastamos 0x008B, /* R25 - Left Line Input 3&4 Volume */ 66203db220SDimitris Papastamos 0x008B, /* R26 - Right Line Input 1&2 Volume */ 67203db220SDimitris Papastamos 0x008B, /* R27 - Right Line Input 3&4 Volume */ 68203db220SDimitris Papastamos 0x0000, /* R28 - Left Output Volume */ 69203db220SDimitris Papastamos 0x0000, /* R29 - Right Output Volume */ 70203db220SDimitris Papastamos 0x0066, /* R30 - Line Outputs Volume */ 71203db220SDimitris Papastamos 0x0022, /* R31 - Out3/4 Volume */ 72203db220SDimitris Papastamos 0x0079, /* R32 - Left OPGA Volume */ 73203db220SDimitris Papastamos 0x0079, /* R33 - Right OPGA Volume */ 74203db220SDimitris Papastamos 0x0003, /* R34 - Speaker Volume */ 75203db220SDimitris Papastamos 0x0003, /* R35 - ClassD1 */ 76203db220SDimitris Papastamos 0x0000, /* R36 */ 77203db220SDimitris Papastamos 0x0100, /* R37 - ClassD3 */ 78203db220SDimitris Papastamos 0x0000, /* R38 */ 79203db220SDimitris Papastamos 0x0000, /* R39 - Input Mixer1 */ 80203db220SDimitris Papastamos 0x0000, /* R40 - Input Mixer2 */ 81203db220SDimitris Papastamos 0x0000, /* R41 - Input Mixer3 */ 82203db220SDimitris Papastamos 0x0000, /* R42 - Input Mixer4 */ 83203db220SDimitris Papastamos 0x0000, /* R43 - Input Mixer5 */ 84203db220SDimitris Papastamos 0x0000, /* R44 - Input Mixer6 */ 85203db220SDimitris Papastamos 0x0000, /* R45 - Output Mixer1 */ 86203db220SDimitris Papastamos 0x0000, /* R46 - Output Mixer2 */ 87203db220SDimitris Papastamos 0x0000, /* R47 - Output Mixer3 */ 88203db220SDimitris Papastamos 0x0000, /* R48 - Output Mixer4 */ 89203db220SDimitris Papastamos 0x0000, /* R49 - Output Mixer5 */ 90203db220SDimitris Papastamos 0x0000, /* R50 - Output Mixer6 */ 91203db220SDimitris Papastamos 0x0180, /* R51 - Out3/4 Mixer */ 92203db220SDimitris Papastamos 0x0000, /* R52 - Line Mixer1 */ 93203db220SDimitris Papastamos 0x0000, /* R53 - Line Mixer2 */ 94203db220SDimitris Papastamos 0x0000, /* R54 - Speaker Mixer */ 95203db220SDimitris Papastamos 0x0000, /* R55 - Additional Control */ 96203db220SDimitris Papastamos 0x0000, /* R56 - AntiPOP1 */ 97203db220SDimitris Papastamos 0x0000, /* R57 - AntiPOP2 */ 98203db220SDimitris Papastamos 0x0000, /* R58 - MICBIAS */ 99203db220SDimitris Papastamos 0x0000, /* R59 */ 100203db220SDimitris Papastamos 0x0008, /* R60 - PLL1 */ 101203db220SDimitris Papastamos 0x0031, /* R61 - PLL2 */ 102203db220SDimitris Papastamos 0x0026, /* R62 - PLL3 */ 103203db220SDimitris Papastamos }; 104203db220SDimitris Papastamos 105203db220SDimitris Papastamos #define wm8991_reset(c) snd_soc_write(c, WM8991_RESET, 0) 106203db220SDimitris Papastamos 107203db220SDimitris Papastamos static const unsigned int rec_mix_tlv[] = { 108203db220SDimitris Papastamos TLV_DB_RANGE_HEAD(1), 109203db220SDimitris Papastamos 0, 7, TLV_DB_LINEAR_ITEM(-1500, 600), 110203db220SDimitris Papastamos }; 111203db220SDimitris Papastamos 112203db220SDimitris Papastamos static const unsigned int in_pga_tlv[] = { 113203db220SDimitris Papastamos TLV_DB_RANGE_HEAD(1), 114203db220SDimitris Papastamos 0, 0x1F, TLV_DB_LINEAR_ITEM(-1650, 3000), 115203db220SDimitris Papastamos }; 116203db220SDimitris Papastamos 117203db220SDimitris Papastamos static const unsigned int out_mix_tlv[] = { 118203db220SDimitris Papastamos TLV_DB_RANGE_HEAD(1), 119203db220SDimitris Papastamos 0, 7, TLV_DB_LINEAR_ITEM(0, -2100), 120203db220SDimitris Papastamos }; 121203db220SDimitris Papastamos 122203db220SDimitris Papastamos static const unsigned int out_pga_tlv[] = { 123203db220SDimitris Papastamos TLV_DB_RANGE_HEAD(1), 124203db220SDimitris Papastamos 0, 127, TLV_DB_LINEAR_ITEM(-7300, 600), 125203db220SDimitris Papastamos }; 126203db220SDimitris Papastamos 127203db220SDimitris Papastamos static const unsigned int out_omix_tlv[] = { 128203db220SDimitris Papastamos TLV_DB_RANGE_HEAD(1), 129203db220SDimitris Papastamos 0, 7, TLV_DB_LINEAR_ITEM(-600, 0), 130203db220SDimitris Papastamos }; 131203db220SDimitris Papastamos 132203db220SDimitris Papastamos static const unsigned int out_dac_tlv[] = { 133203db220SDimitris Papastamos TLV_DB_RANGE_HEAD(1), 134203db220SDimitris Papastamos 0, 255, TLV_DB_LINEAR_ITEM(-7163, 0), 135203db220SDimitris Papastamos }; 136203db220SDimitris Papastamos 137203db220SDimitris Papastamos static const unsigned int in_adc_tlv[] = { 138203db220SDimitris Papastamos TLV_DB_RANGE_HEAD(1), 139203db220SDimitris Papastamos 0, 255, TLV_DB_LINEAR_ITEM(-7163, 1763), 140203db220SDimitris Papastamos }; 141203db220SDimitris Papastamos 142203db220SDimitris Papastamos static const unsigned int out_sidetone_tlv[] = { 143203db220SDimitris Papastamos TLV_DB_RANGE_HEAD(1), 144203db220SDimitris Papastamos 0, 31, TLV_DB_LINEAR_ITEM(-3600, 0), 145203db220SDimitris Papastamos }; 146203db220SDimitris Papastamos 147203db220SDimitris Papastamos static int wm899x_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol, 148203db220SDimitris Papastamos struct snd_ctl_elem_value *ucontrol) 149203db220SDimitris Papastamos { 150203db220SDimitris Papastamos struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 151203db220SDimitris Papastamos int reg = kcontrol->private_value & 0xff; 152203db220SDimitris Papastamos int ret; 153203db220SDimitris Papastamos u16 val; 154203db220SDimitris Papastamos 155203db220SDimitris Papastamos ret = snd_soc_put_volsw(kcontrol, ucontrol); 156203db220SDimitris Papastamos if (ret < 0) 157203db220SDimitris Papastamos return ret; 158203db220SDimitris Papastamos 159203db220SDimitris Papastamos /* now hit the volume update bits (always bit 8) */ 160203db220SDimitris Papastamos val = snd_soc_read(codec, reg); 161203db220SDimitris Papastamos return snd_soc_write(codec, reg, val | 0x0100); 162203db220SDimitris Papastamos } 163203db220SDimitris Papastamos 164203db220SDimitris Papastamos static const char *wm8991_digital_sidetone[] = 165203db220SDimitris Papastamos {"None", "Left ADC", "Right ADC", "Reserved"}; 166203db220SDimitris Papastamos 167203db220SDimitris Papastamos static const struct soc_enum wm8991_left_digital_sidetone_enum = 168203db220SDimitris Papastamos SOC_ENUM_SINGLE(WM8991_DIGITAL_SIDE_TONE, 169203db220SDimitris Papastamos WM8991_ADC_TO_DACL_SHIFT, 170203db220SDimitris Papastamos WM8991_ADC_TO_DACL_MASK, 171203db220SDimitris Papastamos wm8991_digital_sidetone); 172203db220SDimitris Papastamos 173203db220SDimitris Papastamos static const struct soc_enum wm8991_right_digital_sidetone_enum = 174203db220SDimitris Papastamos SOC_ENUM_SINGLE(WM8991_DIGITAL_SIDE_TONE, 175203db220SDimitris Papastamos WM8991_ADC_TO_DACR_SHIFT, 176203db220SDimitris Papastamos WM8991_ADC_TO_DACR_MASK, 177203db220SDimitris Papastamos wm8991_digital_sidetone); 178203db220SDimitris Papastamos 179203db220SDimitris Papastamos static const char *wm8991_adcmode[] = 180203db220SDimitris Papastamos {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"}; 181203db220SDimitris Papastamos 182203db220SDimitris Papastamos static const struct soc_enum wm8991_right_adcmode_enum = 183203db220SDimitris Papastamos SOC_ENUM_SINGLE(WM8991_ADC_CTRL, 184203db220SDimitris Papastamos WM8991_ADC_HPF_CUT_SHIFT, 185203db220SDimitris Papastamos WM8991_ADC_HPF_CUT_MASK, 186203db220SDimitris Papastamos wm8991_adcmode); 187203db220SDimitris Papastamos 188203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_snd_controls[] = { 189203db220SDimitris Papastamos /* INMIXL */ 190203db220SDimitris Papastamos SOC_SINGLE("LIN12 PGA Boost", WM8991_INPUT_MIXER3, WM8991_L12MNBST_BIT, 1, 0), 191203db220SDimitris Papastamos SOC_SINGLE("LIN34 PGA Boost", WM8991_INPUT_MIXER3, WM8991_L34MNBST_BIT, 1, 0), 192203db220SDimitris Papastamos /* INMIXR */ 193203db220SDimitris Papastamos SOC_SINGLE("RIN12 PGA Boost", WM8991_INPUT_MIXER3, WM8991_R12MNBST_BIT, 1, 0), 194203db220SDimitris Papastamos SOC_SINGLE("RIN34 PGA Boost", WM8991_INPUT_MIXER3, WM8991_R34MNBST_BIT, 1, 0), 195203db220SDimitris Papastamos 196203db220SDimitris Papastamos /* LOMIX */ 197203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX LIN3 Bypass Volume", WM8991_OUTPUT_MIXER3, 198203db220SDimitris Papastamos WM8991_LLI3LOVOL_SHIFT, WM8991_LLI3LOVOL_MASK, 1, out_mix_tlv), 199203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX RIN12 PGA Bypass Volume", WM8991_OUTPUT_MIXER3, 200203db220SDimitris Papastamos WM8991_LR12LOVOL_SHIFT, WM8991_LR12LOVOL_MASK, 1, out_mix_tlv), 201203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX LIN12 PGA Bypass Volume", WM8991_OUTPUT_MIXER3, 202203db220SDimitris Papastamos WM8991_LL12LOVOL_SHIFT, WM8991_LL12LOVOL_MASK, 1, out_mix_tlv), 203203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX RIN3 Bypass Volume", WM8991_OUTPUT_MIXER5, 204203db220SDimitris Papastamos WM8991_LRI3LOVOL_SHIFT, WM8991_LRI3LOVOL_MASK, 1, out_mix_tlv), 205203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX AINRMUX Bypass Volume", WM8991_OUTPUT_MIXER5, 206203db220SDimitris Papastamos WM8991_LRBLOVOL_SHIFT, WM8991_LRBLOVOL_MASK, 1, out_mix_tlv), 207203db220SDimitris Papastamos SOC_SINGLE_TLV("LOMIX AINLMUX Bypass Volume", WM8991_OUTPUT_MIXER5, 208203db220SDimitris Papastamos WM8991_LRBLOVOL_SHIFT, WM8991_LRBLOVOL_MASK, 1, out_mix_tlv), 209203db220SDimitris Papastamos 210203db220SDimitris Papastamos /* ROMIX */ 211203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX RIN3 Bypass Volume", WM8991_OUTPUT_MIXER4, 212203db220SDimitris Papastamos WM8991_RRI3ROVOL_SHIFT, WM8991_RRI3ROVOL_MASK, 1, out_mix_tlv), 213203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX LIN12 PGA Bypass Volume", WM8991_OUTPUT_MIXER4, 214203db220SDimitris Papastamos WM8991_RL12ROVOL_SHIFT, WM8991_RL12ROVOL_MASK, 1, out_mix_tlv), 215203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX RIN12 PGA Bypass Volume", WM8991_OUTPUT_MIXER4, 216203db220SDimitris Papastamos WM8991_RR12ROVOL_SHIFT, WM8991_RR12ROVOL_MASK, 1, out_mix_tlv), 217203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX LIN3 Bypass Volume", WM8991_OUTPUT_MIXER6, 218203db220SDimitris Papastamos WM8991_RLI3ROVOL_SHIFT, WM8991_RLI3ROVOL_MASK, 1, out_mix_tlv), 219203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX AINLMUX Bypass Volume", WM8991_OUTPUT_MIXER6, 220203db220SDimitris Papastamos WM8991_RLBROVOL_SHIFT, WM8991_RLBROVOL_MASK, 1, out_mix_tlv), 221203db220SDimitris Papastamos SOC_SINGLE_TLV("ROMIX AINRMUX Bypass Volume", WM8991_OUTPUT_MIXER6, 222203db220SDimitris Papastamos WM8991_RRBROVOL_SHIFT, WM8991_RRBROVOL_MASK, 1, out_mix_tlv), 223203db220SDimitris Papastamos 224203db220SDimitris Papastamos /* LOUT */ 225203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("LOUT Volume", WM8991_LEFT_OUTPUT_VOLUME, 226203db220SDimitris Papastamos WM8991_LOUTVOL_SHIFT, WM8991_LOUTVOL_MASK, 0, out_pga_tlv), 227203db220SDimitris Papastamos SOC_SINGLE("LOUT ZC", WM8991_LEFT_OUTPUT_VOLUME, WM8991_LOZC_BIT, 1, 0), 228203db220SDimitris Papastamos 229203db220SDimitris Papastamos /* ROUT */ 230203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("ROUT Volume", WM8991_RIGHT_OUTPUT_VOLUME, 231203db220SDimitris Papastamos WM8991_ROUTVOL_SHIFT, WM8991_ROUTVOL_MASK, 0, out_pga_tlv), 232203db220SDimitris Papastamos SOC_SINGLE("ROUT ZC", WM8991_RIGHT_OUTPUT_VOLUME, WM8991_ROZC_BIT, 1, 0), 233203db220SDimitris Papastamos 234203db220SDimitris Papastamos /* LOPGA */ 235203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("LOPGA Volume", WM8991_LEFT_OPGA_VOLUME, 236203db220SDimitris Papastamos WM8991_LOPGAVOL_SHIFT, WM8991_LOPGAVOL_MASK, 0, out_pga_tlv), 237203db220SDimitris Papastamos SOC_SINGLE("LOPGA ZC Switch", WM8991_LEFT_OPGA_VOLUME, 238203db220SDimitris Papastamos WM8991_LOPGAZC_BIT, 1, 0), 239203db220SDimitris Papastamos 240203db220SDimitris Papastamos /* ROPGA */ 241203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("ROPGA Volume", WM8991_RIGHT_OPGA_VOLUME, 242203db220SDimitris Papastamos WM8991_ROPGAVOL_SHIFT, WM8991_ROPGAVOL_MASK, 0, out_pga_tlv), 243203db220SDimitris Papastamos SOC_SINGLE("ROPGA ZC Switch", WM8991_RIGHT_OPGA_VOLUME, 244203db220SDimitris Papastamos WM8991_ROPGAZC_BIT, 1, 0), 245203db220SDimitris Papastamos 246203db220SDimitris Papastamos SOC_SINGLE("LON Mute Switch", WM8991_LINE_OUTPUTS_VOLUME, 247203db220SDimitris Papastamos WM8991_LONMUTE_BIT, 1, 0), 248203db220SDimitris Papastamos SOC_SINGLE("LOP Mute Switch", WM8991_LINE_OUTPUTS_VOLUME, 249203db220SDimitris Papastamos WM8991_LOPMUTE_BIT, 1, 0), 250203db220SDimitris Papastamos SOC_SINGLE("LOP Attenuation Switch", WM8991_LINE_OUTPUTS_VOLUME, 251203db220SDimitris Papastamos WM8991_LOATTN_BIT, 1, 0), 252203db220SDimitris Papastamos SOC_SINGLE("RON Mute Switch", WM8991_LINE_OUTPUTS_VOLUME, 253203db220SDimitris Papastamos WM8991_RONMUTE_BIT, 1, 0), 254203db220SDimitris Papastamos SOC_SINGLE("ROP Mute Switch", WM8991_LINE_OUTPUTS_VOLUME, 255203db220SDimitris Papastamos WM8991_ROPMUTE_BIT, 1, 0), 256203db220SDimitris Papastamos SOC_SINGLE("ROP Attenuation Switch", WM8991_LINE_OUTPUTS_VOLUME, 257203db220SDimitris Papastamos WM8991_ROATTN_BIT, 1, 0), 258203db220SDimitris Papastamos 259203db220SDimitris Papastamos SOC_SINGLE("OUT3 Mute Switch", WM8991_OUT3_4_VOLUME, 260203db220SDimitris Papastamos WM8991_OUT3MUTE_BIT, 1, 0), 261203db220SDimitris Papastamos SOC_SINGLE("OUT3 Attenuation Switch", WM8991_OUT3_4_VOLUME, 262203db220SDimitris Papastamos WM8991_OUT3ATTN_BIT, 1, 0), 263203db220SDimitris Papastamos 264203db220SDimitris Papastamos SOC_SINGLE("OUT4 Mute Switch", WM8991_OUT3_4_VOLUME, 265203db220SDimitris Papastamos WM8991_OUT4MUTE_BIT, 1, 0), 266203db220SDimitris Papastamos SOC_SINGLE("OUT4 Attenuation Switch", WM8991_OUT3_4_VOLUME, 267203db220SDimitris Papastamos WM8991_OUT4ATTN_BIT, 1, 0), 268203db220SDimitris Papastamos 269203db220SDimitris Papastamos SOC_SINGLE("Speaker Mode Switch", WM8991_CLASSD1, 270203db220SDimitris Papastamos WM8991_CDMODE_BIT, 1, 0), 271203db220SDimitris Papastamos 272203db220SDimitris Papastamos SOC_SINGLE("Speaker Output Attenuation Volume", WM8991_SPEAKER_VOLUME, 273203db220SDimitris Papastamos WM8991_SPKVOL_SHIFT, WM8991_SPKVOL_MASK, 0), 274203db220SDimitris Papastamos SOC_SINGLE("Speaker DC Boost Volume", WM8991_CLASSD3, 275203db220SDimitris Papastamos WM8991_DCGAIN_SHIFT, WM8991_DCGAIN_MASK, 0), 276203db220SDimitris Papastamos SOC_SINGLE("Speaker AC Boost Volume", WM8991_CLASSD3, 277203db220SDimitris Papastamos WM8991_ACGAIN_SHIFT, WM8991_ACGAIN_MASK, 0), 278203db220SDimitris Papastamos 279203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("Left DAC Digital Volume", 280203db220SDimitris Papastamos WM8991_LEFT_DAC_DIGITAL_VOLUME, 281203db220SDimitris Papastamos WM8991_DACL_VOL_SHIFT, 282203db220SDimitris Papastamos WM8991_DACL_VOL_MASK, 283203db220SDimitris Papastamos 0, 284203db220SDimitris Papastamos out_dac_tlv), 285203db220SDimitris Papastamos 286203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("Right DAC Digital Volume", 287203db220SDimitris Papastamos WM8991_RIGHT_DAC_DIGITAL_VOLUME, 288203db220SDimitris Papastamos WM8991_DACR_VOL_SHIFT, 289203db220SDimitris Papastamos WM8991_DACR_VOL_MASK, 290203db220SDimitris Papastamos 0, 291203db220SDimitris Papastamos out_dac_tlv), 292203db220SDimitris Papastamos 293203db220SDimitris Papastamos SOC_ENUM("Left Digital Sidetone", wm8991_left_digital_sidetone_enum), 294203db220SDimitris Papastamos SOC_ENUM("Right Digital Sidetone", wm8991_right_digital_sidetone_enum), 295203db220SDimitris Papastamos 296203db220SDimitris Papastamos SOC_SINGLE_TLV("Left Digital Sidetone Volume", WM8991_DIGITAL_SIDE_TONE, 297203db220SDimitris Papastamos WM8991_ADCL_DAC_SVOL_SHIFT, WM8991_ADCL_DAC_SVOL_MASK, 0, 298203db220SDimitris Papastamos out_sidetone_tlv), 299203db220SDimitris Papastamos SOC_SINGLE_TLV("Right Digital Sidetone Volume", WM8991_DIGITAL_SIDE_TONE, 300203db220SDimitris Papastamos WM8991_ADCR_DAC_SVOL_SHIFT, WM8991_ADCR_DAC_SVOL_MASK, 0, 301203db220SDimitris Papastamos out_sidetone_tlv), 302203db220SDimitris Papastamos 303203db220SDimitris Papastamos SOC_SINGLE("ADC Digital High Pass Filter Switch", WM8991_ADC_CTRL, 304203db220SDimitris Papastamos WM8991_ADC_HPF_ENA_BIT, 1, 0), 305203db220SDimitris Papastamos 306203db220SDimitris Papastamos SOC_ENUM("ADC HPF Mode", wm8991_right_adcmode_enum), 307203db220SDimitris Papastamos 308203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("Left ADC Digital Volume", 309203db220SDimitris Papastamos WM8991_LEFT_ADC_DIGITAL_VOLUME, 310203db220SDimitris Papastamos WM8991_ADCL_VOL_SHIFT, 311203db220SDimitris Papastamos WM8991_ADCL_VOL_MASK, 312203db220SDimitris Papastamos 0, 313203db220SDimitris Papastamos in_adc_tlv), 314203db220SDimitris Papastamos 315203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("Right ADC Digital Volume", 316203db220SDimitris Papastamos WM8991_RIGHT_ADC_DIGITAL_VOLUME, 317203db220SDimitris Papastamos WM8991_ADCR_VOL_SHIFT, 318203db220SDimitris Papastamos WM8991_ADCR_VOL_MASK, 319203db220SDimitris Papastamos 0, 320203db220SDimitris Papastamos in_adc_tlv), 321203db220SDimitris Papastamos 322203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("LIN12 Volume", 323203db220SDimitris Papastamos WM8991_LEFT_LINE_INPUT_1_2_VOLUME, 324203db220SDimitris Papastamos WM8991_LIN12VOL_SHIFT, 325203db220SDimitris Papastamos WM8991_LIN12VOL_MASK, 326203db220SDimitris Papastamos 0, 327203db220SDimitris Papastamos in_pga_tlv), 328203db220SDimitris Papastamos 329203db220SDimitris Papastamos SOC_SINGLE("LIN12 ZC Switch", WM8991_LEFT_LINE_INPUT_1_2_VOLUME, 330203db220SDimitris Papastamos WM8991_LI12ZC_BIT, 1, 0), 331203db220SDimitris Papastamos 332203db220SDimitris Papastamos SOC_SINGLE("LIN12 Mute Switch", WM8991_LEFT_LINE_INPUT_1_2_VOLUME, 333203db220SDimitris Papastamos WM8991_LI12MUTE_BIT, 1, 0), 334203db220SDimitris Papastamos 335203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("LIN34 Volume", 336203db220SDimitris Papastamos WM8991_LEFT_LINE_INPUT_3_4_VOLUME, 337203db220SDimitris Papastamos WM8991_LIN34VOL_SHIFT, 338203db220SDimitris Papastamos WM8991_LIN34VOL_MASK, 339203db220SDimitris Papastamos 0, 340203db220SDimitris Papastamos in_pga_tlv), 341203db220SDimitris Papastamos 342203db220SDimitris Papastamos SOC_SINGLE("LIN34 ZC Switch", WM8991_LEFT_LINE_INPUT_3_4_VOLUME, 343203db220SDimitris Papastamos WM8991_LI34ZC_BIT, 1, 0), 344203db220SDimitris Papastamos 345203db220SDimitris Papastamos SOC_SINGLE("LIN34 Mute Switch", WM8991_LEFT_LINE_INPUT_3_4_VOLUME, 346203db220SDimitris Papastamos WM8991_LI34MUTE_BIT, 1, 0), 347203db220SDimitris Papastamos 348203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("RIN12 Volume", 349203db220SDimitris Papastamos WM8991_RIGHT_LINE_INPUT_1_2_VOLUME, 350203db220SDimitris Papastamos WM8991_RIN12VOL_SHIFT, 351203db220SDimitris Papastamos WM8991_RIN12VOL_MASK, 352203db220SDimitris Papastamos 0, 353203db220SDimitris Papastamos in_pga_tlv), 354203db220SDimitris Papastamos 355203db220SDimitris Papastamos SOC_SINGLE("RIN12 ZC Switch", WM8991_RIGHT_LINE_INPUT_1_2_VOLUME, 356203db220SDimitris Papastamos WM8991_RI12ZC_BIT, 1, 0), 357203db220SDimitris Papastamos 358203db220SDimitris Papastamos SOC_SINGLE("RIN12 Mute Switch", WM8991_RIGHT_LINE_INPUT_1_2_VOLUME, 359203db220SDimitris Papastamos WM8991_RI12MUTE_BIT, 1, 0), 360203db220SDimitris Papastamos 361203db220SDimitris Papastamos SOC_WM899X_OUTPGA_SINGLE_R_TLV("RIN34 Volume", 362203db220SDimitris Papastamos WM8991_RIGHT_LINE_INPUT_3_4_VOLUME, 363203db220SDimitris Papastamos WM8991_RIN34VOL_SHIFT, 364203db220SDimitris Papastamos WM8991_RIN34VOL_MASK, 365203db220SDimitris Papastamos 0, 366203db220SDimitris Papastamos in_pga_tlv), 367203db220SDimitris Papastamos 368203db220SDimitris Papastamos SOC_SINGLE("RIN34 ZC Switch", WM8991_RIGHT_LINE_INPUT_3_4_VOLUME, 369203db220SDimitris Papastamos WM8991_RI34ZC_BIT, 1, 0), 370203db220SDimitris Papastamos 371203db220SDimitris Papastamos SOC_SINGLE("RIN34 Mute Switch", WM8991_RIGHT_LINE_INPUT_3_4_VOLUME, 372203db220SDimitris Papastamos WM8991_RI34MUTE_BIT, 1, 0), 373203db220SDimitris Papastamos }; 374203db220SDimitris Papastamos 375203db220SDimitris Papastamos /* 376203db220SDimitris Papastamos * _DAPM_ Controls 377203db220SDimitris Papastamos */ 378203db220SDimitris Papastamos static int inmixer_event(struct snd_soc_dapm_widget *w, 379203db220SDimitris Papastamos struct snd_kcontrol *kcontrol, int event) 380203db220SDimitris Papastamos { 381203db220SDimitris Papastamos u16 reg, fakepower; 382203db220SDimitris Papastamos 383203db220SDimitris Papastamos reg = snd_soc_read(w->codec, WM8991_POWER_MANAGEMENT_2); 384203db220SDimitris Papastamos fakepower = snd_soc_read(w->codec, WM8991_INTDRIVBITS); 385203db220SDimitris Papastamos 386203db220SDimitris Papastamos if (fakepower & ((1 << WM8991_INMIXL_PWR_BIT) | 387203db220SDimitris Papastamos (1 << WM8991_AINLMUX_PWR_BIT))) 388203db220SDimitris Papastamos reg |= WM8991_AINL_ENA; 389203db220SDimitris Papastamos else 390203db220SDimitris Papastamos reg &= ~WM8991_AINL_ENA; 391203db220SDimitris Papastamos 392203db220SDimitris Papastamos if (fakepower & ((1 << WM8991_INMIXR_PWR_BIT) | 393203db220SDimitris Papastamos (1 << WM8991_AINRMUX_PWR_BIT))) 394203db220SDimitris Papastamos reg |= WM8991_AINR_ENA; 395203db220SDimitris Papastamos else 3963f387a21SAxel Lin reg &= ~WM8991_AINR_ENA; 397203db220SDimitris Papastamos 398203db220SDimitris Papastamos snd_soc_write(w->codec, WM8991_POWER_MANAGEMENT_2, reg); 399203db220SDimitris Papastamos return 0; 400203db220SDimitris Papastamos } 401203db220SDimitris Papastamos 402203db220SDimitris Papastamos static int outmixer_event(struct snd_soc_dapm_widget *w, 403203db220SDimitris Papastamos struct snd_kcontrol *kcontrol, int event) 404203db220SDimitris Papastamos { 405203db220SDimitris Papastamos u32 reg_shift = kcontrol->private_value & 0xfff; 406203db220SDimitris Papastamos int ret = 0; 407203db220SDimitris Papastamos u16 reg; 408203db220SDimitris Papastamos 409203db220SDimitris Papastamos switch (reg_shift) { 410203db220SDimitris Papastamos case WM8991_SPEAKER_MIXER | (WM8991_LDSPK_BIT << 8): 411203db220SDimitris Papastamos reg = snd_soc_read(w->codec, WM8991_OUTPUT_MIXER1); 412203db220SDimitris Papastamos if (reg & WM8991_LDLO) { 413203db220SDimitris Papastamos printk(KERN_WARNING 414203db220SDimitris Papastamos "Cannot set as Output Mixer 1 LDLO Set\n"); 415203db220SDimitris Papastamos ret = -1; 416203db220SDimitris Papastamos } 417203db220SDimitris Papastamos break; 418203db220SDimitris Papastamos 419203db220SDimitris Papastamos case WM8991_SPEAKER_MIXER | (WM8991_RDSPK_BIT << 8): 420203db220SDimitris Papastamos reg = snd_soc_read(w->codec, WM8991_OUTPUT_MIXER2); 421203db220SDimitris Papastamos if (reg & WM8991_RDRO) { 422203db220SDimitris Papastamos printk(KERN_WARNING 423203db220SDimitris Papastamos "Cannot set as Output Mixer 2 RDRO Set\n"); 424203db220SDimitris Papastamos ret = -1; 425203db220SDimitris Papastamos } 426203db220SDimitris Papastamos break; 427203db220SDimitris Papastamos 428203db220SDimitris Papastamos case WM8991_OUTPUT_MIXER1 | (WM8991_LDLO_BIT << 8): 429203db220SDimitris Papastamos reg = snd_soc_read(w->codec, WM8991_SPEAKER_MIXER); 430203db220SDimitris Papastamos if (reg & WM8991_LDSPK) { 431203db220SDimitris Papastamos printk(KERN_WARNING 432203db220SDimitris Papastamos "Cannot set as Speaker Mixer LDSPK Set\n"); 433203db220SDimitris Papastamos ret = -1; 434203db220SDimitris Papastamos } 435203db220SDimitris Papastamos break; 436203db220SDimitris Papastamos 437203db220SDimitris Papastamos case WM8991_OUTPUT_MIXER2 | (WM8991_RDRO_BIT << 8): 438203db220SDimitris Papastamos reg = snd_soc_read(w->codec, WM8991_SPEAKER_MIXER); 439203db220SDimitris Papastamos if (reg & WM8991_RDSPK) { 440203db220SDimitris Papastamos printk(KERN_WARNING 441203db220SDimitris Papastamos "Cannot set as Speaker Mixer RDSPK Set\n"); 442203db220SDimitris Papastamos ret = -1; 443203db220SDimitris Papastamos } 444203db220SDimitris Papastamos break; 445203db220SDimitris Papastamos } 446203db220SDimitris Papastamos 447203db220SDimitris Papastamos return ret; 448203db220SDimitris Papastamos } 449203db220SDimitris Papastamos 450203db220SDimitris Papastamos /* INMIX dB values */ 451203db220SDimitris Papastamos static const unsigned int in_mix_tlv[] = { 452203db220SDimitris Papastamos TLV_DB_RANGE_HEAD(1), 453203db220SDimitris Papastamos 0, 7, TLV_DB_LINEAR_ITEM(-1200, 600), 454203db220SDimitris Papastamos }; 455203db220SDimitris Papastamos 456203db220SDimitris Papastamos /* Left In PGA Connections */ 457203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_lin12_pga_controls[] = { 458203db220SDimitris Papastamos SOC_DAPM_SINGLE("LIN1 Switch", WM8991_INPUT_MIXER2, WM8991_LMN1_BIT, 1, 0), 459203db220SDimitris Papastamos SOC_DAPM_SINGLE("LIN2 Switch", WM8991_INPUT_MIXER2, WM8991_LMP2_BIT, 1, 0), 460203db220SDimitris Papastamos }; 461203db220SDimitris Papastamos 462203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_lin34_pga_controls[] = { 463203db220SDimitris Papastamos SOC_DAPM_SINGLE("LIN3 Switch", WM8991_INPUT_MIXER2, WM8991_LMN3_BIT, 1, 0), 464203db220SDimitris Papastamos SOC_DAPM_SINGLE("LIN4 Switch", WM8991_INPUT_MIXER2, WM8991_LMP4_BIT, 1, 0), 465203db220SDimitris Papastamos }; 466203db220SDimitris Papastamos 467203db220SDimitris Papastamos /* Right In PGA Connections */ 468203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_rin12_pga_controls[] = { 469203db220SDimitris Papastamos SOC_DAPM_SINGLE("RIN1 Switch", WM8991_INPUT_MIXER2, WM8991_RMN1_BIT, 1, 0), 470203db220SDimitris Papastamos SOC_DAPM_SINGLE("RIN2 Switch", WM8991_INPUT_MIXER2, WM8991_RMP2_BIT, 1, 0), 471203db220SDimitris Papastamos }; 472203db220SDimitris Papastamos 473203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_rin34_pga_controls[] = { 474203db220SDimitris Papastamos SOC_DAPM_SINGLE("RIN3 Switch", WM8991_INPUT_MIXER2, WM8991_RMN3_BIT, 1, 0), 475203db220SDimitris Papastamos SOC_DAPM_SINGLE("RIN4 Switch", WM8991_INPUT_MIXER2, WM8991_RMP4_BIT, 1, 0), 476203db220SDimitris Papastamos }; 477203db220SDimitris Papastamos 478203db220SDimitris Papastamos /* INMIXL */ 479203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_inmixl_controls[] = { 480203db220SDimitris Papastamos SOC_DAPM_SINGLE_TLV("Record Left Volume", WM8991_INPUT_MIXER3, 481203db220SDimitris Papastamos WM8991_LDBVOL_SHIFT, WM8991_LDBVOL_MASK, 0, in_mix_tlv), 482203db220SDimitris Papastamos SOC_DAPM_SINGLE_TLV("LIN2 Volume", WM8991_INPUT_MIXER5, WM8991_LI2BVOL_SHIFT, 483203db220SDimitris Papastamos 7, 0, in_mix_tlv), 484203db220SDimitris Papastamos SOC_DAPM_SINGLE("LINPGA12 Switch", WM8991_INPUT_MIXER3, WM8991_L12MNB_BIT, 485203db220SDimitris Papastamos 1, 0), 486203db220SDimitris Papastamos SOC_DAPM_SINGLE("LINPGA34 Switch", WM8991_INPUT_MIXER3, WM8991_L34MNB_BIT, 487203db220SDimitris Papastamos 1, 0), 488203db220SDimitris Papastamos }; 489203db220SDimitris Papastamos 490203db220SDimitris Papastamos /* INMIXR */ 491203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_inmixr_controls[] = { 492203db220SDimitris Papastamos SOC_DAPM_SINGLE_TLV("Record Right Volume", WM8991_INPUT_MIXER4, 493203db220SDimitris Papastamos WM8991_RDBVOL_SHIFT, WM8991_RDBVOL_MASK, 0, in_mix_tlv), 494203db220SDimitris Papastamos SOC_DAPM_SINGLE_TLV("RIN2 Volume", WM8991_INPUT_MIXER6, WM8991_RI2BVOL_SHIFT, 495203db220SDimitris Papastamos 7, 0, in_mix_tlv), 496203db220SDimitris Papastamos SOC_DAPM_SINGLE("RINPGA12 Switch", WM8991_INPUT_MIXER3, WM8991_L12MNB_BIT, 497203db220SDimitris Papastamos 1, 0), 498203db220SDimitris Papastamos SOC_DAPM_SINGLE("RINPGA34 Switch", WM8991_INPUT_MIXER3, WM8991_L34MNB_BIT, 499203db220SDimitris Papastamos 1, 0), 500203db220SDimitris Papastamos }; 501203db220SDimitris Papastamos 502203db220SDimitris Papastamos /* AINLMUX */ 503203db220SDimitris Papastamos static const char *wm8991_ainlmux[] = 504203db220SDimitris Papastamos {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"}; 505203db220SDimitris Papastamos 506203db220SDimitris Papastamos static const struct soc_enum wm8991_ainlmux_enum = 507203db220SDimitris Papastamos SOC_ENUM_SINGLE(WM8991_INPUT_MIXER1, WM8991_AINLMODE_SHIFT, 508203db220SDimitris Papastamos ARRAY_SIZE(wm8991_ainlmux), wm8991_ainlmux); 509203db220SDimitris Papastamos 510203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_ainlmux_controls = 511203db220SDimitris Papastamos SOC_DAPM_ENUM("Route", wm8991_ainlmux_enum); 512203db220SDimitris Papastamos 513203db220SDimitris Papastamos /* DIFFINL */ 514203db220SDimitris Papastamos 515203db220SDimitris Papastamos /* AINRMUX */ 516203db220SDimitris Papastamos static const char *wm8991_ainrmux[] = 517203db220SDimitris Papastamos {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"}; 518203db220SDimitris Papastamos 519203db220SDimitris Papastamos static const struct soc_enum wm8991_ainrmux_enum = 520203db220SDimitris Papastamos SOC_ENUM_SINGLE(WM8991_INPUT_MIXER1, WM8991_AINRMODE_SHIFT, 521203db220SDimitris Papastamos ARRAY_SIZE(wm8991_ainrmux), wm8991_ainrmux); 522203db220SDimitris Papastamos 523203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_ainrmux_controls = 524203db220SDimitris Papastamos SOC_DAPM_ENUM("Route", wm8991_ainrmux_enum); 525203db220SDimitris Papastamos 526203db220SDimitris Papastamos /* RXVOICE */ 527203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_rxvoice_controls[] = { 528203db220SDimitris Papastamos SOC_DAPM_SINGLE_TLV("LIN4RXN", WM8991_INPUT_MIXER5, WM8991_LR4BVOL_SHIFT, 529203db220SDimitris Papastamos WM8991_LR4BVOL_MASK, 0, in_mix_tlv), 530203db220SDimitris Papastamos SOC_DAPM_SINGLE_TLV("RIN4RXP", WM8991_INPUT_MIXER6, WM8991_RL4BVOL_SHIFT, 531203db220SDimitris Papastamos WM8991_RL4BVOL_MASK, 0, in_mix_tlv), 532203db220SDimitris Papastamos }; 533203db220SDimitris Papastamos 534203db220SDimitris Papastamos /* LOMIX */ 535203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_lomix_controls[] = { 536203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX Right ADC Bypass Switch", WM8991_OUTPUT_MIXER1, 537203db220SDimitris Papastamos WM8991_LRBLO_BIT, 1, 0), 538203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX Left ADC Bypass Switch", WM8991_OUTPUT_MIXER1, 539203db220SDimitris Papastamos WM8991_LLBLO_BIT, 1, 0), 540203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX RIN3 Bypass Switch", WM8991_OUTPUT_MIXER1, 541203db220SDimitris Papastamos WM8991_LRI3LO_BIT, 1, 0), 542203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX LIN3 Bypass Switch", WM8991_OUTPUT_MIXER1, 543203db220SDimitris Papastamos WM8991_LLI3LO_BIT, 1, 0), 544203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX RIN12 PGA Bypass Switch", WM8991_OUTPUT_MIXER1, 545203db220SDimitris Papastamos WM8991_LR12LO_BIT, 1, 0), 546203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX LIN12 PGA Bypass Switch", WM8991_OUTPUT_MIXER1, 547203db220SDimitris Papastamos WM8991_LL12LO_BIT, 1, 0), 548203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOMIX Left DAC Switch", WM8991_OUTPUT_MIXER1, 549203db220SDimitris Papastamos WM8991_LDLO_BIT, 1, 0), 550203db220SDimitris Papastamos }; 551203db220SDimitris Papastamos 552203db220SDimitris Papastamos /* ROMIX */ 553203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_romix_controls[] = { 554203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX Left ADC Bypass Switch", WM8991_OUTPUT_MIXER2, 555203db220SDimitris Papastamos WM8991_RLBRO_BIT, 1, 0), 556203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX Right ADC Bypass Switch", WM8991_OUTPUT_MIXER2, 557203db220SDimitris Papastamos WM8991_RRBRO_BIT, 1, 0), 558203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX LIN3 Bypass Switch", WM8991_OUTPUT_MIXER2, 559203db220SDimitris Papastamos WM8991_RLI3RO_BIT, 1, 0), 560203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX RIN3 Bypass Switch", WM8991_OUTPUT_MIXER2, 561203db220SDimitris Papastamos WM8991_RRI3RO_BIT, 1, 0), 562203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX LIN12 PGA Bypass Switch", WM8991_OUTPUT_MIXER2, 563203db220SDimitris Papastamos WM8991_RL12RO_BIT, 1, 0), 564203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX RIN12 PGA Bypass Switch", WM8991_OUTPUT_MIXER2, 565203db220SDimitris Papastamos WM8991_RR12RO_BIT, 1, 0), 566203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROMIX Right DAC Switch", WM8991_OUTPUT_MIXER2, 567203db220SDimitris Papastamos WM8991_RDRO_BIT, 1, 0), 568203db220SDimitris Papastamos }; 569203db220SDimitris Papastamos 570203db220SDimitris Papastamos /* LONMIX */ 571203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_lonmix_controls[] = { 572203db220SDimitris Papastamos SOC_DAPM_SINGLE("LONMIX Left Mixer PGA Switch", WM8991_LINE_MIXER1, 573203db220SDimitris Papastamos WM8991_LLOPGALON_BIT, 1, 0), 574203db220SDimitris Papastamos SOC_DAPM_SINGLE("LONMIX Right Mixer PGA Switch", WM8991_LINE_MIXER1, 575203db220SDimitris Papastamos WM8991_LROPGALON_BIT, 1, 0), 576203db220SDimitris Papastamos SOC_DAPM_SINGLE("LONMIX Inverted LOP Switch", WM8991_LINE_MIXER1, 577203db220SDimitris Papastamos WM8991_LOPLON_BIT, 1, 0), 578203db220SDimitris Papastamos }; 579203db220SDimitris Papastamos 580203db220SDimitris Papastamos /* LOPMIX */ 581203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_lopmix_controls[] = { 582203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOPMIX Right Mic Bypass Switch", WM8991_LINE_MIXER1, 583203db220SDimitris Papastamos WM8991_LR12LOP_BIT, 1, 0), 584203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOPMIX Left Mic Bypass Switch", WM8991_LINE_MIXER1, 585203db220SDimitris Papastamos WM8991_LL12LOP_BIT, 1, 0), 586203db220SDimitris Papastamos SOC_DAPM_SINGLE("LOPMIX Left Mixer PGA Switch", WM8991_LINE_MIXER1, 587203db220SDimitris Papastamos WM8991_LLOPGALOP_BIT, 1, 0), 588203db220SDimitris Papastamos }; 589203db220SDimitris Papastamos 590203db220SDimitris Papastamos /* RONMIX */ 591203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_ronmix_controls[] = { 592203db220SDimitris Papastamos SOC_DAPM_SINGLE("RONMIX Right Mixer PGA Switch", WM8991_LINE_MIXER2, 593203db220SDimitris Papastamos WM8991_RROPGARON_BIT, 1, 0), 594203db220SDimitris Papastamos SOC_DAPM_SINGLE("RONMIX Left Mixer PGA Switch", WM8991_LINE_MIXER2, 595203db220SDimitris Papastamos WM8991_RLOPGARON_BIT, 1, 0), 596203db220SDimitris Papastamos SOC_DAPM_SINGLE("RONMIX Inverted ROP Switch", WM8991_LINE_MIXER2, 597203db220SDimitris Papastamos WM8991_ROPRON_BIT, 1, 0), 598203db220SDimitris Papastamos }; 599203db220SDimitris Papastamos 600203db220SDimitris Papastamos /* ROPMIX */ 601203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_ropmix_controls[] = { 602203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROPMIX Left Mic Bypass Switch", WM8991_LINE_MIXER2, 603203db220SDimitris Papastamos WM8991_RL12ROP_BIT, 1, 0), 604203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROPMIX Right Mic Bypass Switch", WM8991_LINE_MIXER2, 605203db220SDimitris Papastamos WM8991_RR12ROP_BIT, 1, 0), 606203db220SDimitris Papastamos SOC_DAPM_SINGLE("ROPMIX Right Mixer PGA Switch", WM8991_LINE_MIXER2, 607203db220SDimitris Papastamos WM8991_RROPGAROP_BIT, 1, 0), 608203db220SDimitris Papastamos }; 609203db220SDimitris Papastamos 610203db220SDimitris Papastamos /* OUT3MIX */ 611203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_out3mix_controls[] = { 612203db220SDimitris Papastamos SOC_DAPM_SINGLE("OUT3MIX LIN4RXN Bypass Switch", WM8991_OUT3_4_MIXER, 613203db220SDimitris Papastamos WM8991_LI4O3_BIT, 1, 0), 614203db220SDimitris Papastamos SOC_DAPM_SINGLE("OUT3MIX Left Out PGA Switch", WM8991_OUT3_4_MIXER, 615203db220SDimitris Papastamos WM8991_LPGAO3_BIT, 1, 0), 616203db220SDimitris Papastamos }; 617203db220SDimitris Papastamos 618203db220SDimitris Papastamos /* OUT4MIX */ 619203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_out4mix_controls[] = { 620203db220SDimitris Papastamos SOC_DAPM_SINGLE("OUT4MIX Right Out PGA Switch", WM8991_OUT3_4_MIXER, 621203db220SDimitris Papastamos WM8991_RPGAO4_BIT, 1, 0), 622203db220SDimitris Papastamos SOC_DAPM_SINGLE("OUT4MIX RIN4RXP Bypass Switch", WM8991_OUT3_4_MIXER, 623203db220SDimitris Papastamos WM8991_RI4O4_BIT, 1, 0), 624203db220SDimitris Papastamos }; 625203db220SDimitris Papastamos 626203db220SDimitris Papastamos /* SPKMIX */ 627203db220SDimitris Papastamos static const struct snd_kcontrol_new wm8991_dapm_spkmix_controls[] = { 628203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX LIN2 Bypass Switch", WM8991_SPEAKER_MIXER, 629203db220SDimitris Papastamos WM8991_LI2SPK_BIT, 1, 0), 630203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX LADC Bypass Switch", WM8991_SPEAKER_MIXER, 631203db220SDimitris Papastamos WM8991_LB2SPK_BIT, 1, 0), 632203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX Left Mixer PGA Switch", WM8991_SPEAKER_MIXER, 633203db220SDimitris Papastamos WM8991_LOPGASPK_BIT, 1, 0), 634203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX Left DAC Switch", WM8991_SPEAKER_MIXER, 635203db220SDimitris Papastamos WM8991_LDSPK_BIT, 1, 0), 636203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX Right DAC Switch", WM8991_SPEAKER_MIXER, 637203db220SDimitris Papastamos WM8991_RDSPK_BIT, 1, 0), 638203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX Right Mixer PGA Switch", WM8991_SPEAKER_MIXER, 639203db220SDimitris Papastamos WM8991_ROPGASPK_BIT, 1, 0), 640203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX RADC Bypass Switch", WM8991_SPEAKER_MIXER, 641203db220SDimitris Papastamos WM8991_RL12ROP_BIT, 1, 0), 642203db220SDimitris Papastamos SOC_DAPM_SINGLE("SPKMIX RIN2 Bypass Switch", WM8991_SPEAKER_MIXER, 643203db220SDimitris Papastamos WM8991_RI2SPK_BIT, 1, 0), 644203db220SDimitris Papastamos }; 645203db220SDimitris Papastamos 646203db220SDimitris Papastamos static const struct snd_soc_dapm_widget wm8991_dapm_widgets[] = { 647203db220SDimitris Papastamos /* Input Side */ 648203db220SDimitris Papastamos /* Input Lines */ 649203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("LIN1"), 650203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("LIN2"), 651203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("LIN3"), 652203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("LIN4RXN"), 653203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("RIN3"), 654203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("RIN4RXP"), 655203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("RIN1"), 656203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("RIN2"), 657203db220SDimitris Papastamos SND_SOC_DAPM_INPUT("Internal ADC Source"), 658203db220SDimitris Papastamos 659203db220SDimitris Papastamos /* DACs */ 660203db220SDimitris Papastamos SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8991_POWER_MANAGEMENT_2, 661203db220SDimitris Papastamos WM8991_ADCL_ENA_BIT, 0), 662203db220SDimitris Papastamos SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8991_POWER_MANAGEMENT_2, 663203db220SDimitris Papastamos WM8991_ADCR_ENA_BIT, 0), 664203db220SDimitris Papastamos 665203db220SDimitris Papastamos /* Input PGAs */ 666203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("LIN12 PGA", WM8991_POWER_MANAGEMENT_2, WM8991_LIN12_ENA_BIT, 667203db220SDimitris Papastamos 0, &wm8991_dapm_lin12_pga_controls[0], 668203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_lin12_pga_controls)), 669203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("LIN34 PGA", WM8991_POWER_MANAGEMENT_2, WM8991_LIN34_ENA_BIT, 670203db220SDimitris Papastamos 0, &wm8991_dapm_lin34_pga_controls[0], 671203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_lin34_pga_controls)), 672203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("RIN12 PGA", WM8991_POWER_MANAGEMENT_2, WM8991_RIN12_ENA_BIT, 673203db220SDimitris Papastamos 0, &wm8991_dapm_rin12_pga_controls[0], 674203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_rin12_pga_controls)), 675203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("RIN34 PGA", WM8991_POWER_MANAGEMENT_2, WM8991_RIN34_ENA_BIT, 676203db220SDimitris Papastamos 0, &wm8991_dapm_rin34_pga_controls[0], 677203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_rin34_pga_controls)), 678203db220SDimitris Papastamos 679203db220SDimitris Papastamos /* INMIXL */ 680203db220SDimitris Papastamos SND_SOC_DAPM_MIXER_E("INMIXL", WM8991_INTDRIVBITS, WM8991_INMIXL_PWR_BIT, 0, 681203db220SDimitris Papastamos &wm8991_dapm_inmixl_controls[0], 682203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_inmixl_controls), 683203db220SDimitris Papastamos inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), 684203db220SDimitris Papastamos 685203db220SDimitris Papastamos /* AINLMUX */ 686203db220SDimitris Papastamos SND_SOC_DAPM_MUX_E("AINLMUX", WM8991_INTDRIVBITS, WM8991_AINLMUX_PWR_BIT, 0, 687203db220SDimitris Papastamos &wm8991_dapm_ainlmux_controls, inmixer_event, 688203db220SDimitris Papastamos SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), 689203db220SDimitris Papastamos 690203db220SDimitris Papastamos /* INMIXR */ 691203db220SDimitris Papastamos SND_SOC_DAPM_MIXER_E("INMIXR", WM8991_INTDRIVBITS, WM8991_INMIXR_PWR_BIT, 0, 692203db220SDimitris Papastamos &wm8991_dapm_inmixr_controls[0], 693203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_inmixr_controls), 694203db220SDimitris Papastamos inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), 695203db220SDimitris Papastamos 696203db220SDimitris Papastamos /* AINRMUX */ 697203db220SDimitris Papastamos SND_SOC_DAPM_MUX_E("AINRMUX", WM8991_INTDRIVBITS, WM8991_AINRMUX_PWR_BIT, 0, 698203db220SDimitris Papastamos &wm8991_dapm_ainrmux_controls, inmixer_event, 699203db220SDimitris Papastamos SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), 700203db220SDimitris Papastamos 701203db220SDimitris Papastamos /* Output Side */ 702203db220SDimitris Papastamos /* DACs */ 703203db220SDimitris Papastamos SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8991_POWER_MANAGEMENT_3, 704203db220SDimitris Papastamos WM8991_DACL_ENA_BIT, 0), 705203db220SDimitris Papastamos SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8991_POWER_MANAGEMENT_3, 706203db220SDimitris Papastamos WM8991_DACR_ENA_BIT, 0), 707203db220SDimitris Papastamos 708203db220SDimitris Papastamos /* LOMIX */ 709203db220SDimitris Papastamos SND_SOC_DAPM_MIXER_E("LOMIX", WM8991_POWER_MANAGEMENT_3, WM8991_LOMIX_ENA_BIT, 710203db220SDimitris Papastamos 0, &wm8991_dapm_lomix_controls[0], 711203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_lomix_controls), 712203db220SDimitris Papastamos outmixer_event, SND_SOC_DAPM_PRE_REG), 713203db220SDimitris Papastamos 714203db220SDimitris Papastamos /* LONMIX */ 715203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("LONMIX", WM8991_POWER_MANAGEMENT_3, WM8991_LON_ENA_BIT, 0, 716203db220SDimitris Papastamos &wm8991_dapm_lonmix_controls[0], 717203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_lonmix_controls)), 718203db220SDimitris Papastamos 719203db220SDimitris Papastamos /* LOPMIX */ 720203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("LOPMIX", WM8991_POWER_MANAGEMENT_3, WM8991_LOP_ENA_BIT, 0, 721203db220SDimitris Papastamos &wm8991_dapm_lopmix_controls[0], 722203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_lopmix_controls)), 723203db220SDimitris Papastamos 724203db220SDimitris Papastamos /* OUT3MIX */ 725203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("OUT3MIX", WM8991_POWER_MANAGEMENT_1, WM8991_OUT3_ENA_BIT, 0, 726203db220SDimitris Papastamos &wm8991_dapm_out3mix_controls[0], 727203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_out3mix_controls)), 728203db220SDimitris Papastamos 729203db220SDimitris Papastamos /* SPKMIX */ 730203db220SDimitris Papastamos SND_SOC_DAPM_MIXER_E("SPKMIX", WM8991_POWER_MANAGEMENT_1, WM8991_SPK_ENA_BIT, 0, 731203db220SDimitris Papastamos &wm8991_dapm_spkmix_controls[0], 732203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_spkmix_controls), outmixer_event, 733203db220SDimitris Papastamos SND_SOC_DAPM_PRE_REG), 734203db220SDimitris Papastamos 735203db220SDimitris Papastamos /* OUT4MIX */ 736203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("OUT4MIX", WM8991_POWER_MANAGEMENT_1, WM8991_OUT4_ENA_BIT, 0, 737203db220SDimitris Papastamos &wm8991_dapm_out4mix_controls[0], 738203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_out4mix_controls)), 739203db220SDimitris Papastamos 740203db220SDimitris Papastamos /* ROPMIX */ 741203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("ROPMIX", WM8991_POWER_MANAGEMENT_3, WM8991_ROP_ENA_BIT, 0, 742203db220SDimitris Papastamos &wm8991_dapm_ropmix_controls[0], 743203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_ropmix_controls)), 744203db220SDimitris Papastamos 745203db220SDimitris Papastamos /* RONMIX */ 746203db220SDimitris Papastamos SND_SOC_DAPM_MIXER("RONMIX", WM8991_POWER_MANAGEMENT_3, WM8991_RON_ENA_BIT, 0, 747203db220SDimitris Papastamos &wm8991_dapm_ronmix_controls[0], 748203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_ronmix_controls)), 749203db220SDimitris Papastamos 750203db220SDimitris Papastamos /* ROMIX */ 751203db220SDimitris Papastamos SND_SOC_DAPM_MIXER_E("ROMIX", WM8991_POWER_MANAGEMENT_3, WM8991_ROMIX_ENA_BIT, 752203db220SDimitris Papastamos 0, &wm8991_dapm_romix_controls[0], 753203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_romix_controls), 754203db220SDimitris Papastamos outmixer_event, SND_SOC_DAPM_PRE_REG), 755203db220SDimitris Papastamos 756203db220SDimitris Papastamos /* LOUT PGA */ 757203db220SDimitris Papastamos SND_SOC_DAPM_PGA("LOUT PGA", WM8991_POWER_MANAGEMENT_1, WM8991_LOUT_ENA_BIT, 0, 758203db220SDimitris Papastamos NULL, 0), 759203db220SDimitris Papastamos 760203db220SDimitris Papastamos /* ROUT PGA */ 761203db220SDimitris Papastamos SND_SOC_DAPM_PGA("ROUT PGA", WM8991_POWER_MANAGEMENT_1, WM8991_ROUT_ENA_BIT, 0, 762203db220SDimitris Papastamos NULL, 0), 763203db220SDimitris Papastamos 764203db220SDimitris Papastamos /* LOPGA */ 765203db220SDimitris Papastamos SND_SOC_DAPM_PGA("LOPGA", WM8991_POWER_MANAGEMENT_3, WM8991_LOPGA_ENA_BIT, 0, 766203db220SDimitris Papastamos NULL, 0), 767203db220SDimitris Papastamos 768203db220SDimitris Papastamos /* ROPGA */ 769203db220SDimitris Papastamos SND_SOC_DAPM_PGA("ROPGA", WM8991_POWER_MANAGEMENT_3, WM8991_ROPGA_ENA_BIT, 0, 770203db220SDimitris Papastamos NULL, 0), 771203db220SDimitris Papastamos 772203db220SDimitris Papastamos /* MICBIAS */ 773*b6406a80SMark Brown SND_SOC_DAPM_SUPPLY("MICBIAS", WM8991_POWER_MANAGEMENT_1, 774*b6406a80SMark Brown WM8991_MICBIAS_ENA_BIT, 0, NULL, 0), 775203db220SDimitris Papastamos 776203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("LON"), 777203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("LOP"), 778203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("OUT3"), 779203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("LOUT"), 780203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("SPKN"), 781203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("SPKP"), 782203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("ROUT"), 783203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("OUT4"), 784203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("ROP"), 785203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("RON"), 786203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("OUT"), 787203db220SDimitris Papastamos 788203db220SDimitris Papastamos SND_SOC_DAPM_OUTPUT("Internal DAC Sink"), 789203db220SDimitris Papastamos }; 790203db220SDimitris Papastamos 791203db220SDimitris Papastamos static const struct snd_soc_dapm_route audio_map[] = { 792203db220SDimitris Papastamos /* Make DACs turn on when playing even if not mixed into any outputs */ 793203db220SDimitris Papastamos {"Internal DAC Sink", NULL, "Left DAC"}, 794203db220SDimitris Papastamos {"Internal DAC Sink", NULL, "Right DAC"}, 795203db220SDimitris Papastamos 796203db220SDimitris Papastamos /* Make ADCs turn on when recording even if not mixed from any inputs */ 797203db220SDimitris Papastamos {"Left ADC", NULL, "Internal ADC Source"}, 798203db220SDimitris Papastamos {"Right ADC", NULL, "Internal ADC Source"}, 799203db220SDimitris Papastamos 800203db220SDimitris Papastamos /* Input Side */ 801203db220SDimitris Papastamos /* LIN12 PGA */ 802203db220SDimitris Papastamos {"LIN12 PGA", "LIN1 Switch", "LIN1"}, 803203db220SDimitris Papastamos {"LIN12 PGA", "LIN2 Switch", "LIN2"}, 804203db220SDimitris Papastamos /* LIN34 PGA */ 805203db220SDimitris Papastamos {"LIN34 PGA", "LIN3 Switch", "LIN3"}, 806203db220SDimitris Papastamos {"LIN34 PGA", "LIN4 Switch", "LIN4RXN"}, 807203db220SDimitris Papastamos /* INMIXL */ 808203db220SDimitris Papastamos {"INMIXL", "Record Left Volume", "LOMIX"}, 809203db220SDimitris Papastamos {"INMIXL", "LIN2 Volume", "LIN2"}, 810203db220SDimitris Papastamos {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"}, 811203db220SDimitris Papastamos {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"}, 812203db220SDimitris Papastamos /* AINLMUX */ 813203db220SDimitris Papastamos {"AINLMUX", "INMIXL Mix", "INMIXL"}, 814203db220SDimitris Papastamos {"AINLMUX", "DIFFINL Mix", "LIN12 PGA"}, 815203db220SDimitris Papastamos {"AINLMUX", "DIFFINL Mix", "LIN34 PGA"}, 816203db220SDimitris Papastamos {"AINLMUX", "RXVOICE Mix", "LIN4RXN"}, 817203db220SDimitris Papastamos {"AINLMUX", "RXVOICE Mix", "RIN4RXP"}, 818203db220SDimitris Papastamos /* ADC */ 819203db220SDimitris Papastamos {"Left ADC", NULL, "AINLMUX"}, 820203db220SDimitris Papastamos 821203db220SDimitris Papastamos /* RIN12 PGA */ 822203db220SDimitris Papastamos {"RIN12 PGA", "RIN1 Switch", "RIN1"}, 823203db220SDimitris Papastamos {"RIN12 PGA", "RIN2 Switch", "RIN2"}, 824203db220SDimitris Papastamos /* RIN34 PGA */ 825203db220SDimitris Papastamos {"RIN34 PGA", "RIN3 Switch", "RIN3"}, 826203db220SDimitris Papastamos {"RIN34 PGA", "RIN4 Switch", "RIN4RXP"}, 827203db220SDimitris Papastamos /* INMIXL */ 828203db220SDimitris Papastamos {"INMIXR", "Record Right Volume", "ROMIX"}, 829203db220SDimitris Papastamos {"INMIXR", "RIN2 Volume", "RIN2"}, 830203db220SDimitris Papastamos {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"}, 831203db220SDimitris Papastamos {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"}, 832203db220SDimitris Papastamos /* AINRMUX */ 833203db220SDimitris Papastamos {"AINRMUX", "INMIXR Mix", "INMIXR"}, 834203db220SDimitris Papastamos {"AINRMUX", "DIFFINR Mix", "RIN12 PGA"}, 835203db220SDimitris Papastamos {"AINRMUX", "DIFFINR Mix", "RIN34 PGA"}, 836203db220SDimitris Papastamos {"AINRMUX", "RXVOICE Mix", "LIN4RXN"}, 837203db220SDimitris Papastamos {"AINRMUX", "RXVOICE Mix", "RIN4RXP"}, 838203db220SDimitris Papastamos /* ADC */ 839203db220SDimitris Papastamos {"Right ADC", NULL, "AINRMUX"}, 840203db220SDimitris Papastamos 841203db220SDimitris Papastamos /* LOMIX */ 842203db220SDimitris Papastamos {"LOMIX", "LOMIX RIN3 Bypass Switch", "RIN3"}, 843203db220SDimitris Papastamos {"LOMIX", "LOMIX LIN3 Bypass Switch", "LIN3"}, 844203db220SDimitris Papastamos {"LOMIX", "LOMIX LIN12 PGA Bypass Switch", "LIN12 PGA"}, 845203db220SDimitris Papastamos {"LOMIX", "LOMIX RIN12 PGA Bypass Switch", "RIN12 PGA"}, 846203db220SDimitris Papastamos {"LOMIX", "LOMIX Right ADC Bypass Switch", "AINRMUX"}, 847203db220SDimitris Papastamos {"LOMIX", "LOMIX Left ADC Bypass Switch", "AINLMUX"}, 848203db220SDimitris Papastamos {"LOMIX", "LOMIX Left DAC Switch", "Left DAC"}, 849203db220SDimitris Papastamos 850203db220SDimitris Papastamos /* ROMIX */ 851203db220SDimitris Papastamos {"ROMIX", "ROMIX RIN3 Bypass Switch", "RIN3"}, 852203db220SDimitris Papastamos {"ROMIX", "ROMIX LIN3 Bypass Switch", "LIN3"}, 853203db220SDimitris Papastamos {"ROMIX", "ROMIX LIN12 PGA Bypass Switch", "LIN12 PGA"}, 854203db220SDimitris Papastamos {"ROMIX", "ROMIX RIN12 PGA Bypass Switch", "RIN12 PGA"}, 855203db220SDimitris Papastamos {"ROMIX", "ROMIX Right ADC Bypass Switch", "AINRMUX"}, 856203db220SDimitris Papastamos {"ROMIX", "ROMIX Left ADC Bypass Switch", "AINLMUX"}, 857203db220SDimitris Papastamos {"ROMIX", "ROMIX Right DAC Switch", "Right DAC"}, 858203db220SDimitris Papastamos 859203db220SDimitris Papastamos /* SPKMIX */ 860203db220SDimitris Papastamos {"SPKMIX", "SPKMIX LIN2 Bypass Switch", "LIN2"}, 861203db220SDimitris Papastamos {"SPKMIX", "SPKMIX RIN2 Bypass Switch", "RIN2"}, 862203db220SDimitris Papastamos {"SPKMIX", "SPKMIX LADC Bypass Switch", "AINLMUX"}, 863203db220SDimitris Papastamos {"SPKMIX", "SPKMIX RADC Bypass Switch", "AINRMUX"}, 864203db220SDimitris Papastamos {"SPKMIX", "SPKMIX Left Mixer PGA Switch", "LOPGA"}, 865203db220SDimitris Papastamos {"SPKMIX", "SPKMIX Right Mixer PGA Switch", "ROPGA"}, 866203db220SDimitris Papastamos {"SPKMIX", "SPKMIX Right DAC Switch", "Right DAC"}, 867203db220SDimitris Papastamos {"SPKMIX", "SPKMIX Left DAC Switch", "Right DAC"}, 868203db220SDimitris Papastamos 869203db220SDimitris Papastamos /* LONMIX */ 870203db220SDimitris Papastamos {"LONMIX", "LONMIX Left Mixer PGA Switch", "LOPGA"}, 871203db220SDimitris Papastamos {"LONMIX", "LONMIX Right Mixer PGA Switch", "ROPGA"}, 872203db220SDimitris Papastamos {"LONMIX", "LONMIX Inverted LOP Switch", "LOPMIX"}, 873203db220SDimitris Papastamos 874203db220SDimitris Papastamos /* LOPMIX */ 875203db220SDimitris Papastamos {"LOPMIX", "LOPMIX Right Mic Bypass Switch", "RIN12 PGA"}, 876203db220SDimitris Papastamos {"LOPMIX", "LOPMIX Left Mic Bypass Switch", "LIN12 PGA"}, 877203db220SDimitris Papastamos {"LOPMIX", "LOPMIX Left Mixer PGA Switch", "LOPGA"}, 878203db220SDimitris Papastamos 879203db220SDimitris Papastamos /* OUT3MIX */ 880203db220SDimitris Papastamos {"OUT3MIX", "OUT3MIX LIN4RXN Bypass Switch", "LIN4RXN"}, 881203db220SDimitris Papastamos {"OUT3MIX", "OUT3MIX Left Out PGA Switch", "LOPGA"}, 882203db220SDimitris Papastamos 883203db220SDimitris Papastamos /* OUT4MIX */ 884203db220SDimitris Papastamos {"OUT4MIX", "OUT4MIX Right Out PGA Switch", "ROPGA"}, 885203db220SDimitris Papastamos {"OUT4MIX", "OUT4MIX RIN4RXP Bypass Switch", "RIN4RXP"}, 886203db220SDimitris Papastamos 887203db220SDimitris Papastamos /* RONMIX */ 888203db220SDimitris Papastamos {"RONMIX", "RONMIX Right Mixer PGA Switch", "ROPGA"}, 889203db220SDimitris Papastamos {"RONMIX", "RONMIX Left Mixer PGA Switch", "LOPGA"}, 890203db220SDimitris Papastamos {"RONMIX", "RONMIX Inverted ROP Switch", "ROPMIX"}, 891203db220SDimitris Papastamos 892203db220SDimitris Papastamos /* ROPMIX */ 893203db220SDimitris Papastamos {"ROPMIX", "ROPMIX Left Mic Bypass Switch", "LIN12 PGA"}, 894203db220SDimitris Papastamos {"ROPMIX", "ROPMIX Right Mic Bypass Switch", "RIN12 PGA"}, 895203db220SDimitris Papastamos {"ROPMIX", "ROPMIX Right Mixer PGA Switch", "ROPGA"}, 896203db220SDimitris Papastamos 897203db220SDimitris Papastamos /* Out Mixer PGAs */ 898203db220SDimitris Papastamos {"LOPGA", NULL, "LOMIX"}, 899203db220SDimitris Papastamos {"ROPGA", NULL, "ROMIX"}, 900203db220SDimitris Papastamos 901203db220SDimitris Papastamos {"LOUT PGA", NULL, "LOMIX"}, 902203db220SDimitris Papastamos {"ROUT PGA", NULL, "ROMIX"}, 903203db220SDimitris Papastamos 904203db220SDimitris Papastamos /* Output Pins */ 905203db220SDimitris Papastamos {"LON", NULL, "LONMIX"}, 906203db220SDimitris Papastamos {"LOP", NULL, "LOPMIX"}, 907203db220SDimitris Papastamos {"OUT", NULL, "OUT3MIX"}, 908203db220SDimitris Papastamos {"LOUT", NULL, "LOUT PGA"}, 909203db220SDimitris Papastamos {"SPKN", NULL, "SPKMIX"}, 910203db220SDimitris Papastamos {"ROUT", NULL, "ROUT PGA"}, 911203db220SDimitris Papastamos {"OUT4", NULL, "OUT4MIX"}, 912203db220SDimitris Papastamos {"ROP", NULL, "ROPMIX"}, 913203db220SDimitris Papastamos {"RON", NULL, "RONMIX"}, 914203db220SDimitris Papastamos }; 915203db220SDimitris Papastamos 916203db220SDimitris Papastamos /* PLL divisors */ 917203db220SDimitris Papastamos struct _pll_div { 918203db220SDimitris Papastamos u32 div2; 919203db220SDimitris Papastamos u32 n; 920203db220SDimitris Papastamos u32 k; 921203db220SDimitris Papastamos }; 922203db220SDimitris Papastamos 923203db220SDimitris Papastamos /* The size in bits of the pll divide multiplied by 10 924203db220SDimitris Papastamos * to allow rounding later */ 925203db220SDimitris Papastamos #define FIXED_PLL_SIZE ((1 << 16) * 10) 926203db220SDimitris Papastamos 927203db220SDimitris Papastamos static void pll_factors(struct _pll_div *pll_div, unsigned int target, 928203db220SDimitris Papastamos unsigned int source) 929203db220SDimitris Papastamos { 930203db220SDimitris Papastamos u64 Kpart; 931203db220SDimitris Papastamos unsigned int K, Ndiv, Nmod; 932203db220SDimitris Papastamos 933203db220SDimitris Papastamos 934203db220SDimitris Papastamos Ndiv = target / source; 935203db220SDimitris Papastamos if (Ndiv < 6) { 936203db220SDimitris Papastamos source >>= 1; 937203db220SDimitris Papastamos pll_div->div2 = 1; 938203db220SDimitris Papastamos Ndiv = target / source; 939203db220SDimitris Papastamos } else 940203db220SDimitris Papastamos pll_div->div2 = 0; 941203db220SDimitris Papastamos 942203db220SDimitris Papastamos if ((Ndiv < 6) || (Ndiv > 12)) 943203db220SDimitris Papastamos printk(KERN_WARNING 944203db220SDimitris Papastamos "WM8991 N value outwith recommended range! N = %d\n", Ndiv); 945203db220SDimitris Papastamos 946203db220SDimitris Papastamos pll_div->n = Ndiv; 947203db220SDimitris Papastamos Nmod = target % source; 948203db220SDimitris Papastamos Kpart = FIXED_PLL_SIZE * (long long)Nmod; 949203db220SDimitris Papastamos 950203db220SDimitris Papastamos do_div(Kpart, source); 951203db220SDimitris Papastamos 952203db220SDimitris Papastamos K = Kpart & 0xFFFFFFFF; 953203db220SDimitris Papastamos 954203db220SDimitris Papastamos /* Check if we need to round */ 955203db220SDimitris Papastamos if ((K % 10) >= 5) 956203db220SDimitris Papastamos K += 5; 957203db220SDimitris Papastamos 958203db220SDimitris Papastamos /* Move down to proper range now rounding is done */ 959203db220SDimitris Papastamos K /= 10; 960203db220SDimitris Papastamos 961203db220SDimitris Papastamos pll_div->k = K; 962203db220SDimitris Papastamos } 963203db220SDimitris Papastamos 964203db220SDimitris Papastamos static int wm8991_set_dai_pll(struct snd_soc_dai *codec_dai, 965203db220SDimitris Papastamos int pll_id, int src, unsigned int freq_in, unsigned int freq_out) 966203db220SDimitris Papastamos { 967203db220SDimitris Papastamos u16 reg; 968203db220SDimitris Papastamos struct snd_soc_codec *codec = codec_dai->codec; 969203db220SDimitris Papastamos struct _pll_div pll_div; 970203db220SDimitris Papastamos 971203db220SDimitris Papastamos if (freq_in && freq_out) { 972203db220SDimitris Papastamos pll_factors(&pll_div, freq_out * 4, freq_in); 973203db220SDimitris Papastamos 974203db220SDimitris Papastamos /* Turn on PLL */ 975203db220SDimitris Papastamos reg = snd_soc_read(codec, WM8991_POWER_MANAGEMENT_2); 976203db220SDimitris Papastamos reg |= WM8991_PLL_ENA; 977203db220SDimitris Papastamos snd_soc_write(codec, WM8991_POWER_MANAGEMENT_2, reg); 978203db220SDimitris Papastamos 979203db220SDimitris Papastamos /* sysclk comes from PLL */ 980203db220SDimitris Papastamos reg = snd_soc_read(codec, WM8991_CLOCKING_2); 981203db220SDimitris Papastamos snd_soc_write(codec, WM8991_CLOCKING_2, reg | WM8991_SYSCLK_SRC); 982203db220SDimitris Papastamos 98325985edcSLucas De Marchi /* set up N , fractional mode and pre-divisor if necessary */ 984203db220SDimitris Papastamos snd_soc_write(codec, WM8991_PLL1, pll_div.n | WM8991_SDM | 985203db220SDimitris Papastamos (pll_div.div2 ? WM8991_PRESCALE : 0)); 986203db220SDimitris Papastamos snd_soc_write(codec, WM8991_PLL2, (u8)(pll_div.k>>8)); 987203db220SDimitris Papastamos snd_soc_write(codec, WM8991_PLL3, (u8)(pll_div.k & 0xFF)); 988203db220SDimitris Papastamos } else { 989203db220SDimitris Papastamos /* Turn on PLL */ 990203db220SDimitris Papastamos reg = snd_soc_read(codec, WM8991_POWER_MANAGEMENT_2); 991203db220SDimitris Papastamos reg &= ~WM8991_PLL_ENA; 992203db220SDimitris Papastamos snd_soc_write(codec, WM8991_POWER_MANAGEMENT_2, reg); 993203db220SDimitris Papastamos } 994203db220SDimitris Papastamos return 0; 995203db220SDimitris Papastamos } 996203db220SDimitris Papastamos 997203db220SDimitris Papastamos /* 998203db220SDimitris Papastamos * Set's ADC and Voice DAC format. 999203db220SDimitris Papastamos */ 1000203db220SDimitris Papastamos static int wm8991_set_dai_fmt(struct snd_soc_dai *codec_dai, 1001203db220SDimitris Papastamos unsigned int fmt) 1002203db220SDimitris Papastamos { 1003203db220SDimitris Papastamos struct snd_soc_codec *codec = codec_dai->codec; 1004203db220SDimitris Papastamos u16 audio1, audio3; 1005203db220SDimitris Papastamos 1006203db220SDimitris Papastamos audio1 = snd_soc_read(codec, WM8991_AUDIO_INTERFACE_1); 1007203db220SDimitris Papastamos audio3 = snd_soc_read(codec, WM8991_AUDIO_INTERFACE_3); 1008203db220SDimitris Papastamos 1009203db220SDimitris Papastamos /* set master/slave audio interface */ 1010203db220SDimitris Papastamos switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1011203db220SDimitris Papastamos case SND_SOC_DAIFMT_CBS_CFS: 1012203db220SDimitris Papastamos audio3 &= ~WM8991_AIF_MSTR1; 1013203db220SDimitris Papastamos break; 1014203db220SDimitris Papastamos case SND_SOC_DAIFMT_CBM_CFM: 1015203db220SDimitris Papastamos audio3 |= WM8991_AIF_MSTR1; 1016203db220SDimitris Papastamos break; 1017203db220SDimitris Papastamos default: 1018203db220SDimitris Papastamos return -EINVAL; 1019203db220SDimitris Papastamos } 1020203db220SDimitris Papastamos 1021203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_FMT_MASK; 1022203db220SDimitris Papastamos 1023203db220SDimitris Papastamos /* interface format */ 1024203db220SDimitris Papastamos switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 1025203db220SDimitris Papastamos case SND_SOC_DAIFMT_I2S: 1026203db220SDimitris Papastamos audio1 |= WM8991_AIF_TMF_I2S; 1027203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_LRCLK_INV; 1028203db220SDimitris Papastamos break; 1029203db220SDimitris Papastamos case SND_SOC_DAIFMT_RIGHT_J: 1030203db220SDimitris Papastamos audio1 |= WM8991_AIF_TMF_RIGHTJ; 1031203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_LRCLK_INV; 1032203db220SDimitris Papastamos break; 1033203db220SDimitris Papastamos case SND_SOC_DAIFMT_LEFT_J: 1034203db220SDimitris Papastamos audio1 |= WM8991_AIF_TMF_LEFTJ; 1035203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_LRCLK_INV; 1036203db220SDimitris Papastamos break; 1037203db220SDimitris Papastamos case SND_SOC_DAIFMT_DSP_A: 1038203db220SDimitris Papastamos audio1 |= WM8991_AIF_TMF_DSP; 1039203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_LRCLK_INV; 1040203db220SDimitris Papastamos break; 1041203db220SDimitris Papastamos case SND_SOC_DAIFMT_DSP_B: 1042203db220SDimitris Papastamos audio1 |= WM8991_AIF_TMF_DSP | WM8991_AIF_LRCLK_INV; 1043203db220SDimitris Papastamos break; 1044203db220SDimitris Papastamos default: 1045203db220SDimitris Papastamos return -EINVAL; 1046203db220SDimitris Papastamos } 1047203db220SDimitris Papastamos 1048203db220SDimitris Papastamos snd_soc_write(codec, WM8991_AUDIO_INTERFACE_1, audio1); 1049203db220SDimitris Papastamos snd_soc_write(codec, WM8991_AUDIO_INTERFACE_3, audio3); 1050203db220SDimitris Papastamos return 0; 1051203db220SDimitris Papastamos } 1052203db220SDimitris Papastamos 1053203db220SDimitris Papastamos static int wm8991_set_dai_clkdiv(struct snd_soc_dai *codec_dai, 1054203db220SDimitris Papastamos int div_id, int div) 1055203db220SDimitris Papastamos { 1056203db220SDimitris Papastamos struct snd_soc_codec *codec = codec_dai->codec; 1057203db220SDimitris Papastamos u16 reg; 1058203db220SDimitris Papastamos 1059203db220SDimitris Papastamos switch (div_id) { 1060203db220SDimitris Papastamos case WM8991_MCLK_DIV: 1061203db220SDimitris Papastamos reg = snd_soc_read(codec, WM8991_CLOCKING_2) & 1062203db220SDimitris Papastamos ~WM8991_MCLK_DIV_MASK; 1063203db220SDimitris Papastamos snd_soc_write(codec, WM8991_CLOCKING_2, reg | div); 1064203db220SDimitris Papastamos break; 1065203db220SDimitris Papastamos case WM8991_DACCLK_DIV: 1066203db220SDimitris Papastamos reg = snd_soc_read(codec, WM8991_CLOCKING_2) & 1067203db220SDimitris Papastamos ~WM8991_DAC_CLKDIV_MASK; 1068203db220SDimitris Papastamos snd_soc_write(codec, WM8991_CLOCKING_2, reg | div); 1069203db220SDimitris Papastamos break; 1070203db220SDimitris Papastamos case WM8991_ADCCLK_DIV: 1071203db220SDimitris Papastamos reg = snd_soc_read(codec, WM8991_CLOCKING_2) & 1072203db220SDimitris Papastamos ~WM8991_ADC_CLKDIV_MASK; 1073203db220SDimitris Papastamos snd_soc_write(codec, WM8991_CLOCKING_2, reg | div); 1074203db220SDimitris Papastamos break; 1075203db220SDimitris Papastamos case WM8991_BCLK_DIV: 1076203db220SDimitris Papastamos reg = snd_soc_read(codec, WM8991_CLOCKING_1) & 1077203db220SDimitris Papastamos ~WM8991_BCLK_DIV_MASK; 1078203db220SDimitris Papastamos snd_soc_write(codec, WM8991_CLOCKING_1, reg | div); 1079203db220SDimitris Papastamos break; 1080203db220SDimitris Papastamos default: 1081203db220SDimitris Papastamos return -EINVAL; 1082203db220SDimitris Papastamos } 1083203db220SDimitris Papastamos 1084203db220SDimitris Papastamos return 0; 1085203db220SDimitris Papastamos } 1086203db220SDimitris Papastamos 1087203db220SDimitris Papastamos /* 1088203db220SDimitris Papastamos * Set PCM DAI bit size and sample rate. 1089203db220SDimitris Papastamos */ 1090203db220SDimitris Papastamos static int wm8991_hw_params(struct snd_pcm_substream *substream, 1091203db220SDimitris Papastamos struct snd_pcm_hw_params *params, 1092203db220SDimitris Papastamos struct snd_soc_dai *dai) 1093203db220SDimitris Papastamos { 1094203db220SDimitris Papastamos struct snd_soc_codec *codec = dai->codec; 1095203db220SDimitris Papastamos u16 audio1 = snd_soc_read(codec, WM8991_AUDIO_INTERFACE_1); 1096203db220SDimitris Papastamos 1097203db220SDimitris Papastamos audio1 &= ~WM8991_AIF_WL_MASK; 1098203db220SDimitris Papastamos /* bit size */ 1099203db220SDimitris Papastamos switch (params_format(params)) { 1100203db220SDimitris Papastamos case SNDRV_PCM_FORMAT_S16_LE: 1101203db220SDimitris Papastamos break; 1102203db220SDimitris Papastamos case SNDRV_PCM_FORMAT_S20_3LE: 1103203db220SDimitris Papastamos audio1 |= WM8991_AIF_WL_20BITS; 1104203db220SDimitris Papastamos break; 1105203db220SDimitris Papastamos case SNDRV_PCM_FORMAT_S24_LE: 1106203db220SDimitris Papastamos audio1 |= WM8991_AIF_WL_24BITS; 1107203db220SDimitris Papastamos break; 1108203db220SDimitris Papastamos case SNDRV_PCM_FORMAT_S32_LE: 1109203db220SDimitris Papastamos audio1 |= WM8991_AIF_WL_32BITS; 1110203db220SDimitris Papastamos break; 1111203db220SDimitris Papastamos } 1112203db220SDimitris Papastamos 1113203db220SDimitris Papastamos snd_soc_write(codec, WM8991_AUDIO_INTERFACE_1, audio1); 1114203db220SDimitris Papastamos return 0; 1115203db220SDimitris Papastamos } 1116203db220SDimitris Papastamos 1117203db220SDimitris Papastamos static int wm8991_mute(struct snd_soc_dai *dai, int mute) 1118203db220SDimitris Papastamos { 1119203db220SDimitris Papastamos struct snd_soc_codec *codec = dai->codec; 1120203db220SDimitris Papastamos u16 val; 1121203db220SDimitris Papastamos 1122203db220SDimitris Papastamos val = snd_soc_read(codec, WM8991_DAC_CTRL) & ~WM8991_DAC_MUTE; 1123203db220SDimitris Papastamos if (mute) 1124203db220SDimitris Papastamos snd_soc_write(codec, WM8991_DAC_CTRL, val | WM8991_DAC_MUTE); 1125203db220SDimitris Papastamos else 1126203db220SDimitris Papastamos snd_soc_write(codec, WM8991_DAC_CTRL, val); 1127203db220SDimitris Papastamos return 0; 1128203db220SDimitris Papastamos } 1129203db220SDimitris Papastamos 1130203db220SDimitris Papastamos static int wm8991_set_bias_level(struct snd_soc_codec *codec, 1131203db220SDimitris Papastamos enum snd_soc_bias_level level) 1132203db220SDimitris Papastamos { 1133203db220SDimitris Papastamos u16 val; 1134203db220SDimitris Papastamos 1135203db220SDimitris Papastamos switch (level) { 1136203db220SDimitris Papastamos case SND_SOC_BIAS_ON: 1137203db220SDimitris Papastamos break; 1138203db220SDimitris Papastamos 1139203db220SDimitris Papastamos case SND_SOC_BIAS_PREPARE: 1140203db220SDimitris Papastamos /* VMID=2*50k */ 1141203db220SDimitris Papastamos val = snd_soc_read(codec, WM8991_POWER_MANAGEMENT_1) & 1142203db220SDimitris Papastamos ~WM8991_VMID_MODE_MASK; 1143203db220SDimitris Papastamos snd_soc_write(codec, WM8991_POWER_MANAGEMENT_1, val | 0x2); 1144203db220SDimitris Papastamos break; 1145203db220SDimitris Papastamos 1146203db220SDimitris Papastamos case SND_SOC_BIAS_STANDBY: 1147203db220SDimitris Papastamos if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 1148203db220SDimitris Papastamos snd_soc_cache_sync(codec); 1149203db220SDimitris Papastamos /* Enable all output discharge bits */ 1150203db220SDimitris Papastamos snd_soc_write(codec, WM8991_ANTIPOP1, WM8991_DIS_LLINE | 1151203db220SDimitris Papastamos WM8991_DIS_RLINE | WM8991_DIS_OUT3 | 1152203db220SDimitris Papastamos WM8991_DIS_OUT4 | WM8991_DIS_LOUT | 1153203db220SDimitris Papastamos WM8991_DIS_ROUT); 1154203db220SDimitris Papastamos 1155203db220SDimitris Papastamos /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */ 1156203db220SDimitris Papastamos snd_soc_write(codec, WM8991_ANTIPOP2, WM8991_SOFTST | 1157203db220SDimitris Papastamos WM8991_BUFDCOPEN | WM8991_POBCTRL | 1158203db220SDimitris Papastamos WM8991_VMIDTOG); 1159203db220SDimitris Papastamos 1160203db220SDimitris Papastamos /* Delay to allow output caps to discharge */ 1161203db220SDimitris Papastamos msleep(300); 1162203db220SDimitris Papastamos 1163203db220SDimitris Papastamos /* Disable VMIDTOG */ 1164203db220SDimitris Papastamos snd_soc_write(codec, WM8991_ANTIPOP2, WM8991_SOFTST | 1165203db220SDimitris Papastamos WM8991_BUFDCOPEN | WM8991_POBCTRL); 1166203db220SDimitris Papastamos 1167203db220SDimitris Papastamos /* disable all output discharge bits */ 1168203db220SDimitris Papastamos snd_soc_write(codec, WM8991_ANTIPOP1, 0); 1169203db220SDimitris Papastamos 1170203db220SDimitris Papastamos /* Enable outputs */ 1171203db220SDimitris Papastamos snd_soc_write(codec, WM8991_POWER_MANAGEMENT_1, 0x1b00); 1172203db220SDimitris Papastamos 1173203db220SDimitris Papastamos msleep(50); 1174203db220SDimitris Papastamos 1175203db220SDimitris Papastamos /* Enable VMID at 2x50k */ 1176203db220SDimitris Papastamos snd_soc_write(codec, WM8991_POWER_MANAGEMENT_1, 0x1f02); 1177203db220SDimitris Papastamos 1178203db220SDimitris Papastamos msleep(100); 1179203db220SDimitris Papastamos 1180203db220SDimitris Papastamos /* Enable VREF */ 1181203db220SDimitris Papastamos snd_soc_write(codec, WM8991_POWER_MANAGEMENT_1, 0x1f03); 1182203db220SDimitris Papastamos 1183203db220SDimitris Papastamos msleep(600); 1184203db220SDimitris Papastamos 1185203db220SDimitris Papastamos /* Enable BUFIOEN */ 1186203db220SDimitris Papastamos snd_soc_write(codec, WM8991_ANTIPOP2, WM8991_SOFTST | 1187203db220SDimitris Papastamos WM8991_BUFDCOPEN | WM8991_POBCTRL | 1188203db220SDimitris Papastamos WM8991_BUFIOEN); 1189203db220SDimitris Papastamos 1190203db220SDimitris Papastamos /* Disable outputs */ 1191203db220SDimitris Papastamos snd_soc_write(codec, WM8991_POWER_MANAGEMENT_1, 0x3); 1192203db220SDimitris Papastamos 1193203db220SDimitris Papastamos /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ 1194203db220SDimitris Papastamos snd_soc_write(codec, WM8991_ANTIPOP2, WM8991_BUFIOEN); 1195203db220SDimitris Papastamos } 1196203db220SDimitris Papastamos 1197203db220SDimitris Papastamos /* VMID=2*250k */ 1198203db220SDimitris Papastamos val = snd_soc_read(codec, WM8991_POWER_MANAGEMENT_1) & 1199203db220SDimitris Papastamos ~WM8991_VMID_MODE_MASK; 1200203db220SDimitris Papastamos snd_soc_write(codec, WM8991_POWER_MANAGEMENT_1, val | 0x4); 1201203db220SDimitris Papastamos break; 1202203db220SDimitris Papastamos 1203203db220SDimitris Papastamos case SND_SOC_BIAS_OFF: 1204203db220SDimitris Papastamos /* Enable POBCTRL and SOFT_ST */ 1205203db220SDimitris Papastamos snd_soc_write(codec, WM8991_ANTIPOP2, WM8991_SOFTST | 1206203db220SDimitris Papastamos WM8991_POBCTRL | WM8991_BUFIOEN); 1207203db220SDimitris Papastamos 1208203db220SDimitris Papastamos /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */ 1209203db220SDimitris Papastamos snd_soc_write(codec, WM8991_ANTIPOP2, WM8991_SOFTST | 1210203db220SDimitris Papastamos WM8991_BUFDCOPEN | WM8991_POBCTRL | 1211203db220SDimitris Papastamos WM8991_BUFIOEN); 1212203db220SDimitris Papastamos 1213203db220SDimitris Papastamos /* mute DAC */ 1214203db220SDimitris Papastamos val = snd_soc_read(codec, WM8991_DAC_CTRL); 1215203db220SDimitris Papastamos snd_soc_write(codec, WM8991_DAC_CTRL, val | WM8991_DAC_MUTE); 1216203db220SDimitris Papastamos 1217203db220SDimitris Papastamos /* Enable any disabled outputs */ 1218203db220SDimitris Papastamos snd_soc_write(codec, WM8991_POWER_MANAGEMENT_1, 0x1f03); 1219203db220SDimitris Papastamos 1220203db220SDimitris Papastamos /* Disable VMID */ 1221203db220SDimitris Papastamos snd_soc_write(codec, WM8991_POWER_MANAGEMENT_1, 0x1f01); 1222203db220SDimitris Papastamos 1223203db220SDimitris Papastamos msleep(300); 1224203db220SDimitris Papastamos 1225203db220SDimitris Papastamos /* Enable all output discharge bits */ 1226203db220SDimitris Papastamos snd_soc_write(codec, WM8991_ANTIPOP1, WM8991_DIS_LLINE | 1227203db220SDimitris Papastamos WM8991_DIS_RLINE | WM8991_DIS_OUT3 | 1228203db220SDimitris Papastamos WM8991_DIS_OUT4 | WM8991_DIS_LOUT | 1229203db220SDimitris Papastamos WM8991_DIS_ROUT); 1230203db220SDimitris Papastamos 1231203db220SDimitris Papastamos /* Disable VREF */ 1232203db220SDimitris Papastamos snd_soc_write(codec, WM8991_POWER_MANAGEMENT_1, 0x0); 1233203db220SDimitris Papastamos 1234203db220SDimitris Papastamos /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ 1235203db220SDimitris Papastamos snd_soc_write(codec, WM8991_ANTIPOP2, 0x0); 1236203db220SDimitris Papastamos codec->cache_sync = 1; 1237203db220SDimitris Papastamos break; 1238203db220SDimitris Papastamos } 1239203db220SDimitris Papastamos 1240203db220SDimitris Papastamos codec->dapm.bias_level = level; 1241203db220SDimitris Papastamos return 0; 1242203db220SDimitris Papastamos } 1243203db220SDimitris Papastamos 1244203db220SDimitris Papastamos static int wm8991_suspend(struct snd_soc_codec *codec, pm_message_t state) 1245203db220SDimitris Papastamos { 1246203db220SDimitris Papastamos wm8991_set_bias_level(codec, SND_SOC_BIAS_OFF); 1247203db220SDimitris Papastamos return 0; 1248203db220SDimitris Papastamos } 1249203db220SDimitris Papastamos 1250203db220SDimitris Papastamos static int wm8991_resume(struct snd_soc_codec *codec) 1251203db220SDimitris Papastamos { 1252203db220SDimitris Papastamos wm8991_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1253203db220SDimitris Papastamos return 0; 1254203db220SDimitris Papastamos } 1255203db220SDimitris Papastamos 1256203db220SDimitris Papastamos /* power down chip */ 1257203db220SDimitris Papastamos static int wm8991_remove(struct snd_soc_codec *codec) 1258203db220SDimitris Papastamos { 1259203db220SDimitris Papastamos wm8991_set_bias_level(codec, SND_SOC_BIAS_OFF); 1260203db220SDimitris Papastamos return 0; 1261203db220SDimitris Papastamos } 1262203db220SDimitris Papastamos 1263203db220SDimitris Papastamos static int wm8991_probe(struct snd_soc_codec *codec) 1264203db220SDimitris Papastamos { 1265203db220SDimitris Papastamos struct wm8991_priv *wm8991; 1266203db220SDimitris Papastamos int ret; 1267203db220SDimitris Papastamos 1268203db220SDimitris Papastamos wm8991 = snd_soc_codec_get_drvdata(codec); 1269203db220SDimitris Papastamos 1270203db220SDimitris Papastamos ret = snd_soc_codec_set_cache_io(codec, 8, 16, wm8991->control_type); 1271203db220SDimitris Papastamos if (ret < 0) { 1272203db220SDimitris Papastamos dev_err(codec->dev, "Failed to set cache i/o: %d\n", ret); 1273203db220SDimitris Papastamos return ret; 1274203db220SDimitris Papastamos } 1275203db220SDimitris Papastamos 1276203db220SDimitris Papastamos ret = wm8991_reset(codec); 1277203db220SDimitris Papastamos if (ret < 0) { 1278203db220SDimitris Papastamos dev_err(codec->dev, "Failed to issue reset\n"); 1279203db220SDimitris Papastamos return ret; 1280203db220SDimitris Papastamos } 1281203db220SDimitris Papastamos 1282203db220SDimitris Papastamos wm8991_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1283203db220SDimitris Papastamos 1284c639adc6SAxel Lin snd_soc_update_bits(codec, WM8991_AUDIO_INTERFACE_4, 1285c639adc6SAxel Lin WM8991_ALRCGPIO1, WM8991_ALRCGPIO1); 1286203db220SDimitris Papastamos 1287c639adc6SAxel Lin snd_soc_update_bits(codec, WM8991_GPIO1_GPIO2, 1288c639adc6SAxel Lin WM8991_GPIO1_SEL_MASK, 1); 1289203db220SDimitris Papastamos 1290c639adc6SAxel Lin snd_soc_update_bits(codec, WM8991_POWER_MANAGEMENT_1, 1291c639adc6SAxel Lin WM8991_VREF_ENA | WM8991_VMID_MODE_MASK, 1292c639adc6SAxel Lin WM8991_VREF_ENA | WM8991_VMID_MODE_MASK); 1293203db220SDimitris Papastamos 1294c639adc6SAxel Lin snd_soc_update_bits(codec, WM8991_POWER_MANAGEMENT_2, 1295c639adc6SAxel Lin WM8991_OPCLK_ENA, WM8991_OPCLK_ENA); 1296203db220SDimitris Papastamos 1297203db220SDimitris Papastamos snd_soc_write(codec, WM8991_DAC_CTRL, 0); 1298203db220SDimitris Papastamos snd_soc_write(codec, WM8991_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8)); 1299203db220SDimitris Papastamos snd_soc_write(codec, WM8991_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8)); 1300203db220SDimitris Papastamos 1301203db220SDimitris Papastamos snd_soc_add_controls(codec, wm8991_snd_controls, 1302203db220SDimitris Papastamos ARRAY_SIZE(wm8991_snd_controls)); 1303203db220SDimitris Papastamos 1304203db220SDimitris Papastamos snd_soc_dapm_new_controls(&codec->dapm, wm8991_dapm_widgets, 1305203db220SDimitris Papastamos ARRAY_SIZE(wm8991_dapm_widgets)); 1306203db220SDimitris Papastamos snd_soc_dapm_add_routes(&codec->dapm, audio_map, 1307203db220SDimitris Papastamos ARRAY_SIZE(audio_map)); 1308203db220SDimitris Papastamos return 0; 1309203db220SDimitris Papastamos } 1310203db220SDimitris Papastamos 1311203db220SDimitris Papastamos #define WM8991_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 1312203db220SDimitris Papastamos SNDRV_PCM_FMTBIT_S24_LE) 1313203db220SDimitris Papastamos 1314203db220SDimitris Papastamos static struct snd_soc_dai_ops wm8991_ops = { 1315203db220SDimitris Papastamos .hw_params = wm8991_hw_params, 1316203db220SDimitris Papastamos .digital_mute = wm8991_mute, 1317203db220SDimitris Papastamos .set_fmt = wm8991_set_dai_fmt, 1318203db220SDimitris Papastamos .set_clkdiv = wm8991_set_dai_clkdiv, 1319203db220SDimitris Papastamos .set_pll = wm8991_set_dai_pll 1320203db220SDimitris Papastamos }; 1321203db220SDimitris Papastamos 1322203db220SDimitris Papastamos /* 1323203db220SDimitris Papastamos * The WM8991 supports 2 different and mutually exclusive DAI 1324203db220SDimitris Papastamos * configurations. 1325203db220SDimitris Papastamos * 1326203db220SDimitris Papastamos * 1. ADC/DAC on Primary Interface 1327203db220SDimitris Papastamos * 2. ADC on Primary Interface/DAC on secondary 1328203db220SDimitris Papastamos */ 1329203db220SDimitris Papastamos static struct snd_soc_dai_driver wm8991_dai = { 1330203db220SDimitris Papastamos /* ADC/DAC on primary */ 1331203db220SDimitris Papastamos .name = "wm8991", 1332203db220SDimitris Papastamos .id = 1, 1333203db220SDimitris Papastamos .playback = { 1334203db220SDimitris Papastamos .stream_name = "Playback", 1335203db220SDimitris Papastamos .channels_min = 1, 1336203db220SDimitris Papastamos .channels_max = 2, 1337203db220SDimitris Papastamos .rates = SNDRV_PCM_RATE_8000_96000, 1338203db220SDimitris Papastamos .formats = WM8991_FORMATS 1339203db220SDimitris Papastamos }, 1340203db220SDimitris Papastamos .capture = { 1341203db220SDimitris Papastamos .stream_name = "Capture", 1342203db220SDimitris Papastamos .channels_min = 1, 1343203db220SDimitris Papastamos .channels_max = 2, 1344203db220SDimitris Papastamos .rates = SNDRV_PCM_RATE_8000_96000, 1345203db220SDimitris Papastamos .formats = WM8991_FORMATS 1346203db220SDimitris Papastamos }, 1347203db220SDimitris Papastamos .ops = &wm8991_ops 1348203db220SDimitris Papastamos }; 1349203db220SDimitris Papastamos 1350203db220SDimitris Papastamos static struct snd_soc_codec_driver soc_codec_dev_wm8991 = { 1351203db220SDimitris Papastamos .probe = wm8991_probe, 1352203db220SDimitris Papastamos .remove = wm8991_remove, 1353203db220SDimitris Papastamos .suspend = wm8991_suspend, 1354203db220SDimitris Papastamos .resume = wm8991_resume, 1355203db220SDimitris Papastamos .set_bias_level = wm8991_set_bias_level, 1356203db220SDimitris Papastamos .reg_cache_size = WM8991_MAX_REGISTER + 1, 1357203db220SDimitris Papastamos .reg_word_size = sizeof(u16), 1358203db220SDimitris Papastamos .reg_cache_default = wm8991_reg_defs 1359203db220SDimitris Papastamos }; 1360203db220SDimitris Papastamos 1361203db220SDimitris Papastamos static __devinit int wm8991_i2c_probe(struct i2c_client *i2c, 1362203db220SDimitris Papastamos const struct i2c_device_id *id) 1363203db220SDimitris Papastamos { 1364203db220SDimitris Papastamos struct wm8991_priv *wm8991; 1365203db220SDimitris Papastamos int ret; 1366203db220SDimitris Papastamos 1367203db220SDimitris Papastamos wm8991 = kzalloc(sizeof *wm8991, GFP_KERNEL); 1368203db220SDimitris Papastamos if (!wm8991) 1369203db220SDimitris Papastamos return -ENOMEM; 1370203db220SDimitris Papastamos 1371203db220SDimitris Papastamos wm8991->control_type = SND_SOC_I2C; 1372203db220SDimitris Papastamos i2c_set_clientdata(i2c, wm8991); 1373203db220SDimitris Papastamos 1374203db220SDimitris Papastamos ret = snd_soc_register_codec(&i2c->dev, 1375203db220SDimitris Papastamos &soc_codec_dev_wm8991, &wm8991_dai, 1); 1376203db220SDimitris Papastamos if (ret < 0) 1377203db220SDimitris Papastamos kfree(wm8991); 1378203db220SDimitris Papastamos return ret; 1379203db220SDimitris Papastamos } 1380203db220SDimitris Papastamos 1381203db220SDimitris Papastamos static __devexit int wm8991_i2c_remove(struct i2c_client *client) 1382203db220SDimitris Papastamos { 1383203db220SDimitris Papastamos snd_soc_unregister_codec(&client->dev); 1384203db220SDimitris Papastamos kfree(i2c_get_clientdata(client)); 1385203db220SDimitris Papastamos return 0; 1386203db220SDimitris Papastamos } 1387203db220SDimitris Papastamos 1388203db220SDimitris Papastamos static const struct i2c_device_id wm8991_i2c_id[] = { 1389203db220SDimitris Papastamos { "wm8991", 0 }, 1390203db220SDimitris Papastamos { } 1391203db220SDimitris Papastamos }; 1392203db220SDimitris Papastamos MODULE_DEVICE_TABLE(i2c, wm8991_i2c_id); 1393203db220SDimitris Papastamos 1394203db220SDimitris Papastamos static struct i2c_driver wm8991_i2c_driver = { 1395203db220SDimitris Papastamos .driver = { 1396203db220SDimitris Papastamos .name = "wm8991", 1397203db220SDimitris Papastamos .owner = THIS_MODULE, 1398203db220SDimitris Papastamos }, 1399203db220SDimitris Papastamos .probe = wm8991_i2c_probe, 1400203db220SDimitris Papastamos .remove = __devexit_p(wm8991_i2c_remove), 1401203db220SDimitris Papastamos .id_table = wm8991_i2c_id, 1402203db220SDimitris Papastamos }; 1403203db220SDimitris Papastamos 1404203db220SDimitris Papastamos static int __init wm8991_modinit(void) 1405203db220SDimitris Papastamos { 1406203db220SDimitris Papastamos int ret; 1407203db220SDimitris Papastamos ret = i2c_add_driver(&wm8991_i2c_driver); 1408203db220SDimitris Papastamos if (ret != 0) { 1409203db220SDimitris Papastamos printk(KERN_ERR "Failed to register WM8991 I2C driver: %d\n", 1410203db220SDimitris Papastamos ret); 1411203db220SDimitris Papastamos } 1412203db220SDimitris Papastamos return 0; 1413203db220SDimitris Papastamos } 1414203db220SDimitris Papastamos module_init(wm8991_modinit); 1415203db220SDimitris Papastamos 1416203db220SDimitris Papastamos static void __exit wm8991_exit(void) 1417203db220SDimitris Papastamos { 1418203db220SDimitris Papastamos i2c_del_driver(&wm8991_i2c_driver); 1419203db220SDimitris Papastamos } 1420203db220SDimitris Papastamos module_exit(wm8991_exit); 1421203db220SDimitris Papastamos 1422203db220SDimitris Papastamos MODULE_DESCRIPTION("ASoC WM8991 driver"); 1423203db220SDimitris Papastamos MODULE_AUTHOR("Graeme Gregory"); 1424203db220SDimitris Papastamos MODULE_LICENSE("GPL"); 1425