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 | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 29 | #include <linux/mfd/twl6040.h> |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 30 | |
| 31 | #include <sound/core.h> |
| 32 | #include <sound/pcm.h> |
| 33 | #include <sound/pcm_params.h> |
| 34 | #include <sound/soc.h> |
Liam Girdwood | e48b46b | 2012-01-11 12:43:24 +0000 | [diff] [blame] | 35 | #include <sound/soc-dapm.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 | |
Peter Ujfalusi | d17bf31 | 2011-09-22 11:05:48 +0300 | [diff] [blame] | 49 | /* Shadow register used by the driver */ |
| 50 | #define TWL6040_REG_SW_SHADOW 0x2F |
| 51 | #define TWL6040_CACHEREGNUM (TWL6040_REG_SW_SHADOW + 1) |
| 52 | |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 53 | /* TWL6040_REG_SW_SHADOW (0x2F) fields */ |
| 54 | #define TWL6040_EAR_PATH_ENABLE 0x01 |
| 55 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 56 | struct twl6040_jack_data { |
| 57 | struct snd_soc_jack *jack; |
Peter Ujfalusi | 46dd0b9 | 2011-09-26 16:26:27 +0300 | [diff] [blame] | 58 | struct delayed_work work; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 59 | int report; |
| 60 | }; |
| 61 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 62 | /* codec private data */ |
| 63 | struct twl6040_data { |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 64 | int plug_irq; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 65 | int codec_powered; |
| 66 | int pll; |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 67 | int pll_power_mode; |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 68 | int hs_power_mode; |
| 69 | int hs_power_mode_locked; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 70 | unsigned int clk_in; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 71 | unsigned int sysclk; |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 72 | u16 hs_left_step; |
| 73 | u16 hs_right_step; |
| 74 | u16 hf_left_step; |
| 75 | u16 hf_right_step; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 76 | struct twl6040_jack_data hs_jack; |
| 77 | struct snd_soc_codec *codec; |
| 78 | struct workqueue_struct *workqueue; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 79 | struct mutex mutex; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | /* |
| 83 | * twl6040 register cache & default register settings |
| 84 | */ |
| 85 | static const u8 twl6040_reg[TWL6040_CACHEREGNUM] = { |
Peter Ujfalusi | 4548dc3 | 2011-09-22 11:05:46 +0300 | [diff] [blame] | 86 | 0x00, /* not used 0x00 */ |
| 87 | 0x4B, /* REG_ASICID 0x01 (ro) */ |
| 88 | 0x00, /* REG_ASICREV 0x02 (ro) */ |
| 89 | 0x00, /* REG_INTID 0x03 */ |
| 90 | 0x00, /* REG_INTMR 0x04 */ |
| 91 | 0x00, /* REG_NCPCTRL 0x05 */ |
| 92 | 0x00, /* REG_LDOCTL 0x06 */ |
| 93 | 0x60, /* REG_HPPLLCTL 0x07 */ |
| 94 | 0x00, /* REG_LPPLLCTL 0x08 */ |
| 95 | 0x4A, /* REG_LPPLLDIV 0x09 */ |
| 96 | 0x00, /* REG_AMICBCTL 0x0A */ |
| 97 | 0x00, /* REG_DMICBCTL 0x0B */ |
| 98 | 0x00, /* REG_MICLCTL 0x0C */ |
| 99 | 0x00, /* REG_MICRCTL 0x0D */ |
| 100 | 0x00, /* REG_MICGAIN 0x0E */ |
| 101 | 0x1B, /* REG_LINEGAIN 0x0F */ |
| 102 | 0x00, /* REG_HSLCTL 0x10 */ |
| 103 | 0x00, /* REG_HSRCTL 0x11 */ |
| 104 | 0x00, /* REG_HSGAIN 0x12 */ |
| 105 | 0x00, /* REG_EARCTL 0x13 */ |
| 106 | 0x00, /* REG_HFLCTL 0x14 */ |
| 107 | 0x00, /* REG_HFLGAIN 0x15 */ |
| 108 | 0x00, /* REG_HFRCTL 0x16 */ |
| 109 | 0x00, /* REG_HFRGAIN 0x17 */ |
| 110 | 0x00, /* REG_VIBCTLL 0x18 */ |
| 111 | 0x00, /* REG_VIBDATL 0x19 */ |
| 112 | 0x00, /* REG_VIBCTLR 0x1A */ |
| 113 | 0x00, /* REG_VIBDATR 0x1B */ |
| 114 | 0x00, /* REG_HKCTL1 0x1C */ |
| 115 | 0x00, /* REG_HKCTL2 0x1D */ |
| 116 | 0x00, /* REG_GPOCTL 0x1E */ |
| 117 | 0x00, /* REG_ALB 0x1F */ |
| 118 | 0x00, /* REG_DLB 0x20 */ |
| 119 | 0x00, /* not used 0x21 */ |
| 120 | 0x00, /* not used 0x22 */ |
| 121 | 0x00, /* not used 0x23 */ |
| 122 | 0x00, /* not used 0x24 */ |
| 123 | 0x00, /* not used 0x25 */ |
| 124 | 0x00, /* not used 0x26 */ |
| 125 | 0x00, /* not used 0x27 */ |
| 126 | 0x00, /* REG_TRIM1 0x28 */ |
| 127 | 0x00, /* REG_TRIM2 0x29 */ |
| 128 | 0x00, /* REG_TRIM3 0x2A */ |
| 129 | 0x00, /* REG_HSOTRIM 0x2B */ |
| 130 | 0x00, /* REG_HFOTRIM 0x2C */ |
| 131 | 0x09, /* REG_ACCCTL 0x2D */ |
| 132 | 0x00, /* REG_STATUS 0x2E (ro) */ |
Peter Ujfalusi | d17bf31 | 2011-09-22 11:05:48 +0300 | [diff] [blame] | 133 | |
| 134 | 0x00, /* REG_SW_SHADOW 0x2F - Shadow, non HW register */ |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 137 | /* List of registers to be restored after power up */ |
| 138 | static const int twl6040_restore_list[] = { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 139 | TWL6040_REG_MICLCTL, |
| 140 | TWL6040_REG_MICRCTL, |
| 141 | TWL6040_REG_MICGAIN, |
| 142 | TWL6040_REG_LINEGAIN, |
| 143 | TWL6040_REG_HSLCTL, |
| 144 | TWL6040_REG_HSRCTL, |
| 145 | TWL6040_REG_HSGAIN, |
| 146 | TWL6040_REG_EARCTL, |
| 147 | TWL6040_REG_HFLCTL, |
| 148 | TWL6040_REG_HFLGAIN, |
| 149 | TWL6040_REG_HFRCTL, |
| 150 | TWL6040_REG_HFRGAIN, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 153 | /* set of rates for each pll: low-power and high-performance */ |
| 154 | static unsigned int lp_rates[] = { |
| 155 | 8000, |
| 156 | 11250, |
| 157 | 16000, |
| 158 | 22500, |
| 159 | 32000, |
| 160 | 44100, |
| 161 | 48000, |
| 162 | 88200, |
| 163 | 96000, |
| 164 | }; |
| 165 | |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 166 | static unsigned int hp_rates[] = { |
| 167 | 8000, |
| 168 | 16000, |
| 169 | 32000, |
| 170 | 48000, |
| 171 | 96000, |
| 172 | }; |
| 173 | |
Peter Ujfalusi | f53c346 | 2011-06-29 13:28:18 +0300 | [diff] [blame] | 174 | static struct snd_pcm_hw_constraint_list sysclk_constraints[] = { |
| 175 | { .count = ARRAY_SIZE(lp_rates), .list = lp_rates, }, |
| 176 | { .count = ARRAY_SIZE(hp_rates), .list = hp_rates, }, |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 177 | }; |
| 178 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 179 | /* |
| 180 | * read twl6040 register cache |
| 181 | */ |
| 182 | static inline unsigned int twl6040_read_reg_cache(struct snd_soc_codec *codec, |
| 183 | unsigned int reg) |
| 184 | { |
| 185 | u8 *cache = codec->reg_cache; |
| 186 | |
| 187 | if (reg >= TWL6040_CACHEREGNUM) |
| 188 | return -EIO; |
| 189 | |
| 190 | return cache[reg]; |
| 191 | } |
| 192 | |
| 193 | /* |
| 194 | * write twl6040 register cache |
| 195 | */ |
| 196 | static inline void twl6040_write_reg_cache(struct snd_soc_codec *codec, |
| 197 | u8 reg, u8 value) |
| 198 | { |
| 199 | u8 *cache = codec->reg_cache; |
| 200 | |
| 201 | if (reg >= TWL6040_CACHEREGNUM) |
| 202 | return; |
| 203 | cache[reg] = value; |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * read from twl6040 hardware register |
| 208 | */ |
| 209 | static int twl6040_read_reg_volatile(struct snd_soc_codec *codec, |
| 210 | unsigned int reg) |
| 211 | { |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 212 | struct twl6040 *twl6040 = codec->control_data; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 213 | u8 value; |
| 214 | |
| 215 | if (reg >= TWL6040_CACHEREGNUM) |
| 216 | return -EIO; |
| 217 | |
Peter Ujfalusi | d17bf31 | 2011-09-22 11:05:48 +0300 | [diff] [blame] | 218 | if (likely(reg < TWL6040_REG_SW_SHADOW)) { |
| 219 | value = twl6040_reg_read(twl6040, reg); |
| 220 | twl6040_write_reg_cache(codec, reg, value); |
| 221 | } else { |
| 222 | value = twl6040_read_reg_cache(codec, reg); |
| 223 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 224 | |
| 225 | return value; |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | * write to the twl6040 register space |
| 230 | */ |
| 231 | static int twl6040_write(struct snd_soc_codec *codec, |
| 232 | unsigned int reg, unsigned int value) |
| 233 | { |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 234 | struct twl6040 *twl6040 = codec->control_data; |
| 235 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 236 | if (reg >= TWL6040_CACHEREGNUM) |
| 237 | return -EIO; |
| 238 | |
| 239 | twl6040_write_reg_cache(codec, reg, value); |
Peter Ujfalusi | d17bf31 | 2011-09-22 11:05:48 +0300 | [diff] [blame] | 240 | if (likely(reg < TWL6040_REG_SW_SHADOW)) |
| 241 | return twl6040_reg_write(twl6040, reg, value); |
| 242 | else |
| 243 | return 0; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 246 | static void twl6040_init_chip(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 247 | { |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 248 | struct twl6040 *twl6040 = codec->control_data; |
| 249 | u8 val; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 250 | |
Peter Ujfalusi | f97217f | 2011-09-26 16:05:56 +0300 | [diff] [blame] | 251 | /* Update reg_cache: ASICREV, and TRIM values */ |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 252 | val = twl6040_get_revid(twl6040); |
| 253 | twl6040_write_reg_cache(codec, TWL6040_REG_ASICREV, val); |
| 254 | |
Peter Ujfalusi | f97217f | 2011-09-26 16:05:56 +0300 | [diff] [blame] | 255 | twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM1); |
| 256 | twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM2); |
| 257 | twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM3); |
| 258 | twl6040_read_reg_volatile(codec, TWL6040_REG_HSOTRIM); |
| 259 | twl6040_read_reg_volatile(codec, TWL6040_REG_HFOTRIM); |
| 260 | |
Peter Ujfalusi | 2c27ff4 | 2011-09-15 15:39:28 +0300 | [diff] [blame] | 261 | /* Change chip defaults */ |
| 262 | /* No imput selected for microphone amplifiers */ |
| 263 | twl6040_write_reg_cache(codec, TWL6040_REG_MICLCTL, 0x18); |
| 264 | twl6040_write_reg_cache(codec, TWL6040_REG_MICRCTL, 0x18); |
Peter Ujfalusi | 3acef68 | 2011-09-22 11:05:45 +0300 | [diff] [blame] | 265 | |
| 266 | /* |
| 267 | * We need to lower the default gain values, so the ramp code |
| 268 | * can work correctly for the first playback. |
| 269 | * This reduces the pop noise heard at the first playback. |
| 270 | */ |
| 271 | twl6040_write_reg_cache(codec, TWL6040_REG_HSGAIN, 0xff); |
| 272 | twl6040_write_reg_cache(codec, TWL6040_REG_EARCTL, 0x1e); |
| 273 | twl6040_write_reg_cache(codec, TWL6040_REG_HFLGAIN, 0x1d); |
| 274 | twl6040_write_reg_cache(codec, TWL6040_REG_HFRGAIN, 0x1d); |
| 275 | twl6040_write_reg_cache(codec, TWL6040_REG_LINEGAIN, 0); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 278 | static void twl6040_restore_regs(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 279 | { |
| 280 | u8 *cache = codec->reg_cache; |
| 281 | int reg, i; |
| 282 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 283 | for (i = 0; i < ARRAY_SIZE(twl6040_restore_list); i++) { |
| 284 | reg = twl6040_restore_list[i]; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 285 | twl6040_write(codec, reg, cache[reg]); |
| 286 | } |
| 287 | } |
| 288 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 289 | /* set headset dac and driver power mode */ |
| 290 | static int headset_power_mode(struct snd_soc_codec *codec, int high_perf) |
| 291 | { |
| 292 | int hslctl, hsrctl; |
Peter Ujfalusi | ab6cf13 | 2011-09-22 11:05:54 +0300 | [diff] [blame] | 293 | int mask = TWL6040_HSDRVMODE | TWL6040_HSDACMODE; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 294 | |
| 295 | hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL); |
| 296 | hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL); |
| 297 | |
| 298 | if (high_perf) { |
| 299 | hslctl &= ~mask; |
| 300 | hsrctl &= ~mask; |
| 301 | } else { |
| 302 | hslctl |= mask; |
| 303 | hsrctl |= mask; |
| 304 | } |
| 305 | |
| 306 | twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl); |
| 307 | twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl); |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 312 | static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w, |
| 313 | struct snd_kcontrol *kcontrol, int event) |
| 314 | { |
Peter Ujfalusi | 33b6816 | 2011-10-12 14:46:02 +0300 | [diff] [blame] | 315 | struct snd_soc_codec *codec = w->codec; |
| 316 | u8 hslctl, hsrctl; |
| 317 | |
| 318 | /* |
| 319 | * Workaround for Headset DC offset caused pop noise: |
| 320 | * Both HS DAC need to be turned on (before the HS driver) and off at |
| 321 | * the same time. |
| 322 | */ |
| 323 | hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL); |
| 324 | hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL); |
| 325 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
| 326 | hslctl |= TWL6040_HSDACENA; |
| 327 | hsrctl |= TWL6040_HSDACENA; |
| 328 | } else { |
| 329 | hslctl &= ~TWL6040_HSDACENA; |
| 330 | hsrctl &= ~TWL6040_HSDACENA; |
| 331 | } |
| 332 | twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl); |
| 333 | twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl); |
| 334 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 335 | msleep(1); |
| 336 | return 0; |
| 337 | } |
| 338 | |
Peter Ujfalusi | 694b000 | 2011-10-13 15:05:44 +0300 | [diff] [blame] | 339 | static int twl6040_ep_drv_event(struct snd_soc_dapm_widget *w, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 340 | struct snd_kcontrol *kcontrol, int event) |
| 341 | { |
| 342 | struct snd_soc_codec *codec = w->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 343 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 344 | int ret = 0; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 345 | |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 346 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
Peter Ujfalusi | fac2f3e | 2011-10-13 15:05:42 +0300 | [diff] [blame] | 347 | /* Earphone doesn't support low power mode */ |
| 348 | priv->hs_power_mode_locked = 1; |
| 349 | ret = headset_power_mode(codec, 1); |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 350 | } else { |
Peter Ujfalusi | fac2f3e | 2011-10-13 15:05:42 +0300 | [diff] [blame] | 351 | priv->hs_power_mode_locked = 0; |
| 352 | ret = headset_power_mode(codec, priv->hs_power_mode); |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 353 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 354 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 355 | msleep(1); |
| 356 | |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 357 | return ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Mark Brown | 64ed983 | 2011-01-20 21:43:44 +0000 | [diff] [blame] | 360 | static void twl6040_hs_jack_report(struct snd_soc_codec *codec, |
| 361 | struct snd_soc_jack *jack, int report) |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 362 | { |
| 363 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 364 | int status; |
| 365 | |
| 366 | mutex_lock(&priv->mutex); |
| 367 | |
| 368 | /* Sync status */ |
| 369 | status = twl6040_read_reg_volatile(codec, TWL6040_REG_STATUS); |
| 370 | if (status & TWL6040_PLUGCOMP) |
| 371 | snd_soc_jack_report(jack, report, report); |
| 372 | else |
| 373 | snd_soc_jack_report(jack, 0, report); |
| 374 | |
| 375 | mutex_unlock(&priv->mutex); |
| 376 | } |
| 377 | |
| 378 | void twl6040_hs_jack_detect(struct snd_soc_codec *codec, |
| 379 | struct snd_soc_jack *jack, int report) |
| 380 | { |
| 381 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 382 | struct twl6040_jack_data *hs_jack = &priv->hs_jack; |
| 383 | |
| 384 | hs_jack->jack = jack; |
| 385 | hs_jack->report = report; |
| 386 | |
| 387 | twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report); |
| 388 | } |
| 389 | EXPORT_SYMBOL_GPL(twl6040_hs_jack_detect); |
| 390 | |
| 391 | static void twl6040_accessory_work(struct work_struct *work) |
| 392 | { |
| 393 | struct twl6040_data *priv = container_of(work, |
Peter Ujfalusi | 46dd0b9 | 2011-09-26 16:26:27 +0300 | [diff] [blame] | 394 | struct twl6040_data, hs_jack.work.work); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 395 | struct snd_soc_codec *codec = priv->codec; |
| 396 | struct twl6040_jack_data *hs_jack = &priv->hs_jack; |
| 397 | |
| 398 | twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report); |
| 399 | } |
| 400 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 401 | /* audio interrupt handler */ |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 402 | static irqreturn_t twl6040_audio_handler(int irq, void *data) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 403 | { |
| 404 | struct snd_soc_codec *codec = data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 405 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 406 | |
Peter Ujfalusi | 46dd0b9 | 2011-09-26 16:26:27 +0300 | [diff] [blame] | 407 | queue_delayed_work(priv->workqueue, &priv->hs_jack.work, |
Peter Ujfalusi | f34c660 | 2011-09-23 09:52:02 +0300 | [diff] [blame] | 408 | msecs_to_jiffies(200)); |
Olaya, Margarita | cf370a5 | 2010-12-10 21:05:30 -0600 | [diff] [blame] | 409 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 410 | return IRQ_HANDLED; |
| 411 | } |
| 412 | |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 413 | static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol, |
| 414 | struct snd_ctl_elem_value *ucontrol) |
| 415 | { |
| 416 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 417 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 418 | struct snd_soc_codec *codec = widget->codec; |
| 419 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 420 | unsigned int val; |
| 421 | |
| 422 | /* Do not allow changes while Input/FF efect is running */ |
| 423 | val = twl6040_read_reg_volatile(codec, e->reg); |
| 424 | if (val & TWL6040_VIBENA && !(val & TWL6040_VIBSEL)) |
| 425 | return -EBUSY; |
| 426 | |
| 427 | return snd_soc_dapm_put_enum_double(kcontrol, ucontrol); |
| 428 | } |
| 429 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 430 | /* |
| 431 | * MICATT volume control: |
| 432 | * from -6 to 0 dB in 6 dB steps |
| 433 | */ |
| 434 | static DECLARE_TLV_DB_SCALE(mic_preamp_tlv, -600, 600, 0); |
| 435 | |
| 436 | /* |
| 437 | * MICGAIN volume control: |
Ricardo Neri | 2763f45 | 2011-05-01 15:35:55 +0100 | [diff] [blame] | 438 | * from 6 to 30 dB in 6 dB steps |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 439 | */ |
Ricardo Neri | 2763f45 | 2011-05-01 15:35:55 +0100 | [diff] [blame] | 440 | static DECLARE_TLV_DB_SCALE(mic_amp_tlv, 600, 600, 0); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 441 | |
| 442 | /* |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 443 | * AFMGAIN volume control: |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 444 | * from -18 to 24 dB in 6 dB steps |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 445 | */ |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 446 | static DECLARE_TLV_DB_SCALE(afm_amp_tlv, -1800, 600, 0); |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 447 | |
| 448 | /* |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 449 | * HSGAIN volume control: |
| 450 | * from -30 to 0 dB in 2 dB steps |
| 451 | */ |
| 452 | static DECLARE_TLV_DB_SCALE(hs_tlv, -3000, 200, 0); |
| 453 | |
| 454 | /* |
| 455 | * HFGAIN volume control: |
| 456 | * from -52 to 6 dB in 2 dB steps |
| 457 | */ |
| 458 | static DECLARE_TLV_DB_SCALE(hf_tlv, -5200, 200, 0); |
| 459 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 460 | /* |
| 461 | * EPGAIN volume control: |
| 462 | * from -24 to 6 dB in 2 dB steps |
| 463 | */ |
| 464 | static DECLARE_TLV_DB_SCALE(ep_tlv, -2400, 200, 0); |
| 465 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 466 | /* Left analog microphone selection */ |
| 467 | static const char *twl6040_amicl_texts[] = |
| 468 | {"Headset Mic", "Main Mic", "Aux/FM Left", "Off"}; |
| 469 | |
| 470 | /* Right analog microphone selection */ |
| 471 | static const char *twl6040_amicr_texts[] = |
| 472 | {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"}; |
| 473 | |
| 474 | static const struct soc_enum twl6040_enum[] = { |
Francois Mazard | cb973d7 | 2010-12-10 21:06:03 -0600 | [diff] [blame] | 475 | SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3, 4, twl6040_amicl_texts), |
| 476 | SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3, 4, twl6040_amicr_texts), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 477 | }; |
| 478 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 479 | static const char *twl6040_hs_texts[] = { |
| 480 | "Off", "HS DAC", "Line-In amp" |
| 481 | }; |
| 482 | |
| 483 | static const struct soc_enum twl6040_hs_enum[] = { |
| 484 | SOC_ENUM_SINGLE(TWL6040_REG_HSLCTL, 5, ARRAY_SIZE(twl6040_hs_texts), |
| 485 | twl6040_hs_texts), |
| 486 | SOC_ENUM_SINGLE(TWL6040_REG_HSRCTL, 5, ARRAY_SIZE(twl6040_hs_texts), |
| 487 | twl6040_hs_texts), |
| 488 | }; |
| 489 | |
| 490 | static const char *twl6040_hf_texts[] = { |
| 491 | "Off", "HF DAC", "Line-In amp" |
| 492 | }; |
| 493 | |
| 494 | static const struct soc_enum twl6040_hf_enum[] = { |
| 495 | SOC_ENUM_SINGLE(TWL6040_REG_HFLCTL, 2, ARRAY_SIZE(twl6040_hf_texts), |
| 496 | twl6040_hf_texts), |
| 497 | SOC_ENUM_SINGLE(TWL6040_REG_HFRCTL, 2, ARRAY_SIZE(twl6040_hf_texts), |
| 498 | twl6040_hf_texts), |
| 499 | }; |
| 500 | |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 501 | static const char *twl6040_vibrapath_texts[] = { |
| 502 | "Input FF", "Audio PDM" |
| 503 | }; |
| 504 | |
| 505 | static const struct soc_enum twl6040_vibra_enum[] = { |
| 506 | SOC_ENUM_SINGLE(TWL6040_REG_VIBCTLL, 1, |
| 507 | ARRAY_SIZE(twl6040_vibrapath_texts), |
| 508 | twl6040_vibrapath_texts), |
| 509 | SOC_ENUM_SINGLE(TWL6040_REG_VIBCTLR, 1, |
| 510 | ARRAY_SIZE(twl6040_vibrapath_texts), |
| 511 | twl6040_vibrapath_texts), |
| 512 | }; |
| 513 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 514 | static const struct snd_kcontrol_new amicl_control = |
| 515 | SOC_DAPM_ENUM("Route", twl6040_enum[0]); |
| 516 | |
| 517 | static const struct snd_kcontrol_new amicr_control = |
| 518 | SOC_DAPM_ENUM("Route", twl6040_enum[1]); |
| 519 | |
| 520 | /* Headset DAC playback switches */ |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 521 | static const struct snd_kcontrol_new hsl_mux_controls = |
| 522 | SOC_DAPM_ENUM("Route", twl6040_hs_enum[0]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 523 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 524 | static const struct snd_kcontrol_new hsr_mux_controls = |
| 525 | SOC_DAPM_ENUM("Route", twl6040_hs_enum[1]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 526 | |
| 527 | /* Handsfree DAC playback switches */ |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 528 | static const struct snd_kcontrol_new hfl_mux_controls = |
| 529 | SOC_DAPM_ENUM("Route", twl6040_hf_enum[0]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 530 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 531 | static const struct snd_kcontrol_new hfr_mux_controls = |
| 532 | SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 533 | |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 534 | static const struct snd_kcontrol_new ep_path_enable_control = |
| 535 | SOC_DAPM_SINGLE("Switch", TWL6040_REG_SW_SHADOW, 0, 1, 0); |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 536 | |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 537 | static const struct snd_kcontrol_new auxl_switch_control = |
| 538 | SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 6, 1, 0); |
| 539 | |
| 540 | static const struct snd_kcontrol_new auxr_switch_control = |
| 541 | SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFRCTL, 6, 1, 0); |
| 542 | |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 543 | /* Vibra playback switches */ |
| 544 | static const struct snd_kcontrol_new vibral_mux_controls = |
| 545 | SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[0], |
| 546 | snd_soc_dapm_get_enum_double, |
| 547 | twl6040_soc_dapm_put_vibra_enum); |
| 548 | |
| 549 | static const struct snd_kcontrol_new vibrar_mux_controls = |
| 550 | SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[1], |
| 551 | snd_soc_dapm_get_enum_double, |
| 552 | twl6040_soc_dapm_put_vibra_enum); |
| 553 | |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 554 | /* Headset power mode */ |
Peter Ujfalusi | 7cca606 | 2011-06-27 13:33:14 +0300 | [diff] [blame] | 555 | static const char *twl6040_power_mode_texts[] = { |
Simon Wilson | 3e45365 | 2012-07-06 17:04:17 +0100 | [diff] [blame] | 556 | "Low-Power", "High-Performance", |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 557 | }; |
| 558 | |
Peter Ujfalusi | 7cca606 | 2011-06-27 13:33:14 +0300 | [diff] [blame] | 559 | static const struct soc_enum twl6040_power_mode_enum = |
| 560 | SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(twl6040_power_mode_texts), |
| 561 | twl6040_power_mode_texts); |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 562 | |
| 563 | static int twl6040_headset_power_get_enum(struct snd_kcontrol *kcontrol, |
| 564 | struct snd_ctl_elem_value *ucontrol) |
| 565 | { |
| 566 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 567 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 568 | |
| 569 | ucontrol->value.enumerated.item[0] = priv->hs_power_mode; |
| 570 | |
| 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | static int twl6040_headset_power_put_enum(struct snd_kcontrol *kcontrol, |
| 575 | struct snd_ctl_elem_value *ucontrol) |
| 576 | { |
| 577 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 578 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 579 | int high_perf = ucontrol->value.enumerated.item[0]; |
| 580 | int ret = 0; |
| 581 | |
| 582 | if (!priv->hs_power_mode_locked) |
| 583 | ret = headset_power_mode(codec, high_perf); |
| 584 | |
| 585 | if (!ret) |
| 586 | priv->hs_power_mode = high_perf; |
| 587 | |
| 588 | return ret; |
| 589 | } |
| 590 | |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 591 | static int twl6040_pll_get_enum(struct snd_kcontrol *kcontrol, |
| 592 | struct snd_ctl_elem_value *ucontrol) |
| 593 | { |
| 594 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 595 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 596 | |
| 597 | ucontrol->value.enumerated.item[0] = priv->pll_power_mode; |
| 598 | |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | static int twl6040_pll_put_enum(struct snd_kcontrol *kcontrol, |
| 603 | struct snd_ctl_elem_value *ucontrol) |
| 604 | { |
| 605 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 606 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 607 | |
| 608 | priv->pll_power_mode = ucontrol->value.enumerated.item[0]; |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 609 | |
| 610 | return 0; |
| 611 | } |
| 612 | |
Liam Girdwood | e48b46b | 2012-01-11 12:43:24 +0000 | [diff] [blame] | 613 | int twl6040_get_dl1_gain(struct snd_soc_codec *codec) |
| 614 | { |
| 615 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 616 | |
| 617 | if (snd_soc_dapm_get_pin_status(dapm, "EP")) |
| 618 | return -1; /* -1dB */ |
| 619 | |
| 620 | if (snd_soc_dapm_get_pin_status(dapm, "HSOR") || |
| 621 | snd_soc_dapm_get_pin_status(dapm, "HSOL")) { |
| 622 | |
| 623 | u8 val = snd_soc_read(codec, TWL6040_REG_HSLCTL); |
| 624 | if (val & TWL6040_HSDACMODE) |
| 625 | /* HSDACL in LP mode */ |
| 626 | return -8; /* -8dB */ |
| 627 | else |
| 628 | /* HSDACL in HP mode */ |
| 629 | return -1; /* -1dB */ |
| 630 | } |
| 631 | return 0; /* 0dB */ |
| 632 | } |
| 633 | EXPORT_SYMBOL_GPL(twl6040_get_dl1_gain); |
| 634 | |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 635 | int twl6040_get_clk_id(struct snd_soc_codec *codec) |
| 636 | { |
| 637 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
| 638 | |
Peter Ujfalusi | ff593ca | 2011-07-04 10:35:23 +0300 | [diff] [blame] | 639 | return priv->pll_power_mode; |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 640 | } |
| 641 | EXPORT_SYMBOL_GPL(twl6040_get_clk_id); |
| 642 | |
Peter Ujfalusi | db4aabc | 2011-09-26 16:05:57 +0300 | [diff] [blame] | 643 | int twl6040_get_trim_value(struct snd_soc_codec *codec, enum twl6040_trim trim) |
| 644 | { |
| 645 | if (unlikely(trim >= TWL6040_TRIM_INVAL)) |
| 646 | return -EINVAL; |
| 647 | |
| 648 | return twl6040_read_reg_cache(codec, TWL6040_REG_TRIM1 + trim); |
| 649 | } |
| 650 | EXPORT_SYMBOL_GPL(twl6040_get_trim_value); |
| 651 | |
Liam Girdwood | 0865691 | 2012-01-09 12:10:16 +0000 | [diff] [blame] | 652 | int twl6040_get_hs_step_size(struct snd_soc_codec *codec) |
| 653 | { |
| 654 | struct twl6040 *twl6040 = codec->control_data; |
| 655 | |
Peter Ujfalusi | be4ac00 | 2012-07-16 11:49:43 +0200 | [diff] [blame] | 656 | if (twl6040_get_revid(twl6040) < TWL6040_REV_ES1_3) |
Liam Girdwood | 0865691 | 2012-01-09 12:10:16 +0000 | [diff] [blame] | 657 | /* For ES under ES_1.3 HS step is 2 mV */ |
| 658 | return 2; |
| 659 | else |
| 660 | /* For ES_1.3 HS step is 1 mV */ |
| 661 | return 1; |
| 662 | } |
| 663 | EXPORT_SYMBOL_GPL(twl6040_get_hs_step_size); |
| 664 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 665 | static const struct snd_kcontrol_new twl6040_snd_controls[] = { |
| 666 | /* Capture gains */ |
| 667 | SOC_DOUBLE_TLV("Capture Preamplifier Volume", |
| 668 | TWL6040_REG_MICGAIN, 6, 7, 1, 1, mic_preamp_tlv), |
| 669 | SOC_DOUBLE_TLV("Capture Volume", |
| 670 | TWL6040_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv), |
| 671 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 672 | /* AFM gains */ |
| 673 | SOC_DOUBLE_TLV("Aux FM Volume", |
Liam Girdwood | 1f71a3b | 2011-03-28 19:23:23 +0100 | [diff] [blame] | 674 | TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv), |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 675 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 676 | /* Playback gains */ |
Peter Ujfalusi | 3bb8a81 | 2012-05-04 15:17:20 +0300 | [diff] [blame] | 677 | SOC_DOUBLE_TLV("Headset Playback Volume", |
| 678 | TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv), |
| 679 | SOC_DOUBLE_R_TLV("Handsfree Playback Volume", |
| 680 | TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 681 | SOC_SINGLE_TLV("Earphone Playback Volume", |
| 682 | TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv), |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 683 | |
Peter Ujfalusi | 7cca606 | 2011-06-27 13:33:14 +0300 | [diff] [blame] | 684 | SOC_ENUM_EXT("Headset Power Mode", twl6040_power_mode_enum, |
Misael Lopez Cruz | 6bba63b | 2011-02-11 17:51:05 -0600 | [diff] [blame] | 685 | twl6040_headset_power_get_enum, |
| 686 | twl6040_headset_power_put_enum), |
Peter Ujfalusi | af958c7 | 2011-06-27 17:03:14 +0300 | [diff] [blame] | 687 | |
| 688 | SOC_ENUM_EXT("PLL Selection", twl6040_power_mode_enum, |
| 689 | twl6040_pll_get_enum, twl6040_pll_put_enum), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 690 | }; |
| 691 | |
| 692 | static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = { |
| 693 | /* Inputs */ |
| 694 | SND_SOC_DAPM_INPUT("MAINMIC"), |
| 695 | SND_SOC_DAPM_INPUT("HSMIC"), |
| 696 | SND_SOC_DAPM_INPUT("SUBMIC"), |
| 697 | SND_SOC_DAPM_INPUT("AFML"), |
| 698 | SND_SOC_DAPM_INPUT("AFMR"), |
| 699 | |
| 700 | /* Outputs */ |
| 701 | SND_SOC_DAPM_OUTPUT("HSOL"), |
| 702 | SND_SOC_DAPM_OUTPUT("HSOR"), |
| 703 | SND_SOC_DAPM_OUTPUT("HFL"), |
| 704 | SND_SOC_DAPM_OUTPUT("HFR"), |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 705 | SND_SOC_DAPM_OUTPUT("EP"), |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 706 | SND_SOC_DAPM_OUTPUT("AUXL"), |
| 707 | SND_SOC_DAPM_OUTPUT("AUXR"), |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 708 | SND_SOC_DAPM_OUTPUT("VIBRAL"), |
| 709 | SND_SOC_DAPM_OUTPUT("VIBRAR"), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 710 | |
| 711 | /* Analog input muxes for the capture amplifiers */ |
| 712 | SND_SOC_DAPM_MUX("Analog Left Capture Route", |
| 713 | SND_SOC_NOPM, 0, 0, &amicl_control), |
| 714 | SND_SOC_DAPM_MUX("Analog Right Capture Route", |
| 715 | SND_SOC_NOPM, 0, 0, &amicr_control), |
| 716 | |
| 717 | /* Analog capture PGAs */ |
| 718 | SND_SOC_DAPM_PGA("MicAmpL", |
| 719 | TWL6040_REG_MICLCTL, 0, 0, NULL, 0), |
| 720 | SND_SOC_DAPM_PGA("MicAmpR", |
| 721 | TWL6040_REG_MICRCTL, 0, 0, NULL, 0), |
| 722 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 723 | /* Auxiliary FM PGAs */ |
| 724 | SND_SOC_DAPM_PGA("AFMAmpL", |
| 725 | TWL6040_REG_MICLCTL, 1, 0, NULL, 0), |
| 726 | SND_SOC_DAPM_PGA("AFMAmpR", |
| 727 | TWL6040_REG_MICRCTL, 1, 0, NULL, 0), |
| 728 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 729 | /* ADCs */ |
Peter Ujfalusi | 805238b | 2012-09-20 16:32:15 +0300 | [diff] [blame] | 730 | SND_SOC_DAPM_ADC("ADC Left", NULL, TWL6040_REG_MICLCTL, 2, 0), |
| 731 | SND_SOC_DAPM_ADC("ADC Right", NULL, TWL6040_REG_MICRCTL, 2, 0), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 732 | |
| 733 | /* Microphone bias */ |
Peter Ujfalusi | 778cee7 | 2011-12-22 12:47:21 +0200 | [diff] [blame] | 734 | SND_SOC_DAPM_SUPPLY("Headset Mic Bias", |
| 735 | TWL6040_REG_AMICBCTL, 0, 0, NULL, 0), |
| 736 | SND_SOC_DAPM_SUPPLY("Main Mic Bias", |
| 737 | TWL6040_REG_AMICBCTL, 4, 0, NULL, 0), |
| 738 | SND_SOC_DAPM_SUPPLY("Digital Mic1 Bias", |
| 739 | TWL6040_REG_DMICBCTL, 0, 0, NULL, 0), |
| 740 | SND_SOC_DAPM_SUPPLY("Digital Mic2 Bias", |
| 741 | TWL6040_REG_DMICBCTL, 4, 0, NULL, 0), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 742 | |
| 743 | /* DACs */ |
Peter Ujfalusi | 805238b | 2012-09-20 16:32:15 +0300 | [diff] [blame] | 744 | SND_SOC_DAPM_DAC("HSDAC Left", NULL, SND_SOC_NOPM, 0, 0), |
| 745 | SND_SOC_DAPM_DAC("HSDAC Right", NULL, SND_SOC_NOPM, 0, 0), |
| 746 | SND_SOC_DAPM_DAC("HFDAC Left", NULL, TWL6040_REG_HFLCTL, 0, 0), |
| 747 | SND_SOC_DAPM_DAC("HFDAC Right", NULL, TWL6040_REG_HFRCTL, 0, 0), |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 748 | /* Virtual DAC for vibra path (DL4 channel) */ |
Peter Ujfalusi | 805238b | 2012-09-20 16:32:15 +0300 | [diff] [blame] | 749 | SND_SOC_DAPM_DAC("VIBRA DAC", NULL, SND_SOC_NOPM, 0, 0), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 750 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 751 | SND_SOC_DAPM_MUX("Handsfree Left Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 752 | SND_SOC_NOPM, 0, 0, &hfl_mux_controls), |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 753 | SND_SOC_DAPM_MUX("Handsfree Right Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 754 | SND_SOC_NOPM, 0, 0, &hfr_mux_controls), |
| 755 | /* Analog playback Muxes */ |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 756 | SND_SOC_DAPM_MUX("Headset Left Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 757 | SND_SOC_NOPM, 0, 0, &hsl_mux_controls), |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 758 | SND_SOC_DAPM_MUX("Headset Right Playback", |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 759 | SND_SOC_NOPM, 0, 0, &hsr_mux_controls), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 760 | |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 761 | SND_SOC_DAPM_MUX("Vibra Left Playback", SND_SOC_NOPM, 0, 0, |
| 762 | &vibral_mux_controls), |
| 763 | SND_SOC_DAPM_MUX("Vibra Right Playback", SND_SOC_NOPM, 0, 0, |
| 764 | &vibrar_mux_controls), |
| 765 | |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 766 | SND_SOC_DAPM_SWITCH("Earphone Playback", SND_SOC_NOPM, 0, 0, |
| 767 | &ep_path_enable_control), |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 768 | SND_SOC_DAPM_SWITCH("AUXL Playback", SND_SOC_NOPM, 0, 0, |
| 769 | &auxl_switch_control), |
| 770 | SND_SOC_DAPM_SWITCH("AUXR Playback", SND_SOC_NOPM, 0, 0, |
| 771 | &auxr_switch_control), |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 772 | |
Jorge Eduardo Candelaria | 0fad4ed | 2010-07-15 11:38:01 -0500 | [diff] [blame] | 773 | /* Analog playback drivers */ |
Peter Ujfalusi | 3bb8a81 | 2012-05-04 15:17:20 +0300 | [diff] [blame] | 774 | SND_SOC_DAPM_OUT_DRV("HF Left Driver", |
| 775 | TWL6040_REG_HFLCTL, 4, 0, NULL, 0), |
| 776 | SND_SOC_DAPM_OUT_DRV("HF Right Driver", |
| 777 | TWL6040_REG_HFRCTL, 4, 0, NULL, 0), |
| 778 | SND_SOC_DAPM_OUT_DRV("HS Left Driver", |
| 779 | TWL6040_REG_HSLCTL, 2, 0, NULL, 0), |
| 780 | SND_SOC_DAPM_OUT_DRV("HS Right Driver", |
| 781 | TWL6040_REG_HSRCTL, 2, 0, NULL, 0), |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 782 | SND_SOC_DAPM_OUT_DRV_E("Earphone Driver", |
| 783 | TWL6040_REG_EARCTL, 0, 0, NULL, 0, |
Peter Ujfalusi | 694b000 | 2011-10-13 15:05:44 +0300 | [diff] [blame] | 784 | twl6040_ep_drv_event, |
Peter Ujfalusi | aa1a410 | 2011-10-13 15:05:43 +0300 | [diff] [blame] | 785 | SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 786 | SND_SOC_DAPM_OUT_DRV("Vibra Left Driver", |
| 787 | TWL6040_REG_VIBCTLL, 0, 0, NULL, 0), |
| 788 | SND_SOC_DAPM_OUT_DRV("Vibra Right Driver", |
| 789 | TWL6040_REG_VIBCTLR, 0, 0, NULL, 0), |
| 790 | |
| 791 | SND_SOC_DAPM_SUPPLY("Vibra Left Control", TWL6040_REG_VIBCTLL, 2, 0, |
| 792 | NULL, 0), |
| 793 | SND_SOC_DAPM_SUPPLY("Vibra Right Control", TWL6040_REG_VIBCTLR, 2, 0, |
| 794 | NULL, 0), |
Peter Ujfalusi | 33b6816 | 2011-10-12 14:46:02 +0300 | [diff] [blame] | 795 | SND_SOC_DAPM_SUPPLY_S("HSDAC Power", 1, SND_SOC_NOPM, 0, 0, |
| 796 | twl6040_hs_dac_event, |
| 797 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 798 | |
| 799 | /* Analog playback PGAs */ |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 800 | SND_SOC_DAPM_PGA("HF Left PGA", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 801 | TWL6040_REG_HFLCTL, 1, 0, NULL, 0), |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 802 | SND_SOC_DAPM_PGA("HF Right PGA", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 803 | TWL6040_REG_HFRCTL, 1, 0, NULL, 0), |
| 804 | |
| 805 | }; |
| 806 | |
| 807 | static const struct snd_soc_dapm_route intercon[] = { |
Peter Ujfalusi | 805238b | 2012-09-20 16:32:15 +0300 | [diff] [blame] | 808 | /* Stream -> DAC mapping */ |
| 809 | {"HSDAC Left", NULL, "Legacy Playback"}, |
| 810 | {"HSDAC Left", NULL, "Headset Playback"}, |
| 811 | {"HSDAC Right", NULL, "Legacy Playback"}, |
| 812 | {"HSDAC Right", NULL, "Headset Playback"}, |
| 813 | |
| 814 | {"HFDAC Left", NULL, "Legacy Playback"}, |
| 815 | {"HFDAC Left", NULL, "Handsfree Playback"}, |
| 816 | {"HFDAC Right", NULL, "Legacy Playback"}, |
| 817 | {"HFDAC Right", NULL, "Handsfree Playback"}, |
| 818 | |
| 819 | {"VIBRA DAC", NULL, "Legacy Playback"}, |
| 820 | {"VIBRA DAC", NULL, "Vibra Playback"}, |
| 821 | |
| 822 | /* ADC -> Stream mapping */ |
Peter Ujfalusi | 07ac229 | 2012-10-04 14:15:02 +0300 | [diff] [blame] | 823 | {"Legacy Capture" , NULL, "ADC Left"}, |
| 824 | {"Capture", NULL, "ADC Left"}, |
| 825 | {"Legacy Capture", NULL, "ADC Right"}, |
| 826 | {"Capture" , NULL, "ADC Right"}, |
Peter Ujfalusi | 805238b | 2012-09-20 16:32:15 +0300 | [diff] [blame] | 827 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 828 | /* Capture path */ |
| 829 | {"Analog Left Capture Route", "Headset Mic", "HSMIC"}, |
| 830 | {"Analog Left Capture Route", "Main Mic", "MAINMIC"}, |
| 831 | {"Analog Left Capture Route", "Aux/FM Left", "AFML"}, |
| 832 | |
| 833 | {"Analog Right Capture Route", "Headset Mic", "HSMIC"}, |
| 834 | {"Analog Right Capture Route", "Sub Mic", "SUBMIC"}, |
| 835 | {"Analog Right Capture Route", "Aux/FM Right", "AFMR"}, |
| 836 | |
| 837 | {"MicAmpL", NULL, "Analog Left Capture Route"}, |
| 838 | {"MicAmpR", NULL, "Analog Right Capture Route"}, |
| 839 | |
| 840 | {"ADC Left", NULL, "MicAmpL"}, |
| 841 | {"ADC Right", NULL, "MicAmpR"}, |
| 842 | |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 843 | /* AFM path */ |
Peter Ujfalusi | 5bf692d | 2011-09-22 11:05:47 +0300 | [diff] [blame] | 844 | {"AFMAmpL", NULL, "AFML"}, |
| 845 | {"AFMAmpR", NULL, "AFMR"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 846 | |
Peter Ujfalusi | 33b6816 | 2011-10-12 14:46:02 +0300 | [diff] [blame] | 847 | {"HSDAC Left", NULL, "HSDAC Power"}, |
| 848 | {"HSDAC Right", NULL, "HSDAC Power"}, |
| 849 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 850 | {"Headset Left Playback", "HS DAC", "HSDAC Left"}, |
| 851 | {"Headset Left Playback", "Line-In amp", "AFMAmpL"}, |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 852 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 853 | {"Headset Right Playback", "HS DAC", "HSDAC Right"}, |
| 854 | {"Headset Right Playback", "Line-In amp", "AFMAmpR"}, |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 855 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 856 | {"HS Left Driver", NULL, "Headset Left Playback"}, |
| 857 | {"HS Right Driver", NULL, "Headset Right Playback"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 858 | |
Peter Ujfalusi | 45b0f60 | 2011-09-22 11:05:51 +0300 | [diff] [blame] | 859 | {"HSOL", NULL, "HS Left Driver"}, |
| 860 | {"HSOR", NULL, "HS Right Driver"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 861 | |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 862 | /* Earphone playback path */ |
Peter Ujfalusi | 317596a | 2011-09-22 11:05:49 +0300 | [diff] [blame] | 863 | {"Earphone Playback", "Switch", "HSDAC Left"}, |
| 864 | {"Earphone Driver", NULL, "Earphone Playback"}, |
Jorge Eduardo Candelaria | 871a05a | 2010-05-18 12:44:18 -0500 | [diff] [blame] | 865 | {"EP", NULL, "Earphone Driver"}, |
| 866 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 867 | {"Handsfree Left Playback", "HF DAC", "HFDAC Left"}, |
| 868 | {"Handsfree Left Playback", "Line-In amp", "AFMAmpL"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 869 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 870 | {"Handsfree Right Playback", "HF DAC", "HFDAC Right"}, |
| 871 | {"Handsfree Right Playback", "Line-In amp", "AFMAmpR"}, |
Jorge Eduardo Candelaria | 370a031 | 2010-12-10 21:05:32 -0600 | [diff] [blame] | 872 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 873 | {"HF Left PGA", NULL, "Handsfree Left Playback"}, |
| 874 | {"HF Right PGA", NULL, "Handsfree Right Playback"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 875 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 876 | {"HF Left Driver", NULL, "HF Left PGA"}, |
| 877 | {"HF Right Driver", NULL, "HF Right PGA"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 878 | |
Peter Ujfalusi | df11ce2 | 2011-09-22 11:05:50 +0300 | [diff] [blame] | 879 | {"HFL", NULL, "HF Left Driver"}, |
| 880 | {"HFR", NULL, "HF Right Driver"}, |
Peter Ujfalusi | fdb625f | 2011-09-22 11:05:52 +0300 | [diff] [blame] | 881 | |
| 882 | {"AUXL Playback", "Switch", "HF Left PGA"}, |
| 883 | {"AUXR Playback", "Switch", "HF Right PGA"}, |
| 884 | |
| 885 | {"AUXL", NULL, "AUXL Playback"}, |
| 886 | {"AUXR", NULL, "AUXR Playback"}, |
Peter Ujfalusi | 67c3413 | 2011-10-12 11:57:57 +0300 | [diff] [blame] | 887 | |
| 888 | /* Vibrator paths */ |
| 889 | {"Vibra Left Playback", "Audio PDM", "VIBRA DAC"}, |
| 890 | {"Vibra Right Playback", "Audio PDM", "VIBRA DAC"}, |
| 891 | |
| 892 | {"Vibra Left Driver", NULL, "Vibra Left Playback"}, |
| 893 | {"Vibra Right Driver", NULL, "Vibra Right Playback"}, |
| 894 | {"Vibra Left Driver", NULL, "Vibra Left Control"}, |
| 895 | {"Vibra Right Driver", NULL, "Vibra Right Control"}, |
| 896 | |
| 897 | {"VIBRAL", NULL, "Vibra Left Driver"}, |
| 898 | {"VIBRAR", NULL, "Vibra Right Driver"}, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 899 | }; |
| 900 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 901 | static int twl6040_set_bias_level(struct snd_soc_codec *codec, |
| 902 | enum snd_soc_bias_level level) |
| 903 | { |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 904 | struct twl6040 *twl6040 = codec->control_data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 905 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 906 | int ret; |
| 907 | |
| 908 | switch (level) { |
| 909 | case SND_SOC_BIAS_ON: |
| 910 | break; |
| 911 | case SND_SOC_BIAS_PREPARE: |
| 912 | break; |
| 913 | case SND_SOC_BIAS_STANDBY: |
| 914 | if (priv->codec_powered) |
| 915 | break; |
| 916 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 917 | ret = twl6040_power(twl6040, 1); |
| 918 | if (ret) |
| 919 | return ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 920 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 921 | priv->codec_powered = 1; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 922 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 923 | twl6040_restore_regs(codec); |
Olaya, Margarita | 65b7cec | 2010-12-14 19:18:36 -0600 | [diff] [blame] | 924 | |
| 925 | /* Set external boost GPO */ |
| 926 | twl6040_write(codec, TWL6040_REG_GPOCTL, 0x02); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 927 | break; |
| 928 | case SND_SOC_BIAS_OFF: |
| 929 | if (!priv->codec_powered) |
| 930 | break; |
| 931 | |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 932 | twl6040_power(twl6040, 0); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 933 | priv->codec_powered = 0; |
| 934 | break; |
| 935 | } |
| 936 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 937 | codec->dapm.bias_level = level; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 938 | |
| 939 | return 0; |
| 940 | } |
| 941 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 942 | static int twl6040_startup(struct snd_pcm_substream *substream, |
| 943 | struct snd_soc_dai *dai) |
| 944 | { |
Mark Brown | e6968a1 | 2012-04-04 15:58:16 +0100 | [diff] [blame] | 945 | struct snd_soc_codec *codec = dai->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 946 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 947 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 948 | snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 949 | SNDRV_PCM_HW_PARAM_RATE, |
Peter Ujfalusi | f53c346 | 2011-06-29 13:28:18 +0300 | [diff] [blame] | 950 | &sysclk_constraints[priv->pll_power_mode]); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 951 | |
| 952 | return 0; |
| 953 | } |
| 954 | |
| 955 | static int twl6040_hw_params(struct snd_pcm_substream *substream, |
| 956 | struct snd_pcm_hw_params *params, |
| 957 | struct snd_soc_dai *dai) |
| 958 | { |
Mark Brown | e6968a1 | 2012-04-04 15:58:16 +0100 | [diff] [blame] | 959 | struct snd_soc_codec *codec = dai->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 960 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 961 | int rate; |
| 962 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 963 | rate = params_rate(params); |
| 964 | switch (rate) { |
Olaya, Margarita | 60ea4ce | 2010-12-10 21:05:58 -0600 | [diff] [blame] | 965 | case 11250: |
| 966 | case 22500: |
| 967 | case 44100: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 968 | case 88200: |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 969 | /* These rates are not supported when HPPLL is in use */ |
| 970 | if (unlikely(priv->pll == TWL6040_SYSCLK_SEL_HPPLL)) { |
| 971 | dev_err(codec->dev, "HPPLL does not support rate %d\n", |
| 972 | rate); |
| 973 | return -EINVAL; |
| 974 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 975 | priv->sysclk = 17640000; |
| 976 | break; |
Olaya, Margarita | 60ea4ce | 2010-12-10 21:05:58 -0600 | [diff] [blame] | 977 | case 8000: |
| 978 | case 16000: |
| 979 | case 32000: |
| 980 | case 48000: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 981 | case 96000: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 982 | priv->sysclk = 19200000; |
| 983 | break; |
| 984 | default: |
| 985 | dev_err(codec->dev, "unsupported rate %d\n", rate); |
| 986 | return -EINVAL; |
| 987 | } |
| 988 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 989 | return 0; |
| 990 | } |
| 991 | |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 992 | static int twl6040_prepare(struct snd_pcm_substream *substream, |
| 993 | struct snd_soc_dai *dai) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 994 | { |
Mark Brown | e6968a1 | 2012-04-04 15:58:16 +0100 | [diff] [blame] | 995 | struct snd_soc_codec *codec = dai->codec; |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 996 | struct twl6040 *twl6040 = codec->control_data; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 997 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 998 | int ret; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 999 | |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1000 | if (!priv->sysclk) { |
| 1001 | dev_err(codec->dev, |
| 1002 | "no mclk configured, call set_sysclk() on init\n"); |
| 1003 | return -EINVAL; |
| 1004 | } |
| 1005 | |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1006 | ret = twl6040_set_pll(twl6040, priv->pll, priv->clk_in, priv->sysclk); |
| 1007 | if (ret) { |
| 1008 | dev_err(codec->dev, "Can not set PLL (%d)\n", ret); |
| 1009 | return -EPERM; |
| 1010 | } |
| 1011 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 1016 | int clk_id, unsigned int freq, int dir) |
| 1017 | { |
| 1018 | struct snd_soc_codec *codec = codec_dai->codec; |
Takashi Iwai | d4a8ca2 | 2010-04-20 08:20:31 +0200 | [diff] [blame] | 1019 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1020 | |
| 1021 | switch (clk_id) { |
| 1022 | case TWL6040_SYSCLK_SEL_LPPLL: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1023 | case TWL6040_SYSCLK_SEL_HPPLL: |
Peter Ujfalusi | 753621c | 2011-07-03 02:06:07 +0300 | [diff] [blame] | 1024 | priv->pll = clk_id; |
| 1025 | priv->clk_in = freq; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1026 | break; |
| 1027 | default: |
| 1028 | dev_err(codec->dev, "unknown clk_id %d\n", clk_id); |
| 1029 | return -EINVAL; |
| 1030 | } |
| 1031 | |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1035 | static const struct snd_soc_dai_ops twl6040_dai_ops = { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1036 | .startup = twl6040_startup, |
| 1037 | .hw_params = twl6040_hw_params, |
Olaya, Margarita | 4e624d0 | 2010-12-10 21:05:54 -0600 | [diff] [blame] | 1038 | .prepare = twl6040_prepare, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1039 | .set_sysclk = twl6040_set_dai_sysclk, |
| 1040 | }; |
| 1041 | |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1042 | static struct snd_soc_dai_driver twl6040_dai[] = { |
| 1043 | { |
Peter Ujfalusi | d13f1fe | 2011-09-22 11:05:53 +0300 | [diff] [blame] | 1044 | .name = "twl6040-legacy", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1045 | .playback = { |
Peter Ujfalusi | 805238b | 2012-09-20 16:32:15 +0300 | [diff] [blame] | 1046 | .stream_name = "Legacy Playback", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1047 | .channels_min = 1, |
Peter Ujfalusi | cdd5054 | 2011-09-15 15:59:19 +0300 | [diff] [blame] | 1048 | .channels_max = 5, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1049 | .rates = TWL6040_RATES, |
| 1050 | .formats = TWL6040_FORMATS, |
| 1051 | }, |
| 1052 | .capture = { |
Peter Ujfalusi | 805238b | 2012-09-20 16:32:15 +0300 | [diff] [blame] | 1053 | .stream_name = "Legacy Capture", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1054 | .channels_min = 1, |
| 1055 | .channels_max = 2, |
| 1056 | .rates = TWL6040_RATES, |
| 1057 | .formats = TWL6040_FORMATS, |
| 1058 | }, |
| 1059 | .ops = &twl6040_dai_ops, |
Peter Ujfalusi | 21385ee | 2011-07-05 22:35:53 +0300 | [diff] [blame] | 1060 | }, |
| 1061 | { |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1062 | .name = "twl6040-ul", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1063 | .capture = { |
| 1064 | .stream_name = "Capture", |
| 1065 | .channels_min = 1, |
| 1066 | .channels_max = 2, |
| 1067 | .rates = TWL6040_RATES, |
| 1068 | .formats = TWL6040_FORMATS, |
| 1069 | }, |
| 1070 | .ops = &twl6040_dai_ops, |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1071 | }, |
| 1072 | { |
| 1073 | .name = "twl6040-dl1", |
| 1074 | .playback = { |
| 1075 | .stream_name = "Headset Playback", |
| 1076 | .channels_min = 1, |
| 1077 | .channels_max = 2, |
| 1078 | .rates = TWL6040_RATES, |
| 1079 | .formats = TWL6040_FORMATS, |
| 1080 | }, |
| 1081 | .ops = &twl6040_dai_ops, |
| 1082 | }, |
| 1083 | { |
| 1084 | .name = "twl6040-dl2", |
| 1085 | .playback = { |
| 1086 | .stream_name = "Handsfree Playback", |
| 1087 | .channels_min = 1, |
| 1088 | .channels_max = 2, |
| 1089 | .rates = TWL6040_RATES, |
| 1090 | .formats = TWL6040_FORMATS, |
| 1091 | }, |
| 1092 | .ops = &twl6040_dai_ops, |
| 1093 | }, |
| 1094 | { |
| 1095 | .name = "twl6040-vib", |
| 1096 | .playback = { |
| 1097 | .stream_name = "Vibra Playback", |
Peter Ujfalusi | d8dd032 | 2011-09-15 15:59:18 +0300 | [diff] [blame] | 1098 | .channels_min = 1, |
| 1099 | .channels_max = 1, |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1100 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| 1101 | .formats = TWL6040_FORMATS, |
| 1102 | }, |
| 1103 | .ops = &twl6040_dai_ops, |
| 1104 | }, |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1105 | }; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1106 | |
| 1107 | #ifdef CONFIG_PM |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 1108 | static int twl6040_suspend(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1109 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1110 | twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 1111 | |
| 1112 | return 0; |
| 1113 | } |
| 1114 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1115 | static int twl6040_resume(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1116 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1117 | twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Olaya, Margarita | 6c31104 | 2010-12-10 21:05:46 -0600 | [diff] [blame] | 1118 | twl6040_set_bias_level(codec, codec->dapm.suspend_bias_level); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1119 | |
| 1120 | return 0; |
| 1121 | } |
| 1122 | #else |
| 1123 | #define twl6040_suspend NULL |
| 1124 | #define twl6040_resume NULL |
| 1125 | #endif |
| 1126 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1127 | static int twl6040_probe(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1128 | { |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1129 | struct twl6040_data *priv; |
Peter Ujfalusi | 8eaeb93 | 2012-04-03 11:56:51 +0300 | [diff] [blame] | 1130 | struct twl6040_codec_data *pdata = dev_get_platdata(codec->dev); |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1131 | struct platform_device *pdev = container_of(codec->dev, |
| 1132 | struct platform_device, dev); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1133 | int ret = 0; |
| 1134 | |
| 1135 | priv = kzalloc(sizeof(struct twl6040_data), GFP_KERNEL); |
| 1136 | if (priv == NULL) |
| 1137 | return -ENOMEM; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1138 | snd_soc_codec_set_drvdata(codec, priv); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1139 | |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1140 | priv->codec = codec; |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1141 | codec->control_data = dev_get_drvdata(codec->dev->parent); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1142 | |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 1143 | if (pdata && pdata->hs_left_step && pdata->hs_right_step) { |
| 1144 | priv->hs_left_step = pdata->hs_left_step; |
| 1145 | priv->hs_right_step = pdata->hs_right_step; |
| 1146 | } else { |
| 1147 | priv->hs_left_step = 1; |
| 1148 | priv->hs_right_step = 1; |
| 1149 | } |
Olaya, Margarita | 99903ea | 2010-12-10 21:06:07 -0600 | [diff] [blame] | 1150 | |
Axel Castaneda Gonzalez | 1fbe995 | 2011-02-23 20:08:28 -0600 | [diff] [blame] | 1151 | if (pdata && pdata->hf_left_step && pdata->hf_right_step) { |
| 1152 | priv->hf_left_step = pdata->hf_left_step; |
| 1153 | priv->hf_right_step = pdata->hf_right_step; |
| 1154 | } else { |
| 1155 | priv->hf_left_step = 1; |
| 1156 | priv->hf_right_step = 1; |
| 1157 | } |
Olaya, Margarita | 99903ea | 2010-12-10 21:06:07 -0600 | [diff] [blame] | 1158 | |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1159 | priv->plug_irq = platform_get_irq(pdev, 0); |
| 1160 | if (priv->plug_irq < 0) { |
| 1161 | dev_err(codec->dev, "invalid irq\n"); |
| 1162 | ret = -EINVAL; |
| 1163 | goto work_err; |
| 1164 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1165 | |
Peter Ujfalusi | a46737a | 2011-09-29 15:22:34 +0300 | [diff] [blame] | 1166 | priv->workqueue = alloc_workqueue("twl6040-codec", 0, 0); |
Axel Lin | 19aab08 | 2011-03-26 15:53:58 +0800 | [diff] [blame] | 1167 | if (!priv->workqueue) { |
| 1168 | ret = -ENOMEM; |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1169 | goto work_err; |
Axel Lin | 19aab08 | 2011-03-26 15:53:58 +0800 | [diff] [blame] | 1170 | } |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1171 | |
Peter Ujfalusi | 46dd0b9 | 2011-09-26 16:26:27 +0300 | [diff] [blame] | 1172 | INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1173 | |
| 1174 | mutex_init(&priv->mutex); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1175 | |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1176 | ret = request_threaded_irq(priv->plug_irq, NULL, twl6040_audio_handler, |
| 1177 | 0, "twl6040_irq_plug", codec); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1178 | if (ret) { |
| 1179 | dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret); |
| 1180 | goto plugirq_err; |
| 1181 | } |
| 1182 | |
Peter Ujfalusi | a52762e | 2011-09-15 15:39:27 +0300 | [diff] [blame] | 1183 | twl6040_init_chip(codec); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1184 | |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1185 | /* power on device */ |
| 1186 | ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Peter Ujfalusi | a175fce | 2011-10-11 13:11:12 +0300 | [diff] [blame] | 1187 | if (!ret) |
| 1188 | return 0; |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1189 | |
Peter Ujfalusi | a175fce | 2011-10-11 13:11:12 +0300 | [diff] [blame] | 1190 | /* Error path */ |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1191 | free_irq(priv->plug_irq, codec); |
Misael Lopez Cruz | fb34d3d | 2011-05-01 21:27:00 -0500 | [diff] [blame] | 1192 | plugirq_err: |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1193 | destroy_workqueue(priv->workqueue); |
| 1194 | work_err: |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1195 | kfree(priv); |
| 1196 | return ret; |
| 1197 | } |
| 1198 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1199 | static int twl6040_remove(struct snd_soc_codec *codec) |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1200 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1201 | struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1202 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1203 | twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF); |
Peter Ujfalusi | 2a433b9 | 2011-07-04 19:52:26 +0300 | [diff] [blame] | 1204 | free_irq(priv->plug_irq, codec); |
Jorge Eduardo Candelaria | a2d2362 | 2010-12-10 20:45:17 -0600 | [diff] [blame] | 1205 | destroy_workqueue(priv->workqueue); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1206 | kfree(priv); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1207 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1208 | return 0; |
| 1209 | } |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1210 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1211 | static struct snd_soc_codec_driver soc_codec_dev_twl6040 = { |
| 1212 | .probe = twl6040_probe, |
| 1213 | .remove = twl6040_remove, |
| 1214 | .suspend = twl6040_suspend, |
| 1215 | .resume = twl6040_resume, |
| 1216 | .read = twl6040_read_reg_cache, |
| 1217 | .write = twl6040_write, |
| 1218 | .set_bias_level = twl6040_set_bias_level, |
| 1219 | .reg_cache_size = ARRAY_SIZE(twl6040_reg), |
| 1220 | .reg_word_size = sizeof(u8), |
| 1221 | .reg_cache_default = twl6040_reg, |
Mark Brown | a5d3a21 | 2012-02-08 18:34:19 +0000 | [diff] [blame] | 1222 | .ignore_pmdown_time = true, |
Peter Ujfalusi | a175fce | 2011-10-11 13:11:12 +0300 | [diff] [blame] | 1223 | |
| 1224 | .controls = twl6040_snd_controls, |
| 1225 | .num_controls = ARRAY_SIZE(twl6040_snd_controls), |
| 1226 | .dapm_widgets = twl6040_dapm_widgets, |
| 1227 | .num_dapm_widgets = ARRAY_SIZE(twl6040_dapm_widgets), |
| 1228 | .dapm_routes = intercon, |
| 1229 | .num_dapm_routes = ARRAY_SIZE(intercon), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1230 | }; |
| 1231 | |
| 1232 | static int __devinit twl6040_codec_probe(struct platform_device *pdev) |
| 1233 | { |
Liam Girdwood | 6510bdc | 2011-02-11 17:37:51 +0000 | [diff] [blame] | 1234 | return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl6040, |
| 1235 | twl6040_dai, ARRAY_SIZE(twl6040_dai)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | static int __devexit twl6040_codec_remove(struct platform_device *pdev) |
| 1239 | { |
| 1240 | snd_soc_unregister_codec(&pdev->dev); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1241 | return 0; |
| 1242 | } |
| 1243 | |
| 1244 | static struct platform_driver twl6040_codec_driver = { |
| 1245 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1246 | .name = "twl6040-codec", |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1247 | .owner = THIS_MODULE, |
| 1248 | }, |
| 1249 | .probe = twl6040_codec_probe, |
| 1250 | .remove = __devexit_p(twl6040_codec_remove), |
| 1251 | }; |
| 1252 | |
Mark Brown | 5bbcc3c | 2011-11-23 22:52:08 +0000 | [diff] [blame] | 1253 | module_platform_driver(twl6040_codec_driver); |
Misael Lopez Cruz | 8ecbabd | 2010-03-19 11:25:51 +0000 | [diff] [blame] | 1254 | |
| 1255 | MODULE_DESCRIPTION("ASoC TWL6040 codec driver"); |
| 1256 | MODULE_AUTHOR("Misael Lopez Cruz"); |
| 1257 | MODULE_LICENSE("GPL"); |