blob: 9b9a6e587610540c310c39387791f588592e1a4c [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
Olaya, Margarita60ea4ce2010-12-10 21:05:58 -060041#define TWL6040_RATES SNDRV_PCM_RATE_8000_96000
Margarita Olaya Cabrera1bf84752010-12-14 19:00:21 -060042#define TWL6040_FORMATS (SNDRV_PCM_FMTBIT_S32_LE)
43
44#define TWL6040_OUTHS_0dB 0x00
45#define TWL6040_OUTHS_M30dB 0x0F
46#define TWL6040_OUTHF_0dB 0x03
47#define TWL6040_OUTHF_M52dB 0x1D
48
Peter Ujfalusid17bf312011-09-22 11:05:48 +030049/* Shadow register used by the driver */
50#define TWL6040_REG_SW_SHADOW 0x2F
51#define TWL6040_CACHEREGNUM (TWL6040_REG_SW_SHADOW + 1)
52
Peter Ujfalusi317596a2011-09-22 11:05:49 +030053/* TWL6040_REG_SW_SHADOW (0x2F) fields */
54#define TWL6040_EAR_PATH_ENABLE 0x01
55
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -060056struct twl6040_jack_data {
57 struct snd_soc_jack *jack;
Peter Ujfalusi46dd0b92011-09-26 16:26:27 +030058 struct delayed_work work;
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -060059 int report;
60};
61
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +000062/* codec private data */
63struct twl6040_data {
Peter Ujfalusi2a433b92011-07-04 19:52:26 +030064 int plug_irq;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +000065 int codec_powered;
66 int pll;
Peter Ujfalusiaf958c72011-06-27 17:03:14 +030067 int pll_power_mode;
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -060068 int hs_power_mode;
69 int hs_power_mode_locked;
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -050070 unsigned int clk_in;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +000071 unsigned int sysclk;
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -060072 struct twl6040_jack_data hs_jack;
73 struct snd_soc_codec *codec;
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -060074 struct mutex mutex;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +000075};
76
77/*
78 * twl6040 register cache & default register settings
79 */
80static const u8 twl6040_reg[TWL6040_CACHEREGNUM] = {
Peter Ujfalusi4548dc32011-09-22 11:05:46 +030081 0x00, /* not used 0x00 */
82 0x4B, /* REG_ASICID 0x01 (ro) */
83 0x00, /* REG_ASICREV 0x02 (ro) */
84 0x00, /* REG_INTID 0x03 */
85 0x00, /* REG_INTMR 0x04 */
86 0x00, /* REG_NCPCTRL 0x05 */
87 0x00, /* REG_LDOCTL 0x06 */
88 0x60, /* REG_HPPLLCTL 0x07 */
89 0x00, /* REG_LPPLLCTL 0x08 */
90 0x4A, /* REG_LPPLLDIV 0x09 */
91 0x00, /* REG_AMICBCTL 0x0A */
92 0x00, /* REG_DMICBCTL 0x0B */
93 0x00, /* REG_MICLCTL 0x0C */
94 0x00, /* REG_MICRCTL 0x0D */
95 0x00, /* REG_MICGAIN 0x0E */
96 0x1B, /* REG_LINEGAIN 0x0F */
97 0x00, /* REG_HSLCTL 0x10 */
98 0x00, /* REG_HSRCTL 0x11 */
99 0x00, /* REG_HSGAIN 0x12 */
100 0x00, /* REG_EARCTL 0x13 */
101 0x00, /* REG_HFLCTL 0x14 */
102 0x00, /* REG_HFLGAIN 0x15 */
103 0x00, /* REG_HFRCTL 0x16 */
104 0x00, /* REG_HFRGAIN 0x17 */
105 0x00, /* REG_VIBCTLL 0x18 */
106 0x00, /* REG_VIBDATL 0x19 */
107 0x00, /* REG_VIBCTLR 0x1A */
108 0x00, /* REG_VIBDATR 0x1B */
109 0x00, /* REG_HKCTL1 0x1C */
110 0x00, /* REG_HKCTL2 0x1D */
111 0x00, /* REG_GPOCTL 0x1E */
112 0x00, /* REG_ALB 0x1F */
113 0x00, /* REG_DLB 0x20 */
114 0x00, /* not used 0x21 */
115 0x00, /* not used 0x22 */
116 0x00, /* not used 0x23 */
117 0x00, /* not used 0x24 */
118 0x00, /* not used 0x25 */
119 0x00, /* not used 0x26 */
120 0x00, /* not used 0x27 */
121 0x00, /* REG_TRIM1 0x28 */
122 0x00, /* REG_TRIM2 0x29 */
123 0x00, /* REG_TRIM3 0x2A */
124 0x00, /* REG_HSOTRIM 0x2B */
125 0x00, /* REG_HFOTRIM 0x2C */
126 0x09, /* REG_ACCCTL 0x2D */
127 0x00, /* REG_STATUS 0x2E (ro) */
Peter Ujfalusid17bf312011-09-22 11:05:48 +0300128
129 0x00, /* REG_SW_SHADOW 0x2F - Shadow, non HW register */
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000130};
131
Peter Ujfalusia52762e2011-09-15 15:39:27 +0300132/* List of registers to be restored after power up */
133static const int twl6040_restore_list[] = {
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000134 TWL6040_REG_MICLCTL,
135 TWL6040_REG_MICRCTL,
136 TWL6040_REG_MICGAIN,
137 TWL6040_REG_LINEGAIN,
138 TWL6040_REG_HSLCTL,
139 TWL6040_REG_HSRCTL,
140 TWL6040_REG_HSGAIN,
141 TWL6040_REG_EARCTL,
142 TWL6040_REG_HFLCTL,
143 TWL6040_REG_HFLGAIN,
144 TWL6040_REG_HFRCTL,
145 TWL6040_REG_HFRGAIN,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000146};
147
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300148/* set of rates for each pll: low-power and high-performance */
149static unsigned int lp_rates[] = {
150 8000,
151 11250,
152 16000,
153 22500,
154 32000,
155 44100,
156 48000,
157 88200,
158 96000,
159};
160
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300161static unsigned int hp_rates[] = {
162 8000,
163 16000,
164 32000,
165 48000,
166 96000,
167};
168
Peter Ujfalusif53c3462011-06-29 13:28:18 +0300169static struct snd_pcm_hw_constraint_list sysclk_constraints[] = {
170 { .count = ARRAY_SIZE(lp_rates), .list = lp_rates, },
171 { .count = ARRAY_SIZE(hp_rates), .list = hp_rates, },
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300172};
173
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000174/*
175 * read twl6040 register cache
176 */
177static inline unsigned int twl6040_read_reg_cache(struct snd_soc_codec *codec,
178 unsigned int reg)
179{
180 u8 *cache = codec->reg_cache;
181
182 if (reg >= TWL6040_CACHEREGNUM)
183 return -EIO;
184
185 return cache[reg];
186}
187
188/*
189 * write twl6040 register cache
190 */
191static inline void twl6040_write_reg_cache(struct snd_soc_codec *codec,
192 u8 reg, u8 value)
193{
194 u8 *cache = codec->reg_cache;
195
196 if (reg >= TWL6040_CACHEREGNUM)
197 return;
198 cache[reg] = value;
199}
200
201/*
202 * read from twl6040 hardware register
203 */
204static int twl6040_read_reg_volatile(struct snd_soc_codec *codec,
205 unsigned int reg)
206{
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500207 struct twl6040 *twl6040 = codec->control_data;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000208 u8 value;
209
210 if (reg >= TWL6040_CACHEREGNUM)
211 return -EIO;
212
Peter Ujfalusid17bf312011-09-22 11:05:48 +0300213 if (likely(reg < TWL6040_REG_SW_SHADOW)) {
214 value = twl6040_reg_read(twl6040, reg);
215 twl6040_write_reg_cache(codec, reg, value);
216 } else {
217 value = twl6040_read_reg_cache(codec, reg);
218 }
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000219
220 return value;
221}
222
223/*
224 * write to the twl6040 register space
225 */
226static int twl6040_write(struct snd_soc_codec *codec,
227 unsigned int reg, unsigned int value)
228{
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500229 struct twl6040 *twl6040 = codec->control_data;
230
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000231 if (reg >= TWL6040_CACHEREGNUM)
232 return -EIO;
233
234 twl6040_write_reg_cache(codec, reg, value);
Peter Ujfalusid17bf312011-09-22 11:05:48 +0300235 if (likely(reg < TWL6040_REG_SW_SHADOW))
236 return twl6040_reg_write(twl6040, reg, value);
237 else
238 return 0;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000239}
240
Peter Ujfalusia52762e2011-09-15 15:39:27 +0300241static void twl6040_init_chip(struct snd_soc_codec *codec)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000242{
Peter Ujfalusia52762e2011-09-15 15:39:27 +0300243 struct twl6040 *twl6040 = codec->control_data;
244 u8 val;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000245
Peter Ujfalusif97217f2011-09-26 16:05:56 +0300246 /* Update reg_cache: ASICREV, and TRIM values */
Peter Ujfalusia52762e2011-09-15 15:39:27 +0300247 val = twl6040_get_revid(twl6040);
248 twl6040_write_reg_cache(codec, TWL6040_REG_ASICREV, val);
249
Peter Ujfalusif97217f2011-09-26 16:05:56 +0300250 twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM1);
251 twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM2);
252 twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM3);
253 twl6040_read_reg_volatile(codec, TWL6040_REG_HSOTRIM);
254 twl6040_read_reg_volatile(codec, TWL6040_REG_HFOTRIM);
255
Peter Ujfalusi2c27ff42011-09-15 15:39:28 +0300256 /* Change chip defaults */
257 /* No imput selected for microphone amplifiers */
258 twl6040_write_reg_cache(codec, TWL6040_REG_MICLCTL, 0x18);
259 twl6040_write_reg_cache(codec, TWL6040_REG_MICRCTL, 0x18);
Peter Ujfalusi3acef682011-09-22 11:05:45 +0300260
261 /*
262 * We need to lower the default gain values, so the ramp code
263 * can work correctly for the first playback.
264 * This reduces the pop noise heard at the first playback.
265 */
266 twl6040_write_reg_cache(codec, TWL6040_REG_HSGAIN, 0xff);
267 twl6040_write_reg_cache(codec, TWL6040_REG_EARCTL, 0x1e);
268 twl6040_write_reg_cache(codec, TWL6040_REG_HFLGAIN, 0x1d);
269 twl6040_write_reg_cache(codec, TWL6040_REG_HFRGAIN, 0x1d);
270 twl6040_write_reg_cache(codec, TWL6040_REG_LINEGAIN, 0);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000271}
272
Peter Ujfalusia52762e2011-09-15 15:39:27 +0300273static void twl6040_restore_regs(struct snd_soc_codec *codec)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000274{
275 u8 *cache = codec->reg_cache;
276 int reg, i;
277
Peter Ujfalusia52762e2011-09-15 15:39:27 +0300278 for (i = 0; i < ARRAY_SIZE(twl6040_restore_list); i++) {
279 reg = twl6040_restore_list[i];
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000280 twl6040_write(codec, reg, cache[reg]);
281 }
282}
283
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000284/* set headset dac and driver power mode */
285static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
286{
287 int hslctl, hsrctl;
Peter Ujfalusiab6cf132011-09-22 11:05:54 +0300288 int mask = TWL6040_HSDRVMODE | TWL6040_HSDACMODE;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000289
290 hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL);
291 hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL);
292
293 if (high_perf) {
294 hslctl &= ~mask;
295 hsrctl &= ~mask;
296 } else {
297 hslctl |= mask;
298 hsrctl |= mask;
299 }
300
301 twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl);
302 twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl);
303
304 return 0;
305}
306
Jorge Eduardo Candelaria0fad4ed2010-07-15 11:38:01 -0500307static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w,
308 struct snd_kcontrol *kcontrol, int event)
309{
Peter Ujfalusi33b68162011-10-12 14:46:02 +0300310 struct snd_soc_codec *codec = w->codec;
311 u8 hslctl, hsrctl;
312
313 /*
314 * Workaround for Headset DC offset caused pop noise:
315 * Both HS DAC need to be turned on (before the HS driver) and off at
316 * the same time.
317 */
318 hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL);
319 hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL);
320 if (SND_SOC_DAPM_EVENT_ON(event)) {
321 hslctl |= TWL6040_HSDACENA;
322 hsrctl |= TWL6040_HSDACENA;
323 } else {
324 hslctl &= ~TWL6040_HSDACENA;
325 hsrctl &= ~TWL6040_HSDACENA;
326 }
327 twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl);
328 twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl);
329
Jorge Eduardo Candelaria0fad4ed2010-07-15 11:38:01 -0500330 msleep(1);
331 return 0;
332}
333
Peter Ujfalusi694b0002011-10-13 15:05:44 +0300334static int twl6040_ep_drv_event(struct snd_soc_dapm_widget *w,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000335 struct snd_kcontrol *kcontrol, int event)
336{
337 struct snd_soc_codec *codec = w->codec;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200338 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600339 int ret = 0;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000340
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600341 if (SND_SOC_DAPM_EVENT_ON(event)) {
Peter Ujfalusifac2f3e2011-10-13 15:05:42 +0300342 /* Earphone doesn't support low power mode */
343 priv->hs_power_mode_locked = 1;
344 ret = headset_power_mode(codec, 1);
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600345 } else {
Peter Ujfalusifac2f3e2011-10-13 15:05:42 +0300346 priv->hs_power_mode_locked = 0;
347 ret = headset_power_mode(codec, priv->hs_power_mode);
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600348 }
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000349
Jorge Eduardo Candelaria0fad4ed2010-07-15 11:38:01 -0500350 msleep(1);
351
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600352 return ret;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000353}
354
Mark Brown64ed9832011-01-20 21:43:44 +0000355static void twl6040_hs_jack_report(struct snd_soc_codec *codec,
356 struct snd_soc_jack *jack, int report)
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -0600357{
358 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
359 int status;
360
361 mutex_lock(&priv->mutex);
362
363 /* Sync status */
364 status = twl6040_read_reg_volatile(codec, TWL6040_REG_STATUS);
365 if (status & TWL6040_PLUGCOMP)
366 snd_soc_jack_report(jack, report, report);
367 else
368 snd_soc_jack_report(jack, 0, report);
369
370 mutex_unlock(&priv->mutex);
371}
372
373void twl6040_hs_jack_detect(struct snd_soc_codec *codec,
374 struct snd_soc_jack *jack, int report)
375{
376 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
377 struct twl6040_jack_data *hs_jack = &priv->hs_jack;
378
379 hs_jack->jack = jack;
380 hs_jack->report = report;
381
382 twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report);
383}
384EXPORT_SYMBOL_GPL(twl6040_hs_jack_detect);
385
386static void twl6040_accessory_work(struct work_struct *work)
387{
388 struct twl6040_data *priv = container_of(work,
Peter Ujfalusi46dd0b92011-09-26 16:26:27 +0300389 struct twl6040_data, hs_jack.work.work);
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -0600390 struct snd_soc_codec *codec = priv->codec;
391 struct twl6040_jack_data *hs_jack = &priv->hs_jack;
392
393 twl6040_hs_jack_report(codec, hs_jack->jack, hs_jack->report);
394}
395
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000396/* audio interrupt handler */
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500397static irqreturn_t twl6040_audio_handler(int irq, void *data)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000398{
399 struct snd_soc_codec *codec = data;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200400 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000401
Peter Ujfalusida2107d2013-01-11 17:01:02 +0100402 schedule_delayed_work(&priv->hs_jack.work, msecs_to_jiffies(200));
Olaya, Margaritacf370a52010-12-10 21:05:30 -0600403
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000404 return IRQ_HANDLED;
405}
406
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300407static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol,
408 struct snd_ctl_elem_value *ucontrol)
409{
410 struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
411 struct snd_soc_dapm_widget *widget = wlist->widgets[0];
412 struct snd_soc_codec *codec = widget->codec;
413 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
414 unsigned int val;
415
416 /* Do not allow changes while Input/FF efect is running */
417 val = twl6040_read_reg_volatile(codec, e->reg);
418 if (val & TWL6040_VIBENA && !(val & TWL6040_VIBSEL))
419 return -EBUSY;
420
421 return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
422}
423
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000424/*
425 * MICATT volume control:
426 * from -6 to 0 dB in 6 dB steps
427 */
428static DECLARE_TLV_DB_SCALE(mic_preamp_tlv, -600, 600, 0);
429
430/*
431 * MICGAIN volume control:
Ricardo Neri2763f452011-05-01 15:35:55 +0100432 * from 6 to 30 dB in 6 dB steps
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000433 */
Ricardo Neri2763f452011-05-01 15:35:55 +0100434static DECLARE_TLV_DB_SCALE(mic_amp_tlv, 600, 600, 0);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000435
436/*
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600437 * AFMGAIN volume control:
Liam Girdwood1f71a3b2011-03-28 19:23:23 +0100438 * from -18 to 24 dB in 6 dB steps
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600439 */
Liam Girdwood1f71a3b2011-03-28 19:23:23 +0100440static DECLARE_TLV_DB_SCALE(afm_amp_tlv, -1800, 600, 0);
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600441
442/*
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000443 * HSGAIN volume control:
444 * from -30 to 0 dB in 2 dB steps
445 */
446static DECLARE_TLV_DB_SCALE(hs_tlv, -3000, 200, 0);
447
448/*
449 * HFGAIN volume control:
450 * from -52 to 6 dB in 2 dB steps
451 */
452static DECLARE_TLV_DB_SCALE(hf_tlv, -5200, 200, 0);
453
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500454/*
455 * EPGAIN volume control:
456 * from -24 to 6 dB in 2 dB steps
457 */
458static DECLARE_TLV_DB_SCALE(ep_tlv, -2400, 200, 0);
459
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000460/* Left analog microphone selection */
461static const char *twl6040_amicl_texts[] =
462 {"Headset Mic", "Main Mic", "Aux/FM Left", "Off"};
463
464/* Right analog microphone selection */
465static const char *twl6040_amicr_texts[] =
466 {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"};
467
468static const struct soc_enum twl6040_enum[] = {
Francois Mazardcb973d72010-12-10 21:06:03 -0600469 SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3, 4, twl6040_amicl_texts),
470 SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3, 4, twl6040_amicr_texts),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000471};
472
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600473static const char *twl6040_hs_texts[] = {
474 "Off", "HS DAC", "Line-In amp"
475};
476
477static const struct soc_enum twl6040_hs_enum[] = {
478 SOC_ENUM_SINGLE(TWL6040_REG_HSLCTL, 5, ARRAY_SIZE(twl6040_hs_texts),
479 twl6040_hs_texts),
480 SOC_ENUM_SINGLE(TWL6040_REG_HSRCTL, 5, ARRAY_SIZE(twl6040_hs_texts),
481 twl6040_hs_texts),
482};
483
484static const char *twl6040_hf_texts[] = {
485 "Off", "HF DAC", "Line-In amp"
486};
487
488static const struct soc_enum twl6040_hf_enum[] = {
489 SOC_ENUM_SINGLE(TWL6040_REG_HFLCTL, 2, ARRAY_SIZE(twl6040_hf_texts),
490 twl6040_hf_texts),
491 SOC_ENUM_SINGLE(TWL6040_REG_HFRCTL, 2, ARRAY_SIZE(twl6040_hf_texts),
492 twl6040_hf_texts),
493};
494
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300495static const char *twl6040_vibrapath_texts[] = {
496 "Input FF", "Audio PDM"
497};
498
499static const struct soc_enum twl6040_vibra_enum[] = {
500 SOC_ENUM_SINGLE(TWL6040_REG_VIBCTLL, 1,
501 ARRAY_SIZE(twl6040_vibrapath_texts),
502 twl6040_vibrapath_texts),
503 SOC_ENUM_SINGLE(TWL6040_REG_VIBCTLR, 1,
504 ARRAY_SIZE(twl6040_vibrapath_texts),
505 twl6040_vibrapath_texts),
506};
507
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000508static const struct snd_kcontrol_new amicl_control =
509 SOC_DAPM_ENUM("Route", twl6040_enum[0]);
510
511static const struct snd_kcontrol_new amicr_control =
512 SOC_DAPM_ENUM("Route", twl6040_enum[1]);
513
514/* Headset DAC playback switches */
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600515static const struct snd_kcontrol_new hsl_mux_controls =
516 SOC_DAPM_ENUM("Route", twl6040_hs_enum[0]);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000517
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600518static const struct snd_kcontrol_new hsr_mux_controls =
519 SOC_DAPM_ENUM("Route", twl6040_hs_enum[1]);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000520
521/* Handsfree DAC playback switches */
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600522static const struct snd_kcontrol_new hfl_mux_controls =
523 SOC_DAPM_ENUM("Route", twl6040_hf_enum[0]);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000524
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600525static const struct snd_kcontrol_new hfr_mux_controls =
526 SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000527
Peter Ujfalusi317596a2011-09-22 11:05:49 +0300528static const struct snd_kcontrol_new ep_path_enable_control =
529 SOC_DAPM_SINGLE("Switch", TWL6040_REG_SW_SHADOW, 0, 1, 0);
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500530
Peter Ujfalusifdb625f2011-09-22 11:05:52 +0300531static const struct snd_kcontrol_new auxl_switch_control =
532 SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 6, 1, 0);
533
534static const struct snd_kcontrol_new auxr_switch_control =
535 SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFRCTL, 6, 1, 0);
536
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300537/* Vibra playback switches */
538static const struct snd_kcontrol_new vibral_mux_controls =
539 SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[0],
540 snd_soc_dapm_get_enum_double,
541 twl6040_soc_dapm_put_vibra_enum);
542
543static const struct snd_kcontrol_new vibrar_mux_controls =
544 SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[1],
545 snd_soc_dapm_get_enum_double,
546 twl6040_soc_dapm_put_vibra_enum);
547
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600548/* Headset power mode */
Peter Ujfalusi7cca6062011-06-27 13:33:14 +0300549static const char *twl6040_power_mode_texts[] = {
Simon Wilson3e453652012-07-06 17:04:17 +0100550 "Low-Power", "High-Performance",
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600551};
552
Peter Ujfalusi7cca6062011-06-27 13:33:14 +0300553static const struct soc_enum twl6040_power_mode_enum =
554 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(twl6040_power_mode_texts),
555 twl6040_power_mode_texts);
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600556
557static int twl6040_headset_power_get_enum(struct snd_kcontrol *kcontrol,
558 struct snd_ctl_elem_value *ucontrol)
559{
560 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
561 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
562
563 ucontrol->value.enumerated.item[0] = priv->hs_power_mode;
564
565 return 0;
566}
567
568static int twl6040_headset_power_put_enum(struct snd_kcontrol *kcontrol,
569 struct snd_ctl_elem_value *ucontrol)
570{
571 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
572 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
573 int high_perf = ucontrol->value.enumerated.item[0];
574 int ret = 0;
575
576 if (!priv->hs_power_mode_locked)
577 ret = headset_power_mode(codec, high_perf);
578
579 if (!ret)
580 priv->hs_power_mode = high_perf;
581
582 return ret;
583}
584
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300585static int twl6040_pll_get_enum(struct snd_kcontrol *kcontrol,
586 struct snd_ctl_elem_value *ucontrol)
587{
588 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
589 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
590
591 ucontrol->value.enumerated.item[0] = priv->pll_power_mode;
592
593 return 0;
594}
595
596static int twl6040_pll_put_enum(struct snd_kcontrol *kcontrol,
597 struct snd_ctl_elem_value *ucontrol)
598{
599 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
600 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
601
602 priv->pll_power_mode = ucontrol->value.enumerated.item[0];
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300603
604 return 0;
605}
606
Liam Girdwoode48b46b2012-01-11 12:43:24 +0000607int twl6040_get_dl1_gain(struct snd_soc_codec *codec)
608{
609 struct snd_soc_dapm_context *dapm = &codec->dapm;
610
611 if (snd_soc_dapm_get_pin_status(dapm, "EP"))
612 return -1; /* -1dB */
613
614 if (snd_soc_dapm_get_pin_status(dapm, "HSOR") ||
615 snd_soc_dapm_get_pin_status(dapm, "HSOL")) {
616
617 u8 val = snd_soc_read(codec, TWL6040_REG_HSLCTL);
618 if (val & TWL6040_HSDACMODE)
619 /* HSDACL in LP mode */
620 return -8; /* -8dB */
621 else
622 /* HSDACL in HP mode */
623 return -1; /* -1dB */
624 }
625 return 0; /* 0dB */
626}
627EXPORT_SYMBOL_GPL(twl6040_get_dl1_gain);
628
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300629int twl6040_get_clk_id(struct snd_soc_codec *codec)
630{
631 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
632
Peter Ujfalusiff593ca2011-07-04 10:35:23 +0300633 return priv->pll_power_mode;
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300634}
635EXPORT_SYMBOL_GPL(twl6040_get_clk_id);
636
Peter Ujfalusidb4aabc2011-09-26 16:05:57 +0300637int twl6040_get_trim_value(struct snd_soc_codec *codec, enum twl6040_trim trim)
638{
639 if (unlikely(trim >= TWL6040_TRIM_INVAL))
640 return -EINVAL;
641
642 return twl6040_read_reg_cache(codec, TWL6040_REG_TRIM1 + trim);
643}
644EXPORT_SYMBOL_GPL(twl6040_get_trim_value);
645
Liam Girdwood08656912012-01-09 12:10:16 +0000646int twl6040_get_hs_step_size(struct snd_soc_codec *codec)
647{
648 struct twl6040 *twl6040 = codec->control_data;
649
Peter Ujfalusibe4ac002012-07-16 11:49:43 +0200650 if (twl6040_get_revid(twl6040) < TWL6040_REV_ES1_3)
Liam Girdwood08656912012-01-09 12:10:16 +0000651 /* For ES under ES_1.3 HS step is 2 mV */
652 return 2;
653 else
654 /* For ES_1.3 HS step is 1 mV */
655 return 1;
656}
657EXPORT_SYMBOL_GPL(twl6040_get_hs_step_size);
658
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000659static const struct snd_kcontrol_new twl6040_snd_controls[] = {
660 /* Capture gains */
661 SOC_DOUBLE_TLV("Capture Preamplifier Volume",
662 TWL6040_REG_MICGAIN, 6, 7, 1, 1, mic_preamp_tlv),
663 SOC_DOUBLE_TLV("Capture Volume",
664 TWL6040_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv),
665
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600666 /* AFM gains */
667 SOC_DOUBLE_TLV("Aux FM Volume",
Liam Girdwood1f71a3b2011-03-28 19:23:23 +0100668 TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv),
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600669
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000670 /* Playback gains */
Peter Ujfalusi3bb8a812012-05-04 15:17:20 +0300671 SOC_DOUBLE_TLV("Headset Playback Volume",
672 TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv),
673 SOC_DOUBLE_R_TLV("Handsfree Playback Volume",
674 TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv),
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500675 SOC_SINGLE_TLV("Earphone Playback Volume",
676 TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv),
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600677
Peter Ujfalusi7cca6062011-06-27 13:33:14 +0300678 SOC_ENUM_EXT("Headset Power Mode", twl6040_power_mode_enum,
Misael Lopez Cruz6bba63b2011-02-11 17:51:05 -0600679 twl6040_headset_power_get_enum,
680 twl6040_headset_power_put_enum),
Peter Ujfalusiaf958c72011-06-27 17:03:14 +0300681
682 SOC_ENUM_EXT("PLL Selection", twl6040_power_mode_enum,
683 twl6040_pll_get_enum, twl6040_pll_put_enum),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000684};
685
686static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
687 /* Inputs */
688 SND_SOC_DAPM_INPUT("MAINMIC"),
689 SND_SOC_DAPM_INPUT("HSMIC"),
690 SND_SOC_DAPM_INPUT("SUBMIC"),
691 SND_SOC_DAPM_INPUT("AFML"),
692 SND_SOC_DAPM_INPUT("AFMR"),
693
694 /* Outputs */
695 SND_SOC_DAPM_OUTPUT("HSOL"),
696 SND_SOC_DAPM_OUTPUT("HSOR"),
697 SND_SOC_DAPM_OUTPUT("HFL"),
698 SND_SOC_DAPM_OUTPUT("HFR"),
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500699 SND_SOC_DAPM_OUTPUT("EP"),
Peter Ujfalusifdb625f2011-09-22 11:05:52 +0300700 SND_SOC_DAPM_OUTPUT("AUXL"),
701 SND_SOC_DAPM_OUTPUT("AUXR"),
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300702 SND_SOC_DAPM_OUTPUT("VIBRAL"),
703 SND_SOC_DAPM_OUTPUT("VIBRAR"),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000704
705 /* Analog input muxes for the capture amplifiers */
706 SND_SOC_DAPM_MUX("Analog Left Capture Route",
707 SND_SOC_NOPM, 0, 0, &amicl_control),
708 SND_SOC_DAPM_MUX("Analog Right Capture Route",
709 SND_SOC_NOPM, 0, 0, &amicr_control),
710
711 /* Analog capture PGAs */
712 SND_SOC_DAPM_PGA("MicAmpL",
713 TWL6040_REG_MICLCTL, 0, 0, NULL, 0),
714 SND_SOC_DAPM_PGA("MicAmpR",
715 TWL6040_REG_MICRCTL, 0, 0, NULL, 0),
716
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600717 /* Auxiliary FM PGAs */
718 SND_SOC_DAPM_PGA("AFMAmpL",
719 TWL6040_REG_MICLCTL, 1, 0, NULL, 0),
720 SND_SOC_DAPM_PGA("AFMAmpR",
721 TWL6040_REG_MICRCTL, 1, 0, NULL, 0),
722
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000723 /* ADCs */
Peter Ujfalusi805238b2012-09-20 16:32:15 +0300724 SND_SOC_DAPM_ADC("ADC Left", NULL, TWL6040_REG_MICLCTL, 2, 0),
725 SND_SOC_DAPM_ADC("ADC Right", NULL, TWL6040_REG_MICRCTL, 2, 0),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000726
727 /* Microphone bias */
Peter Ujfalusi778cee72011-12-22 12:47:21 +0200728 SND_SOC_DAPM_SUPPLY("Headset Mic Bias",
729 TWL6040_REG_AMICBCTL, 0, 0, NULL, 0),
730 SND_SOC_DAPM_SUPPLY("Main Mic Bias",
731 TWL6040_REG_AMICBCTL, 4, 0, NULL, 0),
732 SND_SOC_DAPM_SUPPLY("Digital Mic1 Bias",
733 TWL6040_REG_DMICBCTL, 0, 0, NULL, 0),
734 SND_SOC_DAPM_SUPPLY("Digital Mic2 Bias",
735 TWL6040_REG_DMICBCTL, 4, 0, NULL, 0),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000736
737 /* DACs */
Peter Ujfalusi805238b2012-09-20 16:32:15 +0300738 SND_SOC_DAPM_DAC("HSDAC Left", NULL, SND_SOC_NOPM, 0, 0),
739 SND_SOC_DAPM_DAC("HSDAC Right", NULL, SND_SOC_NOPM, 0, 0),
740 SND_SOC_DAPM_DAC("HFDAC Left", NULL, TWL6040_REG_HFLCTL, 0, 0),
741 SND_SOC_DAPM_DAC("HFDAC Right", NULL, TWL6040_REG_HFRCTL, 0, 0),
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300742 /* Virtual DAC for vibra path (DL4 channel) */
Peter Ujfalusi805238b2012-09-20 16:32:15 +0300743 SND_SOC_DAPM_DAC("VIBRA DAC", NULL, SND_SOC_NOPM, 0, 0),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000744
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300745 SND_SOC_DAPM_MUX("Handsfree Left Playback",
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600746 SND_SOC_NOPM, 0, 0, &hfl_mux_controls),
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300747 SND_SOC_DAPM_MUX("Handsfree Right Playback",
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600748 SND_SOC_NOPM, 0, 0, &hfr_mux_controls),
749 /* Analog playback Muxes */
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300750 SND_SOC_DAPM_MUX("Headset Left Playback",
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600751 SND_SOC_NOPM, 0, 0, &hsl_mux_controls),
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300752 SND_SOC_DAPM_MUX("Headset Right Playback",
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600753 SND_SOC_NOPM, 0, 0, &hsr_mux_controls),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000754
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300755 SND_SOC_DAPM_MUX("Vibra Left Playback", SND_SOC_NOPM, 0, 0,
756 &vibral_mux_controls),
757 SND_SOC_DAPM_MUX("Vibra Right Playback", SND_SOC_NOPM, 0, 0,
758 &vibrar_mux_controls),
759
Peter Ujfalusi317596a2011-09-22 11:05:49 +0300760 SND_SOC_DAPM_SWITCH("Earphone Playback", SND_SOC_NOPM, 0, 0,
761 &ep_path_enable_control),
Peter Ujfalusifdb625f2011-09-22 11:05:52 +0300762 SND_SOC_DAPM_SWITCH("AUXL Playback", SND_SOC_NOPM, 0, 0,
763 &auxl_switch_control),
764 SND_SOC_DAPM_SWITCH("AUXR Playback", SND_SOC_NOPM, 0, 0,
765 &auxr_switch_control),
Peter Ujfalusi317596a2011-09-22 11:05:49 +0300766
Jorge Eduardo Candelaria0fad4ed2010-07-15 11:38:01 -0500767 /* Analog playback drivers */
Peter Ujfalusi3bb8a812012-05-04 15:17:20 +0300768 SND_SOC_DAPM_OUT_DRV("HF Left Driver",
769 TWL6040_REG_HFLCTL, 4, 0, NULL, 0),
770 SND_SOC_DAPM_OUT_DRV("HF Right Driver",
771 TWL6040_REG_HFRCTL, 4, 0, NULL, 0),
772 SND_SOC_DAPM_OUT_DRV("HS Left Driver",
773 TWL6040_REG_HSLCTL, 2, 0, NULL, 0),
774 SND_SOC_DAPM_OUT_DRV("HS Right Driver",
775 TWL6040_REG_HSRCTL, 2, 0, NULL, 0),
Peter Ujfalusi317596a2011-09-22 11:05:49 +0300776 SND_SOC_DAPM_OUT_DRV_E("Earphone Driver",
777 TWL6040_REG_EARCTL, 0, 0, NULL, 0,
Peter Ujfalusi694b0002011-10-13 15:05:44 +0300778 twl6040_ep_drv_event,
Peter Ujfalusiaa1a4102011-10-13 15:05:43 +0300779 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300780 SND_SOC_DAPM_OUT_DRV("Vibra Left Driver",
781 TWL6040_REG_VIBCTLL, 0, 0, NULL, 0),
782 SND_SOC_DAPM_OUT_DRV("Vibra Right Driver",
783 TWL6040_REG_VIBCTLR, 0, 0, NULL, 0),
784
785 SND_SOC_DAPM_SUPPLY("Vibra Left Control", TWL6040_REG_VIBCTLL, 2, 0,
786 NULL, 0),
787 SND_SOC_DAPM_SUPPLY("Vibra Right Control", TWL6040_REG_VIBCTLR, 2, 0,
788 NULL, 0),
Peter Ujfalusi33b68162011-10-12 14:46:02 +0300789 SND_SOC_DAPM_SUPPLY_S("HSDAC Power", 1, SND_SOC_NOPM, 0, 0,
790 twl6040_hs_dac_event,
791 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000792
793 /* Analog playback PGAs */
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300794 SND_SOC_DAPM_PGA("HF Left PGA",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000795 TWL6040_REG_HFLCTL, 1, 0, NULL, 0),
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300796 SND_SOC_DAPM_PGA("HF Right PGA",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000797 TWL6040_REG_HFRCTL, 1, 0, NULL, 0),
798
799};
800
801static const struct snd_soc_dapm_route intercon[] = {
Peter Ujfalusi805238b2012-09-20 16:32:15 +0300802 /* Stream -> DAC mapping */
803 {"HSDAC Left", NULL, "Legacy Playback"},
804 {"HSDAC Left", NULL, "Headset Playback"},
805 {"HSDAC Right", NULL, "Legacy Playback"},
806 {"HSDAC Right", NULL, "Headset Playback"},
807
808 {"HFDAC Left", NULL, "Legacy Playback"},
809 {"HFDAC Left", NULL, "Handsfree Playback"},
810 {"HFDAC Right", NULL, "Legacy Playback"},
811 {"HFDAC Right", NULL, "Handsfree Playback"},
812
813 {"VIBRA DAC", NULL, "Legacy Playback"},
814 {"VIBRA DAC", NULL, "Vibra Playback"},
815
816 /* ADC -> Stream mapping */
Peter Ujfalusi07ac2292012-10-04 14:15:02 +0300817 {"Legacy Capture" , NULL, "ADC Left"},
818 {"Capture", NULL, "ADC Left"},
819 {"Legacy Capture", NULL, "ADC Right"},
820 {"Capture" , NULL, "ADC Right"},
Peter Ujfalusi805238b2012-09-20 16:32:15 +0300821
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000822 /* Capture path */
823 {"Analog Left Capture Route", "Headset Mic", "HSMIC"},
824 {"Analog Left Capture Route", "Main Mic", "MAINMIC"},
825 {"Analog Left Capture Route", "Aux/FM Left", "AFML"},
826
827 {"Analog Right Capture Route", "Headset Mic", "HSMIC"},
828 {"Analog Right Capture Route", "Sub Mic", "SUBMIC"},
829 {"Analog Right Capture Route", "Aux/FM Right", "AFMR"},
830
831 {"MicAmpL", NULL, "Analog Left Capture Route"},
832 {"MicAmpR", NULL, "Analog Right Capture Route"},
833
834 {"ADC Left", NULL, "MicAmpL"},
835 {"ADC Right", NULL, "MicAmpR"},
836
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600837 /* AFM path */
Peter Ujfalusi5bf692d2011-09-22 11:05:47 +0300838 {"AFMAmpL", NULL, "AFML"},
839 {"AFMAmpR", NULL, "AFMR"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000840
Peter Ujfalusi33b68162011-10-12 14:46:02 +0300841 {"HSDAC Left", NULL, "HSDAC Power"},
842 {"HSDAC Right", NULL, "HSDAC Power"},
843
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300844 {"Headset Left Playback", "HS DAC", "HSDAC Left"},
845 {"Headset Left Playback", "Line-In amp", "AFMAmpL"},
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600846
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300847 {"Headset Right Playback", "HS DAC", "HSDAC Right"},
848 {"Headset Right Playback", "Line-In amp", "AFMAmpR"},
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600849
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300850 {"HS Left Driver", NULL, "Headset Left Playback"},
851 {"HS Right Driver", NULL, "Headset Right Playback"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000852
Peter Ujfalusi45b0f602011-09-22 11:05:51 +0300853 {"HSOL", NULL, "HS Left Driver"},
854 {"HSOR", NULL, "HS Right Driver"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000855
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500856 /* Earphone playback path */
Peter Ujfalusi317596a2011-09-22 11:05:49 +0300857 {"Earphone Playback", "Switch", "HSDAC Left"},
858 {"Earphone Driver", NULL, "Earphone Playback"},
Jorge Eduardo Candelaria871a05a2010-05-18 12:44:18 -0500859 {"EP", NULL, "Earphone Driver"},
860
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300861 {"Handsfree Left Playback", "HF DAC", "HFDAC Left"},
862 {"Handsfree Left Playback", "Line-In amp", "AFMAmpL"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000863
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300864 {"Handsfree Right Playback", "HF DAC", "HFDAC Right"},
865 {"Handsfree Right Playback", "Line-In amp", "AFMAmpR"},
Jorge Eduardo Candelaria370a0312010-12-10 21:05:32 -0600866
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300867 {"HF Left PGA", NULL, "Handsfree Left Playback"},
868 {"HF Right PGA", NULL, "Handsfree Right Playback"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000869
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300870 {"HF Left Driver", NULL, "HF Left PGA"},
871 {"HF Right Driver", NULL, "HF Right PGA"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000872
Peter Ujfalusidf11ce22011-09-22 11:05:50 +0300873 {"HFL", NULL, "HF Left Driver"},
874 {"HFR", NULL, "HF Right Driver"},
Peter Ujfalusifdb625f2011-09-22 11:05:52 +0300875
876 {"AUXL Playback", "Switch", "HF Left PGA"},
877 {"AUXR Playback", "Switch", "HF Right PGA"},
878
879 {"AUXL", NULL, "AUXL Playback"},
880 {"AUXR", NULL, "AUXR Playback"},
Peter Ujfalusi67c34132011-10-12 11:57:57 +0300881
882 /* Vibrator paths */
883 {"Vibra Left Playback", "Audio PDM", "VIBRA DAC"},
884 {"Vibra Right Playback", "Audio PDM", "VIBRA DAC"},
885
886 {"Vibra Left Driver", NULL, "Vibra Left Playback"},
887 {"Vibra Right Driver", NULL, "Vibra Right Playback"},
888 {"Vibra Left Driver", NULL, "Vibra Left Control"},
889 {"Vibra Right Driver", NULL, "Vibra Right Control"},
890
891 {"VIBRAL", NULL, "Vibra Left Driver"},
892 {"VIBRAR", NULL, "Vibra Right Driver"},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000893};
894
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000895static int twl6040_set_bias_level(struct snd_soc_codec *codec,
896 enum snd_soc_bias_level level)
897{
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500898 struct twl6040 *twl6040 = codec->control_data;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200899 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000900 int ret;
901
902 switch (level) {
903 case SND_SOC_BIAS_ON:
904 break;
905 case SND_SOC_BIAS_PREPARE:
906 break;
907 case SND_SOC_BIAS_STANDBY:
908 if (priv->codec_powered)
909 break;
910
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500911 ret = twl6040_power(twl6040, 1);
912 if (ret)
913 return ret;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000914
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500915 priv->codec_powered = 1;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000916
Peter Ujfalusia52762e2011-09-15 15:39:27 +0300917 twl6040_restore_regs(codec);
Olaya, Margarita65b7cec2010-12-14 19:18:36 -0600918
919 /* Set external boost GPO */
920 twl6040_write(codec, TWL6040_REG_GPOCTL, 0x02);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000921 break;
922 case SND_SOC_BIAS_OFF:
923 if (!priv->codec_powered)
924 break;
925
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -0500926 twl6040_power(twl6040, 0);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000927 priv->codec_powered = 0;
928 break;
929 }
930
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200931 codec->dapm.bias_level = level;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000932
933 return 0;
934}
935
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000936static int twl6040_startup(struct snd_pcm_substream *substream,
937 struct snd_soc_dai *dai)
938{
Mark Browne6968a12012-04-04 15:58:16 +0100939 struct snd_soc_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
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000942 snd_pcm_hw_constraint_list(substream->runtime, 0,
943 SNDRV_PCM_HW_PARAM_RATE,
Peter Ujfalusif53c3462011-06-29 13:28:18 +0300944 &sysclk_constraints[priv->pll_power_mode]);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000945
946 return 0;
947}
948
949static int twl6040_hw_params(struct snd_pcm_substream *substream,
950 struct snd_pcm_hw_params *params,
951 struct snd_soc_dai *dai)
952{
Mark Browne6968a12012-04-04 15:58:16 +0100953 struct snd_soc_codec *codec = dai->codec;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200954 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000955 int rate;
956
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000957 rate = params_rate(params);
958 switch (rate) {
Olaya, Margarita60ea4ce2010-12-10 21:05:58 -0600959 case 11250:
960 case 22500:
961 case 44100:
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000962 case 88200:
Peter Ujfalusi753621c2011-07-03 02:06:07 +0300963 /* These rates are not supported when HPPLL is in use */
964 if (unlikely(priv->pll == TWL6040_SYSCLK_SEL_HPPLL)) {
965 dev_err(codec->dev, "HPPLL does not support rate %d\n",
966 rate);
967 return -EINVAL;
968 }
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000969 priv->sysclk = 17640000;
970 break;
Olaya, Margarita60ea4ce2010-12-10 21:05:58 -0600971 case 8000:
972 case 16000:
973 case 32000:
974 case 48000:
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000975 case 96000:
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000976 priv->sysclk = 19200000;
977 break;
978 default:
979 dev_err(codec->dev, "unsupported rate %d\n", rate);
980 return -EINVAL;
981 }
982
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000983 return 0;
984}
985
Olaya, Margarita4e624d02010-12-10 21:05:54 -0600986static int twl6040_prepare(struct snd_pcm_substream *substream,
987 struct snd_soc_dai *dai)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000988{
Mark Browne6968a12012-04-04 15:58:16 +0100989 struct snd_soc_codec *codec = dai->codec;
Peter Ujfalusi753621c2011-07-03 02:06:07 +0300990 struct twl6040 *twl6040 = codec->control_data;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +0200991 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusi753621c2011-07-03 02:06:07 +0300992 int ret;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +0000993
Olaya, Margarita4e624d02010-12-10 21:05:54 -0600994 if (!priv->sysclk) {
995 dev_err(codec->dev,
996 "no mclk configured, call set_sysclk() on init\n");
997 return -EINVAL;
998 }
999
Peter Ujfalusi753621c2011-07-03 02:06:07 +03001000 ret = twl6040_set_pll(twl6040, priv->pll, priv->clk_in, priv->sysclk);
1001 if (ret) {
1002 dev_err(codec->dev, "Can not set PLL (%d)\n", ret);
1003 return -EPERM;
1004 }
1005
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001006 return 0;
1007}
1008
1009static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1010 int clk_id, unsigned int freq, int dir)
1011{
1012 struct snd_soc_codec *codec = codec_dai->codec;
Takashi Iwaid4a8ca22010-04-20 08:20:31 +02001013 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001014
1015 switch (clk_id) {
1016 case TWL6040_SYSCLK_SEL_LPPLL:
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001017 case TWL6040_SYSCLK_SEL_HPPLL:
Peter Ujfalusi753621c2011-07-03 02:06:07 +03001018 priv->pll = clk_id;
1019 priv->clk_in = freq;
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001020 break;
1021 default:
1022 dev_err(codec->dev, "unknown clk_id %d\n", clk_id);
1023 return -EINVAL;
1024 }
1025
1026 return 0;
1027}
1028
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001029static const struct snd_soc_dai_ops twl6040_dai_ops = {
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001030 .startup = twl6040_startup,
1031 .hw_params = twl6040_hw_params,
Olaya, Margarita4e624d02010-12-10 21:05:54 -06001032 .prepare = twl6040_prepare,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001033 .set_sysclk = twl6040_set_dai_sysclk,
1034};
1035
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001036static struct snd_soc_dai_driver twl6040_dai[] = {
1037{
Peter Ujfalusid13f1fe2011-09-22 11:05:53 +03001038 .name = "twl6040-legacy",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001039 .playback = {
Peter Ujfalusi805238b2012-09-20 16:32:15 +03001040 .stream_name = "Legacy Playback",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001041 .channels_min = 1,
Peter Ujfalusicdd50542011-09-15 15:59:19 +03001042 .channels_max = 5,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001043 .rates = TWL6040_RATES,
1044 .formats = TWL6040_FORMATS,
1045 },
1046 .capture = {
Peter Ujfalusi805238b2012-09-20 16:32:15 +03001047 .stream_name = "Legacy Capture",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001048 .channels_min = 1,
1049 .channels_max = 2,
1050 .rates = TWL6040_RATES,
1051 .formats = TWL6040_FORMATS,
1052 },
1053 .ops = &twl6040_dai_ops,
Peter Ujfalusi21385ee2011-07-05 22:35:53 +03001054},
1055{
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001056 .name = "twl6040-ul",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001057 .capture = {
1058 .stream_name = "Capture",
1059 .channels_min = 1,
1060 .channels_max = 2,
1061 .rates = TWL6040_RATES,
1062 .formats = TWL6040_FORMATS,
1063 },
1064 .ops = &twl6040_dai_ops,
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001065},
1066{
1067 .name = "twl6040-dl1",
1068 .playback = {
1069 .stream_name = "Headset Playback",
1070 .channels_min = 1,
1071 .channels_max = 2,
1072 .rates = TWL6040_RATES,
1073 .formats = TWL6040_FORMATS,
1074 },
1075 .ops = &twl6040_dai_ops,
1076},
1077{
1078 .name = "twl6040-dl2",
1079 .playback = {
1080 .stream_name = "Handsfree Playback",
1081 .channels_min = 1,
1082 .channels_max = 2,
1083 .rates = TWL6040_RATES,
1084 .formats = TWL6040_FORMATS,
1085 },
1086 .ops = &twl6040_dai_ops,
1087},
1088{
1089 .name = "twl6040-vib",
1090 .playback = {
1091 .stream_name = "Vibra Playback",
Peter Ujfalusid8dd0322011-09-15 15:59:18 +03001092 .channels_min = 1,
1093 .channels_max = 1,
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001094 .rates = SNDRV_PCM_RATE_CONTINUOUS,
1095 .formats = TWL6040_FORMATS,
1096 },
1097 .ops = &twl6040_dai_ops,
1098},
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001099};
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001100
1101#ifdef CONFIG_PM
Lars-Peter Clausen84b315e2011-12-02 10:18:28 +01001102static int twl6040_suspend(struct snd_soc_codec *codec)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001103{
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001104 twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
1105
1106 return 0;
1107}
1108
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001109static int twl6040_resume(struct snd_soc_codec *codec)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001110{
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001111 twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001112
1113 return 0;
1114}
1115#else
1116#define twl6040_suspend NULL
1117#define twl6040_resume NULL
1118#endif
1119
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001120static int twl6040_probe(struct snd_soc_codec *codec)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001121{
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001122 struct twl6040_data *priv;
Peter Ujfalusi2a433b92011-07-04 19:52:26 +03001123 struct platform_device *pdev = container_of(codec->dev,
1124 struct platform_device, dev);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001125 int ret = 0;
1126
Peter Ujfalusi9523fcd2013-01-11 17:01:01 +01001127 priv = devm_kzalloc(codec->dev, sizeof(*priv), GFP_KERNEL);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001128 if (priv == NULL)
1129 return -ENOMEM;
Peter Ujfalusi9523fcd2013-01-11 17:01:01 +01001130
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001131 snd_soc_codec_set_drvdata(codec, priv);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001132
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -06001133 priv->codec = codec;
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -05001134 codec->control_data = dev_get_drvdata(codec->dev->parent);
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -06001135
Peter Ujfalusi2a433b92011-07-04 19:52:26 +03001136 priv->plug_irq = platform_get_irq(pdev, 0);
1137 if (priv->plug_irq < 0) {
1138 dev_err(codec->dev, "invalid irq\n");
Peter Ujfalusi9523fcd2013-01-11 17:01:01 +01001139 return -EINVAL;
Peter Ujfalusi2a433b92011-07-04 19:52:26 +03001140 }
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001141
Peter Ujfalusi46dd0b92011-09-26 16:26:27 +03001142 INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work);
Jorge Eduardo Candelariaa2d23622010-12-10 20:45:17 -06001143
1144 mutex_init(&priv->mutex);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001145
Peter Ujfalusi9523fcd2013-01-11 17:01:01 +01001146 ret = devm_request_threaded_irq(codec->dev, priv->plug_irq, NULL,
1147 twl6040_audio_handler, IRQF_NO_SUSPEND,
1148 "twl6040_irq_plug", codec);
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -05001149 if (ret) {
1150 dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret);
Peter Ujfalusida2107d2013-01-11 17:01:02 +01001151 return ret;
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -05001152 }
1153
Peter Ujfalusia52762e2011-09-15 15:39:27 +03001154 twl6040_init_chip(codec);
Misael Lopez Cruzfb34d3d2011-05-01 21:27:00 -05001155
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001156 /* power on device */
Peter Ujfalusida2107d2013-01-11 17:01:02 +01001157 return twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001158}
1159
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001160static int twl6040_remove(struct snd_soc_codec *codec)
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001161{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001162 twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001163
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001164 return 0;
1165}
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001166
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001167static struct snd_soc_codec_driver soc_codec_dev_twl6040 = {
1168 .probe = twl6040_probe,
1169 .remove = twl6040_remove,
1170 .suspend = twl6040_suspend,
1171 .resume = twl6040_resume,
1172 .read = twl6040_read_reg_cache,
1173 .write = twl6040_write,
1174 .set_bias_level = twl6040_set_bias_level,
1175 .reg_cache_size = ARRAY_SIZE(twl6040_reg),
1176 .reg_word_size = sizeof(u8),
1177 .reg_cache_default = twl6040_reg,
Mark Browna5d3a212012-02-08 18:34:19 +00001178 .ignore_pmdown_time = true,
Peter Ujfalusia175fce2011-10-11 13:11:12 +03001179
1180 .controls = twl6040_snd_controls,
1181 .num_controls = ARRAY_SIZE(twl6040_snd_controls),
1182 .dapm_widgets = twl6040_dapm_widgets,
1183 .num_dapm_widgets = ARRAY_SIZE(twl6040_dapm_widgets),
1184 .dapm_routes = intercon,
1185 .num_dapm_routes = ARRAY_SIZE(intercon),
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001186};
1187
Bill Pemberton7a79e942012-12-07 09:26:37 -05001188static int twl6040_codec_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001189{
Liam Girdwood6510bdc2011-02-11 17:37:51 +00001190 return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_twl6040,
1191 twl6040_dai, ARRAY_SIZE(twl6040_dai));
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001192}
1193
Bill Pemberton7a79e942012-12-07 09:26:37 -05001194static int twl6040_codec_remove(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001195{
1196 snd_soc_unregister_codec(&pdev->dev);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001197 return 0;
1198}
1199
1200static struct platform_driver twl6040_codec_driver = {
1201 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001202 .name = "twl6040-codec",
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001203 .owner = THIS_MODULE,
1204 },
1205 .probe = twl6040_codec_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -05001206 .remove = twl6040_codec_remove,
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001207};
1208
Mark Brown5bbcc3c2011-11-23 22:52:08 +00001209module_platform_driver(twl6040_codec_driver);
Misael Lopez Cruz8ecbabd2010-03-19 11:25:51 +00001210
1211MODULE_DESCRIPTION("ASoC TWL6040 codec driver");
1212MODULE_AUTHOR("Misael Lopez Cruz");
1213MODULE_LICENSE("GPL");