Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * wm8993.c -- WM8993 ALSA SoC audio driver |
| 3 | * |
Mark Brown | be587ef | 2010-02-01 18:31:06 +0000 | [diff] [blame] | 4 | * Copyright 2009, 2010 Wolfson Microelectronics plc |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 5 | * |
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/moduleparam.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/pm.h> |
| 18 | #include <linux/i2c.h> |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 19 | #include <linux/regmap.h> |
Mark Brown | b37e399 | 2010-02-03 11:51:42 +0000 | [diff] [blame] | 20 | #include <linux/regulator/consumer.h> |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 21 | #include <linux/spi/spi.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 23 | #include <sound/core.h> |
| 24 | #include <sound/pcm.h> |
| 25 | #include <sound/pcm_params.h> |
| 26 | #include <sound/tlv.h> |
| 27 | #include <sound/soc.h> |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 28 | #include <sound/initval.h> |
| 29 | #include <sound/wm8993.h> |
| 30 | |
| 31 | #include "wm8993.h" |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 32 | #include "wm_hubs.h" |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 33 | |
Mark Brown | b37e399 | 2010-02-03 11:51:42 +0000 | [diff] [blame] | 34 | #define WM8993_NUM_SUPPLIES 6 |
| 35 | static const char *wm8993_supply_names[WM8993_NUM_SUPPLIES] = { |
| 36 | "DCVDD", |
| 37 | "DBVDD", |
| 38 | "AVDD1", |
| 39 | "AVDD2", |
| 40 | "CPVDD", |
| 41 | "SPKVDD", |
| 42 | }; |
| 43 | |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 44 | static struct reg_default wm8993_reg_defaults[] = { |
| 45 | { 1, 0x0000 }, /* R1 - Power Management (1) */ |
| 46 | { 2, 0x6000 }, /* R2 - Power Management (2) */ |
| 47 | { 3, 0x0000 }, /* R3 - Power Management (3) */ |
| 48 | { 4, 0x4050 }, /* R4 - Audio Interface (1) */ |
| 49 | { 5, 0x4000 }, /* R5 - Audio Interface (2) */ |
| 50 | { 6, 0x01C8 }, /* R6 - Clocking 1 */ |
| 51 | { 7, 0x0000 }, /* R7 - Clocking 2 */ |
| 52 | { 8, 0x0000 }, /* R8 - Audio Interface (3) */ |
| 53 | { 9, 0x0040 }, /* R9 - Audio Interface (4) */ |
| 54 | { 10, 0x0004 }, /* R10 - DAC CTRL */ |
| 55 | { 11, 0x00C0 }, /* R11 - Left DAC Digital Volume */ |
| 56 | { 12, 0x00C0 }, /* R12 - Right DAC Digital Volume */ |
| 57 | { 13, 0x0000 }, /* R13 - Digital Side Tone */ |
| 58 | { 14, 0x0300 }, /* R14 - ADC CTRL */ |
| 59 | { 15, 0x00C0 }, /* R15 - Left ADC Digital Volume */ |
| 60 | { 16, 0x00C0 }, /* R16 - Right ADC Digital Volume */ |
| 61 | { 18, 0x0000 }, /* R18 - GPIO CTRL 1 */ |
| 62 | { 19, 0x0010 }, /* R19 - GPIO1 */ |
| 63 | { 20, 0x0000 }, /* R20 - IRQ_DEBOUNCE */ |
| 64 | { 21, 0x8000 }, /* R22 - GPIOCTRL 2 */ |
| 65 | { 22, 0x0800 }, /* R23 - GPIO_POL */ |
| 66 | { 24, 0x008B }, /* R24 - Left Line Input 1&2 Volume */ |
| 67 | { 25, 0x008B }, /* R25 - Left Line Input 3&4 Volume */ |
| 68 | { 26, 0x008B }, /* R26 - Right Line Input 1&2 Volume */ |
| 69 | { 27, 0x008B }, /* R27 - Right Line Input 3&4 Volume */ |
| 70 | { 28, 0x006D }, /* R28 - Left Output Volume */ |
| 71 | { 29, 0x006D }, /* R29 - Right Output Volume */ |
| 72 | { 30, 0x0066 }, /* R30 - Line Outputs Volume */ |
| 73 | { 31, 0x0020 }, /* R31 - HPOUT2 Volume */ |
| 74 | { 32, 0x0079 }, /* R32 - Left OPGA Volume */ |
| 75 | { 33, 0x0079 }, /* R33 - Right OPGA Volume */ |
| 76 | { 34, 0x0003 }, /* R34 - SPKMIXL Attenuation */ |
| 77 | { 35, 0x0003 }, /* R35 - SPKMIXR Attenuation */ |
| 78 | { 36, 0x0011 }, /* R36 - SPKOUT Mixers */ |
| 79 | { 37, 0x0100 }, /* R37 - SPKOUT Boost */ |
| 80 | { 38, 0x0079 }, /* R38 - Speaker Volume Left */ |
| 81 | { 39, 0x0079 }, /* R39 - Speaker Volume Right */ |
| 82 | { 40, 0x0000 }, /* R40 - Input Mixer2 */ |
| 83 | { 41, 0x0000 }, /* R41 - Input Mixer3 */ |
| 84 | { 42, 0x0000 }, /* R42 - Input Mixer4 */ |
| 85 | { 43, 0x0000 }, /* R43 - Input Mixer5 */ |
| 86 | { 44, 0x0000 }, /* R44 - Input Mixer6 */ |
| 87 | { 45, 0x0000 }, /* R45 - Output Mixer1 */ |
| 88 | { 46, 0x0000 }, /* R46 - Output Mixer2 */ |
| 89 | { 47, 0x0000 }, /* R47 - Output Mixer3 */ |
| 90 | { 48, 0x0000 }, /* R48 - Output Mixer4 */ |
| 91 | { 49, 0x0000 }, /* R49 - Output Mixer5 */ |
| 92 | { 50, 0x0000 }, /* R50 - Output Mixer6 */ |
| 93 | { 51, 0x0000 }, /* R51 - HPOUT2 Mixer */ |
| 94 | { 52, 0x0000 }, /* R52 - Line Mixer1 */ |
| 95 | { 53, 0x0000 }, /* R53 - Line Mixer2 */ |
| 96 | { 54, 0x0000 }, /* R54 - Speaker Mixer */ |
| 97 | { 55, 0x0000 }, /* R55 - Additional Control */ |
| 98 | { 56, 0x0000 }, /* R56 - AntiPOP1 */ |
| 99 | { 57, 0x0000 }, /* R57 - AntiPOP2 */ |
| 100 | { 58, 0x0000 }, /* R58 - MICBIAS */ |
| 101 | { 60, 0x0000 }, /* R60 - FLL Control 1 */ |
| 102 | { 61, 0x0000 }, /* R61 - FLL Control 2 */ |
| 103 | { 62, 0x0000 }, /* R62 - FLL Control 3 */ |
| 104 | { 63, 0x2EE0 }, /* R63 - FLL Control 4 */ |
| 105 | { 64, 0x0002 }, /* R64 - FLL Control 5 */ |
| 106 | { 65, 0x2287 }, /* R65 - Clocking 3 */ |
| 107 | { 66, 0x025F }, /* R66 - Clocking 4 */ |
| 108 | { 67, 0x0000 }, /* R67 - MW Slave Control */ |
| 109 | { 69, 0x0002 }, /* R69 - Bus Control 1 */ |
| 110 | { 70, 0x0000 }, /* R70 - Write Sequencer 0 */ |
| 111 | { 71, 0x0000 }, /* R71 - Write Sequencer 1 */ |
| 112 | { 72, 0x0000 }, /* R72 - Write Sequencer 2 */ |
| 113 | { 73, 0x0000 }, /* R73 - Write Sequencer 3 */ |
| 114 | { 74, 0x0000 }, /* R74 - Write Sequencer 4 */ |
| 115 | { 75, 0x0000 }, /* R75 - Write Sequencer 5 */ |
| 116 | { 76, 0x1F25 }, /* R76 - Charge Pump 1 */ |
| 117 | { 81, 0x0000 }, /* R81 - Class W 0 */ |
| 118 | { 85, 0x054A }, /* R85 - DC Servo 1 */ |
| 119 | { 87, 0x0000 }, /* R87 - DC Servo 3 */ |
| 120 | { 96, 0x0100 }, /* R96 - Analogue HP 0 */ |
| 121 | { 98, 0x0000 }, /* R98 - EQ1 */ |
| 122 | { 99, 0x000C }, /* R99 - EQ2 */ |
| 123 | { 100, 0x000C }, /* R100 - EQ3 */ |
| 124 | { 101, 0x000C }, /* R101 - EQ4 */ |
| 125 | { 102, 0x000C }, /* R102 - EQ5 */ |
| 126 | { 103, 0x000C }, /* R103 - EQ6 */ |
| 127 | { 104, 0x0FCA }, /* R104 - EQ7 */ |
| 128 | { 105, 0x0400 }, /* R105 - EQ8 */ |
| 129 | { 106, 0x00D8 }, /* R106 - EQ9 */ |
| 130 | { 107, 0x1EB5 }, /* R107 - EQ10 */ |
| 131 | { 108, 0xF145 }, /* R108 - EQ11 */ |
| 132 | { 109, 0x0B75 }, /* R109 - EQ12 */ |
| 133 | { 110, 0x01C5 }, /* R110 - EQ13 */ |
| 134 | { 111, 0x1C58 }, /* R111 - EQ14 */ |
| 135 | { 112, 0xF373 }, /* R112 - EQ15 */ |
| 136 | { 113, 0x0A54 }, /* R113 - EQ16 */ |
| 137 | { 114, 0x0558 }, /* R114 - EQ17 */ |
| 138 | { 115, 0x168E }, /* R115 - EQ18 */ |
| 139 | { 116, 0xF829 }, /* R116 - EQ19 */ |
| 140 | { 117, 0x07AD }, /* R117 - EQ20 */ |
| 141 | { 118, 0x1103 }, /* R118 - EQ21 */ |
| 142 | { 119, 0x0564 }, /* R119 - EQ22 */ |
| 143 | { 120, 0x0559 }, /* R120 - EQ23 */ |
| 144 | { 121, 0x4000 }, /* R121 - EQ24 */ |
| 145 | { 122, 0x0000 }, /* R122 - Digital Pulls */ |
| 146 | { 123, 0x0F08 }, /* R123 - DRC Control 1 */ |
| 147 | { 124, 0x0000 }, /* R124 - DRC Control 2 */ |
| 148 | { 125, 0x0080 }, /* R125 - DRC Control 3 */ |
| 149 | { 126, 0x0000 }, /* R126 - DRC Control 4 */ |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | static struct { |
| 153 | int ratio; |
| 154 | int clk_sys_rate; |
| 155 | } clk_sys_rates[] = { |
| 156 | { 64, 0 }, |
| 157 | { 128, 1 }, |
| 158 | { 192, 2 }, |
| 159 | { 256, 3 }, |
| 160 | { 384, 4 }, |
| 161 | { 512, 5 }, |
| 162 | { 768, 6 }, |
| 163 | { 1024, 7 }, |
| 164 | { 1408, 8 }, |
| 165 | { 1536, 9 }, |
| 166 | }; |
| 167 | |
| 168 | static struct { |
| 169 | int rate; |
| 170 | int sample_rate; |
| 171 | } sample_rates[] = { |
| 172 | { 8000, 0 }, |
| 173 | { 11025, 1 }, |
| 174 | { 12000, 1 }, |
| 175 | { 16000, 2 }, |
| 176 | { 22050, 3 }, |
| 177 | { 24000, 3 }, |
| 178 | { 32000, 4 }, |
| 179 | { 44100, 5 }, |
| 180 | { 48000, 5 }, |
| 181 | }; |
| 182 | |
| 183 | static struct { |
| 184 | int div; /* *10 due to .5s */ |
| 185 | int bclk_div; |
| 186 | } bclk_divs[] = { |
| 187 | { 10, 0 }, |
| 188 | { 15, 1 }, |
| 189 | { 20, 2 }, |
| 190 | { 30, 3 }, |
| 191 | { 40, 4 }, |
| 192 | { 55, 5 }, |
| 193 | { 60, 6 }, |
| 194 | { 80, 7 }, |
| 195 | { 110, 8 }, |
| 196 | { 120, 9 }, |
| 197 | { 160, 10 }, |
| 198 | { 220, 11 }, |
| 199 | { 240, 12 }, |
| 200 | { 320, 13 }, |
| 201 | { 440, 14 }, |
| 202 | { 480, 15 }, |
| 203 | }; |
| 204 | |
| 205 | struct wm8993_priv { |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 206 | struct wm_hubs_data hubs_data; |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 207 | struct regmap *regmap; |
Mark Brown | b37e399 | 2010-02-03 11:51:42 +0000 | [diff] [blame] | 208 | struct regulator_bulk_data supplies[WM8993_NUM_SUPPLIES]; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 209 | struct wm8993_platform_data pdata; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 210 | int master; |
| 211 | int sysclk_source; |
Mark Brown | d3c9e9a | 2009-08-17 18:52:47 +0100 | [diff] [blame] | 212 | int tdm_slots; |
| 213 | int tdm_width; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 214 | unsigned int mclk_rate; |
| 215 | unsigned int sysclk_rate; |
| 216 | unsigned int fs; |
| 217 | unsigned int bclk; |
| 218 | int class_w_users; |
| 219 | unsigned int fll_fref; |
| 220 | unsigned int fll_fout; |
Mark Brown | 53242c6 | 2010-01-02 13:15:56 +0000 | [diff] [blame] | 221 | int fll_src; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 222 | }; |
| 223 | |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 224 | static bool wm8993_volatile(struct device *dev, unsigned int reg) |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 225 | { |
| 226 | switch (reg) { |
| 227 | case WM8993_SOFTWARE_RESET: |
| 228 | case WM8993_DC_SERVO_0: |
| 229 | case WM8993_DC_SERVO_READBACK_0: |
| 230 | case WM8993_DC_SERVO_READBACK_1: |
| 231 | case WM8993_DC_SERVO_READBACK_2: |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 232 | return true; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 233 | default: |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 234 | return false; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | static bool wm8993_readable(struct device *dev, unsigned int reg) |
| 239 | { |
| 240 | switch (reg) { |
| 241 | case WM8993_SOFTWARE_RESET: |
| 242 | case WM8993_POWER_MANAGEMENT_1: |
| 243 | case WM8993_POWER_MANAGEMENT_2: |
| 244 | case WM8993_POWER_MANAGEMENT_3: |
| 245 | case WM8993_AUDIO_INTERFACE_1: |
| 246 | case WM8993_AUDIO_INTERFACE_2: |
| 247 | case WM8993_CLOCKING_1: |
| 248 | case WM8993_CLOCKING_2: |
| 249 | case WM8993_AUDIO_INTERFACE_3: |
| 250 | case WM8993_AUDIO_INTERFACE_4: |
| 251 | case WM8993_DAC_CTRL: |
| 252 | case WM8993_LEFT_DAC_DIGITAL_VOLUME: |
| 253 | case WM8993_RIGHT_DAC_DIGITAL_VOLUME: |
| 254 | case WM8993_DIGITAL_SIDE_TONE: |
| 255 | case WM8993_ADC_CTRL: |
| 256 | case WM8993_LEFT_ADC_DIGITAL_VOLUME: |
| 257 | case WM8993_RIGHT_ADC_DIGITAL_VOLUME: |
| 258 | case WM8993_GPIO_CTRL_1: |
| 259 | case WM8993_GPIO1: |
| 260 | case WM8993_IRQ_DEBOUNCE: |
| 261 | case WM8993_GPIOCTRL_2: |
| 262 | case WM8993_GPIO_POL: |
| 263 | case WM8993_LEFT_LINE_INPUT_1_2_VOLUME: |
| 264 | case WM8993_LEFT_LINE_INPUT_3_4_VOLUME: |
| 265 | case WM8993_RIGHT_LINE_INPUT_1_2_VOLUME: |
| 266 | case WM8993_RIGHT_LINE_INPUT_3_4_VOLUME: |
| 267 | case WM8993_LEFT_OUTPUT_VOLUME: |
| 268 | case WM8993_RIGHT_OUTPUT_VOLUME: |
| 269 | case WM8993_LINE_OUTPUTS_VOLUME: |
| 270 | case WM8993_HPOUT2_VOLUME: |
| 271 | case WM8993_LEFT_OPGA_VOLUME: |
| 272 | case WM8993_RIGHT_OPGA_VOLUME: |
| 273 | case WM8993_SPKMIXL_ATTENUATION: |
| 274 | case WM8993_SPKMIXR_ATTENUATION: |
| 275 | case WM8993_SPKOUT_MIXERS: |
| 276 | case WM8993_SPKOUT_BOOST: |
| 277 | case WM8993_SPEAKER_VOLUME_LEFT: |
| 278 | case WM8993_SPEAKER_VOLUME_RIGHT: |
| 279 | case WM8993_INPUT_MIXER2: |
| 280 | case WM8993_INPUT_MIXER3: |
| 281 | case WM8993_INPUT_MIXER4: |
| 282 | case WM8993_INPUT_MIXER5: |
| 283 | case WM8993_INPUT_MIXER6: |
| 284 | case WM8993_OUTPUT_MIXER1: |
| 285 | case WM8993_OUTPUT_MIXER2: |
| 286 | case WM8993_OUTPUT_MIXER3: |
| 287 | case WM8993_OUTPUT_MIXER4: |
| 288 | case WM8993_OUTPUT_MIXER5: |
| 289 | case WM8993_OUTPUT_MIXER6: |
| 290 | case WM8993_HPOUT2_MIXER: |
| 291 | case WM8993_LINE_MIXER1: |
| 292 | case WM8993_LINE_MIXER2: |
| 293 | case WM8993_SPEAKER_MIXER: |
| 294 | case WM8993_ADDITIONAL_CONTROL: |
| 295 | case WM8993_ANTIPOP1: |
| 296 | case WM8993_ANTIPOP2: |
| 297 | case WM8993_MICBIAS: |
| 298 | case WM8993_FLL_CONTROL_1: |
| 299 | case WM8993_FLL_CONTROL_2: |
| 300 | case WM8993_FLL_CONTROL_3: |
| 301 | case WM8993_FLL_CONTROL_4: |
| 302 | case WM8993_FLL_CONTROL_5: |
| 303 | case WM8993_CLOCKING_3: |
| 304 | case WM8993_CLOCKING_4: |
| 305 | case WM8993_MW_SLAVE_CONTROL: |
| 306 | case WM8993_BUS_CONTROL_1: |
| 307 | case WM8993_WRITE_SEQUENCER_0: |
| 308 | case WM8993_WRITE_SEQUENCER_1: |
| 309 | case WM8993_WRITE_SEQUENCER_2: |
| 310 | case WM8993_WRITE_SEQUENCER_3: |
| 311 | case WM8993_WRITE_SEQUENCER_4: |
| 312 | case WM8993_WRITE_SEQUENCER_5: |
| 313 | case WM8993_CHARGE_PUMP_1: |
| 314 | case WM8993_CLASS_W_0: |
| 315 | case WM8993_DC_SERVO_0: |
| 316 | case WM8993_DC_SERVO_1: |
| 317 | case WM8993_DC_SERVO_3: |
| 318 | case WM8993_DC_SERVO_READBACK_0: |
| 319 | case WM8993_DC_SERVO_READBACK_1: |
| 320 | case WM8993_DC_SERVO_READBACK_2: |
| 321 | case WM8993_ANALOGUE_HP_0: |
| 322 | case WM8993_EQ1: |
| 323 | case WM8993_EQ2: |
| 324 | case WM8993_EQ3: |
| 325 | case WM8993_EQ4: |
| 326 | case WM8993_EQ5: |
| 327 | case WM8993_EQ6: |
| 328 | case WM8993_EQ7: |
| 329 | case WM8993_EQ8: |
| 330 | case WM8993_EQ9: |
| 331 | case WM8993_EQ10: |
| 332 | case WM8993_EQ11: |
| 333 | case WM8993_EQ12: |
| 334 | case WM8993_EQ13: |
| 335 | case WM8993_EQ14: |
| 336 | case WM8993_EQ15: |
| 337 | case WM8993_EQ16: |
| 338 | case WM8993_EQ17: |
| 339 | case WM8993_EQ18: |
| 340 | case WM8993_EQ19: |
| 341 | case WM8993_EQ20: |
| 342 | case WM8993_EQ21: |
| 343 | case WM8993_EQ22: |
| 344 | case WM8993_EQ23: |
| 345 | case WM8993_EQ24: |
| 346 | case WM8993_DIGITAL_PULLS: |
| 347 | case WM8993_DRC_CONTROL_1: |
| 348 | case WM8993_DRC_CONTROL_2: |
| 349 | case WM8993_DRC_CONTROL_3: |
| 350 | case WM8993_DRC_CONTROL_4: |
| 351 | return true; |
| 352 | default: |
| 353 | return false; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 357 | struct _fll_div { |
| 358 | u16 fll_fratio; |
| 359 | u16 fll_outdiv; |
| 360 | u16 fll_clk_ref_div; |
| 361 | u16 n; |
| 362 | u16 k; |
| 363 | }; |
| 364 | |
| 365 | /* The size in bits of the FLL divide multiplied by 10 |
| 366 | * to allow rounding later */ |
| 367 | #define FIXED_FLL_SIZE ((1 << 16) * 10) |
| 368 | |
| 369 | static struct { |
| 370 | unsigned int min; |
| 371 | unsigned int max; |
| 372 | u16 fll_fratio; |
| 373 | int ratio; |
| 374 | } fll_fratios[] = { |
| 375 | { 0, 64000, 4, 16 }, |
| 376 | { 64000, 128000, 3, 8 }, |
| 377 | { 128000, 256000, 2, 4 }, |
| 378 | { 256000, 1000000, 1, 2 }, |
| 379 | { 1000000, 13500000, 0, 1 }, |
| 380 | }; |
| 381 | |
| 382 | static int fll_factors(struct _fll_div *fll_div, unsigned int Fref, |
| 383 | unsigned int Fout) |
| 384 | { |
| 385 | u64 Kpart; |
| 386 | unsigned int K, Ndiv, Nmod, target; |
| 387 | unsigned int div; |
| 388 | int i; |
| 389 | |
| 390 | /* Fref must be <=13.5MHz */ |
| 391 | div = 1; |
Mark Brown | 0c11f65 | 2009-07-17 22:13:01 +0100 | [diff] [blame] | 392 | fll_div->fll_clk_ref_div = 0; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 393 | while ((Fref / div) > 13500000) { |
| 394 | div *= 2; |
Mark Brown | 0c11f65 | 2009-07-17 22:13:01 +0100 | [diff] [blame] | 395 | fll_div->fll_clk_ref_div++; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 396 | |
| 397 | if (div > 8) { |
| 398 | pr_err("Can't scale %dMHz input down to <=13.5MHz\n", |
| 399 | Fref); |
| 400 | return -EINVAL; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | pr_debug("Fref=%u Fout=%u\n", Fref, Fout); |
| 405 | |
| 406 | /* Apply the division for our remaining calculations */ |
| 407 | Fref /= div; |
| 408 | |
| 409 | /* Fvco should be 90-100MHz; don't check the upper bound */ |
| 410 | div = 0; |
| 411 | target = Fout * 2; |
| 412 | while (target < 90000000) { |
| 413 | div++; |
| 414 | target *= 2; |
| 415 | if (div > 7) { |
| 416 | pr_err("Unable to find FLL_OUTDIV for Fout=%uHz\n", |
| 417 | Fout); |
| 418 | return -EINVAL; |
| 419 | } |
| 420 | } |
| 421 | fll_div->fll_outdiv = div; |
| 422 | |
| 423 | pr_debug("Fvco=%dHz\n", target); |
| 424 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 425 | /* Find an appropriate FLL_FRATIO and factor it out of the target */ |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 426 | for (i = 0; i < ARRAY_SIZE(fll_fratios); i++) { |
| 427 | if (fll_fratios[i].min <= Fref && Fref <= fll_fratios[i].max) { |
| 428 | fll_div->fll_fratio = fll_fratios[i].fll_fratio; |
| 429 | target /= fll_fratios[i].ratio; |
| 430 | break; |
| 431 | } |
| 432 | } |
| 433 | if (i == ARRAY_SIZE(fll_fratios)) { |
| 434 | pr_err("Unable to find FLL_FRATIO for Fref=%uHz\n", Fref); |
| 435 | return -EINVAL; |
| 436 | } |
| 437 | |
| 438 | /* Now, calculate N.K */ |
| 439 | Ndiv = target / Fref; |
| 440 | |
| 441 | fll_div->n = Ndiv; |
| 442 | Nmod = target % Fref; |
| 443 | pr_debug("Nmod=%d\n", Nmod); |
| 444 | |
| 445 | /* Calculate fractional part - scale up so we can round. */ |
| 446 | Kpart = FIXED_FLL_SIZE * (long long)Nmod; |
| 447 | |
| 448 | do_div(Kpart, Fref); |
| 449 | |
| 450 | K = Kpart & 0xFFFFFFFF; |
| 451 | |
| 452 | if ((K % 10) >= 5) |
| 453 | K += 5; |
| 454 | |
| 455 | /* Move down to proper range now rounding is done */ |
| 456 | fll_div->k = K / 10; |
| 457 | |
| 458 | pr_debug("N=%x K=%x FLL_FRATIO=%x FLL_OUTDIV=%x FLL_CLK_REF_DIV=%x\n", |
| 459 | fll_div->n, fll_div->k, |
| 460 | fll_div->fll_fratio, fll_div->fll_outdiv, |
| 461 | fll_div->fll_clk_ref_div); |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 466 | static int _wm8993_set_fll(struct snd_soc_codec *codec, int fll_id, int source, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 467 | unsigned int Fref, unsigned int Fout) |
| 468 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 469 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 470 | u16 reg1, reg4, reg5; |
| 471 | struct _fll_div fll_div; |
| 472 | int ret; |
| 473 | |
| 474 | /* Any change? */ |
| 475 | if (Fref == wm8993->fll_fref && Fout == wm8993->fll_fout) |
| 476 | return 0; |
| 477 | |
| 478 | /* Disable the FLL */ |
| 479 | if (Fout == 0) { |
| 480 | dev_dbg(codec->dev, "FLL disabled\n"); |
| 481 | wm8993->fll_fref = 0; |
| 482 | wm8993->fll_fout = 0; |
| 483 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 484 | reg1 = snd_soc_read(codec, WM8993_FLL_CONTROL_1); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 485 | reg1 &= ~WM8993_FLL_ENA; |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 486 | snd_soc_write(codec, WM8993_FLL_CONTROL_1, reg1); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | ret = fll_factors(&fll_div, Fref, Fout); |
| 492 | if (ret != 0) |
| 493 | return ret; |
| 494 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 495 | reg5 = snd_soc_read(codec, WM8993_FLL_CONTROL_5); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 496 | reg5 &= ~WM8993_FLL_CLK_SRC_MASK; |
| 497 | |
| 498 | switch (fll_id) { |
| 499 | case WM8993_FLL_MCLK: |
| 500 | break; |
| 501 | |
| 502 | case WM8993_FLL_LRCLK: |
| 503 | reg5 |= 1; |
| 504 | break; |
| 505 | |
| 506 | case WM8993_FLL_BCLK: |
| 507 | reg5 |= 2; |
| 508 | break; |
| 509 | |
| 510 | default: |
| 511 | dev_err(codec->dev, "Unknown FLL ID %d\n", fll_id); |
| 512 | return -EINVAL; |
| 513 | } |
| 514 | |
| 515 | /* Any FLL configuration change requires that the FLL be |
| 516 | * disabled first. */ |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 517 | reg1 = snd_soc_read(codec, WM8993_FLL_CONTROL_1); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 518 | reg1 &= ~WM8993_FLL_ENA; |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 519 | snd_soc_write(codec, WM8993_FLL_CONTROL_1, reg1); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 520 | |
| 521 | /* Apply the configuration */ |
| 522 | if (fll_div.k) |
| 523 | reg1 |= WM8993_FLL_FRAC_MASK; |
| 524 | else |
| 525 | reg1 &= ~WM8993_FLL_FRAC_MASK; |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 526 | snd_soc_write(codec, WM8993_FLL_CONTROL_1, reg1); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 527 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 528 | snd_soc_write(codec, WM8993_FLL_CONTROL_2, |
| 529 | (fll_div.fll_outdiv << WM8993_FLL_OUTDIV_SHIFT) | |
| 530 | (fll_div.fll_fratio << WM8993_FLL_FRATIO_SHIFT)); |
| 531 | snd_soc_write(codec, WM8993_FLL_CONTROL_3, fll_div.k); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 532 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 533 | reg4 = snd_soc_read(codec, WM8993_FLL_CONTROL_4); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 534 | reg4 &= ~WM8993_FLL_N_MASK; |
| 535 | reg4 |= fll_div.n << WM8993_FLL_N_SHIFT; |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 536 | snd_soc_write(codec, WM8993_FLL_CONTROL_4, reg4); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 537 | |
| 538 | reg5 &= ~WM8993_FLL_CLK_REF_DIV_MASK; |
| 539 | reg5 |= fll_div.fll_clk_ref_div << WM8993_FLL_CLK_REF_DIV_SHIFT; |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 540 | snd_soc_write(codec, WM8993_FLL_CONTROL_5, reg5); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 541 | |
| 542 | /* Enable the FLL */ |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 543 | snd_soc_write(codec, WM8993_FLL_CONTROL_1, reg1 | WM8993_FLL_ENA); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 544 | |
Mark Brown | 986b2f2 | 2012-01-17 16:28:59 +0000 | [diff] [blame] | 545 | /* Both overestimates */ |
| 546 | if (Fref < 1000000) |
| 547 | msleep(3); |
| 548 | else |
| 549 | msleep(1); |
| 550 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 551 | dev_dbg(codec->dev, "FLL enabled at %dHz->%dHz\n", Fref, Fout); |
| 552 | |
| 553 | wm8993->fll_fref = Fref; |
| 554 | wm8993->fll_fout = Fout; |
Mark Brown | 53242c6 | 2010-01-02 13:15:56 +0000 | [diff] [blame] | 555 | wm8993->fll_src = source; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 556 | |
| 557 | return 0; |
| 558 | } |
| 559 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 560 | static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, int source, |
| 561 | unsigned int Fref, unsigned int Fout) |
| 562 | { |
| 563 | return _wm8993_set_fll(dai->codec, fll_id, source, Fref, Fout); |
| 564 | } |
| 565 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 566 | static int configure_clock(struct snd_soc_codec *codec) |
| 567 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 568 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 569 | unsigned int reg; |
| 570 | |
| 571 | /* This should be done on init() for bypass paths */ |
| 572 | switch (wm8993->sysclk_source) { |
| 573 | case WM8993_SYSCLK_MCLK: |
| 574 | dev_dbg(codec->dev, "Using %dHz MCLK\n", wm8993->mclk_rate); |
| 575 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 576 | reg = snd_soc_read(codec, WM8993_CLOCKING_2); |
Mark Brown | 0182dcc | 2009-08-17 18:51:44 +0100 | [diff] [blame] | 577 | reg &= ~(WM8993_MCLK_DIV | WM8993_SYSCLK_SRC); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 578 | if (wm8993->mclk_rate > 13500000) { |
| 579 | reg |= WM8993_MCLK_DIV; |
| 580 | wm8993->sysclk_rate = wm8993->mclk_rate / 2; |
| 581 | } else { |
| 582 | reg &= ~WM8993_MCLK_DIV; |
| 583 | wm8993->sysclk_rate = wm8993->mclk_rate; |
| 584 | } |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 585 | snd_soc_write(codec, WM8993_CLOCKING_2, reg); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 586 | break; |
| 587 | |
| 588 | case WM8993_SYSCLK_FLL: |
| 589 | dev_dbg(codec->dev, "Using %dHz FLL clock\n", |
| 590 | wm8993->fll_fout); |
| 591 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 592 | reg = snd_soc_read(codec, WM8993_CLOCKING_2); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 593 | reg |= WM8993_SYSCLK_SRC; |
| 594 | if (wm8993->fll_fout > 13500000) { |
| 595 | reg |= WM8993_MCLK_DIV; |
| 596 | wm8993->sysclk_rate = wm8993->fll_fout / 2; |
| 597 | } else { |
| 598 | reg &= ~WM8993_MCLK_DIV; |
| 599 | wm8993->sysclk_rate = wm8993->fll_fout; |
| 600 | } |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 601 | snd_soc_write(codec, WM8993_CLOCKING_2, reg); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 602 | break; |
| 603 | |
| 604 | default: |
| 605 | dev_err(codec->dev, "System clock not configured\n"); |
| 606 | return -EINVAL; |
| 607 | } |
| 608 | |
| 609 | dev_dbg(codec->dev, "CLK_SYS is %dHz\n", wm8993->sysclk_rate); |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 614 | static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -3600, 300, 0); |
| 615 | static const DECLARE_TLV_DB_SCALE(drc_comp_threash, -4500, 75, 0); |
| 616 | static const DECLARE_TLV_DB_SCALE(drc_comp_amp, -2250, 75, 0); |
| 617 | static const DECLARE_TLV_DB_SCALE(drc_min_tlv, -1800, 600, 0); |
| 618 | static const unsigned int drc_max_tlv[] = { |
Clemens Ladisch | dac678f | 2011-11-20 15:14:11 +0100 | [diff] [blame] | 619 | TLV_DB_RANGE_HEAD(2), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 620 | 0, 2, TLV_DB_SCALE_ITEM(1200, 600, 0), |
| 621 | 3, 3, TLV_DB_SCALE_ITEM(3600, 0, 0), |
| 622 | }; |
| 623 | static const DECLARE_TLV_DB_SCALE(drc_qr_tlv, 1200, 600, 0); |
| 624 | static const DECLARE_TLV_DB_SCALE(drc_startup_tlv, -1800, 300, 0); |
| 625 | static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); |
| 626 | static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1); |
| 627 | static const DECLARE_TLV_DB_SCALE(dac_boost_tlv, 0, 600, 0); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 628 | |
| 629 | static const char *dac_deemph_text[] = { |
| 630 | "None", |
| 631 | "32kHz", |
| 632 | "44.1kHz", |
| 633 | "48kHz", |
| 634 | }; |
| 635 | |
| 636 | static const struct soc_enum dac_deemph = |
| 637 | SOC_ENUM_SINGLE(WM8993_DAC_CTRL, 4, 4, dac_deemph_text); |
| 638 | |
| 639 | static const char *adc_hpf_text[] = { |
| 640 | "Hi-Fi", |
| 641 | "Voice 1", |
| 642 | "Voice 2", |
| 643 | "Voice 3", |
| 644 | }; |
| 645 | |
| 646 | static const struct soc_enum adc_hpf = |
| 647 | SOC_ENUM_SINGLE(WM8993_ADC_CTRL, 5, 4, adc_hpf_text); |
| 648 | |
| 649 | static const char *drc_path_text[] = { |
| 650 | "ADC", |
| 651 | "DAC" |
| 652 | }; |
| 653 | |
| 654 | static const struct soc_enum drc_path = |
| 655 | SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_1, 14, 2, drc_path_text); |
| 656 | |
| 657 | static const char *drc_r0_text[] = { |
| 658 | "1", |
| 659 | "1/2", |
| 660 | "1/4", |
| 661 | "1/8", |
| 662 | "1/16", |
| 663 | "0", |
| 664 | }; |
| 665 | |
| 666 | static const struct soc_enum drc_r0 = |
| 667 | SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_3, 8, 6, drc_r0_text); |
| 668 | |
| 669 | static const char *drc_r1_text[] = { |
| 670 | "1", |
| 671 | "1/2", |
| 672 | "1/4", |
| 673 | "1/8", |
| 674 | "0", |
| 675 | }; |
| 676 | |
| 677 | static const struct soc_enum drc_r1 = |
| 678 | SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_4, 13, 5, drc_r1_text); |
| 679 | |
| 680 | static const char *drc_attack_text[] = { |
| 681 | "Reserved", |
| 682 | "181us", |
| 683 | "363us", |
| 684 | "726us", |
| 685 | "1.45ms", |
| 686 | "2.9ms", |
| 687 | "5.8ms", |
| 688 | "11.6ms", |
| 689 | "23.2ms", |
| 690 | "46.4ms", |
| 691 | "92.8ms", |
| 692 | "185.6ms", |
| 693 | }; |
| 694 | |
| 695 | static const struct soc_enum drc_attack = |
| 696 | SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_2, 12, 12, drc_attack_text); |
| 697 | |
| 698 | static const char *drc_decay_text[] = { |
| 699 | "186ms", |
| 700 | "372ms", |
| 701 | "743ms", |
| 702 | "1.49s", |
| 703 | "2.97ms", |
| 704 | "5.94ms", |
| 705 | "11.89ms", |
| 706 | "23.78ms", |
| 707 | "47.56ms", |
| 708 | }; |
| 709 | |
| 710 | static const struct soc_enum drc_decay = |
| 711 | SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_2, 8, 9, drc_decay_text); |
| 712 | |
| 713 | static const char *drc_ff_text[] = { |
| 714 | "5 samples", |
| 715 | "9 samples", |
| 716 | }; |
| 717 | |
| 718 | static const struct soc_enum drc_ff = |
| 719 | SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_3, 7, 2, drc_ff_text); |
| 720 | |
| 721 | static const char *drc_qr_rate_text[] = { |
| 722 | "0.725ms", |
| 723 | "1.45ms", |
| 724 | "5.8ms", |
| 725 | }; |
| 726 | |
| 727 | static const struct soc_enum drc_qr_rate = |
| 728 | SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_3, 0, 3, drc_qr_rate_text); |
| 729 | |
| 730 | static const char *drc_smooth_text[] = { |
| 731 | "Low", |
| 732 | "Medium", |
| 733 | "High", |
| 734 | }; |
| 735 | |
| 736 | static const struct soc_enum drc_smooth = |
| 737 | SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_1, 4, 3, drc_smooth_text); |
| 738 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 739 | static const struct snd_kcontrol_new wm8993_snd_controls[] = { |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 740 | SOC_DOUBLE_TLV("Digital Sidetone Volume", WM8993_DIGITAL_SIDE_TONE, |
| 741 | 5, 9, 12, 0, sidetone_tlv), |
| 742 | |
| 743 | SOC_SINGLE("DRC Switch", WM8993_DRC_CONTROL_1, 15, 1, 0), |
| 744 | SOC_ENUM("DRC Path", drc_path), |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 745 | SOC_SINGLE_TLV("DRC Compressor Threshold Volume", WM8993_DRC_CONTROL_2, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 746 | 2, 60, 1, drc_comp_threash), |
| 747 | SOC_SINGLE_TLV("DRC Compressor Amplitude Volume", WM8993_DRC_CONTROL_3, |
| 748 | 11, 30, 1, drc_comp_amp), |
| 749 | SOC_ENUM("DRC R0", drc_r0), |
| 750 | SOC_ENUM("DRC R1", drc_r1), |
| 751 | SOC_SINGLE_TLV("DRC Minimum Volume", WM8993_DRC_CONTROL_1, 2, 3, 1, |
| 752 | drc_min_tlv), |
| 753 | SOC_SINGLE_TLV("DRC Maximum Volume", WM8993_DRC_CONTROL_1, 0, 3, 0, |
| 754 | drc_max_tlv), |
| 755 | SOC_ENUM("DRC Attack Rate", drc_attack), |
| 756 | SOC_ENUM("DRC Decay Rate", drc_decay), |
| 757 | SOC_ENUM("DRC FF Delay", drc_ff), |
| 758 | SOC_SINGLE("DRC Anti-clip Switch", WM8993_DRC_CONTROL_1, 9, 1, 0), |
| 759 | SOC_SINGLE("DRC Quick Release Switch", WM8993_DRC_CONTROL_1, 10, 1, 0), |
| 760 | SOC_SINGLE_TLV("DRC Quick Release Volume", WM8993_DRC_CONTROL_3, 2, 3, 0, |
| 761 | drc_qr_tlv), |
| 762 | SOC_ENUM("DRC Quick Release Rate", drc_qr_rate), |
| 763 | SOC_SINGLE("DRC Smoothing Switch", WM8993_DRC_CONTROL_1, 11, 1, 0), |
| 764 | SOC_SINGLE("DRC Smoothing Hysteresis Switch", WM8993_DRC_CONTROL_1, 8, 1, 0), |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 765 | SOC_ENUM("DRC Smoothing Hysteresis Threshold", drc_smooth), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 766 | SOC_SINGLE_TLV("DRC Startup Volume", WM8993_DRC_CONTROL_4, 8, 18, 0, |
| 767 | drc_startup_tlv), |
| 768 | |
| 769 | SOC_SINGLE("EQ Switch", WM8993_EQ1, 0, 1, 0), |
| 770 | |
| 771 | SOC_DOUBLE_R_TLV("Capture Volume", WM8993_LEFT_ADC_DIGITAL_VOLUME, |
| 772 | WM8993_RIGHT_ADC_DIGITAL_VOLUME, 1, 96, 0, digital_tlv), |
| 773 | SOC_SINGLE("ADC High Pass Filter Switch", WM8993_ADC_CTRL, 8, 1, 0), |
| 774 | SOC_ENUM("ADC High Pass Filter Mode", adc_hpf), |
| 775 | |
| 776 | SOC_DOUBLE_R_TLV("Playback Volume", WM8993_LEFT_DAC_DIGITAL_VOLUME, |
| 777 | WM8993_RIGHT_DAC_DIGITAL_VOLUME, 1, 96, 0, digital_tlv), |
| 778 | SOC_SINGLE_TLV("Playback Boost Volume", WM8993_AUDIO_INTERFACE_2, 10, 3, 0, |
| 779 | dac_boost_tlv), |
| 780 | SOC_ENUM("DAC Deemphasis", dac_deemph), |
| 781 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 782 | SOC_SINGLE_TLV("SPKL DAC Volume", WM8993_SPKMIXL_ATTENUATION, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 783 | 2, 1, 1, wm_hubs_spkmix_tlv), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 784 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 785 | SOC_SINGLE_TLV("SPKR DAC Volume", WM8993_SPKMIXR_ATTENUATION, |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 786 | 2, 1, 1, wm_hubs_spkmix_tlv), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 787 | }; |
| 788 | |
| 789 | static const struct snd_kcontrol_new wm8993_eq_controls[] = { |
| 790 | SOC_SINGLE_TLV("EQ1 Volume", WM8993_EQ2, 0, 24, 0, eq_tlv), |
| 791 | SOC_SINGLE_TLV("EQ2 Volume", WM8993_EQ3, 0, 24, 0, eq_tlv), |
| 792 | SOC_SINGLE_TLV("EQ3 Volume", WM8993_EQ4, 0, 24, 0, eq_tlv), |
| 793 | SOC_SINGLE_TLV("EQ4 Volume", WM8993_EQ5, 0, 24, 0, eq_tlv), |
| 794 | SOC_SINGLE_TLV("EQ5 Volume", WM8993_EQ6, 0, 24, 0, eq_tlv), |
| 795 | }; |
| 796 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 797 | static int clk_sys_event(struct snd_soc_dapm_widget *w, |
| 798 | struct snd_kcontrol *kcontrol, int event) |
| 799 | { |
| 800 | struct snd_soc_codec *codec = w->codec; |
| 801 | |
| 802 | switch (event) { |
| 803 | case SND_SOC_DAPM_PRE_PMU: |
| 804 | return configure_clock(codec); |
| 805 | |
| 806 | case SND_SOC_DAPM_POST_PMD: |
| 807 | break; |
| 808 | } |
| 809 | |
| 810 | return 0; |
| 811 | } |
| 812 | |
| 813 | /* |
| 814 | * When used with DAC outputs only the WM8993 charge pump supports |
| 815 | * operation in class W mode, providing very low power consumption |
| 816 | * when used with digital sources. Enable and disable this mode |
| 817 | * automatically depending on the mixer configuration. |
| 818 | * |
| 819 | * Currently the only supported paths are the direct DAC->headphone |
| 820 | * paths (which provide minimum power consumption anyway). |
| 821 | */ |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 822 | static int class_w_put(struct snd_kcontrol *kcontrol, |
| 823 | struct snd_ctl_elem_value *ucontrol) |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 824 | { |
Jarkko Nikula | 9d03545 | 2011-05-13 19:16:52 +0300 | [diff] [blame] | 825 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 826 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 827 | struct snd_soc_codec *codec = widget->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 828 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 829 | int ret; |
| 830 | |
| 831 | /* Turn it off if we're using the main output mixer */ |
| 832 | if (ucontrol->value.integer.value[0] == 0) { |
| 833 | if (wm8993->class_w_users == 0) { |
| 834 | dev_dbg(codec->dev, "Disabling Class W\n"); |
| 835 | snd_soc_update_bits(codec, WM8993_CLASS_W_0, |
| 836 | WM8993_CP_DYN_FREQ | |
| 837 | WM8993_CP_DYN_V, |
| 838 | 0); |
| 839 | } |
| 840 | wm8993->class_w_users++; |
Mark Brown | fec6dd8 | 2010-10-27 13:48:36 -0700 | [diff] [blame] | 841 | wm8993->hubs_data.class_w = true; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | /* Implement the change */ |
| 845 | ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 846 | |
| 847 | /* Enable it if we're using the direct DAC path */ |
| 848 | if (ucontrol->value.integer.value[0] == 1) { |
| 849 | if (wm8993->class_w_users == 1) { |
| 850 | dev_dbg(codec->dev, "Enabling Class W\n"); |
| 851 | snd_soc_update_bits(codec, WM8993_CLASS_W_0, |
| 852 | WM8993_CP_DYN_FREQ | |
| 853 | WM8993_CP_DYN_V, |
| 854 | WM8993_CP_DYN_FREQ | |
| 855 | WM8993_CP_DYN_V); |
| 856 | } |
| 857 | wm8993->class_w_users--; |
Mark Brown | fec6dd8 | 2010-10-27 13:48:36 -0700 | [diff] [blame] | 858 | wm8993->hubs_data.class_w = false; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | dev_dbg(codec->dev, "Indirect DAC use count now %d\n", |
| 862 | wm8993->class_w_users); |
| 863 | |
| 864 | return ret; |
| 865 | } |
| 866 | |
| 867 | #define SOC_DAPM_ENUM_W(xname, xenum) \ |
| 868 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 869 | .info = snd_soc_info_enum_double, \ |
| 870 | .get = snd_soc_dapm_get_enum_double, \ |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 871 | .put = class_w_put, \ |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 872 | .private_value = (unsigned long)&xenum } |
| 873 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 874 | static const char *hp_mux_text[] = { |
| 875 | "Mixer", |
| 876 | "DAC", |
| 877 | }; |
| 878 | |
| 879 | static const struct soc_enum hpl_enum = |
| 880 | SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER1, 8, 2, hp_mux_text); |
| 881 | |
| 882 | static const struct snd_kcontrol_new hpl_mux = |
| 883 | SOC_DAPM_ENUM_W("Left Headphone Mux", hpl_enum); |
| 884 | |
| 885 | static const struct soc_enum hpr_enum = |
| 886 | SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER2, 8, 2, hp_mux_text); |
| 887 | |
| 888 | static const struct snd_kcontrol_new hpr_mux = |
| 889 | SOC_DAPM_ENUM_W("Right Headphone Mux", hpr_enum); |
| 890 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 891 | static const struct snd_kcontrol_new left_speaker_mixer[] = { |
| 892 | SOC_DAPM_SINGLE("Input Switch", WM8993_SPEAKER_MIXER, 7, 1, 0), |
| 893 | SOC_DAPM_SINGLE("IN1LP Switch", WM8993_SPEAKER_MIXER, 5, 1, 0), |
| 894 | SOC_DAPM_SINGLE("Output Switch", WM8993_SPEAKER_MIXER, 3, 1, 0), |
| 895 | SOC_DAPM_SINGLE("DAC Switch", WM8993_SPEAKER_MIXER, 6, 1, 0), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 896 | }; |
| 897 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 898 | static const struct snd_kcontrol_new right_speaker_mixer[] = { |
| 899 | SOC_DAPM_SINGLE("Input Switch", WM8993_SPEAKER_MIXER, 6, 1, 0), |
| 900 | SOC_DAPM_SINGLE("IN1RP Switch", WM8993_SPEAKER_MIXER, 4, 1, 0), |
| 901 | SOC_DAPM_SINGLE("Output Switch", WM8993_SPEAKER_MIXER, 2, 1, 0), |
| 902 | SOC_DAPM_SINGLE("DAC Switch", WM8993_SPEAKER_MIXER, 0, 1, 0), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 903 | }; |
| 904 | |
Mark Brown | 59ae07a | 2009-08-18 16:01:57 +0100 | [diff] [blame] | 905 | static const char *aif_text[] = { |
| 906 | "Left", "Right" |
| 907 | }; |
| 908 | |
| 909 | static const struct soc_enum aifoutl_enum = |
| 910 | SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_1, 15, 2, aif_text); |
| 911 | |
| 912 | static const struct snd_kcontrol_new aifoutl_mux = |
| 913 | SOC_DAPM_ENUM("AIFOUTL Mux", aifoutl_enum); |
| 914 | |
| 915 | static const struct soc_enum aifoutr_enum = |
| 916 | SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_1, 14, 2, aif_text); |
| 917 | |
| 918 | static const struct snd_kcontrol_new aifoutr_mux = |
| 919 | SOC_DAPM_ENUM("AIFOUTR Mux", aifoutr_enum); |
| 920 | |
| 921 | static const struct soc_enum aifinl_enum = |
| 922 | SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_2, 15, 2, aif_text); |
| 923 | |
| 924 | static const struct snd_kcontrol_new aifinl_mux = |
| 925 | SOC_DAPM_ENUM("AIFINL Mux", aifinl_enum); |
| 926 | |
| 927 | static const struct soc_enum aifinr_enum = |
| 928 | SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_2, 14, 2, aif_text); |
| 929 | |
| 930 | static const struct snd_kcontrol_new aifinr_mux = |
| 931 | SOC_DAPM_ENUM("AIFINR Mux", aifinr_enum); |
| 932 | |
| 933 | static const char *sidetone_text[] = { |
| 934 | "None", "Left", "Right" |
| 935 | }; |
| 936 | |
| 937 | static const struct soc_enum sidetonel_enum = |
| 938 | SOC_ENUM_SINGLE(WM8993_DIGITAL_SIDE_TONE, 2, 3, sidetone_text); |
| 939 | |
| 940 | static const struct snd_kcontrol_new sidetonel_mux = |
| 941 | SOC_DAPM_ENUM("Left Sidetone", sidetonel_enum); |
| 942 | |
| 943 | static const struct soc_enum sidetoner_enum = |
| 944 | SOC_ENUM_SINGLE(WM8993_DIGITAL_SIDE_TONE, 0, 3, sidetone_text); |
| 945 | |
| 946 | static const struct snd_kcontrol_new sidetoner_mux = |
| 947 | SOC_DAPM_ENUM("Right Sidetone", sidetoner_enum); |
| 948 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 949 | static const struct snd_soc_dapm_widget wm8993_dapm_widgets[] = { |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 950 | SND_SOC_DAPM_SUPPLY("CLK_SYS", WM8993_BUS_CONTROL_1, 1, 0, clk_sys_event, |
| 951 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 952 | SND_SOC_DAPM_SUPPLY("TOCLK", WM8993_CLOCKING_1, 14, 0, NULL, 0), |
| 953 | SND_SOC_DAPM_SUPPLY("CLK_DSP", WM8993_CLOCKING_3, 0, 0, NULL, 0), |
Mark Brown | 4e04ada | 2011-07-15 15:12:31 +0900 | [diff] [blame] | 954 | SND_SOC_DAPM_SUPPLY("VMID", SND_SOC_NOPM, 0, 0, NULL, 0), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 955 | |
Mark Brown | 59ae07a | 2009-08-18 16:01:57 +0100 | [diff] [blame] | 956 | SND_SOC_DAPM_ADC("ADCL", NULL, WM8993_POWER_MANAGEMENT_2, 1, 0), |
| 957 | SND_SOC_DAPM_ADC("ADCR", NULL, WM8993_POWER_MANAGEMENT_2, 0, 0), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 958 | |
Mark Brown | 59ae07a | 2009-08-18 16:01:57 +0100 | [diff] [blame] | 959 | SND_SOC_DAPM_MUX("AIFOUTL Mux", SND_SOC_NOPM, 0, 0, &aifoutl_mux), |
| 960 | SND_SOC_DAPM_MUX("AIFOUTR Mux", SND_SOC_NOPM, 0, 0, &aifoutr_mux), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 961 | |
Mark Brown | 59ae07a | 2009-08-18 16:01:57 +0100 | [diff] [blame] | 962 | SND_SOC_DAPM_AIF_OUT("AIFOUTL", "Capture", 0, SND_SOC_NOPM, 0, 0), |
| 963 | SND_SOC_DAPM_AIF_OUT("AIFOUTR", "Capture", 1, SND_SOC_NOPM, 0, 0), |
| 964 | |
| 965 | SND_SOC_DAPM_AIF_IN("AIFINL", "Playback", 0, SND_SOC_NOPM, 0, 0), |
| 966 | SND_SOC_DAPM_AIF_IN("AIFINR", "Playback", 1, SND_SOC_NOPM, 0, 0), |
| 967 | |
| 968 | SND_SOC_DAPM_MUX("DACL Mux", SND_SOC_NOPM, 0, 0, &aifinl_mux), |
| 969 | SND_SOC_DAPM_MUX("DACR Mux", SND_SOC_NOPM, 0, 0, &aifinr_mux), |
| 970 | |
| 971 | SND_SOC_DAPM_MUX("DACL Sidetone", SND_SOC_NOPM, 0, 0, &sidetonel_mux), |
| 972 | SND_SOC_DAPM_MUX("DACR Sidetone", SND_SOC_NOPM, 0, 0, &sidetoner_mux), |
| 973 | |
| 974 | SND_SOC_DAPM_DAC("DACL", NULL, WM8993_POWER_MANAGEMENT_3, 1, 0), |
| 975 | SND_SOC_DAPM_DAC("DACR", NULL, WM8993_POWER_MANAGEMENT_3, 0, 0), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 976 | |
Mark Brown | a2342ae | 2009-07-29 21:21:49 +0100 | [diff] [blame] | 977 | SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux), |
| 978 | SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 979 | |
| 980 | SND_SOC_DAPM_MIXER("SPKL", WM8993_POWER_MANAGEMENT_3, 8, 0, |
| 981 | left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)), |
| 982 | SND_SOC_DAPM_MIXER("SPKR", WM8993_POWER_MANAGEMENT_3, 9, 0, |
| 983 | right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)), |
Mark Brown | b70a51b | 2011-06-29 00:21:09 -0700 | [diff] [blame] | 984 | SND_SOC_DAPM_PGA("Direct Voice", SND_SOC_NOPM, 0, 0, NULL, 0), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 985 | }; |
| 986 | |
| 987 | static const struct snd_soc_dapm_route routes[] = { |
Mark Brown | 4e04ada | 2011-07-15 15:12:31 +0900 | [diff] [blame] | 988 | { "MICBIAS1", NULL, "VMID" }, |
| 989 | { "MICBIAS2", NULL, "VMID" }, |
| 990 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 991 | { "ADCL", NULL, "CLK_SYS" }, |
| 992 | { "ADCL", NULL, "CLK_DSP" }, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 993 | { "ADCR", NULL, "CLK_SYS" }, |
| 994 | { "ADCR", NULL, "CLK_DSP" }, |
| 995 | |
Mark Brown | 59ae07a | 2009-08-18 16:01:57 +0100 | [diff] [blame] | 996 | { "AIFOUTL Mux", "Left", "ADCL" }, |
| 997 | { "AIFOUTL Mux", "Right", "ADCR" }, |
| 998 | { "AIFOUTR Mux", "Left", "ADCL" }, |
| 999 | { "AIFOUTR Mux", "Right", "ADCR" }, |
| 1000 | |
| 1001 | { "AIFOUTL", NULL, "AIFOUTL Mux" }, |
| 1002 | { "AIFOUTR", NULL, "AIFOUTR Mux" }, |
| 1003 | |
| 1004 | { "DACL Mux", "Left", "AIFINL" }, |
| 1005 | { "DACL Mux", "Right", "AIFINR" }, |
| 1006 | { "DACR Mux", "Left", "AIFINL" }, |
| 1007 | { "DACR Mux", "Right", "AIFINR" }, |
| 1008 | |
| 1009 | { "DACL Sidetone", "Left", "ADCL" }, |
| 1010 | { "DACL Sidetone", "Right", "ADCR" }, |
| 1011 | { "DACR Sidetone", "Left", "ADCL" }, |
| 1012 | { "DACR Sidetone", "Right", "ADCR" }, |
| 1013 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1014 | { "DACL", NULL, "CLK_SYS" }, |
| 1015 | { "DACL", NULL, "CLK_DSP" }, |
Mark Brown | 59ae07a | 2009-08-18 16:01:57 +0100 | [diff] [blame] | 1016 | { "DACL", NULL, "DACL Mux" }, |
| 1017 | { "DACL", NULL, "DACL Sidetone" }, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1018 | { "DACR", NULL, "CLK_SYS" }, |
| 1019 | { "DACR", NULL, "CLK_DSP" }, |
Mark Brown | 59ae07a | 2009-08-18 16:01:57 +0100 | [diff] [blame] | 1020 | { "DACR", NULL, "DACR Mux" }, |
| 1021 | { "DACR", NULL, "DACR Sidetone" }, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1022 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1023 | { "Left Output Mixer", "DAC Switch", "DACL" }, |
| 1024 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1025 | { "Right Output Mixer", "DAC Switch", "DACR" }, |
| 1026 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1027 | { "Left Output PGA", NULL, "CLK_SYS" }, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1028 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1029 | { "Right Output PGA", NULL, "CLK_SYS" }, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1030 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1031 | { "SPKL", "DAC Switch", "DACL" }, |
| 1032 | { "SPKL", NULL, "CLK_SYS" }, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1033 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1034 | { "SPKR", "DAC Switch", "DACR" }, |
| 1035 | { "SPKR", NULL, "CLK_SYS" }, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1036 | |
| 1037 | { "Left Headphone Mux", "DAC", "DACL" }, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1038 | { "Right Headphone Mux", "DAC", "DACR" }, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1039 | }; |
| 1040 | |
| 1041 | static int wm8993_set_bias_level(struct snd_soc_codec *codec, |
| 1042 | enum snd_soc_bias_level level) |
| 1043 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 1044 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | cf56f62 | 2010-02-03 17:55:55 +0000 | [diff] [blame] | 1045 | int ret; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1046 | |
| 1047 | switch (level) { |
| 1048 | case SND_SOC_BIAS_ON: |
| 1049 | case SND_SOC_BIAS_PREPARE: |
| 1050 | /* VMID=2*40k */ |
| 1051 | snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1, |
| 1052 | WM8993_VMID_SEL_MASK, 0x2); |
| 1053 | snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_2, |
| 1054 | WM8993_TSHUT_ENA, WM8993_TSHUT_ENA); |
| 1055 | break; |
| 1056 | |
| 1057 | case SND_SOC_BIAS_STANDBY: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1058 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { |
Mark Brown | cf56f62 | 2010-02-03 17:55:55 +0000 | [diff] [blame] | 1059 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies), |
| 1060 | wm8993->supplies); |
| 1061 | if (ret != 0) |
| 1062 | return ret; |
| 1063 | |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 1064 | regcache_cache_only(wm8993->regmap, false); |
| 1065 | regcache_sync(wm8993->regmap); |
Mark Brown | cf56f62 | 2010-02-03 17:55:55 +0000 | [diff] [blame] | 1066 | |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 1067 | /* Tune DC servo configuration */ |
| 1068 | snd_soc_write(codec, 0x44, 3); |
| 1069 | snd_soc_write(codec, 0x56, 3); |
| 1070 | snd_soc_write(codec, 0x44, 0); |
| 1071 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1072 | /* Bring up VMID with fast soft start */ |
| 1073 | snd_soc_update_bits(codec, WM8993_ANTIPOP2, |
| 1074 | WM8993_STARTUP_BIAS_ENA | |
| 1075 | WM8993_VMID_BUF_ENA | |
| 1076 | WM8993_VMID_RAMP_MASK | |
| 1077 | WM8993_BIAS_SRC, |
| 1078 | WM8993_STARTUP_BIAS_ENA | |
| 1079 | WM8993_VMID_BUF_ENA | |
| 1080 | WM8993_VMID_RAMP_MASK | |
| 1081 | WM8993_BIAS_SRC); |
| 1082 | |
| 1083 | /* If either line output is single ended we |
| 1084 | * need the VMID buffer */ |
| 1085 | if (!wm8993->pdata.lineout1_diff || |
| 1086 | !wm8993->pdata.lineout2_diff) |
| 1087 | snd_soc_update_bits(codec, WM8993_ANTIPOP1, |
| 1088 | WM8993_LINEOUT_VMID_BUF_ENA, |
| 1089 | WM8993_LINEOUT_VMID_BUF_ENA); |
| 1090 | |
| 1091 | /* VMID=2*40k */ |
| 1092 | snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1, |
| 1093 | WM8993_VMID_SEL_MASK | |
| 1094 | WM8993_BIAS_ENA, |
| 1095 | WM8993_BIAS_ENA | 0x2); |
| 1096 | msleep(32); |
| 1097 | |
| 1098 | /* Switch to normal bias */ |
| 1099 | snd_soc_update_bits(codec, WM8993_ANTIPOP2, |
| 1100 | WM8993_BIAS_SRC | |
| 1101 | WM8993_STARTUP_BIAS_ENA, 0); |
| 1102 | } |
| 1103 | |
| 1104 | /* VMID=2*240k */ |
| 1105 | snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1, |
| 1106 | WM8993_VMID_SEL_MASK, 0x4); |
| 1107 | |
| 1108 | snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_2, |
| 1109 | WM8993_TSHUT_ENA, 0); |
| 1110 | break; |
| 1111 | |
| 1112 | case SND_SOC_BIAS_OFF: |
| 1113 | snd_soc_update_bits(codec, WM8993_ANTIPOP1, |
| 1114 | WM8993_LINEOUT_VMID_BUF_ENA, 0); |
| 1115 | |
| 1116 | snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1, |
| 1117 | WM8993_VMID_SEL_MASK | WM8993_BIAS_ENA, |
| 1118 | 0); |
Mark Brown | cf56f62 | 2010-02-03 17:55:55 +0000 | [diff] [blame] | 1119 | |
Mark Brown | 83b6542 | 2010-12-14 11:25:18 +0000 | [diff] [blame] | 1120 | snd_soc_update_bits(codec, WM8993_ANTIPOP2, |
| 1121 | WM8993_STARTUP_BIAS_ENA | |
| 1122 | WM8993_VMID_BUF_ENA | |
| 1123 | WM8993_VMID_RAMP_MASK | |
| 1124 | WM8993_BIAS_SRC, 0); |
| 1125 | |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 1126 | regcache_cache_only(wm8993->regmap, true); |
| 1127 | regcache_mark_dirty(wm8993->regmap); |
Mark Brown | cf56f62 | 2010-02-03 17:55:55 +0000 | [diff] [blame] | 1128 | |
| 1129 | regulator_bulk_disable(ARRAY_SIZE(wm8993->supplies), |
| 1130 | wm8993->supplies); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1131 | break; |
| 1132 | } |
| 1133 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1134 | codec->dapm.bias_level = level; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1135 | |
| 1136 | return 0; |
| 1137 | } |
| 1138 | |
| 1139 | static int wm8993_set_sysclk(struct snd_soc_dai *codec_dai, |
| 1140 | int clk_id, unsigned int freq, int dir) |
| 1141 | { |
| 1142 | struct snd_soc_codec *codec = codec_dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 1143 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1144 | |
| 1145 | switch (clk_id) { |
| 1146 | case WM8993_SYSCLK_MCLK: |
| 1147 | wm8993->mclk_rate = freq; |
| 1148 | case WM8993_SYSCLK_FLL: |
| 1149 | wm8993->sysclk_source = clk_id; |
| 1150 | break; |
| 1151 | |
| 1152 | default: |
| 1153 | return -EINVAL; |
| 1154 | } |
| 1155 | |
| 1156 | return 0; |
| 1157 | } |
| 1158 | |
| 1159 | static int wm8993_set_dai_fmt(struct snd_soc_dai *dai, |
| 1160 | unsigned int fmt) |
| 1161 | { |
| 1162 | struct snd_soc_codec *codec = dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 1163 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1164 | unsigned int aif1 = snd_soc_read(codec, WM8993_AUDIO_INTERFACE_1); |
| 1165 | unsigned int aif4 = snd_soc_read(codec, WM8993_AUDIO_INTERFACE_4); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1166 | |
| 1167 | aif1 &= ~(WM8993_BCLK_DIR | WM8993_AIF_BCLK_INV | |
| 1168 | WM8993_AIF_LRCLK_INV | WM8993_AIF_FMT_MASK); |
| 1169 | aif4 &= ~WM8993_LRCLK_DIR; |
| 1170 | |
| 1171 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1172 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1173 | wm8993->master = 0; |
| 1174 | break; |
| 1175 | case SND_SOC_DAIFMT_CBS_CFM: |
| 1176 | aif4 |= WM8993_LRCLK_DIR; |
| 1177 | wm8993->master = 1; |
| 1178 | break; |
| 1179 | case SND_SOC_DAIFMT_CBM_CFS: |
| 1180 | aif1 |= WM8993_BCLK_DIR; |
| 1181 | wm8993->master = 1; |
| 1182 | break; |
| 1183 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1184 | aif1 |= WM8993_BCLK_DIR; |
| 1185 | aif4 |= WM8993_LRCLK_DIR; |
| 1186 | wm8993->master = 1; |
| 1187 | break; |
| 1188 | default: |
| 1189 | return -EINVAL; |
| 1190 | } |
| 1191 | |
| 1192 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 1193 | case SND_SOC_DAIFMT_DSP_B: |
| 1194 | aif1 |= WM8993_AIF_LRCLK_INV; |
| 1195 | case SND_SOC_DAIFMT_DSP_A: |
| 1196 | aif1 |= 0x18; |
| 1197 | break; |
| 1198 | case SND_SOC_DAIFMT_I2S: |
| 1199 | aif1 |= 0x10; |
| 1200 | break; |
| 1201 | case SND_SOC_DAIFMT_RIGHT_J: |
| 1202 | break; |
| 1203 | case SND_SOC_DAIFMT_LEFT_J: |
| 1204 | aif1 |= 0x8; |
| 1205 | break; |
| 1206 | default: |
| 1207 | return -EINVAL; |
| 1208 | } |
| 1209 | |
| 1210 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 1211 | case SND_SOC_DAIFMT_DSP_A: |
| 1212 | case SND_SOC_DAIFMT_DSP_B: |
| 1213 | /* frame inversion not valid for DSP modes */ |
| 1214 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 1215 | case SND_SOC_DAIFMT_NB_NF: |
| 1216 | break; |
| 1217 | case SND_SOC_DAIFMT_IB_NF: |
| 1218 | aif1 |= WM8993_AIF_BCLK_INV; |
| 1219 | break; |
| 1220 | default: |
| 1221 | return -EINVAL; |
| 1222 | } |
| 1223 | break; |
| 1224 | |
| 1225 | case SND_SOC_DAIFMT_I2S: |
| 1226 | case SND_SOC_DAIFMT_RIGHT_J: |
| 1227 | case SND_SOC_DAIFMT_LEFT_J: |
| 1228 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 1229 | case SND_SOC_DAIFMT_NB_NF: |
| 1230 | break; |
| 1231 | case SND_SOC_DAIFMT_IB_IF: |
| 1232 | aif1 |= WM8993_AIF_BCLK_INV | WM8993_AIF_LRCLK_INV; |
| 1233 | break; |
| 1234 | case SND_SOC_DAIFMT_IB_NF: |
| 1235 | aif1 |= WM8993_AIF_BCLK_INV; |
| 1236 | break; |
| 1237 | case SND_SOC_DAIFMT_NB_IF: |
| 1238 | aif1 |= WM8993_AIF_LRCLK_INV; |
| 1239 | break; |
| 1240 | default: |
| 1241 | return -EINVAL; |
| 1242 | } |
| 1243 | break; |
| 1244 | default: |
| 1245 | return -EINVAL; |
| 1246 | } |
| 1247 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1248 | snd_soc_write(codec, WM8993_AUDIO_INTERFACE_1, aif1); |
| 1249 | snd_soc_write(codec, WM8993_AUDIO_INTERFACE_4, aif4); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1250 | |
| 1251 | return 0; |
| 1252 | } |
| 1253 | |
| 1254 | static int wm8993_hw_params(struct snd_pcm_substream *substream, |
| 1255 | struct snd_pcm_hw_params *params, |
| 1256 | struct snd_soc_dai *dai) |
| 1257 | { |
| 1258 | struct snd_soc_codec *codec = dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 1259 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1260 | int ret, i, best, best_val, cur_val; |
| 1261 | unsigned int clocking1, clocking3, aif1, aif4; |
| 1262 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1263 | clocking1 = snd_soc_read(codec, WM8993_CLOCKING_1); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1264 | clocking1 &= ~WM8993_BCLK_DIV_MASK; |
| 1265 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1266 | clocking3 = snd_soc_read(codec, WM8993_CLOCKING_3); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1267 | clocking3 &= ~(WM8993_CLK_SYS_RATE_MASK | WM8993_SAMPLE_RATE_MASK); |
| 1268 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1269 | aif1 = snd_soc_read(codec, WM8993_AUDIO_INTERFACE_1); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1270 | aif1 &= ~WM8993_AIF_WL_MASK; |
| 1271 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1272 | aif4 = snd_soc_read(codec, WM8993_AUDIO_INTERFACE_4); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1273 | aif4 &= ~WM8993_LRCLK_RATE_MASK; |
| 1274 | |
| 1275 | /* What BCLK do we need? */ |
| 1276 | wm8993->fs = params_rate(params); |
| 1277 | wm8993->bclk = 2 * wm8993->fs; |
Mark Brown | d3c9e9a | 2009-08-17 18:52:47 +0100 | [diff] [blame] | 1278 | if (wm8993->tdm_slots) { |
| 1279 | dev_dbg(codec->dev, "Configuring for %d %d bit TDM slots\n", |
| 1280 | wm8993->tdm_slots, wm8993->tdm_width); |
| 1281 | wm8993->bclk *= wm8993->tdm_width * wm8993->tdm_slots; |
| 1282 | } else { |
| 1283 | switch (params_format(params)) { |
| 1284 | case SNDRV_PCM_FORMAT_S16_LE: |
| 1285 | wm8993->bclk *= 16; |
| 1286 | break; |
| 1287 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 1288 | wm8993->bclk *= 20; |
| 1289 | aif1 |= 0x8; |
| 1290 | break; |
| 1291 | case SNDRV_PCM_FORMAT_S24_LE: |
| 1292 | wm8993->bclk *= 24; |
| 1293 | aif1 |= 0x10; |
| 1294 | break; |
| 1295 | case SNDRV_PCM_FORMAT_S32_LE: |
| 1296 | wm8993->bclk *= 32; |
| 1297 | aif1 |= 0x18; |
| 1298 | break; |
| 1299 | default: |
| 1300 | return -EINVAL; |
| 1301 | } |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | dev_dbg(codec->dev, "Target BCLK is %dHz\n", wm8993->bclk); |
| 1305 | |
| 1306 | ret = configure_clock(codec); |
| 1307 | if (ret != 0) |
| 1308 | return ret; |
| 1309 | |
| 1310 | /* Select nearest CLK_SYS_RATE */ |
| 1311 | best = 0; |
| 1312 | best_val = abs((wm8993->sysclk_rate / clk_sys_rates[0].ratio) |
| 1313 | - wm8993->fs); |
| 1314 | for (i = 1; i < ARRAY_SIZE(clk_sys_rates); i++) { |
| 1315 | cur_val = abs((wm8993->sysclk_rate / |
Joe Perches | ef995e3 | 2010-11-15 09:09:17 -0800 | [diff] [blame] | 1316 | clk_sys_rates[i].ratio) - wm8993->fs); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1317 | if (cur_val < best_val) { |
| 1318 | best = i; |
| 1319 | best_val = cur_val; |
| 1320 | } |
| 1321 | } |
| 1322 | dev_dbg(codec->dev, "Selected CLK_SYS_RATIO of %d\n", |
| 1323 | clk_sys_rates[best].ratio); |
| 1324 | clocking3 |= (clk_sys_rates[best].clk_sys_rate |
| 1325 | << WM8993_CLK_SYS_RATE_SHIFT); |
| 1326 | |
| 1327 | /* SAMPLE_RATE */ |
| 1328 | best = 0; |
| 1329 | best_val = abs(wm8993->fs - sample_rates[0].rate); |
| 1330 | for (i = 1; i < ARRAY_SIZE(sample_rates); i++) { |
| 1331 | /* Closest match */ |
| 1332 | cur_val = abs(wm8993->fs - sample_rates[i].rate); |
| 1333 | if (cur_val < best_val) { |
| 1334 | best = i; |
| 1335 | best_val = cur_val; |
| 1336 | } |
| 1337 | } |
| 1338 | dev_dbg(codec->dev, "Selected SAMPLE_RATE of %dHz\n", |
| 1339 | sample_rates[best].rate); |
Mark Brown | e465d54 | 2009-07-15 10:01:30 +0100 | [diff] [blame] | 1340 | clocking3 |= (sample_rates[best].sample_rate |
| 1341 | << WM8993_SAMPLE_RATE_SHIFT); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1342 | |
| 1343 | /* BCLK_DIV */ |
| 1344 | best = 0; |
| 1345 | best_val = INT_MAX; |
| 1346 | for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) { |
| 1347 | cur_val = ((wm8993->sysclk_rate * 10) / bclk_divs[i].div) |
| 1348 | - wm8993->bclk; |
| 1349 | if (cur_val < 0) /* Table is sorted */ |
| 1350 | break; |
| 1351 | if (cur_val < best_val) { |
| 1352 | best = i; |
| 1353 | best_val = cur_val; |
| 1354 | } |
| 1355 | } |
| 1356 | wm8993->bclk = (wm8993->sysclk_rate * 10) / bclk_divs[best].div; |
| 1357 | dev_dbg(codec->dev, "Selected BCLK_DIV of %d for %dHz BCLK\n", |
| 1358 | bclk_divs[best].div, wm8993->bclk); |
| 1359 | clocking1 |= bclk_divs[best].bclk_div << WM8993_BCLK_DIV_SHIFT; |
| 1360 | |
| 1361 | /* LRCLK is a simple fraction of BCLK */ |
| 1362 | dev_dbg(codec->dev, "LRCLK_RATE is %d\n", wm8993->bclk / wm8993->fs); |
| 1363 | aif4 |= wm8993->bclk / wm8993->fs; |
| 1364 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1365 | snd_soc_write(codec, WM8993_CLOCKING_1, clocking1); |
| 1366 | snd_soc_write(codec, WM8993_CLOCKING_3, clocking3); |
| 1367 | snd_soc_write(codec, WM8993_AUDIO_INTERFACE_1, aif1); |
| 1368 | snd_soc_write(codec, WM8993_AUDIO_INTERFACE_4, aif4); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1369 | |
| 1370 | /* ReTune Mobile? */ |
| 1371 | if (wm8993->pdata.num_retune_configs) { |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1372 | u16 eq1 = snd_soc_read(codec, WM8993_EQ1); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1373 | struct wm8993_retune_mobile_setting *s; |
| 1374 | |
| 1375 | best = 0; |
| 1376 | best_val = abs(wm8993->pdata.retune_configs[0].rate |
| 1377 | - wm8993->fs); |
| 1378 | for (i = 0; i < wm8993->pdata.num_retune_configs; i++) { |
| 1379 | cur_val = abs(wm8993->pdata.retune_configs[i].rate |
| 1380 | - wm8993->fs); |
| 1381 | if (cur_val < best_val) { |
| 1382 | best_val = cur_val; |
| 1383 | best = i; |
| 1384 | } |
| 1385 | } |
| 1386 | s = &wm8993->pdata.retune_configs[best]; |
| 1387 | |
| 1388 | dev_dbg(codec->dev, "ReTune Mobile %s tuned for %dHz\n", |
| 1389 | s->name, s->rate); |
| 1390 | |
| 1391 | /* Disable EQ while we reconfigure */ |
| 1392 | snd_soc_update_bits(codec, WM8993_EQ1, WM8993_EQ_ENA, 0); |
| 1393 | |
| 1394 | for (i = 1; i < ARRAY_SIZE(s->config); i++) |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1395 | snd_soc_write(codec, WM8993_EQ1 + i, s->config[i]); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1396 | |
| 1397 | snd_soc_update_bits(codec, WM8993_EQ1, WM8993_EQ_ENA, eq1); |
| 1398 | } |
| 1399 | |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
| 1403 | static int wm8993_digital_mute(struct snd_soc_dai *codec_dai, int mute) |
| 1404 | { |
| 1405 | struct snd_soc_codec *codec = codec_dai->codec; |
| 1406 | unsigned int reg; |
| 1407 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1408 | reg = snd_soc_read(codec, WM8993_DAC_CTRL); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1409 | |
| 1410 | if (mute) |
| 1411 | reg |= WM8993_DAC_MUTE; |
| 1412 | else |
| 1413 | reg &= ~WM8993_DAC_MUTE; |
| 1414 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1415 | snd_soc_write(codec, WM8993_DAC_CTRL, reg); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1416 | |
| 1417 | return 0; |
| 1418 | } |
| 1419 | |
Mark Brown | d3c9e9a | 2009-08-17 18:52:47 +0100 | [diff] [blame] | 1420 | static int wm8993_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, |
| 1421 | unsigned int rx_mask, int slots, int slot_width) |
| 1422 | { |
| 1423 | struct snd_soc_codec *codec = dai->codec; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 1424 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | d3c9e9a | 2009-08-17 18:52:47 +0100 | [diff] [blame] | 1425 | int aif1 = 0; |
| 1426 | int aif2 = 0; |
| 1427 | |
| 1428 | /* Don't need to validate anything if we're turning off TDM */ |
| 1429 | if (slots == 0) { |
| 1430 | wm8993->tdm_slots = 0; |
| 1431 | goto out; |
| 1432 | } |
| 1433 | |
| 1434 | /* Note that we allow configurations we can't handle ourselves - |
| 1435 | * for example, we can generate clocks for slots 2 and up even if |
| 1436 | * we can't use those slots ourselves. |
| 1437 | */ |
| 1438 | aif1 |= WM8993_AIFADC_TDM; |
| 1439 | aif2 |= WM8993_AIFDAC_TDM; |
| 1440 | |
| 1441 | switch (rx_mask) { |
| 1442 | case 3: |
| 1443 | break; |
| 1444 | case 0xc: |
| 1445 | aif1 |= WM8993_AIFADC_TDM_CHAN; |
| 1446 | break; |
| 1447 | default: |
| 1448 | return -EINVAL; |
| 1449 | } |
| 1450 | |
| 1451 | |
| 1452 | switch (tx_mask) { |
| 1453 | case 3: |
| 1454 | break; |
| 1455 | case 0xc: |
| 1456 | aif2 |= WM8993_AIFDAC_TDM_CHAN; |
| 1457 | break; |
| 1458 | default: |
| 1459 | return -EINVAL; |
| 1460 | } |
| 1461 | |
| 1462 | out: |
| 1463 | wm8993->tdm_width = slot_width; |
| 1464 | wm8993->tdm_slots = slots / 2; |
| 1465 | |
| 1466 | snd_soc_update_bits(codec, WM8993_AUDIO_INTERFACE_1, |
| 1467 | WM8993_AIFADC_TDM | WM8993_AIFADC_TDM_CHAN, aif1); |
| 1468 | snd_soc_update_bits(codec, WM8993_AUDIO_INTERFACE_2, |
| 1469 | WM8993_AIFDAC_TDM | WM8993_AIFDAC_TDM_CHAN, aif2); |
| 1470 | |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1474 | static const struct snd_soc_dai_ops wm8993_ops = { |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1475 | .set_sysclk = wm8993_set_sysclk, |
| 1476 | .set_fmt = wm8993_set_dai_fmt, |
| 1477 | .hw_params = wm8993_hw_params, |
| 1478 | .digital_mute = wm8993_digital_mute, |
| 1479 | .set_pll = wm8993_set_fll, |
Mark Brown | d3c9e9a | 2009-08-17 18:52:47 +0100 | [diff] [blame] | 1480 | .set_tdm_slot = wm8993_set_tdm_slot, |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1481 | }; |
| 1482 | |
| 1483 | #define WM8993_RATES SNDRV_PCM_RATE_8000_48000 |
| 1484 | |
| 1485 | #define WM8993_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\ |
| 1486 | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 1487 | SNDRV_PCM_FMTBIT_S24_LE |\ |
| 1488 | SNDRV_PCM_FMTBIT_S32_LE) |
| 1489 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1490 | static struct snd_soc_dai_driver wm8993_dai = { |
| 1491 | .name = "wm8993-hifi", |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1492 | .playback = { |
| 1493 | .stream_name = "Playback", |
| 1494 | .channels_min = 1, |
| 1495 | .channels_max = 2, |
| 1496 | .rates = WM8993_RATES, |
| 1497 | .formats = WM8993_FORMATS, |
| 1498 | }, |
| 1499 | .capture = { |
| 1500 | .stream_name = "Capture", |
| 1501 | .channels_min = 1, |
| 1502 | .channels_max = 2, |
| 1503 | .rates = WM8993_RATES, |
| 1504 | .formats = WM8993_FORMATS, |
| 1505 | }, |
| 1506 | .ops = &wm8993_ops, |
| 1507 | .symmetric_rates = 1, |
| 1508 | }; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1509 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1510 | static int wm8993_probe(struct snd_soc_codec *codec) |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1511 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 1512 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1513 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1514 | int ret, i, val; |
Mark Brown | 53242c6 | 2010-01-02 13:15:56 +0000 | [diff] [blame] | 1515 | |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 1516 | wm8993->hubs_data.hp_startup_mode = 1; |
Mark Brown | 4537c4e | 2011-08-01 13:10:16 +0900 | [diff] [blame] | 1517 | wm8993->hubs_data.dcs_codes_l = -2; |
| 1518 | wm8993->hubs_data.dcs_codes_r = -2; |
Mark Brown | f9acf9f | 2011-06-07 23:23:52 +0100 | [diff] [blame] | 1519 | wm8993->hubs_data.series_startup = 1; |
Mark Brown | 3ed7074 | 2010-01-20 17:39:45 +0000 | [diff] [blame] | 1520 | |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 1521 | codec->control_data = wm8993->regmap; |
| 1522 | ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_REGMAP); |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1523 | if (ret != 0) { |
| 1524 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1525 | return ret; |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
Mark Brown | b37e399 | 2010-02-03 11:51:42 +0000 | [diff] [blame] | 1528 | for (i = 0; i < ARRAY_SIZE(wm8993->supplies); i++) |
| 1529 | wm8993->supplies[i].supply = wm8993_supply_names[i]; |
| 1530 | |
| 1531 | ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8993->supplies), |
| 1532 | wm8993->supplies); |
| 1533 | if (ret != 0) { |
| 1534 | dev_err(codec->dev, "Failed to request supplies: %d\n", ret); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1535 | return ret; |
Mark Brown | b37e399 | 2010-02-03 11:51:42 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | ret = regulator_bulk_enable(ARRAY_SIZE(wm8993->supplies), |
| 1539 | wm8993->supplies); |
| 1540 | if (ret != 0) { |
| 1541 | dev_err(codec->dev, "Failed to enable supplies: %d\n", ret); |
| 1542 | goto err_get; |
| 1543 | } |
| 1544 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1545 | val = snd_soc_read(codec, WM8993_SOFTWARE_RESET); |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 1546 | if (val != 0x8993) { |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1547 | dev_err(codec->dev, "Invalid ID register value %x\n", val); |
| 1548 | ret = -EINVAL; |
Mark Brown | b37e399 | 2010-02-03 11:51:42 +0000 | [diff] [blame] | 1549 | goto err_enable; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1550 | } |
| 1551 | |
Mark Brown | 3bf6e42 | 2010-02-01 19:05:09 +0000 | [diff] [blame] | 1552 | ret = snd_soc_write(codec, WM8993_SOFTWARE_RESET, 0xffff); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1553 | if (ret != 0) |
Mark Brown | b37e399 | 2010-02-03 11:51:42 +0000 | [diff] [blame] | 1554 | goto err_enable; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1555 | |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 1556 | regcache_cache_only(wm8993->regmap, true); |
Mark Brown | cf56f62 | 2010-02-03 17:55:55 +0000 | [diff] [blame] | 1557 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1558 | /* By default we're using the output mixers */ |
| 1559 | wm8993->class_w_users = 2; |
| 1560 | |
| 1561 | /* Latch volume update bits and default ZC on */ |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1562 | snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME, |
| 1563 | WM8993_DAC_VU, WM8993_DAC_VU); |
| 1564 | snd_soc_update_bits(codec, WM8993_RIGHT_ADC_DIGITAL_VOLUME, |
| 1565 | WM8993_ADC_VU, WM8993_ADC_VU); |
| 1566 | |
| 1567 | /* Manualy manage the HPOUT sequencing for independent stereo |
| 1568 | * control. */ |
| 1569 | snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0, |
| 1570 | WM8993_HPOUT1_AUTO_PU, 0); |
| 1571 | |
| 1572 | /* Use automatic clock configuration */ |
| 1573 | snd_soc_update_bits(codec, WM8993_CLOCKING_4, WM8993_SR_MODE, 0); |
| 1574 | |
Mark Brown | aa983d9 | 2009-09-30 14:16:11 +0100 | [diff] [blame] | 1575 | wm_hubs_handle_analogue_pdata(codec, wm8993->pdata.lineout1_diff, |
| 1576 | wm8993->pdata.lineout2_diff, |
| 1577 | wm8993->pdata.lineout1fb, |
| 1578 | wm8993->pdata.lineout2fb, |
| 1579 | wm8993->pdata.jd_scthr, |
| 1580 | wm8993->pdata.jd_thr, |
| 1581 | wm8993->pdata.micbias1_lvl, |
| 1582 | wm8993->pdata.micbias2_lvl); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1583 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1584 | ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 1585 | if (ret != 0) |
Mark Brown | b37e399 | 2010-02-03 11:51:42 +0000 | [diff] [blame] | 1586 | goto err_enable; |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1587 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1588 | snd_soc_add_controls(codec, wm8993_snd_controls, |
| 1589 | ARRAY_SIZE(wm8993_snd_controls)); |
| 1590 | if (wm8993->pdata.num_retune_configs != 0) { |
| 1591 | dev_dbg(codec->dev, "Using ReTune Mobile\n"); |
| 1592 | } else { |
| 1593 | dev_dbg(codec->dev, "No ReTune Mobile, using normal EQ\n"); |
| 1594 | snd_soc_add_controls(codec, wm8993_eq_controls, |
| 1595 | ARRAY_SIZE(wm8993_eq_controls)); |
| 1596 | } |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1597 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1598 | snd_soc_dapm_new_controls(dapm, wm8993_dapm_widgets, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1599 | ARRAY_SIZE(wm8993_dapm_widgets)); |
| 1600 | wm_hubs_add_analogue_controls(codec); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1601 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1602 | snd_soc_dapm_add_routes(dapm, routes, ARRAY_SIZE(routes)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1603 | wm_hubs_add_analogue_routes(codec, wm8993->pdata.lineout1_diff, |
| 1604 | wm8993->pdata.lineout2_diff); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1605 | |
| 1606 | return 0; |
| 1607 | |
Mark Brown | b37e399 | 2010-02-03 11:51:42 +0000 | [diff] [blame] | 1608 | err_enable: |
| 1609 | regulator_bulk_disable(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); |
| 1610 | err_get: |
| 1611 | regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1612 | return ret; |
| 1613 | } |
| 1614 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1615 | static int wm8993_remove(struct snd_soc_codec *codec) |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1616 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1617 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1618 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1619 | wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF); |
Mark Brown | b37e399 | 2010-02-03 11:51:42 +0000 | [diff] [blame] | 1620 | regulator_bulk_free(ARRAY_SIZE(wm8993->supplies), wm8993->supplies); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1621 | return 0; |
| 1622 | } |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1623 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1624 | #ifdef CONFIG_PM |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 1625 | static int wm8993_suspend(struct snd_soc_codec *codec) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1626 | { |
| 1627 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
| 1628 | int fll_fout = wm8993->fll_fout; |
| 1629 | int fll_fref = wm8993->fll_fref; |
| 1630 | int ret; |
| 1631 | |
| 1632 | /* Stop the FLL in an orderly fashion */ |
| 1633 | ret = _wm8993_set_fll(codec, 0, 0, 0, 0); |
| 1634 | if (ret != 0) { |
| 1635 | dev_err(codec->dev, "Failed to stop FLL\n"); |
| 1636 | return ret; |
| 1637 | } |
| 1638 | |
| 1639 | wm8993->fll_fout = fll_fout; |
| 1640 | wm8993->fll_fref = fll_fref; |
| 1641 | |
| 1642 | wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 1643 | |
| 1644 | return 0; |
| 1645 | } |
| 1646 | |
| 1647 | static int wm8993_resume(struct snd_soc_codec *codec) |
| 1648 | { |
| 1649 | struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec); |
| 1650 | int ret; |
| 1651 | |
| 1652 | wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 1653 | |
| 1654 | /* Restart the FLL? */ |
| 1655 | if (wm8993->fll_fout) { |
| 1656 | int fll_fout = wm8993->fll_fout; |
| 1657 | int fll_fref = wm8993->fll_fref; |
| 1658 | |
| 1659 | wm8993->fll_fref = 0; |
| 1660 | wm8993->fll_fout = 0; |
| 1661 | |
| 1662 | ret = _wm8993_set_fll(codec, 0, wm8993->fll_src, |
| 1663 | fll_fref, fll_fout); |
| 1664 | if (ret != 0) |
| 1665 | dev_err(codec->dev, "Failed to restart FLL\n"); |
| 1666 | } |
| 1667 | |
| 1668 | return 0; |
| 1669 | } |
| 1670 | #else |
| 1671 | #define wm8993_suspend NULL |
| 1672 | #define wm8993_resume NULL |
| 1673 | #endif |
| 1674 | |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 1675 | static const struct regmap_config wm8993_regmap = { |
| 1676 | .reg_bits = 8, |
| 1677 | .val_bits = 16, |
| 1678 | |
| 1679 | .max_register = WM8993_MAX_REGISTER, |
| 1680 | .volatile_reg = wm8993_volatile, |
| 1681 | .readable_reg = wm8993_readable, |
| 1682 | |
| 1683 | .cache_type = REGCACHE_RBTREE, |
| 1684 | .reg_defaults = wm8993_reg_defaults, |
| 1685 | .num_reg_defaults = ARRAY_SIZE(wm8993_reg_defaults), |
| 1686 | }; |
| 1687 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1688 | static struct snd_soc_codec_driver soc_codec_dev_wm8993 = { |
| 1689 | .probe = wm8993_probe, |
| 1690 | .remove = wm8993_remove, |
| 1691 | .suspend = wm8993_suspend, |
| 1692 | .resume = wm8993_resume, |
| 1693 | .set_bias_level = wm8993_set_bias_level, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1694 | }; |
| 1695 | |
| 1696 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
| 1697 | static __devinit int wm8993_i2c_probe(struct i2c_client *i2c, |
| 1698 | const struct i2c_device_id *id) |
| 1699 | { |
| 1700 | struct wm8993_priv *wm8993; |
| 1701 | int ret; |
| 1702 | |
Mark Brown | ec641c4 | 2011-12-15 11:54:00 +0800 | [diff] [blame] | 1703 | wm8993 = devm_kzalloc(&i2c->dev, sizeof(struct wm8993_priv), |
Mark Brown | f6a9336 | 2011-12-14 11:11:52 +0800 | [diff] [blame] | 1704 | GFP_KERNEL); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1705 | if (wm8993 == NULL) |
| 1706 | return -ENOMEM; |
| 1707 | |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 1708 | wm8993->regmap = regmap_init_i2c(i2c, &wm8993_regmap); |
| 1709 | if (IS_ERR(wm8993->regmap)) { |
| 1710 | ret = PTR_ERR(wm8993->regmap); |
| 1711 | dev_err(&i2c->dev, "Failed to allocate regmap: %d\n", ret); |
| 1712 | return ret; |
| 1713 | } |
| 1714 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1715 | i2c_set_clientdata(i2c, wm8993); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1716 | |
| 1717 | ret = snd_soc_register_codec(&i2c->dev, |
| 1718 | &soc_codec_dev_wm8993, &wm8993_dai, 1); |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 1719 | if (ret != 0) { |
| 1720 | dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret); |
| 1721 | goto err; |
| 1722 | } |
| 1723 | |
| 1724 | return ret; |
| 1725 | |
| 1726 | err: |
| 1727 | regmap_exit(wm8993->regmap); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1728 | return ret; |
| 1729 | } |
| 1730 | |
| 1731 | static __devexit int wm8993_i2c_remove(struct i2c_client *client) |
| 1732 | { |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 1733 | struct wm8993_priv *wm8993 = i2c_get_clientdata(client); |
| 1734 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1735 | snd_soc_unregister_codec(&client->dev); |
Mark Brown | d0ad0af | 2011-12-14 11:53:06 +0800 | [diff] [blame^] | 1736 | regmap_exit(wm8993->regmap); |
| 1737 | |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1738 | return 0; |
| 1739 | } |
| 1740 | |
| 1741 | static const struct i2c_device_id wm8993_i2c_id[] = { |
| 1742 | { "wm8993", 0 }, |
| 1743 | { } |
| 1744 | }; |
| 1745 | MODULE_DEVICE_TABLE(i2c, wm8993_i2c_id); |
| 1746 | |
| 1747 | static struct i2c_driver wm8993_i2c_driver = { |
| 1748 | .driver = { |
Mark Brown | 091edcc | 2011-12-02 22:08:49 +0000 | [diff] [blame] | 1749 | .name = "wm8993", |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1750 | .owner = THIS_MODULE, |
| 1751 | }, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1752 | .probe = wm8993_i2c_probe, |
| 1753 | .remove = __devexit_p(wm8993_i2c_remove), |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1754 | .id_table = wm8993_i2c_id, |
| 1755 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1756 | #endif |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1757 | |
| 1758 | static int __init wm8993_modinit(void) |
| 1759 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1760 | int ret = 0; |
| 1761 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1762 | ret = i2c_add_driver(&wm8993_i2c_driver); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1763 | if (ret != 0) { |
| 1764 | pr_err("WM8993: Unable to register I2C driver: %d\n", |
| 1765 | ret); |
| 1766 | } |
| 1767 | #endif |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1768 | return ret; |
| 1769 | } |
| 1770 | module_init(wm8993_modinit); |
| 1771 | |
| 1772 | static void __exit wm8993_exit(void) |
| 1773 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1774 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1775 | i2c_del_driver(&wm8993_i2c_driver); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1776 | #endif |
Mark Brown | 942c435 | 2009-06-05 16:32:59 +0100 | [diff] [blame] | 1777 | } |
| 1778 | module_exit(wm8993_exit); |
| 1779 | |
| 1780 | |
| 1781 | MODULE_DESCRIPTION("ASoC WM8993 driver"); |
| 1782 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 1783 | MODULE_LICENSE("GPL"); |