blob: 1f7081043566fe8f6d7557e730009e9b7de6f84a [file] [log] [blame]
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001/*
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 Cruz8ecbabd2010-03-19 11:25:51 +000027#include <linux/platform_device.h>
Stephen Rothwell68b40cc2010-03-29 17:55:51 +110028#include <linux/slab.h>
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -050029#include <linux/mfd/twl6040.h>
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +000030
31#include <sound/core.h>
32#include <sound/pcm.h>
33#include <sound/pcm_params.h>
34#include <sound/soc.h>
Liam Girdwoode48b46b2012-01-11 12:43:24 +000035#include <sound/soc-dapm.h>
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +000036#include <sound/initval.h>
37#include <sound/tlv.h>
38
39#include "twl6040.h"
40
Peter Ujfalusi68897492013-06-24 15:42:05 +020041enum 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, Margarita60ea4ce2010-12-10 21:05:58 -060049#define TWL6040_RATES SNDRV_PCM_RATE_8000_96000
Margarita Olaya Cabrera1bf84752010-12-14 19:00:21 -060050#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 Clausen290c3482013-10-06 13:43:51 +020057#define TWL6040_CACHEREGNUM (TWL6040_REG_STATUS + 1)
Peter Ujfalusi317596a2011-09-22 11:05:49 +030058
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -060059struct twl6040_jack_data {
60 struct snd_soc_jack *jack;
Peter Ujfalusi46dd0b92011-09-26 16:26:27 +030061 struct delayed_work work;
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -060062 int report;
63};
64
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +000065/* codec private data */
66struct twl6040_data {
Peter Ujfalusi2a433b92011-07-04 19:52:26 +030067 int plug_irq;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +000068 int codec_powered;
69 int pll;
Peter Ujfalusiaf958c72011-06-27 17:03:14 +030070 int pll_power_mode;
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -060071 int hs_power_mode;
72 int hs_power_mode_locked;
Peter Ujfalusi98c5fb12013-06-24 15:42:06 +020073 bool dl1_unmuted;
74 bool dl2_unmuted;
Peter Ujfalusi53509102013-11-29 16:03:44 +020075 u8 dl12_cache[TWL6040_REG_HFRCTL - TWL6040_REG_HSLCTL + 1];
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -050076 unsigned int clk_in;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +000077 unsigned int sysclk;
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -060078 struct twl6040_jack_data hs_jack;
79 struct snd_soc_codec *codec;
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -060080 struct mutex mutex;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +000081};
82
Peter Ujfalusiaf958c72011-06-27 17:03:14 +030083/* set of rates for each pll: low-power and high-performance */
Lars-Peter Clausen0d76fc62014-02-05 21:54:34 +010084static const unsigned int lp_rates[] = {
Peter Ujfalusiaf958c72011-06-27 17:03:14 +030085 8000,
86 11250,
87 16000,
88 22500,
89 32000,
90 44100,
91 48000,
92 88200,
93 96000,
94};
95
Lars-Peter Clausen0d76fc62014-02-05 21:54:34 +010096static const unsigned int hp_rates[] = {
Peter Ujfalusiaf958c72011-06-27 17:03:14 +030097 8000,
98 16000,
99 32000,
100 48000,
101 96000,
102};
103
Lars-Peter Clausen0d76fc62014-02-05 21:54:34 +0100104static const struct snd_pcm_hw_constraint_list sysclk_constraints[] = {
Peter Ujfalusif53c3462011-06-29 13:28:18 +0300105 { .count = ARRAY_SIZE(lp_rates), .list = lp_rates, },
106 { .count = ARRAY_SIZE(hp_rates), .list = hp_rates, },
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300107};
108
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200109static unsigned int twl6040_read(struct snd_soc_codec *codec, unsigned int reg)
Peter Ujfalusi53509102013-11-29 16:03:44 +0200110{
111 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500112 struct twl6040 *twl6040 = codec->control_data;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000113 u8 value;
114
115 if (reg >= TWL6040_CACHEREGNUM)
116 return -EIO;
117
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200118 switch (reg) {
119 case TWL6040_REG_HSLCTL:
120 case TWL6040_REG_HSRCTL:
121 case TWL6040_REG_EARCTL:
122 case TWL6040_REG_HFLCTL:
123 case TWL6040_REG_HFRCTL:
124 value = priv->dl12_cache[reg - TWL6040_REG_HSLCTL];
125 break;
126 default:
127 value = twl6040_reg_read(twl6040, reg);
128 break;
129 }
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000130
131 return value;
132}
133
Peter Ujfalusi0d35d0802013-11-29 16:03:43 +0200134static bool twl6040_can_write_to_chip(struct snd_soc_codec *codec,
135 unsigned int reg)
Peter Ujfalusi98c5fb12013-06-24 15:42:06 +0200136{
137 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
138
139 switch (reg) {
140 case TWL6040_REG_HSLCTL:
141 case TWL6040_REG_HSRCTL:
142 case TWL6040_REG_EARCTL:
143 /* DL1 path */
144 return priv->dl1_unmuted;
145 case TWL6040_REG_HFLCTL:
146 case TWL6040_REG_HFRCTL:
147 return priv->dl2_unmuted;
148 default:
149 return 1;
Sachin Kamatbf551412013-09-13 16:16:17 +0530150 }
Peter Ujfalusi98c5fb12013-06-24 15:42:06 +0200151}
152
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200153static inline void twl6040_update_dl12_cache(struct snd_soc_codec *codec,
154 u8 reg, u8 value)
155{
156 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
157
158 switch (reg) {
159 case TWL6040_REG_HSLCTL:
160 case TWL6040_REG_HSRCTL:
161 case TWL6040_REG_EARCTL:
162 case TWL6040_REG_HFLCTL:
163 case TWL6040_REG_HFRCTL:
164 priv->dl12_cache[reg - TWL6040_REG_HSLCTL] = value;
165 break;
166 default:
167 break;
168 }
169}
170
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000171static int twl6040_write(struct snd_soc_codec *codec,
172 unsigned int reg, unsigned int value)
173{
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500174 struct twl6040 *twl6040 = codec->control_data;
175
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000176 if (reg >= TWL6040_CACHEREGNUM)
177 return -EIO;
178
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200179 twl6040_update_dl12_cache(codec, reg, value);
Peter Ujfalusi0d35d0802013-11-29 16:03:43 +0200180 if (twl6040_can_write_to_chip(codec, reg))
Peter Ujfalusid17bf312011-09-22 11:05:48 +0300181 return twl6040_reg_write(twl6040, reg, value);
182 else
183 return 0;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000184}
185
Peter Ujfalusia52762e2011-09-15 15:39:27 +0300186static void twl6040_init_chip(struct snd_soc_codec *codec)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000187{
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200188 twl6040_read(codec, TWL6040_REG_TRIM1);
189 twl6040_read(codec, TWL6040_REG_TRIM2);
190 twl6040_read(codec, TWL6040_REG_TRIM3);
191 twl6040_read(codec, TWL6040_REG_HSOTRIM);
192 twl6040_read(codec, TWL6040_REG_HFOTRIM);
Peter Ujfalusif97217f2011-09-26 16:05:56 +0300193
Peter Ujfalusi2c27ff42011-09-15 15:39:28 +0300194 /* Change chip defaults */
195 /* No imput selected for microphone amplifiers */
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200196 twl6040_write(codec, TWL6040_REG_MICLCTL, 0x18);
197 twl6040_write(codec, TWL6040_REG_MICRCTL, 0x18);
Peter Ujfalusi3acef682011-09-22 11:05:45 +0300198
199 /*
200 * We need to lower the default gain values, so the ramp code
201 * can work correctly for the first playback.
202 * This reduces the pop noise heard at the first playback.
203 */
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200204 twl6040_write(codec, TWL6040_REG_HSGAIN, 0xff);
205 twl6040_write(codec, TWL6040_REG_EARCTL, 0x1e);
206 twl6040_write(codec, TWL6040_REG_HFLGAIN, 0x1d);
207 twl6040_write(codec, TWL6040_REG_HFRGAIN, 0x1d);
208 twl6040_write(codec, TWL6040_REG_LINEGAIN, 0);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000209}
210
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000211/* set headset dac and driver power mode */
212static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
213{
214 int hslctl, hsrctl;
Peter Ujfalusiab6cf132011-09-22 11:05:54 +0300215 int mask = TWL6040_HSDRVMODE | TWL6040_HSDACMODE;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000216
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200217 hslctl = twl6040_read(codec, TWL6040_REG_HSLCTL);
218 hsrctl = twl6040_read(codec, TWL6040_REG_HSRCTL);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000219
220 if (high_perf) {
221 hslctl &= ~mask;
222 hsrctl &= ~mask;
223 } else {
224 hslctl |= mask;
225 hsrctl |= mask;
226 }
227
228 twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl);
229 twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl);
230
231 return 0;
232}
233
Jorge Eduardo Candelaria0fad4ed2010-07-15 11:38:01 -0500234static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w,
235 struct snd_kcontrol *kcontrol, int event)
236{
Lars-Peter Clausenb27727d2015-01-15 12:52:07 +0100237 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
Peter Ujfalusi33b68162011-10-12 14:46:02 +0300238 u8 hslctl, hsrctl;
239
240 /*
241 * Workaround for Headset DC offset caused pop noise:
242 * Both HS DAC need to be turned on (before the HS driver) and off at
243 * the same time.
244 */
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200245 hslctl = twl6040_read(codec, TWL6040_REG_HSLCTL);
246 hsrctl = twl6040_read(codec, TWL6040_REG_HSRCTL);
Peter Ujfalusi33b68162011-10-12 14:46:02 +0300247 if (SND_SOC_DAPM_EVENT_ON(event)) {
248 hslctl |= TWL6040_HSDACENA;
249 hsrctl |= TWL6040_HSDACENA;
250 } else {
251 hslctl &= ~TWL6040_HSDACENA;
252 hsrctl &= ~TWL6040_HSDACENA;
253 }
254 twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl);
255 twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl);
256
Jorge Eduardo Candelaria0fad4ed2010-07-15 11:38:01 -0500257 msleep(1);
258 return 0;
259}
260
Peter Ujfalusi694b0002011-10-13 15:05:44 +0300261static int twl6040_ep_drv_event(struct snd_soc_dapm_widget *w,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000262 struct snd_kcontrol *kcontrol, int event)
263{
Lars-Peter Clausenb27727d2015-01-15 12:52:07 +0100264 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200265 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600266 int ret = 0;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000267
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600268 if (SND_SOC_DAPM_EVENT_ON(event)) {
Peter Ujfalusifac2f3e2011-10-13 15:05:42 +0300269 /* Earphone doesn't support low power mode */
270 priv->hs_power_mode_locked = 1;
271 ret = headset_power_mode(codec, 1);
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600272 } else {
Peter Ujfalusifac2f3e2011-10-13 15:05:42 +0300273 priv->hs_power_mode_locked = 0;
274 ret = headset_power_mode(codec, priv->hs_power_mode);
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600275 }
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000276
Jorge Eduardo Candelaria0fad4ed2010-07-15 11:38:01 -0500277 msleep(1);
278
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600279 return ret;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000280}
281
Mark Brown64ed9832011-01-20 21:43:44 +0000282static void twl6040_hs_jack_report(struct snd_soc_codec *codec,
283 struct snd_soc_jack *jack, int report)
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -0600284{
285 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
286 int status;
287
288 mutex_lock(&priv->mutex);
289
290 /* Sync status */
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200291 status = twl6040_read(codec, TWL6040_REG_STATUS);
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -0600292 if (status & TWL6040_PLUGCOMP)
293 snd_soc_jack_report(jack, report, report);
294 else
295 snd_soc_jack_report(jack, 0, report);
296
297 mutex_unlock(&priv->mutex);
298}
299
300void twl6040_hs_jack_detect(struct snd_soc_codec *codec,
301 struct snd_soc_jack *jack, int report)
302{
303 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
304 struct twl6040_jack_data *hs_jack = &priv->hs_jack;
305
306 hs_jack->jack = jack;
307 hs_jack->report = report;
308
309 twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report);
310}
311EXPORT_SYMBOL_GPL(twl6040_hs_jack_detect);
312
313static void twl6040_accessory_work(struct work_struct *work)
314{
315 struct twl6040_data *priv = container_of(work,
Peter Ujfalusi46dd0b92011-09-26 16:26:27 +0300316 struct twl6040_data, hs_jack.work.work);
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -0600317 struct snd_soc_codec *codec = priv->codec;
318 struct twl6040_jack_data *hs_jack = &priv->hs_jack;
319
320 twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report);
321}
322
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000323/* audio interrupt handler */
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500324static irqreturn_t twl6040_audio_handler(int irq, void *data)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000325{
326 struct snd_soc_codec *codec = data;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200327 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000328
Mark Browna06e4272013-07-18 22:44:03 +0100329 queue_delayed_work(system_power_efficient_wq,
330 &priv->hs_jack.work, msecs_to_jiffies(200));
Olaya, Margaritacf370a52010-12-10 21:05:30 -0600331
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000332 return IRQ_HANDLED;
333}
334
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300335static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol,
336 struct snd_ctl_elem_value *ucontrol)
337{
Lars-Peter Clauseneee5d7f2013-07-29 17:13:57 +0200338 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300339 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
340 unsigned int val;
341
342 /* Do not allow changes while Input/FF efect is running */
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200343 val = twl6040_read(codec, e->reg);
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300344 if (val & TWL6040_VIBENA && !(val & TWL6040_VIBSEL))
345 return -EBUSY;
346
347 return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
348}
349
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000350/*
351 * MICATT volume control:
352 * from -6 to 0 dB in 6 dB steps
353 */
354static DECLARE_TLV_DB_SCALE(mic_preamp_tlv, -600, 600, 0);
355
356/*
357 * MICGAIN volume control:
Ricardo Neri2763f452011-05-01 15:35:55 +0100358 * from 6 to 30 dB in 6 dB steps
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000359 */
Ricardo Neri2763f452011-05-01 15:35:55 +0100360static DECLARE_TLV_DB_SCALE(mic_amp_tlv, 600, 600, 0);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000361
362/*
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600363 * AFMGAIN volume control:
Liam Girdwood1f71a3b2011-03-28 19:23:23 +0100364 * from -18 to 24 dB in 6 dB steps
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600365 */
Liam Girdwood1f71a3b2011-03-28 19:23:23 +0100366static DECLARE_TLV_DB_SCALE(afm_amp_tlv, -1800, 600, 0);
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600367
368/*
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000369 * HSGAIN volume control:
370 * from -30 to 0 dB in 2 dB steps
371 */
372static DECLARE_TLV_DB_SCALE(hs_tlv, -3000, 200, 0);
373
374/*
375 * HFGAIN volume control:
376 * from -52 to 6 dB in 2 dB steps
377 */
378static DECLARE_TLV_DB_SCALE(hf_tlv, -5200, 200, 0);
379
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500380/*
381 * EPGAIN volume control:
382 * from -24 to 6 dB in 2 dB steps
383 */
384static DECLARE_TLV_DB_SCALE(ep_tlv, -2400, 200, 0);
385
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000386/* Left analog microphone selection */
387static const char *twl6040_amicl_texts[] =
388 {"Headset Mic", "Main Mic", "Aux/FM Left", "Off"};
389
390/* Right analog microphone selection */
391static const char *twl6040_amicr_texts[] =
392 {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"};
393
394static const struct soc_enum twl6040_enum[] = {
Takashi Iwaia1d0d782014-02-18 10:30:20 +0100395 SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3,
396 ARRAY_SIZE(twl6040_amicl_texts), twl6040_amicl_texts),
397 SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3,
398 ARRAY_SIZE(twl6040_amicr_texts), twl6040_amicr_texts),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000399};
400
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600401static const char *twl6040_hs_texts[] = {
402 "Off", "HS DAC", "Line-In amp"
403};
404
405static const struct soc_enum twl6040_hs_enum[] = {
406 SOC_ENUM_SINGLE(TWL6040_REG_HSLCTL, 5, ARRAY_SIZE(twl6040_hs_texts),
407 twl6040_hs_texts),
408 SOC_ENUM_SINGLE(TWL6040_REG_HSRCTL, 5, ARRAY_SIZE(twl6040_hs_texts),
409 twl6040_hs_texts),
410};
411
412static const char *twl6040_hf_texts[] = {
413 "Off", "HF DAC", "Line-In amp"
414};
415
416static const struct soc_enum twl6040_hf_enum[] = {
417 SOC_ENUM_SINGLE(TWL6040_REG_HFLCTL, 2, ARRAY_SIZE(twl6040_hf_texts),
418 twl6040_hf_texts),
419 SOC_ENUM_SINGLE(TWL6040_REG_HFRCTL, 2, ARRAY_SIZE(twl6040_hf_texts),
420 twl6040_hf_texts),
421};
422
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300423static const char *twl6040_vibrapath_texts[] = {
424 "Input FF", "Audio PDM"
425};
426
427static const struct soc_enum twl6040_vibra_enum[] = {
428 SOC_ENUM_SINGLE(TWL6040_REG_VIBCTLL, 1,
429 ARRAY_SIZE(twl6040_vibrapath_texts),
430 twl6040_vibrapath_texts),
431 SOC_ENUM_SINGLE(TWL6040_REG_VIBCTLR, 1,
432 ARRAY_SIZE(twl6040_vibrapath_texts),
433 twl6040_vibrapath_texts),
434};
435
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000436static const struct snd_kcontrol_new amicl_control =
437 SOC_DAPM_ENUM("Route", twl6040_enum[0]);
438
439static const struct snd_kcontrol_new amicr_control =
440 SOC_DAPM_ENUM("Route", twl6040_enum[1]);
441
442/* Headset DAC playback switches */
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600443static const struct snd_kcontrol_new hsl_mux_controls =
444 SOC_DAPM_ENUM("Route", twl6040_hs_enum[0]);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000445
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600446static const struct snd_kcontrol_new hsr_mux_controls =
447 SOC_DAPM_ENUM("Route", twl6040_hs_enum[1]);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000448
449/* Handsfree DAC playback switches */
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600450static const struct snd_kcontrol_new hfl_mux_controls =
451 SOC_DAPM_ENUM("Route", twl6040_hf_enum[0]);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000452
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600453static const struct snd_kcontrol_new hfr_mux_controls =
454 SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000455
Peter Ujfalusi317596a2011-09-22 11:05:49 +0300456static const struct snd_kcontrol_new ep_path_enable_control =
Lars-Peter Clausen290c3482013-10-06 13:43:51 +0200457 SOC_DAPM_SINGLE_VIRT("Switch", 1);
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500458
Peter Ujfalusifdb625f2011-09-22 11:05:52 +0300459static const struct snd_kcontrol_new auxl_switch_control =
460 SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 6, 1, 0);
461
462static const struct snd_kcontrol_new auxr_switch_control =
463 SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFRCTL, 6, 1, 0);
464
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300465/* Vibra playback switches */
466static const struct snd_kcontrol_new vibral_mux_controls =
467 SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[0],
468 snd_soc_dapm_get_enum_double,
469 twl6040_soc_dapm_put_vibra_enum);
470
471static const struct snd_kcontrol_new vibrar_mux_controls =
472 SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[1],
473 snd_soc_dapm_get_enum_double,
474 twl6040_soc_dapm_put_vibra_enum);
475
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600476/* Headset power mode */
Peter Ujfalusi7cca6062011-06-27 13:33:14 +0300477static const char *twl6040_power_mode_texts[] = {
Simon Wilson3e453652012-07-06 17:04:17 +0100478 "Low-Power", "High-Performance",
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600479};
480
Takashi Iwaia1d0d782014-02-18 10:30:20 +0100481static SOC_ENUM_SINGLE_EXT_DECL(twl6040_power_mode_enum,
482 twl6040_power_mode_texts);
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600483
484static int twl6040_headset_power_get_enum(struct snd_kcontrol *kcontrol,
485 struct snd_ctl_elem_value *ucontrol)
486{
Lars-Peter Clausenea53bf72014-03-18 09:02:04 +0100487 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600488 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
489
490 ucontrol->value.enumerated.item[0] = priv->hs_power_mode;
491
492 return 0;
493}
494
495static int twl6040_headset_power_put_enum(struct snd_kcontrol *kcontrol,
496 struct snd_ctl_elem_value *ucontrol)
497{
Lars-Peter Clausenea53bf72014-03-18 09:02:04 +0100498 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600499 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
500 int high_perf = ucontrol->value.enumerated.item[0];
501 int ret = 0;
502
503 if (!priv->hs_power_mode_locked)
504 ret = headset_power_mode(codec, high_perf);
505
506 if (!ret)
507 priv->hs_power_mode = high_perf;
508
509 return ret;
510}
511
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300512static int twl6040_pll_get_enum(struct snd_kcontrol *kcontrol,
513 struct snd_ctl_elem_value *ucontrol)
514{
Lars-Peter Clausenea53bf72014-03-18 09:02:04 +0100515 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300516 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
517
518 ucontrol->value.enumerated.item[0] = priv->pll_power_mode;
519
520 return 0;
521}
522
523static int twl6040_pll_put_enum(struct snd_kcontrol *kcontrol,
524 struct snd_ctl_elem_value *ucontrol)
525{
Lars-Peter Clausenea53bf72014-03-18 09:02:04 +0100526 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300527 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
528
529 priv->pll_power_mode = ucontrol->value.enumerated.item[0];
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300530
531 return 0;
532}
533
Liam Girdwoode48b46b2012-01-11 12:43:24 +0000534int twl6040_get_dl1_gain(struct snd_soc_codec *codec)
535{
Lars-Peter Clausend9dd3732015-05-15 12:33:00 +0200536 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
Liam Girdwoode48b46b2012-01-11 12:43:24 +0000537
538 if (snd_soc_dapm_get_pin_status(dapm, "EP"))
539 return -1; /* -1dB */
540
541 if (snd_soc_dapm_get_pin_status(dapm, "HSOR") ||
542 snd_soc_dapm_get_pin_status(dapm, "HSOL")) {
543
544 u8 val = snd_soc_read(codec, TWL6040_REG_HSLCTL);
545 if (val & TWL6040_HSDACMODE)
546 /* HSDACL in LP mode */
547 return -8; /* -8dB */
548 else
549 /* HSDACL in HP mode */
550 return -1; /* -1dB */
551 }
552 return 0; /* 0dB */
553}
554EXPORT_SYMBOL_GPL(twl6040_get_dl1_gain);
555
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300556int twl6040_get_clk_id(struct snd_soc_codec *codec)
557{
558 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
559
Peter Ujfalusiff593ca2011-07-04 10:35:23 +0300560 return priv->pll_power_mode;
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300561}
562EXPORT_SYMBOL_GPL(twl6040_get_clk_id);
563
Peter Ujfalusidb4aabc2011-09-26 16:05:57 +0300564int twl6040_get_trim_value(struct snd_soc_codec *codec, enum twl6040_trim trim)
565{
566 if (unlikely(trim >= TWL6040_TRIM_INVAL))
567 return -EINVAL;
568
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200569 return twl6040_read(codec, TWL6040_REG_TRIM1 + trim);
Peter Ujfalusidb4aabc2011-09-26 16:05:57 +0300570}
571EXPORT_SYMBOL_GPL(twl6040_get_trim_value);
572
Liam Girdwood08656912012-01-09 12:10:16 +0000573int twl6040_get_hs_step_size(struct snd_soc_codec *codec)
574{
575 struct twl6040 *twl6040 = codec->control_data;
576
Peter Ujfalusibe4ac002012-07-16 11:49:43 +0200577 if (twl6040_get_revid(twl6040) < TWL6040_REV_ES1_3)
Liam Girdwood08656912012-01-09 12:10:16 +0000578 /* For ES under ES_1.3 HS step is 2 mV */
579 return 2;
580 else
581 /* For ES_1.3 HS step is 1 mV */
582 return 1;
583}
584EXPORT_SYMBOL_GPL(twl6040_get_hs_step_size);
585
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000586static const struct snd_kcontrol_new twl6040_snd_controls[] = {
587 /* Capture gains */
588 SOC_DOUBLE_TLV("Capture Preamplifier Volume",
589 TWL6040_REG_MICGAIN, 6, 7, 1, 1, mic_preamp_tlv),
590 SOC_DOUBLE_TLV("Capture Volume",
591 TWL6040_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv),
592
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600593 /* AFM gains */
594 SOC_DOUBLE_TLV("Aux FM Volume",
Liam Girdwood1f71a3b2011-03-28 19:23:23 +0100595 TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv),
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600596
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000597 /* Playback gains */
Peter Ujfalusi3bb8a812012-05-04 15:17:20 +0300598 SOC_DOUBLE_TLV("Headset Playback Volume",
599 TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv),
600 SOC_DOUBLE_R_TLV("Handsfree Playback Volume",
601 TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv),
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500602 SOC_SINGLE_TLV("Earphone Playback Volume",
603 TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv),
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600604
Peter Ujfalusi7cca6062011-06-27 13:33:14 +0300605 SOC_ENUM_EXT("Headset Power Mode", twl6040_power_mode_enum,
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600606 twl6040_headset_power_get_enum,
607 twl6040_headset_power_put_enum),
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300608
609 SOC_ENUM_EXT("PLL Selection", twl6040_power_mode_enum,
610 twl6040_pll_get_enum, twl6040_pll_put_enum),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000611};
612
613static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
614 /* Inputs */
615 SND_SOC_DAPM_INPUT("MAINMIC"),
616 SND_SOC_DAPM_INPUT("HSMIC"),
617 SND_SOC_DAPM_INPUT("SUBMIC"),
618 SND_SOC_DAPM_INPUT("AFML"),
619 SND_SOC_DAPM_INPUT("AFMR"),
620
621 /* Outputs */
622 SND_SOC_DAPM_OUTPUT("HSOL"),
623 SND_SOC_DAPM_OUTPUT("HSOR"),
624 SND_SOC_DAPM_OUTPUT("HFL"),
625 SND_SOC_DAPM_OUTPUT("HFR"),
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500626 SND_SOC_DAPM_OUTPUT("EP"),
Peter Ujfalusifdb625f2011-09-22 11:05:52 +0300627 SND_SOC_DAPM_OUTPUT("AUXL"),
628 SND_SOC_DAPM_OUTPUT("AUXR"),
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300629 SND_SOC_DAPM_OUTPUT("VIBRAL"),
630 SND_SOC_DAPM_OUTPUT("VIBRAR"),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000631
632 /* Analog input muxes for the capture amplifiers */
633 SND_SOC_DAPM_MUX("Analog Left Capture Route",
634 SND_SOC_NOPM, 0, 0, &amicl_control),
635 SND_SOC_DAPM_MUX("Analog Right Capture Route",
636 SND_SOC_NOPM, 0, 0, &amicr_control),
637
638 /* Analog capture PGAs */
639 SND_SOC_DAPM_PGA("MicAmpL",
640 TWL6040_REG_MICLCTL, 0, 0, NULL, 0),
641 SND_SOC_DAPM_PGA("MicAmpR",
642 TWL6040_REG_MICRCTL, 0, 0, NULL, 0),
643
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600644 /* Auxiliary FM PGAs */
645 SND_SOC_DAPM_PGA("AFMAmpL",
646 TWL6040_REG_MICLCTL, 1, 0, NULL, 0),
647 SND_SOC_DAPM_PGA("AFMAmpR",
648 TWL6040_REG_MICRCTL, 1, 0, NULL, 0),
649
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000650 /* ADCs */
Peter Ujfalusi805238b2012-09-20 16:32:15 +0300651 SND_SOC_DAPM_ADC("ADC Left", NULL, TWL6040_REG_MICLCTL, 2, 0),
652 SND_SOC_DAPM_ADC("ADC Right", NULL, TWL6040_REG_MICRCTL, 2, 0),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000653
654 /* Microphone bias */
Peter Ujfalusi778cee72011-12-22 12:47:21 +0200655 SND_SOC_DAPM_SUPPLY("Headset Mic Bias",
656 TWL6040_REG_AMICBCTL, 0, 0, NULL, 0),
657 SND_SOC_DAPM_SUPPLY("Main Mic Bias",
658 TWL6040_REG_AMICBCTL, 4, 0, NULL, 0),
659 SND_SOC_DAPM_SUPPLY("Digital Mic1 Bias",
660 TWL6040_REG_DMICBCTL, 0, 0, NULL, 0),
661 SND_SOC_DAPM_SUPPLY("Digital Mic2 Bias",
662 TWL6040_REG_DMICBCTL, 4, 0, NULL, 0),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000663
664 /* DACs */
Peter Ujfalusi805238b2012-09-20 16:32:15 +0300665 SND_SOC_DAPM_DAC("HSDAC Left", NULL, SND_SOC_NOPM, 0, 0),
666 SND_SOC_DAPM_DAC("HSDAC Right", NULL, SND_SOC_NOPM, 0, 0),
667 SND_SOC_DAPM_DAC("HFDAC Left", NULL, TWL6040_REG_HFLCTL, 0, 0),
668 SND_SOC_DAPM_DAC("HFDAC Right", NULL, TWL6040_REG_HFRCTL, 0, 0),
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300669 /* Virtual DAC for vibra path (DL4 channel) */
Peter Ujfalusi805238b2012-09-20 16:32:15 +0300670 SND_SOC_DAPM_DAC("VIBRA DAC", NULL, SND_SOC_NOPM, 0, 0),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000671
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300672 SND_SOC_DAPM_MUX("Handsfree Left Playback",
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600673 SND_SOC_NOPM, 0, 0, &hfl_mux_controls),
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300674 SND_SOC_DAPM_MUX("Handsfree Right Playback",
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600675 SND_SOC_NOPM, 0, 0, &hfr_mux_controls),
676 /* Analog playback Muxes */
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300677 SND_SOC_DAPM_MUX("Headset Left Playback",
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600678 SND_SOC_NOPM, 0, 0, &hsl_mux_controls),
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300679 SND_SOC_DAPM_MUX("Headset Right Playback",
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600680 SND_SOC_NOPM, 0, 0, &hsr_mux_controls),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000681
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300682 SND_SOC_DAPM_MUX("Vibra Left Playback", SND_SOC_NOPM, 0, 0,
683 &vibral_mux_controls),
684 SND_SOC_DAPM_MUX("Vibra Right Playback", SND_SOC_NOPM, 0, 0,
685 &vibrar_mux_controls),
686
Peter Ujfalusi317596a2011-09-22 11:05:49 +0300687 SND_SOC_DAPM_SWITCH("Earphone Playback", SND_SOC_NOPM, 0, 0,
688 &ep_path_enable_control),
Peter Ujfalusifdb625f2011-09-22 11:05:52 +0300689 SND_SOC_DAPM_SWITCH("AUXL Playback", SND_SOC_NOPM, 0, 0,
690 &auxl_switch_control),
691 SND_SOC_DAPM_SWITCH("AUXR Playback", SND_SOC_NOPM, 0, 0,
692 &auxr_switch_control),
Peter Ujfalusi317596a2011-09-22 11:05:49 +0300693
Jorge Eduardo Candelaria0fad4ed2010-07-15 11:38:01 -0500694 /* Analog playback drivers */
Peter Ujfalusi3bb8a812012-05-04 15:17:20 +0300695 SND_SOC_DAPM_OUT_DRV("HF Left Driver",
696 TWL6040_REG_HFLCTL, 4, 0, NULL, 0),
697 SND_SOC_DAPM_OUT_DRV("HF Right Driver",
698 TWL6040_REG_HFRCTL, 4, 0, NULL, 0),
699 SND_SOC_DAPM_OUT_DRV("HS Left Driver",
700 TWL6040_REG_HSLCTL, 2, 0, NULL, 0),
701 SND_SOC_DAPM_OUT_DRV("HS Right Driver",
702 TWL6040_REG_HSRCTL, 2, 0, NULL, 0),
Peter Ujfalusi317596a2011-09-22 11:05:49 +0300703 SND_SOC_DAPM_OUT_DRV_E("Earphone Driver",
704 TWL6040_REG_EARCTL, 0, 0, NULL, 0,
Peter Ujfalusi694b0002011-10-13 15:05:44 +0300705 twl6040_ep_drv_event,
Peter Ujfalusiaa1a4102011-10-13 15:05:43 +0300706 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300707 SND_SOC_DAPM_OUT_DRV("Vibra Left Driver",
708 TWL6040_REG_VIBCTLL, 0, 0, NULL, 0),
709 SND_SOC_DAPM_OUT_DRV("Vibra Right Driver",
710 TWL6040_REG_VIBCTLR, 0, 0, NULL, 0),
711
712 SND_SOC_DAPM_SUPPLY("Vibra Left Control", TWL6040_REG_VIBCTLL, 2, 0,
713 NULL, 0),
714 SND_SOC_DAPM_SUPPLY("Vibra Right Control", TWL6040_REG_VIBCTLR, 2, 0,
715 NULL, 0),
Peter Ujfalusi33b68162011-10-12 14:46:02 +0300716 SND_SOC_DAPM_SUPPLY_S("HSDAC Power", 1, SND_SOC_NOPM, 0, 0,
717 twl6040_hs_dac_event,
718 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000719
720 /* Analog playback PGAs */
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300721 SND_SOC_DAPM_PGA("HF Left PGA",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000722 TWL6040_REG_HFLCTL, 1, 0, NULL, 0),
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300723 SND_SOC_DAPM_PGA("HF Right PGA",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000724 TWL6040_REG_HFRCTL, 1, 0, NULL, 0),
725
726};
727
728static const struct snd_soc_dapm_route intercon[] = {
Peter Ujfalusi805238b2012-09-20 16:32:15 +0300729 /* Stream -> DAC mapping */
730 {"HSDAC Left", NULL, "Legacy Playback"},
731 {"HSDAC Left", NULL, "Headset Playback"},
732 {"HSDAC Right", NULL, "Legacy Playback"},
733 {"HSDAC Right", NULL, "Headset Playback"},
734
735 {"HFDAC Left", NULL, "Legacy Playback"},
736 {"HFDAC Left", NULL, "Handsfree Playback"},
737 {"HFDAC Right", NULL, "Legacy Playback"},
738 {"HFDAC Right", NULL, "Handsfree Playback"},
739
740 {"VIBRA DAC", NULL, "Legacy Playback"},
741 {"VIBRA DAC", NULL, "Vibra Playback"},
742
743 /* ADC -> Stream mapping */
Peter Ujfalusi07ac2292012-10-04 14:15:02 +0300744 {"Legacy Capture" , NULL, "ADC Left"},
745 {"Capture", NULL, "ADC Left"},
746 {"Legacy Capture", NULL, "ADC Right"},
747 {"Capture" , NULL, "ADC Right"},
Peter Ujfalusi805238b2012-09-20 16:32:15 +0300748
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000749 /* Capture path */
750 {"Analog Left Capture Route", "Headset Mic", "HSMIC"},
751 {"Analog Left Capture Route", "Main Mic", "MAINMIC"},
752 {"Analog Left Capture Route", "Aux/FM Left", "AFML"},
753
754 {"Analog Right Capture Route", "Headset Mic", "HSMIC"},
755 {"Analog Right Capture Route", "Sub Mic", "SUBMIC"},
756 {"Analog Right Capture Route", "Aux/FM Right", "AFMR"},
757
758 {"MicAmpL", NULL, "Analog Left Capture Route"},
759 {"MicAmpR", NULL, "Analog Right Capture Route"},
760
761 {"ADC Left", NULL, "MicAmpL"},
762 {"ADC Right", NULL, "MicAmpR"},
763
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600764 /* AFM path */
Peter Ujfalusi5bf692d2011-09-22 11:05:47 +0300765 {"AFMAmpL", NULL, "AFML"},
766 {"AFMAmpR", NULL, "AFMR"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000767
Peter Ujfalusi33b68162011-10-12 14:46:02 +0300768 {"HSDAC Left", NULL, "HSDAC Power"},
769 {"HSDAC Right", NULL, "HSDAC Power"},
770
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300771 {"Headset Left Playback", "HS DAC", "HSDAC Left"},
772 {"Headset Left Playback", "Line-In amp", "AFMAmpL"},
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600773
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300774 {"Headset Right Playback", "HS DAC", "HSDAC Right"},
775 {"Headset Right Playback", "Line-In amp", "AFMAmpR"},
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600776
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300777 {"HS Left Driver", NULL, "Headset Left Playback"},
778 {"HS Right Driver", NULL, "Headset Right Playback"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000779
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300780 {"HSOL", NULL, "HS Left Driver"},
781 {"HSOR", NULL, "HS Right Driver"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000782
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500783 /* Earphone playback path */
Peter Ujfalusi317596a2011-09-22 11:05:49 +0300784 {"Earphone Playback", "Switch", "HSDAC Left"},
785 {"Earphone Driver", NULL, "Earphone Playback"},
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500786 {"EP", NULL, "Earphone Driver"},
787
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300788 {"Handsfree Left Playback", "HF DAC", "HFDAC Left"},
789 {"Handsfree Left Playback", "Line-In amp", "AFMAmpL"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000790
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300791 {"Handsfree Right Playback", "HF DAC", "HFDAC Right"},
792 {"Handsfree Right Playback", "Line-In amp", "AFMAmpR"},
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600793
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300794 {"HF Left PGA", NULL, "Handsfree Left Playback"},
795 {"HF Right PGA", NULL, "Handsfree Right Playback"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000796
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300797 {"HF Left Driver", NULL, "HF Left PGA"},
798 {"HF Right Driver", NULL, "HF Right PGA"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000799
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300800 {"HFL", NULL, "HF Left Driver"},
801 {"HFR", NULL, "HF Right Driver"},
Peter Ujfalusifdb625f2011-09-22 11:05:52 +0300802
803 {"AUXL Playback", "Switch", "HF Left PGA"},
804 {"AUXR Playback", "Switch", "HF Right PGA"},
805
806 {"AUXL", NULL, "AUXL Playback"},
807 {"AUXR", NULL, "AUXR Playback"},
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300808
809 /* Vibrator paths */
810 {"Vibra Left Playback", "Audio PDM", "VIBRA DAC"},
811 {"Vibra Right Playback", "Audio PDM", "VIBRA DAC"},
812
813 {"Vibra Left Driver", NULL, "Vibra Left Playback"},
814 {"Vibra Right Driver", NULL, "Vibra Right Playback"},
815 {"Vibra Left Driver", NULL, "Vibra Left Control"},
816 {"Vibra Right Driver", NULL, "Vibra Right Control"},
817
818 {"VIBRAL", NULL, "Vibra Left Driver"},
819 {"VIBRAR", NULL, "Vibra Right Driver"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000820};
821
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000822static int twl6040_set_bias_level(struct snd_soc_codec *codec,
823 enum snd_soc_bias_level level)
824{
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500825 struct twl6040 *twl6040 = codec->control_data;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200826 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusi1135ef12016-05-11 14:14:05 +0300827 int ret = 0;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000828
829 switch (level) {
830 case SND_SOC_BIAS_ON:
831 break;
832 case SND_SOC_BIAS_PREPARE:
833 break;
834 case SND_SOC_BIAS_STANDBY:
Peter Ujfalusi1135ef12016-05-11 14:14:05 +0300835 if (priv->codec_powered) {
836 /* Select low power PLL in standby */
837 ret = twl6040_set_pll(twl6040, TWL6040_SYSCLK_SEL_LPPLL,
838 32768, 19200000);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000839 break;
Peter Ujfalusi1135ef12016-05-11 14:14:05 +0300840 }
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000841
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500842 ret = twl6040_power(twl6040, 1);
843 if (ret)
Peter Ujfalusi1135ef12016-05-11 14:14:05 +0300844 break;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000845
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500846 priv->codec_powered = 1;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000847
Olaya, Margarita65b7cec2010-12-14 19:18:36 -0600848 /* Set external boost GPO */
849 twl6040_write(codec, TWL6040_REG_GPOCTL, 0x02);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000850 break;
851 case SND_SOC_BIAS_OFF:
852 if (!priv->codec_powered)
853 break;
854
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500855 twl6040_power(twl6040, 0);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000856 priv->codec_powered = 0;
857 break;
858 }
859
Peter Ujfalusi1135ef12016-05-11 14:14:05 +0300860 return ret;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000861}
862
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000863static int twl6040_startup(struct snd_pcm_substream *substream,
864 struct snd_soc_dai *dai)
865{
Mark Browne6968a12012-04-04 15:58:16 +0100866 struct snd_soc_codec *codec = dai->codec;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200867 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000868
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000869 snd_pcm_hw_constraint_list(substream->runtime, 0,
870 SNDRV_PCM_HW_PARAM_RATE,
Peter Ujfalusif53c3462011-06-29 13:28:18 +0300871 &sysclk_constraints[priv->pll_power_mode]);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000872
873 return 0;
874}
875
876static int twl6040_hw_params(struct snd_pcm_substream *substream,
877 struct snd_pcm_hw_params *params,
878 struct snd_soc_dai *dai)
879{
Mark Browne6968a12012-04-04 15:58:16 +0100880 struct snd_soc_codec *codec = dai->codec;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200881 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000882 int rate;
883
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000884 rate = params_rate(params);
885 switch (rate) {
Olaya, Margarita60ea4ce2010-12-10 21:05:58 -0600886 case 11250:
887 case 22500:
888 case 44100:
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000889 case 88200:
Peter Ujfalusi753621c2011-07-03 02:06:07 +0300890 /* These rates are not supported when HPPLL is in use */
891 if (unlikely(priv->pll == TWL6040_SYSCLK_SEL_HPPLL)) {
892 dev_err(codec->dev, "HPPLL does not support rate %d\n",
893 rate);
894 return -EINVAL;
895 }
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000896 priv->sysclk = 17640000;
897 break;
Olaya, Margarita60ea4ce2010-12-10 21:05:58 -0600898 case 8000:
899 case 16000:
900 case 32000:
901 case 48000:
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000902 case 96000:
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000903 priv->sysclk = 19200000;
904 break;
905 default:
906 dev_err(codec->dev, "unsupported rate %d\n", rate);
907 return -EINVAL;
908 }
909
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000910 return 0;
911}
912
Olaya, Margarita4e624d02010-12-10 21:05:54 -0600913static int twl6040_prepare(struct snd_pcm_substream *substream,
914 struct snd_soc_dai *dai)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000915{
Mark Browne6968a12012-04-04 15:58:16 +0100916 struct snd_soc_codec *codec = dai->codec;
Peter Ujfalusi753621c2011-07-03 02:06:07 +0300917 struct twl6040 *twl6040 = codec->control_data;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200918 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusi753621c2011-07-03 02:06:07 +0300919 int ret;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000920
Olaya, Margarita4e624d02010-12-10 21:05:54 -0600921 if (!priv->sysclk) {
922 dev_err(codec->dev,
923 "no mclk configured, call set_sysclk() on init\n");
924 return -EINVAL;
925 }
926
Peter Ujfalusi753621c2011-07-03 02:06:07 +0300927 ret = twl6040_set_pll(twl6040, priv->pll, priv->clk_in, priv->sysclk);
928 if (ret) {
929 dev_err(codec->dev, "Can not set PLL (%d)\n", ret);
930 return -EPERM;
931 }
932
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000933 return 0;
934}
935
936static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai,
937 int clk_id, unsigned int freq, int dir)
938{
939 struct snd_soc_codec *codec = codec_dai->codec;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200940 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000941
942 switch (clk_id) {
943 case TWL6040_SYSCLK_SEL_LPPLL:
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000944 case TWL6040_SYSCLK_SEL_HPPLL:
Peter Ujfalusi753621c2011-07-03 02:06:07 +0300945 priv->pll = clk_id;
946 priv->clk_in = freq;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000947 break;
948 default:
949 dev_err(codec->dev, "unknown clk_id %d\n", clk_id);
950 return -EINVAL;
951 }
952
953 return 0;
954}
955
Peter Ujfalusi98c5fb12013-06-24 15:42:06 +0200956static void twl6040_mute_path(struct snd_soc_codec *codec, enum twl6040_dai_id id,
957 int mute)
958{
959 struct twl6040 *twl6040 = codec->control_data;
960 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
961 int hslctl, hsrctl, earctl;
962 int hflctl, hfrctl;
963
964 switch (id) {
965 case TWL6040_DAI_DL1:
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200966 hslctl = twl6040_read(codec, TWL6040_REG_HSLCTL);
967 hsrctl = twl6040_read(codec, TWL6040_REG_HSRCTL);
968 earctl = twl6040_read(codec, TWL6040_REG_EARCTL);
Peter Ujfalusi98c5fb12013-06-24 15:42:06 +0200969
970 if (mute) {
971 /* Power down drivers and DACs */
972 earctl &= ~0x01;
973 hslctl &= ~(TWL6040_HSDRVENA | TWL6040_HSDACENA);
974 hsrctl &= ~(TWL6040_HSDRVENA | TWL6040_HSDACENA);
975
976 }
977
978 twl6040_reg_write(twl6040, TWL6040_REG_EARCTL, earctl);
979 twl6040_reg_write(twl6040, TWL6040_REG_HSLCTL, hslctl);
980 twl6040_reg_write(twl6040, TWL6040_REG_HSRCTL, hsrctl);
981 priv->dl1_unmuted = !mute;
982 break;
983 case TWL6040_DAI_DL2:
Peter Ujfalusi626bcac2013-11-29 16:03:47 +0200984 hflctl = twl6040_read(codec, TWL6040_REG_HFLCTL);
985 hfrctl = twl6040_read(codec, TWL6040_REG_HFRCTL);
Peter Ujfalusi98c5fb12013-06-24 15:42:06 +0200986
987 if (mute) {
988 /* Power down drivers and DACs */
989 hflctl &= ~(TWL6040_HFDACENA | TWL6040_HFPGAENA |
Peter Ujfalusi45c04702016-05-18 16:19:01 +0300990 TWL6040_HFDRVENA | TWL6040_HFSWENA);
Peter Ujfalusi98c5fb12013-06-24 15:42:06 +0200991 hfrctl &= ~(TWL6040_HFDACENA | TWL6040_HFPGAENA |
Peter Ujfalusi45c04702016-05-18 16:19:01 +0300992 TWL6040_HFDRVENA | TWL6040_HFSWENA);
Peter Ujfalusi98c5fb12013-06-24 15:42:06 +0200993 }
994
995 twl6040_reg_write(twl6040, TWL6040_REG_HFLCTL, hflctl);
996 twl6040_reg_write(twl6040, TWL6040_REG_HFRCTL, hfrctl);
997 priv->dl2_unmuted = !mute;
998 break;
999 default:
1000 break;
Sachin Kamatbf551412013-09-13 16:16:17 +05301001 }
Peter Ujfalusi98c5fb12013-06-24 15:42:06 +02001002}
1003
1004static int twl6040_digital_mute(struct snd_soc_dai *dai, int mute)
1005{
1006 switch (dai->id) {
1007 case TWL6040_DAI_LEGACY:
1008 twl6040_mute_path(dai->codec, TWL6040_DAI_DL1, mute);
1009 twl6040_mute_path(dai->codec, TWL6040_DAI_DL2, mute);
1010 break;
1011 case TWL6040_DAI_DL1:
1012 case TWL6040_DAI_DL2:
1013 twl6040_mute_path(dai->codec, dai->id, mute);
1014 break;
1015 default:
1016 break;
1017 }
1018
1019 return 0;
1020}
1021
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001022static const struct snd_soc_dai_ops twl6040_dai_ops = {
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001023 .startup = twl6040_startup,
1024 .hw_params = twl6040_hw_params,
Olaya, Margarita4e624d02010-12-10 21:05:54 -06001025 .prepare = twl6040_prepare,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001026 .set_sysclk = twl6040_set_dai_sysclk,
Peter Ujfalusi98c5fb12013-06-24 15:42:06 +02001027 .digital_mute = twl6040_digital_mute,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001028};
1029
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001030static struct snd_soc_dai_driver twl6040_dai[] = {
1031{
Peter Ujfalusid13f1fe2011-09-22 11:05:53 +03001032 .name = "twl6040-legacy",
Peter Ujfalusi68897492013-06-24 15:42:05 +02001033 .id = TWL6040_DAI_LEGACY,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001034 .playback = {
Peter Ujfalusi805238b2012-09-20 16:32:15 +03001035 .stream_name = "Legacy Playback",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001036 .channels_min = 1,
Peter Ujfalusicdd50542011-09-15 15:59:19 +03001037 .channels_max = 5,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001038 .rates = TWL6040_RATES,
1039 .formats = TWL6040_FORMATS,
1040 },
1041 .capture = {
Peter Ujfalusi805238b2012-09-20 16:32:15 +03001042 .stream_name = "Legacy Capture",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001043 .channels_min = 1,
1044 .channels_max = 2,
1045 .rates = TWL6040_RATES,
1046 .formats = TWL6040_FORMATS,
1047 },
1048 .ops = &twl6040_dai_ops,
Peter Ujfalusi21385ee2011-07-05 22:35:53 +03001049},
1050{
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001051 .name = "twl6040-ul",
Peter Ujfalusi68897492013-06-24 15:42:05 +02001052 .id = TWL6040_DAI_UL,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001053 .capture = {
1054 .stream_name = "Capture",
1055 .channels_min = 1,
1056 .channels_max = 2,
1057 .rates = TWL6040_RATES,
1058 .formats = TWL6040_FORMATS,
1059 },
1060 .ops = &twl6040_dai_ops,
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001061},
1062{
1063 .name = "twl6040-dl1",
Peter Ujfalusi68897492013-06-24 15:42:05 +02001064 .id = TWL6040_DAI_DL1,
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001065 .playback = {
1066 .stream_name = "Headset Playback",
1067 .channels_min = 1,
1068 .channels_max = 2,
1069 .rates = TWL6040_RATES,
1070 .formats = TWL6040_FORMATS,
1071 },
1072 .ops = &twl6040_dai_ops,
1073},
1074{
1075 .name = "twl6040-dl2",
Peter Ujfalusi68897492013-06-24 15:42:05 +02001076 .id = TWL6040_DAI_DL2,
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001077 .playback = {
1078 .stream_name = "Handsfree Playback",
1079 .channels_min = 1,
1080 .channels_max = 2,
1081 .rates = TWL6040_RATES,
1082 .formats = TWL6040_FORMATS,
1083 },
1084 .ops = &twl6040_dai_ops,
1085},
1086{
1087 .name = "twl6040-vib",
Peter Ujfalusi68897492013-06-24 15:42:05 +02001088 .id = TWL6040_DAI_VIB,
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001089 .playback = {
1090 .stream_name = "Vibra Playback",
Peter Ujfalusid8dd0322011-09-15 15:59:18 +03001091 .channels_min = 1,
1092 .channels_max = 1,
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001093 .rates = SNDRV_PCM_RATE_CONTINUOUS,
1094 .formats = TWL6040_FORMATS,
1095 },
1096 .ops = &twl6040_dai_ops,
1097},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001098};
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001099
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001100static int twl6040_probe(struct snd_soc_codec *codec)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001101{
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001102 struct twl6040_data *priv;
Peter Ujfalusi626bcac2013-11-29 16:03:47 +02001103 struct twl6040 *twl6040 = dev_get_drvdata(codec->dev->parent);
Geliang Tangbb18f092015-12-23 21:03:39 +08001104 struct platform_device *pdev = to_platform_device(codec->dev);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001105 int ret = 0;
1106
Peter Ujfalusi9523fcd2013-01-11 17:01:01 +01001107 priv = devm_kzalloc(codec->dev, sizeof(*priv), GFP_KERNEL);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001108 if (priv == NULL)
1109 return -ENOMEM;
Peter Ujfalusi9523fcd2013-01-11 17:01:01 +01001110
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001111 snd_soc_codec_set_drvdata(codec, priv);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001112
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -06001113 priv->codec = codec;
Peter Ujfalusi626bcac2013-11-29 16:03:47 +02001114 codec->control_data = twl6040;
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -06001115
Peter Ujfalusi2a433b92011-07-04 19:52:26 +03001116 priv->plug_irq = platform_get_irq(pdev, 0);
1117 if (priv->plug_irq < 0) {
1118 dev_err(codec->dev, "invalid irq\n");
Peter Ujfalusi9523fcd2013-01-11 17:01:01 +01001119 return -EINVAL;
Peter Ujfalusi2a433b92011-07-04 19:52:26 +03001120 }
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001121
Peter Ujfalusi46dd0b92011-09-26 16:26:27 +03001122 INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work);
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -06001123
1124 mutex_init(&priv->mutex);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001125
Peter Ujfalusif60596d2013-06-24 15:42:03 +02001126 ret = request_threaded_irq(priv->plug_irq, NULL,
Fabio Estevam208ba892015-05-12 01:22:59 -03001127 twl6040_audio_handler,
1128 IRQF_NO_SUSPEND | IRQF_ONESHOT,
Peter Ujfalusi9523fcd2013-01-11 17:01:01 +01001129 "twl6040_irq_plug", codec);
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -05001130 if (ret) {
1131 dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret);
Peter Ujfalusida2107d2013-01-11 17:01:02 +01001132 return ret;
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -05001133 }
1134
Lars-Peter Clausenbd1204c2015-04-27 22:13:24 +02001135 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY);
Peter Ujfalusia52762e2011-09-15 15:39:27 +03001136 twl6040_init_chip(codec);
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -05001137
Peter Ujfalusi626bcac2013-11-29 16:03:47 +02001138 return 0;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001139}
1140
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001141static int twl6040_remove(struct snd_soc_codec *codec)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001142{
Peter Ujfalusif60596d2013-06-24 15:42:03 +02001143 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1144
1145 free_irq(priv->plug_irq, codec);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001146
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001147 return 0;
1148}
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001149
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001150static struct snd_soc_codec_driver soc_codec_dev_twl6040 = {
1151 .probe = twl6040_probe,
1152 .remove = twl6040_remove,
Peter Ujfalusi626bcac2013-11-29 16:03:47 +02001153 .read = twl6040_read,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001154 .write = twl6040_write,
1155 .set_bias_level = twl6040_set_bias_level,
Lars-Peter Clausenc4ee42a2014-11-26 20:58:00 +01001156 .suspend_bias_off = true,
Mark Browna5d3a212012-02-08 18:34:19 +00001157 .ignore_pmdown_time = true,
Peter Ujfalusia175fce2011-10-11 13:11:12 +03001158
1159 .controls = twl6040_snd_controls,
1160 .num_controls = ARRAY_SIZE(twl6040_snd_controls),
1161 .dapm_widgets = twl6040_dapm_widgets,
1162 .num_dapm_widgets = ARRAY_SIZE(twl6040_dapm_widgets),
1163 .dapm_routes = intercon,
1164 .num_dapm_routes = ARRAY_SIZE(intercon),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001165};
1166
Bill Pemberton7a79e942012-12-07 09:26:37 -05001167static int twl6040_codec_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001168{
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001169 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl6040,
1170 twl6040_dai, ARRAY_SIZE(twl6040_dai));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001171}
1172
Bill Pemberton7a79e942012-12-07 09:26:37 -05001173static int twl6040_codec_remove(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001174{
1175 snd_soc_unregister_codec(&pdev->dev);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001176 return 0;
1177}
1178
1179static struct platform_driver twl6040_codec_driver = {
1180 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001181 .name = "twl6040-codec",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001182 },
1183 .probe = twl6040_codec_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -05001184 .remove = twl6040_codec_remove,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001185};
1186
Mark Brown5bbcc3c2011-11-23 22:52:08 +00001187module_platform_driver(twl6040_codec_driver);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001188
1189MODULE_DESCRIPTION("ASoC TWL6040 codec driver");
1190MODULE_AUTHOR("Misael Lopez Cruz");
1191MODULE_LICENSE("GPL");