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 | |
Peter Ujfalusi | d17bf31 | 2011-09-22 11:05:48 +0300 | [diff] [blame] | 60 | /* Shadow register used by the driver */ |
| 61 | #define TWL6040_REG_SW_SHADOW 0x2F |
| 62 | #define TWL6040_CACHEREGNUM (TWL6040_REG_SW_SHADOW + 1) |
| 63 | |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 64 | /* TWL6040_REG_SW_SHADOW (0x2F) fields */ |
| 65 | #define TWL6040_EAR_PATH_ENABLE 0x01 |
| 66 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 67 | struct twl6040_output { |
| 68 | u16 active; |
| 69 | u16 left_vol; |
| 70 | u16 right_vol; |
| 71 | u16 left_step; |
| 72 | u16 right_step; |
| 73 | unsigned int step_delay; |
| 74 | u16 ramp; |
Peter Ujfalusi | e71a5e5 | 2011-09-26 16:26:26 +0300 | [diff] [blame] | 75 | struct delayed_work work; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 76 | struct completion ramp_done; |
| 77 | }; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 78 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 79 | struct twl6040_jack_data { |
| 80 | struct snd_soc_jack *jack; |
Peter Ujfalusi | 46dd0b9 | 2011-09-26 16:26:27 +0300 | [diff] [blame] | 81 | struct delayed_work work; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 82 | int report; |
| 83 | }; |
| 84 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 85 | /* codec private data */ |
| 86 | struct twl6040_data { |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 87 | int plug_irq; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 88 | int codec_powered; |
| 89 | int pll; |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 90 | int pll_power_mode; |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 91 | int hs_power_mode; |
| 92 | int hs_power_mode_locked; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 93 | unsigned int clk_in; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 94 | unsigned int sysclk; |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 95 | u16 hs_left_step; |
| 96 | u16 hs_right_step; |
| 97 | u16 hf_left_step; |
| 98 | u16 hf_right_step; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 99 | struct twl6040_jack_data hs_jack; |
| 100 | struct snd_soc_codec *codec; |
| 101 | struct workqueue_struct *workqueue; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 102 | struct mutex mutex; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 103 | struct twl6040_output headset; |
| 104 | struct twl6040_output handsfree; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | /* |
| 108 | * twl6040 register cache & default register settings |
| 109 | */ |
| 110 | static const u8 twl6040_reg[TWL6040_CACHEREGNUM] = { |
Peter Ujfalusi | 4548dc3 | 2011-09-22 11:05:46 +0300 | [diff] [blame] | 111 | 0x00, /* not used 0x00 */ |
| 112 | 0x4B, /* REG_ASICID 0x01 (ro) */ |
| 113 | 0x00, /* REG_ASICREV 0x02 (ro) */ |
| 114 | 0x00, /* REG_INTID 0x03 */ |
| 115 | 0x00, /* REG_INTMR 0x04 */ |
| 116 | 0x00, /* REG_NCPCTRL 0x05 */ |
| 117 | 0x00, /* REG_LDOCTL 0x06 */ |
| 118 | 0x60, /* REG_HPPLLCTL 0x07 */ |
| 119 | 0x00, /* REG_LPPLLCTL 0x08 */ |
| 120 | 0x4A, /* REG_LPPLLDIV 0x09 */ |
| 121 | 0x00, /* REG_AMICBCTL 0x0A */ |
| 122 | 0x00, /* REG_DMICBCTL 0x0B */ |
| 123 | 0x00, /* REG_MICLCTL 0x0C */ |
| 124 | 0x00, /* REG_MICRCTL 0x0D */ |
| 125 | 0x00, /* REG_MICGAIN 0x0E */ |
| 126 | 0x1B, /* REG_LINEGAIN 0x0F */ |
| 127 | 0x00, /* REG_HSLCTL 0x10 */ |
| 128 | 0x00, /* REG_HSRCTL 0x11 */ |
| 129 | 0x00, /* REG_HSGAIN 0x12 */ |
| 130 | 0x00, /* REG_EARCTL 0x13 */ |
| 131 | 0x00, /* REG_HFLCTL 0x14 */ |
| 132 | 0x00, /* REG_HFLGAIN 0x15 */ |
| 133 | 0x00, /* REG_HFRCTL 0x16 */ |
| 134 | 0x00, /* REG_HFRGAIN 0x17 */ |
| 135 | 0x00, /* REG_VIBCTLL 0x18 */ |
| 136 | 0x00, /* REG_VIBDATL 0x19 */ |
| 137 | 0x00, /* REG_VIBCTLR 0x1A */ |
| 138 | 0x00, /* REG_VIBDATR 0x1B */ |
| 139 | 0x00, /* REG_HKCTL1 0x1C */ |
| 140 | 0x00, /* REG_HKCTL2 0x1D */ |
| 141 | 0x00, /* REG_GPOCTL 0x1E */ |
| 142 | 0x00, /* REG_ALB 0x1F */ |
| 143 | 0x00, /* REG_DLB 0x20 */ |
| 144 | 0x00, /* not used 0x21 */ |
| 145 | 0x00, /* not used 0x22 */ |
| 146 | 0x00, /* not used 0x23 */ |
| 147 | 0x00, /* not used 0x24 */ |
| 148 | 0x00, /* not used 0x25 */ |
| 149 | 0x00, /* not used 0x26 */ |
| 150 | 0x00, /* not used 0x27 */ |
| 151 | 0x00, /* REG_TRIM1 0x28 */ |
| 152 | 0x00, /* REG_TRIM2 0x29 */ |
| 153 | 0x00, /* REG_TRIM3 0x2A */ |
| 154 | 0x00, /* REG_HSOTRIM 0x2B */ |
| 155 | 0x00, /* REG_HFOTRIM 0x2C */ |
| 156 | 0x09, /* REG_ACCCTL 0x2D */ |
| 157 | 0x00, /* REG_STATUS 0x2E (ro) */ |
Peter Ujfalusi | d17bf31 | 2011-09-22 11:05:48 +0300 | [diff] [blame] | 158 | |
| 159 | 0x00, /* REG_SW_SHADOW 0x2F - Shadow, non HW register */ |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 160 | }; |
| 161 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 162 | /* List of registers to be restored after power up */ |
| 163 | static const int twl6040_restore_list[] = { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 164 | TWL6040_REG_MICLCTL, |
| 165 | TWL6040_REG_MICRCTL, |
| 166 | TWL6040_REG_MICGAIN, |
| 167 | TWL6040_REG_LINEGAIN, |
| 168 | TWL6040_REG_HSLCTL, |
| 169 | TWL6040_REG_HSRCTL, |
| 170 | TWL6040_REG_HSGAIN, |
| 171 | TWL6040_REG_EARCTL, |
| 172 | TWL6040_REG_HFLCTL, |
| 173 | TWL6040_REG_HFLGAIN, |
| 174 | TWL6040_REG_HFRCTL, |
| 175 | TWL6040_REG_HFRGAIN, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 178 | /* set of rates for each pll: low-power and high-performance */ |
| 179 | static unsigned int lp_rates[] = { |
| 180 | 8000, |
| 181 | 11250, |
| 182 | 16000, |
| 183 | 22500, |
| 184 | 32000, |
| 185 | 44100, |
| 186 | 48000, |
| 187 | 88200, |
| 188 | 96000, |
| 189 | }; |
| 190 | |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 191 | static unsigned int hp_rates[] = { |
| 192 | 8000, |
| 193 | 16000, |
| 194 | 32000, |
| 195 | 48000, |
| 196 | 96000, |
| 197 | }; |
| 198 | |
Peter Ujfalusi | f53c346 | 2011-06-29 13:28:18 +0300 | [diff] [blame] | 199 | static struct snd_pcm_hw_constraint_list sysclk_constraints[] = { |
| 200 | { .count = ARRAY_SIZE(lp_rates), .list = lp_rates, }, |
| 201 | { .count = ARRAY_SIZE(hp_rates), .list = hp_rates, }, |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 202 | }; |
| 203 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 204 | /* |
| 205 | * read twl6040 register cache |
| 206 | */ |
| 207 | static inline unsigned int twl6040_read_reg_cache(struct snd_soc_codec *codec, |
| 208 | unsigned int reg) |
| 209 | { |
| 210 | u8 *cache = codec->reg_cache; |
| 211 | |
| 212 | if (reg >= TWL6040_CACHEREGNUM) |
| 213 | return -EIO; |
| 214 | |
| 215 | return cache[reg]; |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | * write twl6040 register cache |
| 220 | */ |
| 221 | static inline void twl6040_write_reg_cache(struct snd_soc_codec *codec, |
| 222 | u8 reg, u8 value) |
| 223 | { |
| 224 | u8 *cache = codec->reg_cache; |
| 225 | |
| 226 | if (reg >= TWL6040_CACHEREGNUM) |
| 227 | return; |
| 228 | cache[reg] = value; |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * read from twl6040 hardware register |
| 233 | */ |
| 234 | static int twl6040_read_reg_volatile(struct snd_soc_codec *codec, |
| 235 | unsigned int reg) |
| 236 | { |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 237 | struct twl6040 *twl6040 = codec->control_data; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 238 | u8 value; |
| 239 | |
| 240 | if (reg >= TWL6040_CACHEREGNUM) |
| 241 | return -EIO; |
| 242 | |
Peter Ujfalusi | d17bf31 | 2011-09-22 11:05:48 +0300 | [diff] [blame] | 243 | if (likely(reg < TWL6040_REG_SW_SHADOW)) { |
| 244 | value = twl6040_reg_read(twl6040, reg); |
| 245 | twl6040_write_reg_cache(codec, reg, value); |
| 246 | } else { |
| 247 | value = twl6040_read_reg_cache(codec, reg); |
| 248 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 249 | |
| 250 | return value; |
| 251 | } |
| 252 | |
| 253 | /* |
| 254 | * write to the twl6040 register space |
| 255 | */ |
| 256 | static int twl6040_write(struct snd_soc_codec *codec, |
| 257 | unsigned int reg, unsigned int value) |
| 258 | { |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 259 | struct twl6040 *twl6040 = codec->control_data; |
| 260 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 261 | if (reg >= TWL6040_CACHEREGNUM) |
| 262 | return -EIO; |
| 263 | |
| 264 | twl6040_write_reg_cache(codec, reg, value); |
Peter Ujfalusi | d17bf31 | 2011-09-22 11:05:48 +0300 | [diff] [blame] | 265 | if (likely(reg < TWL6040_REG_SW_SHADOW)) |
| 266 | return twl6040_reg_write(twl6040, reg, value); |
| 267 | else |
| 268 | return 0; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 271 | static void twl6040_init_chip(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 272 | { |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 273 | struct twl6040 *twl6040 = codec->control_data; |
| 274 | u8 val; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 275 | |
Peter Ujfalusi | f97217f | 2011-09-26 16:05:56 +0300 | [diff] [blame] | 276 | /* Update reg_cache: ASICREV, and TRIM values */ |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 277 | val = twl6040_get_revid(twl6040); |
| 278 | twl6040_write_reg_cache(codec, TWL6040_REG_ASICREV, val); |
| 279 | |
Peter Ujfalusi | f97217f | 2011-09-26 16:05:56 +0300 | [diff] [blame] | 280 | twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM1); |
| 281 | twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM2); |
| 282 | twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM3); |
| 283 | twl6040_read_reg_volatile(codec, TWL6040_REG_HSOTRIM); |
| 284 | twl6040_read_reg_volatile(codec, TWL6040_REG_HFOTRIM); |
| 285 | |
Peter Ujfalusi | 2c27ff4 | 2011-09-15 15:39:28 +0300 | [diff] [blame] | 286 | /* Change chip defaults */ |
| 287 | /* No imput selected for microphone amplifiers */ |
| 288 | twl6040_write_reg_cache(codec, TWL6040_REG_MICLCTL, 0x18); |
| 289 | twl6040_write_reg_cache(codec, TWL6040_REG_MICRCTL, 0x18); |
Peter Ujfalusi | 3acef68 | 2011-09-22 11:05:45 +0300 | [diff] [blame] | 290 | |
| 291 | /* |
| 292 | * We need to lower the default gain values, so the ramp code |
| 293 | * can work correctly for the first playback. |
| 294 | * This reduces the pop noise heard at the first playback. |
| 295 | */ |
| 296 | twl6040_write_reg_cache(codec, TWL6040_REG_HSGAIN, 0xff); |
| 297 | twl6040_write_reg_cache(codec, TWL6040_REG_EARCTL, 0x1e); |
| 298 | twl6040_write_reg_cache(codec, TWL6040_REG_HFLGAIN, 0x1d); |
| 299 | twl6040_write_reg_cache(codec, TWL6040_REG_HFRGAIN, 0x1d); |
| 300 | twl6040_write_reg_cache(codec, TWL6040_REG_LINEGAIN, 0); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 301 | } |
| 302 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 303 | static void twl6040_restore_regs(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 304 | { |
| 305 | u8 *cache = codec->reg_cache; |
| 306 | int reg, i; |
| 307 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 308 | for (i = 0; i < ARRAY_SIZE(twl6040_restore_list); i++) { |
| 309 | reg = twl6040_restore_list[i]; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 310 | twl6040_write(codec, reg, cache[reg]); |
| 311 | } |
| 312 | } |
| 313 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 314 | /* |
| 315 | * Ramp HS PGA volume to minimise pops at stream startup and shutdown. |
| 316 | */ |
| 317 | static inline int twl6040_hs_ramp_step(struct snd_soc_codec *codec, |
| 318 | unsigned int left_step, unsigned int right_step) |
| 319 | { |
| 320 | |
| 321 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 322 | struct twl6040_output *headset = &priv->headset; |
| 323 | int left_complete = 0, right_complete = 0; |
| 324 | u8 reg, val; |
| 325 | |
| 326 | /* left channel */ |
| 327 | left_step = (left_step > 0xF) ? 0xF : left_step; |
| 328 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN); |
| 329 | val = (~reg & TWL6040_HSL_VOL_MASK); |
| 330 | |
| 331 | if (headset->ramp == TWL6040_RAMP_UP) { |
| 332 | /* ramp step up */ |
| 333 | if (val < headset->left_vol) { |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 334 | if (val + left_step > headset->left_vol) |
| 335 | val = headset->left_vol; |
| 336 | else |
| 337 | val += left_step; |
| 338 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 339 | reg &= ~TWL6040_HSL_VOL_MASK; |
| 340 | twl6040_write(codec, TWL6040_REG_HSGAIN, |
| 341 | (reg | (~val & TWL6040_HSL_VOL_MASK))); |
| 342 | } else { |
| 343 | left_complete = 1; |
| 344 | } |
| 345 | } else if (headset->ramp == TWL6040_RAMP_DOWN) { |
| 346 | /* ramp step down */ |
| 347 | if (val > 0x0) { |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 348 | if ((int)val - (int)left_step < 0) |
| 349 | val = 0; |
| 350 | else |
| 351 | val -= left_step; |
| 352 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 353 | reg &= ~TWL6040_HSL_VOL_MASK; |
| 354 | twl6040_write(codec, TWL6040_REG_HSGAIN, reg | |
| 355 | (~val & TWL6040_HSL_VOL_MASK)); |
| 356 | } else { |
| 357 | left_complete = 1; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | /* right channel */ |
| 362 | right_step = (right_step > 0xF) ? 0xF : right_step; |
| 363 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HSGAIN); |
| 364 | val = (~reg & TWL6040_HSR_VOL_MASK) >> TWL6040_HSR_VOL_SHIFT; |
| 365 | |
| 366 | if (headset->ramp == TWL6040_RAMP_UP) { |
| 367 | /* ramp step up */ |
| 368 | if (val < headset->right_vol) { |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 369 | if (val + right_step > headset->right_vol) |
| 370 | val = headset->right_vol; |
| 371 | else |
| 372 | val += right_step; |
| 373 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 374 | reg &= ~TWL6040_HSR_VOL_MASK; |
| 375 | twl6040_write(codec, TWL6040_REG_HSGAIN, |
| 376 | (reg | (~val << TWL6040_HSR_VOL_SHIFT))); |
| 377 | } else { |
| 378 | right_complete = 1; |
| 379 | } |
| 380 | } else if (headset->ramp == TWL6040_RAMP_DOWN) { |
| 381 | /* ramp step down */ |
| 382 | if (val > 0x0) { |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 383 | if ((int)val - (int)right_step < 0) |
| 384 | val = 0; |
| 385 | else |
| 386 | val -= right_step; |
| 387 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 388 | reg &= ~TWL6040_HSR_VOL_MASK; |
| 389 | twl6040_write(codec, TWL6040_REG_HSGAIN, |
| 390 | reg | (~val << TWL6040_HSR_VOL_SHIFT)); |
| 391 | } else { |
| 392 | right_complete = 1; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | return left_complete & right_complete; |
| 397 | } |
| 398 | |
| 399 | /* |
| 400 | * Ramp HF PGA volume to minimise pops at stream startup and shutdown. |
| 401 | */ |
| 402 | static inline int twl6040_hf_ramp_step(struct snd_soc_codec *codec, |
| 403 | unsigned int left_step, unsigned int right_step) |
| 404 | { |
| 405 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 406 | struct twl6040_output *handsfree = &priv->handsfree; |
| 407 | int left_complete = 0, right_complete = 0; |
| 408 | u16 reg, val; |
| 409 | |
| 410 | /* left channel */ |
| 411 | left_step = (left_step > 0x1D) ? 0x1D : left_step; |
| 412 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFLGAIN); |
| 413 | reg = 0x1D - reg; |
| 414 | val = (reg & TWL6040_HF_VOL_MASK); |
| 415 | if (handsfree->ramp == TWL6040_RAMP_UP) { |
| 416 | /* ramp step up */ |
| 417 | if (val < handsfree->left_vol) { |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 418 | if (val + left_step > handsfree->left_vol) |
| 419 | val = handsfree->left_vol; |
| 420 | else |
| 421 | val += left_step; |
| 422 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 423 | reg &= ~TWL6040_HF_VOL_MASK; |
| 424 | twl6040_write(codec, TWL6040_REG_HFLGAIN, |
| 425 | reg | (0x1D - val)); |
| 426 | } else { |
| 427 | left_complete = 1; |
| 428 | } |
| 429 | } else if (handsfree->ramp == TWL6040_RAMP_DOWN) { |
| 430 | /* ramp step down */ |
| 431 | if (val > 0) { |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 432 | if ((int)val - (int)left_step < 0) |
| 433 | val = 0; |
| 434 | else |
| 435 | val -= left_step; |
| 436 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 437 | reg &= ~TWL6040_HF_VOL_MASK; |
| 438 | twl6040_write(codec, TWL6040_REG_HFLGAIN, |
| 439 | reg | (0x1D - val)); |
| 440 | } else { |
| 441 | left_complete = 1; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | /* right channel */ |
| 446 | right_step = (right_step > 0x1D) ? 0x1D : right_step; |
| 447 | reg = twl6040_read_reg_cache(codec, TWL6040_REG_HFRGAIN); |
| 448 | reg = 0x1D - reg; |
| 449 | val = (reg & TWL6040_HF_VOL_MASK); |
| 450 | if (handsfree->ramp == TWL6040_RAMP_UP) { |
| 451 | /* ramp step up */ |
| 452 | if (val < handsfree->right_vol) { |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 453 | if (val + right_step > handsfree->right_vol) |
| 454 | val = handsfree->right_vol; |
| 455 | else |
| 456 | val += right_step; |
| 457 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 458 | reg &= ~TWL6040_HF_VOL_MASK; |
| 459 | twl6040_write(codec, TWL6040_REG_HFRGAIN, |
| 460 | reg | (0x1D - val)); |
| 461 | } else { |
| 462 | right_complete = 1; |
| 463 | } |
| 464 | } else if (handsfree->ramp == TWL6040_RAMP_DOWN) { |
| 465 | /* ramp step down */ |
| 466 | if (val > 0) { |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 467 | if ((int)val - (int)right_step < 0) |
| 468 | val = 0; |
| 469 | else |
| 470 | val -= right_step; |
| 471 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 472 | reg &= ~TWL6040_HF_VOL_MASK; |
| 473 | twl6040_write(codec, TWL6040_REG_HFRGAIN, |
| 474 | reg | (0x1D - val)); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | return left_complete & right_complete; |
| 479 | } |
| 480 | |
| 481 | /* |
| 482 | * This work ramps both output PGAs at stream start/stop time to |
| 483 | * minimise pop associated with DAPM power switching. |
| 484 | */ |
| 485 | static void twl6040_pga_hs_work(struct work_struct *work) |
| 486 | { |
| 487 | struct twl6040_data *priv = |
Peter Ujfalusi | e71a5e5 | 2011-09-26 16:26:26 +0300 | [diff] [blame] | 488 | container_of(work, struct twl6040_data, headset.work.work); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 489 | struct snd_soc_codec *codec = priv->codec; |
| 490 | struct twl6040_output *headset = &priv->headset; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 491 | int i, headset_complete; |
| 492 | |
| 493 | /* do we need to ramp at all ? */ |
| 494 | if (headset->ramp == TWL6040_RAMP_NONE) |
| 495 | return; |
| 496 | |
Peter Ujfalusi | 93eebc69 | 2011-09-29 15:22:35 +0300 | [diff] [blame] | 497 | /* HS PGA gain range: 0x0 - 0xf (0 - 15) */ |
| 498 | for (i = 0; i < 16; i++) { |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 499 | headset_complete = twl6040_hs_ramp_step(codec, |
| 500 | headset->left_step, |
| 501 | headset->right_step); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 502 | |
| 503 | /* ramp finished ? */ |
| 504 | if (headset_complete) |
| 505 | break; |
| 506 | |
Peter Ujfalusi | 8ff1e17 | 2011-09-26 16:26:30 +0300 | [diff] [blame] | 507 | schedule_timeout_interruptible( |
| 508 | msecs_to_jiffies(headset->step_delay)); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | if (headset->ramp == TWL6040_RAMP_DOWN) { |
| 512 | headset->active = 0; |
| 513 | complete(&headset->ramp_done); |
| 514 | } else { |
| 515 | headset->active = 1; |
| 516 | } |
| 517 | headset->ramp = TWL6040_RAMP_NONE; |
| 518 | } |
| 519 | |
| 520 | static void twl6040_pga_hf_work(struct work_struct *work) |
| 521 | { |
| 522 | struct twl6040_data *priv = |
Peter Ujfalusi | e71a5e5 | 2011-09-26 16:26:26 +0300 | [diff] [blame] | 523 | container_of(work, struct twl6040_data, handsfree.work.work); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 524 | struct snd_soc_codec *codec = priv->codec; |
| 525 | struct twl6040_output *handsfree = &priv->handsfree; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 526 | int i, handsfree_complete; |
| 527 | |
| 528 | /* do we need to ramp at all ? */ |
| 529 | if (handsfree->ramp == TWL6040_RAMP_NONE) |
| 530 | return; |
| 531 | |
Peter Ujfalusi | 93eebc69 | 2011-09-29 15:22:35 +0300 | [diff] [blame] | 532 | /* |
| 533 | * HF PGA gain range: 0x00 - 0x1d (0 - 29) */ |
| 534 | for (i = 0; i < 30; i++) { |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 535 | handsfree_complete = twl6040_hf_ramp_step(codec, |
| 536 | handsfree->left_step, |
| 537 | handsfree->right_step); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 538 | |
| 539 | /* ramp finished ? */ |
| 540 | if (handsfree_complete) |
| 541 | break; |
| 542 | |
Peter Ujfalusi | 4d64bdc | 2011-09-26 16:26:31 +0300 | [diff] [blame] | 543 | schedule_timeout_interruptible( |
| 544 | msecs_to_jiffies(handsfree->step_delay)); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | |
| 548 | if (handsfree->ramp == TWL6040_RAMP_DOWN) { |
| 549 | handsfree->active = 0; |
| 550 | complete(&handsfree->ramp_done); |
| 551 | } else |
| 552 | handsfree->active = 1; |
| 553 | handsfree->ramp = TWL6040_RAMP_NONE; |
| 554 | } |
| 555 | |
Peter Ujfalusi | eb6b71e | 2011-09-26 16:26:24 +0300 | [diff] [blame] | 556 | static int out_drv_event(struct snd_soc_dapm_widget *w, |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 557 | struct snd_kcontrol *kcontrol, int event) |
| 558 | { |
| 559 | struct snd_soc_codec *codec = w->codec; |
| 560 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 561 | struct twl6040_output *out; |
| 562 | struct delayed_work *work; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 563 | |
| 564 | switch (w->shift) { |
Peter Ujfalusi | 6fbb32d | 2011-09-29 15:22:36 +0300 | [diff] [blame] | 565 | case 2: /* Headset output driver */ |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 566 | out = &priv->headset; |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 567 | work = &out->work; |
| 568 | /* |
| 569 | * Make sure, that we do not mess up variables for already |
| 570 | * executing work. |
| 571 | */ |
| 572 | cancel_delayed_work_sync(work); |
| 573 | |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 574 | out->left_step = priv->hs_left_step; |
| 575 | out->right_step = priv->hs_right_step; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 576 | out->step_delay = 5; /* 5 ms between volume ramp steps */ |
| 577 | break; |
Peter Ujfalusi | 6fbb32d | 2011-09-29 15:22:36 +0300 | [diff] [blame] | 578 | case 4: /* Handsfree output driver */ |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 579 | out = &priv->handsfree; |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 580 | work = &out->work; |
| 581 | /* |
| 582 | * Make sure, that we do not mess up variables for already |
| 583 | * executing work. |
| 584 | */ |
| 585 | cancel_delayed_work_sync(work); |
| 586 | |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 587 | out->left_step = priv->hf_left_step; |
| 588 | out->right_step = priv->hf_right_step; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 589 | out->step_delay = 5; /* 5 ms between volume ramp steps */ |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 590 | break; |
| 591 | default: |
| 592 | return -1; |
| 593 | } |
| 594 | |
| 595 | switch (event) { |
| 596 | case SND_SOC_DAPM_POST_PMU: |
| 597 | if (out->active) |
| 598 | break; |
| 599 | |
| 600 | /* don't use volume ramp for power-up */ |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 601 | out->ramp = TWL6040_RAMP_UP; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 602 | out->left_step = out->left_vol; |
| 603 | out->right_step = out->right_vol; |
| 604 | |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 605 | queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1)); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 606 | break; |
| 607 | |
| 608 | case SND_SOC_DAPM_PRE_PMD: |
| 609 | if (!out->active) |
| 610 | break; |
| 611 | |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 612 | /* use volume ramp for power-down */ |
| 613 | out->ramp = TWL6040_RAMP_DOWN; |
| 614 | INIT_COMPLETION(out->ramp_done); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 615 | |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 616 | queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1)); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 617 | |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 618 | wait_for_completion_timeout(&out->ramp_done, |
| 619 | msecs_to_jiffies(2000)); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 620 | break; |
| 621 | } |
| 622 | |
| 623 | return 0; |
| 624 | } |
| 625 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 626 | /* set headset dac and driver power mode */ |
| 627 | static int headset_power_mode(struct snd_soc_codec *codec, int high_perf) |
| 628 | { |
| 629 | int hslctl, hsrctl; |
Peter Ujfalusi | ab6cf13 | 2011-09-22 11:05:54 +0300 | [diff] [blame] | 630 | int mask = TWL6040_HSDRVMODE | TWL6040_HSDACMODE; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 631 | |
| 632 | hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL); |
| 633 | hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL); |
| 634 | |
| 635 | if (high_perf) { |
| 636 | hslctl &= ~mask; |
| 637 | hsrctl &= ~mask; |
| 638 | } else { |
| 639 | hslctl |= mask; |
| 640 | hsrctl |= mask; |
| 641 | } |
| 642 | |
| 643 | twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl); |
| 644 | twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl); |
| 645 | |
| 646 | return 0; |
| 647 | } |
| 648 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 649 | static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w, |
| 650 | struct snd_kcontrol *kcontrol, int event) |
| 651 | { |
Peter Ujfalusi | 33b6816 | 2011-10-12 14:46:02 +0300 | [diff] [blame] | 652 | struct snd_soc_codec *codec = w->codec; |
| 653 | u8 hslctl, hsrctl; |
| 654 | |
| 655 | /* |
| 656 | * Workaround for Headset DC offset caused pop noise: |
| 657 | * Both HS DAC need to be turned on (before the HS driver) and off at |
| 658 | * the same time. |
| 659 | */ |
| 660 | hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL); |
| 661 | hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL); |
| 662 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
| 663 | hslctl |= TWL6040_HSDACENA; |
| 664 | hsrctl |= TWL6040_HSDACENA; |
| 665 | } else { |
| 666 | hslctl &= ~TWL6040_HSDACENA; |
| 667 | hsrctl &= ~TWL6040_HSDACENA; |
| 668 | } |
| 669 | twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl); |
| 670 | twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl); |
| 671 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 672 | msleep(1); |
| 673 | return 0; |
| 674 | } |
| 675 | |
Peter Ujfalusi | 694b000 | 2011-10-13 15:05:44 +0300 | [diff] [blame] | 676 | static int twl6040_ep_drv_event(struct snd_soc_dapm_widget *w, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 677 | struct snd_kcontrol *kcontrol, int event) |
| 678 | { |
| 679 | struct snd_soc_codec *codec = w->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 680 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 681 | int ret = 0; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 682 | |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 683 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
Peter Ujfalusi | fac2f3e | 2011-10-13 15:05:42 +0300 | [diff] [blame] | 684 | /* Earphone doesn't support low power mode */ |
| 685 | priv->hs_power_mode_locked = 1; |
| 686 | ret = headset_power_mode(codec, 1); |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 687 | } else { |
Peter Ujfalusi | fac2f3e | 2011-10-13 15:05:42 +0300 | [diff] [blame] | 688 | priv->hs_power_mode_locked = 0; |
| 689 | ret = headset_power_mode(codec, priv->hs_power_mode); |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 690 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 691 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 692 | msleep(1); |
| 693 | |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 694 | return ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Mark Brown | 64ed983 | 2011-01-20 21:43:44 +0000 | [diff] [blame] | 697 | static void twl6040_hs_jack_report(struct snd_soc_codec *codec, |
| 698 | struct snd_soc_jack *jack, int report) |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 699 | { |
| 700 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 701 | int status; |
| 702 | |
| 703 | mutex_lock(&priv->mutex); |
| 704 | |
| 705 | /* Sync status */ |
| 706 | status = twl6040_read_reg_volatile(codec, TWL6040_REG_STATUS); |
| 707 | if (status & TWL6040_PLUGCOMP) |
| 708 | snd_soc_jack_report(jack, report, report); |
| 709 | else |
| 710 | snd_soc_jack_report(jack, 0, report); |
| 711 | |
| 712 | mutex_unlock(&priv->mutex); |
| 713 | } |
| 714 | |
| 715 | void twl6040_hs_jack_detect(struct snd_soc_codec *codec, |
| 716 | struct snd_soc_jack *jack, int report) |
| 717 | { |
| 718 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 719 | struct twl6040_jack_data *hs_jack = &priv->hs_jack; |
| 720 | |
| 721 | hs_jack->jack = jack; |
| 722 | hs_jack->report = report; |
| 723 | |
| 724 | twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report); |
| 725 | } |
| 726 | EXPORT_SYMBOL_GPL(twl6040_hs_jack_detect); |
| 727 | |
| 728 | static void twl6040_accessory_work(struct work_struct *work) |
| 729 | { |
| 730 | struct twl6040_data *priv = container_of(work, |
Peter Ujfalusi | 46dd0b9 | 2011-09-26 16:26:27 +0300 | [diff] [blame] | 731 | struct twl6040_data, hs_jack.work.work); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 732 | struct snd_soc_codec *codec = priv->codec; |
| 733 | struct twl6040_jack_data *hs_jack = &priv->hs_jack; |
| 734 | |
| 735 | twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report); |
| 736 | } |
| 737 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 738 | /* audio interrupt handler */ |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 739 | static irqreturn_t twl6040_audio_handler(int irq, void *data) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 740 | { |
| 741 | struct snd_soc_codec *codec = data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 742 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 743 | |
Peter Ujfalusi | 46dd0b9 | 2011-09-26 16:26:27 +0300 | [diff] [blame] | 744 | queue_delayed_work(priv->workqueue, &priv->hs_jack.work, |
Peter Ujfalusi | f34c660 | 2011-09-23 09:52:02 +0300 | [diff] [blame] | 745 | msecs_to_jiffies(200)); |
Olaya, Margarita | cf370a5 | 2010-12-10 21:05:30 -0600 | [diff] [blame] | 746 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 747 | return IRQ_HANDLED; |
| 748 | } |
| 749 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 750 | static int twl6040_put_volsw(struct snd_kcontrol *kcontrol, |
| 751 | struct snd_ctl_elem_value *ucontrol) |
| 752 | { |
| 753 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 754 | struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec); |
| 755 | struct twl6040_output *out = NULL; |
| 756 | struct soc_mixer_control *mc = |
| 757 | (struct soc_mixer_control *)kcontrol->private_value; |
Peter Ujfalusi | db382da | 2011-10-05 10:29:26 +0300 | [diff] [blame] | 758 | int ret; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 759 | |
| 760 | /* For HS and HF we shadow the values and only actually write |
| 761 | * them out when active in order to ensure the amplifier comes on |
| 762 | * as quietly as possible. */ |
Peter Ujfalusi | a8cc718 | 2011-09-26 16:26:25 +0300 | [diff] [blame] | 763 | switch (mc->reg) { |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 764 | case TWL6040_REG_HSGAIN: |
| 765 | out = &twl6040_priv->headset; |
| 766 | break; |
Peter Ujfalusi | a8cc718 | 2011-09-26 16:26:25 +0300 | [diff] [blame] | 767 | case TWL6040_REG_HFLGAIN: |
| 768 | out = &twl6040_priv->handsfree; |
| 769 | break; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 770 | default: |
Peter Ujfalusi | a0acf47 | 2011-10-05 10:29:28 +0300 | [diff] [blame] | 771 | dev_warn(codec->dev, "%s: Unexpected register: 0x%02x\n", |
| 772 | __func__, mc->reg); |
Peter Ujfalusi | bfd3d4e | 2011-10-04 14:39:42 +0300 | [diff] [blame] | 773 | return -EINVAL; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 774 | } |
| 775 | |
Peter Ujfalusi | bfd3d4e | 2011-10-04 14:39:42 +0300 | [diff] [blame] | 776 | out->left_vol = ucontrol->value.integer.value[0]; |
| 777 | out->right_vol = ucontrol->value.integer.value[1]; |
| 778 | if (!out->active) |
| 779 | return 1; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 780 | |
Peter Ujfalusi | db382da | 2011-10-05 10:29:26 +0300 | [diff] [blame] | 781 | ret = snd_soc_put_volsw(kcontrol, ucontrol); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 782 | if (ret < 0) |
| 783 | return ret; |
| 784 | |
| 785 | return 1; |
| 786 | } |
| 787 | |
| 788 | static int twl6040_get_volsw(struct snd_kcontrol *kcontrol, |
| 789 | struct snd_ctl_elem_value *ucontrol) |
| 790 | { |
| 791 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 792 | struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec); |
| 793 | struct twl6040_output *out = &twl6040_priv->headset; |
| 794 | struct soc_mixer_control *mc = |
| 795 | (struct soc_mixer_control *)kcontrol->private_value; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 796 | |
Peter Ujfalusi | a8cc718 | 2011-09-26 16:26:25 +0300 | [diff] [blame] | 797 | switch (mc->reg) { |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 798 | case TWL6040_REG_HSGAIN: |
| 799 | out = &twl6040_priv->headset; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 800 | break; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 801 | case TWL6040_REG_HFLGAIN: |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 802 | out = &twl6040_priv->handsfree; |
| 803 | break; |
| 804 | default: |
Peter Ujfalusi | e49b683 | 2011-10-05 10:29:20 +0300 | [diff] [blame] | 805 | dev_warn(codec->dev, "%s: Unexpected register: 0x%02x\n", |
| 806 | __func__, mc->reg); |
| 807 | return -EINVAL; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 808 | } |
| 809 | |
Peter Ujfalusi | e49b683 | 2011-10-05 10:29:20 +0300 | [diff] [blame] | 810 | ucontrol->value.integer.value[0] = out->left_vol; |
| 811 | ucontrol->value.integer.value[1] = out->right_vol; |
| 812 | return 0; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 813 | } |
| 814 | |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 815 | static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol, |
| 816 | struct snd_ctl_elem_value *ucontrol) |
| 817 | { |
| 818 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 819 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 820 | struct snd_soc_codec *codec = widget->codec; |
| 821 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 822 | unsigned int val; |
| 823 | |
| 824 | /* Do not allow changes while Input/FF efect is running */ |
| 825 | val = twl6040_read_reg_volatile(codec, e->reg); |
| 826 | if (val & TWL6040_VIBENA && !(val & TWL6040_VIBSEL)) |
| 827 | return -EBUSY; |
| 828 | |
| 829 | return snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 830 | } |
| 831 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 832 | /* |
| 833 | * MICATT volume control: |
| 834 | * from -6 to 0 dB in 6 dB steps |
| 835 | */ |
| 836 | static DECLARE_TLV_DB_SCALE(mic_preamp_tlv, -600, 600, 0); |
| 837 | |
| 838 | /* |
| 839 | * MICGAIN volume control: |
Ricardo Neri | 2763f45 | 2011-05-01 15:35:55 +0100 | [diff] [blame] | 840 | * from 6 to 30 dB in 6 dB steps |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 841 | */ |
Ricardo Neri | 2763f45 | 2011-05-01 15:35:55 +0100 | [diff] [blame] | 842 | static DECLARE_TLV_DB_SCALE(mic_amp_tlv, 600, 600, 0); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 843 | |
| 844 | /* |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 845 | * AFMGAIN volume control: |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 846 | * from -18 to 24 dB in 6 dB steps |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 847 | */ |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 848 | static DECLARE_TLV_DB_SCALE(afm_amp_tlv, -1800, 600, 0); |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 849 | |
| 850 | /* |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 851 | * HSGAIN volume control: |
| 852 | * from -30 to 0 dB in 2 dB steps |
| 853 | */ |
| 854 | static DECLARE_TLV_DB_SCALE(hs_tlv, -3000, 200, 0); |
| 855 | |
| 856 | /* |
| 857 | * HFGAIN volume control: |
| 858 | * from -52 to 6 dB in 2 dB steps |
| 859 | */ |
| 860 | static DECLARE_TLV_DB_SCALE(hf_tlv, -5200, 200, 0); |
| 861 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 862 | /* |
| 863 | * EPGAIN volume control: |
| 864 | * from -24 to 6 dB in 2 dB steps |
| 865 | */ |
| 866 | static DECLARE_TLV_DB_SCALE(ep_tlv, -2400, 200, 0); |
| 867 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 868 | /* Left analog microphone selection */ |
| 869 | static const char *twl6040_amicl_texts[] = |
| 870 | {"Headset Mic", "Main Mic", "Aux/FM Left", "Off"}; |
| 871 | |
| 872 | /* Right analog microphone selection */ |
| 873 | static const char *twl6040_amicr_texts[] = |
| 874 | {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"}; |
| 875 | |
| 876 | static const struct soc_enum twl6040_enum[] = { |
Francois Mazard | cb973d7 | 2010-12-10 21:06:03 -0600 | [diff] [blame] | 877 | SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3, 4, twl6040_amicl_texts), |
| 878 | SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3, 4, twl6040_amicr_texts), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 879 | }; |
| 880 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 881 | static const char *twl6040_hs_texts[] = { |
| 882 | "Off", "HS DAC", "Line-In amp" |
| 883 | }; |
| 884 | |
| 885 | static const struct soc_enum twl6040_hs_enum[] = { |
| 886 | SOC_ENUM_SINGLE(TWL6040_REG_HSLCTL, 5, ARRAY_SIZE(twl6040_hs_texts), |
| 887 | twl6040_hs_texts), |
| 888 | SOC_ENUM_SINGLE(TWL6040_REG_HSRCTL, 5, ARRAY_SIZE(twl6040_hs_texts), |
| 889 | twl6040_hs_texts), |
| 890 | }; |
| 891 | |
| 892 | static const char *twl6040_hf_texts[] = { |
| 893 | "Off", "HF DAC", "Line-In amp" |
| 894 | }; |
| 895 | |
| 896 | static const struct soc_enum twl6040_hf_enum[] = { |
| 897 | SOC_ENUM_SINGLE(TWL6040_REG_HFLCTL, 2, ARRAY_SIZE(twl6040_hf_texts), |
| 898 | twl6040_hf_texts), |
| 899 | SOC_ENUM_SINGLE(TWL6040_REG_HFRCTL, 2, ARRAY_SIZE(twl6040_hf_texts), |
| 900 | twl6040_hf_texts), |
| 901 | }; |
| 902 | |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 903 | static const char *twl6040_vibrapath_texts[] = { |
| 904 | "Input FF", "Audio PDM" |
| 905 | }; |
| 906 | |
| 907 | static const struct soc_enum twl6040_vibra_enum[] = { |
| 908 | SOC_ENUM_SINGLE(TWL6040_REG_VIBCTLL, 1, |
| 909 | ARRAY_SIZE(twl6040_vibrapath_texts), |
| 910 | twl6040_vibrapath_texts), |
| 911 | SOC_ENUM_SINGLE(TWL6040_REG_VIBCTLR, 1, |
| 912 | ARRAY_SIZE(twl6040_vibrapath_texts), |
| 913 | twl6040_vibrapath_texts), |
| 914 | }; |
| 915 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 916 | static const struct snd_kcontrol_new amicl_control = |
| 917 | SOC_DAPM_ENUM("Route", twl6040_enum[0]); |
| 918 | |
| 919 | static const struct snd_kcontrol_new amicr_control = |
| 920 | SOC_DAPM_ENUM("Route", twl6040_enum[1]); |
| 921 | |
| 922 | /* Headset DAC playback switches */ |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 923 | static const struct snd_kcontrol_new hsl_mux_controls = |
| 924 | SOC_DAPM_ENUM("Route", twl6040_hs_enum[0]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 925 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 926 | static const struct snd_kcontrol_new hsr_mux_controls = |
| 927 | SOC_DAPM_ENUM("Route", twl6040_hs_enum[1]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 928 | |
| 929 | /* Handsfree DAC playback switches */ |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 930 | static const struct snd_kcontrol_new hfl_mux_controls = |
| 931 | SOC_DAPM_ENUM("Route", twl6040_hf_enum[0]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 932 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 933 | static const struct snd_kcontrol_new hfr_mux_controls = |
| 934 | SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 935 | |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 936 | static const struct snd_kcontrol_new ep_path_enable_control = |
| 937 | SOC_DAPM_SINGLE("Switch", TWL6040_REG_SW_SHADOW, 0, 1, 0); |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 938 | |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 939 | static const struct snd_kcontrol_new auxl_switch_control = |
| 940 | SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 6, 1, 0); |
| 941 | |
| 942 | static const struct snd_kcontrol_new auxr_switch_control = |
| 943 | SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFRCTL, 6, 1, 0); |
| 944 | |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 945 | /* Vibra playback switches */ |
| 946 | static const struct snd_kcontrol_new vibral_mux_controls = |
| 947 | SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[0], |
| 948 | snd_soc_dapm_get_enum_double, |
| 949 | twl6040_soc_dapm_put_vibra_enum); |
| 950 | |
| 951 | static const struct snd_kcontrol_new vibrar_mux_controls = |
| 952 | SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[1], |
| 953 | snd_soc_dapm_get_enum_double, |
| 954 | twl6040_soc_dapm_put_vibra_enum); |
| 955 | |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 956 | /* Headset power mode */ |
Peter Ujfalusi | 7cca606 | 2011-06-27 13:33:14 +0300 | [diff] [blame] | 957 | static const char *twl6040_power_mode_texts[] = { |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 958 | "Low-Power", "High-Perfomance", |
| 959 | }; |
| 960 | |
Peter Ujfalusi | 7cca606 | 2011-06-27 13:33:14 +0300 | [diff] [blame] | 961 | static const struct soc_enum twl6040_power_mode_enum = |
| 962 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(twl6040_power_mode_texts), |
| 963 | twl6040_power_mode_texts); |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 964 | |
| 965 | static int twl6040_headset_power_get_enum(struct snd_kcontrol *kcontrol, |
| 966 | struct snd_ctl_elem_value *ucontrol) |
| 967 | { |
| 968 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 969 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 970 | |
| 971 | ucontrol->value.enumerated.item[0] = priv->hs_power_mode; |
| 972 | |
| 973 | return 0; |
| 974 | } |
| 975 | |
| 976 | static int twl6040_headset_power_put_enum(struct snd_kcontrol *kcontrol, |
| 977 | struct snd_ctl_elem_value *ucontrol) |
| 978 | { |
| 979 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 980 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 981 | int high_perf = ucontrol->value.enumerated.item[0]; |
| 982 | int ret = 0; |
| 983 | |
| 984 | if (!priv->hs_power_mode_locked) |
| 985 | ret = headset_power_mode(codec, high_perf); |
| 986 | |
| 987 | if (!ret) |
| 988 | priv->hs_power_mode = high_perf; |
| 989 | |
| 990 | return ret; |
| 991 | } |
| 992 | |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 993 | static int twl6040_pll_get_enum(struct snd_kcontrol *kcontrol, |
| 994 | struct snd_ctl_elem_value *ucontrol) |
| 995 | { |
| 996 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 997 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 998 | |
| 999 | ucontrol->value.enumerated.item[0] = priv->pll_power_mode; |
| 1000 | |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
| 1004 | static int twl6040_pll_put_enum(struct snd_kcontrol *kcontrol, |
| 1005 | struct snd_ctl_elem_value *ucontrol) |
| 1006 | { |
| 1007 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1008 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 1009 | |
| 1010 | priv->pll_power_mode = ucontrol->value.enumerated.item[0]; |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 1011 | |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | int twl6040_get_clk_id(struct snd_soc_codec *codec) |
| 1016 | { |
| 1017 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 1018 | |
Peter Ujfalusi | ff593ca | 2011-07-04 10:35:23 +0300 | [diff] [blame] | 1019 | return priv->pll_power_mode; |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 1020 | } |
| 1021 | EXPORT_SYMBOL_GPL(twl6040_get_clk_id); |
| 1022 | |
Peter Ujfalusi | db4aabc | 2011-09-26 16:05:57 +0300 | [diff] [blame] | 1023 | int twl6040_get_trim_value(struct snd_soc_codec *codec, enum twl6040_trim trim) |
| 1024 | { |
| 1025 | if (unlikely(trim >= TWL6040_TRIM_INVAL)) |
| 1026 | return -EINVAL; |
| 1027 | |
| 1028 | return twl6040_read_reg_cache(codec, TWL6040_REG_TRIM1 + trim); |
| 1029 | } |
| 1030 | EXPORT_SYMBOL_GPL(twl6040_get_trim_value); |
| 1031 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1032 | static const struct snd_kcontrol_new twl6040_snd_controls[] = { |
| 1033 | /* Capture gains */ |
| 1034 | SOC_DOUBLE_TLV("Capture Preamplifier Volume", |
| 1035 | TWL6040_REG_MICGAIN, 6, 7, 1, 1, mic_preamp_tlv), |
| 1036 | SOC_DOUBLE_TLV("Capture Volume", |
| 1037 | TWL6040_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv), |
| 1038 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1039 | /* AFM gains */ |
| 1040 | SOC_DOUBLE_TLV("Aux FM Volume", |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 1041 | TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv), |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1042 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1043 | /* Playback gains */ |
Peter Ujfalusi | 0f9887d | 2011-10-05 10:29:19 +0300 | [diff] [blame] | 1044 | SOC_DOUBLE_EXT_TLV("Headset Playback Volume", |
| 1045 | TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, twl6040_get_volsw, |
| 1046 | twl6040_put_volsw, hs_tlv), |
| 1047 | SOC_DOUBLE_R_EXT_TLV("Handsfree Playback Volume", |
| 1048 | TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, |
| 1049 | twl6040_get_volsw, twl6040_put_volsw, hf_tlv), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 1050 | SOC_SINGLE_TLV("Earphone Playback Volume", |
| 1051 | TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv), |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 1052 | |
Peter Ujfalusi | 7cca606 | 2011-06-27 13:33:14 +0300 | [diff] [blame] | 1053 | SOC_ENUM_EXT("Headset Power Mode", twl6040_power_mode_enum, |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 1054 | twl6040_headset_power_get_enum, |
| 1055 | twl6040_headset_power_put_enum), |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 1056 | |
| 1057 | SOC_ENUM_EXT("PLL Selection", twl6040_power_mode_enum, |
| 1058 | twl6040_pll_get_enum, twl6040_pll_put_enum), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1059 | }; |
| 1060 | |
| 1061 | static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = { |
| 1062 | /* Inputs */ |
| 1063 | SND_SOC_DAPM_INPUT("MAINMIC"), |
| 1064 | SND_SOC_DAPM_INPUT("HSMIC"), |
| 1065 | SND_SOC_DAPM_INPUT("SUBMIC"), |
| 1066 | SND_SOC_DAPM_INPUT("AFML"), |
| 1067 | SND_SOC_DAPM_INPUT("AFMR"), |
| 1068 | |
| 1069 | /* Outputs */ |
| 1070 | SND_SOC_DAPM_OUTPUT("HSOL"), |
| 1071 | SND_SOC_DAPM_OUTPUT("HSOR"), |
| 1072 | SND_SOC_DAPM_OUTPUT("HFL"), |
| 1073 | SND_SOC_DAPM_OUTPUT("HFR"), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 1074 | SND_SOC_DAPM_OUTPUT("EP"), |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 1075 | SND_SOC_DAPM_OUTPUT("AUXL"), |
| 1076 | SND_SOC_DAPM_OUTPUT("AUXR"), |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 1077 | SND_SOC_DAPM_OUTPUT("VIBRAL"), |
| 1078 | SND_SOC_DAPM_OUTPUT("VIBRAR"), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1079 | |
| 1080 | /* Analog input muxes for the capture amplifiers */ |
| 1081 | SND_SOC_DAPM_MUX("Analog Left Capture Route", |
| 1082 | SND_SOC_NOPM, 0, 0, &amicl_control), |
| 1083 | SND_SOC_DAPM_MUX("Analog Right Capture Route", |
| 1084 | SND_SOC_NOPM, 0, 0, &amicr_control), |
| 1085 | |
| 1086 | /* Analog capture PGAs */ |
| 1087 | SND_SOC_DAPM_PGA("MicAmpL", |
| 1088 | TWL6040_REG_MICLCTL, 0, 0, NULL, 0), |
| 1089 | SND_SOC_DAPM_PGA("MicAmpR", |
| 1090 | TWL6040_REG_MICRCTL, 0, 0, NULL, 0), |
| 1091 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1092 | /* Auxiliary FM PGAs */ |
| 1093 | SND_SOC_DAPM_PGA("AFMAmpL", |
| 1094 | TWL6040_REG_MICLCTL, 1, 0, NULL, 0), |
| 1095 | SND_SOC_DAPM_PGA("AFMAmpR", |
| 1096 | TWL6040_REG_MICRCTL, 1, 0, NULL, 0), |
| 1097 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1098 | /* ADCs */ |
| 1099 | SND_SOC_DAPM_ADC("ADC Left", "Left Front Capture", |
| 1100 | TWL6040_REG_MICLCTL, 2, 0), |
| 1101 | SND_SOC_DAPM_ADC("ADC Right", "Right Front Capture", |
| 1102 | TWL6040_REG_MICRCTL, 2, 0), |
| 1103 | |
| 1104 | /* Microphone bias */ |
| 1105 | SND_SOC_DAPM_MICBIAS("Headset Mic Bias", |
| 1106 | TWL6040_REG_AMICBCTL, 0, 0), |
| 1107 | SND_SOC_DAPM_MICBIAS("Main Mic Bias", |
| 1108 | TWL6040_REG_AMICBCTL, 4, 0), |
| 1109 | SND_SOC_DAPM_MICBIAS("Digital Mic1 Bias", |
| 1110 | TWL6040_REG_DMICBCTL, 0, 0), |
| 1111 | SND_SOC_DAPM_MICBIAS("Digital Mic2 Bias", |
| 1112 | TWL6040_REG_DMICBCTL, 4, 0), |
| 1113 | |
| 1114 | /* DACs */ |
Peter Ujfalusi | 33b6816 | 2011-10-12 14:46:02 +0300 | [diff] [blame] | 1115 | SND_SOC_DAPM_DAC("HSDAC Left", "Headset Playback", SND_SOC_NOPM, 0, 0), |
| 1116 | SND_SOC_DAPM_DAC("HSDAC Right", "Headset Playback", SND_SOC_NOPM, 0, 0), |
Peter Ujfalusi | fac2f3e | 2011-10-13 15:05:42 +0300 | [diff] [blame] | 1117 | SND_SOC_DAPM_DAC("HFDAC Left", "Handsfree Playback", |
| 1118 | TWL6040_REG_HFLCTL, 0, 0), |
| 1119 | SND_SOC_DAPM_DAC("HFDAC Right", "Handsfree Playback", |
| 1120 | TWL6040_REG_HFRCTL, 0, 0), |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 1121 | /* Virtual DAC for vibra path (DL4 channel) */ |
| 1122 | SND_SOC_DAPM_DAC("VIBRA DAC", "Vibra Playback", |
| 1123 | SND_SOC_NOPM, 0, 0), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1124 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1125 | SND_SOC_DAPM_MUX("Handsfree Left Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1126 | SND_SOC_NOPM, 0, 0, &hfl_mux_controls), |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1127 | SND_SOC_DAPM_MUX("Handsfree Right Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1128 | SND_SOC_NOPM, 0, 0, &hfr_mux_controls), |
| 1129 | /* Analog playback Muxes */ |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1130 | SND_SOC_DAPM_MUX("Headset Left Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1131 | SND_SOC_NOPM, 0, 0, &hsl_mux_controls), |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1132 | SND_SOC_DAPM_MUX("Headset Right Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1133 | SND_SOC_NOPM, 0, 0, &hsr_mux_controls), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1134 | |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 1135 | SND_SOC_DAPM_MUX("Vibra Left Playback", SND_SOC_NOPM, 0, 0, |
| 1136 | &vibral_mux_controls), |
| 1137 | SND_SOC_DAPM_MUX("Vibra Right Playback", SND_SOC_NOPM, 0, 0, |
| 1138 | &vibrar_mux_controls), |
| 1139 | |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 1140 | SND_SOC_DAPM_SWITCH("Earphone Playback", SND_SOC_NOPM, 0, 0, |
| 1141 | &ep_path_enable_control), |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 1142 | SND_SOC_DAPM_SWITCH("AUXL Playback", SND_SOC_NOPM, 0, 0, |
| 1143 | &auxl_switch_control), |
| 1144 | SND_SOC_DAPM_SWITCH("AUXR Playback", SND_SOC_NOPM, 0, 0, |
| 1145 | &auxr_switch_control), |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 1146 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 1147 | /* Analog playback drivers */ |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1148 | SND_SOC_DAPM_OUT_DRV_E("HF Left Driver", |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 1149 | TWL6040_REG_HFLCTL, 4, 0, NULL, 0, |
Peter Ujfalusi | eb6b71e | 2011-09-26 16:26:24 +0300 | [diff] [blame] | 1150 | out_drv_event, |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1151 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1152 | SND_SOC_DAPM_OUT_DRV_E("HF Right Driver", |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 1153 | TWL6040_REG_HFRCTL, 4, 0, NULL, 0, |
Peter Ujfalusi | eb6b71e | 2011-09-26 16:26:24 +0300 | [diff] [blame] | 1154 | out_drv_event, |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1155 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1156 | SND_SOC_DAPM_OUT_DRV_E("HS Left Driver", |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1157 | TWL6040_REG_HSLCTL, 2, 0, NULL, 0, |
Peter Ujfalusi | eb6b71e | 2011-09-26 16:26:24 +0300 | [diff] [blame] | 1158 | out_drv_event, |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1159 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1160 | SND_SOC_DAPM_OUT_DRV_E("HS Right Driver", |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1161 | TWL6040_REG_HSRCTL, 2, 0, NULL, 0, |
Peter Ujfalusi | eb6b71e | 2011-09-26 16:26:24 +0300 | [diff] [blame] | 1162 | out_drv_event, |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1163 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 1164 | SND_SOC_DAPM_OUT_DRV_E("Earphone Driver", |
| 1165 | TWL6040_REG_EARCTL, 0, 0, NULL, 0, |
Peter Ujfalusi | 694b000 | 2011-10-13 15:05:44 +0300 | [diff] [blame] | 1166 | twl6040_ep_drv_event, |
Peter Ujfalusi | aa1a410 | 2011-10-13 15:05:43 +0300 | [diff] [blame] | 1167 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 1168 | SND_SOC_DAPM_OUT_DRV("Vibra Left Driver", |
| 1169 | TWL6040_REG_VIBCTLL, 0, 0, NULL, 0), |
| 1170 | SND_SOC_DAPM_OUT_DRV("Vibra Right Driver", |
| 1171 | TWL6040_REG_VIBCTLR, 0, 0, NULL, 0), |
| 1172 | |
| 1173 | SND_SOC_DAPM_SUPPLY("Vibra Left Control", TWL6040_REG_VIBCTLL, 2, 0, |
| 1174 | NULL, 0), |
| 1175 | SND_SOC_DAPM_SUPPLY("Vibra Right Control", TWL6040_REG_VIBCTLR, 2, 0, |
| 1176 | NULL, 0), |
Peter Ujfalusi | 33b6816 | 2011-10-12 14:46:02 +0300 | [diff] [blame] | 1177 | SND_SOC_DAPM_SUPPLY_S("HSDAC Power", 1, SND_SOC_NOPM, 0, 0, |
| 1178 | twl6040_hs_dac_event, |
| 1179 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1180 | |
| 1181 | /* Analog playback PGAs */ |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1182 | SND_SOC_DAPM_PGA("HF Left PGA", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1183 | TWL6040_REG_HFLCTL, 1, 0, NULL, 0), |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1184 | SND_SOC_DAPM_PGA("HF Right PGA", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1185 | TWL6040_REG_HFRCTL, 1, 0, NULL, 0), |
| 1186 | |
| 1187 | }; |
| 1188 | |
| 1189 | static const struct snd_soc_dapm_route intercon[] = { |
| 1190 | /* Capture path */ |
| 1191 | {"Analog Left Capture Route", "Headset Mic", "HSMIC"}, |
| 1192 | {"Analog Left Capture Route", "Main Mic", "MAINMIC"}, |
| 1193 | {"Analog Left Capture Route", "Aux/FM Left", "AFML"}, |
| 1194 | |
| 1195 | {"Analog Right Capture Route", "Headset Mic", "HSMIC"}, |
| 1196 | {"Analog Right Capture Route", "Sub Mic", "SUBMIC"}, |
| 1197 | {"Analog Right Capture Route", "Aux/FM Right", "AFMR"}, |
| 1198 | |
| 1199 | {"MicAmpL", NULL, "Analog Left Capture Route"}, |
| 1200 | {"MicAmpR", NULL, "Analog Right Capture Route"}, |
| 1201 | |
| 1202 | {"ADC Left", NULL, "MicAmpL"}, |
| 1203 | {"ADC Right", NULL, "MicAmpR"}, |
| 1204 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1205 | /* AFM path */ |
Peter Ujfalusi | 5bf692d | 2011-09-22 11:05:47 +0300 | [diff] [blame] | 1206 | {"AFMAmpL", NULL, "AFML"}, |
| 1207 | {"AFMAmpR", NULL, "AFMR"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1208 | |
Peter Ujfalusi | 33b6816 | 2011-10-12 14:46:02 +0300 | [diff] [blame] | 1209 | {"HSDAC Left", NULL, "HSDAC Power"}, |
| 1210 | {"HSDAC Right", NULL, "HSDAC Power"}, |
| 1211 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1212 | {"Headset Left Playback", "HS DAC", "HSDAC Left"}, |
| 1213 | {"Headset Left Playback", "Line-In amp", "AFMAmpL"}, |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1214 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1215 | {"Headset Right Playback", "HS DAC", "HSDAC Right"}, |
| 1216 | {"Headset Right Playback", "Line-In amp", "AFMAmpR"}, |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1217 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1218 | {"HS Left Driver", NULL, "Headset Left Playback"}, |
| 1219 | {"HS Right Driver", NULL, "Headset Right Playback"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1220 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1221 | {"HSOL", NULL, "HS Left Driver"}, |
| 1222 | {"HSOR", NULL, "HS Right Driver"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1223 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 1224 | /* Earphone playback path */ |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 1225 | {"Earphone Playback", "Switch", "HSDAC Left"}, |
| 1226 | {"Earphone Driver", NULL, "Earphone Playback"}, |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 1227 | {"EP", NULL, "Earphone Driver"}, |
| 1228 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1229 | {"Handsfree Left Playback", "HF DAC", "HFDAC Left"}, |
| 1230 | {"Handsfree Left Playback", "Line-In amp", "AFMAmpL"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1231 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1232 | {"Handsfree Right Playback", "HF DAC", "HFDAC Right"}, |
| 1233 | {"Handsfree Right Playback", "Line-In amp", "AFMAmpR"}, |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1234 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1235 | {"HF Left PGA", NULL, "Handsfree Left Playback"}, |
| 1236 | {"HF Right PGA", NULL, "Handsfree Right Playback"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1237 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1238 | {"HF Left Driver", NULL, "HF Left PGA"}, |
| 1239 | {"HF Right Driver", NULL, "HF Right PGA"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1240 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1241 | {"HFL", NULL, "HF Left Driver"}, |
| 1242 | {"HFR", NULL, "HF Right Driver"}, |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 1243 | |
| 1244 | {"AUXL Playback", "Switch", "HF Left PGA"}, |
| 1245 | {"AUXR Playback", "Switch", "HF Right PGA"}, |
| 1246 | |
| 1247 | {"AUXL", NULL, "AUXL Playback"}, |
| 1248 | {"AUXR", NULL, "AUXR Playback"}, |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 1249 | |
| 1250 | /* Vibrator paths */ |
| 1251 | {"Vibra Left Playback", "Audio PDM", "VIBRA DAC"}, |
| 1252 | {"Vibra Right Playback", "Audio PDM", "VIBRA DAC"}, |
| 1253 | |
| 1254 | {"Vibra Left Driver", NULL, "Vibra Left Playback"}, |
| 1255 | {"Vibra Right Driver", NULL, "Vibra Right Playback"}, |
| 1256 | {"Vibra Left Driver", NULL, "Vibra Left Control"}, |
| 1257 | {"Vibra Right Driver", NULL, "Vibra Right Control"}, |
| 1258 | |
| 1259 | {"VIBRAL", NULL, "Vibra Left Driver"}, |
| 1260 | {"VIBRAR", NULL, "Vibra Right Driver"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1261 | }; |
| 1262 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1263 | static int twl6040_set_bias_level(struct snd_soc_codec *codec, |
| 1264 | enum snd_soc_bias_level level) |
| 1265 | { |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1266 | struct twl6040 *twl6040 = codec->control_data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1267 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1268 | int ret; |
| 1269 | |
| 1270 | switch (level) { |
| 1271 | case SND_SOC_BIAS_ON: |
| 1272 | break; |
| 1273 | case SND_SOC_BIAS_PREPARE: |
| 1274 | break; |
| 1275 | case SND_SOC_BIAS_STANDBY: |
| 1276 | if (priv->codec_powered) |
| 1277 | break; |
| 1278 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1279 | ret = twl6040_power(twl6040, 1); |
| 1280 | if (ret) |
| 1281 | return ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1282 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1283 | priv->codec_powered = 1; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1284 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 1285 | twl6040_restore_regs(codec); |
Olaya, Margarita | 65b7cec | 2010-12-14 19:18:36 -0600 | [diff] [blame] | 1286 | |
| 1287 | /* Set external boost GPO */ |
| 1288 | twl6040_write(codec, TWL6040_REG_GPOCTL, 0x02); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1289 | break; |
| 1290 | case SND_SOC_BIAS_OFF: |
| 1291 | if (!priv->codec_powered) |
| 1292 | break; |
| 1293 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1294 | twl6040_power(twl6040, 0); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1295 | priv->codec_powered = 0; |
| 1296 | break; |
| 1297 | } |
| 1298 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1299 | codec->dapm.bias_level = level; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1300 | |
| 1301 | return 0; |
| 1302 | } |
| 1303 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1304 | static int twl6040_startup(struct snd_pcm_substream *substream, |
| 1305 | struct snd_soc_dai *dai) |
| 1306 | { |
| 1307 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1308 | struct snd_soc_codec *codec = rtd->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1309 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1310 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1311 | snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 1312 | SNDRV_PCM_HW_PARAM_RATE, |
Peter Ujfalusi | f53c346 | 2011-06-29 13:28:18 +0300 | [diff] [blame] | 1313 | &sysclk_constraints[priv->pll_power_mode]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1314 | |
| 1315 | return 0; |
| 1316 | } |
| 1317 | |
| 1318 | static int twl6040_hw_params(struct snd_pcm_substream *substream, |
| 1319 | struct snd_pcm_hw_params *params, |
| 1320 | struct snd_soc_dai *dai) |
| 1321 | { |
| 1322 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1323 | struct snd_soc_codec *codec = rtd->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1324 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1325 | int rate; |
| 1326 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1327 | rate = params_rate(params); |
| 1328 | switch (rate) { |
Olaya, Margarita | 60ea4ce | 2010-12-10 21:05:58 -0600 | [diff] [blame] | 1329 | case 11250: |
| 1330 | case 22500: |
| 1331 | case 44100: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1332 | case 88200: |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1333 | /* These rates are not supported when HPPLL is in use */ |
| 1334 | if (unlikely(priv->pll == TWL6040_SYSCLK_SEL_HPPLL)) { |
| 1335 | dev_err(codec->dev, "HPPLL does not support rate %d\n", |
| 1336 | rate); |
| 1337 | return -EINVAL; |
| 1338 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1339 | priv->sysclk = 17640000; |
| 1340 | break; |
Olaya, Margarita | 60ea4ce | 2010-12-10 21:05:58 -0600 | [diff] [blame] | 1341 | case 8000: |
| 1342 | case 16000: |
| 1343 | case 32000: |
| 1344 | case 48000: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1345 | case 96000: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1346 | priv->sysclk = 19200000; |
| 1347 | break; |
| 1348 | default: |
| 1349 | dev_err(codec->dev, "unsupported rate %d\n", rate); |
| 1350 | return -EINVAL; |
| 1351 | } |
| 1352 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1353 | return 0; |
| 1354 | } |
| 1355 | |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1356 | static int twl6040_prepare(struct snd_pcm_substream *substream, |
| 1357 | struct snd_soc_dai *dai) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1358 | { |
| 1359 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1360 | struct snd_soc_codec *codec = rtd->codec; |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1361 | struct twl6040 *twl6040 = codec->control_data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1362 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1363 | int ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1364 | |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1365 | if (!priv->sysclk) { |
| 1366 | dev_err(codec->dev, |
| 1367 | "no mclk configured, call set_sysclk() on init\n"); |
| 1368 | return -EINVAL; |
| 1369 | } |
| 1370 | |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1371 | ret = twl6040_set_pll(twl6040, priv->pll, priv->clk_in, priv->sysclk); |
| 1372 | if (ret) { |
| 1373 | dev_err(codec->dev, "Can not set PLL (%d)\n", ret); |
| 1374 | return -EPERM; |
| 1375 | } |
| 1376 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1377 | return 0; |
| 1378 | } |
| 1379 | |
| 1380 | static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 1381 | int clk_id, unsigned int freq, int dir) |
| 1382 | { |
| 1383 | struct snd_soc_codec *codec = codec_dai->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1384 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1385 | |
| 1386 | switch (clk_id) { |
| 1387 | case TWL6040_SYSCLK_SEL_LPPLL: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1388 | case TWL6040_SYSCLK_SEL_HPPLL: |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1389 | priv->pll = clk_id; |
| 1390 | priv->clk_in = freq; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1391 | break; |
| 1392 | default: |
| 1393 | dev_err(codec->dev, "unknown clk_id %d\n", clk_id); |
| 1394 | return -EINVAL; |
| 1395 | } |
| 1396 | |
| 1397 | return 0; |
| 1398 | } |
| 1399 | |
| 1400 | static struct snd_soc_dai_ops twl6040_dai_ops = { |
| 1401 | .startup = twl6040_startup, |
| 1402 | .hw_params = twl6040_hw_params, |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1403 | .prepare = twl6040_prepare, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1404 | .set_sysclk = twl6040_set_dai_sysclk, |
| 1405 | }; |
| 1406 | |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1407 | static struct snd_soc_dai_driver twl6040_dai[] = { |
| 1408 | { |
Peter Ujfalusi | d13f1fe | 2011-09-22 11:05:53 +0300 | [diff] [blame] | 1409 | .name = "twl6040-legacy", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1410 | .playback = { |
| 1411 | .stream_name = "Playback", |
| 1412 | .channels_min = 1, |
Peter Ujfalusi | cdd5054 | 2011-09-15 15:59:19 +0300 | [diff] [blame] | 1413 | .channels_max = 5, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1414 | .rates = TWL6040_RATES, |
| 1415 | .formats = TWL6040_FORMATS, |
| 1416 | }, |
| 1417 | .capture = { |
| 1418 | .stream_name = "Capture", |
| 1419 | .channels_min = 1, |
| 1420 | .channels_max = 2, |
| 1421 | .rates = TWL6040_RATES, |
| 1422 | .formats = TWL6040_FORMATS, |
| 1423 | }, |
| 1424 | .ops = &twl6040_dai_ops, |
Peter Ujfalusi | 21385ee | 2011-07-05 22:35:53 +0300 | [diff] [blame] | 1425 | }, |
| 1426 | { |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1427 | .name = "twl6040-ul", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1428 | .capture = { |
| 1429 | .stream_name = "Capture", |
| 1430 | .channels_min = 1, |
| 1431 | .channels_max = 2, |
| 1432 | .rates = TWL6040_RATES, |
| 1433 | .formats = TWL6040_FORMATS, |
| 1434 | }, |
| 1435 | .ops = &twl6040_dai_ops, |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1436 | }, |
| 1437 | { |
| 1438 | .name = "twl6040-dl1", |
| 1439 | .playback = { |
| 1440 | .stream_name = "Headset Playback", |
| 1441 | .channels_min = 1, |
| 1442 | .channels_max = 2, |
| 1443 | .rates = TWL6040_RATES, |
| 1444 | .formats = TWL6040_FORMATS, |
| 1445 | }, |
| 1446 | .ops = &twl6040_dai_ops, |
| 1447 | }, |
| 1448 | { |
| 1449 | .name = "twl6040-dl2", |
| 1450 | .playback = { |
| 1451 | .stream_name = "Handsfree Playback", |
| 1452 | .channels_min = 1, |
| 1453 | .channels_max = 2, |
| 1454 | .rates = TWL6040_RATES, |
| 1455 | .formats = TWL6040_FORMATS, |
| 1456 | }, |
| 1457 | .ops = &twl6040_dai_ops, |
| 1458 | }, |
| 1459 | { |
| 1460 | .name = "twl6040-vib", |
| 1461 | .playback = { |
| 1462 | .stream_name = "Vibra Playback", |
Peter Ujfalusi | d8dd032 | 2011-09-15 15:59:18 +0300 | [diff] [blame] | 1463 | .channels_min = 1, |
| 1464 | .channels_max = 1, |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1465 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| 1466 | .formats = TWL6040_FORMATS, |
| 1467 | }, |
| 1468 | .ops = &twl6040_dai_ops, |
| 1469 | }, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1470 | }; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1471 | |
| 1472 | #ifdef CONFIG_PM |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1473 | 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] | 1474 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1475 | twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 1476 | |
| 1477 | return 0; |
| 1478 | } |
| 1479 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1480 | static int twl6040_resume(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1481 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1482 | twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Olaya, Margarita | 6c31104 | 2010-12-10 21:05:46 -0600 | [diff] [blame] | 1483 | twl6040_set_bias_level(codec, codec->dapm.suspend_bias_level); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1484 | |
| 1485 | return 0; |
| 1486 | } |
| 1487 | #else |
| 1488 | #define twl6040_suspend NULL |
| 1489 | #define twl6040_resume NULL |
| 1490 | #endif |
| 1491 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1492 | static int twl6040_probe(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1493 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1494 | struct twl6040_data *priv; |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 1495 | struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev); |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1496 | struct platform_device *pdev = container_of(codec->dev, |
| 1497 | struct platform_device, dev); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1498 | int ret = 0; |
| 1499 | |
| 1500 | priv = kzalloc(sizeof(struct twl6040_data), GFP_KERNEL); |
| 1501 | if (priv == NULL) |
| 1502 | return -ENOMEM; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1503 | snd_soc_codec_set_drvdata(codec, priv); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1504 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1505 | priv->codec = codec; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1506 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
Peter Ujfalusi | 35dec69 | 2011-10-14 14:43:34 +0300 | [diff] [blame] | 1507 | codec->ignore_pmdown_time = 1; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1508 | |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 1509 | if (pdata && pdata->hs_left_step && pdata->hs_right_step) { |
| 1510 | priv->hs_left_step = pdata->hs_left_step; |
| 1511 | priv->hs_right_step = pdata->hs_right_step; |
| 1512 | } else { |
| 1513 | priv->hs_left_step = 1; |
| 1514 | priv->hs_right_step = 1; |
| 1515 | } |
Olaya, Margarita | 99903ea | 2010-12-10 21:06:07 -0600 | [diff] [blame] | 1516 | |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 1517 | if (pdata && pdata->hf_left_step && pdata->hf_right_step) { |
| 1518 | priv->hf_left_step = pdata->hf_left_step; |
| 1519 | priv->hf_right_step = pdata->hf_right_step; |
| 1520 | } else { |
| 1521 | priv->hf_left_step = 1; |
| 1522 | priv->hf_right_step = 1; |
| 1523 | } |
Olaya, Margarita | 99903ea | 2010-12-10 21:06:07 -0600 | [diff] [blame] | 1524 | |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1525 | priv->plug_irq = platform_get_irq(pdev, 0); |
| 1526 | if (priv->plug_irq < 0) { |
| 1527 | dev_err(codec->dev, "invalid irq\n"); |
| 1528 | ret = -EINVAL; |
| 1529 | goto work_err; |
| 1530 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1531 | |
Peter Ujfalusi | a46737a | 2011-09-29 15:22:34 +0300 | [diff] [blame] | 1532 | priv->workqueue = alloc_workqueue("twl6040-codec", 0, 0); |
Axel Lin | 19aab08 | 2011-03-26 15:53:58 +0800 | [diff] [blame] | 1533 | if (!priv->workqueue) { |
| 1534 | ret = -ENOMEM; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1535 | goto work_err; |
Axel Lin | 19aab08 | 2011-03-26 15:53:58 +0800 | [diff] [blame] | 1536 | } |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1537 | |
Peter Ujfalusi | 46dd0b9 | 2011-09-26 16:26:27 +0300 | [diff] [blame] | 1538 | INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work); |
Peter Ujfalusi | a46737a | 2011-09-29 15:22:34 +0300 | [diff] [blame] | 1539 | INIT_DELAYED_WORK(&priv->headset.work, twl6040_pga_hs_work); |
| 1540 | INIT_DELAYED_WORK(&priv->handsfree.work, twl6040_pga_hf_work); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1541 | |
| 1542 | mutex_init(&priv->mutex); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1543 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1544 | init_completion(&priv->headset.ramp_done); |
| 1545 | init_completion(&priv->handsfree.ramp_done); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1546 | |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1547 | ret = request_threaded_irq(priv->plug_irq, NULL, twl6040_audio_handler, |
| 1548 | 0, "twl6040_irq_plug", codec); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1549 | if (ret) { |
| 1550 | dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret); |
| 1551 | goto plugirq_err; |
| 1552 | } |
| 1553 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 1554 | twl6040_init_chip(codec); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1555 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1556 | /* power on device */ |
| 1557 | ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Peter Ujfalusi | a175fce | 2011-10-11 13:11:12 +0300 | [diff] [blame] | 1558 | if (!ret) |
| 1559 | return 0; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1560 | |
Peter Ujfalusi | a175fce | 2011-10-11 13:11:12 +0300 | [diff] [blame] | 1561 | /* Error path */ |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1562 | free_irq(priv->plug_irq, codec); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1563 | plugirq_err: |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1564 | destroy_workqueue(priv->workqueue); |
| 1565 | work_err: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1566 | kfree(priv); |
| 1567 | return ret; |
| 1568 | } |
| 1569 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1570 | static int twl6040_remove(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1571 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1572 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1573 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1574 | twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1575 | free_irq(priv->plug_irq, codec); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1576 | destroy_workqueue(priv->workqueue); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1577 | kfree(priv); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1578 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1579 | return 0; |
| 1580 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1581 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1582 | static struct snd_soc_codec_driver soc_codec_dev_twl6040 = { |
| 1583 | .probe = twl6040_probe, |
| 1584 | .remove = twl6040_remove, |
| 1585 | .suspend = twl6040_suspend, |
| 1586 | .resume = twl6040_resume, |
| 1587 | .read = twl6040_read_reg_cache, |
| 1588 | .write = twl6040_write, |
| 1589 | .set_bias_level = twl6040_set_bias_level, |
| 1590 | .reg_cache_size = ARRAY_SIZE(twl6040_reg), |
| 1591 | .reg_word_size = sizeof(u8), |
| 1592 | .reg_cache_default = twl6040_reg, |
Peter Ujfalusi | a175fce | 2011-10-11 13:11:12 +0300 | [diff] [blame] | 1593 | |
| 1594 | .controls = twl6040_snd_controls, |
| 1595 | .num_controls = ARRAY_SIZE(twl6040_snd_controls), |
| 1596 | .dapm_widgets = twl6040_dapm_widgets, |
| 1597 | .num_dapm_widgets = ARRAY_SIZE(twl6040_dapm_widgets), |
| 1598 | .dapm_routes = intercon, |
| 1599 | .num_dapm_routes = ARRAY_SIZE(intercon), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1600 | }; |
| 1601 | |
| 1602 | static int __devinit twl6040_codec_probe(struct platform_device *pdev) |
| 1603 | { |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1604 | return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl6040, |
| 1605 | twl6040_dai, ARRAY_SIZE(twl6040_dai)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | static int __devexit twl6040_codec_remove(struct platform_device *pdev) |
| 1609 | { |
| 1610 | snd_soc_unregister_codec(&pdev->dev); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1611 | return 0; |
| 1612 | } |
| 1613 | |
| 1614 | static struct platform_driver twl6040_codec_driver = { |
| 1615 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1616 | .name = "twl6040-codec", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1617 | .owner = THIS_MODULE, |
| 1618 | }, |
| 1619 | .probe = twl6040_codec_probe, |
| 1620 | .remove = __devexit_p(twl6040_codec_remove), |
| 1621 | }; |
| 1622 | |
| 1623 | static int __init twl6040_codec_init(void) |
| 1624 | { |
| 1625 | return platform_driver_register(&twl6040_codec_driver); |
| 1626 | } |
| 1627 | module_init(twl6040_codec_init); |
| 1628 | |
| 1629 | static void __exit twl6040_codec_exit(void) |
| 1630 | { |
| 1631 | platform_driver_unregister(&twl6040_codec_driver); |
| 1632 | } |
| 1633 | module_exit(twl6040_codec_exit); |
| 1634 | |
| 1635 | MODULE_DESCRIPTION("ASoC TWL6040 codec driver"); |
| 1636 | MODULE_AUTHOR("Misael Lopez Cruz"); |
| 1637 | MODULE_LICENSE("GPL"); |