blob: f01e564b123838b210befb01e778091f5c6a4785 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Routines for control of AD1848/AD1847/CS4248
4 *
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#define SNDRV_MAIN_OBJECT_FILE
23#include <sound/driver.h>
24#include <linux/delay.h>
25#include <linux/init.h>
26#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/slab.h>
28#include <linux/ioport.h>
29#include <sound/core.h>
30#include <sound/ad1848.h>
31#include <sound/control.h>
Takashi Iwaieac06a12006-08-22 13:16:25 +020032#include <sound/tlv.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <sound/pcm_params.h>
34
35#include <asm/io.h>
36#include <asm/dma.h>
37
38MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
39MODULE_DESCRIPTION("Routines for control of AD1848/AD1847/CS4248");
40MODULE_LICENSE("GPL");
41
42#if 0
43#define SNDRV_DEBUG_MCE
44#endif
45
46/*
47 * Some variables
48 */
49
50static unsigned char freq_bits[14] = {
51 /* 5510 */ 0x00 | AD1848_XTAL2,
52 /* 6620 */ 0x0E | AD1848_XTAL2,
53 /* 8000 */ 0x00 | AD1848_XTAL1,
54 /* 9600 */ 0x0E | AD1848_XTAL1,
55 /* 11025 */ 0x02 | AD1848_XTAL2,
56 /* 16000 */ 0x02 | AD1848_XTAL1,
57 /* 18900 */ 0x04 | AD1848_XTAL2,
58 /* 22050 */ 0x06 | AD1848_XTAL2,
59 /* 27042 */ 0x04 | AD1848_XTAL1,
60 /* 32000 */ 0x06 | AD1848_XTAL1,
61 /* 33075 */ 0x0C | AD1848_XTAL2,
62 /* 37800 */ 0x08 | AD1848_XTAL2,
63 /* 44100 */ 0x0A | AD1848_XTAL2,
64 /* 48000 */ 0x0C | AD1848_XTAL1
65};
66
67static unsigned int rates[14] = {
68 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050,
69 27042, 32000, 33075, 37800, 44100, 48000
70};
71
Takashi Iwaic8ff6642005-11-17 14:29:37 +010072static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +020073 .count = ARRAY_SIZE(rates),
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 .list = rates,
75 .mask = 0,
76};
77
78static unsigned char snd_ad1848_original_image[16] =
79{
80 0x00, /* 00 - lic */
81 0x00, /* 01 - ric */
82 0x9f, /* 02 - la1ic */
83 0x9f, /* 03 - ra1ic */
84 0x9f, /* 04 - la2ic */
85 0x9f, /* 05 - ra2ic */
86 0xbf, /* 06 - loc */
87 0xbf, /* 07 - roc */
88 0x20, /* 08 - dfr */
89 AD1848_AUTOCALIB, /* 09 - ic */
90 0x00, /* 0a - pc */
91 0x00, /* 0b - ti */
92 0x00, /* 0c - mi */
93 0x00, /* 0d - lbc */
94 0x00, /* 0e - dru */
95 0x00, /* 0f - drl */
96};
97
98/*
99 * Basic I/O functions
100 */
101
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200102static void snd_ad1848_wait(struct snd_ad1848 *chip)
103{
104 int timeout;
105
106 for (timeout = 250; timeout > 0; timeout--) {
107 if ((inb(AD1848P(chip, REGSEL)) & AD1848_INIT) == 0)
108 break;
109 udelay(100);
110 }
111}
112
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100113void snd_ad1848_out(struct snd_ad1848 *chip,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 unsigned char reg,
115 unsigned char value)
116{
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200117 snd_ad1848_wait(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#ifdef CONFIG_SND_DEBUG
119 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200120 snd_printk(KERN_WARNING "auto calibration time out - "
121 "reg = 0x%x, value = 0x%x\n", reg, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#endif
123 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
124 outb(chip->image[reg] = value, AD1848P(chip, REG));
125 mb();
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200126 snd_printdd("codec out - reg 0x%x = 0x%x\n",
127 chip->mce_bit | reg, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
Takashi Iwaieac06a12006-08-22 13:16:25 +0200130EXPORT_SYMBOL(snd_ad1848_out);
131
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100132static void snd_ad1848_dout(struct snd_ad1848 *chip,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 unsigned char reg, unsigned char value)
134{
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200135 snd_ad1848_wait(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
137 outb(value, AD1848P(chip, REG));
138 mb();
139}
140
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100141static unsigned char snd_ad1848_in(struct snd_ad1848 *chip, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200143 snd_ad1848_wait(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#ifdef CONFIG_SND_DEBUG
145 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200146 snd_printk(KERN_WARNING "auto calibration time out - "
147 "reg = 0x%x\n", reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#endif
149 outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
150 mb();
151 return inb(AD1848P(chip, REG));
152}
153
154#if 0
155
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100156static void snd_ad1848_debug(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
158 printk("AD1848 REGS: INDEX = 0x%02x ", inb(AD1848P(chip, REGSEL)));
159 printk(" STATUS = 0x%02x\n", inb(AD1848P(chip, STATUS)));
160 printk(" 0x00: left input = 0x%02x ", snd_ad1848_in(chip, 0x00));
161 printk(" 0x08: playback format = 0x%02x\n", snd_ad1848_in(chip, 0x08));
162 printk(" 0x01: right input = 0x%02x ", snd_ad1848_in(chip, 0x01));
163 printk(" 0x09: iface (CFIG 1) = 0x%02x\n", snd_ad1848_in(chip, 0x09));
164 printk(" 0x02: AUXA left = 0x%02x ", snd_ad1848_in(chip, 0x02));
165 printk(" 0x0a: pin control = 0x%02x\n", snd_ad1848_in(chip, 0x0a));
166 printk(" 0x03: AUXA right = 0x%02x ", snd_ad1848_in(chip, 0x03));
167 printk(" 0x0b: init & status = 0x%02x\n", snd_ad1848_in(chip, 0x0b));
168 printk(" 0x04: AUXB left = 0x%02x ", snd_ad1848_in(chip, 0x04));
169 printk(" 0x0c: revision & mode = 0x%02x\n", snd_ad1848_in(chip, 0x0c));
170 printk(" 0x05: AUXB right = 0x%02x ", snd_ad1848_in(chip, 0x05));
171 printk(" 0x0d: loopback = 0x%02x\n", snd_ad1848_in(chip, 0x0d));
172 printk(" 0x06: left output = 0x%02x ", snd_ad1848_in(chip, 0x06));
173 printk(" 0x0e: data upr count = 0x%02x\n", snd_ad1848_in(chip, 0x0e));
174 printk(" 0x07: right output = 0x%02x ", snd_ad1848_in(chip, 0x07));
175 printk(" 0x0f: data lwr count = 0x%02x\n", snd_ad1848_in(chip, 0x0f));
176}
177
178#endif
179
180/*
181 * AD1848 detection / MCE routines
182 */
183
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100184static void snd_ad1848_mce_up(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
186 unsigned long flags;
187 int timeout;
188
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200189 snd_ad1848_wait(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190#ifdef CONFIG_SND_DEBUG
191 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
Takashi Iwai99b359b2005-10-20 18:26:44 +0200192 snd_printk(KERN_WARNING "mce_up - auto calibration time out (0)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193#endif
194 spin_lock_irqsave(&chip->reg_lock, flags);
195 chip->mce_bit |= AD1848_MCE;
196 timeout = inb(AD1848P(chip, REGSEL));
197 if (timeout == 0x80)
Takashi Iwai99b359b2005-10-20 18:26:44 +0200198 snd_printk(KERN_WARNING "mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if (!(timeout & AD1848_MCE))
200 outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL));
201 spin_unlock_irqrestore(&chip->reg_lock, flags);
202}
203
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100204static void snd_ad1848_mce_down(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 unsigned long flags;
207 int timeout;
208 signed long time;
209
210 spin_lock_irqsave(&chip->reg_lock, flags);
211 for (timeout = 5; timeout > 0; timeout--)
212 inb(AD1848P(chip, REGSEL));
213 /* end of cleanup sequence */
214 for (timeout = 12000; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
215 udelay(100);
216#if 0
217 printk("(1) timeout = %i\n", timeout);
218#endif
219#ifdef CONFIG_SND_DEBUG
220 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
Takashi Iwai99b359b2005-10-20 18:26:44 +0200221 snd_printk(KERN_WARNING "mce_down [0x%lx] - auto calibration time out (0)\n", AD1848P(chip, REGSEL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#endif
223 chip->mce_bit &= ~AD1848_MCE;
224 timeout = inb(AD1848P(chip, REGSEL));
225 outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL));
226 if (timeout == 0x80)
Takashi Iwai99b359b2005-10-20 18:26:44 +0200227 snd_printk(KERN_WARNING "mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if ((timeout & AD1848_MCE) == 0) {
229 spin_unlock_irqrestore(&chip->reg_lock, flags);
230 return;
231 }
232 /* calibration process */
233
234 for (timeout = 500; timeout > 0 && (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) == 0; timeout--);
235 if ((snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) == 0) {
236 snd_printd("mce_down - auto calibration time out (1)\n");
237 spin_unlock_irqrestore(&chip->reg_lock, flags);
238 return;
239 }
240#if 0
241 printk("(2) timeout = %i, jiffies = %li\n", timeout, jiffies);
242#endif
243 time = HZ / 4;
244 while (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) {
245 spin_unlock_irqrestore(&chip->reg_lock, flags);
246 if (time <= 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +0200247 snd_printk(KERN_ERR "mce_down - auto calibration time out (2)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 return;
249 }
Takashi Iwaie65365d2007-06-25 12:09:32 +0200250 time = schedule_timeout(time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 spin_lock_irqsave(&chip->reg_lock, flags);
252 }
253#if 0
254 printk("(3) jiffies = %li\n", jiffies);
255#endif
256 time = HZ / 10;
257 while (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) {
258 spin_unlock_irqrestore(&chip->reg_lock, flags);
259 if (time <= 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +0200260 snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 return;
262 }
Takashi Iwaie65365d2007-06-25 12:09:32 +0200263 time = schedule_timeout(time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 spin_lock_irqsave(&chip->reg_lock, flags);
265 }
266 spin_unlock_irqrestore(&chip->reg_lock, flags);
267#if 0
268 printk("(4) jiffies = %li\n", jiffies);
269 snd_printk("mce_down - exit = 0x%x\n", inb(AD1848P(chip, REGSEL)));
270#endif
271}
272
273static unsigned int snd_ad1848_get_count(unsigned char format,
274 unsigned int size)
275{
276 switch (format & 0xe0) {
277 case AD1848_LINEAR_16:
278 size >>= 1;
279 break;
280 }
281 if (format & AD1848_STEREO)
282 size >>= 1;
283 return size;
284}
285
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100286static int snd_ad1848_trigger(struct snd_ad1848 *chip, unsigned char what,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 int channel, int cmd)
288{
289 int result = 0;
290
291#if 0
292 printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what, enable, inb(AD1848P(card, STATUS)));
293#endif
294 spin_lock(&chip->reg_lock);
295 if (cmd == SNDRV_PCM_TRIGGER_START) {
296 if (chip->image[AD1848_IFACE_CTRL] & what) {
297 spin_unlock(&chip->reg_lock);
298 return 0;
299 }
300 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] |= what);
301 chip->mode |= AD1848_MODE_RUNNING;
302 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
303 if (!(chip->image[AD1848_IFACE_CTRL] & what)) {
304 spin_unlock(&chip->reg_lock);
305 return 0;
306 }
307 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] &= ~what);
308 chip->mode &= ~AD1848_MODE_RUNNING;
309 } else {
310 result = -EINVAL;
311 }
312 spin_unlock(&chip->reg_lock);
313 return result;
314}
315
316/*
317 * CODEC I/O
318 */
319
320static unsigned char snd_ad1848_get_rate(unsigned int rate)
321{
322 int i;
323
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200324 for (i = 0; i < ARRAY_SIZE(rates); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 if (rate == rates[i])
326 return freq_bits[i];
327 snd_BUG();
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200328 return freq_bits[ARRAY_SIZE(rates) - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329}
330
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100331static int snd_ad1848_ioctl(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 unsigned int cmd, void *arg)
333{
334 return snd_pcm_lib_ioctl(substream, cmd, arg);
335}
336
337static unsigned char snd_ad1848_get_format(int format, int channels)
338{
339 unsigned char rformat;
340
341 rformat = AD1848_LINEAR_8;
342 switch (format) {
343 case SNDRV_PCM_FORMAT_A_LAW: rformat = AD1848_ALAW_8; break;
344 case SNDRV_PCM_FORMAT_MU_LAW: rformat = AD1848_ULAW_8; break;
345 case SNDRV_PCM_FORMAT_S16_LE: rformat = AD1848_LINEAR_16; break;
346 }
347 if (channels > 1)
348 rformat |= AD1848_STEREO;
349#if 0
350 snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode);
351#endif
352 return rformat;
353}
354
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100355static void snd_ad1848_calibrate_mute(struct snd_ad1848 *chip, int mute)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357 unsigned long flags;
358
359 mute = mute ? 1 : 0;
360 spin_lock_irqsave(&chip->reg_lock, flags);
361 if (chip->calibrate_mute == mute) {
362 spin_unlock_irqrestore(&chip->reg_lock, flags);
363 return;
364 }
365 if (!mute) {
366 snd_ad1848_dout(chip, AD1848_LEFT_INPUT, chip->image[AD1848_LEFT_INPUT]);
367 snd_ad1848_dout(chip, AD1848_RIGHT_INPUT, chip->image[AD1848_RIGHT_INPUT]);
368 }
369 snd_ad1848_dout(chip, AD1848_AUX1_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_LEFT_INPUT]);
370 snd_ad1848_dout(chip, AD1848_AUX1_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_RIGHT_INPUT]);
371 snd_ad1848_dout(chip, AD1848_AUX2_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_LEFT_INPUT]);
372 snd_ad1848_dout(chip, AD1848_AUX2_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_RIGHT_INPUT]);
373 snd_ad1848_dout(chip, AD1848_LEFT_OUTPUT, mute ? 0x80 : chip->image[AD1848_LEFT_OUTPUT]);
374 snd_ad1848_dout(chip, AD1848_RIGHT_OUTPUT, mute ? 0x80 : chip->image[AD1848_RIGHT_OUTPUT]);
375 chip->calibrate_mute = mute;
376 spin_unlock_irqrestore(&chip->reg_lock, flags);
377}
378
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100379static void snd_ad1848_set_data_format(struct snd_ad1848 *chip, struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381 if (hw_params == NULL) {
382 chip->image[AD1848_DATA_FORMAT] = 0x20;
383 } else {
384 chip->image[AD1848_DATA_FORMAT] =
385 snd_ad1848_get_format(params_format(hw_params), params_channels(hw_params)) |
386 snd_ad1848_get_rate(params_rate(hw_params));
387 }
388 // snd_printk(">>> pmode = 0x%x, dfr = 0x%x\n", pstr->mode, chip->image[AD1848_DATA_FORMAT]);
389}
390
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100391static int snd_ad1848_open(struct snd_ad1848 *chip, unsigned int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
393 unsigned long flags;
394
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100395 mutex_lock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 if (chip->mode & AD1848_MODE_OPEN) {
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100397 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 return -EAGAIN;
399 }
400 snd_ad1848_mce_down(chip);
401
402#ifdef SNDRV_DEBUG_MCE
403 snd_printk("open: (1)\n");
404#endif
405 snd_ad1848_mce_up(chip);
406 spin_lock_irqsave(&chip->reg_lock, flags);
407 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO |
408 AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO |
409 AD1848_CALIB_MODE);
410 chip->image[AD1848_IFACE_CTRL] |= AD1848_AUTOCALIB;
411 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]);
412 spin_unlock_irqrestore(&chip->reg_lock, flags);
413 snd_ad1848_mce_down(chip);
414
415#ifdef SNDRV_DEBUG_MCE
416 snd_printk("open: (2)\n");
417#endif
418
419 snd_ad1848_set_data_format(chip, NULL);
420
421 snd_ad1848_mce_up(chip);
422 spin_lock_irqsave(&chip->reg_lock, flags);
423 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
424 spin_unlock_irqrestore(&chip->reg_lock, flags);
425 snd_ad1848_mce_down(chip);
426
427#ifdef SNDRV_DEBUG_MCE
428 snd_printk("open: (3)\n");
429#endif
430
431 /* ok. now enable and ack CODEC IRQ */
432 spin_lock_irqsave(&chip->reg_lock, flags);
433 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
434 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
435 chip->image[AD1848_PIN_CTRL] |= AD1848_IRQ_ENABLE;
436 snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]);
437 spin_unlock_irqrestore(&chip->reg_lock, flags);
438
439 chip->mode = mode;
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100440 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442 return 0;
443}
444
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100445static void snd_ad1848_close(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
447 unsigned long flags;
448
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100449 mutex_lock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (!chip->mode) {
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100451 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return;
453 }
454 /* disable IRQ */
455 spin_lock_irqsave(&chip->reg_lock, flags);
456 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
457 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
458 chip->image[AD1848_PIN_CTRL] &= ~AD1848_IRQ_ENABLE;
459 snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]);
460 spin_unlock_irqrestore(&chip->reg_lock, flags);
461
462 /* now disable capture & playback */
463
464 snd_ad1848_mce_up(chip);
465 spin_lock_irqsave(&chip->reg_lock, flags);
466 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO |
467 AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO);
468 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]);
469 spin_unlock_irqrestore(&chip->reg_lock, flags);
470 snd_ad1848_mce_down(chip);
471
472 /* clear IRQ again */
473 spin_lock_irqsave(&chip->reg_lock, flags);
474 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
475 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
476 spin_unlock_irqrestore(&chip->reg_lock, flags);
477
478 chip->mode = 0;
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100479 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
482/*
483 * ok.. exported functions..
484 */
485
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100486static int snd_ad1848_playback_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 int cmd)
488{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100489 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 return snd_ad1848_trigger(chip, AD1848_PLAYBACK_ENABLE, SNDRV_PCM_STREAM_PLAYBACK, cmd);
491}
492
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100493static int snd_ad1848_capture_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 int cmd)
495{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100496 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 return snd_ad1848_trigger(chip, AD1848_CAPTURE_ENABLE, SNDRV_PCM_STREAM_CAPTURE, cmd);
498}
499
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100500static int snd_ad1848_playback_hw_params(struct snd_pcm_substream *substream,
501 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100503 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 unsigned long flags;
505 int err;
506
507 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
508 return err;
509 snd_ad1848_calibrate_mute(chip, 1);
510 snd_ad1848_set_data_format(chip, hw_params);
511 snd_ad1848_mce_up(chip);
512 spin_lock_irqsave(&chip->reg_lock, flags);
513 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
514 spin_unlock_irqrestore(&chip->reg_lock, flags);
515 snd_ad1848_mce_down(chip);
516 snd_ad1848_calibrate_mute(chip, 0);
517 return 0;
518}
519
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100520static int snd_ad1848_playback_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
522 return snd_pcm_lib_free_pages(substream);
523}
524
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100525static int snd_ad1848_playback_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100527 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
528 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 unsigned long flags;
530 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
531 unsigned int count = snd_pcm_lib_period_bytes(substream);
532
533 chip->dma_size = size;
534 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO);
535 snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
536 count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1;
537 spin_lock_irqsave(&chip->reg_lock, flags);
538 snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count);
539 snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8));
540 spin_unlock_irqrestore(&chip->reg_lock, flags);
541 return 0;
542}
543
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100544static int snd_ad1848_capture_hw_params(struct snd_pcm_substream *substream,
545 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100547 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 unsigned long flags;
549 int err;
550
551 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
552 return err;
553 snd_ad1848_calibrate_mute(chip, 1);
554 snd_ad1848_set_data_format(chip, hw_params);
555 snd_ad1848_mce_up(chip);
556 spin_lock_irqsave(&chip->reg_lock, flags);
557 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
558 spin_unlock_irqrestore(&chip->reg_lock, flags);
559 snd_ad1848_mce_down(chip);
560 snd_ad1848_calibrate_mute(chip, 0);
561 return 0;
562}
563
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100564static int snd_ad1848_capture_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565{
566 return snd_pcm_lib_free_pages(substream);
567}
568
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100569static int snd_ad1848_capture_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100571 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
572 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 unsigned long flags;
574 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
575 unsigned int count = snd_pcm_lib_period_bytes(substream);
576
577 chip->dma_size = size;
578 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO);
579 snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
580 count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1;
581 spin_lock_irqsave(&chip->reg_lock, flags);
582 snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count);
583 snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8));
584 spin_unlock_irqrestore(&chip->reg_lock, flags);
585 return 0;
586}
587
David Howells7d12e782006-10-05 14:55:46 +0100588static irqreturn_t snd_ad1848_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100590 struct snd_ad1848 *chip = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 if ((chip->mode & AD1848_MODE_PLAY) && chip->playback_substream &&
593 (chip->mode & AD1848_MODE_RUNNING))
594 snd_pcm_period_elapsed(chip->playback_substream);
595 if ((chip->mode & AD1848_MODE_CAPTURE) && chip->capture_substream &&
596 (chip->mode & AD1848_MODE_RUNNING))
597 snd_pcm_period_elapsed(chip->capture_substream);
598 outb(0, AD1848P(chip, STATUS)); /* clear global interrupt bit */
599 return IRQ_HANDLED;
600}
601
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100602static snd_pcm_uframes_t snd_ad1848_playback_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100604 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 size_t ptr;
606
607 if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_PLAYBACK_ENABLE))
608 return 0;
609 ptr = snd_dma_pointer(chip->dma, chip->dma_size);
610 return bytes_to_frames(substream->runtime, ptr);
611}
612
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100613static snd_pcm_uframes_t snd_ad1848_capture_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100615 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 size_t ptr;
617
618 if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_CAPTURE_ENABLE))
619 return 0;
620 ptr = snd_dma_pointer(chip->dma, chip->dma_size);
621 return bytes_to_frames(substream->runtime, ptr);
622}
623
624/*
625
626 */
627
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100628static void snd_ad1848_thinkpad_twiddle(struct snd_ad1848 *chip, int on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630 int tmp;
631
632 if (!chip->thinkpad_flag) return;
633
634 outb(0x1c, AD1848_THINKPAD_CTL_PORT1);
635 tmp = inb(AD1848_THINKPAD_CTL_PORT2);
636
637 if (on)
638 /* turn it on */
639 tmp |= AD1848_THINKPAD_CS4248_ENABLE_BIT;
640 else
641 /* turn it off */
642 tmp &= ~AD1848_THINKPAD_CS4248_ENABLE_BIT;
643
644 outb(tmp, AD1848_THINKPAD_CTL_PORT2);
645
646}
647
648#ifdef CONFIG_PM
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100649static void snd_ad1848_suspend(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 snd_pcm_suspend_all(chip->pcm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if (chip->thinkpad_flag)
653 snd_ad1848_thinkpad_twiddle(chip, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654}
655
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100656static void snd_ad1848_resume(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657{
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100658 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 if (chip->thinkpad_flag)
661 snd_ad1848_thinkpad_twiddle(chip, 1);
662
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100663 /* clear any pendings IRQ */
664 inb(AD1848P(chip, STATUS));
665 outb(0, AD1848P(chip, STATUS));
666 mb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100668 snd_ad1848_mce_down(chip);
669 for (i = 0; i < 16; i++)
670 snd_ad1848_out(chip, i, chip->image[i]);
671 snd_ad1848_mce_up(chip);
672 snd_ad1848_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673}
674#endif /* CONFIG_PM */
675
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100676static int snd_ad1848_probe(struct snd_ad1848 * chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677{
678 unsigned long flags;
679 int i, id, rev, ad1847;
680 unsigned char *ptr;
681
682#if 0
683 snd_ad1848_debug(chip);
684#endif
685 id = ad1847 = 0;
686 for (i = 0; i < 1000; i++) {
687 mb();
688 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
689 udelay(500);
690 else {
691 spin_lock_irqsave(&chip->reg_lock, flags);
692 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00);
693 snd_ad1848_out(chip, AD1848_LEFT_INPUT, 0xaa);
694 snd_ad1848_out(chip, AD1848_RIGHT_INPUT, 0x45);
695 rev = snd_ad1848_in(chip, AD1848_RIGHT_INPUT);
696 if (rev == 0x65) {
697 spin_unlock_irqrestore(&chip->reg_lock, flags);
698 id = 1;
699 ad1847 = 1;
700 break;
701 }
702 if (snd_ad1848_in(chip, AD1848_LEFT_INPUT) == 0xaa && rev == 0x45) {
703 spin_unlock_irqrestore(&chip->reg_lock, flags);
704 id = 1;
705 break;
706 }
707 spin_unlock_irqrestore(&chip->reg_lock, flags);
708 }
709 }
710 if (id != 1)
711 return -ENODEV; /* no valid device found */
712 if (chip->hardware == AD1848_HW_DETECT) {
713 if (ad1847) {
714 chip->hardware = AD1848_HW_AD1847;
715 } else {
716 chip->hardware = AD1848_HW_AD1848;
717 rev = snd_ad1848_in(chip, AD1848_MISC_INFO);
718 if (rev & 0x80) {
719 chip->hardware = AD1848_HW_CS4248;
720 } else if ((rev & 0x0f) == 0x0a) {
721 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x40);
722 for (i = 0; i < 16; ++i) {
723 if (snd_ad1848_in(chip, i) != snd_ad1848_in(chip, i + 16)) {
724 chip->hardware = AD1848_HW_CMI8330;
725 break;
726 }
727 }
728 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00);
729 }
730 }
731 }
732 spin_lock_irqsave(&chip->reg_lock, flags);
733 inb(AD1848P(chip, STATUS)); /* clear any pendings IRQ */
734 outb(0, AD1848P(chip, STATUS));
735 mb();
736 spin_unlock_irqrestore(&chip->reg_lock, flags);
737
738 chip->image[AD1848_MISC_INFO] = 0x00;
739 chip->image[AD1848_IFACE_CTRL] =
740 (chip->image[AD1848_IFACE_CTRL] & ~AD1848_SINGLE_DMA) | AD1848_SINGLE_DMA;
741 ptr = (unsigned char *) &chip->image;
742 snd_ad1848_mce_down(chip);
743 spin_lock_irqsave(&chip->reg_lock, flags);
744 for (i = 0; i < 16; i++) /* ok.. fill all AD1848 registers */
745 snd_ad1848_out(chip, i, *ptr++);
746 spin_unlock_irqrestore(&chip->reg_lock, flags);
747 snd_ad1848_mce_up(chip);
748 snd_ad1848_mce_down(chip);
749 return 0; /* all things are ok.. */
750}
751
752/*
753
754 */
755
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100756static struct snd_pcm_hardware snd_ad1848_playback =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
758 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
759 SNDRV_PCM_INFO_MMAP_VALID),
760 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
761 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE),
762 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
763 .rate_min = 5510,
764 .rate_max = 48000,
765 .channels_min = 1,
766 .channels_max = 2,
767 .buffer_bytes_max = (128*1024),
768 .period_bytes_min = 64,
769 .period_bytes_max = (128*1024),
770 .periods_min = 1,
771 .periods_max = 1024,
772 .fifo_size = 0,
773};
774
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100775static struct snd_pcm_hardware snd_ad1848_capture =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
777 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
778 SNDRV_PCM_INFO_MMAP_VALID),
779 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
780 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE),
781 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
782 .rate_min = 5510,
783 .rate_max = 48000,
784 .channels_min = 1,
785 .channels_max = 2,
786 .buffer_bytes_max = (128*1024),
787 .period_bytes_min = 64,
788 .period_bytes_max = (128*1024),
789 .periods_min = 1,
790 .periods_max = 1024,
791 .fifo_size = 0,
792};
793
794/*
795
796 */
797
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100798static int snd_ad1848_playback_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100800 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
801 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 int err;
803
804 if ((err = snd_ad1848_open(chip, AD1848_MODE_PLAY)) < 0)
805 return err;
806 chip->playback_substream = substream;
807 runtime->hw = snd_ad1848_playback;
808 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max);
809 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max);
810 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
811 return 0;
812}
813
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100814static int snd_ad1848_capture_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100816 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
817 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 int err;
819
820 if ((err = snd_ad1848_open(chip, AD1848_MODE_CAPTURE)) < 0)
821 return err;
822 chip->capture_substream = substream;
823 runtime->hw = snd_ad1848_capture;
824 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max);
825 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max);
826 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
827 return 0;
828}
829
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100830static int snd_ad1848_playback_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100832 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
834 chip->mode &= ~AD1848_MODE_PLAY;
835 chip->playback_substream = NULL;
836 snd_ad1848_close(chip);
837 return 0;
838}
839
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100840static int snd_ad1848_capture_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100842 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
844 chip->mode &= ~AD1848_MODE_CAPTURE;
845 chip->capture_substream = NULL;
846 snd_ad1848_close(chip);
847 return 0;
848}
849
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100850static int snd_ad1848_free(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
Takashi Iwaib1d57762005-10-10 11:56:31 +0200852 release_and_free_resource(chip->res_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 if (chip->irq >= 0)
854 free_irq(chip->irq, (void *) chip);
855 if (chip->dma >= 0) {
856 snd_dma_disable(chip->dma);
857 free_dma(chip->dma);
858 }
859 kfree(chip);
860 return 0;
861}
862
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100863static int snd_ad1848_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100865 struct snd_ad1848 *chip = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 return snd_ad1848_free(chip);
867}
868
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100869static const char *snd_ad1848_chip_id(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870{
871 switch (chip->hardware) {
872 case AD1848_HW_AD1847: return "AD1847";
873 case AD1848_HW_AD1848: return "AD1848";
874 case AD1848_HW_CS4248: return "CS4248";
875 case AD1848_HW_CMI8330: return "CMI8330/C3D";
876 default: return "???";
877 }
878}
879
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100880int snd_ad1848_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 unsigned long port,
882 int irq, int dma,
883 unsigned short hardware,
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100884 struct snd_ad1848 ** rchip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100886 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 .dev_free = snd_ad1848_dev_free,
888 };
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100889 struct snd_ad1848 *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 int err;
891
892 *rchip = NULL;
Takashi Iwai9e76a762005-09-09 14:21:17 +0200893 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 if (chip == NULL)
895 return -ENOMEM;
896 spin_lock_init(&chip->reg_lock);
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100897 mutex_init(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 chip->card = card;
899 chip->port = port;
900 chip->irq = -1;
901 chip->dma = -1;
902 chip->hardware = hardware;
903 memcpy(&chip->image, &snd_ad1848_original_image, sizeof(snd_ad1848_original_image));
904
905 if ((chip->res_port = request_region(port, 4, "AD1848")) == NULL) {
906 snd_printk(KERN_ERR "ad1848: can't grab port 0x%lx\n", port);
907 snd_ad1848_free(chip);
908 return -EBUSY;
909 }
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700910 if (request_irq(irq, snd_ad1848_interrupt, IRQF_DISABLED, "AD1848", (void *) chip)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 snd_printk(KERN_ERR "ad1848: can't grab IRQ %d\n", irq);
912 snd_ad1848_free(chip);
913 return -EBUSY;
914 }
915 chip->irq = irq;
916 if (request_dma(dma, "AD1848")) {
917 snd_printk(KERN_ERR "ad1848: can't grab DMA %d\n", dma);
918 snd_ad1848_free(chip);
919 return -EBUSY;
920 }
921 chip->dma = dma;
922
923 if (hardware == AD1848_HW_THINKPAD) {
924 chip->thinkpad_flag = 1;
925 chip->hardware = AD1848_HW_DETECT; /* reset */
926 snd_ad1848_thinkpad_twiddle(chip, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 }
928
929 if (snd_ad1848_probe(chip) < 0) {
930 snd_ad1848_free(chip);
931 return -ENODEV;
932 }
933
934 /* Register device */
935 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
936 snd_ad1848_free(chip);
937 return err;
938 }
939
Takashi Iwai9d70d912005-11-30 10:12:26 +0100940#ifdef CONFIG_PM
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100941 chip->suspend = snd_ad1848_suspend;
942 chip->resume = snd_ad1848_resume;
Takashi Iwai9d70d912005-11-30 10:12:26 +0100943#endif
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100944
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 *rchip = chip;
946 return 0;
947}
948
Takashi Iwaieac06a12006-08-22 13:16:25 +0200949EXPORT_SYMBOL(snd_ad1848_create);
950
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100951static struct snd_pcm_ops snd_ad1848_playback_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 .open = snd_ad1848_playback_open,
953 .close = snd_ad1848_playback_close,
954 .ioctl = snd_ad1848_ioctl,
955 .hw_params = snd_ad1848_playback_hw_params,
956 .hw_free = snd_ad1848_playback_hw_free,
957 .prepare = snd_ad1848_playback_prepare,
958 .trigger = snd_ad1848_playback_trigger,
959 .pointer = snd_ad1848_playback_pointer,
960};
961
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100962static struct snd_pcm_ops snd_ad1848_capture_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 .open = snd_ad1848_capture_open,
964 .close = snd_ad1848_capture_close,
965 .ioctl = snd_ad1848_ioctl,
966 .hw_params = snd_ad1848_capture_hw_params,
967 .hw_free = snd_ad1848_capture_hw_free,
968 .prepare = snd_ad1848_capture_prepare,
969 .trigger = snd_ad1848_capture_trigger,
970 .pointer = snd_ad1848_capture_pointer,
971};
972
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100973int snd_ad1848_pcm(struct snd_ad1848 *chip, int device, struct snd_pcm **rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100975 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 int err;
977
978 if ((err = snd_pcm_new(chip->card, "AD1848", device, 1, 1, &pcm)) < 0)
979 return err;
980
981 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ad1848_playback_ops);
982 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ad1848_capture_ops);
983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 pcm->private_data = chip;
985 pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
986 strcpy(pcm->name, snd_ad1848_chip_id(chip));
987
988 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
989 snd_dma_isa_data(),
990 64*1024, chip->dma > 3 ? 128*1024 : 64*1024);
991
992 chip->pcm = pcm;
993 if (rpcm)
994 *rpcm = pcm;
995 return 0;
996}
997
Takashi Iwaieac06a12006-08-22 13:16:25 +0200998EXPORT_SYMBOL(snd_ad1848_pcm);
999
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001000const struct snd_pcm_ops *snd_ad1848_get_pcm_ops(int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
1002 return direction == SNDRV_PCM_STREAM_PLAYBACK ?
1003 &snd_ad1848_playback_ops : &snd_ad1848_capture_ops;
1004}
1005
Takashi Iwaieac06a12006-08-22 13:16:25 +02001006EXPORT_SYMBOL(snd_ad1848_get_pcm_ops);
1007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008/*
1009 * MIXER part
1010 */
1011
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001012static int snd_ad1848_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013{
1014 static char *texts[4] = {
1015 "Line", "Aux", "Mic", "Mix"
1016 };
1017
1018 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1019 uinfo->count = 2;
1020 uinfo->value.enumerated.items = 4;
1021 if (uinfo->value.enumerated.item > 3)
1022 uinfo->value.enumerated.item = 3;
1023 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1024 return 0;
1025}
1026
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001027static int snd_ad1848_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001029 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 unsigned long flags;
1031
1032 spin_lock_irqsave(&chip->reg_lock, flags);
1033 ucontrol->value.enumerated.item[0] = (chip->image[AD1848_LEFT_INPUT] & AD1848_MIXS_ALL) >> 6;
1034 ucontrol->value.enumerated.item[1] = (chip->image[AD1848_RIGHT_INPUT] & AD1848_MIXS_ALL) >> 6;
1035 spin_unlock_irqrestore(&chip->reg_lock, flags);
1036 return 0;
1037}
1038
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001039static int snd_ad1848_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001041 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 unsigned long flags;
1043 unsigned short left, right;
1044 int change;
1045
1046 if (ucontrol->value.enumerated.item[0] > 3 ||
1047 ucontrol->value.enumerated.item[1] > 3)
1048 return -EINVAL;
1049 left = ucontrol->value.enumerated.item[0] << 6;
1050 right = ucontrol->value.enumerated.item[1] << 6;
1051 spin_lock_irqsave(&chip->reg_lock, flags);
1052 left = (chip->image[AD1848_LEFT_INPUT] & ~AD1848_MIXS_ALL) | left;
1053 right = (chip->image[AD1848_RIGHT_INPUT] & ~AD1848_MIXS_ALL) | right;
1054 change = left != chip->image[AD1848_LEFT_INPUT] ||
1055 right != chip->image[AD1848_RIGHT_INPUT];
1056 snd_ad1848_out(chip, AD1848_LEFT_INPUT, left);
1057 snd_ad1848_out(chip, AD1848_RIGHT_INPUT, right);
1058 spin_unlock_irqrestore(&chip->reg_lock, flags);
1059 return change;
1060}
1061
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001062static int snd_ad1848_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
1064 int mask = (kcontrol->private_value >> 16) & 0xff;
1065
1066 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1067 uinfo->count = 1;
1068 uinfo->value.integer.min = 0;
1069 uinfo->value.integer.max = mask;
1070 return 0;
1071}
1072
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001073static int snd_ad1848_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001075 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 unsigned long flags;
1077 int reg = kcontrol->private_value & 0xff;
1078 int shift = (kcontrol->private_value >> 8) & 0xff;
1079 int mask = (kcontrol->private_value >> 16) & 0xff;
1080 int invert = (kcontrol->private_value >> 24) & 0xff;
1081
1082 spin_lock_irqsave(&chip->reg_lock, flags);
1083 ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
1084 spin_unlock_irqrestore(&chip->reg_lock, flags);
1085 if (invert)
1086 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1087 return 0;
1088}
1089
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001090static int snd_ad1848_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001092 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 unsigned long flags;
1094 int reg = kcontrol->private_value & 0xff;
1095 int shift = (kcontrol->private_value >> 8) & 0xff;
1096 int mask = (kcontrol->private_value >> 16) & 0xff;
1097 int invert = (kcontrol->private_value >> 24) & 0xff;
1098 int change;
1099 unsigned short val;
1100
1101 val = (ucontrol->value.integer.value[0] & mask);
1102 if (invert)
1103 val = mask - val;
1104 val <<= shift;
1105 spin_lock_irqsave(&chip->reg_lock, flags);
1106 val = (chip->image[reg] & ~(mask << shift)) | val;
1107 change = val != chip->image[reg];
1108 snd_ad1848_out(chip, reg, val);
1109 spin_unlock_irqrestore(&chip->reg_lock, flags);
1110 return change;
1111}
1112
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001113static int snd_ad1848_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114{
1115 int mask = (kcontrol->private_value >> 24) & 0xff;
1116
1117 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1118 uinfo->count = 2;
1119 uinfo->value.integer.min = 0;
1120 uinfo->value.integer.max = mask;
1121 return 0;
1122}
1123
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001124static int snd_ad1848_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001126 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 unsigned long flags;
1128 int left_reg = kcontrol->private_value & 0xff;
1129 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1130 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1131 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1132 int mask = (kcontrol->private_value >> 24) & 0xff;
1133 int invert = (kcontrol->private_value >> 22) & 1;
1134
1135 spin_lock_irqsave(&chip->reg_lock, flags);
1136 ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
1137 ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
1138 spin_unlock_irqrestore(&chip->reg_lock, flags);
1139 if (invert) {
1140 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1141 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1142 }
1143 return 0;
1144}
1145
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001146static int snd_ad1848_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001148 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 unsigned long flags;
1150 int left_reg = kcontrol->private_value & 0xff;
1151 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1152 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1153 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1154 int mask = (kcontrol->private_value >> 24) & 0xff;
1155 int invert = (kcontrol->private_value >> 22) & 1;
1156 int change;
1157 unsigned short val1, val2;
1158
1159 val1 = ucontrol->value.integer.value[0] & mask;
1160 val2 = ucontrol->value.integer.value[1] & mask;
1161 if (invert) {
1162 val1 = mask - val1;
1163 val2 = mask - val2;
1164 }
1165 val1 <<= shift_left;
1166 val2 <<= shift_right;
1167 spin_lock_irqsave(&chip->reg_lock, flags);
1168 if (left_reg != right_reg) {
1169 val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
1170 val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
1171 change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
1172 snd_ad1848_out(chip, left_reg, val1);
1173 snd_ad1848_out(chip, right_reg, val2);
1174 } else {
1175 val1 = (chip->image[left_reg] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
1176 change = val1 != chip->image[left_reg];
1177 snd_ad1848_out(chip, left_reg, val1);
1178 }
1179 spin_unlock_irqrestore(&chip->reg_lock, flags);
1180 return change;
1181}
1182
1183/*
1184 */
Takashi Iwaieac06a12006-08-22 13:16:25 +02001185int snd_ad1848_add_ctl_elem(struct snd_ad1848 *chip,
1186 const struct ad1848_mix_elem *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001188 static struct snd_kcontrol_new newctls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 [AD1848_MIX_SINGLE] = {
1190 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1191 .info = snd_ad1848_info_single,
1192 .get = snd_ad1848_get_single,
1193 .put = snd_ad1848_put_single,
1194 },
1195 [AD1848_MIX_DOUBLE] = {
1196 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1197 .info = snd_ad1848_info_double,
1198 .get = snd_ad1848_get_double,
1199 .put = snd_ad1848_put_double,
1200 },
1201 [AD1848_MIX_CAPTURE] = {
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001202 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 .info = snd_ad1848_info_mux,
1204 .get = snd_ad1848_get_mux,
1205 .put = snd_ad1848_put_mux,
1206 },
1207 };
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001208 struct snd_kcontrol *ctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 int err;
1210
Takashi Iwaieac06a12006-08-22 13:16:25 +02001211 ctl = snd_ctl_new1(&newctls[c->type], chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 if (! ctl)
1213 return -ENOMEM;
Takashi Iwaieac06a12006-08-22 13:16:25 +02001214 strlcpy(ctl->id.name, c->name, sizeof(ctl->id.name));
1215 ctl->id.index = c->index;
1216 ctl->private_value = c->private_value;
1217 if (c->tlv) {
1218 ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1219 ctl->tlv.p = c->tlv;
1220 }
Dave Jones3de44142006-03-06 13:31:18 +01001221 if ((err = snd_ctl_add(chip->card, ctl)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 return 0;
1224}
1225
Takashi Iwaieac06a12006-08-22 13:16:25 +02001226EXPORT_SYMBOL(snd_ad1848_add_ctl_elem);
1227
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01001228static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
1229static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
1230static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232static struct ad1848_mix_elem snd_ad1848_controls[] = {
1233AD1848_DOUBLE("PCM Playback Switch", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 7, 7, 1, 1),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001234AD1848_DOUBLE_TLV("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 1,
1235 db_scale_6bit),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236AD1848_DOUBLE("Aux Playback Switch", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001237AD1848_DOUBLE_TLV("Aux Playback Volume", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 0, 0, 31, 1,
1238 db_scale_5bit_12db_max),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239AD1848_DOUBLE("Aux Playback Switch", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001240AD1848_DOUBLE_TLV("Aux Playback Volume", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 0, 0, 31, 1,
1241 db_scale_5bit_12db_max),
1242AD1848_DOUBLE_TLV("Capture Volume", 0, AD1848_LEFT_INPUT, AD1848_RIGHT_INPUT, 0, 0, 15, 0,
1243 db_scale_rec_gain),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244{
1245 .name = "Capture Source",
1246 .type = AD1848_MIX_CAPTURE,
1247},
1248AD1848_SINGLE("Loopback Capture Switch", 0, AD1848_LOOPBACK, 0, 1, 0),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001249AD1848_SINGLE_TLV("Loopback Capture Volume", 0, AD1848_LOOPBACK, 1, 63, 0,
1250 db_scale_6bit),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251};
1252
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001253int snd_ad1848_mixer(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001255 struct snd_card *card;
1256 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 unsigned int idx;
1258 int err;
1259
1260 snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL);
1261
1262 pcm = chip->pcm;
1263 card = chip->card;
1264
1265 strcpy(card->mixername, pcm->name);
1266
1267 for (idx = 0; idx < ARRAY_SIZE(snd_ad1848_controls); idx++)
1268 if ((err = snd_ad1848_add_ctl_elem(chip, &snd_ad1848_controls[idx])) < 0)
1269 return err;
1270
1271 return 0;
1272}
1273
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274EXPORT_SYMBOL(snd_ad1848_mixer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276/*
1277 * INIT part
1278 */
1279
1280static int __init alsa_ad1848_init(void)
1281{
1282 return 0;
1283}
1284
1285static void __exit alsa_ad1848_exit(void)
1286{
1287}
1288
1289module_init(alsa_ad1848_init)
1290module_exit(alsa_ad1848_exit)