blob: cf4ee6d6ef64d34faed3530d3728e05022f16a20 [file] [log] [blame]
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -08001/*
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -08002 * SAA713x ALSA support for V4L
3 * Ricardo Cerqueira <v4l@cerqueira.org>
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -08004 *
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -08005 *
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -08006 * Caveats:
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -08007 * - Volume doesn't work (it's always at max)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -08008 *
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -08009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, version 2
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -080022 */
23
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -080024#include <sound/driver.h>
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -080025#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/time.h>
28#include <linux/wait.h>
29#include <linux/moduleparam.h>
30#include <linux/module.h>
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -080031#include <sound/core.h>
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -080032#include <sound/control.h>
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -080033#include <sound/pcm.h>
34#include <sound/rawmidi.h>
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -080035#include <sound/initval.h>
36
37#include "saa7134.h"
38#include "saa7134-reg.h"
39
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -080040static unsigned int alsa_debug = 0;
41module_param(alsa_debug, int, 0644);
42MODULE_PARM_DESC(alsa_debug,"enable debug messages [alsa]");
43
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -080044/*
45 * Configuration macros
46 */
47
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -080048#define MAX_PCM_DEVICES 1
49#define MAX_PCM_SUBSTREAMS 1
50
51/* defaults */
52#define MAX_BUFFER_SIZE (256*1024)
53#define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE
54#define USE_RATE SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000
55#define USE_RATE_MIN 32000
56#define USE_RATE_MAX 48000
57#define USE_CHANNELS_MIN 1
58#define USE_CHANNELS_MAX 2
59#ifndef USE_PERIODS_MIN
60#define USE_PERIODS_MIN 2
61#endif
62#ifndef USE_PERIODS_MAX
63#define USE_PERIODS_MAX 1024
64#endif
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -080065
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -080066#define MIXER_ADDR_TVTUNER 0
67#define MIXER_ADDR_LINE1 1
68#define MIXER_ADDR_LINE2 2
69#define MIXER_ADDR_LAST 2
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -080070
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -080071static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
72static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
73static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
74
75#define dprintk(fmt, arg...) if (alsa_debug) \
76 printk(KERN_DEBUG "%s/alsa: " fmt, dev->name , ## arg)
77
78/*
79 * Main chip structure
80 */
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -080081typedef struct snd_card_saa7134 {
82 snd_card_t *card;
83 spinlock_t mixer_lock;
84 int mixer_volume[MIXER_ADDR_LAST+1][2];
85 int capture_source[MIXER_ADDR_LAST+1][2];
86 struct pci_dev *pci;
87 struct saa7134_dev *saadev;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -080088
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -080089 unsigned long iobase;
90 int irq;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -080091
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -080092 spinlock_t lock;
93} snd_card_saa7134_t;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -080094
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -080095/*
96 * PCM structure
97 */
98
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -080099typedef struct snd_card_saa7134_pcm {
100 struct saa7134_dev *saadev;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800101
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800102 spinlock_t lock;
103 unsigned int pcm_size; /* buffer size */
104 unsigned int pcm_count; /* bytes per period */
105 unsigned int pcm_bps; /* bytes per second */
106 snd_pcm_substream_t *substream;
107} snd_card_saa7134_pcm_t;
108
109static snd_card_t *snd_saa7134_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
110
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800111/*
112 * saa7134 DMA audio stop
113 *
114 * Called when the capture device is released or the buffer overflows
115 *
116 * - Copied verbatim from saa7134-oss's dsp_dma_stop. Can be dropped
117 * if we just share dsp_dma_stop and use it here
118 *
119 */
120
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800121static void saa7134_dma_stop(struct saa7134_dev *dev)
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800122
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800123{
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800124 dev->oss.dma_blk = -1;
125 dev->oss.dma_running = 0;
126 saa7134_set_dmabits(dev);
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800127}
128
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800129/*
130 * saa7134 DMA audio start
131 *
132 * Called when preparing the capture device for use
133 *
134 * - Copied verbatim from saa7134-oss's dsp_dma_start. Can be dropped
135 * if we just share dsp_dma_start and use it here
136 *
137 */
138
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800139static void saa7134_dma_start(struct saa7134_dev *dev)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800140{
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800141 dev->oss.dma_blk = 0;
142 dev->oss.dma_running = 1;
143 saa7134_set_dmabits(dev);
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800144}
145
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800146/*
147 * saa7134 audio DMA IRQ handler
148 *
149 * Called whenever we get an SAA7134_IRQ_REPORT_DONE_RA3 interrupt
150 * Handles shifting between the 2 buffers, manages the read counters,
151 * and notifies ALSA when periods elapse
152 *
153 * - Mostly copied from saa7134-oss's saa7134_irq_oss_done.
154 *
155 */
156
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800157void saa7134_irq_alsa_done(struct saa7134_dev *dev, unsigned long status)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800158{
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800159 int next_blk, reg = 0;
160
161 spin_lock(&dev->slock);
162 if (UNSET == dev->oss.dma_blk) {
163 dprintk("irq: recording stopped\n");
164 goto done;
165 }
166 if (0 != (status & 0x0f000000))
167 dprintk("irq: lost %ld\n", (status >> 24) & 0x0f);
168 if (0 == (status & 0x10000000)) {
169 /* odd */
170 if (0 == (dev->oss.dma_blk & 0x01))
171 reg = SAA7134_RS_BA1(6);
172 } else {
173 /* even */
174 if (1 == (dev->oss.dma_blk & 0x01))
175 reg = SAA7134_RS_BA2(6);
176 }
177 if (0 == reg) {
178 dprintk("irq: field oops [%s]\n",
179 (status & 0x10000000) ? "even" : "odd");
180 goto done;
181 }
182
183 if (dev->oss.read_count >= dev->oss.blksize * (dev->oss.blocks-2)) {
184 dprintk("irq: overrun [full=%d/%d] - Blocks in %d\n",dev->oss.read_count,
185 dev->oss.bufsize, dev->oss.blocks);
186 saa7134_dma_stop(dev);
187 goto done;
188 }
189
190 /* next block addr */
191 next_blk = (dev->oss.dma_blk + 2) % dev->oss.blocks;
192 saa_writel(reg,next_blk * dev->oss.blksize);
193 if (alsa_debug > 2)
194 dprintk("irq: ok, %s, next_blk=%d, addr=%x, blocks=%u, size=%u, read=%u\n",
195 (status & 0x10000000) ? "even" : "odd ", next_blk,
196 next_blk * dev->oss.blksize, dev->oss.blocks, dev->oss.blksize, dev->oss.read_count);
197
198
199 /* update status & wake waiting readers */
200 dev->oss.dma_blk = (dev->oss.dma_blk + 1) % dev->oss.blocks;
201 dev->oss.read_count += dev->oss.blksize;
202
203 dev->oss.recording_on = reg;
204
205 if (dev->oss.read_count >= snd_pcm_lib_period_bytes(dev->oss.substream)) {
206 spin_unlock(&dev->slock);
207 snd_pcm_period_elapsed(dev->oss.substream);
208 spin_lock(&dev->slock);
209 }
210 done:
211 spin_unlock(&dev->slock);
212
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800213}
214
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800215/*
216 * ALSA capture trigger
217 *
218 * - One of the ALSA capture callbacks.
219 *
220 * Called whenever a capture is started or stopped. Must be defined,
221 * but there's nothing we want to do here
222 *
223 */
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800224
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800225static int snd_card_saa7134_capture_trigger(snd_pcm_substream_t * substream,
226 int cmd)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800227{
228 return 0;
229}
230
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800231/*
232 * DMA buffer config
233 *
234 * Sets the values that will later be used as the size of the buffer,
235 * size of the fragments, and total number of fragments.
236 * Must be called during the preparation stage, before memory is
237 * allocated
238 *
239 * - Copied verbatim from saa7134-oss. Can be dropped
240 * if we just share dsp_buffer_conf from OSS.
241 */
242
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800243static int dsp_buffer_conf(struct saa7134_dev *dev, int blksize, int blocks)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800244{
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800245 if (blksize < 0x100)
246 blksize = 0x100;
247 if (blksize > 0x10000)
248 blksize = 0x10000;
249
250 if (blocks < 2)
251 blocks = 2;
252 if ((blksize * blocks) > 1024*1024)
253 blocks = 1024*1024 / blksize;
254
255 dev->oss.blocks = blocks;
256 dev->oss.blksize = blksize;
257 dev->oss.bufsize = blksize * blocks;
258
259 dprintk("buffer config: %d blocks / %d bytes, %d kB total\n",
260 blocks,blksize,blksize * blocks / 1024);
261 return 0;
262}
263
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800264/*
265 * DMA buffer initialization
266 *
267 * Uses V4L functions to initialize the DMA. Shouldn't be necessary in
268 * ALSA, but I was unable to use ALSA's own DMA, and had to force the
269 * usage of V4L's
270 *
271 * - Copied verbatim from saa7134-oss. Can be dropped
272 * if we just share dsp_buffer_init from OSS.
273 */
274
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800275static int dsp_buffer_init(struct saa7134_dev *dev)
276{
277 int err;
278
279 if (!dev->oss.bufsize)
280 BUG();
281 videobuf_dma_init(&dev->oss.dma);
282 err = videobuf_dma_init_kernel(&dev->oss.dma, PCI_DMA_FROMDEVICE,
283 (dev->oss.bufsize + PAGE_SIZE) >> PAGE_SHIFT);
284 if (0 != err)
285 return err;
286 return 0;
287}
288
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800289/*
290 * ALSA PCM preparation
291 *
292 * - One of the ALSA capture callbacks.
293 *
294 * Called right after the capture device is opened, this function configures
295 * the buffer using the previously defined functions, allocates the memory,
296 * sets up the hardware registers, and then starts the DMA. When this function
297 * returns, the audio should be flowing.
298 *
299 */
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800300
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800301static int snd_card_saa7134_capture_prepare(snd_pcm_substream_t * substream)
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800302{
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800303 snd_pcm_runtime_t *runtime = substream->runtime;
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800304 int err, bswap, sign;
305 u32 fmt, control;
306 unsigned long flags;
307 snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream);
308 struct saa7134_dev *dev;
309 snd_card_saa7134_pcm_t *saapcm = runtime->private_data;
310 unsigned int bps;
311 unsigned long size;
312 unsigned count;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800313
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800314 size = snd_pcm_lib_buffer_bytes(substream);
315 count = snd_pcm_lib_period_bytes(substream);
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800316
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800317 saapcm->saadev->oss.substream = substream;
318 bps = runtime->rate * runtime->channels;
319 bps *= snd_pcm_format_width(runtime->format);
320 bps /= 8;
321 if (bps <= 0)
322 return -EINVAL;
323 saapcm->pcm_bps = bps;
324 saapcm->pcm_size = snd_pcm_lib_buffer_bytes(substream);
325 saapcm->pcm_count = snd_pcm_lib_period_bytes(substream);
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800326
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800327
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800328 dev=saa7134->saadev;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800329
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800330 dsp_buffer_conf(dev,saapcm->pcm_count,(saapcm->pcm_size/saapcm->pcm_count));
331
332 err = dsp_buffer_init(dev);
333 if (0 != err)
334 goto fail2;
335
336 /* prepare buffer */
337 if (0 != (err = videobuf_dma_pci_map(dev->pci,&dev->oss.dma)))
338 return err;
339 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->oss.pt)))
340 goto fail1;
341 if (0 != (err = saa7134_pgtable_build(dev->pci,&dev->oss.pt,
342 dev->oss.dma.sglist,
343 dev->oss.dma.sglen,
344 0)))
345 goto fail2;
346
347
348
349 switch (runtime->format) {
350 case SNDRV_PCM_FORMAT_U8:
351 case SNDRV_PCM_FORMAT_S8:
352 fmt = 0x00;
353 break;
354 case SNDRV_PCM_FORMAT_U16_LE:
355 case SNDRV_PCM_FORMAT_U16_BE:
356 case SNDRV_PCM_FORMAT_S16_LE:
357 case SNDRV_PCM_FORMAT_S16_BE:
358 fmt = 0x01;
359 break;
360 default:
361 err = -EINVAL;
362 return 1;
363 }
364
365 switch (runtime->format) {
366 case SNDRV_PCM_FORMAT_S8:
367 case SNDRV_PCM_FORMAT_S16_LE:
368 case SNDRV_PCM_FORMAT_S16_BE:
369 sign = 1;
370 break;
371 default:
372 sign = 0;
373 break;
374 }
375
376 switch (runtime->format) {
377 case SNDRV_PCM_FORMAT_U16_BE:
378 case SNDRV_PCM_FORMAT_S16_BE:
379 bswap = 1; break;
380 default:
381 bswap = 0; break;
382 }
383
384 switch (dev->pci->device) {
385 case PCI_DEVICE_ID_PHILIPS_SAA7134:
386 if (1 == runtime->channels)
387 fmt |= (1 << 3);
388 if (2 == runtime->channels)
389 fmt |= (3 << 3);
390 if (sign)
391 fmt |= 0x04;
392
393 fmt |= (MIXER_ADDR_TVTUNER == dev->oss.input) ? 0xc0 : 0x80;
394 saa_writeb(SAA7134_NUM_SAMPLES0, ((dev->oss.blksize - 1) & 0x0000ff));
395 saa_writeb(SAA7134_NUM_SAMPLES1, ((dev->oss.blksize - 1) & 0x00ff00) >> 8);
396 saa_writeb(SAA7134_NUM_SAMPLES2, ((dev->oss.blksize - 1) & 0xff0000) >> 16);
397 saa_writeb(SAA7134_AUDIO_FORMAT_CTRL, fmt);
398
399 break;
400 case PCI_DEVICE_ID_PHILIPS_SAA7133:
401 case PCI_DEVICE_ID_PHILIPS_SAA7135:
402 if (1 == runtime->channels)
403 fmt |= (1 << 4);
404 if (2 == runtime->channels)
405 fmt |= (2 << 4);
406 if (!sign)
407 fmt |= 0x04;
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800408 saa_writel(SAA7133_NUM_SAMPLES, dev->oss.blksize -1);
409 saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210 | (fmt << 24));
410 //saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210);
411 break;
412 }
413
414 dprintk("rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n",
415 runtime->format, runtime->channels, fmt,
416 bswap ? 'b' : '-');
417 /* dma: setup channel 6 (= AUDIO) */
418 control = SAA7134_RS_CONTROL_BURST_16 |
419 SAA7134_RS_CONTROL_ME |
420 (dev->oss.pt.dma >> 12);
421 if (bswap)
422 control |= SAA7134_RS_CONTROL_BSWAP;
423
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800424 /* I should be able to use runtime->dma_addr in the control
425 byte, but it doesn't work. So I allocate the DMA using the
426 V4L functions, and force ALSA to use that as the DMA area */
427
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800428 runtime->dma_area = dev->oss.dma.vmalloc;
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800429
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800430 saa_writel(SAA7134_RS_BA1(6),0);
431 saa_writel(SAA7134_RS_BA2(6),dev->oss.blksize);
432 saa_writel(SAA7134_RS_PITCH(6),0);
433 saa_writel(SAA7134_RS_CONTROL(6),control);
434
435 dev->oss.rate = runtime->rate;
436 /* start dma */
437 spin_lock_irqsave(&dev->slock,flags);
438 saa7134_dma_start(dev);
439 spin_unlock_irqrestore(&dev->slock,flags);
440
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800441 return 0;
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800442 fail2:
443 saa7134_pgtable_free(dev->pci,&dev->oss.pt);
444 fail1:
445 videobuf_dma_pci_unmap(dev->pci,&dev->oss.dma);
446 return err;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800447
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800448
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800449}
450
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800451/*
452 * ALSA pointer fetching
453 *
454 * - One of the ALSA capture callbacks.
455 *
456 * Called whenever a period elapses, it must return the current hardware
457 * position of the buffer.
458 * Also resets the read counter used to prevent overruns
459 *
460 */
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800461
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800462static snd_pcm_uframes_t snd_card_saa7134_capture_pointer(snd_pcm_substream_t * substream)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800463{
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800464 snd_pcm_runtime_t *runtime = substream->runtime;
465 snd_card_saa7134_pcm_t *saapcm = runtime->private_data;
466 struct saa7134_dev *dev=saapcm->saadev;
467
468
469
470 if (dev->oss.read_count) {
471 dev->oss.read_count -= snd_pcm_lib_period_bytes(substream);
472 dev->oss.read_offset += snd_pcm_lib_period_bytes(substream);
473 if (dev->oss.read_offset == dev->oss.bufsize)
474 dev->oss.read_offset = 0;
475 }
476
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800477 return bytes_to_frames(runtime, dev->oss.read_offset);
478}
479
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800480/*
481 * ALSA hardware capabilities definition
482 */
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800483
484static snd_pcm_hardware_t snd_card_saa7134_capture =
485{
486 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
487 SNDRV_PCM_INFO_BLOCK_TRANSFER |
488 SNDRV_PCM_INFO_MMAP_VALID),
489 .formats = USE_FORMATS,
490 .rates = USE_RATE,
491 .rate_min = USE_RATE_MIN,
492 .rate_max = USE_RATE_MAX,
493 .channels_min = USE_CHANNELS_MIN,
494 .channels_max = USE_CHANNELS_MAX,
495 .buffer_bytes_max = MAX_BUFFER_SIZE,
496 .period_bytes_min = 64,
497 .period_bytes_max = MAX_BUFFER_SIZE,
498 .periods_min = USE_PERIODS_MIN,
499 .periods_max = USE_PERIODS_MAX,
500 .fifo_size = 0x08070503,
501};
502
503static void snd_card_saa7134_runtime_free(snd_pcm_runtime_t *runtime)
504{
505 snd_card_saa7134_pcm_t *saapcm = runtime->private_data;
506
507 kfree(saapcm);
508}
509
510
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800511/*
512 * ALSA hardware params
513 *
514 * - One of the ALSA capture callbacks.
515 *
516 * Called on initialization, right before the PCM preparation
517 * Usually used in ALSA to allocate the DMA, but since we don't use the
518 * ALSA DMA I'm almost sure this isn't necessary.
519 *
520 */
521
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800522static int snd_card_saa7134_hw_params(snd_pcm_substream_t * substream,
523 snd_pcm_hw_params_t * hw_params)
524{
525
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800526 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800527
528
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800529}
530
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800531/*
532 * ALSA hardware release
533 *
534 * - One of the ALSA capture callbacks.
535 *
536 * Called after closing the device, but before snd_card_saa7134_capture_close
537 * Usually used in ALSA to free the DMA, but since we don't use the
538 * ALSA DMA I'm almost sure this isn't necessary.
539 *
540 */
541
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800542static int snd_card_saa7134_hw_free(snd_pcm_substream_t * substream)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800543{
544 return snd_pcm_lib_free_pages(substream);
545}
546
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800547/*
548 * DMA buffer release
549 *
550 * Called after closing the device, during snd_card_saa7134_capture_close
551 *
552 */
553
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800554static int dsp_buffer_free(struct saa7134_dev *dev)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800555{
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800556 if (!dev->oss.blksize)
557 BUG();
558
559 videobuf_dma_free(&dev->oss.dma);
560
561 dev->oss.blocks = 0;
562 dev->oss.blksize = 0;
563 dev->oss.bufsize = 0;
564
565 return 0;
566}
567
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800568/*
569 * ALSA capture finish
570 *
571 * - One of the ALSA capture callbacks.
572 *
573 * Called after closing the device. It stops the DMA audio and releases
574 * the buffers
575 *
576 */
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800577
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800578static int snd_card_saa7134_capture_close(snd_pcm_substream_t * substream)
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800579{
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800580 snd_card_saa7134_t *chip = snd_pcm_substream_chip(substream);
581 struct saa7134_dev *dev = chip->saadev;
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800582 unsigned long flags;
583
584 /* stop dma */
585 spin_lock_irqsave(&dev->slock,flags);
586 saa7134_dma_stop(dev);
587 spin_unlock_irqrestore(&dev->slock,flags);
588
589 /* unlock buffer */
590 saa7134_pgtable_free(dev->pci,&dev->oss.pt);
591 videobuf_dma_pci_unmap(dev->pci,&dev->oss.dma);
592
593 dsp_buffer_free(dev);
594 return 0;
595}
596
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800597/*
598 * ALSA capture start
599 *
600 * - One of the ALSA capture callbacks.
601 *
602 * Called when opening the device. It creates and populates the PCM
603 * structure
604 *
605 */
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800606
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800607static int snd_card_saa7134_capture_open(snd_pcm_substream_t * substream)
608{
609 snd_pcm_runtime_t *runtime = substream->runtime;
610 snd_card_saa7134_pcm_t *saapcm;
611 snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream);
612 struct saa7134_dev *dev = saa7134->saadev;
613 int err;
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800614
615 down(&dev->oss.lock);
616
617 dev->oss.afmt = SNDRV_PCM_FORMAT_U8;
618 dev->oss.channels = 2;
619 dev->oss.read_count = 0;
620 dev->oss.read_offset = 0;
621
622 up(&dev->oss.lock);
623
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800624 saapcm = kcalloc(1, sizeof(*saapcm), GFP_KERNEL);
625 if (saapcm == NULL)
626 return -ENOMEM;
627 saapcm->saadev=saa7134->saadev;
628
629 spin_lock_init(&saapcm->lock);
630
631 saapcm->substream = substream;
632 runtime->private_data = saapcm;
633 runtime->private_free = snd_card_saa7134_runtime_free;
634 runtime->hw = snd_card_saa7134_capture;
635
636 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
637 return err;
638
639 return 0;
640}
641
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800642/*
643 * ALSA capture callbacks definition
644 */
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800645
646static snd_pcm_ops_t snd_card_saa7134_capture_ops = {
647 .open = snd_card_saa7134_capture_open,
648 .close = snd_card_saa7134_capture_close,
649 .ioctl = snd_pcm_lib_ioctl,
650 .hw_params = snd_card_saa7134_hw_params,
651 .hw_free = snd_card_saa7134_hw_free,
652 .prepare = snd_card_saa7134_capture_prepare,
653 .trigger = snd_card_saa7134_capture_trigger,
654 .pointer = snd_card_saa7134_capture_pointer,
655};
656
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800657/*
658 * ALSA PCM setup
659 *
660 * Called when initializing the board. Sets up the name and hooks up
661 * the callbacks
662 *
663 */
664
665static int snd_card_saa7134_pcm(snd_card_saa7134_t *saa7134, int device)
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800666{
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800667 snd_pcm_t *pcm;
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800668 int err;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800669
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800670 if ((err = snd_pcm_new(saa7134->card, "SAA7134 PCM", device, 0, 1, &pcm)) < 0)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800671 return err;
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800672 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_saa7134_capture_ops);
673 pcm->private_data = saa7134;
674 pcm->info_flags = 0;
675 strcpy(pcm->name, "SAA7134 PCM");
676 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
677 snd_dma_pci_data(saa7134->pci),
678 128*1024, 256*1024);
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800679 return 0;
680}
681
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800682#define SAA713x_VOLUME(xname, xindex, addr) \
683{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
684 .info = snd_saa7134_volume_info, \
685 .get = snd_saa7134_volume_get, .put = snd_saa7134_volume_put, \
686 .private_value = addr }
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800687
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800688static int snd_saa7134_volume_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
689{
690 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
691 uinfo->count = 2;
692 uinfo->value.integer.min = 0;
693 uinfo->value.integer.max = 20;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800694 return 0;
695}
696
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800697static int snd_saa7134_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800698{
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800699 snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol);
700 unsigned long flags;
701 int addr = kcontrol->private_value;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800702
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800703 spin_lock_irqsave(&chip->mixer_lock, flags);
704 ucontrol->value.integer.value[0] = chip->mixer_volume[addr][0];
705 ucontrol->value.integer.value[1] = chip->mixer_volume[addr][1];
706 spin_unlock_irqrestore(&chip->mixer_lock, flags);
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800707 return 0;
708}
709
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800710static int snd_saa7134_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
711{
712 snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol);
713 unsigned long flags;
714 int change, addr = kcontrol->private_value;
715 int left, right;
716
717 left = ucontrol->value.integer.value[0];
718 if (left < 0)
719 left = 0;
720 if (left > 20)
721 left = 20;
722 right = ucontrol->value.integer.value[1];
723 if (right < 0)
724 right = 0;
725 if (right > 20)
726 right = 20;
727 spin_lock_irqsave(&chip->mixer_lock, flags);
728 change = chip->mixer_volume[addr][0] != left ||
729 chip->mixer_volume[addr][1] != right;
730 chip->mixer_volume[addr][0] = left;
731 chip->mixer_volume[addr][1] = right;
732 spin_unlock_irqrestore(&chip->mixer_lock, flags);
733 return change;
734}
735
736#define SAA713x_CAPSRC(xname, xindex, addr) \
737{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
738 .info = snd_saa7134_capsrc_info, \
739 .get = snd_saa7134_capsrc_get, .put = snd_saa7134_capsrc_put, \
740 .private_value = addr }
741
742static int snd_saa7134_capsrc_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
743{
744 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800745 uinfo->count = 2;
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800746 uinfo->value.integer.min = 0;
747 uinfo->value.integer.max = 1;
748 return 0;
749}
750
751static int snd_saa7134_capsrc_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
752{
753 snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol);
754 unsigned long flags;
755 int addr = kcontrol->private_value;
756
757 spin_lock_irqsave(&chip->mixer_lock, flags);
758 ucontrol->value.integer.value[0] = chip->capture_source[addr][0];
759 ucontrol->value.integer.value[1] = chip->capture_source[addr][1];
760 spin_unlock_irqrestore(&chip->mixer_lock, flags);
761 return 0;
762}
763
764static int snd_saa7134_capsrc_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
765{
766 snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol);
767 unsigned long flags;
768 int change, addr = kcontrol->private_value;
769 int left, right;
770 u32 anabar, xbarin;
771 int analog_io, rate;
772 struct saa7134_dev *dev;
773
774 dev = chip->saadev;
775
776 left = ucontrol->value.integer.value[0] & 1;
777 right = ucontrol->value.integer.value[1] & 1;
778 spin_lock_irqsave(&chip->mixer_lock, flags);
779
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800780 change = chip->capture_source[addr][0] != left ||
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800781 chip->capture_source[addr][1] != right;
782 chip->capture_source[addr][0] = left;
783 chip->capture_source[addr][1] = right;
784 dev->oss.input=addr;
785 spin_unlock_irqrestore(&chip->mixer_lock, flags);
786
787
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800788 if (change) {
789 switch (dev->pci->device) {
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800790
791 case PCI_DEVICE_ID_PHILIPS_SAA7134:
792 switch (addr) {
793 case MIXER_ADDR_TVTUNER:
794 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0xc0);
795 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, 0x00);
796 break;
797 case MIXER_ADDR_LINE1:
798 case MIXER_ADDR_LINE2:
799 analog_io = (MIXER_ADDR_LINE1 == addr) ? 0x00 : 0x08;
800 rate = (32000 == dev->oss.rate) ? 0x01 : 0x03;
801 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, analog_io);
802 saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0x80);
803 saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, rate);
804 break;
805 }
806
807 case PCI_DEVICE_ID_PHILIPS_SAA7133:
808 case PCI_DEVICE_ID_PHILIPS_SAA7135:
809 xbarin = 0x03; // adc
810 anabar = 0;
811 switch (addr) {
812 case MIXER_ADDR_TVTUNER:
813 xbarin = 0; // Demodulator
814 anabar = 2; // DACs
815 break;
816 case MIXER_ADDR_LINE1:
817 anabar = 0; // aux1, aux1
818 break;
819 case MIXER_ADDR_LINE2:
820 anabar = 9; // aux2, aux2
821 break;
822 }
823
824 /* output xbar always main channel */
825 saa_dsp_writel(dev, SAA7133_DIGITAL_OUTPUT_SEL1, 0xbbbb10);
826
827 if (left || right) { // We've got data, turn the input on
828 //saa_dsp_writel(dev, SAA7133_DIGITAL_OUTPUT_SEL2, 0x101010);
829 saa_dsp_writel(dev, SAA7133_DIGITAL_INPUT_XBAR1, xbarin);
830 saa_writel(SAA7133_ANALOG_IO_SELECT, anabar);
831 } else {
832 //saa_dsp_writel(dev, SAA7133_DIGITAL_OUTPUT_SEL2, 0x101010);
833 saa_dsp_writel(dev, SAA7133_DIGITAL_INPUT_XBAR1, 0);
834 saa_writel(SAA7133_ANALOG_IO_SELECT, 0);
835 }
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800836 }
837 }
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800838
839 return change;
840}
841
842static snd_kcontrol_new_t snd_saa7134_controls[] = {
843SAA713x_VOLUME("Video Volume", 0, MIXER_ADDR_TVTUNER),
844SAA713x_CAPSRC("Video Capture Switch", 0, MIXER_ADDR_TVTUNER),
845SAA713x_VOLUME("Line Volume", 1, MIXER_ADDR_LINE1),
846SAA713x_CAPSRC("Line Capture Switch", 1, MIXER_ADDR_LINE1),
847SAA713x_VOLUME("Line Volume", 2, MIXER_ADDR_LINE2),
848SAA713x_CAPSRC("Line Capture Switch", 2, MIXER_ADDR_LINE2),
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800849};
850
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800851/*
852 * ALSA mixer setup
853 *
854 * Called when initializing the board. Sets up the name and hooks up
855 * the callbacks
856 *
857 */
858
859static int snd_card_saa7134_new_mixer(snd_card_saa7134_t * chip)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800860{
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800861 snd_card_t *card = chip->card;
862 unsigned int idx;
863 int err;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800864
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800865 snd_assert(chip != NULL, return -EINVAL);
866 strcpy(card->mixername, "SAA7134 Mixer");
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800867
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800868 for (idx = 0; idx < ARRAY_SIZE(snd_saa7134_controls); idx++) {
869 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_saa7134_controls[idx], chip))) < 0)
870 return err;
871 }
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800872 return 0;
873}
874
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800875static int snd_saa7134_free(snd_card_saa7134_t *chip)
876{
877 return 0;
878}
879
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800880static int snd_saa7134_dev_free(snd_device_t *device)
881{
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800882 snd_card_saa7134_t *chip = device->device_data;
883 return snd_saa7134_free(chip);
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800884}
885
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800886/*
887 * ALSA initialization
888 *
889 * Called by saa7134-core, it creates the basic structures and registers
890 * the ALSA devices
891 *
892 */
893
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800894int alsa_card_saa7134_create(struct saa7134_dev *saadev)
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800895{
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800896 static int dev;
897 snd_card_t *card;
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800898 snd_card_saa7134_t *chip;
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800899 int err;
900 static snd_device_ops_t ops = {
901 .dev_free = snd_saa7134_dev_free,
902 };
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800903
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800904 if (dev >= SNDRV_CARDS)
905 return -ENODEV;
906 if (!enable[dev])
907 return -ENODEV;
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800908
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800909 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800910 0);
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800911 if (card == NULL)
912 return -ENOMEM;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800913
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800914 strcpy(card->driver, "SAA7134");
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800915
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800916 /* Card "creation" */
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800917
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800918 chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
919 if (chip == NULL) {
920 return -ENOMEM;
921 }
922
923 spin_lock_init(&chip->lock);
924
925 chip->saadev = saadev;
926
927 chip->card = card;
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800928
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800929 chip->pci = saadev->pci;
930 chip->irq = saadev->pci->irq;
931 chip->iobase = pci_resource_start(saadev->pci, 0);
932
933 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
934 snd_saa7134_free(chip);
935 return err;
936 }
937
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800938 if ((err = snd_card_saa7134_new_mixer(chip)) < 0)
939 goto __nodev;
940
941 if ((err = snd_card_saa7134_pcm(chip, 0)) < 0)
942 goto __nodev;
Ricardo Cerqueirab2c15ea2005-11-08 21:37:14 -0800943
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800944 spin_lock_init(&chip->mixer_lock);
945
946 snd_card_set_dev(card, &chip->pci->dev);
947
948 /* End of "creation" */
949
950 strcpy(card->shortname, "SAA7134");
951 sprintf(card->longname, "%s at 0x%lx irq %d",
952 card->shortname, chip->iobase, chip->irq);
953
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800954 if ((err = snd_card_register(card)) == 0) {
955 snd_saa7134_cards[dev] = card;
956 return 0;
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800957 }
958
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800959__nodev:
960 snd_card_free(card);
961 kfree(card);
962 return err;
963}
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800964
Ricardo Cerqueirabd15eba2005-11-08 21:37:11 -0800965void alsa_card_saa7134_exit(void)
966{
967 int idx;
968 for (idx = 0; idx < SNDRV_CARDS; idx++) {
969 snd_card_free(snd_saa7134_cards[idx]);
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800970 }
Nickolay V. Shmyrev5f7591c2005-11-08 21:37:04 -0800971}