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