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