board.d: merge ucidef_add_switch() and ucidef_add_switch_ports()
[openwrt/openwrt.git] / target / linux / mxs / patches-3.18 / 001-soc-audio-support.patch
1 From ef05a3ce8340c7156610b173324ab793b06e0ae2 Mon Sep 17 00:00:00 2001
2 From: Michal Ulianko <info@itserve.cz>
3 Date: Mon, 29 Jul 2013 20:14:38 +0200
4 Subject: [PATCH 1/2] Added ASoC driver for i.MX233's builtin ADC/DAC codec.
5
6 ---
7 sound/soc/codecs/Kconfig | 4 +
8 sound/soc/codecs/Makefile | 2 +
9 sound/soc/codecs/mxs-builtin-codec.c | 1128 ++++++++++++++++++++++++++++++++++
10 sound/soc/codecs/mxs-builtin-codec.h | 825 +++++++++++++++++++++++++
11 sound/soc/mxs/Kconfig | 10 +
12 sound/soc/mxs/Makefile | 9 +
13 sound/soc/mxs/mxs-builtin-audio.c | 120 ++++
14 sound/soc/mxs/mxs-builtin-dai.c | 588 ++++++++++++++++++
15 sound/soc/mxs/mxs-builtin-pcm.c | 69 +++
16 sound/soc/mxs/mxs-builtin-pcm.h | 25 +
17 10 files changed, 2780 insertions(+)
18 create mode 100644 sound/soc/codecs/mxs-builtin-codec.c
19 create mode 100644 sound/soc/codecs/mxs-builtin-codec.h
20 create mode 100644 sound/soc/mxs/mxs-builtin-audio.c
21 create mode 100644 sound/soc/mxs/mxs-builtin-dai.c
22 create mode 100644 sound/soc/mxs/mxs-builtin-pcm.c
23 create mode 100644 sound/soc/mxs/mxs-builtin-pcm.h
24
25 --- a/sound/soc/codecs/Kconfig
26 +++ b/sound/soc/codecs/Kconfig
27 @@ -164,6 +164,7 @@ config SND_SOC_ALL_CODECS
28 select SND_SOC_WM9705 if SND_SOC_AC97_BUS
29 select SND_SOC_WM9712 if SND_SOC_AC97_BUS
30 select SND_SOC_WM9713 if SND_SOC_AC97_BUS
31 + select SND_SOC_MXS_BUILTIN_CODEC
32 help
33 Normally ASoC codec drivers are only built if a machine driver which
34 uses them is also built since they are only usable with a machine
35 @@ -789,6 +790,9 @@ config SND_SOC_WM9712
36 config SND_SOC_WM9713
37 tristate
38
39 +config SND_SOC_MXS_BUILTIN_CODEC
40 + tristate
41 +
42 # Amp
43 config SND_SOC_LM4857
44 tristate
45 --- a/sound/soc/codecs/Makefile
46 +++ b/sound/soc/codecs/Makefile
47 @@ -166,6 +166,7 @@ snd-soc-wm9705-objs := wm9705.o
48 snd-soc-wm9712-objs := wm9712.o
49 snd-soc-wm9713-objs := wm9713.o
50 snd-soc-wm-hubs-objs := wm_hubs.o
51 +snd-soc-mxs-builtin-codec-objs := mxs-builtin-codec.o
52
53 # Amp
54 snd-soc-max9877-objs := max9877.o
55 @@ -339,6 +340,7 @@ obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-
56 obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o
57 obj-$(CONFIG_SND_SOC_WM_ADSP) += snd-soc-wm-adsp.o
58 obj-$(CONFIG_SND_SOC_WM_HUBS) += snd-soc-wm-hubs.o
59 +obj-$(CONFIG_SND_SOC_MXS_BUILTIN_CODEC) += snd-soc-mxs-builtin-codec.o
60
61 # Amp
62 obj-$(CONFIG_SND_SOC_MAX9877) += snd-soc-max9877.o
63 --- /dev/null
64 +++ b/sound/soc/codecs/mxs-builtin-codec.c
65 @@ -0,0 +1,1128 @@
66 +/*
67 + * mxs-builtin-codec.c -- i.MX233 built-in codec ALSA Soc Audio driver
68 + *
69 + * Author: Michal Ulianko <michal.ulianko@gmail.com>
70 + *
71 + * Based on sound/soc/codecs/mxs-adc-codec.c for kernel 2.6.35
72 + * by Vladislav Buzov <vbuzov@embeddedalley.com>
73 + *
74 + * This program is free software; you can redistribute it and/or modify
75 + * it under the terms of the GNU General Public License version 2 as
76 + * published by the Free Software Foundation.
77 + */
78 +
79 +#include <linux/clk.h>
80 +#include <linux/delay.h>
81 +#include <linux/module.h>
82 +#include <linux/platform_device.h>
83 +#include <sound/pcm.h>
84 +#include <sound/pcm_params.h>
85 +#include <sound/soc.h>
86 +
87 +#include "mxs-builtin-codec.h"
88 +
89 +#ifndef BF
90 +#define BF(value, field) (((value) << BP_##field) & BM_##field)
91 +#endif
92 +
93 +/* TODO Delete this and use BM_RTC_PERSISTENT0_RELEASE_GND from header file
94 + * if it works. */
95 +#define BP_RTC_PERSISTENT0_SPARE_ANALOG 18
96 +#define BM_RTC_PERSISTENT0_SPARE_ANALOG 0xFFFC0000
97 +#define BM_RTC_PERSISTENT0_RELEASE_GND BF(0x2, RTC_PERSISTENT0_SPARE_ANALOG)
98 +
99 +/* TODO Use codec IO function soc snd write etc, instead of __writel __readl */
100 +
101 +struct mxs_adc_priv {
102 + void __iomem *ain_base;
103 + void __iomem *aout_base;
104 + void __iomem *rtc_base;
105 + struct clk *clk;
106 +};
107 +
108 +static unsigned int mxs_regmap[] = {
109 + HW_AUDIOOUT_CTRL,
110 + HW_AUDIOOUT_STAT,
111 + HW_AUDIOOUT_DACSRR,
112 + HW_AUDIOOUT_DACVOLUME,
113 + HW_AUDIOOUT_DACDEBUG,
114 + HW_AUDIOOUT_HPVOL,
115 + HW_AUDIOOUT_PWRDN,
116 + HW_AUDIOOUT_REFCTRL,
117 + HW_AUDIOOUT_ANACTRL,
118 + HW_AUDIOOUT_TEST,
119 + HW_AUDIOOUT_BISTCTRL,
120 + HW_AUDIOOUT_BISTSTAT0,
121 + HW_AUDIOOUT_BISTSTAT1,
122 + HW_AUDIOOUT_ANACLKCTRL,
123 + HW_AUDIOOUT_DATA,
124 + HW_AUDIOOUT_SPEAKERCTRL,
125 + HW_AUDIOOUT_VERSION,
126 + HW_AUDIOIN_CTRL,
127 + HW_AUDIOIN_STAT,
128 + HW_AUDIOIN_ADCSRR,
129 + HW_AUDIOIN_ADCVOLUME,
130 + HW_AUDIOIN_ADCDEBUG,
131 + HW_AUDIOIN_ADCVOL,
132 + HW_AUDIOIN_MICLINE,
133 + HW_AUDIOIN_ANACLKCTRL,
134 + HW_AUDIOIN_DATA,
135 +};
136 +
137 +static void __iomem *mxs_getreg(struct mxs_adc_priv *mxs_adc, int i)
138 +{
139 + if (i <= 16)
140 + return mxs_adc->aout_base + mxs_regmap[i];
141 + else if (i < ADC_REGNUM)
142 + return mxs_adc->ain_base + mxs_regmap[i];
143 + else
144 + return NULL;
145 +}
146 +
147 +static u8 dac_volumn_control_word[] = {
148 + 0x37, 0x5e, 0x7e, 0x8e,
149 + 0x9e, 0xae, 0xb6, 0xbe,
150 + 0xc6, 0xce, 0xd6, 0xde,
151 + 0xe6, 0xee, 0xf6, 0xfe,
152 +};
153 +
154 +struct dac_srr {
155 + u32 rate;
156 + u32 basemult;
157 + u32 src_hold;
158 + u32 src_int;
159 + u32 src_frac;
160 +};
161 +
162 +static struct dac_srr srr_values[] = {
163 + {192000, 0x4, 0x0, 0x0F, 0x13FF},
164 + {176400, 0x4, 0x0, 0x11, 0x0037},
165 + {128000, 0x4, 0x0, 0x17, 0x0E00},
166 + {96000, 0x2, 0x0, 0x0F, 0x13FF},
167 + {88200, 0x2, 0x0, 0x11, 0x0037},
168 + {64000, 0x2, 0x0, 0x17, 0x0E00},
169 + {48000, 0x1, 0x0, 0x0F, 0x13FF},
170 + {44100, 0x1, 0x0, 0x11, 0x0037},
171 + {32000, 0x1, 0x0, 0x17, 0x0E00},
172 + {24000, 0x1, 0x1, 0x0F, 0x13FF},
173 + {22050, 0x1, 0x1, 0x11, 0x0037},
174 + {16000, 0x1, 0x1, 0x17, 0x0E00},
175 + {12000, 0x1, 0x3, 0x0F, 0x13FF},
176 + {11025, 0x1, 0x3, 0x11, 0x0037},
177 + {8000, 0x1, 0x3, 0x17, 0x0E00}
178 +};
179 +
180 +static inline int get_srr_values(int rate)
181 +{
182 + int i;
183 +
184 + for (i = 0; i < ARRAY_SIZE(srr_values); i++)
185 + if (srr_values[i].rate == rate)
186 + return i;
187 +
188 + return -1;
189 +}
190 +
191 +/* SoC IO functions */
192 +static void mxs_codec_write_cache(struct snd_soc_codec *codec, unsigned int reg, unsigned int value)
193 +{
194 + u16 *cache = codec->reg_cache;
195 + if (reg < ADC_REGNUM)
196 + cache[reg] = value;
197 +}
198 +
199 +static int mxs_codec_write(struct snd_soc_codec *codec, unsigned int reg, unsigned int value)
200 +{
201 + struct mxs_adc_priv *mxs_adc = snd_soc_codec_get_drvdata(codec);
202 + unsigned int reg_val;
203 + unsigned int mask = 0xffff;
204 +
205 + if (reg >= ADC_REGNUM)
206 + return -EIO;
207 +
208 + mxs_codec_write_cache(codec, reg, value);
209 +
210 + if (reg & 0x1) {
211 + mask <<= 16;
212 + value <<= 16;
213 + }
214 +
215 + reg_val = __raw_readl(mxs_getreg(mxs_adc, reg >> 1));
216 + reg_val = (reg_val & ~mask) | value;
217 + __raw_writel(reg_val, mxs_getreg(mxs_adc, reg >> 1));
218 +
219 + return 0;
220 +}
221 +
222 +static unsigned int mxs_codec_read(struct snd_soc_codec *codec, unsigned int reg)
223 +{
224 + struct mxs_adc_priv *mxs_adc = snd_soc_codec_get_drvdata(codec);
225 + unsigned int reg_val;
226 +
227 + if (reg >= ADC_REGNUM)
228 + return -1;
229 +
230 + reg_val = __raw_readl(mxs_getreg(mxs_adc, reg >> 1));
231 + if (reg & 1)
232 + reg_val >>= 16;
233 +
234 + return reg_val & 0xffff;
235 +}
236 +
237 +// static unsigned int mxs_codec_read_cache(struct snd_soc_codec *codec, unsigned int reg)
238 +// {
239 +// u16 *cache = codec->reg_cache;
240 +// if (reg >= ADC_REGNUM)
241 +// return -EINVAL;
242 +// return cache[reg];
243 +// }
244 +
245 +static void mxs_codec_sync_reg_cache(struct snd_soc_codec *codec)
246 +{
247 + int reg;
248 + for (reg = 0; reg < ADC_REGNUM; reg += 1)
249 + mxs_codec_write_cache(codec, reg,
250 + mxs_codec_read(codec, reg));
251 +}
252 +
253 +// static int mxs_codec_restore_reg(struct snd_soc_codec *codec, unsigned int reg)
254 +// {
255 +// unsigned int cached_val, hw_val;
256 +//
257 +// cached_val = mxs_codec_read_cache(codec, reg);
258 +// hw_val = mxs_codec_read(codec, reg);
259 +//
260 +// if (hw_val != cached_val)
261 +// return mxs_codec_write(codec, reg, cached_val);
262 +//
263 +// return 0;
264 +// }
265 +/* END SoC IO functions */
266 +
267 +/* Codec routines */
268 +#define VAG_BASE_VALUE ((1400/2 - 625)/25)
269 +
270 +static void mxs_codec_dac_set_vag(struct mxs_adc_priv *mxs_adc)
271 +{
272 + u32 refctrl_val = __raw_readl(mxs_adc->aout_base + HW_AUDIOOUT_REFCTRL);
273 +
274 + refctrl_val &= ~(BM_AUDIOOUT_REFCTRL_VAG_VAL);
275 + refctrl_val &= ~(BM_AUDIOOUT_REFCTRL_VBG_ADJ);
276 + refctrl_val |= BF(VAG_BASE_VALUE, AUDIOOUT_REFCTRL_VAG_VAL) |
277 + BM_AUDIOOUT_REFCTRL_ADJ_VAG |
278 + BF(0xF, AUDIOOUT_REFCTRL_ADC_REFVAL) |
279 + BM_AUDIOOUT_REFCTRL_ADJ_ADC |
280 + BF(0x3, AUDIOOUT_REFCTRL_VBG_ADJ) | BM_AUDIOOUT_REFCTRL_RAISE_REF;
281 +
282 + __raw_writel(refctrl_val, mxs_adc->aout_base + HW_AUDIOOUT_REFCTRL);
283 +}
284 +
285 +static bool mxs_codec_dac_is_capless(struct mxs_adc_priv *mxs_adc)
286 +{
287 + if ((__raw_readl(mxs_adc->aout_base + HW_AUDIOOUT_PWRDN)
288 + & BM_AUDIOOUT_PWRDN_CAPLESS) == 0)
289 + return false;
290 + else
291 + return true;
292 +}
293 +
294 +static void mxs_codec_dac_arm_short_cm(struct mxs_adc_priv *mxs_adc, bool bShort)
295 +{
296 + __raw_writel(BF(3, AUDIOOUT_ANACTRL_SHORTMODE_CM),
297 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL_CLR);
298 + __raw_writel(BM_AUDIOOUT_ANACTRL_SHORT_CM_STS,
299 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL_CLR);
300 + if (bShort)
301 + __raw_writel(BF(1, AUDIOOUT_ANACTRL_SHORTMODE_CM),
302 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL_SET);
303 +}
304 +
305 +static void mxs_codec_dac_arm_short_lr(struct mxs_adc_priv *mxs_adc, bool bShort)
306 +{
307 + __raw_writel(BF(3, AUDIOOUT_ANACTRL_SHORTMODE_LR),
308 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL_CLR);
309 + __raw_writel(BM_AUDIOOUT_ANACTRL_SHORT_LR_STS,
310 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL_CLR);
311 + if (bShort)
312 + __raw_writel(BF(1, AUDIOOUT_ANACTRL_SHORTMODE_LR),
313 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL_SET);
314 +}
315 +
316 +static void mxs_codec_dac_set_short_trip_level(struct mxs_adc_priv *mxs_adc, u8 u8level)
317 +{
318 + __raw_writel(__raw_readl(mxs_adc->aout_base +
319 + HW_AUDIOOUT_ANACTRL)
320 + & (~BM_AUDIOOUT_ANACTRL_SHORT_LVLADJL)
321 + & (~BM_AUDIOOUT_ANACTRL_SHORT_LVLADJR)
322 + | BF(u8level, AUDIOOUT_ANACTRL_SHORT_LVLADJL)
323 + | BF(u8level, AUDIOOUT_ANACTRL_SHORT_LVLADJR),
324 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL);
325 +}
326 +
327 +static void mxs_codec_dac_arm_short(struct mxs_adc_priv *mxs_adc, bool bLatchCM, bool bLatchLR)
328 +{
329 + if (bLatchCM) {
330 + if (mxs_codec_dac_is_capless(mxs_adc))
331 + mxs_codec_dac_arm_short_cm(mxs_adc, true);
332 + } else
333 + mxs_codec_dac_arm_short_cm(mxs_adc, false);
334 +
335 + if (bLatchLR)
336 + mxs_codec_dac_arm_short_lr(mxs_adc, true);
337 + else
338 + mxs_codec_dac_arm_short_lr(mxs_adc, false);
339 +}
340 +
341 +static void
342 +mxs_codec_dac_power_on(struct mxs_adc_priv *mxs_adc)
343 +{
344 + /* Ungate DAC clocks */
345 + __raw_writel(BM_AUDIOOUT_CTRL_CLKGATE,
346 + mxs_adc->aout_base + HW_AUDIOOUT_CTRL_CLR);
347 + __raw_writel(BM_AUDIOOUT_ANACLKCTRL_CLKGATE,
348 + mxs_adc->aout_base + HW_AUDIOOUT_ANACLKCTRL_CLR);
349 +
350 + /* 16 bit word length */
351 + __raw_writel(BM_AUDIOOUT_CTRL_WORD_LENGTH,
352 + mxs_adc->aout_base + HW_AUDIOOUT_CTRL_SET);
353 +
354 + /* Arm headphone LR short protect */
355 + mxs_codec_dac_set_short_trip_level(mxs_adc, 0);
356 + mxs_codec_dac_arm_short(mxs_adc, false, true);
357 +
358 + /* Update DAC volume over zero crossings */
359 + __raw_writel(BM_AUDIOOUT_DACVOLUME_EN_ZCD,
360 + mxs_adc->aout_base + HW_AUDIOOUT_DACVOLUME_SET);
361 + /* Mute DAC */
362 + __raw_writel(BM_AUDIOOUT_DACVOLUME_MUTE_LEFT |
363 + BM_AUDIOOUT_DACVOLUME_MUTE_RIGHT,
364 + mxs_adc->aout_base + HW_AUDIOOUT_DACVOLUME_SET);
365 +
366 + /* Update HP volume over zero crossings */
367 + __raw_writel(BM_AUDIOOUT_HPVOL_EN_MSTR_ZCD,
368 + mxs_adc->aout_base + HW_AUDIOOUT_HPVOL_SET);
369 +
370 + __raw_writel(BM_AUDIOOUT_ANACTRL_HP_CLASSAB,
371 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL_SET);
372 +
373 + /* Mute HP output */
374 + __raw_writel(BM_AUDIOOUT_HPVOL_MUTE,
375 + mxs_adc->aout_base + HW_AUDIOOUT_HPVOL_SET);
376 + /* Mute speaker amp */
377 + __raw_writel(BM_AUDIOOUT_SPEAKERCTRL_MUTE,
378 + mxs_adc->aout_base + HW_AUDIOOUT_SPEAKERCTRL_SET);
379 + /* Enable the audioout */
380 + __raw_writel(BM_AUDIOOUT_CTRL_RUN,
381 + mxs_adc->aout_base + HW_AUDIOOUT_CTRL_SET);
382 +}
383 +
384 +static void
385 +mxs_codec_dac_power_down(struct mxs_adc_priv *mxs_adc)
386 +{
387 + /* Disable the audioout */
388 + __raw_writel(BM_AUDIOOUT_CTRL_RUN,
389 + mxs_adc->aout_base + HW_AUDIOOUT_CTRL_CLR);
390 + /* Disable class AB */
391 + __raw_writel(BM_AUDIOOUT_ANACTRL_HP_CLASSAB,
392 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL_CLR);
393 +
394 + /* Set hold to ground */
395 + __raw_writel(BM_AUDIOOUT_ANACTRL_HP_HOLD_GND,
396 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL_SET);
397 +
398 + /* Mute HP output */
399 + __raw_writel(BM_AUDIOOUT_HPVOL_MUTE,
400 + mxs_adc->aout_base + HW_AUDIOOUT_HPVOL_SET);
401 + /* Power down HP output */
402 + __raw_writel(BM_AUDIOOUT_PWRDN_HEADPHONE,
403 + mxs_adc->aout_base + HW_AUDIOOUT_PWRDN_SET);
404 +
405 + /* Mute speaker amp */
406 + __raw_writel(BM_AUDIOOUT_SPEAKERCTRL_MUTE,
407 + mxs_adc->aout_base + HW_AUDIOOUT_SPEAKERCTRL_SET);
408 + /* Power down speaker amp */
409 + __raw_writel(BM_AUDIOOUT_PWRDN_SPEAKER,
410 + mxs_adc->aout_base + HW_AUDIOOUT_PWRDN_SET);
411 +
412 + /* Mute DAC */
413 + __raw_writel(BM_AUDIOOUT_DACVOLUME_MUTE_LEFT |
414 + BM_AUDIOOUT_DACVOLUME_MUTE_RIGHT,
415 + mxs_adc->aout_base + HW_AUDIOOUT_DACVOLUME_SET);
416 + /* Power down DAC */
417 + __raw_writel(BM_AUDIOOUT_PWRDN_DAC,
418 + mxs_adc->aout_base + HW_AUDIOOUT_PWRDN_SET);
419 +
420 + /* Gate DAC clocks */
421 + __raw_writel(BM_AUDIOOUT_ANACLKCTRL_CLKGATE,
422 + mxs_adc->aout_base + HW_AUDIOOUT_ANACLKCTRL_SET);
423 + __raw_writel(BM_AUDIOOUT_CTRL_CLKGATE,
424 + mxs_adc->aout_base + HW_AUDIOOUT_CTRL_SET);
425 +}
426 +
427 +static void
428 +mxs_codec_adc_power_on(struct mxs_adc_priv *mxs_adc)
429 +{
430 + u32 reg;
431 +
432 + /* Ungate ADC clocks */
433 + __raw_writel(BM_AUDIOIN_CTRL_CLKGATE,
434 + mxs_adc->ain_base + HW_AUDIOIN_CTRL_CLR);
435 + __raw_writel(BM_AUDIOIN_ANACLKCTRL_CLKGATE,
436 + mxs_adc->ain_base + HW_AUDIOIN_ANACLKCTRL_CLR);
437 +
438 + /* 16 bit word length */
439 + __raw_writel(BM_AUDIOIN_CTRL_WORD_LENGTH,
440 + mxs_adc->ain_base + HW_AUDIOIN_CTRL_SET);
441 +
442 + /* Unmute ADC channels */
443 + __raw_writel(BM_AUDIOIN_ADCVOL_MUTE,
444 + mxs_adc->ain_base + HW_AUDIOIN_ADCVOL_CLR);
445 +
446 + /*
447 + * The MUTE_LEFT and MUTE_RIGHT fields need to be cleared.
448 + * They aren't presented in the datasheet, so this is hardcode.
449 + */
450 + __raw_writel(0x01000100, mxs_adc->ain_base + HW_AUDIOIN_ADCVOLUME_CLR);
451 +
452 + /* Set the Input channel gain 3dB */
453 + __raw_writel(BM_AUDIOIN_ADCVOL_GAIN_LEFT,
454 + mxs_adc->ain_base + HW_AUDIOIN_ADCVOL_CLR);
455 + __raw_writel(BM_AUDIOIN_ADCVOL_GAIN_RIGHT,
456 + mxs_adc->ain_base + HW_AUDIOIN_ADCVOL_CLR);
457 + __raw_writel(BF(2, AUDIOIN_ADCVOL_GAIN_LEFT),
458 + mxs_adc->ain_base + HW_AUDIOIN_ADCVOL_SET);
459 + __raw_writel(BF(2, AUDIOIN_ADCVOL_GAIN_RIGHT),
460 + mxs_adc->ain_base + HW_AUDIOIN_ADCVOL_SET);
461 +
462 + /* Select default input - Microphone */
463 + __raw_writel(BM_AUDIOIN_ADCVOL_SELECT_LEFT,
464 + mxs_adc->ain_base + HW_AUDIOIN_ADCVOL_CLR);
465 + __raw_writel(BM_AUDIOIN_ADCVOL_SELECT_RIGHT,
466 + mxs_adc->ain_base + HW_AUDIOIN_ADCVOL_CLR);
467 + __raw_writel(BF
468 + (BV_AUDIOIN_ADCVOL_SELECT__MIC,
469 + AUDIOIN_ADCVOL_SELECT_LEFT),
470 + mxs_adc->ain_base + HW_AUDIOIN_ADCVOL_SET);
471 + __raw_writel(BF
472 + (BV_AUDIOIN_ADCVOL_SELECT__MIC,
473 + AUDIOIN_ADCVOL_SELECT_RIGHT),
474 + mxs_adc->ain_base + HW_AUDIOIN_ADCVOL_SET);
475 +
476 + /* Supply bias voltage to microphone */
477 + __raw_writel(BF(1, AUDIOIN_MICLINE_MIC_RESISTOR),
478 + mxs_adc->ain_base + HW_AUDIOIN_MICLINE_SET);
479 + __raw_writel(BM_AUDIOIN_MICLINE_MIC_SELECT,
480 + mxs_adc->ain_base + HW_AUDIOIN_MICLINE_SET);
481 + __raw_writel(BF(1, AUDIOIN_MICLINE_MIC_GAIN),
482 + mxs_adc->ain_base + HW_AUDIOIN_MICLINE_SET);
483 + __raw_writel(BF(7, AUDIOIN_MICLINE_MIC_BIAS),
484 + mxs_adc->ain_base + HW_AUDIOIN_MICLINE_SET);
485 +
486 + /* Set max ADC volume */
487 + reg = __raw_readl(mxs_adc->ain_base + HW_AUDIOIN_ADCVOLUME);
488 + reg &= ~BM_AUDIOIN_ADCVOLUME_VOLUME_LEFT;
489 + reg &= ~BM_AUDIOIN_ADCVOLUME_VOLUME_RIGHT;
490 + reg |= BF(ADC_VOLUME_MAX, AUDIOIN_ADCVOLUME_VOLUME_LEFT);
491 + reg |= BF(ADC_VOLUME_MAX, AUDIOIN_ADCVOLUME_VOLUME_RIGHT);
492 + __raw_writel(reg, mxs_adc->ain_base + HW_AUDIOIN_ADCVOLUME);
493 +}
494 +
495 +static void
496 +mxs_codec_adc_power_down(struct mxs_adc_priv *mxs_adc)
497 +{
498 + /* Mute ADC channels */
499 + __raw_writel(BM_AUDIOIN_ADCVOL_MUTE,
500 + mxs_adc->ain_base + HW_AUDIOIN_ADCVOL_SET);
501 +
502 + /* Power Down ADC */
503 + __raw_writel(BM_AUDIOOUT_PWRDN_ADC | BM_AUDIOOUT_PWRDN_RIGHT_ADC,
504 + mxs_adc->aout_base + HW_AUDIOOUT_PWRDN_SET);
505 +
506 + /* Gate ADC clocks */
507 + __raw_writel(BM_AUDIOIN_CTRL_CLKGATE,
508 + mxs_adc->ain_base + HW_AUDIOIN_CTRL_SET);
509 + __raw_writel(BM_AUDIOIN_ANACLKCTRL_CLKGATE,
510 + mxs_adc->ain_base + HW_AUDIOIN_ANACLKCTRL_SET);
511 +
512 + /* Disable bias voltage to microphone */
513 + __raw_writel(BF(0, AUDIOIN_MICLINE_MIC_RESISTOR),
514 + mxs_adc->ain_base + HW_AUDIOIN_MICLINE_SET);
515 +}
516 +
517 +static void mxs_codec_dac_enable(struct mxs_adc_priv *mxs_adc)
518 +{
519 + /* Move DAC codec out of reset */
520 + __raw_writel(BM_AUDIOOUT_CTRL_SFTRST,
521 + mxs_adc->aout_base + HW_AUDIOOUT_CTRL_CLR);
522 +
523 + /* Reduce analog power */
524 + __raw_writel(BM_AUDIOOUT_TEST_HP_I1_ADJ,
525 + mxs_adc->aout_base + HW_AUDIOOUT_TEST_CLR);
526 + __raw_writel(BF(0x1, AUDIOOUT_TEST_HP_I1_ADJ),
527 + mxs_adc->aout_base + HW_AUDIOOUT_TEST_SET);
528 + __raw_writel(BM_AUDIOOUT_REFCTRL_LOW_PWR,
529 + mxs_adc->aout_base + HW_AUDIOOUT_REFCTRL_SET);
530 + __raw_writel(BM_AUDIOOUT_REFCTRL_XTAL_BGR_BIAS,
531 + mxs_adc->aout_base + HW_AUDIOOUT_REFCTRL_SET);
532 + __raw_writel(BM_AUDIOOUT_REFCTRL_BIAS_CTRL,
533 + mxs_adc->aout_base + HW_AUDIOOUT_REFCTRL_CLR);
534 + __raw_writel(BF(0x1, AUDIOOUT_REFCTRL_BIAS_CTRL),
535 + mxs_adc->aout_base + HW_AUDIOOUT_REFCTRL_CLR);
536 +
537 + /* Set Vag value */
538 + mxs_codec_dac_set_vag(mxs_adc);
539 +
540 + /* Power on DAC codec */
541 + mxs_codec_dac_power_on(mxs_adc);
542 +}
543 +
544 +static void mxs_codec_dac_disable(struct mxs_adc_priv *mxs_adc)
545 +{
546 + mxs_codec_dac_power_down(mxs_adc);
547 +}
548 +
549 +static void mxs_codec_adc_enable(struct mxs_adc_priv *mxs_adc)
550 +{
551 + /* Move ADC codec out of reset */
552 + __raw_writel(BM_AUDIOIN_CTRL_SFTRST,
553 + mxs_adc->ain_base + HW_AUDIOIN_CTRL_CLR);
554 +
555 + /* Power on ADC codec */
556 + mxs_codec_adc_power_on(mxs_adc);
557 +}
558 +
559 +static void mxs_codec_adc_disable(struct mxs_adc_priv *mxs_adc)
560 +{
561 + mxs_codec_adc_power_down(mxs_adc);
562 +}
563 +
564 +static void mxs_codec_startup(struct snd_soc_codec *codec)
565 +{
566 + struct mxs_adc_priv *mxs_adc = snd_soc_codec_get_drvdata(codec);
567 +
568 + /* Soft reset DAC block */
569 + __raw_writel(BM_AUDIOOUT_CTRL_SFTRST,
570 + mxs_adc->aout_base + HW_AUDIOOUT_CTRL_SET);
571 + while (!(__raw_readl(mxs_adc->aout_base + HW_AUDIOOUT_CTRL)
572 + & BM_AUDIOOUT_CTRL_CLKGATE)){
573 + }
574 +
575 + /* Soft reset ADC block */
576 + __raw_writel(BM_AUDIOIN_CTRL_SFTRST,
577 + mxs_adc->ain_base + HW_AUDIOIN_CTRL_SET);
578 + while (!(__raw_readl(mxs_adc->ain_base + HW_AUDIOIN_CTRL)
579 + & BM_AUDIOIN_CTRL_CLKGATE)){
580 + }
581 +
582 + mxs_codec_dac_enable(mxs_adc);
583 + mxs_codec_adc_enable(mxs_adc);
584 +
585 + /* Sync regs and cache */
586 + mxs_codec_sync_reg_cache(codec);
587 +}
588 +
589 +static void mxs_codec_stop(struct snd_soc_codec *codec)
590 +{
591 + struct mxs_adc_priv *mxs_adc = snd_soc_codec_get_drvdata(codec);
592 +
593 + mxs_codec_dac_disable(mxs_adc);
594 + mxs_codec_adc_disable(mxs_adc);
595 +}
596 +/* END Codec routines */
597 +
598 +/* kcontrol */
599 +static int dac_info_volsw(struct snd_kcontrol *kcontrol,
600 + struct snd_ctl_elem_info *uinfo)
601 +{
602 + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
603 + uinfo->count = 2;
604 + uinfo->value.integer.min = 0;
605 + uinfo->value.integer.max = 0xf;
606 + return 0;
607 +}
608 +
609 +static int dac_get_volsw(struct snd_kcontrol *kcontrol,
610 + struct snd_ctl_elem_value *ucontrol)
611 +{
612 + struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
613 + struct mxs_adc_priv *mxs_adc = snd_soc_codec_get_drvdata(codec);
614 + int reg, l, r;
615 + int i;
616 +
617 + reg = __raw_readl(mxs_adc->aout_base + HW_AUDIOOUT_DACVOLUME);
618 +
619 + l = (reg & BM_AUDIOOUT_DACVOLUME_VOLUME_LEFT) >>
620 + BP_AUDIOOUT_DACVOLUME_VOLUME_LEFT;
621 + r = (reg & BM_AUDIOOUT_DACVOLUME_VOLUME_RIGHT) >>
622 + BP_AUDIOOUT_DACVOLUME_VOLUME_RIGHT;
623 + /*Left channel */
624 + i = 0;
625 + while (i < 16) {
626 + if (l == dac_volumn_control_word[i]) {
627 + ucontrol->value.integer.value[0] = i;
628 + break;
629 + }
630 + i++;
631 + }
632 + if (i == 16)
633 + ucontrol->value.integer.value[0] = i;
634 + /*Right channel */
635 + i = 0;
636 + while (i < 16) {
637 + if (r == dac_volumn_control_word[i]) {
638 + ucontrol->value.integer.value[1] = i;
639 + break;
640 + }
641 + i++;
642 + }
643 + if (i == 16)
644 + ucontrol->value.integer.value[1] = i;
645 +
646 + return 0;
647 +}
648 +
649 +static int dac_put_volsw(struct snd_kcontrol *kcontrol,
650 + struct snd_ctl_elem_value *ucontrol)
651 +{
652 + struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
653 + struct mxs_adc_priv *mxs_adc = snd_soc_codec_get_drvdata(codec);
654 + int reg, l, r;
655 + int i;
656 +
657 + i = ucontrol->value.integer.value[0];
658 + l = dac_volumn_control_word[i];
659 + /*Get dac volume for left channel */
660 + reg = BF(l, AUDIOOUT_DACVOLUME_VOLUME_LEFT);
661 +
662 + i = ucontrol->value.integer.value[1];
663 + r = dac_volumn_control_word[i];
664 + /*Get dac volume for right channel */
665 + reg = reg | BF(r, AUDIOOUT_DACVOLUME_VOLUME_RIGHT);
666 +
667 + /*Clear left/right dac volume */
668 + __raw_writel(BM_AUDIOOUT_DACVOLUME_VOLUME_LEFT |
669 + BM_AUDIOOUT_DACVOLUME_VOLUME_RIGHT,
670 + mxs_adc->aout_base + HW_AUDIOOUT_DACVOLUME_CLR);
671 + __raw_writel(reg, mxs_adc->aout_base + HW_AUDIOOUT_DACVOLUME_SET);
672 +
673 + return 0;
674 +}
675 +
676 +static const char *mxs_codec_adc_input_sel[] = {
677 + "Mic", "Line In 1", "Head Phone", "Line In 2" };
678 +
679 +static const char *mxs_codec_hp_output_sel[] = { "DAC Out", "Line In 1" };
680 +
681 +static const char *mxs_codec_adc_3d_sel[] = {
682 + "Off", "Low", "Medium", "High" };
683 +
684 +static const struct soc_enum mxs_codec_enum[] = {
685 + SOC_ENUM_SINGLE(ADC_ADCVOL_L, 12, 4, mxs_codec_adc_input_sel),
686 + SOC_ENUM_SINGLE(ADC_ADCVOL_L, 4, 4, mxs_codec_adc_input_sel),
687 + SOC_ENUM_SINGLE(DAC_HPVOL_H, 0, 2, mxs_codec_hp_output_sel),
688 + SOC_ENUM_SINGLE(DAC_CTRL_L, 8, 4, mxs_codec_adc_3d_sel),
689 +};
690 +
691 +static const struct snd_kcontrol_new mxs_snd_controls[] = {
692 + /* Playback Volume */
693 + {
694 + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
695 + .name = "DAC Playback Volume",
696 + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
697 + SNDRV_CTL_ELEM_ACCESS_VOLATILE,
698 + .info = dac_info_volsw,
699 + .get = dac_get_volsw,
700 + .put = dac_put_volsw,
701 + },
702 +
703 + SOC_DOUBLE_R("DAC Playback Switch",
704 + DAC_VOLUME_H, DAC_VOLUME_L, 8, 0x01, 1),
705 + SOC_DOUBLE("HP Playback Volume", DAC_HPVOL_L, 8, 0, 0x7F, 1),
706 +
707 + /* Capture Volume */
708 + SOC_DOUBLE_R("ADC Capture Volume",
709 + ADC_VOLUME_H, ADC_VOLUME_L, 0, 0xFF, 0),
710 + SOC_DOUBLE("ADC PGA Capture Volume", ADC_ADCVOL_L, 8, 0, 0x0F, 0),
711 + SOC_SINGLE("ADC PGA Capture Switch", ADC_ADCVOL_H, 8, 0x1, 1),
712 + SOC_SINGLE("Mic PGA Capture Volume", ADC_MICLINE_L, 0, 0x03, 0),
713 +
714 + /* Virtual 3D effect */
715 + SOC_ENUM("3D effect", mxs_codec_enum[3]),
716 +};
717 +/* END kcontrol */
718 +
719 +/* DAPM */
720 +static int pga_event(struct snd_soc_dapm_widget *w,
721 + struct snd_kcontrol *kcontrol, int event)
722 +{
723 + struct mxs_adc_priv *mxs_adc = snd_soc_codec_get_drvdata(w->codec);
724 +
725 + switch (event) {
726 + case SND_SOC_DAPM_PRE_PMU:
727 + /* Prepare powering up HP and SPEAKER output */
728 + __raw_writel(BM_AUDIOOUT_ANACTRL_HP_HOLD_GND,
729 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL_SET);
730 + __raw_writel(BM_RTC_PERSISTENT0_RELEASE_GND,
731 + mxs_adc->rtc_base + HW_RTC_PERSISTENT0_SET);
732 + msleep(100);
733 + break;
734 + case SND_SOC_DAPM_POST_PMU:
735 + __raw_writel(BM_AUDIOOUT_ANACTRL_HP_HOLD_GND,
736 + mxs_adc->aout_base + HW_AUDIOOUT_ANACTRL_CLR);
737 + break;
738 + case SND_SOC_DAPM_POST_PMD:
739 + __raw_writel(BM_RTC_PERSISTENT0_RELEASE_GND,
740 + mxs_adc->rtc_base + HW_RTC_PERSISTENT0_CLR);
741 + break;
742 + }
743 + return 0;
744 +}
745 +
746 +static int adc_event(struct snd_soc_dapm_widget *w,
747 + struct snd_kcontrol *kcontrol, int event)
748 +{
749 + struct mxs_adc_priv *mxs_adc = snd_soc_codec_get_drvdata(w->codec);
750 +
751 + switch (event) {
752 + case SND_SOC_DAPM_PRE_PMU:
753 + __raw_writel(BM_RTC_PERSISTENT0_RELEASE_GND,
754 + mxs_adc->rtc_base + HW_RTC_PERSISTENT0_SET);
755 + msleep(100);
756 + break;
757 + case SND_SOC_DAPM_POST_PMD:
758 + __raw_writel(BM_RTC_PERSISTENT0_RELEASE_GND,
759 + mxs_adc->rtc_base + HW_RTC_PERSISTENT0_CLR);
760 + break;
761 + }
762 + return 0;
763 +}
764 +
765 +/* Left ADC Mux */
766 +static const struct snd_kcontrol_new mxs_left_adc_controls =
767 +SOC_DAPM_ENUM("Route", mxs_codec_enum[0]);
768 +
769 +/* Right ADC Mux */
770 +static const struct snd_kcontrol_new mxs_right_adc_controls =
771 +SOC_DAPM_ENUM("Route", mxs_codec_enum[1]);
772 +
773 +/* Head Phone Mux */
774 +static const struct snd_kcontrol_new mxs_hp_controls =
775 +SOC_DAPM_ENUM("Route", mxs_codec_enum[2]);
776 +
777 +static const struct snd_soc_dapm_widget mxs_dapm_widgets[] = {
778 + SND_SOC_DAPM_ADC_E("ADC", "Capture", DAC_PWRDN_L, 8, 1, adc_event,
779 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
780 +
781 + SND_SOC_DAPM_DAC("DAC", "Playback", DAC_PWRDN_L, 12, 1),
782 +
783 + SND_SOC_DAPM_MUX("Left ADC Mux", SND_SOC_NOPM, 0, 0,
784 + &mxs_left_adc_controls),
785 + SND_SOC_DAPM_MUX("Right ADC Mux", SND_SOC_NOPM, 0, 0,
786 + &mxs_right_adc_controls),
787 + SND_SOC_DAPM_MUX("HP Mux", SND_SOC_NOPM, 0, 0,
788 + &mxs_hp_controls),
789 + SND_SOC_DAPM_PGA_E("HP AMP", DAC_PWRDN_L, 0, 1, NULL, 0, pga_event,
790 + SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
791 + SND_SOC_DAPM_POST_PMD),
792 + SND_SOC_DAPM_PGA("SPEAKER AMP", DAC_PWRDN_H, 8, 1, NULL, 0),
793 + SND_SOC_DAPM_INPUT("LINE1L"),
794 + SND_SOC_DAPM_INPUT("LINE1R"),
795 + SND_SOC_DAPM_INPUT("LINE2L"),
796 + SND_SOC_DAPM_INPUT("LINE2R"),
797 + SND_SOC_DAPM_INPUT("MIC"),
798 +
799 + SND_SOC_DAPM_OUTPUT("SPEAKER"),
800 + SND_SOC_DAPM_OUTPUT("HPL"),
801 + SND_SOC_DAPM_OUTPUT("HPR"),
802 +};
803 +
804 +/* routes for sgtl5000 */
805 +static const struct snd_soc_dapm_route mxs_dapm_routes[] = {
806 + /* Left ADC Mux */
807 + {"Left ADC Mux", "Mic", "MIC"},
808 + {"Left ADC Mux", "Line In 1", "LINE1L"},
809 + {"Left ADC Mux", "Line In 2", "LINE2L"},
810 + {"Left ADC Mux", "Head Phone", "HPL"},
811 +
812 + /* Right ADC Mux */
813 + {"Right ADC Mux", "Mic", "MIC"},
814 + {"Right ADC Mux", "Line In 1", "LINE1R"},
815 + {"Right ADC Mux", "Line In 2", "LINE2R"},
816 + {"Right ADC Mux", "Head Phone", "HPR"},
817 +
818 + /* ADC */
819 + {"ADC", NULL, "Left ADC Mux"},
820 + {"ADC", NULL, "Right ADC Mux"},
821 +
822 + /* HP Mux */
823 + {"HP Mux", "DAC Out", "DAC"},
824 + {"HP Mux", "Line In 1", "LINE1L"},
825 + {"HP Mux", "Line In 1", "LINE1R"},
826 +
827 + /* HP amp */
828 + {"HP AMP", NULL, "HP Mux"},
829 + /* HP output */
830 + {"HPR", NULL, "HP AMP"},
831 + {"HPL", NULL, "HP AMP"},
832 +
833 + /* Speaker amp */
834 + {"SPEAKER AMP", NULL, "DAC"},
835 + {"SPEAKER", NULL, "SPEAKER AMP"},
836 +};
837 +/* END DAPM */
838 +
839 +static int mxs_set_bias_level(struct snd_soc_codec *codec,
840 + enum snd_soc_bias_level level)
841 +{
842 + struct mxs_adc_priv *mxs_adc = snd_soc_codec_get_drvdata(codec);
843 +
844 + pr_debug("dapm level %d\n", level);
845 + switch (level) {
846 + case SND_SOC_BIAS_ON: /* full On */
847 + if (codec->dapm.bias_level == SND_SOC_BIAS_ON)
848 + break;
849 + break;
850 +
851 + case SND_SOC_BIAS_PREPARE: /* partial On */
852 + if (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE)
853 + break;
854 + /* Set Capless mode */
855 + __raw_writel(BM_AUDIOOUT_PWRDN_CAPLESS,
856 + mxs_adc->aout_base + HW_AUDIOOUT_PWRDN_CLR);
857 + break;
858 +
859 + case SND_SOC_BIAS_STANDBY: /* Off, with power */
860 + if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY)
861 + break;
862 + /* Unset Capless mode */
863 + __raw_writel(BM_AUDIOOUT_PWRDN_CAPLESS,
864 + mxs_adc->aout_base + HW_AUDIOOUT_PWRDN_SET);
865 + break;
866 +
867 + case SND_SOC_BIAS_OFF: /* Off, without power */
868 + if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
869 + break;
870 + /* Unset Capless mode */
871 + __raw_writel(BM_AUDIOOUT_PWRDN_CAPLESS,
872 + mxs_adc->aout_base + HW_AUDIOOUT_PWRDN_SET);
873 + break;
874 + }
875 +
876 + codec->dapm.bias_level = level;
877 + return 0;
878 +}
879 +
880 +/* MXS-ADC Codec DAI driver */
881 +static int mxs_pcm_hw_params(struct snd_pcm_substream *substream,
882 + struct snd_pcm_hw_params *params,
883 + struct snd_soc_dai *dai)
884 +{
885 + struct snd_soc_codec *codec = dai->codec;
886 + struct mxs_adc_priv *mxs_adc = snd_soc_codec_get_drvdata(codec);
887 + int playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0;
888 + int i;
889 + u32 srr_value = 0;
890 + u32 src_hold = 0;
891 +
892 + i = get_srr_values(params_rate(params));
893 + if (i < 0)
894 + dev_warn(codec->dev, "codec doesn't support rate %d\n",
895 + params_rate(params));
896 + else {
897 + src_hold = srr_values[i].src_hold;
898 +
899 + srr_value =
900 + BF(srr_values[i].basemult, AUDIOOUT_DACSRR_BASEMULT) |
901 + BF(srr_values[i].src_int, AUDIOOUT_DACSRR_SRC_INT) |
902 + BF(srr_values[i].src_frac, AUDIOOUT_DACSRR_SRC_FRAC) |
903 + BF(src_hold, AUDIOOUT_DACSRR_SRC_HOLD);
904 +
905 + if (playback)
906 + __raw_writel(srr_value,
907 + mxs_adc->aout_base + HW_AUDIOOUT_DACSRR);
908 + else
909 + __raw_writel(srr_value,
910 + mxs_adc->ain_base + HW_AUDIOIN_ADCSRR);
911 + }
912 +
913 + switch (params_format(params)) {
914 + case SNDRV_PCM_FORMAT_S16_LE:
915 + if (playback)
916 + __raw_writel(BM_AUDIOOUT_CTRL_WORD_LENGTH,
917 + mxs_adc->aout_base + HW_AUDIOOUT_CTRL_SET);
918 + else
919 + __raw_writel(BM_AUDIOIN_CTRL_WORD_LENGTH,
920 + mxs_adc->ain_base + HW_AUDIOIN_CTRL_SET);
921 +
922 + break;
923 +
924 + case SNDRV_PCM_FORMAT_S32_LE:
925 + if (playback)
926 + __raw_writel(BM_AUDIOOUT_CTRL_WORD_LENGTH,
927 + mxs_adc->aout_base + HW_AUDIOOUT_CTRL_CLR);
928 + else
929 + __raw_writel(BM_AUDIOIN_CTRL_WORD_LENGTH,
930 + mxs_adc->ain_base + HW_AUDIOIN_CTRL_CLR);
931 +
932 + break;
933 +
934 + default:
935 + dev_warn(codec->dev, "codec doesn't support format %d\n",
936 + params_format(params));
937 +
938 + }
939 +
940 + return 0;
941 +}
942 +
943 +/* mute the codec used by alsa core */
944 +static int mxs_codec_dig_mute(struct snd_soc_dai *codec_dai, int mute)
945 +{
946 + struct mxs_adc_priv *mxs_adc = snd_soc_codec_get_drvdata(codec_dai->codec);
947 + int l, r;
948 + int ll, rr;
949 + u32 reg, reg1, reg2;
950 + u32 dac_mask = BM_AUDIOOUT_DACVOLUME_MUTE_LEFT |
951 + BM_AUDIOOUT_DACVOLUME_MUTE_RIGHT;
952 +
953 + if (mute) {
954 + reg = __raw_readl(mxs_adc->aout_base + \
955 + HW_AUDIOOUT_DACVOLUME);
956 +
957 + reg1 = reg & ~BM_AUDIOOUT_DACVOLUME_VOLUME_LEFT;
958 + reg1 = reg1 & ~BM_AUDIOOUT_DACVOLUME_VOLUME_RIGHT;
959 +
960 + l = (reg & BM_AUDIOOUT_DACVOLUME_VOLUME_LEFT) >>
961 + BP_AUDIOOUT_DACVOLUME_VOLUME_LEFT;
962 + r = (reg & BM_AUDIOOUT_DACVOLUME_VOLUME_RIGHT) >>
963 + BP_AUDIOOUT_DACVOLUME_VOLUME_RIGHT;
964 +
965 + /* fade out dac vol */
966 + while ((l > DAC_VOLUME_MIN) || (r > DAC_VOLUME_MIN)) {
967 + l -= 0x8;
968 + r -= 0x8;
969 + ll = l > DAC_VOLUME_MIN ? l : DAC_VOLUME_MIN;
970 + rr = r > DAC_VOLUME_MIN ? r : DAC_VOLUME_MIN;
971 + reg2 = reg1 | BF_AUDIOOUT_DACVOLUME_VOLUME_LEFT(ll)
972 + | BF_AUDIOOUT_DACVOLUME_VOLUME_RIGHT(rr);
973 + __raw_writel(reg2,
974 + mxs_adc->aout_base + HW_AUDIOOUT_DACVOLUME);
975 + msleep(1);
976 + }
977 +
978 + __raw_writel(dac_mask,
979 + mxs_adc->aout_base + HW_AUDIOOUT_DACVOLUME_SET);
980 + reg = reg | dac_mask;
981 + __raw_writel(reg,
982 + mxs_adc->aout_base + HW_AUDIOOUT_DACVOLUME);
983 + } else
984 + __raw_writel(dac_mask,
985 + mxs_adc->aout_base + HW_AUDIOOUT_DACVOLUME_CLR);
986 +
987 + return 0;
988 +}
989 +
990 +#define MXS_ADC_RATES SNDRV_PCM_RATE_8000_192000
991 +#define MXS_ADC_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
992 +
993 +static const struct snd_soc_dai_ops mxs_codec_dai_ops = {
994 + .hw_params = mxs_pcm_hw_params,
995 + .digital_mute = mxs_codec_dig_mute,
996 +};
997 +
998 +static struct snd_soc_dai_driver mxs_codec_dai_driver = {
999 + .name = "mxs-builtin-codec-dai",
1000 + .playback = {
1001 + .stream_name = "Playback",
1002 + .channels_min = 2,
1003 + .channels_max = 2,
1004 + .rates = MXS_ADC_RATES,
1005 + .formats = MXS_ADC_FORMATS,
1006 + },
1007 + .capture = {
1008 + .stream_name = "Capture",
1009 + .channels_min = 2,
1010 + .channels_max = 2,
1011 + .rates = MXS_ADC_RATES,
1012 + .formats = MXS_ADC_FORMATS,
1013 + },
1014 + .ops = &mxs_codec_dai_ops,
1015 +};
1016 +/* END MXS-ADC Codec DAI driver */
1017 +
1018 +/* MXS-ADC Codec driver */
1019 +static int mxs_codec_driver_probe(struct snd_soc_codec *codec)
1020 +{
1021 + int ret = 0;
1022 + /* We don't use snd_soc_codec_set_cache_io because we are using
1023 + * our own IO functions: write, read. */
1024 +
1025 + mxs_codec_startup(codec);
1026 +
1027 + /* leading to standby state */
1028 + ret = mxs_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1029 + if (ret)
1030 + goto err;
1031 +
1032 + return 0;
1033 +
1034 +err:
1035 + mxs_codec_stop(codec);
1036 +
1037 + return ret;
1038 +}
1039 +
1040 +static int mxs_codec_driver_remove(struct snd_soc_codec *codec)
1041 +{
1042 + mxs_codec_stop(codec);
1043 +
1044 + return 0;
1045 +}
1046 +
1047 +// static int mxs_codec_driver_suspend(struct snd_soc_codec *codec)
1048 +// {
1049 +// /* TODO Enable power management. */
1050 +// return 0;
1051 +// }
1052 +
1053 +// static int mxs_codec_driver_resume(struct snd_soc_codec *codec)
1054 +// {
1055 +// /* TODO Enable power management. */
1056 +// return 0;
1057 +// }
1058 +
1059 +static struct snd_soc_codec_driver mxs_codec_driver = {
1060 + .probe = mxs_codec_driver_probe,
1061 + .remove = mxs_codec_driver_remove,
1062 +// .suspend = mxs_codec_driver_suspend,
1063 +// .resume = mxs_codec_driver_resume,
1064 + .set_bias_level = mxs_set_bias_level,
1065 + .reg_cache_size = ADC_REGNUM,
1066 + .reg_word_size = sizeof(u16),
1067 + .reg_cache_step = 1,
1068 +// .reg_cache_default = mxsadc_regs,
1069 +// .volatile_register = sgtl5000_volatile_register,
1070 + .controls = mxs_snd_controls,
1071 + .num_controls = ARRAY_SIZE(mxs_snd_controls),
1072 + .dapm_widgets = mxs_dapm_widgets,
1073 + .num_dapm_widgets = ARRAY_SIZE(mxs_dapm_widgets),
1074 + .dapm_routes = mxs_dapm_routes,
1075 + .num_dapm_routes = ARRAY_SIZE(mxs_dapm_routes),
1076 + .write = mxs_codec_write,
1077 + .read = mxs_codec_read,
1078 +};
1079 +/* END MXS-ADC Codec driver */
1080 +
1081 +/* Underlying platform device that registers codec */
1082 +static int mxs_adc_probe(struct platform_device *pdev)
1083 +{
1084 + struct mxs_adc_priv *mxs_adc;
1085 + struct resource *r;
1086 + int ret;
1087 +
1088 + mxs_adc = devm_kzalloc(&pdev->dev, sizeof(struct mxs_adc_priv), GFP_KERNEL);
1089 + if (!mxs_adc)
1090 + return -ENOMEM;
1091 +
1092 + platform_set_drvdata(pdev, mxs_adc);
1093 +
1094 + /* audio-in IO memory */
1095 + r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "audioin");
1096 + if (IS_ERR(r)) {
1097 + dev_err(&pdev->dev, "failed to get resource\n");
1098 + return PTR_ERR(r);
1099 + }
1100 +
1101 + mxs_adc->ain_base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
1102 + if (IS_ERR(mxs_adc->ain_base)) {
1103 + dev_err(&pdev->dev, "ioremap failed\n");
1104 + return PTR_ERR(mxs_adc->ain_base);
1105 + }
1106 +
1107 + /* audio-out IO memory */
1108 + r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "audioout");
1109 + if (IS_ERR(r)) {
1110 + dev_err(&pdev->dev, "failed to get resource\n");
1111 + return PTR_ERR(r);
1112 + }
1113 +
1114 + mxs_adc->aout_base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
1115 + if (IS_ERR(mxs_adc->aout_base)) {
1116 + dev_err(&pdev->dev, "ioremap failed\n");
1117 + return PTR_ERR(mxs_adc->aout_base);
1118 + }
1119 +
1120 + /* rtc IO memory */
1121 + r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rtc");
1122 + if (IS_ERR(r)) {
1123 + dev_err(&pdev->dev, "failed to get resource\n");
1124 + return PTR_ERR(r);
1125 + }
1126 +
1127 + mxs_adc->rtc_base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
1128 + if (IS_ERR(mxs_adc->rtc_base)) {
1129 + dev_err(&pdev->dev, "ioremap failed\n");
1130 + return PTR_ERR(mxs_adc->rtc_base);
1131 + }
1132 +
1133 + /* Get audio clock */
1134 + mxs_adc->clk = devm_clk_get(&pdev->dev, "filt");
1135 + if (IS_ERR(mxs_adc->clk)) {
1136 + ret = PTR_ERR(mxs_adc->clk);
1137 + dev_err(&pdev->dev, "%s: Clock initialization failed\n", __func__);
1138 + return ret;
1139 + }
1140 +
1141 + /* Turn on audio clock */
1142 + ret = clk_prepare_enable(mxs_adc->clk);
1143 + if (unlikely(ret != 0)) {
1144 + dev_err(&pdev->dev, "%s: Clock prepare or enable failed\n", __func__);
1145 + return ret;
1146 + }
1147 +
1148 + ret = snd_soc_register_codec(&pdev->dev,
1149 + &mxs_codec_driver,&mxs_codec_dai_driver, 1);
1150 + if (unlikely(ret != 0)) {
1151 + dev_err(&pdev->dev, "Codec registration failed\n");
1152 + goto disable_clk;
1153 + }
1154 +
1155 + return 0;
1156 +
1157 +disable_clk:
1158 + clk_disable_unprepare(mxs_adc->clk);
1159 + return ret;
1160 +}
1161 +
1162 +static int mxs_adc_remove(struct platform_device *pdev)
1163 +{
1164 + struct mxs_adc_priv *mxs_adc = platform_get_drvdata(pdev);
1165 +
1166 + clk_disable_unprepare(mxs_adc->clk);
1167 + snd_soc_unregister_codec(&pdev->dev);
1168 +
1169 + return 0;
1170 +}
1171 +
1172 +static const struct of_device_id mxs_adc_dt_ids[] = {
1173 + { .compatible = "fsl,mxs-builtin-codec", },
1174 + { /* sentinel */ }
1175 +};
1176 +MODULE_DEVICE_TABLE(of, mxs_adc_dt_ids);
1177 +
1178 +static struct platform_driver mxs_adc_driver = {
1179 + .driver = {
1180 + .name = "mxs-builtin-codec",
1181 + .owner = THIS_MODULE,
1182 + .of_match_table = mxs_adc_dt_ids,
1183 + },
1184 + .probe = mxs_adc_probe,
1185 + .remove = mxs_adc_remove,
1186 +};
1187 +
1188 +module_platform_driver(mxs_adc_driver);
1189 +/* END Underlying platform device that registers codec */
1190 +
1191 +MODULE_DESCRIPTION("Freescale MXS ADC/DAC SoC Codec Driver");
1192 +MODULE_AUTHOR("Michal Ulianko <michal.ulianko@gmail.com>");
1193 +MODULE_LICENSE("GPL");
1194 --- /dev/null
1195 +++ b/sound/soc/codecs/mxs-builtin-codec.h
1196 @@ -0,0 +1,825 @@
1197 +#ifndef __MXS_ADC_CODEC_H
1198 +
1199 +#include <linux/io.h>
1200 +
1201 +/* MXS ADC/DAC registers */
1202 +#define DAC_CTRL_L 0
1203 +#define DAC_CTRL_H 1
1204 +#define DAC_STAT_L 2
1205 +#define DAC_STAT_H 3
1206 +#define DAC_SRR_L 4
1207 +#define DAC_VOLUME_L 6
1208 +#define DAC_VOLUME_H 7
1209 +#define DAC_DEBUG_L 8
1210 +#define DAC_DEBUG_H 9
1211 +#define DAC_HPVOL_L 10
1212 +#define DAC_HPVOL_H 11
1213 +#define DAC_PWRDN_L 12
1214 +#define DAC_PWRDN_H 13
1215 +#define DAC_REFCTRL_L 14
1216 +#define DAC_REFCTRL_H 15
1217 +#define DAC_ANACTRL_L 16
1218 +#define DAC_ANACTRL_H 17
1219 +#define DAC_TEST_L 18
1220 +#define DAC_TEST_H 19
1221 +#define DAC_BISTCTRL_L 20
1222 +#define DAC_BISTCTRL_H 21
1223 +#define DAC_BISTSTAT0_L 22
1224 +#define DAC_BISTSTAT0_H 23
1225 +#define DAC_BISTSTAT1_L 24
1226 +#define DAC_BISTSTAT1_H 25
1227 +#define DAC_ANACLKCTRL_L 26
1228 +#define DAC_ANACLKCTRL_H 27
1229 +#define DAC_DATA_L 28
1230 +#define DAC_DATA_H 29
1231 +#define DAC_SPEAKERCTRL_L 30
1232 +#define DAC_SPEAKERCTRL_H 31
1233 +#define DAC_VERSION_L 32
1234 +#define DAC_VERSION_H 33
1235 +#define ADC_CTRL_L 34
1236 +#define ADC_CTRL_H 35
1237 +#define ADC_STAT_L 36
1238 +#define ADC_STAT_H 37
1239 +#define ADC_SRR_L 38
1240 +#define ADC_SRR_H 39
1241 +#define ADC_VOLUME_L 40
1242 +#define ADC_VOLUME_H 41
1243 +#define ADC_DEBUG_L 42
1244 +#define ADC_DEBUG_H 43
1245 +#define ADC_ADCVOL_L 44
1246 +#define ADC_ADCVOL_H 45
1247 +#define ADC_MICLINE_L 46
1248 +#define ADC_MICLINE_H 47
1249 +#define ADC_ANACLKCTRL_L 48
1250 +#define ADC_ANACLKCTRL_H 49
1251 +#define ADC_DATA_L 50
1252 +#define ADC_DATA_H 51
1253 +
1254 +#define ADC_REGNUM 52
1255 +
1256 +#define DAC_VOLUME_MIN 0x37
1257 +#define DAC_VOLUME_MAX 0xFE
1258 +#define ADC_VOLUME_MIN 0x37
1259 +#define ADC_VOLUME_MAX 0xFE
1260 +#define HP_VOLUME_MAX 0x0
1261 +#define HP_VOLUME_MIN 0x7F
1262 +#define LO_VOLUME_MAX 0x0
1263 +#define LO_VOLUME_MIN 0x1F
1264 +
1265 +/* RTC */
1266 +#define HW_RTC_PERSISTENT0 (0x00000060)
1267 +#define HW_RTC_PERSISTENT0_SET (0x00000064)
1268 +#define HW_RTC_PERSISTENT0_CLR (0x00000068)
1269 +#define HW_RTC_PERSISTENT0_TOG (0x0000006c)
1270 +
1271 +// TODO
1272 +//#define BM_RTC_PERSISTENT0_RELEASE_GND 0x00080000
1273 +
1274 +/* AUDIOOUT */
1275 +#define HW_AUDIOOUT_CTRL (0x00000000)
1276 +#define HW_AUDIOOUT_CTRL_SET (0x00000004)
1277 +#define HW_AUDIOOUT_CTRL_CLR (0x00000008)
1278 +#define HW_AUDIOOUT_CTRL_TOG (0x0000000c)
1279 +
1280 +#define BM_AUDIOOUT_CTRL_SFTRST 0x80000000
1281 +#define BM_AUDIOOUT_CTRL_CLKGATE 0x40000000
1282 +#define BP_AUDIOOUT_CTRL_RSRVD4 21
1283 +#define BM_AUDIOOUT_CTRL_RSRVD4 0x3FE00000
1284 +#define BF_AUDIOOUT_CTRL_RSRVD4(v) \
1285 + (((v) << 21) & BM_AUDIOOUT_CTRL_RSRVD4)
1286 +#define BP_AUDIOOUT_CTRL_DMAWAIT_COUNT 16
1287 +#define BM_AUDIOOUT_CTRL_DMAWAIT_COUNT 0x001F0000
1288 +#define BF_AUDIOOUT_CTRL_DMAWAIT_COUNT(v) \
1289 + (((v) << 16) & BM_AUDIOOUT_CTRL_DMAWAIT_COUNT)
1290 +#define BM_AUDIOOUT_CTRL_RSRVD3 0x00008000
1291 +#define BM_AUDIOOUT_CTRL_LR_SWAP 0x00004000
1292 +#define BM_AUDIOOUT_CTRL_EDGE_SYNC 0x00002000
1293 +#define BM_AUDIOOUT_CTRL_INVERT_1BIT 0x00001000
1294 +#define BP_AUDIOOUT_CTRL_RSRVD2 10
1295 +#define BM_AUDIOOUT_CTRL_RSRVD2 0x00000C00
1296 +#define BF_AUDIOOUT_CTRL_RSRVD2(v) \
1297 + (((v) << 10) & BM_AUDIOOUT_CTRL_RSRVD2)
1298 +#define BP_AUDIOOUT_CTRL_SS3D_EFFECT 8
1299 +#define BM_AUDIOOUT_CTRL_SS3D_EFFECT 0x00000300
1300 +#define BF_AUDIOOUT_CTRL_SS3D_EFFECT(v) \
1301 + (((v) << 8) & BM_AUDIOOUT_CTRL_SS3D_EFFECT)
1302 +#define BM_AUDIOOUT_CTRL_RSRVD1 0x00000080
1303 +#define BM_AUDIOOUT_CTRL_WORD_LENGTH 0x00000040
1304 +#define BM_AUDIOOUT_CTRL_DAC_ZERO_ENABLE 0x00000020
1305 +#define BM_AUDIOOUT_CTRL_LOOPBACK 0x00000010
1306 +#define BM_AUDIOOUT_CTRL_FIFO_UNDERFLOW_IRQ 0x00000008
1307 +#define BM_AUDIOOUT_CTRL_FIFO_OVERFLOW_IRQ 0x00000004
1308 +#define BM_AUDIOOUT_CTRL_FIFO_ERROR_IRQ_EN 0x00000002
1309 +#define BM_AUDIOOUT_CTRL_RUN 0x00000001
1310 +
1311 +#define HW_AUDIOOUT_STAT (0x00000010)
1312 +#define HW_AUDIOOUT_STAT_SET (0x00000014)
1313 +#define HW_AUDIOOUT_STAT_CLR (0x00000018)
1314 +#define HW_AUDIOOUT_STAT_TOG (0x0000001c)
1315 +
1316 +#define BM_AUDIOOUT_STAT_DAC_PRESENT 0x80000000
1317 +#define BP_AUDIOOUT_STAT_RSRVD1 0
1318 +#define BM_AUDIOOUT_STAT_RSRVD1 0x7FFFFFFF
1319 +#define BF_AUDIOOUT_STAT_RSRVD1(v) \
1320 + (((v) << 0) & BM_AUDIOOUT_STAT_RSRVD1)
1321 +
1322 +#define HW_AUDIOOUT_DACSRR (0x00000020)
1323 +#define HW_AUDIOOUT_DACSRR_SET (0x00000024)
1324 +#define HW_AUDIOOUT_DACSRR_CLR (0x00000028)
1325 +#define HW_AUDIOOUT_DACSRR_TOG (0x0000002c)
1326 +
1327 +#define BM_AUDIOOUT_DACSRR_OSR 0x80000000
1328 +#define BV_AUDIOOUT_DACSRR_OSR__OSR6 0x0
1329 +#define BV_AUDIOOUT_DACSRR_OSR__OSR12 0x1
1330 +#define BP_AUDIOOUT_DACSRR_BASEMULT 28
1331 +#define BM_AUDIOOUT_DACSRR_BASEMULT 0x70000000
1332 +#define BF_AUDIOOUT_DACSRR_BASEMULT(v) \
1333 + (((v) << 28) & BM_AUDIOOUT_DACSRR_BASEMULT)
1334 +#define BV_AUDIOOUT_DACSRR_BASEMULT__SINGLE_RATE 0x1
1335 +#define BV_AUDIOOUT_DACSRR_BASEMULT__DOUBLE_RATE 0x2
1336 +#define BV_AUDIOOUT_DACSRR_BASEMULT__QUAD_RATE 0x4
1337 +#define BM_AUDIOOUT_DACSRR_RSRVD2 0x08000000
1338 +#define BP_AUDIOOUT_DACSRR_SRC_HOLD 24
1339 +#define BM_AUDIOOUT_DACSRR_SRC_HOLD 0x07000000
1340 +#define BF_AUDIOOUT_DACSRR_SRC_HOLD(v) \
1341 + (((v) << 24) & BM_AUDIOOUT_DACSRR_SRC_HOLD)
1342 +#define BP_AUDIOOUT_DACSRR_RSRVD1 21
1343 +#define BM_AUDIOOUT_DACSRR_RSRVD1 0x00E00000
1344 +#define BF_AUDIOOUT_DACSRR_RSRVD1(v) \
1345 + (((v) << 21) & BM_AUDIOOUT_DACSRR_RSRVD1)
1346 +#define BP_AUDIOOUT_DACSRR_SRC_INT 16
1347 +#define BM_AUDIOOUT_DACSRR_SRC_INT 0x001F0000
1348 +#define BF_AUDIOOUT_DACSRR_SRC_INT(v) \
1349 + (((v) << 16) & BM_AUDIOOUT_DACSRR_SRC_INT)
1350 +#define BP_AUDIOOUT_DACSRR_RSRVD0 13
1351 +#define BM_AUDIOOUT_DACSRR_RSRVD0 0x0000E000
1352 +#define BF_AUDIOOUT_DACSRR_RSRVD0(v) \
1353 + (((v) << 13) & BM_AUDIOOUT_DACSRR_RSRVD0)
1354 +#define BP_AUDIOOUT_DACSRR_SRC_FRAC 0
1355 +#define BM_AUDIOOUT_DACSRR_SRC_FRAC 0x00001FFF
1356 +#define BF_AUDIOOUT_DACSRR_SRC_FRAC(v) \
1357 + (((v) << 0) & BM_AUDIOOUT_DACSRR_SRC_FRAC)
1358 +
1359 +#define HW_AUDIOOUT_DACVOLUME (0x00000030)
1360 +#define HW_AUDIOOUT_DACVOLUME_SET (0x00000034)
1361 +#define HW_AUDIOOUT_DACVOLUME_CLR (0x00000038)
1362 +#define HW_AUDIOOUT_DACVOLUME_TOG (0x0000003c)
1363 +
1364 +#define BP_AUDIOOUT_DACVOLUME_RSRVD4 29
1365 +#define BM_AUDIOOUT_DACVOLUME_RSRVD4 0xE0000000
1366 +#define BF_AUDIOOUT_DACVOLUME_RSRVD4(v) \
1367 + (((v) << 29) & BM_AUDIOOUT_DACVOLUME_RSRVD4)
1368 +#define BM_AUDIOOUT_DACVOLUME_VOLUME_UPDATE_LEFT 0x10000000
1369 +#define BP_AUDIOOUT_DACVOLUME_RSRVD3 26
1370 +#define BM_AUDIOOUT_DACVOLUME_RSRVD3 0x0C000000
1371 +#define BF_AUDIOOUT_DACVOLUME_RSRVD3(v) \
1372 + (((v) << 26) & BM_AUDIOOUT_DACVOLUME_RSRVD3)
1373 +#define BM_AUDIOOUT_DACVOLUME_EN_ZCD 0x02000000
1374 +#define BM_AUDIOOUT_DACVOLUME_MUTE_LEFT 0x01000000
1375 +#define BP_AUDIOOUT_DACVOLUME_VOLUME_LEFT 16
1376 +#define BM_AUDIOOUT_DACVOLUME_VOLUME_LEFT 0x00FF0000
1377 +#define BF_AUDIOOUT_DACVOLUME_VOLUME_LEFT(v) \
1378 + (((v) << 16) & BM_AUDIOOUT_DACVOLUME_VOLUME_LEFT)
1379 +#define BP_AUDIOOUT_DACVOLUME_RSRVD2 13
1380 +#define BM_AUDIOOUT_DACVOLUME_RSRVD2 0x0000E000
1381 +#define BF_AUDIOOUT_DACVOLUME_RSRVD2(v) \
1382 + (((v) << 13) & BM_AUDIOOUT_DACVOLUME_RSRVD2)
1383 +#define BM_AUDIOOUT_DACVOLUME_VOLUME_UPDATE_RIGHT 0x00001000
1384 +#define BP_AUDIOOUT_DACVOLUME_RSRVD1 9
1385 +#define BM_AUDIOOUT_DACVOLUME_RSRVD1 0x00000E00
1386 +#define BF_AUDIOOUT_DACVOLUME_RSRVD1(v) \
1387 + (((v) << 9) & BM_AUDIOOUT_DACVOLUME_RSRVD1)
1388 +#define BM_AUDIOOUT_DACVOLUME_MUTE_RIGHT 0x00000100
1389 +#define BP_AUDIOOUT_DACVOLUME_VOLUME_RIGHT 0
1390 +#define BM_AUDIOOUT_DACVOLUME_VOLUME_RIGHT 0x000000FF
1391 +#define BF_AUDIOOUT_DACVOLUME_VOLUME_RIGHT(v) \
1392 + (((v) << 0) & BM_AUDIOOUT_DACVOLUME_VOLUME_RIGHT)
1393 +
1394 +#define HW_AUDIOOUT_DACDEBUG (0x00000040)
1395 +#define HW_AUDIOOUT_DACDEBUG_SET (0x00000044)
1396 +#define HW_AUDIOOUT_DACDEBUG_CLR (0x00000048)
1397 +#define HW_AUDIOOUT_DACDEBUG_TOG (0x0000004c)
1398 +
1399 +#define BM_AUDIOOUT_DACDEBUG_ENABLE_DACDMA 0x80000000
1400 +#define BP_AUDIOOUT_DACDEBUG_RSRVD2 12
1401 +#define BM_AUDIOOUT_DACDEBUG_RSRVD2 0x7FFFF000
1402 +#define BF_AUDIOOUT_DACDEBUG_RSRVD2(v) \
1403 + (((v) << 12) & BM_AUDIOOUT_DACDEBUG_RSRVD2)
1404 +#define BP_AUDIOOUT_DACDEBUG_RAM_SS 8
1405 +#define BM_AUDIOOUT_DACDEBUG_RAM_SS 0x00000F00
1406 +#define BF_AUDIOOUT_DACDEBUG_RAM_SS(v) \
1407 + (((v) << 8) & BM_AUDIOOUT_DACDEBUG_RAM_SS)
1408 +#define BP_AUDIOOUT_DACDEBUG_RSRVD1 6
1409 +#define BM_AUDIOOUT_DACDEBUG_RSRVD1 0x000000C0
1410 +#define BF_AUDIOOUT_DACDEBUG_RSRVD1(v) \
1411 + (((v) << 6) & BM_AUDIOOUT_DACDEBUG_RSRVD1)
1412 +#define BM_AUDIOOUT_DACDEBUG_SET_INTERRUPT1_CLK_CROSS 0x00000020
1413 +#define BM_AUDIOOUT_DACDEBUG_SET_INTERRUPT0_CLK_CROSS 0x00000010
1414 +#define BM_AUDIOOUT_DACDEBUG_SET_INTERRUPT1_HAND_SHAKE 0x00000008
1415 +#define BM_AUDIOOUT_DACDEBUG_SET_INTERRUPT0_HAND_SHAKE 0x00000004
1416 +#define BM_AUDIOOUT_DACDEBUG_DMA_PREQ 0x00000002
1417 +#define BM_AUDIOOUT_DACDEBUG_FIFO_STATUS 0x00000001
1418 +
1419 +#define HW_AUDIOOUT_HPVOL (0x00000050)
1420 +#define HW_AUDIOOUT_HPVOL_SET (0x00000054)
1421 +#define HW_AUDIOOUT_HPVOL_CLR (0x00000058)
1422 +#define HW_AUDIOOUT_HPVOL_TOG (0x0000005c)
1423 +
1424 +#define BP_AUDIOOUT_HPVOL_RSRVD5 29
1425 +#define BM_AUDIOOUT_HPVOL_RSRVD5 0xE0000000
1426 +#define BF_AUDIOOUT_HPVOL_RSRVD5(v) \
1427 + (((v) << 29) & BM_AUDIOOUT_HPVOL_RSRVD5)
1428 +#define BM_AUDIOOUT_HPVOL_VOLUME_UPDATE_PENDING 0x10000000
1429 +#define BP_AUDIOOUT_HPVOL_RSRVD4 26
1430 +#define BM_AUDIOOUT_HPVOL_RSRVD4 0x0C000000
1431 +#define BF_AUDIOOUT_HPVOL_RSRVD4(v) \
1432 + (((v) << 26) & BM_AUDIOOUT_HPVOL_RSRVD4)
1433 +#define BM_AUDIOOUT_HPVOL_EN_MSTR_ZCD 0x02000000
1434 +#define BM_AUDIOOUT_HPVOL_MUTE 0x01000000
1435 +#define BP_AUDIOOUT_HPVOL_RSRVD3 17
1436 +#define BM_AUDIOOUT_HPVOL_RSRVD3 0x00FE0000
1437 +#define BF_AUDIOOUT_HPVOL_RSRVD3(v) \
1438 + (((v) << 17) & BM_AUDIOOUT_HPVOL_RSRVD3)
1439 +#define BM_AUDIOOUT_HPVOL_SELECT 0x00010000
1440 +#define BM_AUDIOOUT_HPVOL_RSRVD2 0x00008000
1441 +#define BP_AUDIOOUT_HPVOL_VOL_LEFT 8
1442 +#define BM_AUDIOOUT_HPVOL_VOL_LEFT 0x00007F00
1443 +#define BF_AUDIOOUT_HPVOL_VOL_LEFT(v) \
1444 + (((v) << 8) & BM_AUDIOOUT_HPVOL_VOL_LEFT)
1445 +#define BM_AUDIOOUT_HPVOL_RSRVD1 0x00000080
1446 +#define BP_AUDIOOUT_HPVOL_VOL_RIGHT 0
1447 +#define BM_AUDIOOUT_HPVOL_VOL_RIGHT 0x0000007F
1448 +#define BF_AUDIOOUT_HPVOL_VOL_RIGHT(v) \
1449 + (((v) << 0) & BM_AUDIOOUT_HPVOL_VOL_RIGHT)
1450 +
1451 +#define HW_AUDIOOUT_RESERVED (0x00000060)
1452 +#define HW_AUDIOOUT_RESERVED_SET (0x00000064)
1453 +#define HW_AUDIOOUT_RESERVED_CLR (0x00000068)
1454 +#define HW_AUDIOOUT_RESERVED_TOG (0x0000006c)
1455 +
1456 +#define BP_AUDIOOUT_RESERVED_RSRVD1 0
1457 +#define BM_AUDIOOUT_RESERVED_RSRVD1 0xFFFFFFFF
1458 +#define BF_AUDIOOUT_RESERVED_RSRVD1(v) (v)
1459 +
1460 +#define HW_AUDIOOUT_PWRDN (0x00000070)
1461 +#define HW_AUDIOOUT_PWRDN_SET (0x00000074)
1462 +#define HW_AUDIOOUT_PWRDN_CLR (0x00000078)
1463 +#define HW_AUDIOOUT_PWRDN_TOG (0x0000007c)
1464 +
1465 +#define BP_AUDIOOUT_PWRDN_RSRVD7 25
1466 +#define BM_AUDIOOUT_PWRDN_RSRVD7 0xFE000000
1467 +#define BF_AUDIOOUT_PWRDN_RSRVD7(v) \
1468 + (((v) << 25) & BM_AUDIOOUT_PWRDN_RSRVD7)
1469 +#define BM_AUDIOOUT_PWRDN_SPEAKER 0x01000000
1470 +#define BP_AUDIOOUT_PWRDN_RSRVD6 21
1471 +#define BM_AUDIOOUT_PWRDN_RSRVD6 0x00E00000
1472 +#define BF_AUDIOOUT_PWRDN_RSRVD6(v) \
1473 + (((v) << 21) & BM_AUDIOOUT_PWRDN_RSRVD6)
1474 +#define BM_AUDIOOUT_PWRDN_SELFBIAS 0x00100000
1475 +#define BP_AUDIOOUT_PWRDN_RSRVD5 17
1476 +#define BM_AUDIOOUT_PWRDN_RSRVD5 0x000E0000
1477 +#define BF_AUDIOOUT_PWRDN_RSRVD5(v) \
1478 + (((v) << 17) & BM_AUDIOOUT_PWRDN_RSRVD5)
1479 +#define BM_AUDIOOUT_PWRDN_RIGHT_ADC 0x00010000
1480 +#define BP_AUDIOOUT_PWRDN_RSRVD4 13
1481 +#define BM_AUDIOOUT_PWRDN_RSRVD4 0x0000E000
1482 +#define BF_AUDIOOUT_PWRDN_RSRVD4(v) \
1483 + (((v) << 13) & BM_AUDIOOUT_PWRDN_RSRVD4)
1484 +#define BM_AUDIOOUT_PWRDN_DAC 0x00001000
1485 +#define BP_AUDIOOUT_PWRDN_RSRVD3 9
1486 +#define BM_AUDIOOUT_PWRDN_RSRVD3 0x00000E00
1487 +#define BF_AUDIOOUT_PWRDN_RSRVD3(v) \
1488 + (((v) << 9) & BM_AUDIOOUT_PWRDN_RSRVD3)
1489 +#define BM_AUDIOOUT_PWRDN_ADC 0x00000100
1490 +#define BP_AUDIOOUT_PWRDN_RSRVD2 5
1491 +#define BM_AUDIOOUT_PWRDN_RSRVD2 0x000000E0
1492 +#define BF_AUDIOOUT_PWRDN_RSRVD2(v) \
1493 + (((v) << 5) & BM_AUDIOOUT_PWRDN_RSRVD2)
1494 +#define BM_AUDIOOUT_PWRDN_CAPLESS 0x00000010
1495 +#define BP_AUDIOOUT_PWRDN_RSRVD1 1
1496 +#define BM_AUDIOOUT_PWRDN_RSRVD1 0x0000000E
1497 +#define BF_AUDIOOUT_PWRDN_RSRVD1(v) \
1498 + (((v) << 1) & BM_AUDIOOUT_PWRDN_RSRVD1)
1499 +#define BM_AUDIOOUT_PWRDN_HEADPHONE 0x00000001
1500 +
1501 +#define HW_AUDIOOUT_REFCTRL (0x00000080)
1502 +#define HW_AUDIOOUT_REFCTRL_SET (0x00000084)
1503 +#define HW_AUDIOOUT_REFCTRL_CLR (0x00000088)
1504 +#define HW_AUDIOOUT_REFCTRL_TOG (0x0000008c)
1505 +
1506 +#define BP_AUDIOOUT_REFCTRL_RSRVD4 27
1507 +#define BM_AUDIOOUT_REFCTRL_RSRVD4 0xF8000000
1508 +#define BF_AUDIOOUT_REFCTRL_RSRVD4(v) \
1509 + (((v) << 27) & BM_AUDIOOUT_REFCTRL_RSRVD4)
1510 +#define BM_AUDIOOUT_REFCTRL_FASTSETTLING 0x04000000
1511 +#define BM_AUDIOOUT_REFCTRL_RAISE_REF 0x02000000
1512 +#define BM_AUDIOOUT_REFCTRL_XTAL_BGR_BIAS 0x01000000
1513 +#define BM_AUDIOOUT_REFCTRL_RSRVD3 0x00800000
1514 +#define BP_AUDIOOUT_REFCTRL_VBG_ADJ 20
1515 +#define BM_AUDIOOUT_REFCTRL_VBG_ADJ 0x00700000
1516 +#define BF_AUDIOOUT_REFCTRL_VBG_ADJ(v) \
1517 + (((v) << 20) & BM_AUDIOOUT_REFCTRL_VBG_ADJ)
1518 +#define BM_AUDIOOUT_REFCTRL_LOW_PWR 0x00080000
1519 +#define BM_AUDIOOUT_REFCTRL_LW_REF 0x00040000
1520 +#define BP_AUDIOOUT_REFCTRL_BIAS_CTRL 16
1521 +#define BM_AUDIOOUT_REFCTRL_BIAS_CTRL 0x00030000
1522 +#define BF_AUDIOOUT_REFCTRL_BIAS_CTRL(v) \
1523 + (((v) << 16) & BM_AUDIOOUT_REFCTRL_BIAS_CTRL)
1524 +#define BM_AUDIOOUT_REFCTRL_RSRVD2 0x00008000
1525 +#define BM_AUDIOOUT_REFCTRL_VDDXTAL_TO_VDDD 0x00004000
1526 +#define BM_AUDIOOUT_REFCTRL_ADJ_ADC 0x00002000
1527 +#define BM_AUDIOOUT_REFCTRL_ADJ_VAG 0x00001000
1528 +#define BP_AUDIOOUT_REFCTRL_ADC_REFVAL 8
1529 +#define BM_AUDIOOUT_REFCTRL_ADC_REFVAL 0x00000F00
1530 +#define BF_AUDIOOUT_REFCTRL_ADC_REFVAL(v) \
1531 + (((v) << 8) & BM_AUDIOOUT_REFCTRL_ADC_REFVAL)
1532 +#define BP_AUDIOOUT_REFCTRL_VAG_VAL 4
1533 +#define BM_AUDIOOUT_REFCTRL_VAG_VAL 0x000000F0
1534 +#define BF_AUDIOOUT_REFCTRL_VAG_VAL(v) \
1535 + (((v) << 4) & BM_AUDIOOUT_REFCTRL_VAG_VAL)
1536 +#define BM_AUDIOOUT_REFCTRL_RSRVD1 0x00000008
1537 +#define BP_AUDIOOUT_REFCTRL_DAC_ADJ 0
1538 +#define BM_AUDIOOUT_REFCTRL_DAC_ADJ 0x00000007
1539 +#define BF_AUDIOOUT_REFCTRL_DAC_ADJ(v) \
1540 + (((v) << 0) & BM_AUDIOOUT_REFCTRL_DAC_ADJ)
1541 +
1542 +#define HW_AUDIOOUT_ANACTRL (0x00000090)
1543 +#define HW_AUDIOOUT_ANACTRL_SET (0x00000094)
1544 +#define HW_AUDIOOUT_ANACTRL_CLR (0x00000098)
1545 +#define HW_AUDIOOUT_ANACTRL_TOG (0x0000009c)
1546 +
1547 +#define BP_AUDIOOUT_ANACTRL_RSRVD8 29
1548 +#define BM_AUDIOOUT_ANACTRL_RSRVD8 0xE0000000
1549 +#define BF_AUDIOOUT_ANACTRL_RSRVD8(v) \
1550 + (((v) << 29) & BM_AUDIOOUT_ANACTRL_RSRVD8)
1551 +#define BM_AUDIOOUT_ANACTRL_SHORT_CM_STS 0x10000000
1552 +#define BP_AUDIOOUT_ANACTRL_RSRVD7 25
1553 +#define BM_AUDIOOUT_ANACTRL_RSRVD7 0x0E000000
1554 +#define BF_AUDIOOUT_ANACTRL_RSRVD7(v) \
1555 + (((v) << 25) & BM_AUDIOOUT_ANACTRL_RSRVD7)
1556 +#define BM_AUDIOOUT_ANACTRL_SHORT_LR_STS 0x01000000
1557 +#define BP_AUDIOOUT_ANACTRL_RSRVD6 22
1558 +#define BM_AUDIOOUT_ANACTRL_RSRVD6 0x00C00000
1559 +#define BF_AUDIOOUT_ANACTRL_RSRVD6(v) \
1560 + (((v) << 22) & BM_AUDIOOUT_ANACTRL_RSRVD6)
1561 +#define BP_AUDIOOUT_ANACTRL_SHORTMODE_CM 20
1562 +#define BM_AUDIOOUT_ANACTRL_SHORTMODE_CM 0x00300000
1563 +#define BF_AUDIOOUT_ANACTRL_SHORTMODE_CM(v) \
1564 + (((v) << 20) & BM_AUDIOOUT_ANACTRL_SHORTMODE_CM)
1565 +#define BM_AUDIOOUT_ANACTRL_RSRVD5 0x00080000
1566 +#define BP_AUDIOOUT_ANACTRL_SHORTMODE_LR 17
1567 +#define BM_AUDIOOUT_ANACTRL_SHORTMODE_LR 0x00060000
1568 +#define BF_AUDIOOUT_ANACTRL_SHORTMODE_LR(v) \
1569 + (((v) << 17) & BM_AUDIOOUT_ANACTRL_SHORTMODE_LR)
1570 +#define BP_AUDIOOUT_ANACTRL_RSRVD4 15
1571 +#define BM_AUDIOOUT_ANACTRL_RSRVD4 0x00018000
1572 +#define BF_AUDIOOUT_ANACTRL_RSRVD4(v) \
1573 + (((v) << 15) & BM_AUDIOOUT_ANACTRL_RSRVD4)
1574 +#define BP_AUDIOOUT_ANACTRL_SHORT_LVLADJL 12
1575 +#define BM_AUDIOOUT_ANACTRL_SHORT_LVLADJL 0x00007000
1576 +#define BF_AUDIOOUT_ANACTRL_SHORT_LVLADJL(v) \
1577 + (((v) << 12) & BM_AUDIOOUT_ANACTRL_SHORT_LVLADJL)
1578 +#define BM_AUDIOOUT_ANACTRL_RSRVD3 0x00000800
1579 +#define BP_AUDIOOUT_ANACTRL_SHORT_LVLADJR 8
1580 +#define BM_AUDIOOUT_ANACTRL_SHORT_LVLADJR 0x00000700
1581 +#define BF_AUDIOOUT_ANACTRL_SHORT_LVLADJR(v) \
1582 + (((v) << 8) & BM_AUDIOOUT_ANACTRL_SHORT_LVLADJR)
1583 +#define BP_AUDIOOUT_ANACTRL_RSRVD2 6
1584 +#define BM_AUDIOOUT_ANACTRL_RSRVD2 0x000000C0
1585 +#define BF_AUDIOOUT_ANACTRL_RSRVD2(v) \
1586 + (((v) << 6) & BM_AUDIOOUT_ANACTRL_RSRVD2)
1587 +#define BM_AUDIOOUT_ANACTRL_HP_HOLD_GND 0x00000020
1588 +#define BM_AUDIOOUT_ANACTRL_HP_CLASSAB 0x00000010
1589 +#define BP_AUDIOOUT_ANACTRL_RSRVD1 0
1590 +#define BM_AUDIOOUT_ANACTRL_RSRVD1 0x0000000F
1591 +#define BF_AUDIOOUT_ANACTRL_RSRVD1(v) \
1592 + (((v) << 0) & BM_AUDIOOUT_ANACTRL_RSRVD1)
1593 +
1594 +#define HW_AUDIOOUT_TEST (0x000000a0)
1595 +#define HW_AUDIOOUT_TEST_SET (0x000000a4)
1596 +#define HW_AUDIOOUT_TEST_CLR (0x000000a8)
1597 +#define HW_AUDIOOUT_TEST_TOG (0x000000ac)
1598 +
1599 +#define BM_AUDIOOUT_TEST_RSRVD4 0x80000000
1600 +#define BP_AUDIOOUT_TEST_HP_ANTIPOP 28
1601 +#define BM_AUDIOOUT_TEST_HP_ANTIPOP 0x70000000
1602 +#define BF_AUDIOOUT_TEST_HP_ANTIPOP(v) \
1603 + (((v) << 28) & BM_AUDIOOUT_TEST_HP_ANTIPOP)
1604 +#define BM_AUDIOOUT_TEST_RSRVD3 0x08000000
1605 +#define BM_AUDIOOUT_TEST_TM_ADCIN_TOHP 0x04000000
1606 +#define BM_AUDIOOUT_TEST_TM_LOOP 0x02000000
1607 +#define BM_AUDIOOUT_TEST_TM_HPCOMMON 0x01000000
1608 +#define BP_AUDIOOUT_TEST_HP_I1_ADJ 22
1609 +#define BM_AUDIOOUT_TEST_HP_I1_ADJ 0x00C00000
1610 +#define BF_AUDIOOUT_TEST_HP_I1_ADJ(v) \
1611 + (((v) << 22) & BM_AUDIOOUT_TEST_HP_I1_ADJ)
1612 +#define BP_AUDIOOUT_TEST_HP_IALL_ADJ 20
1613 +#define BM_AUDIOOUT_TEST_HP_IALL_ADJ 0x00300000
1614 +#define BF_AUDIOOUT_TEST_HP_IALL_ADJ(v) \
1615 + (((v) << 20) & BM_AUDIOOUT_TEST_HP_IALL_ADJ)
1616 +#define BP_AUDIOOUT_TEST_RSRVD2 14
1617 +#define BM_AUDIOOUT_TEST_RSRVD2 0x000FC000
1618 +#define BF_AUDIOOUT_TEST_RSRVD2(v) \
1619 + (((v) << 14) & BM_AUDIOOUT_TEST_RSRVD2)
1620 +#define BM_AUDIOOUT_TEST_VAG_CLASSA 0x00002000
1621 +#define BM_AUDIOOUT_TEST_VAG_DOUBLE_I 0x00001000
1622 +#define BP_AUDIOOUT_TEST_RSRVD1 4
1623 +#define BM_AUDIOOUT_TEST_RSRVD1 0x00000FF0
1624 +#define BF_AUDIOOUT_TEST_RSRVD1(v) \
1625 + (((v) << 4) & BM_AUDIOOUT_TEST_RSRVD1)
1626 +#define BM_AUDIOOUT_TEST_ADCTODAC_LOOP 0x00000008
1627 +#define BM_AUDIOOUT_TEST_DAC_CLASSA 0x00000004
1628 +#define BM_AUDIOOUT_TEST_DAC_DOUBLE_I 0x00000002
1629 +#define BM_AUDIOOUT_TEST_DAC_DIS_RTZ 0x00000001
1630 +
1631 +#define HW_AUDIOOUT_BISTCTRL (0x000000b0)
1632 +#define HW_AUDIOOUT_BISTCTRL_SET (0x000000b4)
1633 +#define HW_AUDIOOUT_BISTCTRL_CLR (0x000000b8)
1634 +#define HW_AUDIOOUT_BISTCTRL_TOG (0x000000bc)
1635 +
1636 +#define BP_AUDIOOUT_BISTCTRL_RSVD0 4
1637 +#define BM_AUDIOOUT_BISTCTRL_RSVD0 0xFFFFFFF0
1638 +#define BF_AUDIOOUT_BISTCTRL_RSVD0(v) \
1639 + (((v) << 4) & BM_AUDIOOUT_BISTCTRL_RSVD0)
1640 +#define BM_AUDIOOUT_BISTCTRL_FAIL 0x00000008
1641 +#define BM_AUDIOOUT_BISTCTRL_PASS 0x00000004
1642 +#define BM_AUDIOOUT_BISTCTRL_DONE 0x00000002
1643 +#define BM_AUDIOOUT_BISTCTRL_START 0x00000001
1644 +
1645 +#define HW_AUDIOOUT_BISTSTAT0 (0x000000c0)
1646 +#define HW_AUDIOOUT_BISTSTAT0_SET (0x000000c4)
1647 +#define HW_AUDIOOUT_BISTSTAT0_CLR (0x000000c8)
1648 +#define HW_AUDIOOUT_BISTSTAT0_TOG (0x000000cc)
1649 +
1650 +#define BP_AUDIOOUT_BISTSTAT0_RSVD0 24
1651 +#define BM_AUDIOOUT_BISTSTAT0_RSVD0 0xFF000000
1652 +#define BF_AUDIOOUT_BISTSTAT0_RSVD0(v) \
1653 + (((v) << 24) & BM_AUDIOOUT_BISTSTAT0_RSVD0)
1654 +#define BP_AUDIOOUT_BISTSTAT0_DATA 0
1655 +#define BM_AUDIOOUT_BISTSTAT0_DATA 0x00FFFFFF
1656 +#define BF_AUDIOOUT_BISTSTAT0_DATA(v) \
1657 + (((v) << 0) & BM_AUDIOOUT_BISTSTAT0_DATA)
1658 +
1659 +#define HW_AUDIOOUT_BISTSTAT1 (0x000000d0)
1660 +#define HW_AUDIOOUT_BISTSTAT1_SET (0x000000d4)
1661 +#define HW_AUDIOOUT_BISTSTAT1_CLR (0x000000d8)
1662 +#define HW_AUDIOOUT_BISTSTAT1_TOG (0x000000dc)
1663 +
1664 +#define BP_AUDIOOUT_BISTSTAT1_RSVD1 29
1665 +#define BM_AUDIOOUT_BISTSTAT1_RSVD1 0xE0000000
1666 +#define BF_AUDIOOUT_BISTSTAT1_RSVD1(v) \
1667 + (((v) << 29) & BM_AUDIOOUT_BISTSTAT1_RSVD1)
1668 +#define BP_AUDIOOUT_BISTSTAT1_STATE 24
1669 +#define BM_AUDIOOUT_BISTSTAT1_STATE 0x1F000000
1670 +#define BF_AUDIOOUT_BISTSTAT1_STATE(v) \
1671 + (((v) << 24) & BM_AUDIOOUT_BISTSTAT1_STATE)
1672 +#define BP_AUDIOOUT_BISTSTAT1_RSVD0 8
1673 +#define BM_AUDIOOUT_BISTSTAT1_RSVD0 0x00FFFF00
1674 +#define BF_AUDIOOUT_BISTSTAT1_RSVD0(v) \
1675 + (((v) << 8) & BM_AUDIOOUT_BISTSTAT1_RSVD0)
1676 +#define BP_AUDIOOUT_BISTSTAT1_ADDR 0
1677 +#define BM_AUDIOOUT_BISTSTAT1_ADDR 0x000000FF
1678 +#define BF_AUDIOOUT_BISTSTAT1_ADDR(v) \
1679 + (((v) << 0) & BM_AUDIOOUT_BISTSTAT1_ADDR)
1680 +
1681 +#define HW_AUDIOOUT_ANACLKCTRL (0x000000e0)
1682 +#define HW_AUDIOOUT_ANACLKCTRL_SET (0x000000e4)
1683 +#define HW_AUDIOOUT_ANACLKCTRL_CLR (0x000000e8)
1684 +#define HW_AUDIOOUT_ANACLKCTRL_TOG (0x000000ec)
1685 +
1686 +#define BM_AUDIOOUT_ANACLKCTRL_CLKGATE 0x80000000
1687 +#define BP_AUDIOOUT_ANACLKCTRL_RSRVD3 5
1688 +#define BM_AUDIOOUT_ANACLKCTRL_RSRVD3 0x7FFFFFE0
1689 +#define BF_AUDIOOUT_ANACLKCTRL_RSRVD3(v) \
1690 + (((v) << 5) & BM_AUDIOOUT_ANACLKCTRL_RSRVD3)
1691 +#define BM_AUDIOOUT_ANACLKCTRL_INVERT_DACCLK 0x00000010
1692 +#define BM_AUDIOOUT_ANACLKCTRL_RSRVD2 0x00000008
1693 +#define BP_AUDIOOUT_ANACLKCTRL_DACDIV 0
1694 +#define BM_AUDIOOUT_ANACLKCTRL_DACDIV 0x00000007
1695 +#define BF_AUDIOOUT_ANACLKCTRL_DACDIV(v) \
1696 + (((v) << 0) & BM_AUDIOOUT_ANACLKCTRL_DACDIV)
1697 +
1698 +#define HW_AUDIOOUT_DATA (0x000000f0)
1699 +#define HW_AUDIOOUT_DATA_SET (0x000000f4)
1700 +#define HW_AUDIOOUT_DATA_CLR (0x000000f8)
1701 +#define HW_AUDIOOUT_DATA_TOG (0x000000fc)
1702 +
1703 +#define BP_AUDIOOUT_DATA_HIGH 16
1704 +#define BM_AUDIOOUT_DATA_HIGH 0xFFFF0000
1705 +#define BF_AUDIOOUT_DATA_HIGH(v) \
1706 + (((v) << 16) & BM_AUDIOOUT_DATA_HIGH)
1707 +#define BP_AUDIOOUT_DATA_LOW 0
1708 +#define BM_AUDIOOUT_DATA_LOW 0x0000FFFF
1709 +#define BF_AUDIOOUT_DATA_LOW(v) \
1710 + (((v) << 0) & BM_AUDIOOUT_DATA_LOW)
1711 +
1712 +#define HW_AUDIOOUT_SPEAKERCTRL (0x00000100)
1713 +#define HW_AUDIOOUT_SPEAKERCTRL_SET (0x00000104)
1714 +#define HW_AUDIOOUT_SPEAKERCTRL_CLR (0x00000108)
1715 +#define HW_AUDIOOUT_SPEAKERCTRL_TOG (0x0000010c)
1716 +
1717 +#define BP_AUDIOOUT_SPEAKERCTRL_RSRVD2 25
1718 +#define BM_AUDIOOUT_SPEAKERCTRL_RSRVD2 0xFE000000
1719 +#define BF_AUDIOOUT_SPEAKERCTRL_RSRVD2(v) \
1720 + (((v) << 25) & BM_AUDIOOUT_SPEAKERCTRL_RSRVD2)
1721 +#define BM_AUDIOOUT_SPEAKERCTRL_MUTE 0x01000000
1722 +#define BP_AUDIOOUT_SPEAKERCTRL_I1_ADJ 22
1723 +#define BM_AUDIOOUT_SPEAKERCTRL_I1_ADJ 0x00C00000
1724 +#define BF_AUDIOOUT_SPEAKERCTRL_I1_ADJ(v) \
1725 + (((v) << 22) & BM_AUDIOOUT_SPEAKERCTRL_I1_ADJ)
1726 +#define BP_AUDIOOUT_SPEAKERCTRL_IALL_ADJ 20
1727 +#define BM_AUDIOOUT_SPEAKERCTRL_IALL_ADJ 0x00300000
1728 +#define BF_AUDIOOUT_SPEAKERCTRL_IALL_ADJ(v) \
1729 + (((v) << 20) & BM_AUDIOOUT_SPEAKERCTRL_IALL_ADJ)
1730 +#define BP_AUDIOOUT_SPEAKERCTRL_RSRVD1 16
1731 +#define BM_AUDIOOUT_SPEAKERCTRL_RSRVD1 0x000F0000
1732 +#define BF_AUDIOOUT_SPEAKERCTRL_RSRVD1(v) \
1733 + (((v) << 16) & BM_AUDIOOUT_SPEAKERCTRL_RSRVD1)
1734 +#define BP_AUDIOOUT_SPEAKERCTRL_POSDRIVER 14
1735 +#define BM_AUDIOOUT_SPEAKERCTRL_POSDRIVER 0x0000C000
1736 +#define BF_AUDIOOUT_SPEAKERCTRL_POSDRIVER(v) \
1737 + (((v) << 14) & BM_AUDIOOUT_SPEAKERCTRL_POSDRIVER)
1738 +#define BP_AUDIOOUT_SPEAKERCTRL_NEGDRIVER 12
1739 +#define BM_AUDIOOUT_SPEAKERCTRL_NEGDRIVER 0x00003000
1740 +#define BF_AUDIOOUT_SPEAKERCTRL_NEGDRIVER(v) \
1741 + (((v) << 12) & BM_AUDIOOUT_SPEAKERCTRL_NEGDRIVER)
1742 +#define BP_AUDIOOUT_SPEAKERCTRL_RSRVD0 0
1743 +#define BM_AUDIOOUT_SPEAKERCTRL_RSRVD0 0x00000FFF
1744 +#define BF_AUDIOOUT_SPEAKERCTRL_RSRVD0(v) \
1745 + (((v) << 0) & BM_AUDIOOUT_SPEAKERCTRL_RSRVD0)
1746 +
1747 +#define HW_AUDIOOUT_VERSION (0x00000200)
1748 +
1749 +#define BP_AUDIOOUT_VERSION_MAJOR 24
1750 +#define BM_AUDIOOUT_VERSION_MAJOR 0xFF000000
1751 +#define BF_AUDIOOUT_VERSION_MAJOR(v) \
1752 + (((v) << 24) & BM_AUDIOOUT_VERSION_MAJOR)
1753 +#define BP_AUDIOOUT_VERSION_MINOR 16
1754 +#define BM_AUDIOOUT_VERSION_MINOR 0x00FF0000
1755 +#define BF_AUDIOOUT_VERSION_MINOR(v) \
1756 + (((v) << 16) & BM_AUDIOOUT_VERSION_MINOR)
1757 +#define BP_AUDIOOUT_VERSION_STEP 0
1758 +#define BM_AUDIOOUT_VERSION_STEP 0x0000FFFF
1759 +#define BF_AUDIOOUT_VERSION_STEP(v) \
1760 + (((v) << 0) & BM_AUDIOOUT_VERSION_STEP)
1761 +
1762 +/* AUDIOIN */
1763 +#define HW_AUDIOIN_CTRL (0x00000000)
1764 +#define HW_AUDIOIN_CTRL_SET (0x00000004)
1765 +#define HW_AUDIOIN_CTRL_CLR (0x00000008)
1766 +#define HW_AUDIOIN_CTRL_TOG (0x0000000c)
1767 +
1768 +#define BM_AUDIOIN_CTRL_SFTRST 0x80000000
1769 +#define BM_AUDIOIN_CTRL_CLKGATE 0x40000000
1770 +#define BP_AUDIOIN_CTRL_RSRVD3 21
1771 +#define BM_AUDIOIN_CTRL_RSRVD3 0x3FE00000
1772 +#define BF_AUDIOIN_CTRL_RSRVD3(v) \
1773 + (((v) << 21) & BM_AUDIOIN_CTRL_RSRVD3)
1774 +#define BP_AUDIOIN_CTRL_DMAWAIT_COUNT 16
1775 +#define BM_AUDIOIN_CTRL_DMAWAIT_COUNT 0x001F0000
1776 +#define BF_AUDIOIN_CTRL_DMAWAIT_COUNT(v) \
1777 + (((v) << 16) & BM_AUDIOIN_CTRL_DMAWAIT_COUNT)
1778 +#define BP_AUDIOIN_CTRL_RSRVD1 11
1779 +#define BM_AUDIOIN_CTRL_RSRVD1 0x0000F800
1780 +#define BF_AUDIOIN_CTRL_RSRVD1(v) \
1781 + (((v) << 11) & BM_AUDIOIN_CTRL_RSRVD1)
1782 +#define BM_AUDIOIN_CTRL_LR_SWAP 0x00000400
1783 +#define BM_AUDIOIN_CTRL_EDGE_SYNC 0x00000200
1784 +#define BM_AUDIOIN_CTRL_INVERT_1BIT 0x00000100
1785 +#define BM_AUDIOIN_CTRL_OFFSET_ENABLE 0x00000080
1786 +#define BM_AUDIOIN_CTRL_HPF_ENABLE 0x00000040
1787 +#define BM_AUDIOIN_CTRL_WORD_LENGTH 0x00000020
1788 +#define BM_AUDIOIN_CTRL_LOOPBACK 0x00000010
1789 +#define BM_AUDIOIN_CTRL_FIFO_UNDERFLOW_IRQ 0x00000008
1790 +#define BM_AUDIOIN_CTRL_FIFO_OVERFLOW_IRQ 0x00000004
1791 +#define BM_AUDIOIN_CTRL_FIFO_ERROR_IRQ_EN 0x00000002
1792 +#define BM_AUDIOIN_CTRL_RUN 0x00000001
1793 +
1794 +#define HW_AUDIOIN_STAT (0x00000010)
1795 +#define HW_AUDIOIN_STAT_SET (0x00000014)
1796 +#define HW_AUDIOIN_STAT_CLR (0x00000018)
1797 +#define HW_AUDIOIN_STAT_TOG (0x0000001c)
1798 +
1799 +#define BM_AUDIOIN_STAT_ADC_PRESENT 0x80000000
1800 +#define BP_AUDIOIN_STAT_RSRVD3 0
1801 +#define BM_AUDIOIN_STAT_RSRVD3 0x7FFFFFFF
1802 +#define BF_AUDIOIN_STAT_RSRVD3(v) \
1803 + (((v) << 0) & BM_AUDIOIN_STAT_RSRVD3)
1804 +
1805 +#define HW_AUDIOIN_ADCSRR (0x00000020)
1806 +#define HW_AUDIOIN_ADCSRR_SET (0x00000024)
1807 +#define HW_AUDIOIN_ADCSRR_CLR (0x00000028)
1808 +#define HW_AUDIOIN_ADCSRR_TOG (0x0000002c)
1809 +
1810 +#define BM_AUDIOIN_ADCSRR_OSR 0x80000000
1811 +#define BV_AUDIOIN_ADCSRR_OSR__OSR6 0x0
1812 +#define BV_AUDIOIN_ADCSRR_OSR__OSR12 0x1
1813 +#define BP_AUDIOIN_ADCSRR_BASEMULT 28
1814 +#define BM_AUDIOIN_ADCSRR_BASEMULT 0x70000000
1815 +#define BF_AUDIOIN_ADCSRR_BASEMULT(v) \
1816 + (((v) << 28) & BM_AUDIOIN_ADCSRR_BASEMULT)
1817 +#define BV_AUDIOIN_ADCSRR_BASEMULT__SINGLE_RATE 0x1
1818 +#define BV_AUDIOIN_ADCSRR_BASEMULT__DOUBLE_RATE 0x2
1819 +#define BV_AUDIOIN_ADCSRR_BASEMULT__QUAD_RATE 0x4
1820 +#define BM_AUDIOIN_ADCSRR_RSRVD2 0x08000000
1821 +#define BP_AUDIOIN_ADCSRR_SRC_HOLD 24
1822 +#define BM_AUDIOIN_ADCSRR_SRC_HOLD 0x07000000
1823 +#define BF_AUDIOIN_ADCSRR_SRC_HOLD(v) \
1824 + (((v) << 24) & BM_AUDIOIN_ADCSRR_SRC_HOLD)
1825 +#define BP_AUDIOIN_ADCSRR_RSRVD1 21
1826 +#define BM_AUDIOIN_ADCSRR_RSRVD1 0x00E00000
1827 +#define BF_AUDIOIN_ADCSRR_RSRVD1(v) \
1828 + (((v) << 21) & BM_AUDIOIN_ADCSRR_RSRVD1)
1829 +#define BP_AUDIOIN_ADCSRR_SRC_INT 16
1830 +#define BM_AUDIOIN_ADCSRR_SRC_INT 0x001F0000
1831 +#define BF_AUDIOIN_ADCSRR_SRC_INT(v) \
1832 + (((v) << 16) & BM_AUDIOIN_ADCSRR_SRC_INT)
1833 +#define BP_AUDIOIN_ADCSRR_RSRVD0 13
1834 +#define BM_AUDIOIN_ADCSRR_RSRVD0 0x0000E000
1835 +#define BF_AUDIOIN_ADCSRR_RSRVD0(v) \
1836 + (((v) << 13) & BM_AUDIOIN_ADCSRR_RSRVD0)
1837 +#define BP_AUDIOIN_ADCSRR_SRC_FRAC 0
1838 +#define BM_AUDIOIN_ADCSRR_SRC_FRAC 0x00001FFF
1839 +#define BF_AUDIOIN_ADCSRR_SRC_FRAC(v) \
1840 + (((v) << 0) & BM_AUDIOIN_ADCSRR_SRC_FRAC)
1841 +
1842 +#define HW_AUDIOIN_ADCVOLUME (0x00000030)
1843 +#define HW_AUDIOIN_ADCVOLUME_SET (0x00000034)
1844 +#define HW_AUDIOIN_ADCVOLUME_CLR (0x00000038)
1845 +#define HW_AUDIOIN_ADCVOLUME_TOG (0x0000003c)
1846 +
1847 +#define BP_AUDIOIN_ADCVOLUME_RSRVD5 29
1848 +#define BM_AUDIOIN_ADCVOLUME_RSRVD5 0xE0000000
1849 +#define BF_AUDIOIN_ADCVOLUME_RSRVD5(v) \
1850 + (((v) << 29) & BM_AUDIOIN_ADCVOLUME_RSRVD5)
1851 +#define BM_AUDIOIN_ADCVOLUME_VOLUME_UPDATE_LEFT 0x10000000
1852 +#define BP_AUDIOIN_ADCVOLUME_RSRVD4 26
1853 +#define BM_AUDIOIN_ADCVOLUME_RSRVD4 0x0C000000
1854 +#define BF_AUDIOIN_ADCVOLUME_RSRVD4(v) \
1855 + (((v) << 26) & BM_AUDIOIN_ADCVOLUME_RSRVD4)
1856 +#define BM_AUDIOIN_ADCVOLUME_EN_ZCD 0x02000000
1857 +#define BM_AUDIOIN_ADCVOLUME_RSRVD3 0x01000000
1858 +#define BP_AUDIOIN_ADCVOLUME_VOLUME_LEFT 16
1859 +#define BM_AUDIOIN_ADCVOLUME_VOLUME_LEFT 0x00FF0000
1860 +#define BF_AUDIOIN_ADCVOLUME_VOLUME_LEFT(v) \
1861 + (((v) << 16) & BM_AUDIOIN_ADCVOLUME_VOLUME_LEFT)
1862 +#define BP_AUDIOIN_ADCVOLUME_RSRVD2 13
1863 +#define BM_AUDIOIN_ADCVOLUME_RSRVD2 0x0000E000
1864 +#define BF_AUDIOIN_ADCVOLUME_RSRVD2(v) \
1865 + (((v) << 13) & BM_AUDIOIN_ADCVOLUME_RSRVD2)
1866 +#define BM_AUDIOIN_ADCVOLUME_VOLUME_UPDATE_RIGHT 0x00001000
1867 +#define BP_AUDIOIN_ADCVOLUME_RSRVD1 8
1868 +#define BM_AUDIOIN_ADCVOLUME_RSRVD1 0x00000F00
1869 +#define BF_AUDIOIN_ADCVOLUME_RSRVD1(v) \
1870 + (((v) << 8) & BM_AUDIOIN_ADCVOLUME_RSRVD1)
1871 +#define BP_AUDIOIN_ADCVOLUME_VOLUME_RIGHT 0
1872 +#define BM_AUDIOIN_ADCVOLUME_VOLUME_RIGHT 0x000000FF
1873 +#define BF_AUDIOIN_ADCVOLUME_VOLUME_RIGHT(v) \
1874 + (((v) << 0) & BM_AUDIOIN_ADCVOLUME_VOLUME_RIGHT)
1875 +
1876 +#define HW_AUDIOIN_ADCDEBUG (0x00000040)
1877 +#define HW_AUDIOIN_ADCDEBUG_SET (0x00000044)
1878 +#define HW_AUDIOIN_ADCDEBUG_CLR (0x00000048)
1879 +#define HW_AUDIOIN_ADCDEBUG_TOG (0x0000004c)
1880 +
1881 +#define BM_AUDIOIN_ADCDEBUG_ENABLE_ADCDMA 0x80000000
1882 +#define BP_AUDIOIN_ADCDEBUG_RSRVD1 4
1883 +#define BM_AUDIOIN_ADCDEBUG_RSRVD1 0x7FFFFFF0
1884 +#define BF_AUDIOIN_ADCDEBUG_RSRVD1(v) \
1885 + (((v) << 4) & BM_AUDIOIN_ADCDEBUG_RSRVD1)
1886 +#define BM_AUDIOIN_ADCDEBUG_ADC_DMA_REQ_HAND_SHAKE_CLK_CROSS 0x00000008
1887 +#define BM_AUDIOIN_ADCDEBUG_SET_INTERRUPT3_HAND_SHAKE 0x00000004
1888 +#define BM_AUDIOIN_ADCDEBUG_DMA_PREQ 0x00000002
1889 +#define BM_AUDIOIN_ADCDEBUG_FIFO_STATUS 0x00000001
1890 +
1891 +#define HW_AUDIOIN_ADCVOL (0x00000050)
1892 +#define HW_AUDIOIN_ADCVOL_SET (0x00000054)
1893 +#define HW_AUDIOIN_ADCVOL_CLR (0x00000058)
1894 +#define HW_AUDIOIN_ADCVOL_TOG (0x0000005c)
1895 +
1896 +#define BP_AUDIOIN_ADCVOL_RSRVD4 29
1897 +#define BM_AUDIOIN_ADCVOL_RSRVD4 0xE0000000
1898 +#define BF_AUDIOIN_ADCVOL_RSRVD4(v) \
1899 + (((v) << 29) & BM_AUDIOIN_ADCVOL_RSRVD4)
1900 +#define BM_AUDIOIN_ADCVOL_VOLUME_UPDATE_PENDING 0x10000000
1901 +#define BP_AUDIOIN_ADCVOL_RSRVD3 26
1902 +#define BM_AUDIOIN_ADCVOL_RSRVD3 0x0C000000
1903 +#define BF_AUDIOIN_ADCVOL_RSRVD3(v) \
1904 + (((v) << 26) & BM_AUDIOIN_ADCVOL_RSRVD3)
1905 +#define BM_AUDIOIN_ADCVOL_EN_ADC_ZCD 0x02000000
1906 +#define BM_AUDIOIN_ADCVOL_MUTE 0x01000000
1907 +#define BP_AUDIOIN_ADCVOL_RSRVD2 14
1908 +#define BM_AUDIOIN_ADCVOL_RSRVD2 0x00FFC000
1909 +#define BF_AUDIOIN_ADCVOL_RSRVD2(v) \
1910 + (((v) << 14) & BM_AUDIOIN_ADCVOL_RSRVD2)
1911 +#define BP_AUDIOIN_ADCVOL_SELECT_LEFT 12
1912 +#define BM_AUDIOIN_ADCVOL_SELECT_LEFT 0x00003000
1913 +#define BF_AUDIOIN_ADCVOL_SELECT_LEFT(v) \
1914 + (((v) << 12) & BM_AUDIOIN_ADCVOL_SELECT_LEFT)
1915 +#define BP_AUDIOIN_ADCVOL_GAIN_LEFT 8
1916 +#define BM_AUDIOIN_ADCVOL_GAIN_LEFT 0x00000F00
1917 +#define BF_AUDIOIN_ADCVOL_GAIN_LEFT(v) \
1918 + (((v) << 8) & BM_AUDIOIN_ADCVOL_GAIN_LEFT)
1919 +#define BP_AUDIOIN_ADCVOL_RSRVD1 6
1920 +#define BM_AUDIOIN_ADCVOL_RSRVD1 0x000000C0
1921 +#define BF_AUDIOIN_ADCVOL_RSRVD1(v) \
1922 + (((v) << 6) & BM_AUDIOIN_ADCVOL_RSRVD1)
1923 +#define BP_AUDIOIN_ADCVOL_SELECT_RIGHT 4
1924 +#define BM_AUDIOIN_ADCVOL_SELECT_RIGHT 0x00000030
1925 +#define BF_AUDIOIN_ADCVOL_SELECT_RIGHT(v) \
1926 + (((v) << 4) & BM_AUDIOIN_ADCVOL_SELECT_RIGHT)
1927 +#define BP_AUDIOIN_ADCVOL_GAIN_RIGHT 0
1928 +#define BM_AUDIOIN_ADCVOL_GAIN_RIGHT 0x0000000F
1929 +#define BF_AUDIOIN_ADCVOL_GAIN_RIGHT(v) \
1930 + (((v) << 0) & BM_AUDIOIN_ADCVOL_GAIN_RIGHT)
1931 +
1932 +#define HW_AUDIOIN_MICLINE (0x00000060)
1933 +#define HW_AUDIOIN_MICLINE_SET (0x00000064)
1934 +#define HW_AUDIOIN_MICLINE_CLR (0x00000068)
1935 +#define HW_AUDIOIN_MICLINE_TOG (0x0000006c)
1936 +
1937 +#define BP_AUDIOIN_MICLINE_RSRVD6 30
1938 +#define BM_AUDIOIN_MICLINE_RSRVD6 0xC0000000
1939 +#define BF_AUDIOIN_MICLINE_RSRVD6(v) \
1940 + (((v) << 30) & BM_AUDIOIN_MICLINE_RSRVD6)
1941 +#define BM_AUDIOIN_MICLINE_DIVIDE_LINE1 0x20000000
1942 +#define BM_AUDIOIN_MICLINE_DIVIDE_LINE2 0x10000000
1943 +#define BP_AUDIOIN_MICLINE_RSRVD5 25
1944 +#define BM_AUDIOIN_MICLINE_RSRVD5 0x0E000000
1945 +#define BF_AUDIOIN_MICLINE_RSRVD5(v) \
1946 + (((v) << 25) & BM_AUDIOIN_MICLINE_RSRVD5)
1947 +#define BM_AUDIOIN_MICLINE_MIC_SELECT 0x01000000
1948 +#define BP_AUDIOIN_MICLINE_RSRVD4 22
1949 +#define BM_AUDIOIN_MICLINE_RSRVD4 0x00C00000
1950 +#define BF_AUDIOIN_MICLINE_RSRVD4(v) \
1951 + (((v) << 22) & BM_AUDIOIN_MICLINE_RSRVD4)
1952 +#define BP_AUDIOIN_MICLINE_MIC_RESISTOR 20
1953 +#define BM_AUDIOIN_MICLINE_MIC_RESISTOR 0x00300000
1954 +#define BF_AUDIOIN_MICLINE_MIC_RESISTOR(v) \
1955 + (((v) << 20) & BM_AUDIOIN_MICLINE_MIC_RESISTOR)
1956 +#define BM_AUDIOIN_MICLINE_RSRVD3 0x00080000
1957 +#define BP_AUDIOIN_MICLINE_MIC_BIAS 16
1958 +#define BM_AUDIOIN_MICLINE_MIC_BIAS 0x00070000
1959 +#define BF_AUDIOIN_MICLINE_MIC_BIAS(v) \
1960 + (((v) << 16) & BM_AUDIOIN_MICLINE_MIC_BIAS)
1961 +#define BP_AUDIOIN_MICLINE_RSRVD2 6
1962 +#define BM_AUDIOIN_MICLINE_RSRVD2 0x0000FFC0
1963 +#define BF_AUDIOIN_MICLINE_RSRVD2(v) \
1964 + (((v) << 6) & BM_AUDIOIN_MICLINE_RSRVD2)
1965 +#define BP_AUDIOIN_MICLINE_MIC_CHOPCLK 4
1966 +#define BM_AUDIOIN_MICLINE_MIC_CHOPCLK 0x00000030
1967 +#define BF_AUDIOIN_MICLINE_MIC_CHOPCLK(v) \
1968 + (((v) << 4) & BM_AUDIOIN_MICLINE_MIC_CHOPCLK)
1969 +#define BP_AUDIOIN_MICLINE_RSRVD1 2
1970 +#define BM_AUDIOIN_MICLINE_RSRVD1 0x0000000C
1971 +#define BF_AUDIOIN_MICLINE_RSRVD1(v) \
1972 + (((v) << 2) & BM_AUDIOIN_MICLINE_RSRVD1)
1973 +#define BP_AUDIOIN_MICLINE_MIC_GAIN 0
1974 +#define BM_AUDIOIN_MICLINE_MIC_GAIN 0x00000003
1975 +#define BF_AUDIOIN_MICLINE_MIC_GAIN(v) \
1976 + (((v) << 0) & BM_AUDIOIN_MICLINE_MIC_GAIN)
1977 +
1978 +#define HW_AUDIOIN_ANACLKCTRL (0x00000070)
1979 +#define HW_AUDIOIN_ANACLKCTRL_SET (0x00000074)
1980 +#define HW_AUDIOIN_ANACLKCTRL_CLR (0x00000078)
1981 +#define HW_AUDIOIN_ANACLKCTRL_TOG (0x0000007c)
1982 +
1983 +#define BM_AUDIOIN_ANACLKCTRL_CLKGATE 0x80000000
1984 +#define BP_AUDIOIN_ANACLKCTRL_RSRVD4 11
1985 +#define BM_AUDIOIN_ANACLKCTRL_RSRVD4 0x7FFFF800
1986 +#define BF_AUDIOIN_ANACLKCTRL_RSRVD4(v) \
1987 + (((v) << 11) & BM_AUDIOIN_ANACLKCTRL_RSRVD4)
1988 +#define BM_AUDIOIN_ANACLKCTRL_DITHER_OFF 0x00000400
1989 +#define BM_AUDIOIN_ANACLKCTRL_SLOW_DITHER 0x00000200
1990 +#define BM_AUDIOIN_ANACLKCTRL_INVERT_ADCCLK 0x00000100
1991 +#define BP_AUDIOIN_ANACLKCTRL_RSRVD3 6
1992 +#define BM_AUDIOIN_ANACLKCTRL_RSRVD3 0x000000C0
1993 +#define BF_AUDIOIN_ANACLKCTRL_RSRVD3(v) \
1994 + (((v) << 6) & BM_AUDIOIN_ANACLKCTRL_RSRVD3)
1995 +#define BP_AUDIOIN_ANACLKCTRL_ADCCLK_SHIFT 4
1996 +#define BM_AUDIOIN_ANACLKCTRL_ADCCLK_SHIFT 0x00000030
1997 +#define BF_AUDIOIN_ANACLKCTRL_ADCCLK_SHIFT(v) \
1998 + (((v) << 4) & BM_AUDIOIN_ANACLKCTRL_ADCCLK_SHIFT)
1999 +#define BM_AUDIOIN_ANACLKCTRL_RSRVD2 0x00000008
2000 +#define BP_AUDIOIN_ANACLKCTRL_ADCDIV 0
2001 +#define BM_AUDIOIN_ANACLKCTRL_ADCDIV 0x00000007
2002 +#define BF_AUDIOIN_ANACLKCTRL_ADCDIV(v) \
2003 + (((v) << 0) & BM_AUDIOIN_ANACLKCTRL_ADCDIV)
2004 +
2005 +#define HW_AUDIOIN_DATA (0x00000080)
2006 +#define HW_AUDIOIN_DATA_SET (0x00000084)
2007 +#define HW_AUDIOIN_DATA_CLR (0x00000088)
2008 +#define HW_AUDIOIN_DATA_TOG (0x0000008c)
2009 +
2010 +#define BP_AUDIOIN_DATA_HIGH 16
2011 +#define BM_AUDIOIN_DATA_HIGH 0xFFFF0000
2012 +#define BF_AUDIOIN_DATA_HIGH(v) \
2013 + (((v) << 16) & BM_AUDIOIN_DATA_HIGH)
2014 +#define BP_AUDIOIN_DATA_LOW 0
2015 +#define BM_AUDIOIN_DATA_LOW 0x0000FFFF
2016 +#define BF_AUDIOIN_DATA_LOW(v) \
2017 + (((v) << 0) & BM_AUDIOIN_DATA_LOW)
2018 +
2019 +#define BV_AUDIOIN_ADCVOL_SELECT__MIC 0x00
2020 +
2021 +#endif /* __MXS_ADC_CODEC_H */
2022 --- a/sound/soc/mxs/Kconfig
2023 +++ b/sound/soc/mxs/Kconfig
2024 @@ -19,3 +19,13 @@ config SND_SOC_MXS_SGTL5000
2025 a sgtl5000 codec.
2026
2027 endif # SND_MXS_SOC
2028 +
2029 +
2030 +config SND_MXS_SOC_BUILTIN
2031 + tristate "SoC Audio for Freescale i.MX23 built-in codec"
2032 + depends on ARCH_MXS
2033 + select SND_SOC_GENERIC_DMAENGINE_PCM
2034 + select SND_SOC_MXS_BUILTIN_CODEC
2035 + help
2036 + Say Y or M if you want to add support for codecs attached to
2037 + the MXS SAIF interface.
2038 --- a/sound/soc/mxs/Makefile
2039 +++ b/sound/soc/mxs/Makefile
2040 @@ -8,3 +8,12 @@ obj-$(CONFIG_SND_MXS_SOC) += snd-soc-mxs
2041 snd-soc-mxs-sgtl5000-objs := mxs-sgtl5000.o
2042
2043 obj-$(CONFIG_SND_SOC_MXS_SGTL5000) += snd-soc-mxs-sgtl5000.o
2044 +
2045 +# i.MX23 built-in audio Machine and Platform support
2046 +snd-soc-mxs-builtin-pcm-objs := mxs-builtin-pcm.o
2047 +snd-soc-mxs-builtin-dai-objs := mxs-builtin-dai.o
2048 +snd-soc-mxs-builtin-audio-objs := mxs-builtin-audio.o
2049 +
2050 +obj-$(CONFIG_SND_MXS_SOC_BUILTIN) += snd-soc-mxs-builtin-pcm.o
2051 +obj-$(CONFIG_SND_MXS_SOC_BUILTIN) += snd-soc-mxs-builtin-dai.o
2052 +obj-$(CONFIG_SND_MXS_SOC_BUILTIN) += snd-soc-mxs-builtin-audio.o
2053 --- /dev/null
2054 +++ b/sound/soc/mxs/mxs-builtin-audio.c
2055 @@ -0,0 +1,120 @@
2056 +/*
2057 + * mxs-builtin-audio.c -- i.MX233 built-in codec ALSA Soc Audio driver
2058 + *
2059 + * Author: Michal Ulianko <michal.ulianko@gmail.com>
2060 + *
2061 + * This program is free software; you can redistribute it and/or modify
2062 + * it under the terms of the GNU General Public License version 2 as
2063 + * published by the Free Software Foundation.
2064 + */
2065 +
2066 +#include <linux/module.h>
2067 +#include <linux/device.h>
2068 +#include <linux/of.h>
2069 +#include <linux/of_device.h>
2070 +#include <sound/core.h>
2071 +#include <sound/pcm.h>
2072 +#include <sound/soc.h>
2073 +#include <sound/jack.h>
2074 +#include <sound/soc-dapm.h>
2075 +#include <asm/mach-types.h>
2076 +
2077 +static struct snd_soc_dai_link mxs_adc_dai_link[] = {
2078 + {
2079 + .name = "MXS ADC/DAC",
2080 + .stream_name = "MXS ADC/DAC",
2081 + .codec_dai_name = "mxs-builtin-codec-dai",
2082 +// .codec_name = "mxs-builtin-codec",
2083 +// .cpu_dai_name = "mxs-builtin-cpu-dai",
2084 +// .platform_name = "mxs-builtin-cpu-dai",
2085 +// .ops = &mxs_sgtl5000_hifi_ops,
2086 + },
2087 +};
2088 +
2089 +static struct snd_soc_card mxs_adc_audio = {
2090 + .name = "mxs-builtin-audio",
2091 + .owner = THIS_MODULE,
2092 + .dai_link = mxs_adc_dai_link,
2093 + .num_links = ARRAY_SIZE(mxs_adc_dai_link),
2094 +};
2095 +
2096 +static int mxsadc_audio_probe_dt(struct platform_device *pdev)
2097 +{
2098 + struct device_node *np = pdev->dev.of_node;
2099 + struct device_node *cpu_dai_np, *codec_np;
2100 + int ret = 0;
2101 +
2102 + if (!np)
2103 + return 1; /* no device tree */
2104 +
2105 + cpu_dai_np = of_parse_phandle(np, "cpu-dai", 0);
2106 + codec_np = of_parse_phandle(np, "audio-codec", 0);
2107 + if (!cpu_dai_np || !codec_np) {
2108 + dev_err(&pdev->dev, "phandle missing or invalid\n");
2109 + return -EINVAL;
2110 + }
2111 +
2112 + mxs_adc_dai_link[0].codec_name = NULL;
2113 + mxs_adc_dai_link[0].codec_of_node = codec_np;
2114 + mxs_adc_dai_link[0].cpu_dai_name = NULL;
2115 + mxs_adc_dai_link[0].cpu_of_node = cpu_dai_np;
2116 + mxs_adc_dai_link[0].platform_name = NULL;
2117 + mxs_adc_dai_link[0].platform_of_node = cpu_dai_np;
2118 +
2119 +// of_node_put(codec_np);
2120 +// of_node_put(cpu_dai_np);
2121 +
2122 + return ret;
2123 +}
2124 +
2125 +static int mxsadc_audio_probe(struct platform_device *pdev)
2126 +{
2127 + struct snd_soc_card *card = &mxs_adc_audio;
2128 + int ret;
2129 +
2130 + ret = mxsadc_audio_probe_dt(pdev);
2131 + if (ret < 0)
2132 + return ret;
2133 +
2134 + card->dev = &pdev->dev;
2135 + platform_set_drvdata(pdev, card);
2136 +
2137 + ret = snd_soc_register_card(card);
2138 + if (ret) {
2139 + dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
2140 + return ret;
2141 + }
2142 +
2143 + return 0;
2144 +}
2145 +
2146 +static int mxsadc_audio_remove(struct platform_device *pdev)
2147 +{
2148 + struct snd_soc_card *card = platform_get_drvdata(pdev);
2149 +
2150 + snd_soc_unregister_card(card);
2151 +
2152 + return 0;
2153 +}
2154 +
2155 +static const struct of_device_id mxs_adc_audio_dt_ids[] = {
2156 + { .compatible = "fsl,mxs-builtin-audio", },
2157 + { /* sentinel */ }
2158 +};
2159 +MODULE_DEVICE_TABLE(of, mxs_adc_audio_dt_ids);
2160 +
2161 +static struct platform_driver mxs_adc_audio_driver = {
2162 + .driver = {
2163 + .name = "mxs-builtin-audio",
2164 + .owner = THIS_MODULE,
2165 + .of_match_table = mxs_adc_audio_dt_ids,
2166 + },
2167 + .probe = mxsadc_audio_probe,
2168 + .remove = mxsadc_audio_remove,
2169 +};
2170 +
2171 +module_platform_driver(mxs_adc_audio_driver);
2172 +
2173 +MODULE_DESCRIPTION("Freescale MXS ADC/DAC SoC Machine Driver");
2174 +MODULE_AUTHOR("Michal Ulianko <michal.ulianko@gmail.com>");
2175 +MODULE_LICENSE("GPL");
2176 --- /dev/null
2177 +++ b/sound/soc/mxs/mxs-builtin-dai.c
2178 @@ -0,0 +1,588 @@
2179 +/*
2180 + * mxs-builtin-dai.c -- i.MX233 built-in codec ALSA Soc Audio driver
2181 + *
2182 + * Author: Michal Ulianko <michal.ulianko@gmail.com>
2183 + *
2184 + * Based on sound/soc/mxs/mxs-adc.c for kernel 2.6.35
2185 + * by Vladislav Buzov <vbuzov@embeddedalley.com>
2186 + *
2187 + * This program is free software; you can redistribute it and/or modify
2188 + * it under the terms of the GNU General Public License version 2 as
2189 + * published by the Free Software Foundation.
2190 + */
2191 +
2192 +#include <linux/module.h>
2193 +#include <linux/init.h>
2194 +#include <linux/interrupt.h>
2195 +#include <linux/delay.h>
2196 +#include <linux/dma-mapping.h>
2197 +#include <linux/platform_device.h>
2198 +#include <sound/pcm.h>
2199 +#include <sound/pcm_params.h>
2200 +#include <sound/soc.h>
2201 +
2202 +#include "../codecs/mxs-builtin-codec.h"
2203 +#include "mxs-builtin-pcm.h"
2204 +
2205 +#define ADC_VOLUME_MIN 0x37
2206 +
2207 +/* TODO Use codec IO function soc snd write etc, instead of __writel __readl */
2208 +
2209 +// TODO use container_of
2210 +struct mxs_irq_data {
2211 + struct snd_pcm_substream *substream;
2212 + struct mxs_adc_priv *mxs_adc;
2213 +};
2214 +
2215 +struct mxs_adc_priv {
2216 + struct mxs_irq_data irq_data;
2217 + int dma_adc_err_irq;
2218 + int dma_dac_err_irq;
2219 + int hp_short_irq;
2220 + void __iomem *audioin_base;
2221 + void __iomem *audioout_base;
2222 + void __iomem *rtc_base;
2223 +};
2224 +
2225 +typedef struct {
2226 + struct work_struct work;
2227 + struct timer_list timer;
2228 +
2229 + /* target workqueue and CPU ->timer uses to queue ->work */
2230 + struct workqueue_struct *wq;
2231 + int cpu;
2232 +
2233 + struct mxs_adc_priv *mxs_adc;
2234 +} my_delayed_work_t;
2235 +
2236 +// static struct delayed_work work;
2237 +// static struct delayed_work adc_ramp_work;
2238 +// static struct delayed_work dac_ramp_work;
2239 +// static struct delayed_work test;
2240 +static my_delayed_work_t work;
2241 +static my_delayed_work_t adc_ramp_work;
2242 +static my_delayed_work_t dac_ramp_work;
2243 +static my_delayed_work_t test;
2244 +static bool adc_ramp_done = 1;
2245 +static bool dac_ramp_done = 1;
2246 +
2247 +static inline void mxs_adc_schedule_work(struct delayed_work *work)
2248 +{
2249 + schedule_delayed_work(work, HZ / 10);
2250 +}
2251 +
2252 +static void mxs_adc_work(struct work_struct *work)
2253 +{
2254 + struct mxs_adc_priv *mxs_adc = ((my_delayed_work_t *)work)->mxs_adc;
2255 + /* disable irq */
2256 + disable_irq(mxs_adc->hp_short_irq);
2257 +
2258 + while (true) {
2259 + __raw_writel(BM_AUDIOOUT_PWRDN_HEADPHONE,
2260 + mxs_adc->audioout_base + HW_AUDIOOUT_PWRDN_CLR);
2261 + msleep(10);
2262 + if ((__raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_ANACTRL)
2263 + & BM_AUDIOOUT_ANACTRL_SHORT_LR_STS) != 0) {
2264 + /* rearm the short protection */
2265 + __raw_writel(BM_AUDIOOUT_ANACTRL_SHORTMODE_LR,
2266 + mxs_adc->audioout_base + HW_AUDIOOUT_ANACTRL_CLR);
2267 + __raw_writel(BM_AUDIOOUT_ANACTRL_SHORT_LR_STS,
2268 + mxs_adc->audioout_base + HW_AUDIOOUT_ANACTRL_CLR);
2269 + __raw_writel(BF_AUDIOOUT_ANACTRL_SHORTMODE_LR(0x1),
2270 + mxs_adc->audioout_base + HW_AUDIOOUT_ANACTRL_SET);
2271 +
2272 + __raw_writel(BM_AUDIOOUT_PWRDN_HEADPHONE,
2273 + mxs_adc->audioout_base + HW_AUDIOOUT_PWRDN_SET);
2274 + printk(KERN_WARNING "WARNING : Headphone LR short!\r\n");
2275 + } else {
2276 + printk(KERN_WARNING "INFO : Headphone LR no longer short!\r\n");
2277 + break;
2278 + }
2279 + msleep(1000);
2280 + }
2281 +
2282 + /* power up the HEADPHONE and un-mute the HPVOL */
2283 + __raw_writel(BM_AUDIOOUT_HPVOL_MUTE,
2284 + mxs_adc->audioout_base + HW_AUDIOOUT_HPVOL_CLR);
2285 + __raw_writel(BM_AUDIOOUT_PWRDN_HEADPHONE,
2286 + mxs_adc->audioout_base + HW_AUDIOOUT_PWRDN_CLR);
2287 +
2288 + /* enable irq for next short detect*/
2289 + enable_irq(mxs_adc->hp_short_irq);
2290 +}
2291 +
2292 +static void mxs_adc_schedule_ramp_work(struct delayed_work *work)
2293 +{
2294 + schedule_delayed_work(work, msecs_to_jiffies(2));
2295 + adc_ramp_done = 0;
2296 +}
2297 +
2298 +static void mxs_adc_ramp_work(struct work_struct *work)
2299 +{
2300 + struct mxs_adc_priv *mxs_adc = ((my_delayed_work_t *)work)->mxs_adc;
2301 + u32 reg = 0;
2302 + u32 reg1 = 0;
2303 + u32 reg2 = 0;
2304 + u32 l, r;
2305 + u32 ll, rr;
2306 + int i;
2307 +
2308 + reg = __raw_readl(mxs_adc->audioin_base + \
2309 + HW_AUDIOIN_ADCVOLUME);
2310 +
2311 + reg1 = reg & ~BM_AUDIOIN_ADCVOLUME_VOLUME_LEFT;
2312 + reg1 = reg1 & ~BM_AUDIOIN_ADCVOLUME_VOLUME_RIGHT;
2313 + /* minimize adc volume */
2314 + reg2 = reg1 |
2315 + BF_AUDIOIN_ADCVOLUME_VOLUME_LEFT(ADC_VOLUME_MIN) |
2316 + BF_AUDIOIN_ADCVOLUME_VOLUME_RIGHT(ADC_VOLUME_MIN);
2317 + __raw_writel(reg2,
2318 + mxs_adc->audioin_base + HW_AUDIOIN_ADCVOLUME);
2319 + msleep(1);
2320 +
2321 + l = (reg & BM_AUDIOIN_ADCVOLUME_VOLUME_LEFT) >>
2322 + BP_AUDIOIN_ADCVOLUME_VOLUME_LEFT;
2323 + r = (reg & BM_AUDIOIN_ADCVOLUME_VOLUME_RIGHT) >>
2324 + BP_AUDIOIN_ADCVOLUME_VOLUME_RIGHT;
2325 +
2326 + /* fade in adc vol */
2327 + for (i = ADC_VOLUME_MIN; (i < l) || (i < r);) {
2328 + i += 0x8;
2329 + ll = i < l ? i : l;
2330 + rr = i < r ? i : r;
2331 + reg2 = reg1 |
2332 + BF_AUDIOIN_ADCVOLUME_VOLUME_LEFT(ll) |
2333 + BF_AUDIOIN_ADCVOLUME_VOLUME_RIGHT(rr);
2334 + __raw_writel(reg2,
2335 + mxs_adc->audioin_base + HW_AUDIOIN_ADCVOLUME);
2336 + msleep(1);
2337 + }
2338 + adc_ramp_done = 1;
2339 +}
2340 +
2341 +static void mxs_dac_schedule_ramp_work(struct delayed_work *work)
2342 +{
2343 + schedule_delayed_work(work, msecs_to_jiffies(2));
2344 + dac_ramp_done = 0;
2345 +}
2346 +
2347 +static void mxs_dac_ramp_work(struct work_struct *work)
2348 +{
2349 + struct mxs_adc_priv *mxs_adc = ((my_delayed_work_t *)work)->mxs_adc;
2350 + u32 reg = 0;
2351 + u32 reg1 = 0;
2352 + u32 l, r;
2353 + u32 ll, rr;
2354 + int i;
2355 +
2356 + /* unmute hp and speaker */
2357 + __raw_writel(BM_AUDIOOUT_HPVOL_MUTE,
2358 + mxs_adc->audioout_base + HW_AUDIOOUT_HPVOL_CLR);
2359 + __raw_writel(BM_AUDIOOUT_SPEAKERCTRL_MUTE,
2360 + mxs_adc->audioout_base + HW_AUDIOOUT_SPEAKERCTRL_CLR);
2361 +
2362 + reg = __raw_readl(mxs_adc->audioout_base + \
2363 + HW_AUDIOOUT_HPVOL);
2364 +
2365 + reg1 = reg & ~BM_AUDIOOUT_HPVOL_VOL_LEFT;
2366 + reg1 = reg1 & ~BM_AUDIOOUT_HPVOL_VOL_RIGHT;
2367 +
2368 + l = (reg & BM_AUDIOOUT_HPVOL_VOL_LEFT) >>
2369 + BP_AUDIOOUT_HPVOL_VOL_LEFT;
2370 + r = (reg & BM_AUDIOOUT_HPVOL_VOL_RIGHT) >>
2371 + BP_AUDIOOUT_HPVOL_VOL_RIGHT;
2372 + /* fade in hp vol */
2373 + for (i = 0x7f; i > 0 ;) {
2374 + i -= 0x8;
2375 + ll = i > (int)l ? i : l;
2376 + rr = i > (int)r ? i : r;
2377 + reg = reg1 | BF_AUDIOOUT_HPVOL_VOL_LEFT(ll)
2378 + | BF_AUDIOOUT_HPVOL_VOL_RIGHT(rr);
2379 + __raw_writel(reg,
2380 + mxs_adc->audioout_base + HW_AUDIOOUT_HPVOL);
2381 + msleep(1);
2382 + }
2383 + dac_ramp_done = 1;
2384 +}
2385 +
2386 +/* IRQs */
2387 +static irqreturn_t mxs_short_irq(int irq, void *dev_id)
2388 +{
2389 + struct mxs_adc_priv *mxs_adc = dev_id;
2390 + //struct snd_pcm_substream *substream = mxs_adc->irq_data.substream;
2391 +
2392 + __raw_writel(BM_AUDIOOUT_ANACTRL_SHORTMODE_LR,
2393 + mxs_adc->audioout_base + HW_AUDIOOUT_ANACTRL_CLR);
2394 + __raw_writel(BM_AUDIOOUT_ANACTRL_SHORT_LR_STS,
2395 + mxs_adc->audioout_base + HW_AUDIOOUT_ANACTRL_CLR);
2396 + __raw_writel(BF_AUDIOOUT_ANACTRL_SHORTMODE_LR(0x1),
2397 + mxs_adc->audioout_base + HW_AUDIOOUT_ANACTRL_SET);
2398 +
2399 + __raw_writel(BM_AUDIOOUT_HPVOL_MUTE,
2400 + mxs_adc->audioout_base + HW_AUDIOOUT_HPVOL_SET);
2401 + __raw_writel(BM_AUDIOOUT_PWRDN_HEADPHONE,
2402 + mxs_adc->audioout_base + HW_AUDIOOUT_PWRDN_SET);
2403 + __raw_writel(BM_AUDIOOUT_ANACTRL_HP_CLASSAB,
2404 + mxs_adc->audioout_base + HW_AUDIOOUT_ANACTRL_SET);
2405 +
2406 + mxs_adc_schedule_work((struct delayed_work *) &work);
2407 + return IRQ_HANDLED;
2408 +}
2409 +
2410 +static irqreturn_t mxs_err_irq(int irq, void *dev_id)
2411 +{
2412 + struct mxs_adc_priv *mxs_adc = dev_id;
2413 + struct snd_pcm_substream *substream = mxs_adc->irq_data.substream;
2414 + int playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0;
2415 + u32 ctrl_reg;
2416 + u32 overflow_mask;
2417 + u32 underflow_mask;
2418 +
2419 + if (playback) {
2420 + ctrl_reg = __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_CTRL);
2421 + underflow_mask = BM_AUDIOOUT_CTRL_FIFO_UNDERFLOW_IRQ;
2422 + overflow_mask = BM_AUDIOOUT_CTRL_FIFO_OVERFLOW_IRQ;
2423 + } else {
2424 + ctrl_reg = __raw_readl(mxs_adc->audioin_base + HW_AUDIOIN_CTRL);
2425 + underflow_mask = BM_AUDIOIN_CTRL_FIFO_UNDERFLOW_IRQ;
2426 + overflow_mask = BM_AUDIOIN_CTRL_FIFO_OVERFLOW_IRQ;
2427 + }
2428 +
2429 + if (ctrl_reg & underflow_mask) {
2430 + printk(KERN_DEBUG "%s underflow detected\n",
2431 + playback ? "DAC" : "ADC");
2432 +
2433 + if (playback)
2434 + __raw_writel(
2435 + BM_AUDIOOUT_CTRL_FIFO_UNDERFLOW_IRQ,
2436 + mxs_adc->audioout_base + HW_AUDIOOUT_CTRL_CLR);
2437 + else
2438 + __raw_writel(
2439 + BM_AUDIOIN_CTRL_FIFO_UNDERFLOW_IRQ,
2440 + mxs_adc->audioin_base + HW_AUDIOIN_CTRL_CLR);
2441 +
2442 + } else if (ctrl_reg & overflow_mask) {
2443 + printk(KERN_DEBUG "%s overflow detected\n",
2444 + playback ? "DAC" : "ADC");
2445 +
2446 + if (playback)
2447 + __raw_writel(
2448 + BM_AUDIOOUT_CTRL_FIFO_OVERFLOW_IRQ,
2449 + mxs_adc->audioout_base + HW_AUDIOOUT_CTRL_CLR);
2450 + else
2451 + __raw_writel(BM_AUDIOIN_CTRL_FIFO_OVERFLOW_IRQ,
2452 + mxs_adc->audioin_base + HW_AUDIOIN_CTRL_CLR);
2453 + } else
2454 + printk(KERN_WARNING "Unknown DAC error interrupt\n");
2455 +
2456 + return IRQ_HANDLED;
2457 +}
2458 +/* END IRQs */
2459 +
2460 +static int mxs_trigger(struct snd_pcm_substream *substream,
2461 + int cmd,
2462 + struct snd_soc_dai *cpu_dai)
2463 +{
2464 + struct mxs_adc_priv *mxs_adc = snd_soc_dai_get_drvdata(cpu_dai);
2465 + int playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0;
2466 + int ret = 0;
2467 +
2468 + switch (cmd) {
2469 + case SNDRV_PCM_TRIGGER_START:
2470 + case SNDRV_PCM_TRIGGER_RESUME:
2471 + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
2472 +
2473 + if (playback) {
2474 + /* enable the fifo error interrupt */
2475 + __raw_writel(BM_AUDIOOUT_CTRL_FIFO_ERROR_IRQ_EN,
2476 + mxs_adc->audioout_base + HW_AUDIOOUT_CTRL_SET);
2477 + /* write a data to data reg to trigger the transfer */
2478 + __raw_writel(0x0,
2479 + mxs_adc->audioout_base + HW_AUDIOOUT_DATA);
2480 + mxs_dac_schedule_ramp_work((struct delayed_work *) &dac_ramp_work);
2481 + } else {
2482 +// mxs_dma_get_info(prtd->dma_ch, &dma_info);
2483 +// cur_bar1 = dma_info.buf_addr;
2484 +// xfer_count1 = dma_info.xfer_count;
2485 +
2486 + __raw_writel(BM_AUDIOIN_CTRL_RUN,
2487 + mxs_adc->audioin_base + HW_AUDIOIN_CTRL_SET);
2488 + udelay(100);
2489 +
2490 +// mxs_dma_get_info(prtd->dma_ch, &dma_info);
2491 +// cur_bar2 = dma_info.buf_addr;
2492 +// xfer_count2 = dma_info.xfer_count;
2493 +//
2494 +// /* check if DMA getting stuck */
2495 +// if ((xfer_count1 == xfer_count2) && (cur_bar1 == cur_bar2))
2496 +// /* read a data from data reg to trigger the receive */
2497 +// reg = __raw_readl(mxs_adc->audioin_base + HW_AUDIOIN_DATA);
2498 +
2499 + mxs_adc_schedule_ramp_work((struct delayed_work *) &adc_ramp_work);
2500 + }
2501 + break;
2502 +
2503 + case SNDRV_PCM_TRIGGER_SUSPEND:
2504 + case SNDRV_PCM_TRIGGER_STOP:
2505 + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
2506 +
2507 + if (playback) {
2508 +// printk(KERN_INFO "SNDRV_PCM_TRIGGER_START\n");
2509 +// printk(KERN_INFO "ctrl:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_CTRL));
2510 +// printk(KERN_INFO "stat:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_STAT));
2511 +// printk(KERN_INFO "srr:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_DACSRR));
2512 +// printk(KERN_INFO "vol:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_DACVOLUME));
2513 +// printk(KERN_INFO "debug:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_DACDEBUG));
2514 +// printk(KERN_INFO "hpvol:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_HPVOL));
2515 +// printk(KERN_INFO "pwrdn:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_PWRDN));
2516 +// printk(KERN_INFO "refc:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_REFCTRL));
2517 +// printk(KERN_INFO "anac:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_ANACTRL));
2518 +// printk(KERN_INFO "test:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_TEST));
2519 +// printk(KERN_INFO "bist:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_BISTCTRL));
2520 +// printk(KERN_INFO "anaclk:%x\n", __raw_readl(mxs_adc->audioout_base + HW_AUDIOOUT_ANACLKCTRL));
2521 +
2522 + if (dac_ramp_done == 0) {
2523 + cancel_delayed_work((struct delayed_work *) &dac_ramp_work);
2524 + dac_ramp_done = 1;
2525 + }
2526 + __raw_writel(BM_AUDIOOUT_HPVOL_MUTE,
2527 + mxs_adc->audioout_base + HW_AUDIOOUT_HPVOL_SET);
2528 + __raw_writel(BM_AUDIOOUT_SPEAKERCTRL_MUTE,
2529 + mxs_adc->audioout_base + HW_AUDIOOUT_SPEAKERCTRL_SET);
2530 + /* disable the fifo error interrupt */
2531 + __raw_writel(BM_AUDIOOUT_CTRL_FIFO_ERROR_IRQ_EN,
2532 + mxs_adc->audioout_base + HW_AUDIOOUT_CTRL_CLR);
2533 + mdelay(50);
2534 + } else {
2535 + if (adc_ramp_done == 0) {
2536 + cancel_delayed_work((struct delayed_work *) &adc_ramp_work);
2537 + adc_ramp_done = 1;
2538 + }
2539 + __raw_writel(BM_AUDIOIN_CTRL_RUN,
2540 + mxs_adc->audioin_base + HW_AUDIOIN_CTRL_CLR);
2541 + }
2542 + break;
2543 +
2544 + default:
2545 + printk(KERN_ERR "TRIGGER ERROR\n");
2546 + ret = -EINVAL;
2547 + }
2548 +
2549 + return ret;
2550 +}
2551 +
2552 +static int mxs_startup(struct snd_pcm_substream *substream,
2553 + struct snd_soc_dai *cpu_dai)
2554 +{
2555 + struct mxs_adc_priv *mxs_adc = snd_soc_dai_get_drvdata(cpu_dai);
2556 + int playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0;
2557 + mxs_adc->irq_data.mxs_adc = mxs_adc;
2558 + mxs_adc->irq_data.substream = substream;
2559 +
2560 + work.mxs_adc = mxs_adc;
2561 + adc_ramp_work.mxs_adc = mxs_adc;
2562 + dac_ramp_work.mxs_adc = mxs_adc;
2563 + test.mxs_adc = mxs_adc;
2564 + INIT_DELAYED_WORK(&work, mxs_adc_work);
2565 + INIT_DELAYED_WORK(&adc_ramp_work, mxs_adc_ramp_work);
2566 + INIT_DELAYED_WORK(&dac_ramp_work, mxs_dac_ramp_work);
2567 +
2568 + /* Enable error interrupt */
2569 + if (playback) {
2570 + __raw_writel(BM_AUDIOOUT_CTRL_FIFO_OVERFLOW_IRQ,
2571 + mxs_adc->audioout_base + HW_AUDIOOUT_CTRL_CLR);
2572 + __raw_writel(BM_AUDIOOUT_CTRL_FIFO_UNDERFLOW_IRQ,
2573 + mxs_adc->audioout_base + HW_AUDIOOUT_CTRL_CLR);
2574 + } else {
2575 + __raw_writel(BM_AUDIOIN_CTRL_FIFO_OVERFLOW_IRQ,
2576 + mxs_adc->audioin_base + HW_AUDIOIN_CTRL_CLR);
2577 + __raw_writel(BM_AUDIOIN_CTRL_FIFO_UNDERFLOW_IRQ,
2578 + mxs_adc->audioin_base + HW_AUDIOIN_CTRL_CLR);
2579 + __raw_writel(BM_AUDIOIN_CTRL_FIFO_ERROR_IRQ_EN,
2580 + mxs_adc->audioin_base + HW_AUDIOIN_CTRL_SET);
2581 + }
2582 +
2583 + return 0;
2584 +}
2585 +
2586 +static void mxs_shutdown(struct snd_pcm_substream *substream,
2587 + struct snd_soc_dai *cpu_dai)
2588 +{
2589 + struct mxs_adc_priv *mxs_adc = snd_soc_dai_get_drvdata(cpu_dai);
2590 + int playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0;
2591 +
2592 + /* Disable error interrupt */
2593 + if (playback) {
2594 + __raw_writel(BM_AUDIOOUT_CTRL_FIFO_ERROR_IRQ_EN,
2595 + mxs_adc->audioout_base + HW_AUDIOOUT_CTRL_CLR);
2596 + } else {
2597 + __raw_writel(BM_AUDIOIN_CTRL_FIFO_ERROR_IRQ_EN,
2598 + mxs_adc->audioin_base + HW_AUDIOIN_CTRL_CLR);
2599 + }
2600 +}
2601 +
2602 +#define MXS_ADC_RATES SNDRV_PCM_RATE_8000_192000
2603 +#define MXS_ADC_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
2604 +
2605 +static const struct snd_soc_dai_ops mxs_adc_dai_ops = {
2606 + .startup = mxs_startup,
2607 + .trigger = mxs_trigger,
2608 + .shutdown = mxs_shutdown,
2609 +};
2610 +
2611 +static int mxs_dai_probe(struct snd_soc_dai *dai)
2612 +{
2613 + // TODO This does not make any sense.
2614 + struct mxs_adc_priv *mxs_adc = dev_get_drvdata(dai->dev);
2615 +
2616 + snd_soc_dai_set_drvdata(dai, mxs_adc);
2617 +
2618 + return 0;
2619 +}
2620 +
2621 +static struct snd_soc_dai_driver mxs_adc_dai = {
2622 + .name = "mxs-builtin-cpu-dai",
2623 + .probe = mxs_dai_probe,
2624 + .playback = {
2625 + .channels_min = 2,
2626 + .channels_max = 2,
2627 + .rates = MXS_ADC_RATES,
2628 + .formats = MXS_ADC_FORMATS,
2629 + },
2630 + .capture = {
2631 + .channels_min = 2,
2632 + .channels_max = 2,
2633 + .rates = MXS_ADC_RATES,
2634 + .formats = MXS_ADC_FORMATS,
2635 + },
2636 + .ops = &mxs_adc_dai_ops,
2637 +};
2638 +
2639 +static const struct snd_soc_component_driver mxs_adc_component = {
2640 + .name = "mxs-xxx", //TODO change this name
2641 +};
2642 +
2643 +static int mxs_adc_probe(struct platform_device *pdev)
2644 +{
2645 + struct device_node *np = pdev->dev.of_node;
2646 + struct mxs_adc_priv *mxs_adc;
2647 + int ret = 0;
2648 +
2649 + if (!np)
2650 + return -EINVAL;
2651 +
2652 + mxs_adc = devm_kzalloc(&pdev->dev, sizeof(*mxs_adc), GFP_KERNEL);
2653 + if (!mxs_adc)
2654 + return -ENOMEM;
2655 +
2656 + mxs_adc->audioout_base = devm_ioremap(&pdev->dev, 0x80048000, 0x2000);
2657 + if (IS_ERR(mxs_adc->audioout_base))
2658 + return PTR_ERR(mxs_adc->audioout_base);
2659 +
2660 + mxs_adc->audioin_base = devm_ioremap(&pdev->dev, 0x8004c000, 0x2000);
2661 + if (IS_ERR(mxs_adc->audioin_base))
2662 + return PTR_ERR(mxs_adc->audioin_base);
2663 +
2664 + mxs_adc->rtc_base = devm_ioremap(&pdev->dev, 0x8005c000, 0x2000);
2665 + if (IS_ERR(mxs_adc->rtc_base))
2666 + return PTR_ERR(mxs_adc->rtc_base);
2667 +
2668 + /* Get IRQ numbers */
2669 + mxs_adc->dma_adc_err_irq = platform_get_irq(pdev, 0);
2670 + if (mxs_adc->dma_adc_err_irq < 0) {
2671 + ret = mxs_adc->dma_adc_err_irq;
2672 + dev_err(&pdev->dev, "failed to get ADC DMA ERR irq resource: %d\n", ret);
2673 + return ret;
2674 + }
2675 +
2676 + mxs_adc->dma_dac_err_irq = platform_get_irq(pdev, 1);
2677 + if (mxs_adc->dma_dac_err_irq < 0) {
2678 + ret = mxs_adc->dma_dac_err_irq;
2679 + dev_err(&pdev->dev, "failed to get DAC DMA ERR irq resource: %d\n", ret);
2680 + return ret;
2681 + }
2682 +
2683 + mxs_adc->hp_short_irq = platform_get_irq(pdev, 2);
2684 + if (mxs_adc->hp_short_irq < 0) {
2685 + ret = mxs_adc->hp_short_irq;
2686 + dev_err(&pdev->dev, "failed to get HP_SHORT irq resource: %d\n", ret);
2687 + return ret;
2688 + }
2689 +
2690 + /* Request IRQs */
2691 + ret = devm_request_irq(&pdev->dev, mxs_adc->dma_adc_err_irq, mxs_err_irq, 0, "MXS DAC and ADC Error",
2692 + mxs_adc);
2693 + if (ret) {
2694 + printk(KERN_ERR "%s: Unable to request ADC/DAC error irq %d\n",
2695 + __func__, mxs_adc->dma_adc_err_irq);
2696 + return ret;
2697 + }
2698 +
2699 + ret = devm_request_irq(&pdev->dev, mxs_adc->dma_dac_err_irq, mxs_err_irq, 0, "MXS DAC and ADC Error",
2700 + mxs_adc);
2701 + if (ret) {
2702 + printk(KERN_ERR "%s: Unable to request ADC/DAC error irq %d\n",
2703 + __func__, mxs_adc->dma_dac_err_irq);
2704 + return ret;
2705 + }
2706 +
2707 + ret = devm_request_irq(&pdev->dev, mxs_adc->hp_short_irq, mxs_short_irq,
2708 + IRQF_DISABLED | IRQF_SHARED, "MXS DAC and ADC HP SHORT", mxs_adc);
2709 + if (ret) {
2710 + printk(KERN_ERR "%s: Unable to request ADC/DAC HP SHORT irq %d\n",
2711 + __func__, mxs_adc->hp_short_irq);
2712 + return ret;
2713 + }
2714 +
2715 + platform_set_drvdata(pdev, mxs_adc);
2716 +
2717 + ret = snd_soc_register_component(&pdev->dev, &mxs_adc_component, &mxs_adc_dai, 1);
2718 + if (ret) {
2719 + dev_err(&pdev->dev, "register DAI failed\n");
2720 + return ret;
2721 + }
2722 +
2723 + ret = mxs_adc_pcm_platform_register(&pdev->dev);
2724 + if (ret) {
2725 + dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
2726 + goto failed_pdev_alloc;
2727 + }
2728 +
2729 + return 0;
2730 +
2731 +failed_pdev_alloc:
2732 + snd_soc_unregister_component(&pdev->dev);
2733 +
2734 + return ret;
2735 +}
2736 +
2737 +static int mxs_adc_remove(struct platform_device *pdev)
2738 +{
2739 + mxs_adc_pcm_platform_unregister(&pdev->dev);
2740 + snd_soc_unregister_component(&pdev->dev);
2741 +
2742 + return 0;
2743 +}
2744 +
2745 +static const struct of_device_id mxs_adc_dai_dt_ids[] = {
2746 + { .compatible = "fsl,mxs-builtin-cpu-dai", },
2747 + { /* sentinel */ }
2748 +};
2749 +MODULE_DEVICE_TABLE(of, mxs_adc_dai_dt_ids);
2750 +
2751 +static struct platform_driver mxs_adc_dai_driver = {
2752 + .probe = mxs_adc_probe,
2753 + .remove = mxs_adc_remove,
2754 +
2755 + .driver = {
2756 + .name = "mxs-builtin-cpu-dai",
2757 + .owner = THIS_MODULE,
2758 + .of_match_table = mxs_adc_dai_dt_ids,
2759 + },
2760 +};
2761 +
2762 +module_platform_driver(mxs_adc_dai_driver);
2763 +
2764 +MODULE_DESCRIPTION("Freescale MXS ADC/DAC SoC Codec DAI Driver");
2765 +MODULE_AUTHOR("Michal Ulianko <michal.ulianko@gmail.com>");
2766 +MODULE_LICENSE("GPL");
2767 --- /dev/null
2768 +++ b/sound/soc/mxs/mxs-builtin-pcm.c
2769 @@ -0,0 +1,69 @@
2770 +/*
2771 + * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
2772 + *
2773 + * Based on sound/soc/imx/imx-pcm-dma-mx2.c
2774 + *
2775 + * This program is free software; you can redistribute it and/or modify
2776 + * it under the terms of the GNU General Public License as published by
2777 + * the Free Software Foundation; either version 2 of the License, or
2778 + * (at your option) any later version.
2779 + *
2780 + * This program is distributed in the hope that it will be useful,
2781 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2782 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2783 + * GNU General Public License for more details.
2784 + *
2785 + * You should have received a copy of the GNU General Public License along
2786 + * with this program; if not, write to the Free Software Foundation, Inc.,
2787 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2788 + */
2789 +
2790 +#include <linux/device.h>
2791 +#include <linux/init.h>
2792 +#include <linux/module.h>
2793 +
2794 +#include <sound/core.h>
2795 +#include <sound/pcm.h>
2796 +#include <sound/soc.h>
2797 +#include <sound/dmaengine_pcm.h>
2798 +
2799 +#include "mxs-builtin-pcm.h"
2800 +
2801 +static const struct snd_pcm_hardware snd_mxs_hardware = {
2802 + .info = SNDRV_PCM_INFO_MMAP |
2803 + SNDRV_PCM_INFO_MMAP_VALID |
2804 + SNDRV_PCM_INFO_PAUSE |
2805 + SNDRV_PCM_INFO_RESUME |
2806 + SNDRV_PCM_INFO_INTERLEAVED,
2807 + .formats = SNDRV_PCM_FMTBIT_S16_LE |
2808 + SNDRV_PCM_FMTBIT_S20_3LE |
2809 + SNDRV_PCM_FMTBIT_S24_LE,
2810 + .channels_min = 2,
2811 + .channels_max = 2,
2812 + .period_bytes_min = 32,
2813 + .period_bytes_max = 8192,
2814 + .periods_min = 1,
2815 + .periods_max = 52,
2816 + .buffer_bytes_max = 64 * 1024,
2817 + .fifo_size = 32,
2818 +};
2819 +
2820 +static const struct snd_dmaengine_pcm_config mxs_dmaengine_pcm_config = {
2821 + .pcm_hardware = &snd_mxs_hardware,
2822 + .prealloc_buffer_size = 64 * 1024,
2823 +};
2824 +
2825 +int mxs_adc_pcm_platform_register(struct device *dev)
2826 +{
2827 + return snd_dmaengine_pcm_register(dev, &mxs_dmaengine_pcm_config,
2828 + SND_DMAENGINE_PCM_FLAG_NO_RESIDUE);
2829 +}
2830 +EXPORT_SYMBOL_GPL(mxs_adc_pcm_platform_register);
2831 +
2832 +void mxs_adc_pcm_platform_unregister(struct device *dev)
2833 +{
2834 + snd_dmaengine_pcm_unregister(dev);
2835 +}
2836 +EXPORT_SYMBOL_GPL(mxs_adc_pcm_platform_unregister);
2837 +
2838 +MODULE_LICENSE("GPL");
2839 --- /dev/null
2840 +++ b/sound/soc/mxs/mxs-builtin-pcm.h
2841 @@ -0,0 +1,25 @@
2842 +/*
2843 + * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
2844 + *
2845 + * This program is free software; you can redistribute it and/or modify
2846 + * it under the terms of the GNU General Public License as published by
2847 + * the Free Software Foundation; either version 2 of the License, or
2848 + * (at your option) any later version.
2849 + *
2850 + * This program is distributed in the hope that it will be useful,
2851 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2852 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2853 + * GNU General Public License for more details.
2854 + *
2855 + * You should have received a copy of the GNU General Public License along
2856 + * with this program; if not, write to the Free Software Foundation, Inc.,
2857 + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2858 + */
2859 +
2860 +#ifndef _MXS_PCM_H
2861 +#define _MXS_PCM_H
2862 +
2863 +int mxs_adc_pcm_platform_register(struct device *dev);
2864 +void mxs_adc_pcm_platform_unregister(struct device *dev);
2865 +
2866 +#endif