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