X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Fvia82xx.c;h=39daf62d2bad55a4ba376ce9c300bff7e2a838cd;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=4f4c2cb69ff1b7626d3f8a120f59d9f043ed78bc;hpb=5273a3df6485dc2ad6aa7ddd441b9a21970f003b;p=linux-2.6.git diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c index 4f4c2cb69..39daf62d2 100644 --- a/sound/pci/via82xx.c +++ b/sound/pci/via82xx.c @@ -41,6 +41,9 @@ * device for applications. * - clean up the code, separate low-level initialization * routines for each chipset. + * + * Sep. 26, 2005 Karsten Wiese + * - Optimize position calculation for the 823x chips. */ #include @@ -51,13 +54,13 @@ #include #include #include +#include #include #include #include #include #include #include -#define SNDRV_GET_ID #include #if 0 @@ -67,59 +70,43 @@ MODULE_AUTHOR("Jaroslav Kysela "); MODULE_DESCRIPTION("VIA VT82xx audio"); MODULE_LICENSE("GPL"); -MODULE_CLASSES("{sound}"); -MODULE_DEVICES("{{VIA,VT82C686A/B/C,pci},{VIA,VT8233A/C,8235}}"); +MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C,pci},{VIA,VT8233A/C,8235}}"); #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) #define SUPPORT_JOYSTICK 1 #endif -static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ -static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ -static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ -static long mpu_port[SNDRV_CARDS]; +static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ +static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ +static long mpu_port; #ifdef SUPPORT_JOYSTICK -static int joystick[SNDRV_CARDS]; +static int joystick; #endif -static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 48000}; -static int ac97_quirk[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = AC97_TUNE_DEFAULT}; -static int dxs_support[SNDRV_CARDS]; +static int ac97_clock = 48000; +static char *ac97_quirk; +static int dxs_support; -MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param(index, int, 0444); MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge."); -MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC); -MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s"); +module_param(id, charp, 0444); MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge."); -MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC); -MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); -MODULE_PARM_DESC(enable, "Enable audio part of VIA 82xx bridge."); -MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC); -MODULE_PARM(mpu_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l"); +module_param(mpu_port, long, 0444); MODULE_PARM_DESC(mpu_port, "MPU-401 port. (VT82C686x only)"); -MODULE_PARM_SYNTAX(mpu_port, SNDRV_PORT_DESC); #ifdef SUPPORT_JOYSTICK -MODULE_PARM(joystick, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param(joystick, bool, 0444); MODULE_PARM_DESC(joystick, "Enable joystick. (VT82C686x only)"); -MODULE_PARM_SYNTAX(joystick, SNDRV_ENABLE_DESC "," SNDRV_BOOLEAN_FALSE_DESC); #endif -MODULE_PARM(ac97_clock, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param(ac97_clock, int, 0444); MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz)."); -MODULE_PARM_SYNTAX(ac97_clock, SNDRV_ENABLED ",default:48000"); -MODULE_PARM(ac97_quirk, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); +module_param(ac97_quirk, charp, 0444); MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); -MODULE_PARM_SYNTAX(ac97_quirk, SNDRV_ENABLED ",allows:{{-1,4}},dialog:list,default:-1"); -MODULE_PARM(dxs_support, "1-" __MODULE_STRING(SNDRV_CARDS) "i"); -MODULE_PARM_DESC(dxs_support, "Support for DXS channels (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 = no VRA)"); -MODULE_PARM_SYNTAX(dxs_support, SNDRV_ENABLED ",allows:{{0,4}},dialog:list"); +module_param(dxs_support, int, 0444); +MODULE_PARM_DESC(dxs_support, "Support for DXS channels (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 = no VRA, 5 = enable any sample rate)"); +/* just for backward compatibility */ +static int enable; +module_param(enable, bool, 0444); -/* pci ids */ -#ifndef PCI_DEVICE_ID_VIA_82C686_5 -#define PCI_DEVICE_ID_VIA_82C686_5 0x3058 -#endif -#ifndef PCI_DEVICE_ID_VIA_8233_5 -#define PCI_DEVICE_ID_VIA_8233_5 0x3059 -#endif /* revision numbers for via686 */ #define VIA_REV_686_A 0x10 @@ -135,6 +122,8 @@ MODULE_PARM_SYNTAX(dxs_support, SNDRV_ENABLED ",allows:{{0,4}},dialog:list"); #define VIA_REV_8233 0x30 /* 2 rec, 4 pb, 1 multi-pb, spdif */ #define VIA_REV_8233A 0x40 /* 1 rec, 1 multi-pb, spdf */ #define VIA_REV_8235 0x50 /* 2 rec, 4 pb, 1 multi-pb, spdif */ +#define VIA_REV_8237 0x60 +#define VIA_REV_8251 0x70 /* * Direct registers @@ -146,6 +135,7 @@ MODULE_PARM_SYNTAX(dxs_support, SNDRV_ENABLED ",allows:{{0,4}},dialog:list"); /* common offsets */ #define VIA_REG_OFFSET_STATUS 0x00 /* byte - channel status */ #define VIA_REG_STAT_ACTIVE 0x80 /* RO */ +#define VIA8233_SHADOW_STAT_ACTIVE 0x08 /* RO */ #define VIA_REG_STAT_PAUSED 0x40 /* RO */ #define VIA_REG_STAT_TRIGGER_QUEUED 0x08 /* RO */ #define VIA_REG_STAT_STOPPED 0x04 /* RWC */ @@ -310,15 +300,9 @@ DEFINE_VIA_REGSET(CAPTURE_8233, 0x60); #define VIA_DXS_DISABLE 2 #define VIA_DXS_48K 3 #define VIA_DXS_NO_VRA 4 +#define VIA_DXS_SRC 5 -/* - */ - -typedef struct _snd_via82xx via82xx_t; -typedef struct via_dev viadev_t; -#define chip_t via82xx_t - /* * pcm stream */ @@ -330,19 +314,23 @@ struct snd_via_sg_table { #define VIA_TABLE_SIZE 255 -struct via_dev { +struct viadev { unsigned int reg_offset; unsigned long port; int direction; /* playback = 0, capture = 1 */ - snd_pcm_substream_t *substream; + struct snd_pcm_substream *substream; int running; unsigned int tbl_entries; /* # descriptors */ struct snd_dma_buffer table; struct snd_via_sg_table *idx_table; /* for recovery from the unexpected pointer */ unsigned int lastpos; + unsigned int fragsize; unsigned int bufsize; unsigned int bufsize2; + int hwptr_done; /* processed frame position in the buffer */ + int in_interrupt; + int shadow_shift; }; @@ -357,55 +345,62 @@ struct via_rate_lock { int used; }; -struct _snd_via82xx { +struct via82xx { int irq; unsigned long port; - struct resource *res_port; struct resource *mpu_res; int chip_type; unsigned char revision; unsigned char old_legacy; unsigned char old_legacy_cfg; +#ifdef CONFIG_PM + unsigned char legacy_saved; + unsigned char legacy_cfg_saved; + unsigned char spdif_ctrl_saved; + unsigned char capture_src_saved[2]; + unsigned int mpu_port_saved; +#endif unsigned char playback_volume[4][2]; /* for VIA8233/C/8235; default = 0 */ + unsigned char playback_volume_c[2]; /* for VIA8233/C/8235; default = 0 */ unsigned int intr_mask; /* SGD_SHADOW mask to check interrupts */ struct pci_dev *pci; - snd_card_t *card; + struct snd_card *card; unsigned int num_devs; unsigned int playback_devno, multi_devno, capture_devno; - viadev_t devs[VIA_MAX_DEVS]; + struct viadev devs[VIA_MAX_DEVS]; struct via_rate_lock rates[2]; /* playback and capture */ unsigned int dxs_fixed: 1; /* DXS channel accepts only 48kHz */ unsigned int no_vra: 1; /* no need to set VRA on DXS channels */ + unsigned int dxs_src: 1; /* use full SRC capabilities of DXS */ unsigned int spdif_on: 1; /* only spdif rates work to external DACs */ - snd_rawmidi_t *rmidi; + struct snd_pcm *pcms[2]; + struct snd_rawmidi *rmidi; - ac97_bus_t *ac97_bus; - ac97_t *ac97; + struct snd_ac97_bus *ac97_bus; + struct snd_ac97 *ac97; unsigned int ac97_clock; unsigned int ac97_secondary; /* secondary AC'97 codec is present */ spinlock_t reg_lock; - spinlock_t ac97_lock; - snd_info_entry_t *proc_entry; - - struct snd_dma_device dma_dev; + struct snd_info_entry *proc_entry; #ifdef SUPPORT_JOYSTICK - struct gameport gameport; - struct resource *res_joystick; + struct gameport *gameport; #endif }; -static struct pci_device_id snd_via82xx_ids[] = { - { 0x1106, 0x3058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, }, /* 686A */ - { 0x1106, 0x3059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, }, /* VT8233 */ +static struct pci_device_id snd_via82xx_ids[] __devinitdata = { + /* 0x1106, 0x3058 */ + { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, }, /* 686A */ + /* 0x1106, 0x3059 */ + { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, }, /* VT8233 */ { 0, } }; @@ -419,19 +414,21 @@ MODULE_DEVICE_TABLE(pci, snd_via82xx_ids); * periods = number of periods * fragsize = period size in bytes */ -static int build_via_table(viadev_t *dev, snd_pcm_substream_t *substream, +static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substream, struct pci_dev *pci, unsigned int periods, unsigned int fragsize) { unsigned int i, idx, ofs, rest; - via82xx_t *chip = snd_pcm_substream_chip(substream); + struct via82xx *chip = snd_pcm_substream_chip(substream); struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream); if (dev->table.area == NULL) { /* the start of each lists must be aligned to 8 bytes, * but the kernel pages are much bigger, so we don't care */ - if (snd_dma_alloc_pages(&chip->dma_dev, PAGE_ALIGN(VIA_TABLE_SIZE * 2 * 8), &dev->table) < 0) + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), + PAGE_ALIGN(VIA_TABLE_SIZE * 2 * 8), + &dev->table) < 0) return -ENOMEM; } if (! dev->idx_table) { @@ -480,22 +477,20 @@ static int build_via_table(viadev_t *dev, snd_pcm_substream_t *substream, dev->tbl_entries = idx; dev->bufsize = periods * fragsize; dev->bufsize2 = dev->bufsize / 2; + dev->fragsize = fragsize; return 0; } -static int clean_via_table(viadev_t *dev, snd_pcm_substream_t *substream, +static int clean_via_table(struct viadev *dev, struct snd_pcm_substream *substream, struct pci_dev *pci) { - via82xx_t *chip = snd_pcm_substream_chip(substream); if (dev->table.area) { - snd_dma_free_pages(&chip->dma_dev, &dev->table); + snd_dma_free_pages(&dev->table); dev->table.area = NULL; } - if (dev->idx_table) { - kfree(dev->idx_table); - dev->idx_table = NULL; - } + kfree(dev->idx_table); + dev->idx_table = NULL; return 0; } @@ -503,17 +498,17 @@ static int clean_via_table(viadev_t *dev, snd_pcm_substream_t *substream, * Basic I/O */ -static inline unsigned int snd_via82xx_codec_xread(via82xx_t *chip) +static inline unsigned int snd_via82xx_codec_xread(struct via82xx *chip) { return inl(VIAREG(chip, AC97)); } -static inline void snd_via82xx_codec_xwrite(via82xx_t *chip, unsigned int val) +static inline void snd_via82xx_codec_xwrite(struct via82xx *chip, unsigned int val) { outl(val, VIAREG(chip, AC97)); } -static int snd_via82xx_codec_ready(via82xx_t *chip, int secondary) +static int snd_via82xx_codec_ready(struct via82xx *chip, int secondary) { unsigned int timeout = 1000; /* 1ms */ unsigned int val; @@ -523,11 +518,12 @@ static int snd_via82xx_codec_ready(via82xx_t *chip, int secondary) if (!((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)) return val & 0xffff; } - snd_printk(KERN_ERR "codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_via82xx_codec_xread(chip)); + snd_printk(KERN_ERR "codec_ready: codec %i is not ready [0x%x]\n", + secondary, snd_via82xx_codec_xread(chip)); return -EIO; } -static int snd_via82xx_codec_valid(via82xx_t *chip, int secondary) +static int snd_via82xx_codec_valid(struct via82xx *chip, int secondary) { unsigned int timeout = 1000; /* 1ms */ unsigned int val, val1; @@ -544,36 +540,33 @@ static int snd_via82xx_codec_valid(via82xx_t *chip, int secondary) return -EIO; } -static void snd_via82xx_codec_wait(ac97_t *ac97) +static void snd_via82xx_codec_wait(struct snd_ac97 *ac97) { - via82xx_t *chip = snd_magic_cast(via82xx_t, ac97->private_data, return); + struct via82xx *chip = ac97->private_data; int err; err = snd_via82xx_codec_ready(chip, ac97->num); /* here we need to wait fairly for long time.. */ - set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(HZ/2); + msleep(500); } -static void snd_via82xx_codec_write(ac97_t *ac97, +static void snd_via82xx_codec_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val) { - via82xx_t *chip = snd_magic_cast(via82xx_t, ac97->private_data, return); + struct via82xx *chip = ac97->private_data; unsigned int xval; - + xval = !ac97->num ? VIA_REG_AC97_CODEC_ID_PRIMARY : VIA_REG_AC97_CODEC_ID_SECONDARY; xval <<= VIA_REG_AC97_CODEC_ID_SHIFT; xval |= reg << VIA_REG_AC97_CMD_SHIFT; xval |= val << VIA_REG_AC97_DATA_SHIFT; - spin_lock(&chip->ac97_lock); snd_via82xx_codec_xwrite(chip, xval); snd_via82xx_codec_ready(chip, ac97->num); - spin_unlock(&chip->ac97_lock); } -static unsigned short snd_via82xx_codec_read(ac97_t *ac97, unsigned short reg) +static unsigned short snd_via82xx_codec_read(struct snd_ac97 *ac97, unsigned short reg) { - via82xx_t *chip = snd_magic_cast(via82xx_t, ac97->private_data, return ~0); + struct via82xx *chip = ac97->private_data; unsigned int xval, val = 0xffff; int again = 0; @@ -581,11 +574,10 @@ static unsigned short snd_via82xx_codec_read(ac97_t *ac97, unsigned short reg) xval |= ac97->num ? VIA_REG_AC97_SECONDARY_VALID : VIA_REG_AC97_PRIMARY_VALID; xval |= VIA_REG_AC97_READ; xval |= (reg & 0x7f) << VIA_REG_AC97_CMD_SHIFT; - spin_lock(&chip->ac97_lock); while (1) { if (again++ > 3) { - spin_unlock(&chip->ac97_lock); - snd_printk(KERN_ERR "codec_read: codec %i is not valid [0x%x]\n", ac97->num, snd_via82xx_codec_xread(chip)); + snd_printk(KERN_ERR "codec_read: codec %i is not valid [0x%x]\n", + ac97->num, snd_via82xx_codec_xread(chip)); return 0xffff; } snd_via82xx_codec_xwrite(chip, xval); @@ -596,11 +588,10 @@ static unsigned short snd_via82xx_codec_read(ac97_t *ac97, unsigned short reg) break; } } - spin_unlock(&chip->ac97_lock); return val & 0xffff; } -static void snd_via82xx_channel_reset(via82xx_t *chip, viadev_t *viadev) +static void snd_via82xx_channel_reset(struct via82xx *chip, struct viadev *viadev) { outb(VIA_REG_CTRL_PAUSE | VIA_REG_CTRL_TERMINATE | VIA_REG_CTRL_RESET, VIADEV_REG(viadev, OFFSET_CONTROL)); @@ -613,46 +604,50 @@ static void snd_via82xx_channel_reset(via82xx_t *chip, viadev_t *viadev) outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */ // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); viadev->lastpos = 0; + viadev->hwptr_done = 0; } /* * Interrupt handler + * Used for 686 and 8233A */ - -static irqreturn_t snd_via82xx_interrupt(int irq, void *dev_id, struct pt_regs *regs) +static irqreturn_t snd_via686_interrupt(int irq, void *dev_id, struct pt_regs *regs) { - via82xx_t *chip = snd_magic_cast(via82xx_t, dev_id, return IRQ_NONE); + struct via82xx *chip = dev_id; unsigned int status; unsigned int i; - spin_lock(&chip->reg_lock); -#if 0 - /* FIXME: does it work on via823x? */ - if (chip->chip_type != TYPE_VIA686) - goto _skip_sgd; -#endif status = inl(VIAREG(chip, SGD_SHADOW)); if (! (status & chip->intr_mask)) { - spin_unlock(&chip->reg_lock); if (chip->rmidi) /* check mpu401 interrupt */ return snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs); return IRQ_NONE; } -// _skip_sgd: /* check status for each stream */ + spin_lock(&chip->reg_lock); for (i = 0; i < chip->num_devs; i++) { - viadev_t *viadev = &chip->devs[i]; + struct viadev *viadev = &chip->devs[i]; unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS)); - c_status &= (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED); - if (! c_status) + if (! (c_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED))) continue; if (viadev->substream && viadev->running) { + /* + * Update hwptr_done based on 'period elapsed' + * interrupts. We'll use it, when the chip returns 0 + * for OFFSET_CURR_COUNT. + */ + if (c_status & VIA_REG_STAT_EOL) + viadev->hwptr_done = 0; + else + viadev->hwptr_done += viadev->fragsize; + viadev->in_interrupt = c_status; spin_unlock(&chip->reg_lock); snd_pcm_period_elapsed(viadev->substream); spin_lock(&chip->reg_lock); + viadev->in_interrupt = 0; } outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */ } @@ -660,6 +655,60 @@ static irqreturn_t snd_via82xx_interrupt(int irq, void *dev_id, struct pt_regs * return IRQ_HANDLED; } +/* + * Interrupt handler + */ +static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id, struct pt_regs *regs) +{ + struct via82xx *chip = dev_id; + unsigned int status; + unsigned int i; + int irqreturn = 0; + + /* check status for each stream */ + spin_lock(&chip->reg_lock); + status = inl(VIAREG(chip, SGD_SHADOW)); + + for (i = 0; i < chip->num_devs; i++) { + struct viadev *viadev = &chip->devs[i]; + struct snd_pcm_substream *substream; + unsigned char c_status, shadow_status; + + shadow_status = (status >> viadev->shadow_shift) & + (VIA8233_SHADOW_STAT_ACTIVE|VIA_REG_STAT_EOL| + VIA_REG_STAT_FLAG); + c_status = shadow_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG); + if (!c_status) + continue; + + substream = viadev->substream; + if (substream && viadev->running) { + /* + * Update hwptr_done based on 'period elapsed' + * interrupts. We'll use it, when the chip returns 0 + * for OFFSET_CURR_COUNT. + */ + if (c_status & VIA_REG_STAT_EOL) + viadev->hwptr_done = 0; + else + viadev->hwptr_done += viadev->fragsize; + viadev->in_interrupt = c_status; + if (shadow_status & VIA8233_SHADOW_STAT_ACTIVE) + viadev->in_interrupt |= VIA_REG_STAT_ACTIVE; + spin_unlock(&chip->reg_lock); + + snd_pcm_period_elapsed(substream); + + spin_lock(&chip->reg_lock); + viadev->in_interrupt = 0; + } + outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */ + irqreturn = 1; + } + spin_unlock(&chip->reg_lock); + return IRQ_RETVAL(irqreturn); +} + /* * PCM callbacks */ @@ -667,10 +716,10 @@ static irqreturn_t snd_via82xx_interrupt(int irq, void *dev_id, struct pt_regs * /* * trigger callback */ -static int snd_via82xx_pcm_trigger(snd_pcm_substream_t * substream, int cmd) +static int snd_via82xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = (viadev_t *)substream->runtime->private_data; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = substream->runtime->private_data; unsigned char val; if (chip->chip_type != TYPE_VIA686) @@ -679,10 +728,12 @@ static int snd_via82xx_pcm_trigger(snd_pcm_substream_t * substream, int cmd) val = 0; switch (cmd) { case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: val |= VIA_REG_CTRL_START; viadev->running = 1; break; case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_SUSPEND: val = VIA_REG_CTRL_TERMINATE; viadev->running = 0; break; @@ -710,43 +761,67 @@ static int snd_via82xx_pcm_trigger(snd_pcm_substream_t * substream, int cmd) /* * calculate the linear position at the given sg-buffer index and the rest count */ -static inline unsigned int calc_linear_pos(viadev_t *viadev, unsigned int idx, unsigned int count) + +#define check_invalid_pos(viadev,pos) \ + ((pos) < viadev->lastpos && ((pos) >= viadev->bufsize2 ||\ + viadev->lastpos < viadev->bufsize2)) + +static inline unsigned int calc_linear_pos(struct viadev *viadev, unsigned int idx, + unsigned int count) { - unsigned int size, res; + unsigned int size, base, res; size = viadev->idx_table[idx].size; - res = viadev->idx_table[idx].offset + size - count; + base = viadev->idx_table[idx].offset; + res = base + size - count; + if (res >= viadev->bufsize) + res -= viadev->bufsize; /* check the validity of the calculated position */ - if (size < count || (res < viadev->lastpos && (res >= viadev->bufsize2 || viadev->lastpos < viadev->bufsize2))) { + if (size < count) { + snd_printd(KERN_ERR "invalid via82xx_cur_ptr (size = %d, count = %d)\n", + (int)size, (int)count); + res = viadev->lastpos; + } else { + if (! count) { + /* Some mobos report count = 0 on the DMA boundary, + * i.e. count = size indeed. + * Let's check whether this step is above the expected size. + */ + int delta = res - viadev->lastpos; + if (delta < 0) + delta += viadev->bufsize; + if ((unsigned int)delta > viadev->fragsize) + res = base; + } + if (check_invalid_pos(viadev, res)) { #ifdef POINTER_DEBUG - printk("fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n", idx, viadev->tbl_entries, viadev->lastpos, viadev->bufsize2, viadev->idx_table[idx].offset, viadev->idx_table[idx].size, count); + printk(KERN_DEBUG "fail: idx = %i/%i, lastpos = 0x%x, " + "bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, " + "count = 0x%x\n", idx, viadev->tbl_entries, + viadev->lastpos, viadev->bufsize2, + viadev->idx_table[idx].offset, + viadev->idx_table[idx].size, count); #endif - /* count register returns full size when end of buffer is reached */ - if (size != count) { - snd_printd(KERN_ERR "invalid via82xx_cur_ptr, using last valid pointer\n"); - res = viadev->lastpos; - } else { - res = viadev->idx_table[idx].offset + size; - if (res < viadev->lastpos && (res >= viadev->bufsize2 || viadev->lastpos < viadev->bufsize2)) { - snd_printd(KERN_ERR "invalid via82xx_cur_ptr (2), using last valid pointer\n"); + /* count register returns full size when end of buffer is reached */ + res = base + size; + if (check_invalid_pos(viadev, res)) { + snd_printd(KERN_ERR "invalid via82xx_cur_ptr (2), " + "using last valid pointer\n"); res = viadev->lastpos; } } } - viadev->lastpos = res; /* remember the last position */ - if (res >= viadev->bufsize) - res -= viadev->bufsize; return res; } /* * get the current pointer on via686 */ -static snd_pcm_uframes_t snd_via686_pcm_pointer(snd_pcm_substream_t *substream) +static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = (viadev_t *)substream->runtime->private_data; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = substream->runtime->private_data; unsigned int idx, ptr, count, res; snd_assert(viadev->tbl_entries, return 0); @@ -764,6 +839,7 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(snd_pcm_substream_t *substream) else /* CURR_PTR holds the address + 8 */ idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries; res = calc_linear_pos(viadev, idx, count); + viadev->lastpos = res; /* remember the last position */ spin_unlock(&chip->reg_lock); return bytes_to_frames(substream->runtime, res); @@ -772,27 +848,55 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(snd_pcm_substream_t *substream) /* * get the current pointer on via823x */ -static snd_pcm_uframes_t snd_via8233_pcm_pointer(snd_pcm_substream_t *substream) +static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = (viadev_t *)substream->runtime->private_data; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = substream->runtime->private_data; unsigned int idx, count, res; + int status; snd_assert(viadev->tbl_entries, return 0); - if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE)) - return 0; + spin_lock(&chip->reg_lock); count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)); - idx = count >> 24; - if (idx >= viadev->tbl_entries) { + status = viadev->in_interrupt; + if (!status) + status = inb(VIADEV_REG(viadev, OFFSET_STATUS)); + + /* An apparent bug in the 8251 is worked around by sending a + * REG_CTRL_START. */ + if (chip->revision == VIA_REV_8251 && (status & VIA_REG_STAT_EOL)) + snd_via82xx_pcm_trigger(substream, SNDRV_PCM_TRIGGER_START); + + if (!(status & VIA_REG_STAT_ACTIVE)) { + res = 0; + goto unlock; + } + if (count & 0xffffff) { + idx = count >> 24; + if (idx >= viadev->tbl_entries) { #ifdef POINTER_DEBUG - printk("fail: invalid idx = %i/%i\n", idx, viadev->tbl_entries); + printk(KERN_DEBUG "fail: invalid idx = %i/%i\n", idx, + viadev->tbl_entries); #endif - res = viadev->lastpos; + res = viadev->lastpos; + } else { + count &= 0xffffff; + res = calc_linear_pos(viadev, idx, count); + } } else { - count &= 0xffffff; - res = calc_linear_pos(viadev, idx, count); - } + res = viadev->hwptr_done; + if (!viadev->in_interrupt) { + if (status & VIA_REG_STAT_EOL) { + res = 0; + } else + if (status & VIA_REG_STAT_FLAG) { + res += viadev->fragsize; + } + } + } +unlock: + viadev->lastpos = res; spin_unlock(&chip->reg_lock); return bytes_to_frames(substream->runtime, res); @@ -803,11 +907,11 @@ static snd_pcm_uframes_t snd_via8233_pcm_pointer(snd_pcm_substream_t *substream) * hw_params callback: * allocate the buffer and build up the buffer description table */ -static int snd_via82xx_hw_params(snd_pcm_substream_t * substream, - snd_pcm_hw_params_t * hw_params) +static int snd_via82xx_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = (viadev_t *)substream->runtime->private_data; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = substream->runtime->private_data; int err; err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); @@ -826,10 +930,10 @@ static int snd_via82xx_hw_params(snd_pcm_substream_t * substream, * hw_free callback: * clean up the buffer description table and release the buffer */ -static int snd_via82xx_hw_free(snd_pcm_substream_t * substream) +static int snd_via82xx_hw_free(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = (viadev_t *)substream->runtime->private_data; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = substream->runtime->private_data; clean_via_table(viadev, substream, chip->pci); snd_pcm_lib_free_pages(substream); @@ -840,7 +944,7 @@ static int snd_via82xx_hw_free(snd_pcm_substream_t * substream) /* * set up the table pointer */ -static void snd_via82xx_set_table_ptr(via82xx_t *chip, viadev_t *viadev) +static void snd_via82xx_set_table_ptr(struct via82xx *chip, struct viadev *viadev) { snd_via82xx_codec_ready(chip, 0); outl((u32)viadev->table.addr, VIADEV_REG(viadev, OFFSET_TABLE_PTR)); @@ -851,7 +955,8 @@ static void snd_via82xx_set_table_ptr(via82xx_t *chip, viadev_t *viadev) /* * prepare callback for playback and capture on via686 */ -static void via686_setup_format(via82xx_t *chip, viadev_t *viadev, snd_pcm_runtime_t *runtime) +static void via686_setup_format(struct via82xx *chip, struct viadev *viadev, + struct snd_pcm_runtime *runtime) { snd_via82xx_channel_reset(chip, viadev); /* this must be set after channel_reset */ @@ -864,11 +969,11 @@ static void via686_setup_format(via82xx_t *chip, viadev_t *viadev, snd_pcm_runti VIA_REG_TYPE_INT_FLAG, VIADEV_REG(viadev, OFFSET_TYPE)); } -static int snd_via686_playback_prepare(snd_pcm_substream_t *substream) +static int snd_via686_playback_prepare(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = (viadev_t *)substream->runtime->private_data; - snd_pcm_runtime_t *runtime = substream->runtime; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = substream->runtime->private_data; + struct snd_pcm_runtime *runtime = substream->runtime; snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, runtime->rate); snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate); @@ -876,11 +981,11 @@ static int snd_via686_playback_prepare(snd_pcm_substream_t *substream) return 0; } -static int snd_via686_capture_prepare(snd_pcm_substream_t *substream) +static int snd_via686_capture_prepare(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = (viadev_t *)substream->runtime->private_data; - snd_pcm_runtime_t *runtime = substream->runtime; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = substream->runtime->private_data; + struct snd_pcm_runtime *runtime = substream->runtime; snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate); via686_setup_format(chip, viadev, runtime); @@ -894,7 +999,7 @@ static int via_lock_rate(struct via_rate_lock *rec, int rate) { int changed = 0; - spin_lock(&rec->lock); + spin_lock_irq(&rec->lock); if (rec->rate != rate) { if (rec->rate && rec->used > 1) /* already set */ changed = -EINVAL; @@ -903,37 +1008,42 @@ static int via_lock_rate(struct via_rate_lock *rec, int rate) changed = 1; } } - spin_unlock(&rec->lock); + spin_unlock_irq(&rec->lock); return changed; } /* * prepare callback for DSX playback on via823x */ -static int snd_via8233_playback_prepare(snd_pcm_substream_t *substream) +static int snd_via8233_playback_prepare(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = (viadev_t *)substream->runtime->private_data; - snd_pcm_runtime_t *runtime = substream->runtime; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = substream->runtime->private_data; + struct snd_pcm_runtime *runtime = substream->runtime; + int ac97_rate = chip->dxs_src ? 48000 : runtime->rate; int rate_changed; u32 rbits; - if ((rate_changed = via_lock_rate(&chip->rates[0], runtime->rate)) < 0) + if ((rate_changed = via_lock_rate(&chip->rates[0], ac97_rate)) < 0) return rate_changed; - if (rate_changed) { + if (rate_changed) snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, chip->no_vra ? 48000 : runtime->rate); + if (chip->spdif_on && viadev->reg_offset == 0x30) snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate); - } + if (runtime->rate == 48000) rbits = 0xfffff; else - rbits = (0x100000 / 48000) * runtime->rate + ((0x100000 % 48000) * runtime->rate) / 48000; + rbits = (0x100000 / 48000) * runtime->rate + + ((0x100000 % 48000) * runtime->rate) / 48000; snd_assert((rbits & ~0xfffff) == 0, return -EINVAL); snd_via82xx_channel_reset(chip, viadev); snd_via82xx_set_table_ptr(chip, viadev); - outb(chip->playback_volume[viadev->reg_offset / 0x10][0], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L)); - outb(chip->playback_volume[viadev->reg_offset / 0x10][1], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R)); + outb(chip->playback_volume[viadev->reg_offset / 0x10][0], + VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L)); + outb(chip->playback_volume[viadev->reg_offset / 0x10][1], + VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R)); outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | /* format */ (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | /* stereo */ rbits | /* rate */ @@ -947,11 +1057,11 @@ static int snd_via8233_playback_prepare(snd_pcm_substream_t *substream) /* * prepare callback for multi-channel playback on via823x */ -static int snd_via8233_multi_prepare(snd_pcm_substream_t *substream) +static int snd_via8233_multi_prepare(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = (viadev_t *)substream->runtime->private_data; - snd_pcm_runtime_t *runtime = substream->runtime; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = substream->runtime->private_data; + struct snd_pcm_runtime *runtime = substream->runtime; unsigned int slots; int fmt; @@ -964,7 +1074,8 @@ static int snd_via8233_multi_prepare(snd_pcm_substream_t *substream) snd_via82xx_channel_reset(chip, viadev); snd_via82xx_set_table_ptr(chip, viadev); - fmt = (runtime->format == SNDRV_PCM_FORMAT_S16_LE) ? VIA_REG_MULTPLAY_FMT_16BIT : VIA_REG_MULTPLAY_FMT_8BIT; + fmt = (runtime->format == SNDRV_PCM_FORMAT_S16_LE) ? + VIA_REG_MULTPLAY_FMT_16BIT : VIA_REG_MULTPLAY_FMT_8BIT; fmt |= runtime->channels << 4; outb(fmt, VIADEV_REG(viadev, OFS_MULTPLAY_FORMAT)); #if 0 @@ -995,11 +1106,11 @@ static int snd_via8233_multi_prepare(snd_pcm_substream_t *substream) /* * prepare callback for capture on via823x */ -static int snd_via8233_capture_prepare(snd_pcm_substream_t *substream) +static int snd_via8233_capture_prepare(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = (viadev_t *)substream->runtime->private_data; - snd_pcm_runtime_t *runtime = substream->runtime; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = substream->runtime->private_data; + struct snd_pcm_runtime *runtime = substream->runtime; if (via_lock_rate(&chip->rates[1], runtime->rate) < 0) return -EINVAL; @@ -1020,11 +1131,12 @@ static int snd_via8233_capture_prepare(snd_pcm_substream_t *substream) /* * pcm hardware definition, identical for both playback and capture */ -static snd_pcm_hardware_t snd_via82xx_hw = +static struct snd_pcm_hardware snd_via82xx_hw = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID | + /* SNDRV_PCM_INFO_RESUME | */ SNDRV_PCM_INFO_PAUSE), .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, .rates = SNDRV_PCM_RATE_48000, @@ -1044,67 +1156,43 @@ static snd_pcm_hardware_t snd_via82xx_hw = /* * open callback skeleton */ -static int snd_via82xx_pcm_open(via82xx_t *chip, viadev_t *viadev, snd_pcm_substream_t * substream) +static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev, + struct snd_pcm_substream *substream) { - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_pcm_runtime *runtime = substream->runtime; int err; - unsigned long flags; struct via_rate_lock *ratep; - struct ratetbl { - int rate; - unsigned int bit; - } ratebits[] = { - {8000, SNDRV_PCM_RATE_8000}, - {11025, SNDRV_PCM_RATE_11025}, - {16000, SNDRV_PCM_RATE_16000}, - {22050, SNDRV_PCM_RATE_22050}, - {32000, SNDRV_PCM_RATE_32000}, - {44100, SNDRV_PCM_RATE_44100}, - {48000, SNDRV_PCM_RATE_48000}, - }; - int i; runtime->hw = snd_via82xx_hw; /* set the hw rate condition */ ratep = &chip->rates[viadev->direction]; - spin_lock_irqsave(&ratep->lock, flags); + spin_lock_irq(&ratep->lock); ratep->used++; - if (chip->spdif_on) { - runtime->hw.rates = SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000; - runtime->hw.rate_min = 32000; - runtime->hw.rate_max = 48000; + if (chip->spdif_on && viadev->reg_offset == 0x30) { + /* DXS#3 and spdif is on */ + runtime->hw.rates = chip->ac97->rates[AC97_RATES_SPDIF]; + snd_pcm_limit_hw_rates(runtime); } else if (chip->dxs_fixed && viadev->reg_offset < 0x40) { /* fixed DXS playback rate */ runtime->hw.rates = SNDRV_PCM_RATE_48000; runtime->hw.rate_min = runtime->hw.rate_max = 48000; + } else if (chip->dxs_src && viadev->reg_offset < 0x40) { + /* use full SRC capabilities of DXS */ + runtime->hw.rates = (SNDRV_PCM_RATE_CONTINUOUS | + SNDRV_PCM_RATE_8000_48000); + runtime->hw.rate_min = 8000; + runtime->hw.rate_max = 48000; } else if (! ratep->rate) { int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC; runtime->hw.rates = chip->ac97->rates[idx]; - for (i = 0; i < (int)ARRAY_SIZE(ratebits); i++) { - if (runtime->hw.rates & ratebits[i].bit) { - runtime->hw.rate_min = ratebits[i].rate; - break; - } - } - for (i = ARRAY_SIZE(ratebits) - 1; i >= 0; i--) { - if (runtime->hw.rates & ratebits[i].bit) { - runtime->hw.rate_max = ratebits[i].rate; - break; - } - } + snd_pcm_limit_hw_rates(runtime); } else { /* a fixed rate */ runtime->hw.rates = SNDRV_PCM_RATE_KNOT; - for (i = 0; i < (int)ARRAY_SIZE(ratebits); i++) { - if (ratep->rate == ratebits[i].rate) { - runtime->hw.rates = ratebits[i].bit; - break; - } - } runtime->hw.rate_max = runtime->hw.rate_min = ratep->rate; } - spin_unlock_irqrestore(&ratep->lock, flags); + spin_unlock_irq(&ratep->lock); /* we may remove following constaint when we modify table entries in interrupt */ @@ -1121,10 +1209,10 @@ static int snd_via82xx_pcm_open(via82xx_t *chip, viadev_t *viadev, snd_pcm_subst /* * open callback for playback on via686 and via823x DSX */ -static int snd_via82xx_playback_open(snd_pcm_substream_t * substream) +static int snd_via82xx_playback_open(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = &chip->devs[chip->playback_devno + substream->number]; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = &chip->devs[chip->playback_devno + substream->number]; int err; if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0) @@ -1135,10 +1223,10 @@ static int snd_via82xx_playback_open(snd_pcm_substream_t * substream) /* * open callback for playback on via823x multi-channel */ -static int snd_via8233_multi_open(snd_pcm_substream_t * substream) +static int snd_via8233_multi_open(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = &chip->devs[chip->multi_devno]; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = &chip->devs[chip->multi_devno]; int err; /* channels constraint for VIA8233A * 3 and 5 channels are not supported @@ -1146,7 +1234,7 @@ static int snd_via8233_multi_open(snd_pcm_substream_t * substream) static unsigned int channels[] = { 1, 2, 4, 6 }; - static snd_pcm_hw_constraint_list_t hw_constraints_channels = { + static struct snd_pcm_hw_constraint_list hw_constraints_channels = { .count = ARRAY_SIZE(channels), .list = channels, .mask = 0, @@ -1156,17 +1244,19 @@ static int snd_via8233_multi_open(snd_pcm_substream_t * substream) return err; substream->runtime->hw.channels_max = 6; if (chip->revision == VIA_REV_8233A) - snd_pcm_hw_constraint_list(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels); + snd_pcm_hw_constraint_list(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_CHANNELS, + &hw_constraints_channels); return 0; } /* * open callback for capture on via686 and via823x */ -static int snd_via82xx_capture_open(snd_pcm_substream_t * substream) +static int snd_via82xx_capture_open(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = &chip->devs[chip->capture_devno + substream->pcm->device]; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = &chip->devs[chip->capture_devno + substream->pcm->device]; return snd_via82xx_pcm_open(chip, viadev, substream); } @@ -1174,20 +1264,19 @@ static int snd_via82xx_capture_open(snd_pcm_substream_t * substream) /* * close callback */ -static int snd_via82xx_pcm_close(snd_pcm_substream_t * substream) +static int snd_via82xx_pcm_close(struct snd_pcm_substream *substream) { - via82xx_t *chip = snd_pcm_substream_chip(substream); - viadev_t *viadev = (viadev_t *)substream->runtime->private_data; - unsigned long flags; + struct via82xx *chip = snd_pcm_substream_chip(substream); + struct viadev *viadev = substream->runtime->private_data; struct via_rate_lock *ratep; /* release the rate lock */ ratep = &chip->rates[viadev->direction]; - spin_lock_irqsave(&ratep->lock, flags); + spin_lock_irq(&ratep->lock); ratep->used--; if (! ratep->used) ratep->rate = 0; - spin_unlock_irqrestore(&ratep->lock, flags); + spin_unlock_irq(&ratep->lock); viadev->substream = NULL; return 0; @@ -1195,7 +1284,7 @@ static int snd_via82xx_pcm_close(snd_pcm_substream_t * substream) /* via686 playback callbacks */ -static snd_pcm_ops_t snd_via686_playback_ops = { +static struct snd_pcm_ops snd_via686_playback_ops = { .open = snd_via82xx_playback_open, .close = snd_via82xx_pcm_close, .ioctl = snd_pcm_lib_ioctl, @@ -1208,7 +1297,7 @@ static snd_pcm_ops_t snd_via686_playback_ops = { }; /* via686 capture callbacks */ -static snd_pcm_ops_t snd_via686_capture_ops = { +static struct snd_pcm_ops snd_via686_capture_ops = { .open = snd_via82xx_capture_open, .close = snd_via82xx_pcm_close, .ioctl = snd_pcm_lib_ioctl, @@ -1221,7 +1310,7 @@ static snd_pcm_ops_t snd_via686_capture_ops = { }; /* via823x DSX playback callbacks */ -static snd_pcm_ops_t snd_via8233_playback_ops = { +static struct snd_pcm_ops snd_via8233_playback_ops = { .open = snd_via82xx_playback_open, .close = snd_via82xx_pcm_close, .ioctl = snd_pcm_lib_ioctl, @@ -1234,7 +1323,7 @@ static snd_pcm_ops_t snd_via8233_playback_ops = { }; /* via823x multi-channel playback callbacks */ -static snd_pcm_ops_t snd_via8233_multi_ops = { +static struct snd_pcm_ops snd_via8233_multi_ops = { .open = snd_via8233_multi_open, .close = snd_via82xx_pcm_close, .ioctl = snd_pcm_lib_ioctl, @@ -1247,7 +1336,7 @@ static snd_pcm_ops_t snd_via8233_multi_ops = { }; /* via823x capture callbacks */ -static snd_pcm_ops_t snd_via8233_capture_ops = { +static struct snd_pcm_ops snd_via8233_capture_ops = { .open = snd_via82xx_capture_open, .close = snd_via82xx_pcm_close, .ioctl = snd_pcm_lib_ioctl, @@ -1260,9 +1349,11 @@ static snd_pcm_ops_t snd_via8233_capture_ops = { }; -static void init_viadev(via82xx_t *chip, int idx, unsigned int reg_offset, int direction) +static void init_viadev(struct via82xx *chip, int idx, unsigned int reg_offset, + int shadow_pos, int direction) { chip->devs[idx].reg_offset = reg_offset; + chip->devs[idx].shadow_shift = shadow_pos * 4; chip->devs[idx].direction = direction; chip->devs[idx].port = chip->port + reg_offset; } @@ -1270,9 +1361,9 @@ static void init_viadev(via82xx_t *chip, int idx, unsigned int reg_offset, int d /* * create pcm instances for VIA8233, 8233C and 8235 (not 8233A) */ -static int __devinit snd_via8233_pcm_new(via82xx_t *chip) +static int __devinit snd_via8233_pcm_new(struct via82xx *chip) { - snd_pcm_t *pcm; + struct snd_pcm *pcm; int i, err; chip->playback_devno = 0; /* x 4 */ @@ -1289,14 +1380,16 @@ static int __devinit snd_via8233_pcm_new(via82xx_t *chip) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); pcm->private_data = chip; strcpy(pcm->name, chip->card->shortname); + chip->pcms[0] = pcm; /* set up playbacks */ for (i = 0; i < 4; i++) - init_viadev(chip, i, 0x10 * i, 0); + init_viadev(chip, i, 0x10 * i, i, 0); /* capture */ - init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 1); + init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1); if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, - snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) + snd_dma_pci_data(chip->pci), + 64*1024, 128*1024)) < 0) return err; /* PCM #1: multi-channel playback and 2nd capture */ @@ -1307,13 +1400,15 @@ static int __devinit snd_via8233_pcm_new(via82xx_t *chip) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); pcm->private_data = chip; strcpy(pcm->name, chip->card->shortname); + chip->pcms[1] = pcm; /* set up playback */ - init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 0); + init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0); /* set up capture */ - init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 1); + init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1); if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, - snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) + snd_dma_pci_data(chip->pci), + 64*1024, 128*1024)) < 0) return err; return 0; @@ -1322,9 +1417,9 @@ static int __devinit snd_via8233_pcm_new(via82xx_t *chip) /* * create pcm instances for VIA8233A */ -static int __devinit snd_via8233a_pcm_new(via82xx_t *chip) +static int __devinit snd_via8233a_pcm_new(struct via82xx *chip) { - snd_pcm_t *pcm; + struct snd_pcm *pcm; int err; chip->multi_devno = 0; @@ -1341,15 +1436,21 @@ static int __devinit snd_via8233a_pcm_new(via82xx_t *chip) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via8233_capture_ops); pcm->private_data = chip; strcpy(pcm->name, chip->card->shortname); + chip->pcms[0] = pcm; /* set up playback */ - init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 0); + init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0); /* capture */ - init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 1); + init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1); if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, - snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) + snd_dma_pci_data(chip->pci), + 64*1024, 128*1024)) < 0) return err; + /* SPDIF supported? */ + if (! ac97_can_spdif(chip->ac97)) + return 0; + /* PCM #1: DXS3 playback (for spdif) */ err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 0, &pcm); if (err < 0) @@ -1357,11 +1458,13 @@ static int __devinit snd_via8233a_pcm_new(via82xx_t *chip) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via8233_playback_ops); pcm->private_data = chip; strcpy(pcm->name, chip->card->shortname); + chip->pcms[1] = pcm; /* set up playback */ - init_viadev(chip, chip->playback_devno, 0x30, 0); + init_viadev(chip, chip->playback_devno, 0x30, 3, 0); if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, - snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) + snd_dma_pci_data(chip->pci), + 64*1024, 128*1024)) < 0) return err; return 0; @@ -1370,9 +1473,9 @@ static int __devinit snd_via8233a_pcm_new(via82xx_t *chip) /* * create a pcm instance for via686a/b */ -static int __devinit snd_via686_pcm_new(via82xx_t *chip) +static int __devinit snd_via686_pcm_new(struct via82xx *chip) { - snd_pcm_t *pcm; + struct snd_pcm *pcm; int err; chip->playback_devno = 0; @@ -1387,11 +1490,13 @@ static int __devinit snd_via686_pcm_new(via82xx_t *chip) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via686_capture_ops); pcm->private_data = chip; strcpy(pcm->name, chip->card->shortname); - init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0); - init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 1); + chip->pcms[0] = pcm; + init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0); + init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1); if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, - snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) + snd_dma_pci_data(chip->pci), + 64*1024, 128*1024)) < 0) return err; return 0; @@ -1402,10 +1507,14 @@ static int __devinit snd_via686_pcm_new(via82xx_t *chip) * Mixer part */ -static int snd_via8233_capture_source_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) +static int snd_via8233_capture_source_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { + /* formerly they were "Line" and "Mic", but it looks like that they + * have nothing to do with the actual physical connections... + */ static char *texts[2] = { - "Line", "Mic" + "Input1", "Input2" }; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; @@ -1416,33 +1525,34 @@ static int snd_via8233_capture_source_info(snd_kcontrol_t *kcontrol, snd_ctl_ele return 0; } -static int snd_via8233_capture_source_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) +static int snd_via8233_capture_source_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - via82xx_t *chip = snd_kcontrol_chip(kcontrol); + struct via82xx *chip = snd_kcontrol_chip(kcontrol); unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL); ucontrol->value.enumerated.item[0] = inb(port) & VIA_REG_CAPTURE_CHANNEL_MIC ? 1 : 0; return 0; } -static int snd_via8233_capture_source_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) +static int snd_via8233_capture_source_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - via82xx_t *chip = snd_kcontrol_chip(kcontrol); + struct via82xx *chip = snd_kcontrol_chip(kcontrol); unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL); - unsigned long flags; u8 val, oval; - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); oval = inb(port); val = oval & ~VIA_REG_CAPTURE_CHANNEL_MIC; if (ucontrol->value.enumerated.item[0]) val |= VIA_REG_CAPTURE_CHANNEL_MIC; if (val != oval) outb(val, port); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); return val != oval; } -static snd_kcontrol_new_t snd_via8233_capture_source __devinitdata = { +static struct snd_kcontrol_new snd_via8233_capture_source __devinitdata = { .name = "Input Source Select", .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .info = snd_via8233_capture_source_info, @@ -1450,7 +1560,8 @@ static snd_kcontrol_new_t snd_via8233_capture_source __devinitdata = { .put = snd_via8233_capture_source_put, }; -static int snd_via8233_dxs3_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) +static int snd_via8233_dxs3_spdif_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; @@ -1459,9 +1570,10 @@ static int snd_via8233_dxs3_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_in return 0; } -static int snd_via8233_dxs3_spdif_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) +static int snd_via8233_dxs3_spdif_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - via82xx_t *chip = snd_kcontrol_chip(kcontrol); + struct via82xx *chip = snd_kcontrol_chip(kcontrol); u8 val; pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val); @@ -1469,9 +1581,10 @@ static int snd_via8233_dxs3_spdif_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_val return 0; } -static int snd_via8233_dxs3_spdif_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) +static int snd_via8233_dxs3_spdif_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - via82xx_t *chip = snd_kcontrol_chip(kcontrol); + struct via82xx *chip = snd_kcontrol_chip(kcontrol); u8 val, oval; pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &oval); @@ -1487,15 +1600,16 @@ static int snd_via8233_dxs3_spdif_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_val return 0; } -static snd_kcontrol_new_t snd_via8233_dxs3_spdif_control __devinitdata = { - .name = "IEC958 Output Switch", +static struct snd_kcontrol_new snd_via8233_dxs3_spdif_control __devinitdata = { + .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH), .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .info = snd_via8233_dxs3_spdif_info, .get = snd_via8233_dxs3_spdif_get, .put = snd_via8233_dxs3_spdif_put, }; -static int snd_via8233_dxs_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) +static int snd_via8233_dxs_volume_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; @@ -1504,18 +1618,30 @@ static int snd_via8233_dxs_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_in return 0; } -static int snd_via8233_dxs_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) +static int snd_via8233_dxs_volume_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - via82xx_t *chip = snd_kcontrol_chip(kcontrol); + struct via82xx *chip = snd_kcontrol_chip(kcontrol); unsigned int idx = snd_ctl_get_ioff(kcontrol, &ucontrol->id); + ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][0]; ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][1]; return 0; } -static int snd_via8233_dxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) +static int snd_via8233_pcmdxs_volume_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct via82xx *chip = snd_kcontrol_chip(kcontrol); + ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[0]; + ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[1]; + return 0; +} + +static int snd_via8233_dxs_volume_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - via82xx_t *chip = snd_kcontrol_chip(kcontrol); + struct via82xx *chip = snd_kcontrol_chip(kcontrol); unsigned int idx = snd_ctl_get_ioff(kcontrol, &ucontrol->id); unsigned long port = chip->port + 0x10 * idx; unsigned char val; @@ -1535,7 +1661,41 @@ static int snd_via8233_dxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_val return change; } -static snd_kcontrol_new_t snd_via8233_dxs_volume_control __devinitdata = { +static int snd_via8233_pcmdxs_volume_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct via82xx *chip = snd_kcontrol_chip(kcontrol); + unsigned int idx; + unsigned char val; + int i, change = 0; + + for (i = 0; i < 2; i++) { + val = ucontrol->value.integer.value[i]; + if (val > VIA_DXS_MAX_VOLUME) + val = VIA_DXS_MAX_VOLUME; + val = VIA_DXS_MAX_VOLUME - val; + if (val != chip->playback_volume_c[i]) { + change = 1; + chip->playback_volume_c[i] = val; + for (idx = 0; idx < 4; idx++) { + unsigned long port = chip->port + 0x10 * idx; + chip->playback_volume[idx][i] = val; + outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); + } + } + } + return change; +} + +static struct snd_kcontrol_new snd_via8233_pcmdxs_volume_control __devinitdata = { + .name = "PCM Playback Volume", + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .info = snd_via8233_dxs_volume_info, + .get = snd_via8233_pcmdxs_volume_get, + .put = snd_via8233_pcmdxs_volume_put, +}; + +static struct snd_kcontrol_new snd_via8233_dxs_volume_control __devinitdata = { .name = "VIA DXS Playback Volume", .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .count = 4, @@ -1547,70 +1707,101 @@ static snd_kcontrol_new_t snd_via8233_dxs_volume_control __devinitdata = { /* */ -static void snd_via82xx_mixer_free_ac97_bus(ac97_bus_t *bus) +static void snd_via82xx_mixer_free_ac97_bus(struct snd_ac97_bus *bus) { - via82xx_t *chip = snd_magic_cast(via82xx_t, bus->private_data, return); + struct via82xx *chip = bus->private_data; chip->ac97_bus = NULL; } -static void snd_via82xx_mixer_free_ac97(ac97_t *ac97) +static void snd_via82xx_mixer_free_ac97(struct snd_ac97 *ac97) { - via82xx_t *chip = snd_magic_cast(via82xx_t, ac97->private_data, return); + struct via82xx *chip = ac97->private_data; chip->ac97 = NULL; } static struct ac97_quirk ac97_quirks[] = { + { + .subvendor = 0x1106, + .subdevice = 0x4161, + .codec_id = 0x56494161, /* VT1612A */ + .name = "Soltek SL-75DRV5", + .type = AC97_TUNE_NONE + }, { /* FIXME: which codec? */ - .vendor = 0x1106, - .device = 0x4161, + .subvendor = 0x1106, + .subdevice = 0x4161, .name = "ASRock K7VT2", .type = AC97_TUNE_HP_ONLY }, { - .vendor = 0x1849, - .device = 0x3059, + .subvendor = 0x1019, + .subdevice = 0x0a81, + .name = "ECS K7VTA3", + .type = AC97_TUNE_HP_ONLY + }, + { + .subvendor = 0x1019, + .subdevice = 0x0a85, + .name = "ECS L7VMM2", + .type = AC97_TUNE_HP_ONLY + }, + { + .subvendor = 0x1849, + .subdevice = 0x3059, .name = "ASRock K7VM2", .type = AC97_TUNE_HP_ONLY /* VT1616 */ }, { - .vendor = 0x14cd, - .device = 0x7002, + .subvendor = 0x14cd, + .subdevice = 0x7002, .name = "Unknown", .type = AC97_TUNE_ALC_JACK }, { - .vendor = 0x1071, - .device = 0x8590, + .subvendor = 0x1071, + .subdevice = 0x8590, .name = "Mitac Mobo", .type = AC97_TUNE_ALC_JACK }, + { + .subvendor = 0x161f, + .subdevice = 0x202b, + .name = "Arima Notebook", + .type = AC97_TUNE_HP_ONLY, + }, + { + .subvendor = 0x161f, + .subdevice = 0x2032, + .name = "Targa Traveller 811", + .type = AC97_TUNE_HP_ONLY, + }, { } /* terminator */ }; -static int __devinit snd_via82xx_mixer_new(via82xx_t *chip, int ac97_quirk) +static int __devinit snd_via82xx_mixer_new(struct via82xx *chip, const char *quirk_override) { - ac97_bus_t bus; - ac97_t ac97; + struct snd_ac97_template ac97; int err; + static struct snd_ac97_bus_ops ops = { + .write = snd_via82xx_codec_write, + .read = snd_via82xx_codec_read, + .wait = snd_via82xx_codec_wait, + }; - memset(&bus, 0, sizeof(bus)); - bus.write = snd_via82xx_codec_write; - bus.read = snd_via82xx_codec_read; - bus.wait = snd_via82xx_codec_wait; - bus.private_data = chip; - bus.private_free = snd_via82xx_mixer_free_ac97_bus; - bus.clock = chip->ac97_clock; - if ((err = snd_ac97_bus(chip->card, &bus, &chip->ac97_bus)) < 0) + if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0) return err; + chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus; + chip->ac97_bus->clock = chip->ac97_clock; memset(&ac97, 0, sizeof(ac97)); ac97.private_data = chip; ac97.private_free = snd_via82xx_mixer_free_ac97; ac97.pci = chip->pci; + ac97.scaps = AC97_SCAP_SKIP_MODEM; if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0) return err; - snd_ac97_tune_hardware(chip->ac97, ac97_quirks, ac97_quirk); + snd_ac97_tune_hardware(chip->ac97, ac97_quirks, quirk_override); if (chip->chip_type != TYPE_VIA686) { /* use slot 10/11 */ @@ -1620,11 +1811,69 @@ static int __devinit snd_via82xx_mixer_new(via82xx_t *chip, int ac97_quirk) return 0; } +#ifdef SUPPORT_JOYSTICK +#define JOYSTICK_ADDR 0x200 +static int __devinit snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy) +{ + struct gameport *gp; + struct resource *r; + + if (!joystick) + return -ENODEV; + + r = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport"); + if (!r) { + printk(KERN_WARNING "via82xx: cannot reserve joystick port 0x%#x\n", + JOYSTICK_ADDR); + return -EBUSY; + } + + chip->gameport = gp = gameport_allocate_port(); + if (!gp) { + printk(KERN_ERR "via82xx: cannot allocate memory for gameport\n"); + release_and_free_resource(r); + return -ENOMEM; + } + + gameport_set_name(gp, "VIA686 Gameport"); + gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci)); + gameport_set_dev_parent(gp, &chip->pci->dev); + gp->io = JOYSTICK_ADDR; + gameport_set_port_data(gp, r); + + /* Enable legacy joystick port */ + *legacy |= VIA_FUNC_ENABLE_GAME; + pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, *legacy); + + gameport_register_port(chip->gameport); + + return 0; +} + +static void snd_via686_free_gameport(struct via82xx *chip) +{ + if (chip->gameport) { + struct resource *r = gameport_get_port_data(chip->gameport); + + gameport_unregister_port(chip->gameport); + chip->gameport = NULL; + release_and_free_resource(r); + } +} +#else +static inline int snd_via686_create_gameport(struct via82xx *chip, unsigned char *legacy) +{ + return -ENOSYS; +} +static inline void snd_via686_free_gameport(struct via82xx *chip) { } +#endif + + /* * */ -static int snd_via8233_init_misc(via82xx_t *chip, int dev) +static int __devinit snd_via8233_init_misc(struct via82xx *chip) { int i, err, caps; unsigned char val; @@ -1636,24 +1885,43 @@ static int snd_via8233_init_misc(via82xx_t *chip, int dev) if (err < 0) return err; } - err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs3_spdif_control, chip)); - if (err < 0) - return err; - if (chip->chip_type != TYPE_VIA8233A) { - err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs_volume_control, chip)); + if (ac97_can_spdif(chip->ac97)) { + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs3_spdif_control, chip)); if (err < 0) return err; } - + if (chip->chip_type != TYPE_VIA8233A) { + /* when no h/w PCM volume control is found, use DXS volume control + * as the PCM vol control + */ + struct snd_ctl_elem_id sid; + memset(&sid, 0, sizeof(sid)); + strcpy(sid.name, "PCM Playback Volume"); + sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; + if (! snd_ctl_find_id(chip->card, &sid)) { + snd_printd(KERN_INFO "Using DXS as PCM Playback\n"); + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_pcmdxs_volume_control, chip)); + if (err < 0) + return err; + } + else /* Using DXS when PCM emulation is enabled is really weird */ + { + /* Standalone DXS controls */ + err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs_volume_control, chip)); + if (err < 0) + return err; + } + } /* select spdif data slot 10/11 */ pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val); val = (val & ~VIA8233_SPDIF_SLOT_MASK) | VIA8233_SPDIF_SLOT_1011; + val &= ~VIA8233_SPDIF_DX3; /* SPDIF off as default */ pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, val); return 0; } -static int snd_via686_init_misc(via82xx_t *chip, int dev) +static int __devinit snd_via686_init_misc(struct via82xx *chip) { unsigned char legacy, legacy_cfg; int rev_h = 0; @@ -1664,29 +1932,33 @@ static int snd_via686_init_misc(via82xx_t *chip, int dev) legacy &= ~VIA_FUNC_ENABLE_GAME; /* disable joystick */ if (chip->revision >= VIA_REV_686_H) { rev_h = 1; - if (mpu_port[dev] >= 0x200) { /* force MIDI */ - mpu_port[dev] &= 0xfffc; - pci_write_config_dword(chip->pci, 0x18, mpu_port[dev] | 0x01); + if (mpu_port >= 0x200) { /* force MIDI */ + mpu_port &= 0xfffc; + pci_write_config_dword(chip->pci, 0x18, mpu_port | 0x01); +#ifdef CONFIG_PM + chip->mpu_port_saved = mpu_port; +#endif } else { - mpu_port[dev] = pci_resource_start(chip->pci, 2); + mpu_port = pci_resource_start(chip->pci, 2); } } else { - switch (mpu_port[dev]) { /* force MIDI */ + switch (mpu_port) { /* force MIDI */ case 0x300: case 0x310: case 0x320: case 0x330: legacy_cfg &= ~(3 << 2); - legacy_cfg |= (mpu_port[dev] & 0x0030) >> 2; + legacy_cfg |= (mpu_port & 0x0030) >> 2; break; default: /* no, use BIOS settings */ if (legacy & VIA_FUNC_ENABLE_MIDI) - mpu_port[dev] = 0x300 + ((legacy_cfg & 0x000c) << 2); + mpu_port = 0x300 + ((legacy_cfg & 0x000c) << 2); break; } } - if (mpu_port[dev] >= 0x200 && - (chip->mpu_res = request_region(mpu_port[dev], 2, "VIA82xx MPU401")) != NULL) { + if (mpu_port >= 0x200 && + (chip->mpu_res = request_region(mpu_port, 2, "VIA82xx MPU401")) + != NULL) { if (rev_h) legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */ legacy |= VIA_FUNC_ENABLE_MIDI; @@ -1694,25 +1966,17 @@ static int snd_via686_init_misc(via82xx_t *chip, int dev) if (rev_h) legacy &= ~VIA_FUNC_MIDI_PNP; /* disable PCI I/O 2 */ legacy &= ~VIA_FUNC_ENABLE_MIDI; - mpu_port[dev] = 0; - } - -#ifdef SUPPORT_JOYSTICK -#define JOYSTICK_ADDR 0x200 - if (joystick[dev] && - (chip->res_joystick = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport")) != NULL) { - legacy |= VIA_FUNC_ENABLE_GAME; - chip->gameport.io = JOYSTICK_ADDR; + mpu_port = 0; } -#endif pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg); if (chip->mpu_res) { if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A, - mpu_port[dev], 1, + mpu_port, 1, chip->irq, 0, &chip->rmidi) < 0) { - printk(KERN_WARNING "unable to initialize MPU-401 at 0x%lx, skipping\n", mpu_port[dev]); + printk(KERN_WARNING "unable to initialize MPU-401" + " at 0x%lx, skipping\n", mpu_port); legacy &= ~VIA_FUNC_ENABLE_MIDI; } else { legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */ @@ -1720,9 +1984,11 @@ static int snd_via686_init_misc(via82xx_t *chip, int dev) pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); } -#ifdef SUPPORT_JOYSTICK - if (chip->res_joystick) - gameport_register_port(&chip->gameport); + snd_via686_create_gameport(chip, &legacy); + +#ifdef CONFIG_PM + chip->legacy_saved = legacy; + chip->legacy_cfg_saved = legacy_cfg; #endif return 0; @@ -1732,9 +1998,10 @@ static int snd_via686_init_misc(via82xx_t *chip, int dev) /* * proc interface */ -static void snd_via82xx_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer) +static void snd_via82xx_proc_read(struct snd_info_entry *entry, + struct snd_info_buffer *buffer) { - via82xx_t *chip = snd_magic_cast(via82xx_t, entry->private_data, return); + struct via82xx *chip = entry->private_data; int i; snd_iprintf(buffer, "%s\n\n", chip->card->longname); @@ -1743,9 +2010,9 @@ static void snd_via82xx_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *bu } } -static void __devinit snd_via82xx_proc_init(via82xx_t *chip) +static void __devinit snd_via82xx_proc_init(struct via82xx *chip) { - snd_info_entry_t *entry; + struct snd_info_entry *entry; if (! snd_card_proc_new(chip->card, "via82xx", &entry)) snd_info_set_text_ops(entry, chip, 1024, snd_via82xx_proc_read); @@ -1755,16 +2022,12 @@ static void __devinit snd_via82xx_proc_init(via82xx_t *chip) * */ -static int __devinit snd_via82xx_chip_init(via82xx_t *chip) +static int snd_via82xx_chip_init(struct via82xx *chip) { - ac97_t ac97; unsigned int val; - int max_count; + unsigned long end_time; unsigned char pval; - memset(&ac97, 0, sizeof(ac97)); - ac97.private_data = chip; - #if 0 /* broken on K7M? */ if (chip->chip_type == TYPE_VIA686) /* disable all legacy ports */ @@ -1804,28 +2067,22 @@ static int __devinit snd_via82xx_chip_init(via82xx_t *chip) } /* wait until codec ready */ - max_count = ((3 * HZ) / 4) + 1; + end_time = jiffies + msecs_to_jiffies(750); do { pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */ break; - set_current_state(TASK_UNINTERRUPTIBLE); - schedule_timeout(1); - } while (--max_count > 0); + schedule_timeout_uninterruptible(1); + } while (time_before(jiffies, end_time)); if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) - snd_printk("AC'97 codec is not ready [0x%x]\n", val); - - /* and then reset codec.. */ - snd_via82xx_codec_ready(chip, 0); - snd_via82xx_codec_write(&ac97, AC97_RESET, 0x0000); - snd_via82xx_codec_read(&ac97, 0); + snd_printk(KERN_ERR "AC'97 codec is not ready [0x%x]\n", val); #if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */ snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | VIA_REG_AC97_SECONDARY_VALID | (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); - max_count = ((3 * HZ) / 4) + 1; + end_time = jiffies + msecs_to_jiffies(750); snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | VIA_REG_AC97_SECONDARY_VALID | (VIA_REG_AC97_CODEC_ID_SECONDARY << VIA_REG_AC97_CODEC_ID_SHIFT)); @@ -1834,9 +2091,8 @@ static int __devinit snd_via82xx_chip_init(via82xx_t *chip) chip->ac97_secondary = 1; goto __ac97_ok2; } - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(1); - } while (--max_count > 0); + schedule_timeout_interruptible(1); + } while (time_before(jiffies, end_time)); /* This is ok, the most of motherboards have only one codec */ __ac97_ok2: @@ -1854,18 +2110,95 @@ static int __devinit snd_via82xx_chip_init(via82xx_t *chip) * DXS channels don't work properly with VRA if MC97 is disabled. */ struct pci_dev *pci; - pci = pci_find_device(0x1106, 0x3068, NULL); /* MC97 */ + pci = pci_get_device(0x1106, 0x3068, NULL); /* MC97 */ if (pci) { unsigned char data; pci_read_config_byte(pci, 0x44, &data); pci_write_config_byte(pci, 0x44, data | 0x40); + pci_dev_put(pci); + } + } + + if (chip->chip_type != TYPE_VIA8233A) { + int i, idx; + for (idx = 0; idx < 4; idx++) { + unsigned long port = chip->port + 0x10 * idx; + for (i = 0; i < 2; i++) { + chip->playback_volume[idx][i]=chip->playback_volume_c[i]; + outb(chip->playback_volume_c[i], + port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); + } } } return 0; } -static int snd_via82xx_free(via82xx_t *chip) +#ifdef CONFIG_PM +/* + * power management + */ +static int snd_via82xx_suspend(struct pci_dev *pci, pm_message_t state) +{ + struct snd_card *card = pci_get_drvdata(pci); + struct via82xx *chip = card->private_data; + int i; + + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); + for (i = 0; i < 2; i++) + snd_pcm_suspend_all(chip->pcms[i]); + for (i = 0; i < chip->num_devs; i++) + snd_via82xx_channel_reset(chip, &chip->devs[i]); + synchronize_irq(chip->irq); + snd_ac97_suspend(chip->ac97); + + /* save misc values */ + if (chip->chip_type != TYPE_VIA686) { + pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &chip->spdif_ctrl_saved); + chip->capture_src_saved[0] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL); + chip->capture_src_saved[1] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10); + } + + pci_set_power_state(pci, PCI_D3hot); + pci_disable_device(pci); + pci_save_state(pci); + return 0; +} + +static int snd_via82xx_resume(struct pci_dev *pci) +{ + struct snd_card *card = pci_get_drvdata(pci); + struct via82xx *chip = card->private_data; + int i; + + pci_restore_state(pci); + pci_enable_device(pci); + pci_set_power_state(pci, PCI_D0); + + snd_via82xx_chip_init(chip); + + if (chip->chip_type == TYPE_VIA686) { + if (chip->mpu_port_saved) + pci_write_config_dword(chip->pci, 0x18, chip->mpu_port_saved | 0x01); + pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->legacy_saved); + pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->legacy_cfg_saved); + } else { + pci_write_config_byte(chip->pci, VIA8233_SPDIF_CTRL, chip->spdif_ctrl_saved); + outb(chip->capture_src_saved[0], chip->port + VIA_REG_CAPTURE_CHANNEL); + outb(chip->capture_src_saved[1], chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10); + } + + snd_ac97_resume(chip->ac97); + + for (i = 0; i < chip->num_devs; i++) + snd_via82xx_channel_reset(chip, &chip->devs[i]); + + snd_power_change_state(card, SNDRV_CTL_POWER_D0); + return 0; +} +#endif /* CONFIG_PM */ + +static int snd_via82xx_free(struct via82xx *chip) { unsigned int i; @@ -1876,83 +2209,75 @@ static int snd_via82xx_free(via82xx_t *chip) snd_via82xx_channel_reset(chip, &chip->devs[i]); synchronize_irq(chip->irq); __end_hw: - if (chip->mpu_res) { - release_resource(chip->mpu_res); - kfree_nocheck(chip->mpu_res); - } - if (chip->res_port) { - release_resource(chip->res_port); - kfree_nocheck(chip->res_port); - } if (chip->irq >= 0) - free_irq(chip->irq, (void *)chip); + free_irq(chip->irq, chip); + release_and_free_resource(chip->mpu_res); + pci_release_regions(chip->pci); + if (chip->chip_type == TYPE_VIA686) { -#ifdef SUPPORT_JOYSTICK - if (chip->res_joystick) { - gameport_unregister_port(&chip->gameport); - release_resource(chip->res_joystick); - kfree_nocheck(chip->res_joystick); - } -#endif + snd_via686_free_gameport(chip); pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, chip->old_legacy); pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, chip->old_legacy_cfg); } - snd_magic_kfree(chip); + pci_disable_device(chip->pci); + kfree(chip); return 0; } -static int snd_via82xx_dev_free(snd_device_t *device) +static int snd_via82xx_dev_free(struct snd_device *device) { - via82xx_t *chip = snd_magic_cast(via82xx_t, device->device_data, return -ENXIO); + struct via82xx *chip = device->device_data; return snd_via82xx_free(chip); } -static int __devinit snd_via82xx_create(snd_card_t * card, +static int __devinit snd_via82xx_create(struct snd_card *card, struct pci_dev *pci, int chip_type, int revision, unsigned int ac97_clock, - via82xx_t ** r_via) + struct via82xx ** r_via) { - via82xx_t *chip; + struct via82xx *chip; int err; - static snd_device_ops_t ops = { + static struct snd_device_ops ops = { .dev_free = snd_via82xx_dev_free, }; if ((err = pci_enable_device(pci)) < 0) return err; - if ((chip = snd_magic_kcalloc(via82xx_t, 0, GFP_KERNEL)) == NULL) + if ((chip = kzalloc(sizeof(*chip), GFP_KERNEL)) == NULL) { + pci_disable_device(pci); return -ENOMEM; + } chip->chip_type = chip_type; chip->revision = revision; spin_lock_init(&chip->reg_lock); - spin_lock_init(&chip->ac97_lock); spin_lock_init(&chip->rates[0].lock); spin_lock_init(&chip->rates[1].lock); chip->card = card; chip->pci = pci; chip->irq = -1; - memset(&chip->dma_dev, 0, sizeof(chip->dma_dev)); - chip->dma_dev.type = SNDRV_DMA_TYPE_DEV; - chip->dma_dev.dev = snd_dma_pci_data(pci); - pci_read_config_byte(pci, VIA_FUNC_ENABLE, &chip->old_legacy); pci_read_config_byte(pci, VIA_PNP_CONTROL, &chip->old_legacy_cfg); + pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, + chip->old_legacy & ~(VIA_FUNC_ENABLE_SB|VIA_FUNC_ENABLE_FM)); - chip->port = pci_resource_start(pci, 0); - if ((chip->res_port = request_region(chip->port, 256, card->driver)) == NULL) { - snd_printk("unable to grab ports 0x%lx-0x%lx\n", chip->port, chip->port + 256 - 1); - snd_via82xx_free(chip); - return -EBUSY; + if ((err = pci_request_regions(pci, card->driver)) < 0) { + kfree(chip); + pci_disable_device(pci); + return err; } - if (request_irq(pci->irq, snd_via82xx_interrupt, SA_INTERRUPT|SA_SHIRQ, - card->driver, (void *)chip)) { - snd_printk("unable to grab IRQ %d\n", pci->irq); + chip->port = pci_resource_start(pci, 0); + if (request_irq(pci->irq, + chip_type == TYPE_VIA8233 ? + snd_via8233_interrupt : snd_via686_interrupt, + SA_INTERRUPT|SA_SHIRQ, + card->driver, chip)) { + snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); snd_via82xx_free(chip); return -EBUSY; } @@ -1993,41 +2318,80 @@ static struct via823x_info via823x_cards[] __devinitdata = { { VIA_REV_8233, "VIA 8233", TYPE_VIA8233 }, { VIA_REV_8233A, "VIA 8233A", TYPE_VIA8233A }, { VIA_REV_8235, "VIA 8235", TYPE_VIA8233 }, + { VIA_REV_8237, "VIA 8237", TYPE_VIA8233 }, + { VIA_REV_8251, "VIA 8251", TYPE_VIA8233 }, }; /* * auto detection of DXS channel supports. */ struct dxs_whitelist { - unsigned short vendor; - unsigned short device; + unsigned short subvendor; + unsigned short subdevice; unsigned short mask; short action; /* new dxs_support value */ }; -static int __devinit check_dxs_list(struct pci_dev *pci) +static int __devinit check_dxs_list(struct pci_dev *pci, int revision) { static struct dxs_whitelist whitelist[] = { - { .vendor = 0x1005, .device = 0x4710, .action = VIA_DXS_ENABLE }, /* Avance Logic Mobo */ - { .vendor = 0x1019, .device = 0x0996, .action = VIA_DXS_48K }, - { .vendor = 0x1043, .device = 0x8095, .action = VIA_DXS_ENABLE }, /* ASUS A7V8X */ - { .vendor = 0x1043, .device = 0x80a1, .action = VIA_DXS_NO_VRA }, /* ASUS A7V8-X */ - { .vendor = 0x1043, .device = 0x80b0, .action = VIA_DXS_NO_VRA }, /* ASUS A7V600 & K8V*/ - { .vendor = 0x10cf, .device = 0x118e, .action = VIA_DXS_ENABLE }, /* FSC laptop */ - { .vendor = 0x1106, .device = 0x4161, .action = VIA_DXS_NO_VRA }, /* ASRock K7VT2 */ - { .vendor = 0x1106, .device = 0xaa01, .action = VIA_DXS_NO_VRA }, /* EPIA MII */ - { .vendor = 0x1297, .device = 0xa232, .action = VIA_DXS_ENABLE }, /* Shuttle ?? */ - { .vendor = 0x1297, .device = 0xc160, .action = VIA_DXS_ENABLE }, /* Shuttle SK41G */ - { .vendor = 0x1458, .device = 0xa002, .action = VIA_DXS_NO_VRA }, /* Gigabyte GA-7VAXP (FIXME: or DXS_ENABLE?) */ - { .vendor = 0x147b, .device = 0x1401, .action = VIA_DXS_ENABLE }, /* ABIT KD7(-RAID) */ - { .vendor = 0x14ff, .device = 0x0403, .action = VIA_DXS_ENABLE }, /* Twinhead mobo */ - { .vendor = 0x1462, .device = 0x3800, .action = VIA_DXS_ENABLE }, /* MSI KT266 */ - { .vendor = 0x1462, .device = 0x7120, .action = VIA_DXS_ENABLE }, /* MSI KT4V */ - { .vendor = 0x1462, .device = 0x5901, .action = VIA_DXS_NO_VRA }, /* MSI KT6 Delta-SR */ - { .vendor = 0x1584, .device = 0x8120, .action = VIA_DXS_ENABLE }, /* Gericom/Targa/Vobis/Uniwill laptop */ - { .vendor = 0x1631, .device = 0xe004, .action = VIA_DXS_ENABLE }, /* Easy Note 3174, Packard Bell */ - { .vendor = 0x1695, .device = 0x3005, .action = VIA_DXS_ENABLE }, /* EPoX EP-8K9A */ - { .vendor = 0x1849, .device = 0x3059, .action = VIA_DXS_NO_VRA }, /* ASRock K7VM2 */ + { .subvendor = 0x1005, .subdevice = 0x4710, .action = VIA_DXS_ENABLE }, /* Avance Logic Mobo */ + { .subvendor = 0x1019, .subdevice = 0x0996, .action = VIA_DXS_48K }, + { .subvendor = 0x1019, .subdevice = 0x0a81, .action = VIA_DXS_NO_VRA }, /* ECS K7VTA3 v8.0 */ + { .subvendor = 0x1019, .subdevice = 0x0a85, .action = VIA_DXS_NO_VRA }, /* ECS L7VMM2 */ + { .subvendor = 0x1019, .subdevice = 0xa101, .action = VIA_DXS_SRC }, + { .subvendor = 0x1019, .subdevice = 0xaa01, .action = VIA_DXS_SRC }, /* ECS K8T890-A */ + { .subvendor = 0x1025, .subdevice = 0x0033, .action = VIA_DXS_NO_VRA }, /* Acer Inspire 1353LM */ + { .subvendor = 0x1025, .subdevice = 0x0046, .action = VIA_DXS_SRC }, /* Acer Aspire 1524 WLMi */ + { .subvendor = 0x1043, .subdevice = 0x8095, .action = VIA_DXS_NO_VRA }, /* ASUS A7V8X (FIXME: possibly VIA_DXS_ENABLE?)*/ + { .subvendor = 0x1043, .subdevice = 0x80a1, .action = VIA_DXS_NO_VRA }, /* ASUS A7V8-X */ + { .subvendor = 0x1043, .subdevice = 0x80b0, .action = VIA_DXS_NO_VRA }, /* ASUS A7V600 & K8V*/ + { .subvendor = 0x1043, .subdevice = 0x810d, .action = VIA_DXS_SRC }, /* ASUS */ + { .subvendor = 0x1043, .subdevice = 0x812a, .action = VIA_DXS_SRC }, /* ASUS A8V Deluxe */ + { .subvendor = 0x1043, .subdevice = 0x8174, .action = VIA_DXS_SRC }, /* ASUS */ + { .subvendor = 0x1043, .subdevice = 0x81b9, .action = VIA_DXS_SRC }, /* ASUS A8V-MX */ + { .subvendor = 0x1071, .subdevice = 0x8375, .action = VIA_DXS_NO_VRA }, /* Vobis/Yakumo/Mitac notebook */ + { .subvendor = 0x1071, .subdevice = 0x8399, .action = VIA_DXS_NO_VRA }, /* Umax AB 595T (VIA K8N800A - VT8237) */ + { .subvendor = 0x10cf, .subdevice = 0x118e, .action = VIA_DXS_ENABLE }, /* FSC laptop */ + { .subvendor = 0x1106, .subdevice = 0x4161, .action = VIA_DXS_NO_VRA }, /* ASRock K7VT2 */ + { .subvendor = 0x1106, .subdevice = 0x4552, .action = VIA_DXS_NO_VRA }, /* QDI Kudoz 7X/600-6AL */ + { .subvendor = 0x1106, .subdevice = 0xaa01, .action = VIA_DXS_NO_VRA }, /* EPIA MII */ + { .subvendor = 0x1106, .subdevice = 0xc001, .action = VIA_DXS_SRC }, /* Insight P4-ITX */ + { .subvendor = 0x1297, .subdevice = 0xa232, .action = VIA_DXS_ENABLE }, /* Shuttle ?? */ + { .subvendor = 0x1297, .subdevice = 0xc160, .action = VIA_DXS_ENABLE }, /* Shuttle SK41G */ + { .subvendor = 0x1458, .subdevice = 0xa002, .action = VIA_DXS_ENABLE }, /* Gigabyte GA-7VAXP */ + { .subvendor = 0x1462, .subdevice = 0x0080, .action = VIA_DXS_SRC }, /* MSI K8T Neo-FIS2R */ + { .subvendor = 0x1462, .subdevice = 0x0430, .action = VIA_DXS_SRC }, /* MSI 7142 (K8MM-V) */ + { .subvendor = 0x1462, .subdevice = 0x0470, .action = VIA_DXS_SRC }, /* MSI KT880 Delta-FSR */ + { .subvendor = 0x1462, .subdevice = 0x3800, .action = VIA_DXS_ENABLE }, /* MSI KT266 */ + { .subvendor = 0x1462, .subdevice = 0x5901, .action = VIA_DXS_NO_VRA }, /* MSI KT6 Delta-SR */ + { .subvendor = 0x1462, .subdevice = 0x7023, .action = VIA_DXS_NO_VRA }, /* MSI K8T Neo2-FI */ + { .subvendor = 0x1462, .subdevice = 0x7120, .action = VIA_DXS_ENABLE }, /* MSI KT4V */ + { .subvendor = 0x1462, .subdevice = 0x7142, .action = VIA_DXS_ENABLE }, /* MSI K8MM-V */ + { .subvendor = 0x1462, .subdevice = 0xb012, .action = VIA_DXS_SRC }, /* P4M800/VIA8237R */ + { .subvendor = 0x147b, .subdevice = 0x1401, .action = VIA_DXS_ENABLE }, /* ABIT KD7(-RAID) */ + { .subvendor = 0x147b, .subdevice = 0x1411, .action = VIA_DXS_ENABLE }, /* ABIT VA-20 */ + { .subvendor = 0x147b, .subdevice = 0x1413, .action = VIA_DXS_ENABLE }, /* ABIT KV8 Pro */ + { .subvendor = 0x147b, .subdevice = 0x1415, .action = VIA_DXS_NO_VRA }, /* Abit AV8 */ + { .subvendor = 0x14ff, .subdevice = 0x0403, .action = VIA_DXS_ENABLE }, /* Twinhead mobo */ + { .subvendor = 0x14ff, .subdevice = 0x0408, .action = VIA_DXS_SRC }, /* Twinhead laptop */ + { .subvendor = 0x1558, .subdevice = 0x4701, .action = VIA_DXS_SRC }, /* Clevo D470 */ + { .subvendor = 0x1584, .subdevice = 0x8120, .action = VIA_DXS_ENABLE }, /* Gericom/Targa/Vobis/Uniwill laptop */ + { .subvendor = 0x1584, .subdevice = 0x8123, .action = VIA_DXS_NO_VRA }, /* Uniwill (Targa Visionary XP-210) */ + { .subvendor = 0x161f, .subdevice = 0x202b, .action = VIA_DXS_NO_VRA }, /* Amira Note book */ + { .subvendor = 0x161f, .subdevice = 0x2032, .action = VIA_DXS_48K }, /* m680x machines */ + { .subvendor = 0x1631, .subdevice = 0xe004, .action = VIA_DXS_ENABLE }, /* Easy Note 3174, Packard Bell */ + { .subvendor = 0x1695, .subdevice = 0x3005, .action = VIA_DXS_ENABLE }, /* EPoX EP-8K9A */ + { .subvendor = 0x1695, .subdevice = 0x300c, .action = VIA_DXS_SRC }, /* EPoX EP-8KRAI */ + { .subvendor = 0x1695, .subdevice = 0x300e, .action = VIA_DXS_SRC }, /* EPoX 9HEAI */ + { .subvendor = 0x16f3, .subdevice = 0x6405, .action = VIA_DXS_SRC }, /* Jetway K8M8MS */ + { .subvendor = 0x1734, .subdevice = 0x1078, .action = VIA_DXS_SRC }, /* FSC Amilo L7300 */ + { .subvendor = 0x1734, .subdevice = 0x1093, .action = VIA_DXS_SRC }, /* FSC */ + { .subvendor = 0x1849, .subdevice = 0x3059, .action = VIA_DXS_NO_VRA }, /* ASRock K7VM2 */ + { .subvendor = 0x1849, .subdevice = 0x9739, .action = VIA_DXS_SRC }, /* ASRock mobo(?) */ + { .subvendor = 0x1849, .subdevice = 0x9761, .action = VIA_DXS_SRC }, /* ASRock mobo(?) */ + { .subvendor = 0x1919, .subdevice = 0x200a, .action = VIA_DXS_NO_VRA }, /* Soltek SL-K8Tpro-939 */ + { .subvendor = 0x4005, .subdevice = 0x4710, .action = VIA_DXS_SRC }, /* MSI K7T266 Pro2 (MS-6380 V2.0) BIOS 3.7 */ { } /* terminator */ }; struct dxs_whitelist *w; @@ -2037,46 +2401,43 @@ static int __devinit check_dxs_list(struct pci_dev *pci) pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor); pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device); - for (w = whitelist; w->vendor; w++) { - if (w->vendor != subsystem_vendor) + for (w = whitelist; w->subvendor; w++) { + if (w->subvendor != subsystem_vendor) continue; if (w->mask) { - if ((w->mask & subsystem_device) == w->device) + if ((w->mask & subsystem_device) == w->subdevice) return w->action; } else { - if (subsystem_device == w->device) + if (subsystem_device == w->subdevice) return w->action; } } + /* for newer revision, default to DXS_SRC */ + if (revision >= VIA_REV_8235) + return VIA_DXS_SRC; + /* * not detected, try 48k rate only to be sure. */ printk(KERN_INFO "via82xx: Assuming DXS channels with 48k fixed sample rate.\n"); - printk(KERN_INFO " Please try dxs_support=1 or dxs_support=4 option\n"); + printk(KERN_INFO " Please try dxs_support=5 option\n"); printk(KERN_INFO " and report if it works on your machine.\n"); + printk(KERN_INFO " For more details, read ALSA-Configuration.txt.\n"); return VIA_DXS_48K; }; static int __devinit snd_via82xx_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { - static int dev; - snd_card_t *card; - via82xx_t *chip; + struct snd_card *card; + struct via82xx *chip; unsigned char revision; int chip_type = 0, card_type; unsigned int i; int err; - if (dev >= SNDRV_CARDS) - return -ENODEV; - if (!enable[dev]) { - dev++; - return -ENOENT; - } - - card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); + card = snd_card_new(index, id, THIS_MODULE, 0); if (card == NULL) return -ENOMEM; @@ -2099,18 +2460,20 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci, } } if (chip_type != TYPE_VIA8233A) { - if (dxs_support[dev] == VIA_DXS_AUTO) - dxs_support[dev] = check_dxs_list(pci); + if (dxs_support == VIA_DXS_AUTO) + dxs_support = check_dxs_list(pci, revision); /* force to use VIA8233 or 8233A model according to * dxs_support module option */ - if (dxs_support[dev] == VIA_DXS_DISABLE) + if (dxs_support == VIA_DXS_DISABLE) chip_type = TYPE_VIA8233A; else chip_type = TYPE_VIA8233; } if (chip_type == TYPE_VIA8233A) strcpy(card->driver, "VIA8233A"); + else if (revision >= VIA_REV_8237) + strcpy(card->driver, "VIA8237"); /* no slog assignment */ else strcpy(card->driver, "VIA8233"); break; @@ -2120,14 +2483,16 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci, goto __error; } - if ((err = snd_via82xx_create(card, pci, chip_type, revision, ac97_clock[dev], &chip)) < 0) + if ((err = snd_via82xx_create(card, pci, chip_type, revision, + ac97_clock, &chip)) < 0) goto __error; - if ((err = snd_via82xx_mixer_new(chip, ac97_quirk[dev])) < 0) + card->private_data = chip; + if ((err = snd_via82xx_mixer_new(chip, ac97_quirk)) < 0) goto __error; if (chip_type == TYPE_VIA686) { if ((err = snd_via686_pcm_new(chip)) < 0 || - (err = snd_via686_init_misc(chip, dev)) < 0) + (err = snd_via686_init_misc(chip)) < 0) goto __error; } else { if (chip_type == TYPE_VIA8233A) { @@ -2137,20 +2502,26 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci, } else { if ((err = snd_via8233_pcm_new(chip)) < 0) goto __error; - if (dxs_support[dev] == VIA_DXS_48K) + if (dxs_support == VIA_DXS_48K) chip->dxs_fixed = 1; - else if (dxs_support[dev] == VIA_DXS_NO_VRA) + else if (dxs_support == VIA_DXS_NO_VRA) chip->no_vra = 1; + else if (dxs_support == VIA_DXS_SRC) { + chip->no_vra = 1; + chip->dxs_src = 1; + } } - if ((err = snd_via8233_init_misc(chip, dev)) < 0) + if ((err = snd_via8233_init_misc(chip)) < 0) goto __error; } + /* disable interrupts */ for (i = 0; i < chip->num_devs; i++) snd_via82xx_channel_reset(chip, &chip->devs[i]); - sprintf(card->longname, "%s at 0x%lx, irq %d", - card->shortname, chip->port, chip->irq); + snprintf(card->longname, sizeof(card->longname), + "%s with %s at %#lx, irq %d", card->shortname, + snd_ac97_get_short_name(chip->ac97), chip->port, chip->irq); snd_via82xx_proc_init(chip); @@ -2159,7 +2530,6 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci, return err; } pci_set_drvdata(pci, card); - dev++; return 0; __error: @@ -2178,19 +2548,15 @@ static struct pci_driver driver = { .id_table = snd_via82xx_ids, .probe = snd_via82xx_probe, .remove = __devexit_p(snd_via82xx_remove), +#ifdef CONFIG_PM + .suspend = snd_via82xx_suspend, + .resume = snd_via82xx_resume, +#endif }; static int __init alsa_card_via82xx_init(void) { - int err; - - if ((err = pci_module_init(&driver)) < 0) { -#ifdef MODULE - printk(KERN_ERR "VIA 82xx soundcard not found or device busy\n"); -#endif - return err; - } - return 0; + return pci_register_driver(&driver); } static void __exit alsa_card_via82xx_exit(void) @@ -2200,33 +2566,3 @@ static void __exit alsa_card_via82xx_exit(void) module_init(alsa_card_via82xx_init) module_exit(alsa_card_via82xx_exit) - -#ifndef MODULE - -/* format is: snd-via82xx=enable,index,id, - mpu_port,joystick, - ac97_quirk,ac97_clock,dxs_support */ - -static int __init alsa_card_via82xx_setup(char *str) -{ - static unsigned __initdata nr_dev = 0; - - if (nr_dev >= SNDRV_CARDS) - return 0; - (void)(get_option(&str,&enable[nr_dev]) == 2 && - get_option(&str,&index[nr_dev]) == 2 && - get_id(&str,&id[nr_dev]) == 2 && - get_option_long(&str,&mpu_port[nr_dev]) == 2 && -#ifdef SUPPORT_JOYSTICK - get_option(&str,&joystick[nr_dev]) == 2 && -#endif - get_option(&str,&ac97_quirk[nr_dev]) == 2 && - get_option(&str,&ac97_clock[nr_dev]) == 2 && - get_option(&str,&dxs_support[nr_dev]) == 2); - nr_dev++; - return 1; -} - -__setup("snd-via82xx=", alsa_card_via82xx_setup); - -#endif /* ifndef MODULE */