Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * wm_hubs.c -- WM8993/4 common code |
| 3 | * |
Mark Brown | 656baae | 2012-05-23 12:39:07 +0100 | [diff] [blame] | 4 | * Copyright 2009-12 Wolfson Microelectronics plc |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 5 | * |
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 7 | * |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/moduleparam.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <linux/pm.h> |
| 19 | #include <linux/i2c.h> |
Mark Brown | 79ef0ab | 2011-08-01 13:02:17 +0900 | [diff] [blame] | 20 | #include <linux/mfd/wm8994/registers.h> |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 21 | #include <sound/core.h> |
| 22 | #include <sound/pcm.h> |
| 23 | #include <sound/pcm_params.h> |
| 24 | #include <sound/soc.h> |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 25 | #include <sound/initval.h> |
| 26 | #include <sound/tlv.h> |
| 27 | |
| 28 | #include "wm8993.h" |
| 29 | #include "wm_hubs.h" |
| 30 | |
| 31 | const DECLARE_TLV_DB_SCALE(wm_hubs_spkmix_tlv, -300, 300, 0); |
| 32 | EXPORT_SYMBOL_GPL(wm_hubs_spkmix_tlv); |
| 33 | |
| 34 | static const DECLARE_TLV_DB_SCALE(inpga_tlv, -1650, 150, 0); |
| 35 | static const DECLARE_TLV_DB_SCALE(inmix_sw_tlv, 0, 3000, 0); |
| 36 | static const DECLARE_TLV_DB_SCALE(inmix_tlv, -1500, 300, 1); |
| 37 | static const DECLARE_TLV_DB_SCALE(earpiece_tlv, -600, 600, 0); |
| 38 | static const DECLARE_TLV_DB_SCALE(outmix_tlv, -2100, 300, 0); |
| 39 | static const DECLARE_TLV_DB_SCALE(spkmixout_tlv, -1800, 600, 1); |
| 40 | static const DECLARE_TLV_DB_SCALE(outpga_tlv, -5700, 100, 0); |
| 41 | static const unsigned int spkboost_tlv[] = { |
Clemens Ladisch | 028aa63 | 2011-11-20 15:15:31 +0100 | [diff] [blame] | 42 | TLV_DB_RANGE_HEAD(2), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 43 | 0, 6, TLV_DB_SCALE_ITEM(0, 150, 0), |
| 44 | 7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0), |
| 45 | }; |
| 46 | static const DECLARE_TLV_DB_SCALE(line_tlv, -600, 600, 0); |
| 47 | |
| 48 | static const char *speaker_ref_text[] = { |
| 49 | "SPKVDD/2", |
| 50 | "VMID", |
| 51 | }; |
| 52 | |
| 53 | static const struct soc_enum speaker_ref = |
| 54 | SOC_ENUM_SINGLE(WM8993_SPEAKER_MIXER, 8, 2, speaker_ref_text); |
| 55 | |
| 56 | static const char *speaker_mode_text[] = { |
| 57 | "Class D", |
| 58 | "Class AB", |
| 59 | }; |
| 60 | |
| 61 | static const struct soc_enum speaker_mode = |
| 62 | SOC_ENUM_SINGLE(WM8993_SPKMIXR_ATTENUATION, 8, 2, speaker_mode_text); |
| 63 | |
Mark Brown | 4dcc93d | 2010-03-29 17:18:41 +0100 | [diff] [blame] | 64 | static void wait_for_dc_servo(struct snd_soc_codec *codec, unsigned int op) |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 65 | { |
Mark Brown | d96ca3c | 2011-07-12 15:25:03 +0900 | [diff] [blame] | 66 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 67 | unsigned int reg; |
| 68 | int count = 0; |
Mark Brown | 1479c3f | 2011-07-15 17:33:26 +0900 | [diff] [blame] | 69 | int timeout; |
Mark Brown | 4dcc93d | 2010-03-29 17:18:41 +0100 | [diff] [blame] | 70 | unsigned int val; |
| 71 | |
| 72 | val = op | WM8993_DCS_ENA_CHAN_0 | WM8993_DCS_ENA_CHAN_1; |
| 73 | |
| 74 | /* Trigger the command */ |
| 75 | snd_soc_write(codec, WM8993_DC_SERVO_0, val); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 76 | |
| 77 | dev_dbg(codec->dev, "Waiting for DC servo...\n"); |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 78 | |
Mark Brown | 1479c3f | 2011-07-15 17:33:26 +0900 | [diff] [blame] | 79 | if (hubs->dcs_done_irq) |
| 80 | timeout = 4; |
| 81 | else |
| 82 | timeout = 400; |
| 83 | |
| 84 | do { |
| 85 | count++; |
| 86 | |
| 87 | if (hubs->dcs_done_irq) |
| 88 | wait_for_completion_timeout(&hubs->dcs_done, |
| 89 | msecs_to_jiffies(250)); |
| 90 | else |
| 91 | msleep(1); |
Mark Brown | d96ca3c | 2011-07-12 15:25:03 +0900 | [diff] [blame] | 92 | |
Mark Brown | 4dcc93d | 2010-03-29 17:18:41 +0100 | [diff] [blame] | 93 | reg = snd_soc_read(codec, WM8993_DC_SERVO_0); |
Mark Brown | 1479c3f | 2011-07-15 17:33:26 +0900 | [diff] [blame] | 94 | dev_dbg(codec->dev, "DC servo: %x\n", reg); |
| 95 | } while (reg & op && count < timeout); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 96 | |
Mark Brown | 4dcc93d | 2010-03-29 17:18:41 +0100 | [diff] [blame] | 97 | if (reg & op) |
Mark Brown | 5a9f91c | 2011-02-17 12:05:46 -0800 | [diff] [blame] | 98 | dev_err(codec->dev, "Timed out waiting for DC Servo %x\n", |
| 99 | op); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Mark Brown | d96ca3c | 2011-07-12 15:25:03 +0900 | [diff] [blame] | 102 | irqreturn_t wm_hubs_dcs_done(int irq, void *data) |
| 103 | { |
| 104 | struct wm_hubs_data *hubs = data; |
| 105 | |
| 106 | complete(&hubs->dcs_done); |
| 107 | |
| 108 | return IRQ_HANDLED; |
| 109 | } |
| 110 | EXPORT_SYMBOL_GPL(wm_hubs_dcs_done); |
| 111 | |
Mark Brown | af31a22 | 2012-04-26 20:06:56 +0100 | [diff] [blame] | 112 | static bool wm_hubs_dac_hp_direct(struct snd_soc_codec *codec) |
| 113 | { |
| 114 | int reg; |
| 115 | |
| 116 | /* If we're going via the mixer we'll need to do additional checks */ |
| 117 | reg = snd_soc_read(codec, WM8993_OUTPUT_MIXER1); |
| 118 | if (!(reg & WM8993_DACL_TO_HPOUT1L)) { |
| 119 | if (reg & ~WM8993_DACL_TO_MIXOUTL) { |
| 120 | dev_vdbg(codec->dev, "Analogue paths connected: %x\n", |
| 121 | reg & ~WM8993_DACL_TO_HPOUT1L); |
| 122 | return false; |
| 123 | } else { |
| 124 | dev_vdbg(codec->dev, "HPL connected to mixer\n"); |
Mark Brown | af31a22 | 2012-04-26 20:06:56 +0100 | [diff] [blame] | 125 | } |
| 126 | } else { |
| 127 | dev_vdbg(codec->dev, "HPL connected to DAC\n"); |
| 128 | } |
| 129 | |
| 130 | reg = snd_soc_read(codec, WM8993_OUTPUT_MIXER2); |
| 131 | if (!(reg & WM8993_DACR_TO_HPOUT1R)) { |
| 132 | if (reg & ~WM8993_DACR_TO_MIXOUTR) { |
| 133 | dev_vdbg(codec->dev, "Analogue paths connected: %x\n", |
| 134 | reg & ~WM8993_DACR_TO_HPOUT1R); |
| 135 | return false; |
| 136 | } else { |
| 137 | dev_vdbg(codec->dev, "HPR connected to mixer\n"); |
Mark Brown | af31a22 | 2012-04-26 20:06:56 +0100 | [diff] [blame] | 138 | } |
| 139 | } else { |
| 140 | dev_vdbg(codec->dev, "HPR connected to DAC\n"); |
| 141 | } |
| 142 | |
| 143 | return true; |
| 144 | } |
| 145 | |
Mark Brown | 94aa733 | 2012-05-01 18:45:09 +0100 | [diff] [blame] | 146 | struct wm_hubs_dcs_cache { |
| 147 | struct list_head list; |
| 148 | unsigned int left; |
| 149 | unsigned int right; |
| 150 | u16 dcs_cfg; |
| 151 | }; |
| 152 | |
| 153 | static bool wm_hubs_dcs_cache_get(struct snd_soc_codec *codec, |
| 154 | struct wm_hubs_dcs_cache **entry) |
| 155 | { |
| 156 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
| 157 | struct wm_hubs_dcs_cache *cache; |
| 158 | unsigned int left, right; |
| 159 | |
| 160 | left = snd_soc_read(codec, WM8993_LEFT_OUTPUT_VOLUME); |
| 161 | left &= WM8993_HPOUT1L_VOL_MASK; |
| 162 | |
| 163 | right = snd_soc_read(codec, WM8993_RIGHT_OUTPUT_VOLUME); |
| 164 | right &= WM8993_HPOUT1R_VOL_MASK; |
| 165 | |
| 166 | list_for_each_entry(cache, &hubs->dcs_cache, list) { |
| 167 | if (cache->left != left || cache->right != right) |
| 168 | continue; |
| 169 | |
| 170 | *entry = cache; |
| 171 | return true; |
| 172 | } |
| 173 | |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | static void wm_hubs_dcs_cache_set(struct snd_soc_codec *codec, u16 dcs_cfg) |
| 178 | { |
| 179 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
| 180 | struct wm_hubs_dcs_cache *cache; |
| 181 | |
| 182 | if (hubs->no_cache_dac_hp_direct) |
| 183 | return; |
| 184 | |
| 185 | cache = devm_kzalloc(codec->dev, sizeof(*cache), GFP_KERNEL); |
| 186 | if (!cache) { |
| 187 | dev_err(codec->dev, "Failed to allocate DCS cache entry\n"); |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | cache->left = snd_soc_read(codec, WM8993_LEFT_OUTPUT_VOLUME); |
| 192 | cache->left &= WM8993_HPOUT1L_VOL_MASK; |
| 193 | |
| 194 | cache->right = snd_soc_read(codec, WM8993_RIGHT_OUTPUT_VOLUME); |
| 195 | cache->right &= WM8993_HPOUT1R_VOL_MASK; |
| 196 | |
| 197 | cache->dcs_cfg = dcs_cfg; |
| 198 | |
| 199 | list_add_tail(&cache->list, &hubs->dcs_cache); |
| 200 | } |
| 201 | |
Mark Brown | fae4efa | 2012-07-23 19:49:06 +0100 | [diff] [blame] | 202 | static void wm_hubs_read_dc_servo(struct snd_soc_codec *codec, |
| 203 | u16 *reg_l, u16 *reg_r) |
| 204 | { |
| 205 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
| 206 | u16 dcs_reg, reg; |
| 207 | |
| 208 | switch (hubs->dcs_readback_mode) { |
| 209 | case 2: |
| 210 | dcs_reg = WM8994_DC_SERVO_4E; |
| 211 | break; |
| 212 | case 1: |
| 213 | dcs_reg = WM8994_DC_SERVO_READBACK; |
| 214 | break; |
| 215 | default: |
| 216 | dcs_reg = WM8993_DC_SERVO_3; |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | /* Different chips in the family support different readback |
| 221 | * methods. |
| 222 | */ |
| 223 | switch (hubs->dcs_readback_mode) { |
| 224 | case 0: |
| 225 | *reg_l = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_1) |
| 226 | & WM8993_DCS_INTEG_CHAN_0_MASK; |
| 227 | *reg_r = snd_soc_read(codec, WM8993_DC_SERVO_READBACK_2) |
| 228 | & WM8993_DCS_INTEG_CHAN_1_MASK; |
| 229 | break; |
| 230 | case 2: |
| 231 | case 1: |
| 232 | reg = snd_soc_read(codec, dcs_reg); |
| 233 | *reg_r = (reg & WM8993_DCS_DAC_WR_VAL_1_MASK) |
| 234 | >> WM8993_DCS_DAC_WR_VAL_1_SHIFT; |
| 235 | *reg_l = reg & WM8993_DCS_DAC_WR_VAL_0_MASK; |
| 236 | break; |
| 237 | default: |
| 238 | WARN(1, "Unknown DCS readback method\n"); |
| 239 | return; |
| 240 | } |
| 241 | } |
| 242 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 243 | /* |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 244 | * Startup calibration of the DC servo |
| 245 | */ |
Mark Brown | a7892c3 | 2012-07-23 19:50:45 +0100 | [diff] [blame] | 246 | static void enable_dc_servo(struct snd_soc_codec *codec) |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 247 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 248 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 94aa733 | 2012-05-01 18:45:09 +0100 | [diff] [blame] | 249 | struct wm_hubs_dcs_cache *cache; |
Mark Brown | 20a4e7f | 2011-01-21 12:47:33 +0000 | [diff] [blame] | 250 | s8 offset; |
Mark Brown | fae4efa | 2012-07-23 19:49:06 +0100 | [diff] [blame] | 251 | u16 reg_l, reg_r, dcs_cfg, dcs_reg; |
Mark Brown | 79ef0ab | 2011-08-01 13:02:17 +0900 | [diff] [blame] | 252 | |
| 253 | switch (hubs->dcs_readback_mode) { |
| 254 | case 2: |
| 255 | dcs_reg = WM8994_DC_SERVO_4E; |
| 256 | break; |
| 257 | default: |
| 258 | dcs_reg = WM8993_DC_SERVO_3; |
| 259 | break; |
| 260 | } |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 261 | |
Mark Brown | fec6dd8 | 2010-10-27 13:48:36 -0700 | [diff] [blame] | 262 | /* If we're using a digital only path and have a previously |
| 263 | * callibrated DC servo offset stored then use that. */ |
Mark Brown | 94aa733 | 2012-05-01 18:45:09 +0100 | [diff] [blame] | 264 | if (wm_hubs_dac_hp_direct(codec) && |
| 265 | wm_hubs_dcs_cache_get(codec, &cache)) { |
| 266 | dev_dbg(codec->dev, "Using cached DCS offset %x for %d,%d\n", |
| 267 | cache->dcs_cfg, cache->left, cache->right); |
| 268 | snd_soc_write(codec, dcs_reg, cache->dcs_cfg); |
Mark Brown | fec6dd8 | 2010-10-27 13:48:36 -0700 | [diff] [blame] | 269 | wait_for_dc_servo(codec, |
| 270 | WM8993_DCS_TRIG_DAC_WR_0 | |
| 271 | WM8993_DCS_TRIG_DAC_WR_1); |
| 272 | return; |
| 273 | } |
| 274 | |
Mark Brown | f9acf9f | 2011-06-07 23:23:52 +0100 | [diff] [blame] | 275 | if (hubs->series_startup) { |
Mark Brown | 11cef5f | 2010-11-26 17:23:44 +0000 | [diff] [blame] | 276 | /* Set for 32 series updates */ |
| 277 | snd_soc_update_bits(codec, WM8993_DC_SERVO_1, |
| 278 | WM8993_DCS_SERIES_NO_01_MASK, |
| 279 | 32 << WM8993_DCS_SERIES_NO_01_SHIFT); |
| 280 | wait_for_dc_servo(codec, |
| 281 | WM8993_DCS_TRIG_SERIES_0 | |
| 282 | WM8993_DCS_TRIG_SERIES_1); |
| 283 | } else { |
| 284 | wait_for_dc_servo(codec, |
| 285 | WM8993_DCS_TRIG_STARTUP_0 | |
| 286 | WM8993_DCS_TRIG_STARTUP_1); |
| 287 | } |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 288 | |
Mark Brown | fae4efa | 2012-07-23 19:49:06 +0100 | [diff] [blame] | 289 | wm_hubs_read_dc_servo(codec, ®_l, ®_r); |
Mark Brown | fec6dd8 | 2010-10-27 13:48:36 -0700 | [diff] [blame] | 290 | |
| 291 | dev_dbg(codec->dev, "DCS input: %x %x\n", reg_l, reg_r); |
| 292 | |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 293 | /* Apply correction to DC servo result */ |
Mark Brown | 4537c4e | 2011-08-01 13:10:16 +0900 | [diff] [blame] | 294 | if (hubs->dcs_codes_l || hubs->dcs_codes_r) { |
| 295 | dev_dbg(codec->dev, |
| 296 | "Applying %d/%d code DC servo correction\n", |
| 297 | hubs->dcs_codes_l, hubs->dcs_codes_r); |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 298 | |
Mark Brown | d5b040c | 2011-06-07 23:28:45 +0100 | [diff] [blame] | 299 | /* HPOUT1R */ |
Mark Brown | 363947d | 2012-08-20 19:54:24 +0100 | [diff] [blame^] | 300 | offset = (s8)reg_r; |
Mark Brown | 4537c4e | 2011-08-01 13:10:16 +0900 | [diff] [blame] | 301 | offset += hubs->dcs_codes_r; |
Mark Brown | 20a4e7f | 2011-01-21 12:47:33 +0000 | [diff] [blame] | 302 | dcs_cfg = (u8)offset << WM8993_DCS_DAC_WR_VAL_1_SHIFT; |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 303 | |
Mark Brown | d5b040c | 2011-06-07 23:28:45 +0100 | [diff] [blame] | 304 | /* HPOUT1L */ |
Mark Brown | 363947d | 2012-08-20 19:54:24 +0100 | [diff] [blame^] | 305 | offset = (s8)reg_l; |
Mark Brown | 4537c4e | 2011-08-01 13:10:16 +0900 | [diff] [blame] | 306 | offset += hubs->dcs_codes_l; |
Mark Brown | 20a4e7f | 2011-01-21 12:47:33 +0000 | [diff] [blame] | 307 | dcs_cfg |= (u8)offset; |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 308 | |
Mark Brown | 3254d28 | 2010-05-10 14:56:03 +0100 | [diff] [blame] | 309 | dev_dbg(codec->dev, "DCS result: %x\n", dcs_cfg); |
| 310 | |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 311 | /* Do it */ |
Mark Brown | 79ef0ab | 2011-08-01 13:02:17 +0900 | [diff] [blame] | 312 | snd_soc_write(codec, dcs_reg, dcs_cfg); |
Mark Brown | 4dcc93d | 2010-03-29 17:18:41 +0100 | [diff] [blame] | 313 | wait_for_dc_servo(codec, |
| 314 | WM8993_DCS_TRIG_DAC_WR_0 | |
| 315 | WM8993_DCS_TRIG_DAC_WR_1); |
Mark Brown | fec6dd8 | 2010-10-27 13:48:36 -0700 | [diff] [blame] | 316 | } else { |
Mark Brown | d5b040c | 2011-06-07 23:28:45 +0100 | [diff] [blame] | 317 | dcs_cfg = reg_r << WM8993_DCS_DAC_WR_VAL_1_SHIFT; |
| 318 | dcs_cfg |= reg_l; |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 319 | } |
Mark Brown | fec6dd8 | 2010-10-27 13:48:36 -0700 | [diff] [blame] | 320 | |
| 321 | /* Save the callibrated offset if we're in class W mode and |
| 322 | * therefore don't have any analogue signal mixed in. */ |
Mark Brown | 94aa733 | 2012-05-01 18:45:09 +0100 | [diff] [blame] | 323 | if (wm_hubs_dac_hp_direct(codec)) |
| 324 | wm_hubs_dcs_cache_set(codec, dcs_cfg); |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /* |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 328 | * Update the DC servo calibration on gain changes |
| 329 | */ |
| 330 | static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol, |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 331 | struct snd_ctl_elem_value *ucontrol) |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 332 | { |
| 333 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 334 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 335 | int ret; |
| 336 | |
Peter Ujfalusi | c4671a9 | 2011-10-06 09:59:12 +0300 | [diff] [blame] | 337 | ret = snd_soc_put_volsw(kcontrol, ucontrol); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 338 | |
Mark Brown | ae9d860 | 2010-03-29 16:34:42 +0100 | [diff] [blame] | 339 | /* If we're applying an offset correction then updating the |
| 340 | * callibration would be likely to introduce further offsets. */ |
Mark Brown | 4537c4e | 2011-08-01 13:10:16 +0900 | [diff] [blame] | 341 | if (hubs->dcs_codes_l || hubs->dcs_codes_r || hubs->no_series_update) |
Mark Brown | ae9d860 | 2010-03-29 16:34:42 +0100 | [diff] [blame] | 342 | return ret; |
| 343 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 344 | /* Only need to do this if the outputs are active */ |
| 345 | if (snd_soc_read(codec, WM8993_POWER_MANAGEMENT_1) |
| 346 | & (WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA)) |
| 347 | snd_soc_update_bits(codec, |
| 348 | WM8993_DC_SERVO_0, |
| 349 | WM8993_DCS_TRIG_SINGLE_0 | |
| 350 | WM8993_DCS_TRIG_SINGLE_1, |
| 351 | WM8993_DCS_TRIG_SINGLE_0 | |
| 352 | WM8993_DCS_TRIG_SINGLE_1); |
| 353 | |
| 354 | return ret; |
| 355 | } |
| 356 | |
| 357 | static const struct snd_kcontrol_new analogue_snd_controls[] = { |
| 358 | SOC_SINGLE_TLV("IN1L Volume", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 0, 31, 0, |
| 359 | inpga_tlv), |
| 360 | SOC_SINGLE("IN1L Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 7, 1, 1), |
Mark Brown | ea02c63 | 2011-05-27 21:56:16 +0800 | [diff] [blame] | 361 | SOC_SINGLE("IN1L ZC Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 6, 1, 0), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 362 | |
| 363 | SOC_SINGLE_TLV("IN1R Volume", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 0, 31, 0, |
| 364 | inpga_tlv), |
| 365 | SOC_SINGLE("IN1R Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 7, 1, 1), |
Mark Brown | ea02c63 | 2011-05-27 21:56:16 +0800 | [diff] [blame] | 366 | SOC_SINGLE("IN1R ZC Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 6, 1, 0), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 367 | |
| 368 | |
| 369 | SOC_SINGLE_TLV("IN2L Volume", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 0, 31, 0, |
| 370 | inpga_tlv), |
| 371 | SOC_SINGLE("IN2L Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 7, 1, 1), |
Mark Brown | ea02c63 | 2011-05-27 21:56:16 +0800 | [diff] [blame] | 372 | SOC_SINGLE("IN2L ZC Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 6, 1, 0), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 373 | |
| 374 | SOC_SINGLE_TLV("IN2R Volume", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 0, 31, 0, |
| 375 | inpga_tlv), |
| 376 | SOC_SINGLE("IN2R Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 7, 1, 1), |
Mark Brown | ea02c63 | 2011-05-27 21:56:16 +0800 | [diff] [blame] | 377 | SOC_SINGLE("IN2R ZC Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 6, 1, 0), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 378 | |
| 379 | SOC_SINGLE_TLV("MIXINL IN2L Volume", WM8993_INPUT_MIXER3, 7, 1, 0, |
| 380 | inmix_sw_tlv), |
| 381 | SOC_SINGLE_TLV("MIXINL IN1L Volume", WM8993_INPUT_MIXER3, 4, 1, 0, |
| 382 | inmix_sw_tlv), |
| 383 | SOC_SINGLE_TLV("MIXINL Output Record Volume", WM8993_INPUT_MIXER3, 0, 7, 0, |
| 384 | inmix_tlv), |
| 385 | SOC_SINGLE_TLV("MIXINL IN1LP Volume", WM8993_INPUT_MIXER5, 6, 7, 0, inmix_tlv), |
| 386 | SOC_SINGLE_TLV("MIXINL Direct Voice Volume", WM8993_INPUT_MIXER5, 0, 6, 0, |
| 387 | inmix_tlv), |
| 388 | |
| 389 | SOC_SINGLE_TLV("MIXINR IN2R Volume", WM8993_INPUT_MIXER4, 7, 1, 0, |
| 390 | inmix_sw_tlv), |
| 391 | SOC_SINGLE_TLV("MIXINR IN1R Volume", WM8993_INPUT_MIXER4, 4, 1, 0, |
| 392 | inmix_sw_tlv), |
| 393 | SOC_SINGLE_TLV("MIXINR Output Record Volume", WM8993_INPUT_MIXER4, 0, 7, 0, |
| 394 | inmix_tlv), |
| 395 | SOC_SINGLE_TLV("MIXINR IN1RP Volume", WM8993_INPUT_MIXER6, 6, 7, 0, inmix_tlv), |
| 396 | SOC_SINGLE_TLV("MIXINR Direct Voice Volume", WM8993_INPUT_MIXER6, 0, 6, 0, |
| 397 | inmix_tlv), |
| 398 | |
| 399 | SOC_SINGLE_TLV("Left Output Mixer IN2RN Volume", WM8993_OUTPUT_MIXER5, 6, 7, 1, |
| 400 | outmix_tlv), |
| 401 | SOC_SINGLE_TLV("Left Output Mixer IN2LN Volume", WM8993_OUTPUT_MIXER3, 6, 7, 1, |
| 402 | outmix_tlv), |
| 403 | SOC_SINGLE_TLV("Left Output Mixer IN2LP Volume", WM8993_OUTPUT_MIXER3, 9, 7, 1, |
| 404 | outmix_tlv), |
| 405 | SOC_SINGLE_TLV("Left Output Mixer IN1L Volume", WM8993_OUTPUT_MIXER3, 0, 7, 1, |
| 406 | outmix_tlv), |
| 407 | SOC_SINGLE_TLV("Left Output Mixer IN1R Volume", WM8993_OUTPUT_MIXER3, 3, 7, 1, |
| 408 | outmix_tlv), |
| 409 | SOC_SINGLE_TLV("Left Output Mixer Right Input Volume", |
| 410 | WM8993_OUTPUT_MIXER5, 3, 7, 1, outmix_tlv), |
| 411 | SOC_SINGLE_TLV("Left Output Mixer Left Input Volume", |
| 412 | WM8993_OUTPUT_MIXER5, 0, 7, 1, outmix_tlv), |
| 413 | SOC_SINGLE_TLV("Left Output Mixer DAC Volume", WM8993_OUTPUT_MIXER5, 9, 7, 1, |
| 414 | outmix_tlv), |
| 415 | |
| 416 | SOC_SINGLE_TLV("Right Output Mixer IN2LN Volume", |
| 417 | WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv), |
| 418 | SOC_SINGLE_TLV("Right Output Mixer IN2RN Volume", |
| 419 | WM8993_OUTPUT_MIXER4, 6, 7, 1, outmix_tlv), |
| 420 | SOC_SINGLE_TLV("Right Output Mixer IN1L Volume", |
| 421 | WM8993_OUTPUT_MIXER4, 3, 7, 1, outmix_tlv), |
| 422 | SOC_SINGLE_TLV("Right Output Mixer IN1R Volume", |
| 423 | WM8993_OUTPUT_MIXER4, 0, 7, 1, outmix_tlv), |
| 424 | SOC_SINGLE_TLV("Right Output Mixer IN2RP Volume", |
| 425 | WM8993_OUTPUT_MIXER4, 9, 7, 1, outmix_tlv), |
| 426 | SOC_SINGLE_TLV("Right Output Mixer Left Input Volume", |
| 427 | WM8993_OUTPUT_MIXER6, 3, 7, 1, outmix_tlv), |
| 428 | SOC_SINGLE_TLV("Right Output Mixer Right Input Volume", |
| 429 | WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv), |
| 430 | SOC_SINGLE_TLV("Right Output Mixer DAC Volume", |
| 431 | WM8993_OUTPUT_MIXER6, 9, 7, 1, outmix_tlv), |
| 432 | |
| 433 | SOC_DOUBLE_R_TLV("Output Volume", WM8993_LEFT_OPGA_VOLUME, |
| 434 | WM8993_RIGHT_OPGA_VOLUME, 0, 63, 0, outpga_tlv), |
| 435 | SOC_DOUBLE_R("Output Switch", WM8993_LEFT_OPGA_VOLUME, |
| 436 | WM8993_RIGHT_OPGA_VOLUME, 6, 1, 0), |
| 437 | SOC_DOUBLE_R("Output ZC Switch", WM8993_LEFT_OPGA_VOLUME, |
| 438 | WM8993_RIGHT_OPGA_VOLUME, 7, 1, 0), |
| 439 | |
| 440 | SOC_SINGLE("Earpiece Switch", WM8993_HPOUT2_VOLUME, 5, 1, 1), |
| 441 | SOC_SINGLE_TLV("Earpiece Volume", WM8993_HPOUT2_VOLUME, 4, 1, 1, earpiece_tlv), |
| 442 | |
| 443 | SOC_SINGLE_TLV("SPKL Input Volume", WM8993_SPKMIXL_ATTENUATION, |
| 444 | 5, 1, 1, wm_hubs_spkmix_tlv), |
| 445 | SOC_SINGLE_TLV("SPKL IN1LP Volume", WM8993_SPKMIXL_ATTENUATION, |
| 446 | 4, 1, 1, wm_hubs_spkmix_tlv), |
| 447 | SOC_SINGLE_TLV("SPKL Output Volume", WM8993_SPKMIXL_ATTENUATION, |
| 448 | 3, 1, 1, wm_hubs_spkmix_tlv), |
| 449 | |
| 450 | SOC_SINGLE_TLV("SPKR Input Volume", WM8993_SPKMIXR_ATTENUATION, |
| 451 | 5, 1, 1, wm_hubs_spkmix_tlv), |
| 452 | SOC_SINGLE_TLV("SPKR IN1RP Volume", WM8993_SPKMIXR_ATTENUATION, |
| 453 | 4, 1, 1, wm_hubs_spkmix_tlv), |
| 454 | SOC_SINGLE_TLV("SPKR Output Volume", WM8993_SPKMIXR_ATTENUATION, |
| 455 | 3, 1, 1, wm_hubs_spkmix_tlv), |
| 456 | |
| 457 | SOC_DOUBLE_R_TLV("Speaker Mixer Volume", |
| 458 | WM8993_SPKMIXL_ATTENUATION, WM8993_SPKMIXR_ATTENUATION, |
| 459 | 0, 3, 1, spkmixout_tlv), |
| 460 | SOC_DOUBLE_R_TLV("Speaker Volume", |
| 461 | WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT, |
| 462 | 0, 63, 0, outpga_tlv), |
| 463 | SOC_DOUBLE_R("Speaker Switch", |
| 464 | WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT, |
| 465 | 6, 1, 0), |
| 466 | SOC_DOUBLE_R("Speaker ZC Switch", |
| 467 | WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT, |
| 468 | 7, 1, 0), |
Uk Kim | ed8cc47 | 2010-12-05 17:26:07 +0900 | [diff] [blame] | 469 | SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST, 3, 0, 7, 0, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 470 | spkboost_tlv), |
| 471 | SOC_ENUM("Speaker Reference", speaker_ref), |
| 472 | SOC_ENUM("Speaker Mode", speaker_mode), |
| 473 | |
Peter Ujfalusi | 0f9887d | 2011-10-05 10:29:19 +0300 | [diff] [blame] | 474 | SOC_DOUBLE_R_EXT_TLV("Headphone Volume", |
| 475 | WM8993_LEFT_OUTPUT_VOLUME, WM8993_RIGHT_OUTPUT_VOLUME, |
Peter Ujfalusi | c4671a9 | 2011-10-06 09:59:12 +0300 | [diff] [blame] | 476 | 0, 63, 0, snd_soc_get_volsw, wm8993_put_dc_servo, |
Peter Ujfalusi | 0f9887d | 2011-10-05 10:29:19 +0300 | [diff] [blame] | 477 | outpga_tlv), |
| 478 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 479 | SOC_DOUBLE_R("Headphone Switch", WM8993_LEFT_OUTPUT_VOLUME, |
| 480 | WM8993_RIGHT_OUTPUT_VOLUME, 6, 1, 0), |
| 481 | SOC_DOUBLE_R("Headphone ZC Switch", WM8993_LEFT_OUTPUT_VOLUME, |
| 482 | WM8993_RIGHT_OUTPUT_VOLUME, 7, 1, 0), |
| 483 | |
| 484 | SOC_SINGLE("LINEOUT1N Switch", WM8993_LINE_OUTPUTS_VOLUME, 6, 1, 1), |
| 485 | SOC_SINGLE("LINEOUT1P Switch", WM8993_LINE_OUTPUTS_VOLUME, 5, 1, 1), |
| 486 | SOC_SINGLE_TLV("LINEOUT1 Volume", WM8993_LINE_OUTPUTS_VOLUME, 4, 1, 1, |
| 487 | line_tlv), |
| 488 | |
| 489 | SOC_SINGLE("LINEOUT2N Switch", WM8993_LINE_OUTPUTS_VOLUME, 2, 1, 1), |
| 490 | SOC_SINGLE("LINEOUT2P Switch", WM8993_LINE_OUTPUTS_VOLUME, 1, 1, 1), |
| 491 | SOC_SINGLE_TLV("LINEOUT2 Volume", WM8993_LINE_OUTPUTS_VOLUME, 0, 1, 1, |
| 492 | line_tlv), |
| 493 | }; |
| 494 | |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 495 | static int hp_supply_event(struct snd_soc_dapm_widget *w, |
| 496 | struct snd_kcontrol *kcontrol, int event) |
| 497 | { |
| 498 | struct snd_soc_codec *codec = w->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 499 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 500 | |
| 501 | switch (event) { |
| 502 | case SND_SOC_DAPM_PRE_PMU: |
| 503 | switch (hubs->hp_startup_mode) { |
| 504 | case 0: |
| 505 | break; |
| 506 | case 1: |
| 507 | /* Enable the headphone amp */ |
| 508 | snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1, |
| 509 | WM8993_HPOUT1L_ENA | |
| 510 | WM8993_HPOUT1R_ENA, |
| 511 | WM8993_HPOUT1L_ENA | |
| 512 | WM8993_HPOUT1R_ENA); |
| 513 | |
| 514 | /* Enable the second stage */ |
| 515 | snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0, |
| 516 | WM8993_HPOUT1L_DLY | |
| 517 | WM8993_HPOUT1R_DLY, |
| 518 | WM8993_HPOUT1L_DLY | |
| 519 | WM8993_HPOUT1R_DLY); |
| 520 | break; |
| 521 | default: |
| 522 | dev_err(codec->dev, "Unknown HP startup mode %d\n", |
| 523 | hubs->hp_startup_mode); |
| 524 | break; |
| 525 | } |
| 526 | |
| 527 | case SND_SOC_DAPM_PRE_PMD: |
| 528 | snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1, |
| 529 | WM8993_CP_ENA, 0); |
| 530 | break; |
| 531 | } |
| 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 536 | static int hp_event(struct snd_soc_dapm_widget *w, |
| 537 | struct snd_kcontrol *kcontrol, int event) |
| 538 | { |
| 539 | struct snd_soc_codec *codec = w->codec; |
| 540 | unsigned int reg = snd_soc_read(codec, WM8993_ANALOGUE_HP_0); |
| 541 | |
| 542 | switch (event) { |
| 543 | case SND_SOC_DAPM_POST_PMU: |
| 544 | snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1, |
| 545 | WM8993_CP_ENA, WM8993_CP_ENA); |
| 546 | |
| 547 | msleep(5); |
| 548 | |
| 549 | snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1, |
| 550 | WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA, |
| 551 | WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA); |
| 552 | |
| 553 | reg |= WM8993_HPOUT1L_DLY | WM8993_HPOUT1R_DLY; |
| 554 | snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg); |
| 555 | |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 556 | snd_soc_update_bits(codec, WM8993_DC_SERVO_1, |
Mark Brown | f9925d4 | 2011-07-28 12:44:44 +0100 | [diff] [blame] | 557 | WM8993_DCS_TIMER_PERIOD_01_MASK, 0); |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 558 | |
Mark Brown | a7892c3 | 2012-07-23 19:50:45 +0100 | [diff] [blame] | 559 | enable_dc_servo(codec); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 560 | |
| 561 | reg |= WM8993_HPOUT1R_OUTP | WM8993_HPOUT1R_RMV_SHORT | |
| 562 | WM8993_HPOUT1L_OUTP | WM8993_HPOUT1L_RMV_SHORT; |
| 563 | snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg); |
| 564 | break; |
| 565 | |
| 566 | case SND_SOC_DAPM_PRE_PMD: |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 567 | snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0, |
Mark Brown | 6adb26b | 2010-05-10 16:13:11 +0100 | [diff] [blame] | 568 | WM8993_HPOUT1L_OUTP | |
| 569 | WM8993_HPOUT1R_OUTP | |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 570 | WM8993_HPOUT1L_RMV_SHORT | |
| 571 | WM8993_HPOUT1R_RMV_SHORT, 0); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 572 | |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 573 | snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0, |
Mark Brown | 6adb26b | 2010-05-10 16:13:11 +0100 | [diff] [blame] | 574 | WM8993_HPOUT1L_DLY | |
| 575 | WM8993_HPOUT1R_DLY, 0); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 576 | |
Mark Brown | 395e4b7 | 2010-05-10 21:06:14 +0100 | [diff] [blame] | 577 | snd_soc_write(codec, WM8993_DC_SERVO_0, 0); |
| 578 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 579 | snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1, |
| 580 | WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA, |
| 581 | 0); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 582 | break; |
| 583 | } |
| 584 | |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | static int earpiece_event(struct snd_soc_dapm_widget *w, |
| 589 | struct snd_kcontrol *control, int event) |
| 590 | { |
| 591 | struct snd_soc_codec *codec = w->codec; |
| 592 | u16 reg = snd_soc_read(codec, WM8993_ANTIPOP1) & ~WM8993_HPOUT2_IN_ENA; |
| 593 | |
| 594 | switch (event) { |
| 595 | case SND_SOC_DAPM_PRE_PMU: |
| 596 | reg |= WM8993_HPOUT2_IN_ENA; |
| 597 | snd_soc_write(codec, WM8993_ANTIPOP1, reg); |
| 598 | udelay(50); |
| 599 | break; |
| 600 | |
| 601 | case SND_SOC_DAPM_POST_PMD: |
| 602 | snd_soc_write(codec, WM8993_ANTIPOP1, reg); |
| 603 | break; |
| 604 | |
| 605 | default: |
| 606 | BUG(); |
| 607 | break; |
| 608 | } |
| 609 | |
| 610 | return 0; |
| 611 | } |
| 612 | |
Mark Brown | 5f2f3890 | 2012-02-08 18:51:42 +0000 | [diff] [blame] | 613 | static int lineout_event(struct snd_soc_dapm_widget *w, |
| 614 | struct snd_kcontrol *control, int event) |
| 615 | { |
| 616 | struct snd_soc_codec *codec = w->codec; |
| 617 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
| 618 | bool *flag; |
| 619 | |
| 620 | switch (w->shift) { |
| 621 | case WM8993_LINEOUT1N_ENA_SHIFT: |
| 622 | flag = &hubs->lineout1n_ena; |
| 623 | break; |
| 624 | case WM8993_LINEOUT1P_ENA_SHIFT: |
| 625 | flag = &hubs->lineout1p_ena; |
| 626 | break; |
| 627 | case WM8993_LINEOUT2N_ENA_SHIFT: |
| 628 | flag = &hubs->lineout2n_ena; |
| 629 | break; |
| 630 | case WM8993_LINEOUT2P_ENA_SHIFT: |
| 631 | flag = &hubs->lineout2p_ena; |
| 632 | break; |
| 633 | default: |
| 634 | WARN(1, "Unknown line output"); |
| 635 | return -EINVAL; |
| 636 | } |
| 637 | |
| 638 | *flag = SND_SOC_DAPM_EVENT_ON(event); |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
Mark Brown | c340304 | 2012-04-26 21:29:29 +0100 | [diff] [blame] | 643 | void wm_hubs_update_class_w(struct snd_soc_codec *codec) |
| 644 | { |
| 645 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
| 646 | int enable = WM8993_CP_DYN_V | WM8993_CP_DYN_FREQ; |
| 647 | |
| 648 | if (!wm_hubs_dac_hp_direct(codec)) |
| 649 | enable = false; |
| 650 | |
| 651 | if (hubs->check_class_w_digital && !hubs->check_class_w_digital(codec)) |
| 652 | enable = false; |
| 653 | |
| 654 | dev_vdbg(codec->dev, "Class W %s\n", enable ? "enabled" : "disabled"); |
| 655 | |
| 656 | snd_soc_update_bits(codec, WM8993_CLASS_W_0, |
| 657 | WM8993_CP_DYN_V | WM8993_CP_DYN_FREQ, enable); |
| 658 | } |
| 659 | EXPORT_SYMBOL_GPL(wm_hubs_update_class_w); |
| 660 | |
Mark Brown | 04de57c | 2012-04-26 22:08:50 +0100 | [diff] [blame] | 661 | #define WM_HUBS_SINGLE_W(xname, reg, shift, max, invert) \ |
| 662 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 663 | .info = snd_soc_info_volsw, \ |
| 664 | .get = snd_soc_dapm_get_volsw, .put = class_w_put_volsw, \ |
| 665 | .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) } |
| 666 | |
| 667 | static int class_w_put_volsw(struct snd_kcontrol *kcontrol, |
| 668 | struct snd_ctl_elem_value *ucontrol) |
| 669 | { |
| 670 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 671 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 672 | struct snd_soc_codec *codec = widget->codec; |
| 673 | int ret; |
| 674 | |
| 675 | ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); |
| 676 | |
| 677 | wm_hubs_update_class_w(codec); |
| 678 | |
| 679 | return ret; |
| 680 | } |
| 681 | |
Mark Brown | c340304 | 2012-04-26 21:29:29 +0100 | [diff] [blame] | 682 | #define WM_HUBS_ENUM_W(xname, xenum) \ |
| 683 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 684 | .info = snd_soc_info_enum_double, \ |
| 685 | .get = snd_soc_dapm_get_enum_double, \ |
Mark Brown | 04de57c | 2012-04-26 22:08:50 +0100 | [diff] [blame] | 686 | .put = class_w_put_double, \ |
Mark Brown | c340304 | 2012-04-26 21:29:29 +0100 | [diff] [blame] | 687 | .private_value = (unsigned long)&xenum } |
| 688 | |
Mark Brown | 04de57c | 2012-04-26 22:08:50 +0100 | [diff] [blame] | 689 | static int class_w_put_double(struct snd_kcontrol *kcontrol, |
| 690 | struct snd_ctl_elem_value *ucontrol) |
Mark Brown | c340304 | 2012-04-26 21:29:29 +0100 | [diff] [blame] | 691 | { |
| 692 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 693 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 694 | struct snd_soc_codec *codec = widget->codec; |
| 695 | int ret; |
| 696 | |
| 697 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 698 | |
| 699 | wm_hubs_update_class_w(codec); |
| 700 | |
| 701 | return ret; |
| 702 | } |
| 703 | |
| 704 | static const char *hp_mux_text[] = { |
| 705 | "Mixer", |
| 706 | "DAC", |
| 707 | }; |
| 708 | |
| 709 | static const struct soc_enum hpl_enum = |
| 710 | SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER1, 8, 2, hp_mux_text); |
| 711 | |
| 712 | const struct snd_kcontrol_new wm_hubs_hpl_mux = |
| 713 | WM_HUBS_ENUM_W("Left Headphone Mux", hpl_enum); |
| 714 | EXPORT_SYMBOL_GPL(wm_hubs_hpl_mux); |
| 715 | |
| 716 | static const struct soc_enum hpr_enum = |
| 717 | SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER2, 8, 2, hp_mux_text); |
| 718 | |
| 719 | const struct snd_kcontrol_new wm_hubs_hpr_mux = |
| 720 | WM_HUBS_ENUM_W("Right Headphone Mux", hpr_enum); |
| 721 | EXPORT_SYMBOL_GPL(wm_hubs_hpr_mux); |
| 722 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 723 | static const struct snd_kcontrol_new in1l_pga[] = { |
| 724 | SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0), |
| 725 | SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0), |
| 726 | }; |
| 727 | |
| 728 | static const struct snd_kcontrol_new in1r_pga[] = { |
| 729 | SOC_DAPM_SINGLE("IN1RP Switch", WM8993_INPUT_MIXER2, 1, 1, 0), |
| 730 | SOC_DAPM_SINGLE("IN1RN Switch", WM8993_INPUT_MIXER2, 0, 1, 0), |
| 731 | }; |
| 732 | |
| 733 | static const struct snd_kcontrol_new in2l_pga[] = { |
| 734 | SOC_DAPM_SINGLE("IN2LP Switch", WM8993_INPUT_MIXER2, 7, 1, 0), |
| 735 | SOC_DAPM_SINGLE("IN2LN Switch", WM8993_INPUT_MIXER2, 6, 1, 0), |
| 736 | }; |
| 737 | |
| 738 | static const struct snd_kcontrol_new in2r_pga[] = { |
| 739 | SOC_DAPM_SINGLE("IN2RP Switch", WM8993_INPUT_MIXER2, 3, 1, 0), |
| 740 | SOC_DAPM_SINGLE("IN2RN Switch", WM8993_INPUT_MIXER2, 2, 1, 0), |
| 741 | }; |
| 742 | |
| 743 | static const struct snd_kcontrol_new mixinl[] = { |
| 744 | SOC_DAPM_SINGLE("IN2L Switch", WM8993_INPUT_MIXER3, 8, 1, 0), |
| 745 | SOC_DAPM_SINGLE("IN1L Switch", WM8993_INPUT_MIXER3, 5, 1, 0), |
| 746 | }; |
| 747 | |
| 748 | static const struct snd_kcontrol_new mixinr[] = { |
| 749 | SOC_DAPM_SINGLE("IN2R Switch", WM8993_INPUT_MIXER4, 8, 1, 0), |
| 750 | SOC_DAPM_SINGLE("IN1R Switch", WM8993_INPUT_MIXER4, 5, 1, 0), |
| 751 | }; |
| 752 | |
| 753 | static const struct snd_kcontrol_new left_output_mixer[] = { |
Mark Brown | 04de57c | 2012-04-26 22:08:50 +0100 | [diff] [blame] | 754 | WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0), |
| 755 | WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0), |
| 756 | WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0), |
| 757 | WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0), |
| 758 | WM_HUBS_SINGLE_W("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0), |
| 759 | WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0), |
| 760 | WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0), |
| 761 | WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 762 | }; |
| 763 | |
| 764 | static const struct snd_kcontrol_new right_output_mixer[] = { |
Mark Brown | 04de57c | 2012-04-26 22:08:50 +0100 | [diff] [blame] | 765 | WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0), |
| 766 | WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0), |
| 767 | WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0), |
| 768 | WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0), |
| 769 | WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0), |
| 770 | WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0), |
| 771 | WM_HUBS_SINGLE_W("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0), |
| 772 | WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 773 | }; |
| 774 | |
| 775 | static const struct snd_kcontrol_new earpiece_mixer[] = { |
| 776 | SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_HPOUT2_MIXER, 5, 1, 0), |
| 777 | SOC_DAPM_SINGLE("Left Output Switch", WM8993_HPOUT2_MIXER, 4, 1, 0), |
| 778 | SOC_DAPM_SINGLE("Right Output Switch", WM8993_HPOUT2_MIXER, 3, 1, 0), |
| 779 | }; |
| 780 | |
| 781 | static const struct snd_kcontrol_new left_speaker_boost[] = { |
| 782 | SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 5, 1, 0), |
| 783 | SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 4, 1, 0), |
| 784 | SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 3, 1, 0), |
| 785 | }; |
| 786 | |
| 787 | static const struct snd_kcontrol_new right_speaker_boost[] = { |
| 788 | SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 2, 1, 0), |
| 789 | SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 1, 1, 0), |
| 790 | SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 0, 1, 0), |
| 791 | }; |
| 792 | |
| 793 | static const struct snd_kcontrol_new line1_mix[] = { |
| 794 | SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER1, 2, 1, 0), |
| 795 | SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER1, 1, 1, 0), |
| 796 | SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER1, 0, 1, 0), |
| 797 | }; |
| 798 | |
| 799 | static const struct snd_kcontrol_new line1n_mix[] = { |
| 800 | SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 6, 1, 0), |
| 801 | SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER1, 5, 1, 0), |
| 802 | }; |
| 803 | |
| 804 | static const struct snd_kcontrol_new line1p_mix[] = { |
| 805 | SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 0, 1, 0), |
| 806 | }; |
| 807 | |
| 808 | static const struct snd_kcontrol_new line2_mix[] = { |
Mark Brown | 43b6cec | 2012-02-01 23:46:58 +0000 | [diff] [blame] | 809 | SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER2, 2, 1, 0), |
| 810 | SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER2, 1, 1, 0), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 811 | SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER2, 0, 1, 0), |
| 812 | }; |
| 813 | |
| 814 | static const struct snd_kcontrol_new line2n_mix[] = { |
UK KIM | 114395c | 2012-01-28 01:52:22 +0900 | [diff] [blame] | 815 | SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER2, 5, 1, 0), |
| 816 | SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 6, 1, 0), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 817 | }; |
| 818 | |
| 819 | static const struct snd_kcontrol_new line2p_mix[] = { |
| 820 | SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 0, 1, 0), |
| 821 | }; |
| 822 | |
| 823 | static const struct snd_soc_dapm_widget analogue_dapm_widgets[] = { |
| 824 | SND_SOC_DAPM_INPUT("IN1LN"), |
| 825 | SND_SOC_DAPM_INPUT("IN1LP"), |
| 826 | SND_SOC_DAPM_INPUT("IN2LN"), |
Joonyoung Shim | 3482594 | 2009-12-04 15:12:10 +0900 | [diff] [blame] | 827 | SND_SOC_DAPM_INPUT("IN2LP:VXRN"), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 828 | SND_SOC_DAPM_INPUT("IN1RN"), |
| 829 | SND_SOC_DAPM_INPUT("IN1RP"), |
| 830 | SND_SOC_DAPM_INPUT("IN2RN"), |
Joonyoung Shim | 3482594 | 2009-12-04 15:12:10 +0900 | [diff] [blame] | 831 | SND_SOC_DAPM_INPUT("IN2RP:VXRP"), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 832 | |
Mark Brown | 91e2085 | 2011-12-02 16:01:41 +0000 | [diff] [blame] | 833 | SND_SOC_DAPM_SUPPLY("MICBIAS2", WM8993_POWER_MANAGEMENT_1, 5, 0, NULL, 0), |
| 834 | SND_SOC_DAPM_SUPPLY("MICBIAS1", WM8993_POWER_MANAGEMENT_1, 4, 0, NULL, 0), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 835 | |
| 836 | SND_SOC_DAPM_MIXER("IN1L PGA", WM8993_POWER_MANAGEMENT_2, 6, 0, |
| 837 | in1l_pga, ARRAY_SIZE(in1l_pga)), |
| 838 | SND_SOC_DAPM_MIXER("IN1R PGA", WM8993_POWER_MANAGEMENT_2, 4, 0, |
| 839 | in1r_pga, ARRAY_SIZE(in1r_pga)), |
| 840 | |
| 841 | SND_SOC_DAPM_MIXER("IN2L PGA", WM8993_POWER_MANAGEMENT_2, 7, 0, |
| 842 | in2l_pga, ARRAY_SIZE(in2l_pga)), |
| 843 | SND_SOC_DAPM_MIXER("IN2R PGA", WM8993_POWER_MANAGEMENT_2, 5, 0, |
| 844 | in2r_pga, ARRAY_SIZE(in2r_pga)), |
| 845 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 846 | SND_SOC_DAPM_MIXER("MIXINL", WM8993_POWER_MANAGEMENT_2, 9, 0, |
| 847 | mixinl, ARRAY_SIZE(mixinl)), |
| 848 | SND_SOC_DAPM_MIXER("MIXINR", WM8993_POWER_MANAGEMENT_2, 8, 0, |
| 849 | mixinr, ARRAY_SIZE(mixinr)), |
| 850 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 851 | SND_SOC_DAPM_MIXER("Left Output Mixer", WM8993_POWER_MANAGEMENT_3, 5, 0, |
| 852 | left_output_mixer, ARRAY_SIZE(left_output_mixer)), |
| 853 | SND_SOC_DAPM_MIXER("Right Output Mixer", WM8993_POWER_MANAGEMENT_3, 4, 0, |
| 854 | right_output_mixer, ARRAY_SIZE(right_output_mixer)), |
| 855 | |
| 856 | SND_SOC_DAPM_PGA("Left Output PGA", WM8993_POWER_MANAGEMENT_3, 7, 0, NULL, 0), |
| 857 | SND_SOC_DAPM_PGA("Right Output PGA", WM8993_POWER_MANAGEMENT_3, 6, 0, NULL, 0), |
| 858 | |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 859 | SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0, hp_supply_event, |
| 860 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), |
Mark Brown | 2642262 | 2012-02-21 09:36:49 +0000 | [diff] [blame] | 861 | SND_SOC_DAPM_OUT_DRV_E("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0, |
| 862 | hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 863 | |
| 864 | SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0, |
| 865 | earpiece_mixer, ARRAY_SIZE(earpiece_mixer)), |
| 866 | SND_SOC_DAPM_PGA_E("Earpiece Driver", WM8993_POWER_MANAGEMENT_1, 11, 0, |
| 867 | NULL, 0, earpiece_event, |
| 868 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 869 | |
| 870 | SND_SOC_DAPM_MIXER("SPKL Boost", SND_SOC_NOPM, 0, 0, |
| 871 | left_speaker_boost, ARRAY_SIZE(left_speaker_boost)), |
| 872 | SND_SOC_DAPM_MIXER("SPKR Boost", SND_SOC_NOPM, 0, 0, |
| 873 | right_speaker_boost, ARRAY_SIZE(right_speaker_boost)), |
| 874 | |
Mark Brown | 0343197 | 2011-11-04 17:11:54 +0000 | [diff] [blame] | 875 | SND_SOC_DAPM_SUPPLY("TSHUT", WM8993_POWER_MANAGEMENT_2, 14, 0, NULL, 0), |
Mark Brown | dc9c745 | 2012-02-07 14:24:57 +0000 | [diff] [blame] | 876 | SND_SOC_DAPM_OUT_DRV("SPKL Driver", WM8993_POWER_MANAGEMENT_1, 12, 0, |
| 877 | NULL, 0), |
| 878 | SND_SOC_DAPM_OUT_DRV("SPKR Driver", WM8993_POWER_MANAGEMENT_1, 13, 0, |
| 879 | NULL, 0), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 880 | |
| 881 | SND_SOC_DAPM_MIXER("LINEOUT1 Mixer", SND_SOC_NOPM, 0, 0, |
| 882 | line1_mix, ARRAY_SIZE(line1_mix)), |
| 883 | SND_SOC_DAPM_MIXER("LINEOUT2 Mixer", SND_SOC_NOPM, 0, 0, |
| 884 | line2_mix, ARRAY_SIZE(line2_mix)), |
| 885 | |
| 886 | SND_SOC_DAPM_MIXER("LINEOUT1N Mixer", SND_SOC_NOPM, 0, 0, |
| 887 | line1n_mix, ARRAY_SIZE(line1n_mix)), |
| 888 | SND_SOC_DAPM_MIXER("LINEOUT1P Mixer", SND_SOC_NOPM, 0, 0, |
| 889 | line1p_mix, ARRAY_SIZE(line1p_mix)), |
| 890 | SND_SOC_DAPM_MIXER("LINEOUT2N Mixer", SND_SOC_NOPM, 0, 0, |
| 891 | line2n_mix, ARRAY_SIZE(line2n_mix)), |
| 892 | SND_SOC_DAPM_MIXER("LINEOUT2P Mixer", SND_SOC_NOPM, 0, 0, |
| 893 | line2p_mix, ARRAY_SIZE(line2p_mix)), |
| 894 | |
Mark Brown | 5f2f3890 | 2012-02-08 18:51:42 +0000 | [diff] [blame] | 895 | SND_SOC_DAPM_OUT_DRV_E("LINEOUT1N Driver", WM8993_POWER_MANAGEMENT_3, 13, 0, |
| 896 | NULL, 0, lineout_event, |
| 897 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 898 | SND_SOC_DAPM_OUT_DRV_E("LINEOUT1P Driver", WM8993_POWER_MANAGEMENT_3, 12, 0, |
| 899 | NULL, 0, lineout_event, |
| 900 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 901 | SND_SOC_DAPM_OUT_DRV_E("LINEOUT2N Driver", WM8993_POWER_MANAGEMENT_3, 11, 0, |
| 902 | NULL, 0, lineout_event, |
| 903 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 904 | SND_SOC_DAPM_OUT_DRV_E("LINEOUT2P Driver", WM8993_POWER_MANAGEMENT_3, 10, 0, |
| 905 | NULL, 0, lineout_event, |
| 906 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 907 | |
| 908 | SND_SOC_DAPM_OUTPUT("SPKOUTLP"), |
| 909 | SND_SOC_DAPM_OUTPUT("SPKOUTLN"), |
| 910 | SND_SOC_DAPM_OUTPUT("SPKOUTRP"), |
| 911 | SND_SOC_DAPM_OUTPUT("SPKOUTRN"), |
| 912 | SND_SOC_DAPM_OUTPUT("HPOUT1L"), |
| 913 | SND_SOC_DAPM_OUTPUT("HPOUT1R"), |
| 914 | SND_SOC_DAPM_OUTPUT("HPOUT2P"), |
| 915 | SND_SOC_DAPM_OUTPUT("HPOUT2N"), |
| 916 | SND_SOC_DAPM_OUTPUT("LINEOUT1P"), |
| 917 | SND_SOC_DAPM_OUTPUT("LINEOUT1N"), |
| 918 | SND_SOC_DAPM_OUTPUT("LINEOUT2P"), |
| 919 | SND_SOC_DAPM_OUTPUT("LINEOUT2N"), |
| 920 | }; |
| 921 | |
| 922 | static const struct snd_soc_dapm_route analogue_routes[] = { |
Mark Brown | 4baafdd | 2011-02-18 15:05:53 -0800 | [diff] [blame] | 923 | { "MICBIAS1", NULL, "CLK_SYS" }, |
| 924 | { "MICBIAS2", NULL, "CLK_SYS" }, |
| 925 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 926 | { "IN1L PGA", "IN1LP Switch", "IN1LP" }, |
| 927 | { "IN1L PGA", "IN1LN Switch", "IN1LN" }, |
| 928 | |
Mark Brown | 4e04ada | 2011-07-15 15:12:31 +0900 | [diff] [blame] | 929 | { "IN1L PGA", NULL, "VMID" }, |
| 930 | { "IN1R PGA", NULL, "VMID" }, |
| 931 | { "IN2L PGA", NULL, "VMID" }, |
| 932 | { "IN2R PGA", NULL, "VMID" }, |
| 933 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 934 | { "IN1R PGA", "IN1RP Switch", "IN1RP" }, |
| 935 | { "IN1R PGA", "IN1RN Switch", "IN1RN" }, |
| 936 | |
Joonyoung Shim | 3482594 | 2009-12-04 15:12:10 +0900 | [diff] [blame] | 937 | { "IN2L PGA", "IN2LP Switch", "IN2LP:VXRN" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 938 | { "IN2L PGA", "IN2LN Switch", "IN2LN" }, |
| 939 | |
Joonyoung Shim | 3482594 | 2009-12-04 15:12:10 +0900 | [diff] [blame] | 940 | { "IN2R PGA", "IN2RP Switch", "IN2RP:VXRP" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 941 | { "IN2R PGA", "IN2RN Switch", "IN2RN" }, |
| 942 | |
Joonyoung Shim | 3482594 | 2009-12-04 15:12:10 +0900 | [diff] [blame] | 943 | { "Direct Voice", NULL, "IN2LP:VXRN" }, |
| 944 | { "Direct Voice", NULL, "IN2RP:VXRP" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 945 | |
| 946 | { "MIXINL", "IN1L Switch", "IN1L PGA" }, |
| 947 | { "MIXINL", "IN2L Switch", "IN2L PGA" }, |
| 948 | { "MIXINL", NULL, "Direct Voice" }, |
| 949 | { "MIXINL", NULL, "IN1LP" }, |
| 950 | { "MIXINL", NULL, "Left Output Mixer" }, |
Mark Brown | 4e04ada | 2011-07-15 15:12:31 +0900 | [diff] [blame] | 951 | { "MIXINL", NULL, "VMID" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 952 | |
| 953 | { "MIXINR", "IN1R Switch", "IN1R PGA" }, |
| 954 | { "MIXINR", "IN2R Switch", "IN2R PGA" }, |
| 955 | { "MIXINR", NULL, "Direct Voice" }, |
| 956 | { "MIXINR", NULL, "IN1RP" }, |
| 957 | { "MIXINR", NULL, "Right Output Mixer" }, |
Mark Brown | 4e04ada | 2011-07-15 15:12:31 +0900 | [diff] [blame] | 958 | { "MIXINR", NULL, "VMID" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 959 | |
| 960 | { "ADCL", NULL, "MIXINL" }, |
| 961 | { "ADCR", NULL, "MIXINR" }, |
| 962 | |
| 963 | { "Left Output Mixer", "Left Input Switch", "MIXINL" }, |
| 964 | { "Left Output Mixer", "Right Input Switch", "MIXINR" }, |
| 965 | { "Left Output Mixer", "IN2RN Switch", "IN2RN" }, |
| 966 | { "Left Output Mixer", "IN2LN Switch", "IN2LN" }, |
Joonyoung Shim | 3482594 | 2009-12-04 15:12:10 +0900 | [diff] [blame] | 967 | { "Left Output Mixer", "IN2LP Switch", "IN2LP:VXRN" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 968 | { "Left Output Mixer", "IN1L Switch", "IN1L PGA" }, |
| 969 | { "Left Output Mixer", "IN1R Switch", "IN1R PGA" }, |
| 970 | |
| 971 | { "Right Output Mixer", "Left Input Switch", "MIXINL" }, |
| 972 | { "Right Output Mixer", "Right Input Switch", "MIXINR" }, |
| 973 | { "Right Output Mixer", "IN2LN Switch", "IN2LN" }, |
| 974 | { "Right Output Mixer", "IN2RN Switch", "IN2RN" }, |
Joonyoung Shim | 3482594 | 2009-12-04 15:12:10 +0900 | [diff] [blame] | 975 | { "Right Output Mixer", "IN2RP Switch", "IN2RP:VXRP" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 976 | { "Right Output Mixer", "IN1L Switch", "IN1L PGA" }, |
| 977 | { "Right Output Mixer", "IN1R Switch", "IN1R PGA" }, |
| 978 | |
| 979 | { "Left Output PGA", NULL, "Left Output Mixer" }, |
| 980 | { "Left Output PGA", NULL, "TOCLK" }, |
| 981 | |
| 982 | { "Right Output PGA", NULL, "Right Output Mixer" }, |
| 983 | { "Right Output PGA", NULL, "TOCLK" }, |
| 984 | |
| 985 | { "Earpiece Mixer", "Direct Voice Switch", "Direct Voice" }, |
| 986 | { "Earpiece Mixer", "Left Output Switch", "Left Output PGA" }, |
| 987 | { "Earpiece Mixer", "Right Output Switch", "Right Output PGA" }, |
| 988 | |
Mark Brown | 4e04ada | 2011-07-15 15:12:31 +0900 | [diff] [blame] | 989 | { "Earpiece Driver", NULL, "VMID" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 990 | { "Earpiece Driver", NULL, "Earpiece Mixer" }, |
| 991 | { "HPOUT2N", NULL, "Earpiece Driver" }, |
| 992 | { "HPOUT2P", NULL, "Earpiece Driver" }, |
| 993 | |
| 994 | { "SPKL", "Input Switch", "MIXINL" }, |
| 995 | { "SPKL", "IN1LP Switch", "IN1LP" }, |
Mark Brown | 39cca16 | 2011-04-08 16:32:16 +0900 | [diff] [blame] | 996 | { "SPKL", "Output Switch", "Left Output PGA" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 997 | { "SPKL", NULL, "TOCLK" }, |
| 998 | |
| 999 | { "SPKR", "Input Switch", "MIXINR" }, |
| 1000 | { "SPKR", "IN1RP Switch", "IN1RP" }, |
Mark Brown | 39cca16 | 2011-04-08 16:32:16 +0900 | [diff] [blame] | 1001 | { "SPKR", "Output Switch", "Right Output PGA" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1002 | { "SPKR", NULL, "TOCLK" }, |
| 1003 | |
| 1004 | { "SPKL Boost", "Direct Voice Switch", "Direct Voice" }, |
| 1005 | { "SPKL Boost", "SPKL Switch", "SPKL" }, |
| 1006 | { "SPKL Boost", "SPKR Switch", "SPKR" }, |
| 1007 | |
| 1008 | { "SPKR Boost", "Direct Voice Switch", "Direct Voice" }, |
| 1009 | { "SPKR Boost", "SPKR Switch", "SPKR" }, |
| 1010 | { "SPKR Boost", "SPKL Switch", "SPKL" }, |
| 1011 | |
Mark Brown | 4e04ada | 2011-07-15 15:12:31 +0900 | [diff] [blame] | 1012 | { "SPKL Driver", NULL, "VMID" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1013 | { "SPKL Driver", NULL, "SPKL Boost" }, |
| 1014 | { "SPKL Driver", NULL, "CLK_SYS" }, |
Mark Brown | 0343197 | 2011-11-04 17:11:54 +0000 | [diff] [blame] | 1015 | { "SPKL Driver", NULL, "TSHUT" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1016 | |
Mark Brown | 4e04ada | 2011-07-15 15:12:31 +0900 | [diff] [blame] | 1017 | { "SPKR Driver", NULL, "VMID" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1018 | { "SPKR Driver", NULL, "SPKR Boost" }, |
| 1019 | { "SPKR Driver", NULL, "CLK_SYS" }, |
Mark Brown | 0343197 | 2011-11-04 17:11:54 +0000 | [diff] [blame] | 1020 | { "SPKR Driver", NULL, "TSHUT" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1021 | |
| 1022 | { "SPKOUTLP", NULL, "SPKL Driver" }, |
| 1023 | { "SPKOUTLN", NULL, "SPKL Driver" }, |
| 1024 | { "SPKOUTRP", NULL, "SPKR Driver" }, |
| 1025 | { "SPKOUTRN", NULL, "SPKR Driver" }, |
| 1026 | |
Mark Brown | 39cca16 | 2011-04-08 16:32:16 +0900 | [diff] [blame] | 1027 | { "Left Headphone Mux", "Mixer", "Left Output PGA" }, |
| 1028 | { "Right Headphone Mux", "Mixer", "Right Output PGA" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1029 | |
| 1030 | { "Headphone PGA", NULL, "Left Headphone Mux" }, |
| 1031 | { "Headphone PGA", NULL, "Right Headphone Mux" }, |
Mark Brown | 4e04ada | 2011-07-15 15:12:31 +0900 | [diff] [blame] | 1032 | { "Headphone PGA", NULL, "VMID" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1033 | { "Headphone PGA", NULL, "CLK_SYS" }, |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 1034 | { "Headphone PGA", NULL, "Headphone Supply" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1035 | |
| 1036 | { "HPOUT1L", NULL, "Headphone PGA" }, |
| 1037 | { "HPOUT1R", NULL, "Headphone PGA" }, |
| 1038 | |
Mark Brown | 4e04ada | 2011-07-15 15:12:31 +0900 | [diff] [blame] | 1039 | { "LINEOUT1N Driver", NULL, "VMID" }, |
| 1040 | { "LINEOUT1P Driver", NULL, "VMID" }, |
| 1041 | { "LINEOUT2N Driver", NULL, "VMID" }, |
| 1042 | { "LINEOUT2P Driver", NULL, "VMID" }, |
| 1043 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1044 | { "LINEOUT1N", NULL, "LINEOUT1N Driver" }, |
| 1045 | { "LINEOUT1P", NULL, "LINEOUT1P Driver" }, |
| 1046 | { "LINEOUT2N", NULL, "LINEOUT2N Driver" }, |
| 1047 | { "LINEOUT2P", NULL, "LINEOUT2P Driver" }, |
| 1048 | }; |
| 1049 | |
| 1050 | static const struct snd_soc_dapm_route lineout1_diff_routes[] = { |
| 1051 | { "LINEOUT1 Mixer", "IN1L Switch", "IN1L PGA" }, |
| 1052 | { "LINEOUT1 Mixer", "IN1R Switch", "IN1R PGA" }, |
Mark Brown | d0b48af | 2011-05-14 17:21:28 -0700 | [diff] [blame] | 1053 | { "LINEOUT1 Mixer", "Output Switch", "Left Output PGA" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1054 | |
| 1055 | { "LINEOUT1N Driver", NULL, "LINEOUT1 Mixer" }, |
| 1056 | { "LINEOUT1P Driver", NULL, "LINEOUT1 Mixer" }, |
| 1057 | }; |
| 1058 | |
| 1059 | static const struct snd_soc_dapm_route lineout1_se_routes[] = { |
Mark Brown | d0b48af | 2011-05-14 17:21:28 -0700 | [diff] [blame] | 1060 | { "LINEOUT1N Mixer", "Left Output Switch", "Left Output PGA" }, |
| 1061 | { "LINEOUT1N Mixer", "Right Output Switch", "Right Output PGA" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1062 | |
Mark Brown | d0b48af | 2011-05-14 17:21:28 -0700 | [diff] [blame] | 1063 | { "LINEOUT1P Mixer", "Left Output Switch", "Left Output PGA" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1064 | |
| 1065 | { "LINEOUT1N Driver", NULL, "LINEOUT1N Mixer" }, |
| 1066 | { "LINEOUT1P Driver", NULL, "LINEOUT1P Mixer" }, |
| 1067 | }; |
| 1068 | |
| 1069 | static const struct snd_soc_dapm_route lineout2_diff_routes[] = { |
Mark Brown | ee76744 | 2012-01-31 11:55:32 +0000 | [diff] [blame] | 1070 | { "LINEOUT2 Mixer", "IN1L Switch", "IN1L PGA" }, |
| 1071 | { "LINEOUT2 Mixer", "IN1R Switch", "IN1R PGA" }, |
Mark Brown | d0b48af | 2011-05-14 17:21:28 -0700 | [diff] [blame] | 1072 | { "LINEOUT2 Mixer", "Output Switch", "Right Output PGA" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1073 | |
| 1074 | { "LINEOUT2N Driver", NULL, "LINEOUT2 Mixer" }, |
| 1075 | { "LINEOUT2P Driver", NULL, "LINEOUT2 Mixer" }, |
| 1076 | }; |
| 1077 | |
| 1078 | static const struct snd_soc_dapm_route lineout2_se_routes[] = { |
Mark Brown | d0b48af | 2011-05-14 17:21:28 -0700 | [diff] [blame] | 1079 | { "LINEOUT2N Mixer", "Left Output Switch", "Left Output PGA" }, |
| 1080 | { "LINEOUT2N Mixer", "Right Output Switch", "Right Output PGA" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1081 | |
Mark Brown | d0b48af | 2011-05-14 17:21:28 -0700 | [diff] [blame] | 1082 | { "LINEOUT2P Mixer", "Right Output Switch", "Right Output PGA" }, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1083 | |
| 1084 | { "LINEOUT2N Driver", NULL, "LINEOUT2N Mixer" }, |
| 1085 | { "LINEOUT2P Driver", NULL, "LINEOUT2P Mixer" }, |
| 1086 | }; |
| 1087 | |
| 1088 | int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec) |
| 1089 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1090 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 1091 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1092 | /* Latch volume update bits & default ZC on */ |
| 1093 | snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_1_2_VOLUME, |
| 1094 | WM8993_IN1_VU, WM8993_IN1_VU); |
| 1095 | snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, |
| 1096 | WM8993_IN1_VU, WM8993_IN1_VU); |
| 1097 | snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_3_4_VOLUME, |
| 1098 | WM8993_IN2_VU, WM8993_IN2_VU); |
| 1099 | snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, |
| 1100 | WM8993_IN2_VU, WM8993_IN2_VU); |
| 1101 | |
Mark Brown | fb5af53 | 2011-05-15 12:18:38 -0700 | [diff] [blame] | 1102 | snd_soc_update_bits(codec, WM8993_SPEAKER_VOLUME_LEFT, |
| 1103 | WM8993_SPKOUT_VU, WM8993_SPKOUT_VU); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1104 | snd_soc_update_bits(codec, WM8993_SPEAKER_VOLUME_RIGHT, |
| 1105 | WM8993_SPKOUT_VU, WM8993_SPKOUT_VU); |
| 1106 | |
| 1107 | snd_soc_update_bits(codec, WM8993_LEFT_OUTPUT_VOLUME, |
Mark Brown | fb5af53 | 2011-05-15 12:18:38 -0700 | [diff] [blame] | 1108 | WM8993_HPOUT1_VU | WM8993_HPOUT1L_ZC, |
| 1109 | WM8993_HPOUT1_VU | WM8993_HPOUT1L_ZC); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1110 | snd_soc_update_bits(codec, WM8993_RIGHT_OUTPUT_VOLUME, |
| 1111 | WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC, |
| 1112 | WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC); |
| 1113 | |
| 1114 | snd_soc_update_bits(codec, WM8993_LEFT_OPGA_VOLUME, |
Mark Brown | fb5af53 | 2011-05-15 12:18:38 -0700 | [diff] [blame] | 1115 | WM8993_MIXOUTL_ZC | WM8993_MIXOUT_VU, |
| 1116 | WM8993_MIXOUTL_ZC | WM8993_MIXOUT_VU); |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1117 | snd_soc_update_bits(codec, WM8993_RIGHT_OPGA_VOLUME, |
| 1118 | WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU, |
| 1119 | WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU); |
| 1120 | |
Liam Girdwood | 022658b | 2012-02-03 17:43:09 +0000 | [diff] [blame] | 1121 | snd_soc_add_codec_controls(codec, analogue_snd_controls, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1122 | ARRAY_SIZE(analogue_snd_controls)); |
| 1123 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1124 | snd_soc_dapm_new_controls(dapm, analogue_dapm_widgets, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1125 | ARRAY_SIZE(analogue_dapm_widgets)); |
| 1126 | return 0; |
| 1127 | } |
| 1128 | EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_controls); |
| 1129 | |
| 1130 | int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec, |
| 1131 | int lineout1_diff, int lineout2_diff) |
| 1132 | { |
Mark Brown | d96ca3c | 2011-07-12 15:25:03 +0900 | [diff] [blame] | 1133 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1134 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 1135 | |
Mark Brown | 8cb8e83 | 2012-07-25 18:10:03 +0100 | [diff] [blame] | 1136 | hubs->codec = codec; |
| 1137 | |
Mark Brown | 94aa733 | 2012-05-01 18:45:09 +0100 | [diff] [blame] | 1138 | INIT_LIST_HEAD(&hubs->dcs_cache); |
Mark Brown | d96ca3c | 2011-07-12 15:25:03 +0900 | [diff] [blame] | 1139 | init_completion(&hubs->dcs_done); |
| 1140 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1141 | snd_soc_dapm_add_routes(dapm, analogue_routes, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1142 | ARRAY_SIZE(analogue_routes)); |
| 1143 | |
| 1144 | if (lineout1_diff) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1145 | snd_soc_dapm_add_routes(dapm, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1146 | lineout1_diff_routes, |
| 1147 | ARRAY_SIZE(lineout1_diff_routes)); |
| 1148 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1149 | snd_soc_dapm_add_routes(dapm, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1150 | lineout1_se_routes, |
| 1151 | ARRAY_SIZE(lineout1_se_routes)); |
| 1152 | |
| 1153 | if (lineout2_diff) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1154 | snd_soc_dapm_add_routes(dapm, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1155 | lineout2_diff_routes, |
| 1156 | ARRAY_SIZE(lineout2_diff_routes)); |
| 1157 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1158 | snd_soc_dapm_add_routes(dapm, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1159 | lineout2_se_routes, |
| 1160 | ARRAY_SIZE(lineout2_se_routes)); |
| 1161 | |
| 1162 | return 0; |
| 1163 | } |
| 1164 | EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes); |
| 1165 | |
Mark Brown | aa983d9 | 2009-09-30 14:16:11 +0100 | [diff] [blame] | 1166 | int wm_hubs_handle_analogue_pdata(struct snd_soc_codec *codec, |
| 1167 | int lineout1_diff, int lineout2_diff, |
| 1168 | int lineout1fb, int lineout2fb, |
| 1169 | int jd_scthr, int jd_thr, int micbias1_lvl, |
| 1170 | int micbias2_lvl) |
| 1171 | { |
Mark Brown | 5f2f3890 | 2012-02-08 18:51:42 +0000 | [diff] [blame] | 1172 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
| 1173 | |
| 1174 | hubs->lineout1_se = !lineout1_diff; |
| 1175 | hubs->lineout2_se = !lineout2_diff; |
| 1176 | |
Mark Brown | aa983d9 | 2009-09-30 14:16:11 +0100 | [diff] [blame] | 1177 | if (!lineout1_diff) |
| 1178 | snd_soc_update_bits(codec, WM8993_LINE_MIXER1, |
| 1179 | WM8993_LINEOUT1_MODE, |
| 1180 | WM8993_LINEOUT1_MODE); |
| 1181 | if (!lineout2_diff) |
| 1182 | snd_soc_update_bits(codec, WM8993_LINE_MIXER2, |
| 1183 | WM8993_LINEOUT2_MODE, |
| 1184 | WM8993_LINEOUT2_MODE); |
| 1185 | |
Mark Brown | 5472bbc | 2012-03-19 17:31:56 +0000 | [diff] [blame] | 1186 | if (!lineout1_diff && !lineout2_diff) |
| 1187 | snd_soc_update_bits(codec, WM8993_ANTIPOP1, |
| 1188 | WM8993_LINEOUT_VMID_BUF_ENA, |
| 1189 | WM8993_LINEOUT_VMID_BUF_ENA); |
| 1190 | |
Mark Brown | aa983d9 | 2009-09-30 14:16:11 +0100 | [diff] [blame] | 1191 | if (lineout1fb) |
| 1192 | snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL, |
| 1193 | WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB); |
| 1194 | |
| 1195 | if (lineout2fb) |
| 1196 | snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL, |
| 1197 | WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB); |
| 1198 | |
| 1199 | snd_soc_update_bits(codec, WM8993_MICBIAS, |
| 1200 | WM8993_JD_SCTHR_MASK | WM8993_JD_THR_MASK | |
| 1201 | WM8993_MICB1_LVL | WM8993_MICB2_LVL, |
| 1202 | jd_scthr << WM8993_JD_SCTHR_SHIFT | |
| 1203 | jd_thr << WM8993_JD_THR_SHIFT | |
| 1204 | micbias1_lvl | |
| 1205 | micbias2_lvl << WM8993_MICB2_LVL_SHIFT); |
| 1206 | |
| 1207 | return 0; |
| 1208 | } |
| 1209 | EXPORT_SYMBOL_GPL(wm_hubs_handle_analogue_pdata); |
| 1210 | |
Mark Brown | 5f2f3890 | 2012-02-08 18:51:42 +0000 | [diff] [blame] | 1211 | void wm_hubs_vmid_ena(struct snd_soc_codec *codec) |
| 1212 | { |
| 1213 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
| 1214 | int val = 0; |
| 1215 | |
| 1216 | if (hubs->lineout1_se) |
| 1217 | val |= WM8993_LINEOUT1N_ENA | WM8993_LINEOUT1P_ENA; |
| 1218 | |
| 1219 | if (hubs->lineout2_se) |
| 1220 | val |= WM8993_LINEOUT2N_ENA | WM8993_LINEOUT2P_ENA; |
| 1221 | |
| 1222 | /* Enable the line outputs while we power up */ |
| 1223 | snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_3, val, val); |
| 1224 | } |
| 1225 | EXPORT_SYMBOL_GPL(wm_hubs_vmid_ena); |
| 1226 | |
| 1227 | void wm_hubs_set_bias_level(struct snd_soc_codec *codec, |
| 1228 | enum snd_soc_bias_level level) |
| 1229 | { |
| 1230 | struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); |
Mark Brown | de050ac | 2012-04-17 20:28:10 +0100 | [diff] [blame] | 1231 | int mask, val; |
Mark Brown | 5f2f3890 | 2012-02-08 18:51:42 +0000 | [diff] [blame] | 1232 | |
| 1233 | switch (level) { |
Mark Brown | d60d6c3 | 2012-02-10 18:09:42 +0000 | [diff] [blame] | 1234 | case SND_SOC_BIAS_STANDBY: |
| 1235 | /* Clamp the inputs to VMID while we ramp to charge caps */ |
| 1236 | snd_soc_update_bits(codec, WM8993_INPUTS_CLAMP_REG, |
| 1237 | WM8993_INPUTS_CLAMP, WM8993_INPUTS_CLAMP); |
| 1238 | break; |
| 1239 | |
Mark Brown | 5f2f3890 | 2012-02-08 18:51:42 +0000 | [diff] [blame] | 1240 | case SND_SOC_BIAS_ON: |
| 1241 | /* Turn off any unneded single ended outputs */ |
| 1242 | val = 0; |
Mark Brown | de050ac | 2012-04-17 20:28:10 +0100 | [diff] [blame] | 1243 | mask = 0; |
| 1244 | |
| 1245 | if (hubs->lineout1_se) |
| 1246 | mask |= WM8993_LINEOUT1N_ENA | WM8993_LINEOUT1P_ENA; |
| 1247 | |
| 1248 | if (hubs->lineout2_se) |
| 1249 | mask |= WM8993_LINEOUT2N_ENA | WM8993_LINEOUT2P_ENA; |
Mark Brown | 5f2f3890 | 2012-02-08 18:51:42 +0000 | [diff] [blame] | 1250 | |
| 1251 | if (hubs->lineout1_se && hubs->lineout1n_ena) |
| 1252 | val |= WM8993_LINEOUT1N_ENA; |
| 1253 | |
| 1254 | if (hubs->lineout1_se && hubs->lineout1p_ena) |
| 1255 | val |= WM8993_LINEOUT1P_ENA; |
| 1256 | |
| 1257 | if (hubs->lineout2_se && hubs->lineout2n_ena) |
| 1258 | val |= WM8993_LINEOUT2N_ENA; |
| 1259 | |
| 1260 | if (hubs->lineout2_se && hubs->lineout2p_ena) |
| 1261 | val |= WM8993_LINEOUT2P_ENA; |
| 1262 | |
| 1263 | snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_3, |
Mark Brown | de050ac | 2012-04-17 20:28:10 +0100 | [diff] [blame] | 1264 | mask, val); |
Mark Brown | 5f2f3890 | 2012-02-08 18:51:42 +0000 | [diff] [blame] | 1265 | |
Mark Brown | d60d6c3 | 2012-02-10 18:09:42 +0000 | [diff] [blame] | 1266 | /* Remove the input clamps */ |
| 1267 | snd_soc_update_bits(codec, WM8993_INPUTS_CLAMP_REG, |
| 1268 | WM8993_INPUTS_CLAMP, 0); |
Mark Brown | 5f2f3890 | 2012-02-08 18:51:42 +0000 | [diff] [blame] | 1269 | break; |
| 1270 | |
| 1271 | default: |
| 1272 | break; |
| 1273 | } |
| 1274 | } |
| 1275 | EXPORT_SYMBOL_GPL(wm_hubs_set_bias_level); |
| 1276 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 1277 | MODULE_DESCRIPTION("Shared support for Wolfson hubs products"); |
| 1278 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 1279 | MODULE_LICENSE("GPL"); |