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