Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ALSA SoC TWL6040 codec driver |
| 3 | * |
| 4 | * Author: Misael Lopez Cruz <x0052729@ti.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * version 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 18 | * 02110-1301 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/moduleparam.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/pm.h> |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 27 | #include <linux/platform_device.h> |
Stephen Rothwell | 68b40cc | 2010-03-29 17:55:51 +1100 | [diff] [blame] | 28 | #include <linux/slab.h> |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 29 | #include <linux/i2c/twl.h> |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 30 | #include <linux/mfd/twl6040.h> |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 31 | |
| 32 | #include <sound/core.h> |
| 33 | #include <sound/pcm.h> |
| 34 | #include <sound/pcm_params.h> |
| 35 | #include <sound/soc.h> |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 36 | #include <sound/initval.h> |
| 37 | #include <sound/tlv.h> |
| 38 | |
| 39 | #include "twl6040.h" |
| 40 | |
Olaya, Margarita | 60ea4ce | 2010-12-10 21:05:58 -0600 | [diff] [blame] | 41 | #define TWL6040_RATES SNDRV_PCM_RATE_8000_96000 |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 42 | #define TWL6040_FORMATS (SNDRV_PCM_FMTBIT_S32_LE) |
| 43 | |
| 44 | #define TWL6040_OUTHS_0dB 0x00 |
| 45 | #define TWL6040_OUTHS_M30dB 0x0F |
| 46 | #define TWL6040_OUTHF_0dB 0x03 |
| 47 | #define TWL6040_OUTHF_M52dB 0x1D |
| 48 | |
| 49 | #define TWL6040_RAMP_NONE 0 |
| 50 | #define TWL6040_RAMP_UP 1 |
| 51 | #define TWL6040_RAMP_DOWN 2 |
| 52 | |
| 53 | #define TWL6040_HSL_VOL_MASK 0x0F |
| 54 | #define TWL6040_HSL_VOL_SHIFT 0 |
| 55 | #define TWL6040_HSR_VOL_MASK 0xF0 |
| 56 | #define TWL6040_HSR_VOL_SHIFT 4 |
| 57 | #define TWL6040_HF_VOL_MASK 0x1F |
| 58 | #define TWL6040_HF_VOL_SHIFT 0 |
| 59 | |
| 60 | struct twl6040_output { |
| 61 | u16 active; |
| 62 | u16 left_vol; |
| 63 | u16 right_vol; |
| 64 | u16 left_step; |
| 65 | u16 right_step; |
| 66 | unsigned int step_delay; |
| 67 | u16 ramp; |
| 68 | u16 mute; |
| 69 | struct completion ramp_done; |
| 70 | }; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 71 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 72 | struct twl6040_jack_data { |
| 73 | struct snd_soc_jack *jack; |
| 74 | int report; |
| 75 | }; |
| 76 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 77 | /* codec private data */ |
| 78 | struct twl6040_data { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 79 | int codec_powered; |
| 80 | int pll; |
| 81 | int non_lp; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 82 | unsigned int clk_in; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 83 | unsigned int sysclk; |
| 84 | struct snd_pcm_hw_constraint_list *sysclk_constraints; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 85 | struct twl6040_jack_data hs_jack; |
| 86 | struct snd_soc_codec *codec; |
| 87 | struct workqueue_struct *workqueue; |
| 88 | struct delayed_work delayed_work; |
| 89 | struct mutex mutex; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 90 | struct twl6040_output headset; |
| 91 | struct twl6040_output handsfree; |
| 92 | struct workqueue_struct *hf_workqueue; |
| 93 | struct workqueue_struct *hs_workqueue; |
| 94 | struct delayed_work hs_delayed_work; |
| 95 | struct delayed_work hf_delayed_work; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | /* |
| 99 | * twl6040 register cache & default register settings |
| 100 | */ |
| 101 | static const u8 twl6040_reg[TWL6040_CACHEREGNUM] = { |
| 102 | 0x00, /* not used 0x00 */ |
| 103 | 0x4B, /* TWL6040_ASICID (ro) 0x01 */ |
| 104 | 0x00, /* TWL6040_ASICREV (ro) 0x02 */ |
| 105 | 0x00, /* TWL6040_INTID 0x03 */ |
| 106 | 0x00, /* TWL6040_INTMR 0x04 */ |
| 107 | 0x00, /* TWL6040_NCPCTRL 0x05 */ |
| 108 | 0x00, /* TWL6040_LDOCTL 0x06 */ |
| 109 | 0x60, /* TWL6040_HPPLLCTL 0x07 */ |
| 110 | 0x00, /* TWL6040_LPPLLCTL 0x08 */ |
| 111 | 0x4A, /* TWL6040_LPPLLDIV 0x09 */ |
| 112 | 0x00, /* TWL6040_AMICBCTL 0x0A */ |
| 113 | 0x00, /* TWL6040_DMICBCTL 0x0B */ |
| 114 | 0x18, /* TWL6040_MICLCTL 0x0C - No input selected on Left Mic */ |
| 115 | 0x18, /* TWL6040_MICRCTL 0x0D - No input selected on Right Mic */ |
| 116 | 0x00, /* TWL6040_MICGAIN 0x0E */ |
| 117 | 0x1B, /* TWL6040_LINEGAIN 0x0F */ |
| 118 | 0x00, /* TWL6040_HSLCTL 0x10 */ |
| 119 | 0x00, /* TWL6040_HSRCTL 0x11 */ |
| 120 | 0x00, /* TWL6040_HSGAIN 0x12 */ |
| 121 | 0x00, /* TWL6040_EARCTL 0x13 */ |
| 122 | 0x00, /* TWL6040_HFLCTL 0x14 */ |
| 123 | 0x00, /* TWL6040_HFLGAIN 0x15 */ |
| 124 | 0x00, /* TWL6040_HFRCTL 0x16 */ |
| 125 | 0x00, /* TWL6040_HFRGAIN 0x17 */ |
| 126 | 0x00, /* TWL6040_VIBCTLL 0x18 */ |
| 127 | 0x00, /* TWL6040_VIBDATL 0x19 */ |
| 128 | 0x00, /* TWL6040_VIBCTLR 0x1A */ |
| 129 | 0x00, /* TWL6040_VIBDATR 0x1B */ |
| 130 | 0x00, /* TWL6040_HKCTL1 0x1C */ |
| 131 | 0x00, /* TWL6040_HKCTL2 0x1D */ |
| 132 | 0x00, /* TWL6040_GPOCTL 0x1E */ |
| 133 | 0x00, /* TWL6040_ALB 0x1F */ |
| 134 | 0x00, /* TWL6040_DLB 0x20 */ |
| 135 | 0x00, /* not used 0x21 */ |
| 136 | 0x00, /* not used 0x22 */ |
| 137 | 0x00, /* not used 0x23 */ |
| 138 | 0x00, /* not used 0x24 */ |
| 139 | 0x00, /* not used 0x25 */ |
| 140 | 0x00, /* not used 0x26 */ |
| 141 | 0x00, /* not used 0x27 */ |
| 142 | 0x00, /* TWL6040_TRIM1 0x28 */ |
| 143 | 0x00, /* TWL6040_TRIM2 0x29 */ |
| 144 | 0x00, /* TWL6040_TRIM3 0x2A */ |
| 145 | 0x00, /* TWL6040_HSOTRIM 0x2B */ |
| 146 | 0x00, /* TWL6040_HFOTRIM 0x2C */ |
| 147 | 0x09, /* TWL6040_ACCCTL 0x2D */ |
| 148 | 0x00, /* TWL6040_STATUS (ro) 0x2E */ |
| 149 | }; |
| 150 | |
| 151 | /* |
| 152 | * twl6040 vio/gnd registers: |
| 153 | * registers under vio/gnd supply can be accessed |
| 154 | * before the power-up sequence, after NRESPWRON goes high |
| 155 | */ |
| 156 | static const int twl6040_vio_reg[TWL6040_VIOREGNUM] = { |
| 157 | TWL6040_REG_ASICID, |
| 158 | TWL6040_REG_ASICREV, |
| 159 | TWL6040_REG_INTID, |
| 160 | TWL6040_REG_INTMR, |
| 161 | TWL6040_REG_NCPCTL, |
| 162 | TWL6040_REG_LDOCTL, |
| 163 | TWL6040_REG_AMICBCTL, |
| 164 | TWL6040_REG_DMICBCTL, |
| 165 | TWL6040_REG_HKCTL1, |
| 166 | TWL6040_REG_HKCTL2, |
| 167 | TWL6040_REG_GPOCTL, |
| 168 | TWL6040_REG_TRIM1, |
| 169 | TWL6040_REG_TRIM2, |
| 170 | TWL6040_REG_TRIM3, |
| 171 | TWL6040_REG_HSOTRIM, |
| 172 | TWL6040_REG_HFOTRIM, |
| 173 | TWL6040_REG_ACCCTL, |
| 174 | TWL6040_REG_STATUS, |
| 175 | }; |
| 176 | |
| 177 | /* |
| 178 | * twl6040 vdd/vss registers: |
| 179 | * registers under vdd/vss supplies can only be accessed |
| 180 | * after the power-up sequence |
| 181 | */ |
| 182 | static const int twl6040_vdd_reg[TWL6040_VDDREGNUM] = { |
| 183 | TWL6040_REG_HPPLLCTL, |
| 184 | TWL6040_REG_LPPLLCTL, |
| 185 | TWL6040_REG_LPPLLDIV, |
| 186 | TWL6040_REG_MICLCTL, |
| 187 | TWL6040_REG_MICRCTL, |
| 188 | TWL6040_REG_MICGAIN, |
| 189 | TWL6040_REG_LINEGAIN, |
| 190 | TWL6040_REG_HSLCTL, |
| 191 | TWL6040_REG_HSRCTL, |
| 192 | TWL6040_REG_HSGAIN, |
| 193 | TWL6040_REG_EARCTL, |
| 194 | TWL6040_REG_HFLCTL, |
| 195 | TWL6040_REG_HFLGAIN, |
| 196 | TWL6040_REG_HFRCTL, |
| 197 | TWL6040_REG_HFRGAIN, |
| 198 | TWL6040_REG_VIBCTLL, |
| 199 | TWL6040_REG_VIBDATL, |
| 200 | TWL6040_REG_VIBCTLR, |
| 201 | TWL6040_REG_VIBDATR, |
| 202 | TWL6040_REG_ALB, |
| 203 | TWL6040_REG_DLB, |
| 204 | }; |
| 205 | |
| 206 | /* |
| 207 | * read twl6040 register cache |
| 208 | */ |
| 209 | static inline unsigned int twl6040_read_reg_cache(struct snd_soc_codec *codec, |
| 210 | unsigned int reg) |
| 211 | { |
| 212 | u8 *cache = codec->reg_cache; |
| 213 | |
| 214 | if (reg >= TWL6040_CACHEREGNUM) |
| 215 | return -EIO; |
| 216 | |
| 217 | return cache[reg]; |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * write twl6040 register cache |
| 222 | */ |
| 223 | static inline void twl6040_write_reg_cache(struct snd_soc_codec *codec, |
| 224 | u8 reg, u8 value) |
| 225 | { |
| 226 | u8 *cache = codec->reg_cache; |
| 227 | |
| 228 | if (reg >= TWL6040_CACHEREGNUM) |
| 229 | return; |
| 230 | cache[reg] = value; |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | * read from twl6040 hardware register |
| 235 | */ |
| 236 | static int twl6040_read_reg_volatile(struct snd_soc_codec *codec, |
| 237 | unsigned int reg) |
| 238 | { |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 239 | struct twl6040 *twl6040 = codec->control_data; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 240 | u8 value; |
| 241 | |
| 242 | if (reg >= TWL6040_CACHEREGNUM) |
| 243 | return -EIO; |
| 244 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 245 | value = twl6040_reg_read(twl6040, reg); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 246 | twl6040_write_reg_cache(codec, reg, value); |
| 247 | |
| 248 | return value; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * write to the twl6040 register space |
| 253 | */ |
| 254 | static int twl6040_write(struct snd_soc_codec *codec, |
| 255 | unsigned int reg, unsigned int value) |
| 256 | { |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 257 | struct twl6040 *twl6040 = codec->control_data; |
| 258 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 259 | if (reg >= TWL6040_CACHEREGNUM) |
| 260 | return -EIO; |
| 261 | |
| 262 | twl6040_write_reg_cache(codec, reg, value); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 263 | return twl6040_reg_write(twl6040, reg, value); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | static void twl6040_init_vio_regs(struct snd_soc_codec *codec) |
| 267 | { |
| 268 | u8 *cache = codec->reg_cache; |
| 269 | int reg, i; |
| 270 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 271 | for (i = 0; i < TWL6040_VIOREGNUM; i++) { |
| 272 | reg = twl6040_vio_reg[i]; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 273 | /* |
| 274 | * skip read-only registers (ASICID, ASICREV, STATUS) |
| 275 | * and registers shared among MFD children |
| 276 | */ |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 277 | switch (reg) { |
| 278 | case TWL6040_REG_ASICID: |
| 279 | case TWL6040_REG_ASICREV: |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 280 | case TWL6040_REG_INTID: |
| 281 | case TWL6040_REG_INTMR: |
| 282 | case TWL6040_REG_NCPCTL: |
| 283 | case TWL6040_REG_LDOCTL: |
| 284 | case TWL6040_REG_GPOCTL: |
| 285 | case TWL6040_REG_ACCCTL: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 286 | case TWL6040_REG_STATUS: |
| 287 | continue; |
| 288 | default: |
| 289 | break; |
| 290 | } |
| 291 | twl6040_write(codec, reg, cache[reg]); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | static void twl6040_init_vdd_regs(struct snd_soc_codec *codec) |
| 296 | { |
| 297 | u8 *cache = codec->reg_cache; |
| 298 | int reg, i; |
| 299 | |
| 300 | for (i = 0; i < TWL6040_VDDREGNUM; i++) { |
| 301 | reg = twl6040_vdd_reg[i]; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 302 | /* skip vibra and PLL registers */ |
| 303 | switch (reg) { |
| 304 | case TWL6040_REG_VIBCTLL: |
| 305 | case TWL6040_REG_VIBDATL: |
| 306 | case TWL6040_REG_VIBCTLR: |
| 307 | case TWL6040_REG_VIBDATR: |
| 308 | case TWL6040_REG_HPPLLCTL: |
| 309 | case TWL6040_REG_LPPLLCTL: |
| 310 | case TWL6040_REG_LPPLLDIV: |
| 311 | continue; |
| 312 | default: |
| 313 | break; |
| 314 | } |
| 315 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 316 | twl6040_write(codec, reg, cache[reg]); |
| 317 | } |
| 318 | } |
| 319 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 320 | /* |
| 321 | * Ramp HS PGA volume to minimise pops at stream startup and shutdown. |
| 322 | */ |
| 323 | static inline int twl6040_hs_ramp_step(struct snd_soc_codec *codec, |
| 324 | unsigned int left_step, unsigned int right_step) |
| 325 | { |
| 326 | |
| 327 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 328 | struct twl6040_output *headset = &priv->headset; |
| 329 | int left_complete = 0, right_complete = 0; |
| 330 | u8 reg, val; |
| 331 | |
| 332 | /* left channel */ |
| 333 | left_step = (left_step > 0xF) ? 0xF : left_step; |
| 334 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN); |
| 335 | val = (~reg & TWL6040_HSL_VOL_MASK); |
| 336 | |
| 337 | if (headset->ramp == TWL6040_RAMP_UP) { |
| 338 | /* ramp step up */ |
| 339 | if (val < headset->left_vol) { |
| 340 | val += left_step; |
| 341 | reg &= ~TWL6040_HSL_VOL_MASK; |
| 342 | twl6040_write(codec, TWL6040_REG_HSGAIN, |
| 343 | (reg | (~val & TWL6040_HSL_VOL_MASK))); |
| 344 | } else { |
| 345 | left_complete = 1; |
| 346 | } |
| 347 | } else if (headset->ramp == TWL6040_RAMP_DOWN) { |
| 348 | /* ramp step down */ |
| 349 | if (val > 0x0) { |
| 350 | val -= left_step; |
| 351 | reg &= ~TWL6040_HSL_VOL_MASK; |
| 352 | twl6040_write(codec, TWL6040_REG_HSGAIN, reg | |
| 353 | (~val & TWL6040_HSL_VOL_MASK)); |
| 354 | } else { |
| 355 | left_complete = 1; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /* right channel */ |
| 360 | right_step = (right_step > 0xF) ? 0xF : right_step; |
| 361 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN); |
| 362 | val = (~reg & TWL6040_HSR_VOL_MASK) >> TWL6040_HSR_VOL_SHIFT; |
| 363 | |
| 364 | if (headset->ramp == TWL6040_RAMP_UP) { |
| 365 | /* ramp step up */ |
| 366 | if (val < headset->right_vol) { |
| 367 | val += right_step; |
| 368 | reg &= ~TWL6040_HSR_VOL_MASK; |
| 369 | twl6040_write(codec, TWL6040_REG_HSGAIN, |
| 370 | (reg | (~val << TWL6040_HSR_VOL_SHIFT))); |
| 371 | } else { |
| 372 | right_complete = 1; |
| 373 | } |
| 374 | } else if (headset->ramp == TWL6040_RAMP_DOWN) { |
| 375 | /* ramp step down */ |
| 376 | if (val > 0x0) { |
| 377 | val -= right_step; |
| 378 | reg &= ~TWL6040_HSR_VOL_MASK; |
| 379 | twl6040_write(codec, TWL6040_REG_HSGAIN, |
| 380 | reg | (~val << TWL6040_HSR_VOL_SHIFT)); |
| 381 | } else { |
| 382 | right_complete = 1; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | return left_complete & right_complete; |
| 387 | } |
| 388 | |
| 389 | /* |
| 390 | * Ramp HF PGA volume to minimise pops at stream startup and shutdown. |
| 391 | */ |
| 392 | static inline int twl6040_hf_ramp_step(struct snd_soc_codec *codec, |
| 393 | unsigned int left_step, unsigned int right_step) |
| 394 | { |
| 395 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 396 | struct twl6040_output *handsfree = &priv->handsfree; |
| 397 | int left_complete = 0, right_complete = 0; |
| 398 | u16 reg, val; |
| 399 | |
| 400 | /* left channel */ |
| 401 | left_step = (left_step > 0x1D) ? 0x1D : left_step; |
| 402 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFLGAIN); |
| 403 | reg = 0x1D - reg; |
| 404 | val = (reg & TWL6040_HF_VOL_MASK); |
| 405 | if (handsfree->ramp == TWL6040_RAMP_UP) { |
| 406 | /* ramp step up */ |
| 407 | if (val < handsfree->left_vol) { |
| 408 | val += left_step; |
| 409 | reg &= ~TWL6040_HF_VOL_MASK; |
| 410 | twl6040_write(codec, TWL6040_REG_HFLGAIN, |
| 411 | reg | (0x1D - val)); |
| 412 | } else { |
| 413 | left_complete = 1; |
| 414 | } |
| 415 | } else if (handsfree->ramp == TWL6040_RAMP_DOWN) { |
| 416 | /* ramp step down */ |
| 417 | if (val > 0) { |
| 418 | val -= left_step; |
| 419 | reg &= ~TWL6040_HF_VOL_MASK; |
| 420 | twl6040_write(codec, TWL6040_REG_HFLGAIN, |
| 421 | reg | (0x1D - val)); |
| 422 | } else { |
| 423 | left_complete = 1; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | /* right channel */ |
| 428 | right_step = (right_step > 0x1D) ? 0x1D : right_step; |
| 429 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFRGAIN); |
| 430 | reg = 0x1D - reg; |
| 431 | val = (reg & TWL6040_HF_VOL_MASK); |
| 432 | if (handsfree->ramp == TWL6040_RAMP_UP) { |
| 433 | /* ramp step up */ |
| 434 | if (val < handsfree->right_vol) { |
| 435 | val += right_step; |
| 436 | reg &= ~TWL6040_HF_VOL_MASK; |
| 437 | twl6040_write(codec, TWL6040_REG_HFRGAIN, |
| 438 | reg | (0x1D - val)); |
| 439 | } else { |
| 440 | right_complete = 1; |
| 441 | } |
| 442 | } else if (handsfree->ramp == TWL6040_RAMP_DOWN) { |
| 443 | /* ramp step down */ |
| 444 | if (val > 0) { |
| 445 | val -= right_step; |
| 446 | reg &= ~TWL6040_HF_VOL_MASK; |
| 447 | twl6040_write(codec, TWL6040_REG_HFRGAIN, |
| 448 | reg | (0x1D - val)); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | return left_complete & right_complete; |
| 453 | } |
| 454 | |
| 455 | /* |
| 456 | * This work ramps both output PGAs at stream start/stop time to |
| 457 | * minimise pop associated with DAPM power switching. |
| 458 | */ |
| 459 | static void twl6040_pga_hs_work(struct work_struct *work) |
| 460 | { |
| 461 | struct twl6040_data *priv = |
| 462 | container_of(work, struct twl6040_data, hs_delayed_work.work); |
| 463 | struct snd_soc_codec *codec = priv->codec; |
| 464 | struct twl6040_output *headset = &priv->headset; |
| 465 | unsigned int delay = headset->step_delay; |
| 466 | int i, headset_complete; |
| 467 | |
| 468 | /* do we need to ramp at all ? */ |
| 469 | if (headset->ramp == TWL6040_RAMP_NONE) |
| 470 | return; |
| 471 | |
| 472 | /* HS PGA volumes have 4 bits of resolution to ramp */ |
| 473 | for (i = 0; i <= 16; i++) { |
| 474 | headset_complete = 1; |
| 475 | if (headset->ramp != TWL6040_RAMP_NONE) |
| 476 | headset_complete = twl6040_hs_ramp_step(codec, |
| 477 | headset->left_step, |
| 478 | headset->right_step); |
| 479 | |
| 480 | /* ramp finished ? */ |
| 481 | if (headset_complete) |
| 482 | break; |
| 483 | |
| 484 | /* |
| 485 | * TODO: tune: delay is longer over 0dB |
| 486 | * as increases are larger. |
| 487 | */ |
| 488 | if (i >= 8) |
| 489 | schedule_timeout_interruptible(msecs_to_jiffies(delay + |
| 490 | (delay >> 1))); |
| 491 | else |
| 492 | schedule_timeout_interruptible(msecs_to_jiffies(delay)); |
| 493 | } |
| 494 | |
| 495 | if (headset->ramp == TWL6040_RAMP_DOWN) { |
| 496 | headset->active = 0; |
| 497 | complete(&headset->ramp_done); |
| 498 | } else { |
| 499 | headset->active = 1; |
| 500 | } |
| 501 | headset->ramp = TWL6040_RAMP_NONE; |
| 502 | } |
| 503 | |
| 504 | static void twl6040_pga_hf_work(struct work_struct *work) |
| 505 | { |
| 506 | struct twl6040_data *priv = |
| 507 | container_of(work, struct twl6040_data, hf_delayed_work.work); |
| 508 | struct snd_soc_codec *codec = priv->codec; |
| 509 | struct twl6040_output *handsfree = &priv->handsfree; |
| 510 | unsigned int delay = handsfree->step_delay; |
| 511 | int i, handsfree_complete; |
| 512 | |
| 513 | /* do we need to ramp at all ? */ |
| 514 | if (handsfree->ramp == TWL6040_RAMP_NONE) |
| 515 | return; |
| 516 | |
| 517 | /* HF PGA volumes have 5 bits of resolution to ramp */ |
| 518 | for (i = 0; i <= 32; i++) { |
| 519 | handsfree_complete = 1; |
| 520 | if (handsfree->ramp != TWL6040_RAMP_NONE) |
| 521 | handsfree_complete = twl6040_hf_ramp_step(codec, |
| 522 | handsfree->left_step, |
| 523 | handsfree->right_step); |
| 524 | |
| 525 | /* ramp finished ? */ |
| 526 | if (handsfree_complete) |
| 527 | break; |
| 528 | |
| 529 | /* |
| 530 | * TODO: tune: delay is longer over 0dB |
| 531 | * as increases are larger. |
| 532 | */ |
| 533 | if (i >= 16) |
| 534 | schedule_timeout_interruptible(msecs_to_jiffies(delay + |
| 535 | (delay >> 1))); |
| 536 | else |
| 537 | schedule_timeout_interruptible(msecs_to_jiffies(delay)); |
| 538 | } |
| 539 | |
| 540 | |
| 541 | if (handsfree->ramp == TWL6040_RAMP_DOWN) { |
| 542 | handsfree->active = 0; |
| 543 | complete(&handsfree->ramp_done); |
| 544 | } else |
| 545 | handsfree->active = 1; |
| 546 | handsfree->ramp = TWL6040_RAMP_NONE; |
| 547 | } |
| 548 | |
| 549 | static int pga_event(struct snd_soc_dapm_widget *w, |
| 550 | struct snd_kcontrol *kcontrol, int event) |
| 551 | { |
| 552 | struct snd_soc_codec *codec = w->codec; |
| 553 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 554 | struct twl6040_output *out; |
| 555 | struct delayed_work *work; |
| 556 | struct workqueue_struct *queue; |
| 557 | |
| 558 | switch (w->shift) { |
| 559 | case 2: |
| 560 | case 3: |
| 561 | out = &priv->headset; |
| 562 | work = &priv->hs_delayed_work; |
| 563 | queue = priv->hs_workqueue; |
| 564 | out->step_delay = 5; /* 5 ms between volume ramp steps */ |
| 565 | break; |
| 566 | case 4: |
| 567 | out = &priv->handsfree; |
| 568 | work = &priv->hf_delayed_work; |
| 569 | queue = priv->hf_workqueue; |
| 570 | out->step_delay = 5; /* 5 ms between volume ramp steps */ |
| 571 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 572 | priv->non_lp++; |
| 573 | else |
| 574 | priv->non_lp--; |
| 575 | break; |
| 576 | default: |
| 577 | return -1; |
| 578 | } |
| 579 | |
| 580 | switch (event) { |
| 581 | case SND_SOC_DAPM_POST_PMU: |
| 582 | if (out->active) |
| 583 | break; |
| 584 | |
| 585 | /* don't use volume ramp for power-up */ |
| 586 | out->left_step = out->left_vol; |
| 587 | out->right_step = out->right_vol; |
| 588 | |
| 589 | if (!delayed_work_pending(work)) { |
| 590 | out->ramp = TWL6040_RAMP_UP; |
| 591 | queue_delayed_work(queue, work, |
| 592 | msecs_to_jiffies(1)); |
| 593 | } |
| 594 | break; |
| 595 | |
| 596 | case SND_SOC_DAPM_PRE_PMD: |
| 597 | if (!out->active) |
| 598 | break; |
| 599 | |
| 600 | if (!delayed_work_pending(work)) { |
| 601 | /* use volume ramp for power-down */ |
| 602 | out->left_step = 1; |
| 603 | out->right_step = 1; |
| 604 | out->ramp = TWL6040_RAMP_DOWN; |
| 605 | INIT_COMPLETION(out->ramp_done); |
| 606 | |
| 607 | queue_delayed_work(queue, work, |
| 608 | msecs_to_jiffies(1)); |
| 609 | |
| 610 | wait_for_completion_timeout(&out->ramp_done, |
| 611 | msecs_to_jiffies(2000)); |
| 612 | } |
| 613 | break; |
| 614 | } |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 619 | /* set headset dac and driver power mode */ |
| 620 | static int headset_power_mode(struct snd_soc_codec *codec, int high_perf) |
| 621 | { |
| 622 | int hslctl, hsrctl; |
| 623 | int mask = TWL6040_HSDRVMODEL | TWL6040_HSDACMODEL; |
| 624 | |
| 625 | hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL); |
| 626 | hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL); |
| 627 | |
| 628 | if (high_perf) { |
| 629 | hslctl &= ~mask; |
| 630 | hsrctl &= ~mask; |
| 631 | } else { |
| 632 | hslctl |= mask; |
| 633 | hsrctl |= mask; |
| 634 | } |
| 635 | |
| 636 | twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl); |
| 637 | twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl); |
| 638 | |
| 639 | return 0; |
| 640 | } |
| 641 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 642 | static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w, |
| 643 | struct snd_kcontrol *kcontrol, int event) |
| 644 | { |
| 645 | msleep(1); |
| 646 | return 0; |
| 647 | } |
| 648 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 649 | static int twl6040_power_mode_event(struct snd_soc_dapm_widget *w, |
| 650 | struct snd_kcontrol *kcontrol, int event) |
| 651 | { |
| 652 | struct snd_soc_codec *codec = w->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 653 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 654 | |
| 655 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 656 | priv->non_lp++; |
| 657 | else |
| 658 | priv->non_lp--; |
| 659 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 660 | msleep(1); |
| 661 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 662 | return 0; |
| 663 | } |
| 664 | |
Mark Brown | 64ed983 | 2011-01-20 21:43:44 +0000 | [diff] [blame] | 665 | static void twl6040_hs_jack_report(struct snd_soc_codec *codec, |
| 666 | struct snd_soc_jack *jack, int report) |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 667 | { |
| 668 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 669 | int status; |
| 670 | |
| 671 | mutex_lock(&priv->mutex); |
| 672 | |
| 673 | /* Sync status */ |
| 674 | status = twl6040_read_reg_volatile(codec, TWL6040_REG_STATUS); |
| 675 | if (status & TWL6040_PLUGCOMP) |
| 676 | snd_soc_jack_report(jack, report, report); |
| 677 | else |
| 678 | snd_soc_jack_report(jack, 0, report); |
| 679 | |
| 680 | mutex_unlock(&priv->mutex); |
| 681 | } |
| 682 | |
| 683 | void twl6040_hs_jack_detect(struct snd_soc_codec *codec, |
| 684 | struct snd_soc_jack *jack, int report) |
| 685 | { |
| 686 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 687 | struct twl6040_jack_data *hs_jack = &priv->hs_jack; |
| 688 | |
| 689 | hs_jack->jack = jack; |
| 690 | hs_jack->report = report; |
| 691 | |
| 692 | twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report); |
| 693 | } |
| 694 | EXPORT_SYMBOL_GPL(twl6040_hs_jack_detect); |
| 695 | |
| 696 | static void twl6040_accessory_work(struct work_struct *work) |
| 697 | { |
| 698 | struct twl6040_data *priv = container_of(work, |
| 699 | struct twl6040_data, delayed_work.work); |
| 700 | struct snd_soc_codec *codec = priv->codec; |
| 701 | struct twl6040_jack_data *hs_jack = &priv->hs_jack; |
| 702 | |
| 703 | twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report); |
| 704 | } |
| 705 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 706 | /* audio interrupt handler */ |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 707 | static irqreturn_t twl6040_audio_handler(int irq, void *data) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 708 | { |
| 709 | struct snd_soc_codec *codec = data; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 710 | struct twl6040 *twl6040 = codec->control_data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 711 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 712 | u8 intid; |
| 713 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 714 | intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID); |
Olaya, Margarita | cf370a5 | 2010-12-10 21:05:30 -0600 | [diff] [blame] | 715 | |
| 716 | if ((intid & TWL6040_PLUGINT) || (intid & TWL6040_UNPLUGINT)) |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 717 | queue_delayed_work(priv->workqueue, &priv->delayed_work, |
| 718 | msecs_to_jiffies(200)); |
Olaya, Margarita | cf370a5 | 2010-12-10 21:05:30 -0600 | [diff] [blame] | 719 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 720 | return IRQ_HANDLED; |
| 721 | } |
| 722 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 723 | static int twl6040_put_volsw(struct snd_kcontrol *kcontrol, |
| 724 | struct snd_ctl_elem_value *ucontrol) |
| 725 | { |
| 726 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 727 | struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec); |
| 728 | struct twl6040_output *out = NULL; |
| 729 | struct soc_mixer_control *mc = |
| 730 | (struct soc_mixer_control *)kcontrol->private_value; |
| 731 | int ret; |
| 732 | unsigned int reg = mc->reg; |
| 733 | |
| 734 | /* For HS and HF we shadow the values and only actually write |
| 735 | * them out when active in order to ensure the amplifier comes on |
| 736 | * as quietly as possible. */ |
| 737 | switch (reg) { |
| 738 | case TWL6040_REG_HSGAIN: |
| 739 | out = &twl6040_priv->headset; |
| 740 | break; |
| 741 | default: |
| 742 | break; |
| 743 | } |
| 744 | |
| 745 | if (out) { |
| 746 | out->left_vol = ucontrol->value.integer.value[0]; |
| 747 | out->right_vol = ucontrol->value.integer.value[1]; |
| 748 | if (!out->active) |
| 749 | return 1; |
| 750 | } |
| 751 | |
| 752 | ret = snd_soc_put_volsw(kcontrol, ucontrol); |
| 753 | if (ret < 0) |
| 754 | return ret; |
| 755 | |
| 756 | return 1; |
| 757 | } |
| 758 | |
| 759 | static int twl6040_get_volsw(struct snd_kcontrol *kcontrol, |
| 760 | struct snd_ctl_elem_value *ucontrol) |
| 761 | { |
| 762 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 763 | struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec); |
| 764 | struct twl6040_output *out = &twl6040_priv->headset; |
| 765 | struct soc_mixer_control *mc = |
| 766 | (struct soc_mixer_control *)kcontrol->private_value; |
| 767 | unsigned int reg = mc->reg; |
| 768 | |
| 769 | switch (reg) { |
| 770 | case TWL6040_REG_HSGAIN: |
| 771 | out = &twl6040_priv->headset; |
| 772 | ucontrol->value.integer.value[0] = out->left_vol; |
| 773 | ucontrol->value.integer.value[1] = out->right_vol; |
| 774 | return 0; |
| 775 | |
| 776 | default: |
| 777 | break; |
| 778 | } |
| 779 | |
| 780 | return snd_soc_get_volsw(kcontrol, ucontrol); |
| 781 | } |
| 782 | |
| 783 | static int twl6040_put_volsw_2r_vu(struct snd_kcontrol *kcontrol, |
| 784 | struct snd_ctl_elem_value *ucontrol) |
| 785 | { |
| 786 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 787 | struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec); |
| 788 | struct twl6040_output *out = NULL; |
| 789 | struct soc_mixer_control *mc = |
| 790 | (struct soc_mixer_control *)kcontrol->private_value; |
| 791 | int ret; |
| 792 | unsigned int reg = mc->reg; |
| 793 | |
| 794 | /* For HS and HF we shadow the values and only actually write |
| 795 | * them out when active in order to ensure the amplifier comes on |
| 796 | * as quietly as possible. */ |
| 797 | switch (reg) { |
| 798 | case TWL6040_REG_HFLGAIN: |
| 799 | case TWL6040_REG_HFRGAIN: |
| 800 | out = &twl6040_priv->handsfree; |
| 801 | break; |
| 802 | default: |
| 803 | break; |
| 804 | } |
| 805 | |
| 806 | if (out) { |
| 807 | out->left_vol = ucontrol->value.integer.value[0]; |
| 808 | out->right_vol = ucontrol->value.integer.value[1]; |
| 809 | if (!out->active) |
| 810 | return 1; |
| 811 | } |
| 812 | |
| 813 | ret = snd_soc_put_volsw_2r(kcontrol, ucontrol); |
| 814 | if (ret < 0) |
| 815 | return ret; |
| 816 | |
| 817 | return 1; |
| 818 | } |
| 819 | |
| 820 | static int twl6040_get_volsw_2r(struct snd_kcontrol *kcontrol, |
| 821 | struct snd_ctl_elem_value *ucontrol) |
| 822 | { |
| 823 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 824 | struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec); |
| 825 | struct twl6040_output *out = &twl6040_priv->handsfree; |
| 826 | struct soc_mixer_control *mc = |
| 827 | (struct soc_mixer_control *)kcontrol->private_value; |
| 828 | unsigned int reg = mc->reg; |
| 829 | |
| 830 | /* If these are cached registers use the cache */ |
| 831 | switch (reg) { |
| 832 | case TWL6040_REG_HFLGAIN: |
| 833 | case TWL6040_REG_HFRGAIN: |
| 834 | out = &twl6040_priv->handsfree; |
| 835 | ucontrol->value.integer.value[0] = out->left_vol; |
| 836 | ucontrol->value.integer.value[1] = out->right_vol; |
| 837 | return 0; |
| 838 | |
| 839 | default: |
| 840 | break; |
| 841 | } |
| 842 | |
| 843 | return snd_soc_get_volsw_2r(kcontrol, ucontrol); |
| 844 | } |
| 845 | |
| 846 | /* double control with volume update */ |
| 847 | #define SOC_TWL6040_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax,\ |
| 848 | xinvert, tlv_array)\ |
| 849 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ |
| 850 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ |
| 851 | SNDRV_CTL_ELEM_ACCESS_READWRITE,\ |
| 852 | .tlv.p = (tlv_array), \ |
| 853 | .info = snd_soc_info_volsw, .get = twl6040_get_volsw, \ |
| 854 | .put = twl6040_put_volsw, \ |
| 855 | .private_value = (unsigned long)&(struct soc_mixer_control) \ |
| 856 | {.reg = xreg, .shift = shift_left, .rshift = shift_right,\ |
| 857 | .max = xmax, .platform_max = xmax, .invert = xinvert} } |
| 858 | |
| 859 | /* double control with volume update */ |
| 860 | #define SOC_TWL6040_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax,\ |
| 861 | xinvert, tlv_array)\ |
| 862 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\ |
| 863 | .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \ |
| 864 | SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 865 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 866 | .tlv.p = (tlv_array), \ |
| 867 | .info = snd_soc_info_volsw_2r, \ |
| 868 | .get = twl6040_get_volsw_2r, .put = twl6040_put_volsw_2r_vu, \ |
| 869 | .private_value = (unsigned long)&(struct soc_mixer_control) \ |
| 870 | {.reg = reg_left, .rreg = reg_right, .shift = xshift, \ |
| 871 | .rshift = xshift, .max = xmax, .invert = xinvert}, } |
| 872 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 873 | /* |
| 874 | * MICATT volume control: |
| 875 | * from -6 to 0 dB in 6 dB steps |
| 876 | */ |
| 877 | static DECLARE_TLV_DB_SCALE(mic_preamp_tlv, -600, 600, 0); |
| 878 | |
| 879 | /* |
| 880 | * MICGAIN volume control: |
Olaya, Margarita | 9020808 | 2010-12-10 21:06:39 -0600 | [diff] [blame] | 881 | * from -6 to 30 dB in 6 dB steps |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 882 | */ |
Olaya, Margarita | 9020808 | 2010-12-10 21:06:39 -0600 | [diff] [blame] | 883 | static DECLARE_TLV_DB_SCALE(mic_amp_tlv, -600, 600, 0); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 884 | |
| 885 | /* |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 886 | * AFMGAIN volume control: |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 887 | * from -18 to 24 dB in 6 dB steps |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 888 | */ |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 889 | static DECLARE_TLV_DB_SCALE(afm_amp_tlv, -1800, 600, 0); |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 890 | |
| 891 | /* |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 892 | * HSGAIN volume control: |
| 893 | * from -30 to 0 dB in 2 dB steps |
| 894 | */ |
| 895 | static DECLARE_TLV_DB_SCALE(hs_tlv, -3000, 200, 0); |
| 896 | |
| 897 | /* |
| 898 | * HFGAIN volume control: |
| 899 | * from -52 to 6 dB in 2 dB steps |
| 900 | */ |
| 901 | static DECLARE_TLV_DB_SCALE(hf_tlv, -5200, 200, 0); |
| 902 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 903 | /* |
| 904 | * EPGAIN volume control: |
| 905 | * from -24 to 6 dB in 2 dB steps |
| 906 | */ |
| 907 | static DECLARE_TLV_DB_SCALE(ep_tlv, -2400, 200, 0); |
| 908 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 909 | /* Left analog microphone selection */ |
| 910 | static const char *twl6040_amicl_texts[] = |
| 911 | {"Headset Mic", "Main Mic", "Aux/FM Left", "Off"}; |
| 912 | |
| 913 | /* Right analog microphone selection */ |
| 914 | static const char *twl6040_amicr_texts[] = |
| 915 | {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"}; |
| 916 | |
| 917 | static const struct soc_enum twl6040_enum[] = { |
Francois Mazard | cb973d7 | 2010-12-10 21:06:03 -0600 | [diff] [blame] | 918 | SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3, 4, twl6040_amicl_texts), |
| 919 | SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3, 4, twl6040_amicr_texts), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 920 | }; |
| 921 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 922 | static const char *twl6040_hs_texts[] = { |
| 923 | "Off", "HS DAC", "Line-In amp" |
| 924 | }; |
| 925 | |
| 926 | static const struct soc_enum twl6040_hs_enum[] = { |
| 927 | SOC_ENUM_SINGLE(TWL6040_REG_HSLCTL, 5, ARRAY_SIZE(twl6040_hs_texts), |
| 928 | twl6040_hs_texts), |
| 929 | SOC_ENUM_SINGLE(TWL6040_REG_HSRCTL, 5, ARRAY_SIZE(twl6040_hs_texts), |
| 930 | twl6040_hs_texts), |
| 931 | }; |
| 932 | |
| 933 | static const char *twl6040_hf_texts[] = { |
| 934 | "Off", "HF DAC", "Line-In amp" |
| 935 | }; |
| 936 | |
| 937 | static const struct soc_enum twl6040_hf_enum[] = { |
| 938 | SOC_ENUM_SINGLE(TWL6040_REG_HFLCTL, 2, ARRAY_SIZE(twl6040_hf_texts), |
| 939 | twl6040_hf_texts), |
| 940 | SOC_ENUM_SINGLE(TWL6040_REG_HFRCTL, 2, ARRAY_SIZE(twl6040_hf_texts), |
| 941 | twl6040_hf_texts), |
| 942 | }; |
| 943 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 944 | static const struct snd_kcontrol_new amicl_control = |
| 945 | SOC_DAPM_ENUM("Route", twl6040_enum[0]); |
| 946 | |
| 947 | static const struct snd_kcontrol_new amicr_control = |
| 948 | SOC_DAPM_ENUM("Route", twl6040_enum[1]); |
| 949 | |
| 950 | /* Headset DAC playback switches */ |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 951 | static const struct snd_kcontrol_new hsl_mux_controls = |
| 952 | SOC_DAPM_ENUM("Route", twl6040_hs_enum[0]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 953 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 954 | static const struct snd_kcontrol_new hsr_mux_controls = |
| 955 | SOC_DAPM_ENUM("Route", twl6040_hs_enum[1]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 956 | |
| 957 | /* Handsfree DAC playback switches */ |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 958 | static const struct snd_kcontrol_new hfl_mux_controls = |
| 959 | SOC_DAPM_ENUM("Route", twl6040_hf_enum[0]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 960 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 961 | static const struct snd_kcontrol_new hfr_mux_controls = |
| 962 | SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 963 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 964 | static const struct snd_kcontrol_new ep_driver_switch_controls = |
| 965 | SOC_DAPM_SINGLE("Switch", TWL6040_REG_EARCTL, 0, 1, 0); |
| 966 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 967 | static const struct snd_kcontrol_new twl6040_snd_controls[] = { |
| 968 | /* Capture gains */ |
| 969 | SOC_DOUBLE_TLV("Capture Preamplifier Volume", |
| 970 | TWL6040_REG_MICGAIN, 6, 7, 1, 1, mic_preamp_tlv), |
| 971 | SOC_DOUBLE_TLV("Capture Volume", |
| 972 | TWL6040_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv), |
| 973 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 974 | /* AFM gains */ |
| 975 | SOC_DOUBLE_TLV("Aux FM Volume", |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 976 | TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv), |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 977 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 978 | /* Playback gains */ |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 979 | SOC_TWL6040_DOUBLE_TLV("Headset Playback Volume", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 980 | TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv), |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 981 | SOC_TWL6040_DOUBLE_R_TLV("Handsfree Playback Volume", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 982 | TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 983 | SOC_SINGLE_TLV("Earphone Playback Volume", |
| 984 | TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 985 | }; |
| 986 | |
| 987 | static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = { |
| 988 | /* Inputs */ |
| 989 | SND_SOC_DAPM_INPUT("MAINMIC"), |
| 990 | SND_SOC_DAPM_INPUT("HSMIC"), |
| 991 | SND_SOC_DAPM_INPUT("SUBMIC"), |
| 992 | SND_SOC_DAPM_INPUT("AFML"), |
| 993 | SND_SOC_DAPM_INPUT("AFMR"), |
| 994 | |
| 995 | /* Outputs */ |
| 996 | SND_SOC_DAPM_OUTPUT("HSOL"), |
| 997 | SND_SOC_DAPM_OUTPUT("HSOR"), |
| 998 | SND_SOC_DAPM_OUTPUT("HFL"), |
| 999 | SND_SOC_DAPM_OUTPUT("HFR"), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 1000 | SND_SOC_DAPM_OUTPUT("EP"), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1001 | |
| 1002 | /* Analog input muxes for the capture amplifiers */ |
| 1003 | SND_SOC_DAPM_MUX("Analog Left Capture Route", |
| 1004 | SND_SOC_NOPM, 0, 0, &amicl_control), |
| 1005 | SND_SOC_DAPM_MUX("Analog Right Capture Route", |
| 1006 | SND_SOC_NOPM, 0, 0, &amicr_control), |
| 1007 | |
| 1008 | /* Analog capture PGAs */ |
| 1009 | SND_SOC_DAPM_PGA("MicAmpL", |
| 1010 | TWL6040_REG_MICLCTL, 0, 0, NULL, 0), |
| 1011 | SND_SOC_DAPM_PGA("MicAmpR", |
| 1012 | TWL6040_REG_MICRCTL, 0, 0, NULL, 0), |
| 1013 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1014 | /* Auxiliary FM PGAs */ |
| 1015 | SND_SOC_DAPM_PGA("AFMAmpL", |
| 1016 | TWL6040_REG_MICLCTL, 1, 0, NULL, 0), |
| 1017 | SND_SOC_DAPM_PGA("AFMAmpR", |
| 1018 | TWL6040_REG_MICRCTL, 1, 0, NULL, 0), |
| 1019 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1020 | /* ADCs */ |
| 1021 | SND_SOC_DAPM_ADC("ADC Left", "Left Front Capture", |
| 1022 | TWL6040_REG_MICLCTL, 2, 0), |
| 1023 | SND_SOC_DAPM_ADC("ADC Right", "Right Front Capture", |
| 1024 | TWL6040_REG_MICRCTL, 2, 0), |
| 1025 | |
| 1026 | /* Microphone bias */ |
| 1027 | SND_SOC_DAPM_MICBIAS("Headset Mic Bias", |
| 1028 | TWL6040_REG_AMICBCTL, 0, 0), |
| 1029 | SND_SOC_DAPM_MICBIAS("Main Mic Bias", |
| 1030 | TWL6040_REG_AMICBCTL, 4, 0), |
| 1031 | SND_SOC_DAPM_MICBIAS("Digital Mic1 Bias", |
| 1032 | TWL6040_REG_DMICBCTL, 0, 0), |
| 1033 | SND_SOC_DAPM_MICBIAS("Digital Mic2 Bias", |
| 1034 | TWL6040_REG_DMICBCTL, 4, 0), |
| 1035 | |
| 1036 | /* DACs */ |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 1037 | SND_SOC_DAPM_DAC_E("HSDAC Left", "Headset Playback", |
| 1038 | TWL6040_REG_HSLCTL, 0, 0, |
| 1039 | twl6040_hs_dac_event, |
| 1040 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1041 | SND_SOC_DAPM_DAC_E("HSDAC Right", "Headset Playback", |
| 1042 | TWL6040_REG_HSRCTL, 0, 0, |
| 1043 | twl6040_hs_dac_event, |
| 1044 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1045 | SND_SOC_DAPM_DAC_E("HFDAC Left", "Handsfree Playback", |
| 1046 | TWL6040_REG_HFLCTL, 0, 0, |
| 1047 | twl6040_power_mode_event, |
| 1048 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1049 | SND_SOC_DAPM_DAC_E("HFDAC Right", "Handsfree Playback", |
| 1050 | TWL6040_REG_HFRCTL, 0, 0, |
| 1051 | twl6040_power_mode_event, |
| 1052 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1053 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1054 | SND_SOC_DAPM_MUX("HF Left Playback", |
| 1055 | SND_SOC_NOPM, 0, 0, &hfl_mux_controls), |
| 1056 | SND_SOC_DAPM_MUX("HF Right Playback", |
| 1057 | SND_SOC_NOPM, 0, 0, &hfr_mux_controls), |
| 1058 | /* Analog playback Muxes */ |
| 1059 | SND_SOC_DAPM_MUX("HS Left Playback", |
| 1060 | SND_SOC_NOPM, 0, 0, &hsl_mux_controls), |
| 1061 | SND_SOC_DAPM_MUX("HS Right Playback", |
| 1062 | SND_SOC_NOPM, 0, 0, &hsr_mux_controls), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1063 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 1064 | /* Analog playback drivers */ |
Olaya, Margarita | f769bdf | 2010-12-20 10:39:20 -0600 | [diff] [blame] | 1065 | SND_SOC_DAPM_OUT_DRV_E("Handsfree Left Driver", |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 1066 | TWL6040_REG_HFLCTL, 4, 0, NULL, 0, |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1067 | pga_event, |
| 1068 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Olaya, Margarita | f769bdf | 2010-12-20 10:39:20 -0600 | [diff] [blame] | 1069 | SND_SOC_DAPM_OUT_DRV_E("Handsfree Right Driver", |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 1070 | TWL6040_REG_HFRCTL, 4, 0, NULL, 0, |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1071 | pga_event, |
| 1072 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Olaya, Margarita | f769bdf | 2010-12-20 10:39:20 -0600 | [diff] [blame] | 1073 | SND_SOC_DAPM_OUT_DRV_E("Headset Left Driver", |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1074 | TWL6040_REG_HSLCTL, 2, 0, NULL, 0, |
| 1075 | pga_event, |
| 1076 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Olaya, Margarita | f769bdf | 2010-12-20 10:39:20 -0600 | [diff] [blame] | 1077 | SND_SOC_DAPM_OUT_DRV_E("Headset Right Driver", |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1078 | TWL6040_REG_HSRCTL, 2, 0, NULL, 0, |
| 1079 | pga_event, |
| 1080 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 1081 | SND_SOC_DAPM_SWITCH_E("Earphone Driver", |
| 1082 | SND_SOC_NOPM, 0, 0, &ep_driver_switch_controls, |
| 1083 | twl6040_power_mode_event, |
| 1084 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1085 | |
| 1086 | /* Analog playback PGAs */ |
| 1087 | SND_SOC_DAPM_PGA("HFDAC Left PGA", |
| 1088 | TWL6040_REG_HFLCTL, 1, 0, NULL, 0), |
| 1089 | SND_SOC_DAPM_PGA("HFDAC Right PGA", |
| 1090 | TWL6040_REG_HFRCTL, 1, 0, NULL, 0), |
| 1091 | |
| 1092 | }; |
| 1093 | |
| 1094 | static const struct snd_soc_dapm_route intercon[] = { |
| 1095 | /* Capture path */ |
| 1096 | {"Analog Left Capture Route", "Headset Mic", "HSMIC"}, |
| 1097 | {"Analog Left Capture Route", "Main Mic", "MAINMIC"}, |
| 1098 | {"Analog Left Capture Route", "Aux/FM Left", "AFML"}, |
| 1099 | |
| 1100 | {"Analog Right Capture Route", "Headset Mic", "HSMIC"}, |
| 1101 | {"Analog Right Capture Route", "Sub Mic", "SUBMIC"}, |
| 1102 | {"Analog Right Capture Route", "Aux/FM Right", "AFMR"}, |
| 1103 | |
| 1104 | {"MicAmpL", NULL, "Analog Left Capture Route"}, |
| 1105 | {"MicAmpR", NULL, "Analog Right Capture Route"}, |
| 1106 | |
| 1107 | {"ADC Left", NULL, "MicAmpL"}, |
| 1108 | {"ADC Right", NULL, "MicAmpR"}, |
| 1109 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1110 | /* AFM path */ |
| 1111 | {"AFMAmpL", "NULL", "AFML"}, |
| 1112 | {"AFMAmpR", "NULL", "AFMR"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1113 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1114 | {"HS Left Playback", "HS DAC", "HSDAC Left"}, |
| 1115 | {"HS Left Playback", "Line-In amp", "AFMAmpL"}, |
| 1116 | |
| 1117 | {"HS Right Playback", "HS DAC", "HSDAC Right"}, |
| 1118 | {"HS Right Playback", "Line-In amp", "AFMAmpR"}, |
| 1119 | |
| 1120 | {"Headset Left Driver", "NULL", "HS Left Playback"}, |
| 1121 | {"Headset Right Driver", "NULL", "HS Right Playback"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1122 | |
| 1123 | {"HSOL", NULL, "Headset Left Driver"}, |
| 1124 | {"HSOR", NULL, "Headset Right Driver"}, |
| 1125 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 1126 | /* Earphone playback path */ |
| 1127 | {"Earphone Driver", "Switch", "HSDAC Left"}, |
| 1128 | {"EP", NULL, "Earphone Driver"}, |
| 1129 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1130 | {"HF Left Playback", "HF DAC", "HFDAC Left"}, |
| 1131 | {"HF Left Playback", "Line-In amp", "AFMAmpL"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1132 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1133 | {"HF Right Playback", "HF DAC", "HFDAC Right"}, |
| 1134 | {"HF Right Playback", "Line-In amp", "AFMAmpR"}, |
| 1135 | |
| 1136 | {"HFDAC Left PGA", NULL, "HF Left Playback"}, |
| 1137 | {"HFDAC Right PGA", NULL, "HF Right Playback"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1138 | |
| 1139 | {"Handsfree Left Driver", "Switch", "HFDAC Left PGA"}, |
| 1140 | {"Handsfree Right Driver", "Switch", "HFDAC Right PGA"}, |
| 1141 | |
| 1142 | {"HFL", NULL, "Handsfree Left Driver"}, |
| 1143 | {"HFR", NULL, "Handsfree Right Driver"}, |
| 1144 | }; |
| 1145 | |
| 1146 | static int twl6040_add_widgets(struct snd_soc_codec *codec) |
| 1147 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1148 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 1149 | |
| 1150 | snd_soc_dapm_new_controls(dapm, twl6040_dapm_widgets, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1151 | ARRAY_SIZE(twl6040_dapm_widgets)); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1152 | snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon)); |
| 1153 | snd_soc_dapm_new_widgets(dapm); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1154 | |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1158 | static int twl6040_set_bias_level(struct snd_soc_codec *codec, |
| 1159 | enum snd_soc_bias_level level) |
| 1160 | { |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1161 | struct twl6040 *twl6040 = codec->control_data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1162 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1163 | int ret; |
| 1164 | |
| 1165 | switch (level) { |
| 1166 | case SND_SOC_BIAS_ON: |
| 1167 | break; |
| 1168 | case SND_SOC_BIAS_PREPARE: |
| 1169 | break; |
| 1170 | case SND_SOC_BIAS_STANDBY: |
| 1171 | if (priv->codec_powered) |
| 1172 | break; |
| 1173 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1174 | ret = twl6040_power(twl6040, 1); |
| 1175 | if (ret) |
| 1176 | return ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1177 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1178 | priv->codec_powered = 1; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1179 | |
| 1180 | /* initialize vdd/vss registers with reg_cache */ |
| 1181 | twl6040_init_vdd_regs(codec); |
Olaya, Margarita | 65b7cec | 2010-12-14 19:18:36 -0600 | [diff] [blame] | 1182 | |
| 1183 | /* Set external boost GPO */ |
| 1184 | twl6040_write(codec, TWL6040_REG_GPOCTL, 0x02); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1185 | break; |
| 1186 | case SND_SOC_BIAS_OFF: |
| 1187 | if (!priv->codec_powered) |
| 1188 | break; |
| 1189 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1190 | twl6040_power(twl6040, 0); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1191 | priv->codec_powered = 0; |
| 1192 | break; |
| 1193 | } |
| 1194 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1195 | /* get PLL and sysclk after power transition */ |
| 1196 | priv->pll = twl6040_get_pll(twl6040); |
| 1197 | priv->sysclk = twl6040_get_sysclk(twl6040); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1198 | codec->dapm.bias_level = level; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1199 | |
| 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | /* set of rates for each pll: low-power and high-performance */ |
| 1204 | |
| 1205 | static unsigned int lp_rates[] = { |
Liam Girdwood | e17e4ab | 2011-03-18 19:00:50 +0000 | [diff] [blame^] | 1206 | 8000, |
| 1207 | 11250, |
| 1208 | 16000, |
| 1209 | 22500, |
| 1210 | 32000, |
| 1211 | 44100, |
| 1212 | 48000, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1213 | 88200, |
| 1214 | 96000, |
| 1215 | }; |
| 1216 | |
| 1217 | static struct snd_pcm_hw_constraint_list lp_constraints = { |
| 1218 | .count = ARRAY_SIZE(lp_rates), |
| 1219 | .list = lp_rates, |
| 1220 | }; |
| 1221 | |
| 1222 | static unsigned int hp_rates[] = { |
Liam Girdwood | e17e4ab | 2011-03-18 19:00:50 +0000 | [diff] [blame^] | 1223 | 8000, |
| 1224 | 16000, |
| 1225 | 32000, |
| 1226 | 48000, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1227 | 96000, |
| 1228 | }; |
| 1229 | |
| 1230 | static struct snd_pcm_hw_constraint_list hp_constraints = { |
| 1231 | .count = ARRAY_SIZE(hp_rates), |
| 1232 | .list = hp_rates, |
| 1233 | }; |
| 1234 | |
| 1235 | static int twl6040_startup(struct snd_pcm_substream *substream, |
| 1236 | struct snd_soc_dai *dai) |
| 1237 | { |
| 1238 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1239 | struct snd_soc_codec *codec = rtd->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1240 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1241 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1242 | snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 1243 | SNDRV_PCM_HW_PARAM_RATE, |
| 1244 | priv->sysclk_constraints); |
| 1245 | |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | static int twl6040_hw_params(struct snd_pcm_substream *substream, |
| 1250 | struct snd_pcm_hw_params *params, |
| 1251 | struct snd_soc_dai *dai) |
| 1252 | { |
| 1253 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1254 | struct snd_soc_codec *codec = rtd->codec; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1255 | struct twl6040 *twl6040 = codec->control_data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1256 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1257 | unsigned int sysclk; |
| 1258 | int rate, ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1259 | |
| 1260 | /* nothing to do for high-perf pll, it supports only 48 kHz */ |
| 1261 | if (priv->pll == TWL6040_HPPLL_ID) |
| 1262 | return 0; |
| 1263 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1264 | rate = params_rate(params); |
| 1265 | switch (rate) { |
Olaya, Margarita | 60ea4ce | 2010-12-10 21:05:58 -0600 | [diff] [blame] | 1266 | case 11250: |
| 1267 | case 22500: |
| 1268 | case 44100: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1269 | case 88200: |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1270 | sysclk = 17640000; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1271 | break; |
Olaya, Margarita | 60ea4ce | 2010-12-10 21:05:58 -0600 | [diff] [blame] | 1272 | case 8000: |
| 1273 | case 16000: |
| 1274 | case 32000: |
| 1275 | case 48000: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1276 | case 96000: |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1277 | sysclk = 19200000; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1278 | break; |
| 1279 | default: |
| 1280 | dev_err(codec->dev, "unsupported rate %d\n", rate); |
| 1281 | return -EINVAL; |
| 1282 | } |
| 1283 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1284 | ret = twl6040_set_pll(twl6040, TWL6040_LPPLL_ID, priv->clk_in, sysclk); |
| 1285 | if (ret) |
| 1286 | return ret; |
| 1287 | |
| 1288 | priv->sysclk = twl6040_get_sysclk(twl6040); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1289 | |
| 1290 | return 0; |
| 1291 | } |
| 1292 | |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1293 | static int twl6040_prepare(struct snd_pcm_substream *substream, |
| 1294 | struct snd_soc_dai *dai) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1295 | { |
| 1296 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1297 | struct snd_soc_codec *codec = rtd->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1298 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1299 | |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1300 | if (!priv->sysclk) { |
| 1301 | dev_err(codec->dev, |
| 1302 | "no mclk configured, call set_sysclk() on init\n"); |
| 1303 | return -EINVAL; |
| 1304 | } |
| 1305 | |
| 1306 | /* |
| 1307 | * capture is not supported at 17.64 MHz, |
| 1308 | * it's reserved for headset low-power playback scenario |
| 1309 | */ |
| 1310 | if ((priv->sysclk == 17640000) && |
| 1311 | substream->stream == SNDRV_PCM_STREAM_CAPTURE) { |
| 1312 | dev_err(codec->dev, |
| 1313 | "capture mode is not supported at %dHz\n", |
| 1314 | priv->sysclk); |
| 1315 | return -EINVAL; |
| 1316 | } |
| 1317 | |
| 1318 | if ((priv->sysclk == 17640000) && priv->non_lp) { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1319 | dev_err(codec->dev, |
| 1320 | "some enabled paths aren't supported at %dHz\n", |
| 1321 | priv->sysclk); |
| 1322 | return -EPERM; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1323 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 1328 | int clk_id, unsigned int freq, int dir) |
| 1329 | { |
| 1330 | struct snd_soc_codec *codec = codec_dai->codec; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1331 | struct twl6040 *twl6040 = codec->control_data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1332 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1333 | int ret = 0; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1334 | |
| 1335 | switch (clk_id) { |
| 1336 | case TWL6040_SYSCLK_SEL_LPPLL: |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1337 | ret = twl6040_set_pll(twl6040, TWL6040_LPPLL_ID, |
| 1338 | freq, priv->sysclk); |
| 1339 | if (ret) |
| 1340 | return ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1341 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1342 | headset_power_mode(codec, 0); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1343 | priv->sysclk_constraints = &lp_constraints; |
| 1344 | break; |
| 1345 | case TWL6040_SYSCLK_SEL_HPPLL: |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1346 | ret = twl6040_set_pll(twl6040, TWL6040_HPPLL_ID, |
| 1347 | freq, priv->sysclk); |
| 1348 | if (ret) |
| 1349 | return ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1350 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1351 | headset_power_mode(codec, 1); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1352 | priv->sysclk_constraints = &hp_constraints; |
| 1353 | break; |
| 1354 | default: |
| 1355 | dev_err(codec->dev, "unknown clk_id %d\n", clk_id); |
| 1356 | return -EINVAL; |
| 1357 | } |
| 1358 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1359 | priv->pll = twl6040_get_pll(twl6040); |
| 1360 | priv->clk_in = freq; |
| 1361 | priv->sysclk = twl6040_get_sysclk(twl6040); |
| 1362 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1363 | return 0; |
| 1364 | } |
| 1365 | |
| 1366 | static struct snd_soc_dai_ops twl6040_dai_ops = { |
| 1367 | .startup = twl6040_startup, |
| 1368 | .hw_params = twl6040_hw_params, |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1369 | .prepare = twl6040_prepare, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1370 | .set_sysclk = twl6040_set_dai_sysclk, |
| 1371 | }; |
| 1372 | |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1373 | static struct snd_soc_dai_driver twl6040_dai[] = { |
| 1374 | { |
| 1375 | .name = "twl6040-ul", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1376 | .capture = { |
| 1377 | .stream_name = "Capture", |
| 1378 | .channels_min = 1, |
| 1379 | .channels_max = 2, |
| 1380 | .rates = TWL6040_RATES, |
| 1381 | .formats = TWL6040_FORMATS, |
| 1382 | }, |
| 1383 | .ops = &twl6040_dai_ops, |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1384 | }, |
| 1385 | { |
| 1386 | .name = "twl6040-dl1", |
| 1387 | .playback = { |
| 1388 | .stream_name = "Headset Playback", |
| 1389 | .channels_min = 1, |
| 1390 | .channels_max = 2, |
| 1391 | .rates = TWL6040_RATES, |
| 1392 | .formats = TWL6040_FORMATS, |
| 1393 | }, |
| 1394 | .ops = &twl6040_dai_ops, |
| 1395 | }, |
| 1396 | { |
| 1397 | .name = "twl6040-dl2", |
| 1398 | .playback = { |
| 1399 | .stream_name = "Handsfree Playback", |
| 1400 | .channels_min = 1, |
| 1401 | .channels_max = 2, |
| 1402 | .rates = TWL6040_RATES, |
| 1403 | .formats = TWL6040_FORMATS, |
| 1404 | }, |
| 1405 | .ops = &twl6040_dai_ops, |
| 1406 | }, |
| 1407 | { |
| 1408 | .name = "twl6040-vib", |
| 1409 | .playback = { |
| 1410 | .stream_name = "Vibra Playback", |
| 1411 | .channels_min = 2, |
| 1412 | .channels_max = 2, |
| 1413 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| 1414 | .formats = TWL6040_FORMATS, |
| 1415 | }, |
| 1416 | .ops = &twl6040_dai_ops, |
| 1417 | }, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1418 | }; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1419 | |
| 1420 | #ifdef CONFIG_PM |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1421 | static int twl6040_suspend(struct snd_soc_codec *codec, pm_message_t state) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1422 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1423 | twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 1424 | |
| 1425 | return 0; |
| 1426 | } |
| 1427 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1428 | static int twl6040_resume(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1429 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1430 | twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Olaya, Margarita | 6c31104 | 2010-12-10 21:05:46 -0600 | [diff] [blame] | 1431 | twl6040_set_bias_level(codec, codec->dapm.suspend_bias_level); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1432 | |
| 1433 | return 0; |
| 1434 | } |
| 1435 | #else |
| 1436 | #define twl6040_suspend NULL |
| 1437 | #define twl6040_resume NULL |
| 1438 | #endif |
| 1439 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1440 | static int twl6040_probe(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1441 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1442 | struct twl6040_data *priv; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1443 | int ret = 0; |
| 1444 | |
| 1445 | priv = kzalloc(sizeof(struct twl6040_data), GFP_KERNEL); |
| 1446 | if (priv == NULL) |
| 1447 | return -ENOMEM; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1448 | snd_soc_codec_set_drvdata(codec, priv); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1449 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1450 | priv->codec = codec; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1451 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1452 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1453 | priv->workqueue = create_singlethread_workqueue("twl6040-codec"); |
Axel Lin | 19aab08 | 2011-03-26 15:53:58 +0800 | [diff] [blame] | 1454 | if (!priv->workqueue) { |
| 1455 | ret = -ENOMEM; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1456 | goto work_err; |
Axel Lin | 19aab08 | 2011-03-26 15:53:58 +0800 | [diff] [blame] | 1457 | } |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1458 | |
| 1459 | INIT_DELAYED_WORK(&priv->delayed_work, twl6040_accessory_work); |
| 1460 | |
| 1461 | mutex_init(&priv->mutex); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1462 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1463 | init_completion(&priv->headset.ramp_done); |
| 1464 | init_completion(&priv->handsfree.ramp_done); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1465 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1466 | priv->hf_workqueue = create_singlethread_workqueue("twl6040-hf"); |
| 1467 | if (priv->hf_workqueue == NULL) { |
| 1468 | ret = -ENOMEM; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1469 | goto hfwq_err; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1470 | } |
| 1471 | priv->hs_workqueue = create_singlethread_workqueue("twl6040-hs"); |
| 1472 | if (priv->hs_workqueue == NULL) { |
| 1473 | ret = -ENOMEM; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1474 | goto hswq_err; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | INIT_DELAYED_WORK(&priv->hs_delayed_work, twl6040_pga_hs_work); |
| 1478 | INIT_DELAYED_WORK(&priv->hf_delayed_work, twl6040_pga_hf_work); |
| 1479 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1480 | ret = twl6040_request_irq(codec->control_data, TWL6040_IRQ_PLUG, |
| 1481 | twl6040_audio_handler, 0, |
| 1482 | "twl6040_irq_plug", codec); |
| 1483 | if (ret) { |
| 1484 | dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret); |
| 1485 | goto plugirq_err; |
| 1486 | } |
| 1487 | |
| 1488 | /* init vio registers */ |
| 1489 | twl6040_init_vio_regs(codec); |
| 1490 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1491 | /* power on device */ |
| 1492 | ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 1493 | if (ret) |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1494 | goto bias_err; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1495 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1496 | snd_soc_add_controls(codec, twl6040_snd_controls, |
| 1497 | ARRAY_SIZE(twl6040_snd_controls)); |
| 1498 | twl6040_add_widgets(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1499 | |
| 1500 | return 0; |
| 1501 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1502 | bias_err: |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1503 | twl6040_free_irq(codec->control_data, TWL6040_IRQ_PLUG, codec); |
| 1504 | plugirq_err: |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1505 | destroy_workqueue(priv->hs_workqueue); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1506 | hswq_err: |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1507 | destroy_workqueue(priv->hf_workqueue); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1508 | hfwq_err: |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1509 | destroy_workqueue(priv->workqueue); |
| 1510 | work_err: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1511 | kfree(priv); |
| 1512 | return ret; |
| 1513 | } |
| 1514 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1515 | static int twl6040_remove(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1516 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1517 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1518 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1519 | twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1520 | twl6040_free_irq(codec->control_data, TWL6040_IRQ_PLUG, codec); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1521 | destroy_workqueue(priv->workqueue); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1522 | destroy_workqueue(priv->hf_workqueue); |
| 1523 | destroy_workqueue(priv->hs_workqueue); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1524 | kfree(priv); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1525 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1526 | return 0; |
| 1527 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1528 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1529 | static struct snd_soc_codec_driver soc_codec_dev_twl6040 = { |
| 1530 | .probe = twl6040_probe, |
| 1531 | .remove = twl6040_remove, |
| 1532 | .suspend = twl6040_suspend, |
| 1533 | .resume = twl6040_resume, |
| 1534 | .read = twl6040_read_reg_cache, |
| 1535 | .write = twl6040_write, |
| 1536 | .set_bias_level = twl6040_set_bias_level, |
| 1537 | .reg_cache_size = ARRAY_SIZE(twl6040_reg), |
| 1538 | .reg_word_size = sizeof(u8), |
| 1539 | .reg_cache_default = twl6040_reg, |
| 1540 | }; |
| 1541 | |
| 1542 | static int __devinit twl6040_codec_probe(struct platform_device *pdev) |
| 1543 | { |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1544 | return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl6040, |
| 1545 | twl6040_dai, ARRAY_SIZE(twl6040_dai)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | static int __devexit twl6040_codec_remove(struct platform_device *pdev) |
| 1549 | { |
| 1550 | snd_soc_unregister_codec(&pdev->dev); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1551 | return 0; |
| 1552 | } |
| 1553 | |
| 1554 | static struct platform_driver twl6040_codec_driver = { |
| 1555 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1556 | .name = "twl6040-codec", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1557 | .owner = THIS_MODULE, |
| 1558 | }, |
| 1559 | .probe = twl6040_codec_probe, |
| 1560 | .remove = __devexit_p(twl6040_codec_remove), |
| 1561 | }; |
| 1562 | |
| 1563 | static int __init twl6040_codec_init(void) |
| 1564 | { |
| 1565 | return platform_driver_register(&twl6040_codec_driver); |
| 1566 | } |
| 1567 | module_init(twl6040_codec_init); |
| 1568 | |
| 1569 | static void __exit twl6040_codec_exit(void) |
| 1570 | { |
| 1571 | platform_driver_unregister(&twl6040_codec_driver); |
| 1572 | } |
| 1573 | module_exit(twl6040_codec_exit); |
| 1574 | |
| 1575 | MODULE_DESCRIPTION("ASoC TWL6040 codec driver"); |
| 1576 | MODULE_AUTHOR("Misael Lopez Cruz"); |
| 1577 | MODULE_LICENSE("GPL"); |