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