Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * wm8994.c -- WM8994 ALSA SoC Audio driver |
| 3 | * |
| 4 | * Copyright 2009 Wolfson Microelectronics plc |
| 5 | * |
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 7 | * |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/moduleparam.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/pm.h> |
| 19 | #include <linux/i2c.h> |
| 20 | #include <linux/platform_device.h> |
Mark Brown | 39fb51a | 2010-11-26 17:23:43 +0000 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 22 | #include <linux/regulator/consumer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 24 | #include <sound/core.h> |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 25 | #include <sound/jack.h> |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 26 | #include <sound/pcm.h> |
| 27 | #include <sound/pcm_params.h> |
| 28 | #include <sound/soc.h> |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 29 | #include <sound/initval.h> |
| 30 | #include <sound/tlv.h> |
Mark Brown | 2bbb5d6 | 2010-12-05 12:50:12 +0000 | [diff] [blame] | 31 | #include <trace/events/asoc.h> |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 32 | |
| 33 | #include <linux/mfd/wm8994/core.h> |
| 34 | #include <linux/mfd/wm8994/registers.h> |
| 35 | #include <linux/mfd/wm8994/pdata.h> |
| 36 | #include <linux/mfd/wm8994/gpio.h> |
| 37 | |
| 38 | #include "wm8994.h" |
| 39 | #include "wm_hubs.h" |
| 40 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 41 | #define WM8994_NUM_DRC 3 |
| 42 | #define WM8994_NUM_EQ 3 |
| 43 | |
| 44 | static int wm8994_drc_base[] = { |
| 45 | WM8994_AIF1_DRC1_1, |
| 46 | WM8994_AIF1_DRC2_1, |
| 47 | WM8994_AIF2_DRC_1, |
| 48 | }; |
| 49 | |
| 50 | static int wm8994_retune_mobile_base[] = { |
| 51 | WM8994_AIF1_DAC1_EQ_GAINS_1, |
| 52 | WM8994_AIF1_DAC2_EQ_GAINS_1, |
| 53 | WM8994_AIF2_EQ_GAINS_1, |
| 54 | }; |
| 55 | |
Dimitris Papastamos | d4754ec | 2011-01-13 12:20:37 +0000 | [diff] [blame] | 56 | static int wm8994_readable(struct snd_soc_codec *codec, unsigned int reg) |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 57 | { |
Mark Brown | af9af86 | 2011-03-16 21:05:06 +0000 | [diff] [blame] | 58 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 8eeea52 | 2011-11-04 15:52:31 +0000 | [diff] [blame] | 59 | struct wm8994 *control = codec->control_data; |
Mark Brown | af9af86 | 2011-03-16 21:05:06 +0000 | [diff] [blame] | 60 | |
Mark Brown | e88ff1e | 2010-07-09 00:12:08 +0900 | [diff] [blame] | 61 | switch (reg) { |
| 62 | case WM8994_GPIO_1: |
| 63 | case WM8994_GPIO_2: |
| 64 | case WM8994_GPIO_3: |
| 65 | case WM8994_GPIO_4: |
| 66 | case WM8994_GPIO_5: |
| 67 | case WM8994_GPIO_6: |
| 68 | case WM8994_GPIO_7: |
| 69 | case WM8994_GPIO_8: |
| 70 | case WM8994_GPIO_9: |
| 71 | case WM8994_GPIO_10: |
| 72 | case WM8994_GPIO_11: |
| 73 | case WM8994_INTERRUPT_STATUS_1: |
| 74 | case WM8994_INTERRUPT_STATUS_2: |
| 75 | case WM8994_INTERRUPT_RAW_STATUS_2: |
| 76 | return 1; |
Mark Brown | af9af86 | 2011-03-16 21:05:06 +0000 | [diff] [blame] | 77 | |
| 78 | case WM8958_DSP2_PROGRAM: |
| 79 | case WM8958_DSP2_CONFIG: |
| 80 | case WM8958_DSP2_EXECCONTROL: |
| 81 | if (control->type == WM8958) |
| 82 | return 1; |
| 83 | else |
| 84 | return 0; |
| 85 | |
Mark Brown | e88ff1e | 2010-07-09 00:12:08 +0900 | [diff] [blame] | 86 | default: |
| 87 | break; |
| 88 | } |
| 89 | |
Mark Brown | 7b306da | 2010-11-16 20:11:40 +0000 | [diff] [blame] | 90 | if (reg >= WM8994_CACHE_SIZE) |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 91 | return 0; |
Mark Brown | 7b306da | 2010-11-16 20:11:40 +0000 | [diff] [blame] | 92 | return wm8994_access_masks[reg].readable != 0; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Dimitris Papastamos | d4754ec | 2011-01-13 12:20:37 +0000 | [diff] [blame] | 95 | static int wm8994_volatile(struct snd_soc_codec *codec, unsigned int reg) |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 96 | { |
Mark Brown | ca9aef5 | 2010-11-26 17:23:41 +0000 | [diff] [blame] | 97 | if (reg >= WM8994_CACHE_SIZE) |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 98 | return 1; |
| 99 | |
| 100 | switch (reg) { |
| 101 | case WM8994_SOFTWARE_RESET: |
| 102 | case WM8994_CHIP_REVISION: |
| 103 | case WM8994_DC_SERVO_1: |
| 104 | case WM8994_DC_SERVO_READBACK: |
| 105 | case WM8994_RATE_STATUS: |
| 106 | case WM8994_LDO_1: |
| 107 | case WM8994_LDO_2: |
Mark Brown | d6addcc | 2010-11-26 15:21:08 +0000 | [diff] [blame] | 108 | case WM8958_DSP2_EXECCONTROL: |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 109 | case WM8958_MIC_DETECT_3: |
Mark Brown | 79ef0ab | 2011-08-01 13:02:17 +0900 | [diff] [blame] | 110 | case WM8994_DC_SERVO_4E: |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 111 | return 1; |
| 112 | default: |
| 113 | return 0; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | static int wm8994_write(struct snd_soc_codec *codec, unsigned int reg, |
| 118 | unsigned int value) |
| 119 | { |
Mark Brown | ca9aef5 | 2010-11-26 17:23:41 +0000 | [diff] [blame] | 120 | int ret; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 121 | |
| 122 | BUG_ON(reg > WM8994_MAX_REGISTER); |
| 123 | |
Dimitris Papastamos | d4754ec | 2011-01-13 12:20:37 +0000 | [diff] [blame] | 124 | if (!wm8994_volatile(codec, reg)) { |
Mark Brown | ca9aef5 | 2010-11-26 17:23:41 +0000 | [diff] [blame] | 125 | ret = snd_soc_cache_write(codec, reg, value); |
| 126 | if (ret != 0) |
| 127 | dev_err(codec->dev, "Cache write to %x failed: %d\n", |
| 128 | reg, ret); |
| 129 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 130 | |
| 131 | return wm8994_reg_write(codec->control_data, reg, value); |
| 132 | } |
| 133 | |
| 134 | static unsigned int wm8994_read(struct snd_soc_codec *codec, |
| 135 | unsigned int reg) |
| 136 | { |
Mark Brown | ca9aef5 | 2010-11-26 17:23:41 +0000 | [diff] [blame] | 137 | unsigned int val; |
| 138 | int ret; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 139 | |
| 140 | BUG_ON(reg > WM8994_MAX_REGISTER); |
| 141 | |
Dimitris Papastamos | d4754ec | 2011-01-13 12:20:37 +0000 | [diff] [blame] | 142 | if (!wm8994_volatile(codec, reg) && wm8994_readable(codec, reg) && |
Mark Brown | ca9aef5 | 2010-11-26 17:23:41 +0000 | [diff] [blame] | 143 | reg < codec->driver->reg_cache_size) { |
| 144 | ret = snd_soc_cache_read(codec, reg, &val); |
| 145 | if (ret >= 0) |
| 146 | return val; |
| 147 | else |
| 148 | dev_err(codec->dev, "Cache read from %x failed: %d\n", |
| 149 | reg, ret); |
| 150 | } |
| 151 | |
| 152 | return wm8994_reg_read(codec->control_data, reg); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static int configure_aif_clock(struct snd_soc_codec *codec, int aif) |
| 156 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 157 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 158 | int rate; |
| 159 | int reg1 = 0; |
| 160 | int offset; |
| 161 | |
| 162 | if (aif) |
| 163 | offset = 4; |
| 164 | else |
| 165 | offset = 0; |
| 166 | |
| 167 | switch (wm8994->sysclk[aif]) { |
| 168 | case WM8994_SYSCLK_MCLK1: |
| 169 | rate = wm8994->mclk[0]; |
| 170 | break; |
| 171 | |
| 172 | case WM8994_SYSCLK_MCLK2: |
| 173 | reg1 |= 0x8; |
| 174 | rate = wm8994->mclk[1]; |
| 175 | break; |
| 176 | |
| 177 | case WM8994_SYSCLK_FLL1: |
| 178 | reg1 |= 0x10; |
| 179 | rate = wm8994->fll[0].out; |
| 180 | break; |
| 181 | |
| 182 | case WM8994_SYSCLK_FLL2: |
| 183 | reg1 |= 0x18; |
| 184 | rate = wm8994->fll[1].out; |
| 185 | break; |
| 186 | |
| 187 | default: |
| 188 | return -EINVAL; |
| 189 | } |
| 190 | |
| 191 | if (rate >= 13500000) { |
| 192 | rate /= 2; |
| 193 | reg1 |= WM8994_AIF1CLK_DIV; |
| 194 | |
| 195 | dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n", |
| 196 | aif + 1, rate); |
| 197 | } |
Mark Brown | 5e5e2be | 2010-04-25 12:20:30 +0100 | [diff] [blame] | 198 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 199 | wm8994->aifclk[aif] = rate; |
| 200 | |
| 201 | snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1 + offset, |
| 202 | WM8994_AIF1CLK_SRC_MASK | WM8994_AIF1CLK_DIV, |
| 203 | reg1); |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | static int configure_clock(struct snd_soc_codec *codec) |
| 209 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 210 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Axel Lin | 04f45c4 | 2011-10-04 20:07:03 +0800 | [diff] [blame] | 211 | int change, new; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 212 | |
| 213 | /* Bring up the AIF clocks first */ |
| 214 | configure_aif_clock(codec, 0); |
| 215 | configure_aif_clock(codec, 1); |
| 216 | |
| 217 | /* Then switch CLK_SYS over to the higher of them; a change |
| 218 | * can only happen as a result of a clocking change which can |
| 219 | * only be made outside of DAPM so we can safely redo the |
| 220 | * clocking. |
| 221 | */ |
| 222 | |
| 223 | /* If they're equal it doesn't matter which is used */ |
| 224 | if (wm8994->aifclk[0] == wm8994->aifclk[1]) |
| 225 | return 0; |
| 226 | |
| 227 | if (wm8994->aifclk[0] < wm8994->aifclk[1]) |
| 228 | new = WM8994_SYSCLK_SRC; |
| 229 | else |
| 230 | new = 0; |
| 231 | |
Axel Lin | 04f45c4 | 2011-10-04 20:07:03 +0800 | [diff] [blame] | 232 | change = snd_soc_update_bits(codec, WM8994_CLOCKING_1, |
| 233 | WM8994_SYSCLK_SRC, new); |
| 234 | if (!change) |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 235 | return 0; |
| 236 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 237 | snd_soc_dapm_sync(&codec->dapm); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static int check_clk_sys(struct snd_soc_dapm_widget *source, |
| 243 | struct snd_soc_dapm_widget *sink) |
| 244 | { |
| 245 | int reg = snd_soc_read(source->codec, WM8994_CLOCKING_1); |
| 246 | const char *clk; |
| 247 | |
| 248 | /* Check what we're currently using for CLK_SYS */ |
| 249 | if (reg & WM8994_SYSCLK_SRC) |
| 250 | clk = "AIF2CLK"; |
| 251 | else |
| 252 | clk = "AIF1CLK"; |
| 253 | |
| 254 | return strcmp(source->name, clk) == 0; |
| 255 | } |
| 256 | |
| 257 | static const char *sidetone_hpf_text[] = { |
| 258 | "2.7kHz", "1.35kHz", "675Hz", "370Hz", "180Hz", "90Hz", "45Hz" |
| 259 | }; |
| 260 | |
| 261 | static const struct soc_enum sidetone_hpf = |
| 262 | SOC_ENUM_SINGLE(WM8994_SIDETONE, 7, 7, sidetone_hpf_text); |
| 263 | |
Uk Kim | 146fd57 | 2010-12-07 13:58:40 +0000 | [diff] [blame] | 264 | static const char *adc_hpf_text[] = { |
| 265 | "HiFi", "Voice 1", "Voice 2", "Voice 3" |
| 266 | }; |
| 267 | |
| 268 | static const struct soc_enum aif1adc1_hpf = |
| 269 | SOC_ENUM_SINGLE(WM8994_AIF1_ADC1_FILTERS, 13, 4, adc_hpf_text); |
| 270 | |
| 271 | static const struct soc_enum aif1adc2_hpf = |
| 272 | SOC_ENUM_SINGLE(WM8994_AIF1_ADC2_FILTERS, 13, 4, adc_hpf_text); |
| 273 | |
| 274 | static const struct soc_enum aif2adc_hpf = |
| 275 | SOC_ENUM_SINGLE(WM8994_AIF2_ADC_FILTERS, 13, 4, adc_hpf_text); |
| 276 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 277 | static const DECLARE_TLV_DB_SCALE(aif_tlv, 0, 600, 0); |
| 278 | static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1); |
| 279 | static const DECLARE_TLV_DB_SCALE(st_tlv, -3600, 300, 0); |
| 280 | static const DECLARE_TLV_DB_SCALE(wm8994_3d_tlv, -1600, 183, 0); |
| 281 | static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); |
Mark Brown | 1ddc07d | 2011-08-16 10:08:48 +0900 | [diff] [blame] | 282 | static const DECLARE_TLV_DB_SCALE(ng_tlv, -10200, 600, 0); |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 283 | static const DECLARE_TLV_DB_SCALE(mixin_boost_tlv, 0, 900, 0); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 284 | |
| 285 | #define WM8994_DRC_SWITCH(xname, reg, shift) \ |
| 286 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 287 | .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\ |
| 288 | .put = wm8994_put_drc_sw, \ |
| 289 | .private_value = SOC_SINGLE_VALUE(reg, shift, 1, 0) } |
| 290 | |
| 291 | static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol, |
| 292 | struct snd_ctl_elem_value *ucontrol) |
| 293 | { |
| 294 | struct soc_mixer_control *mc = |
| 295 | (struct soc_mixer_control *)kcontrol->private_value; |
| 296 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 297 | int mask, ret; |
| 298 | |
| 299 | /* Can't enable both ADC and DAC paths simultaneously */ |
| 300 | if (mc->shift == WM8994_AIF1DAC1_DRC_ENA_SHIFT) |
| 301 | mask = WM8994_AIF1ADC1L_DRC_ENA_MASK | |
| 302 | WM8994_AIF1ADC1R_DRC_ENA_MASK; |
| 303 | else |
| 304 | mask = WM8994_AIF1DAC1_DRC_ENA_MASK; |
| 305 | |
| 306 | ret = snd_soc_read(codec, mc->reg); |
| 307 | if (ret < 0) |
| 308 | return ret; |
| 309 | if (ret & mask) |
| 310 | return -EINVAL; |
| 311 | |
| 312 | return snd_soc_put_volsw(kcontrol, ucontrol); |
| 313 | } |
| 314 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 315 | static void wm8994_set_drc(struct snd_soc_codec *codec, int drc) |
| 316 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 317 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 318 | struct wm8994_pdata *pdata = wm8994->pdata; |
| 319 | int base = wm8994_drc_base[drc]; |
| 320 | int cfg = wm8994->drc_cfg[drc]; |
| 321 | int save, i; |
| 322 | |
| 323 | /* Save any enables; the configuration should clear them. */ |
| 324 | save = snd_soc_read(codec, base); |
| 325 | save &= WM8994_AIF1DAC1_DRC_ENA | WM8994_AIF1ADC1L_DRC_ENA | |
| 326 | WM8994_AIF1ADC1R_DRC_ENA; |
| 327 | |
| 328 | for (i = 0; i < WM8994_DRC_REGS; i++) |
| 329 | snd_soc_update_bits(codec, base + i, 0xffff, |
| 330 | pdata->drc_cfgs[cfg].regs[i]); |
| 331 | |
| 332 | snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_DRC_ENA | |
| 333 | WM8994_AIF1ADC1L_DRC_ENA | |
| 334 | WM8994_AIF1ADC1R_DRC_ENA, save); |
| 335 | } |
| 336 | |
| 337 | /* Icky as hell but saves code duplication */ |
| 338 | static int wm8994_get_drc(const char *name) |
| 339 | { |
| 340 | if (strcmp(name, "AIF1DRC1 Mode") == 0) |
| 341 | return 0; |
| 342 | if (strcmp(name, "AIF1DRC2 Mode") == 0) |
| 343 | return 1; |
| 344 | if (strcmp(name, "AIF2DRC Mode") == 0) |
| 345 | return 2; |
| 346 | return -EINVAL; |
| 347 | } |
| 348 | |
| 349 | static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol, |
| 350 | struct snd_ctl_elem_value *ucontrol) |
| 351 | { |
| 352 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 353 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 354 | struct wm8994_pdata *pdata = wm8994->pdata; |
| 355 | int drc = wm8994_get_drc(kcontrol->id.name); |
| 356 | int value = ucontrol->value.integer.value[0]; |
| 357 | |
| 358 | if (drc < 0) |
| 359 | return drc; |
| 360 | |
| 361 | if (value >= pdata->num_drc_cfgs) |
| 362 | return -EINVAL; |
| 363 | |
| 364 | wm8994->drc_cfg[drc] = value; |
| 365 | |
| 366 | wm8994_set_drc(codec, drc); |
| 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol, |
| 372 | struct snd_ctl_elem_value *ucontrol) |
| 373 | { |
| 374 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 375 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 376 | int drc = wm8994_get_drc(kcontrol->id.name); |
| 377 | |
| 378 | ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc]; |
| 379 | |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block) |
| 384 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 385 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 386 | struct wm8994_pdata *pdata = wm8994->pdata; |
| 387 | int base = wm8994_retune_mobile_base[block]; |
| 388 | int iface, best, best_val, save, i, cfg; |
| 389 | |
| 390 | if (!pdata || !wm8994->num_retune_mobile_texts) |
| 391 | return; |
| 392 | |
| 393 | switch (block) { |
| 394 | case 0: |
| 395 | case 1: |
| 396 | iface = 0; |
| 397 | break; |
| 398 | case 2: |
| 399 | iface = 1; |
| 400 | break; |
| 401 | default: |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | /* Find the version of the currently selected configuration |
| 406 | * with the nearest sample rate. */ |
| 407 | cfg = wm8994->retune_mobile_cfg[block]; |
| 408 | best = 0; |
| 409 | best_val = INT_MAX; |
| 410 | for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) { |
| 411 | if (strcmp(pdata->retune_mobile_cfgs[i].name, |
| 412 | wm8994->retune_mobile_texts[cfg]) == 0 && |
| 413 | abs(pdata->retune_mobile_cfgs[i].rate |
| 414 | - wm8994->dac_rates[iface]) < best_val) { |
| 415 | best = i; |
| 416 | best_val = abs(pdata->retune_mobile_cfgs[i].rate |
| 417 | - wm8994->dac_rates[iface]); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | dev_dbg(codec->dev, "ReTune Mobile %d %s/%dHz for %dHz sample rate\n", |
| 422 | block, |
| 423 | pdata->retune_mobile_cfgs[best].name, |
| 424 | pdata->retune_mobile_cfgs[best].rate, |
| 425 | wm8994->dac_rates[iface]); |
| 426 | |
| 427 | /* The EQ will be disabled while reconfiguring it, remember the |
| 428 | * current configuration. |
| 429 | */ |
| 430 | save = snd_soc_read(codec, base); |
| 431 | save &= WM8994_AIF1DAC1_EQ_ENA; |
| 432 | |
| 433 | for (i = 0; i < WM8994_EQ_REGS; i++) |
| 434 | snd_soc_update_bits(codec, base + i, 0xffff, |
| 435 | pdata->retune_mobile_cfgs[best].regs[i]); |
| 436 | |
| 437 | snd_soc_update_bits(codec, base, WM8994_AIF1DAC1_EQ_ENA, save); |
| 438 | } |
| 439 | |
| 440 | /* Icky as hell but saves code duplication */ |
| 441 | static int wm8994_get_retune_mobile_block(const char *name) |
| 442 | { |
| 443 | if (strcmp(name, "AIF1.1 EQ Mode") == 0) |
| 444 | return 0; |
| 445 | if (strcmp(name, "AIF1.2 EQ Mode") == 0) |
| 446 | return 1; |
| 447 | if (strcmp(name, "AIF2 EQ Mode") == 0) |
| 448 | return 2; |
| 449 | return -EINVAL; |
| 450 | } |
| 451 | |
| 452 | static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol, |
| 453 | struct snd_ctl_elem_value *ucontrol) |
| 454 | { |
| 455 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 456 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 457 | struct wm8994_pdata *pdata = wm8994->pdata; |
| 458 | int block = wm8994_get_retune_mobile_block(kcontrol->id.name); |
| 459 | int value = ucontrol->value.integer.value[0]; |
| 460 | |
| 461 | if (block < 0) |
| 462 | return block; |
| 463 | |
| 464 | if (value >= pdata->num_retune_mobile_cfgs) |
| 465 | return -EINVAL; |
| 466 | |
| 467 | wm8994->retune_mobile_cfg[block] = value; |
| 468 | |
| 469 | wm8994_set_retune_mobile(codec, block); |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol, |
| 475 | struct snd_ctl_elem_value *ucontrol) |
| 476 | { |
| 477 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Mark Brown | 4a8d929 | 2011-02-16 14:57:17 -0800 | [diff] [blame] | 478 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 479 | int block = wm8994_get_retune_mobile_block(kcontrol->id.name); |
| 480 | |
| 481 | ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block]; |
| 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | |
Mark Brown | 96b101e | 2010-11-18 15:49:38 +0000 | [diff] [blame] | 486 | static const char *aif_chan_src_text[] = { |
Mark Brown | f554885 | 2010-08-31 19:39:48 +0100 | [diff] [blame] | 487 | "Left", "Right" |
| 488 | }; |
| 489 | |
Mark Brown | 96b101e | 2010-11-18 15:49:38 +0000 | [diff] [blame] | 490 | static const struct soc_enum aif1adcl_src = |
| 491 | SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 15, 2, aif_chan_src_text); |
| 492 | |
| 493 | static const struct soc_enum aif1adcr_src = |
| 494 | SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_1, 14, 2, aif_chan_src_text); |
| 495 | |
| 496 | static const struct soc_enum aif2adcl_src = |
| 497 | SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 15, 2, aif_chan_src_text); |
| 498 | |
| 499 | static const struct soc_enum aif2adcr_src = |
| 500 | SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_1, 14, 2, aif_chan_src_text); |
| 501 | |
Mark Brown | f554885 | 2010-08-31 19:39:48 +0100 | [diff] [blame] | 502 | static const struct soc_enum aif1dacl_src = |
Mark Brown | 96b101e | 2010-11-18 15:49:38 +0000 | [diff] [blame] | 503 | SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 15, 2, aif_chan_src_text); |
Mark Brown | f554885 | 2010-08-31 19:39:48 +0100 | [diff] [blame] | 504 | |
| 505 | static const struct soc_enum aif1dacr_src = |
Mark Brown | 96b101e | 2010-11-18 15:49:38 +0000 | [diff] [blame] | 506 | SOC_ENUM_SINGLE(WM8994_AIF1_CONTROL_2, 14, 2, aif_chan_src_text); |
Mark Brown | f554885 | 2010-08-31 19:39:48 +0100 | [diff] [blame] | 507 | |
| 508 | static const struct soc_enum aif2dacl_src = |
Mark Brown | 96b101e | 2010-11-18 15:49:38 +0000 | [diff] [blame] | 509 | SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 15, 2, aif_chan_src_text); |
Mark Brown | f554885 | 2010-08-31 19:39:48 +0100 | [diff] [blame] | 510 | |
| 511 | static const struct soc_enum aif2dacr_src = |
Mark Brown | 96b101e | 2010-11-18 15:49:38 +0000 | [diff] [blame] | 512 | SOC_ENUM_SINGLE(WM8994_AIF2_CONTROL_2, 14, 2, aif_chan_src_text); |
Mark Brown | f554885 | 2010-08-31 19:39:48 +0100 | [diff] [blame] | 513 | |
Mark Brown | 154b26a | 2010-12-09 12:07:44 +0000 | [diff] [blame] | 514 | static const char *osr_text[] = { |
| 515 | "Low Power", "High Performance", |
| 516 | }; |
| 517 | |
| 518 | static const struct soc_enum dac_osr = |
| 519 | SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 0, 2, osr_text); |
| 520 | |
| 521 | static const struct soc_enum adc_osr = |
| 522 | SOC_ENUM_SINGLE(WM8994_OVERSAMPLING, 1, 2, osr_text); |
| 523 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 524 | static const struct snd_kcontrol_new wm8994_snd_controls[] = { |
| 525 | SOC_DOUBLE_R_TLV("AIF1ADC1 Volume", WM8994_AIF1_ADC1_LEFT_VOLUME, |
| 526 | WM8994_AIF1_ADC1_RIGHT_VOLUME, |
| 527 | 1, 119, 0, digital_tlv), |
| 528 | SOC_DOUBLE_R_TLV("AIF1ADC2 Volume", WM8994_AIF1_ADC2_LEFT_VOLUME, |
| 529 | WM8994_AIF1_ADC2_RIGHT_VOLUME, |
| 530 | 1, 119, 0, digital_tlv), |
| 531 | SOC_DOUBLE_R_TLV("AIF2ADC Volume", WM8994_AIF2_ADC_LEFT_VOLUME, |
| 532 | WM8994_AIF2_ADC_RIGHT_VOLUME, |
| 533 | 1, 119, 0, digital_tlv), |
| 534 | |
Mark Brown | 96b101e | 2010-11-18 15:49:38 +0000 | [diff] [blame] | 535 | SOC_ENUM("AIF1ADCL Source", aif1adcl_src), |
| 536 | SOC_ENUM("AIF1ADCR Source", aif1adcr_src), |
Mark Brown | 49db7e7 | 2010-12-08 13:49:43 +0000 | [diff] [blame] | 537 | SOC_ENUM("AIF2ADCL Source", aif2adcl_src), |
| 538 | SOC_ENUM("AIF2ADCR Source", aif2adcr_src), |
Mark Brown | 96b101e | 2010-11-18 15:49:38 +0000 | [diff] [blame] | 539 | |
Mark Brown | f554885 | 2010-08-31 19:39:48 +0100 | [diff] [blame] | 540 | SOC_ENUM("AIF1DACL Source", aif1dacl_src), |
| 541 | SOC_ENUM("AIF1DACR Source", aif1dacr_src), |
Mark Brown | 49db7e7 | 2010-12-08 13:49:43 +0000 | [diff] [blame] | 542 | SOC_ENUM("AIF2DACL Source", aif2dacl_src), |
| 543 | SOC_ENUM("AIF2DACR Source", aif2dacr_src), |
Mark Brown | f554885 | 2010-08-31 19:39:48 +0100 | [diff] [blame] | 544 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 545 | SOC_DOUBLE_R_TLV("AIF1DAC1 Volume", WM8994_AIF1_DAC1_LEFT_VOLUME, |
| 546 | WM8994_AIF1_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv), |
| 547 | SOC_DOUBLE_R_TLV("AIF1DAC2 Volume", WM8994_AIF1_DAC2_LEFT_VOLUME, |
| 548 | WM8994_AIF1_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv), |
| 549 | SOC_DOUBLE_R_TLV("AIF2DAC Volume", WM8994_AIF2_DAC_LEFT_VOLUME, |
| 550 | WM8994_AIF2_DAC_RIGHT_VOLUME, 1, 96, 0, digital_tlv), |
| 551 | |
| 552 | SOC_SINGLE_TLV("AIF1 Boost Volume", WM8994_AIF1_CONTROL_2, 10, 3, 0, aif_tlv), |
| 553 | SOC_SINGLE_TLV("AIF2 Boost Volume", WM8994_AIF2_CONTROL_2, 10, 3, 0, aif_tlv), |
| 554 | |
| 555 | SOC_SINGLE("AIF1DAC1 EQ Switch", WM8994_AIF1_DAC1_EQ_GAINS_1, 0, 1, 0), |
| 556 | SOC_SINGLE("AIF1DAC2 EQ Switch", WM8994_AIF1_DAC2_EQ_GAINS_1, 0, 1, 0), |
| 557 | SOC_SINGLE("AIF2 EQ Switch", WM8994_AIF2_EQ_GAINS_1, 0, 1, 0), |
| 558 | |
| 559 | WM8994_DRC_SWITCH("AIF1DAC1 DRC Switch", WM8994_AIF1_DRC1_1, 2), |
| 560 | WM8994_DRC_SWITCH("AIF1ADC1L DRC Switch", WM8994_AIF1_DRC1_1, 1), |
| 561 | WM8994_DRC_SWITCH("AIF1ADC1R DRC Switch", WM8994_AIF1_DRC1_1, 0), |
| 562 | |
| 563 | WM8994_DRC_SWITCH("AIF1DAC2 DRC Switch", WM8994_AIF1_DRC2_1, 2), |
| 564 | WM8994_DRC_SWITCH("AIF1ADC2L DRC Switch", WM8994_AIF1_DRC2_1, 1), |
| 565 | WM8994_DRC_SWITCH("AIF1ADC2R DRC Switch", WM8994_AIF1_DRC2_1, 0), |
| 566 | |
| 567 | WM8994_DRC_SWITCH("AIF2DAC DRC Switch", WM8994_AIF2_DRC_1, 2), |
| 568 | WM8994_DRC_SWITCH("AIF2ADCL DRC Switch", WM8994_AIF2_DRC_1, 1), |
| 569 | WM8994_DRC_SWITCH("AIF2ADCR DRC Switch", WM8994_AIF2_DRC_1, 0), |
| 570 | |
| 571 | SOC_SINGLE_TLV("DAC1 Right Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES, |
| 572 | 5, 12, 0, st_tlv), |
| 573 | SOC_SINGLE_TLV("DAC1 Left Sidetone Volume", WM8994_DAC1_MIXER_VOLUMES, |
| 574 | 0, 12, 0, st_tlv), |
| 575 | SOC_SINGLE_TLV("DAC2 Right Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES, |
| 576 | 5, 12, 0, st_tlv), |
| 577 | SOC_SINGLE_TLV("DAC2 Left Sidetone Volume", WM8994_DAC2_MIXER_VOLUMES, |
| 578 | 0, 12, 0, st_tlv), |
| 579 | SOC_ENUM("Sidetone HPF Mux", sidetone_hpf), |
| 580 | SOC_SINGLE("Sidetone HPF Switch", WM8994_SIDETONE, 6, 1, 0), |
| 581 | |
Uk Kim | 146fd57 | 2010-12-07 13:58:40 +0000 | [diff] [blame] | 582 | SOC_ENUM("AIF1ADC1 HPF Mode", aif1adc1_hpf), |
| 583 | SOC_DOUBLE("AIF1ADC1 HPF Switch", WM8994_AIF1_ADC1_FILTERS, 12, 11, 1, 0), |
| 584 | |
| 585 | SOC_ENUM("AIF1ADC2 HPF Mode", aif1adc2_hpf), |
| 586 | SOC_DOUBLE("AIF1ADC2 HPF Switch", WM8994_AIF1_ADC2_FILTERS, 12, 11, 1, 0), |
| 587 | |
| 588 | SOC_ENUM("AIF2ADC HPF Mode", aif2adc_hpf), |
| 589 | SOC_DOUBLE("AIF2ADC HPF Switch", WM8994_AIF2_ADC_FILTERS, 12, 11, 1, 0), |
| 590 | |
Mark Brown | 154b26a | 2010-12-09 12:07:44 +0000 | [diff] [blame] | 591 | SOC_ENUM("ADC OSR", adc_osr), |
| 592 | SOC_ENUM("DAC OSR", dac_osr), |
| 593 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 594 | SOC_DOUBLE_R_TLV("DAC1 Volume", WM8994_DAC1_LEFT_VOLUME, |
| 595 | WM8994_DAC1_RIGHT_VOLUME, 1, 96, 0, digital_tlv), |
| 596 | SOC_DOUBLE_R("DAC1 Switch", WM8994_DAC1_LEFT_VOLUME, |
| 597 | WM8994_DAC1_RIGHT_VOLUME, 9, 1, 1), |
| 598 | |
| 599 | SOC_DOUBLE_R_TLV("DAC2 Volume", WM8994_DAC2_LEFT_VOLUME, |
| 600 | WM8994_DAC2_RIGHT_VOLUME, 1, 96, 0, digital_tlv), |
| 601 | SOC_DOUBLE_R("DAC2 Switch", WM8994_DAC2_LEFT_VOLUME, |
| 602 | WM8994_DAC2_RIGHT_VOLUME, 9, 1, 1), |
| 603 | |
| 604 | SOC_SINGLE_TLV("SPKL DAC2 Volume", WM8994_SPKMIXL_ATTENUATION, |
| 605 | 6, 1, 1, wm_hubs_spkmix_tlv), |
| 606 | SOC_SINGLE_TLV("SPKL DAC1 Volume", WM8994_SPKMIXL_ATTENUATION, |
| 607 | 2, 1, 1, wm_hubs_spkmix_tlv), |
| 608 | |
| 609 | SOC_SINGLE_TLV("SPKR DAC2 Volume", WM8994_SPKMIXR_ATTENUATION, |
| 610 | 6, 1, 1, wm_hubs_spkmix_tlv), |
| 611 | SOC_SINGLE_TLV("SPKR DAC1 Volume", WM8994_SPKMIXR_ATTENUATION, |
| 612 | 2, 1, 1, wm_hubs_spkmix_tlv), |
| 613 | |
| 614 | SOC_SINGLE_TLV("AIF1DAC1 3D Stereo Volume", WM8994_AIF1_DAC1_FILTERS_2, |
| 615 | 10, 15, 0, wm8994_3d_tlv), |
Mark Brown | 458350b | 2010-12-20 14:35:09 +0000 | [diff] [blame] | 616 | SOC_SINGLE("AIF1DAC1 3D Stereo Switch", WM8994_AIF1_DAC1_FILTERS_2, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 617 | 8, 1, 0), |
| 618 | SOC_SINGLE_TLV("AIF1DAC2 3D Stereo Volume", WM8994_AIF1_DAC2_FILTERS_2, |
| 619 | 10, 15, 0, wm8994_3d_tlv), |
| 620 | SOC_SINGLE("AIF1DAC2 3D Stereo Switch", WM8994_AIF1_DAC2_FILTERS_2, |
| 621 | 8, 1, 0), |
Mark Brown | 458350b | 2010-12-20 14:35:09 +0000 | [diff] [blame] | 622 | SOC_SINGLE_TLV("AIF2DAC 3D Stereo Volume", WM8994_AIF2_DAC_FILTERS_2, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 623 | 10, 15, 0, wm8994_3d_tlv), |
Mark Brown | 458350b | 2010-12-20 14:35:09 +0000 | [diff] [blame] | 624 | SOC_SINGLE("AIF2DAC 3D Stereo Switch", WM8994_AIF2_DAC_FILTERS_2, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 625 | 8, 1, 0), |
| 626 | }; |
| 627 | |
| 628 | static const struct snd_kcontrol_new wm8994_eq_controls[] = { |
| 629 | SOC_SINGLE_TLV("AIF1DAC1 EQ1 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 11, 31, 0, |
| 630 | eq_tlv), |
| 631 | SOC_SINGLE_TLV("AIF1DAC1 EQ2 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 6, 31, 0, |
| 632 | eq_tlv), |
| 633 | SOC_SINGLE_TLV("AIF1DAC1 EQ3 Volume", WM8994_AIF1_DAC1_EQ_GAINS_1, 1, 31, 0, |
| 634 | eq_tlv), |
| 635 | SOC_SINGLE_TLV("AIF1DAC1 EQ4 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 11, 31, 0, |
| 636 | eq_tlv), |
| 637 | SOC_SINGLE_TLV("AIF1DAC1 EQ5 Volume", WM8994_AIF1_DAC1_EQ_GAINS_2, 6, 31, 0, |
| 638 | eq_tlv), |
| 639 | |
| 640 | SOC_SINGLE_TLV("AIF1DAC2 EQ1 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 11, 31, 0, |
| 641 | eq_tlv), |
| 642 | SOC_SINGLE_TLV("AIF1DAC2 EQ2 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 6, 31, 0, |
| 643 | eq_tlv), |
| 644 | SOC_SINGLE_TLV("AIF1DAC2 EQ3 Volume", WM8994_AIF1_DAC2_EQ_GAINS_1, 1, 31, 0, |
| 645 | eq_tlv), |
| 646 | SOC_SINGLE_TLV("AIF1DAC2 EQ4 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 11, 31, 0, |
| 647 | eq_tlv), |
| 648 | SOC_SINGLE_TLV("AIF1DAC2 EQ5 Volume", WM8994_AIF1_DAC2_EQ_GAINS_2, 6, 31, 0, |
| 649 | eq_tlv), |
| 650 | |
| 651 | SOC_SINGLE_TLV("AIF2 EQ1 Volume", WM8994_AIF2_EQ_GAINS_1, 11, 31, 0, |
| 652 | eq_tlv), |
| 653 | SOC_SINGLE_TLV("AIF2 EQ2 Volume", WM8994_AIF2_EQ_GAINS_1, 6, 31, 0, |
| 654 | eq_tlv), |
| 655 | SOC_SINGLE_TLV("AIF2 EQ3 Volume", WM8994_AIF2_EQ_GAINS_1, 1, 31, 0, |
| 656 | eq_tlv), |
| 657 | SOC_SINGLE_TLV("AIF2 EQ4 Volume", WM8994_AIF2_EQ_GAINS_2, 11, 31, 0, |
| 658 | eq_tlv), |
| 659 | SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0, |
| 660 | eq_tlv), |
| 661 | }; |
| 662 | |
Mark Brown | 1ddc07d | 2011-08-16 10:08:48 +0900 | [diff] [blame] | 663 | static const char *wm8958_ng_text[] = { |
| 664 | "30ms", "125ms", "250ms", "500ms", |
| 665 | }; |
| 666 | |
| 667 | static const struct soc_enum wm8958_aif1dac1_ng_hold = |
| 668 | SOC_ENUM_SINGLE(WM8958_AIF1_DAC1_NOISE_GATE, |
| 669 | WM8958_AIF1DAC1_NG_THR_SHIFT, 4, wm8958_ng_text); |
| 670 | |
| 671 | static const struct soc_enum wm8958_aif1dac2_ng_hold = |
| 672 | SOC_ENUM_SINGLE(WM8958_AIF1_DAC2_NOISE_GATE, |
| 673 | WM8958_AIF1DAC2_NG_THR_SHIFT, 4, wm8958_ng_text); |
| 674 | |
| 675 | static const struct soc_enum wm8958_aif2dac_ng_hold = |
| 676 | SOC_ENUM_SINGLE(WM8958_AIF2_DAC_NOISE_GATE, |
| 677 | WM8958_AIF2DAC_NG_THR_SHIFT, 4, wm8958_ng_text); |
| 678 | |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 679 | static const struct snd_kcontrol_new wm8958_snd_controls[] = { |
| 680 | SOC_SINGLE_TLV("AIF3 Boost Volume", WM8958_AIF3_CONTROL_2, 10, 3, 0, aif_tlv), |
Mark Brown | 1ddc07d | 2011-08-16 10:08:48 +0900 | [diff] [blame] | 681 | |
| 682 | SOC_SINGLE("AIF1DAC1 Noise Gate Switch", WM8958_AIF1_DAC1_NOISE_GATE, |
| 683 | WM8958_AIF1DAC1_NG_ENA_SHIFT, 1, 0), |
| 684 | SOC_ENUM("AIF1DAC1 Noise Gate Hold Time", wm8958_aif1dac1_ng_hold), |
| 685 | SOC_SINGLE_TLV("AIF1DAC1 Noise Gate Threshold Volume", |
| 686 | WM8958_AIF1_DAC1_NOISE_GATE, WM8958_AIF1DAC1_NG_THR_SHIFT, |
| 687 | 7, 1, ng_tlv), |
| 688 | |
| 689 | SOC_SINGLE("AIF1DAC2 Noise Gate Switch", WM8958_AIF1_DAC2_NOISE_GATE, |
| 690 | WM8958_AIF1DAC2_NG_ENA_SHIFT, 1, 0), |
| 691 | SOC_ENUM("AIF1DAC2 Noise Gate Hold Time", wm8958_aif1dac2_ng_hold), |
| 692 | SOC_SINGLE_TLV("AIF1DAC2 Noise Gate Threshold Volume", |
| 693 | WM8958_AIF1_DAC2_NOISE_GATE, WM8958_AIF1DAC2_NG_THR_SHIFT, |
| 694 | 7, 1, ng_tlv), |
| 695 | |
| 696 | SOC_SINGLE("AIF2DAC Noise Gate Switch", WM8958_AIF2_DAC_NOISE_GATE, |
| 697 | WM8958_AIF2DAC_NG_ENA_SHIFT, 1, 0), |
| 698 | SOC_ENUM("AIF2DAC Noise Gate Hold Time", wm8958_aif2dac_ng_hold), |
| 699 | SOC_SINGLE_TLV("AIF2DAC Noise Gate Threshold Volume", |
| 700 | WM8958_AIF2_DAC_NOISE_GATE, WM8958_AIF2DAC_NG_THR_SHIFT, |
| 701 | 7, 1, ng_tlv), |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 702 | }; |
| 703 | |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 704 | static const struct snd_kcontrol_new wm1811_snd_controls[] = { |
| 705 | SOC_SINGLE_TLV("MIXINL IN1LP Boost Volume", WM8994_INPUT_MIXER_1, 7, 1, 0, |
| 706 | mixin_boost_tlv), |
| 707 | SOC_SINGLE_TLV("MIXINL IN1RP Boost Volume", WM8994_INPUT_MIXER_1, 8, 1, 0, |
| 708 | mixin_boost_tlv), |
| 709 | }; |
| 710 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 711 | static int clk_sys_event(struct snd_soc_dapm_widget *w, |
| 712 | struct snd_kcontrol *kcontrol, int event) |
| 713 | { |
| 714 | struct snd_soc_codec *codec = w->codec; |
| 715 | |
| 716 | switch (event) { |
| 717 | case SND_SOC_DAPM_PRE_PMU: |
| 718 | return configure_clock(codec); |
| 719 | |
| 720 | case SND_SOC_DAPM_POST_PMD: |
| 721 | configure_clock(codec); |
| 722 | break; |
| 723 | } |
| 724 | |
| 725 | return 0; |
| 726 | } |
| 727 | |
Mark Brown | 4b7ed83 | 2011-08-10 17:47:33 +0900 | [diff] [blame] | 728 | static void vmid_reference(struct snd_soc_codec *codec) |
| 729 | { |
| 730 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
| 731 | |
| 732 | wm8994->vmid_refcount++; |
| 733 | |
| 734 | dev_dbg(codec->dev, "Referencing VMID, refcount is now %d\n", |
| 735 | wm8994->vmid_refcount); |
| 736 | |
| 737 | if (wm8994->vmid_refcount == 1) { |
| 738 | /* Startup bias, VMID ramp & buffer */ |
| 739 | snd_soc_update_bits(codec, WM8994_ANTIPOP_2, |
| 740 | WM8994_STARTUP_BIAS_ENA | |
| 741 | WM8994_VMID_BUF_ENA | |
| 742 | WM8994_VMID_RAMP_MASK, |
| 743 | WM8994_STARTUP_BIAS_ENA | |
| 744 | WM8994_VMID_BUF_ENA | |
| 745 | (0x11 << WM8994_VMID_RAMP_SHIFT)); |
| 746 | |
| 747 | /* Main bias enable, VMID=2x40k */ |
| 748 | snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1, |
| 749 | WM8994_BIAS_ENA | |
| 750 | WM8994_VMID_SEL_MASK, |
| 751 | WM8994_BIAS_ENA | 0x2); |
| 752 | |
| 753 | msleep(20); |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | static void vmid_dereference(struct snd_soc_codec *codec) |
| 758 | { |
| 759 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
| 760 | |
| 761 | wm8994->vmid_refcount--; |
| 762 | |
| 763 | dev_dbg(codec->dev, "Dereferencing VMID, refcount is now %d\n", |
| 764 | wm8994->vmid_refcount); |
| 765 | |
| 766 | if (wm8994->vmid_refcount == 0) { |
| 767 | /* Switch over to startup biases */ |
| 768 | snd_soc_update_bits(codec, WM8994_ANTIPOP_2, |
| 769 | WM8994_BIAS_SRC | |
| 770 | WM8994_STARTUP_BIAS_ENA | |
| 771 | WM8994_VMID_BUF_ENA | |
| 772 | WM8994_VMID_RAMP_MASK, |
| 773 | WM8994_BIAS_SRC | |
| 774 | WM8994_STARTUP_BIAS_ENA | |
| 775 | WM8994_VMID_BUF_ENA | |
| 776 | (1 << WM8994_VMID_RAMP_SHIFT)); |
| 777 | |
| 778 | /* Disable main biases */ |
| 779 | snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_1, |
| 780 | WM8994_BIAS_ENA | |
| 781 | WM8994_VMID_SEL_MASK, 0); |
| 782 | |
| 783 | /* Discharge line */ |
| 784 | snd_soc_update_bits(codec, WM8994_ANTIPOP_1, |
| 785 | WM8994_LINEOUT1_DISCH | |
| 786 | WM8994_LINEOUT2_DISCH, |
| 787 | WM8994_LINEOUT1_DISCH | |
| 788 | WM8994_LINEOUT2_DISCH); |
| 789 | |
| 790 | msleep(5); |
| 791 | |
| 792 | /* Switch off startup biases */ |
| 793 | snd_soc_update_bits(codec, WM8994_ANTIPOP_2, |
| 794 | WM8994_BIAS_SRC | |
| 795 | WM8994_STARTUP_BIAS_ENA | |
| 796 | WM8994_VMID_BUF_ENA | |
| 797 | WM8994_VMID_RAMP_MASK, 0); |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | static int vmid_event(struct snd_soc_dapm_widget *w, |
| 802 | struct snd_kcontrol *kcontrol, int event) |
| 803 | { |
| 804 | struct snd_soc_codec *codec = w->codec; |
| 805 | |
| 806 | switch (event) { |
| 807 | case SND_SOC_DAPM_PRE_PMU: |
| 808 | vmid_reference(codec); |
| 809 | break; |
| 810 | |
| 811 | case SND_SOC_DAPM_POST_PMD: |
| 812 | vmid_dereference(codec); |
| 813 | break; |
| 814 | } |
| 815 | |
| 816 | return 0; |
| 817 | } |
| 818 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 819 | static void wm8994_update_class_w(struct snd_soc_codec *codec) |
| 820 | { |
Mark Brown | fec6dd8 | 2010-10-27 13:48:36 -0700 | [diff] [blame] | 821 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 822 | int enable = 1; |
| 823 | int source = 0; /* GCC flow analysis can't track enable */ |
| 824 | int reg, reg_r; |
| 825 | |
| 826 | /* Only support direct DAC->headphone paths */ |
| 827 | reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1); |
| 828 | if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) { |
Mark Brown | ee839a2 | 2010-04-20 13:57:08 +0900 | [diff] [blame] | 829 | dev_vdbg(codec->dev, "HPL connected to output mixer\n"); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 830 | enable = 0; |
| 831 | } |
| 832 | |
| 833 | reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2); |
| 834 | if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) { |
Mark Brown | ee839a2 | 2010-04-20 13:57:08 +0900 | [diff] [blame] | 835 | dev_vdbg(codec->dev, "HPR connected to output mixer\n"); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 836 | enable = 0; |
| 837 | } |
| 838 | |
| 839 | /* We also need the same setting for L/R and only one path */ |
| 840 | reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING); |
| 841 | switch (reg) { |
| 842 | case WM8994_AIF2DACL_TO_DAC1L: |
Mark Brown | ee839a2 | 2010-04-20 13:57:08 +0900 | [diff] [blame] | 843 | dev_vdbg(codec->dev, "Class W source AIF2DAC\n"); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 844 | source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT; |
| 845 | break; |
| 846 | case WM8994_AIF1DAC2L_TO_DAC1L: |
Mark Brown | ee839a2 | 2010-04-20 13:57:08 +0900 | [diff] [blame] | 847 | dev_vdbg(codec->dev, "Class W source AIF1DAC2\n"); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 848 | source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT; |
| 849 | break; |
| 850 | case WM8994_AIF1DAC1L_TO_DAC1L: |
Mark Brown | ee839a2 | 2010-04-20 13:57:08 +0900 | [diff] [blame] | 851 | dev_vdbg(codec->dev, "Class W source AIF1DAC1\n"); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 852 | source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT; |
| 853 | break; |
| 854 | default: |
Mark Brown | ee839a2 | 2010-04-20 13:57:08 +0900 | [diff] [blame] | 855 | dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 856 | enable = 0; |
| 857 | break; |
| 858 | } |
| 859 | |
| 860 | reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING); |
| 861 | if (reg_r != reg) { |
Mark Brown | ee839a2 | 2010-04-20 13:57:08 +0900 | [diff] [blame] | 862 | dev_vdbg(codec->dev, "Left and right DAC mixers different\n"); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 863 | enable = 0; |
| 864 | } |
| 865 | |
| 866 | if (enable) { |
| 867 | dev_dbg(codec->dev, "Class W enabled\n"); |
| 868 | snd_soc_update_bits(codec, WM8994_CLASS_W_1, |
| 869 | WM8994_CP_DYN_PWR | |
| 870 | WM8994_CP_DYN_SRC_SEL_MASK, |
| 871 | source | WM8994_CP_DYN_PWR); |
Mark Brown | fec6dd8 | 2010-10-27 13:48:36 -0700 | [diff] [blame] | 872 | wm8994->hubs.class_w = true; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 873 | |
| 874 | } else { |
| 875 | dev_dbg(codec->dev, "Class W disabled\n"); |
| 876 | snd_soc_update_bits(codec, WM8994_CLASS_W_1, |
| 877 | WM8994_CP_DYN_PWR, 0); |
Mark Brown | fec6dd8 | 2010-10-27 13:48:36 -0700 | [diff] [blame] | 878 | wm8994->hubs.class_w = false; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 882 | static int late_enable_ev(struct snd_soc_dapm_widget *w, |
| 883 | struct snd_kcontrol *kcontrol, int event) |
| 884 | { |
| 885 | struct snd_soc_codec *codec = w->codec; |
| 886 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
| 887 | |
| 888 | switch (event) { |
| 889 | case SND_SOC_DAPM_PRE_PMU: |
Dimitris Papastamos | a3cff81 | 2011-02-28 17:24:11 +0000 | [diff] [blame] | 890 | if (wm8994->aif1clk_enable) { |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 891 | snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1, |
| 892 | WM8994_AIF1CLK_ENA_MASK, |
| 893 | WM8994_AIF1CLK_ENA); |
Dimitris Papastamos | a3cff81 | 2011-02-28 17:24:11 +0000 | [diff] [blame] | 894 | wm8994->aif1clk_enable = 0; |
| 895 | } |
| 896 | if (wm8994->aif2clk_enable) { |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 897 | snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1, |
| 898 | WM8994_AIF2CLK_ENA_MASK, |
| 899 | WM8994_AIF2CLK_ENA); |
Dimitris Papastamos | a3cff81 | 2011-02-28 17:24:11 +0000 | [diff] [blame] | 900 | wm8994->aif2clk_enable = 0; |
| 901 | } |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 902 | break; |
| 903 | } |
| 904 | |
Mark Brown | c6b7b57 | 2011-03-11 18:13:12 +0000 | [diff] [blame] | 905 | /* We may also have postponed startup of DSP, handle that. */ |
| 906 | wm8958_aif_ev(w, kcontrol, event); |
| 907 | |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | static int late_disable_ev(struct snd_soc_dapm_widget *w, |
| 912 | struct snd_kcontrol *kcontrol, int event) |
| 913 | { |
| 914 | struct snd_soc_codec *codec = w->codec; |
| 915 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
| 916 | |
| 917 | switch (event) { |
| 918 | case SND_SOC_DAPM_POST_PMD: |
Dimitris Papastamos | a3cff81 | 2011-02-28 17:24:11 +0000 | [diff] [blame] | 919 | if (wm8994->aif1clk_disable) { |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 920 | snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1, |
| 921 | WM8994_AIF1CLK_ENA_MASK, 0); |
Dimitris Papastamos | a3cff81 | 2011-02-28 17:24:11 +0000 | [diff] [blame] | 922 | wm8994->aif1clk_disable = 0; |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 923 | } |
Dimitris Papastamos | a3cff81 | 2011-02-28 17:24:11 +0000 | [diff] [blame] | 924 | if (wm8994->aif2clk_disable) { |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 925 | snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1, |
| 926 | WM8994_AIF2CLK_ENA_MASK, 0); |
Dimitris Papastamos | a3cff81 | 2011-02-28 17:24:11 +0000 | [diff] [blame] | 927 | wm8994->aif2clk_disable = 0; |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 928 | } |
| 929 | break; |
| 930 | } |
| 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | |
| 935 | static int aif1clk_ev(struct snd_soc_dapm_widget *w, |
| 936 | struct snd_kcontrol *kcontrol, int event) |
| 937 | { |
| 938 | struct snd_soc_codec *codec = w->codec; |
| 939 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
| 940 | |
| 941 | switch (event) { |
| 942 | case SND_SOC_DAPM_PRE_PMU: |
| 943 | wm8994->aif1clk_enable = 1; |
| 944 | break; |
Dimitris Papastamos | a3cff81 | 2011-02-28 17:24:11 +0000 | [diff] [blame] | 945 | case SND_SOC_DAPM_POST_PMD: |
| 946 | wm8994->aif1clk_disable = 1; |
| 947 | break; |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | return 0; |
| 951 | } |
| 952 | |
| 953 | static int aif2clk_ev(struct snd_soc_dapm_widget *w, |
| 954 | struct snd_kcontrol *kcontrol, int event) |
| 955 | { |
| 956 | struct snd_soc_codec *codec = w->codec; |
| 957 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
| 958 | |
| 959 | switch (event) { |
| 960 | case SND_SOC_DAPM_PRE_PMU: |
| 961 | wm8994->aif2clk_enable = 1; |
| 962 | break; |
Dimitris Papastamos | a3cff81 | 2011-02-28 17:24:11 +0000 | [diff] [blame] | 963 | case SND_SOC_DAPM_POST_PMD: |
| 964 | wm8994->aif2clk_disable = 1; |
| 965 | break; |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | return 0; |
| 969 | } |
| 970 | |
Dimitris Papastamos | 04d2868 | 2011-03-01 11:47:10 +0000 | [diff] [blame] | 971 | static int adc_mux_ev(struct snd_soc_dapm_widget *w, |
| 972 | struct snd_kcontrol *kcontrol, int event) |
| 973 | { |
| 974 | late_enable_ev(w, kcontrol, event); |
| 975 | return 0; |
| 976 | } |
| 977 | |
Dimitris Papastamos | b462c6e | 2011-03-01 12:54:39 +0000 | [diff] [blame] | 978 | static int micbias_ev(struct snd_soc_dapm_widget *w, |
| 979 | struct snd_kcontrol *kcontrol, int event) |
| 980 | { |
| 981 | late_enable_ev(w, kcontrol, event); |
| 982 | return 0; |
| 983 | } |
| 984 | |
Dimitris Papastamos | c52fd02 | 2011-02-11 16:32:12 +0000 | [diff] [blame] | 985 | static int dac_ev(struct snd_soc_dapm_widget *w, |
| 986 | struct snd_kcontrol *kcontrol, int event) |
| 987 | { |
| 988 | struct snd_soc_codec *codec = w->codec; |
| 989 | unsigned int mask = 1 << w->shift; |
| 990 | |
| 991 | snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5, |
| 992 | mask, mask); |
| 993 | return 0; |
| 994 | } |
| 995 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 996 | static const char *hp_mux_text[] = { |
| 997 | "Mixer", |
| 998 | "DAC", |
| 999 | }; |
| 1000 | |
| 1001 | #define WM8994_HP_ENUM(xname, xenum) \ |
| 1002 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1003 | .info = snd_soc_info_enum_double, \ |
| 1004 | .get = snd_soc_dapm_get_enum_double, \ |
| 1005 | .put = wm8994_put_hp_enum, \ |
| 1006 | .private_value = (unsigned long)&xenum } |
| 1007 | |
| 1008 | static int wm8994_put_hp_enum(struct snd_kcontrol *kcontrol, |
| 1009 | struct snd_ctl_elem_value *ucontrol) |
| 1010 | { |
Jarkko Nikula | 9d03545 | 2011-05-13 19:16:52 +0300 | [diff] [blame] | 1011 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1012 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1013 | struct snd_soc_codec *codec = w->codec; |
| 1014 | int ret; |
| 1015 | |
| 1016 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 1017 | |
| 1018 | wm8994_update_class_w(codec); |
| 1019 | |
| 1020 | return ret; |
| 1021 | } |
| 1022 | |
| 1023 | static const struct soc_enum hpl_enum = |
| 1024 | SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_1, 8, 2, hp_mux_text); |
| 1025 | |
| 1026 | static const struct snd_kcontrol_new hpl_mux = |
| 1027 | WM8994_HP_ENUM("Left Headphone Mux", hpl_enum); |
| 1028 | |
| 1029 | static const struct soc_enum hpr_enum = |
| 1030 | SOC_ENUM_SINGLE(WM8994_OUTPUT_MIXER_2, 8, 2, hp_mux_text); |
| 1031 | |
| 1032 | static const struct snd_kcontrol_new hpr_mux = |
| 1033 | WM8994_HP_ENUM("Right Headphone Mux", hpr_enum); |
| 1034 | |
| 1035 | static const char *adc_mux_text[] = { |
| 1036 | "ADC", |
| 1037 | "DMIC", |
| 1038 | }; |
| 1039 | |
| 1040 | static const struct soc_enum adc_enum = |
| 1041 | SOC_ENUM_SINGLE(0, 0, 2, adc_mux_text); |
| 1042 | |
| 1043 | static const struct snd_kcontrol_new adcl_mux = |
| 1044 | SOC_DAPM_ENUM_VIRT("ADCL Mux", adc_enum); |
| 1045 | |
| 1046 | static const struct snd_kcontrol_new adcr_mux = |
| 1047 | SOC_DAPM_ENUM_VIRT("ADCR Mux", adc_enum); |
| 1048 | |
| 1049 | static const struct snd_kcontrol_new left_speaker_mixer[] = { |
| 1050 | SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 9, 1, 0), |
| 1051 | SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 7, 1, 0), |
| 1052 | SOC_DAPM_SINGLE("IN1LP Switch", WM8994_SPEAKER_MIXER, 5, 1, 0), |
| 1053 | SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 3, 1, 0), |
| 1054 | SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 1, 1, 0), |
| 1055 | }; |
| 1056 | |
| 1057 | static const struct snd_kcontrol_new right_speaker_mixer[] = { |
| 1058 | SOC_DAPM_SINGLE("DAC2 Switch", WM8994_SPEAKER_MIXER, 8, 1, 0), |
| 1059 | SOC_DAPM_SINGLE("Input Switch", WM8994_SPEAKER_MIXER, 6, 1, 0), |
| 1060 | SOC_DAPM_SINGLE("IN1RP Switch", WM8994_SPEAKER_MIXER, 4, 1, 0), |
| 1061 | SOC_DAPM_SINGLE("Output Switch", WM8994_SPEAKER_MIXER, 2, 1, 0), |
| 1062 | SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0), |
| 1063 | }; |
| 1064 | |
| 1065 | /* Debugging; dump chip status after DAPM transitions */ |
| 1066 | static int post_ev(struct snd_soc_dapm_widget *w, |
| 1067 | struct snd_kcontrol *kcontrol, int event) |
| 1068 | { |
| 1069 | struct snd_soc_codec *codec = w->codec; |
| 1070 | dev_dbg(codec->dev, "SRC status: %x\n", |
| 1071 | snd_soc_read(codec, |
| 1072 | WM8994_RATE_STATUS)); |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
| 1076 | static const struct snd_kcontrol_new aif1adc1l_mix[] = { |
| 1077 | SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING, |
| 1078 | 1, 1, 0), |
| 1079 | SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_LEFT_MIXER_ROUTING, |
| 1080 | 0, 1, 0), |
| 1081 | }; |
| 1082 | |
| 1083 | static const struct snd_kcontrol_new aif1adc1r_mix[] = { |
| 1084 | SOC_DAPM_SINGLE("ADC/DMIC Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING, |
| 1085 | 1, 1, 0), |
| 1086 | SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC1_RIGHT_MIXER_ROUTING, |
| 1087 | 0, 1, 0), |
| 1088 | }; |
| 1089 | |
Mark Brown | a3257ba | 2010-07-19 14:02:34 +0100 | [diff] [blame] | 1090 | static const struct snd_kcontrol_new aif1adc2l_mix[] = { |
| 1091 | SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING, |
| 1092 | 1, 1, 0), |
| 1093 | SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_LEFT_MIXER_ROUTING, |
| 1094 | 0, 1, 0), |
| 1095 | }; |
| 1096 | |
| 1097 | static const struct snd_kcontrol_new aif1adc2r_mix[] = { |
| 1098 | SOC_DAPM_SINGLE("DMIC Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING, |
| 1099 | 1, 1, 0), |
| 1100 | SOC_DAPM_SINGLE("AIF2 Switch", WM8994_AIF1_ADC2_RIGHT_MIXER_ROUTING, |
| 1101 | 0, 1, 0), |
| 1102 | }; |
| 1103 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1104 | static const struct snd_kcontrol_new aif2dac2l_mix[] = { |
| 1105 | SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING, |
| 1106 | 5, 1, 0), |
| 1107 | SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_LEFT_MIXER_ROUTING, |
| 1108 | 4, 1, 0), |
| 1109 | SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING, |
| 1110 | 2, 1, 0), |
| 1111 | SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING, |
| 1112 | 1, 1, 0), |
| 1113 | SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_LEFT_MIXER_ROUTING, |
| 1114 | 0, 1, 0), |
| 1115 | }; |
| 1116 | |
| 1117 | static const struct snd_kcontrol_new aif2dac2r_mix[] = { |
| 1118 | SOC_DAPM_SINGLE("Right Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING, |
| 1119 | 5, 1, 0), |
| 1120 | SOC_DAPM_SINGLE("Left Sidetone Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING, |
| 1121 | 4, 1, 0), |
| 1122 | SOC_DAPM_SINGLE("AIF2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING, |
| 1123 | 2, 1, 0), |
| 1124 | SOC_DAPM_SINGLE("AIF1.2 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING, |
| 1125 | 1, 1, 0), |
| 1126 | SOC_DAPM_SINGLE("AIF1.1 Switch", WM8994_DAC2_RIGHT_MIXER_ROUTING, |
| 1127 | 0, 1, 0), |
| 1128 | }; |
| 1129 | |
| 1130 | #define WM8994_CLASS_W_SWITCH(xname, reg, shift, max, invert) \ |
| 1131 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 1132 | .info = snd_soc_info_volsw, \ |
| 1133 | .get = snd_soc_dapm_get_volsw, .put = wm8994_put_class_w, \ |
| 1134 | .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) } |
| 1135 | |
| 1136 | static int wm8994_put_class_w(struct snd_kcontrol *kcontrol, |
| 1137 | struct snd_ctl_elem_value *ucontrol) |
| 1138 | { |
Jarkko Nikula | 9d03545 | 2011-05-13 19:16:52 +0300 | [diff] [blame] | 1139 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 1140 | struct snd_soc_dapm_widget *w = wlist->widgets[0]; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1141 | struct snd_soc_codec *codec = w->codec; |
| 1142 | int ret; |
| 1143 | |
| 1144 | ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); |
| 1145 | |
| 1146 | wm8994_update_class_w(codec); |
| 1147 | |
| 1148 | return ret; |
| 1149 | } |
| 1150 | |
| 1151 | static const struct snd_kcontrol_new dac1l_mix[] = { |
| 1152 | WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING, |
| 1153 | 5, 1, 0), |
| 1154 | WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_LEFT_MIXER_ROUTING, |
| 1155 | 4, 1, 0), |
| 1156 | WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING, |
| 1157 | 2, 1, 0), |
| 1158 | WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING, |
| 1159 | 1, 1, 0), |
| 1160 | WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_LEFT_MIXER_ROUTING, |
| 1161 | 0, 1, 0), |
| 1162 | }; |
| 1163 | |
| 1164 | static const struct snd_kcontrol_new dac1r_mix[] = { |
| 1165 | WM8994_CLASS_W_SWITCH("Right Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING, |
| 1166 | 5, 1, 0), |
| 1167 | WM8994_CLASS_W_SWITCH("Left Sidetone Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING, |
| 1168 | 4, 1, 0), |
| 1169 | WM8994_CLASS_W_SWITCH("AIF2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING, |
| 1170 | 2, 1, 0), |
| 1171 | WM8994_CLASS_W_SWITCH("AIF1.2 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING, |
| 1172 | 1, 1, 0), |
| 1173 | WM8994_CLASS_W_SWITCH("AIF1.1 Switch", WM8994_DAC1_RIGHT_MIXER_ROUTING, |
| 1174 | 0, 1, 0), |
| 1175 | }; |
| 1176 | |
| 1177 | static const char *sidetone_text[] = { |
| 1178 | "ADC/DMIC1", "DMIC2", |
| 1179 | }; |
| 1180 | |
| 1181 | static const struct soc_enum sidetone1_enum = |
| 1182 | SOC_ENUM_SINGLE(WM8994_SIDETONE, 0, 2, sidetone_text); |
| 1183 | |
| 1184 | static const struct snd_kcontrol_new sidetone1_mux = |
| 1185 | SOC_DAPM_ENUM("Left Sidetone Mux", sidetone1_enum); |
| 1186 | |
| 1187 | static const struct soc_enum sidetone2_enum = |
| 1188 | SOC_ENUM_SINGLE(WM8994_SIDETONE, 1, 2, sidetone_text); |
| 1189 | |
| 1190 | static const struct snd_kcontrol_new sidetone2_mux = |
| 1191 | SOC_DAPM_ENUM("Right Sidetone Mux", sidetone2_enum); |
| 1192 | |
| 1193 | static const char *aif1dac_text[] = { |
| 1194 | "AIF1DACDAT", "AIF3DACDAT", |
| 1195 | }; |
| 1196 | |
| 1197 | static const struct soc_enum aif1dac_enum = |
| 1198 | SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 0, 2, aif1dac_text); |
| 1199 | |
| 1200 | static const struct snd_kcontrol_new aif1dac_mux = |
| 1201 | SOC_DAPM_ENUM("AIF1DAC Mux", aif1dac_enum); |
| 1202 | |
| 1203 | static const char *aif2dac_text[] = { |
| 1204 | "AIF2DACDAT", "AIF3DACDAT", |
| 1205 | }; |
| 1206 | |
| 1207 | static const struct soc_enum aif2dac_enum = |
| 1208 | SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 1, 2, aif2dac_text); |
| 1209 | |
| 1210 | static const struct snd_kcontrol_new aif2dac_mux = |
| 1211 | SOC_DAPM_ENUM("AIF2DAC Mux", aif2dac_enum); |
| 1212 | |
| 1213 | static const char *aif2adc_text[] = { |
| 1214 | "AIF2ADCDAT", "AIF3DACDAT", |
| 1215 | }; |
| 1216 | |
| 1217 | static const struct soc_enum aif2adc_enum = |
| 1218 | SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 2, 2, aif2adc_text); |
| 1219 | |
| 1220 | static const struct snd_kcontrol_new aif2adc_mux = |
| 1221 | SOC_DAPM_ENUM("AIF2ADC Mux", aif2adc_enum); |
| 1222 | |
| 1223 | static const char *aif3adc_text[] = { |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 1224 | "AIF1ADCDAT", "AIF2ADCDAT", "AIF2DACDAT", "Mono PCM", |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1225 | }; |
| 1226 | |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 1227 | static const struct soc_enum wm8994_aif3adc_enum = |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1228 | SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 3, aif3adc_text); |
| 1229 | |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 1230 | static const struct snd_kcontrol_new wm8994_aif3adc_mux = |
| 1231 | SOC_DAPM_ENUM("AIF3ADC Mux", wm8994_aif3adc_enum); |
| 1232 | |
| 1233 | static const struct soc_enum wm8958_aif3adc_enum = |
| 1234 | SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 3, 4, aif3adc_text); |
| 1235 | |
| 1236 | static const struct snd_kcontrol_new wm8958_aif3adc_mux = |
| 1237 | SOC_DAPM_ENUM("AIF3ADC Mux", wm8958_aif3adc_enum); |
| 1238 | |
| 1239 | static const char *mono_pcm_out_text[] = { |
| 1240 | "None", "AIF2ADCL", "AIF2ADCR", |
| 1241 | }; |
| 1242 | |
| 1243 | static const struct soc_enum mono_pcm_out_enum = |
| 1244 | SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 9, 3, mono_pcm_out_text); |
| 1245 | |
| 1246 | static const struct snd_kcontrol_new mono_pcm_out_mux = |
| 1247 | SOC_DAPM_ENUM("Mono PCM Out Mux", mono_pcm_out_enum); |
| 1248 | |
| 1249 | static const char *aif2dac_src_text[] = { |
| 1250 | "AIF2", "AIF3", |
| 1251 | }; |
| 1252 | |
| 1253 | /* Note that these two control shouldn't be simultaneously switched to AIF3 */ |
| 1254 | static const struct soc_enum aif2dacl_src_enum = |
| 1255 | SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 7, 2, aif2dac_src_text); |
| 1256 | |
| 1257 | static const struct snd_kcontrol_new aif2dacl_src_mux = |
| 1258 | SOC_DAPM_ENUM("AIF2DACL Mux", aif2dacl_src_enum); |
| 1259 | |
| 1260 | static const struct soc_enum aif2dacr_src_enum = |
| 1261 | SOC_ENUM_SINGLE(WM8994_POWER_MANAGEMENT_6, 8, 2, aif2dac_src_text); |
| 1262 | |
| 1263 | static const struct snd_kcontrol_new aif2dacr_src_mux = |
| 1264 | SOC_DAPM_ENUM("AIF2DACR Mux", aif2dacr_src_enum); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1265 | |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 1266 | static const struct snd_soc_dapm_widget wm8994_lateclk_revd_widgets[] = { |
| 1267 | SND_SOC_DAPM_SUPPLY("AIF1CLK", SND_SOC_NOPM, 0, 0, aif1clk_ev, |
| 1268 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1269 | SND_SOC_DAPM_SUPPLY("AIF2CLK", SND_SOC_NOPM, 0, 0, aif2clk_ev, |
| 1270 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 1271 | |
| 1272 | SND_SOC_DAPM_PGA_E("Late DAC1L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 1273 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
| 1274 | SND_SOC_DAPM_PGA_E("Late DAC1R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 1275 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
| 1276 | SND_SOC_DAPM_PGA_E("Late DAC2L Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 1277 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
| 1278 | SND_SOC_DAPM_PGA_E("Late DAC2R Enable PGA", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 1279 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
Mark Brown | b70a51b | 2011-06-29 00:21:09 -0700 | [diff] [blame] | 1280 | SND_SOC_DAPM_PGA_E("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 1281 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
| 1282 | |
| 1283 | SND_SOC_DAPM_MIXER_E("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0, |
| 1284 | left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer), |
| 1285 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
| 1286 | SND_SOC_DAPM_MIXER_E("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0, |
| 1287 | right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer), |
| 1288 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
| 1289 | SND_SOC_DAPM_MUX_E("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux, |
| 1290 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
| 1291 | SND_SOC_DAPM_MUX_E("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux, |
| 1292 | late_enable_ev, SND_SOC_DAPM_PRE_PMU), |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 1293 | |
| 1294 | SND_SOC_DAPM_POST("Late Disable PGA", late_disable_ev) |
| 1295 | }; |
| 1296 | |
| 1297 | static const struct snd_soc_dapm_widget wm8994_lateclk_widgets[] = { |
| 1298 | SND_SOC_DAPM_SUPPLY("AIF1CLK", WM8994_AIF1_CLOCKING_1, 0, 0, NULL, 0), |
Mark Brown | b70a51b | 2011-06-29 00:21:09 -0700 | [diff] [blame] | 1299 | SND_SOC_DAPM_SUPPLY("AIF2CLK", WM8994_AIF2_CLOCKING_1, 0, 0, NULL, 0), |
| 1300 | SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 1301 | SND_SOC_DAPM_MIXER("SPKL", WM8994_POWER_MANAGEMENT_3, 8, 0, |
| 1302 | left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)), |
| 1303 | SND_SOC_DAPM_MIXER("SPKR", WM8994_POWER_MANAGEMENT_3, 9, 0, |
| 1304 | right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)), |
| 1305 | SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux), |
| 1306 | SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux), |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 1307 | }; |
| 1308 | |
Dimitris Papastamos | c52fd02 | 2011-02-11 16:32:12 +0000 | [diff] [blame] | 1309 | static const struct snd_soc_dapm_widget wm8994_dac_revd_widgets[] = { |
| 1310 | SND_SOC_DAPM_DAC_E("DAC2L", NULL, SND_SOC_NOPM, 3, 0, |
| 1311 | dac_ev, SND_SOC_DAPM_PRE_PMU), |
| 1312 | SND_SOC_DAPM_DAC_E("DAC2R", NULL, SND_SOC_NOPM, 2, 0, |
| 1313 | dac_ev, SND_SOC_DAPM_PRE_PMU), |
| 1314 | SND_SOC_DAPM_DAC_E("DAC1L", NULL, SND_SOC_NOPM, 1, 0, |
| 1315 | dac_ev, SND_SOC_DAPM_PRE_PMU), |
| 1316 | SND_SOC_DAPM_DAC_E("DAC1R", NULL, SND_SOC_NOPM, 0, 0, |
| 1317 | dac_ev, SND_SOC_DAPM_PRE_PMU), |
| 1318 | }; |
| 1319 | |
| 1320 | static const struct snd_soc_dapm_widget wm8994_dac_widgets[] = { |
| 1321 | SND_SOC_DAPM_DAC("DAC2L", NULL, WM8994_POWER_MANAGEMENT_5, 3, 0), |
Mark Brown | 0627bd2 | 2011-03-09 19:09:17 +0000 | [diff] [blame] | 1322 | SND_SOC_DAPM_DAC("DAC2R", NULL, WM8994_POWER_MANAGEMENT_5, 2, 0), |
Dimitris Papastamos | c52fd02 | 2011-02-11 16:32:12 +0000 | [diff] [blame] | 1323 | SND_SOC_DAPM_DAC("DAC1L", NULL, WM8994_POWER_MANAGEMENT_5, 1, 0), |
| 1324 | SND_SOC_DAPM_DAC("DAC1R", NULL, WM8994_POWER_MANAGEMENT_5, 0, 0), |
| 1325 | }; |
| 1326 | |
Dimitris Papastamos | 04d2868 | 2011-03-01 11:47:10 +0000 | [diff] [blame] | 1327 | static const struct snd_soc_dapm_widget wm8994_adc_revd_widgets[] = { |
| 1328 | SND_SOC_DAPM_MUX_E("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux, |
| 1329 | adc_mux_ev, SND_SOC_DAPM_PRE_PMU), |
| 1330 | SND_SOC_DAPM_MUX_E("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux, |
| 1331 | adc_mux_ev, SND_SOC_DAPM_PRE_PMU), |
| 1332 | }; |
| 1333 | |
| 1334 | static const struct snd_soc_dapm_widget wm8994_adc_widgets[] = { |
| 1335 | SND_SOC_DAPM_MUX("ADCL Mux", WM8994_POWER_MANAGEMENT_4, 1, 0, &adcl_mux), |
| 1336 | SND_SOC_DAPM_MUX("ADCR Mux", WM8994_POWER_MANAGEMENT_4, 0, 0, &adcr_mux), |
| 1337 | }; |
| 1338 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1339 | static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = { |
| 1340 | SND_SOC_DAPM_INPUT("DMIC1DAT"), |
| 1341 | SND_SOC_DAPM_INPUT("DMIC2DAT"), |
Mark Brown | 66b47fd | 2010-07-08 11:25:43 +0900 | [diff] [blame] | 1342 | SND_SOC_DAPM_INPUT("Clock"), |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1343 | |
Dimitris Papastamos | b462c6e | 2011-03-01 12:54:39 +0000 | [diff] [blame] | 1344 | SND_SOC_DAPM_SUPPLY_S("MICBIAS Supply", 1, SND_SOC_NOPM, 0, 0, micbias_ev, |
| 1345 | SND_SOC_DAPM_PRE_PMU), |
Mark Brown | 4b7ed83 | 2011-08-10 17:47:33 +0900 | [diff] [blame] | 1346 | SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, vmid_event, |
| 1347 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
Dimitris Papastamos | b462c6e | 2011-03-01 12:54:39 +0000 | [diff] [blame] | 1348 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1349 | SND_SOC_DAPM_SUPPLY("CLK_SYS", SND_SOC_NOPM, 0, 0, clk_sys_event, |
| 1350 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1351 | |
| 1352 | SND_SOC_DAPM_SUPPLY("DSP1CLK", WM8994_CLOCKING_1, 3, 0, NULL, 0), |
| 1353 | SND_SOC_DAPM_SUPPLY("DSP2CLK", WM8994_CLOCKING_1, 2, 0, NULL, 0), |
| 1354 | SND_SOC_DAPM_SUPPLY("DSPINTCLK", WM8994_CLOCKING_1, 1, 0, NULL, 0), |
| 1355 | |
Mark Brown | 7f94de4 | 2011-02-03 16:27:34 +0000 | [diff] [blame] | 1356 | SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", NULL, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1357 | 0, WM8994_POWER_MANAGEMENT_4, 9, 0), |
Mark Brown | 7f94de4 | 2011-02-03 16:27:34 +0000 | [diff] [blame] | 1358 | SND_SOC_DAPM_AIF_OUT("AIF1ADC1R", NULL, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1359 | 0, WM8994_POWER_MANAGEMENT_4, 8, 0), |
Mark Brown | d6addcc | 2010-11-26 15:21:08 +0000 | [diff] [blame] | 1360 | SND_SOC_DAPM_AIF_IN_E("AIF1DAC1L", NULL, 0, |
| 1361 | WM8994_POWER_MANAGEMENT_5, 9, 0, wm8958_aif_ev, |
Mark Brown | b2822a8 | 2010-11-30 16:59:29 +0000 | [diff] [blame] | 1362 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Mark Brown | d6addcc | 2010-11-26 15:21:08 +0000 | [diff] [blame] | 1363 | SND_SOC_DAPM_AIF_IN_E("AIF1DAC1R", NULL, 0, |
| 1364 | WM8994_POWER_MANAGEMENT_5, 8, 0, wm8958_aif_ev, |
Mark Brown | b2822a8 | 2010-11-30 16:59:29 +0000 | [diff] [blame] | 1365 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1366 | |
Mark Brown | 7f94de4 | 2011-02-03 16:27:34 +0000 | [diff] [blame] | 1367 | SND_SOC_DAPM_AIF_OUT("AIF1ADC2L", NULL, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1368 | 0, WM8994_POWER_MANAGEMENT_4, 11, 0), |
Mark Brown | 7f94de4 | 2011-02-03 16:27:34 +0000 | [diff] [blame] | 1369 | SND_SOC_DAPM_AIF_OUT("AIF1ADC2R", NULL, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1370 | 0, WM8994_POWER_MANAGEMENT_4, 10, 0), |
Mark Brown | d6addcc | 2010-11-26 15:21:08 +0000 | [diff] [blame] | 1371 | SND_SOC_DAPM_AIF_IN_E("AIF1DAC2L", NULL, 0, |
| 1372 | WM8994_POWER_MANAGEMENT_5, 11, 0, wm8958_aif_ev, |
Mark Brown | b2822a8 | 2010-11-30 16:59:29 +0000 | [diff] [blame] | 1373 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Mark Brown | d6addcc | 2010-11-26 15:21:08 +0000 | [diff] [blame] | 1374 | SND_SOC_DAPM_AIF_IN_E("AIF1DAC2R", NULL, 0, |
| 1375 | WM8994_POWER_MANAGEMENT_5, 10, 0, wm8958_aif_ev, |
Mark Brown | b2822a8 | 2010-11-30 16:59:29 +0000 | [diff] [blame] | 1376 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1377 | |
| 1378 | SND_SOC_DAPM_MIXER("AIF1ADC1L Mixer", SND_SOC_NOPM, 0, 0, |
| 1379 | aif1adc1l_mix, ARRAY_SIZE(aif1adc1l_mix)), |
| 1380 | SND_SOC_DAPM_MIXER("AIF1ADC1R Mixer", SND_SOC_NOPM, 0, 0, |
| 1381 | aif1adc1r_mix, ARRAY_SIZE(aif1adc1r_mix)), |
| 1382 | |
Mark Brown | a3257ba | 2010-07-19 14:02:34 +0100 | [diff] [blame] | 1383 | SND_SOC_DAPM_MIXER("AIF1ADC2L Mixer", SND_SOC_NOPM, 0, 0, |
| 1384 | aif1adc2l_mix, ARRAY_SIZE(aif1adc2l_mix)), |
| 1385 | SND_SOC_DAPM_MIXER("AIF1ADC2R Mixer", SND_SOC_NOPM, 0, 0, |
| 1386 | aif1adc2r_mix, ARRAY_SIZE(aif1adc2r_mix)), |
| 1387 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1388 | SND_SOC_DAPM_MIXER("AIF2DAC2L Mixer", SND_SOC_NOPM, 0, 0, |
| 1389 | aif2dac2l_mix, ARRAY_SIZE(aif2dac2l_mix)), |
| 1390 | SND_SOC_DAPM_MIXER("AIF2DAC2R Mixer", SND_SOC_NOPM, 0, 0, |
| 1391 | aif2dac2r_mix, ARRAY_SIZE(aif2dac2r_mix)), |
| 1392 | |
| 1393 | SND_SOC_DAPM_MUX("Left Sidetone", SND_SOC_NOPM, 0, 0, &sidetone1_mux), |
| 1394 | SND_SOC_DAPM_MUX("Right Sidetone", SND_SOC_NOPM, 0, 0, &sidetone2_mux), |
| 1395 | |
| 1396 | SND_SOC_DAPM_MIXER("DAC1L Mixer", SND_SOC_NOPM, 0, 0, |
| 1397 | dac1l_mix, ARRAY_SIZE(dac1l_mix)), |
| 1398 | SND_SOC_DAPM_MIXER("DAC1R Mixer", SND_SOC_NOPM, 0, 0, |
| 1399 | dac1r_mix, ARRAY_SIZE(dac1r_mix)), |
| 1400 | |
| 1401 | SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0, |
| 1402 | WM8994_POWER_MANAGEMENT_4, 13, 0), |
| 1403 | SND_SOC_DAPM_AIF_OUT("AIF2ADCR", NULL, 0, |
| 1404 | WM8994_POWER_MANAGEMENT_4, 12, 0), |
Mark Brown | d6addcc | 2010-11-26 15:21:08 +0000 | [diff] [blame] | 1405 | SND_SOC_DAPM_AIF_IN_E("AIF2DACL", NULL, 0, |
| 1406 | WM8994_POWER_MANAGEMENT_5, 13, 0, wm8958_aif_ev, |
| 1407 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 1408 | SND_SOC_DAPM_AIF_IN_E("AIF2DACR", NULL, 0, |
| 1409 | WM8994_POWER_MANAGEMENT_5, 12, 0, wm8958_aif_ev, |
| 1410 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1411 | |
| 1412 | SND_SOC_DAPM_AIF_IN("AIF1DACDAT", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), |
| 1413 | SND_SOC_DAPM_AIF_IN("AIF2DACDAT", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0), |
Mark Brown | 7f94de4 | 2011-02-03 16:27:34 +0000 | [diff] [blame] | 1414 | SND_SOC_DAPM_AIF_OUT("AIF1ADCDAT", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0), |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1415 | SND_SOC_DAPM_AIF_OUT("AIF2ADCDAT", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0), |
| 1416 | |
| 1417 | SND_SOC_DAPM_MUX("AIF1DAC Mux", SND_SOC_NOPM, 0, 0, &aif1dac_mux), |
| 1418 | SND_SOC_DAPM_MUX("AIF2DAC Mux", SND_SOC_NOPM, 0, 0, &aif2dac_mux), |
| 1419 | SND_SOC_DAPM_MUX("AIF2ADC Mux", SND_SOC_NOPM, 0, 0, &aif2adc_mux), |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1420 | |
| 1421 | SND_SOC_DAPM_AIF_IN("AIF3DACDAT", "AIF3 Playback", 0, SND_SOC_NOPM, 0, 0), |
Axel Lin | 35024f4 | 2011-10-20 12:13:24 +0800 | [diff] [blame] | 1422 | SND_SOC_DAPM_AIF_OUT("AIF3ADCDAT", "AIF3 Capture", 0, SND_SOC_NOPM, 0, 0), |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1423 | |
| 1424 | SND_SOC_DAPM_SUPPLY("TOCLK", WM8994_CLOCKING_1, 4, 0, NULL, 0), |
| 1425 | |
| 1426 | SND_SOC_DAPM_ADC("DMIC2L", NULL, WM8994_POWER_MANAGEMENT_4, 5, 0), |
| 1427 | SND_SOC_DAPM_ADC("DMIC2R", NULL, WM8994_POWER_MANAGEMENT_4, 4, 0), |
| 1428 | SND_SOC_DAPM_ADC("DMIC1L", NULL, WM8994_POWER_MANAGEMENT_4, 3, 0), |
| 1429 | SND_SOC_DAPM_ADC("DMIC1R", NULL, WM8994_POWER_MANAGEMENT_4, 2, 0), |
| 1430 | |
| 1431 | /* Power is done with the muxes since the ADC power also controls the |
| 1432 | * downsampling chain, the chip will automatically manage the analogue |
| 1433 | * specific portions. |
| 1434 | */ |
| 1435 | SND_SOC_DAPM_ADC("ADCL", NULL, SND_SOC_NOPM, 1, 0), |
| 1436 | SND_SOC_DAPM_ADC("ADCR", NULL, SND_SOC_NOPM, 0, 0), |
| 1437 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1438 | SND_SOC_DAPM_POST("Debug log", post_ev), |
| 1439 | }; |
| 1440 | |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 1441 | static const struct snd_soc_dapm_widget wm8994_specific_dapm_widgets[] = { |
| 1442 | SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8994_aif3adc_mux), |
| 1443 | }; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1444 | |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 1445 | static const struct snd_soc_dapm_widget wm8958_dapm_widgets[] = { |
| 1446 | SND_SOC_DAPM_MUX("Mono PCM Out Mux", SND_SOC_NOPM, 0, 0, &mono_pcm_out_mux), |
| 1447 | SND_SOC_DAPM_MUX("AIF2DACL Mux", SND_SOC_NOPM, 0, 0, &aif2dacl_src_mux), |
| 1448 | SND_SOC_DAPM_MUX("AIF2DACR Mux", SND_SOC_NOPM, 0, 0, &aif2dacr_src_mux), |
| 1449 | SND_SOC_DAPM_MUX("AIF3ADC Mux", SND_SOC_NOPM, 0, 0, &wm8958_aif3adc_mux), |
| 1450 | }; |
| 1451 | |
| 1452 | static const struct snd_soc_dapm_route intercon[] = { |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1453 | { "CLK_SYS", NULL, "AIF1CLK", check_clk_sys }, |
| 1454 | { "CLK_SYS", NULL, "AIF2CLK", check_clk_sys }, |
| 1455 | |
| 1456 | { "DSP1CLK", NULL, "CLK_SYS" }, |
| 1457 | { "DSP2CLK", NULL, "CLK_SYS" }, |
| 1458 | { "DSPINTCLK", NULL, "CLK_SYS" }, |
| 1459 | |
| 1460 | { "AIF1ADC1L", NULL, "AIF1CLK" }, |
| 1461 | { "AIF1ADC1L", NULL, "DSP1CLK" }, |
| 1462 | { "AIF1ADC1R", NULL, "AIF1CLK" }, |
| 1463 | { "AIF1ADC1R", NULL, "DSP1CLK" }, |
| 1464 | { "AIF1ADC1R", NULL, "DSPINTCLK" }, |
| 1465 | |
| 1466 | { "AIF1DAC1L", NULL, "AIF1CLK" }, |
| 1467 | { "AIF1DAC1L", NULL, "DSP1CLK" }, |
| 1468 | { "AIF1DAC1R", NULL, "AIF1CLK" }, |
| 1469 | { "AIF1DAC1R", NULL, "DSP1CLK" }, |
| 1470 | { "AIF1DAC1R", NULL, "DSPINTCLK" }, |
| 1471 | |
| 1472 | { "AIF1ADC2L", NULL, "AIF1CLK" }, |
| 1473 | { "AIF1ADC2L", NULL, "DSP1CLK" }, |
| 1474 | { "AIF1ADC2R", NULL, "AIF1CLK" }, |
| 1475 | { "AIF1ADC2R", NULL, "DSP1CLK" }, |
| 1476 | { "AIF1ADC2R", NULL, "DSPINTCLK" }, |
| 1477 | |
| 1478 | { "AIF1DAC2L", NULL, "AIF1CLK" }, |
| 1479 | { "AIF1DAC2L", NULL, "DSP1CLK" }, |
| 1480 | { "AIF1DAC2R", NULL, "AIF1CLK" }, |
| 1481 | { "AIF1DAC2R", NULL, "DSP1CLK" }, |
| 1482 | { "AIF1DAC2R", NULL, "DSPINTCLK" }, |
| 1483 | |
| 1484 | { "AIF2ADCL", NULL, "AIF2CLK" }, |
| 1485 | { "AIF2ADCL", NULL, "DSP2CLK" }, |
| 1486 | { "AIF2ADCR", NULL, "AIF2CLK" }, |
| 1487 | { "AIF2ADCR", NULL, "DSP2CLK" }, |
| 1488 | { "AIF2ADCR", NULL, "DSPINTCLK" }, |
| 1489 | |
| 1490 | { "AIF2DACL", NULL, "AIF2CLK" }, |
| 1491 | { "AIF2DACL", NULL, "DSP2CLK" }, |
| 1492 | { "AIF2DACR", NULL, "AIF2CLK" }, |
| 1493 | { "AIF2DACR", NULL, "DSP2CLK" }, |
| 1494 | { "AIF2DACR", NULL, "DSPINTCLK" }, |
| 1495 | |
| 1496 | { "DMIC1L", NULL, "DMIC1DAT" }, |
| 1497 | { "DMIC1L", NULL, "CLK_SYS" }, |
| 1498 | { "DMIC1R", NULL, "DMIC1DAT" }, |
| 1499 | { "DMIC1R", NULL, "CLK_SYS" }, |
| 1500 | { "DMIC2L", NULL, "DMIC2DAT" }, |
| 1501 | { "DMIC2L", NULL, "CLK_SYS" }, |
| 1502 | { "DMIC2R", NULL, "DMIC2DAT" }, |
| 1503 | { "DMIC2R", NULL, "CLK_SYS" }, |
| 1504 | |
| 1505 | { "ADCL", NULL, "AIF1CLK" }, |
| 1506 | { "ADCL", NULL, "DSP1CLK" }, |
| 1507 | { "ADCL", NULL, "DSPINTCLK" }, |
| 1508 | |
| 1509 | { "ADCR", NULL, "AIF1CLK" }, |
| 1510 | { "ADCR", NULL, "DSP1CLK" }, |
| 1511 | { "ADCR", NULL, "DSPINTCLK" }, |
| 1512 | |
| 1513 | { "ADCL Mux", "ADC", "ADCL" }, |
| 1514 | { "ADCL Mux", "DMIC", "DMIC1L" }, |
| 1515 | { "ADCR Mux", "ADC", "ADCR" }, |
| 1516 | { "ADCR Mux", "DMIC", "DMIC1R" }, |
| 1517 | |
| 1518 | { "DAC1L", NULL, "AIF1CLK" }, |
| 1519 | { "DAC1L", NULL, "DSP1CLK" }, |
| 1520 | { "DAC1L", NULL, "DSPINTCLK" }, |
| 1521 | |
| 1522 | { "DAC1R", NULL, "AIF1CLK" }, |
| 1523 | { "DAC1R", NULL, "DSP1CLK" }, |
| 1524 | { "DAC1R", NULL, "DSPINTCLK" }, |
| 1525 | |
| 1526 | { "DAC2L", NULL, "AIF2CLK" }, |
| 1527 | { "DAC2L", NULL, "DSP2CLK" }, |
| 1528 | { "DAC2L", NULL, "DSPINTCLK" }, |
| 1529 | |
| 1530 | { "DAC2R", NULL, "AIF2DACR" }, |
| 1531 | { "DAC2R", NULL, "AIF2CLK" }, |
| 1532 | { "DAC2R", NULL, "DSP2CLK" }, |
| 1533 | { "DAC2R", NULL, "DSPINTCLK" }, |
| 1534 | |
| 1535 | { "TOCLK", NULL, "CLK_SYS" }, |
| 1536 | |
| 1537 | /* AIF1 outputs */ |
| 1538 | { "AIF1ADC1L", NULL, "AIF1ADC1L Mixer" }, |
| 1539 | { "AIF1ADC1L Mixer", "ADC/DMIC Switch", "ADCL Mux" }, |
| 1540 | { "AIF1ADC1L Mixer", "AIF2 Switch", "AIF2DACL" }, |
| 1541 | |
| 1542 | { "AIF1ADC1R", NULL, "AIF1ADC1R Mixer" }, |
| 1543 | { "AIF1ADC1R Mixer", "ADC/DMIC Switch", "ADCR Mux" }, |
| 1544 | { "AIF1ADC1R Mixer", "AIF2 Switch", "AIF2DACR" }, |
| 1545 | |
Mark Brown | a3257ba | 2010-07-19 14:02:34 +0100 | [diff] [blame] | 1546 | { "AIF1ADC2L", NULL, "AIF1ADC2L Mixer" }, |
| 1547 | { "AIF1ADC2L Mixer", "DMIC Switch", "DMIC2L" }, |
| 1548 | { "AIF1ADC2L Mixer", "AIF2 Switch", "AIF2DACL" }, |
| 1549 | |
| 1550 | { "AIF1ADC2R", NULL, "AIF1ADC2R Mixer" }, |
| 1551 | { "AIF1ADC2R Mixer", "DMIC Switch", "DMIC2R" }, |
| 1552 | { "AIF1ADC2R Mixer", "AIF2 Switch", "AIF2DACR" }, |
| 1553 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1554 | /* Pin level routing for AIF3 */ |
| 1555 | { "AIF1DAC1L", NULL, "AIF1DAC Mux" }, |
| 1556 | { "AIF1DAC1R", NULL, "AIF1DAC Mux" }, |
| 1557 | { "AIF1DAC2L", NULL, "AIF1DAC Mux" }, |
| 1558 | { "AIF1DAC2R", NULL, "AIF1DAC Mux" }, |
| 1559 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1560 | { "AIF1DAC Mux", "AIF1DACDAT", "AIF1DACDAT" }, |
| 1561 | { "AIF1DAC Mux", "AIF3DACDAT", "AIF3DACDAT" }, |
| 1562 | { "AIF2DAC Mux", "AIF2DACDAT", "AIF2DACDAT" }, |
| 1563 | { "AIF2DAC Mux", "AIF3DACDAT", "AIF3DACDAT" }, |
| 1564 | { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCL" }, |
| 1565 | { "AIF2ADC Mux", "AIF2ADCDAT", "AIF2ADCR" }, |
| 1566 | { "AIF2ADC Mux", "AIF3DACDAT", "AIF3ADCDAT" }, |
| 1567 | |
| 1568 | /* DAC1 inputs */ |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1569 | { "DAC1L Mixer", "AIF2 Switch", "AIF2DACL" }, |
| 1570 | { "DAC1L Mixer", "AIF1.2 Switch", "AIF1DAC2L" }, |
| 1571 | { "DAC1L Mixer", "AIF1.1 Switch", "AIF1DAC1L" }, |
| 1572 | { "DAC1L Mixer", "Left Sidetone Switch", "Left Sidetone" }, |
| 1573 | { "DAC1L Mixer", "Right Sidetone Switch", "Right Sidetone" }, |
| 1574 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1575 | { "DAC1R Mixer", "AIF2 Switch", "AIF2DACR" }, |
| 1576 | { "DAC1R Mixer", "AIF1.2 Switch", "AIF1DAC2R" }, |
| 1577 | { "DAC1R Mixer", "AIF1.1 Switch", "AIF1DAC1R" }, |
| 1578 | { "DAC1R Mixer", "Left Sidetone Switch", "Left Sidetone" }, |
| 1579 | { "DAC1R Mixer", "Right Sidetone Switch", "Right Sidetone" }, |
| 1580 | |
| 1581 | /* DAC2/AIF2 outputs */ |
| 1582 | { "AIF2ADCL", NULL, "AIF2DAC2L Mixer" }, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1583 | { "AIF2DAC2L Mixer", "AIF2 Switch", "AIF2DACL" }, |
| 1584 | { "AIF2DAC2L Mixer", "AIF1.2 Switch", "AIF1DAC2L" }, |
| 1585 | { "AIF2DAC2L Mixer", "AIF1.1 Switch", "AIF1DAC1L" }, |
| 1586 | { "AIF2DAC2L Mixer", "Left Sidetone Switch", "Left Sidetone" }, |
| 1587 | { "AIF2DAC2L Mixer", "Right Sidetone Switch", "Right Sidetone" }, |
| 1588 | |
| 1589 | { "AIF2ADCR", NULL, "AIF2DAC2R Mixer" }, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1590 | { "AIF2DAC2R Mixer", "AIF2 Switch", "AIF2DACR" }, |
| 1591 | { "AIF2DAC2R Mixer", "AIF1.2 Switch", "AIF1DAC2R" }, |
| 1592 | { "AIF2DAC2R Mixer", "AIF1.1 Switch", "AIF1DAC1R" }, |
| 1593 | { "AIF2DAC2R Mixer", "Left Sidetone Switch", "Left Sidetone" }, |
| 1594 | { "AIF2DAC2R Mixer", "Right Sidetone Switch", "Right Sidetone" }, |
| 1595 | |
Mark Brown | 7f94de4 | 2011-02-03 16:27:34 +0000 | [diff] [blame] | 1596 | { "AIF1ADCDAT", NULL, "AIF1ADC1L" }, |
| 1597 | { "AIF1ADCDAT", NULL, "AIF1ADC1R" }, |
| 1598 | { "AIF1ADCDAT", NULL, "AIF1ADC2L" }, |
| 1599 | { "AIF1ADCDAT", NULL, "AIF1ADC2R" }, |
| 1600 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1601 | { "AIF2ADCDAT", NULL, "AIF2ADC Mux" }, |
| 1602 | |
| 1603 | /* AIF3 output */ |
| 1604 | { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" }, |
| 1605 | { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" }, |
| 1606 | { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" }, |
| 1607 | { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" }, |
| 1608 | { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" }, |
| 1609 | { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" }, |
| 1610 | { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" }, |
| 1611 | { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" }, |
| 1612 | |
| 1613 | /* Sidetone */ |
| 1614 | { "Left Sidetone", "ADC/DMIC1", "ADCL Mux" }, |
| 1615 | { "Left Sidetone", "DMIC2", "DMIC2L" }, |
| 1616 | { "Right Sidetone", "ADC/DMIC1", "ADCR Mux" }, |
| 1617 | { "Right Sidetone", "DMIC2", "DMIC2R" }, |
| 1618 | |
| 1619 | /* Output stages */ |
| 1620 | { "Left Output Mixer", "DAC Switch", "DAC1L" }, |
| 1621 | { "Right Output Mixer", "DAC Switch", "DAC1R" }, |
| 1622 | |
| 1623 | { "SPKL", "DAC1 Switch", "DAC1L" }, |
| 1624 | { "SPKL", "DAC2 Switch", "DAC2L" }, |
| 1625 | |
| 1626 | { "SPKR", "DAC1 Switch", "DAC1R" }, |
| 1627 | { "SPKR", "DAC2 Switch", "DAC2R" }, |
| 1628 | |
| 1629 | { "Left Headphone Mux", "DAC", "DAC1L" }, |
| 1630 | { "Right Headphone Mux", "DAC", "DAC1R" }, |
| 1631 | }; |
| 1632 | |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 1633 | static const struct snd_soc_dapm_route wm8994_lateclk_revd_intercon[] = { |
| 1634 | { "DAC1L", NULL, "Late DAC1L Enable PGA" }, |
| 1635 | { "Late DAC1L Enable PGA", NULL, "DAC1L Mixer" }, |
| 1636 | { "DAC1R", NULL, "Late DAC1R Enable PGA" }, |
| 1637 | { "Late DAC1R Enable PGA", NULL, "DAC1R Mixer" }, |
| 1638 | { "DAC2L", NULL, "Late DAC2L Enable PGA" }, |
| 1639 | { "Late DAC2L Enable PGA", NULL, "AIF2DAC2L Mixer" }, |
| 1640 | { "DAC2R", NULL, "Late DAC2R Enable PGA" }, |
| 1641 | { "Late DAC2R Enable PGA", NULL, "AIF2DAC2R Mixer" } |
| 1642 | }; |
| 1643 | |
| 1644 | static const struct snd_soc_dapm_route wm8994_lateclk_intercon[] = { |
| 1645 | { "DAC1L", NULL, "DAC1L Mixer" }, |
| 1646 | { "DAC1R", NULL, "DAC1R Mixer" }, |
| 1647 | { "DAC2L", NULL, "AIF2DAC2L Mixer" }, |
| 1648 | { "DAC2R", NULL, "AIF2DAC2R Mixer" }, |
| 1649 | }; |
| 1650 | |
Mark Brown | 6ed8f14 | 2011-02-03 16:27:35 +0000 | [diff] [blame] | 1651 | static const struct snd_soc_dapm_route wm8994_revd_intercon[] = { |
| 1652 | { "AIF1DACDAT", NULL, "AIF2DACDAT" }, |
| 1653 | { "AIF2DACDAT", NULL, "AIF1DACDAT" }, |
| 1654 | { "AIF1ADCDAT", NULL, "AIF2ADCDAT" }, |
| 1655 | { "AIF2ADCDAT", NULL, "AIF1ADCDAT" }, |
Mark Brown | b793eb6 | 2011-07-14 18:21:37 +0900 | [diff] [blame] | 1656 | { "MICBIAS1", NULL, "CLK_SYS" }, |
| 1657 | { "MICBIAS1", NULL, "MICBIAS Supply" }, |
| 1658 | { "MICBIAS2", NULL, "CLK_SYS" }, |
| 1659 | { "MICBIAS2", NULL, "MICBIAS Supply" }, |
Mark Brown | 6ed8f14 | 2011-02-03 16:27:35 +0000 | [diff] [blame] | 1660 | }; |
| 1661 | |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 1662 | static const struct snd_soc_dapm_route wm8994_intercon[] = { |
| 1663 | { "AIF2DACL", NULL, "AIF2DAC Mux" }, |
| 1664 | { "AIF2DACR", NULL, "AIF2DAC Mux" }, |
Mark Brown | 4e04ada | 2011-07-15 15:12:31 +0900 | [diff] [blame] | 1665 | { "MICBIAS1", NULL, "VMID" }, |
| 1666 | { "MICBIAS2", NULL, "VMID" }, |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 1667 | }; |
| 1668 | |
| 1669 | static const struct snd_soc_dapm_route wm8958_intercon[] = { |
| 1670 | { "AIF2DACL", NULL, "AIF2DACL Mux" }, |
| 1671 | { "AIF2DACR", NULL, "AIF2DACR Mux" }, |
| 1672 | |
| 1673 | { "AIF2DACL Mux", "AIF2", "AIF2DAC Mux" }, |
| 1674 | { "AIF2DACL Mux", "AIF3", "AIF3DACDAT" }, |
| 1675 | { "AIF2DACR Mux", "AIF2", "AIF2DAC Mux" }, |
| 1676 | { "AIF2DACR Mux", "AIF3", "AIF3DACDAT" }, |
| 1677 | |
| 1678 | { "Mono PCM Out Mux", "AIF2ADCL", "AIF2ADCL" }, |
| 1679 | { "Mono PCM Out Mux", "AIF2ADCR", "AIF2ADCR" }, |
| 1680 | |
| 1681 | { "AIF3ADC Mux", "Mono PCM", "Mono PCM Out Mux" }, |
| 1682 | }; |
| 1683 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1684 | /* The size in bits of the FLL divide multiplied by 10 |
| 1685 | * to allow rounding later */ |
| 1686 | #define FIXED_FLL_SIZE ((1 << 16) * 10) |
| 1687 | |
| 1688 | struct fll_div { |
| 1689 | u16 outdiv; |
| 1690 | u16 n; |
| 1691 | u16 k; |
| 1692 | u16 clk_ref_div; |
| 1693 | u16 fll_fratio; |
| 1694 | }; |
| 1695 | |
| 1696 | static int wm8994_get_fll_config(struct fll_div *fll, |
| 1697 | int freq_in, int freq_out) |
| 1698 | { |
| 1699 | u64 Kpart; |
| 1700 | unsigned int K, Ndiv, Nmod; |
| 1701 | |
| 1702 | pr_debug("FLL input=%dHz, output=%dHz\n", freq_in, freq_out); |
| 1703 | |
| 1704 | /* Scale the input frequency down to <= 13.5MHz */ |
| 1705 | fll->clk_ref_div = 0; |
| 1706 | while (freq_in > 13500000) { |
| 1707 | fll->clk_ref_div++; |
| 1708 | freq_in /= 2; |
| 1709 | |
| 1710 | if (fll->clk_ref_div > 3) |
| 1711 | return -EINVAL; |
| 1712 | } |
| 1713 | pr_debug("CLK_REF_DIV=%d, Fref=%dHz\n", fll->clk_ref_div, freq_in); |
| 1714 | |
| 1715 | /* Scale the output to give 90MHz<=Fvco<=100MHz */ |
| 1716 | fll->outdiv = 3; |
| 1717 | while (freq_out * (fll->outdiv + 1) < 90000000) { |
| 1718 | fll->outdiv++; |
| 1719 | if (fll->outdiv > 63) |
| 1720 | return -EINVAL; |
| 1721 | } |
| 1722 | freq_out *= fll->outdiv + 1; |
| 1723 | pr_debug("OUTDIV=%d, Fvco=%dHz\n", fll->outdiv, freq_out); |
| 1724 | |
| 1725 | if (freq_in > 1000000) { |
| 1726 | fll->fll_fratio = 0; |
Mark Brown | 7d48a6a | 2010-04-20 13:36:11 +0900 | [diff] [blame] | 1727 | } else if (freq_in > 256000) { |
| 1728 | fll->fll_fratio = 1; |
| 1729 | freq_in *= 2; |
| 1730 | } else if (freq_in > 128000) { |
| 1731 | fll->fll_fratio = 2; |
| 1732 | freq_in *= 4; |
| 1733 | } else if (freq_in > 64000) { |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1734 | fll->fll_fratio = 3; |
| 1735 | freq_in *= 8; |
Mark Brown | 7d48a6a | 2010-04-20 13:36:11 +0900 | [diff] [blame] | 1736 | } else { |
| 1737 | fll->fll_fratio = 4; |
| 1738 | freq_in *= 16; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1739 | } |
| 1740 | pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in); |
| 1741 | |
| 1742 | /* Now, calculate N.K */ |
| 1743 | Ndiv = freq_out / freq_in; |
| 1744 | |
| 1745 | fll->n = Ndiv; |
| 1746 | Nmod = freq_out % freq_in; |
| 1747 | pr_debug("Nmod=%d\n", Nmod); |
| 1748 | |
| 1749 | /* Calculate fractional part - scale up so we can round. */ |
| 1750 | Kpart = FIXED_FLL_SIZE * (long long)Nmod; |
| 1751 | |
| 1752 | do_div(Kpart, freq_in); |
| 1753 | |
| 1754 | K = Kpart & 0xFFFFFFFF; |
| 1755 | |
| 1756 | if ((K % 10) >= 5) |
| 1757 | K += 5; |
| 1758 | |
| 1759 | /* Move down to proper range now rounding is done */ |
| 1760 | fll->k = K / 10; |
| 1761 | |
| 1762 | pr_debug("N=%x K=%x\n", fll->n, fll->k); |
| 1763 | |
| 1764 | return 0; |
| 1765 | } |
| 1766 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1767 | static int _wm8994_set_fll(struct snd_soc_codec *codec, int id, int src, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1768 | unsigned int freq_in, unsigned int freq_out) |
| 1769 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 1770 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 4b7ed83 | 2011-08-10 17:47:33 +0900 | [diff] [blame] | 1771 | struct wm8994 *control = codec->control_data; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1772 | int reg_offset, ret; |
| 1773 | struct fll_div fll; |
| 1774 | u16 reg, aif1, aif2; |
Mark Brown | c7ebf93 | 2011-07-12 19:47:59 +0900 | [diff] [blame] | 1775 | unsigned long timeout; |
Mark Brown | 4b7ed83 | 2011-08-10 17:47:33 +0900 | [diff] [blame] | 1776 | bool was_enabled; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1777 | |
| 1778 | aif1 = snd_soc_read(codec, WM8994_AIF1_CLOCKING_1) |
| 1779 | & WM8994_AIF1CLK_ENA; |
| 1780 | |
| 1781 | aif2 = snd_soc_read(codec, WM8994_AIF2_CLOCKING_1) |
| 1782 | & WM8994_AIF2CLK_ENA; |
| 1783 | |
| 1784 | switch (id) { |
| 1785 | case WM8994_FLL1: |
| 1786 | reg_offset = 0; |
| 1787 | id = 0; |
| 1788 | break; |
| 1789 | case WM8994_FLL2: |
| 1790 | reg_offset = 0x20; |
| 1791 | id = 1; |
| 1792 | break; |
| 1793 | default: |
| 1794 | return -EINVAL; |
| 1795 | } |
| 1796 | |
Mark Brown | 4b7ed83 | 2011-08-10 17:47:33 +0900 | [diff] [blame] | 1797 | reg = snd_soc_read(codec, WM8994_FLL1_CONTROL_1 + reg_offset); |
| 1798 | was_enabled = reg & WM8994_FLL1_ENA; |
| 1799 | |
Mark Brown | 136ff2a | 2010-04-20 12:56:18 +0900 | [diff] [blame] | 1800 | switch (src) { |
Mark Brown | 7add84a | 2010-04-22 02:29:01 +0900 | [diff] [blame] | 1801 | case 0: |
| 1802 | /* Allow no source specification when stopping */ |
| 1803 | if (freq_out) |
| 1804 | return -EINVAL; |
Mark Brown | 4514e89 | 2010-12-03 16:02:10 +0000 | [diff] [blame] | 1805 | src = wm8994->fll[id].src; |
Mark Brown | 7add84a | 2010-04-22 02:29:01 +0900 | [diff] [blame] | 1806 | break; |
Mark Brown | 136ff2a | 2010-04-20 12:56:18 +0900 | [diff] [blame] | 1807 | case WM8994_FLL_SRC_MCLK1: |
| 1808 | case WM8994_FLL_SRC_MCLK2: |
| 1809 | case WM8994_FLL_SRC_LRCLK: |
| 1810 | case WM8994_FLL_SRC_BCLK: |
| 1811 | break; |
| 1812 | default: |
| 1813 | return -EINVAL; |
| 1814 | } |
| 1815 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1816 | /* Are we changing anything? */ |
| 1817 | if (wm8994->fll[id].src == src && |
| 1818 | wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out) |
| 1819 | return 0; |
| 1820 | |
| 1821 | /* If we're stopping the FLL redo the old config - no |
| 1822 | * registers will actually be written but we avoid GCC flow |
| 1823 | * analysis bugs spewing warnings. |
| 1824 | */ |
| 1825 | if (freq_out) |
| 1826 | ret = wm8994_get_fll_config(&fll, freq_in, freq_out); |
| 1827 | else |
| 1828 | ret = wm8994_get_fll_config(&fll, wm8994->fll[id].in, |
| 1829 | wm8994->fll[id].out); |
| 1830 | if (ret < 0) |
| 1831 | return ret; |
| 1832 | |
| 1833 | /* Gate the AIF clocks while we reclock */ |
| 1834 | snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1, |
| 1835 | WM8994_AIF1CLK_ENA, 0); |
| 1836 | snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1, |
| 1837 | WM8994_AIF2CLK_ENA, 0); |
| 1838 | |
| 1839 | /* We always need to disable the FLL while reconfiguring */ |
| 1840 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset, |
| 1841 | WM8994_FLL1_ENA, 0); |
| 1842 | |
| 1843 | reg = (fll.outdiv << WM8994_FLL1_OUTDIV_SHIFT) | |
| 1844 | (fll.fll_fratio << WM8994_FLL1_FRATIO_SHIFT); |
| 1845 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_2 + reg_offset, |
| 1846 | WM8994_FLL1_OUTDIV_MASK | |
| 1847 | WM8994_FLL1_FRATIO_MASK, reg); |
| 1848 | |
| 1849 | snd_soc_write(codec, WM8994_FLL1_CONTROL_3 + reg_offset, fll.k); |
| 1850 | |
| 1851 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_4 + reg_offset, |
| 1852 | WM8994_FLL1_N_MASK, |
| 1853 | fll.n << WM8994_FLL1_N_SHIFT); |
| 1854 | |
| 1855 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset, |
Mark Brown | 136ff2a | 2010-04-20 12:56:18 +0900 | [diff] [blame] | 1856 | WM8994_FLL1_REFCLK_DIV_MASK | |
| 1857 | WM8994_FLL1_REFCLK_SRC_MASK, |
| 1858 | (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) | |
| 1859 | (src - 1)); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1860 | |
Mark Brown | f0f5039 | 2011-07-16 03:12:18 +0900 | [diff] [blame] | 1861 | /* Clear any pending completion from a previous failure */ |
| 1862 | try_wait_for_completion(&wm8994->fll_locked[id]); |
| 1863 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1864 | /* Enable (with fractional mode if required) */ |
| 1865 | if (freq_out) { |
Mark Brown | 4b7ed83 | 2011-08-10 17:47:33 +0900 | [diff] [blame] | 1866 | /* Enable VMID if we need it */ |
| 1867 | if (!was_enabled) { |
| 1868 | switch (control->type) { |
| 1869 | case WM8994: |
| 1870 | vmid_reference(codec); |
| 1871 | break; |
| 1872 | case WM8958: |
| 1873 | if (wm8994->revision < 1) |
| 1874 | vmid_reference(codec); |
| 1875 | break; |
| 1876 | default: |
| 1877 | break; |
| 1878 | } |
| 1879 | } |
| 1880 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1881 | if (fll.k) |
| 1882 | reg = WM8994_FLL1_ENA | WM8994_FLL1_FRAC; |
| 1883 | else |
| 1884 | reg = WM8994_FLL1_ENA; |
| 1885 | snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_1 + reg_offset, |
| 1886 | WM8994_FLL1_ENA | WM8994_FLL1_FRAC, |
| 1887 | reg); |
Mark Brown | 8e9ddf8 | 2011-07-01 17:24:46 -0700 | [diff] [blame] | 1888 | |
Mark Brown | c7ebf93 | 2011-07-12 19:47:59 +0900 | [diff] [blame] | 1889 | if (wm8994->fll_locked_irq) { |
| 1890 | timeout = wait_for_completion_timeout(&wm8994->fll_locked[id], |
| 1891 | msecs_to_jiffies(10)); |
| 1892 | if (timeout == 0) |
| 1893 | dev_warn(codec->dev, |
| 1894 | "Timed out waiting for FLL lock\n"); |
| 1895 | } else { |
| 1896 | msleep(5); |
| 1897 | } |
Mark Brown | 4b7ed83 | 2011-08-10 17:47:33 +0900 | [diff] [blame] | 1898 | } else { |
| 1899 | if (was_enabled) { |
| 1900 | switch (control->type) { |
| 1901 | case WM8994: |
| 1902 | vmid_dereference(codec); |
| 1903 | break; |
| 1904 | case WM8958: |
| 1905 | if (wm8994->revision < 1) |
| 1906 | vmid_dereference(codec); |
| 1907 | break; |
| 1908 | default: |
| 1909 | break; |
| 1910 | } |
| 1911 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | wm8994->fll[id].in = freq_in; |
| 1915 | wm8994->fll[id].out = freq_out; |
Mark Brown | 136ff2a | 2010-04-20 12:56:18 +0900 | [diff] [blame] | 1916 | wm8994->fll[id].src = src; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1917 | |
| 1918 | /* Enable any gated AIF clocks */ |
| 1919 | snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1, |
| 1920 | WM8994_AIF1CLK_ENA, aif1); |
| 1921 | snd_soc_update_bits(codec, WM8994_AIF2_CLOCKING_1, |
| 1922 | WM8994_AIF2CLK_ENA, aif2); |
| 1923 | |
| 1924 | configure_clock(codec); |
| 1925 | |
| 1926 | return 0; |
| 1927 | } |
| 1928 | |
Mark Brown | c7ebf93 | 2011-07-12 19:47:59 +0900 | [diff] [blame] | 1929 | static irqreturn_t wm8994_fll_locked_irq(int irq, void *data) |
| 1930 | { |
| 1931 | struct completion *completion = data; |
| 1932 | |
| 1933 | complete(completion); |
| 1934 | |
| 1935 | return IRQ_HANDLED; |
| 1936 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1937 | |
Mark Brown | 66b47fd | 2010-07-08 11:25:43 +0900 | [diff] [blame] | 1938 | static int opclk_divs[] = { 10, 20, 30, 40, 55, 60, 80, 120, 160 }; |
| 1939 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1940 | static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src, |
| 1941 | unsigned int freq_in, unsigned int freq_out) |
| 1942 | { |
| 1943 | return _wm8994_set_fll(dai->codec, id, src, freq_in, freq_out); |
| 1944 | } |
| 1945 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1946 | static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai, |
| 1947 | int clk_id, unsigned int freq, int dir) |
| 1948 | { |
| 1949 | struct snd_soc_codec *codec = dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 1950 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 66b47fd | 2010-07-08 11:25:43 +0900 | [diff] [blame] | 1951 | int i; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 1952 | |
| 1953 | switch (dai->id) { |
| 1954 | case 1: |
| 1955 | case 2: |
| 1956 | break; |
| 1957 | |
| 1958 | default: |
| 1959 | /* AIF3 shares clocking with AIF1/2 */ |
| 1960 | return -EINVAL; |
| 1961 | } |
| 1962 | |
| 1963 | switch (clk_id) { |
| 1964 | case WM8994_SYSCLK_MCLK1: |
| 1965 | wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK1; |
| 1966 | wm8994->mclk[0] = freq; |
| 1967 | dev_dbg(dai->dev, "AIF%d using MCLK1 at %uHz\n", |
| 1968 | dai->id, freq); |
| 1969 | break; |
| 1970 | |
| 1971 | case WM8994_SYSCLK_MCLK2: |
| 1972 | /* TODO: Set GPIO AF */ |
| 1973 | wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_MCLK2; |
| 1974 | wm8994->mclk[1] = freq; |
| 1975 | dev_dbg(dai->dev, "AIF%d using MCLK2 at %uHz\n", |
| 1976 | dai->id, freq); |
| 1977 | break; |
| 1978 | |
| 1979 | case WM8994_SYSCLK_FLL1: |
| 1980 | wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL1; |
| 1981 | dev_dbg(dai->dev, "AIF%d using FLL1\n", dai->id); |
| 1982 | break; |
| 1983 | |
| 1984 | case WM8994_SYSCLK_FLL2: |
| 1985 | wm8994->sysclk[dai->id - 1] = WM8994_SYSCLK_FLL2; |
| 1986 | dev_dbg(dai->dev, "AIF%d using FLL2\n", dai->id); |
| 1987 | break; |
| 1988 | |
Mark Brown | 66b47fd | 2010-07-08 11:25:43 +0900 | [diff] [blame] | 1989 | case WM8994_SYSCLK_OPCLK: |
| 1990 | /* Special case - a division (times 10) is given and |
| 1991 | * no effect on main clocking. |
| 1992 | */ |
| 1993 | if (freq) { |
| 1994 | for (i = 0; i < ARRAY_SIZE(opclk_divs); i++) |
| 1995 | if (opclk_divs[i] == freq) |
| 1996 | break; |
| 1997 | if (i == ARRAY_SIZE(opclk_divs)) |
| 1998 | return -EINVAL; |
| 1999 | snd_soc_update_bits(codec, WM8994_CLOCKING_2, |
| 2000 | WM8994_OPCLK_DIV_MASK, i); |
| 2001 | snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2, |
| 2002 | WM8994_OPCLK_ENA, WM8994_OPCLK_ENA); |
| 2003 | } else { |
| 2004 | snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_2, |
| 2005 | WM8994_OPCLK_ENA, 0); |
| 2006 | } |
| 2007 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2008 | default: |
| 2009 | return -EINVAL; |
| 2010 | } |
| 2011 | |
| 2012 | configure_clock(codec); |
| 2013 | |
| 2014 | return 0; |
| 2015 | } |
| 2016 | |
| 2017 | static int wm8994_set_bias_level(struct snd_soc_codec *codec, |
| 2018 | enum snd_soc_bias_level level) |
| 2019 | { |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 2020 | struct wm8994 *control = codec->control_data; |
Mark Brown | b6b0569 | 2010-08-13 12:58:20 +0100 | [diff] [blame] | 2021 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
| 2022 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2023 | switch (level) { |
| 2024 | case SND_SOC_BIAS_ON: |
| 2025 | break; |
| 2026 | |
| 2027 | case SND_SOC_BIAS_PREPARE: |
Mark Brown | 500fa30 | 2011-11-29 19:58:19 +0000 | [diff] [blame^] | 2028 | /* MICBIAS into regulating mode */ |
| 2029 | switch (control->type) { |
| 2030 | case WM8958: |
| 2031 | case WM1811: |
| 2032 | snd_soc_update_bits(codec, WM8958_MICBIAS1, |
| 2033 | WM8958_MICB1_MODE, 0); |
| 2034 | snd_soc_update_bits(codec, WM8958_MICBIAS2, |
| 2035 | WM8958_MICB2_MODE, 0); |
| 2036 | break; |
| 2037 | default: |
| 2038 | break; |
| 2039 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2040 | break; |
| 2041 | |
| 2042 | case SND_SOC_BIAS_STANDBY: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2043 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { |
Mark Brown | 39fb51a | 2010-11-26 17:23:43 +0000 | [diff] [blame] | 2044 | pm_runtime_get_sync(codec->dev); |
| 2045 | |
Mark Brown | 8bc3c2c | 2010-11-30 14:56:18 +0000 | [diff] [blame] | 2046 | switch (control->type) { |
| 2047 | case WM8994: |
| 2048 | if (wm8994->revision < 4) { |
| 2049 | /* Tweak DC servo and DSP |
| 2050 | * configuration for improved |
| 2051 | * performance. */ |
| 2052 | snd_soc_write(codec, 0x102, 0x3); |
| 2053 | snd_soc_write(codec, 0x56, 0x3); |
| 2054 | snd_soc_write(codec, 0x817, 0); |
| 2055 | snd_soc_write(codec, 0x102, 0); |
| 2056 | } |
| 2057 | break; |
| 2058 | |
| 2059 | case WM8958: |
| 2060 | if (wm8994->revision == 0) { |
| 2061 | /* Optimise performance for rev A */ |
| 2062 | snd_soc_write(codec, 0x102, 0x3); |
| 2063 | snd_soc_write(codec, 0xcb, 0x81); |
| 2064 | snd_soc_write(codec, 0x817, 0); |
| 2065 | snd_soc_write(codec, 0x102, 0); |
| 2066 | |
| 2067 | snd_soc_update_bits(codec, |
| 2068 | WM8958_CHARGE_PUMP_2, |
| 2069 | WM8958_CP_DISCH, |
| 2070 | WM8958_CP_DISCH); |
| 2071 | } |
| 2072 | break; |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 2073 | |
| 2074 | case WM1811: |
| 2075 | if (wm8994->revision < 2) { |
| 2076 | snd_soc_write(codec, 0x102, 0x3); |
| 2077 | snd_soc_write(codec, 0x5d, 0x7e); |
| 2078 | snd_soc_write(codec, 0x5e, 0x0); |
| 2079 | snd_soc_write(codec, 0x102, 0x0); |
| 2080 | } |
| 2081 | break; |
Mark Brown | b6b0569 | 2010-08-13 12:58:20 +0100 | [diff] [blame] | 2082 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2083 | |
| 2084 | /* Discharge LINEOUT1 & 2 */ |
| 2085 | snd_soc_update_bits(codec, WM8994_ANTIPOP_1, |
| 2086 | WM8994_LINEOUT1_DISCH | |
| 2087 | WM8994_LINEOUT2_DISCH, |
| 2088 | WM8994_LINEOUT1_DISCH | |
| 2089 | WM8994_LINEOUT2_DISCH); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
Mark Brown | 500fa30 | 2011-11-29 19:58:19 +0000 | [diff] [blame^] | 2092 | /* MICBIAS into bypass mode on newer devices */ |
| 2093 | switch (control->type) { |
| 2094 | case WM8958: |
| 2095 | case WM1811: |
| 2096 | snd_soc_update_bits(codec, WM8958_MICBIAS1, |
| 2097 | WM8958_MICB1_MODE, |
| 2098 | WM8958_MICB1_MODE); |
| 2099 | snd_soc_update_bits(codec, WM8958_MICBIAS2, |
| 2100 | WM8958_MICB2_MODE, |
| 2101 | WM8958_MICB2_MODE); |
| 2102 | break; |
| 2103 | default: |
| 2104 | break; |
| 2105 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2106 | break; |
| 2107 | |
| 2108 | case SND_SOC_BIAS_OFF: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2109 | if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) { |
Mark Brown | fbbf592 | 2011-03-11 18:09:04 +0000 | [diff] [blame] | 2110 | wm8994->cur_fw = NULL; |
| 2111 | |
Mark Brown | 39fb51a | 2010-11-26 17:23:43 +0000 | [diff] [blame] | 2112 | pm_runtime_put(codec->dev); |
Mark Brown | d522ffb | 2010-03-30 14:29:14 +0100 | [diff] [blame] | 2113 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2114 | break; |
| 2115 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2116 | codec->dapm.bias_level = level; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2117 | return 0; |
| 2118 | } |
| 2119 | |
| 2120 | static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 2121 | { |
| 2122 | struct snd_soc_codec *codec = dai->codec; |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 2123 | struct wm8994 *control = codec->control_data; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2124 | int ms_reg; |
| 2125 | int aif1_reg; |
| 2126 | int ms = 0; |
| 2127 | int aif1 = 0; |
| 2128 | |
| 2129 | switch (dai->id) { |
| 2130 | case 1: |
| 2131 | ms_reg = WM8994_AIF1_MASTER_SLAVE; |
| 2132 | aif1_reg = WM8994_AIF1_CONTROL_1; |
| 2133 | break; |
| 2134 | case 2: |
| 2135 | ms_reg = WM8994_AIF2_MASTER_SLAVE; |
| 2136 | aif1_reg = WM8994_AIF2_CONTROL_1; |
| 2137 | break; |
| 2138 | default: |
| 2139 | return -EINVAL; |
| 2140 | } |
| 2141 | |
| 2142 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 2143 | case SND_SOC_DAIFMT_CBS_CFS: |
| 2144 | break; |
| 2145 | case SND_SOC_DAIFMT_CBM_CFM: |
| 2146 | ms = WM8994_AIF1_MSTR; |
| 2147 | break; |
| 2148 | default: |
| 2149 | return -EINVAL; |
| 2150 | } |
| 2151 | |
| 2152 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 2153 | case SND_SOC_DAIFMT_DSP_B: |
| 2154 | aif1 |= WM8994_AIF1_LRCLK_INV; |
| 2155 | case SND_SOC_DAIFMT_DSP_A: |
| 2156 | aif1 |= 0x18; |
| 2157 | break; |
| 2158 | case SND_SOC_DAIFMT_I2S: |
| 2159 | aif1 |= 0x10; |
| 2160 | break; |
| 2161 | case SND_SOC_DAIFMT_RIGHT_J: |
| 2162 | break; |
| 2163 | case SND_SOC_DAIFMT_LEFT_J: |
| 2164 | aif1 |= 0x8; |
| 2165 | break; |
| 2166 | default: |
| 2167 | return -EINVAL; |
| 2168 | } |
| 2169 | |
| 2170 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 2171 | case SND_SOC_DAIFMT_DSP_A: |
| 2172 | case SND_SOC_DAIFMT_DSP_B: |
| 2173 | /* frame inversion not valid for DSP modes */ |
| 2174 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 2175 | case SND_SOC_DAIFMT_NB_NF: |
| 2176 | break; |
| 2177 | case SND_SOC_DAIFMT_IB_NF: |
| 2178 | aif1 |= WM8994_AIF1_BCLK_INV; |
| 2179 | break; |
| 2180 | default: |
| 2181 | return -EINVAL; |
| 2182 | } |
| 2183 | break; |
| 2184 | |
| 2185 | case SND_SOC_DAIFMT_I2S: |
| 2186 | case SND_SOC_DAIFMT_RIGHT_J: |
| 2187 | case SND_SOC_DAIFMT_LEFT_J: |
| 2188 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 2189 | case SND_SOC_DAIFMT_NB_NF: |
| 2190 | break; |
| 2191 | case SND_SOC_DAIFMT_IB_IF: |
| 2192 | aif1 |= WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV; |
| 2193 | break; |
| 2194 | case SND_SOC_DAIFMT_IB_NF: |
| 2195 | aif1 |= WM8994_AIF1_BCLK_INV; |
| 2196 | break; |
| 2197 | case SND_SOC_DAIFMT_NB_IF: |
| 2198 | aif1 |= WM8994_AIF1_LRCLK_INV; |
| 2199 | break; |
| 2200 | default: |
| 2201 | return -EINVAL; |
| 2202 | } |
| 2203 | break; |
| 2204 | default: |
| 2205 | return -EINVAL; |
| 2206 | } |
| 2207 | |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 2208 | /* The AIF2 format configuration needs to be mirrored to AIF3 |
| 2209 | * on WM8958 if it's in use so just do it all the time. */ |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 2210 | switch (control->type) { |
| 2211 | case WM1811: |
| 2212 | case WM8958: |
| 2213 | if (dai->id == 2) |
| 2214 | snd_soc_update_bits(codec, WM8958_AIF3_CONTROL_1, |
| 2215 | WM8994_AIF1_LRCLK_INV | |
| 2216 | WM8958_AIF3_FMT_MASK, aif1); |
| 2217 | break; |
| 2218 | |
| 2219 | default: |
| 2220 | break; |
| 2221 | } |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 2222 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2223 | snd_soc_update_bits(codec, aif1_reg, |
| 2224 | WM8994_AIF1_BCLK_INV | WM8994_AIF1_LRCLK_INV | |
| 2225 | WM8994_AIF1_FMT_MASK, |
| 2226 | aif1); |
| 2227 | snd_soc_update_bits(codec, ms_reg, WM8994_AIF1_MSTR, |
| 2228 | ms); |
| 2229 | |
| 2230 | return 0; |
| 2231 | } |
| 2232 | |
| 2233 | static struct { |
| 2234 | int val, rate; |
| 2235 | } srs[] = { |
| 2236 | { 0, 8000 }, |
| 2237 | { 1, 11025 }, |
| 2238 | { 2, 12000 }, |
| 2239 | { 3, 16000 }, |
| 2240 | { 4, 22050 }, |
| 2241 | { 5, 24000 }, |
| 2242 | { 6, 32000 }, |
| 2243 | { 7, 44100 }, |
| 2244 | { 8, 48000 }, |
| 2245 | { 9, 88200 }, |
| 2246 | { 10, 96000 }, |
| 2247 | }; |
| 2248 | |
| 2249 | static int fs_ratios[] = { |
| 2250 | 64, 128, 192, 256, 348, 512, 768, 1024, 1408, 1536 |
| 2251 | }; |
| 2252 | |
| 2253 | static int bclk_divs[] = { |
| 2254 | 10, 15, 20, 30, 40, 50, 60, 80, 110, 120, 160, 220, 240, 320, 440, 480, |
| 2255 | 640, 880, 960, 1280, 1760, 1920 |
| 2256 | }; |
| 2257 | |
| 2258 | static int wm8994_hw_params(struct snd_pcm_substream *substream, |
| 2259 | struct snd_pcm_hw_params *params, |
| 2260 | struct snd_soc_dai *dai) |
| 2261 | { |
| 2262 | struct snd_soc_codec *codec = dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 2263 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2264 | int aif1_reg; |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2265 | int aif2_reg; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2266 | int bclk_reg; |
| 2267 | int lrclk_reg; |
| 2268 | int rate_reg; |
| 2269 | int aif1 = 0; |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2270 | int aif2 = 0; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2271 | int bclk = 0; |
| 2272 | int lrclk = 0; |
| 2273 | int rate_val = 0; |
| 2274 | int id = dai->id - 1; |
| 2275 | |
| 2276 | int i, cur_val, best_val, bclk_rate, best; |
| 2277 | |
| 2278 | switch (dai->id) { |
| 2279 | case 1: |
| 2280 | aif1_reg = WM8994_AIF1_CONTROL_1; |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2281 | aif2_reg = WM8994_AIF1_CONTROL_2; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2282 | bclk_reg = WM8994_AIF1_BCLK; |
| 2283 | rate_reg = WM8994_AIF1_RATE; |
| 2284 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || |
Mark Brown | 7d83d21 | 2010-08-23 10:54:43 +0100 | [diff] [blame] | 2285 | wm8994->lrclk_shared[0]) { |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2286 | lrclk_reg = WM8994_AIF1DAC_LRCLK; |
Mark Brown | 7d83d21 | 2010-08-23 10:54:43 +0100 | [diff] [blame] | 2287 | } else { |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2288 | lrclk_reg = WM8994_AIF1ADC_LRCLK; |
Mark Brown | 7d83d21 | 2010-08-23 10:54:43 +0100 | [diff] [blame] | 2289 | dev_dbg(codec->dev, "AIF1 using split LRCLK\n"); |
| 2290 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2291 | break; |
| 2292 | case 2: |
| 2293 | aif1_reg = WM8994_AIF2_CONTROL_1; |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2294 | aif2_reg = WM8994_AIF2_CONTROL_2; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2295 | bclk_reg = WM8994_AIF2_BCLK; |
| 2296 | rate_reg = WM8994_AIF2_RATE; |
| 2297 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || |
Mark Brown | 7d83d21 | 2010-08-23 10:54:43 +0100 | [diff] [blame] | 2298 | wm8994->lrclk_shared[1]) { |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2299 | lrclk_reg = WM8994_AIF2DAC_LRCLK; |
Mark Brown | 7d83d21 | 2010-08-23 10:54:43 +0100 | [diff] [blame] | 2300 | } else { |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2301 | lrclk_reg = WM8994_AIF2ADC_LRCLK; |
Mark Brown | 7d83d21 | 2010-08-23 10:54:43 +0100 | [diff] [blame] | 2302 | dev_dbg(codec->dev, "AIF2 using split LRCLK\n"); |
| 2303 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2304 | break; |
| 2305 | default: |
| 2306 | return -EINVAL; |
| 2307 | } |
| 2308 | |
| 2309 | bclk_rate = params_rate(params) * 2; |
| 2310 | switch (params_format(params)) { |
| 2311 | case SNDRV_PCM_FORMAT_S16_LE: |
| 2312 | bclk_rate *= 16; |
| 2313 | break; |
| 2314 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 2315 | bclk_rate *= 20; |
| 2316 | aif1 |= 0x20; |
| 2317 | break; |
| 2318 | case SNDRV_PCM_FORMAT_S24_LE: |
| 2319 | bclk_rate *= 24; |
| 2320 | aif1 |= 0x40; |
| 2321 | break; |
| 2322 | case SNDRV_PCM_FORMAT_S32_LE: |
| 2323 | bclk_rate *= 32; |
| 2324 | aif1 |= 0x60; |
| 2325 | break; |
| 2326 | default: |
| 2327 | return -EINVAL; |
| 2328 | } |
| 2329 | |
| 2330 | /* Try to find an appropriate sample rate; look for an exact match. */ |
| 2331 | for (i = 0; i < ARRAY_SIZE(srs); i++) |
| 2332 | if (srs[i].rate == params_rate(params)) |
| 2333 | break; |
| 2334 | if (i == ARRAY_SIZE(srs)) |
| 2335 | return -EINVAL; |
| 2336 | rate_val |= srs[i].val << WM8994_AIF1_SR_SHIFT; |
| 2337 | |
| 2338 | dev_dbg(dai->dev, "Sample rate is %dHz\n", srs[i].rate); |
| 2339 | dev_dbg(dai->dev, "AIF%dCLK is %dHz, target BCLK %dHz\n", |
| 2340 | dai->id, wm8994->aifclk[id], bclk_rate); |
| 2341 | |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2342 | if (params_channels(params) == 1 && |
| 2343 | (snd_soc_read(codec, aif1_reg) & 0x18) == 0x18) |
| 2344 | aif2 |= WM8994_AIF1_MONO; |
| 2345 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2346 | if (wm8994->aifclk[id] == 0) { |
| 2347 | dev_err(dai->dev, "AIF%dCLK not configured\n", dai->id); |
| 2348 | return -EINVAL; |
| 2349 | } |
| 2350 | |
| 2351 | /* AIFCLK/fs ratio; look for a close match in either direction */ |
| 2352 | best = 0; |
| 2353 | best_val = abs((fs_ratios[0] * params_rate(params)) |
| 2354 | - wm8994->aifclk[id]); |
| 2355 | for (i = 1; i < ARRAY_SIZE(fs_ratios); i++) { |
| 2356 | cur_val = abs((fs_ratios[i] * params_rate(params)) |
| 2357 | - wm8994->aifclk[id]); |
| 2358 | if (cur_val >= best_val) |
| 2359 | continue; |
| 2360 | best = i; |
| 2361 | best_val = cur_val; |
| 2362 | } |
| 2363 | dev_dbg(dai->dev, "Selected AIF%dCLK/fs = %d\n", |
| 2364 | dai->id, fs_ratios[best]); |
| 2365 | rate_val |= best; |
| 2366 | |
| 2367 | /* We may not get quite the right frequency if using |
| 2368 | * approximate clocks so look for the closest match that is |
| 2369 | * higher than the target (we need to ensure that there enough |
| 2370 | * BCLKs to clock out the samples). |
| 2371 | */ |
| 2372 | best = 0; |
| 2373 | for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) { |
Joonyoung Shim | 07cd8ad | 2010-02-02 18:53:19 +0900 | [diff] [blame] | 2374 | cur_val = (wm8994->aifclk[id] * 10 / bclk_divs[i]) - bclk_rate; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2375 | if (cur_val < 0) /* BCLK table is sorted */ |
| 2376 | break; |
| 2377 | best = i; |
| 2378 | } |
Joonyoung Shim | 07cd8ad | 2010-02-02 18:53:19 +0900 | [diff] [blame] | 2379 | bclk_rate = wm8994->aifclk[id] * 10 / bclk_divs[best]; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2380 | dev_dbg(dai->dev, "Using BCLK_DIV %d for actual BCLK %dHz\n", |
| 2381 | bclk_divs[best], bclk_rate); |
| 2382 | bclk |= best << WM8994_AIF1_BCLK_DIV_SHIFT; |
| 2383 | |
| 2384 | lrclk = bclk_rate / params_rate(params); |
Mark Brown | fc07ecd | 2011-11-28 21:16:56 +0000 | [diff] [blame] | 2385 | if (!lrclk) { |
| 2386 | dev_err(dai->dev, "Unable to generate LRCLK from %dHz BCLK\n", |
| 2387 | bclk_rate); |
| 2388 | return -EINVAL; |
| 2389 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2390 | dev_dbg(dai->dev, "Using LRCLK rate %d for actual LRCLK %dHz\n", |
| 2391 | lrclk, bclk_rate / lrclk); |
| 2392 | |
| 2393 | snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1); |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2394 | snd_soc_update_bits(codec, aif2_reg, WM8994_AIF1_MONO, aif2); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2395 | snd_soc_update_bits(codec, bclk_reg, WM8994_AIF1_BCLK_DIV_MASK, bclk); |
| 2396 | snd_soc_update_bits(codec, lrclk_reg, WM8994_AIF1DAC_RATE_MASK, |
| 2397 | lrclk); |
| 2398 | snd_soc_update_bits(codec, rate_reg, WM8994_AIF1_SR_MASK | |
| 2399 | WM8994_AIF1CLK_RATE_MASK, rate_val); |
| 2400 | |
| 2401 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 2402 | switch (dai->id) { |
| 2403 | case 1: |
| 2404 | wm8994->dac_rates[0] = params_rate(params); |
| 2405 | wm8994_set_retune_mobile(codec, 0); |
| 2406 | wm8994_set_retune_mobile(codec, 1); |
| 2407 | break; |
| 2408 | case 2: |
| 2409 | wm8994->dac_rates[1] = params_rate(params); |
| 2410 | wm8994_set_retune_mobile(codec, 2); |
| 2411 | break; |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | return 0; |
| 2416 | } |
| 2417 | |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 2418 | static int wm8994_aif3_hw_params(struct snd_pcm_substream *substream, |
| 2419 | struct snd_pcm_hw_params *params, |
| 2420 | struct snd_soc_dai *dai) |
| 2421 | { |
| 2422 | struct snd_soc_codec *codec = dai->codec; |
| 2423 | struct wm8994 *control = codec->control_data; |
| 2424 | int aif1_reg; |
| 2425 | int aif1 = 0; |
| 2426 | |
| 2427 | switch (dai->id) { |
| 2428 | case 3: |
| 2429 | switch (control->type) { |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 2430 | case WM1811: |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 2431 | case WM8958: |
| 2432 | aif1_reg = WM8958_AIF3_CONTROL_1; |
| 2433 | break; |
| 2434 | default: |
| 2435 | return 0; |
| 2436 | } |
| 2437 | default: |
| 2438 | return 0; |
| 2439 | } |
| 2440 | |
| 2441 | switch (params_format(params)) { |
| 2442 | case SNDRV_PCM_FORMAT_S16_LE: |
| 2443 | break; |
| 2444 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 2445 | aif1 |= 0x20; |
| 2446 | break; |
| 2447 | case SNDRV_PCM_FORMAT_S24_LE: |
| 2448 | aif1 |= 0x40; |
| 2449 | break; |
| 2450 | case SNDRV_PCM_FORMAT_S32_LE: |
| 2451 | aif1 |= 0x60; |
| 2452 | break; |
| 2453 | default: |
| 2454 | return -EINVAL; |
| 2455 | } |
| 2456 | |
| 2457 | return snd_soc_update_bits(codec, aif1_reg, WM8994_AIF1_WL_MASK, aif1); |
| 2458 | } |
| 2459 | |
Mark Brown | 7d02173 | 2011-07-14 17:11:38 +0900 | [diff] [blame] | 2460 | static void wm8994_aif_shutdown(struct snd_pcm_substream *substream, |
| 2461 | struct snd_soc_dai *dai) |
| 2462 | { |
| 2463 | struct snd_soc_codec *codec = dai->codec; |
| 2464 | int rate_reg = 0; |
| 2465 | |
| 2466 | switch (dai->id) { |
| 2467 | case 1: |
| 2468 | rate_reg = WM8994_AIF1_RATE; |
| 2469 | break; |
| 2470 | case 2: |
Axel Lin | c527e6a | 2011-10-04 22:07:18 +0800 | [diff] [blame] | 2471 | rate_reg = WM8994_AIF2_RATE; |
Mark Brown | 7d02173 | 2011-07-14 17:11:38 +0900 | [diff] [blame] | 2472 | break; |
| 2473 | default: |
| 2474 | break; |
| 2475 | } |
| 2476 | |
| 2477 | /* If the DAI is idle then configure the divider tree for the |
| 2478 | * lowest output rate to save a little power if the clock is |
| 2479 | * still active (eg, because it is system clock). |
| 2480 | */ |
| 2481 | if (rate_reg && !dai->playback_active && !dai->capture_active) |
| 2482 | snd_soc_update_bits(codec, rate_reg, |
| 2483 | WM8994_AIF1_SR_MASK | |
| 2484 | WM8994_AIF1CLK_RATE_MASK, 0x9); |
| 2485 | } |
| 2486 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2487 | static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute) |
| 2488 | { |
| 2489 | struct snd_soc_codec *codec = codec_dai->codec; |
| 2490 | int mute_reg; |
| 2491 | int reg; |
| 2492 | |
| 2493 | switch (codec_dai->id) { |
| 2494 | case 1: |
| 2495 | mute_reg = WM8994_AIF1_DAC1_FILTERS_1; |
| 2496 | break; |
| 2497 | case 2: |
| 2498 | mute_reg = WM8994_AIF2_DAC_FILTERS_1; |
| 2499 | break; |
| 2500 | default: |
| 2501 | return -EINVAL; |
| 2502 | } |
| 2503 | |
| 2504 | if (mute) |
| 2505 | reg = WM8994_AIF1DAC1_MUTE; |
| 2506 | else |
| 2507 | reg = 0; |
| 2508 | |
| 2509 | snd_soc_update_bits(codec, mute_reg, WM8994_AIF1DAC1_MUTE, reg); |
| 2510 | |
| 2511 | return 0; |
| 2512 | } |
| 2513 | |
Mark Brown | 778a76e | 2010-03-22 22:05:10 +0000 | [diff] [blame] | 2514 | static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate) |
| 2515 | { |
| 2516 | struct snd_soc_codec *codec = codec_dai->codec; |
| 2517 | int reg, val, mask; |
| 2518 | |
| 2519 | switch (codec_dai->id) { |
| 2520 | case 1: |
| 2521 | reg = WM8994_AIF1_MASTER_SLAVE; |
| 2522 | mask = WM8994_AIF1_TRI; |
| 2523 | break; |
| 2524 | case 2: |
| 2525 | reg = WM8994_AIF2_MASTER_SLAVE; |
| 2526 | mask = WM8994_AIF2_TRI; |
| 2527 | break; |
| 2528 | case 3: |
| 2529 | reg = WM8994_POWER_MANAGEMENT_6; |
| 2530 | mask = WM8994_AIF3_TRI; |
| 2531 | break; |
| 2532 | default: |
| 2533 | return -EINVAL; |
| 2534 | } |
| 2535 | |
| 2536 | if (tristate) |
| 2537 | val = mask; |
| 2538 | else |
| 2539 | val = 0; |
| 2540 | |
Qiao Zhou | 78b3fb4 | 2011-01-19 19:10:47 +0800 | [diff] [blame] | 2541 | return snd_soc_update_bits(codec, reg, mask, val); |
Mark Brown | 778a76e | 2010-03-22 22:05:10 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
Mark Brown | d09f3ec | 2011-08-15 11:01:02 +0900 | [diff] [blame] | 2544 | static int wm8994_aif2_probe(struct snd_soc_dai *dai) |
| 2545 | { |
| 2546 | struct snd_soc_codec *codec = dai->codec; |
| 2547 | |
| 2548 | /* Disable the pulls on the AIF if we're using it to save power. */ |
| 2549 | snd_soc_update_bits(codec, WM8994_GPIO_3, |
| 2550 | WM8994_GPN_PU | WM8994_GPN_PD, 0); |
| 2551 | snd_soc_update_bits(codec, WM8994_GPIO_4, |
| 2552 | WM8994_GPN_PU | WM8994_GPN_PD, 0); |
| 2553 | snd_soc_update_bits(codec, WM8994_GPIO_5, |
| 2554 | WM8994_GPN_PU | WM8994_GPN_PD, 0); |
| 2555 | |
| 2556 | return 0; |
| 2557 | } |
| 2558 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2559 | #define WM8994_RATES SNDRV_PCM_RATE_8000_96000 |
| 2560 | |
| 2561 | #define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
Ian Lartey | 3079aed | 2010-08-31 23:56:34 +0100 | [diff] [blame] | 2562 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2563 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 2564 | static const struct snd_soc_dai_ops wm8994_aif1_dai_ops = { |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2565 | .set_sysclk = wm8994_set_dai_sysclk, |
| 2566 | .set_fmt = wm8994_set_dai_fmt, |
| 2567 | .hw_params = wm8994_hw_params, |
Mark Brown | 7d02173 | 2011-07-14 17:11:38 +0900 | [diff] [blame] | 2568 | .shutdown = wm8994_aif_shutdown, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2569 | .digital_mute = wm8994_aif_mute, |
| 2570 | .set_pll = wm8994_set_fll, |
Mark Brown | 778a76e | 2010-03-22 22:05:10 +0000 | [diff] [blame] | 2571 | .set_tristate = wm8994_set_tristate, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2572 | }; |
| 2573 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 2574 | static const struct snd_soc_dai_ops wm8994_aif2_dai_ops = { |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2575 | .set_sysclk = wm8994_set_dai_sysclk, |
| 2576 | .set_fmt = wm8994_set_dai_fmt, |
| 2577 | .hw_params = wm8994_hw_params, |
Mark Brown | 7d02173 | 2011-07-14 17:11:38 +0900 | [diff] [blame] | 2578 | .shutdown = wm8994_aif_shutdown, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2579 | .digital_mute = wm8994_aif_mute, |
| 2580 | .set_pll = wm8994_set_fll, |
Mark Brown | 778a76e | 2010-03-22 22:05:10 +0000 | [diff] [blame] | 2581 | .set_tristate = wm8994_set_tristate, |
| 2582 | }; |
| 2583 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 2584 | static const struct snd_soc_dai_ops wm8994_aif3_dai_ops = { |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 2585 | .hw_params = wm8994_aif3_hw_params, |
Mark Brown | 778a76e | 2010-03-22 22:05:10 +0000 | [diff] [blame] | 2586 | .set_tristate = wm8994_set_tristate, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2587 | }; |
| 2588 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2589 | static struct snd_soc_dai_driver wm8994_dai[] = { |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2590 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2591 | .name = "wm8994-aif1", |
Mark Brown | 8c7f78b | 2010-10-12 15:56:09 +0100 | [diff] [blame] | 2592 | .id = 1, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2593 | .playback = { |
| 2594 | .stream_name = "AIF1 Playback", |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2595 | .channels_min = 1, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2596 | .channels_max = 2, |
| 2597 | .rates = WM8994_RATES, |
| 2598 | .formats = WM8994_FORMATS, |
| 2599 | }, |
| 2600 | .capture = { |
| 2601 | .stream_name = "AIF1 Capture", |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2602 | .channels_min = 1, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2603 | .channels_max = 2, |
| 2604 | .rates = WM8994_RATES, |
| 2605 | .formats = WM8994_FORMATS, |
| 2606 | }, |
| 2607 | .ops = &wm8994_aif1_dai_ops, |
| 2608 | }, |
| 2609 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2610 | .name = "wm8994-aif2", |
Mark Brown | 8c7f78b | 2010-10-12 15:56:09 +0100 | [diff] [blame] | 2611 | .id = 2, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2612 | .playback = { |
| 2613 | .stream_name = "AIF2 Playback", |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2614 | .channels_min = 1, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2615 | .channels_max = 2, |
| 2616 | .rates = WM8994_RATES, |
| 2617 | .formats = WM8994_FORMATS, |
| 2618 | }, |
| 2619 | .capture = { |
| 2620 | .stream_name = "AIF2 Capture", |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2621 | .channels_min = 1, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2622 | .channels_max = 2, |
| 2623 | .rates = WM8994_RATES, |
| 2624 | .formats = WM8994_FORMATS, |
| 2625 | }, |
Mark Brown | d09f3ec | 2011-08-15 11:01:02 +0900 | [diff] [blame] | 2626 | .probe = wm8994_aif2_probe, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2627 | .ops = &wm8994_aif2_dai_ops, |
| 2628 | }, |
| 2629 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2630 | .name = "wm8994-aif3", |
Mark Brown | 8c7f78b | 2010-10-12 15:56:09 +0100 | [diff] [blame] | 2631 | .id = 3, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2632 | .playback = { |
| 2633 | .stream_name = "AIF3 Playback", |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2634 | .channels_min = 1, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2635 | .channels_max = 2, |
| 2636 | .rates = WM8994_RATES, |
| 2637 | .formats = WM8994_FORMATS, |
| 2638 | }, |
Dan Carpenter | a8462bd | 2010-03-24 14:58:34 +0300 | [diff] [blame] | 2639 | .capture = { |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2640 | .stream_name = "AIF3 Capture", |
Mark Brown | b1e43d9 | 2010-12-07 17:14:56 +0000 | [diff] [blame] | 2641 | .channels_min = 1, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2642 | .channels_max = 2, |
| 2643 | .rates = WM8994_RATES, |
| 2644 | .formats = WM8994_FORMATS, |
| 2645 | }, |
Mark Brown | 778a76e | 2010-03-22 22:05:10 +0000 | [diff] [blame] | 2646 | .ops = &wm8994_aif3_dai_ops, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2647 | } |
| 2648 | }; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2649 | |
| 2650 | #ifdef CONFIG_PM |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2651 | static int wm8994_suspend(struct snd_soc_codec *codec, pm_message_t state) |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2652 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 2653 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | ca62992 | 2011-05-11 14:34:53 +0200 | [diff] [blame] | 2654 | struct wm8994 *control = codec->control_data; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2655 | int i, ret; |
| 2656 | |
Mark Brown | ca62992 | 2011-05-11 14:34:53 +0200 | [diff] [blame] | 2657 | switch (control->type) { |
| 2658 | case WM8994: |
| 2659 | snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, 0); |
| 2660 | break; |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 2661 | case WM1811: |
Mark Brown | ca62992 | 2011-05-11 14:34:53 +0200 | [diff] [blame] | 2662 | case WM8958: |
| 2663 | snd_soc_update_bits(codec, WM8958_MIC_DETECT_1, |
| 2664 | WM8958_MICD_ENA, 0); |
| 2665 | break; |
| 2666 | } |
| 2667 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2668 | for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) { |
| 2669 | memcpy(&wm8994->fll_suspend[i], &wm8994->fll[i], |
Mark Brown | f701a2e | 2011-03-09 19:31:01 +0000 | [diff] [blame] | 2670 | sizeof(struct wm8994_fll_config)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2671 | ret = _wm8994_set_fll(codec, i + 1, 0, 0, 0); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2672 | if (ret < 0) |
| 2673 | dev_warn(codec->dev, "Failed to stop FLL%d: %d\n", |
| 2674 | i + 1, ret); |
| 2675 | } |
| 2676 | |
| 2677 | wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 2678 | |
| 2679 | return 0; |
| 2680 | } |
| 2681 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2682 | static int wm8994_resume(struct snd_soc_codec *codec) |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2683 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 2684 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | ca62992 | 2011-05-11 14:34:53 +0200 | [diff] [blame] | 2685 | struct wm8994 *control = codec->control_data; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2686 | int i, ret; |
Dimitris Papastamos | c52fd02 | 2011-02-11 16:32:12 +0000 | [diff] [blame] | 2687 | unsigned int val, mask; |
| 2688 | |
| 2689 | if (wm8994->revision < 4) { |
| 2690 | /* force a HW read */ |
| 2691 | val = wm8994_reg_read(codec->control_data, |
| 2692 | WM8994_POWER_MANAGEMENT_5); |
| 2693 | |
| 2694 | /* modify the cache only */ |
| 2695 | codec->cache_only = 1; |
| 2696 | mask = WM8994_DAC1R_ENA | WM8994_DAC1L_ENA | |
| 2697 | WM8994_DAC2R_ENA | WM8994_DAC2L_ENA; |
| 2698 | val &= mask; |
| 2699 | snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5, |
| 2700 | mask, val); |
| 2701 | codec->cache_only = 0; |
| 2702 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2703 | |
| 2704 | /* Restore the registers */ |
Mark Brown | ca9aef5 | 2010-11-26 17:23:41 +0000 | [diff] [blame] | 2705 | ret = snd_soc_cache_sync(codec); |
| 2706 | if (ret != 0) |
| 2707 | dev_err(codec->dev, "Failed to sync cache: %d\n", ret); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2708 | |
| 2709 | wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 2710 | |
| 2711 | for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) { |
Mark Brown | 6a2f1ee | 2010-05-10 18:36:37 +0100 | [diff] [blame] | 2712 | if (!wm8994->fll_suspend[i].out) |
| 2713 | continue; |
| 2714 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2715 | ret = _wm8994_set_fll(codec, i + 1, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2716 | wm8994->fll_suspend[i].src, |
| 2717 | wm8994->fll_suspend[i].in, |
| 2718 | wm8994->fll_suspend[i].out); |
| 2719 | if (ret < 0) |
| 2720 | dev_warn(codec->dev, "Failed to restore FLL%d: %d\n", |
| 2721 | i + 1, ret); |
| 2722 | } |
| 2723 | |
Mark Brown | ca62992 | 2011-05-11 14:34:53 +0200 | [diff] [blame] | 2724 | switch (control->type) { |
| 2725 | case WM8994: |
| 2726 | if (wm8994->micdet[0].jack || wm8994->micdet[1].jack) |
| 2727 | snd_soc_update_bits(codec, WM8994_MICBIAS, |
| 2728 | WM8994_MICD_ENA, WM8994_MICD_ENA); |
| 2729 | break; |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 2730 | case WM1811: |
Mark Brown | ca62992 | 2011-05-11 14:34:53 +0200 | [diff] [blame] | 2731 | case WM8958: |
| 2732 | if (wm8994->jack_cb) |
| 2733 | snd_soc_update_bits(codec, WM8958_MIC_DETECT_1, |
| 2734 | WM8958_MICD_ENA, WM8958_MICD_ENA); |
| 2735 | break; |
| 2736 | } |
| 2737 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2738 | return 0; |
| 2739 | } |
| 2740 | #else |
| 2741 | #define wm8994_suspend NULL |
| 2742 | #define wm8994_resume NULL |
| 2743 | #endif |
| 2744 | |
| 2745 | static void wm8994_handle_retune_mobile_pdata(struct wm8994_priv *wm8994) |
| 2746 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2747 | struct snd_soc_codec *codec = wm8994->codec; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2748 | struct wm8994_pdata *pdata = wm8994->pdata; |
| 2749 | struct snd_kcontrol_new controls[] = { |
| 2750 | SOC_ENUM_EXT("AIF1.1 EQ Mode", |
| 2751 | wm8994->retune_mobile_enum, |
| 2752 | wm8994_get_retune_mobile_enum, |
| 2753 | wm8994_put_retune_mobile_enum), |
| 2754 | SOC_ENUM_EXT("AIF1.2 EQ Mode", |
| 2755 | wm8994->retune_mobile_enum, |
| 2756 | wm8994_get_retune_mobile_enum, |
| 2757 | wm8994_put_retune_mobile_enum), |
| 2758 | SOC_ENUM_EXT("AIF2 EQ Mode", |
| 2759 | wm8994->retune_mobile_enum, |
| 2760 | wm8994_get_retune_mobile_enum, |
| 2761 | wm8994_put_retune_mobile_enum), |
| 2762 | }; |
| 2763 | int ret, i, j; |
| 2764 | const char **t; |
| 2765 | |
| 2766 | /* We need an array of texts for the enum API but the number |
| 2767 | * of texts is likely to be less than the number of |
| 2768 | * configurations due to the sample rate dependency of the |
| 2769 | * configurations. */ |
| 2770 | wm8994->num_retune_mobile_texts = 0; |
| 2771 | wm8994->retune_mobile_texts = NULL; |
| 2772 | for (i = 0; i < pdata->num_retune_mobile_cfgs; i++) { |
| 2773 | for (j = 0; j < wm8994->num_retune_mobile_texts; j++) { |
| 2774 | if (strcmp(pdata->retune_mobile_cfgs[i].name, |
| 2775 | wm8994->retune_mobile_texts[j]) == 0) |
| 2776 | break; |
| 2777 | } |
| 2778 | |
| 2779 | if (j != wm8994->num_retune_mobile_texts) |
| 2780 | continue; |
| 2781 | |
| 2782 | /* Expand the array... */ |
| 2783 | t = krealloc(wm8994->retune_mobile_texts, |
| 2784 | sizeof(char *) * |
| 2785 | (wm8994->num_retune_mobile_texts + 1), |
| 2786 | GFP_KERNEL); |
| 2787 | if (t == NULL) |
| 2788 | continue; |
| 2789 | |
| 2790 | /* ...store the new entry... */ |
| 2791 | t[wm8994->num_retune_mobile_texts] = |
| 2792 | pdata->retune_mobile_cfgs[i].name; |
| 2793 | |
| 2794 | /* ...and remember the new version. */ |
| 2795 | wm8994->num_retune_mobile_texts++; |
| 2796 | wm8994->retune_mobile_texts = t; |
| 2797 | } |
| 2798 | |
| 2799 | dev_dbg(codec->dev, "Allocated %d unique ReTune Mobile names\n", |
| 2800 | wm8994->num_retune_mobile_texts); |
| 2801 | |
| 2802 | wm8994->retune_mobile_enum.max = wm8994->num_retune_mobile_texts; |
| 2803 | wm8994->retune_mobile_enum.texts = wm8994->retune_mobile_texts; |
| 2804 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2805 | ret = snd_soc_add_controls(wm8994->codec, controls, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2806 | ARRAY_SIZE(controls)); |
| 2807 | if (ret != 0) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2808 | dev_err(wm8994->codec->dev, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2809 | "Failed to add ReTune Mobile controls: %d\n", ret); |
| 2810 | } |
| 2811 | |
| 2812 | static void wm8994_handle_pdata(struct wm8994_priv *wm8994) |
| 2813 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2814 | struct snd_soc_codec *codec = wm8994->codec; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2815 | struct wm8994_pdata *pdata = wm8994->pdata; |
| 2816 | int ret, i; |
| 2817 | |
| 2818 | if (!pdata) |
| 2819 | return; |
| 2820 | |
| 2821 | wm_hubs_handle_analogue_pdata(codec, pdata->lineout1_diff, |
| 2822 | pdata->lineout2_diff, |
| 2823 | pdata->lineout1fb, |
| 2824 | pdata->lineout2fb, |
| 2825 | pdata->jd_scthr, |
| 2826 | pdata->jd_thr, |
| 2827 | pdata->micbias1_lvl, |
| 2828 | pdata->micbias2_lvl); |
| 2829 | |
| 2830 | dev_dbg(codec->dev, "%d DRC configurations\n", pdata->num_drc_cfgs); |
| 2831 | |
| 2832 | if (pdata->num_drc_cfgs) { |
| 2833 | struct snd_kcontrol_new controls[] = { |
| 2834 | SOC_ENUM_EXT("AIF1DRC1 Mode", wm8994->drc_enum, |
| 2835 | wm8994_get_drc_enum, wm8994_put_drc_enum), |
| 2836 | SOC_ENUM_EXT("AIF1DRC2 Mode", wm8994->drc_enum, |
| 2837 | wm8994_get_drc_enum, wm8994_put_drc_enum), |
| 2838 | SOC_ENUM_EXT("AIF2DRC Mode", wm8994->drc_enum, |
| 2839 | wm8994_get_drc_enum, wm8994_put_drc_enum), |
| 2840 | }; |
| 2841 | |
| 2842 | /* We need an array of texts for the enum API */ |
| 2843 | wm8994->drc_texts = kmalloc(sizeof(char *) |
| 2844 | * pdata->num_drc_cfgs, GFP_KERNEL); |
| 2845 | if (!wm8994->drc_texts) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2846 | dev_err(wm8994->codec->dev, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2847 | "Failed to allocate %d DRC config texts\n", |
| 2848 | pdata->num_drc_cfgs); |
| 2849 | return; |
| 2850 | } |
| 2851 | |
| 2852 | for (i = 0; i < pdata->num_drc_cfgs; i++) |
| 2853 | wm8994->drc_texts[i] = pdata->drc_cfgs[i].name; |
| 2854 | |
| 2855 | wm8994->drc_enum.max = pdata->num_drc_cfgs; |
| 2856 | wm8994->drc_enum.texts = wm8994->drc_texts; |
| 2857 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2858 | ret = snd_soc_add_controls(wm8994->codec, controls, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2859 | ARRAY_SIZE(controls)); |
| 2860 | if (ret != 0) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2861 | dev_err(wm8994->codec->dev, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2862 | "Failed to add DRC mode controls: %d\n", ret); |
| 2863 | |
| 2864 | for (i = 0; i < WM8994_NUM_DRC; i++) |
| 2865 | wm8994_set_drc(codec, i); |
| 2866 | } |
| 2867 | |
| 2868 | dev_dbg(codec->dev, "%d ReTune Mobile configurations\n", |
| 2869 | pdata->num_retune_mobile_cfgs); |
| 2870 | |
| 2871 | if (pdata->num_retune_mobile_cfgs) |
| 2872 | wm8994_handle_retune_mobile_pdata(wm8994); |
| 2873 | else |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2874 | snd_soc_add_controls(wm8994->codec, wm8994_eq_controls, |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2875 | ARRAY_SIZE(wm8994_eq_controls)); |
Mark Brown | 48e028e | 2011-02-21 17:11:59 -0800 | [diff] [blame] | 2876 | |
| 2877 | for (i = 0; i < ARRAY_SIZE(pdata->micbias); i++) { |
| 2878 | if (pdata->micbias[i]) { |
| 2879 | snd_soc_write(codec, WM8958_MICBIAS1 + i, |
| 2880 | pdata->micbias[i] & 0xffff); |
| 2881 | } |
| 2882 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 2885 | /** |
| 2886 | * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ |
| 2887 | * |
| 2888 | * @codec: WM8994 codec |
| 2889 | * @jack: jack to report detection events on |
| 2890 | * @micbias: microphone bias to detect on |
| 2891 | * @det: value to report for presence detection |
| 2892 | * @shrt: value to report for short detection |
| 2893 | * |
| 2894 | * Enable microphone detection via IRQ on the WM8994. If GPIOs are |
| 2895 | * being used to bring out signals to the processor then only platform |
Mark Brown | 5ab230a | 2010-09-06 14:59:34 +0100 | [diff] [blame] | 2896 | * data configuration is needed for WM8994 and processor GPIOs should |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 2897 | * be configured using snd_soc_jack_add_gpios() instead. |
| 2898 | * |
| 2899 | * Configuration of detection levels is available via the micbias1_lvl |
| 2900 | * and micbias2_lvl platform data members. |
| 2901 | */ |
| 2902 | int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack, |
| 2903 | int micbias, int det, int shrt) |
| 2904 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 2905 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 2906 | struct wm8994_micdet *micdet; |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 2907 | struct wm8994 *control = codec->control_data; |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 2908 | int reg; |
| 2909 | |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 2910 | if (control->type != WM8994) |
| 2911 | return -EINVAL; |
| 2912 | |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 2913 | switch (micbias) { |
| 2914 | case 1: |
| 2915 | micdet = &wm8994->micdet[0]; |
| 2916 | break; |
| 2917 | case 2: |
| 2918 | micdet = &wm8994->micdet[1]; |
| 2919 | break; |
| 2920 | default: |
| 2921 | return -EINVAL; |
| 2922 | } |
| 2923 | |
| 2924 | dev_dbg(codec->dev, "Configuring microphone detection on %d: %x %x\n", |
| 2925 | micbias, det, shrt); |
| 2926 | |
| 2927 | /* Store the configuration */ |
| 2928 | micdet->jack = jack; |
| 2929 | micdet->det = det; |
| 2930 | micdet->shrt = shrt; |
| 2931 | |
| 2932 | /* If either of the jacks is set up then enable detection */ |
| 2933 | if (wm8994->micdet[0].jack || wm8994->micdet[1].jack) |
| 2934 | reg = WM8994_MICD_ENA; |
| 2935 | else |
| 2936 | reg = 0; |
| 2937 | |
| 2938 | snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg); |
| 2939 | |
| 2940 | return 0; |
| 2941 | } |
| 2942 | EXPORT_SYMBOL_GPL(wm8994_mic_detect); |
| 2943 | |
| 2944 | static irqreturn_t wm8994_mic_irq(int irq, void *data) |
| 2945 | { |
| 2946 | struct wm8994_priv *priv = data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2947 | struct snd_soc_codec *codec = priv->codec; |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 2948 | int reg; |
| 2949 | int report; |
| 2950 | |
Mark Brown | 7116f45 | 2010-12-29 13:05:21 +0000 | [diff] [blame] | 2951 | #ifndef CONFIG_SND_SOC_WM8994_MODULE |
Mark Brown | 2bbb5d6 | 2010-12-05 12:50:12 +0000 | [diff] [blame] | 2952 | trace_snd_soc_jack_irq(dev_name(codec->dev)); |
Mark Brown | 7116f45 | 2010-12-29 13:05:21 +0000 | [diff] [blame] | 2953 | #endif |
Mark Brown | 2bbb5d6 | 2010-12-05 12:50:12 +0000 | [diff] [blame] | 2954 | |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 2955 | reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2); |
| 2956 | if (reg < 0) { |
| 2957 | dev_err(codec->dev, "Failed to read microphone status: %d\n", |
| 2958 | reg); |
| 2959 | return IRQ_HANDLED; |
| 2960 | } |
| 2961 | |
| 2962 | dev_dbg(codec->dev, "Microphone status: %x\n", reg); |
| 2963 | |
| 2964 | report = 0; |
| 2965 | if (reg & WM8994_MIC1_DET_STS) |
| 2966 | report |= priv->micdet[0].det; |
| 2967 | if (reg & WM8994_MIC1_SHRT_STS) |
| 2968 | report |= priv->micdet[0].shrt; |
| 2969 | snd_soc_jack_report(priv->micdet[0].jack, report, |
| 2970 | priv->micdet[0].det | priv->micdet[0].shrt); |
| 2971 | |
| 2972 | report = 0; |
| 2973 | if (reg & WM8994_MIC2_DET_STS) |
| 2974 | report |= priv->micdet[1].det; |
| 2975 | if (reg & WM8994_MIC2_SHRT_STS) |
| 2976 | report |= priv->micdet[1].shrt; |
| 2977 | snd_soc_jack_report(priv->micdet[1].jack, report, |
| 2978 | priv->micdet[1].det | priv->micdet[1].shrt); |
| 2979 | |
| 2980 | return IRQ_HANDLED; |
| 2981 | } |
| 2982 | |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 2983 | /* Default microphone detection handler for WM8958 - the user can |
| 2984 | * override this if they wish. |
| 2985 | */ |
| 2986 | static void wm8958_default_micdet(u16 status, void *data) |
| 2987 | { |
| 2988 | struct snd_soc_codec *codec = data; |
| 2989 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
| 2990 | int report = 0; |
| 2991 | |
| 2992 | /* If nothing present then clear our statuses */ |
Mark Brown | 864c4bd | 2011-02-21 20:51:13 -0800 | [diff] [blame] | 2993 | if (!(status & WM8958_MICD_STS)) |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 2994 | goto done; |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 2995 | |
Mark Brown | 864c4bd | 2011-02-21 20:51:13 -0800 | [diff] [blame] | 2996 | report = SND_JACK_MICROPHONE; |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 2997 | |
| 2998 | /* Everything else is buttons; just assign slots */ |
Mark Brown | b35e160 | 2011-07-15 22:28:32 +0900 | [diff] [blame] | 2999 | if (status & 0x1c) |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3000 | report |= SND_JACK_BTN_0; |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3001 | |
| 3002 | done: |
Mark Brown | 406e56c | 2011-02-21 20:41:25 -0800 | [diff] [blame] | 3003 | snd_soc_jack_report(wm8994->micdet[0].jack, report, |
Mark Brown | 864c4bd | 2011-02-21 20:51:13 -0800 | [diff] [blame] | 3004 | SND_JACK_BTN_0 | SND_JACK_MICROPHONE); |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | /** |
| 3008 | * wm8958_mic_detect - Enable microphone detection via the WM8958 IRQ |
| 3009 | * |
| 3010 | * @codec: WM8958 codec |
| 3011 | * @jack: jack to report detection events on |
| 3012 | * |
| 3013 | * Enable microphone detection functionality for the WM8958. By |
| 3014 | * default simple detection which supports the detection of up to 6 |
| 3015 | * buttons plus video and microphone functionality is supported. |
| 3016 | * |
| 3017 | * The WM8958 has an advanced jack detection facility which is able to |
| 3018 | * support complex accessory detection, especially when used in |
| 3019 | * conjunction with external circuitry. In order to provide maximum |
| 3020 | * flexiblity a callback is provided which allows a completely custom |
| 3021 | * detection algorithm. |
| 3022 | */ |
| 3023 | int wm8958_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack, |
| 3024 | wm8958_micdet_cb cb, void *cb_data) |
| 3025 | { |
| 3026 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
| 3027 | struct wm8994 *control = codec->control_data; |
| 3028 | |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 3029 | switch (control->type) { |
| 3030 | case WM1811: |
| 3031 | case WM8958: |
| 3032 | break; |
| 3033 | default: |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3034 | return -EINVAL; |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 3035 | } |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3036 | |
| 3037 | if (jack) { |
| 3038 | if (!cb) { |
| 3039 | dev_dbg(codec->dev, "Using default micdet callback\n"); |
| 3040 | cb = wm8958_default_micdet; |
| 3041 | cb_data = codec; |
| 3042 | } |
| 3043 | |
Mark Brown | 4cdf5e4 | 2011-11-29 14:36:17 +0000 | [diff] [blame] | 3044 | snd_soc_dapm_force_enable_pin(&codec->dapm, "CLK_SYS"); |
| 3045 | |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3046 | wm8994->micdet[0].jack = jack; |
| 3047 | wm8994->jack_cb = cb; |
| 3048 | wm8994->jack_cb_data = cb_data; |
| 3049 | |
| 3050 | snd_soc_update_bits(codec, WM8958_MIC_DETECT_1, |
| 3051 | WM8958_MICD_ENA, WM8958_MICD_ENA); |
| 3052 | } else { |
| 3053 | snd_soc_update_bits(codec, WM8958_MIC_DETECT_1, |
| 3054 | WM8958_MICD_ENA, 0); |
Mark Brown | 4cdf5e4 | 2011-11-29 14:36:17 +0000 | [diff] [blame] | 3055 | snd_soc_dapm_disable_pin(&codec->dapm, "CLK_SYS"); |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | return 0; |
| 3059 | } |
| 3060 | EXPORT_SYMBOL_GPL(wm8958_mic_detect); |
| 3061 | |
| 3062 | static irqreturn_t wm8958_mic_irq(int irq, void *data) |
| 3063 | { |
| 3064 | struct wm8994_priv *wm8994 = data; |
| 3065 | struct snd_soc_codec *codec = wm8994->codec; |
Mark Brown | 19940b3 | 2011-08-19 18:05:05 +0900 | [diff] [blame] | 3066 | int reg, count; |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3067 | |
Mark Brown | 19940b3 | 2011-08-19 18:05:05 +0900 | [diff] [blame] | 3068 | /* We may occasionally read a detection without an impedence |
| 3069 | * range being provided - if that happens loop again. |
| 3070 | */ |
| 3071 | count = 10; |
| 3072 | do { |
| 3073 | reg = snd_soc_read(codec, WM8958_MIC_DETECT_3); |
| 3074 | if (reg < 0) { |
| 3075 | dev_err(codec->dev, |
| 3076 | "Failed to read mic detect status: %d\n", |
| 3077 | reg); |
| 3078 | return IRQ_NONE; |
| 3079 | } |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3080 | |
Mark Brown | 19940b3 | 2011-08-19 18:05:05 +0900 | [diff] [blame] | 3081 | if (!(reg & WM8958_MICD_VALID)) { |
| 3082 | dev_dbg(codec->dev, "Mic detect data not valid\n"); |
| 3083 | goto out; |
| 3084 | } |
| 3085 | |
| 3086 | if (!(reg & WM8958_MICD_STS) || (reg & WM8958_MICD_LVL_MASK)) |
| 3087 | break; |
| 3088 | |
| 3089 | msleep(1); |
| 3090 | } while (count--); |
| 3091 | |
| 3092 | if (count == 0) |
| 3093 | dev_warn(codec->dev, "No impedence range reported for jack\n"); |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3094 | |
Mark Brown | 7116f45 | 2010-12-29 13:05:21 +0000 | [diff] [blame] | 3095 | #ifndef CONFIG_SND_SOC_WM8994_MODULE |
Mark Brown | 2bbb5d6 | 2010-12-05 12:50:12 +0000 | [diff] [blame] | 3096 | trace_snd_soc_jack_irq(dev_name(codec->dev)); |
Mark Brown | 7116f45 | 2010-12-29 13:05:21 +0000 | [diff] [blame] | 3097 | #endif |
Mark Brown | 2bbb5d6 | 2010-12-05 12:50:12 +0000 | [diff] [blame] | 3098 | |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3099 | if (wm8994->jack_cb) |
| 3100 | wm8994->jack_cb(reg, wm8994->jack_cb_data); |
| 3101 | else |
| 3102 | dev_warn(codec->dev, "Accessory detection with no callback\n"); |
| 3103 | |
| 3104 | out: |
| 3105 | return IRQ_HANDLED; |
| 3106 | } |
| 3107 | |
Mark Brown | 3b1af3f | 2011-07-14 12:38:18 +0900 | [diff] [blame] | 3108 | static irqreturn_t wm8994_fifo_error(int irq, void *data) |
| 3109 | { |
| 3110 | struct snd_soc_codec *codec = data; |
| 3111 | |
| 3112 | dev_err(codec->dev, "FIFO error\n"); |
| 3113 | |
| 3114 | return IRQ_HANDLED; |
| 3115 | } |
| 3116 | |
Mark Brown | f0b182b | 2011-08-16 12:01:27 +0900 | [diff] [blame] | 3117 | static irqreturn_t wm8994_temp_warn(int irq, void *data) |
| 3118 | { |
| 3119 | struct snd_soc_codec *codec = data; |
| 3120 | |
| 3121 | dev_err(codec->dev, "Thermal warning\n"); |
| 3122 | |
| 3123 | return IRQ_HANDLED; |
| 3124 | } |
| 3125 | |
| 3126 | static irqreturn_t wm8994_temp_shut(int irq, void *data) |
| 3127 | { |
| 3128 | struct snd_soc_codec *codec = data; |
| 3129 | |
| 3130 | dev_crit(codec->dev, "Thermal shutdown\n"); |
| 3131 | |
| 3132 | return IRQ_HANDLED; |
| 3133 | } |
| 3134 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3135 | static int wm8994_codec_probe(struct snd_soc_codec *codec) |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3136 | { |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3137 | struct wm8994 *control; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3138 | struct wm8994_priv *wm8994; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3139 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Mark Brown | ec62dbd | 2010-08-15 14:56:40 +0100 | [diff] [blame] | 3140 | int ret, i; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3141 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3142 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3143 | control = codec->control_data; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3144 | |
| 3145 | wm8994 = kzalloc(sizeof(struct wm8994_priv), GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3146 | if (wm8994 == NULL) |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3147 | return -ENOMEM; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 3148 | snd_soc_codec_set_drvdata(codec, wm8994); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3149 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3150 | wm8994->pdata = dev_get_platdata(codec->dev->parent); |
| 3151 | wm8994->codec = codec; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3152 | |
Mark Brown | c7ebf93 | 2011-07-12 19:47:59 +0900 | [diff] [blame] | 3153 | for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) |
| 3154 | init_completion(&wm8994->fll_locked[i]); |
| 3155 | |
Mark Brown | 9b7c525 | 2011-02-17 20:05:44 -0800 | [diff] [blame] | 3156 | if (wm8994->pdata && wm8994->pdata->micdet_irq) |
| 3157 | wm8994->micdet_irq = wm8994->pdata->micdet_irq; |
| 3158 | else if (wm8994->pdata && wm8994->pdata->irq_base) |
| 3159 | wm8994->micdet_irq = wm8994->pdata->irq_base + |
| 3160 | WM8994_IRQ_MIC1_DET; |
| 3161 | |
Mark Brown | 39fb51a | 2010-11-26 17:23:43 +0000 | [diff] [blame] | 3162 | pm_runtime_enable(codec->dev); |
| 3163 | pm_runtime_resume(codec->dev); |
| 3164 | |
Mark Brown | ca9aef5 | 2010-11-26 17:23:41 +0000 | [diff] [blame] | 3165 | /* Read our current status back from the chip - we don't want to |
| 3166 | * reset as this may interfere with the GPIO or LDO operation. */ |
| 3167 | for (i = 0; i < WM8994_CACHE_SIZE; i++) { |
Dimitris Papastamos | d4754ec | 2011-01-13 12:20:37 +0000 | [diff] [blame] | 3168 | if (!wm8994_readable(codec, i) || wm8994_volatile(codec, i)) |
Mark Brown | ca9aef5 | 2010-11-26 17:23:41 +0000 | [diff] [blame] | 3169 | continue; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3170 | |
Mark Brown | ca9aef5 | 2010-11-26 17:23:41 +0000 | [diff] [blame] | 3171 | ret = wm8994_reg_read(codec->control_data, i); |
| 3172 | if (ret <= 0) |
| 3173 | continue; |
| 3174 | |
| 3175 | ret = snd_soc_cache_write(codec, i, ret); |
| 3176 | if (ret != 0) { |
| 3177 | dev_err(codec->dev, |
| 3178 | "Failed to initialise cache for 0x%x: %d\n", |
| 3179 | i, ret); |
| 3180 | goto err; |
| 3181 | } |
| 3182 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3183 | |
| 3184 | /* Set revision-specific configuration */ |
Mark Brown | b6b0569 | 2010-08-13 12:58:20 +0100 | [diff] [blame] | 3185 | wm8994->revision = snd_soc_read(codec, WM8994_CHIP_REVISION); |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3186 | switch (control->type) { |
| 3187 | case WM8994: |
| 3188 | switch (wm8994->revision) { |
| 3189 | case 2: |
| 3190 | case 3: |
Mark Brown | 4537c4e | 2011-08-01 13:10:16 +0900 | [diff] [blame] | 3191 | wm8994->hubs.dcs_codes_l = -5; |
| 3192 | wm8994->hubs.dcs_codes_r = -5; |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3193 | wm8994->hubs.hp_startup_mode = 1; |
| 3194 | wm8994->hubs.dcs_readback_mode = 1; |
Mark Brown | f9acf9f | 2011-06-07 23:23:52 +0100 | [diff] [blame] | 3195 | wm8994->hubs.series_startup = 1; |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3196 | break; |
| 3197 | default: |
Mark Brown | 79ef0ab | 2011-08-01 13:02:17 +0900 | [diff] [blame] | 3198 | wm8994->hubs.dcs_readback_mode = 2; |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3199 | break; |
| 3200 | } |
Mark Brown | 280ec8b | 2011-08-10 22:19:19 +0900 | [diff] [blame] | 3201 | break; |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3202 | |
| 3203 | case WM8958: |
Mark Brown | 8437f70 | 2010-03-29 17:09:45 +0100 | [diff] [blame] | 3204 | wm8994->hubs.dcs_readback_mode = 1; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3205 | break; |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3206 | |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 3207 | case WM1811: |
| 3208 | wm8994->hubs.dcs_readback_mode = 2; |
| 3209 | wm8994->hubs.no_series_update = 1; |
| 3210 | |
| 3211 | switch (wm8994->revision) { |
| 3212 | case 0: |
| 3213 | case 1: |
Mark Brown | fc8e6e8 | 2011-11-28 18:48:46 +0000 | [diff] [blame] | 3214 | case 2: |
| 3215 | case 3: |
Mark Brown | 6473a14 | 2011-10-17 19:38:52 +0100 | [diff] [blame] | 3216 | wm8994->hubs.dcs_codes_l = -9; |
| 3217 | wm8994->hubs.dcs_codes_r = -5; |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 3218 | break; |
| 3219 | default: |
| 3220 | break; |
| 3221 | } |
| 3222 | |
| 3223 | snd_soc_update_bits(codec, WM8994_ANALOGUE_HP_1, |
| 3224 | WM1811_HPOUT1_ATTN, WM1811_HPOUT1_ATTN); |
| 3225 | break; |
| 3226 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3227 | default: |
| 3228 | break; |
| 3229 | } |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3230 | |
Mark Brown | 3b1af3f | 2011-07-14 12:38:18 +0900 | [diff] [blame] | 3231 | wm8994_request_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR, |
| 3232 | wm8994_fifo_error, "FIFO error", codec); |
Mark Brown | 5a3ad6b | 2011-11-04 15:53:48 +0000 | [diff] [blame] | 3233 | wm8994_request_irq(codec->control_data, WM8994_IRQ_TEMP_WARN, |
Mark Brown | f0b182b | 2011-08-16 12:01:27 +0900 | [diff] [blame] | 3234 | wm8994_temp_warn, "Thermal warning", codec); |
Mark Brown | 5a3ad6b | 2011-11-04 15:53:48 +0000 | [diff] [blame] | 3235 | wm8994_request_irq(codec->control_data, WM8994_IRQ_TEMP_SHUT, |
Mark Brown | f0b182b | 2011-08-16 12:01:27 +0900 | [diff] [blame] | 3236 | wm8994_temp_shut, "Thermal shutdown", codec); |
Mark Brown | 3b1af3f | 2011-07-14 12:38:18 +0900 | [diff] [blame] | 3237 | |
Mark Brown | b30ead5 | 2011-07-12 15:47:17 +0900 | [diff] [blame] | 3238 | ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_DCS_DONE, |
| 3239 | wm_hubs_dcs_done, "DC servo done", |
| 3240 | &wm8994->hubs); |
| 3241 | if (ret == 0) |
| 3242 | wm8994->hubs.dcs_done_irq = true; |
| 3243 | |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3244 | switch (control->type) { |
| 3245 | case WM8994: |
Mark Brown | 9b7c525 | 2011-02-17 20:05:44 -0800 | [diff] [blame] | 3246 | if (wm8994->micdet_irq) { |
| 3247 | ret = request_threaded_irq(wm8994->micdet_irq, NULL, |
| 3248 | wm8994_mic_irq, |
| 3249 | IRQF_TRIGGER_RISING, |
| 3250 | "Mic1 detect", |
| 3251 | wm8994); |
| 3252 | if (ret != 0) |
| 3253 | dev_warn(codec->dev, |
| 3254 | "Failed to request Mic1 detect IRQ: %d\n", |
| 3255 | ret); |
| 3256 | } |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 3257 | |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3258 | ret = wm8994_request_irq(codec->control_data, |
| 3259 | WM8994_IRQ_MIC1_SHRT, |
| 3260 | wm8994_mic_irq, "Mic 1 short", |
| 3261 | wm8994); |
| 3262 | if (ret != 0) |
| 3263 | dev_warn(codec->dev, |
| 3264 | "Failed to request Mic1 short IRQ: %d\n", |
| 3265 | ret); |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 3266 | |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3267 | ret = wm8994_request_irq(codec->control_data, |
| 3268 | WM8994_IRQ_MIC2_DET, |
| 3269 | wm8994_mic_irq, "Mic 2 detect", |
| 3270 | wm8994); |
| 3271 | if (ret != 0) |
| 3272 | dev_warn(codec->dev, |
| 3273 | "Failed to request Mic2 detect IRQ: %d\n", |
| 3274 | ret); |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 3275 | |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3276 | ret = wm8994_request_irq(codec->control_data, |
| 3277 | WM8994_IRQ_MIC2_SHRT, |
| 3278 | wm8994_mic_irq, "Mic 2 short", |
| 3279 | wm8994); |
| 3280 | if (ret != 0) |
| 3281 | dev_warn(codec->dev, |
| 3282 | "Failed to request Mic2 short IRQ: %d\n", |
| 3283 | ret); |
| 3284 | break; |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3285 | |
| 3286 | case WM8958: |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 3287 | case WM1811: |
Mark Brown | 9b7c525 | 2011-02-17 20:05:44 -0800 | [diff] [blame] | 3288 | if (wm8994->micdet_irq) { |
| 3289 | ret = request_threaded_irq(wm8994->micdet_irq, NULL, |
| 3290 | wm8958_mic_irq, |
| 3291 | IRQF_TRIGGER_RISING, |
| 3292 | "Mic detect", |
| 3293 | wm8994); |
| 3294 | if (ret != 0) |
| 3295 | dev_warn(codec->dev, |
| 3296 | "Failed to request Mic detect IRQ: %d\n", |
| 3297 | ret); |
| 3298 | } |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3299 | } |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 3300 | |
Mark Brown | c7ebf93 | 2011-07-12 19:47:59 +0900 | [diff] [blame] | 3301 | wm8994->fll_locked_irq = true; |
| 3302 | for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) { |
| 3303 | ret = wm8994_request_irq(codec->control_data, |
| 3304 | WM8994_IRQ_FLL1_LOCK + i, |
| 3305 | wm8994_fll_locked_irq, "FLL lock", |
| 3306 | &wm8994->fll_locked[i]); |
| 3307 | if (ret != 0) |
| 3308 | wm8994->fll_locked_irq = false; |
| 3309 | } |
| 3310 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3311 | /* Remember if AIFnLRCLK is configured as a GPIO. This should be |
| 3312 | * configured on init - if a system wants to do this dynamically |
| 3313 | * at runtime we can deal with that then. |
| 3314 | */ |
| 3315 | ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_1); |
| 3316 | if (ret < 0) { |
| 3317 | dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret); |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 3318 | goto err_irq; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3319 | } |
| 3320 | if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) { |
| 3321 | wm8994->lrclk_shared[0] = 1; |
| 3322 | wm8994_dai[0].symmetric_rates = 1; |
| 3323 | } else { |
| 3324 | wm8994->lrclk_shared[0] = 0; |
| 3325 | } |
| 3326 | |
| 3327 | ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_6); |
| 3328 | if (ret < 0) { |
| 3329 | dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret); |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 3330 | goto err_irq; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3331 | } |
| 3332 | if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) { |
| 3333 | wm8994->lrclk_shared[1] = 1; |
| 3334 | wm8994_dai[1].symmetric_rates = 1; |
| 3335 | } else { |
| 3336 | wm8994->lrclk_shared[1] = 0; |
| 3337 | } |
| 3338 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3339 | wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 3340 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3341 | /* Latch volume updates (right only; we always do left then right). */ |
Mark Brown | baa8160 | 2011-04-06 10:52:42 +0900 | [diff] [blame] | 3342 | snd_soc_update_bits(codec, WM8994_AIF1_DAC1_LEFT_VOLUME, |
| 3343 | WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3344 | snd_soc_update_bits(codec, WM8994_AIF1_DAC1_RIGHT_VOLUME, |
| 3345 | WM8994_AIF1DAC1_VU, WM8994_AIF1DAC1_VU); |
Mark Brown | baa8160 | 2011-04-06 10:52:42 +0900 | [diff] [blame] | 3346 | snd_soc_update_bits(codec, WM8994_AIF1_DAC2_LEFT_VOLUME, |
| 3347 | WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3348 | snd_soc_update_bits(codec, WM8994_AIF1_DAC2_RIGHT_VOLUME, |
| 3349 | WM8994_AIF1DAC2_VU, WM8994_AIF1DAC2_VU); |
Mark Brown | baa8160 | 2011-04-06 10:52:42 +0900 | [diff] [blame] | 3350 | snd_soc_update_bits(codec, WM8994_AIF2_DAC_LEFT_VOLUME, |
| 3351 | WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3352 | snd_soc_update_bits(codec, WM8994_AIF2_DAC_RIGHT_VOLUME, |
| 3353 | WM8994_AIF2DAC_VU, WM8994_AIF2DAC_VU); |
Mark Brown | baa8160 | 2011-04-06 10:52:42 +0900 | [diff] [blame] | 3354 | snd_soc_update_bits(codec, WM8994_AIF1_ADC1_LEFT_VOLUME, |
| 3355 | WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3356 | snd_soc_update_bits(codec, WM8994_AIF1_ADC1_RIGHT_VOLUME, |
| 3357 | WM8994_AIF1ADC1_VU, WM8994_AIF1ADC1_VU); |
Mark Brown | baa8160 | 2011-04-06 10:52:42 +0900 | [diff] [blame] | 3358 | snd_soc_update_bits(codec, WM8994_AIF1_ADC2_LEFT_VOLUME, |
| 3359 | WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3360 | snd_soc_update_bits(codec, WM8994_AIF1_ADC2_RIGHT_VOLUME, |
| 3361 | WM8994_AIF1ADC2_VU, WM8994_AIF1ADC2_VU); |
Mark Brown | baa8160 | 2011-04-06 10:52:42 +0900 | [diff] [blame] | 3362 | snd_soc_update_bits(codec, WM8994_AIF2_ADC_LEFT_VOLUME, |
| 3363 | WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3364 | snd_soc_update_bits(codec, WM8994_AIF2_ADC_RIGHT_VOLUME, |
| 3365 | WM8994_AIF2ADC_VU, WM8994_AIF1ADC2_VU); |
Mark Brown | baa8160 | 2011-04-06 10:52:42 +0900 | [diff] [blame] | 3366 | snd_soc_update_bits(codec, WM8994_DAC1_LEFT_VOLUME, |
| 3367 | WM8994_DAC1_VU, WM8994_DAC1_VU); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3368 | snd_soc_update_bits(codec, WM8994_DAC1_RIGHT_VOLUME, |
| 3369 | WM8994_DAC1_VU, WM8994_DAC1_VU); |
Mark Brown | baa8160 | 2011-04-06 10:52:42 +0900 | [diff] [blame] | 3370 | snd_soc_update_bits(codec, WM8994_DAC2_LEFT_VOLUME, |
| 3371 | WM8994_DAC2_VU, WM8994_DAC2_VU); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3372 | snd_soc_update_bits(codec, WM8994_DAC2_RIGHT_VOLUME, |
| 3373 | WM8994_DAC2_VU, WM8994_DAC2_VU); |
| 3374 | |
| 3375 | /* Set the low bit of the 3D stereo depth so TLV matches */ |
| 3376 | snd_soc_update_bits(codec, WM8994_AIF1_DAC1_FILTERS_2, |
| 3377 | 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT, |
| 3378 | 1 << WM8994_AIF1DAC1_3D_GAIN_SHIFT); |
| 3379 | snd_soc_update_bits(codec, WM8994_AIF1_DAC2_FILTERS_2, |
| 3380 | 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT, |
| 3381 | 1 << WM8994_AIF1DAC2_3D_GAIN_SHIFT); |
| 3382 | snd_soc_update_bits(codec, WM8994_AIF2_DAC_FILTERS_2, |
| 3383 | 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT, |
| 3384 | 1 << WM8994_AIF2DAC_3D_GAIN_SHIFT); |
| 3385 | |
Mark Brown | 5b73967 | 2011-07-06 00:08:43 -0700 | [diff] [blame] | 3386 | /* Unconditionally enable AIF1 ADC TDM mode on chips which can |
| 3387 | * use this; it only affects behaviour on idle TDM clock |
| 3388 | * cycles. */ |
| 3389 | switch (control->type) { |
| 3390 | case WM8994: |
| 3391 | case WM8958: |
| 3392 | snd_soc_update_bits(codec, WM8994_AIF1_CONTROL_1, |
| 3393 | WM8994_AIF1ADC_TDM, WM8994_AIF1ADC_TDM); |
| 3394 | break; |
| 3395 | default: |
| 3396 | break; |
| 3397 | } |
Mark Brown | d1ce6b2 | 2010-07-20 10:13:14 +0100 | [diff] [blame] | 3398 | |
Mark Brown | 500fa30 | 2011-11-29 19:58:19 +0000 | [diff] [blame^] | 3399 | /* Put MICBIAS into bypass mode by default on newer devices */ |
| 3400 | switch (control->type) { |
| 3401 | case WM8958: |
| 3402 | case WM1811: |
| 3403 | snd_soc_update_bits(codec, WM8958_MICBIAS1, |
| 3404 | WM8958_MICB1_MODE, WM8958_MICB1_MODE); |
| 3405 | snd_soc_update_bits(codec, WM8958_MICBIAS2, |
| 3406 | WM8958_MICB2_MODE, WM8958_MICB2_MODE); |
| 3407 | break; |
| 3408 | default: |
| 3409 | break; |
| 3410 | } |
| 3411 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3412 | wm8994_update_class_w(codec); |
| 3413 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3414 | wm8994_handle_pdata(wm8994); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3415 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3416 | wm_hubs_add_analogue_controls(codec); |
| 3417 | snd_soc_add_controls(codec, wm8994_snd_controls, |
| 3418 | ARRAY_SIZE(wm8994_snd_controls)); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3419 | snd_soc_dapm_new_controls(dapm, wm8994_dapm_widgets, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3420 | ARRAY_SIZE(wm8994_dapm_widgets)); |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 3421 | |
| 3422 | switch (control->type) { |
| 3423 | case WM8994: |
| 3424 | snd_soc_dapm_new_controls(dapm, wm8994_specific_dapm_widgets, |
| 3425 | ARRAY_SIZE(wm8994_specific_dapm_widgets)); |
Dimitris Papastamos | c52fd02 | 2011-02-11 16:32:12 +0000 | [diff] [blame] | 3426 | if (wm8994->revision < 4) { |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 3427 | snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets, |
| 3428 | ARRAY_SIZE(wm8994_lateclk_revd_widgets)); |
Dimitris Papastamos | 04d2868 | 2011-03-01 11:47:10 +0000 | [diff] [blame] | 3429 | snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets, |
| 3430 | ARRAY_SIZE(wm8994_adc_revd_widgets)); |
Dimitris Papastamos | c52fd02 | 2011-02-11 16:32:12 +0000 | [diff] [blame] | 3431 | snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets, |
| 3432 | ARRAY_SIZE(wm8994_dac_revd_widgets)); |
| 3433 | } else { |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 3434 | snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets, |
| 3435 | ARRAY_SIZE(wm8994_lateclk_widgets)); |
Dimitris Papastamos | 04d2868 | 2011-03-01 11:47:10 +0000 | [diff] [blame] | 3436 | snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets, |
| 3437 | ARRAY_SIZE(wm8994_adc_widgets)); |
Dimitris Papastamos | c52fd02 | 2011-02-11 16:32:12 +0000 | [diff] [blame] | 3438 | snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets, |
| 3439 | ARRAY_SIZE(wm8994_dac_widgets)); |
| 3440 | } |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 3441 | break; |
| 3442 | case WM8958: |
| 3443 | snd_soc_add_controls(codec, wm8958_snd_controls, |
| 3444 | ARRAY_SIZE(wm8958_snd_controls)); |
| 3445 | snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets, |
| 3446 | ARRAY_SIZE(wm8958_dapm_widgets)); |
Mark Brown | 780e280 | 2011-03-11 18:00:19 +0000 | [diff] [blame] | 3447 | if (wm8994->revision < 1) { |
| 3448 | snd_soc_dapm_new_controls(dapm, wm8994_lateclk_revd_widgets, |
| 3449 | ARRAY_SIZE(wm8994_lateclk_revd_widgets)); |
| 3450 | snd_soc_dapm_new_controls(dapm, wm8994_adc_revd_widgets, |
| 3451 | ARRAY_SIZE(wm8994_adc_revd_widgets)); |
| 3452 | snd_soc_dapm_new_controls(dapm, wm8994_dac_revd_widgets, |
| 3453 | ARRAY_SIZE(wm8994_dac_revd_widgets)); |
| 3454 | } else { |
| 3455 | snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets, |
| 3456 | ARRAY_SIZE(wm8994_lateclk_widgets)); |
| 3457 | snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets, |
| 3458 | ARRAY_SIZE(wm8994_adc_widgets)); |
| 3459 | snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets, |
| 3460 | ARRAY_SIZE(wm8994_dac_widgets)); |
| 3461 | } |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 3462 | break; |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 3463 | |
| 3464 | case WM1811: |
| 3465 | snd_soc_add_controls(codec, wm8958_snd_controls, |
| 3466 | ARRAY_SIZE(wm8958_snd_controls)); |
| 3467 | snd_soc_dapm_new_controls(dapm, wm8958_dapm_widgets, |
| 3468 | ARRAY_SIZE(wm8958_dapm_widgets)); |
| 3469 | snd_soc_dapm_new_controls(dapm, wm8994_lateclk_widgets, |
| 3470 | ARRAY_SIZE(wm8994_lateclk_widgets)); |
| 3471 | snd_soc_dapm_new_controls(dapm, wm8994_adc_widgets, |
| 3472 | ARRAY_SIZE(wm8994_adc_widgets)); |
| 3473 | snd_soc_dapm_new_controls(dapm, wm8994_dac_widgets, |
| 3474 | ARRAY_SIZE(wm8994_dac_widgets)); |
| 3475 | break; |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3479 | wm_hubs_add_analogue_routes(codec, 0, 0); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3480 | snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon)); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3481 | |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 3482 | switch (control->type) { |
| 3483 | case WM8994: |
| 3484 | snd_soc_dapm_add_routes(dapm, wm8994_intercon, |
| 3485 | ARRAY_SIZE(wm8994_intercon)); |
Mark Brown | 6ed8f14 | 2011-02-03 16:27:35 +0000 | [diff] [blame] | 3486 | |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 3487 | if (wm8994->revision < 4) { |
Mark Brown | 6ed8f14 | 2011-02-03 16:27:35 +0000 | [diff] [blame] | 3488 | snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon, |
| 3489 | ARRAY_SIZE(wm8994_revd_intercon)); |
Dimitris Papastamos | 173efa0 | 2011-02-11 16:32:11 +0000 | [diff] [blame] | 3490 | snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon, |
| 3491 | ARRAY_SIZE(wm8994_lateclk_revd_intercon)); |
| 3492 | } else { |
| 3493 | snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon, |
| 3494 | ARRAY_SIZE(wm8994_lateclk_intercon)); |
| 3495 | } |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 3496 | break; |
| 3497 | case WM8958: |
Mark Brown | 780e280 | 2011-03-11 18:00:19 +0000 | [diff] [blame] | 3498 | if (wm8994->revision < 1) { |
| 3499 | snd_soc_dapm_add_routes(dapm, wm8994_revd_intercon, |
| 3500 | ARRAY_SIZE(wm8994_revd_intercon)); |
| 3501 | snd_soc_dapm_add_routes(dapm, wm8994_lateclk_revd_intercon, |
| 3502 | ARRAY_SIZE(wm8994_lateclk_revd_intercon)); |
| 3503 | } else { |
| 3504 | snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon, |
| 3505 | ARRAY_SIZE(wm8994_lateclk_intercon)); |
| 3506 | snd_soc_dapm_add_routes(dapm, wm8958_intercon, |
| 3507 | ARRAY_SIZE(wm8958_intercon)); |
| 3508 | } |
Mark Brown | f701a2e | 2011-03-09 19:31:01 +0000 | [diff] [blame] | 3509 | |
| 3510 | wm8958_dsp2_init(codec); |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 3511 | break; |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 3512 | case WM1811: |
| 3513 | snd_soc_dapm_add_routes(dapm, wm8994_lateclk_intercon, |
| 3514 | ARRAY_SIZE(wm8994_lateclk_intercon)); |
| 3515 | snd_soc_dapm_add_routes(dapm, wm8958_intercon, |
| 3516 | ARRAY_SIZE(wm8958_intercon)); |
| 3517 | break; |
Mark Brown | c4431df | 2010-11-26 15:21:07 +0000 | [diff] [blame] | 3518 | } |
| 3519 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3520 | return 0; |
| 3521 | |
Mark Brown | 8876698 | 2010-03-29 20:57:12 +0100 | [diff] [blame] | 3522 | err_irq: |
| 3523 | wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, wm8994); |
| 3524 | wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994); |
| 3525 | wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994); |
Mark Brown | 9b7c525 | 2011-02-17 20:05:44 -0800 | [diff] [blame] | 3526 | if (wm8994->micdet_irq) |
| 3527 | free_irq(wm8994->micdet_irq, wm8994); |
Mark Brown | c7ebf93 | 2011-07-12 19:47:59 +0900 | [diff] [blame] | 3528 | for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) |
| 3529 | wm8994_free_irq(codec->control_data, WM8994_IRQ_FLL1_LOCK + i, |
| 3530 | &wm8994->fll_locked[i]); |
Mark Brown | b30ead5 | 2011-07-12 15:47:17 +0900 | [diff] [blame] | 3531 | wm8994_free_irq(codec->control_data, WM8994_IRQ_DCS_DONE, |
| 3532 | &wm8994->hubs); |
Mark Brown | 3b1af3f | 2011-07-14 12:38:18 +0900 | [diff] [blame] | 3533 | wm8994_free_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR, codec); |
Mark Brown | f0b182b | 2011-08-16 12:01:27 +0900 | [diff] [blame] | 3534 | wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_SHUT, codec); |
| 3535 | wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_WARN, codec); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3536 | err: |
| 3537 | kfree(wm8994); |
| 3538 | return ret; |
| 3539 | } |
| 3540 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3541 | static int wm8994_codec_remove(struct snd_soc_codec *codec) |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3542 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3543 | struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3544 | struct wm8994 *control = codec->control_data; |
Mark Brown | c7ebf93 | 2011-07-12 19:47:59 +0900 | [diff] [blame] | 3545 | int i; |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3546 | |
| 3547 | wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3548 | |
Mark Brown | 39fb51a | 2010-11-26 17:23:43 +0000 | [diff] [blame] | 3549 | pm_runtime_disable(codec->dev); |
| 3550 | |
Mark Brown | c7ebf93 | 2011-07-12 19:47:59 +0900 | [diff] [blame] | 3551 | for (i = 0; i < ARRAY_SIZE(wm8994->fll_locked); i++) |
| 3552 | wm8994_free_irq(codec->control_data, WM8994_IRQ_FLL1_LOCK + i, |
| 3553 | &wm8994->fll_locked[i]); |
| 3554 | |
Mark Brown | b30ead5 | 2011-07-12 15:47:17 +0900 | [diff] [blame] | 3555 | wm8994_free_irq(codec->control_data, WM8994_IRQ_DCS_DONE, |
| 3556 | &wm8994->hubs); |
Mark Brown | 3b1af3f | 2011-07-14 12:38:18 +0900 | [diff] [blame] | 3557 | wm8994_free_irq(codec->control_data, WM8994_IRQ_FIFOS_ERR, codec); |
Mark Brown | f0b182b | 2011-08-16 12:01:27 +0900 | [diff] [blame] | 3558 | wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_SHUT, codec); |
| 3559 | wm8994_free_irq(codec->control_data, WM8994_IRQ_TEMP_WARN, codec); |
Mark Brown | b30ead5 | 2011-07-12 15:47:17 +0900 | [diff] [blame] | 3560 | |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3561 | switch (control->type) { |
| 3562 | case WM8994: |
Mark Brown | 9b7c525 | 2011-02-17 20:05:44 -0800 | [diff] [blame] | 3563 | if (wm8994->micdet_irq) |
| 3564 | free_irq(wm8994->micdet_irq, wm8994); |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3565 | wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, |
| 3566 | wm8994); |
| 3567 | wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, |
| 3568 | wm8994); |
| 3569 | wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET, |
| 3570 | wm8994); |
| 3571 | break; |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3572 | |
Mark Brown | 81204c8 | 2011-05-24 17:35:53 +0800 | [diff] [blame] | 3573 | case WM1811: |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3574 | case WM8958: |
Mark Brown | 9b7c525 | 2011-02-17 20:05:44 -0800 | [diff] [blame] | 3575 | if (wm8994->micdet_irq) |
| 3576 | free_irq(wm8994->micdet_irq, wm8994); |
Mark Brown | 821edd2 | 2010-11-26 15:21:09 +0000 | [diff] [blame] | 3577 | break; |
Mark Brown | 3a42315 | 2010-11-26 15:21:06 +0000 | [diff] [blame] | 3578 | } |
Mark Brown | fbbf592 | 2011-03-11 18:09:04 +0000 | [diff] [blame] | 3579 | if (wm8994->mbc) |
| 3580 | release_firmware(wm8994->mbc); |
Mark Brown | 09e10d7 | 2011-03-16 22:57:47 +0000 | [diff] [blame] | 3581 | if (wm8994->mbc_vss) |
| 3582 | release_firmware(wm8994->mbc_vss); |
Mark Brown | 3121587 | 2011-03-17 20:23:43 +0000 | [diff] [blame] | 3583 | if (wm8994->enh_eq) |
| 3584 | release_firmware(wm8994->enh_eq); |
Axel Lin | 24fb2b1 | 2010-11-23 15:58:39 +0800 | [diff] [blame] | 3585 | kfree(wm8994->retune_mobile_texts); |
| 3586 | kfree(wm8994->drc_texts); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3587 | kfree(wm8994); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3588 | |
| 3589 | return 0; |
| 3590 | } |
| 3591 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3592 | static struct snd_soc_codec_driver soc_codec_dev_wm8994 = { |
| 3593 | .probe = wm8994_codec_probe, |
| 3594 | .remove = wm8994_codec_remove, |
| 3595 | .suspend = wm8994_suspend, |
| 3596 | .resume = wm8994_resume, |
Mark Brown | ca9aef5 | 2010-11-26 17:23:41 +0000 | [diff] [blame] | 3597 | .read = wm8994_read, |
| 3598 | .write = wm8994_write, |
Mark Brown | eba19fd | 2010-11-19 16:09:15 +0000 | [diff] [blame] | 3599 | .readable_register = wm8994_readable, |
| 3600 | .volatile_register = wm8994_volatile, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3601 | .set_bias_level = wm8994_set_bias_level, |
Mark Brown | ca9aef5 | 2010-11-26 17:23:41 +0000 | [diff] [blame] | 3602 | |
| 3603 | .reg_cache_size = WM8994_CACHE_SIZE, |
| 3604 | .reg_cache_default = wm8994_reg_defaults, |
| 3605 | .reg_word_size = 2, |
Mark Brown | 2e19b0c | 2010-11-26 17:23:42 +0000 | [diff] [blame] | 3606 | .compress_type = SND_SOC_RBTREE_COMPRESSION, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3607 | }; |
| 3608 | |
| 3609 | static int __devinit wm8994_probe(struct platform_device *pdev) |
| 3610 | { |
| 3611 | return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8994, |
| 3612 | wm8994_dai, ARRAY_SIZE(wm8994_dai)); |
| 3613 | } |
| 3614 | |
| 3615 | static int __devexit wm8994_remove(struct platform_device *pdev) |
| 3616 | { |
| 3617 | snd_soc_unregister_codec(&pdev->dev); |
| 3618 | return 0; |
| 3619 | } |
| 3620 | |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3621 | static struct platform_driver wm8994_codec_driver = { |
| 3622 | .driver = { |
| 3623 | .name = "wm8994-codec", |
| 3624 | .owner = THIS_MODULE, |
| 3625 | }, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3626 | .probe = wm8994_probe, |
| 3627 | .remove = __devexit_p(wm8994_remove), |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3628 | }; |
| 3629 | |
Mark Brown | 5bbcc3c | 2011-11-23 22:52:08 +0000 | [diff] [blame] | 3630 | module_platform_driver(wm8994_codec_driver); |
Mark Brown | 9e6e96a | 2010-01-29 17:47:12 +0000 | [diff] [blame] | 3631 | |
| 3632 | MODULE_DESCRIPTION("ASoC WM8994 driver"); |
| 3633 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 3634 | MODULE_LICENSE("GPL"); |
| 3635 | MODULE_ALIAS("platform:wm8994-codec"); |