70 #include <linux/pci.h>
71 #include <linux/gameport.h>
72 #include <linux/module.h>
87 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
88 #define SUPPORT_JOYSTICK 1
94 #ifdef SUPPORT_JOYSTICK
104 #ifdef SUPPORT_JOYSTICK
106 MODULE_PARM_DESC(joystick_port,
"Joystick port address for ALS4000 soundcard. (0 = disabled)");
114 #ifdef SUPPORT_JOYSTICK
191 static inline void snd_als4k_iobase_writeb(
unsigned long iobase,
195 outb(val, iobase + reg);
198 static inline void snd_als4k_iobase_writel(
unsigned long iobase,
202 outl(val, iobase + reg);
205 static inline u8 snd_als4k_iobase_readb(
unsigned long iobase,
208 return inb(iobase + reg);
211 static inline u32 snd_als4k_iobase_readl(
unsigned long iobase,
214 return inl(iobase + reg);
217 static inline void snd_als4k_gcr_write_addr(
unsigned long iobase,
225 static inline void snd_als4k_gcr_write(
struct snd_sb *
sb,
229 snd_als4k_gcr_write_addr(sb->
alt_port, reg, val);
232 static inline u32 snd_als4k_gcr_read_addr(
unsigned long iobase,
242 return snd_als4k_gcr_read_addr(sb->
alt_port, reg);
269 static inline void snd_als4_cr_write(
struct snd_sb *
chip,
288 static void snd_als4000_set_rate(
struct snd_sb *
chip,
unsigned int rate)
297 static inline void snd_als4000_set_capture_dma(
struct snd_sb *chip,
305 static inline void snd_als4000_set_playback_dma(
struct snd_sb *chip,
315 #define ALS4000_FORMAT_SIGNED (1<<0)
316 #define ALS4000_FORMAT_16BIT (1<<1)
317 #define ALS4000_FORMAT_STEREO (1<<2)
334 static const struct {
336 } playback_cmd_vals[]={
354 #define playback_cmd(chip) (playback_cmd_vals[(chip)->playback_format])
358 static const unsigned char capture_cmd_vals[]=
369 #define capture_cmd(chip) (capture_cmd_vals[(chip)->capture_format])
392 size = snd_pcm_lib_buffer_bytes(substream);
393 count = snd_pcm_lib_period_bytes(substream);
400 snd_als4000_set_rate(chip, runtime->
rate);
401 snd_als4000_set_capture_dma(chip, runtime->
dma_addr, size);
419 size = snd_pcm_lib_buffer_bytes(substream);
420 count = snd_pcm_lib_period_bytes(substream);
433 snd_als4000_set_rate(chip, runtime->
rate);
434 snd_als4000_set_playback_dma(chip, runtime->
dma_addr, size);
481 static int snd_als4000_playback_trigger(
struct snd_pcm_substream *substream,
int cmd)
515 return bytes_to_frames( substream->
runtime, result );
527 return bytes_to_frames( substream->
runtime, result );
546 unsigned pci_irqstatus;
547 unsigned sb_irqstatus;
551 pci_irqstatus = snd_als4k_iobase_readb(chip->
alt_port,
563 snd_als4k_iobase_writeb(chip->
alt_port,
572 snd_sb_ack_8bit(chip);
574 snd_sb_ack_16bit(chip);
578 snd_als4k_iobase_readb(chip->
alt_port,
586 (pci_irqstatus & (ALS4K_IOB_0E_SB_DMA_IRQ|ALS4K_IOB_0E_CR1E_IRQ|
587 ALS4K_IOB_0E_MPU_IRQ))
588 || (sb_irqstatus & (SB_IRQTYPE_8BIT|SB_IRQTYPE_16BIT|
589 SB_IRQTYPE_MPUIN|ALS4K_IRQTYPE_CR1E_DMA))
641 runtime->
hw = snd_als4000_playback;
660 runtime->
hw = snd_als4000_capture;
675 static struct snd_pcm_ops snd_als4000_playback_ops = {
676 .open = snd_als4000_playback_open,
677 .close = snd_als4000_playback_close,
679 .hw_params = snd_als4000_hw_params,
680 .hw_free = snd_als4000_hw_free,
681 .prepare = snd_als4000_playback_prepare,
682 .trigger = snd_als4000_playback_trigger,
683 .pointer = snd_als4000_playback_pointer
686 static struct snd_pcm_ops snd_als4000_capture_ops = {
687 .open = snd_als4000_capture_open,
688 .close = snd_als4000_capture_close,
690 .hw_params = snd_als4000_hw_params,
691 .hw_free = snd_als4000_hw_free,
692 .prepare = snd_als4000_capture_prepare,
693 .trigger = snd_als4000_capture_trigger,
694 .pointer = snd_als4000_capture_pointer
720 static void snd_als4000_set_addr(
unsigned long iobase,
724 unsigned int game_io)
730 cfg2 |= (mpu_io | 1) << 16;
734 cfg1 |= (game_io | 1) << 16;
736 cfg1 |= (opl_io | 1);
741 static void snd_als4000_configure(
struct snd_sb *chip)
765 snd_als4k_gcr_write(chip, i, 0);
772 #ifdef SUPPORT_JOYSTICK
779 if (joystick_port[dev] == 0)
782 if (joystick_port[dev] == 1) {
783 for (io_port = 0x200; io_port <= 0x218; io_port += 8) {
789 io_port = joystick_port[
dev];
798 acard->gameport = gp = gameport_allocate_port();
800 printk(
KERN_ERR "als4000: cannot allocate memory for gameport\n");
805 gameport_set_name(gp,
"ALS4000 Gameport");
807 gameport_set_dev_parent(gp, &acard->
pci->dev);
809 gameport_set_port_data(gp, r);
812 snd_als4000_set_addr(acard->
iobase, 0, 0, 0, 1);
814 gameport_register_port(acard->gameport);
821 if (acard->gameport) {
822 struct resource *r = gameport_get_port_data(acard->gameport);
825 acard->gameport =
NULL;
828 snd_als4000_set_addr(acard->
iobase, 0, 0, 0, 0);
834 static inline int snd_als4000_create_gameport(
struct snd_card_als4000 *acard,
int dev) {
return -
ENOSYS; }
835 static inline void snd_als4000_free_gameport(
struct snd_card_als4000 *acard) { }
838 static void snd_card_als4000_free(
struct snd_card *
card )
845 snd_als4000_free_gameport(acard);
875 pci_set_consistent_dma_mask(pci,
DMA_BIT_MASK(24)) < 0) {
906 snd_als4000_set_addr(acard->
iobase, 0, 0, 0, 0);
912 snd_als4000_interrupt,
925 snd_als4000_configure(chip);
936 -1, &chip->
rmidi)) < 0) {
947 if ((err = snd_als4000_pcm(chip, 0)) < 0) {
967 snd_als4000_create_gameport(acard, dev);
972 pci_set_drvdata(pci, card);
987 pci_set_drvdata(pci,
NULL);
990 #ifdef CONFIG_PM_SLEEP
991 static int snd_als4000_suspend(
struct device *dev)
1000 snd_pcm_suspend_all(chip->
pcm);
1001 snd_sbmixer_suspend(chip);
1009 static int snd_als4000_resume(
struct device *dev)
1020 "disabling device\n");
1026 snd_als4000_configure(chip);
1028 snd_sbmixer_resume(chip);
1030 #ifdef SUPPORT_JOYSTICK
1031 if (acard->gameport)
1032 snd_als4000_set_addr(acard->
iobase, 0, 0, 0, 1);
1039 static SIMPLE_DEV_PM_OPS(snd_als4000_pm, snd_als4000_suspend, snd_als4000_resume);
1040 #define SND_ALS4000_PM_OPS &snd_als4000_pm
1042 #define SND_ALS4000_PM_OPS NULL
1046 .name = KBUILD_MODNAME,
1047 .id_table = snd_als4000_ids,
1048 .probe = snd_card_als4000_probe,