[PATCH] fix semaphore handling in __unregister_chrdev_region
[linux/fpc-iii.git] / sound / mips / au1x00.c
blobc20522b0213463409a92f750c50940944081e19a
1 /*
2 * BRIEF MODULE DESCRIPTION
3 * Driver for AMD Au1000 MIPS Processor, AC'97 Sound Port
5 * Copyright 2004 Cooper Street Innovations Inc.
6 * Author: Charles Eidsness <charles@cooper-street.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
16 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
19 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 * History:
30 * 2004-09-09 Charles Eidsness -- Original verion -- based on
31 * sa11xx-uda1341.c ALSA driver and the
32 * au1000.c OSS driver.
33 * 2004-09-09 Matt Porter -- Added support for ALSA 1.0.6
37 #include <linux/ioport.h>
38 #include <linux/interrupt.h>
39 #include <sound/driver.h>
40 #include <linux/init.h>
41 #include <linux/slab.h>
42 #include <linux/version.h>
43 #include <sound/core.h>
44 #include <sound/initval.h>
45 #include <sound/pcm.h>
46 #include <sound/ac97_codec.h>
47 #include <asm/mach-au1x00/au1000.h>
48 #include <asm/mach-au1x00/au1000_dma.h>
50 MODULE_AUTHOR("Charles Eidsness <charles@cooper-street.com>");
51 MODULE_DESCRIPTION("Au1000 AC'97 ALSA Driver");
52 MODULE_LICENSE("GPL");
53 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
54 MODULE_SUPPORTED_DEVICE("{{AMD,Au1000 AC'97}}");
55 #else
56 MODULE_CLASSES("{sound}");
57 MODULE_DEVICES("{{AMD,Au1000 AC'97}}");
58 #endif
60 #define chip_t au1000_t
62 #define PLAYBACK 0
63 #define CAPTURE 1
64 #define AC97_SLOT_3 0x01
65 #define AC97_SLOT_4 0x02
66 #define AC97_SLOT_6 0x08
67 #define AC97_CMD_IRQ 31
68 #define READ 0
69 #define WRITE 1
70 #define READ_WAIT 2
71 #define RW_DONE 3
73 DECLARE_WAIT_QUEUE_HEAD(ac97_command_wq);
75 typedef struct au1000_period au1000_period_t;
76 struct au1000_period
78 u32 start;
79 u32 relative_end; /*realtive to start of buffer*/
80 au1000_period_t * next;
83 /*Au1000 AC97 Port Control Reisters*/
84 typedef struct au1000_ac97_reg au1000_ac97_reg_t;
85 struct au1000_ac97_reg {
86 u32 volatile config;
87 u32 volatile status;
88 u32 volatile data;
89 u32 volatile cmd;
90 u32 volatile cntrl;
93 typedef struct audio_stream audio_stream_t;
94 struct audio_stream {
95 snd_pcm_substream_t * substream;
96 int dma;
97 spinlock_t dma_lock;
98 au1000_period_t * buffer;
99 unsigned long period_size;
102 typedef struct snd_card_au1000 {
103 snd_card_t *card;
104 au1000_ac97_reg_t volatile *ac97_ioport;
106 struct resource *ac97_res_port;
107 spinlock_t ac97_lock;
108 ac97_t *ac97;
110 snd_pcm_t *pcm;
111 audio_stream_t *stream[2]; /* playback & capture */
112 } au1000_t;
114 static au1000_t *au1000 = NULL;
116 /*--------------------------- Local Functions --------------------------------*/
117 static void
118 au1000_set_ac97_xmit_slots(long xmit_slots)
120 u32 volatile ac97_config;
122 spin_lock(&au1000->ac97_lock);
123 ac97_config = au1000->ac97_ioport->config;
124 ac97_config = ac97_config & ~AC97C_XMIT_SLOTS_MASK;
125 ac97_config |= (xmit_slots << AC97C_XMIT_SLOTS_BIT);
126 au1000->ac97_ioport->config = ac97_config;
127 spin_unlock(&au1000->ac97_lock);
130 static void
131 au1000_set_ac97_recv_slots(long recv_slots)
133 u32 volatile ac97_config;
135 spin_lock(&au1000->ac97_lock);
136 ac97_config = au1000->ac97_ioport->config;
137 ac97_config = ac97_config & ~AC97C_RECV_SLOTS_MASK;
138 ac97_config |= (recv_slots << AC97C_RECV_SLOTS_BIT);
139 au1000->ac97_ioport->config = ac97_config;
140 spin_unlock(&au1000->ac97_lock);
144 static void
145 au1000_dma_stop(audio_stream_t *stream)
147 unsigned long flags;
148 au1000_period_t * pointer;
149 au1000_period_t * pointer_next;
151 if (stream->buffer != NULL) {
152 spin_lock_irqsave(&stream->dma_lock, flags);
153 disable_dma(stream->dma);
154 spin_unlock_irqrestore(&stream->dma_lock, flags);
156 pointer = stream->buffer;
157 pointer_next = stream->buffer->next;
159 do {
160 kfree(pointer);
161 pointer = pointer_next;
162 pointer_next = pointer->next;
163 } while (pointer != stream->buffer);
165 stream->buffer = NULL;
169 static void
170 au1000_dma_start(audio_stream_t *stream)
172 snd_pcm_substream_t *substream = stream->substream;
173 snd_pcm_runtime_t *runtime = substream->runtime;
175 unsigned long flags, dma_start;
176 int i;
177 au1000_period_t * pointer;
179 if (stream->buffer == NULL) {
180 dma_start = virt_to_phys(runtime->dma_area);
182 stream->period_size = frames_to_bytes(runtime,
183 runtime->period_size);
184 stream->buffer = kmalloc(sizeof(au1000_period_t), GFP_KERNEL);
185 pointer = stream->buffer;
186 for (i = 0 ; i < runtime->periods ; i++) {
187 pointer->start = (u32)(dma_start +
188 (i * stream->period_size));
189 pointer->relative_end = (u32)
190 (((i+1) * stream->period_size) - 0x1);
191 if ( i < runtime->periods - 1) {
192 pointer->next = kmalloc(sizeof(au1000_period_t)
193 , GFP_KERNEL);
194 pointer = pointer->next;
197 pointer->next = stream->buffer;
199 spin_lock_irqsave(&stream->dma_lock, flags);
200 init_dma(stream->dma);
201 if (get_dma_active_buffer(stream->dma) == 0) {
202 clear_dma_done0(stream->dma);
203 set_dma_addr0(stream->dma, stream->buffer->start);
204 set_dma_count0(stream->dma, stream->period_size >> 1);
205 set_dma_addr1(stream->dma, stream->buffer->next->start);
206 set_dma_count1(stream->dma, stream->period_size >> 1);
207 } else {
208 clear_dma_done1(stream->dma);
209 set_dma_addr1(stream->dma, stream->buffer->start);
210 set_dma_count1(stream->dma, stream->period_size >> 1);
211 set_dma_addr0(stream->dma, stream->buffer->next->start);
212 set_dma_count0(stream->dma, stream->period_size >> 1);
214 enable_dma_buffers(stream->dma);
215 start_dma(stream->dma);
216 spin_unlock_irqrestore(&stream->dma_lock, flags);
220 static irqreturn_t
221 au1000_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs)
223 audio_stream_t *stream = (audio_stream_t *) dev_id;
224 snd_pcm_substream_t *substream = stream->substream;
226 spin_lock(&stream->dma_lock);
227 switch (get_dma_buffer_done(stream->dma)) {
228 case DMA_D0:
229 stream->buffer = stream->buffer->next;
230 clear_dma_done0(stream->dma);
231 set_dma_addr0(stream->dma, stream->buffer->next->start);
232 set_dma_count0(stream->dma, stream->period_size >> 1);
233 enable_dma_buffer0(stream->dma);
234 break;
235 case DMA_D1:
236 stream->buffer = stream->buffer->next;
237 clear_dma_done1(stream->dma);
238 set_dma_addr1(stream->dma, stream->buffer->next->start);
239 set_dma_count1(stream->dma, stream->period_size >> 1);
240 enable_dma_buffer1(stream->dma);
241 break;
242 case (DMA_D0 | DMA_D1):
243 spin_unlock(&stream->dma_lock);
244 printk(KERN_ERR "DMA %d missed interrupt.\n",stream->dma);
245 au1000_dma_stop(stream);
246 au1000_dma_start(stream);
247 spin_lock(&stream->dma_lock);
248 break;
249 case (~DMA_D0 & ~DMA_D1):
250 printk(KERN_ERR "DMA %d empty irq.\n",stream->dma);
252 spin_unlock(&stream->dma_lock);
253 snd_pcm_period_elapsed(substream);
254 return IRQ_HANDLED;
257 /*-------------------------- PCM Audio Streams -------------------------------*/
259 static unsigned int rates[] = {8000, 11025, 16000, 22050};
260 static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
261 .count = sizeof(rates) / sizeof(rates[0]),
262 .list = rates,
263 .mask = 0,
266 static snd_pcm_hardware_t snd_au1000 =
268 .info = (SNDRV_PCM_INFO_INTERLEAVED | \
269 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
270 .formats = SNDRV_PCM_FMTBIT_S16_LE,
271 .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |
272 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050),
273 .rate_min = 8000,
274 .rate_max = 22050,
275 .channels_min = 1,
276 .channels_max = 2,
277 .buffer_bytes_max = 128*1024,
278 .period_bytes_min = 32,
279 .period_bytes_max = 16*1024,
280 .periods_min = 8,
281 .periods_max = 255,
282 .fifo_size = 16,
285 static int
286 snd_au1000_playback_open(snd_pcm_substream_t * substream)
288 au1000->stream[PLAYBACK]->substream = substream;
289 au1000->stream[PLAYBACK]->buffer = NULL;
290 substream->private_data = au1000->stream[PLAYBACK];
291 substream->runtime->hw = snd_au1000;
292 return (snd_pcm_hw_constraint_list(substream->runtime, 0,
293 SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates) < 0);
296 static int
297 snd_au1000_capture_open(snd_pcm_substream_t * substream)
299 au1000->stream[CAPTURE]->substream = substream;
300 au1000->stream[CAPTURE]->buffer = NULL;
301 substream->private_data = au1000->stream[CAPTURE];
302 substream->runtime->hw = snd_au1000;
303 return (snd_pcm_hw_constraint_list(substream->runtime, 0,
304 SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates) < 0);
308 static int
309 snd_au1000_playback_close(snd_pcm_substream_t * substream)
311 au1000->stream[PLAYBACK]->substream = NULL;
312 return 0;
315 static int
316 snd_au1000_capture_close(snd_pcm_substream_t * substream)
318 au1000->stream[CAPTURE]->substream = NULL;
319 return 0;
322 static int
323 snd_au1000_hw_params(snd_pcm_substream_t * substream,
324 snd_pcm_hw_params_t * hw_params)
326 return snd_pcm_lib_malloc_pages(substream,
327 params_buffer_bytes(hw_params));
330 static int
331 snd_au1000_hw_free(snd_pcm_substream_t * substream)
333 return snd_pcm_lib_free_pages(substream);
336 static int
337 snd_au1000_playback_prepare(snd_pcm_substream_t * substream)
339 snd_pcm_runtime_t *runtime = substream->runtime;
341 if (runtime->channels == 1 )
342 au1000_set_ac97_xmit_slots(AC97_SLOT_4);
343 else
344 au1000_set_ac97_xmit_slots(AC97_SLOT_3 | AC97_SLOT_4);
345 snd_ac97_set_rate(au1000->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate);
346 return 0;
349 static int
350 snd_au1000_capture_prepare(snd_pcm_substream_t * substream)
352 snd_pcm_runtime_t *runtime = substream->runtime;
354 if (runtime->channels == 1 )
355 au1000_set_ac97_recv_slots(AC97_SLOT_4);
356 else
357 au1000_set_ac97_recv_slots(AC97_SLOT_3 | AC97_SLOT_4);
358 snd_ac97_set_rate(au1000->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate);
359 return 0;
362 static int
363 snd_au1000_trigger(snd_pcm_substream_t * substream, int cmd)
365 audio_stream_t *stream = substream->private_data;
366 int err = 0;
368 switch (cmd) {
369 case SNDRV_PCM_TRIGGER_START:
370 au1000_dma_start(stream);
371 break;
372 case SNDRV_PCM_TRIGGER_STOP:
373 au1000_dma_stop(stream);
374 break;
375 default:
376 err = -EINVAL;
377 break;
379 return err;
382 static snd_pcm_uframes_t
383 snd_au1000_pointer(snd_pcm_substream_t * substream)
385 audio_stream_t *stream = substream->private_data;
386 snd_pcm_runtime_t *runtime = substream->runtime;
387 unsigned long flags;
388 long location;
390 spin_lock_irqsave(&stream->dma_lock, flags);
391 location = get_dma_residue(stream->dma);
392 spin_unlock_irqrestore(&stream->dma_lock, flags);
393 location = stream->buffer->relative_end - location;
394 if (location == -1)
395 location = 0;
396 return bytes_to_frames(runtime,location);
399 static snd_pcm_ops_t snd_card_au1000_playback_ops = {
400 .open = snd_au1000_playback_open,
401 .close = snd_au1000_playback_close,
402 .ioctl = snd_pcm_lib_ioctl,
403 .hw_params = snd_au1000_hw_params,
404 .hw_free = snd_au1000_hw_free,
405 .prepare = snd_au1000_playback_prepare,
406 .trigger = snd_au1000_trigger,
407 .pointer = snd_au1000_pointer,
410 static snd_pcm_ops_t snd_card_au1000_capture_ops = {
411 .open = snd_au1000_capture_open,
412 .close = snd_au1000_capture_close,
413 .ioctl = snd_pcm_lib_ioctl,
414 .hw_params = snd_au1000_hw_params,
415 .hw_free = snd_au1000_hw_free,
416 .prepare = snd_au1000_capture_prepare,
417 .trigger = snd_au1000_trigger,
418 .pointer = snd_au1000_pointer,
421 static int __devinit
422 snd_au1000_pcm_new(void)
424 snd_pcm_t *pcm;
425 int err;
426 unsigned long flags;
428 if ((err = snd_pcm_new(au1000->card, "AU1000 AC97 PCM", 0, 1, 1, &pcm)) < 0)
429 return err;
431 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
432 snd_dma_continuous_data(GFP_KERNEL), 128*1024, 128*1024);
434 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
435 &snd_card_au1000_playback_ops);
436 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
437 &snd_card_au1000_capture_ops);
439 pcm->private_data = au1000;
440 pcm->info_flags = 0;
441 strcpy(pcm->name, "Au1000 AC97 PCM");
443 flags = claim_dma_lock();
444 if ((au1000->stream[PLAYBACK]->dma = request_au1000_dma(DMA_ID_AC97C_TX,
445 "AC97 TX", au1000_dma_interrupt, SA_INTERRUPT,
446 au1000->stream[PLAYBACK])) < 0) {
447 release_dma_lock(flags);
448 return -EBUSY;
450 if ((au1000->stream[CAPTURE]->dma = request_au1000_dma(DMA_ID_AC97C_RX,
451 "AC97 RX", au1000_dma_interrupt, SA_INTERRUPT,
452 au1000->stream[CAPTURE])) < 0){
453 release_dma_lock(flags);
454 return -EBUSY;
456 /* enable DMA coherency in read/write DMA channels */
457 set_dma_mode(au1000->stream[PLAYBACK]->dma,
458 get_dma_mode(au1000->stream[PLAYBACK]->dma) & ~DMA_NC);
459 set_dma_mode(au1000->stream[CAPTURE]->dma,
460 get_dma_mode(au1000->stream[CAPTURE]->dma) & ~DMA_NC);
461 release_dma_lock(flags);
462 spin_lock_init(&au1000->stream[PLAYBACK]->dma_lock);
463 spin_lock_init(&au1000->stream[CAPTURE]->dma_lock);
464 au1000->pcm = pcm;
465 return 0;
469 /*-------------------------- AC97 CODEC Control ------------------------------*/
471 static unsigned short
472 snd_au1000_ac97_read(ac97_t *ac97, unsigned short reg)
474 u32 volatile cmd;
475 u16 volatile data;
476 int i;
477 spin_lock(au1000->ac97_lock);
478 /* would rather use the interupt than this polling but it works and I can't
479 get the interupt driven case to work efficiently */
480 for (i = 0; i < 0x5000; i++)
481 if (!(au1000->ac97_ioport->status & AC97C_CP))
482 break;
483 if (i == 0x5000)
484 printk(KERN_ERR "au1000 AC97: AC97 command read timeout\n");
486 cmd = (u32) reg & AC97C_INDEX_MASK;
487 cmd |= AC97C_READ;
488 au1000->ac97_ioport->cmd = cmd;
490 /* now wait for the data */
491 for (i = 0; i < 0x5000; i++)
492 if (!(au1000->ac97_ioport->status & AC97C_CP))
493 break;
494 if (i == 0x5000) {
495 printk(KERN_ERR "au1000 AC97: AC97 command read timeout\n");
496 return 0;
499 data = au1000->ac97_ioport->cmd & 0xffff;
500 spin_unlock(au1000->ac97_lock);
502 return data;
507 static void
508 snd_au1000_ac97_write(ac97_t *ac97, unsigned short reg, unsigned short val)
510 u32 cmd;
511 int i;
512 spin_lock(au1000->ac97_lock);
513 /* would rather use the interupt than this polling but it works and I can't
514 get the interupt driven case to work efficiently */
515 for (i = 0; i < 0x5000; i++)
516 if (!(au1000->ac97_ioport->status & AC97C_CP))
517 break;
518 if (i == 0x5000)
519 printk(KERN_ERR "au1000 AC97: AC97 command write timeout\n");
521 cmd = (u32) reg & AC97C_INDEX_MASK;
522 cmd &= ~AC97C_READ;
523 cmd |= ((u32) val << AC97C_WD_BIT);
524 au1000->ac97_ioport->cmd = cmd;
525 spin_unlock(au1000->ac97_lock);
527 static void
528 snd_au1000_ac97_free(ac97_t *ac97)
530 au1000->ac97 = NULL;
533 static int __devinit
534 snd_au1000_ac97_new(void)
536 int err;
538 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
539 ac97_bus_t *pbus;
540 ac97_template_t ac97;
541 static ac97_bus_ops_t ops = {
542 .write = snd_au1000_ac97_write,
543 .read = snd_au1000_ac97_read,
545 #else
546 ac97_bus_t bus, *pbus;
547 ac97_t ac97;
548 #endif
550 if ((au1000->ac97_res_port = request_region(AC97C_CONFIG,
551 sizeof(au1000_ac97_reg_t), "Au1x00 AC97")) == NULL) {
552 snd_printk(KERN_ERR "ALSA AC97: can't grap AC97 port\n");
553 return -EBUSY;
555 au1000->ac97_ioport = (au1000_ac97_reg_t *) au1000->ac97_res_port->start;
557 spin_lock_init(&au1000->ac97_lock);
559 spin_lock(&au1000->ac97_lock);
561 /* configure pins for AC'97
562 TODO: move to board_setup.c */
563 au_writel(au_readl(SYS_PINFUNC) & ~0x02, SYS_PINFUNC);
565 /* Initialise Au1000's AC'97 Control Block */
566 au1000->ac97_ioport->cntrl = AC97C_RS | AC97C_CE;
567 udelay(10);
568 au1000->ac97_ioport->cntrl = AC97C_CE;
569 udelay(10);
571 /* Initialise External CODEC -- cold reset */
572 au1000->ac97_ioport->config = AC97C_RESET;
573 udelay(10);
574 au1000->ac97_ioport->config = 0x0;
575 mdelay(5);
577 spin_unlock(&au1000->ac97_lock);
579 /* Initialise AC97 middle-layer */
580 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
581 if ((err = snd_ac97_bus(au1000->card, 0, &ops, au1000, &pbus)) < 0)
582 return err;
583 #else
584 memset(&bus, 0, sizeof(bus));
585 bus.write = snd_au1000_ac97_write;
586 bus.read = snd_au1000_ac97_read;
587 if ((err = snd_ac97_bus(au1000->card, &bus, &pbus)) < 0)
588 return err;
589 #endif
590 memset(&ac97, 0, sizeof(ac97));
591 ac97.private_data = au1000;
592 ac97.private_free = snd_au1000_ac97_free;
593 if ((err = snd_ac97_mixer(pbus, &ac97, &au1000->ac97)) < 0)
594 return err;
595 return 0;
599 /*------------------------------ Setup / Destroy ----------------------------*/
601 void
602 snd_au1000_free(snd_card_t *card)
605 if (au1000->ac97_res_port) {
606 /* put internal AC97 block into reset */
607 au1000->ac97_ioport->cntrl = AC97C_RS;
608 au1000->ac97_ioport = NULL;
609 release_resource(au1000->ac97_res_port);
610 kfree_nocheck(au1000->ac97_res_port);
613 if (au1000->stream[PLAYBACK]->dma >= 0)
614 free_au1000_dma(au1000->stream[PLAYBACK]->dma);
616 if (au1000->stream[CAPTURE]->dma >= 0)
617 free_au1000_dma(au1000->stream[CAPTURE]->dma);
619 kfree(au1000->stream[PLAYBACK]);
620 au1000->stream[PLAYBACK] = NULL;
621 kfree(au1000->stream[CAPTURE]);
622 au1000->stream[CAPTURE] = NULL;
623 kfree(au1000);
624 au1000 = NULL;
628 static int __init
629 au1000_init(void)
631 int err;
633 au1000 = kmalloc(sizeof(au1000_t), GFP_KERNEL);
634 if (au1000 == NULL)
635 return -ENOMEM;
636 au1000->stream[PLAYBACK] = kmalloc(sizeof(audio_stream_t), GFP_KERNEL);
637 if (au1000->stream[PLAYBACK] == NULL)
638 return -ENOMEM;
639 au1000->stream[CAPTURE] = kmalloc(sizeof(audio_stream_t), GFP_KERNEL);
640 if (au1000->stream[CAPTURE] == NULL)
641 return -ENOMEM;
642 /* so that snd_au1000_free will work as intended */
643 au1000->stream[PLAYBACK]->dma = -1;
644 au1000->stream[CAPTURE]->dma = -1;
645 au1000->ac97_res_port = NULL;
647 au1000->card = snd_card_new(-1, "AC97", THIS_MODULE, sizeof(au1000_t));
648 if (au1000->card == NULL) {
649 snd_au1000_free(au1000->card);
650 return -ENOMEM;
653 au1000->card->private_data = (au1000_t *)au1000;
654 au1000->card->private_free = snd_au1000_free;
656 if ((err = snd_au1000_ac97_new()) < 0 ) {
657 snd_card_free(au1000->card);
658 return err;
661 if ((err = snd_au1000_pcm_new()) < 0) {
662 snd_card_free(au1000->card);
663 return err;
666 strcpy(au1000->card->driver, "AMD-Au1000-AC97");
667 strcpy(au1000->card->shortname, "Au1000-AC97");
668 sprintf(au1000->card->longname, "AMD Au1000--AC97 ALSA Driver");
670 if ((err = snd_card_register(au1000->card)) < 0) {
671 snd_card_free(au1000->card);
672 return err;
675 printk( KERN_INFO "ALSA AC97: Driver Initialized\n" );
676 return 0;
679 static void __exit au1000_exit(void)
681 snd_card_free(au1000->card);
684 module_init(au1000_init);
685 module_exit(au1000_exit);