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) { |
Peter Ujfalusi | 6fbb32d | 2011-09-29 15:22:36 +0300 | [diff] [blame] | 566 | case 2: /* Headset output driver */ |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 567 | out = &priv->headset; |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 568 | work = &out->work; |
| 569 | /* |
| 570 | * Make sure, that we do not mess up variables for already |
| 571 | * executing work. |
| 572 | */ |
| 573 | cancel_delayed_work_sync(work); |
| 574 | |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 575 | out->left_step = priv->hs_left_step; |
| 576 | out->right_step = priv->hs_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 | break; |
Peter Ujfalusi | 6fbb32d | 2011-09-29 15:22:36 +0300 | [diff] [blame] | 579 | case 4: /* Handsfree output driver */ |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 580 | out = &priv->handsfree; |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 581 | work = &out->work; |
| 582 | /* |
| 583 | * Make sure, that we do not mess up variables for already |
| 584 | * executing work. |
| 585 | */ |
| 586 | cancel_delayed_work_sync(work); |
| 587 | |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 588 | out->left_step = priv->hf_left_step; |
| 589 | out->right_step = priv->hf_right_step; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 590 | out->step_delay = 5; /* 5 ms between volume ramp steps */ |
| 591 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 592 | priv->non_lp++; |
| 593 | else |
| 594 | priv->non_lp--; |
| 595 | break; |
| 596 | default: |
| 597 | return -1; |
| 598 | } |
| 599 | |
| 600 | switch (event) { |
| 601 | case SND_SOC_DAPM_POST_PMU: |
| 602 | if (out->active) |
| 603 | break; |
| 604 | |
| 605 | /* don't use volume ramp for power-up */ |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 606 | out->ramp = TWL6040_RAMP_UP; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 607 | out->left_step = out->left_vol; |
| 608 | out->right_step = out->right_vol; |
| 609 | |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 610 | queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1)); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 611 | break; |
| 612 | |
| 613 | case SND_SOC_DAPM_PRE_PMD: |
| 614 | if (!out->active) |
| 615 | break; |
| 616 | |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 617 | /* use volume ramp for power-down */ |
| 618 | out->ramp = TWL6040_RAMP_DOWN; |
| 619 | INIT_COMPLETION(out->ramp_done); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 620 | |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 621 | queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1)); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 622 | |
Peter Ujfalusi | 009d196 | 2011-09-29 15:22:37 +0300 | [diff] [blame] | 623 | wait_for_completion_timeout(&out->ramp_done, |
| 624 | msecs_to_jiffies(2000)); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 625 | break; |
| 626 | } |
| 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 631 | /* set headset dac and driver power mode */ |
| 632 | static int headset_power_mode(struct snd_soc_codec *codec, int high_perf) |
| 633 | { |
| 634 | int hslctl, hsrctl; |
Peter Ujfalusi | ab6cf13 | 2011-09-22 11:05:54 +0300 | [diff] [blame] | 635 | int mask = TWL6040_HSDRVMODE | TWL6040_HSDACMODE; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 636 | |
| 637 | hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL); |
| 638 | hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL); |
| 639 | |
| 640 | if (high_perf) { |
| 641 | hslctl &= ~mask; |
| 642 | hsrctl &= ~mask; |
| 643 | } else { |
| 644 | hslctl |= mask; |
| 645 | hsrctl |= mask; |
| 646 | } |
| 647 | |
| 648 | twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl); |
| 649 | twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl); |
| 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 654 | static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w, |
| 655 | struct snd_kcontrol *kcontrol, int event) |
| 656 | { |
| 657 | msleep(1); |
| 658 | return 0; |
| 659 | } |
| 660 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 661 | static int twl6040_power_mode_event(struct snd_soc_dapm_widget *w, |
| 662 | struct snd_kcontrol *kcontrol, int event) |
| 663 | { |
| 664 | struct snd_soc_codec *codec = w->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 665 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 666 | int ret = 0; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 667 | |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 668 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 669 | priv->non_lp++; |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 670 | if (!strcmp(w->name, "Earphone Driver")) { |
| 671 | /* Earphone doesn't support low power mode */ |
| 672 | priv->hs_power_mode_locked = 1; |
| 673 | ret = headset_power_mode(codec, 1); |
| 674 | } |
| 675 | } else { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 676 | priv->non_lp--; |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 677 | if (!strcmp(w->name, "Earphone Driver")) { |
| 678 | priv->hs_power_mode_locked = 0; |
| 679 | ret = headset_power_mode(codec, priv->hs_power_mode); |
| 680 | } |
| 681 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 682 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 683 | msleep(1); |
| 684 | |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 685 | return ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 686 | } |
| 687 | |
Mark Brown | 64ed983 | 2011-01-20 21:43:44 +0000 | [diff] [blame] | 688 | static void twl6040_hs_jack_report(struct snd_soc_codec *codec, |
| 689 | struct snd_soc_jack *jack, int report) |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 690 | { |
| 691 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 692 | int status; |
| 693 | |
| 694 | mutex_lock(&priv->mutex); |
| 695 | |
| 696 | /* Sync status */ |
| 697 | status = twl6040_read_reg_volatile(codec, TWL6040_REG_STATUS); |
| 698 | if (status & TWL6040_PLUGCOMP) |
| 699 | snd_soc_jack_report(jack, report, report); |
| 700 | else |
| 701 | snd_soc_jack_report(jack, 0, report); |
| 702 | |
| 703 | mutex_unlock(&priv->mutex); |
| 704 | } |
| 705 | |
| 706 | void twl6040_hs_jack_detect(struct snd_soc_codec *codec, |
| 707 | struct snd_soc_jack *jack, int report) |
| 708 | { |
| 709 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 710 | struct twl6040_jack_data *hs_jack = &priv->hs_jack; |
| 711 | |
| 712 | hs_jack->jack = jack; |
| 713 | hs_jack->report = report; |
| 714 | |
| 715 | twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report); |
| 716 | } |
| 717 | EXPORT_SYMBOL_GPL(twl6040_hs_jack_detect); |
| 718 | |
| 719 | static void twl6040_accessory_work(struct work_struct *work) |
| 720 | { |
| 721 | struct twl6040_data *priv = container_of(work, |
Peter Ujfalusi | 46dd0b9 | 2011-09-26 16:26:27 +0300 | [diff] [blame] | 722 | struct twl6040_data, hs_jack.work.work); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 723 | struct snd_soc_codec *codec = priv->codec; |
| 724 | struct twl6040_jack_data *hs_jack = &priv->hs_jack; |
| 725 | |
| 726 | twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report); |
| 727 | } |
| 728 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 729 | /* audio interrupt handler */ |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 730 | static irqreturn_t twl6040_audio_handler(int irq, void *data) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 731 | { |
| 732 | struct snd_soc_codec *codec = data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 733 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 734 | |
Peter Ujfalusi | 46dd0b9 | 2011-09-26 16:26:27 +0300 | [diff] [blame] | 735 | queue_delayed_work(priv->workqueue, &priv->hs_jack.work, |
Peter Ujfalusi | f34c660 | 2011-09-23 09:52:02 +0300 | [diff] [blame] | 736 | msecs_to_jiffies(200)); |
Olaya, Margarita | cf370a5 | 2010-12-10 21:05:30 -0600 | [diff] [blame] | 737 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 738 | return IRQ_HANDLED; |
| 739 | } |
| 740 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 741 | static int twl6040_put_volsw(struct snd_kcontrol *kcontrol, |
| 742 | struct snd_ctl_elem_value *ucontrol) |
| 743 | { |
| 744 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 745 | struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec); |
| 746 | struct twl6040_output *out = NULL; |
| 747 | struct soc_mixer_control *mc = |
| 748 | (struct soc_mixer_control *)kcontrol->private_value; |
Peter Ujfalusi | db382da | 2011-10-05 10:29:26 +0300 | [diff] [blame^] | 749 | int ret; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 750 | |
| 751 | /* For HS and HF we shadow the values and only actually write |
| 752 | * them out when active in order to ensure the amplifier comes on |
| 753 | * as quietly as possible. */ |
Peter Ujfalusi | a8cc718 | 2011-09-26 16:26:25 +0300 | [diff] [blame] | 754 | switch (mc->reg) { |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 755 | case TWL6040_REG_HSGAIN: |
| 756 | out = &twl6040_priv->headset; |
| 757 | break; |
Peter Ujfalusi | a8cc718 | 2011-09-26 16:26:25 +0300 | [diff] [blame] | 758 | case TWL6040_REG_HFLGAIN: |
| 759 | out = &twl6040_priv->handsfree; |
| 760 | break; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 761 | default: |
Peter Ujfalusi | bfd3d4e | 2011-10-04 14:39:42 +0300 | [diff] [blame] | 762 | return -EINVAL; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 763 | } |
| 764 | |
Peter Ujfalusi | bfd3d4e | 2011-10-04 14:39:42 +0300 | [diff] [blame] | 765 | out->left_vol = ucontrol->value.integer.value[0]; |
| 766 | out->right_vol = ucontrol->value.integer.value[1]; |
| 767 | if (!out->active) |
| 768 | return 1; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 769 | |
Peter Ujfalusi | db382da | 2011-10-05 10:29:26 +0300 | [diff] [blame^] | 770 | ret = snd_soc_put_volsw(kcontrol, ucontrol); |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 771 | if (ret < 0) |
| 772 | return ret; |
| 773 | |
| 774 | return 1; |
| 775 | } |
| 776 | |
| 777 | static int twl6040_get_volsw(struct snd_kcontrol *kcontrol, |
| 778 | struct snd_ctl_elem_value *ucontrol) |
| 779 | { |
| 780 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 781 | struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec); |
| 782 | struct twl6040_output *out = &twl6040_priv->headset; |
| 783 | struct soc_mixer_control *mc = |
| 784 | (struct soc_mixer_control *)kcontrol->private_value; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 785 | |
Peter Ujfalusi | a8cc718 | 2011-09-26 16:26:25 +0300 | [diff] [blame] | 786 | switch (mc->reg) { |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 787 | case TWL6040_REG_HSGAIN: |
| 788 | out = &twl6040_priv->headset; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 789 | break; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 790 | case TWL6040_REG_HFLGAIN: |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 791 | out = &twl6040_priv->handsfree; |
| 792 | break; |
| 793 | default: |
Peter Ujfalusi | e49b683 | 2011-10-05 10:29:20 +0300 | [diff] [blame] | 794 | dev_warn(codec->dev, "%s: Unexpected register: 0x%02x\n", |
| 795 | __func__, mc->reg); |
| 796 | return -EINVAL; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 797 | } |
| 798 | |
Peter Ujfalusi | e49b683 | 2011-10-05 10:29:20 +0300 | [diff] [blame] | 799 | ucontrol->value.integer.value[0] = out->left_vol; |
| 800 | ucontrol->value.integer.value[1] = out->right_vol; |
| 801 | return 0; |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 802 | } |
| 803 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 804 | /* |
| 805 | * MICATT volume control: |
| 806 | * from -6 to 0 dB in 6 dB steps |
| 807 | */ |
| 808 | static DECLARE_TLV_DB_SCALE(mic_preamp_tlv, -600, 600, 0); |
| 809 | |
| 810 | /* |
| 811 | * MICGAIN volume control: |
Ricardo Neri | 2763f45 | 2011-05-01 15:35:55 +0100 | [diff] [blame] | 812 | * from 6 to 30 dB in 6 dB steps |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 813 | */ |
Ricardo Neri | 2763f45 | 2011-05-01 15:35:55 +0100 | [diff] [blame] | 814 | static DECLARE_TLV_DB_SCALE(mic_amp_tlv, 600, 600, 0); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 815 | |
| 816 | /* |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 817 | * AFMGAIN volume control: |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 818 | * from -18 to 24 dB in 6 dB steps |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 819 | */ |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 820 | static DECLARE_TLV_DB_SCALE(afm_amp_tlv, -1800, 600, 0); |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 821 | |
| 822 | /* |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 823 | * HSGAIN volume control: |
| 824 | * from -30 to 0 dB in 2 dB steps |
| 825 | */ |
| 826 | static DECLARE_TLV_DB_SCALE(hs_tlv, -3000, 200, 0); |
| 827 | |
| 828 | /* |
| 829 | * HFGAIN volume control: |
| 830 | * from -52 to 6 dB in 2 dB steps |
| 831 | */ |
| 832 | static DECLARE_TLV_DB_SCALE(hf_tlv, -5200, 200, 0); |
| 833 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 834 | /* |
| 835 | * EPGAIN volume control: |
| 836 | * from -24 to 6 dB in 2 dB steps |
| 837 | */ |
| 838 | static DECLARE_TLV_DB_SCALE(ep_tlv, -2400, 200, 0); |
| 839 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 840 | /* Left analog microphone selection */ |
| 841 | static const char *twl6040_amicl_texts[] = |
| 842 | {"Headset Mic", "Main Mic", "Aux/FM Left", "Off"}; |
| 843 | |
| 844 | /* Right analog microphone selection */ |
| 845 | static const char *twl6040_amicr_texts[] = |
| 846 | {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"}; |
| 847 | |
| 848 | static const struct soc_enum twl6040_enum[] = { |
Francois Mazard | cb973d7 | 2010-12-10 21:06:03 -0600 | [diff] [blame] | 849 | SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3, 4, twl6040_amicl_texts), |
| 850 | SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3, 4, twl6040_amicr_texts), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 851 | }; |
| 852 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 853 | static const char *twl6040_hs_texts[] = { |
| 854 | "Off", "HS DAC", "Line-In amp" |
| 855 | }; |
| 856 | |
| 857 | static const struct soc_enum twl6040_hs_enum[] = { |
| 858 | SOC_ENUM_SINGLE(TWL6040_REG_HSLCTL, 5, ARRAY_SIZE(twl6040_hs_texts), |
| 859 | twl6040_hs_texts), |
| 860 | SOC_ENUM_SINGLE(TWL6040_REG_HSRCTL, 5, ARRAY_SIZE(twl6040_hs_texts), |
| 861 | twl6040_hs_texts), |
| 862 | }; |
| 863 | |
| 864 | static const char *twl6040_hf_texts[] = { |
| 865 | "Off", "HF DAC", "Line-In amp" |
| 866 | }; |
| 867 | |
| 868 | static const struct soc_enum twl6040_hf_enum[] = { |
| 869 | SOC_ENUM_SINGLE(TWL6040_REG_HFLCTL, 2, ARRAY_SIZE(twl6040_hf_texts), |
| 870 | twl6040_hf_texts), |
| 871 | SOC_ENUM_SINGLE(TWL6040_REG_HFRCTL, 2, ARRAY_SIZE(twl6040_hf_texts), |
| 872 | twl6040_hf_texts), |
| 873 | }; |
| 874 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 875 | static const struct snd_kcontrol_new amicl_control = |
| 876 | SOC_DAPM_ENUM("Route", twl6040_enum[0]); |
| 877 | |
| 878 | static const struct snd_kcontrol_new amicr_control = |
| 879 | SOC_DAPM_ENUM("Route", twl6040_enum[1]); |
| 880 | |
| 881 | /* Headset DAC playback switches */ |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 882 | static const struct snd_kcontrol_new hsl_mux_controls = |
| 883 | SOC_DAPM_ENUM("Route", twl6040_hs_enum[0]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 884 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 885 | static const struct snd_kcontrol_new hsr_mux_controls = |
| 886 | SOC_DAPM_ENUM("Route", twl6040_hs_enum[1]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 887 | |
| 888 | /* Handsfree DAC playback switches */ |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 889 | static const struct snd_kcontrol_new hfl_mux_controls = |
| 890 | SOC_DAPM_ENUM("Route", twl6040_hf_enum[0]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 891 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 892 | static const struct snd_kcontrol_new hfr_mux_controls = |
| 893 | SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 894 | |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 895 | static const struct snd_kcontrol_new ep_path_enable_control = |
| 896 | SOC_DAPM_SINGLE("Switch", TWL6040_REG_SW_SHADOW, 0, 1, 0); |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 897 | |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 898 | static const struct snd_kcontrol_new auxl_switch_control = |
| 899 | SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 6, 1, 0); |
| 900 | |
| 901 | static const struct snd_kcontrol_new auxr_switch_control = |
| 902 | SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFRCTL, 6, 1, 0); |
| 903 | |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 904 | /* Headset power mode */ |
Peter Ujfalusi | 7cca606 | 2011-06-27 13:33:14 +0300 | [diff] [blame] | 905 | static const char *twl6040_power_mode_texts[] = { |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 906 | "Low-Power", "High-Perfomance", |
| 907 | }; |
| 908 | |
Peter Ujfalusi | 7cca606 | 2011-06-27 13:33:14 +0300 | [diff] [blame] | 909 | static const struct soc_enum twl6040_power_mode_enum = |
| 910 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(twl6040_power_mode_texts), |
| 911 | twl6040_power_mode_texts); |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 912 | |
| 913 | static int twl6040_headset_power_get_enum(struct snd_kcontrol *kcontrol, |
| 914 | struct snd_ctl_elem_value *ucontrol) |
| 915 | { |
| 916 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 917 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 918 | |
| 919 | ucontrol->value.enumerated.item[0] = priv->hs_power_mode; |
| 920 | |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | static int twl6040_headset_power_put_enum(struct snd_kcontrol *kcontrol, |
| 925 | struct snd_ctl_elem_value *ucontrol) |
| 926 | { |
| 927 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 928 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 929 | int high_perf = ucontrol->value.enumerated.item[0]; |
| 930 | int ret = 0; |
| 931 | |
| 932 | if (!priv->hs_power_mode_locked) |
| 933 | ret = headset_power_mode(codec, high_perf); |
| 934 | |
| 935 | if (!ret) |
| 936 | priv->hs_power_mode = high_perf; |
| 937 | |
| 938 | return ret; |
| 939 | } |
| 940 | |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 941 | static int twl6040_pll_get_enum(struct snd_kcontrol *kcontrol, |
| 942 | struct snd_ctl_elem_value *ucontrol) |
| 943 | { |
| 944 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 945 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 946 | |
| 947 | ucontrol->value.enumerated.item[0] = priv->pll_power_mode; |
| 948 | |
| 949 | return 0; |
| 950 | } |
| 951 | |
| 952 | static int twl6040_pll_put_enum(struct snd_kcontrol *kcontrol, |
| 953 | struct snd_ctl_elem_value *ucontrol) |
| 954 | { |
| 955 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 956 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 957 | |
| 958 | priv->pll_power_mode = ucontrol->value.enumerated.item[0]; |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 959 | |
| 960 | return 0; |
| 961 | } |
| 962 | |
| 963 | int twl6040_get_clk_id(struct snd_soc_codec *codec) |
| 964 | { |
| 965 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 966 | |
Peter Ujfalusi | ff593ca | 2011-07-04 10:35:23 +0300 | [diff] [blame] | 967 | return priv->pll_power_mode; |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 968 | } |
| 969 | EXPORT_SYMBOL_GPL(twl6040_get_clk_id); |
| 970 | |
Peter Ujfalusi | db4aabc | 2011-09-26 16:05:57 +0300 | [diff] [blame] | 971 | int twl6040_get_trim_value(struct snd_soc_codec *codec, enum twl6040_trim trim) |
| 972 | { |
| 973 | if (unlikely(trim >= TWL6040_TRIM_INVAL)) |
| 974 | return -EINVAL; |
| 975 | |
| 976 | return twl6040_read_reg_cache(codec, TWL6040_REG_TRIM1 + trim); |
| 977 | } |
| 978 | EXPORT_SYMBOL_GPL(twl6040_get_trim_value); |
| 979 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 980 | static const struct snd_kcontrol_new twl6040_snd_controls[] = { |
| 981 | /* Capture gains */ |
| 982 | SOC_DOUBLE_TLV("Capture Preamplifier Volume", |
| 983 | TWL6040_REG_MICGAIN, 6, 7, 1, 1, mic_preamp_tlv), |
| 984 | SOC_DOUBLE_TLV("Capture Volume", |
| 985 | TWL6040_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv), |
| 986 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 987 | /* AFM gains */ |
| 988 | SOC_DOUBLE_TLV("Aux FM Volume", |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 989 | TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv), |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 990 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 991 | /* Playback gains */ |
Peter Ujfalusi | 0f9887d | 2011-10-05 10:29:19 +0300 | [diff] [blame] | 992 | SOC_DOUBLE_EXT_TLV("Headset Playback Volume", |
| 993 | TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, twl6040_get_volsw, |
| 994 | twl6040_put_volsw, hs_tlv), |
| 995 | SOC_DOUBLE_R_EXT_TLV("Handsfree Playback Volume", |
| 996 | TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, |
| 997 | twl6040_get_volsw, twl6040_put_volsw, hf_tlv), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 998 | SOC_SINGLE_TLV("Earphone Playback Volume", |
| 999 | TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv), |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 1000 | |
Peter Ujfalusi | 7cca606 | 2011-06-27 13:33:14 +0300 | [diff] [blame] | 1001 | SOC_ENUM_EXT("Headset Power Mode", twl6040_power_mode_enum, |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 1002 | twl6040_headset_power_get_enum, |
| 1003 | twl6040_headset_power_put_enum), |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 1004 | |
| 1005 | SOC_ENUM_EXT("PLL Selection", twl6040_power_mode_enum, |
| 1006 | twl6040_pll_get_enum, twl6040_pll_put_enum), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1007 | }; |
| 1008 | |
| 1009 | static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = { |
| 1010 | /* Inputs */ |
| 1011 | SND_SOC_DAPM_INPUT("MAINMIC"), |
| 1012 | SND_SOC_DAPM_INPUT("HSMIC"), |
| 1013 | SND_SOC_DAPM_INPUT("SUBMIC"), |
| 1014 | SND_SOC_DAPM_INPUT("AFML"), |
| 1015 | SND_SOC_DAPM_INPUT("AFMR"), |
| 1016 | |
| 1017 | /* Outputs */ |
| 1018 | SND_SOC_DAPM_OUTPUT("HSOL"), |
| 1019 | SND_SOC_DAPM_OUTPUT("HSOR"), |
| 1020 | SND_SOC_DAPM_OUTPUT("HFL"), |
| 1021 | SND_SOC_DAPM_OUTPUT("HFR"), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 1022 | SND_SOC_DAPM_OUTPUT("EP"), |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 1023 | SND_SOC_DAPM_OUTPUT("AUXL"), |
| 1024 | SND_SOC_DAPM_OUTPUT("AUXR"), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1025 | |
| 1026 | /* Analog input muxes for the capture amplifiers */ |
| 1027 | SND_SOC_DAPM_MUX("Analog Left Capture Route", |
| 1028 | SND_SOC_NOPM, 0, 0, &amicl_control), |
| 1029 | SND_SOC_DAPM_MUX("Analog Right Capture Route", |
| 1030 | SND_SOC_NOPM, 0, 0, &amicr_control), |
| 1031 | |
| 1032 | /* Analog capture PGAs */ |
| 1033 | SND_SOC_DAPM_PGA("MicAmpL", |
| 1034 | TWL6040_REG_MICLCTL, 0, 0, NULL, 0), |
| 1035 | SND_SOC_DAPM_PGA("MicAmpR", |
| 1036 | TWL6040_REG_MICRCTL, 0, 0, NULL, 0), |
| 1037 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1038 | /* Auxiliary FM PGAs */ |
| 1039 | SND_SOC_DAPM_PGA("AFMAmpL", |
| 1040 | TWL6040_REG_MICLCTL, 1, 0, NULL, 0), |
| 1041 | SND_SOC_DAPM_PGA("AFMAmpR", |
| 1042 | TWL6040_REG_MICRCTL, 1, 0, NULL, 0), |
| 1043 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1044 | /* ADCs */ |
| 1045 | SND_SOC_DAPM_ADC("ADC Left", "Left Front Capture", |
| 1046 | TWL6040_REG_MICLCTL, 2, 0), |
| 1047 | SND_SOC_DAPM_ADC("ADC Right", "Right Front Capture", |
| 1048 | TWL6040_REG_MICRCTL, 2, 0), |
| 1049 | |
| 1050 | /* Microphone bias */ |
| 1051 | SND_SOC_DAPM_MICBIAS("Headset Mic Bias", |
| 1052 | TWL6040_REG_AMICBCTL, 0, 0), |
| 1053 | SND_SOC_DAPM_MICBIAS("Main Mic Bias", |
| 1054 | TWL6040_REG_AMICBCTL, 4, 0), |
| 1055 | SND_SOC_DAPM_MICBIAS("Digital Mic1 Bias", |
| 1056 | TWL6040_REG_DMICBCTL, 0, 0), |
| 1057 | SND_SOC_DAPM_MICBIAS("Digital Mic2 Bias", |
| 1058 | TWL6040_REG_DMICBCTL, 4, 0), |
| 1059 | |
| 1060 | /* DACs */ |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 1061 | SND_SOC_DAPM_DAC_E("HSDAC Left", "Headset Playback", |
| 1062 | TWL6040_REG_HSLCTL, 0, 0, |
| 1063 | twl6040_hs_dac_event, |
| 1064 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1065 | SND_SOC_DAPM_DAC_E("HSDAC Right", "Headset Playback", |
| 1066 | TWL6040_REG_HSRCTL, 0, 0, |
| 1067 | twl6040_hs_dac_event, |
| 1068 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1069 | SND_SOC_DAPM_DAC_E("HFDAC Left", "Handsfree Playback", |
| 1070 | TWL6040_REG_HFLCTL, 0, 0, |
| 1071 | twl6040_power_mode_event, |
| 1072 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1073 | SND_SOC_DAPM_DAC_E("HFDAC Right", "Handsfree Playback", |
| 1074 | TWL6040_REG_HFRCTL, 0, 0, |
| 1075 | twl6040_power_mode_event, |
| 1076 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
| 1077 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1078 | SND_SOC_DAPM_MUX("Handsfree Left Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1079 | SND_SOC_NOPM, 0, 0, &hfl_mux_controls), |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1080 | SND_SOC_DAPM_MUX("Handsfree Right Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1081 | SND_SOC_NOPM, 0, 0, &hfr_mux_controls), |
| 1082 | /* Analog playback Muxes */ |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1083 | SND_SOC_DAPM_MUX("Headset Left Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1084 | SND_SOC_NOPM, 0, 0, &hsl_mux_controls), |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1085 | SND_SOC_DAPM_MUX("Headset Right Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1086 | SND_SOC_NOPM, 0, 0, &hsr_mux_controls), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1087 | |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 1088 | SND_SOC_DAPM_SWITCH("Earphone Playback", SND_SOC_NOPM, 0, 0, |
| 1089 | &ep_path_enable_control), |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 1090 | SND_SOC_DAPM_SWITCH("AUXL Playback", SND_SOC_NOPM, 0, 0, |
| 1091 | &auxl_switch_control), |
| 1092 | SND_SOC_DAPM_SWITCH("AUXR Playback", SND_SOC_NOPM, 0, 0, |
| 1093 | &auxr_switch_control), |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 1094 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 1095 | /* Analog playback drivers */ |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1096 | SND_SOC_DAPM_OUT_DRV_E("HF Left Driver", |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 1097 | TWL6040_REG_HFLCTL, 4, 0, NULL, 0, |
Peter Ujfalusi | eb6b71e | 2011-09-26 16:26:24 +0300 | [diff] [blame] | 1098 | out_drv_event, |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1099 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1100 | SND_SOC_DAPM_OUT_DRV_E("HF Right Driver", |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 1101 | TWL6040_REG_HFRCTL, 4, 0, NULL, 0, |
Peter Ujfalusi | eb6b71e | 2011-09-26 16:26:24 +0300 | [diff] [blame] | 1102 | out_drv_event, |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1103 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1104 | SND_SOC_DAPM_OUT_DRV_E("HS Left Driver", |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1105 | TWL6040_REG_HSLCTL, 2, 0, NULL, 0, |
Peter Ujfalusi | eb6b71e | 2011-09-26 16:26:24 +0300 | [diff] [blame] | 1106 | out_drv_event, |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1107 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1108 | SND_SOC_DAPM_OUT_DRV_E("HS Right Driver", |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1109 | TWL6040_REG_HSRCTL, 2, 0, NULL, 0, |
Peter Ujfalusi | eb6b71e | 2011-09-26 16:26:24 +0300 | [diff] [blame] | 1110 | out_drv_event, |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1111 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 1112 | SND_SOC_DAPM_OUT_DRV_E("Earphone Driver", |
| 1113 | TWL6040_REG_EARCTL, 0, 0, NULL, 0, |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 1114 | twl6040_power_mode_event, |
| 1115 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1116 | |
| 1117 | /* Analog playback PGAs */ |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1118 | SND_SOC_DAPM_PGA("HF Left PGA", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1119 | TWL6040_REG_HFLCTL, 1, 0, NULL, 0), |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1120 | SND_SOC_DAPM_PGA("HF Right PGA", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1121 | TWL6040_REG_HFRCTL, 1, 0, NULL, 0), |
| 1122 | |
| 1123 | }; |
| 1124 | |
| 1125 | static const struct snd_soc_dapm_route intercon[] = { |
| 1126 | /* Capture path */ |
| 1127 | {"Analog Left Capture Route", "Headset Mic", "HSMIC"}, |
| 1128 | {"Analog Left Capture Route", "Main Mic", "MAINMIC"}, |
| 1129 | {"Analog Left Capture Route", "Aux/FM Left", "AFML"}, |
| 1130 | |
| 1131 | {"Analog Right Capture Route", "Headset Mic", "HSMIC"}, |
| 1132 | {"Analog Right Capture Route", "Sub Mic", "SUBMIC"}, |
| 1133 | {"Analog Right Capture Route", "Aux/FM Right", "AFMR"}, |
| 1134 | |
| 1135 | {"MicAmpL", NULL, "Analog Left Capture Route"}, |
| 1136 | {"MicAmpR", NULL, "Analog Right Capture Route"}, |
| 1137 | |
| 1138 | {"ADC Left", NULL, "MicAmpL"}, |
| 1139 | {"ADC Right", NULL, "MicAmpR"}, |
| 1140 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1141 | /* AFM path */ |
Peter Ujfalusi | 5bf692d | 2011-09-22 11:05:47 +0300 | [diff] [blame] | 1142 | {"AFMAmpL", NULL, "AFML"}, |
| 1143 | {"AFMAmpR", NULL, "AFMR"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1144 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1145 | {"Headset Left Playback", "HS DAC", "HSDAC Left"}, |
| 1146 | {"Headset Left Playback", "Line-In amp", "AFMAmpL"}, |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1147 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1148 | {"Headset Right Playback", "HS DAC", "HSDAC Right"}, |
| 1149 | {"Headset Right Playback", "Line-In amp", "AFMAmpR"}, |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1150 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1151 | {"HS Left Driver", NULL, "Headset Left Playback"}, |
| 1152 | {"HS Right Driver", NULL, "Headset Right Playback"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1153 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 1154 | {"HSOL", NULL, "HS Left Driver"}, |
| 1155 | {"HSOR", NULL, "HS Right Driver"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1156 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 1157 | /* Earphone playback path */ |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 1158 | {"Earphone Playback", "Switch", "HSDAC Left"}, |
| 1159 | {"Earphone Driver", NULL, "Earphone Playback"}, |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 1160 | {"EP", NULL, "Earphone Driver"}, |
| 1161 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1162 | {"Handsfree Left Playback", "HF DAC", "HFDAC Left"}, |
| 1163 | {"Handsfree Left Playback", "Line-In amp", "AFMAmpL"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1164 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1165 | {"Handsfree Right Playback", "HF DAC", "HFDAC Right"}, |
| 1166 | {"Handsfree Right Playback", "Line-In amp", "AFMAmpR"}, |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 1167 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1168 | {"HF Left PGA", NULL, "Handsfree Left Playback"}, |
| 1169 | {"HF Right PGA", NULL, "Handsfree Right Playback"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1170 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1171 | {"HF Left Driver", NULL, "HF Left PGA"}, |
| 1172 | {"HF Right Driver", NULL, "HF Right PGA"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1173 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 1174 | {"HFL", NULL, "HF Left Driver"}, |
| 1175 | {"HFR", NULL, "HF Right Driver"}, |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 1176 | |
| 1177 | {"AUXL Playback", "Switch", "HF Left PGA"}, |
| 1178 | {"AUXR Playback", "Switch", "HF Right PGA"}, |
| 1179 | |
| 1180 | {"AUXL", NULL, "AUXL Playback"}, |
| 1181 | {"AUXR", NULL, "AUXR Playback"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1182 | }; |
| 1183 | |
| 1184 | static int twl6040_add_widgets(struct snd_soc_codec *codec) |
| 1185 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1186 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 1187 | |
| 1188 | snd_soc_dapm_new_controls(dapm, twl6040_dapm_widgets, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1189 | ARRAY_SIZE(twl6040_dapm_widgets)); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1190 | snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon)); |
| 1191 | snd_soc_dapm_new_widgets(dapm); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1192 | |
| 1193 | return 0; |
| 1194 | } |
| 1195 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1196 | static int twl6040_set_bias_level(struct snd_soc_codec *codec, |
| 1197 | enum snd_soc_bias_level level) |
| 1198 | { |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1199 | struct twl6040 *twl6040 = codec->control_data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1200 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1201 | int ret; |
| 1202 | |
| 1203 | switch (level) { |
| 1204 | case SND_SOC_BIAS_ON: |
| 1205 | break; |
| 1206 | case SND_SOC_BIAS_PREPARE: |
| 1207 | break; |
| 1208 | case SND_SOC_BIAS_STANDBY: |
| 1209 | if (priv->codec_powered) |
| 1210 | break; |
| 1211 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1212 | ret = twl6040_power(twl6040, 1); |
| 1213 | if (ret) |
| 1214 | return ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1215 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1216 | priv->codec_powered = 1; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1217 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 1218 | twl6040_restore_regs(codec); |
Olaya, Margarita | 65b7cec | 2010-12-14 19:18:36 -0600 | [diff] [blame] | 1219 | |
| 1220 | /* Set external boost GPO */ |
| 1221 | twl6040_write(codec, TWL6040_REG_GPOCTL, 0x02); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1222 | break; |
| 1223 | case SND_SOC_BIAS_OFF: |
| 1224 | if (!priv->codec_powered) |
| 1225 | break; |
| 1226 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1227 | twl6040_power(twl6040, 0); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1228 | priv->codec_powered = 0; |
| 1229 | break; |
| 1230 | } |
| 1231 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1232 | codec->dapm.bias_level = level; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1237 | static int twl6040_startup(struct snd_pcm_substream *substream, |
| 1238 | struct snd_soc_dai *dai) |
| 1239 | { |
| 1240 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1241 | struct snd_soc_codec *codec = rtd->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1242 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1243 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1244 | snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 1245 | SNDRV_PCM_HW_PARAM_RATE, |
Peter Ujfalusi | f53c346 | 2011-06-29 13:28:18 +0300 | [diff] [blame] | 1246 | &sysclk_constraints[priv->pll_power_mode]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1247 | |
| 1248 | return 0; |
| 1249 | } |
| 1250 | |
| 1251 | static int twl6040_hw_params(struct snd_pcm_substream *substream, |
| 1252 | struct snd_pcm_hw_params *params, |
| 1253 | struct snd_soc_dai *dai) |
| 1254 | { |
| 1255 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1256 | struct snd_soc_codec *codec = rtd->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1257 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1258 | int rate; |
| 1259 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1260 | rate = params_rate(params); |
| 1261 | switch (rate) { |
Olaya, Margarita | 60ea4ce | 2010-12-10 21:05:58 -0600 | [diff] [blame] | 1262 | case 11250: |
| 1263 | case 22500: |
| 1264 | case 44100: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1265 | case 88200: |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1266 | /* These rates are not supported when HPPLL is in use */ |
| 1267 | if (unlikely(priv->pll == TWL6040_SYSCLK_SEL_HPPLL)) { |
| 1268 | dev_err(codec->dev, "HPPLL does not support rate %d\n", |
| 1269 | rate); |
| 1270 | return -EINVAL; |
| 1271 | } |
| 1272 | /* Capture is not supported with 17.64MHz sysclk */ |
| 1273 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { |
| 1274 | dev_err(codec->dev, |
| 1275 | "capture mode is not supported at %dHz\n", |
| 1276 | rate); |
| 1277 | return -EINVAL; |
| 1278 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1279 | priv->sysclk = 17640000; |
| 1280 | break; |
Olaya, Margarita | 60ea4ce | 2010-12-10 21:05:58 -0600 | [diff] [blame] | 1281 | case 8000: |
| 1282 | case 16000: |
| 1283 | case 32000: |
| 1284 | case 48000: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1285 | case 96000: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1286 | priv->sysclk = 19200000; |
| 1287 | break; |
| 1288 | default: |
| 1289 | dev_err(codec->dev, "unsupported rate %d\n", rate); |
| 1290 | return -EINVAL; |
| 1291 | } |
| 1292 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1293 | return 0; |
| 1294 | } |
| 1295 | |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1296 | static int twl6040_prepare(struct snd_pcm_substream *substream, |
| 1297 | struct snd_soc_dai *dai) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1298 | { |
| 1299 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1300 | struct snd_soc_codec *codec = rtd->codec; |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1301 | struct twl6040 *twl6040 = codec->control_data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1302 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1303 | int ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1304 | |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1305 | if (!priv->sysclk) { |
| 1306 | dev_err(codec->dev, |
| 1307 | "no mclk configured, call set_sysclk() on init\n"); |
| 1308 | return -EINVAL; |
| 1309 | } |
| 1310 | |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1311 | if ((priv->sysclk == 17640000) && priv->non_lp) { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1312 | dev_err(codec->dev, |
| 1313 | "some enabled paths aren't supported at %dHz\n", |
| 1314 | priv->sysclk); |
| 1315 | return -EPERM; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1316 | } |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1317 | |
| 1318 | ret = twl6040_set_pll(twl6040, priv->pll, priv->clk_in, priv->sysclk); |
| 1319 | if (ret) { |
| 1320 | dev_err(codec->dev, "Can not set PLL (%d)\n", ret); |
| 1321 | return -EPERM; |
| 1322 | } |
| 1323 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 1328 | int clk_id, unsigned int freq, int dir) |
| 1329 | { |
| 1330 | struct snd_soc_codec *codec = codec_dai->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1331 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1332 | |
| 1333 | switch (clk_id) { |
| 1334 | case TWL6040_SYSCLK_SEL_LPPLL: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1335 | case TWL6040_SYSCLK_SEL_HPPLL: |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1336 | priv->pll = clk_id; |
| 1337 | priv->clk_in = freq; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1338 | break; |
| 1339 | default: |
| 1340 | dev_err(codec->dev, "unknown clk_id %d\n", clk_id); |
| 1341 | return -EINVAL; |
| 1342 | } |
| 1343 | |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
| 1347 | static struct snd_soc_dai_ops twl6040_dai_ops = { |
| 1348 | .startup = twl6040_startup, |
| 1349 | .hw_params = twl6040_hw_params, |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1350 | .prepare = twl6040_prepare, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1351 | .set_sysclk = twl6040_set_dai_sysclk, |
| 1352 | }; |
| 1353 | |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1354 | static struct snd_soc_dai_driver twl6040_dai[] = { |
| 1355 | { |
Peter Ujfalusi | d13f1fe | 2011-09-22 11:05:53 +0300 | [diff] [blame] | 1356 | .name = "twl6040-legacy", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1357 | .playback = { |
| 1358 | .stream_name = "Playback", |
| 1359 | .channels_min = 1, |
Peter Ujfalusi | cdd5054 | 2011-09-15 15:59:19 +0300 | [diff] [blame] | 1360 | .channels_max = 5, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1361 | .rates = TWL6040_RATES, |
| 1362 | .formats = TWL6040_FORMATS, |
| 1363 | }, |
| 1364 | .capture = { |
| 1365 | .stream_name = "Capture", |
| 1366 | .channels_min = 1, |
| 1367 | .channels_max = 2, |
| 1368 | .rates = TWL6040_RATES, |
| 1369 | .formats = TWL6040_FORMATS, |
| 1370 | }, |
| 1371 | .ops = &twl6040_dai_ops, |
Peter Ujfalusi | 21385ee | 2011-07-05 22:35:53 +0300 | [diff] [blame] | 1372 | }, |
| 1373 | { |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1374 | .name = "twl6040-ul", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1375 | .capture = { |
| 1376 | .stream_name = "Capture", |
| 1377 | .channels_min = 1, |
| 1378 | .channels_max = 2, |
| 1379 | .rates = TWL6040_RATES, |
| 1380 | .formats = TWL6040_FORMATS, |
| 1381 | }, |
| 1382 | .ops = &twl6040_dai_ops, |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1383 | }, |
| 1384 | { |
| 1385 | .name = "twl6040-dl1", |
| 1386 | .playback = { |
| 1387 | .stream_name = "Headset Playback", |
| 1388 | .channels_min = 1, |
| 1389 | .channels_max = 2, |
| 1390 | .rates = TWL6040_RATES, |
| 1391 | .formats = TWL6040_FORMATS, |
| 1392 | }, |
| 1393 | .ops = &twl6040_dai_ops, |
| 1394 | }, |
| 1395 | { |
| 1396 | .name = "twl6040-dl2", |
| 1397 | .playback = { |
| 1398 | .stream_name = "Handsfree Playback", |
| 1399 | .channels_min = 1, |
| 1400 | .channels_max = 2, |
| 1401 | .rates = TWL6040_RATES, |
| 1402 | .formats = TWL6040_FORMATS, |
| 1403 | }, |
| 1404 | .ops = &twl6040_dai_ops, |
| 1405 | }, |
| 1406 | { |
| 1407 | .name = "twl6040-vib", |
| 1408 | .playback = { |
| 1409 | .stream_name = "Vibra Playback", |
Peter Ujfalusi | d8dd032 | 2011-09-15 15:59:18 +0300 | [diff] [blame] | 1410 | .channels_min = 1, |
| 1411 | .channels_max = 1, |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1412 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| 1413 | .formats = TWL6040_FORMATS, |
| 1414 | }, |
| 1415 | .ops = &twl6040_dai_ops, |
| 1416 | }, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1417 | }; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1418 | |
| 1419 | #ifdef CONFIG_PM |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1420 | 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] | 1421 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1422 | twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 1423 | |
| 1424 | return 0; |
| 1425 | } |
| 1426 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1427 | static int twl6040_resume(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1428 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1429 | twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Olaya, Margarita | 6c31104 | 2010-12-10 21:05:46 -0600 | [diff] [blame] | 1430 | twl6040_set_bias_level(codec, codec->dapm.suspend_bias_level); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1431 | |
| 1432 | return 0; |
| 1433 | } |
| 1434 | #else |
| 1435 | #define twl6040_suspend NULL |
| 1436 | #define twl6040_resume NULL |
| 1437 | #endif |
| 1438 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1439 | static int twl6040_probe(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1440 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1441 | struct twl6040_data *priv; |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 1442 | struct twl4030_codec_data *pdata = dev_get_platdata(codec->dev); |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1443 | struct platform_device *pdev = container_of(codec->dev, |
| 1444 | struct platform_device, dev); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1445 | int ret = 0; |
| 1446 | |
| 1447 | priv = kzalloc(sizeof(struct twl6040_data), GFP_KERNEL); |
| 1448 | if (priv == NULL) |
| 1449 | return -ENOMEM; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1450 | snd_soc_codec_set_drvdata(codec, priv); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1451 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1452 | priv->codec = codec; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1453 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1454 | |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 1455 | if (pdata && pdata->hs_left_step && pdata->hs_right_step) { |
| 1456 | priv->hs_left_step = pdata->hs_left_step; |
| 1457 | priv->hs_right_step = pdata->hs_right_step; |
| 1458 | } else { |
| 1459 | priv->hs_left_step = 1; |
| 1460 | priv->hs_right_step = 1; |
| 1461 | } |
Olaya, Margarita | 99903ea | 2010-12-10 21:06:07 -0600 | [diff] [blame] | 1462 | |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 1463 | if (pdata && pdata->hf_left_step && pdata->hf_right_step) { |
| 1464 | priv->hf_left_step = pdata->hf_left_step; |
| 1465 | priv->hf_right_step = pdata->hf_right_step; |
| 1466 | } else { |
| 1467 | priv->hf_left_step = 1; |
| 1468 | priv->hf_right_step = 1; |
| 1469 | } |
Olaya, Margarita | 99903ea | 2010-12-10 21:06:07 -0600 | [diff] [blame] | 1470 | |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1471 | priv->plug_irq = platform_get_irq(pdev, 0); |
| 1472 | if (priv->plug_irq < 0) { |
| 1473 | dev_err(codec->dev, "invalid irq\n"); |
| 1474 | ret = -EINVAL; |
| 1475 | goto work_err; |
| 1476 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1477 | |
Peter Ujfalusi | a46737a | 2011-09-29 15:22:34 +0300 | [diff] [blame] | 1478 | priv->workqueue = alloc_workqueue("twl6040-codec", 0, 0); |
Axel Lin | 19aab08 | 2011-03-26 15:53:58 +0800 | [diff] [blame] | 1479 | if (!priv->workqueue) { |
| 1480 | ret = -ENOMEM; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1481 | goto work_err; |
Axel Lin | 19aab08 | 2011-03-26 15:53:58 +0800 | [diff] [blame] | 1482 | } |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1483 | |
Peter Ujfalusi | 46dd0b9 | 2011-09-26 16:26:27 +0300 | [diff] [blame] | 1484 | INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work); |
Peter Ujfalusi | a46737a | 2011-09-29 15:22:34 +0300 | [diff] [blame] | 1485 | INIT_DELAYED_WORK(&priv->headset.work, twl6040_pga_hs_work); |
| 1486 | INIT_DELAYED_WORK(&priv->handsfree.work, twl6040_pga_hf_work); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1487 | |
| 1488 | mutex_init(&priv->mutex); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1489 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1490 | init_completion(&priv->headset.ramp_done); |
| 1491 | init_completion(&priv->handsfree.ramp_done); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1492 | |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1493 | ret = request_threaded_irq(priv->plug_irq, NULL, twl6040_audio_handler, |
| 1494 | 0, "twl6040_irq_plug", codec); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1495 | if (ret) { |
| 1496 | dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret); |
| 1497 | goto plugirq_err; |
| 1498 | } |
| 1499 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 1500 | twl6040_init_chip(codec); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1501 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1502 | /* power on device */ |
| 1503 | ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
| 1504 | if (ret) |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1505 | goto bias_err; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1506 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1507 | snd_soc_add_controls(codec, twl6040_snd_controls, |
| 1508 | ARRAY_SIZE(twl6040_snd_controls)); |
| 1509 | twl6040_add_widgets(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1510 | |
| 1511 | return 0; |
| 1512 | |
Margarita Olaya Cabrera | 1bf8475 | 2010-12-14 19:00:21 -0600 | [diff] [blame] | 1513 | bias_err: |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1514 | free_irq(priv->plug_irq, codec); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1515 | plugirq_err: |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1516 | destroy_workqueue(priv->workqueue); |
| 1517 | work_err: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1518 | kfree(priv); |
| 1519 | return ret; |
| 1520 | } |
| 1521 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1522 | static int twl6040_remove(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1523 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1524 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1525 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1526 | twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1527 | free_irq(priv->plug_irq, codec); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1528 | destroy_workqueue(priv->workqueue); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1529 | kfree(priv); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1530 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1531 | return 0; |
| 1532 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1533 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1534 | static struct snd_soc_codec_driver soc_codec_dev_twl6040 = { |
| 1535 | .probe = twl6040_probe, |
| 1536 | .remove = twl6040_remove, |
| 1537 | .suspend = twl6040_suspend, |
| 1538 | .resume = twl6040_resume, |
| 1539 | .read = twl6040_read_reg_cache, |
| 1540 | .write = twl6040_write, |
| 1541 | .set_bias_level = twl6040_set_bias_level, |
| 1542 | .reg_cache_size = ARRAY_SIZE(twl6040_reg), |
| 1543 | .reg_word_size = sizeof(u8), |
| 1544 | .reg_cache_default = twl6040_reg, |
| 1545 | }; |
| 1546 | |
| 1547 | static int __devinit twl6040_codec_probe(struct platform_device *pdev) |
| 1548 | { |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1549 | return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl6040, |
| 1550 | twl6040_dai, ARRAY_SIZE(twl6040_dai)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | static int __devexit twl6040_codec_remove(struct platform_device *pdev) |
| 1554 | { |
| 1555 | snd_soc_unregister_codec(&pdev->dev); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1556 | return 0; |
| 1557 | } |
| 1558 | |
| 1559 | static struct platform_driver twl6040_codec_driver = { |
| 1560 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1561 | .name = "twl6040-codec", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1562 | .owner = THIS_MODULE, |
| 1563 | }, |
| 1564 | .probe = twl6040_codec_probe, |
| 1565 | .remove = __devexit_p(twl6040_codec_remove), |
| 1566 | }; |
| 1567 | |
| 1568 | static int __init twl6040_codec_init(void) |
| 1569 | { |
| 1570 | return platform_driver_register(&twl6040_codec_driver); |
| 1571 | } |
| 1572 | module_init(twl6040_codec_init); |
| 1573 | |
| 1574 | static void __exit twl6040_codec_exit(void) |
| 1575 | { |
| 1576 | platform_driver_unregister(&twl6040_codec_driver); |
| 1577 | } |
| 1578 | module_exit(twl6040_codec_exit); |
| 1579 | |
| 1580 | MODULE_DESCRIPTION("ASoC TWL6040 codec driver"); |
| 1581 | MODULE_AUTHOR("Misael Lopez Cruz"); |
| 1582 | MODULE_LICENSE("GPL"); |