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