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