2 * als300.c - driver for Avance Logic ALS300/ALS300+ soundcards.
3 * Copyright (C) 2005 by Ash Willis <ashwillis@programmer.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * 4 channel playback for ALS300+
26 * The BLOCK_COUNTER registers for the ALS300(+) return a figure related to
27 * the position in the current period, NOT the whole buffer. It is important
28 * to know which period we are in so we can calculate the correct pointer.
29 * This is why we always use 2 periods. We can then use a flip-flop variable
30 * to keep track of what period we are in.
33 #include <linux/delay.h>
34 #include <linux/init.h>
35 #include <linux/module.h>
36 #include <linux/pci.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/interrupt.h>
39 #include <linux/slab.h>
43 #include <sound/core.h>
44 #include <sound/control.h>
45 #include <sound/initval.h>
46 #include <sound/pcm.h>
47 #include <sound/pcm_params.h>
48 #include <sound/ac97_codec.h>
49 #include <sound/opl3.h>
51 /* snd_als300_set_irq_flag */
56 #define AC97_ACCESS 0x00
57 #define AC97_READ 0x04
58 #define AC97_STATUS 0x06
59 #define AC97_DATA_AVAIL (1<<6)
60 #define AC97_BUSY (1<<7)
61 #define ALS300_IRQ_STATUS 0x07 /* ALS300 Only */
62 #define IRQ_PLAYBACK (1<<3)
63 #define IRQ_CAPTURE (1<<2)
65 #define GCR_INDEX 0x0C
66 #define ALS300P_DRAM_IRQ_STATUS 0x0D /* ALS300+ Only */
67 #define MPU_IRQ_STATUS 0x0E /* ALS300 Rev. E+, ALS300+ */
68 #define ALS300P_IRQ_STATUS 0x0F /* ALS300+ Only */
70 /* General Control Registers */
71 #define PLAYBACK_START 0x80
72 #define PLAYBACK_END 0x81
73 #define PLAYBACK_CONTROL 0x82
74 #define TRANSFER_START (1<<16)
75 #define FIFO_PAUSE (1<<17)
76 #define RECORD_START 0x83
77 #define RECORD_END 0x84
78 #define RECORD_CONTROL 0x85
79 #define DRAM_WRITE_CONTROL 0x8B
80 #define WRITE_TRANS_START (1<<16)
81 #define DRAM_MODE_2 (1<<17)
82 #define MISC_CONTROL 0x8C
83 #define IRQ_SET_BIT (1<<15)
84 #define VMUTE_NORMAL (1<<20)
85 #define MMUTE_NORMAL (1<<21)
86 #define MUS_VOC_VOL 0x8E
87 #define PLAYBACK_BLOCK_COUNTER 0x9A
88 #define RECORD_BLOCK_COUNTER 0x9B
90 #define DEBUG_PLAY_REC 0
93 #define snd_als300_dbgplay(format, args...) printk(KERN_ERR format, ##args)
95 #define snd_als300_dbgplay(format, args...)
98 enum {DEVICE_ALS300
, DEVICE_ALS300_PLUS
};
100 MODULE_AUTHOR("Ash Willis <ashwillis@programmer.net>");
101 MODULE_DESCRIPTION("Avance Logic ALS300");
102 MODULE_LICENSE("GPL");
103 MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS300},{Avance Logic,ALS300+}}");
105 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
106 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
107 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
109 module_param_array(index
, int, NULL
, 0444);
110 MODULE_PARM_DESC(index
, "Index value for ALS300 sound card.");
111 module_param_array(id
, charp
, NULL
, 0444);
112 MODULE_PARM_DESC(id
, "ID string for ALS300 sound card.");
113 module_param_array(enable
, bool, NULL
, 0444);
114 MODULE_PARM_DESC(enable
, "Enable ALS300 sound card.");
119 struct snd_card
*card
;
123 struct snd_pcm_substream
*playback_substream
;
124 struct snd_pcm_substream
*capture_substream
;
126 struct snd_ac97
*ac97
;
127 struct snd_opl3
*opl3
;
129 struct resource
*res_port
;
133 int chip_type
; /* ALS300 or ALS300+ */
138 struct snd_als300_substream_data
{
140 int control_register
;
141 int block_counter_register
;
144 static DEFINE_PCI_DEVICE_TABLE(snd_als300_ids
) = {
145 { 0x4005, 0x0300, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_ALS300
},
146 { 0x4005, 0x0308, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, DEVICE_ALS300_PLUS
},
150 MODULE_DEVICE_TABLE(pci
, snd_als300_ids
);
152 static inline u32
snd_als300_gcr_read(unsigned long port
, unsigned short reg
)
154 outb(reg
, port
+GCR_INDEX
);
155 return inl(port
+GCR_DATA
);
158 static inline void snd_als300_gcr_write(unsigned long port
,
159 unsigned short reg
, u32 val
)
161 outb(reg
, port
+GCR_INDEX
);
162 outl(val
, port
+GCR_DATA
);
165 /* Enable/Disable Interrupts */
166 static void snd_als300_set_irq_flag(struct snd_als300
*chip
, int cmd
)
168 u32 tmp
= snd_als300_gcr_read(chip
->port
, MISC_CONTROL
);
170 /* boolean XOR check, since old vs. new hardware have
171 directly reversed bit setting for ENABLE and DISABLE.
172 ALS300+ acts like newer versions of ALS300 */
173 if (((chip
->revision
> 5 || chip
->chip_type
== DEVICE_ALS300_PLUS
) ^
174 (cmd
== IRQ_ENABLE
)) == 0)
178 snd_als300_gcr_write(chip
->port
, MISC_CONTROL
, tmp
);
181 static int snd_als300_free(struct snd_als300
*chip
)
183 snd_als300_set_irq_flag(chip
, IRQ_DISABLE
);
185 free_irq(chip
->irq
, chip
);
186 pci_release_regions(chip
->pci
);
187 pci_disable_device(chip
->pci
);
192 static int snd_als300_dev_free(struct snd_device
*device
)
194 struct snd_als300
*chip
= device
->device_data
;
195 return snd_als300_free(chip
);
198 static irqreturn_t
snd_als300_interrupt(int irq
, void *dev_id
)
201 struct snd_als300
*chip
= dev_id
;
202 struct snd_als300_substream_data
*data
;
204 status
= inb(chip
->port
+ALS300_IRQ_STATUS
);
205 if (!status
) /* shared IRQ, for different device?? Exit ASAP! */
208 /* ACK everything ASAP */
209 outb(status
, chip
->port
+ALS300_IRQ_STATUS
);
210 if (status
& IRQ_PLAYBACK
) {
211 if (chip
->pcm
&& chip
->playback_substream
) {
212 data
= chip
->playback_substream
->runtime
->private_data
;
213 data
->period_flipflop
^= 1;
214 snd_pcm_period_elapsed(chip
->playback_substream
);
215 snd_als300_dbgplay("IRQ_PLAYBACK\n");
218 if (status
& IRQ_CAPTURE
) {
219 if (chip
->pcm
&& chip
->capture_substream
) {
220 data
= chip
->capture_substream
->runtime
->private_data
;
221 data
->period_flipflop
^= 1;
222 snd_pcm_period_elapsed(chip
->capture_substream
);
223 snd_als300_dbgplay("IRQ_CAPTURE\n");
229 static irqreturn_t
snd_als300plus_interrupt(int irq
, void *dev_id
)
231 u8 general
, mpu
, dram
;
232 struct snd_als300
*chip
= dev_id
;
233 struct snd_als300_substream_data
*data
;
235 general
= inb(chip
->port
+ALS300P_IRQ_STATUS
);
236 mpu
= inb(chip
->port
+MPU_IRQ_STATUS
);
237 dram
= inb(chip
->port
+ALS300P_DRAM_IRQ_STATUS
);
239 /* shared IRQ, for different device?? Exit ASAP! */
240 if ((general
== 0) && ((mpu
& 0x80) == 0) && ((dram
& 0x01) == 0))
243 if (general
& IRQ_PLAYBACK
) {
244 if (chip
->pcm
&& chip
->playback_substream
) {
245 outb(IRQ_PLAYBACK
, chip
->port
+ALS300P_IRQ_STATUS
);
246 data
= chip
->playback_substream
->runtime
->private_data
;
247 data
->period_flipflop
^= 1;
248 snd_pcm_period_elapsed(chip
->playback_substream
);
249 snd_als300_dbgplay("IRQ_PLAYBACK\n");
252 if (general
& IRQ_CAPTURE
) {
253 if (chip
->pcm
&& chip
->capture_substream
) {
254 outb(IRQ_CAPTURE
, chip
->port
+ALS300P_IRQ_STATUS
);
255 data
= chip
->capture_substream
->runtime
->private_data
;
256 data
->period_flipflop
^= 1;
257 snd_pcm_period_elapsed(chip
->capture_substream
);
258 snd_als300_dbgplay("IRQ_CAPTURE\n");
261 /* FIXME: Ack other interrupt types. Not important right now as
262 * those other devices aren't enabled. */
266 static void snd_als300_remove(struct pci_dev
*pci
)
268 snd_card_free(pci_get_drvdata(pci
));
271 static unsigned short snd_als300_ac97_read(struct snd_ac97
*ac97
,
275 struct snd_als300
*chip
= ac97
->private_data
;
277 for (i
= 0; i
< 1000; i
++) {
278 if ((inb(chip
->port
+AC97_STATUS
) & (AC97_BUSY
)) == 0)
282 outl((reg
<< 24) | (1 << 31), chip
->port
+AC97_ACCESS
);
284 for (i
= 0; i
< 1000; i
++) {
285 if ((inb(chip
->port
+AC97_STATUS
) & (AC97_DATA_AVAIL
)) != 0)
289 return inw(chip
->port
+AC97_READ
);
292 static void snd_als300_ac97_write(struct snd_ac97
*ac97
,
293 unsigned short reg
, unsigned short val
)
296 struct snd_als300
*chip
= ac97
->private_data
;
298 for (i
= 0; i
< 1000; i
++) {
299 if ((inb(chip
->port
+AC97_STATUS
) & (AC97_BUSY
)) == 0)
303 outl((reg
<< 24) | val
, chip
->port
+AC97_ACCESS
);
306 static int snd_als300_ac97(struct snd_als300
*chip
)
308 struct snd_ac97_bus
*bus
;
309 struct snd_ac97_template ac97
;
311 static struct snd_ac97_bus_ops ops
= {
312 .write
= snd_als300_ac97_write
,
313 .read
= snd_als300_ac97_read
,
316 if ((err
= snd_ac97_bus(chip
->card
, 0, &ops
, NULL
, &bus
)) < 0)
319 memset(&ac97
, 0, sizeof(ac97
));
320 ac97
.private_data
= chip
;
322 return snd_ac97_mixer(bus
, &ac97
, &chip
->ac97
);
325 /* hardware definition
327 * In AC97 mode, we always use 48k/16bit/stereo.
328 * Any request to change data type is ignored by
329 * the card when it is running outside of legacy
332 static struct snd_pcm_hardware snd_als300_playback_hw
=
334 .info
= (SNDRV_PCM_INFO_MMAP
|
335 SNDRV_PCM_INFO_INTERLEAVED
|
336 SNDRV_PCM_INFO_PAUSE
|
337 SNDRV_PCM_INFO_MMAP_VALID
),
338 .formats
= SNDRV_PCM_FMTBIT_S16
,
339 .rates
= SNDRV_PCM_RATE_48000
,
344 .buffer_bytes_max
= 64 * 1024,
345 .period_bytes_min
= 64,
346 .period_bytes_max
= 32 * 1024,
351 static struct snd_pcm_hardware snd_als300_capture_hw
=
353 .info
= (SNDRV_PCM_INFO_MMAP
|
354 SNDRV_PCM_INFO_INTERLEAVED
|
355 SNDRV_PCM_INFO_PAUSE
|
356 SNDRV_PCM_INFO_MMAP_VALID
),
357 .formats
= SNDRV_PCM_FMTBIT_S16
,
358 .rates
= SNDRV_PCM_RATE_48000
,
363 .buffer_bytes_max
= 64 * 1024,
364 .period_bytes_min
= 64,
365 .period_bytes_max
= 32 * 1024,
370 static int snd_als300_playback_open(struct snd_pcm_substream
*substream
)
372 struct snd_als300
*chip
= snd_pcm_substream_chip(substream
);
373 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
374 struct snd_als300_substream_data
*data
= kzalloc(sizeof(*data
),
379 chip
->playback_substream
= substream
;
380 runtime
->hw
= snd_als300_playback_hw
;
381 runtime
->private_data
= data
;
382 data
->control_register
= PLAYBACK_CONTROL
;
383 data
->block_counter_register
= PLAYBACK_BLOCK_COUNTER
;
387 static int snd_als300_playback_close(struct snd_pcm_substream
*substream
)
389 struct snd_als300
*chip
= snd_pcm_substream_chip(substream
);
390 struct snd_als300_substream_data
*data
;
392 data
= substream
->runtime
->private_data
;
394 chip
->playback_substream
= NULL
;
395 snd_pcm_lib_free_pages(substream
);
399 static int snd_als300_capture_open(struct snd_pcm_substream
*substream
)
401 struct snd_als300
*chip
= snd_pcm_substream_chip(substream
);
402 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
403 struct snd_als300_substream_data
*data
= kzalloc(sizeof(*data
),
408 chip
->capture_substream
= substream
;
409 runtime
->hw
= snd_als300_capture_hw
;
410 runtime
->private_data
= data
;
411 data
->control_register
= RECORD_CONTROL
;
412 data
->block_counter_register
= RECORD_BLOCK_COUNTER
;
416 static int snd_als300_capture_close(struct snd_pcm_substream
*substream
)
418 struct snd_als300
*chip
= snd_pcm_substream_chip(substream
);
419 struct snd_als300_substream_data
*data
;
421 data
= substream
->runtime
->private_data
;
423 chip
->capture_substream
= NULL
;
424 snd_pcm_lib_free_pages(substream
);
428 static int snd_als300_pcm_hw_params(struct snd_pcm_substream
*substream
,
429 struct snd_pcm_hw_params
*hw_params
)
431 return snd_pcm_lib_malloc_pages(substream
,
432 params_buffer_bytes(hw_params
));
435 static int snd_als300_pcm_hw_free(struct snd_pcm_substream
*substream
)
437 return snd_pcm_lib_free_pages(substream
);
440 static int snd_als300_playback_prepare(struct snd_pcm_substream
*substream
)
443 struct snd_als300
*chip
= snd_pcm_substream_chip(substream
);
444 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
445 unsigned short period_bytes
= snd_pcm_lib_period_bytes(substream
);
446 unsigned short buffer_bytes
= snd_pcm_lib_buffer_bytes(substream
);
448 spin_lock_irq(&chip
->reg_lock
);
449 tmp
= snd_als300_gcr_read(chip
->port
, PLAYBACK_CONTROL
);
450 tmp
&= ~TRANSFER_START
;
452 snd_als300_dbgplay("Period bytes: %d Buffer bytes %d\n",
453 period_bytes
, buffer_bytes
);
457 tmp
|= period_bytes
- 1;
458 snd_als300_gcr_write(chip
->port
, PLAYBACK_CONTROL
, tmp
);
461 snd_als300_gcr_write(chip
->port
, PLAYBACK_START
,
463 snd_als300_gcr_write(chip
->port
, PLAYBACK_END
,
464 runtime
->dma_addr
+ buffer_bytes
- 1);
465 spin_unlock_irq(&chip
->reg_lock
);
469 static int snd_als300_capture_prepare(struct snd_pcm_substream
*substream
)
472 struct snd_als300
*chip
= snd_pcm_substream_chip(substream
);
473 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
474 unsigned short period_bytes
= snd_pcm_lib_period_bytes(substream
);
475 unsigned short buffer_bytes
= snd_pcm_lib_buffer_bytes(substream
);
477 spin_lock_irq(&chip
->reg_lock
);
478 tmp
= snd_als300_gcr_read(chip
->port
, RECORD_CONTROL
);
479 tmp
&= ~TRANSFER_START
;
481 snd_als300_dbgplay("Period bytes: %d Buffer bytes %d\n", period_bytes
,
486 tmp
|= period_bytes
- 1;
489 snd_als300_gcr_write(chip
->port
, RECORD_CONTROL
, tmp
);
490 snd_als300_gcr_write(chip
->port
, RECORD_START
,
492 snd_als300_gcr_write(chip
->port
, RECORD_END
,
493 runtime
->dma_addr
+ buffer_bytes
- 1);
494 spin_unlock_irq(&chip
->reg_lock
);
498 static int snd_als300_trigger(struct snd_pcm_substream
*substream
, int cmd
)
500 struct snd_als300
*chip
= snd_pcm_substream_chip(substream
);
502 struct snd_als300_substream_data
*data
;
506 data
= substream
->runtime
->private_data
;
507 reg
= data
->control_register
;
509 spin_lock(&chip
->reg_lock
);
511 case SNDRV_PCM_TRIGGER_START
:
512 case SNDRV_PCM_TRIGGER_RESUME
:
513 tmp
= snd_als300_gcr_read(chip
->port
, reg
);
514 data
->period_flipflop
= 1;
515 snd_als300_gcr_write(chip
->port
, reg
, tmp
| TRANSFER_START
);
516 snd_als300_dbgplay("TRIGGER START\n");
518 case SNDRV_PCM_TRIGGER_STOP
:
519 case SNDRV_PCM_TRIGGER_SUSPEND
:
520 tmp
= snd_als300_gcr_read(chip
->port
, reg
);
521 snd_als300_gcr_write(chip
->port
, reg
, tmp
& ~TRANSFER_START
);
522 snd_als300_dbgplay("TRIGGER STOP\n");
524 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
525 tmp
= snd_als300_gcr_read(chip
->port
, reg
);
526 snd_als300_gcr_write(chip
->port
, reg
, tmp
| FIFO_PAUSE
);
527 snd_als300_dbgplay("TRIGGER PAUSE\n");
529 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
530 tmp
= snd_als300_gcr_read(chip
->port
, reg
);
531 snd_als300_gcr_write(chip
->port
, reg
, tmp
& ~FIFO_PAUSE
);
532 snd_als300_dbgplay("TRIGGER RELEASE\n");
535 snd_als300_dbgplay("TRIGGER INVALID\n");
538 spin_unlock(&chip
->reg_lock
);
542 static snd_pcm_uframes_t
snd_als300_pointer(struct snd_pcm_substream
*substream
)
545 struct snd_als300
*chip
= snd_pcm_substream_chip(substream
);
546 struct snd_als300_substream_data
*data
;
547 unsigned short period_bytes
;
549 data
= substream
->runtime
->private_data
;
550 period_bytes
= snd_pcm_lib_period_bytes(substream
);
552 spin_lock(&chip
->reg_lock
);
553 current_ptr
= (u16
) snd_als300_gcr_read(chip
->port
,
554 data
->block_counter_register
) + 4;
555 spin_unlock(&chip
->reg_lock
);
556 if (current_ptr
> period_bytes
)
559 current_ptr
= period_bytes
- current_ptr
;
561 if (data
->period_flipflop
== 0)
562 current_ptr
+= period_bytes
;
563 snd_als300_dbgplay("Pointer (bytes): %d\n", current_ptr
);
564 return bytes_to_frames(substream
->runtime
, current_ptr
);
567 static struct snd_pcm_ops snd_als300_playback_ops
= {
568 .open
= snd_als300_playback_open
,
569 .close
= snd_als300_playback_close
,
570 .ioctl
= snd_pcm_lib_ioctl
,
571 .hw_params
= snd_als300_pcm_hw_params
,
572 .hw_free
= snd_als300_pcm_hw_free
,
573 .prepare
= snd_als300_playback_prepare
,
574 .trigger
= snd_als300_trigger
,
575 .pointer
= snd_als300_pointer
,
578 static struct snd_pcm_ops snd_als300_capture_ops
= {
579 .open
= snd_als300_capture_open
,
580 .close
= snd_als300_capture_close
,
581 .ioctl
= snd_pcm_lib_ioctl
,
582 .hw_params
= snd_als300_pcm_hw_params
,
583 .hw_free
= snd_als300_pcm_hw_free
,
584 .prepare
= snd_als300_capture_prepare
,
585 .trigger
= snd_als300_trigger
,
586 .pointer
= snd_als300_pointer
,
589 static int snd_als300_new_pcm(struct snd_als300
*chip
)
594 err
= snd_pcm_new(chip
->card
, "ALS300", 0, 1, 1, &pcm
);
597 pcm
->private_data
= chip
;
598 strcpy(pcm
->name
, "ALS300");
602 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
,
603 &snd_als300_playback_ops
);
604 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
,
605 &snd_als300_capture_ops
);
607 /* pre-allocation of buffers */
608 snd_pcm_lib_preallocate_pages_for_all(pcm
, SNDRV_DMA_TYPE_DEV
,
609 snd_dma_pci_data(chip
->pci
), 64*1024, 64*1024);
613 static void snd_als300_init(struct snd_als300
*chip
)
618 spin_lock_irqsave(&chip
->reg_lock
, flags
);
619 chip
->revision
= (snd_als300_gcr_read(chip
->port
, MISC_CONTROL
) >> 16)
622 tmp
= snd_als300_gcr_read(chip
->port
, DRAM_WRITE_CONTROL
);
623 snd_als300_gcr_write(chip
->port
, DRAM_WRITE_CONTROL
,
625 & ~WRITE_TRANS_START
);
627 /* Enable IRQ output */
628 snd_als300_set_irq_flag(chip
, IRQ_ENABLE
);
630 /* Unmute hardware devices so their outputs get routed to
631 * the onboard mixer */
632 tmp
= snd_als300_gcr_read(chip
->port
, MISC_CONTROL
);
633 snd_als300_gcr_write(chip
->port
, MISC_CONTROL
,
634 tmp
| VMUTE_NORMAL
| MMUTE_NORMAL
);
637 snd_als300_gcr_write(chip
->port
, MUS_VOC_VOL
, 0);
639 /* Make sure playback transfer is stopped */
640 tmp
= snd_als300_gcr_read(chip
->port
, PLAYBACK_CONTROL
);
641 snd_als300_gcr_write(chip
->port
, PLAYBACK_CONTROL
,
642 tmp
& ~TRANSFER_START
);
643 spin_unlock_irqrestore(&chip
->reg_lock
, flags
);
646 static int snd_als300_create(struct snd_card
*card
,
647 struct pci_dev
*pci
, int chip_type
,
648 struct snd_als300
**rchip
)
650 struct snd_als300
*chip
;
654 static struct snd_device_ops ops
= {
655 .dev_free
= snd_als300_dev_free
,
659 if ((err
= pci_enable_device(pci
)) < 0)
662 if (pci_set_dma_mask(pci
, DMA_BIT_MASK(28)) < 0 ||
663 pci_set_consistent_dma_mask(pci
, DMA_BIT_MASK(28)) < 0) {
664 dev_err(card
->dev
, "error setting 28bit DMA mask\n");
665 pci_disable_device(pci
);
670 chip
= kzalloc(sizeof(*chip
), GFP_KERNEL
);
672 pci_disable_device(pci
);
679 chip
->chip_type
= chip_type
;
680 spin_lock_init(&chip
->reg_lock
);
682 if ((err
= pci_request_regions(pci
, "ALS300")) < 0) {
684 pci_disable_device(pci
);
687 chip
->port
= pci_resource_start(pci
, 0);
689 if (chip
->chip_type
== DEVICE_ALS300_PLUS
)
690 irq_handler
= snd_als300plus_interrupt
;
692 irq_handler
= snd_als300_interrupt
;
694 if (request_irq(pci
->irq
, irq_handler
, IRQF_SHARED
,
695 KBUILD_MODNAME
, chip
)) {
696 dev_err(card
->dev
, "unable to grab IRQ %d\n", pci
->irq
);
697 snd_als300_free(chip
);
700 chip
->irq
= pci
->irq
;
703 snd_als300_init(chip
);
705 err
= snd_als300_ac97(chip
);
707 dev_err(card
->dev
, "Could not create ac97\n");
708 snd_als300_free(chip
);
712 if ((err
= snd_als300_new_pcm(chip
)) < 0) {
713 dev_err(card
->dev
, "Could not create PCM\n");
714 snd_als300_free(chip
);
718 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
,
720 snd_als300_free(chip
);
728 #ifdef CONFIG_PM_SLEEP
729 static int snd_als300_suspend(struct device
*dev
)
731 struct pci_dev
*pci
= to_pci_dev(dev
);
732 struct snd_card
*card
= dev_get_drvdata(dev
);
733 struct snd_als300
*chip
= card
->private_data
;
735 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
736 snd_pcm_suspend_all(chip
->pcm
);
737 snd_ac97_suspend(chip
->ac97
);
739 pci_disable_device(pci
);
741 pci_set_power_state(pci
, PCI_D3hot
);
745 static int snd_als300_resume(struct device
*dev
)
747 struct pci_dev
*pci
= to_pci_dev(dev
);
748 struct snd_card
*card
= dev_get_drvdata(dev
);
749 struct snd_als300
*chip
= card
->private_data
;
751 pci_set_power_state(pci
, PCI_D0
);
752 pci_restore_state(pci
);
753 if (pci_enable_device(pci
) < 0) {
754 dev_err(dev
, "pci_enable_device failed, disabling device\n");
755 snd_card_disconnect(card
);
760 snd_als300_init(chip
);
761 snd_ac97_resume(chip
->ac97
);
763 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
767 static SIMPLE_DEV_PM_OPS(snd_als300_pm
, snd_als300_suspend
, snd_als300_resume
);
768 #define SND_ALS300_PM_OPS &snd_als300_pm
770 #define SND_ALS300_PM_OPS NULL
773 static int snd_als300_probe(struct pci_dev
*pci
,
774 const struct pci_device_id
*pci_id
)
777 struct snd_card
*card
;
778 struct snd_als300
*chip
;
781 if (dev
>= SNDRV_CARDS
)
788 err
= snd_card_new(&pci
->dev
, index
[dev
], id
[dev
], THIS_MODULE
,
794 chip_type
= pci_id
->driver_data
;
796 if ((err
= snd_als300_create(card
, pci
, chip_type
, &chip
)) < 0) {
800 card
->private_data
= chip
;
802 strcpy(card
->driver
, "ALS300");
803 if (chip
->chip_type
== DEVICE_ALS300_PLUS
)
804 /* don't know much about ALS300+ yet
805 * print revision number for now */
806 sprintf(card
->shortname
, "ALS300+ (Rev. %d)", chip
->revision
);
808 sprintf(card
->shortname
, "ALS300 (Rev. %c)", 'A' +
810 sprintf(card
->longname
, "%s at 0x%lx irq %i",
811 card
->shortname
, chip
->port
, chip
->irq
);
813 if ((err
= snd_card_register(card
)) < 0) {
817 pci_set_drvdata(pci
, card
);
822 static struct pci_driver als300_driver
= {
823 .name
= KBUILD_MODNAME
,
824 .id_table
= snd_als300_ids
,
825 .probe
= snd_als300_probe
,
826 .remove
= snd_als300_remove
,
828 .pm
= SND_ALS300_PM_OPS
,
832 module_pci_driver(als300_driver
);