1 /* 2 * wm_hubs.c -- WM8993/4 common code 3 * 4 * Copyright 2009-12 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/mfd/wm8994/registers.h> 21 #include <sound/core.h> 22 #include <sound/pcm.h> 23 #include <sound/pcm_params.h> 24 #include <sound/soc.h> 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[] = { 42 TLV_DB_RANGE_HEAD(2), 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 64 static void wait_for_dc_servo(struct snd_soc_codec *codec, unsigned int op) 65 { 66 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 67 unsigned int reg; 68 int count = 0; 69 int timeout; 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); 76 77 dev_dbg(codec->dev, "Waiting for DC servo...\n"); 78 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); 92 93 reg = snd_soc_read(codec, WM8993_DC_SERVO_0); 94 dev_dbg(codec->dev, "DC servo: %x\n", reg); 95 } while (reg & op && count < timeout); 96 97 if (reg & op) 98 dev_err(codec->dev, "Timed out waiting for DC Servo %x\n", 99 op); 100 } 101 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 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"); 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"); 138 } 139 } else { 140 dev_vdbg(codec->dev, "HPR connected to DAC\n"); 141 } 142 143 return true; 144 } 145 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 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 243 /* 244 * Startup calibration of the DC servo 245 */ 246 static void enable_dc_servo(struct snd_soc_codec *codec) 247 { 248 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 249 struct wm_hubs_dcs_cache *cache; 250 s8 offset; 251 u16 reg_l, reg_r, dcs_cfg, dcs_reg; 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 } 261 262 /* If we're using a digital only path and have a previously 263 * callibrated DC servo offset stored then use that. */ 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); 269 wait_for_dc_servo(codec, 270 WM8993_DCS_TRIG_DAC_WR_0 | 271 WM8993_DCS_TRIG_DAC_WR_1); 272 return; 273 } 274 275 if (hubs->series_startup) { 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 } 288 289 wm_hubs_read_dc_servo(codec, ®_l, ®_r); 290 291 dev_dbg(codec->dev, "DCS input: %x %x\n", reg_l, reg_r); 292 293 /* Apply correction to DC servo result */ 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); 298 299 /* HPOUT1R */ 300 offset = (s8)reg_r; 301 dev_dbg(codec->dev, "DCS right %d->%d\n", offset, 302 offset + hubs->dcs_codes_r); 303 offset += hubs->dcs_codes_r; 304 dcs_cfg = (u8)offset << WM8993_DCS_DAC_WR_VAL_1_SHIFT; 305 306 /* HPOUT1L */ 307 offset = (s8)reg_l; 308 dev_dbg(codec->dev, "DCS left %d->%d\n", offset, 309 offset + hubs->dcs_codes_l); 310 offset += hubs->dcs_codes_l; 311 dcs_cfg |= (u8)offset; 312 313 dev_dbg(codec->dev, "DCS result: %x\n", dcs_cfg); 314 315 /* Do it */ 316 snd_soc_write(codec, dcs_reg, dcs_cfg); 317 wait_for_dc_servo(codec, 318 WM8993_DCS_TRIG_DAC_WR_0 | 319 WM8993_DCS_TRIG_DAC_WR_1); 320 } else { 321 dcs_cfg = reg_r << WM8993_DCS_DAC_WR_VAL_1_SHIFT; 322 dcs_cfg |= reg_l; 323 } 324 325 /* Save the callibrated offset if we're in class W mode and 326 * therefore don't have any analogue signal mixed in. */ 327 if (wm_hubs_dac_hp_direct(codec)) 328 wm_hubs_dcs_cache_set(codec, dcs_cfg); 329 } 330 331 /* 332 * Update the DC servo calibration on gain changes 333 */ 334 static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol, 335 struct snd_ctl_elem_value *ucontrol) 336 { 337 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 338 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 339 int ret; 340 341 ret = snd_soc_put_volsw(kcontrol, ucontrol); 342 343 /* If we're applying an offset correction then updating the 344 * callibration would be likely to introduce further offsets. */ 345 if (hubs->dcs_codes_l || hubs->dcs_codes_r || hubs->no_series_update) 346 return ret; 347 348 /* Only need to do this if the outputs are active */ 349 if (snd_soc_read(codec, WM8993_POWER_MANAGEMENT_1) 350 & (WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA)) 351 snd_soc_update_bits(codec, 352 WM8993_DC_SERVO_0, 353 WM8993_DCS_TRIG_SINGLE_0 | 354 WM8993_DCS_TRIG_SINGLE_1, 355 WM8993_DCS_TRIG_SINGLE_0 | 356 WM8993_DCS_TRIG_SINGLE_1); 357 358 return ret; 359 } 360 361 static const struct snd_kcontrol_new analogue_snd_controls[] = { 362 SOC_SINGLE_TLV("IN1L Volume", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 0, 31, 0, 363 inpga_tlv), 364 SOC_SINGLE("IN1L Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 7, 1, 1), 365 SOC_SINGLE("IN1L ZC Switch", WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 6, 1, 0), 366 367 SOC_SINGLE_TLV("IN1R Volume", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 0, 31, 0, 368 inpga_tlv), 369 SOC_SINGLE("IN1R Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 7, 1, 1), 370 SOC_SINGLE("IN1R ZC Switch", WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 6, 1, 0), 371 372 373 SOC_SINGLE_TLV("IN2L Volume", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 0, 31, 0, 374 inpga_tlv), 375 SOC_SINGLE("IN2L Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 7, 1, 1), 376 SOC_SINGLE("IN2L ZC Switch", WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 6, 1, 0), 377 378 SOC_SINGLE_TLV("IN2R Volume", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 0, 31, 0, 379 inpga_tlv), 380 SOC_SINGLE("IN2R Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 7, 1, 1), 381 SOC_SINGLE("IN2R ZC Switch", WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 6, 1, 0), 382 383 SOC_SINGLE_TLV("MIXINL IN2L Volume", WM8993_INPUT_MIXER3, 7, 1, 0, 384 inmix_sw_tlv), 385 SOC_SINGLE_TLV("MIXINL IN1L Volume", WM8993_INPUT_MIXER3, 4, 1, 0, 386 inmix_sw_tlv), 387 SOC_SINGLE_TLV("MIXINL Output Record Volume", WM8993_INPUT_MIXER3, 0, 7, 0, 388 inmix_tlv), 389 SOC_SINGLE_TLV("MIXINL IN1LP Volume", WM8993_INPUT_MIXER5, 6, 7, 0, inmix_tlv), 390 SOC_SINGLE_TLV("MIXINL Direct Voice Volume", WM8993_INPUT_MIXER5, 0, 6, 0, 391 inmix_tlv), 392 393 SOC_SINGLE_TLV("MIXINR IN2R Volume", WM8993_INPUT_MIXER4, 7, 1, 0, 394 inmix_sw_tlv), 395 SOC_SINGLE_TLV("MIXINR IN1R Volume", WM8993_INPUT_MIXER4, 4, 1, 0, 396 inmix_sw_tlv), 397 SOC_SINGLE_TLV("MIXINR Output Record Volume", WM8993_INPUT_MIXER4, 0, 7, 0, 398 inmix_tlv), 399 SOC_SINGLE_TLV("MIXINR IN1RP Volume", WM8993_INPUT_MIXER6, 6, 7, 0, inmix_tlv), 400 SOC_SINGLE_TLV("MIXINR Direct Voice Volume", WM8993_INPUT_MIXER6, 0, 6, 0, 401 inmix_tlv), 402 403 SOC_SINGLE_TLV("Left Output Mixer IN2RN Volume", WM8993_OUTPUT_MIXER5, 6, 7, 1, 404 outmix_tlv), 405 SOC_SINGLE_TLV("Left Output Mixer IN2LN Volume", WM8993_OUTPUT_MIXER3, 6, 7, 1, 406 outmix_tlv), 407 SOC_SINGLE_TLV("Left Output Mixer IN2LP Volume", WM8993_OUTPUT_MIXER3, 9, 7, 1, 408 outmix_tlv), 409 SOC_SINGLE_TLV("Left Output Mixer IN1L Volume", WM8993_OUTPUT_MIXER3, 0, 7, 1, 410 outmix_tlv), 411 SOC_SINGLE_TLV("Left Output Mixer IN1R Volume", WM8993_OUTPUT_MIXER3, 3, 7, 1, 412 outmix_tlv), 413 SOC_SINGLE_TLV("Left Output Mixer Right Input Volume", 414 WM8993_OUTPUT_MIXER5, 3, 7, 1, outmix_tlv), 415 SOC_SINGLE_TLV("Left Output Mixer Left Input Volume", 416 WM8993_OUTPUT_MIXER5, 0, 7, 1, outmix_tlv), 417 SOC_SINGLE_TLV("Left Output Mixer DAC Volume", WM8993_OUTPUT_MIXER5, 9, 7, 1, 418 outmix_tlv), 419 420 SOC_SINGLE_TLV("Right Output Mixer IN2LN Volume", 421 WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv), 422 SOC_SINGLE_TLV("Right Output Mixer IN2RN Volume", 423 WM8993_OUTPUT_MIXER4, 6, 7, 1, outmix_tlv), 424 SOC_SINGLE_TLV("Right Output Mixer IN1L Volume", 425 WM8993_OUTPUT_MIXER4, 3, 7, 1, outmix_tlv), 426 SOC_SINGLE_TLV("Right Output Mixer IN1R Volume", 427 WM8993_OUTPUT_MIXER4, 0, 7, 1, outmix_tlv), 428 SOC_SINGLE_TLV("Right Output Mixer IN2RP Volume", 429 WM8993_OUTPUT_MIXER4, 9, 7, 1, outmix_tlv), 430 SOC_SINGLE_TLV("Right Output Mixer Left Input Volume", 431 WM8993_OUTPUT_MIXER6, 3, 7, 1, outmix_tlv), 432 SOC_SINGLE_TLV("Right Output Mixer Right Input Volume", 433 WM8993_OUTPUT_MIXER6, 6, 7, 1, outmix_tlv), 434 SOC_SINGLE_TLV("Right Output Mixer DAC Volume", 435 WM8993_OUTPUT_MIXER6, 9, 7, 1, outmix_tlv), 436 437 SOC_DOUBLE_R_TLV("Output Volume", WM8993_LEFT_OPGA_VOLUME, 438 WM8993_RIGHT_OPGA_VOLUME, 0, 63, 0, outpga_tlv), 439 SOC_DOUBLE_R("Output Switch", WM8993_LEFT_OPGA_VOLUME, 440 WM8993_RIGHT_OPGA_VOLUME, 6, 1, 0), 441 SOC_DOUBLE_R("Output ZC Switch", WM8993_LEFT_OPGA_VOLUME, 442 WM8993_RIGHT_OPGA_VOLUME, 7, 1, 0), 443 444 SOC_SINGLE("Earpiece Switch", WM8993_HPOUT2_VOLUME, 5, 1, 1), 445 SOC_SINGLE_TLV("Earpiece Volume", WM8993_HPOUT2_VOLUME, 4, 1, 1, earpiece_tlv), 446 447 SOC_SINGLE_TLV("SPKL Input Volume", WM8993_SPKMIXL_ATTENUATION, 448 5, 1, 1, wm_hubs_spkmix_tlv), 449 SOC_SINGLE_TLV("SPKL IN1LP Volume", WM8993_SPKMIXL_ATTENUATION, 450 4, 1, 1, wm_hubs_spkmix_tlv), 451 SOC_SINGLE_TLV("SPKL Output Volume", WM8993_SPKMIXL_ATTENUATION, 452 3, 1, 1, wm_hubs_spkmix_tlv), 453 454 SOC_SINGLE_TLV("SPKR Input Volume", WM8993_SPKMIXR_ATTENUATION, 455 5, 1, 1, wm_hubs_spkmix_tlv), 456 SOC_SINGLE_TLV("SPKR IN1RP Volume", WM8993_SPKMIXR_ATTENUATION, 457 4, 1, 1, wm_hubs_spkmix_tlv), 458 SOC_SINGLE_TLV("SPKR Output Volume", WM8993_SPKMIXR_ATTENUATION, 459 3, 1, 1, wm_hubs_spkmix_tlv), 460 461 SOC_DOUBLE_R_TLV("Speaker Mixer Volume", 462 WM8993_SPKMIXL_ATTENUATION, WM8993_SPKMIXR_ATTENUATION, 463 0, 3, 1, spkmixout_tlv), 464 SOC_DOUBLE_R_TLV("Speaker Volume", 465 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT, 466 0, 63, 0, outpga_tlv), 467 SOC_DOUBLE_R("Speaker Switch", 468 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT, 469 6, 1, 0), 470 SOC_DOUBLE_R("Speaker ZC Switch", 471 WM8993_SPEAKER_VOLUME_LEFT, WM8993_SPEAKER_VOLUME_RIGHT, 472 7, 1, 0), 473 SOC_DOUBLE_TLV("Speaker Boost Volume", WM8993_SPKOUT_BOOST, 3, 0, 7, 0, 474 spkboost_tlv), 475 SOC_ENUM("Speaker Reference", speaker_ref), 476 SOC_ENUM("Speaker Mode", speaker_mode), 477 478 SOC_DOUBLE_R_EXT_TLV("Headphone Volume", 479 WM8993_LEFT_OUTPUT_VOLUME, WM8993_RIGHT_OUTPUT_VOLUME, 480 0, 63, 0, snd_soc_get_volsw, wm8993_put_dc_servo, 481 outpga_tlv), 482 483 SOC_DOUBLE_R("Headphone Switch", WM8993_LEFT_OUTPUT_VOLUME, 484 WM8993_RIGHT_OUTPUT_VOLUME, 6, 1, 0), 485 SOC_DOUBLE_R("Headphone ZC Switch", WM8993_LEFT_OUTPUT_VOLUME, 486 WM8993_RIGHT_OUTPUT_VOLUME, 7, 1, 0), 487 488 SOC_SINGLE("LINEOUT1N Switch", WM8993_LINE_OUTPUTS_VOLUME, 6, 1, 1), 489 SOC_SINGLE("LINEOUT1P Switch", WM8993_LINE_OUTPUTS_VOLUME, 5, 1, 1), 490 SOC_SINGLE_TLV("LINEOUT1 Volume", WM8993_LINE_OUTPUTS_VOLUME, 4, 1, 1, 491 line_tlv), 492 493 SOC_SINGLE("LINEOUT2N Switch", WM8993_LINE_OUTPUTS_VOLUME, 2, 1, 1), 494 SOC_SINGLE("LINEOUT2P Switch", WM8993_LINE_OUTPUTS_VOLUME, 1, 1, 1), 495 SOC_SINGLE_TLV("LINEOUT2 Volume", WM8993_LINE_OUTPUTS_VOLUME, 0, 1, 1, 496 line_tlv), 497 }; 498 499 static int hp_supply_event(struct snd_soc_dapm_widget *w, 500 struct snd_kcontrol *kcontrol, int event) 501 { 502 struct snd_soc_codec *codec = w->codec; 503 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 504 505 switch (event) { 506 case SND_SOC_DAPM_PRE_PMU: 507 switch (hubs->hp_startup_mode) { 508 case 0: 509 break; 510 case 1: 511 /* Enable the headphone amp */ 512 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1, 513 WM8993_HPOUT1L_ENA | 514 WM8993_HPOUT1R_ENA, 515 WM8993_HPOUT1L_ENA | 516 WM8993_HPOUT1R_ENA); 517 518 /* Enable the second stage */ 519 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0, 520 WM8993_HPOUT1L_DLY | 521 WM8993_HPOUT1R_DLY, 522 WM8993_HPOUT1L_DLY | 523 WM8993_HPOUT1R_DLY); 524 break; 525 default: 526 dev_err(codec->dev, "Unknown HP startup mode %d\n", 527 hubs->hp_startup_mode); 528 break; 529 } 530 531 case SND_SOC_DAPM_PRE_PMD: 532 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1, 533 WM8993_CP_ENA, 0); 534 break; 535 } 536 537 return 0; 538 } 539 540 static int hp_event(struct snd_soc_dapm_widget *w, 541 struct snd_kcontrol *kcontrol, int event) 542 { 543 struct snd_soc_codec *codec = w->codec; 544 unsigned int reg = snd_soc_read(codec, WM8993_ANALOGUE_HP_0); 545 546 switch (event) { 547 case SND_SOC_DAPM_POST_PMU: 548 snd_soc_update_bits(codec, WM8993_CHARGE_PUMP_1, 549 WM8993_CP_ENA, WM8993_CP_ENA); 550 551 msleep(5); 552 553 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1, 554 WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA, 555 WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA); 556 557 reg |= WM8993_HPOUT1L_DLY | WM8993_HPOUT1R_DLY; 558 snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg); 559 560 snd_soc_update_bits(codec, WM8993_DC_SERVO_1, 561 WM8993_DCS_TIMER_PERIOD_01_MASK, 0); 562 563 enable_dc_servo(codec); 564 565 reg |= WM8993_HPOUT1R_OUTP | WM8993_HPOUT1R_RMV_SHORT | 566 WM8993_HPOUT1L_OUTP | WM8993_HPOUT1L_RMV_SHORT; 567 snd_soc_write(codec, WM8993_ANALOGUE_HP_0, reg); 568 break; 569 570 case SND_SOC_DAPM_PRE_PMD: 571 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0, 572 WM8993_HPOUT1L_OUTP | 573 WM8993_HPOUT1R_OUTP | 574 WM8993_HPOUT1L_RMV_SHORT | 575 WM8993_HPOUT1R_RMV_SHORT, 0); 576 577 snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0, 578 WM8993_HPOUT1L_DLY | 579 WM8993_HPOUT1R_DLY, 0); 580 581 snd_soc_write(codec, WM8993_DC_SERVO_0, 0); 582 583 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1, 584 WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA, 585 0); 586 break; 587 } 588 589 return 0; 590 } 591 592 static int earpiece_event(struct snd_soc_dapm_widget *w, 593 struct snd_kcontrol *control, int event) 594 { 595 struct snd_soc_codec *codec = w->codec; 596 u16 reg = snd_soc_read(codec, WM8993_ANTIPOP1) & ~WM8993_HPOUT2_IN_ENA; 597 598 switch (event) { 599 case SND_SOC_DAPM_PRE_PMU: 600 reg |= WM8993_HPOUT2_IN_ENA; 601 snd_soc_write(codec, WM8993_ANTIPOP1, reg); 602 udelay(50); 603 break; 604 605 case SND_SOC_DAPM_POST_PMD: 606 snd_soc_write(codec, WM8993_ANTIPOP1, reg); 607 break; 608 609 default: 610 BUG(); 611 break; 612 } 613 614 return 0; 615 } 616 617 static int lineout_event(struct snd_soc_dapm_widget *w, 618 struct snd_kcontrol *control, int event) 619 { 620 struct snd_soc_codec *codec = w->codec; 621 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 622 bool *flag; 623 624 switch (w->shift) { 625 case WM8993_LINEOUT1N_ENA_SHIFT: 626 flag = &hubs->lineout1n_ena; 627 break; 628 case WM8993_LINEOUT1P_ENA_SHIFT: 629 flag = &hubs->lineout1p_ena; 630 break; 631 case WM8993_LINEOUT2N_ENA_SHIFT: 632 flag = &hubs->lineout2n_ena; 633 break; 634 case WM8993_LINEOUT2P_ENA_SHIFT: 635 flag = &hubs->lineout2p_ena; 636 break; 637 default: 638 WARN(1, "Unknown line output"); 639 return -EINVAL; 640 } 641 642 *flag = SND_SOC_DAPM_EVENT_ON(event); 643 644 return 0; 645 } 646 647 static int micbias_event(struct snd_soc_dapm_widget *w, 648 struct snd_kcontrol *kcontrol, int event) 649 { 650 struct snd_soc_codec *codec = w->codec; 651 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 652 653 switch (w->shift) { 654 case WM8993_MICB1_ENA_SHIFT: 655 if (hubs->micb1_delay) 656 msleep(hubs->micb1_delay); 657 break; 658 case WM8993_MICB2_ENA_SHIFT: 659 if (hubs->micb2_delay) 660 msleep(hubs->micb2_delay); 661 break; 662 default: 663 return -EINVAL; 664 } 665 666 return 0; 667 } 668 669 void wm_hubs_update_class_w(struct snd_soc_codec *codec) 670 { 671 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 672 int enable = WM8993_CP_DYN_V | WM8993_CP_DYN_FREQ; 673 674 if (!wm_hubs_dac_hp_direct(codec)) 675 enable = false; 676 677 if (hubs->check_class_w_digital && !hubs->check_class_w_digital(codec)) 678 enable = false; 679 680 dev_vdbg(codec->dev, "Class W %s\n", enable ? "enabled" : "disabled"); 681 682 snd_soc_update_bits(codec, WM8993_CLASS_W_0, 683 WM8993_CP_DYN_V | WM8993_CP_DYN_FREQ, enable); 684 685 snd_soc_write(codec, WM8993_LEFT_OUTPUT_VOLUME, 686 snd_soc_read(codec, WM8993_LEFT_OUTPUT_VOLUME)); 687 snd_soc_write(codec, WM8993_RIGHT_OUTPUT_VOLUME, 688 snd_soc_read(codec, WM8993_RIGHT_OUTPUT_VOLUME)); 689 } 690 EXPORT_SYMBOL_GPL(wm_hubs_update_class_w); 691 692 #define WM_HUBS_SINGLE_W(xname, reg, shift, max, invert) \ 693 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 694 .info = snd_soc_info_volsw, \ 695 .get = snd_soc_dapm_get_volsw, .put = class_w_put_volsw, \ 696 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) } 697 698 static int class_w_put_volsw(struct snd_kcontrol *kcontrol, 699 struct snd_ctl_elem_value *ucontrol) 700 { 701 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); 702 struct snd_soc_dapm_widget *widget = wlist->widgets[0]; 703 struct snd_soc_codec *codec = widget->codec; 704 int ret; 705 706 ret = snd_soc_dapm_put_volsw(kcontrol, ucontrol); 707 708 wm_hubs_update_class_w(codec); 709 710 return ret; 711 } 712 713 #define WM_HUBS_ENUM_W(xname, xenum) \ 714 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 715 .info = snd_soc_info_enum_double, \ 716 .get = snd_soc_dapm_get_enum_double, \ 717 .put = class_w_put_double, \ 718 .private_value = (unsigned long)&xenum } 719 720 static int class_w_put_double(struct snd_kcontrol *kcontrol, 721 struct snd_ctl_elem_value *ucontrol) 722 { 723 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); 724 struct snd_soc_dapm_widget *widget = wlist->widgets[0]; 725 struct snd_soc_codec *codec = widget->codec; 726 int ret; 727 728 ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); 729 730 wm_hubs_update_class_w(codec); 731 732 return ret; 733 } 734 735 static const char *hp_mux_text[] = { 736 "Mixer", 737 "DAC", 738 }; 739 740 static const struct soc_enum hpl_enum = 741 SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER1, 8, 2, hp_mux_text); 742 743 const struct snd_kcontrol_new wm_hubs_hpl_mux = 744 WM_HUBS_ENUM_W("Left Headphone Mux", hpl_enum); 745 EXPORT_SYMBOL_GPL(wm_hubs_hpl_mux); 746 747 static const struct soc_enum hpr_enum = 748 SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER2, 8, 2, hp_mux_text); 749 750 const struct snd_kcontrol_new wm_hubs_hpr_mux = 751 WM_HUBS_ENUM_W("Right Headphone Mux", hpr_enum); 752 EXPORT_SYMBOL_GPL(wm_hubs_hpr_mux); 753 754 static const struct snd_kcontrol_new in1l_pga[] = { 755 SOC_DAPM_SINGLE("IN1LP Switch", WM8993_INPUT_MIXER2, 5, 1, 0), 756 SOC_DAPM_SINGLE("IN1LN Switch", WM8993_INPUT_MIXER2, 4, 1, 0), 757 }; 758 759 static const struct snd_kcontrol_new in1r_pga[] = { 760 SOC_DAPM_SINGLE("IN1RP Switch", WM8993_INPUT_MIXER2, 1, 1, 0), 761 SOC_DAPM_SINGLE("IN1RN Switch", WM8993_INPUT_MIXER2, 0, 1, 0), 762 }; 763 764 static const struct snd_kcontrol_new in2l_pga[] = { 765 SOC_DAPM_SINGLE("IN2LP Switch", WM8993_INPUT_MIXER2, 7, 1, 0), 766 SOC_DAPM_SINGLE("IN2LN Switch", WM8993_INPUT_MIXER2, 6, 1, 0), 767 }; 768 769 static const struct snd_kcontrol_new in2r_pga[] = { 770 SOC_DAPM_SINGLE("IN2RP Switch", WM8993_INPUT_MIXER2, 3, 1, 0), 771 SOC_DAPM_SINGLE("IN2RN Switch", WM8993_INPUT_MIXER2, 2, 1, 0), 772 }; 773 774 static const struct snd_kcontrol_new mixinl[] = { 775 SOC_DAPM_SINGLE("IN2L Switch", WM8993_INPUT_MIXER3, 8, 1, 0), 776 SOC_DAPM_SINGLE("IN1L Switch", WM8993_INPUT_MIXER3, 5, 1, 0), 777 }; 778 779 static const struct snd_kcontrol_new mixinr[] = { 780 SOC_DAPM_SINGLE("IN2R Switch", WM8993_INPUT_MIXER4, 8, 1, 0), 781 SOC_DAPM_SINGLE("IN1R Switch", WM8993_INPUT_MIXER4, 5, 1, 0), 782 }; 783 784 static const struct snd_kcontrol_new left_output_mixer[] = { 785 WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER1, 7, 1, 0), 786 WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER1, 6, 1, 0), 787 WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER1, 5, 1, 0), 788 WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER1, 4, 1, 0), 789 WM_HUBS_SINGLE_W("IN2LP Switch", WM8993_OUTPUT_MIXER1, 1, 1, 0), 790 WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER1, 3, 1, 0), 791 WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER1, 2, 1, 0), 792 WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER1, 0, 1, 0), 793 }; 794 795 static const struct snd_kcontrol_new right_output_mixer[] = { 796 WM_HUBS_SINGLE_W("Left Input Switch", WM8993_OUTPUT_MIXER2, 7, 1, 0), 797 WM_HUBS_SINGLE_W("Right Input Switch", WM8993_OUTPUT_MIXER2, 6, 1, 0), 798 WM_HUBS_SINGLE_W("IN2LN Switch", WM8993_OUTPUT_MIXER2, 5, 1, 0), 799 WM_HUBS_SINGLE_W("IN2RN Switch", WM8993_OUTPUT_MIXER2, 4, 1, 0), 800 WM_HUBS_SINGLE_W("IN1L Switch", WM8993_OUTPUT_MIXER2, 3, 1, 0), 801 WM_HUBS_SINGLE_W("IN1R Switch", WM8993_OUTPUT_MIXER2, 2, 1, 0), 802 WM_HUBS_SINGLE_W("IN2RP Switch", WM8993_OUTPUT_MIXER2, 1, 1, 0), 803 WM_HUBS_SINGLE_W("DAC Switch", WM8993_OUTPUT_MIXER2, 0, 1, 0), 804 }; 805 806 static const struct snd_kcontrol_new earpiece_mixer[] = { 807 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_HPOUT2_MIXER, 5, 1, 0), 808 SOC_DAPM_SINGLE("Left Output Switch", WM8993_HPOUT2_MIXER, 4, 1, 0), 809 SOC_DAPM_SINGLE("Right Output Switch", WM8993_HPOUT2_MIXER, 3, 1, 0), 810 }; 811 812 static const struct snd_kcontrol_new left_speaker_boost[] = { 813 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 5, 1, 0), 814 SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 4, 1, 0), 815 SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 3, 1, 0), 816 }; 817 818 static const struct snd_kcontrol_new right_speaker_boost[] = { 819 SOC_DAPM_SINGLE("Direct Voice Switch", WM8993_SPKOUT_MIXERS, 2, 1, 0), 820 SOC_DAPM_SINGLE("SPKL Switch", WM8993_SPKOUT_MIXERS, 1, 1, 0), 821 SOC_DAPM_SINGLE("SPKR Switch", WM8993_SPKOUT_MIXERS, 0, 1, 0), 822 }; 823 824 static const struct snd_kcontrol_new line1_mix[] = { 825 SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER1, 2, 1, 0), 826 SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER1, 1, 1, 0), 827 SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER1, 0, 1, 0), 828 }; 829 830 static const struct snd_kcontrol_new line1n_mix[] = { 831 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 6, 1, 0), 832 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER1, 5, 1, 0), 833 }; 834 835 static const struct snd_kcontrol_new line1p_mix[] = { 836 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER1, 0, 1, 0), 837 }; 838 839 static const struct snd_kcontrol_new line2_mix[] = { 840 SOC_DAPM_SINGLE("IN1L Switch", WM8993_LINE_MIXER2, 2, 1, 0), 841 SOC_DAPM_SINGLE("IN1R Switch", WM8993_LINE_MIXER2, 1, 1, 0), 842 SOC_DAPM_SINGLE("Output Switch", WM8993_LINE_MIXER2, 0, 1, 0), 843 }; 844 845 static const struct snd_kcontrol_new line2n_mix[] = { 846 SOC_DAPM_SINGLE("Left Output Switch", WM8993_LINE_MIXER2, 5, 1, 0), 847 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 6, 1, 0), 848 }; 849 850 static const struct snd_kcontrol_new line2p_mix[] = { 851 SOC_DAPM_SINGLE("Right Output Switch", WM8993_LINE_MIXER2, 0, 1, 0), 852 }; 853 854 static const struct snd_soc_dapm_widget analogue_dapm_widgets[] = { 855 SND_SOC_DAPM_INPUT("IN1LN"), 856 SND_SOC_DAPM_INPUT("IN1LP"), 857 SND_SOC_DAPM_INPUT("IN2LN"), 858 SND_SOC_DAPM_INPUT("IN2LP:VXRN"), 859 SND_SOC_DAPM_INPUT("IN1RN"), 860 SND_SOC_DAPM_INPUT("IN1RP"), 861 SND_SOC_DAPM_INPUT("IN2RN"), 862 SND_SOC_DAPM_INPUT("IN2RP:VXRP"), 863 864 SND_SOC_DAPM_SUPPLY("MICBIAS2", WM8993_POWER_MANAGEMENT_1, 5, 0, 865 micbias_event, SND_SOC_DAPM_POST_PMU), 866 SND_SOC_DAPM_SUPPLY("MICBIAS1", WM8993_POWER_MANAGEMENT_1, 4, 0, 867 micbias_event, SND_SOC_DAPM_POST_PMU), 868 869 SND_SOC_DAPM_MIXER("IN1L PGA", WM8993_POWER_MANAGEMENT_2, 6, 0, 870 in1l_pga, ARRAY_SIZE(in1l_pga)), 871 SND_SOC_DAPM_MIXER("IN1R PGA", WM8993_POWER_MANAGEMENT_2, 4, 0, 872 in1r_pga, ARRAY_SIZE(in1r_pga)), 873 874 SND_SOC_DAPM_MIXER("IN2L PGA", WM8993_POWER_MANAGEMENT_2, 7, 0, 875 in2l_pga, ARRAY_SIZE(in2l_pga)), 876 SND_SOC_DAPM_MIXER("IN2R PGA", WM8993_POWER_MANAGEMENT_2, 5, 0, 877 in2r_pga, ARRAY_SIZE(in2r_pga)), 878 879 SND_SOC_DAPM_MIXER("MIXINL", WM8993_POWER_MANAGEMENT_2, 9, 0, 880 mixinl, ARRAY_SIZE(mixinl)), 881 SND_SOC_DAPM_MIXER("MIXINR", WM8993_POWER_MANAGEMENT_2, 8, 0, 882 mixinr, ARRAY_SIZE(mixinr)), 883 884 SND_SOC_DAPM_MIXER("Left Output Mixer", WM8993_POWER_MANAGEMENT_3, 5, 0, 885 left_output_mixer, ARRAY_SIZE(left_output_mixer)), 886 SND_SOC_DAPM_MIXER("Right Output Mixer", WM8993_POWER_MANAGEMENT_3, 4, 0, 887 right_output_mixer, ARRAY_SIZE(right_output_mixer)), 888 889 SND_SOC_DAPM_PGA("Left Output PGA", WM8993_POWER_MANAGEMENT_3, 7, 0, NULL, 0), 890 SND_SOC_DAPM_PGA("Right Output PGA", WM8993_POWER_MANAGEMENT_3, 6, 0, NULL, 0), 891 892 SND_SOC_DAPM_SUPPLY("Headphone Supply", SND_SOC_NOPM, 0, 0, hp_supply_event, 893 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD), 894 SND_SOC_DAPM_OUT_DRV_E("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0, 895 hp_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), 896 897 SND_SOC_DAPM_MIXER("Earpiece Mixer", SND_SOC_NOPM, 0, 0, 898 earpiece_mixer, ARRAY_SIZE(earpiece_mixer)), 899 SND_SOC_DAPM_PGA_E("Earpiece Driver", WM8993_POWER_MANAGEMENT_1, 11, 0, 900 NULL, 0, earpiece_event, 901 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), 902 903 SND_SOC_DAPM_MIXER("SPKL Boost", SND_SOC_NOPM, 0, 0, 904 left_speaker_boost, ARRAY_SIZE(left_speaker_boost)), 905 SND_SOC_DAPM_MIXER("SPKR Boost", SND_SOC_NOPM, 0, 0, 906 right_speaker_boost, ARRAY_SIZE(right_speaker_boost)), 907 908 SND_SOC_DAPM_SUPPLY("TSHUT", WM8993_POWER_MANAGEMENT_2, 14, 0, NULL, 0), 909 SND_SOC_DAPM_OUT_DRV("SPKL Driver", WM8993_POWER_MANAGEMENT_1, 12, 0, 910 NULL, 0), 911 SND_SOC_DAPM_OUT_DRV("SPKR Driver", WM8993_POWER_MANAGEMENT_1, 13, 0, 912 NULL, 0), 913 914 SND_SOC_DAPM_MIXER("LINEOUT1 Mixer", SND_SOC_NOPM, 0, 0, 915 line1_mix, ARRAY_SIZE(line1_mix)), 916 SND_SOC_DAPM_MIXER("LINEOUT2 Mixer", SND_SOC_NOPM, 0, 0, 917 line2_mix, ARRAY_SIZE(line2_mix)), 918 919 SND_SOC_DAPM_MIXER("LINEOUT1N Mixer", SND_SOC_NOPM, 0, 0, 920 line1n_mix, ARRAY_SIZE(line1n_mix)), 921 SND_SOC_DAPM_MIXER("LINEOUT1P Mixer", SND_SOC_NOPM, 0, 0, 922 line1p_mix, ARRAY_SIZE(line1p_mix)), 923 SND_SOC_DAPM_MIXER("LINEOUT2N Mixer", SND_SOC_NOPM, 0, 0, 924 line2n_mix, ARRAY_SIZE(line2n_mix)), 925 SND_SOC_DAPM_MIXER("LINEOUT2P Mixer", SND_SOC_NOPM, 0, 0, 926 line2p_mix, ARRAY_SIZE(line2p_mix)), 927 928 SND_SOC_DAPM_OUT_DRV_E("LINEOUT1N Driver", WM8993_POWER_MANAGEMENT_3, 13, 0, 929 NULL, 0, lineout_event, 930 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), 931 SND_SOC_DAPM_OUT_DRV_E("LINEOUT1P Driver", WM8993_POWER_MANAGEMENT_3, 12, 0, 932 NULL, 0, lineout_event, 933 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), 934 SND_SOC_DAPM_OUT_DRV_E("LINEOUT2N Driver", WM8993_POWER_MANAGEMENT_3, 11, 0, 935 NULL, 0, lineout_event, 936 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), 937 SND_SOC_DAPM_OUT_DRV_E("LINEOUT2P Driver", WM8993_POWER_MANAGEMENT_3, 10, 0, 938 NULL, 0, lineout_event, 939 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), 940 941 SND_SOC_DAPM_OUTPUT("SPKOUTLP"), 942 SND_SOC_DAPM_OUTPUT("SPKOUTLN"), 943 SND_SOC_DAPM_OUTPUT("SPKOUTRP"), 944 SND_SOC_DAPM_OUTPUT("SPKOUTRN"), 945 SND_SOC_DAPM_OUTPUT("HPOUT1L"), 946 SND_SOC_DAPM_OUTPUT("HPOUT1R"), 947 SND_SOC_DAPM_OUTPUT("HPOUT2P"), 948 SND_SOC_DAPM_OUTPUT("HPOUT2N"), 949 SND_SOC_DAPM_OUTPUT("LINEOUT1P"), 950 SND_SOC_DAPM_OUTPUT("LINEOUT1N"), 951 SND_SOC_DAPM_OUTPUT("LINEOUT2P"), 952 SND_SOC_DAPM_OUTPUT("LINEOUT2N"), 953 }; 954 955 static const struct snd_soc_dapm_route analogue_routes[] = { 956 { "MICBIAS1", NULL, "CLK_SYS" }, 957 { "MICBIAS2", NULL, "CLK_SYS" }, 958 959 { "IN1L PGA", "IN1LP Switch", "IN1LP" }, 960 { "IN1L PGA", "IN1LN Switch", "IN1LN" }, 961 962 { "IN1L PGA", NULL, "VMID" }, 963 { "IN1R PGA", NULL, "VMID" }, 964 { "IN2L PGA", NULL, "VMID" }, 965 { "IN2R PGA", NULL, "VMID" }, 966 967 { "IN1R PGA", "IN1RP Switch", "IN1RP" }, 968 { "IN1R PGA", "IN1RN Switch", "IN1RN" }, 969 970 { "IN2L PGA", "IN2LP Switch", "IN2LP:VXRN" }, 971 { "IN2L PGA", "IN2LN Switch", "IN2LN" }, 972 973 { "IN2R PGA", "IN2RP Switch", "IN2RP:VXRP" }, 974 { "IN2R PGA", "IN2RN Switch", "IN2RN" }, 975 976 { "Direct Voice", NULL, "IN2LP:VXRN" }, 977 { "Direct Voice", NULL, "IN2RP:VXRP" }, 978 979 { "MIXINL", "IN1L Switch", "IN1L PGA" }, 980 { "MIXINL", "IN2L Switch", "IN2L PGA" }, 981 { "MIXINL", NULL, "Direct Voice" }, 982 { "MIXINL", NULL, "IN1LP" }, 983 { "MIXINL", NULL, "Left Output Mixer" }, 984 { "MIXINL", NULL, "VMID" }, 985 986 { "MIXINR", "IN1R Switch", "IN1R PGA" }, 987 { "MIXINR", "IN2R Switch", "IN2R PGA" }, 988 { "MIXINR", NULL, "Direct Voice" }, 989 { "MIXINR", NULL, "IN1RP" }, 990 { "MIXINR", NULL, "Right Output Mixer" }, 991 { "MIXINR", NULL, "VMID" }, 992 993 { "ADCL", NULL, "MIXINL" }, 994 { "ADCR", NULL, "MIXINR" }, 995 996 { "Left Output Mixer", "Left Input Switch", "MIXINL" }, 997 { "Left Output Mixer", "Right Input Switch", "MIXINR" }, 998 { "Left Output Mixer", "IN2RN Switch", "IN2RN" }, 999 { "Left Output Mixer", "IN2LN Switch", "IN2LN" }, 1000 { "Left Output Mixer", "IN2LP Switch", "IN2LP:VXRN" }, 1001 { "Left Output Mixer", "IN1L Switch", "IN1L PGA" }, 1002 { "Left Output Mixer", "IN1R Switch", "IN1R PGA" }, 1003 1004 { "Right Output Mixer", "Left Input Switch", "MIXINL" }, 1005 { "Right Output Mixer", "Right Input Switch", "MIXINR" }, 1006 { "Right Output Mixer", "IN2LN Switch", "IN2LN" }, 1007 { "Right Output Mixer", "IN2RN Switch", "IN2RN" }, 1008 { "Right Output Mixer", "IN2RP Switch", "IN2RP:VXRP" }, 1009 { "Right Output Mixer", "IN1L Switch", "IN1L PGA" }, 1010 { "Right Output Mixer", "IN1R Switch", "IN1R PGA" }, 1011 1012 { "Left Output PGA", NULL, "Left Output Mixer" }, 1013 { "Left Output PGA", NULL, "TOCLK" }, 1014 1015 { "Right Output PGA", NULL, "Right Output Mixer" }, 1016 { "Right Output PGA", NULL, "TOCLK" }, 1017 1018 { "Earpiece Mixer", "Direct Voice Switch", "Direct Voice" }, 1019 { "Earpiece Mixer", "Left Output Switch", "Left Output PGA" }, 1020 { "Earpiece Mixer", "Right Output Switch", "Right Output PGA" }, 1021 1022 { "Earpiece Driver", NULL, "VMID" }, 1023 { "Earpiece Driver", NULL, "Earpiece Mixer" }, 1024 { "HPOUT2N", NULL, "Earpiece Driver" }, 1025 { "HPOUT2P", NULL, "Earpiece Driver" }, 1026 1027 { "SPKL", "Input Switch", "MIXINL" }, 1028 { "SPKL", "IN1LP Switch", "IN1LP" }, 1029 { "SPKL", "Output Switch", "Left Output PGA" }, 1030 { "SPKL", NULL, "TOCLK" }, 1031 1032 { "SPKR", "Input Switch", "MIXINR" }, 1033 { "SPKR", "IN1RP Switch", "IN1RP" }, 1034 { "SPKR", "Output Switch", "Right Output PGA" }, 1035 { "SPKR", NULL, "TOCLK" }, 1036 1037 { "SPKL Boost", "Direct Voice Switch", "Direct Voice" }, 1038 { "SPKL Boost", "SPKL Switch", "SPKL" }, 1039 { "SPKL Boost", "SPKR Switch", "SPKR" }, 1040 1041 { "SPKR Boost", "Direct Voice Switch", "Direct Voice" }, 1042 { "SPKR Boost", "SPKR Switch", "SPKR" }, 1043 { "SPKR Boost", "SPKL Switch", "SPKL" }, 1044 1045 { "SPKL Driver", NULL, "VMID" }, 1046 { "SPKL Driver", NULL, "SPKL Boost" }, 1047 { "SPKL Driver", NULL, "CLK_SYS" }, 1048 { "SPKL Driver", NULL, "TSHUT" }, 1049 1050 { "SPKR Driver", NULL, "VMID" }, 1051 { "SPKR Driver", NULL, "SPKR Boost" }, 1052 { "SPKR Driver", NULL, "CLK_SYS" }, 1053 { "SPKR Driver", NULL, "TSHUT" }, 1054 1055 { "SPKOUTLP", NULL, "SPKL Driver" }, 1056 { "SPKOUTLN", NULL, "SPKL Driver" }, 1057 { "SPKOUTRP", NULL, "SPKR Driver" }, 1058 { "SPKOUTRN", NULL, "SPKR Driver" }, 1059 1060 { "Left Headphone Mux", "Mixer", "Left Output PGA" }, 1061 { "Right Headphone Mux", "Mixer", "Right Output PGA" }, 1062 1063 { "Headphone PGA", NULL, "Left Headphone Mux" }, 1064 { "Headphone PGA", NULL, "Right Headphone Mux" }, 1065 { "Headphone PGA", NULL, "VMID" }, 1066 { "Headphone PGA", NULL, "CLK_SYS" }, 1067 { "Headphone PGA", NULL, "Headphone Supply" }, 1068 1069 { "HPOUT1L", NULL, "Headphone PGA" }, 1070 { "HPOUT1R", NULL, "Headphone PGA" }, 1071 1072 { "LINEOUT1N Driver", NULL, "VMID" }, 1073 { "LINEOUT1P Driver", NULL, "VMID" }, 1074 { "LINEOUT2N Driver", NULL, "VMID" }, 1075 { "LINEOUT2P Driver", NULL, "VMID" }, 1076 1077 { "LINEOUT1N", NULL, "LINEOUT1N Driver" }, 1078 { "LINEOUT1P", NULL, "LINEOUT1P Driver" }, 1079 { "LINEOUT2N", NULL, "LINEOUT2N Driver" }, 1080 { "LINEOUT2P", NULL, "LINEOUT2P Driver" }, 1081 }; 1082 1083 static const struct snd_soc_dapm_route lineout1_diff_routes[] = { 1084 { "LINEOUT1 Mixer", "IN1L Switch", "IN1L PGA" }, 1085 { "LINEOUT1 Mixer", "IN1R Switch", "IN1R PGA" }, 1086 { "LINEOUT1 Mixer", "Output Switch", "Left Output PGA" }, 1087 1088 { "LINEOUT1N Driver", NULL, "LINEOUT1 Mixer" }, 1089 { "LINEOUT1P Driver", NULL, "LINEOUT1 Mixer" }, 1090 }; 1091 1092 static const struct snd_soc_dapm_route lineout1_se_routes[] = { 1093 { "LINEOUT1N Mixer", "Left Output Switch", "Left Output PGA" }, 1094 { "LINEOUT1N Mixer", "Right Output Switch", "Right Output PGA" }, 1095 1096 { "LINEOUT1P Mixer", "Left Output Switch", "Left Output PGA" }, 1097 1098 { "LINEOUT1N Driver", NULL, "LINEOUT1N Mixer" }, 1099 { "LINEOUT1P Driver", NULL, "LINEOUT1P Mixer" }, 1100 }; 1101 1102 static const struct snd_soc_dapm_route lineout2_diff_routes[] = { 1103 { "LINEOUT2 Mixer", "IN1L Switch", "IN1L PGA" }, 1104 { "LINEOUT2 Mixer", "IN1R Switch", "IN1R PGA" }, 1105 { "LINEOUT2 Mixer", "Output Switch", "Right Output PGA" }, 1106 1107 { "LINEOUT2N Driver", NULL, "LINEOUT2 Mixer" }, 1108 { "LINEOUT2P Driver", NULL, "LINEOUT2 Mixer" }, 1109 }; 1110 1111 static const struct snd_soc_dapm_route lineout2_se_routes[] = { 1112 { "LINEOUT2N Mixer", "Left Output Switch", "Left Output PGA" }, 1113 { "LINEOUT2N Mixer", "Right Output Switch", "Right Output PGA" }, 1114 1115 { "LINEOUT2P Mixer", "Right Output Switch", "Right Output PGA" }, 1116 1117 { "LINEOUT2N Driver", NULL, "LINEOUT2N Mixer" }, 1118 { "LINEOUT2P Driver", NULL, "LINEOUT2P Mixer" }, 1119 }; 1120 1121 int wm_hubs_add_analogue_controls(struct snd_soc_codec *codec) 1122 { 1123 struct snd_soc_dapm_context *dapm = &codec->dapm; 1124 1125 /* Latch volume update bits & default ZC on */ 1126 snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_1_2_VOLUME, 1127 WM8993_IN1_VU, WM8993_IN1_VU); 1128 snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_1_2_VOLUME, 1129 WM8993_IN1_VU, WM8993_IN1_VU); 1130 snd_soc_update_bits(codec, WM8993_LEFT_LINE_INPUT_3_4_VOLUME, 1131 WM8993_IN2_VU, WM8993_IN2_VU); 1132 snd_soc_update_bits(codec, WM8993_RIGHT_LINE_INPUT_3_4_VOLUME, 1133 WM8993_IN2_VU, WM8993_IN2_VU); 1134 1135 snd_soc_update_bits(codec, WM8993_SPEAKER_VOLUME_LEFT, 1136 WM8993_SPKOUT_VU, WM8993_SPKOUT_VU); 1137 snd_soc_update_bits(codec, WM8993_SPEAKER_VOLUME_RIGHT, 1138 WM8993_SPKOUT_VU, WM8993_SPKOUT_VU); 1139 1140 snd_soc_update_bits(codec, WM8993_LEFT_OUTPUT_VOLUME, 1141 WM8993_HPOUT1_VU | WM8993_HPOUT1L_ZC, 1142 WM8993_HPOUT1_VU | WM8993_HPOUT1L_ZC); 1143 snd_soc_update_bits(codec, WM8993_RIGHT_OUTPUT_VOLUME, 1144 WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC, 1145 WM8993_HPOUT1_VU | WM8993_HPOUT1R_ZC); 1146 1147 snd_soc_update_bits(codec, WM8993_LEFT_OPGA_VOLUME, 1148 WM8993_MIXOUTL_ZC | WM8993_MIXOUT_VU, 1149 WM8993_MIXOUTL_ZC | WM8993_MIXOUT_VU); 1150 snd_soc_update_bits(codec, WM8993_RIGHT_OPGA_VOLUME, 1151 WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU, 1152 WM8993_MIXOUTR_ZC | WM8993_MIXOUT_VU); 1153 1154 snd_soc_add_codec_controls(codec, analogue_snd_controls, 1155 ARRAY_SIZE(analogue_snd_controls)); 1156 1157 snd_soc_dapm_new_controls(dapm, analogue_dapm_widgets, 1158 ARRAY_SIZE(analogue_dapm_widgets)); 1159 return 0; 1160 } 1161 EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_controls); 1162 1163 int wm_hubs_add_analogue_routes(struct snd_soc_codec *codec, 1164 int lineout1_diff, int lineout2_diff) 1165 { 1166 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 1167 struct snd_soc_dapm_context *dapm = &codec->dapm; 1168 1169 hubs->codec = codec; 1170 1171 INIT_LIST_HEAD(&hubs->dcs_cache); 1172 init_completion(&hubs->dcs_done); 1173 1174 snd_soc_dapm_add_routes(dapm, analogue_routes, 1175 ARRAY_SIZE(analogue_routes)); 1176 1177 if (lineout1_diff) 1178 snd_soc_dapm_add_routes(dapm, 1179 lineout1_diff_routes, 1180 ARRAY_SIZE(lineout1_diff_routes)); 1181 else 1182 snd_soc_dapm_add_routes(dapm, 1183 lineout1_se_routes, 1184 ARRAY_SIZE(lineout1_se_routes)); 1185 1186 if (lineout2_diff) 1187 snd_soc_dapm_add_routes(dapm, 1188 lineout2_diff_routes, 1189 ARRAY_SIZE(lineout2_diff_routes)); 1190 else 1191 snd_soc_dapm_add_routes(dapm, 1192 lineout2_se_routes, 1193 ARRAY_SIZE(lineout2_se_routes)); 1194 1195 return 0; 1196 } 1197 EXPORT_SYMBOL_GPL(wm_hubs_add_analogue_routes); 1198 1199 int wm_hubs_handle_analogue_pdata(struct snd_soc_codec *codec, 1200 int lineout1_diff, int lineout2_diff, 1201 int lineout1fb, int lineout2fb, 1202 int jd_scthr, int jd_thr, 1203 int micbias1_delay, int micbias2_delay, 1204 int micbias1_lvl, int micbias2_lvl) 1205 { 1206 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 1207 1208 hubs->lineout1_se = !lineout1_diff; 1209 hubs->lineout2_se = !lineout2_diff; 1210 hubs->micb1_delay = micbias1_delay; 1211 hubs->micb2_delay = micbias2_delay; 1212 1213 if (!lineout1_diff) 1214 snd_soc_update_bits(codec, WM8993_LINE_MIXER1, 1215 WM8993_LINEOUT1_MODE, 1216 WM8993_LINEOUT1_MODE); 1217 if (!lineout2_diff) 1218 snd_soc_update_bits(codec, WM8993_LINE_MIXER2, 1219 WM8993_LINEOUT2_MODE, 1220 WM8993_LINEOUT2_MODE); 1221 1222 if (!lineout1_diff && !lineout2_diff) 1223 snd_soc_update_bits(codec, WM8993_ANTIPOP1, 1224 WM8993_LINEOUT_VMID_BUF_ENA, 1225 WM8993_LINEOUT_VMID_BUF_ENA); 1226 1227 if (lineout1fb) 1228 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL, 1229 WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB); 1230 1231 if (lineout2fb) 1232 snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL, 1233 WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB); 1234 1235 snd_soc_update_bits(codec, WM8993_MICBIAS, 1236 WM8993_JD_SCTHR_MASK | WM8993_JD_THR_MASK | 1237 WM8993_MICB1_LVL | WM8993_MICB2_LVL, 1238 jd_scthr << WM8993_JD_SCTHR_SHIFT | 1239 jd_thr << WM8993_JD_THR_SHIFT | 1240 micbias1_lvl | 1241 micbias2_lvl << WM8993_MICB2_LVL_SHIFT); 1242 1243 return 0; 1244 } 1245 EXPORT_SYMBOL_GPL(wm_hubs_handle_analogue_pdata); 1246 1247 void wm_hubs_vmid_ena(struct snd_soc_codec *codec) 1248 { 1249 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 1250 int val = 0; 1251 1252 if (hubs->lineout1_se) 1253 val |= WM8993_LINEOUT1N_ENA | WM8993_LINEOUT1P_ENA; 1254 1255 if (hubs->lineout2_se) 1256 val |= WM8993_LINEOUT2N_ENA | WM8993_LINEOUT2P_ENA; 1257 1258 /* Enable the line outputs while we power up */ 1259 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_3, val, val); 1260 } 1261 EXPORT_SYMBOL_GPL(wm_hubs_vmid_ena); 1262 1263 void wm_hubs_set_bias_level(struct snd_soc_codec *codec, 1264 enum snd_soc_bias_level level) 1265 { 1266 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 1267 int mask, val; 1268 1269 switch (level) { 1270 case SND_SOC_BIAS_STANDBY: 1271 /* Clamp the inputs to VMID while we ramp to charge caps */ 1272 snd_soc_update_bits(codec, WM8993_INPUTS_CLAMP_REG, 1273 WM8993_INPUTS_CLAMP, WM8993_INPUTS_CLAMP); 1274 break; 1275 1276 case SND_SOC_BIAS_ON: 1277 /* Turn off any unneded single ended outputs */ 1278 val = 0; 1279 mask = 0; 1280 1281 if (hubs->lineout1_se) 1282 mask |= WM8993_LINEOUT1N_ENA | WM8993_LINEOUT1P_ENA; 1283 1284 if (hubs->lineout2_se) 1285 mask |= WM8993_LINEOUT2N_ENA | WM8993_LINEOUT2P_ENA; 1286 1287 if (hubs->lineout1_se && hubs->lineout1n_ena) 1288 val |= WM8993_LINEOUT1N_ENA; 1289 1290 if (hubs->lineout1_se && hubs->lineout1p_ena) 1291 val |= WM8993_LINEOUT1P_ENA; 1292 1293 if (hubs->lineout2_se && hubs->lineout2n_ena) 1294 val |= WM8993_LINEOUT2N_ENA; 1295 1296 if (hubs->lineout2_se && hubs->lineout2p_ena) 1297 val |= WM8993_LINEOUT2P_ENA; 1298 1299 snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_3, 1300 mask, val); 1301 1302 /* Remove the input clamps */ 1303 snd_soc_update_bits(codec, WM8993_INPUTS_CLAMP_REG, 1304 WM8993_INPUTS_CLAMP, 0); 1305 break; 1306 1307 default: 1308 break; 1309 } 1310 } 1311 EXPORT_SYMBOL_GPL(wm_hubs_set_bias_level); 1312 1313 MODULE_DESCRIPTION("Shared support for Wolfson hubs products"); 1314 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 1315 MODULE_LICENSE("GPL"); 1316