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> |
| 27 | #include <linux/i2c.h> |
| 28 | #include <linux/gpio.h> |
| 29 | #include <linux/platform_device.h> |
Stephen Rothwell | 68b40cc | 2010-03-29 17:55:51 +1100 | [diff] [blame] | 30 | #include <linux/slab.h> |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 31 | #include <linux/i2c/twl.h> |
| 32 | |
| 33 | #include <sound/core.h> |
| 34 | #include <sound/pcm.h> |
| 35 | #include <sound/pcm_params.h> |
| 36 | #include <sound/soc.h> |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 37 | #include <sound/initval.h> |
| 38 | #include <sound/tlv.h> |
| 39 | |
| 40 | #include "twl6040.h" |
| 41 | |
| 42 | #define TWL6040_RATES (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) |
| 43 | #define TWL6040_FORMATS (SNDRV_PCM_FMTBIT_S32_LE) |
| 44 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 45 | struct twl6040_jack_data { |
| 46 | struct snd_soc_jack *jack; |
| 47 | int report; |
| 48 | }; |
| 49 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 50 | /* codec private data */ |
| 51 | struct twl6040_data { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 52 | int audpwron; |
| 53 | int naudint; |
| 54 | int codec_powered; |
| 55 | int pll; |
| 56 | int non_lp; |
| 57 | unsigned int sysclk; |
| 58 | struct snd_pcm_hw_constraint_list *sysclk_constraints; |
| 59 | struct completion ready; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 60 | struct twl6040_jack_data hs_jack; |
| 61 | struct snd_soc_codec *codec; |
| 62 | struct workqueue_struct *workqueue; |
| 63 | struct delayed_work delayed_work; |
| 64 | struct mutex mutex; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | /* |
| 68 | * twl6040 register cache & default register settings |
| 69 | */ |
| 70 | static const u8 twl6040_reg[TWL6040_CACHEREGNUM] = { |
| 71 | 0x00, /* not used 0x00 */ |
| 72 | 0x4B, /* TWL6040_ASICID (ro) 0x01 */ |
| 73 | 0x00, /* TWL6040_ASICREV (ro) 0x02 */ |
| 74 | 0x00, /* TWL6040_INTID 0x03 */ |
| 75 | 0x00, /* TWL6040_INTMR 0x04 */ |
| 76 | 0x00, /* TWL6040_NCPCTRL 0x05 */ |
| 77 | 0x00, /* TWL6040_LDOCTL 0x06 */ |
| 78 | 0x60, /* TWL6040_HPPLLCTL 0x07 */ |
| 79 | 0x00, /* TWL6040_LPPLLCTL 0x08 */ |
| 80 | 0x4A, /* TWL6040_LPPLLDIV 0x09 */ |
| 81 | 0x00, /* TWL6040_AMICBCTL 0x0A */ |
| 82 | 0x00, /* TWL6040_DMICBCTL 0x0B */ |
| 83 | 0x18, /* TWL6040_MICLCTL 0x0C - No input selected on Left Mic */ |
| 84 | 0x18, /* TWL6040_MICRCTL 0x0D - No input selected on Right Mic */ |
| 85 | 0x00, /* TWL6040_MICGAIN 0x0E */ |
| 86 | 0x1B, /* TWL6040_LINEGAIN 0x0F */ |
| 87 | 0x00, /* TWL6040_HSLCTL 0x10 */ |
| 88 | 0x00, /* TWL6040_HSRCTL 0x11 */ |
| 89 | 0x00, /* TWL6040_HSGAIN 0x12 */ |
| 90 | 0x00, /* TWL6040_EARCTL 0x13 */ |
| 91 | 0x00, /* TWL6040_HFLCTL 0x14 */ |
| 92 | 0x00, /* TWL6040_HFLGAIN 0x15 */ |
| 93 | 0x00, /* TWL6040_HFRCTL 0x16 */ |
| 94 | 0x00, /* TWL6040_HFRGAIN 0x17 */ |
| 95 | 0x00, /* TWL6040_VIBCTLL 0x18 */ |
| 96 | 0x00, /* TWL6040_VIBDATL 0x19 */ |
| 97 | 0x00, /* TWL6040_VIBCTLR 0x1A */ |
| 98 | 0x00, /* TWL6040_VIBDATR 0x1B */ |
| 99 | 0x00, /* TWL6040_HKCTL1 0x1C */ |
| 100 | 0x00, /* TWL6040_HKCTL2 0x1D */ |
| 101 | 0x00, /* TWL6040_GPOCTL 0x1E */ |
| 102 | 0x00, /* TWL6040_ALB 0x1F */ |
| 103 | 0x00, /* TWL6040_DLB 0x20 */ |
| 104 | 0x00, /* not used 0x21 */ |
| 105 | 0x00, /* not used 0x22 */ |
| 106 | 0x00, /* not used 0x23 */ |
| 107 | 0x00, /* not used 0x24 */ |
| 108 | 0x00, /* not used 0x25 */ |
| 109 | 0x00, /* not used 0x26 */ |
| 110 | 0x00, /* not used 0x27 */ |
| 111 | 0x00, /* TWL6040_TRIM1 0x28 */ |
| 112 | 0x00, /* TWL6040_TRIM2 0x29 */ |
| 113 | 0x00, /* TWL6040_TRIM3 0x2A */ |
| 114 | 0x00, /* TWL6040_HSOTRIM 0x2B */ |
| 115 | 0x00, /* TWL6040_HFOTRIM 0x2C */ |
| 116 | 0x09, /* TWL6040_ACCCTL 0x2D */ |
| 117 | 0x00, /* TWL6040_STATUS (ro) 0x2E */ |
| 118 | }; |
| 119 | |
| 120 | /* |
| 121 | * twl6040 vio/gnd registers: |
| 122 | * registers under vio/gnd supply can be accessed |
| 123 | * before the power-up sequence, after NRESPWRON goes high |
| 124 | */ |
| 125 | static const int twl6040_vio_reg[TWL6040_VIOREGNUM] = { |
| 126 | TWL6040_REG_ASICID, |
| 127 | TWL6040_REG_ASICREV, |
| 128 | TWL6040_REG_INTID, |
| 129 | TWL6040_REG_INTMR, |
| 130 | TWL6040_REG_NCPCTL, |
| 131 | TWL6040_REG_LDOCTL, |
| 132 | TWL6040_REG_AMICBCTL, |
| 133 | TWL6040_REG_DMICBCTL, |
| 134 | TWL6040_REG_HKCTL1, |
| 135 | TWL6040_REG_HKCTL2, |
| 136 | TWL6040_REG_GPOCTL, |
| 137 | TWL6040_REG_TRIM1, |
| 138 | TWL6040_REG_TRIM2, |
| 139 | TWL6040_REG_TRIM3, |
| 140 | TWL6040_REG_HSOTRIM, |
| 141 | TWL6040_REG_HFOTRIM, |
| 142 | TWL6040_REG_ACCCTL, |
| 143 | TWL6040_REG_STATUS, |
| 144 | }; |
| 145 | |
| 146 | /* |
| 147 | * twl6040 vdd/vss registers: |
| 148 | * registers under vdd/vss supplies can only be accessed |
| 149 | * after the power-up sequence |
| 150 | */ |
| 151 | static const int twl6040_vdd_reg[TWL6040_VDDREGNUM] = { |
| 152 | TWL6040_REG_HPPLLCTL, |
| 153 | TWL6040_REG_LPPLLCTL, |
| 154 | TWL6040_REG_LPPLLDIV, |
| 155 | TWL6040_REG_MICLCTL, |
| 156 | TWL6040_REG_MICRCTL, |
| 157 | TWL6040_REG_MICGAIN, |
| 158 | TWL6040_REG_LINEGAIN, |
| 159 | TWL6040_REG_HSLCTL, |
| 160 | TWL6040_REG_HSRCTL, |
| 161 | TWL6040_REG_HSGAIN, |
| 162 | TWL6040_REG_EARCTL, |
| 163 | TWL6040_REG_HFLCTL, |
| 164 | TWL6040_REG_HFLGAIN, |
| 165 | TWL6040_REG_HFRCTL, |
| 166 | TWL6040_REG_HFRGAIN, |
| 167 | TWL6040_REG_VIBCTLL, |
| 168 | TWL6040_REG_VIBDATL, |
| 169 | TWL6040_REG_VIBCTLR, |
| 170 | TWL6040_REG_VIBDATR, |
| 171 | TWL6040_REG_ALB, |
| 172 | TWL6040_REG_DLB, |
| 173 | }; |
| 174 | |
| 175 | /* |
| 176 | * read twl6040 register cache |
| 177 | */ |
| 178 | static inline unsigned int twl6040_read_reg_cache(struct snd_soc_codec *codec, |
| 179 | unsigned int reg) |
| 180 | { |
| 181 | u8 *cache = codec->reg_cache; |
| 182 | |
| 183 | if (reg >= TWL6040_CACHEREGNUM) |
| 184 | return -EIO; |
| 185 | |
| 186 | return cache[reg]; |
| 187 | } |
| 188 | |
| 189 | /* |
| 190 | * write twl6040 register cache |
| 191 | */ |
| 192 | static inline void twl6040_write_reg_cache(struct snd_soc_codec *codec, |
| 193 | u8 reg, u8 value) |
| 194 | { |
| 195 | u8 *cache = codec->reg_cache; |
| 196 | |
| 197 | if (reg >= TWL6040_CACHEREGNUM) |
| 198 | return; |
| 199 | cache[reg] = value; |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | * read from twl6040 hardware register |
| 204 | */ |
| 205 | static int twl6040_read_reg_volatile(struct snd_soc_codec *codec, |
| 206 | unsigned int reg) |
| 207 | { |
| 208 | u8 value; |
| 209 | |
| 210 | if (reg >= TWL6040_CACHEREGNUM) |
| 211 | return -EIO; |
| 212 | |
Olaya, Margarita | 0dec1ec | 2010-12-10 21:05:24 -0600 | [diff] [blame] | 213 | twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &value, reg); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 214 | twl6040_write_reg_cache(codec, reg, value); |
| 215 | |
| 216 | return value; |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | * write to the twl6040 register space |
| 221 | */ |
| 222 | static int twl6040_write(struct snd_soc_codec *codec, |
| 223 | unsigned int reg, unsigned int value) |
| 224 | { |
| 225 | if (reg >= TWL6040_CACHEREGNUM) |
| 226 | return -EIO; |
| 227 | |
| 228 | twl6040_write_reg_cache(codec, reg, value); |
Olaya, Margarita | 0dec1ec | 2010-12-10 21:05:24 -0600 | [diff] [blame] | 229 | return twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, value, reg); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | static void twl6040_init_vio_regs(struct snd_soc_codec *codec) |
| 233 | { |
| 234 | u8 *cache = codec->reg_cache; |
| 235 | int reg, i; |
| 236 | |
| 237 | /* allow registers to be accessed by i2c */ |
| 238 | twl6040_write(codec, TWL6040_REG_ACCCTL, cache[TWL6040_REG_ACCCTL]); |
| 239 | |
| 240 | for (i = 0; i < TWL6040_VIOREGNUM; i++) { |
| 241 | reg = twl6040_vio_reg[i]; |
| 242 | /* skip read-only registers (ASICID, ASICREV, STATUS) */ |
| 243 | switch (reg) { |
| 244 | case TWL6040_REG_ASICID: |
| 245 | case TWL6040_REG_ASICREV: |
| 246 | case TWL6040_REG_STATUS: |
| 247 | continue; |
| 248 | default: |
| 249 | break; |
| 250 | } |
| 251 | twl6040_write(codec, reg, cache[reg]); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | static void twl6040_init_vdd_regs(struct snd_soc_codec *codec) |
| 256 | { |
| 257 | u8 *cache = codec->reg_cache; |
| 258 | int reg, i; |
| 259 | |
| 260 | for (i = 0; i < TWL6040_VDDREGNUM; i++) { |
| 261 | reg = twl6040_vdd_reg[i]; |
| 262 | twl6040_write(codec, reg, cache[reg]); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /* twl6040 codec manual power-up sequence */ |
| 267 | static void twl6040_power_up(struct snd_soc_codec *codec) |
| 268 | { |
| 269 | u8 ncpctl, ldoctl, lppllctl, accctl; |
| 270 | |
| 271 | ncpctl = twl6040_read_reg_cache(codec, TWL6040_REG_NCPCTL); |
| 272 | ldoctl = twl6040_read_reg_cache(codec, TWL6040_REG_LDOCTL); |
| 273 | lppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_LPPLLCTL); |
| 274 | accctl = twl6040_read_reg_cache(codec, TWL6040_REG_ACCCTL); |
| 275 | |
| 276 | /* enable reference system */ |
| 277 | ldoctl |= TWL6040_REFENA; |
| 278 | twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl); |
| 279 | msleep(10); |
| 280 | /* enable internal oscillator */ |
| 281 | ldoctl |= TWL6040_OSCENA; |
| 282 | twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl); |
| 283 | udelay(10); |
| 284 | /* enable high-side ldo */ |
| 285 | ldoctl |= TWL6040_HSLDOENA; |
| 286 | twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl); |
| 287 | udelay(244); |
| 288 | /* enable negative charge pump */ |
| 289 | ncpctl |= TWL6040_NCPENA | TWL6040_NCPOPEN; |
| 290 | twl6040_write(codec, TWL6040_REG_NCPCTL, ncpctl); |
| 291 | udelay(488); |
| 292 | /* enable low-side ldo */ |
| 293 | ldoctl |= TWL6040_LSLDOENA; |
| 294 | twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl); |
| 295 | udelay(244); |
| 296 | /* enable low-power pll */ |
| 297 | lppllctl |= TWL6040_LPLLENA; |
| 298 | twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl); |
| 299 | /* reset state machine */ |
| 300 | accctl |= TWL6040_RESETSPLIT; |
| 301 | twl6040_write(codec, TWL6040_REG_ACCCTL, accctl); |
| 302 | mdelay(5); |
| 303 | accctl &= ~TWL6040_RESETSPLIT; |
| 304 | twl6040_write(codec, TWL6040_REG_ACCCTL, accctl); |
| 305 | /* disable internal oscillator */ |
| 306 | ldoctl &= ~TWL6040_OSCENA; |
| 307 | twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl); |
| 308 | } |
| 309 | |
| 310 | /* twl6040 codec manual power-down sequence */ |
| 311 | static void twl6040_power_down(struct snd_soc_codec *codec) |
| 312 | { |
| 313 | u8 ncpctl, ldoctl, lppllctl, accctl; |
| 314 | |
| 315 | ncpctl = twl6040_read_reg_cache(codec, TWL6040_REG_NCPCTL); |
| 316 | ldoctl = twl6040_read_reg_cache(codec, TWL6040_REG_LDOCTL); |
| 317 | lppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_LPPLLCTL); |
| 318 | accctl = twl6040_read_reg_cache(codec, TWL6040_REG_ACCCTL); |
| 319 | |
| 320 | /* enable internal oscillator */ |
| 321 | ldoctl |= TWL6040_OSCENA; |
| 322 | twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl); |
| 323 | udelay(10); |
| 324 | /* disable low-power pll */ |
| 325 | lppllctl &= ~TWL6040_LPLLENA; |
| 326 | twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl); |
| 327 | /* disable low-side ldo */ |
| 328 | ldoctl &= ~TWL6040_LSLDOENA; |
| 329 | twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl); |
| 330 | udelay(244); |
| 331 | /* disable negative charge pump */ |
| 332 | ncpctl &= ~(TWL6040_NCPENA | TWL6040_NCPOPEN); |
| 333 | twl6040_write(codec, TWL6040_REG_NCPCTL, ncpctl); |
| 334 | udelay(488); |
| 335 | /* disable high-side ldo */ |
| 336 | ldoctl &= ~TWL6040_HSLDOENA; |
| 337 | twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl); |
| 338 | udelay(244); |
| 339 | /* disable internal oscillator */ |
| 340 | ldoctl &= ~TWL6040_OSCENA; |
| 341 | twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl); |
| 342 | /* disable reference system */ |
| 343 | ldoctl &= ~TWL6040_REFENA; |
| 344 | twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl); |
| 345 | msleep(10); |
| 346 | } |
| 347 | |
| 348 | /* set headset dac and driver power mode */ |
| 349 | static int headset_power_mode(struct snd_soc_codec *codec, int high_perf) |
| 350 | { |
| 351 | int hslctl, hsrctl; |
| 352 | int mask = TWL6040_HSDRVMODEL | TWL6040_HSDACMODEL; |
| 353 | |
| 354 | hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL); |
| 355 | hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL); |
| 356 | |
| 357 | if (high_perf) { |
| 358 | hslctl &= ~mask; |
| 359 | hsrctl &= ~mask; |
| 360 | } else { |
| 361 | hslctl |= mask; |
| 362 | hsrctl |= mask; |
| 363 | } |
| 364 | |
| 365 | twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl); |
| 366 | twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl); |
| 367 | |
| 368 | return 0; |
| 369 | } |
| 370 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 371 | static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w, |
| 372 | struct snd_kcontrol *kcontrol, int event) |
| 373 | { |
| 374 | msleep(1); |
| 375 | return 0; |
| 376 | } |
| 377 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 378 | static int twl6040_power_mode_event(struct snd_soc_dapm_widget *w, |
| 379 | struct snd_kcontrol *kcontrol, int event) |
| 380 | { |
| 381 | struct snd_soc_codec *codec = w->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 382 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 383 | |
| 384 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 385 | priv->non_lp++; |
| 386 | else |
| 387 | priv->non_lp--; |
| 388 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 389 | msleep(1); |
| 390 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 391 | return 0; |
| 392 | } |
| 393 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 394 | void twl6040_hs_jack_report(struct snd_soc_codec *codec, |
| 395 | struct snd_soc_jack *jack, int report) |
| 396 | { |
| 397 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 398 | int status; |
| 399 | |
| 400 | mutex_lock(&priv->mutex); |
| 401 | |
| 402 | /* Sync status */ |
| 403 | status = twl6040_read_reg_volatile(codec, TWL6040_REG_STATUS); |
| 404 | if (status & TWL6040_PLUGCOMP) |
| 405 | snd_soc_jack_report(jack, report, report); |
| 406 | else |
| 407 | snd_soc_jack_report(jack, 0, report); |
| 408 | |
| 409 | mutex_unlock(&priv->mutex); |
| 410 | } |
| 411 | |
| 412 | void twl6040_hs_jack_detect(struct snd_soc_codec *codec, |
| 413 | struct snd_soc_jack *jack, int report) |
| 414 | { |
| 415 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 416 | struct twl6040_jack_data *hs_jack = &priv->hs_jack; |
| 417 | |
| 418 | hs_jack->jack = jack; |
| 419 | hs_jack->report = report; |
| 420 | |
| 421 | twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report); |
| 422 | } |
| 423 | EXPORT_SYMBOL_GPL(twl6040_hs_jack_detect); |
| 424 | |
| 425 | static void twl6040_accessory_work(struct work_struct *work) |
| 426 | { |
| 427 | struct twl6040_data *priv = container_of(work, |
| 428 | struct twl6040_data, delayed_work.work); |
| 429 | struct snd_soc_codec *codec = priv->codec; |
| 430 | struct twl6040_jack_data *hs_jack = &priv->hs_jack; |
| 431 | |
| 432 | twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report); |
| 433 | } |
| 434 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 435 | /* audio interrupt handler */ |
| 436 | static irqreturn_t twl6040_naudint_handler(int irq, void *data) |
| 437 | { |
| 438 | struct snd_soc_codec *codec = data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 439 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 440 | u8 intid; |
| 441 | |
Olaya, Margarita | 0dec1ec | 2010-12-10 21:05:24 -0600 | [diff] [blame] | 442 | twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &intid, TWL6040_REG_INTID); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 443 | |
Olaya, Margarita | cf370a5 | 2010-12-10 21:05:30 -0600 | [diff] [blame] | 444 | if (intid & TWL6040_THINT) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 445 | dev_alert(codec->dev, "die temp over-limit detection\n"); |
Olaya, Margarita | cf370a5 | 2010-12-10 21:05:30 -0600 | [diff] [blame] | 446 | |
| 447 | if ((intid & TWL6040_PLUGINT) || (intid & TWL6040_UNPLUGINT)) |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 448 | queue_delayed_work(priv->workqueue, &priv->delayed_work, |
| 449 | msecs_to_jiffies(200)); |
Olaya, Margarita | cf370a5 | 2010-12-10 21:05:30 -0600 | [diff] [blame] | 450 | |
| 451 | if (intid & TWL6040_HOOKINT) |
| 452 | dev_info(codec->dev, "hook detection\n"); |
| 453 | |
| 454 | if (intid & TWL6040_HFINT) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 455 | dev_alert(codec->dev, "hf drivers over current detection\n"); |
Olaya, Margarita | cf370a5 | 2010-12-10 21:05:30 -0600 | [diff] [blame] | 456 | |
| 457 | if (intid & TWL6040_VIBINT) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 458 | dev_alert(codec->dev, "vib drivers over current detection\n"); |
Olaya, Margarita | cf370a5 | 2010-12-10 21:05:30 -0600 | [diff] [blame] | 459 | |
| 460 | if (intid & TWL6040_READYINT) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 461 | complete(&priv->ready); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 462 | |
| 463 | return IRQ_HANDLED; |
| 464 | } |
| 465 | |
| 466 | /* |
| 467 | * MICATT volume control: |
| 468 | * from -6 to 0 dB in 6 dB steps |
| 469 | */ |
| 470 | static DECLARE_TLV_DB_SCALE(mic_preamp_tlv, -600, 600, 0); |
| 471 | |
| 472 | /* |
| 473 | * MICGAIN volume control: |
| 474 | * from 6 to 30 dB in 6 dB steps |
| 475 | */ |
| 476 | static DECLARE_TLV_DB_SCALE(mic_amp_tlv, 600, 600, 0); |
| 477 | |
| 478 | /* |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 479 | * AFMGAIN volume control: |
| 480 | * from 18 to 24 dB in 6 dB steps |
| 481 | */ |
| 482 | static DECLARE_TLV_DB_SCALE(afm_amp_tlv, 1800, 600, 0); |
| 483 | |
| 484 | /* |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 485 | * HSGAIN volume control: |
| 486 | * from -30 to 0 dB in 2 dB steps |
| 487 | */ |
| 488 | static DECLARE_TLV_DB_SCALE(hs_tlv, -3000, 200, 0); |
| 489 | |
| 490 | /* |
| 491 | * HFGAIN volume control: |
| 492 | * from -52 to 6 dB in 2 dB steps |
| 493 | */ |
| 494 | static DECLARE_TLV_DB_SCALE(hf_tlv, -5200, 200, 0); |
| 495 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 496 | /* |
| 497 | * EPGAIN volume control: |
| 498 | * from -24 to 6 dB in 2 dB steps |
| 499 | */ |
| 500 | static DECLARE_TLV_DB_SCALE(ep_tlv, -2400, 200, 0); |
| 501 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 502 | /* Left analog microphone selection */ |
| 503 | static const char *twl6040_amicl_texts[] = |
| 504 | {"Headset Mic", "Main Mic", "Aux/FM Left", "Off"}; |
| 505 | |
| 506 | /* Right analog microphone selection */ |
| 507 | static const char *twl6040_amicr_texts[] = |
| 508 | {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"}; |
| 509 | |
| 510 | static const struct soc_enum twl6040_enum[] = { |
| 511 | SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3, 3, twl6040_amicl_texts), |
| 512 | SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3, 3, twl6040_amicr_texts), |
| 513 | }; |
| 514 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 515 | static const char *twl6040_hs_texts[] = { |
| 516 | "Off", "HS DAC", "Line-In amp" |
| 517 | }; |
| 518 | |
| 519 | static const struct soc_enum twl6040_hs_enum[] = { |
| 520 | SOC_ENUM_SINGLE(TWL6040_REG_HSLCTL, 5, ARRAY_SIZE(twl6040_hs_texts), |
| 521 | twl6040_hs_texts), |
| 522 | SOC_ENUM_SINGLE(TWL6040_REG_HSRCTL, 5, ARRAY_SIZE(twl6040_hs_texts), |
| 523 | twl6040_hs_texts), |
| 524 | }; |
| 525 | |
| 526 | static const char *twl6040_hf_texts[] = { |
| 527 | "Off", "HF DAC", "Line-In amp" |
| 528 | }; |
| 529 | |
| 530 | static const struct soc_enum twl6040_hf_enum[] = { |
| 531 | SOC_ENUM_SINGLE(TWL6040_REG_HFLCTL, 2, ARRAY_SIZE(twl6040_hf_texts), |
| 532 | twl6040_hf_texts), |
| 533 | SOC_ENUM_SINGLE(TWL6040_REG_HFRCTL, 2, ARRAY_SIZE(twl6040_hf_texts), |
| 534 | twl6040_hf_texts), |
| 535 | }; |
| 536 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 537 | static const struct snd_kcontrol_new amicl_control = |
| 538 | SOC_DAPM_ENUM("Route", twl6040_enum[0]); |
| 539 | |
| 540 | static const struct snd_kcontrol_new amicr_control = |
| 541 | SOC_DAPM_ENUM("Route", twl6040_enum[1]); |
| 542 | |
| 543 | /* Headset DAC playback switches */ |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 544 | static const struct snd_kcontrol_new hsl_mux_controls = |
| 545 | SOC_DAPM_ENUM("Route", twl6040_hs_enum[0]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 546 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 547 | static const struct snd_kcontrol_new hsr_mux_controls = |
| 548 | SOC_DAPM_ENUM("Route", twl6040_hs_enum[1]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 549 | |
| 550 | /* Handsfree DAC playback switches */ |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 551 | static const struct snd_kcontrol_new hfl_mux_controls = |
| 552 | SOC_DAPM_ENUM("Route", twl6040_hf_enum[0]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 553 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 554 | static const struct snd_kcontrol_new hfr_mux_controls = |
| 555 | SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 556 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 557 | static const struct snd_kcontrol_new ep_driver_switch_controls = |
| 558 | SOC_DAPM_SINGLE("Switch", TWL6040_REG_EARCTL, 0, 1, 0); |
| 559 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 560 | static const struct snd_kcontrol_new twl6040_snd_controls[] = { |
| 561 | /* Capture gains */ |
| 562 | SOC_DOUBLE_TLV("Capture Preamplifier Volume", |
| 563 | TWL6040_REG_MICGAIN, 6, 7, 1, 1, mic_preamp_tlv), |
| 564 | SOC_DOUBLE_TLV("Capture Volume", |
| 565 | TWL6040_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv), |
| 566 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 567 | /* AFM gains */ |
| 568 | SOC_DOUBLE_TLV("Aux FM Volume", |
| 569 | TWL6040_REG_LINEGAIN, 0, 5, 0xF, 0, afm_amp_tlv), |
| 570 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 571 | /* Playback gains */ |
| 572 | SOC_DOUBLE_TLV("Headset Playback Volume", |
| 573 | TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv), |
| 574 | SOC_DOUBLE_R_TLV("Handsfree Playback Volume", |
| 575 | TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 576 | SOC_SINGLE_TLV("Earphone Playback Volume", |
| 577 | TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 578 | }; |
| 579 | |
| 580 | static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = { |
| 581 | /* Inputs */ |
| 582 | SND_SOC_DAPM_INPUT("MAINMIC"), |
| 583 | SND_SOC_DAPM_INPUT("HSMIC"), |
| 584 | SND_SOC_DAPM_INPUT("SUBMIC"), |
| 585 | SND_SOC_DAPM_INPUT("AFML"), |
| 586 | SND_SOC_DAPM_INPUT("AFMR"), |
| 587 | |
| 588 | /* Outputs */ |
| 589 | SND_SOC_DAPM_OUTPUT("HSOL"), |
| 590 | SND_SOC_DAPM_OUTPUT("HSOR"), |
| 591 | SND_SOC_DAPM_OUTPUT("HFL"), |
| 592 | SND_SOC_DAPM_OUTPUT("HFR"), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 593 | SND_SOC_DAPM_OUTPUT("EP"), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 594 | |
| 595 | /* Analog input muxes for the capture amplifiers */ |
| 596 | SND_SOC_DAPM_MUX("Analog Left Capture Route", |
| 597 | SND_SOC_NOPM, 0, 0, &amicl_control), |
| 598 | SND_SOC_DAPM_MUX("Analog Right Capture Route", |
| 599 | SND_SOC_NOPM, 0, 0, &amicr_control), |
| 600 | |
| 601 | /* Analog capture PGAs */ |
| 602 | SND_SOC_DAPM_PGA("MicAmpL", |
| 603 | TWL6040_REG_MICLCTL, 0, 0, NULL, 0), |
| 604 | SND_SOC_DAPM_PGA("MicAmpR", |
| 605 | TWL6040_REG_MICRCTL, 0, 0, NULL, 0), |
| 606 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 607 | /* Auxiliary FM PGAs */ |
| 608 | SND_SOC_DAPM_PGA("AFMAmpL", |
| 609 | TWL6040_REG_MICLCTL, 1, 0, NULL, 0), |
| 610 | SND_SOC_DAPM_PGA("AFMAmpR", |
| 611 | TWL6040_REG_MICRCTL, 1, 0, NULL, 0), |
| 612 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 613 | /* ADCs */ |
| 614 | SND_SOC_DAPM_ADC("ADC Left", "Left Front Capture", |
| 615 | TWL6040_REG_MICLCTL, 2, 0), |
| 616 | SND_SOC_DAPM_ADC("ADC Right", "Right Front Capture", |
| 617 | TWL6040_REG_MICRCTL, 2, 0), |
| 618 | |
| 619 | /* Microphone bias */ |
| 620 | SND_SOC_DAPM_MICBIAS("Headset Mic Bias", |
| 621 | TWL6040_REG_AMICBCTL, 0, 0), |
| 622 | SND_SOC_DAPM_MICBIAS("Main Mic Bias", |
| 623 | TWL6040_REG_AMICBCTL, 4, 0), |
| 624 | SND_SOC_DAPM_MICBIAS("Digital Mic1 Bias", |
| 625 | TWL6040_REG_DMICBCTL, 0, 0), |
| 626 | SND_SOC_DAPM_MICBIAS("Digital Mic2 Bias", |
| 627 | TWL6040_REG_DMICBCTL, 4, 0), |
| 628 | |
| 629 | /* DACs */ |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 630 | SND_SOC_DAPM_DAC_E("HSDAC Left", "Headset Playback", |
| 631 | TWL6040_REG_HSLCTL, 0, 0, |
| 632 | twl6040_hs_dac_event, |
| 633 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 634 | SND_SOC_DAPM_DAC_E("HSDAC Right", "Headset Playback", |
| 635 | TWL6040_REG_HSRCTL, 0, 0, |
| 636 | twl6040_hs_dac_event, |
| 637 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 638 | SND_SOC_DAPM_DAC_E("HFDAC Left", "Handsfree Playback", |
| 639 | TWL6040_REG_HFLCTL, 0, 0, |
| 640 | twl6040_power_mode_event, |
| 641 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 642 | SND_SOC_DAPM_DAC_E("HFDAC Right", "Handsfree Playback", |
| 643 | TWL6040_REG_HFRCTL, 0, 0, |
| 644 | twl6040_power_mode_event, |
| 645 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 646 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 647 | SND_SOC_DAPM_MUX("HF Left Playback", |
| 648 | SND_SOC_NOPM, 0, 0, &hfl_mux_controls), |
| 649 | SND_SOC_DAPM_MUX("HF Right Playback", |
| 650 | SND_SOC_NOPM, 0, 0, &hfr_mux_controls), |
| 651 | /* Analog playback Muxes */ |
| 652 | SND_SOC_DAPM_MUX("HS Left Playback", |
| 653 | SND_SOC_NOPM, 0, 0, &hsl_mux_controls), |
| 654 | SND_SOC_DAPM_MUX("HS Right Playback", |
| 655 | SND_SOC_NOPM, 0, 0, &hsr_mux_controls), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 656 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 657 | /* Analog playback drivers */ |
| 658 | SND_SOC_DAPM_PGA_E("Handsfree Left Driver", |
| 659 | TWL6040_REG_HFLCTL, 4, 0, NULL, 0, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 660 | twl6040_power_mode_event, |
| 661 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 662 | SND_SOC_DAPM_PGA_E("Handsfree Right Driver", |
| 663 | TWL6040_REG_HFRCTL, 4, 0, NULL, 0, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 664 | twl6040_power_mode_event, |
| 665 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 666 | SND_SOC_DAPM_PGA("Headset Left Driver", |
| 667 | TWL6040_REG_HSLCTL, 2, 0, NULL, 0), |
| 668 | SND_SOC_DAPM_PGA("Headset Right Driver", |
| 669 | TWL6040_REG_HSRCTL, 2, 0, NULL, 0), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 670 | SND_SOC_DAPM_SWITCH_E("Earphone Driver", |
| 671 | SND_SOC_NOPM, 0, 0, &ep_driver_switch_controls, |
| 672 | twl6040_power_mode_event, |
| 673 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 674 | |
| 675 | /* Analog playback PGAs */ |
| 676 | SND_SOC_DAPM_PGA("HFDAC Left PGA", |
| 677 | TWL6040_REG_HFLCTL, 1, 0, NULL, 0), |
| 678 | SND_SOC_DAPM_PGA("HFDAC Right PGA", |
| 679 | TWL6040_REG_HFRCTL, 1, 0, NULL, 0), |
| 680 | |
| 681 | }; |
| 682 | |
| 683 | static const struct snd_soc_dapm_route intercon[] = { |
| 684 | /* Capture path */ |
| 685 | {"Analog Left Capture Route", "Headset Mic", "HSMIC"}, |
| 686 | {"Analog Left Capture Route", "Main Mic", "MAINMIC"}, |
| 687 | {"Analog Left Capture Route", "Aux/FM Left", "AFML"}, |
| 688 | |
| 689 | {"Analog Right Capture Route", "Headset Mic", "HSMIC"}, |
| 690 | {"Analog Right Capture Route", "Sub Mic", "SUBMIC"}, |
| 691 | {"Analog Right Capture Route", "Aux/FM Right", "AFMR"}, |
| 692 | |
| 693 | {"MicAmpL", NULL, "Analog Left Capture Route"}, |
| 694 | {"MicAmpR", NULL, "Analog Right Capture Route"}, |
| 695 | |
| 696 | {"ADC Left", NULL, "MicAmpL"}, |
| 697 | {"ADC Right", NULL, "MicAmpR"}, |
| 698 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 699 | /* AFM path */ |
| 700 | {"AFMAmpL", "NULL", "AFML"}, |
| 701 | {"AFMAmpR", "NULL", "AFMR"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 702 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 703 | {"HS Left Playback", "HS DAC", "HSDAC Left"}, |
| 704 | {"HS Left Playback", "Line-In amp", "AFMAmpL"}, |
| 705 | |
| 706 | {"HS Right Playback", "HS DAC", "HSDAC Right"}, |
| 707 | {"HS Right Playback", "Line-In amp", "AFMAmpR"}, |
| 708 | |
| 709 | {"Headset Left Driver", "NULL", "HS Left Playback"}, |
| 710 | {"Headset Right Driver", "NULL", "HS Right Playback"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 711 | |
| 712 | {"HSOL", NULL, "Headset Left Driver"}, |
| 713 | {"HSOR", NULL, "Headset Right Driver"}, |
| 714 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 715 | /* Earphone playback path */ |
| 716 | {"Earphone Driver", "Switch", "HSDAC Left"}, |
| 717 | {"EP", NULL, "Earphone Driver"}, |
| 718 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 719 | {"HF Left Playback", "HF DAC", "HFDAC Left"}, |
| 720 | {"HF Left Playback", "Line-In amp", "AFMAmpL"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 721 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 722 | {"HF Right Playback", "HF DAC", "HFDAC Right"}, |
| 723 | {"HF Right Playback", "Line-In amp", "AFMAmpR"}, |
| 724 | |
| 725 | {"HFDAC Left PGA", NULL, "HF Left Playback"}, |
| 726 | {"HFDAC Right PGA", NULL, "HF Right Playback"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 727 | |
| 728 | {"Handsfree Left Driver", "Switch", "HFDAC Left PGA"}, |
| 729 | {"Handsfree Right Driver", "Switch", "HFDAC Right PGA"}, |
| 730 | |
| 731 | {"HFL", NULL, "Handsfree Left Driver"}, |
| 732 | {"HFR", NULL, "Handsfree Right Driver"}, |
| 733 | }; |
| 734 | |
| 735 | static int twl6040_add_widgets(struct snd_soc_codec *codec) |
| 736 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 737 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 738 | |
| 739 | snd_soc_dapm_new_controls(dapm, twl6040_dapm_widgets, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 740 | ARRAY_SIZE(twl6040_dapm_widgets)); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 741 | snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon)); |
| 742 | snd_soc_dapm_new_widgets(dapm); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 743 | |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | static int twl6040_power_up_completion(struct snd_soc_codec *codec, |
| 748 | int naudint) |
| 749 | { |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 750 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 751 | int time_left; |
| 752 | u8 intid; |
| 753 | |
| 754 | time_left = wait_for_completion_timeout(&priv->ready, |
| 755 | msecs_to_jiffies(48)); |
| 756 | |
| 757 | if (!time_left) { |
Olaya, Margarita | 0dec1ec | 2010-12-10 21:05:24 -0600 | [diff] [blame] | 758 | twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &intid, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 759 | TWL6040_REG_INTID); |
| 760 | if (!(intid & TWL6040_READYINT)) { |
| 761 | dev_err(codec->dev, "timeout waiting for READYINT\n"); |
| 762 | return -ETIMEDOUT; |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | priv->codec_powered = 1; |
| 767 | |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | static int twl6040_set_bias_level(struct snd_soc_codec *codec, |
| 772 | enum snd_soc_bias_level level) |
| 773 | { |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 774 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 775 | int audpwron = priv->audpwron; |
| 776 | int naudint = priv->naudint; |
| 777 | int ret; |
| 778 | |
| 779 | switch (level) { |
| 780 | case SND_SOC_BIAS_ON: |
| 781 | break; |
| 782 | case SND_SOC_BIAS_PREPARE: |
| 783 | break; |
| 784 | case SND_SOC_BIAS_STANDBY: |
| 785 | if (priv->codec_powered) |
| 786 | break; |
| 787 | |
| 788 | if (gpio_is_valid(audpwron)) { |
| 789 | /* use AUDPWRON line */ |
| 790 | gpio_set_value(audpwron, 1); |
| 791 | |
| 792 | /* wait for power-up completion */ |
| 793 | ret = twl6040_power_up_completion(codec, naudint); |
| 794 | if (ret) |
| 795 | return ret; |
| 796 | |
| 797 | /* sync registers updated during power-up sequence */ |
| 798 | twl6040_read_reg_volatile(codec, TWL6040_REG_NCPCTL); |
| 799 | twl6040_read_reg_volatile(codec, TWL6040_REG_LDOCTL); |
| 800 | twl6040_read_reg_volatile(codec, TWL6040_REG_LPPLLCTL); |
| 801 | } else { |
| 802 | /* use manual power-up sequence */ |
| 803 | twl6040_power_up(codec); |
| 804 | priv->codec_powered = 1; |
| 805 | } |
| 806 | |
| 807 | /* initialize vdd/vss registers with reg_cache */ |
| 808 | twl6040_init_vdd_regs(codec); |
| 809 | break; |
| 810 | case SND_SOC_BIAS_OFF: |
| 811 | if (!priv->codec_powered) |
| 812 | break; |
| 813 | |
| 814 | if (gpio_is_valid(audpwron)) { |
| 815 | /* use AUDPWRON line */ |
| 816 | gpio_set_value(audpwron, 0); |
| 817 | |
| 818 | /* power-down sequence latency */ |
| 819 | udelay(500); |
| 820 | |
| 821 | /* sync registers updated during power-down sequence */ |
| 822 | twl6040_read_reg_volatile(codec, TWL6040_REG_NCPCTL); |
| 823 | twl6040_read_reg_volatile(codec, TWL6040_REG_LDOCTL); |
| 824 | twl6040_write_reg_cache(codec, TWL6040_REG_LPPLLCTL, |
| 825 | 0x00); |
| 826 | } else { |
| 827 | /* use manual power-down sequence */ |
| 828 | twl6040_power_down(codec); |
| 829 | } |
| 830 | |
| 831 | priv->codec_powered = 0; |
| 832 | break; |
| 833 | } |
| 834 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 835 | codec->dapm.bias_level = level; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 836 | |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | /* set of rates for each pll: low-power and high-performance */ |
| 841 | |
| 842 | static unsigned int lp_rates[] = { |
| 843 | 88200, |
| 844 | 96000, |
| 845 | }; |
| 846 | |
| 847 | static struct snd_pcm_hw_constraint_list lp_constraints = { |
| 848 | .count = ARRAY_SIZE(lp_rates), |
| 849 | .list = lp_rates, |
| 850 | }; |
| 851 | |
| 852 | static unsigned int hp_rates[] = { |
| 853 | 96000, |
| 854 | }; |
| 855 | |
| 856 | static struct snd_pcm_hw_constraint_list hp_constraints = { |
| 857 | .count = ARRAY_SIZE(hp_rates), |
| 858 | .list = hp_rates, |
| 859 | }; |
| 860 | |
| 861 | static int twl6040_startup(struct snd_pcm_substream *substream, |
| 862 | struct snd_soc_dai *dai) |
| 863 | { |
| 864 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 865 | struct snd_soc_codec *codec = rtd->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 866 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 867 | |
| 868 | if (!priv->sysclk) { |
| 869 | dev_err(codec->dev, |
| 870 | "no mclk configured, call set_sysclk() on init\n"); |
| 871 | return -EINVAL; |
| 872 | } |
| 873 | |
| 874 | /* |
| 875 | * capture is not supported at 17.64 MHz, |
| 876 | * it's reserved for headset low-power playback scenario |
| 877 | */ |
| 878 | if ((priv->sysclk == 17640000) && substream->stream) { |
| 879 | dev_err(codec->dev, |
| 880 | "capture mode is not supported at %dHz\n", |
| 881 | priv->sysclk); |
| 882 | return -EINVAL; |
| 883 | } |
| 884 | |
| 885 | snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 886 | SNDRV_PCM_HW_PARAM_RATE, |
| 887 | priv->sysclk_constraints); |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | static int twl6040_hw_params(struct snd_pcm_substream *substream, |
| 893 | struct snd_pcm_hw_params *params, |
| 894 | struct snd_soc_dai *dai) |
| 895 | { |
| 896 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 897 | struct snd_soc_codec *codec = rtd->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 898 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 899 | u8 lppllctl; |
| 900 | int rate; |
| 901 | |
| 902 | /* nothing to do for high-perf pll, it supports only 48 kHz */ |
| 903 | if (priv->pll == TWL6040_HPPLL_ID) |
| 904 | return 0; |
| 905 | |
| 906 | lppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_LPPLLCTL); |
| 907 | |
| 908 | rate = params_rate(params); |
| 909 | switch (rate) { |
| 910 | case 88200: |
| 911 | lppllctl |= TWL6040_LPLLFIN; |
| 912 | priv->sysclk = 17640000; |
| 913 | break; |
| 914 | case 96000: |
| 915 | lppllctl &= ~TWL6040_LPLLFIN; |
| 916 | priv->sysclk = 19200000; |
| 917 | break; |
| 918 | default: |
| 919 | dev_err(codec->dev, "unsupported rate %d\n", rate); |
| 920 | return -EINVAL; |
| 921 | } |
| 922 | |
| 923 | twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl); |
| 924 | |
| 925 | return 0; |
| 926 | } |
| 927 | |
| 928 | static int twl6040_trigger(struct snd_pcm_substream *substream, |
| 929 | int cmd, struct snd_soc_dai *dai) |
| 930 | { |
| 931 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 932 | struct snd_soc_codec *codec = rtd->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 933 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 934 | |
| 935 | switch (cmd) { |
| 936 | case SNDRV_PCM_TRIGGER_START: |
| 937 | case SNDRV_PCM_TRIGGER_RESUME: |
| 938 | /* |
| 939 | * low-power playback mode is restricted |
| 940 | * for headset path only |
| 941 | */ |
| 942 | if ((priv->sysclk == 17640000) && priv->non_lp) { |
| 943 | dev_err(codec->dev, |
| 944 | "some enabled paths aren't supported at %dHz\n", |
| 945 | priv->sysclk); |
| 946 | return -EPERM; |
| 947 | } |
| 948 | break; |
| 949 | default: |
| 950 | break; |
| 951 | } |
| 952 | |
| 953 | return 0; |
| 954 | } |
| 955 | |
| 956 | static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 957 | int clk_id, unsigned int freq, int dir) |
| 958 | { |
| 959 | struct snd_soc_codec *codec = codec_dai->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 960 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 961 | u8 hppllctl, lppllctl; |
| 962 | |
| 963 | hppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_HPPLLCTL); |
| 964 | lppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_LPPLLCTL); |
| 965 | |
| 966 | switch (clk_id) { |
| 967 | case TWL6040_SYSCLK_SEL_LPPLL: |
| 968 | switch (freq) { |
| 969 | case 32768: |
| 970 | /* headset dac and driver must be in low-power mode */ |
| 971 | headset_power_mode(codec, 0); |
| 972 | |
| 973 | /* clk32k input requires low-power pll */ |
| 974 | lppllctl |= TWL6040_LPLLENA; |
| 975 | twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl); |
| 976 | mdelay(5); |
| 977 | lppllctl &= ~TWL6040_HPLLSEL; |
| 978 | twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl); |
| 979 | hppllctl &= ~TWL6040_HPLLENA; |
| 980 | twl6040_write(codec, TWL6040_REG_HPPLLCTL, hppllctl); |
| 981 | break; |
| 982 | default: |
| 983 | dev_err(codec->dev, "unknown mclk freq %d\n", freq); |
| 984 | return -EINVAL; |
| 985 | } |
| 986 | |
| 987 | /* lppll divider */ |
| 988 | switch (priv->sysclk) { |
| 989 | case 17640000: |
| 990 | lppllctl |= TWL6040_LPLLFIN; |
| 991 | break; |
| 992 | case 19200000: |
| 993 | lppllctl &= ~TWL6040_LPLLFIN; |
| 994 | break; |
| 995 | default: |
| 996 | /* sysclk not yet configured */ |
| 997 | lppllctl &= ~TWL6040_LPLLFIN; |
| 998 | priv->sysclk = 19200000; |
| 999 | break; |
| 1000 | } |
| 1001 | |
| 1002 | twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl); |
| 1003 | |
| 1004 | priv->pll = TWL6040_LPPLL_ID; |
| 1005 | priv->sysclk_constraints = &lp_constraints; |
| 1006 | break; |
| 1007 | case TWL6040_SYSCLK_SEL_HPPLL: |
| 1008 | hppllctl &= ~TWL6040_MCLK_MSK; |
| 1009 | |
| 1010 | switch (freq) { |
| 1011 | case 12000000: |
| 1012 | /* mclk input, pll enabled */ |
| 1013 | hppllctl |= TWL6040_MCLK_12000KHZ | |
| 1014 | TWL6040_HPLLSQRBP | |
| 1015 | TWL6040_HPLLENA; |
| 1016 | break; |
| 1017 | case 19200000: |
| 1018 | /* mclk input, pll disabled */ |
| 1019 | hppllctl |= TWL6040_MCLK_19200KHZ | |
Jorge Eduardo Candelaria | 44ebaa5 | 2010-05-20 17:53:07 -0500 | [diff] [blame] | 1020 | TWL6040_HPLLSQRENA | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1021 | TWL6040_HPLLBP; |
| 1022 | break; |
| 1023 | case 26000000: |
| 1024 | /* mclk input, pll enabled */ |
| 1025 | hppllctl |= TWL6040_MCLK_26000KHZ | |
| 1026 | TWL6040_HPLLSQRBP | |
| 1027 | TWL6040_HPLLENA; |
| 1028 | break; |
| 1029 | case 38400000: |
| 1030 | /* clk slicer, pll disabled */ |
| 1031 | hppllctl |= TWL6040_MCLK_38400KHZ | |
| 1032 | TWL6040_HPLLSQRENA | |
| 1033 | TWL6040_HPLLBP; |
| 1034 | break; |
| 1035 | default: |
| 1036 | dev_err(codec->dev, "unknown mclk freq %d\n", freq); |
| 1037 | return -EINVAL; |
| 1038 | } |
| 1039 | |
| 1040 | /* headset dac and driver must be in high-performance mode */ |
| 1041 | headset_power_mode(codec, 1); |
| 1042 | |
| 1043 | twl6040_write(codec, TWL6040_REG_HPPLLCTL, hppllctl); |
| 1044 | udelay(500); |
| 1045 | lppllctl |= TWL6040_HPLLSEL; |
| 1046 | twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl); |
| 1047 | lppllctl &= ~TWL6040_LPLLENA; |
| 1048 | twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl); |
| 1049 | |
| 1050 | /* high-performance pll can provide only 19.2 MHz */ |
| 1051 | priv->pll = TWL6040_HPPLL_ID; |
| 1052 | priv->sysclk = 19200000; |
| 1053 | priv->sysclk_constraints = &hp_constraints; |
| 1054 | break; |
| 1055 | default: |
| 1056 | dev_err(codec->dev, "unknown clk_id %d\n", clk_id); |
| 1057 | return -EINVAL; |
| 1058 | } |
| 1059 | |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | static struct snd_soc_dai_ops twl6040_dai_ops = { |
| 1064 | .startup = twl6040_startup, |
| 1065 | .hw_params = twl6040_hw_params, |
| 1066 | .trigger = twl6040_trigger, |
| 1067 | .set_sysclk = twl6040_set_dai_sysclk, |
| 1068 | }; |
| 1069 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1070 | static struct snd_soc_dai_driver twl6040_dai = { |
| 1071 | .name = "twl6040-hifi", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1072 | .playback = { |
| 1073 | .stream_name = "Playback", |
| 1074 | .channels_min = 1, |
| 1075 | .channels_max = 4, |
| 1076 | .rates = TWL6040_RATES, |
| 1077 | .formats = TWL6040_FORMATS, |
| 1078 | }, |
| 1079 | .capture = { |
| 1080 | .stream_name = "Capture", |
| 1081 | .channels_min = 1, |
| 1082 | .channels_max = 2, |
| 1083 | .rates = TWL6040_RATES, |
| 1084 | .formats = TWL6040_FORMATS, |
| 1085 | }, |
| 1086 | .ops = &twl6040_dai_ops, |
| 1087 | }; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1088 | |
| 1089 | #ifdef CONFIG_PM |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1090 | 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] | 1091 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1092 | twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 1093 | |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1097 | static int twl6040_resume(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1098 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1099 | twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Olaya, Margarita | 6c31104 | 2010-12-10 21:05:46 -0600 | [diff] [blame^] | 1100 | twl6040_set_bias_level(codec, codec->dapm.suspend_bias_level); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1101 | |
| 1102 | return 0; |
| 1103 | } |
| 1104 | #else |
| 1105 | #define twl6040_suspend NULL |
| 1106 | #define twl6040_resume NULL |
| 1107 | #endif |
| 1108 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1109 | static int twl6040_probe(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1110 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1111 | struct twl4030_codec_data *twl_codec = codec->dev->platform_data; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1112 | struct twl6040_data *priv; |
| 1113 | int audpwron, naudint; |
| 1114 | int ret = 0; |
| 1115 | |
| 1116 | priv = kzalloc(sizeof(struct twl6040_data), GFP_KERNEL); |
| 1117 | if (priv == NULL) |
| 1118 | return -ENOMEM; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1119 | snd_soc_codec_set_drvdata(codec, priv); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1120 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1121 | priv->codec = codec; |
| 1122 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1123 | if (twl_codec) { |
| 1124 | audpwron = twl_codec->audpwron_gpio; |
| 1125 | naudint = twl_codec->naudint_irq; |
| 1126 | } else { |
| 1127 | audpwron = -EINVAL; |
| 1128 | naudint = 0; |
| 1129 | } |
| 1130 | |
| 1131 | priv->audpwron = audpwron; |
| 1132 | priv->naudint = naudint; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1133 | priv->workqueue = create_singlethread_workqueue("twl6040-codec"); |
| 1134 | |
| 1135 | if (!priv->workqueue) |
| 1136 | goto work_err; |
| 1137 | |
| 1138 | INIT_DELAYED_WORK(&priv->delayed_work, twl6040_accessory_work); |
| 1139 | |
| 1140 | mutex_init(&priv->mutex); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1141 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1142 | init_completion(&priv->ready); |
| 1143 | |
| 1144 | if (gpio_is_valid(audpwron)) { |
| 1145 | ret = gpio_request(audpwron, "audpwron"); |
| 1146 | if (ret) |
| 1147 | goto gpio1_err; |
| 1148 | |
| 1149 | ret = gpio_direction_output(audpwron, 0); |
| 1150 | if (ret) |
| 1151 | goto gpio2_err; |
| 1152 | |
| 1153 | priv->codec_powered = 0; |
| 1154 | } |
| 1155 | |
| 1156 | if (naudint) { |
| 1157 | /* audio interrupt */ |
| 1158 | ret = request_threaded_irq(naudint, NULL, |
| 1159 | twl6040_naudint_handler, |
| 1160 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, |
| 1161 | "twl6040_codec", codec); |
| 1162 | if (ret) |
| 1163 | goto gpio2_err; |
| 1164 | } else { |
| 1165 | if (gpio_is_valid(audpwron)) { |
| 1166 | /* enable only codec ready interrupt */ |
| 1167 | twl6040_write_reg_cache(codec, TWL6040_REG_INTMR, |
| 1168 | ~TWL6040_READYMSK & TWL6040_ALLINT_MSK); |
| 1169 | } else { |
| 1170 | /* no interrupts at all */ |
| 1171 | twl6040_write_reg_cache(codec, TWL6040_REG_INTMR, |
| 1172 | TWL6040_ALLINT_MSK); |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | /* init vio registers */ |
| 1177 | twl6040_init_vio_regs(codec); |
| 1178 | |
| 1179 | /* power on device */ |
| 1180 | ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 1181 | if (ret) |
| 1182 | goto irq_err; |
| 1183 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1184 | snd_soc_add_controls(codec, twl6040_snd_controls, |
| 1185 | ARRAY_SIZE(twl6040_snd_controls)); |
| 1186 | twl6040_add_widgets(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1187 | |
| 1188 | return 0; |
| 1189 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1190 | irq_err: |
| 1191 | if (naudint) |
| 1192 | free_irq(naudint, codec); |
| 1193 | gpio2_err: |
| 1194 | if (gpio_is_valid(audpwron)) |
| 1195 | gpio_free(audpwron); |
| 1196 | gpio1_err: |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1197 | destroy_workqueue(priv->workqueue); |
| 1198 | work_err: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1199 | kfree(priv); |
| 1200 | return ret; |
| 1201 | } |
| 1202 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1203 | static int twl6040_remove(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1204 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1205 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1206 | int audpwron = priv->audpwron; |
| 1207 | int naudint = priv->naudint; |
| 1208 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1209 | twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 1210 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1211 | if (gpio_is_valid(audpwron)) |
| 1212 | gpio_free(audpwron); |
| 1213 | |
| 1214 | if (naudint) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1215 | free_irq(naudint, codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1216 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1217 | destroy_workqueue(priv->workqueue); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1218 | kfree(priv); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1219 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1220 | return 0; |
| 1221 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1222 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1223 | static struct snd_soc_codec_driver soc_codec_dev_twl6040 = { |
| 1224 | .probe = twl6040_probe, |
| 1225 | .remove = twl6040_remove, |
| 1226 | .suspend = twl6040_suspend, |
| 1227 | .resume = twl6040_resume, |
| 1228 | .read = twl6040_read_reg_cache, |
| 1229 | .write = twl6040_write, |
| 1230 | .set_bias_level = twl6040_set_bias_level, |
| 1231 | .reg_cache_size = ARRAY_SIZE(twl6040_reg), |
| 1232 | .reg_word_size = sizeof(u8), |
| 1233 | .reg_cache_default = twl6040_reg, |
| 1234 | }; |
| 1235 | |
| 1236 | static int __devinit twl6040_codec_probe(struct platform_device *pdev) |
| 1237 | { |
| 1238 | return snd_soc_register_codec(&pdev->dev, |
| 1239 | &soc_codec_dev_twl6040, &twl6040_dai, 1); |
| 1240 | } |
| 1241 | |
| 1242 | static int __devexit twl6040_codec_remove(struct platform_device *pdev) |
| 1243 | { |
| 1244 | snd_soc_unregister_codec(&pdev->dev); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1245 | return 0; |
| 1246 | } |
| 1247 | |
| 1248 | static struct platform_driver twl6040_codec_driver = { |
| 1249 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1250 | .name = "twl6040-codec", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1251 | .owner = THIS_MODULE, |
| 1252 | }, |
| 1253 | .probe = twl6040_codec_probe, |
| 1254 | .remove = __devexit_p(twl6040_codec_remove), |
| 1255 | }; |
| 1256 | |
| 1257 | static int __init twl6040_codec_init(void) |
| 1258 | { |
| 1259 | return platform_driver_register(&twl6040_codec_driver); |
| 1260 | } |
| 1261 | module_init(twl6040_codec_init); |
| 1262 | |
| 1263 | static void __exit twl6040_codec_exit(void) |
| 1264 | { |
| 1265 | platform_driver_unregister(&twl6040_codec_driver); |
| 1266 | } |
| 1267 | module_exit(twl6040_codec_exit); |
| 1268 | |
| 1269 | MODULE_DESCRIPTION("ASoC TWL6040 codec driver"); |
| 1270 | MODULE_AUTHOR("Misael Lopez Cruz"); |
| 1271 | MODULE_LICENSE("GPL"); |