blob: 4f358393d6d63b721495ccc8330da431a9c38a20 [file] [log] [blame]
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001/*
2 * ALSA SoC Texas Instruments TLV320DAC33 codec driver
3 *
Peter Ujfalusi93864cf2011-05-03 18:11:36 +03004 * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03005 *
6 * Copyright: (C) 2009 Nokia Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/pm.h>
29#include <linux/i2c.h>
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +030030#include <linux/interrupt.h>
31#include <linux/gpio.h>
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +020032#include <linux/regulator/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +030034#include <sound/core.h>
35#include <sound/pcm.h>
36#include <sound/pcm_params.h>
37#include <sound/soc.h>
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +030038#include <sound/initval.h>
39#include <sound/tlv.h>
40
41#include <sound/tlv320dac33-plat.h>
42#include "tlv320dac33.h"
43
Peter Ujfalusi549675e2010-12-22 10:45:17 +020044/*
45 * The internal FIFO is 24576 bytes long
46 * It can be configured to hold 16bit or 24bit samples
47 * In 16bit configuration the FIFO can hold 6144 stereo samples
48 * In 24bit configuration the FIFO can hold 4096 stereo samples
49 */
50#define DAC33_FIFO_SIZE_16BIT 6144
51#define DAC33_FIFO_SIZE_24BIT 4096
52#define DAC33_MODE7_MARGIN 10 /* Safety margin for FIFO in Mode7 */
Peter Ujfalusi42603932010-04-23 10:09:59 +030053
Peter Ujfalusi76f471272010-04-23 10:10:00 +030054#define BURST_BASEFREQ_HZ 49152000
55
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +030056#define SAMPLES_TO_US(rate, samples) \
Axel Linc29429f32011-09-29 12:09:57 +080057 (1000000000 / (((rate) * 1000) / (samples)))
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +030058
59#define US_TO_SAMPLES(rate, us) \
Axel Linc29429f32011-09-29 12:09:57 +080060 ((rate) / (1000000 / ((us) < 1000000 ? (us) : 1000000)))
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +030061
Peter Ujfalusia577b312010-07-28 15:26:55 +030062#define UTHR_FROM_PERIOD_SIZE(samples, playrate, burstrate) \
Axel Linc29429f32011-09-29 12:09:57 +080063 (((samples)*5000) / (((burstrate)*5000) / ((burstrate) - (playrate))))
Peter Ujfalusia577b312010-07-28 15:26:55 +030064
Mark Browne6968a12012-04-04 15:58:16 +010065static void dac33_calculate_times(struct snd_pcm_substream *substream,
66 struct snd_soc_codec *codec);
67static int dac33_prepare_chip(struct snd_pcm_substream *substream,
68 struct snd_soc_codec *codec);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +030069
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +030070enum dac33_state {
71 DAC33_IDLE = 0,
72 DAC33_PREFILL,
73 DAC33_PLAYBACK,
74 DAC33_FLUSH,
75};
76
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +020077enum dac33_fifo_modes {
78 DAC33_FIFO_BYPASS = 0,
79 DAC33_FIFO_MODE1,
Peter Ujfalusi28e05d92009-12-31 10:30:22 +020080 DAC33_FIFO_MODE7,
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +020081 DAC33_FIFO_LAST_MODE,
82};
83
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +020084#define DAC33_NUM_SUPPLIES 3
85static const char *dac33_supply_names[DAC33_NUM_SUPPLIES] = {
86 "AVDD",
87 "DVDD",
88 "IOVDD",
89};
90
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +030091struct tlv320dac33_priv {
92 struct mutex mutex;
93 struct workqueue_struct *dac33_wq;
94 struct work_struct work;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000095 struct snd_soc_codec *codec;
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +020096 struct regulator_bulk_data supplies[DAC33_NUM_SUPPLIES];
Peter Ujfalusi0b61d2b2010-04-30 14:59:35 +030097 struct snd_pcm_substream *substream;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +030098 int power_gpio;
99 int chip_power;
100 int irq;
101 unsigned int refclk;
102
103 unsigned int alarm_threshold; /* set to be half of LATENCY_TIME_MS */
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +0200104 enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */
Peter Ujfalusi549675e2010-12-22 10:45:17 +0200105 unsigned int fifo_size; /* Size of the FIFO in samples */
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300106 unsigned int nsample; /* burst read amount from host */
Peter Ujfalusif430a272010-07-28 15:26:54 +0300107 int mode1_latency; /* latency caused by the i2c writes in
108 * us */
Peter Ujfalusi6aceabb2010-01-20 09:39:36 +0200109 u8 burst_bclkdiv; /* BCLK divider value in burst mode */
Peter Ujfalusi76f471272010-04-23 10:10:00 +0300110 unsigned int burst_rate; /* Interface speed in Burst modes */
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300111
Peter Ujfalusieeb309a2010-03-11 16:26:22 +0200112 int keep_bclk; /* Keep the BCLK continuously running
113 * in FIFO modes */
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300114 spinlock_t lock;
115 unsigned long long t_stamp1; /* Time stamp for FIFO modes to */
116 unsigned long long t_stamp2; /* calculate the FIFO caused delay */
117
118 unsigned int mode1_us_burst; /* Time to burst read n number of
119 * samples */
120 unsigned int mode7_us_to_lthr; /* Time to reach lthr from uthr */
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300121
Peter Ujfalusi9d7db2b2010-06-07 10:50:39 +0300122 unsigned int uthr;
123
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300124 enum dac33_state state;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000125 enum snd_soc_control_type control_type;
126 void *control_data;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300127};
128
129static const u8 dac33_reg[DAC33_CACHEREGNUM] = {
1300x00, 0x00, 0x00, 0x00, /* 0x00 - 0x03 */
1310x00, 0x00, 0x00, 0x00, /* 0x04 - 0x07 */
1320x00, 0x00, 0x00, 0x00, /* 0x08 - 0x0b */
1330x00, 0x00, 0x00, 0x00, /* 0x0c - 0x0f */
1340x00, 0x00, 0x00, 0x00, /* 0x10 - 0x13 */
1350x00, 0x00, 0x00, 0x00, /* 0x14 - 0x17 */
1360x00, 0x00, 0x00, 0x00, /* 0x18 - 0x1b */
1370x00, 0x00, 0x00, 0x00, /* 0x1c - 0x1f */
1380x00, 0x00, 0x00, 0x00, /* 0x20 - 0x23 */
1390x00, 0x00, 0x00, 0x00, /* 0x24 - 0x27 */
1400x00, 0x00, 0x00, 0x00, /* 0x28 - 0x2b */
1410x00, 0x00, 0x00, 0x80, /* 0x2c - 0x2f */
1420x80, 0x00, 0x00, 0x00, /* 0x30 - 0x33 */
1430x00, 0x00, 0x00, 0x00, /* 0x34 - 0x37 */
1440x00, 0x00, /* 0x38 - 0x39 */
145/* Registers 0x3a - 0x3f are reserved */
146 0x00, 0x00, /* 0x3a - 0x3b */
1470x00, 0x00, 0x00, 0x00, /* 0x3c - 0x3f */
148
1490x00, 0x00, 0x00, 0x00, /* 0x40 - 0x43 */
1500x00, 0x80, /* 0x44 - 0x45 */
151/* Registers 0x46 - 0x47 are reserved */
152 0x80, 0x80, /* 0x46 - 0x47 */
153
1540x80, 0x00, 0x00, /* 0x48 - 0x4a */
155/* Registers 0x4b - 0x7c are reserved */
156 0x00, /* 0x4b */
1570x00, 0x00, 0x00, 0x00, /* 0x4c - 0x4f */
1580x00, 0x00, 0x00, 0x00, /* 0x50 - 0x53 */
1590x00, 0x00, 0x00, 0x00, /* 0x54 - 0x57 */
1600x00, 0x00, 0x00, 0x00, /* 0x58 - 0x5b */
1610x00, 0x00, 0x00, 0x00, /* 0x5c - 0x5f */
1620x00, 0x00, 0x00, 0x00, /* 0x60 - 0x63 */
1630x00, 0x00, 0x00, 0x00, /* 0x64 - 0x67 */
1640x00, 0x00, 0x00, 0x00, /* 0x68 - 0x6b */
1650x00, 0x00, 0x00, 0x00, /* 0x6c - 0x6f */
1660x00, 0x00, 0x00, 0x00, /* 0x70 - 0x73 */
1670x00, 0x00, 0x00, 0x00, /* 0x74 - 0x77 */
1680x00, 0x00, 0x00, 0x00, /* 0x78 - 0x7b */
1690x00, /* 0x7c */
170
171 0xda, 0x33, 0x03, /* 0x7d - 0x7f */
172};
173
174/* Register read and write */
175static inline unsigned int dac33_read_reg_cache(struct snd_soc_codec *codec,
176 unsigned reg)
177{
178 u8 *cache = codec->reg_cache;
179 if (reg >= DAC33_CACHEREGNUM)
180 return 0;
181
182 return cache[reg];
183}
184
185static inline void dac33_write_reg_cache(struct snd_soc_codec *codec,
186 u8 reg, u8 value)
187{
188 u8 *cache = codec->reg_cache;
189 if (reg >= DAC33_CACHEREGNUM)
190 return;
191
192 cache[reg] = value;
193}
194
195static int dac33_read(struct snd_soc_codec *codec, unsigned int reg,
196 u8 *value)
197{
Mark Brownb2c812e2010-04-14 15:35:19 +0900198 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusi911a0f02010-10-26 11:45:59 +0300199 int val, ret = 0;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300200
201 *value = reg & 0xff;
202
203 /* If powered off, return the cached value */
204 if (dac33->chip_power) {
205 val = i2c_smbus_read_byte_data(codec->control_data, value[0]);
206 if (val < 0) {
207 dev_err(codec->dev, "Read failed (%d)\n", val);
208 value[0] = dac33_read_reg_cache(codec, reg);
Peter Ujfalusi911a0f02010-10-26 11:45:59 +0300209 ret = val;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300210 } else {
211 value[0] = val;
212 dac33_write_reg_cache(codec, reg, val);
213 }
214 } else {
215 value[0] = dac33_read_reg_cache(codec, reg);
216 }
217
Peter Ujfalusi911a0f02010-10-26 11:45:59 +0300218 return ret;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300219}
220
221static int dac33_write(struct snd_soc_codec *codec, unsigned int reg,
222 unsigned int value)
223{
Mark Brownb2c812e2010-04-14 15:35:19 +0900224 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300225 u8 data[2];
226 int ret = 0;
227
228 /*
229 * data is
230 * D15..D8 dac33 register offset
231 * D7...D0 register data
232 */
233 data[0] = reg & 0xff;
234 data[1] = value & 0xff;
235
236 dac33_write_reg_cache(codec, data[0], data[1]);
237 if (dac33->chip_power) {
238 ret = codec->hw_write(codec->control_data, data, 2);
239 if (ret != 2)
240 dev_err(codec->dev, "Write failed (%d)\n", ret);
241 else
242 ret = 0;
243 }
244
245 return ret;
246}
247
248static int dac33_write_locked(struct snd_soc_codec *codec, unsigned int reg,
249 unsigned int value)
250{
Mark Brownb2c812e2010-04-14 15:35:19 +0900251 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300252 int ret;
253
254 mutex_lock(&dac33->mutex);
255 ret = dac33_write(codec, reg, value);
256 mutex_unlock(&dac33->mutex);
257
258 return ret;
259}
260
261#define DAC33_I2C_ADDR_AUTOINC 0x80
262static int dac33_write16(struct snd_soc_codec *codec, unsigned int reg,
263 unsigned int value)
264{
Mark Brownb2c812e2010-04-14 15:35:19 +0900265 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300266 u8 data[3];
267 int ret = 0;
268
269 /*
270 * data is
271 * D23..D16 dac33 register offset
272 * D15..D8 register data MSB
273 * D7...D0 register data LSB
274 */
275 data[0] = reg & 0xff;
276 data[1] = (value >> 8) & 0xff;
277 data[2] = value & 0xff;
278
279 dac33_write_reg_cache(codec, data[0], data[1]);
280 dac33_write_reg_cache(codec, data[0] + 1, data[2]);
281
282 if (dac33->chip_power) {
283 /* We need to set autoincrement mode for 16 bit writes */
284 data[0] |= DAC33_I2C_ADDR_AUTOINC;
285 ret = codec->hw_write(codec->control_data, data, 3);
286 if (ret != 3)
287 dev_err(codec->dev, "Write failed (%d)\n", ret);
288 else
289 ret = 0;
290 }
291
292 return ret;
293}
294
Peter Ujfalusief909d62010-04-30 14:59:33 +0300295static void dac33_init_chip(struct snd_soc_codec *codec)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300296{
Mark Brownb2c812e2010-04-14 15:35:19 +0900297 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300298
Peter Ujfalusief909d62010-04-30 14:59:33 +0300299 if (unlikely(!dac33->chip_power))
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300300 return;
301
Peter Ujfalusief909d62010-04-30 14:59:33 +0300302 /* A : DAC sample rate Fsref/1.5 */
303 dac33_write(codec, DAC33_DAC_CTRL_A, DAC33_DACRATE(0));
304 /* B : DAC src=normal, not muted */
305 dac33_write(codec, DAC33_DAC_CTRL_B, DAC33_DACSRCR_RIGHT |
306 DAC33_DACSRCL_LEFT);
307 /* C : (defaults) */
308 dac33_write(codec, DAC33_DAC_CTRL_C, 0x00);
309
Peter Ujfalusief909d62010-04-30 14:59:33 +0300310 /* 73 : volume soft stepping control,
311 clock source = internal osc (?) */
312 dac33_write(codec, DAC33_ANA_VOL_SOFT_STEP_CTRL, DAC33_VOLCLKEN);
313
Peter Ujfalusief909d62010-04-30 14:59:33 +0300314 /* Restore only selected registers (gains mostly) */
315 dac33_write(codec, DAC33_LDAC_DIG_VOL_CTRL,
316 dac33_read_reg_cache(codec, DAC33_LDAC_DIG_VOL_CTRL));
317 dac33_write(codec, DAC33_RDAC_DIG_VOL_CTRL,
318 dac33_read_reg_cache(codec, DAC33_RDAC_DIG_VOL_CTRL));
319
320 dac33_write(codec, DAC33_LINEL_TO_LLO_VOL,
321 dac33_read_reg_cache(codec, DAC33_LINEL_TO_LLO_VOL));
322 dac33_write(codec, DAC33_LINER_TO_RLO_VOL,
323 dac33_read_reg_cache(codec, DAC33_LINER_TO_RLO_VOL));
Peter Ujfalusi399b82e2011-01-10 15:39:49 +0200324
325 dac33_write(codec, DAC33_OUT_AMP_CTRL,
326 dac33_read_reg_cache(codec, DAC33_OUT_AMP_CTRL));
327
Peter Ujfalusi56a35362011-03-24 08:58:05 +0200328 dac33_write(codec, DAC33_LDAC_PWR_CTRL,
329 dac33_read_reg_cache(codec, DAC33_LDAC_PWR_CTRL));
330 dac33_write(codec, DAC33_RDAC_PWR_CTRL,
331 dac33_read_reg_cache(codec, DAC33_RDAC_PWR_CTRL));
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300332}
333
Peter Ujfalusi911a0f02010-10-26 11:45:59 +0300334static inline int dac33_read_id(struct snd_soc_codec *codec)
Peter Ujfalusi239fe552010-04-30 14:59:34 +0300335{
Peter Ujfalusi911a0f02010-10-26 11:45:59 +0300336 int i, ret = 0;
Peter Ujfalusi239fe552010-04-30 14:59:34 +0300337 u8 reg;
338
Peter Ujfalusi911a0f02010-10-26 11:45:59 +0300339 for (i = 0; i < 3; i++) {
340 ret = dac33_read(codec, DAC33_DEVICE_ID_MSB + i, &reg);
341 if (ret < 0)
342 break;
343 }
344
345 return ret;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300346}
347
348static inline void dac33_soft_power(struct snd_soc_codec *codec, int power)
349{
350 u8 reg;
351
352 reg = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
353 if (power)
354 reg |= DAC33_PDNALLB;
355 else
Peter Ujfalusic3746a02010-03-11 16:26:21 +0200356 reg &= ~(DAC33_PDNALLB | DAC33_OSCPDNB |
357 DAC33_DACRPDNB | DAC33_DACLPDNB);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300358 dac33_write(codec, DAC33_PWR_CTRL, reg);
359}
360
Peter Ujfalusia6cea962010-12-10 13:26:31 +0200361static inline void dac33_disable_digital(struct snd_soc_codec *codec)
362{
363 u8 reg;
364
365 /* Stop the DAI clock */
366 reg = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B);
367 reg &= ~DAC33_BCLKON;
368 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_B, reg);
369
370 /* Power down the Oscillator, and DACs */
371 reg = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
372 reg &= ~(DAC33_OSCPDNB | DAC33_DACRPDNB | DAC33_DACLPDNB);
373 dac33_write(codec, DAC33_PWR_CTRL, reg);
374}
375
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +0200376static int dac33_hard_power(struct snd_soc_codec *codec, int power)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300377{
Mark Brownb2c812e2010-04-14 15:35:19 +0900378 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusiad05c032010-04-30 14:59:36 +0300379 int ret = 0;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300380
381 mutex_lock(&dac33->mutex);
Peter Ujfalusiad05c032010-04-30 14:59:36 +0300382
383 /* Safety check */
384 if (unlikely(power == dac33->chip_power)) {
Felipe Balbi7fd1d742010-05-17 14:21:45 +0300385 dev_dbg(codec->dev, "Trying to set the same power state: %s\n",
Peter Ujfalusiad05c032010-04-30 14:59:36 +0300386 power ? "ON" : "OFF");
387 goto exit;
388 }
389
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300390 if (power) {
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +0200391 ret = regulator_bulk_enable(ARRAY_SIZE(dac33->supplies),
392 dac33->supplies);
393 if (ret != 0) {
394 dev_err(codec->dev,
395 "Failed to enable supplies: %d\n", ret);
396 goto exit;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300397 }
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +0200398
399 if (dac33->power_gpio >= 0)
400 gpio_set_value(dac33->power_gpio, 1);
401
402 dac33->chip_power = 1;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300403 } else {
404 dac33_soft_power(codec, 0);
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +0200405 if (dac33->power_gpio >= 0)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300406 gpio_set_value(dac33->power_gpio, 0);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300407
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +0200408 ret = regulator_bulk_disable(ARRAY_SIZE(dac33->supplies),
409 dac33->supplies);
410 if (ret != 0) {
411 dev_err(codec->dev,
412 "Failed to disable supplies: %d\n", ret);
413 goto exit;
414 }
415
416 dac33->chip_power = 0;
417 }
418
419exit:
420 mutex_unlock(&dac33->mutex);
421 return ret;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300422}
423
Peter Ujfalusia6cea962010-12-10 13:26:31 +0200424static int dac33_playback_event(struct snd_soc_dapm_widget *w,
Peter Ujfalusiad05c032010-04-30 14:59:36 +0300425 struct snd_kcontrol *kcontrol, int event)
426{
427 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(w->codec);
428
429 switch (event) {
430 case SND_SOC_DAPM_PRE_PMU:
431 if (likely(dac33->substream)) {
Mark Browne6968a12012-04-04 15:58:16 +0100432 dac33_calculate_times(dac33->substream, w->codec);
433 dac33_prepare_chip(dac33->substream, w->codec);
Peter Ujfalusiad05c032010-04-30 14:59:36 +0300434 }
435 break;
Peter Ujfalusia6cea962010-12-10 13:26:31 +0200436 case SND_SOC_DAPM_POST_PMD:
437 dac33_disable_digital(w->codec);
438 break;
Peter Ujfalusiad05c032010-04-30 14:59:36 +0300439 }
440 return 0;
441}
442
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +0200443static int dac33_get_fifo_mode(struct snd_kcontrol *kcontrol,
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300444 struct snd_ctl_elem_value *ucontrol)
445{
446 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brownb2c812e2010-04-14 15:35:19 +0900447 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300448
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +0200449 ucontrol->value.integer.value[0] = dac33->fifo_mode;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300450
451 return 0;
452}
453
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +0200454static int dac33_set_fifo_mode(struct snd_kcontrol *kcontrol,
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300455 struct snd_ctl_elem_value *ucontrol)
456{
457 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
Mark Brownb2c812e2010-04-14 15:35:19 +0900458 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300459 int ret = 0;
460
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +0200461 if (dac33->fifo_mode == ucontrol->value.integer.value[0])
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300462 return 0;
463 /* Do not allow changes while stream is running*/
464 if (codec->active)
465 return -EPERM;
466
467 if (ucontrol->value.integer.value[0] < 0 ||
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +0200468 ucontrol->value.integer.value[0] >= DAC33_FIFO_LAST_MODE)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300469 ret = -EINVAL;
470 else
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +0200471 dac33->fifo_mode = ucontrol->value.integer.value[0];
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300472
473 return ret;
474}
475
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +0200476/* Codec operation modes */
477static const char *dac33_fifo_mode_texts[] = {
Peter Ujfalusi28e05d92009-12-31 10:30:22 +0200478 "Bypass", "Mode 1", "Mode 7"
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +0200479};
480
481static const struct soc_enum dac33_fifo_mode_enum =
482 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dac33_fifo_mode_texts),
483 dac33_fifo_mode_texts);
484
Peter Ujfalusicf4bb6982010-10-13 11:56:28 +0300485/* L/R Line Output Gain */
486static const char *lr_lineout_gain_texts[] = {
487 "Line -12dB DAC 0dB", "Line -6dB DAC 6dB",
488 "Line 0dB DAC 12dB", "Line 6dB DAC 18dB",
489};
490
491static const struct soc_enum l_lineout_gain_enum =
492 SOC_ENUM_SINGLE(DAC33_LDAC_PWR_CTRL, 0,
493 ARRAY_SIZE(lr_lineout_gain_texts),
494 lr_lineout_gain_texts);
495
496static const struct soc_enum r_lineout_gain_enum =
497 SOC_ENUM_SINGLE(DAC33_RDAC_PWR_CTRL, 0,
498 ARRAY_SIZE(lr_lineout_gain_texts),
499 lr_lineout_gain_texts);
500
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300501/*
502 * DACL/R digital volume control:
503 * from 0 dB to -63.5 in 0.5 dB steps
504 * Need to be inverted later on:
505 * 0x00 == 0 dB
506 * 0x7f == -63.5 dB
507 */
508static DECLARE_TLV_DB_SCALE(dac_digivol_tlv, -6350, 50, 0);
509
510static const struct snd_kcontrol_new dac33_snd_controls[] = {
511 SOC_DOUBLE_R_TLV("DAC Digital Playback Volume",
512 DAC33_LDAC_DIG_VOL_CTRL, DAC33_RDAC_DIG_VOL_CTRL,
513 0, 0x7f, 1, dac_digivol_tlv),
514 SOC_DOUBLE_R("DAC Digital Playback Switch",
515 DAC33_LDAC_DIG_VOL_CTRL, DAC33_RDAC_DIG_VOL_CTRL, 7, 1, 1),
516 SOC_DOUBLE_R("Line to Line Out Volume",
517 DAC33_LINEL_TO_LLO_VOL, DAC33_LINER_TO_RLO_VOL, 0, 127, 1),
Peter Ujfalusicf4bb6982010-10-13 11:56:28 +0300518 SOC_ENUM("Left Line Output Gain", l_lineout_gain_enum),
519 SOC_ENUM("Right Line Output Gain", r_lineout_gain_enum),
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300520};
521
Peter Ujfalusia577b312010-07-28 15:26:55 +0300522static const struct snd_kcontrol_new dac33_mode_snd_controls[] = {
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +0200523 SOC_ENUM_EXT("FIFO Mode", dac33_fifo_mode_enum,
524 dac33_get_fifo_mode, dac33_set_fifo_mode),
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300525};
526
527/* Analog bypass */
528static const struct snd_kcontrol_new dac33_dapm_abypassl_control =
529 SOC_DAPM_SINGLE("Switch", DAC33_LINEL_TO_LLO_VOL, 7, 1, 1);
530
531static const struct snd_kcontrol_new dac33_dapm_abypassr_control =
532 SOC_DAPM_SINGLE("Switch", DAC33_LINER_TO_RLO_VOL, 7, 1, 1);
533
Peter Ujfalusi399b82e2011-01-10 15:39:49 +0200534/* LOP L/R invert selection */
535static const char *dac33_lr_lom_texts[] = {"DAC", "LOP"};
536
537static const struct soc_enum dac33_left_lom_enum =
538 SOC_ENUM_SINGLE(DAC33_OUT_AMP_CTRL, 3,
539 ARRAY_SIZE(dac33_lr_lom_texts),
540 dac33_lr_lom_texts);
541
542static const struct snd_kcontrol_new dac33_dapm_left_lom_control =
543SOC_DAPM_ENUM("Route", dac33_left_lom_enum);
544
545static const struct soc_enum dac33_right_lom_enum =
546 SOC_ENUM_SINGLE(DAC33_OUT_AMP_CTRL, 2,
547 ARRAY_SIZE(dac33_lr_lom_texts),
548 dac33_lr_lom_texts);
549
550static const struct snd_kcontrol_new dac33_dapm_right_lom_control =
551SOC_DAPM_ENUM("Route", dac33_right_lom_enum);
552
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300553static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = {
554 SND_SOC_DAPM_OUTPUT("LEFT_LO"),
555 SND_SOC_DAPM_OUTPUT("RIGHT_LO"),
556
557 SND_SOC_DAPM_INPUT("LINEL"),
558 SND_SOC_DAPM_INPUT("LINER"),
559
Peter Ujfalusi76eac392010-12-08 16:04:33 +0200560 SND_SOC_DAPM_DAC("DACL", "Left Playback", SND_SOC_NOPM, 0, 0),
561 SND_SOC_DAPM_DAC("DACR", "Right Playback", SND_SOC_NOPM, 0, 0),
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300562
563 /* Analog bypass */
564 SND_SOC_DAPM_SWITCH("Analog Left Bypass", SND_SOC_NOPM, 0, 0,
565 &dac33_dapm_abypassl_control),
566 SND_SOC_DAPM_SWITCH("Analog Right Bypass", SND_SOC_NOPM, 0, 0,
567 &dac33_dapm_abypassr_control),
568
Peter Ujfalusi399b82e2011-01-10 15:39:49 +0200569 SND_SOC_DAPM_MUX("Left LOM Inverted From", SND_SOC_NOPM, 0, 0,
570 &dac33_dapm_left_lom_control),
571 SND_SOC_DAPM_MUX("Right LOM Inverted From", SND_SOC_NOPM, 0, 0,
572 &dac33_dapm_right_lom_control),
573 /*
574 * For DAPM path, when only the anlog bypass path is enabled, and the
575 * LOP inverted from the corresponding DAC side.
576 * This is needed, so we can attach the DAC power supply in this case.
577 */
578 SND_SOC_DAPM_PGA("Left Bypass PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
579 SND_SOC_DAPM_PGA("Right Bypass PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
580
Peter Ujfalusi9e871862010-12-08 16:04:32 +0200581 SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Left Amplifier",
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300582 DAC33_OUT_AMP_PWR_CTRL, 6, 3, 3, 0),
Peter Ujfalusi9e871862010-12-08 16:04:32 +0200583 SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Right Amplifier",
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300584 DAC33_OUT_AMP_PWR_CTRL, 4, 3, 3, 0),
Peter Ujfalusiad05c032010-04-30 14:59:36 +0300585
Peter Ujfalusi76eac392010-12-08 16:04:33 +0200586 SND_SOC_DAPM_SUPPLY("Left DAC Power",
587 DAC33_LDAC_PWR_CTRL, 2, 0, NULL, 0),
588 SND_SOC_DAPM_SUPPLY("Right DAC Power",
589 DAC33_RDAC_PWR_CTRL, 2, 0, NULL, 0),
590
Peter Ujfalusi4b8ffdb2011-03-24 09:11:49 +0200591 SND_SOC_DAPM_SUPPLY("Codec Power",
592 DAC33_PWR_CTRL, 4, 0, NULL, 0),
593
Peter Ujfalusia6cea962010-12-10 13:26:31 +0200594 SND_SOC_DAPM_PRE("Pre Playback", dac33_playback_event),
595 SND_SOC_DAPM_POST("Post Playback", dac33_playback_event),
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300596};
597
598static const struct snd_soc_dapm_route audio_map[] = {
599 /* Analog bypass */
600 {"Analog Left Bypass", "Switch", "LINEL"},
601 {"Analog Right Bypass", "Switch", "LINER"},
602
Peter Ujfalusi9e871862010-12-08 16:04:32 +0200603 {"Output Left Amplifier", NULL, "DACL"},
604 {"Output Right Amplifier", NULL, "DACR"},
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300605
Peter Ujfalusi399b82e2011-01-10 15:39:49 +0200606 {"Left Bypass PGA", NULL, "Analog Left Bypass"},
607 {"Right Bypass PGA", NULL, "Analog Right Bypass"},
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300608
Peter Ujfalusi399b82e2011-01-10 15:39:49 +0200609 {"Left LOM Inverted From", "DAC", "Left Bypass PGA"},
610 {"Right LOM Inverted From", "DAC", "Right Bypass PGA"},
611 {"Left LOM Inverted From", "LOP", "Analog Left Bypass"},
612 {"Right LOM Inverted From", "LOP", "Analog Right Bypass"},
613
614 {"Output Left Amplifier", NULL, "Left LOM Inverted From"},
615 {"Output Right Amplifier", NULL, "Right LOM Inverted From"},
616
617 {"DACL", NULL, "Left DAC Power"},
618 {"DACR", NULL, "Right DAC Power"},
619
620 {"Left Bypass PGA", NULL, "Left DAC Power"},
621 {"Right Bypass PGA", NULL, "Right DAC Power"},
Peter Ujfalusi76eac392010-12-08 16:04:33 +0200622
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300623 /* output */
Peter Ujfalusi9e871862010-12-08 16:04:32 +0200624 {"LEFT_LO", NULL, "Output Left Amplifier"},
625 {"RIGHT_LO", NULL, "Output Right Amplifier"},
Peter Ujfalusi4b8ffdb2011-03-24 09:11:49 +0200626
627 {"LEFT_LO", NULL, "Codec Power"},
628 {"RIGHT_LO", NULL, "Codec Power"},
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300629};
630
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300631static int dac33_set_bias_level(struct snd_soc_codec *codec,
632 enum snd_soc_bias_level level)
633{
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +0200634 int ret;
635
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300636 switch (level) {
637 case SND_SOC_BIAS_ON:
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300638 break;
639 case SND_SOC_BIAS_PREPARE:
640 break;
641 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200642 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
Peter Ujfalusiad05c032010-04-30 14:59:36 +0300643 /* Coming from OFF, switch on the codec */
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +0200644 ret = dac33_hard_power(codec, 1);
645 if (ret != 0)
646 return ret;
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +0200647
Peter Ujfalusiad05c032010-04-30 14:59:36 +0300648 dac33_init_chip(codec);
649 }
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300650 break;
651 case SND_SOC_BIAS_OFF:
Peter Ujfalusi2d4cdd62010-05-17 14:21:46 +0300652 /* Do not power off, when the codec is already off */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200653 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
Peter Ujfalusi2d4cdd62010-05-17 14:21:46 +0300654 return 0;
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +0200655 ret = dac33_hard_power(codec, 0);
656 if (ret != 0)
657 return ret;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300658 break;
659 }
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200660 codec->dapm.bias_level = level;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300661
662 return 0;
663}
664
Peter Ujfalusid4f102d2009-12-31 10:30:20 +0200665static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
666{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000667 struct snd_soc_codec *codec = dac33->codec;
Peter Ujfalusi84eae182010-10-22 15:11:20 +0300668 unsigned int delay;
Peter Ujfalusia3b55792011-03-18 15:15:11 +0200669 unsigned long flags;
Peter Ujfalusid4f102d2009-12-31 10:30:20 +0200670
671 switch (dac33->fifo_mode) {
672 case DAC33_FIFO_MODE1:
673 dac33_write16(codec, DAC33_NSAMPLE_MSB,
Peter Ujfalusif430a272010-07-28 15:26:54 +0300674 DAC33_THRREG(dac33->nsample));
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300675
676 /* Take the timestamps */
Peter Ujfalusia3b55792011-03-18 15:15:11 +0200677 spin_lock_irqsave(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300678 dac33->t_stamp2 = ktime_to_us(ktime_get());
679 dac33->t_stamp1 = dac33->t_stamp2;
Peter Ujfalusia3b55792011-03-18 15:15:11 +0200680 spin_unlock_irqrestore(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300681
Peter Ujfalusid4f102d2009-12-31 10:30:20 +0200682 dac33_write16(codec, DAC33_PREFILL_MSB,
683 DAC33_THRREG(dac33->alarm_threshold));
Peter Ujfalusif4d59322010-04-23 10:09:57 +0300684 /* Enable Alarm Threshold IRQ with a delay */
Peter Ujfalusi84eae182010-10-22 15:11:20 +0300685 delay = SAMPLES_TO_US(dac33->burst_rate,
686 dac33->alarm_threshold) + 1000;
687 usleep_range(delay, delay + 500);
Peter Ujfalusif4d59322010-04-23 10:09:57 +0300688 dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MAT);
Peter Ujfalusid4f102d2009-12-31 10:30:20 +0200689 break;
Peter Ujfalusi28e05d92009-12-31 10:30:22 +0200690 case DAC33_FIFO_MODE7:
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300691 /* Take the timestamp */
Peter Ujfalusia3b55792011-03-18 15:15:11 +0200692 spin_lock_irqsave(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300693 dac33->t_stamp1 = ktime_to_us(ktime_get());
694 /* Move back the timestamp with drain time */
695 dac33->t_stamp1 -= dac33->mode7_us_to_lthr;
Peter Ujfalusia3b55792011-03-18 15:15:11 +0200696 spin_unlock_irqrestore(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300697
Peter Ujfalusi28e05d92009-12-31 10:30:22 +0200698 dac33_write16(codec, DAC33_PREFILL_MSB,
Peter Ujfalusi549675e2010-12-22 10:45:17 +0200699 DAC33_THRREG(DAC33_MODE7_MARGIN));
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300700
701 /* Enable Upper Threshold IRQ */
702 dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MUT);
Peter Ujfalusi28e05d92009-12-31 10:30:22 +0200703 break;
Peter Ujfalusid4f102d2009-12-31 10:30:20 +0200704 default:
705 dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
706 dac33->fifo_mode);
707 break;
708 }
709}
710
711static inline void dac33_playback_handler(struct tlv320dac33_priv *dac33)
712{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000713 struct snd_soc_codec *codec = dac33->codec;
Peter Ujfalusia3b55792011-03-18 15:15:11 +0200714 unsigned long flags;
Peter Ujfalusid4f102d2009-12-31 10:30:20 +0200715
716 switch (dac33->fifo_mode) {
717 case DAC33_FIFO_MODE1:
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300718 /* Take the timestamp */
Peter Ujfalusia3b55792011-03-18 15:15:11 +0200719 spin_lock_irqsave(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300720 dac33->t_stamp2 = ktime_to_us(ktime_get());
Peter Ujfalusia3b55792011-03-18 15:15:11 +0200721 spin_unlock_irqrestore(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300722
Peter Ujfalusid4f102d2009-12-31 10:30:20 +0200723 dac33_write16(codec, DAC33_NSAMPLE_MSB,
724 DAC33_THRREG(dac33->nsample));
725 break;
Peter Ujfalusi28e05d92009-12-31 10:30:22 +0200726 case DAC33_FIFO_MODE7:
727 /* At the moment we are not using interrupts in mode7 */
728 break;
Peter Ujfalusid4f102d2009-12-31 10:30:20 +0200729 default:
730 dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
731 dac33->fifo_mode);
732 break;
733 }
734}
735
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300736static void dac33_work(struct work_struct *work)
737{
738 struct snd_soc_codec *codec;
739 struct tlv320dac33_priv *dac33;
740 u8 reg;
741
742 dac33 = container_of(work, struct tlv320dac33_priv, work);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000743 codec = dac33->codec;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300744
745 mutex_lock(&dac33->mutex);
746 switch (dac33->state) {
747 case DAC33_PREFILL:
748 dac33->state = DAC33_PLAYBACK;
Peter Ujfalusid4f102d2009-12-31 10:30:20 +0200749 dac33_prefill_handler(dac33);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300750 break;
751 case DAC33_PLAYBACK:
Peter Ujfalusid4f102d2009-12-31 10:30:20 +0200752 dac33_playback_handler(dac33);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300753 break;
754 case DAC33_IDLE:
755 break;
756 case DAC33_FLUSH:
757 dac33->state = DAC33_IDLE;
758 /* Mask all interrupts from dac33 */
759 dac33_write(codec, DAC33_FIFO_IRQ_MASK, 0);
760
761 /* flush fifo */
762 reg = dac33_read_reg_cache(codec, DAC33_FIFO_CTRL_A);
763 reg |= DAC33_FIFOFLUSH;
764 dac33_write(codec, DAC33_FIFO_CTRL_A, reg);
765 break;
766 }
767 mutex_unlock(&dac33->mutex);
768}
769
770static irqreturn_t dac33_interrupt_handler(int irq, void *dev)
771{
772 struct snd_soc_codec *codec = dev;
Mark Brownb2c812e2010-04-14 15:35:19 +0900773 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusia3b55792011-03-18 15:15:11 +0200774 unsigned long flags;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300775
Peter Ujfalusia3b55792011-03-18 15:15:11 +0200776 spin_lock_irqsave(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300777 dac33->t_stamp1 = ktime_to_us(ktime_get());
Peter Ujfalusia3b55792011-03-18 15:15:11 +0200778 spin_unlock_irqrestore(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300779
780 /* Do not schedule the workqueue in Mode7 */
781 if (dac33->fifo_mode != DAC33_FIFO_MODE7)
782 queue_work(dac33->dac33_wq, &dac33->work);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300783
784 return IRQ_HANDLED;
785}
786
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300787static void dac33_oscwait(struct snd_soc_codec *codec)
788{
Peter Ujfalusi84eae182010-10-22 15:11:20 +0300789 int timeout = 60;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300790 u8 reg;
791
792 do {
Peter Ujfalusi84eae182010-10-22 15:11:20 +0300793 usleep_range(1000, 2000);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300794 dac33_read(codec, DAC33_INT_OSC_STATUS, &reg);
795 } while (((reg & 0x03) != DAC33_OSCSTATUS_NORMAL) && timeout--);
796 if ((reg & 0x03) != DAC33_OSCSTATUS_NORMAL)
797 dev_err(codec->dev,
798 "internal oscillator calibration failed\n");
799}
800
Peter Ujfalusi0b61d2b2010-04-30 14:59:35 +0300801static int dac33_startup(struct snd_pcm_substream *substream,
802 struct snd_soc_dai *dai)
803{
Mark Browne6968a12012-04-04 15:58:16 +0100804 struct snd_soc_codec *codec = dai->codec;
Peter Ujfalusi0b61d2b2010-04-30 14:59:35 +0300805 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
806
807 /* Stream started, save the substream pointer */
808 dac33->substream = substream;
809
810 return 0;
811}
812
813static void dac33_shutdown(struct snd_pcm_substream *substream,
814 struct snd_soc_dai *dai)
815{
Mark Browne6968a12012-04-04 15:58:16 +0100816 struct snd_soc_codec *codec = dai->codec;
Peter Ujfalusi0b61d2b2010-04-30 14:59:35 +0300817 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
818
819 dac33->substream = NULL;
820}
821
Peter Ujfalusi549675e2010-12-22 10:45:17 +0200822#define CALC_BURST_RATE(bclkdiv, bclk_per_sample) \
823 (BURST_BASEFREQ_HZ / bclkdiv / bclk_per_sample)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300824static int dac33_hw_params(struct snd_pcm_substream *substream,
825 struct snd_pcm_hw_params *params,
826 struct snd_soc_dai *dai)
827{
Mark Browne6968a12012-04-04 15:58:16 +0100828 struct snd_soc_codec *codec = dai->codec;
Peter Ujfalusi549675e2010-12-22 10:45:17 +0200829 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300830
831 /* Check parameters for validity */
832 switch (params_rate(params)) {
833 case 44100:
834 case 48000:
835 break;
836 default:
837 dev_err(codec->dev, "unsupported rate %d\n",
838 params_rate(params));
839 return -EINVAL;
840 }
841
842 switch (params_format(params)) {
843 case SNDRV_PCM_FORMAT_S16_LE:
Peter Ujfalusi549675e2010-12-22 10:45:17 +0200844 dac33->fifo_size = DAC33_FIFO_SIZE_16BIT;
845 dac33->burst_rate = CALC_BURST_RATE(dac33->burst_bclkdiv, 32);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300846 break;
Peter Ujfalusi0d99d2b2010-12-22 10:45:18 +0200847 case SNDRV_PCM_FORMAT_S32_LE:
848 dac33->fifo_size = DAC33_FIFO_SIZE_24BIT;
849 dac33->burst_rate = CALC_BURST_RATE(dac33->burst_bclkdiv, 64);
850 break;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300851 default:
852 dev_err(codec->dev, "unsupported format %d\n",
853 params_format(params));
854 return -EINVAL;
855 }
856
857 return 0;
858}
859
860#define CALC_OSCSET(rate, refclk) ( \
Peter Ujfalusi7833ae02010-02-16 13:23:16 +0200861 ((((rate * 10000) / refclk) * 4096) + 7000) / 10000)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300862#define CALC_RATIOSET(rate, refclk) ( \
863 ((((refclk * 100000) / rate) * 16384) + 50000) / 100000)
864
865/*
866 * tlv320dac33 is strict on the sequence of the register writes, if the register
867 * writes happens in different order, than dac33 might end up in unknown state.
868 * Use the known, working sequence of register writes to initialize the dac33.
869 */
Mark Browne6968a12012-04-04 15:58:16 +0100870static int dac33_prepare_chip(struct snd_pcm_substream *substream,
871 struct snd_soc_codec *codec)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300872{
Mark Brownb2c812e2010-04-14 15:35:19 +0900873 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300874 unsigned int oscset, ratioset, pwr_ctrl, reg_tmp;
Peter Ujfalusiaec242d2009-12-31 10:30:21 +0200875 u8 aictrl_a, aictrl_b, fifoctrl_a;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300876
877 switch (substream->runtime->rate) {
878 case 44100:
879 case 48000:
880 oscset = CALC_OSCSET(substream->runtime->rate, dac33->refclk);
881 ratioset = CALC_RATIOSET(substream->runtime->rate,
882 dac33->refclk);
883 break;
884 default:
885 dev_err(codec->dev, "unsupported rate %d\n",
886 substream->runtime->rate);
887 return -EINVAL;
888 }
889
890
891 aictrl_a = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A);
892 aictrl_a &= ~(DAC33_NCYCL_MASK | DAC33_WLEN_MASK);
Peter Ujfalusie5e878c2010-02-16 13:23:15 +0200893 /* Read FIFO control A, and clear FIFO flush bit */
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300894 fifoctrl_a = dac33_read_reg_cache(codec, DAC33_FIFO_CTRL_A);
Peter Ujfalusie5e878c2010-02-16 13:23:15 +0200895 fifoctrl_a &= ~DAC33_FIFOFLUSH;
896
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300897 fifoctrl_a &= ~DAC33_WIDTH;
898 switch (substream->runtime->format) {
899 case SNDRV_PCM_FORMAT_S16_LE:
900 aictrl_a |= (DAC33_NCYCL_16 | DAC33_WLEN_16);
901 fifoctrl_a |= DAC33_WIDTH;
902 break;
Peter Ujfalusi0d99d2b2010-12-22 10:45:18 +0200903 case SNDRV_PCM_FORMAT_S32_LE:
904 aictrl_a |= (DAC33_NCYCL_32 | DAC33_WLEN_24);
905 break;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300906 default:
907 dev_err(codec->dev, "unsupported format %d\n",
908 substream->runtime->format);
909 return -EINVAL;
910 }
911
912 mutex_lock(&dac33->mutex);
Peter Ujfalusiad05c032010-04-30 14:59:36 +0300913
914 if (!dac33->chip_power) {
915 /*
916 * Chip is not powered yet.
917 * Do the init in the dac33_set_bias_level later.
918 */
919 mutex_unlock(&dac33->mutex);
920 return 0;
921 }
922
Peter Ujfalusic3746a02010-03-11 16:26:21 +0200923 dac33_soft_power(codec, 0);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300924 dac33_soft_power(codec, 1);
925
926 reg_tmp = dac33_read_reg_cache(codec, DAC33_INT_OSC_CTRL);
927 dac33_write(codec, DAC33_INT_OSC_CTRL, reg_tmp);
928
929 /* Write registers 0x08 and 0x09 (MSB, LSB) */
930 dac33_write16(codec, DAC33_INT_OSC_FREQ_RAT_A, oscset);
931
Peter Ujfalusi82a58a82011-04-12 09:09:17 +0300932 /* OSC calibration time */
933 dac33_write(codec, DAC33_CALIB_TIME, 96);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300934
935 /* adjustment treshold & step */
936 dac33_write(codec, DAC33_INT_OSC_CTRL_B, DAC33_ADJTHRSHLD(2) |
937 DAC33_ADJSTEP(1));
938
939 /* div=4 / gain=1 / div */
940 dac33_write(codec, DAC33_INT_OSC_CTRL_C, DAC33_REFDIV(4));
941
942 pwr_ctrl = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
943 pwr_ctrl |= DAC33_OSCPDNB | DAC33_DACRPDNB | DAC33_DACLPDNB;
944 dac33_write(codec, DAC33_PWR_CTRL, pwr_ctrl);
945
946 dac33_oscwait(codec);
947
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +0200948 if (dac33->fifo_mode) {
Peter Ujfalusiaec242d2009-12-31 10:30:21 +0200949 /* Generic for all FIFO modes */
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300950 /* 50-51 : ASRC Control registers */
Peter Ujfalusifdb6b1e2010-03-19 11:10:20 +0200951 dac33_write(codec, DAC33_ASRC_CTRL_A, DAC33_SRCLKDIV(1));
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300952 dac33_write(codec, DAC33_ASRC_CTRL_B, 1); /* ??? */
953
954 /* Write registers 0x34 and 0x35 (MSB, LSB) */
955 dac33_write16(codec, DAC33_SRC_REF_CLK_RATIO_A, ratioset);
956
957 /* Set interrupts to high active */
958 dac33_write(codec, DAC33_INTP_CTRL_A, DAC33_INTPM_AHIGH);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300959 } else {
Peter Ujfalusiaec242d2009-12-31 10:30:21 +0200960 /* FIFO bypass mode */
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300961 /* 50-51 : ASRC Control registers */
962 dac33_write(codec, DAC33_ASRC_CTRL_A, DAC33_SRCBYP);
963 dac33_write(codec, DAC33_ASRC_CTRL_B, 0); /* ??? */
964 }
965
Peter Ujfalusiaec242d2009-12-31 10:30:21 +0200966 /* Interrupt behaviour configuration */
967 switch (dac33->fifo_mode) {
968 case DAC33_FIFO_MODE1:
969 dac33_write(codec, DAC33_FIFO_IRQ_MODE_B,
970 DAC33_ATM(DAC33_FIFO_IRQ_MODE_LEVEL));
Peter Ujfalusiaec242d2009-12-31 10:30:21 +0200971 break;
Peter Ujfalusi28e05d92009-12-31 10:30:22 +0200972 case DAC33_FIFO_MODE7:
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +0300973 dac33_write(codec, DAC33_FIFO_IRQ_MODE_A,
974 DAC33_UTM(DAC33_FIFO_IRQ_MODE_LEVEL));
Peter Ujfalusi28e05d92009-12-31 10:30:22 +0200975 break;
Peter Ujfalusiaec242d2009-12-31 10:30:21 +0200976 default:
977 /* in FIFO bypass mode, the interrupts are not used */
978 break;
979 }
980
981 aictrl_b = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B);
982
983 switch (dac33->fifo_mode) {
984 case DAC33_FIFO_MODE1:
985 /*
986 * For mode1:
987 * Disable the FIFO bypass (Enable the use of FIFO)
988 * Select nSample mode
989 * BCLK is only running when data is needed by DAC33
990 */
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +0300991 fifoctrl_a &= ~DAC33_FBYPAS;
Peter Ujfalusiaec242d2009-12-31 10:30:21 +0200992 fifoctrl_a &= ~DAC33_FAUTO;
Peter Ujfalusieeb309a2010-03-11 16:26:22 +0200993 if (dac33->keep_bclk)
994 aictrl_b |= DAC33_BCLKON;
995 else
996 aictrl_b &= ~DAC33_BCLKON;
Peter Ujfalusiaec242d2009-12-31 10:30:21 +0200997 break;
Peter Ujfalusi28e05d92009-12-31 10:30:22 +0200998 case DAC33_FIFO_MODE7:
999 /*
1000 * For mode1:
1001 * Disable the FIFO bypass (Enable the use of FIFO)
1002 * Select Threshold mode
1003 * BCLK is only running when data is needed by DAC33
1004 */
1005 fifoctrl_a &= ~DAC33_FBYPAS;
1006 fifoctrl_a |= DAC33_FAUTO;
Peter Ujfalusieeb309a2010-03-11 16:26:22 +02001007 if (dac33->keep_bclk)
1008 aictrl_b |= DAC33_BCLKON;
1009 else
1010 aictrl_b &= ~DAC33_BCLKON;
Peter Ujfalusi28e05d92009-12-31 10:30:22 +02001011 break;
Peter Ujfalusiaec242d2009-12-31 10:30:21 +02001012 default:
1013 /*
1014 * For FIFO bypass mode:
1015 * Enable the FIFO bypass (Disable the FIFO use)
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001016 * Set the BCLK as continuous
Peter Ujfalusiaec242d2009-12-31 10:30:21 +02001017 */
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001018 fifoctrl_a |= DAC33_FBYPAS;
Peter Ujfalusiaec242d2009-12-31 10:30:21 +02001019 aictrl_b |= DAC33_BCLKON;
1020 break;
1021 }
1022
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001023 dac33_write(codec, DAC33_FIFO_CTRL_A, fifoctrl_a);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001024 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_A, aictrl_a);
Peter Ujfalusiaec242d2009-12-31 10:30:21 +02001025 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_B, aictrl_b);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001026
Peter Ujfalusi6aceabb2010-01-20 09:39:36 +02001027 /*
1028 * BCLK divide ratio
1029 * 0: 1.5
1030 * 1: 1
1031 * 2: 2
1032 * ...
1033 * 254: 254
1034 * 255: 255
1035 */
Peter Ujfalusi6cd6ced2010-01-20 09:39:35 +02001036 if (dac33->fifo_mode)
Peter Ujfalusi6aceabb2010-01-20 09:39:36 +02001037 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C,
1038 dac33->burst_bclkdiv);
Peter Ujfalusi6cd6ced2010-01-20 09:39:35 +02001039 else
Peter Ujfalusi0d99d2b2010-12-22 10:45:18 +02001040 if (substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE)
1041 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 32);
1042 else
1043 dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 16);
Peter Ujfalusi6cd6ced2010-01-20 09:39:35 +02001044
Peter Ujfalusiaec242d2009-12-31 10:30:21 +02001045 switch (dac33->fifo_mode) {
1046 case DAC33_FIFO_MODE1:
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001047 dac33_write16(codec, DAC33_ATHR_MSB,
1048 DAC33_THRREG(dac33->alarm_threshold));
Peter Ujfalusiaec242d2009-12-31 10:30:21 +02001049 break;
Peter Ujfalusi28e05d92009-12-31 10:30:22 +02001050 case DAC33_FIFO_MODE7:
1051 /*
1052 * Configure the threshold levels, and leave 10 sample space
1053 * at the bottom, and also at the top of the FIFO
1054 */
Peter Ujfalusi9d7db2b2010-06-07 10:50:39 +03001055 dac33_write16(codec, DAC33_UTHR_MSB, DAC33_THRREG(dac33->uthr));
Peter Ujfalusi549675e2010-12-22 10:45:17 +02001056 dac33_write16(codec, DAC33_LTHR_MSB,
1057 DAC33_THRREG(DAC33_MODE7_MARGIN));
Peter Ujfalusi28e05d92009-12-31 10:30:22 +02001058 break;
Peter Ujfalusiaec242d2009-12-31 10:30:21 +02001059 default:
Peter Ujfalusiaec242d2009-12-31 10:30:21 +02001060 break;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001061 }
1062
1063 mutex_unlock(&dac33->mutex);
1064
1065 return 0;
1066}
1067
Mark Browne6968a12012-04-04 15:58:16 +01001068static void dac33_calculate_times(struct snd_pcm_substream *substream,
1069 struct snd_soc_codec *codec)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001070{
Mark Brownb2c812e2010-04-14 15:35:19 +09001071 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusif430a272010-07-28 15:26:54 +03001072 unsigned int period_size = substream->runtime->period_size;
1073 unsigned int rate = substream->runtime->rate;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001074 unsigned int nsample_limit;
1075
Peter Ujfalusi55abb592010-04-23 10:09:58 +03001076 /* In bypass mode we don't need to calculate */
1077 if (!dac33->fifo_mode)
1078 return;
1079
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001080 switch (dac33->fifo_mode) {
1081 case DAC33_FIFO_MODE1:
Peter Ujfalusif430a272010-07-28 15:26:54 +03001082 /* Number of samples under i2c latency */
1083 dac33->alarm_threshold = US_TO_SAMPLES(rate,
1084 dac33->mode1_latency);
Peter Ujfalusi549675e2010-12-22 10:45:17 +02001085 nsample_limit = dac33->fifo_size - dac33->alarm_threshold;
Peter Ujfalusi1bc13b22010-10-29 09:49:37 +03001086
Peter Ujfalusi3591f4c2010-12-22 10:45:16 +02001087 if (period_size <= dac33->alarm_threshold)
Peter Ujfalusia577b312010-07-28 15:26:55 +03001088 /*
Peter Ujfalusi3591f4c2010-12-22 10:45:16 +02001089 * Configure nSamaple to number of periods,
1090 * which covers the latency requironment.
Peter Ujfalusia577b312010-07-28 15:26:55 +03001091 */
Peter Ujfalusi3591f4c2010-12-22 10:45:16 +02001092 dac33->nsample = period_size *
1093 ((dac33->alarm_threshold / period_size) +
1094 (dac33->alarm_threshold % period_size ?
1095 1 : 0));
1096 else if (period_size > nsample_limit)
1097 dac33->nsample = nsample_limit;
1098 else
1099 dac33->nsample = period_size;
Peter Ujfalusif430a272010-07-28 15:26:54 +03001100
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001101 dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate,
1102 dac33->nsample);
1103 dac33->t_stamp1 = 0;
1104 dac33->t_stamp2 = 0;
1105 break;
1106 case DAC33_FIFO_MODE7:
Peter Ujfalusi3591f4c2010-12-22 10:45:16 +02001107 dac33->uthr = UTHR_FROM_PERIOD_SIZE(period_size, rate,
1108 dac33->burst_rate) + 9;
Peter Ujfalusi549675e2010-12-22 10:45:17 +02001109 if (dac33->uthr > (dac33->fifo_size - DAC33_MODE7_MARGIN))
1110 dac33->uthr = dac33->fifo_size - DAC33_MODE7_MARGIN;
1111 if (dac33->uthr < (DAC33_MODE7_MARGIN + 10))
1112 dac33->uthr = (DAC33_MODE7_MARGIN + 10);
Peter Ujfalusi3591f4c2010-12-22 10:45:16 +02001113
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001114 dac33->mode7_us_to_lthr =
Peter Ujfalusi9d7db2b2010-06-07 10:50:39 +03001115 SAMPLES_TO_US(substream->runtime->rate,
Peter Ujfalusi549675e2010-12-22 10:45:17 +02001116 dac33->uthr - DAC33_MODE7_MARGIN + 1);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001117 dac33->t_stamp1 = 0;
1118 break;
1119 default:
1120 break;
1121 }
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001122
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001123}
1124
1125static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
1126 struct snd_soc_dai *dai)
1127{
Mark Browne6968a12012-04-04 15:58:16 +01001128 struct snd_soc_codec *codec = dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09001129 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001130 int ret = 0;
1131
1132 switch (cmd) {
1133 case SNDRV_PCM_TRIGGER_START:
1134 case SNDRV_PCM_TRIGGER_RESUME:
1135 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +02001136 if (dac33->fifo_mode) {
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001137 dac33->state = DAC33_PREFILL;
1138 queue_work(dac33->dac33_wq, &dac33->work);
1139 }
1140 break;
1141 case SNDRV_PCM_TRIGGER_STOP:
1142 case SNDRV_PCM_TRIGGER_SUSPEND:
1143 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +02001144 if (dac33->fifo_mode) {
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001145 dac33->state = DAC33_FLUSH;
1146 queue_work(dac33->dac33_wq, &dac33->work);
1147 }
1148 break;
1149 default:
1150 ret = -EINVAL;
1151 }
1152
1153 return ret;
1154}
1155
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001156static snd_pcm_sframes_t dac33_dai_delay(
1157 struct snd_pcm_substream *substream,
1158 struct snd_soc_dai *dai)
1159{
Mark Browne6968a12012-04-04 15:58:16 +01001160 struct snd_soc_codec *codec = dai->codec;
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001161 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
1162 unsigned long long t0, t1, t_now;
Peter Ujfalusi9d7db2b2010-06-07 10:50:39 +03001163 unsigned int time_delta, uthr;
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001164 int samples_out, samples_in, samples;
1165 snd_pcm_sframes_t delay = 0;
Peter Ujfalusia3b55792011-03-18 15:15:11 +02001166 unsigned long flags;
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001167
1168 switch (dac33->fifo_mode) {
1169 case DAC33_FIFO_BYPASS:
1170 break;
1171 case DAC33_FIFO_MODE1:
Peter Ujfalusia3b55792011-03-18 15:15:11 +02001172 spin_lock_irqsave(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001173 t0 = dac33->t_stamp1;
1174 t1 = dac33->t_stamp2;
Peter Ujfalusia3b55792011-03-18 15:15:11 +02001175 spin_unlock_irqrestore(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001176 t_now = ktime_to_us(ktime_get());
1177
1178 /* We have not started to fill the FIFO yet, delay is 0 */
1179 if (!t1)
1180 goto out;
1181
1182 if (t0 > t1) {
1183 /*
1184 * Phase 1:
1185 * After Alarm threshold, and before nSample write
1186 */
1187 time_delta = t_now - t0;
1188 samples_out = time_delta ? US_TO_SAMPLES(
1189 substream->runtime->rate,
1190 time_delta) : 0;
1191
1192 if (likely(dac33->alarm_threshold > samples_out))
1193 delay = dac33->alarm_threshold - samples_out;
1194 else
1195 delay = 0;
1196 } else if ((t_now - t1) <= dac33->mode1_us_burst) {
1197 /*
1198 * Phase 2:
1199 * After nSample write (during burst operation)
1200 */
1201 time_delta = t_now - t0;
1202 samples_out = time_delta ? US_TO_SAMPLES(
1203 substream->runtime->rate,
1204 time_delta) : 0;
1205
1206 time_delta = t_now - t1;
1207 samples_in = time_delta ? US_TO_SAMPLES(
1208 dac33->burst_rate,
1209 time_delta) : 0;
1210
1211 samples = dac33->alarm_threshold;
1212 samples += (samples_in - samples_out);
1213
1214 if (likely(samples > 0))
1215 delay = samples;
1216 else
1217 delay = 0;
1218 } else {
1219 /*
1220 * Phase 3:
1221 * After burst operation, before next alarm threshold
1222 */
1223 time_delta = t_now - t0;
1224 samples_out = time_delta ? US_TO_SAMPLES(
1225 substream->runtime->rate,
1226 time_delta) : 0;
1227
1228 samples_in = dac33->nsample;
1229 samples = dac33->alarm_threshold;
1230 samples += (samples_in - samples_out);
1231
1232 if (likely(samples > 0))
Peter Ujfalusi549675e2010-12-22 10:45:17 +02001233 delay = samples > dac33->fifo_size ?
1234 dac33->fifo_size : samples;
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001235 else
1236 delay = 0;
1237 }
1238 break;
1239 case DAC33_FIFO_MODE7:
Peter Ujfalusia3b55792011-03-18 15:15:11 +02001240 spin_lock_irqsave(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001241 t0 = dac33->t_stamp1;
Peter Ujfalusi9d7db2b2010-06-07 10:50:39 +03001242 uthr = dac33->uthr;
Peter Ujfalusia3b55792011-03-18 15:15:11 +02001243 spin_unlock_irqrestore(&dac33->lock, flags);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001244 t_now = ktime_to_us(ktime_get());
1245
1246 /* We have not started to fill the FIFO yet, delay is 0 */
1247 if (!t0)
1248 goto out;
1249
1250 if (t_now <= t0) {
1251 /*
1252 * Either the timestamps are messed or equal. Report
1253 * maximum delay
1254 */
Peter Ujfalusi9d7db2b2010-06-07 10:50:39 +03001255 delay = uthr;
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001256 goto out;
1257 }
1258
1259 time_delta = t_now - t0;
1260 if (time_delta <= dac33->mode7_us_to_lthr) {
1261 /*
1262 * Phase 1:
1263 * After burst (draining phase)
1264 */
1265 samples_out = US_TO_SAMPLES(
1266 substream->runtime->rate,
1267 time_delta);
1268
Peter Ujfalusi9d7db2b2010-06-07 10:50:39 +03001269 if (likely(uthr > samples_out))
1270 delay = uthr - samples_out;
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001271 else
1272 delay = 0;
1273 } else {
1274 /*
1275 * Phase 2:
1276 * During burst operation
1277 */
1278 time_delta = time_delta - dac33->mode7_us_to_lthr;
1279
1280 samples_out = US_TO_SAMPLES(
1281 substream->runtime->rate,
1282 time_delta);
1283 samples_in = US_TO_SAMPLES(
1284 dac33->burst_rate,
1285 time_delta);
Peter Ujfalusi549675e2010-12-22 10:45:17 +02001286 delay = DAC33_MODE7_MARGIN + samples_in - samples_out;
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001287
Peter Ujfalusi9d7db2b2010-06-07 10:50:39 +03001288 if (unlikely(delay > uthr))
1289 delay = uthr;
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001290 }
1291 break;
1292 default:
1293 dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
1294 dac33->fifo_mode);
1295 break;
1296 }
1297out:
1298 return delay;
1299}
1300
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001301static int dac33_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1302 int clk_id, unsigned int freq, int dir)
1303{
1304 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09001305 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001306 u8 ioc_reg, asrcb_reg;
1307
1308 ioc_reg = dac33_read_reg_cache(codec, DAC33_INT_OSC_CTRL);
1309 asrcb_reg = dac33_read_reg_cache(codec, DAC33_ASRC_CTRL_B);
1310 switch (clk_id) {
1311 case TLV320DAC33_MCLK:
1312 ioc_reg |= DAC33_REFSEL;
1313 asrcb_reg |= DAC33_SRCREFSEL;
1314 break;
1315 case TLV320DAC33_SLEEPCLK:
1316 ioc_reg &= ~DAC33_REFSEL;
1317 asrcb_reg &= ~DAC33_SRCREFSEL;
1318 break;
1319 default:
1320 dev_err(codec->dev, "Invalid clock ID (%d)\n", clk_id);
1321 break;
1322 }
1323 dac33->refclk = freq;
1324
1325 dac33_write_reg_cache(codec, DAC33_INT_OSC_CTRL, ioc_reg);
1326 dac33_write_reg_cache(codec, DAC33_ASRC_CTRL_B, asrcb_reg);
1327
1328 return 0;
1329}
1330
1331static int dac33_set_dai_fmt(struct snd_soc_dai *codec_dai,
1332 unsigned int fmt)
1333{
1334 struct snd_soc_codec *codec = codec_dai->codec;
Mark Brownb2c812e2010-04-14 15:35:19 +09001335 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001336 u8 aictrl_a, aictrl_b;
1337
1338 aictrl_a = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A);
1339 aictrl_b = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B);
1340 /* set master/slave audio interface */
1341 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1342 case SND_SOC_DAIFMT_CBM_CFM:
1343 /* Codec Master */
1344 aictrl_a |= (DAC33_MSBCLK | DAC33_MSWCLK);
1345 break;
1346 case SND_SOC_DAIFMT_CBS_CFS:
1347 /* Codec Slave */
Peter Ujfalusiadcb8bc2009-12-31 10:30:23 +02001348 if (dac33->fifo_mode) {
1349 dev_err(codec->dev, "FIFO mode requires master mode\n");
1350 return -EINVAL;
1351 } else
1352 aictrl_a &= ~(DAC33_MSBCLK | DAC33_MSWCLK);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001353 break;
1354 default:
1355 return -EINVAL;
1356 }
1357
1358 aictrl_a &= ~DAC33_AFMT_MASK;
1359 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1360 case SND_SOC_DAIFMT_I2S:
1361 aictrl_a |= DAC33_AFMT_I2S;
1362 break;
1363 case SND_SOC_DAIFMT_DSP_A:
1364 aictrl_a |= DAC33_AFMT_DSP;
1365 aictrl_b &= ~DAC33_DATA_DELAY_MASK;
Peter Ujfalusi44f497b2010-03-19 11:10:19 +02001366 aictrl_b |= DAC33_DATA_DELAY(0);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001367 break;
1368 case SND_SOC_DAIFMT_RIGHT_J:
1369 aictrl_a |= DAC33_AFMT_RIGHT_J;
1370 break;
1371 case SND_SOC_DAIFMT_LEFT_J:
1372 aictrl_a |= DAC33_AFMT_LEFT_J;
1373 break;
1374 default:
1375 dev_err(codec->dev, "Unsupported format (%u)\n",
1376 fmt & SND_SOC_DAIFMT_FORMAT_MASK);
1377 return -EINVAL;
1378 }
1379
1380 dac33_write_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A, aictrl_a);
1381 dac33_write_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B, aictrl_b);
1382
1383 return 0;
1384}
1385
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001386static int dac33_soc_probe(struct snd_soc_codec *codec)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001387{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001388 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001389 int ret = 0;
1390
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001391 codec->control_data = dac33->control_data;
1392 codec->hw_write = (hw_write_t) i2c_master_send;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001393 dac33->codec = codec;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001394
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001395 /* Read the tlv320dac33 ID registers */
1396 ret = dac33_hard_power(codec, 1);
1397 if (ret != 0) {
1398 dev_err(codec->dev, "Failed to power up codec: %d\n", ret);
1399 goto err_power;
1400 }
Peter Ujfalusi911a0f02010-10-26 11:45:59 +03001401 ret = dac33_read_id(codec);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001402 dac33_hard_power(codec, 0);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001403
Peter Ujfalusi911a0f02010-10-26 11:45:59 +03001404 if (ret < 0) {
1405 dev_err(codec->dev, "Failed to read chip ID: %d\n", ret);
1406 ret = -ENODEV;
1407 goto err_power;
1408 }
1409
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001410 /* Check if the IRQ number is valid and request it */
1411 if (dac33->irq >= 0) {
1412 ret = request_irq(dac33->irq, dac33_interrupt_handler,
Yong Zhang88e24c32011-09-22 16:59:20 +08001413 IRQF_TRIGGER_RISING,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001414 codec->name, codec);
1415 if (ret < 0) {
1416 dev_err(codec->dev, "Could not request IRQ%d (%d)\n",
1417 dac33->irq, ret);
1418 dac33->irq = -1;
1419 }
1420 if (dac33->irq != -1) {
1421 /* Setup work queue */
1422 dac33->dac33_wq =
1423 create_singlethread_workqueue("tlv320dac33");
1424 if (dac33->dac33_wq == NULL) {
1425 free_irq(dac33->irq, codec);
1426 return -ENOMEM;
1427 }
1428
1429 INIT_WORK(&dac33->work, dac33_work);
1430 }
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001431 }
1432
Peter Ujfalusia577b312010-07-28 15:26:55 +03001433 /* Only add the FIFO controls, if we have valid IRQ number */
Peter Ujfalusi3591f4c2010-12-22 10:45:16 +02001434 if (dac33->irq >= 0)
Liam Girdwood022658b2012-02-03 17:43:09 +00001435 snd_soc_add_codec_controls(codec, dac33_mode_snd_controls,
Peter Ujfalusia577b312010-07-28 15:26:55 +03001436 ARRAY_SIZE(dac33_mode_snd_controls));
Peter Ujfalusi3591f4c2010-12-22 10:45:16 +02001437
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001438err_power:
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001439 return ret;
1440}
1441
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001442static int dac33_soc_remove(struct snd_soc_codec *codec)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001443{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001444 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001445
1446 dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
1447
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001448 if (dac33->irq >= 0) {
1449 free_irq(dac33->irq, dac33->codec);
1450 destroy_workqueue(dac33->dac33_wq);
1451 }
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001452 return 0;
1453}
1454
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001455static struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = {
1456 .read = dac33_read_reg_cache,
1457 .write = dac33_write_locked,
1458 .set_bias_level = dac33_set_bias_level,
Axel Lineb3032f2012-01-27 18:02:09 +08001459 .idle_bias_off = true,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001460 .reg_cache_size = ARRAY_SIZE(dac33_reg),
1461 .reg_word_size = sizeof(u8),
1462 .reg_cache_default = dac33_reg,
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001463 .probe = dac33_soc_probe,
1464 .remove = dac33_soc_remove,
Peter Ujfalusi8066eb52011-10-11 13:11:55 +03001465
1466 .controls = dac33_snd_controls,
1467 .num_controls = ARRAY_SIZE(dac33_snd_controls),
1468 .dapm_widgets = dac33_dapm_widgets,
1469 .num_dapm_widgets = ARRAY_SIZE(dac33_dapm_widgets),
1470 .dapm_routes = audio_map,
1471 .num_dapm_routes = ARRAY_SIZE(audio_map),
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001472};
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001473
1474#define DAC33_RATES (SNDRV_PCM_RATE_44100 | \
1475 SNDRV_PCM_RATE_48000)
Peter Ujfalusi0d99d2b2010-12-22 10:45:18 +02001476#define DAC33_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001477
Lars-Peter Clausen85e76522011-11-23 11:40:40 +01001478static const struct snd_soc_dai_ops dac33_dai_ops = {
Peter Ujfalusi0b61d2b2010-04-30 14:59:35 +03001479 .startup = dac33_startup,
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001480 .shutdown = dac33_shutdown,
1481 .hw_params = dac33_hw_params,
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001482 .trigger = dac33_pcm_trigger,
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001483 .delay = dac33_dai_delay,
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001484 .set_sysclk = dac33_set_dai_sysclk,
1485 .set_fmt = dac33_set_dai_fmt,
1486};
1487
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001488static struct snd_soc_dai_driver dac33_dai = {
1489 .name = "tlv320dac33-hifi",
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001490 .playback = {
1491 .stream_name = "Playback",
1492 .channels_min = 2,
1493 .channels_max = 2,
1494 .rates = DAC33_RATES,
Mark Brown3a4cbf82012-01-20 17:52:39 +00001495 .formats = DAC33_FORMATS,
Peter Ujfalusi8d725b22012-01-18 12:18:25 +01001496 .sig_bits = 24,
Mark Brown3a4cbf82012-01-20 17:52:39 +00001497 },
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001498 .ops = &dac33_dai_ops,
1499};
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001500
Bill Pemberton7a79e942012-12-07 09:26:37 -05001501static int dac33_i2c_probe(struct i2c_client *client,
1502 const struct i2c_device_id *id)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001503{
1504 struct tlv320dac33_platform_data *pdata;
1505 struct tlv320dac33_priv *dac33;
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +02001506 int ret, i;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001507
1508 if (client->dev.platform_data == NULL) {
1509 dev_err(&client->dev, "Platform data not set\n");
1510 return -ENODEV;
1511 }
1512 pdata = client->dev.platform_data;
1513
Axel Lina54877d2011-12-29 12:11:00 +08001514 dac33 = devm_kzalloc(&client->dev, sizeof(struct tlv320dac33_priv),
1515 GFP_KERNEL);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001516 if (dac33 == NULL)
1517 return -ENOMEM;
1518
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001519 dac33->control_data = client;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001520 mutex_init(&dac33->mutex);
Peter Ujfalusif57d2cf2010-04-23 10:10:01 +03001521 spin_lock_init(&dac33->lock);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001522
1523 i2c_set_clientdata(client, dac33);
1524
1525 dac33->power_gpio = pdata->power_gpio;
Peter Ujfalusi6aceabb2010-01-20 09:39:36 +02001526 dac33->burst_bclkdiv = pdata->burst_bclkdiv;
Peter Ujfalusieeb309a2010-03-11 16:26:22 +02001527 dac33->keep_bclk = pdata->keep_bclk;
Peter Ujfalusif430a272010-07-28 15:26:54 +03001528 dac33->mode1_latency = pdata->mode1_latency;
1529 if (!dac33->mode1_latency)
1530 dac33->mode1_latency = 10000; /* 10ms */
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001531 dac33->irq = client->irq;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001532 /* Disable FIFO use by default */
Peter Ujfalusi7427b4b2009-12-31 10:30:19 +02001533 dac33->fifo_mode = DAC33_FIFO_BYPASS;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001534
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001535 /* Check if the reset GPIO number is valid and request it */
1536 if (dac33->power_gpio >= 0) {
1537 ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset");
1538 if (ret < 0) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001539 dev_err(&client->dev,
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001540 "Failed to request reset GPIO (%d)\n",
1541 dac33->power_gpio);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001542 goto err_gpio;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001543 }
1544 gpio_direction_output(dac33->power_gpio, 0);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001545 }
1546
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +02001547 for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++)
1548 dac33->supplies[i].supply = dac33_supply_names[i];
1549
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001550 ret = regulator_bulk_get(&client->dev, ARRAY_SIZE(dac33->supplies),
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +02001551 dac33->supplies);
1552
1553 if (ret != 0) {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001554 dev_err(&client->dev, "Failed to request supplies: %d\n", ret);
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +02001555 goto err_get;
1556 }
1557
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001558 ret = snd_soc_register_codec(&client->dev,
1559 &soc_codec_dev_tlv320dac33, &dac33_dai, 1);
1560 if (ret < 0)
1561 goto err_register;
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001562
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001563 return ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001564err_register:
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +02001565 regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies);
1566err_get:
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001567 if (dac33->power_gpio >= 0)
1568 gpio_free(dac33->power_gpio);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001569err_gpio:
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001570 return ret;
1571}
1572
Bill Pemberton7a79e942012-12-07 09:26:37 -05001573static int dac33_i2c_remove(struct i2c_client *client)
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001574{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001575 struct tlv320dac33_priv *dac33 = i2c_get_clientdata(client);
Peter Ujfalusi239fe552010-04-30 14:59:34 +03001576
1577 if (unlikely(dac33->chip_power))
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001578 dac33_hard_power(dac33->codec, 0);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001579
1580 if (dac33->power_gpio >= 0)
1581 gpio_free(dac33->power_gpio);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001582
Ilkka Koskinen3a7aaed2009-12-04 13:49:10 +02001583 regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies);
1584
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001585 snd_soc_unregister_codec(&client->dev);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001586 return 0;
1587}
1588
1589static const struct i2c_device_id tlv320dac33_i2c_id[] = {
1590 {
1591 .name = "tlv320dac33",
1592 .driver_data = 0,
1593 },
1594 { },
1595};
Axel Lin573f26e2011-03-04 15:18:18 +08001596MODULE_DEVICE_TABLE(i2c, tlv320dac33_i2c_id);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001597
1598static struct i2c_driver tlv320dac33_i2c_driver = {
1599 .driver = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001600 .name = "tlv320dac33-codec",
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001601 .owner = THIS_MODULE,
1602 },
1603 .probe = dac33_i2c_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -05001604 .remove = dac33_i2c_remove,
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001605 .id_table = tlv320dac33_i2c_id,
1606};
1607
Sachin Kamat63a47a72012-08-06 17:25:44 +05301608module_i2c_driver(tlv320dac33_i2c_driver);
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001609
1610MODULE_DESCRIPTION("ASoC TLV320DAC33 codec driver");
Peter Ujfalusi93864cf2011-05-03 18:11:36 +03001611MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
Peter Ujfalusic8bf93f2009-10-15 09:03:56 +03001612MODULE_LICENSE("GPL");