Cleanup for CS5535 audio driver
Subsystems (2)
[email protected]
maintainerPATCH 1/1 Cleanup for CS5535 audio driver
Hi,
This patch is against 2.6.14-rc2 + cs5535-audio-alsa-driver.patch ( The prior patch is as was at http://lkml.org/lkml/2005/9/19/34
and I guess in akpm's -mm tree). I wasn't sure if I should generate
a diff against the previous patch or if I should just diff against the real vanilla 2.6.14-rc2. So I just did a diff against the previous patch.
Thanks,
Jaya Kumar
Signed-off-by Jaya Kumar <[email protected]>
---
cs5535audio.c | 208 ++++++++++++++++++++++++++---------------------------- cs5535audio.h | 11 +- cs5535audio_pcm.c | 43 +++++------ 3 files changed, 129 insertions(+), 133 deletions(-)
sound/pci/cs5535audio/cs5535audio.c +103 -105
@@ -21,13 +21,13 @@* */ -#include <asm/io.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/init.h> #include <linux/pci.h> #include <linux/slab.h> #include <linux/moduleparam.h> +#include <asm/io.h> #include <sound/driver.h> #include <sound/core.h> #include <sound/control.h>
@@ -53,41 +53,43 @@ static struct pci_device_id snd_cs5535auMODULE_DEVICE_TABLE (pci, snd_cs5535audio_ids); +static void wait_till_cmd_acked (cs5535audio_t *cs5535au,unsigned long timeout) +{ +unsigned long tmp; +do { + tmp =cs_readl (cs5535au,ACC_CODEC_CNTL ); +if (!(tmp &CMD_NEW )) +break ; +msleep (10 ); + }while (--timeout); +if (!timeout) +snd_printk (KERN_ERR "Failure writing to cs5535 codec\n" ); +} +static unsigned short snd_cs5535audio_codec_read (cs5535audio_t *cs5535au,unsigned short reg) {unsigned long regdata; -unsigned long tmp, timeout; +unsigned long timeout;unsigned long val; regdata = ((unsigned long ) reg) <<24 ; regdata |=ACC_CODEC_CNTL_RD_CMD ; regdata |=CMD_NEW ; -cs_writel (ACC_CODEC_CNTL , regdata); - - timeout =500 ; -do { - tmp =cs_readl (ACC_CODEC_CNTL ); -if (!(tmp &CMD_NEW )) -break ; -msleep (10 ); - }while (timeout--); -if (!timeout) { -snd_printk (KERN_ERR "Failure writing to cs5535 codec\n" ); - } +cs_writel (cs5535au,ACC_CODEC_CNTL , regdata); +wait_till_cmd_acked (cs5535au,500 ); timeout =50 ;do { - val =cs_readl (ACC_CODEC_STATUS ); + val =cs_readl (cs5535au,ACC_CODEC_STATUS );if ( (val &STS_NEW ) && ((unsigned long ) reg == ((0xFF000000 & val)>>24 )) )break ;msleep (10 ); - }while (timeout--); -if (!timeout) { + }while (--timeout); +if (!timeout)snd_printk (KERN_ERR "Failure reading cs5535 codec\n" ); - }return ((unsigned short ) val); }
@@ -96,7 +98,6 @@ static void snd_cs5535audio_codec_write( unsigned short reg, unsigned short val) {unsigned long regdata; -unsigned long tmp, timeout; regdata = ((unsigned long ) reg) <<24 ; regdata |= (unsigned long ) val;
@@ -104,32 +105,22 @@ static void snd_cs5535audio_codec_write( regdata |=CMD_NEW ; regdata &=ACC_CODEC_CNTL_WR_CMD ; -cs_writel (ACC_CODEC_CNTL , regdata); - - timeout =50 ; -do { - tmp =cs_readl (ACC_CODEC_CNTL ); -if (!(tmp &CMD_NEW )) -break ; -msleep (10 ); - }while (timeout--); -if (!timeout) { -snd_printk (KERN_ERR "Failure writing to cs5535 codec\n" ); - } +cs_writel (cs5535au,ACC_CODEC_CNTL , regdata); +wait_till_cmd_acked (cs5535au,50 ); }static void snd_cs5535audio_ac97_codec_write (ac97_t *ac97,unsigned short reg,unsigned short val) {cs5535audio_t *cs5535au = ac97->private_data; -snd_cs5535audio_codec_write (cs5535au,reg,val); +snd_cs5535audio_codec_write (cs5535au, reg, val); }static unsigned short snd_cs5535audio_ac97_codec_read (ac97_t *ac97,unsigned short reg) {cs5535audio_t *cs5535au = ac97->private_data; -return snd_cs5535audio_codec_read (cs5535au,reg); +return snd_cs5535audio_codec_read (cs5535au, reg); }static void snd_cs5535audio_mixer_free_ac97 (ac97_t *ac97)
@@ -170,13 +161,11 @@ static void process_bm0_irq(cs5535audio_ {u8 bm_stat;spin_lock (&cs5535au->reg_lock); - bm_stat =cs_readb (ACC_BM0_STATUS ); + bm_stat =cs_readb (cs5535au,ACC_BM0_STATUS );spin_unlock (&cs5535au->reg_lock);if (bm_stat &EOP ) {cs5535audio_dma_t *dma; - dma = (cs5535audio_dma_t *) - cs5535au->playback_substream->runtime->private_data; - dma->index = (++(dma->index)) % dma->periods; + dma = cs5535au->playback_substream->runtime->private_data;snd_pcm_period_elapsed (cs5535au->playback_substream); }else { snd_printk(KERN_ERR "unexpected bm0 irq src, bm_stat=%x\n",
@@ -188,13 +177,11 @@ static void process_bm1_irq(cs5535audio_ {u8 bm_stat;spin_lock (&cs5535au->reg_lock); - bm_stat =cs_readb (ACC_BM1_STATUS ); + bm_stat =cs_readb (cs5535au,ACC_BM1_STATUS );spin_unlock (&cs5535au->reg_lock);if (bm_stat &EOP ) {cs5535audio_dma_t *dma; - dma = (cs5535audio_dma_t *) - cs5535au->capture_substream->runtime->private_data; - dma->index = (++(dma->index)) % dma->periods; + dma = cs5535au->capture_substream->runtime->private_data;snd_pcm_period_elapsed (cs5535au->capture_substream); } }
@@ -210,47 +197,46 @@ static irqreturn_t snd_cs5535audio_interif (cs5535au ==NULL )return IRQ_NONE ; - acc_irq_stat =cs_readw (ACC_IRQ_STATUS ); + acc_irq_stat =cs_readw (cs5535au,ACC_IRQ_STATUS );if (!acc_irq_stat)return IRQ_NONE ;for (count=0 ; count <10 ; count++) {if (acc_irq_stat & (1 <<count)) {switch (count) { -case IRQ_STS : -cs_readl (ACC_GPIO_STATUS ); -break ; -case WU_IRQ_STS : -cs_readl (ACC_GPIO_STATUS ); -break ; -case BM0_IRQ_STS : -process_bm0_irq (cs5535au); -break ; -case BM1_IRQ_STS : -process_bm1_irq (cs5535au); -break ; -case BM2_IRQ_STS : - bm_stat =cs_readb (ACC_BM2_STATUS ); -break ; -case BM3_IRQ_STS : - bm_stat =cs_readb (ACC_BM3_STATUS ); -break ; -case BM4_IRQ_STS : - bm_stat =cs_readb (ACC_BM4_STATUS ); -break ; -case BM5_IRQ_STS : - bm_stat =cs_readb (ACC_BM5_STATUS ); -break ; -case BM6_IRQ_STS : - bm_stat =cs_readb (ACC_BM6_STATUS ); -break ; -case BM7_IRQ_STS : - bm_stat =cs_readb (ACC_BM7_STATUS ); -break ; -default : -snd_printk (KERN_ERR -"Unexpected irq src\n" ); -break ; +case IRQ_STS : +cs_readl (cs5535au,ACC_GPIO_STATUS ); +break ; +case WU_IRQ_STS : +cs_readl (cs5535au,ACC_GPIO_STATUS ); +break ; +case BM0_IRQ_STS : +process_bm0_irq (cs5535au); +break ; +case BM1_IRQ_STS : +process_bm1_irq (cs5535au); +break ; +case BM2_IRQ_STS : + bm_stat =cs_readb (cs5535au,ACC_BM2_STATUS ); +break ; +case BM3_IRQ_STS : + bm_stat =cs_readb (cs5535au,ACC_BM3_STATUS ); +break ; +case BM4_IRQ_STS : + bm_stat =cs_readb (cs5535au,ACC_BM4_STATUS ); +break ; +case BM5_IRQ_STS : + bm_stat =cs_readb (cs5535au,ACC_BM5_STATUS ); +break ; +case BM6_IRQ_STS : + bm_stat =cs_readb (cs5535au,ACC_BM6_STATUS ); +break ; +case BM7_IRQ_STS : + bm_stat =cs_readb (cs5535au,ACC_BM7_STATUS ); +break ; +default : +snd_printk (KERN_ERR "Unexpected irq src\n" ); +break ; } } }
@@ -263,7 +249,7 @@ static int snd_cs5535audio_free(cs5535aupci_set_power_state (cs5535au->pci,3 );if (cs5535au->irq >=0 ) -free_irq (cs5535au->irq, (void *)cs5535au); +free_irq (cs5535au->irq, cs5535au);pci_release_regions (cs5535au->pci);pci_disable_device (cs5535au->pci);
@@ -292,41 +278,57 @@ static int __devinit snd_cs5535audio_creif ((err =pci_enable_device (pci)) <0 )return err; - cs5535au =kcalloc (1 ,sizeof (*cs5535au),GFP_KERNEL ); +if (pci_set_dma_mask (pci,DMA_32BIT_MASK ) <0 || +pci_set_consistent_dma_mask (pci,DMA_32BIT_MASK ) <0 ) { +printk (KERN_WARNING "unable to get 32bit dma\n" ); + err = -ENXIO ; + goto pcifail; + } + + cs5535au =kzalloc (sizeof (*cs5535au),GFP_KERNEL );if (cs5535au ==NULL ) { -pci_disable_device (pci); -return -ENOMEM ; + err = -ENOMEM ; + goto pcifail; } +spin_lock_init (&cs5535au->reg_lock); cs5535au->card = card; cs5535au->pci = pci; cs5535au->irq =-1 ; +if ((err =pci_request_regions (pci,"CS5535 Audio" )) <0 ) {kfree (cs5535au); -pci_disable_device (pci); -return err; + goto pcifail; } + cs5535au->port =pci_resource_start (pci,0 ); +if (request_irq (pci->irq, snd_cs5535audio_interrupt, -SA_INTERRUPT |SA_SHIRQ ,"CS5535 Audio" , (void *) cs5535au)) { +SA_INTERRUPT |SA_SHIRQ ,"CS5535 Audio" , cs5535au)) {snd_printk ("unable to grab IRQ %d\n" , pci->irq); -snd_cs5535audio_free (cs5535au); -return -EBUSY ; + err = -EBUSY ; + goto sndfail; } cs5535au->irq = pci->irq;pci_set_master (pci);if ((err =snd_device_new (card,SNDRV_DEV_LOWLEVEL , - cs5535au, &ops)) <0 ) { -snd_cs5535audio_free (cs5535au); -return err; - } + cs5535au, &ops)) <0 ) + goto sndfail;snd_card_set_dev (card, &pci->dev); *rcs5535au = cs5535au;return 0 ; + +sndfail:/* leave the device alive, just kill the snd */ +snd_cs5535audio_free (cs5535au); +return err; + +pcifail: +pci_disable_device (pci); +return err; } static int __devinit snd_cs5535audio_probe(struct pci_dev *pci,
@@ -348,20 +350,14 @@ static int __devinit snd_cs5535audio_proif (card ==NULL )return -ENOMEM ; -if ((err =snd_cs5535audio_create (card, pci, &cs5535au)) <0 ) { -snd_card_free (card); -return err; - } +if ((err =snd_cs5535audio_create (card, pci, &cs5535au)) <0 ) + goto probefail_out; -if ((err =snd_cs5535audio_mixer (cs5535au)) <0 ) { -snd_card_free (card); -return err; - } +if ((err =snd_cs5535audio_mixer (cs5535au)) <0 ) + goto probefail_out; -if ((err =snd_cs5535audio_pcm (cs5535au)) <0 ) { -snd_card_free (card); -return err; - } +if ((err =snd_cs5535audio_pcm (cs5535au)) <0 ) + goto probefail_out;strcpy (card->driver,DRIVER_NAME );
@@ -370,14 +366,16 @@ static int __devinit snd_cs5535audio_pro card->shortname, card->driver, cs5535au->port, cs5535au->irq); -if ((err =snd_card_register (card)) <0 ) { -snd_card_free (card); -return err; - } +if ((err =snd_card_register (card)) <0 ) + goto probefail_out;pci_set_drvdata (pci, card); dev++;return 0 ; + +probefail_out: +snd_card_free (card); +return err; } static void __devexit snd_cs5535audio_remove(struct pci_dev *pci)
sound/pci/cs5535audio/cs5535audio.h +5 -6
@@ -1,11 +1,11 @@#ifndef __SOUND_CS5535AUDIO_H#define __SOUND_CS5535AUDIO_H -#define cs_writel (reg, val) outl(val, (int) cs5535au->port + reg) -#define cs_writeb (reg, val) outb(val, (int) cs5535au->port + reg) -#define cs_readl (reg) inl((unsigned short) (cs5535au->port + reg)) -#define cs_readw (reg) inw((unsigned short) (cs5535au->port + reg)) -#define cs_readb (reg) inb((unsigned short) (cs5535au->port + reg)) +#define cs_writel (cs5535au, reg, val) outl(val, (int) cs5535au->port + reg) +#define cs_writeb (cs5535au, reg, val) outb(val, (int) cs5535au->port + reg) +#define cs_readl (cs5535au, reg) inl((unsigned short) (cs5535au->port + reg)) +#define cs_readw (cs5535au, reg) inw((unsigned short) (cs5535au->port + reg)) +#define cs_readb (cs5535au, reg) inb((unsigned short) (cs5535au->port + reg))#define CS5535AUDIO_MAX_DESCRIPTORS 128
@@ -104,7 +104,6 @@ struct snd_cs5535audio_dma {snd_pcm_substream_t *substream;unsigned int buf_addr, buf_bytes;unsigned int period_bytes, periods; -int index; };struct _snd_cs5535audio {
sound/pci/cs5535audio/cs5535audio_pcm.c +21 -22
125 lines not on this page · raw message