35 #include <linux/module.h>
36 #include <linux/pci.h>
39 #include <linux/slab.h>
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
62 #define IRQ_PLAYBACK (1<<3)
63 #define IRQ_CAPTURE (1<<2)
65 #define GCR_INDEX 0x0C
66 #define ALS300P_DRAM_IRQ_STATUS 0x0D
67 #define MPU_IRQ_STATUS 0x0E
68 #define ALS300P_IRQ_STATUS 0x0F
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
91 #define DEBUG_PLAY_REC 0
94 #define snd_als300_dbgcalls(format, args...) printk(KERN_DEBUG format, ##args)
95 #define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__)
96 #define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__)
98 #define snd_als300_dbgcalls(format, args...)
99 #define snd_als300_dbgcallenter()
100 #define snd_als300_dbgcallleave()
104 #define snd_als300_dbgplay(format, args...) printk(KERN_ERR format, ##args)
106 #define snd_als300_dbgplay(format, args...)
163 static inline u32 snd_als300_gcr_read(
unsigned long port,
unsigned short reg)
169 static inline void snd_als300_gcr_write(
unsigned long port,
194 static int snd_als300_free(
struct snd_als300 *chip)
210 return snd_als300_free(chip);
244 static irqreturn_t snd_als300plus_interrupt(
int irq,
void *dev_id)
246 u8 general, mpu, dram;
255 if ((general == 0) && ((mpu & 0x80) == 0) && ((dram & 0x01) == 0))
258 if (general & IRQ_PLAYBACK) {
267 if (general & IRQ_CAPTURE) {
285 pci_set_drvdata(pci,
NULL);
289 static unsigned short snd_als300_ac97_read(
struct snd_ac97 *ac97,
295 for (i = 0; i < 1000; i++) {
302 for (i = 0; i < 1000; i++) {
310 static void snd_als300_ac97_write(
struct snd_ac97 *ac97,
311 unsigned short reg,
unsigned short val)
316 for (i = 0; i < 1000; i++) {
324 static int snd_als300_ac97(
struct snd_als300 *chip)
330 .write = snd_als300_ac97_write,
331 .read = snd_als300_ac97_read,
338 memset(&ac97, 0,
sizeof(ac97));
358 .
formats = SNDRV_PCM_FMTBIT_S16,
377 .
formats = SNDRV_PCM_FMTBIT_S16,
401 runtime->
hw = snd_als300_playback_hw;
414 data = substream->
runtime->private_data;
434 runtime->
hw = snd_als300_capture_hw;
447 data = substream->
runtime->private_data;
473 unsigned short period_bytes = snd_pcm_lib_period_bytes(substream);
474 unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
482 period_bytes, buffer_bytes);
486 tmp |= period_bytes - 1;
493 runtime->
dma_addr + buffer_bytes - 1);
504 unsigned short period_bytes = snd_pcm_lib_period_bytes(substream);
505 unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
517 tmp |= period_bytes - 1;
524 runtime->
dma_addr + buffer_bytes - 1);
538 data = substream->
runtime->private_data;
546 tmp = snd_als300_gcr_read(chip->
port, reg);
553 tmp = snd_als300_gcr_read(chip->
port, reg);
558 tmp = snd_als300_gcr_read(chip->
port, reg);
563 tmp = snd_als300_gcr_read(chip->
port, reg);
581 unsigned short period_bytes;
583 data = substream->
runtime->private_data;
584 period_bytes = snd_pcm_lib_period_bytes(substream);
588 current_ptr = (
u16) snd_als300_gcr_read(chip->
port,
591 if (current_ptr > period_bytes)
594 current_ptr = period_bytes - current_ptr;
597 current_ptr += period_bytes;
600 return bytes_to_frames(substream->
runtime, current_ptr);
603 static struct snd_pcm_ops snd_als300_playback_ops = {
604 .open = snd_als300_playback_open,
605 .close = snd_als300_playback_close,
607 .hw_params = snd_als300_pcm_hw_params,
608 .hw_free = snd_als300_pcm_hw_free,
609 .prepare = snd_als300_playback_prepare,
610 .trigger = snd_als300_trigger,
611 .pointer = snd_als300_pointer,
614 static struct snd_pcm_ops snd_als300_capture_ops = {
615 .open = snd_als300_capture_open,
616 .close = snd_als300_capture_close,
618 .hw_params = snd_als300_pcm_hw_params,
619 .hw_free = snd_als300_pcm_hw_free,
620 .prepare = snd_als300_capture_prepare,
621 .trigger = snd_als300_trigger,
622 .pointer = snd_als300_pointer,
640 &snd_als300_playback_ops);
642 &snd_als300_capture_ops);
651 static void snd_als300_init(
struct snd_als300 *chip)
682 spin_unlock_irqrestore(&chip->
reg_lock, flags);
695 .dev_free = snd_als300_dev_free,
704 pci_set_consistent_dma_mask(pci,
DMA_BIT_MASK(28)) < 0) {
731 irq_handler = snd_als300plus_interrupt;
733 irq_handler = snd_als300_interrupt;
736 KBUILD_MODNAME, chip)) {
738 snd_als300_free(chip);
744 snd_als300_init(chip);
746 err = snd_als300_ac97(chip);
749 snd_als300_free(chip);
753 if ((err = snd_als300_new_pcm(chip)) < 0) {
755 snd_als300_free(chip);
761 snd_als300_free(chip);
772 #ifdef CONFIG_PM_SLEEP
773 static int snd_als300_suspend(
struct device *
dev)
780 snd_pcm_suspend_all(chip->
pcm);
781 snd_ac97_suspend(chip->
ac97);
789 static int snd_als300_resume(
struct device *
dev)
799 "disabling device\n");
805 snd_als300_init(chip);
806 snd_ac97_resume(chip->
ac97);
813 #define SND_ALS300_PM_OPS &snd_als300_pm
815 #define SND_ALS300_PM_OPS NULL
840 if ((err = snd_als300_create(card, pci, chip_type, &chip)) < 0) {
861 pci_set_drvdata(pci, card);
867 .name = KBUILD_MODNAME,
868 .id_table = snd_als300_ids,
869 .probe = snd_als300_probe,