X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=sound%2Fpci%2Fatiixp.c;h=347e25ff073dba9e5af492908f2a9190f1473413;hb=16c70f8c1b54b61c3b951b6fb220df250fe09b32;hp=8869e7a68a27deeff85148cba023f3d6d306a859;hpb=9213980e6a70d8473e0ffd4b39ab5b6caaba9ff5;p=linux-2.6.git diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c index 8869e7a68..347e25ff0 100644 --- a/sound/pci/atiixp.c +++ b/sound/pci/atiixp.c @@ -1,5 +1,5 @@ /* - * ALSA driver for ATI IXP 150/200/250 AC97 controllers + * ALSA driver for ATI IXP 150/200/250/300 AC97 controllers * * Copyright (c) 2004 Takashi Iwai * @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -37,31 +38,28 @@ MODULE_AUTHOR("Takashi Iwai "); MODULE_DESCRIPTION("ATI IXP AC97 controller"); MODULE_LICENSE("GPL"); -MODULE_CLASSES("{sound}"); -MODULE_DEVICES("{{ATI,IXP150/200/250/300}}"); +MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250/300/400}}"); -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 int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 48000}; -static int spdif_aclink[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; -static int boot_devs; +static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ +static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ +static int ac97_clock = 48000; +static char *ac97_quirk; +static int spdif_aclink = 1; -module_param_array(index, int, boot_devs, 0444); +module_param(index, int, 0444); MODULE_PARM_DESC(index, "Index value for ATI IXP controller."); -MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC); -module_param_array(id, charp, boot_devs, 0444); +module_param(id, charp, 0444); MODULE_PARM_DESC(id, "ID string for ATI IXP controller."); -MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC); -module_param_array(enable, bool, boot_devs, 0444); -MODULE_PARM_DESC(enable, "Enable audio part of ATI IXP controller."); -MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC); -module_param_array(ac97_clock, int, boot_devs, 0444); +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_param_array(spdif_aclink, bool, boot_devs, 0444); +module_param(ac97_quirk, charp, 0444); +MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); +module_param(spdif_aclink, bool, 0444); MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link."); -MODULE_PARM_SYNTAX(spdif_aclink, SNDRV_ENABLED "," SNDRV_BOOLEAN_TRUE_DESC); + +/* just for backward compatibility */ +static int enable; +module_param(enable, bool, 0444); /* @@ -197,29 +195,21 @@ MODULE_PARM_SYNTAX(spdif_aclink, SNDRV_ENABLED "," SNDRV_BOOLEAN_TRUE_DESC); #define ATI_REG_DMA_STATE (7U<<26) -#define ATI_MEM_REGION 256 /* i/o memory size */ #define ATI_MAX_DESCRIPTORS 256 /* max number of descriptor packets */ -/* - */ - -typedef struct snd_atiixp atiixp_t; -typedef struct snd_atiixp_dma atiixp_dma_t; -typedef struct snd_atiixp_dma_ops atiixp_dma_ops_t; -#define chip_t atiixp_t - +struct atiixp; /* * DMA packate descriptor */ -typedef struct atiixp_dma_desc { +struct atiixp_dma_desc { u32 addr; /* DMA buffer address */ u16 status; /* status bits */ u16 size; /* size of the packet in dwords */ u32 next; /* address of the next packet descriptor */ -} atiixp_dma_desc_t; +}; /* * stream enum @@ -234,63 +224,61 @@ enum { ATI_PCMDEV_ANALOG, ATI_PCMDEV_DIGITAL, NUM_ATI_PCMDEVS }; /* pcm devices /* * constants and callbacks for each DMA type */ -struct snd_atiixp_dma_ops { +struct atiixp_dma_ops { int type; /* ATI_DMA_XXX */ unsigned int llp_offset; /* LINKPTR offset */ unsigned int dt_cur; /* DT_CUR offset */ - void (*enable_dma)(atiixp_t *chip, int on); /* called from open callback */ - void (*enable_transfer)(atiixp_t *chip, int on); /* called from trigger (START/STOP) */ - void (*flush_dma)(atiixp_t *chip); /* called from trigger (STOP only) */ + /* called from open callback */ + void (*enable_dma)(struct atiixp *chip, int on); + /* called from trigger (START/STOP) */ + void (*enable_transfer)(struct atiixp *chip, int on); + /* called from trigger (STOP only) */ + void (*flush_dma)(struct atiixp *chip); }; /* * DMA stream */ -struct snd_atiixp_dma { - const atiixp_dma_ops_t *ops; - struct snd_dma_device desc_dev; +struct atiixp_dma { + const struct atiixp_dma_ops *ops; struct snd_dma_buffer desc_buf; - snd_pcm_substream_t *substream; /* assigned PCM substream */ + struct snd_pcm_substream *substream; /* assigned PCM substream */ unsigned int buf_addr, buf_bytes; /* DMA buffer address, bytes */ unsigned int period_bytes, periods; int opened; int running; + int suspended; int pcm_open_flag; int ac97_pcm_type; /* index # of ac97_pcm to access, -1 = not used */ + unsigned int saved_curptr; }; /* * ATI IXP chip */ -struct snd_atiixp { - snd_card_t *card; +struct atiixp { + struct snd_card *card; struct pci_dev *pci; - struct resource *res; /* memory i/o */ unsigned long addr; - unsigned long remap_addr; + void __iomem *remap_addr; int irq; - ac97_bus_t *ac97_bus; - ac97_t *ac97[NUM_ATI_CODECS]; + struct snd_ac97_bus *ac97_bus; + struct snd_ac97 *ac97[NUM_ATI_CODECS]; spinlock_t reg_lock; - spinlock_t ac97_lock; - atiixp_dma_t dmas[NUM_ATI_DMAS]; + struct atiixp_dma dmas[NUM_ATI_DMAS]; struct ac97_pcm *pcms[NUM_ATI_PCMS]; - snd_pcm_t *pcmdevs[NUM_ATI_PCMDEVS]; + struct snd_pcm *pcmdevs[NUM_ATI_PCMDEVS]; int max_channels; /* max. channels for PCM out */ unsigned int codec_not_ready_bits; /* for codec detection */ int spdif_over_aclink; /* passed from the module option */ - struct semaphore open_mutex; /* playback open mutex */ - -#ifdef CONFIG_PM - u32 pci_state[16]; -#endif + struct mutex open_mutex; /* playback open mutex */ }; @@ -299,6 +287,7 @@ struct snd_atiixp { static struct pci_device_id snd_atiixp_ids[] = { { 0x1002, 0x4341, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB200 */ { 0x1002, 0x4361, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB300 */ + { 0x1002, 0x4370, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* SB400 */ { 0, } }; @@ -313,10 +302,10 @@ MODULE_DEVICE_TABLE(pci, snd_atiixp_ids); * update the bits of the given register. * return 1 if the bits changed. */ -static int snd_atiixp_update_bits(atiixp_t *chip, unsigned int reg, +static int snd_atiixp_update_bits(struct atiixp *chip, unsigned int reg, unsigned int mask, unsigned int value) { - unsigned long addr = chip->remap_addr + reg; + void __iomem *addr = chip->remap_addr + reg; unsigned int data, old_data; old_data = data = readl(addr); data &= ~mask; @@ -337,13 +326,6 @@ static int snd_atiixp_update_bits(atiixp_t *chip, unsigned int reg, #define atiixp_update(chip,reg,mask,val) \ snd_atiixp_update_bits(chip, ATI_REG_##reg, mask, val) -/* delay for one tick */ -#define do_delay() do { \ - set_current_state(TASK_UNINTERRUPTIBLE); \ - schedule_timeout(1); \ -} while (0) - - /* * handling DMA packets * @@ -352,7 +334,7 @@ static int snd_atiixp_update_bits(atiixp_t *chip, unsigned int reg, */ #define ATI_DESC_LIST_SIZE \ - PAGE_ALIGN(ATI_MAX_DESCRIPTORS * sizeof(atiixp_dma_desc_t)) + PAGE_ALIGN(ATI_MAX_DESCRIPTORS * sizeof(struct atiixp_dma_desc)) /* * build packets ring for the given buffer size. @@ -363,10 +345,10 @@ static int snd_atiixp_update_bits(atiixp_t *chip, unsigned int reg, * * the ring is built in this function, and is set up to the hardware. */ -static int atiixp_build_dma_packets(atiixp_t *chip, atiixp_dma_t *dma, - snd_pcm_substream_t *substream, - unsigned int periods, - unsigned int period_bytes) +static int atiixp_build_dma_packets(struct atiixp *chip, struct atiixp_dma *dma, + struct snd_pcm_substream *substream, + unsigned int periods, + unsigned int period_bytes) { unsigned int i; u32 addr, desc_addr; @@ -376,15 +358,15 @@ static int atiixp_build_dma_packets(atiixp_t *chip, atiixp_dma_t *dma, return -ENOMEM; if (dma->desc_buf.area == NULL) { - memset(&dma->desc_dev, 0, sizeof(dma->desc_dev)); - dma->desc_dev.type = SNDRV_DMA_TYPE_DEV; - dma->desc_dev.dev = snd_dma_pci_data(chip->pci); - if (snd_dma_alloc_pages(&dma->desc_dev, ATI_DESC_LIST_SIZE, &dma->desc_buf) < 0) + if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, + snd_dma_pci_data(chip->pci), + ATI_DESC_LIST_SIZE, + &dma->desc_buf) < 0) return -ENOMEM; dma->period_bytes = dma->periods = 0; /* clear */ } - if (dma->periods == dma->periods && dma->period_bytes == period_bytes) + if (dma->periods == periods && dma->period_bytes == period_bytes) return 0; /* reset DMA before changing the descriptor table */ @@ -398,11 +380,12 @@ static int atiixp_build_dma_packets(atiixp_t *chip, atiixp_dma_t *dma, addr = (u32)substream->runtime->dma_addr; desc_addr = (u32)dma->desc_buf.addr; for (i = 0; i < periods; i++) { - atiixp_dma_desc_t *desc = &((atiixp_dma_desc_t *)dma->desc_buf.area)[i]; + struct atiixp_dma_desc *desc; + desc = &((struct atiixp_dma_desc *)dma->desc_buf.area)[i]; desc->addr = cpu_to_le32(addr); desc->status = 0; desc->size = period_bytes >> 2; /* in dwords */ - desc_addr += sizeof(atiixp_dma_desc_t); + desc_addr += sizeof(struct atiixp_dma_desc); if (i == periods - 1) desc->next = cpu_to_le32((u32)dma->desc_buf.addr); else @@ -422,11 +405,12 @@ static int atiixp_build_dma_packets(atiixp_t *chip, atiixp_dma_t *dma, /* * remove the ring buffer and release it if assigned */ -static void atiixp_clear_dma_packets(atiixp_t *chip, atiixp_dma_t *dma, snd_pcm_substream_t *substream) +static void atiixp_clear_dma_packets(struct atiixp *chip, struct atiixp_dma *dma, + struct snd_pcm_substream *substream) { if (dma->desc_buf.area) { writel(0, chip->remap_addr + dma->ops->llp_offset); - snd_dma_free_pages(&dma->desc_dev, &dma->desc_buf); + snd_dma_free_pages(&dma->desc_buf); dma->desc_buf.area = NULL; } } @@ -434,7 +418,7 @@ static void atiixp_clear_dma_packets(atiixp_t *chip, atiixp_dma_t *dma, snd_pcm_ /* * AC97 interface */ -static int snd_atiixp_acquire_codec(atiixp_t *chip) +static int snd_atiixp_acquire_codec(struct atiixp *chip) { int timeout = 1000; @@ -448,7 +432,7 @@ static int snd_atiixp_acquire_codec(atiixp_t *chip) return 0; } -static unsigned short snd_atiixp_codec_read(atiixp_t *chip, unsigned short codec, unsigned short reg) +static unsigned short snd_atiixp_codec_read(struct atiixp *chip, unsigned short codec, unsigned short reg) { unsigned int data; int timeout; @@ -476,7 +460,8 @@ static unsigned short snd_atiixp_codec_read(atiixp_t *chip, unsigned short codec } -static void snd_atiixp_codec_write(atiixp_t *chip, unsigned short codec, unsigned short reg, unsigned short val) +static void snd_atiixp_codec_write(struct atiixp *chip, unsigned short codec, + unsigned short reg, unsigned short val) { unsigned int data; @@ -489,29 +474,25 @@ static void snd_atiixp_codec_write(atiixp_t *chip, unsigned short codec, unsigne } -static unsigned short snd_atiixp_ac97_read(ac97_t *ac97, unsigned short reg) +static unsigned short snd_atiixp_ac97_read(struct snd_ac97 *ac97, + unsigned short reg) { - atiixp_t *chip = snd_magic_cast(atiixp_t, ac97->private_data, return 0xffff); - unsigned short data; - spin_lock(&chip->ac97_lock); - data = snd_atiixp_codec_read(chip, ac97->num, reg); - spin_unlock(&chip->ac97_lock); - return data; + struct atiixp *chip = ac97->private_data; + return snd_atiixp_codec_read(chip, ac97->num, reg); } -static void snd_atiixp_ac97_write(ac97_t *ac97, unsigned short reg, unsigned short val) +static void snd_atiixp_ac97_write(struct snd_ac97 *ac97, unsigned short reg, + unsigned short val) { - atiixp_t *chip = snd_magic_cast(atiixp_t, ac97->private_data, return); - spin_lock(&chip->ac97_lock); + struct atiixp *chip = ac97->private_data; snd_atiixp_codec_write(chip, ac97->num, reg, val); - spin_unlock(&chip->ac97_lock); } /* * reset AC link */ -static int snd_atiixp_aclink_reset(atiixp_t *chip) +static int snd_atiixp_aclink_reset(struct atiixp *chip) { int timeout; @@ -531,7 +512,7 @@ static int snd_atiixp_aclink_reset(atiixp_t *chip) atiixp_update(chip, CMD, ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_SYNC); atiixp_read(chip, CMD); - do_delay(); + mdelay(1); atiixp_update(chip, CMD, ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_RESET); if (--timeout) { snd_printk(KERN_ERR "atiixp: codec reset timeout\n"); @@ -547,7 +528,7 @@ static int snd_atiixp_aclink_reset(atiixp_t *chip) } #ifdef CONFIG_PM -static int snd_atiixp_aclink_down(atiixp_t *chip) +static int snd_atiixp_aclink_down(struct atiixp *chip) { // if (atiixp_read(chip, MODEM_MIRROR) & 0x1) /* modem running, too? */ // return -EBUSY; @@ -572,16 +553,16 @@ static int snd_atiixp_aclink_down(atiixp_t *chip) ATI_REG_ISR_CODEC2_NOT_READY) #define CODEC_CHECK_BITS (ALL_CODEC_NOT_READY|ATI_REG_ISR_NEW_FRAME) -static int snd_atiixp_codec_detect(atiixp_t *chip) +static int snd_atiixp_codec_detect(struct atiixp *chip) { int timeout; chip->codec_not_ready_bits = 0; atiixp_write(chip, IER, CODEC_CHECK_BITS); /* wait for the interrupts */ - timeout = HZ / 10; + timeout = 50; while (timeout-- > 0) { - do_delay(); + mdelay(1); if (chip->codec_not_ready_bits) break; } @@ -598,7 +579,7 @@ static int snd_atiixp_codec_detect(atiixp_t *chip) /* * enable DMA and irqs */ -static int snd_atiixp_chip_start(atiixp_t *chip) +static int snd_atiixp_chip_start(struct atiixp *chip) { unsigned int reg; @@ -628,7 +609,7 @@ static int snd_atiixp_chip_start(atiixp_t *chip) /* * disable DMA and IRQs */ -static int snd_atiixp_chip_stop(atiixp_t *chip) +static int snd_atiixp_chip_stop(struct atiixp *chip) { /* clear interrupt source */ atiixp_write(chip, ISR, atiixp_read(chip, ISR)); @@ -647,34 +628,32 @@ static int snd_atiixp_chip_stop(atiixp_t *chip) * position. when SG-buffer is implemented, the offset must be calculated * correctly... */ -static snd_pcm_uframes_t snd_atiixp_pcm_pointer(snd_pcm_substream_t *substream) +static snd_pcm_uframes_t snd_atiixp_pcm_pointer(struct snd_pcm_substream *substream) { - atiixp_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - atiixp_dma_t *dma = (atiixp_dma_t *)runtime->private_data; + struct atiixp *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct atiixp_dma *dma = runtime->private_data; unsigned int curptr; - unsigned long flags; + int timeout = 1000; - spin_lock_irqsave(&chip->reg_lock, flags); - curptr = readl(chip->remap_addr + dma->ops->dt_cur); - if (curptr < dma->buf_addr) { - snd_printdd("curptr = %x, base = %x\n", curptr, dma->buf_addr); - curptr = 0; - } else { + while (timeout--) { + curptr = readl(chip->remap_addr + dma->ops->dt_cur); + if (curptr < dma->buf_addr) + continue; curptr -= dma->buf_addr; - if (curptr >= dma->buf_bytes) { - snd_printdd("curptr = %x, size = %x\n", curptr, dma->buf_bytes); - curptr = 0; - } + if (curptr >= dma->buf_bytes) + continue; + return bytes_to_frames(runtime, curptr); } - spin_unlock_irqrestore(&chip->reg_lock, flags); - return bytes_to_frames(runtime, curptr); + snd_printd("atiixp: invalid DMA pointer read 0x%x (buf=%x)\n", + readl(chip->remap_addr + dma->ops->dt_cur), dma->buf_addr); + return 0; } /* * XRUN detected, and stop the PCM substream */ -static void snd_atiixp_xrun_dma(atiixp_t *chip, atiixp_dma_t *dma) +static void snd_atiixp_xrun_dma(struct atiixp *chip, struct atiixp_dma *dma) { if (! dma->substream || ! dma->running) return; @@ -685,7 +664,7 @@ static void snd_atiixp_xrun_dma(atiixp_t *chip, atiixp_dma_t *dma) /* * the period ack. update the substream. */ -static void snd_atiixp_update_dma(atiixp_t *chip, atiixp_dma_t *dma) +static void snd_atiixp_update_dma(struct atiixp *chip, struct atiixp_dma *dma) { if (! dma->substream || ! dma->running) return; @@ -694,7 +673,7 @@ static void snd_atiixp_update_dma(atiixp_t *chip, atiixp_dma_t *dma) /* set BUS_BUSY interrupt bit if any DMA is running */ /* call with spinlock held */ -static void snd_atiixp_check_bus_busy(atiixp_t *chip) +static void snd_atiixp_check_bus_busy(struct atiixp *chip) { unsigned int bus_busy; if (atiixp_read(chip, CMD) & (ATI_REG_CMD_SEND_EN | @@ -709,10 +688,10 @@ static void snd_atiixp_check_bus_busy(atiixp_t *chip) /* common trigger callback * calling the lowlevel callbacks in it */ -static int snd_atiixp_pcm_trigger(snd_pcm_substream_t *substream, int cmd) +static int snd_atiixp_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { - atiixp_t *chip = snd_pcm_substream_chip(substream); - atiixp_dma_t *dma = (atiixp_dma_t *)substream->runtime->private_data; + struct atiixp *chip = snd_pcm_substream_chip(substream); + struct atiixp_dma *dma = substream->runtime->private_data; int err = 0; snd_assert(dma->ops->enable_transfer && dma->ops->flush_dma, return -EINVAL); @@ -720,12 +699,18 @@ static int snd_atiixp_pcm_trigger(snd_pcm_substream_t *substream, int cmd) spin_lock(&chip->reg_lock); switch (cmd) { case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + case SNDRV_PCM_TRIGGER_RESUME: dma->ops->enable_transfer(chip, 1); dma->running = 1; + dma->suspended = 0; break; case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: + case SNDRV_PCM_TRIGGER_SUSPEND: dma->ops->enable_transfer(chip, 0); dma->running = 0; + dma->suspended = cmd == SNDRV_PCM_TRIGGER_SUSPEND; break; default: err = -EINVAL; @@ -750,13 +735,13 @@ static int snd_atiixp_pcm_trigger(snd_pcm_substream_t *substream, int cmd) */ /* flush FIFO of analog OUT DMA */ -static void atiixp_out_flush_dma(atiixp_t *chip) +static void atiixp_out_flush_dma(struct atiixp *chip) { atiixp_write(chip, FIFO_FLUSH, ATI_REG_FIFO_OUT_FLUSH); } /* enable/disable analog OUT DMA */ -static void atiixp_out_enable_dma(atiixp_t *chip, int on) +static void atiixp_out_enable_dma(struct atiixp *chip, int on) { unsigned int data; data = atiixp_read(chip, CMD); @@ -771,21 +756,21 @@ static void atiixp_out_enable_dma(atiixp_t *chip, int on) } /* start/stop transfer over OUT DMA */ -static void atiixp_out_enable_transfer(atiixp_t *chip, int on) +static void atiixp_out_enable_transfer(struct atiixp *chip, int on) { atiixp_update(chip, CMD, ATI_REG_CMD_SEND_EN, on ? ATI_REG_CMD_SEND_EN : 0); } /* enable/disable analog IN DMA */ -static void atiixp_in_enable_dma(atiixp_t *chip, int on) +static void atiixp_in_enable_dma(struct atiixp *chip, int on) { atiixp_update(chip, CMD, ATI_REG_CMD_IN_DMA_EN, on ? ATI_REG_CMD_IN_DMA_EN : 0); } /* start/stop analog IN DMA */ -static void atiixp_in_enable_transfer(atiixp_t *chip, int on) +static void atiixp_in_enable_transfer(struct atiixp *chip, int on) { if (on) { unsigned int data = atiixp_read(chip, CMD); @@ -804,20 +789,20 @@ static void atiixp_in_enable_transfer(atiixp_t *chip, int on) } /* flush FIFO of analog IN DMA */ -static void atiixp_in_flush_dma(atiixp_t *chip) +static void atiixp_in_flush_dma(struct atiixp *chip) { atiixp_write(chip, FIFO_FLUSH, ATI_REG_FIFO_IN_FLUSH); } /* enable/disable SPDIF OUT DMA */ -static void atiixp_spdif_enable_dma(atiixp_t *chip, int on) +static void atiixp_spdif_enable_dma(struct atiixp *chip, int on) { atiixp_update(chip, CMD, ATI_REG_CMD_SPDF_DMA_EN, on ? ATI_REG_CMD_SPDF_DMA_EN : 0); } /* start/stop SPDIF OUT DMA */ -static void atiixp_spdif_enable_transfer(atiixp_t *chip, int on) +static void atiixp_spdif_enable_transfer(struct atiixp *chip, int on) { unsigned int data; data = atiixp_read(chip, CMD); @@ -829,7 +814,7 @@ static void atiixp_spdif_enable_transfer(atiixp_t *chip, int on) } /* flush FIFO of SPDIF OUT DMA */ -static void atiixp_spdif_flush_dma(atiixp_t *chip) +static void atiixp_spdif_flush_dma(struct atiixp *chip) { int timeout; @@ -848,11 +833,11 @@ static void atiixp_spdif_flush_dma(atiixp_t *chip) } /* set up slots and formats for SPDIF OUT */ -static int snd_atiixp_spdif_prepare(snd_pcm_substream_t *substream) +static int snd_atiixp_spdif_prepare(struct snd_pcm_substream *substream) { - atiixp_t *chip = snd_pcm_substream_chip(substream); + struct atiixp *chip = snd_pcm_substream_chip(substream); - spin_lock(&chip->reg_lock); + spin_lock_irq(&chip->reg_lock); if (chip->spdif_over_aclink) { unsigned int data; /* enable slots 10/11 */ @@ -870,17 +855,17 @@ static int snd_atiixp_spdif_prepare(snd_pcm_substream_t *substream) atiixp_update(chip, CMD, ATI_REG_CMD_SPDF_CONFIG_MASK, 0); atiixp_update(chip, CMD, ATI_REG_CMD_INTERLEAVE_SPDF, 0); } - spin_unlock(&chip->reg_lock); + spin_unlock_irq(&chip->reg_lock); return 0; } /* set up slots and formats for analog OUT */ -static int snd_atiixp_playback_prepare(snd_pcm_substream_t *substream) +static int snd_atiixp_playback_prepare(struct snd_pcm_substream *substream) { - atiixp_t *chip = snd_pcm_substream_chip(substream); + struct atiixp *chip = snd_pcm_substream_chip(substream); unsigned int data; - spin_lock(&chip->reg_lock); + spin_lock_irq(&chip->reg_lock); data = atiixp_read(chip, OUT_DMA_SLOT) & ~ATI_REG_OUT_DMA_SLOT_MASK; switch (substream->runtime->channels) { case 8: @@ -915,31 +900,31 @@ static int snd_atiixp_playback_prepare(snd_pcm_substream_t *substream) atiixp_update(chip, 6CH_REORDER, ATI_REG_6CH_REORDER_EN, substream->runtime->channels >= 6 ? ATI_REG_6CH_REORDER_EN: 0); - spin_unlock(&chip->reg_lock); + spin_unlock_irq(&chip->reg_lock); return 0; } /* set up slots and formats for analog IN */ -static int snd_atiixp_capture_prepare(snd_pcm_substream_t *substream) +static int snd_atiixp_capture_prepare(struct snd_pcm_substream *substream) { - atiixp_t *chip = snd_pcm_substream_chip(substream); + struct atiixp *chip = snd_pcm_substream_chip(substream); - spin_lock(&chip->reg_lock); + spin_lock_irq(&chip->reg_lock); atiixp_update(chip, CMD, ATI_REG_CMD_INTERLEAVE_IN, substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE ? ATI_REG_CMD_INTERLEAVE_IN : 0); - spin_unlock(&chip->reg_lock); + spin_unlock_irq(&chip->reg_lock); return 0; } /* * hw_params - allocate the buffer and set up buffer descriptors */ -static int snd_atiixp_pcm_hw_params(snd_pcm_substream_t *substream, - snd_pcm_hw_params_t *hw_params) +static int snd_atiixp_pcm_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { - atiixp_t *chip = snd_pcm_substream_chip(substream); - atiixp_dma_t *dma = (atiixp_dma_t *)substream->runtime->private_data; + struct atiixp *chip = snd_pcm_substream_chip(substream); + struct atiixp_dma *dma = substream->runtime->private_data; int err; err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); @@ -973,10 +958,10 @@ static int snd_atiixp_pcm_hw_params(snd_pcm_substream_t *substream, return err; } -static int snd_atiixp_pcm_hw_free(snd_pcm_substream_t * substream) +static int snd_atiixp_pcm_hw_free(struct snd_pcm_substream *substream) { - atiixp_t *chip = snd_pcm_substream_chip(substream); - atiixp_dma_t *dma = (atiixp_dma_t *)substream->runtime->private_data; + struct atiixp *chip = snd_pcm_substream_chip(substream); + struct atiixp_dma *dma = substream->runtime->private_data; if (dma->pcm_open_flag) { struct ac97_pcm *pcm = chip->pcms[dma->ac97_pcm_type]; @@ -992,10 +977,12 @@ static int snd_atiixp_pcm_hw_free(snd_pcm_substream_t * substream) /* * pcm hardware definition, identical for all DMA types */ -static snd_pcm_hardware_t snd_atiixp_pcm_hw = +static struct snd_pcm_hardware snd_atiixp_pcm_hw = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | + SNDRV_PCM_INFO_PAUSE | + SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID), .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, .rates = SNDRV_PCM_RATE_48000, @@ -1010,11 +997,11 @@ static snd_pcm_hardware_t snd_atiixp_pcm_hw = .periods_max = ATI_MAX_DESCRIPTORS, }; -static int snd_atiixp_pcm_open(snd_pcm_substream_t *substream, atiixp_dma_t *dma, int pcm_type) +static int snd_atiixp_pcm_open(struct snd_pcm_substream *substream, + struct atiixp_dma *dma, int pcm_type) { - atiixp_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; - unsigned long flags; + struct atiixp *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; int err; snd_assert(dma->ops && dma->ops->enable_dma, return -EINVAL); @@ -1036,17 +1023,18 @@ static int snd_atiixp_pcm_open(snd_pcm_substream_t *substream, atiixp_dma_t *dma runtime->private_data = dma; /* enable DMA bits */ - spin_lock_irqsave(&chip->reg_lock, flags); + spin_lock_irq(&chip->reg_lock); dma->ops->enable_dma(chip, 1); - spin_unlock_irqrestore(&chip->reg_lock, flags); + spin_unlock_irq(&chip->reg_lock); dma->opened = 1; return 0; } -static int snd_atiixp_pcm_close(snd_pcm_substream_t *substream, atiixp_dma_t *dma) +static int snd_atiixp_pcm_close(struct snd_pcm_substream *substream, + struct atiixp_dma *dma) { - atiixp_t *chip = snd_pcm_substream_chip(substream); + struct atiixp *chip = snd_pcm_substream_chip(substream); /* disable DMA bits */ snd_assert(dma->ops && dma->ops->enable_dma, return -EINVAL); spin_lock_irq(&chip->reg_lock); @@ -1059,14 +1047,14 @@ static int snd_atiixp_pcm_close(snd_pcm_substream_t *substream, atiixp_dma_t *dm /* */ -static int snd_atiixp_playback_open(snd_pcm_substream_t *substream) +static int snd_atiixp_playback_open(struct snd_pcm_substream *substream) { - atiixp_t *chip = snd_pcm_substream_chip(substream); + struct atiixp *chip = snd_pcm_substream_chip(substream); int err; - down(&chip->open_mutex); + mutex_lock(&chip->open_mutex); err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_PLAYBACK], 0); - up(&chip->open_mutex); + mutex_unlock(&chip->open_mutex); if (err < 0) return err; substream->runtime->hw.channels_max = chip->max_channels; @@ -1077,56 +1065,56 @@ static int snd_atiixp_playback_open(snd_pcm_substream_t *substream) return 0; } -static int snd_atiixp_playback_close(snd_pcm_substream_t *substream) +static int snd_atiixp_playback_close(struct snd_pcm_substream *substream) { - atiixp_t *chip = snd_pcm_substream_chip(substream); + struct atiixp *chip = snd_pcm_substream_chip(substream); int err; - down(&chip->open_mutex); + mutex_lock(&chip->open_mutex); err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_PLAYBACK]); - up(&chip->open_mutex); + mutex_unlock(&chip->open_mutex); return err; } -static int snd_atiixp_capture_open(snd_pcm_substream_t *substream) +static int snd_atiixp_capture_open(struct snd_pcm_substream *substream) { - atiixp_t *chip = snd_pcm_substream_chip(substream); + struct atiixp *chip = snd_pcm_substream_chip(substream); return snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_CAPTURE], 1); } -static int snd_atiixp_capture_close(snd_pcm_substream_t *substream) +static int snd_atiixp_capture_close(struct snd_pcm_substream *substream) { - atiixp_t *chip = snd_pcm_substream_chip(substream); + struct atiixp *chip = snd_pcm_substream_chip(substream); return snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_CAPTURE]); } -static int snd_atiixp_spdif_open(snd_pcm_substream_t *substream) +static int snd_atiixp_spdif_open(struct snd_pcm_substream *substream) { - atiixp_t *chip = snd_pcm_substream_chip(substream); + struct atiixp *chip = snd_pcm_substream_chip(substream); int err; - down(&chip->open_mutex); + mutex_lock(&chip->open_mutex); if (chip->spdif_over_aclink) /* share DMA_PLAYBACK */ err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_PLAYBACK], 2); else err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_SPDIF], -1); - up(&chip->open_mutex); + mutex_unlock(&chip->open_mutex); return err; } -static int snd_atiixp_spdif_close(snd_pcm_substream_t *substream) +static int snd_atiixp_spdif_close(struct snd_pcm_substream *substream) { - atiixp_t *chip = snd_pcm_substream_chip(substream); + struct atiixp *chip = snd_pcm_substream_chip(substream); int err; - down(&chip->open_mutex); + mutex_lock(&chip->open_mutex); if (chip->spdif_over_aclink) err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_PLAYBACK]); else err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_SPDIF]); - up(&chip->open_mutex); + mutex_unlock(&chip->open_mutex); return err; } /* AC97 playback */ -static snd_pcm_ops_t snd_atiixp_playback_ops = { +static struct snd_pcm_ops snd_atiixp_playback_ops = { .open = snd_atiixp_playback_open, .close = snd_atiixp_playback_close, .ioctl = snd_pcm_lib_ioctl, @@ -1138,7 +1126,7 @@ static snd_pcm_ops_t snd_atiixp_playback_ops = { }; /* AC97 capture */ -static snd_pcm_ops_t snd_atiixp_capture_ops = { +static struct snd_pcm_ops snd_atiixp_capture_ops = { .open = snd_atiixp_capture_open, .close = snd_atiixp_capture_close, .ioctl = snd_pcm_lib_ioctl, @@ -1150,7 +1138,7 @@ static snd_pcm_ops_t snd_atiixp_capture_ops = { }; /* SPDIF playback */ -static snd_pcm_ops_t snd_atiixp_spdif_ops = { +static struct snd_pcm_ops snd_atiixp_spdif_ops = { .open = snd_atiixp_spdif_open, .close = snd_atiixp_spdif_close, .ioctl = snd_pcm_lib_ioctl, @@ -1197,7 +1185,7 @@ static struct ac97_pcm atiixp_pcm_defs[] __devinitdata = { }, }; -static atiixp_dma_ops_t snd_atiixp_playback_dma_ops = { +static struct atiixp_dma_ops snd_atiixp_playback_dma_ops = { .type = ATI_DMA_PLAYBACK, .llp_offset = ATI_REG_OUT_DMA_LINKPTR, .dt_cur = ATI_REG_OUT_DMA_DT_CUR, @@ -1206,7 +1194,7 @@ static atiixp_dma_ops_t snd_atiixp_playback_dma_ops = { .flush_dma = atiixp_out_flush_dma, }; -static atiixp_dma_ops_t snd_atiixp_capture_dma_ops = { +static struct atiixp_dma_ops snd_atiixp_capture_dma_ops = { .type = ATI_DMA_CAPTURE, .llp_offset = ATI_REG_IN_DMA_LINKPTR, .dt_cur = ATI_REG_IN_DMA_DT_CUR, @@ -1215,7 +1203,7 @@ static atiixp_dma_ops_t snd_atiixp_capture_dma_ops = { .flush_dma = atiixp_in_flush_dma, }; -static atiixp_dma_ops_t snd_atiixp_spdif_dma_ops = { +static struct atiixp_dma_ops snd_atiixp_spdif_dma_ops = { .type = ATI_DMA_SPDIF, .llp_offset = ATI_REG_SPDF_DMA_LINKPTR, .dt_cur = ATI_REG_SPDF_DMA_DT_CUR, @@ -1225,10 +1213,10 @@ static atiixp_dma_ops_t snd_atiixp_spdif_dma_ops = { }; -static int __devinit snd_atiixp_pcm_new(atiixp_t *chip) +static int __devinit snd_atiixp_pcm_new(struct atiixp *chip) { - snd_pcm_t *pcm; - ac97_bus_t *pbus = chip->ac97_bus; + struct snd_pcm *pcm; + struct snd_ac97_bus *pbus = chip->ac97_bus; int err, i, num_pcms; /* initialize constants */ @@ -1257,7 +1245,8 @@ static int __devinit snd_atiixp_pcm_new(atiixp_t *chip) } /* PCM #0: analog I/O */ - err = snd_pcm_new(chip->card, "ATI IXP AC97", ATI_PCMDEV_ANALOG, 1, 1, &pcm); + err = snd_pcm_new(chip->card, "ATI IXP AC97", + ATI_PCMDEV_ANALOG, 1, 1, &pcm); if (err < 0) return err; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_atiixp_playback_ops); @@ -1267,7 +1256,8 @@ static int __devinit snd_atiixp_pcm_new(atiixp_t *chip) chip->pcmdevs[ATI_PCMDEV_ANALOG] = pcm; snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, - snd_dma_pci_data(chip->pci), 64*1024, 128*1024); + snd_dma_pci_data(chip->pci), + 64*1024, 128*1024); /* no SPDIF support on codec? */ if (chip->pcms[ATI_PCM_SPDIF] && ! chip->pcms[ATI_PCM_SPDIF]->rates) @@ -1278,7 +1268,8 @@ static int __devinit snd_atiixp_pcm_new(atiixp_t *chip) chip->pcms[ATI_PCM_SPDIF]->rates = SNDRV_PCM_RATE_48000; /* PCM #1: spdif playback */ - err = snd_pcm_new(chip->card, "ATI IXP IEC958", ATI_PCMDEV_DIGITAL, 1, 0, &pcm); + err = snd_pcm_new(chip->card, "ATI IXP IEC958", + ATI_PCMDEV_DIGITAL, 1, 0, &pcm); if (err < 0) return err; snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_atiixp_spdif_ops); @@ -1290,12 +1281,15 @@ static int __devinit snd_atiixp_pcm_new(atiixp_t *chip) chip->pcmdevs[ATI_PCMDEV_DIGITAL] = pcm; snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, - snd_dma_pci_data(chip->pci), 64*1024, 128*1024); + snd_dma_pci_data(chip->pci), + 64*1024, 128*1024); /* pre-select AC97 SPDIF slots 10/11 */ for (i = 0; i < NUM_ATI_CODECS; i++) { if (chip->ac97[i]) - snd_ac97_update_bits(chip->ac97[i], AC97_EXTENDED_STATUS, 0x03 << 4, 0x03 << 4); + snd_ac97_update_bits(chip->ac97[i], + AC97_EXTENDED_STATUS, + 0x03 << 4, 0x03 << 4); } return 0; @@ -1308,7 +1302,7 @@ static int __devinit snd_atiixp_pcm_new(atiixp_t *chip) */ static irqreturn_t snd_atiixp_interrupt(int irq, void *dev_id, struct pt_regs *regs) { - atiixp_t *chip = snd_magic_cast(atiixp_t, dev_id, return IRQ_NONE); + struct atiixp *chip = dev_id; unsigned int status; status = atiixp_read(chip, ISR); @@ -1353,12 +1347,33 @@ static irqreturn_t snd_atiixp_interrupt(int irq, void *dev_id, struct pt_regs *r * ac97 mixer section */ -static int __devinit snd_atiixp_mixer_new(atiixp_t *chip, int clock) +static struct ac97_quirk ac97_quirks[] __devinitdata = { + { + .subvendor = 0x103c, + .subdevice = 0x006b, + .name = "HP Pavilion ZV5030US", + .type = AC97_TUNE_MUTE_LED + }, + { + .subvendor = 0x103c, + .subdevice = 0x308b, + .name = "HP nx6125", + .type = AC97_TUNE_MUTE_LED + }, + { } /* terminator */ +}; + +static int __devinit snd_atiixp_mixer_new(struct atiixp *chip, int clock, + const char *quirk_override) { - ac97_bus_t bus, *pbus; - ac97_t ac97; + struct snd_ac97_bus *pbus; + struct snd_ac97_template ac97; int i, err; int codec_count; + static struct snd_ac97_bus_ops ops = { + .write = snd_atiixp_ac97_write, + .read = snd_atiixp_ac97_read, + }; static unsigned int codec_skip[NUM_ATI_CODECS] = { ATI_REG_ISR_CODEC0_NOT_READY, ATI_REG_ISR_CODEC1_NOT_READY, @@ -1368,13 +1383,9 @@ static int __devinit snd_atiixp_mixer_new(atiixp_t *chip, int clock) if (snd_atiixp_codec_detect(chip) < 0) return -ENXIO; - memset(&bus, 0, sizeof(bus)); - bus.write = snd_atiixp_ac97_write; - bus.read = snd_atiixp_ac97_read; - bus.private_data = chip; - bus.clock = clock; - if ((err = snd_ac97_bus(chip->card, &bus, &pbus)) < 0) + if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0) return err; + pbus->clock = clock; chip->ac97_bus = pbus; codec_count = 0; @@ -1386,18 +1397,12 @@ static int __devinit snd_atiixp_mixer_new(atiixp_t *chip, int clock) ac97.pci = chip->pci; ac97.num = i; ac97.scaps = AC97_SCAP_SKIP_MODEM; + if (! chip->spdif_over_aclink) + ac97.scaps |= AC97_SCAP_NO_SPDIF; if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) { - if (chip->codec_not_ready_bits) - /* codec(s) was detected but not available. - * return the error - */ - return err; - else { - /* codec(s) was NOT detected, so just ignore here */ - chip->ac97[i] = NULL; /* to be sure */ - snd_printd("atiixp: codec %d not found\n", i); - continue; - } + chip->ac97[i] = NULL; /* to be sure */ + snd_printdd("atiixp: codec %d not available for audio\n", i); + continue; } codec_count++; } @@ -1407,7 +1412,7 @@ static int __devinit snd_atiixp_mixer_new(atiixp_t *chip, int clock) return -ENODEV; } - /* snd_ac97_tune_hardware(chip->ac97, ac97_quirks); */ + snd_ac97_tune_hardware(chip->ac97[0], ac97_quirks, quirk_override); return 0; } @@ -1417,42 +1422,61 @@ static int __devinit snd_atiixp_mixer_new(atiixp_t *chip, int clock) /* * power management */ -static int snd_atiixp_suspend(snd_card_t *card, unsigned int state) +static int snd_atiixp_suspend(struct pci_dev *pci, pm_message_t state) { - atiixp_t *chip = snd_magic_cast(atiixp_t, card->pm_private_data, return -EINVAL); + struct snd_card *card = pci_get_drvdata(pci); + struct atiixp *chip = card->private_data; int i; + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); for (i = 0; i < NUM_ATI_PCMDEVS; i++) - if (chip->pcmdevs[i]) + if (chip->pcmdevs[i]) { + struct atiixp_dma *dma = &chip->dmas[i]; + if (dma->substream && dma->running) + dma->saved_curptr = readl(chip->remap_addr + + dma->ops->dt_cur); snd_pcm_suspend_all(chip->pcmdevs[i]); + } for (i = 0; i < NUM_ATI_CODECS; i++) - if (chip->ac97[i]) - snd_ac97_suspend(chip->ac97[i]); + snd_ac97_suspend(chip->ac97[i]); snd_atiixp_aclink_down(chip); snd_atiixp_chip_stop(chip); - pci_save_state(chip->pci, chip->pci_state); - pci_set_power_state(chip->pci, 3); - pci_disable_device(chip->pci); - snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); + pci_set_power_state(pci, PCI_D3hot); + pci_disable_device(pci); + pci_save_state(pci); return 0; } -static int snd_atiixp_resume(snd_card_t *card, unsigned int state) +static int snd_atiixp_resume(struct pci_dev *pci) { - atiixp_t *chip = snd_magic_cast(atiixp_t, card->pm_private_data, return -EINVAL); + struct snd_card *card = pci_get_drvdata(pci); + struct atiixp *chip = card->private_data; int i; - pci_enable_device(chip->pci); - pci_restore_state(chip->pci, chip->pci_state); - pci_set_power_state(chip->pci, 0); + pci_restore_state(pci); + pci_enable_device(pci); + pci_set_power_state(pci, PCI_D0); + pci_set_master(pci); snd_atiixp_aclink_reset(chip); snd_atiixp_chip_start(chip); for (i = 0; i < NUM_ATI_CODECS; i++) - if (chip->ac97[i]) - snd_ac97_resume(chip->ac97[i]); + snd_ac97_resume(chip->ac97[i]); + + for (i = 0; i < NUM_ATI_PCMDEVS; i++) + if (chip->pcmdevs[i]) { + struct atiixp_dma *dma = &chip->dmas[i]; + if (dma->substream && dma->suspended) { + dma->ops->enable_dma(chip, 1); + dma->substream->ops->prepare(dma->substream); + writel((u32)dma->desc_buf.addr | ATI_REG_LINKPTR_EN, + chip->remap_addr + dma->ops->llp_offset); + writel(dma->saved_curptr, chip->remap_addr + + dma->ops->dt_cur); + } + } snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; @@ -1460,98 +1484,102 @@ static int snd_atiixp_resume(snd_card_t *card, unsigned int state) #endif /* CONFIG_PM */ +#ifdef CONFIG_PROC_FS /* * proc interface for register dump */ -static void snd_atiixp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer) +static void snd_atiixp_proc_read(struct snd_info_entry *entry, + struct snd_info_buffer *buffer) { - atiixp_t *chip = snd_magic_cast(atiixp_t, entry->private_data, return); + struct atiixp *chip = entry->private_data; int i; for (i = 0; i < 256; i += 4) snd_iprintf(buffer, "%02x: %08x\n", i, readl(chip->remap_addr + i)); } -static void __devinit snd_atiixp_proc_init(atiixp_t *chip) +static void __devinit snd_atiixp_proc_init(struct atiixp *chip) { - snd_info_entry_t *entry; + struct snd_info_entry *entry; if (! snd_card_proc_new(chip->card, "atiixp", &entry)) - snd_info_set_text_ops(entry, chip, 1024, snd_atiixp_proc_read); + snd_info_set_text_ops(entry, chip, snd_atiixp_proc_read); } - +#else /* !CONFIG_PROC_FS */ +#define snd_atiixp_proc_init(chip) +#endif /* * destructor */ -static int snd_atiixp_free(atiixp_t *chip) +static int snd_atiixp_free(struct atiixp *chip) { if (chip->irq < 0) goto __hw_end; snd_atiixp_chip_stop(chip); synchronize_irq(chip->irq); __hw_end: - if (chip->remap_addr) - iounmap((void *) chip->remap_addr); - if (chip->res) { - release_resource(chip->res); - kfree_nocheck(chip->res); - } if (chip->irq >= 0) - free_irq(chip->irq, (void *)chip); - snd_magic_kfree(chip); + free_irq(chip->irq, chip); + if (chip->remap_addr) + iounmap(chip->remap_addr); + pci_release_regions(chip->pci); + pci_disable_device(chip->pci); + kfree(chip); return 0; } -static int snd_atiixp_dev_free(snd_device_t *device) +static int snd_atiixp_dev_free(struct snd_device *device) { - atiixp_t *chip = snd_magic_cast(atiixp_t, device->device_data, return -ENXIO); + struct atiixp *chip = device->device_data; return snd_atiixp_free(chip); } /* * constructor for chip instance */ -static int __devinit snd_atiixp_create(snd_card_t *card, +static int __devinit snd_atiixp_create(struct snd_card *card, struct pci_dev *pci, - atiixp_t **r_chip) + struct atiixp **r_chip) { - static snd_device_ops_t ops = { + static struct snd_device_ops ops = { .dev_free = snd_atiixp_dev_free, }; - atiixp_t *chip; + struct atiixp *chip; int err; if ((err = pci_enable_device(pci)) < 0) return err; - chip = snd_magic_kcalloc(atiixp_t, 0, GFP_KERNEL); - if (chip == NULL) + chip = kzalloc(sizeof(*chip), GFP_KERNEL); + if (chip == NULL) { + pci_disable_device(pci); return -ENOMEM; + } spin_lock_init(&chip->reg_lock); - spin_lock_init(&chip->ac97_lock); - init_MUTEX(&chip->open_mutex); + mutex_init(&chip->open_mutex); chip->card = card; chip->pci = pci; chip->irq = -1; - chip->addr = pci_resource_start(pci, 0); - if ((chip->res = request_mem_region(chip->addr, ATI_MEM_REGION, "ATI IXP AC97")) == NULL) { - snd_printk(KERN_ERR "unable to grab I/O memory 0x%lx\n", chip->addr); - snd_atiixp_free(chip); - return -EBUSY; + if ((err = pci_request_regions(pci, "ATI IXP AC97")) < 0) { + pci_disable_device(pci); + kfree(chip); + return err; } - chip->remap_addr = (unsigned long) ioremap_nocache(chip->addr, ATI_MEM_REGION); - if (chip->remap_addr == 0) { + chip->addr = pci_resource_start(pci, 0); + chip->remap_addr = ioremap_nocache(chip->addr, pci_resource_len(pci, 0)); + if (chip->remap_addr == NULL) { snd_printk(KERN_ERR "AC'97 space ioremap problem\n"); snd_atiixp_free(chip); return -EIO; } - if (request_irq(pci->irq, snd_atiixp_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) { + if (request_irq(pci->irq, snd_atiixp_interrupt, IRQF_DISABLED|IRQF_SHARED, + card->shortname, chip)) { snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); snd_atiixp_free(chip); return -EBUSY; @@ -1575,36 +1603,29 @@ static int __devinit snd_atiixp_create(snd_card_t *card, static int __devinit snd_atiixp_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { - static int dev; - snd_card_t *card; - atiixp_t *chip; + struct snd_card *card; + struct atiixp *chip; unsigned char revision; 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; pci_read_config_byte(pci, PCI_REVISION_ID, &revision); - strcpy(card->driver, spdif_aclink[dev] ? "ATIIXP" : "ATIIXP-SPDMA"); + strcpy(card->driver, spdif_aclink ? "ATIIXP" : "ATIIXP-SPDMA"); strcpy(card->shortname, "ATI IXP"); if ((err = snd_atiixp_create(card, pci, &chip)) < 0) goto __error; + card->private_data = chip; if ((err = snd_atiixp_aclink_reset(chip)) < 0) goto __error; - chip->spdif_over_aclink = spdif_aclink[dev]; + chip->spdif_over_aclink = spdif_aclink; - if ((err = snd_atiixp_mixer_new(chip, ac97_clock[dev])) < 0) + if ((err = snd_atiixp_mixer_new(chip, ac97_clock, ac97_quirk)) < 0) goto __error; if ((err = snd_atiixp_pcm_new(chip)) < 0) @@ -1614,16 +1635,15 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci, snd_atiixp_chip_start(chip); - sprintf(card->longname, "%s rev %x at 0x%lx, irq %i", - card->shortname, revision, chip->addr, chip->irq); - - snd_card_set_pm_callback(card, snd_atiixp_suspend, snd_atiixp_resume, chip); + snprintf(card->longname, sizeof(card->longname), + "%s rev %x with %s at %#lx, irq %i", card->shortname, revision, + chip->ac97[0] ? snd_ac97_get_short_name(chip->ac97[0]) : "?", + chip->addr, chip->irq); if ((err = snd_card_register(card)) < 0) goto __error; pci_set_drvdata(pci, card); - dev++; return 0; __error: @@ -1642,13 +1662,16 @@ static struct pci_driver driver = { .id_table = snd_atiixp_ids, .probe = snd_atiixp_probe, .remove = __devexit_p(snd_atiixp_remove), - SND_PCI_PM_CALLBACKS +#ifdef CONFIG_PM + .suspend = snd_atiixp_suspend, + .resume = snd_atiixp_resume, +#endif }; static int __init alsa_card_atiixp_init(void) { - return pci_module_init(&driver); + return pci_register_driver(&driver); } static void __exit alsa_card_atiixp_exit(void)