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