blob: a901cd1ee692474316cd7bf5ff34d926e3578a83 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02002 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020038MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070039MODULE_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{
Trent Piephofe1b5e82007-09-19 21:20:17 +0200206 unsigned long flags, timeout;
207 int reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209 spin_lock_irqsave(&chip->reg_lock, flags);
210 for (timeout = 5; timeout > 0; timeout--)
211 inb(AD1848P(chip, REGSEL));
212 /* end of cleanup sequence */
213 for (timeout = 12000; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--)
214 udelay(100);
Rene Hermand44df2d2007-09-10 23:22:55 +0200215
216 snd_printdd("(1) timeout = %d\n", timeout);
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218#ifdef CONFIG_SND_DEBUG
219 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
Takashi Iwai99b359b2005-10-20 18:26:44 +0200220 snd_printk(KERN_WARNING "mce_down [0x%lx] - auto calibration time out (0)\n", AD1848P(chip, REGSEL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#endif
Rene Hermand44df2d2007-09-10 23:22:55 +0200222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 chip->mce_bit &= ~AD1848_MCE;
Trent Piephofe1b5e82007-09-19 21:20:17 +0200224 reg = inb(AD1848P(chip, REGSEL));
225 outb(chip->mce_bit | (reg & 0x1f), AD1848P(chip, REGSEL));
226 if (reg == 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);
Trent Piephofe1b5e82007-09-19 21:20:17 +0200228 if ((reg & AD1848_MCE) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 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 /*
Trent Piephofe1b5e82007-09-19 21:20:17 +0200234 * Wait for auto-calibration (AC) process to finish, i.e. ACI to go low.
235 * It may take up to 5 sample periods (at most 907 us @ 5.5125 kHz) for
236 * the process to _start_, so it is important to wait at least that long
237 * before checking. Otherwise we might think AC has finished when it
238 * has in fact not begun. It could take 128 (no AC) or 384 (AC) cycles
239 * for ACI to drop. This gives a wait of at most 70 ms with a more
240 * typical value of 3-9 ms.
Rene Herman90cf9b82007-09-10 23:19:55 +0200241 */
Trent Piephofe1b5e82007-09-19 21:20:17 +0200242 timeout = jiffies + msecs_to_jiffies(250);
243 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 spin_unlock_irqrestore(&chip->reg_lock, flags);
Krzysztof Heltf79415202007-09-17 12:52:43 +0200245 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 spin_lock_irqsave(&chip->reg_lock, flags);
Trent Piephofe1b5e82007-09-19 21:20:17 +0200247 reg = snd_ad1848_in(chip, AD1848_TEST_INIT) &
248 AD1848_CALIB_IN_PROGRESS;
249 } while (reg && time_before(jiffies, timeout));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 spin_unlock_irqrestore(&chip->reg_lock, flags);
Trent Piephofe1b5e82007-09-19 21:20:17 +0200251 if (reg)
252 snd_printk(KERN_ERR
253 "mce_down - auto calibration time out (2)\n");
Rene Hermand44df2d2007-09-10 23:22:55 +0200254
255 snd_printdd("(4) jiffies = %lu\n", jiffies);
256 snd_printd("mce_down - exit = 0x%x\n", inb(AD1848P(chip, REGSEL)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
258
259static unsigned int snd_ad1848_get_count(unsigned char format,
260 unsigned int size)
261{
262 switch (format & 0xe0) {
263 case AD1848_LINEAR_16:
264 size >>= 1;
265 break;
266 }
267 if (format & AD1848_STEREO)
268 size >>= 1;
269 return size;
270}
271
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100272static int snd_ad1848_trigger(struct snd_ad1848 *chip, unsigned char what,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 int channel, int cmd)
274{
275 int result = 0;
276
277#if 0
278 printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what, enable, inb(AD1848P(card, STATUS)));
279#endif
280 spin_lock(&chip->reg_lock);
281 if (cmd == SNDRV_PCM_TRIGGER_START) {
282 if (chip->image[AD1848_IFACE_CTRL] & what) {
283 spin_unlock(&chip->reg_lock);
284 return 0;
285 }
286 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] |= what);
287 chip->mode |= AD1848_MODE_RUNNING;
288 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
289 if (!(chip->image[AD1848_IFACE_CTRL] & what)) {
290 spin_unlock(&chip->reg_lock);
291 return 0;
292 }
293 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] &= ~what);
294 chip->mode &= ~AD1848_MODE_RUNNING;
295 } else {
296 result = -EINVAL;
297 }
298 spin_unlock(&chip->reg_lock);
299 return result;
300}
301
302/*
303 * CODEC I/O
304 */
305
306static unsigned char snd_ad1848_get_rate(unsigned int rate)
307{
308 int i;
309
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200310 for (i = 0; i < ARRAY_SIZE(rates); i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 if (rate == rates[i])
312 return freq_bits[i];
313 snd_BUG();
Krzysztof Helt8e6a2c22007-09-06 15:03:22 +0200314 return freq_bits[ARRAY_SIZE(rates) - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100317static int snd_ad1848_ioctl(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 unsigned int cmd, void *arg)
319{
320 return snd_pcm_lib_ioctl(substream, cmd, arg);
321}
322
323static unsigned char snd_ad1848_get_format(int format, int channels)
324{
325 unsigned char rformat;
326
327 rformat = AD1848_LINEAR_8;
328 switch (format) {
329 case SNDRV_PCM_FORMAT_A_LAW: rformat = AD1848_ALAW_8; break;
330 case SNDRV_PCM_FORMAT_MU_LAW: rformat = AD1848_ULAW_8; break;
331 case SNDRV_PCM_FORMAT_S16_LE: rformat = AD1848_LINEAR_16; break;
332 }
333 if (channels > 1)
334 rformat |= AD1848_STEREO;
335#if 0
336 snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode);
337#endif
338 return rformat;
339}
340
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100341static void snd_ad1848_calibrate_mute(struct snd_ad1848 *chip, int mute)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
343 unsigned long flags;
344
345 mute = mute ? 1 : 0;
346 spin_lock_irqsave(&chip->reg_lock, flags);
347 if (chip->calibrate_mute == mute) {
348 spin_unlock_irqrestore(&chip->reg_lock, flags);
349 return;
350 }
351 if (!mute) {
352 snd_ad1848_dout(chip, AD1848_LEFT_INPUT, chip->image[AD1848_LEFT_INPUT]);
353 snd_ad1848_dout(chip, AD1848_RIGHT_INPUT, chip->image[AD1848_RIGHT_INPUT]);
354 }
355 snd_ad1848_dout(chip, AD1848_AUX1_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_LEFT_INPUT]);
356 snd_ad1848_dout(chip, AD1848_AUX1_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_RIGHT_INPUT]);
357 snd_ad1848_dout(chip, AD1848_AUX2_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_LEFT_INPUT]);
358 snd_ad1848_dout(chip, AD1848_AUX2_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_RIGHT_INPUT]);
359 snd_ad1848_dout(chip, AD1848_LEFT_OUTPUT, mute ? 0x80 : chip->image[AD1848_LEFT_OUTPUT]);
360 snd_ad1848_dout(chip, AD1848_RIGHT_OUTPUT, mute ? 0x80 : chip->image[AD1848_RIGHT_OUTPUT]);
361 chip->calibrate_mute = mute;
362 spin_unlock_irqrestore(&chip->reg_lock, flags);
363}
364
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100365static void snd_ad1848_set_data_format(struct snd_ad1848 *chip, struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
367 if (hw_params == NULL) {
368 chip->image[AD1848_DATA_FORMAT] = 0x20;
369 } else {
370 chip->image[AD1848_DATA_FORMAT] =
371 snd_ad1848_get_format(params_format(hw_params), params_channels(hw_params)) |
372 snd_ad1848_get_rate(params_rate(hw_params));
373 }
374 // snd_printk(">>> pmode = 0x%x, dfr = 0x%x\n", pstr->mode, chip->image[AD1848_DATA_FORMAT]);
375}
376
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100377static int snd_ad1848_open(struct snd_ad1848 *chip, unsigned int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
379 unsigned long flags;
380
Krzysztof Heltca2df452007-10-16 14:54:14 +0200381 if (chip->mode & AD1848_MODE_OPEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 return -EAGAIN;
Krzysztof Heltca2df452007-10-16 14:54:14 +0200383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 snd_ad1848_mce_down(chip);
385
386#ifdef SNDRV_DEBUG_MCE
387 snd_printk("open: (1)\n");
388#endif
389 snd_ad1848_mce_up(chip);
390 spin_lock_irqsave(&chip->reg_lock, flags);
391 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO |
392 AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO |
393 AD1848_CALIB_MODE);
394 chip->image[AD1848_IFACE_CTRL] |= AD1848_AUTOCALIB;
395 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]);
396 spin_unlock_irqrestore(&chip->reg_lock, flags);
397 snd_ad1848_mce_down(chip);
398
399#ifdef SNDRV_DEBUG_MCE
400 snd_printk("open: (2)\n");
401#endif
402
403 snd_ad1848_set_data_format(chip, NULL);
404
405 snd_ad1848_mce_up(chip);
406 spin_lock_irqsave(&chip->reg_lock, flags);
407 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
408 spin_unlock_irqrestore(&chip->reg_lock, flags);
409 snd_ad1848_mce_down(chip);
410
411#ifdef SNDRV_DEBUG_MCE
412 snd_printk("open: (3)\n");
413#endif
414
415 /* ok. now enable and ack CODEC IRQ */
416 spin_lock_irqsave(&chip->reg_lock, flags);
417 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
418 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
419 chip->image[AD1848_PIN_CTRL] |= AD1848_IRQ_ENABLE;
420 snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]);
421 spin_unlock_irqrestore(&chip->reg_lock, flags);
422
423 chip->mode = mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 return 0;
426}
427
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100428static void snd_ad1848_close(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
430 unsigned long flags;
431
Krzysztof Heltca2df452007-10-16 14:54:14 +0200432 if (!chip->mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 /* disable IRQ */
435 spin_lock_irqsave(&chip->reg_lock, flags);
436 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
437 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
438 chip->image[AD1848_PIN_CTRL] &= ~AD1848_IRQ_ENABLE;
439 snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]);
440 spin_unlock_irqrestore(&chip->reg_lock, flags);
441
442 /* now disable capture & playback */
443
444 snd_ad1848_mce_up(chip);
445 spin_lock_irqsave(&chip->reg_lock, flags);
446 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO |
447 AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO);
448 snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]);
449 spin_unlock_irqrestore(&chip->reg_lock, flags);
450 snd_ad1848_mce_down(chip);
451
452 /* clear IRQ again */
453 spin_lock_irqsave(&chip->reg_lock, flags);
454 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
455 outb(0, AD1848P(chip, STATUS)); /* clear IRQ */
456 spin_unlock_irqrestore(&chip->reg_lock, flags);
457
458 chip->mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
461/*
462 * ok.. exported functions..
463 */
464
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100465static int snd_ad1848_playback_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 int cmd)
467{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100468 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 return snd_ad1848_trigger(chip, AD1848_PLAYBACK_ENABLE, SNDRV_PCM_STREAM_PLAYBACK, cmd);
470}
471
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100472static int snd_ad1848_capture_trigger(struct snd_pcm_substream *substream,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 int cmd)
474{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100475 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return snd_ad1848_trigger(chip, AD1848_CAPTURE_ENABLE, SNDRV_PCM_STREAM_CAPTURE, cmd);
477}
478
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100479static int snd_ad1848_playback_hw_params(struct snd_pcm_substream *substream,
480 struct snd_pcm_hw_params *hw_params)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100482 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 unsigned long flags;
484 int err;
485
486 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
487 return err;
488 snd_ad1848_calibrate_mute(chip, 1);
489 snd_ad1848_set_data_format(chip, hw_params);
490 snd_ad1848_mce_up(chip);
491 spin_lock_irqsave(&chip->reg_lock, flags);
492 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
493 spin_unlock_irqrestore(&chip->reg_lock, flags);
494 snd_ad1848_mce_down(chip);
495 snd_ad1848_calibrate_mute(chip, 0);
496 return 0;
497}
498
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100499static int snd_ad1848_playback_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
501 return snd_pcm_lib_free_pages(substream);
502}
503
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100504static int snd_ad1848_playback_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100506 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
507 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 unsigned long flags;
509 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
510 unsigned int count = snd_pcm_lib_period_bytes(substream);
511
512 chip->dma_size = size;
513 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO);
514 snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
515 count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1;
516 spin_lock_irqsave(&chip->reg_lock, flags);
517 snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count);
518 snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8));
519 spin_unlock_irqrestore(&chip->reg_lock, flags);
520 return 0;
521}
522
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100523static int snd_ad1848_capture_hw_params(struct snd_pcm_substream *substream,
524 struct snd_pcm_hw_params *hw_params)
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 unsigned long flags;
528 int err;
529
530 if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0)
531 return err;
532 snd_ad1848_calibrate_mute(chip, 1);
533 snd_ad1848_set_data_format(chip, hw_params);
534 snd_ad1848_mce_up(chip);
535 spin_lock_irqsave(&chip->reg_lock, flags);
536 snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]);
537 spin_unlock_irqrestore(&chip->reg_lock, flags);
538 snd_ad1848_mce_down(chip);
539 snd_ad1848_calibrate_mute(chip, 0);
540 return 0;
541}
542
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100543static int snd_ad1848_capture_hw_free(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
545 return snd_pcm_lib_free_pages(substream);
546}
547
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100548static int snd_ad1848_capture_prepare(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100550 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
551 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 unsigned long flags;
553 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
554 unsigned int count = snd_pcm_lib_period_bytes(substream);
555
556 chip->dma_size = size;
557 chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO);
558 snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
559 count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1;
560 spin_lock_irqsave(&chip->reg_lock, flags);
561 snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count);
562 snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8));
563 spin_unlock_irqrestore(&chip->reg_lock, flags);
564 return 0;
565}
566
David Howells7d12e782006-10-05 14:55:46 +0100567static irqreturn_t snd_ad1848_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100569 struct snd_ad1848 *chip = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571 if ((chip->mode & AD1848_MODE_PLAY) && chip->playback_substream &&
572 (chip->mode & AD1848_MODE_RUNNING))
573 snd_pcm_period_elapsed(chip->playback_substream);
574 if ((chip->mode & AD1848_MODE_CAPTURE) && chip->capture_substream &&
575 (chip->mode & AD1848_MODE_RUNNING))
576 snd_pcm_period_elapsed(chip->capture_substream);
577 outb(0, AD1848P(chip, STATUS)); /* clear global interrupt bit */
578 return IRQ_HANDLED;
579}
580
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100581static snd_pcm_uframes_t snd_ad1848_playback_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100583 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 size_t ptr;
585
586 if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_PLAYBACK_ENABLE))
587 return 0;
588 ptr = snd_dma_pointer(chip->dma, chip->dma_size);
589 return bytes_to_frames(substream->runtime, ptr);
590}
591
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100592static snd_pcm_uframes_t snd_ad1848_capture_pointer(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100594 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 size_t ptr;
596
597 if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_CAPTURE_ENABLE))
598 return 0;
599 ptr = snd_dma_pointer(chip->dma, chip->dma_size);
600 return bytes_to_frames(substream->runtime, ptr);
601}
602
603/*
604
605 */
606
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100607static void snd_ad1848_thinkpad_twiddle(struct snd_ad1848 *chip, int on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 int tmp;
610
611 if (!chip->thinkpad_flag) return;
612
613 outb(0x1c, AD1848_THINKPAD_CTL_PORT1);
614 tmp = inb(AD1848_THINKPAD_CTL_PORT2);
615
616 if (on)
617 /* turn it on */
618 tmp |= AD1848_THINKPAD_CS4248_ENABLE_BIT;
619 else
620 /* turn it off */
621 tmp &= ~AD1848_THINKPAD_CS4248_ENABLE_BIT;
622
623 outb(tmp, AD1848_THINKPAD_CTL_PORT2);
624
625}
626
627#ifdef CONFIG_PM
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100628static void snd_ad1848_suspend(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 snd_pcm_suspend_all(chip->pcm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 if (chip->thinkpad_flag)
632 snd_ad1848_thinkpad_twiddle(chip, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633}
634
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100635static void snd_ad1848_resume(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636{
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100637 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639 if (chip->thinkpad_flag)
640 snd_ad1848_thinkpad_twiddle(chip, 1);
641
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100642 /* clear any pendings IRQ */
643 inb(AD1848P(chip, STATUS));
644 outb(0, AD1848P(chip, STATUS));
645 mb();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100647 snd_ad1848_mce_down(chip);
648 for (i = 0; i < 16; i++)
649 snd_ad1848_out(chip, i, chip->image[i]);
650 snd_ad1848_mce_up(chip);
651 snd_ad1848_mce_down(chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}
653#endif /* CONFIG_PM */
654
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100655static int snd_ad1848_probe(struct snd_ad1848 * chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
657 unsigned long flags;
658 int i, id, rev, ad1847;
659 unsigned char *ptr;
660
661#if 0
662 snd_ad1848_debug(chip);
663#endif
664 id = ad1847 = 0;
665 for (i = 0; i < 1000; i++) {
666 mb();
667 if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
668 udelay(500);
669 else {
670 spin_lock_irqsave(&chip->reg_lock, flags);
671 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00);
672 snd_ad1848_out(chip, AD1848_LEFT_INPUT, 0xaa);
673 snd_ad1848_out(chip, AD1848_RIGHT_INPUT, 0x45);
674 rev = snd_ad1848_in(chip, AD1848_RIGHT_INPUT);
675 if (rev == 0x65) {
676 spin_unlock_irqrestore(&chip->reg_lock, flags);
677 id = 1;
678 ad1847 = 1;
679 break;
680 }
681 if (snd_ad1848_in(chip, AD1848_LEFT_INPUT) == 0xaa && rev == 0x45) {
682 spin_unlock_irqrestore(&chip->reg_lock, flags);
683 id = 1;
684 break;
685 }
686 spin_unlock_irqrestore(&chip->reg_lock, flags);
687 }
688 }
689 if (id != 1)
690 return -ENODEV; /* no valid device found */
691 if (chip->hardware == AD1848_HW_DETECT) {
692 if (ad1847) {
693 chip->hardware = AD1848_HW_AD1847;
694 } else {
695 chip->hardware = AD1848_HW_AD1848;
696 rev = snd_ad1848_in(chip, AD1848_MISC_INFO);
697 if (rev & 0x80) {
698 chip->hardware = AD1848_HW_CS4248;
699 } else if ((rev & 0x0f) == 0x0a) {
700 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x40);
701 for (i = 0; i < 16; ++i) {
702 if (snd_ad1848_in(chip, i) != snd_ad1848_in(chip, i + 16)) {
703 chip->hardware = AD1848_HW_CMI8330;
704 break;
705 }
706 }
707 snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00);
708 }
709 }
710 }
711 spin_lock_irqsave(&chip->reg_lock, flags);
712 inb(AD1848P(chip, STATUS)); /* clear any pendings IRQ */
713 outb(0, AD1848P(chip, STATUS));
714 mb();
715 spin_unlock_irqrestore(&chip->reg_lock, flags);
716
717 chip->image[AD1848_MISC_INFO] = 0x00;
718 chip->image[AD1848_IFACE_CTRL] =
719 (chip->image[AD1848_IFACE_CTRL] & ~AD1848_SINGLE_DMA) | AD1848_SINGLE_DMA;
720 ptr = (unsigned char *) &chip->image;
721 snd_ad1848_mce_down(chip);
722 spin_lock_irqsave(&chip->reg_lock, flags);
723 for (i = 0; i < 16; i++) /* ok.. fill all AD1848 registers */
724 snd_ad1848_out(chip, i, *ptr++);
725 spin_unlock_irqrestore(&chip->reg_lock, flags);
726 snd_ad1848_mce_up(chip);
727 snd_ad1848_mce_down(chip);
728 return 0; /* all things are ok.. */
729}
730
731/*
732
733 */
734
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100735static struct snd_pcm_hardware snd_ad1848_playback =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
737 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
738 SNDRV_PCM_INFO_MMAP_VALID),
739 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
740 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE),
741 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
742 .rate_min = 5510,
743 .rate_max = 48000,
744 .channels_min = 1,
745 .channels_max = 2,
746 .buffer_bytes_max = (128*1024),
747 .period_bytes_min = 64,
748 .period_bytes_max = (128*1024),
749 .periods_min = 1,
750 .periods_max = 1024,
751 .fifo_size = 0,
752};
753
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100754static struct snd_pcm_hardware snd_ad1848_capture =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
756 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
757 SNDRV_PCM_INFO_MMAP_VALID),
758 .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
759 SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE),
760 .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
761 .rate_min = 5510,
762 .rate_max = 48000,
763 .channels_min = 1,
764 .channels_max = 2,
765 .buffer_bytes_max = (128*1024),
766 .period_bytes_min = 64,
767 .period_bytes_max = (128*1024),
768 .periods_min = 1,
769 .periods_max = 1024,
770 .fifo_size = 0,
771};
772
773/*
774
775 */
776
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100777static int snd_ad1848_playback_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100779 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
780 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 int err;
782
783 if ((err = snd_ad1848_open(chip, AD1848_MODE_PLAY)) < 0)
784 return err;
785 chip->playback_substream = substream;
786 runtime->hw = snd_ad1848_playback;
787 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max);
788 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max);
789 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
790 return 0;
791}
792
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100793static int snd_ad1848_capture_open(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100795 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
796 struct snd_pcm_runtime *runtime = substream->runtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 int err;
798
799 if ((err = snd_ad1848_open(chip, AD1848_MODE_CAPTURE)) < 0)
800 return err;
801 chip->capture_substream = substream;
802 runtime->hw = snd_ad1848_capture;
803 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max);
804 snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max);
805 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
806 return 0;
807}
808
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100809static int snd_ad1848_playback_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100811 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 chip->mode &= ~AD1848_MODE_PLAY;
814 chip->playback_substream = NULL;
815 snd_ad1848_close(chip);
816 return 0;
817}
818
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100819static int snd_ad1848_capture_close(struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100821 struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 chip->mode &= ~AD1848_MODE_CAPTURE;
824 chip->capture_substream = NULL;
825 snd_ad1848_close(chip);
826 return 0;
827}
828
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100829static int snd_ad1848_free(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830{
Takashi Iwaib1d57762005-10-10 11:56:31 +0200831 release_and_free_resource(chip->res_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 if (chip->irq >= 0)
833 free_irq(chip->irq, (void *) chip);
834 if (chip->dma >= 0) {
835 snd_dma_disable(chip->dma);
836 free_dma(chip->dma);
837 }
838 kfree(chip);
839 return 0;
840}
841
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100842static int snd_ad1848_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100844 struct snd_ad1848 *chip = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 return snd_ad1848_free(chip);
846}
847
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100848static const char *snd_ad1848_chip_id(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849{
850 switch (chip->hardware) {
851 case AD1848_HW_AD1847: return "AD1847";
852 case AD1848_HW_AD1848: return "AD1848";
853 case AD1848_HW_CS4248: return "CS4248";
854 case AD1848_HW_CMI8330: return "CMI8330/C3D";
855 default: return "???";
856 }
857}
858
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100859int snd_ad1848_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 unsigned long port,
861 int irq, int dma,
862 unsigned short hardware,
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100863 struct snd_ad1848 ** rchip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100865 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 .dev_free = snd_ad1848_dev_free,
867 };
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100868 struct snd_ad1848 *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 int err;
870
871 *rchip = NULL;
Takashi Iwai9e76a762005-09-09 14:21:17 +0200872 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 if (chip == NULL)
874 return -ENOMEM;
875 spin_lock_init(&chip->reg_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 chip->card = card;
877 chip->port = port;
878 chip->irq = -1;
879 chip->dma = -1;
880 chip->hardware = hardware;
881 memcpy(&chip->image, &snd_ad1848_original_image, sizeof(snd_ad1848_original_image));
882
883 if ((chip->res_port = request_region(port, 4, "AD1848")) == NULL) {
884 snd_printk(KERN_ERR "ad1848: can't grab port 0x%lx\n", port);
885 snd_ad1848_free(chip);
886 return -EBUSY;
887 }
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700888 if (request_irq(irq, snd_ad1848_interrupt, IRQF_DISABLED, "AD1848", (void *) chip)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 snd_printk(KERN_ERR "ad1848: can't grab IRQ %d\n", irq);
890 snd_ad1848_free(chip);
891 return -EBUSY;
892 }
893 chip->irq = irq;
894 if (request_dma(dma, "AD1848")) {
895 snd_printk(KERN_ERR "ad1848: can't grab DMA %d\n", dma);
896 snd_ad1848_free(chip);
897 return -EBUSY;
898 }
899 chip->dma = dma;
900
901 if (hardware == AD1848_HW_THINKPAD) {
902 chip->thinkpad_flag = 1;
903 chip->hardware = AD1848_HW_DETECT; /* reset */
904 snd_ad1848_thinkpad_twiddle(chip, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 }
906
907 if (snd_ad1848_probe(chip) < 0) {
908 snd_ad1848_free(chip);
909 return -ENODEV;
910 }
911
912 /* Register device */
913 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
914 snd_ad1848_free(chip);
915 return err;
916 }
917
Takashi Iwai9d70d912005-11-30 10:12:26 +0100918#ifdef CONFIG_PM
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100919 chip->suspend = snd_ad1848_suspend;
920 chip->resume = snd_ad1848_resume;
Takashi Iwai9d70d912005-11-30 10:12:26 +0100921#endif
Takashi Iwaic66d7f72005-11-17 16:57:48 +0100922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 *rchip = chip;
924 return 0;
925}
926
Takashi Iwaieac06a12006-08-22 13:16:25 +0200927EXPORT_SYMBOL(snd_ad1848_create);
928
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100929static struct snd_pcm_ops snd_ad1848_playback_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 .open = snd_ad1848_playback_open,
931 .close = snd_ad1848_playback_close,
932 .ioctl = snd_ad1848_ioctl,
933 .hw_params = snd_ad1848_playback_hw_params,
934 .hw_free = snd_ad1848_playback_hw_free,
935 .prepare = snd_ad1848_playback_prepare,
936 .trigger = snd_ad1848_playback_trigger,
937 .pointer = snd_ad1848_playback_pointer,
938};
939
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100940static struct snd_pcm_ops snd_ad1848_capture_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 .open = snd_ad1848_capture_open,
942 .close = snd_ad1848_capture_close,
943 .ioctl = snd_ad1848_ioctl,
944 .hw_params = snd_ad1848_capture_hw_params,
945 .hw_free = snd_ad1848_capture_hw_free,
946 .prepare = snd_ad1848_capture_prepare,
947 .trigger = snd_ad1848_capture_trigger,
948 .pointer = snd_ad1848_capture_pointer,
949};
950
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100951int snd_ad1848_pcm(struct snd_ad1848 *chip, int device, struct snd_pcm **rpcm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100953 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 int err;
955
956 if ((err = snd_pcm_new(chip->card, "AD1848", device, 1, 1, &pcm)) < 0)
957 return err;
958
959 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ad1848_playback_ops);
960 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ad1848_capture_ops);
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 pcm->private_data = chip;
963 pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
964 strcpy(pcm->name, snd_ad1848_chip_id(chip));
965
966 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
967 snd_dma_isa_data(),
968 64*1024, chip->dma > 3 ? 128*1024 : 64*1024);
969
970 chip->pcm = pcm;
971 if (rpcm)
972 *rpcm = pcm;
973 return 0;
974}
975
Takashi Iwaieac06a12006-08-22 13:16:25 +0200976EXPORT_SYMBOL(snd_ad1848_pcm);
977
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100978const struct snd_pcm_ops *snd_ad1848_get_pcm_ops(int direction)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979{
980 return direction == SNDRV_PCM_STREAM_PLAYBACK ?
981 &snd_ad1848_playback_ops : &snd_ad1848_capture_ops;
982}
983
Takashi Iwaieac06a12006-08-22 13:16:25 +0200984EXPORT_SYMBOL(snd_ad1848_get_pcm_ops);
985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986/*
987 * MIXER part
988 */
989
Takashi Iwaic8ff6642005-11-17 14:29:37 +0100990static int snd_ad1848_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991{
992 static char *texts[4] = {
993 "Line", "Aux", "Mic", "Mix"
994 };
995
996 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
997 uinfo->count = 2;
998 uinfo->value.enumerated.items = 4;
999 if (uinfo->value.enumerated.item > 3)
1000 uinfo->value.enumerated.item = 3;
1001 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1002 return 0;
1003}
1004
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001005static int snd_ad1848_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001007 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 unsigned long flags;
1009
1010 spin_lock_irqsave(&chip->reg_lock, flags);
1011 ucontrol->value.enumerated.item[0] = (chip->image[AD1848_LEFT_INPUT] & AD1848_MIXS_ALL) >> 6;
1012 ucontrol->value.enumerated.item[1] = (chip->image[AD1848_RIGHT_INPUT] & AD1848_MIXS_ALL) >> 6;
1013 spin_unlock_irqrestore(&chip->reg_lock, flags);
1014 return 0;
1015}
1016
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001017static int snd_ad1848_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001019 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 unsigned long flags;
1021 unsigned short left, right;
1022 int change;
1023
1024 if (ucontrol->value.enumerated.item[0] > 3 ||
1025 ucontrol->value.enumerated.item[1] > 3)
1026 return -EINVAL;
1027 left = ucontrol->value.enumerated.item[0] << 6;
1028 right = ucontrol->value.enumerated.item[1] << 6;
1029 spin_lock_irqsave(&chip->reg_lock, flags);
1030 left = (chip->image[AD1848_LEFT_INPUT] & ~AD1848_MIXS_ALL) | left;
1031 right = (chip->image[AD1848_RIGHT_INPUT] & ~AD1848_MIXS_ALL) | right;
1032 change = left != chip->image[AD1848_LEFT_INPUT] ||
1033 right != chip->image[AD1848_RIGHT_INPUT];
1034 snd_ad1848_out(chip, AD1848_LEFT_INPUT, left);
1035 snd_ad1848_out(chip, AD1848_RIGHT_INPUT, right);
1036 spin_unlock_irqrestore(&chip->reg_lock, flags);
1037 return change;
1038}
1039
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001040static int snd_ad1848_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
1042 int mask = (kcontrol->private_value >> 16) & 0xff;
1043
1044 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1045 uinfo->count = 1;
1046 uinfo->value.integer.min = 0;
1047 uinfo->value.integer.max = mask;
1048 return 0;
1049}
1050
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001051static int snd_ad1848_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001053 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 unsigned long flags;
1055 int reg = kcontrol->private_value & 0xff;
1056 int shift = (kcontrol->private_value >> 8) & 0xff;
1057 int mask = (kcontrol->private_value >> 16) & 0xff;
1058 int invert = (kcontrol->private_value >> 24) & 0xff;
1059
1060 spin_lock_irqsave(&chip->reg_lock, flags);
1061 ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask;
1062 spin_unlock_irqrestore(&chip->reg_lock, flags);
1063 if (invert)
1064 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1065 return 0;
1066}
1067
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001068static int snd_ad1848_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001070 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 unsigned long flags;
1072 int reg = kcontrol->private_value & 0xff;
1073 int shift = (kcontrol->private_value >> 8) & 0xff;
1074 int mask = (kcontrol->private_value >> 16) & 0xff;
1075 int invert = (kcontrol->private_value >> 24) & 0xff;
1076 int change;
1077 unsigned short val;
1078
1079 val = (ucontrol->value.integer.value[0] & mask);
1080 if (invert)
1081 val = mask - val;
1082 val <<= shift;
1083 spin_lock_irqsave(&chip->reg_lock, flags);
1084 val = (chip->image[reg] & ~(mask << shift)) | val;
1085 change = val != chip->image[reg];
1086 snd_ad1848_out(chip, reg, val);
1087 spin_unlock_irqrestore(&chip->reg_lock, flags);
1088 return change;
1089}
1090
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001091static int snd_ad1848_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092{
1093 int mask = (kcontrol->private_value >> 24) & 0xff;
1094
1095 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
1096 uinfo->count = 2;
1097 uinfo->value.integer.min = 0;
1098 uinfo->value.integer.max = mask;
1099 return 0;
1100}
1101
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001102static int snd_ad1848_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001104 struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 unsigned long flags;
1106 int left_reg = kcontrol->private_value & 0xff;
1107 int right_reg = (kcontrol->private_value >> 8) & 0xff;
1108 int shift_left = (kcontrol->private_value >> 16) & 0x07;
1109 int shift_right = (kcontrol->private_value >> 19) & 0x07;
1110 int mask = (kcontrol->private_value >> 24) & 0xff;
1111 int invert = (kcontrol->private_value >> 22) & 1;
1112
1113 spin_lock_irqsave(&chip->reg_lock, flags);
1114 ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask;
1115 ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask;
1116 spin_unlock_irqrestore(&chip->reg_lock, flags);
1117 if (invert) {
1118 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
1119 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
1120 }
1121 return 0;
1122}
1123
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001124static int snd_ad1848_put_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 int change;
1135 unsigned short val1, val2;
1136
1137 val1 = ucontrol->value.integer.value[0] & mask;
1138 val2 = ucontrol->value.integer.value[1] & mask;
1139 if (invert) {
1140 val1 = mask - val1;
1141 val2 = mask - val2;
1142 }
1143 val1 <<= shift_left;
1144 val2 <<= shift_right;
1145 spin_lock_irqsave(&chip->reg_lock, flags);
1146 if (left_reg != right_reg) {
1147 val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1;
1148 val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2;
1149 change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg];
1150 snd_ad1848_out(chip, left_reg, val1);
1151 snd_ad1848_out(chip, right_reg, val2);
1152 } else {
1153 val1 = (chip->image[left_reg] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
1154 change = val1 != chip->image[left_reg];
1155 snd_ad1848_out(chip, left_reg, val1);
1156 }
1157 spin_unlock_irqrestore(&chip->reg_lock, flags);
1158 return change;
1159}
1160
1161/*
1162 */
Takashi Iwaieac06a12006-08-22 13:16:25 +02001163int snd_ad1848_add_ctl_elem(struct snd_ad1848 *chip,
1164 const struct ad1848_mix_elem *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001166 static struct snd_kcontrol_new newctls[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 [AD1848_MIX_SINGLE] = {
1168 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1169 .info = snd_ad1848_info_single,
1170 .get = snd_ad1848_get_single,
1171 .put = snd_ad1848_put_single,
1172 },
1173 [AD1848_MIX_DOUBLE] = {
1174 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1175 .info = snd_ad1848_info_double,
1176 .get = snd_ad1848_get_double,
1177 .put = snd_ad1848_put_double,
1178 },
1179 [AD1848_MIX_CAPTURE] = {
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001180 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 .info = snd_ad1848_info_mux,
1182 .get = snd_ad1848_get_mux,
1183 .put = snd_ad1848_put_mux,
1184 },
1185 };
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001186 struct snd_kcontrol *ctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 int err;
1188
Takashi Iwaieac06a12006-08-22 13:16:25 +02001189 ctl = snd_ctl_new1(&newctls[c->type], chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 if (! ctl)
1191 return -ENOMEM;
Takashi Iwaieac06a12006-08-22 13:16:25 +02001192 strlcpy(ctl->id.name, c->name, sizeof(ctl->id.name));
1193 ctl->id.index = c->index;
1194 ctl->private_value = c->private_value;
1195 if (c->tlv) {
1196 ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
1197 ctl->tlv.p = c->tlv;
1198 }
Dave Jones3de44142006-03-06 13:31:18 +01001199 if ((err = snd_ctl_add(chip->card, ctl)) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 return 0;
1202}
1203
Takashi Iwaieac06a12006-08-22 13:16:25 +02001204EXPORT_SYMBOL(snd_ad1848_add_ctl_elem);
1205
Takashi Iwai0cb29ea2007-01-29 15:33:49 +01001206static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
1207static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
1208static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
1210static struct ad1848_mix_elem snd_ad1848_controls[] = {
1211AD1848_DOUBLE("PCM Playback Switch", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 7, 7, 1, 1),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001212AD1848_DOUBLE_TLV("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 1,
1213 db_scale_6bit),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214AD1848_DOUBLE("Aux Playback Switch", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001215AD1848_DOUBLE_TLV("Aux Playback Volume", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 0, 0, 31, 1,
1216 db_scale_5bit_12db_max),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217AD1848_DOUBLE("Aux Playback Switch", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001218AD1848_DOUBLE_TLV("Aux Playback Volume", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 0, 0, 31, 1,
1219 db_scale_5bit_12db_max),
1220AD1848_DOUBLE_TLV("Capture Volume", 0, AD1848_LEFT_INPUT, AD1848_RIGHT_INPUT, 0, 0, 15, 0,
1221 db_scale_rec_gain),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222{
1223 .name = "Capture Source",
1224 .type = AD1848_MIX_CAPTURE,
1225},
1226AD1848_SINGLE("Loopback Capture Switch", 0, AD1848_LOOPBACK, 0, 1, 0),
Takashi Iwaieac06a12006-08-22 13:16:25 +02001227AD1848_SINGLE_TLV("Loopback Capture Volume", 0, AD1848_LOOPBACK, 1, 63, 0,
1228 db_scale_6bit),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229};
1230
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001231int snd_ad1848_mixer(struct snd_ad1848 *chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232{
Takashi Iwaic8ff6642005-11-17 14:29:37 +01001233 struct snd_card *card;
1234 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 unsigned int idx;
1236 int err;
1237
1238 snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL);
1239
1240 pcm = chip->pcm;
1241 card = chip->card;
1242
1243 strcpy(card->mixername, pcm->name);
1244
1245 for (idx = 0; idx < ARRAY_SIZE(snd_ad1848_controls); idx++)
1246 if ((err = snd_ad1848_add_ctl_elem(chip, &snd_ad1848_controls[idx])) < 0)
1247 return err;
1248
1249 return 0;
1250}
1251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252EXPORT_SYMBOL(snd_ad1848_mixer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
1254/*
1255 * INIT part
1256 */
1257
1258static int __init alsa_ad1848_init(void)
1259{
1260 return 0;
1261}
1262
1263static void __exit alsa_ad1848_exit(void)
1264{
1265}
1266
1267module_init(alsa_ad1848_init)
1268module_exit(alsa_ad1848_exit)