blob: d454d11989f0f71df8737b29f9dc2dba0e35096b [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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Rene Herman90cf9b82007-09-10 23:19:55 +0200233 /*
234 * Wait for (possible -- during init auto-calibration may not be set)
235 * calibration process to start. Needs upto 5 sample periods on AD1848
236 * which at the slowest possible rate of 5.5125 kHz means 907 us.
237 */
238 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239#if 0
Rene Herman90cf9b82007-09-10 23:19:55 +0200240 printk("(2) jiffies = %li\n", jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241#endif
242 time = HZ / 4;
243 while (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) {
244 spin_unlock_irqrestore(&chip->reg_lock, flags);
245 if (time <= 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +0200246 snd_printk(KERN_ERR "mce_down - auto calibration time out (2)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 return;
248 }
Takashi Iwaie65365d2007-06-25 12:09:32 +0200249 time = schedule_timeout(time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 spin_lock_irqsave(&chip->reg_lock, flags);
251 }
252#if 0
253 printk("(3) jiffies = %li\n", jiffies);
254#endif
255 time = HZ / 10;
256 while (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) {
257 spin_unlock_irqrestore(&chip->reg_lock, flags);
258 if (time <= 0) {
Takashi Iwai99b359b2005-10-20 18:26:44 +0200259 snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 return;
261 }
Takashi Iwaie65365d2007-06-25 12:09:32 +0200262 time = schedule_timeout(time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 spin_lock_irqsave(&chip->reg_lock, flags);
264 }
265 spin_unlock_irqrestore(&chip->reg_lock, flags);
266#if 0
267 printk("(4) jiffies = %li\n", jiffies);
268 snd_printk("mce_down - exit = 0x%x\n", inb(AD1848P(chip, REGSEL)));
269#endif
270}
271
272static unsigned int snd_ad1848_get_count(unsigned char format,
273 unsigned int size)
274{
275 switch (format & 0xe0) {
276 case AD1848_LINEAR_16:
277 size >>= 1;
278 break;
279 }
280 if (format & AD1848_STEREO)
281 size >>= 1;
282 return size;
283}
284
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100285static int snd_ad1848_trigger(struct snd_ad1848 *chip, unsigned char what,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 int channel, int cmd)
287{
288 int result = 0;
289
290#if 0
291 printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what, enable, inb(AD1848P(card, STATUS)));
292#endif
293 spin_lock(&chip->reg_lock);
294 if (cmd == SNDRV_PCM_TRIGGER_START) {
295 if (chip->image[AD1848_IFACE_CTRL] & what) {
296 spin_unlock(&chip->reg_lock);
297 return 0;
298 }
299 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] |= what);
300 chip->mode |= AD1848_MODE_RUNNING;
301 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
302 if (!(chip->image[AD1848_IFACE_CTRL] & what)) {
303 spin_unlock(&chip->reg_lock);
304 return 0;
305 }
306 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] &= ~what);
307 chip->mode &= ~AD1848_MODE_RUNNING;
308 } else {
309 result = -EINVAL;
310 }
311 spin_unlock(&chip->reg_lock);
312 return result;
313}
314
315/*
316 * CODEC I/O
317 */
318
319static unsigned char snd_ad1848_get_rate(unsigned int rate)
320{
321 int i;
322
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200323 for (i = 0; i < ARRAY_SIZE(rates); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 if (rate == rates[i])
325 return freq_bits[i];
326 snd_BUG();
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200327 return freq_bits[ARRAY_SIZE(rates) - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328}
329
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100330static int snd_ad1848_ioctl(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 unsigned int cmd, void *arg)
332{
333 return snd_pcm_lib_ioctl(substream, cmd, arg);
334}
335
336static unsigned char snd_ad1848_get_format(int format, int channels)
337{
338 unsigned char rformat;
339
340 rformat = AD1848_LINEAR_8;
341 switch (format) {
342 case SNDRV_PCM_FORMAT_A_LAW: rformat = AD1848_ALAW_8; break;
343 case SNDRV_PCM_FORMAT_MU_LAW: rformat = AD1848_ULAW_8; break;
344 case SNDRV_PCM_FORMAT_S16_LE: rformat = AD1848_LINEAR_16; break;
345 }
346 if (channels > 1)
347 rformat |= AD1848_STEREO;
348#if 0
349 snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode);
350#endif
351 return rformat;
352}
353
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100354static void snd_ad1848_calibrate_mute(struct snd_ad1848 *chip, int mute)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355{
356 unsigned long flags;
357
358 mute = mute ? 1 : 0;
359 spin_lock_irqsave(&chip->reg_lock, flags);
360 if (chip->calibrate_mute == mute) {
361 spin_unlock_irqrestore(&chip->reg_lock, flags);
362 return;
363 }
364 if (!mute) {
365 snd_ad1848_dout(chip, AD1848_LEFT_INPUT, chip->image[AD1848_LEFT_INPUT]);
366 snd_ad1848_dout(chip, AD1848_RIGHT_INPUT, chip->image[AD1848_RIGHT_INPUT]);
367 }
368 snd_ad1848_dout(chip, AD1848_AUX1_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_LEFT_INPUT]);
369 snd_ad1848_dout(chip, AD1848_AUX1_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_RIGHT_INPUT]);
370 snd_ad1848_dout(chip, AD1848_AUX2_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_LEFT_INPUT]);
371 snd_ad1848_dout(chip, AD1848_AUX2_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_RIGHT_INPUT]);
372 snd_ad1848_dout(chip, AD1848_LEFT_OUTPUT, mute ? 0x80 : chip->image[AD1848_LEFT_OUTPUT]);
373 snd_ad1848_dout(chip, AD1848_RIGHT_OUTPUT, mute ? 0x80 : chip->image[AD1848_RIGHT_OUTPUT]);
374 chip->calibrate_mute = mute;
375 spin_unlock_irqrestore(&chip->reg_lock, flags);
376}
377
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100378static void snd_ad1848_set_data_format(struct snd_ad1848 *chip, struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
380 if (hw_params == NULL) {
381 chip->image[AD1848_DATA_FORMAT] = 0x20;
382 } else {
383 chip->image[AD1848_DATA_FORMAT] =
384 snd_ad1848_get_format(params_format(hw_params), params_channels(hw_params)) |
385 snd_ad1848_get_rate(params_rate(hw_params));
386 }
387 // snd_printk(">>> pmode = 0x%x, dfr = 0x%x\n", pstr->mode, chip->image[AD1848_DATA_FORMAT]);
388}
389
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100390static int snd_ad1848_open(struct snd_ad1848 *chip, unsigned int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391{
392 unsigned long flags;
393
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100394 mutex_lock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (chip->mode & AD1848_MODE_OPEN) {
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100396 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return -EAGAIN;
398 }
399 snd_ad1848_mce_down(chip);
400
401#ifdef SNDRV_DEBUG_MCE
402 snd_printk("open: (1)\n");
403#endif
404 snd_ad1848_mce_up(chip);
405 spin_lock_irqsave(&chip->reg_lock, flags);
406 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO |
407 AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO |
408 AD1848_CALIB_MODE);
409 chip->image[AD1848_IFACE_CTRL] |= AD1848_AUTOCALIB;
410 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]);
411 spin_unlock_irqrestore(&chip->reg_lock, flags);
412 snd_ad1848_mce_down(chip);
413
414#ifdef SNDRV_DEBUG_MCE
415 snd_printk("open: (2)\n");
416#endif
417
418 snd_ad1848_set_data_format(chip, NULL);
419
420 snd_ad1848_mce_up(chip);
421 spin_lock_irqsave(&chip->reg_lock, flags);
422 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
423 spin_unlock_irqrestore(&chip->reg_lock, flags);
424 snd_ad1848_mce_down(chip);
425
426#ifdef SNDRV_DEBUG_MCE
427 snd_printk("open: (3)\n");
428#endif
429
430 /* ok. now enable and ack CODEC IRQ */
431 spin_lock_irqsave(&chip->reg_lock, flags);
432 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
433 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
434 chip->image[AD1848_PIN_CTRL] |= AD1848_IRQ_ENABLE;
435 snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]);
436 spin_unlock_irqrestore(&chip->reg_lock, flags);
437
438 chip->mode = mode;
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100439 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 return 0;
442}
443
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100444static void snd_ad1848_close(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
446 unsigned long flags;
447
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100448 mutex_lock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 if (!chip->mode) {
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100450 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 return;
452 }
453 /* disable IRQ */
454 spin_lock_irqsave(&chip->reg_lock, flags);
455 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
456 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
457 chip->image[AD1848_PIN_CTRL] &= ~AD1848_IRQ_ENABLE;
458 snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]);
459 spin_unlock_irqrestore(&chip->reg_lock, flags);
460
461 /* now disable capture & playback */
462
463 snd_ad1848_mce_up(chip);
464 spin_lock_irqsave(&chip->reg_lock, flags);
465 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO |
466 AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO);
467 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]);
468 spin_unlock_irqrestore(&chip->reg_lock, flags);
469 snd_ad1848_mce_down(chip);
470
471 /* clear IRQ again */
472 spin_lock_irqsave(&chip->reg_lock, flags);
473 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
474 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
475 spin_unlock_irqrestore(&chip->reg_lock, flags);
476
477 chip->mode = 0;
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100478 mutex_unlock(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
481/*
482 * ok.. exported functions..
483 */
484
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100485static int snd_ad1848_playback_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 int cmd)
487{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100488 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 return snd_ad1848_trigger(chip, AD1848_PLAYBACK_ENABLE, SNDRV_PCM_STREAM_PLAYBACK, cmd);
490}
491
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100492static int snd_ad1848_capture_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 int cmd)
494{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100495 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 return snd_ad1848_trigger(chip, AD1848_CAPTURE_ENABLE, SNDRV_PCM_STREAM_CAPTURE, cmd);
497}
498
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100499static int snd_ad1848_playback_hw_params(struct snd_pcm_substream *substream,
500 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100502 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 unsigned long flags;
504 int err;
505
506 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
507 return err;
508 snd_ad1848_calibrate_mute(chip, 1);
509 snd_ad1848_set_data_format(chip, hw_params);
510 snd_ad1848_mce_up(chip);
511 spin_lock_irqsave(&chip->reg_lock, flags);
512 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
513 spin_unlock_irqrestore(&chip->reg_lock, flags);
514 snd_ad1848_mce_down(chip);
515 snd_ad1848_calibrate_mute(chip, 0);
516 return 0;
517}
518
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100519static int snd_ad1848_playback_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520{
521 return snd_pcm_lib_free_pages(substream);
522}
523
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100524static int snd_ad1848_playback_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100526 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
527 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 unsigned long flags;
529 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
530 unsigned int count = snd_pcm_lib_period_bytes(substream);
531
532 chip->dma_size = size;
533 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO);
534 snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
535 count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1;
536 spin_lock_irqsave(&chip->reg_lock, flags);
537 snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count);
538 snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8));
539 spin_unlock_irqrestore(&chip->reg_lock, flags);
540 return 0;
541}
542
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100543static int snd_ad1848_capture_hw_params(struct snd_pcm_substream *substream,
544 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100546 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 unsigned long flags;
548 int err;
549
550 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
551 return err;
552 snd_ad1848_calibrate_mute(chip, 1);
553 snd_ad1848_set_data_format(chip, hw_params);
554 snd_ad1848_mce_up(chip);
555 spin_lock_irqsave(&chip->reg_lock, flags);
556 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
557 spin_unlock_irqrestore(&chip->reg_lock, flags);
558 snd_ad1848_mce_down(chip);
559 snd_ad1848_calibrate_mute(chip, 0);
560 return 0;
561}
562
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100563static int snd_ad1848_capture_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
565 return snd_pcm_lib_free_pages(substream);
566}
567
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100568static int snd_ad1848_capture_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100570 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
571 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 unsigned long flags;
573 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
574 unsigned int count = snd_pcm_lib_period_bytes(substream);
575
576 chip->dma_size = size;
577 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO);
578 snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
579 count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1;
580 spin_lock_irqsave(&chip->reg_lock, flags);
581 snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count);
582 snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8));
583 spin_unlock_irqrestore(&chip->reg_lock, flags);
584 return 0;
585}
586
David Howells7d12e782006-10-05 14:55:46 +0100587static irqreturn_t snd_ad1848_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100589 struct snd_ad1848 *chip = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 if ((chip->mode & AD1848_MODE_PLAY) && chip->playback_substream &&
592 (chip->mode & AD1848_MODE_RUNNING))
593 snd_pcm_period_elapsed(chip->playback_substream);
594 if ((chip->mode & AD1848_MODE_CAPTURE) && chip->capture_substream &&
595 (chip->mode & AD1848_MODE_RUNNING))
596 snd_pcm_period_elapsed(chip->capture_substream);
597 outb(0, AD1848P(chip, STATUS)); /* clear global interrupt bit */
598 return IRQ_HANDLED;
599}
600
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100601static snd_pcm_uframes_t snd_ad1848_playback_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100603 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 size_t ptr;
605
606 if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_PLAYBACK_ENABLE))
607 return 0;
608 ptr = snd_dma_pointer(chip->dma, chip->dma_size);
609 return bytes_to_frames(substream->runtime, ptr);
610}
611
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100612static snd_pcm_uframes_t snd_ad1848_capture_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100614 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 size_t ptr;
616
617 if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_CAPTURE_ENABLE))
618 return 0;
619 ptr = snd_dma_pointer(chip->dma, chip->dma_size);
620 return bytes_to_frames(substream->runtime, ptr);
621}
622
623/*
624
625 */
626
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100627static void snd_ad1848_thinkpad_twiddle(struct snd_ad1848 *chip, int on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629 int tmp;
630
631 if (!chip->thinkpad_flag) return;
632
633 outb(0x1c, AD1848_THINKPAD_CTL_PORT1);
634 tmp = inb(AD1848_THINKPAD_CTL_PORT2);
635
636 if (on)
637 /* turn it on */
638 tmp |= AD1848_THINKPAD_CS4248_ENABLE_BIT;
639 else
640 /* turn it off */
641 tmp &= ~AD1848_THINKPAD_CS4248_ENABLE_BIT;
642
643 outb(tmp, AD1848_THINKPAD_CTL_PORT2);
644
645}
646
647#ifdef CONFIG_PM
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100648static void snd_ad1848_suspend(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 snd_pcm_suspend_all(chip->pcm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 if (chip->thinkpad_flag)
652 snd_ad1848_thinkpad_twiddle(chip, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653}
654
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100655static void snd_ad1848_resume(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100657 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 if (chip->thinkpad_flag)
660 snd_ad1848_thinkpad_twiddle(chip, 1);
661
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100662 /* clear any pendings IRQ */
663 inb(AD1848P(chip, STATUS));
664 outb(0, AD1848P(chip, STATUS));
665 mb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100667 snd_ad1848_mce_down(chip);
668 for (i = 0; i < 16; i++)
669 snd_ad1848_out(chip, i, chip->image[i]);
670 snd_ad1848_mce_up(chip);
671 snd_ad1848_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672}
673#endif /* CONFIG_PM */
674
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100675static int snd_ad1848_probe(struct snd_ad1848 * chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
677 unsigned long flags;
678 int i, id, rev, ad1847;
679 unsigned char *ptr;
680
681#if 0
682 snd_ad1848_debug(chip);
683#endif
684 id = ad1847 = 0;
685 for (i = 0; i < 1000; i++) {
686 mb();
687 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
688 udelay(500);
689 else {
690 spin_lock_irqsave(&chip->reg_lock, flags);
691 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00);
692 snd_ad1848_out(chip, AD1848_LEFT_INPUT, 0xaa);
693 snd_ad1848_out(chip, AD1848_RIGHT_INPUT, 0x45);
694 rev = snd_ad1848_in(chip, AD1848_RIGHT_INPUT);
695 if (rev == 0x65) {
696 spin_unlock_irqrestore(&chip->reg_lock, flags);
697 id = 1;
698 ad1847 = 1;
699 break;
700 }
701 if (snd_ad1848_in(chip, AD1848_LEFT_INPUT) == 0xaa && rev == 0x45) {
702 spin_unlock_irqrestore(&chip->reg_lock, flags);
703 id = 1;
704 break;
705 }
706 spin_unlock_irqrestore(&chip->reg_lock, flags);
707 }
708 }
709 if (id != 1)
710 return -ENODEV; /* no valid device found */
711 if (chip->hardware == AD1848_HW_DETECT) {
712 if (ad1847) {
713 chip->hardware = AD1848_HW_AD1847;
714 } else {
715 chip->hardware = AD1848_HW_AD1848;
716 rev = snd_ad1848_in(chip, AD1848_MISC_INFO);
717 if (rev & 0x80) {
718 chip->hardware = AD1848_HW_CS4248;
719 } else if ((rev & 0x0f) == 0x0a) {
720 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x40);
721 for (i = 0; i < 16; ++i) {
722 if (snd_ad1848_in(chip, i) != snd_ad1848_in(chip, i + 16)) {
723 chip->hardware = AD1848_HW_CMI8330;
724 break;
725 }
726 }
727 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00);
728 }
729 }
730 }
731 spin_lock_irqsave(&chip->reg_lock, flags);
732 inb(AD1848P(chip, STATUS)); /* clear any pendings IRQ */
733 outb(0, AD1848P(chip, STATUS));
734 mb();
735 spin_unlock_irqrestore(&chip->reg_lock, flags);
736
737 chip->image[AD1848_MISC_INFO] = 0x00;
738 chip->image[AD1848_IFACE_CTRL] =
739 (chip->image[AD1848_IFACE_CTRL] & ~AD1848_SINGLE_DMA) | AD1848_SINGLE_DMA;
740 ptr = (unsigned char *) &chip->image;
741 snd_ad1848_mce_down(chip);
742 spin_lock_irqsave(&chip->reg_lock, flags);
743 for (i = 0; i < 16; i++) /* ok.. fill all AD1848 registers */
744 snd_ad1848_out(chip, i, *ptr++);
745 spin_unlock_irqrestore(&chip->reg_lock, flags);
746 snd_ad1848_mce_up(chip);
747 snd_ad1848_mce_down(chip);
748 return 0; /* all things are ok.. */
749}
750
751/*
752
753 */
754
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100755static struct snd_pcm_hardware snd_ad1848_playback =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756{
757 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
758 SNDRV_PCM_INFO_MMAP_VALID),
759 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
760 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE),
761 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
762 .rate_min = 5510,
763 .rate_max = 48000,
764 .channels_min = 1,
765 .channels_max = 2,
766 .buffer_bytes_max = (128*1024),
767 .period_bytes_min = 64,
768 .period_bytes_max = (128*1024),
769 .periods_min = 1,
770 .periods_max = 1024,
771 .fifo_size = 0,
772};
773
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100774static struct snd_pcm_hardware snd_ad1848_capture =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
776 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
777 SNDRV_PCM_INFO_MMAP_VALID),
778 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
779 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE),
780 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
781 .rate_min = 5510,
782 .rate_max = 48000,
783 .channels_min = 1,
784 .channels_max = 2,
785 .buffer_bytes_max = (128*1024),
786 .period_bytes_min = 64,
787 .period_bytes_max = (128*1024),
788 .periods_min = 1,
789 .periods_max = 1024,
790 .fifo_size = 0,
791};
792
793/*
794
795 */
796
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100797static int snd_ad1848_playback_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100799 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
800 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 int err;
802
803 if ((err = snd_ad1848_open(chip, AD1848_MODE_PLAY)) < 0)
804 return err;
805 chip->playback_substream = substream;
806 runtime->hw = snd_ad1848_playback;
807 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max);
808 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max);
809 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
810 return 0;
811}
812
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100813static int snd_ad1848_capture_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100815 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
816 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 int err;
818
819 if ((err = snd_ad1848_open(chip, AD1848_MODE_CAPTURE)) < 0)
820 return err;
821 chip->capture_substream = substream;
822 runtime->hw = snd_ad1848_capture;
823 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max);
824 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max);
825 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
826 return 0;
827}
828
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100829static int snd_ad1848_playback_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100831 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 chip->mode &= ~AD1848_MODE_PLAY;
834 chip->playback_substream = NULL;
835 snd_ad1848_close(chip);
836 return 0;
837}
838
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100839static int snd_ad1848_capture_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100841 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 chip->mode &= ~AD1848_MODE_CAPTURE;
844 chip->capture_substream = NULL;
845 snd_ad1848_close(chip);
846 return 0;
847}
848
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100849static int snd_ad1848_free(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
Takashi Iwaib1d57762005-10-10 11:56:31 +0200851 release_and_free_resource(chip->res_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 if (chip->irq >= 0)
853 free_irq(chip->irq, (void *) chip);
854 if (chip->dma >= 0) {
855 snd_dma_disable(chip->dma);
856 free_dma(chip->dma);
857 }
858 kfree(chip);
859 return 0;
860}
861
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100862static int snd_ad1848_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100864 struct snd_ad1848 *chip = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 return snd_ad1848_free(chip);
866}
867
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100868static const char *snd_ad1848_chip_id(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
870 switch (chip->hardware) {
871 case AD1848_HW_AD1847: return "AD1847";
872 case AD1848_HW_AD1848: return "AD1848";
873 case AD1848_HW_CS4248: return "CS4248";
874 case AD1848_HW_CMI8330: return "CMI8330/C3D";
875 default: return "???";
876 }
877}
878
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100879int snd_ad1848_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 unsigned long port,
881 int irq, int dma,
882 unsigned short hardware,
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100883 struct snd_ad1848 ** rchip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100885 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 .dev_free = snd_ad1848_dev_free,
887 };
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100888 struct snd_ad1848 *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 int err;
890
891 *rchip = NULL;
Takashi Iwai9e76a762005-09-09 14:21:17 +0200892 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 if (chip == NULL)
894 return -ENOMEM;
895 spin_lock_init(&chip->reg_lock);
Ingo Molnar8b7547f2006-01-16 16:33:08 +0100896 mutex_init(&chip->open_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 chip->card = card;
898 chip->port = port;
899 chip->irq = -1;
900 chip->dma = -1;
901 chip->hardware = hardware;
902 memcpy(&chip->image, &snd_ad1848_original_image, sizeof(snd_ad1848_original_image));
903
904 if ((chip->res_port = request_region(port, 4, "AD1848")) == NULL) {
905 snd_printk(KERN_ERR "ad1848: can't grab port 0x%lx\n", port);
906 snd_ad1848_free(chip);
907 return -EBUSY;
908 }
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700909 if (request_irq(irq, snd_ad1848_interrupt, IRQF_DISABLED, "AD1848", (void *) chip)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 snd_printk(KERN_ERR "ad1848: can't grab IRQ %d\n", irq);
911 snd_ad1848_free(chip);
912 return -EBUSY;
913 }
914 chip->irq = irq;
915 if (request_dma(dma, "AD1848")) {
916 snd_printk(KERN_ERR "ad1848: can't grab DMA %d\n", dma);
917 snd_ad1848_free(chip);
918 return -EBUSY;
919 }
920 chip->dma = dma;
921
922 if (hardware == AD1848_HW_THINKPAD) {
923 chip->thinkpad_flag = 1;
924 chip->hardware = AD1848_HW_DETECT; /* reset */
925 snd_ad1848_thinkpad_twiddle(chip, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 }
927
928 if (snd_ad1848_probe(chip) < 0) {
929 snd_ad1848_free(chip);
930 return -ENODEV;
931 }
932
933 /* Register device */
934 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
935 snd_ad1848_free(chip);
936 return err;
937 }
938
Takashi Iwai9d70d912005-11-30 10:12:26 +0100939#ifdef CONFIG_PM
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100940 chip->suspend = snd_ad1848_suspend;
941 chip->resume = snd_ad1848_resume;
Takashi Iwai9d70d912005-11-30 10:12:26 +0100942#endif
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100943
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 *rchip = chip;
945 return 0;
946}
947
Takashi Iwaieac06a12006-08-22 13:16:25 +0200948EXPORT_SYMBOL(snd_ad1848_create);
949
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100950static struct snd_pcm_ops snd_ad1848_playback_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 .open = snd_ad1848_playback_open,
952 .close = snd_ad1848_playback_close,
953 .ioctl = snd_ad1848_ioctl,
954 .hw_params = snd_ad1848_playback_hw_params,
955 .hw_free = snd_ad1848_playback_hw_free,
956 .prepare = snd_ad1848_playback_prepare,
957 .trigger = snd_ad1848_playback_trigger,
958 .pointer = snd_ad1848_playback_pointer,
959};
960
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100961static struct snd_pcm_ops snd_ad1848_capture_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 .open = snd_ad1848_capture_open,
963 .close = snd_ad1848_capture_close,
964 .ioctl = snd_ad1848_ioctl,
965 .hw_params = snd_ad1848_capture_hw_params,
966 .hw_free = snd_ad1848_capture_hw_free,
967 .prepare = snd_ad1848_capture_prepare,
968 .trigger = snd_ad1848_capture_trigger,
969 .pointer = snd_ad1848_capture_pointer,
970};
971
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100972int snd_ad1848_pcm(struct snd_ad1848 *chip, int device, struct snd_pcm **rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100974 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 int err;
976
977 if ((err = snd_pcm_new(chip->card, "AD1848", device, 1, 1, &pcm)) < 0)
978 return err;
979
980 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ad1848_playback_ops);
981 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ad1848_capture_ops);
982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 pcm->private_data = chip;
984 pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
985 strcpy(pcm->name, snd_ad1848_chip_id(chip));
986
987 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
988 snd_dma_isa_data(),
989 64*1024, chip->dma > 3 ? 128*1024 : 64*1024);
990
991 chip->pcm = pcm;
992 if (rpcm)
993 *rpcm = pcm;
994 return 0;
995}
996
Takashi Iwaieac06a12006-08-22 13:16:25 +0200997EXPORT_SYMBOL(snd_ad1848_pcm);
998
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100999const struct snd_pcm_ops *snd_ad1848_get_pcm_ops(int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
1001 return direction == SNDRV_PCM_STREAM_PLAYBACK ?
1002 &snd_ad1848_playback_ops : &snd_ad1848_capture_ops;
1003}
1004
Takashi Iwaieac06a12006-08-22 13:16:25 +02001005EXPORT_SYMBOL(snd_ad1848_get_pcm_ops);
1006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007/*
1008 * MIXER part
1009 */
1010
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001011static int snd_ad1848_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012{
1013 static char *texts[4] = {
1014 "Line", "Aux", "Mic", "Mix"
1015 };
1016
1017 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1018 uinfo->count = 2;
1019 uinfo->value.enumerated.items = 4;
1020 if (uinfo->value.enumerated.item > 3)
1021 uinfo->value.enumerated.item = 3;
1022 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1023 return 0;
1024}
1025
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001026static int snd_ad1848_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001028 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 unsigned long flags;
1030
1031 spin_lock_irqsave(&chip->reg_lock, flags);
1032 ucontrol->value.enumerated.item[0] = (chip->image[AD1848_LEFT_INPUT] & AD1848_MIXS_ALL) >> 6;
1033 ucontrol->value.enumerated.item[1] = (chip->image[AD1848_RIGHT_INPUT] & AD1848_MIXS_ALL) >> 6;
1034 spin_unlock_irqrestore(&chip->reg_lock, flags);
1035 return 0;
1036}
1037
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001038static int snd_ad1848_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001040 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 unsigned long flags;
1042 unsigned short left, right;
1043 int change;
1044
1045 if (ucontrol->value.enumerated.item[0] > 3 ||
1046 ucontrol->value.enumerated.item[1] > 3)
1047 return -EINVAL;
1048 left = ucontrol->value.enumerated.item[0] << 6;
1049 right = ucontrol->value.enumerated.item[1] << 6;
1050 spin_lock_irqsave(&chip->reg_lock, flags);
1051 left = (chip->image[AD1848_LEFT_INPUT] & ~AD1848_MIXS_ALL) | left;
1052 right = (chip->image[AD1848_RIGHT_INPUT] & ~AD1848_MIXS_ALL) | right;
1053 change = left != chip->image[AD1848_LEFT_INPUT] ||
1054 right != chip->image[AD1848_RIGHT_INPUT];
1055 snd_ad1848_out(chip, AD1848_LEFT_INPUT, left);
1056 snd_ad1848_out(chip, AD1848_RIGHT_INPUT, right);
1057 spin_unlock_irqrestore(&chip->reg_lock, flags);
1058 return change;
1059}
1060
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001061static int snd_ad1848_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
1063 int mask = (kcontrol->private_value >> 16) & 0xff;
1064
1065 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1066 uinfo->count = 1;
1067 uinfo->value.integer.min = 0;
1068 uinfo->value.integer.max = mask;
1069 return 0;
1070}
1071
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001072static int snd_ad1848_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001074 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 unsigned long flags;
1076 int reg = kcontrol->private_value & 0xff;
1077 int shift = (kcontrol->private_value >> 8) & 0xff;
1078 int mask = (kcontrol->private_value >> 16) & 0xff;
1079 int invert = (kcontrol->private_value >> 24) & 0xff;
1080
1081 spin_lock_irqsave(&chip->reg_lock, flags);
1082 ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
1083 spin_unlock_irqrestore(&chip->reg_lock, flags);
1084 if (invert)
1085 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1086 return 0;
1087}
1088
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001089static int snd_ad1848_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001091 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 unsigned long flags;
1093 int reg = kcontrol->private_value & 0xff;
1094 int shift = (kcontrol->private_value >> 8) & 0xff;
1095 int mask = (kcontrol->private_value >> 16) & 0xff;
1096 int invert = (kcontrol->private_value >> 24) & 0xff;
1097 int change;
1098 unsigned short val;
1099
1100 val = (ucontrol->value.integer.value[0] & mask);
1101 if (invert)
1102 val = mask - val;
1103 val <<= shift;
1104 spin_lock_irqsave(&chip->reg_lock, flags);
1105 val = (chip->image[reg] & ~(mask << shift)) | val;
1106 change = val != chip->image[reg];
1107 snd_ad1848_out(chip, reg, val);
1108 spin_unlock_irqrestore(&chip->reg_lock, flags);
1109 return change;
1110}
1111
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001112static int snd_ad1848_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
1114 int mask = (kcontrol->private_value >> 24) & 0xff;
1115
1116 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1117 uinfo->count = 2;
1118 uinfo->value.integer.min = 0;
1119 uinfo->value.integer.max = mask;
1120 return 0;
1121}
1122
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001123static int snd_ad1848_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001125 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 unsigned long flags;
1127 int left_reg = kcontrol->private_value & 0xff;
1128 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1129 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1130 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1131 int mask = (kcontrol->private_value >> 24) & 0xff;
1132 int invert = (kcontrol->private_value >> 22) & 1;
1133
1134 spin_lock_irqsave(&chip->reg_lock, flags);
1135 ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
1136 ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
1137 spin_unlock_irqrestore(&chip->reg_lock, flags);
1138 if (invert) {
1139 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1140 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1141 }
1142 return 0;
1143}
1144
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001145static int snd_ad1848_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001147 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 unsigned long flags;
1149 int left_reg = kcontrol->private_value & 0xff;
1150 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1151 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1152 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1153 int mask = (kcontrol->private_value >> 24) & 0xff;
1154 int invert = (kcontrol->private_value >> 22) & 1;
1155 int change;
1156 unsigned short val1, val2;
1157
1158 val1 = ucontrol->value.integer.value[0] & mask;
1159 val2 = ucontrol->value.integer.value[1] & mask;
1160 if (invert) {
1161 val1 = mask - val1;
1162 val2 = mask - val2;
1163 }
1164 val1 <<= shift_left;
1165 val2 <<= shift_right;
1166 spin_lock_irqsave(&chip->reg_lock, flags);
1167 if (left_reg != right_reg) {
1168 val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
1169 val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
1170 change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
1171 snd_ad1848_out(chip, left_reg, val1);
1172 snd_ad1848_out(chip, right_reg, val2);
1173 } else {
1174 val1 = (chip->image[left_reg] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
1175 change = val1 != chip->image[left_reg];
1176 snd_ad1848_out(chip, left_reg, val1);
1177 }
1178 spin_unlock_irqrestore(&chip->reg_lock, flags);
1179 return change;
1180}
1181
1182/*
1183 */
Takashi Iwaieac06a12006-08-22 13:16:25 +02001184int snd_ad1848_add_ctl_elem(struct snd_ad1848 *chip,
1185 const struct ad1848_mix_elem *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001187 static struct snd_kcontrol_new newctls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 [AD1848_MIX_SINGLE] = {
1189 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1190 .info = snd_ad1848_info_single,
1191 .get = snd_ad1848_get_single,
1192 .put = snd_ad1848_put_single,
1193 },
1194 [AD1848_MIX_DOUBLE] = {
1195 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1196 .info = snd_ad1848_info_double,
1197 .get = snd_ad1848_get_double,
1198 .put = snd_ad1848_put_double,
1199 },
1200 [AD1848_MIX_CAPTURE] = {
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001201 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 .info = snd_ad1848_info_mux,
1203 .get = snd_ad1848_get_mux,
1204 .put = snd_ad1848_put_mux,
1205 },
1206 };
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001207 struct snd_kcontrol *ctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 int err;
1209
Takashi Iwaieac06a12006-08-22 13:16:25 +02001210 ctl = snd_ctl_new1(&newctls[c->type], chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 if (! ctl)
1212 return -ENOMEM;
Takashi Iwaieac06a12006-08-22 13:16:25 +02001213 strlcpy(ctl->id.name, c->name, sizeof(ctl->id.name));
1214 ctl->id.index = c->index;
1215 ctl->private_value = c->private_value;
1216 if (c->tlv) {
1217 ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1218 ctl->tlv.p = c->tlv;
1219 }
Dave Jones3de44142006-03-06 13:31:18 +01001220 if ((err = snd_ctl_add(chip->card, ctl)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 return 0;
1223}
1224
Takashi Iwaieac06a12006-08-22 13:16:25 +02001225EXPORT_SYMBOL(snd_ad1848_add_ctl_elem);
1226
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01001227static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
1228static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
1229static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
1231static struct ad1848_mix_elem snd_ad1848_controls[] = {
1232AD1848_DOUBLE("PCM Playback Switch", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 7, 7, 1, 1),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001233AD1848_DOUBLE_TLV("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 1,
1234 db_scale_6bit),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235AD1848_DOUBLE("Aux Playback Switch", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001236AD1848_DOUBLE_TLV("Aux Playback Volume", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 0, 0, 31, 1,
1237 db_scale_5bit_12db_max),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238AD1848_DOUBLE("Aux Playback Switch", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001239AD1848_DOUBLE_TLV("Aux Playback Volume", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 0, 0, 31, 1,
1240 db_scale_5bit_12db_max),
1241AD1848_DOUBLE_TLV("Capture Volume", 0, AD1848_LEFT_INPUT, AD1848_RIGHT_INPUT, 0, 0, 15, 0,
1242 db_scale_rec_gain),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
1244 .name = "Capture Source",
1245 .type = AD1848_MIX_CAPTURE,
1246},
1247AD1848_SINGLE("Loopback Capture Switch", 0, AD1848_LOOPBACK, 0, 1, 0),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001248AD1848_SINGLE_TLV("Loopback Capture Volume", 0, AD1848_LOOPBACK, 1, 63, 0,
1249 db_scale_6bit),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250};
1251
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001252int snd_ad1848_mixer(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001254 struct snd_card *card;
1255 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 unsigned int idx;
1257 int err;
1258
1259 snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL);
1260
1261 pcm = chip->pcm;
1262 card = chip->card;
1263
1264 strcpy(card->mixername, pcm->name);
1265
1266 for (idx = 0; idx < ARRAY_SIZE(snd_ad1848_controls); idx++)
1267 if ((err = snd_ad1848_add_ctl_elem(chip, &snd_ad1848_controls[idx])) < 0)
1268 return err;
1269
1270 return 0;
1271}
1272
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273EXPORT_SYMBOL(snd_ad1848_mixer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
1275/*
1276 * INIT part
1277 */
1278
1279static int __init alsa_ad1848_init(void)
1280{
1281 return 0;
1282}
1283
1284static void __exit alsa_ad1848_exit(void)
1285{
1286}
1287
1288module_init(alsa_ad1848_init)
1289module_exit(alsa_ad1848_exit)