Merge branch 'fix/misc' into for-linus
[safe/jmp/linux-2.6] / sound / mips / au1x00.c
index a8f9a3b..446cf97 100644 (file)
 
 #include <linux/ioport.h>
 #include <linux/interrupt.h>
-#include <sound/driver.h>
 #include <linux/init.h>
 #include <linux/slab.h>
-#include <linux/version.h>
 #include <sound/core.h>
 #include <sound/initval.h>
 #include <sound/pcm.h>
+#include <sound/pcm_params.h>
 #include <sound/ac97_codec.h>
 #include <asm/mach-au1x00/au1000.h>
 #include <asm/mach-au1x00/au1000_dma.h>
@@ -63,16 +62,14 @@ MODULE_SUPPORTED_DEVICE("{{AMD,Au1000 AC'97}}");
 #define READ_WAIT 2
 #define RW_DONE 3
 
-typedef struct au1000_period au1000_period_t;
 struct au1000_period
 {
        u32 start;
        u32 relative_end;       /*realtive to start of buffer*/
-       au1000_period_t * next;
+       struct au1000_period * next;
 };
 
 /*Au1000 AC97 Port Control Reisters*/
-typedef struct au1000_ac97_reg au1000_ac97_reg_t;
 struct au1000_ac97_reg {
        u32 volatile config;
        u32 volatile status;
@@ -81,31 +78,30 @@ struct au1000_ac97_reg {
        u32 volatile cntrl;
 };
 
-typedef struct audio_stream audio_stream_t;
 struct audio_stream {
-       snd_pcm_substream_t * substream;
+       struct snd_pcm_substream *substream;
        int dma;
        spinlock_t dma_lock;
-       au1000_period_t * buffer;
+       struct au1000_period * buffer;
        unsigned int period_size;
        unsigned int periods;
 };
 
-typedef struct snd_card_au1000 {
-       snd_card_t *card;
-       au1000_ac97_reg_t volatile *ac97_ioport;
+struct snd_au1000 {
+       struct snd_card *card;
+       struct au1000_ac97_reg volatile *ac97_ioport;
 
        struct resource *ac97_res_port;
        spinlock_t ac97_lock;
-       ac97_t *ac97;
+       struct snd_ac97 *ac97;
 
-       snd_pcm_t *pcm;
-       audio_stream_t *stream[2];      /* playback & capture */
-} au1000_t;
+       struct snd_pcm *pcm;
+       struct audio_stream *stream[2]; /* playback & capture */
+};
 
 /*--------------------------- Local Functions --------------------------------*/
 static void
-au1000_set_ac97_xmit_slots(au1000_t *au1000, long xmit_slots)
+au1000_set_ac97_xmit_slots(struct snd_au1000 *au1000, long xmit_slots)
 {
        u32 volatile ac97_config;
 
@@ -118,7 +114,7 @@ au1000_set_ac97_xmit_slots(au1000_t *au1000, long xmit_slots)
 }
 
 static void
-au1000_set_ac97_recv_slots(au1000_t *au1000, long recv_slots)
+au1000_set_ac97_recv_slots(struct snd_au1000 *au1000, long recv_slots)
 {
        u32 volatile ac97_config;
 
@@ -132,10 +128,10 @@ au1000_set_ac97_recv_slots(au1000_t *au1000, long recv_slots)
 
 
 static void
-au1000_release_dma_link(audio_stream_t *stream)
+au1000_release_dma_link(struct audio_stream *stream)
 {
-       au1000_period_t * pointer;
-       au1000_period_t * pointer_next;
+       struct au1000_period * pointer;
+       struct au1000_period * pointer_next;
 
        stream->period_size = 0;
        stream->periods = 0;
@@ -151,11 +147,12 @@ au1000_release_dma_link(audio_stream_t *stream)
 }
 
 static int
-au1000_setup_dma_link(audio_stream_t *stream, unsigned int period_bytes,
+au1000_setup_dma_link(struct audio_stream *stream, unsigned int period_bytes,
                      unsigned int periods)
 {
-       snd_pcm_substream_t *substream = stream->substream;
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_pcm_substream *substream = stream->substream;
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct au1000_period *pointer;
        unsigned long dma_start;
        int i;
 
@@ -170,7 +167,7 @@ au1000_setup_dma_link(audio_stream_t *stream, unsigned int period_bytes,
        stream->period_size = period_bytes;
        stream->periods = periods;
 
-       stream->buffer = kmalloc(sizeof(au1000_period_t), GFP_KERNEL);
+       stream->buffer = kmalloc(sizeof(struct au1000_period), GFP_KERNEL);
        if (! stream->buffer)
                return -ENOMEM;
        pointer = stream->buffer;
@@ -191,16 +188,18 @@ au1000_setup_dma_link(audio_stream_t *stream, unsigned int period_bytes,
 }
 
 static void
-au1000_dma_stop(audio_stream_t *stream)
+au1000_dma_stop(struct audio_stream *stream)
 {
-       snd_assert(stream->buffer, return);
+       if (snd_BUG_ON(!stream->buffer))
+               return;
        disable_dma(stream->dma);
 }
 
 static void
-au1000_dma_start(audio_stream_t *stream)
+au1000_dma_start(struct audio_stream *stream)
 {
-       snd_assert(stream->buffer, return);
+       if (snd_BUG_ON(!stream->buffer))
+               return;
 
        init_dma(stream->dma);
        if (get_dma_active_buffer(stream->dma) == 0) {
@@ -221,10 +220,10 @@ au1000_dma_start(audio_stream_t *stream)
 }
 
 static irqreturn_t
-au1000_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+au1000_dma_interrupt(int irq, void *dev_id)
 {
-       audio_stream_t *stream = (audio_stream_t *) dev_id;
-       snd_pcm_substream_t *substream = stream->substream;
+       struct audio_stream *stream = (struct audio_stream *) dev_id;
+       struct snd_pcm_substream *substream = stream->substream;
 
        spin_lock(&stream->dma_lock);
        switch (get_dma_buffer_done(stream->dma)) {
@@ -258,13 +257,13 @@ au1000_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 /*-------------------------- PCM Audio Streams -------------------------------*/
 
 static unsigned int rates[] = {8000, 11025, 16000, 22050};
-static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
-       .count  =  sizeof(rates) / sizeof(rates[0]),
+static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
+       .count  = ARRAY_SIZE(rates),
        .list   = rates,
        .mask   = 0,
 };
 
-static snd_pcm_hardware_t snd_au1000_hw =
+static struct snd_pcm_hardware snd_au1000_hw =
 {
        .info                   = (SNDRV_PCM_INFO_INTERLEAVED | \
                                SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
@@ -284,9 +283,9 @@ static snd_pcm_hardware_t snd_au1000_hw =
 };
 
 static int
-snd_au1000_playback_open(snd_pcm_substream_t * substream)
+snd_au1000_playback_open(struct snd_pcm_substream *substream)
 {
-       au1000_t *au1000 = substream->pcm->private_data;
+       struct snd_au1000 *au1000 = substream->pcm->private_data;
 
        au1000->stream[PLAYBACK]->substream = substream;
        au1000->stream[PLAYBACK]->buffer = NULL;
@@ -297,9 +296,9 @@ snd_au1000_playback_open(snd_pcm_substream_t * substream)
 }
 
 static int
-snd_au1000_capture_open(snd_pcm_substream_t * substream)
+snd_au1000_capture_open(struct snd_pcm_substream *substream)
 {
-       au1000_t *au1000 = substream->pcm->private_data;
+       struct snd_au1000 *au1000 = substream->pcm->private_data;
 
        au1000->stream[CAPTURE]->substream = substream;
        au1000->stream[CAPTURE]->buffer = NULL;
@@ -307,32 +306,31 @@ snd_au1000_capture_open(snd_pcm_substream_t * substream)
        substream->runtime->hw = snd_au1000_hw;
        return (snd_pcm_hw_constraint_list(substream->runtime, 0,
                SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates) < 0);
-
 }
 
 static int
-snd_au1000_playback_close(snd_pcm_substream_t * substream)
+snd_au1000_playback_close(struct snd_pcm_substream *substream)
 {
-       au1000_t *au1000 = substream->pcm->private_data;
+       struct snd_au1000 *au1000 = substream->pcm->private_data;
 
        au1000->stream[PLAYBACK]->substream = NULL;
        return 0;
 }
 
 static int
-snd_au1000_capture_close(snd_pcm_substream_t * substream)
+snd_au1000_capture_close(struct snd_pcm_substream *substream)
 {
-       au1000_t *au1000 = substream->pcm->private_data;
+       struct snd_au1000 *au1000 = substream->pcm->private_data;
 
        au1000->stream[CAPTURE]->substream = NULL;
        return 0;
 }
 
 static int
-snd_au1000_hw_params(snd_pcm_substream_t * substream,
-                                       snd_pcm_hw_params_t * hw_params)
+snd_au1000_hw_params(struct snd_pcm_substream *substream,
+                                       struct snd_pcm_hw_params *hw_params)
 {
-       audio_stream_t *stream = substream->private_data;
+       struct audio_stream *stream = substream->private_data;
        int err;
 
        err = snd_pcm_lib_malloc_pages(substream,
@@ -345,18 +343,18 @@ snd_au1000_hw_params(snd_pcm_substream_t * substream,
 }
 
 static int
-snd_au1000_hw_free(snd_pcm_substream_t * substream)
+snd_au1000_hw_free(struct snd_pcm_substream *substream)
 {
-       audio_stream_t *stream = substream->private_data;
+       struct audio_stream *stream = substream->private_data;
        au1000_release_dma_link(stream);
        return snd_pcm_lib_free_pages(substream);
 }
 
 static int
-snd_au1000_playback_prepare(snd_pcm_substream_t * substream)
+snd_au1000_playback_prepare(struct snd_pcm_substream *substream)
 {
-       au1000_t *au1000 = substream->pcm->private_data;
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_au1000 *au1000 = substream->pcm->private_data;
+       struct snd_pcm_runtime *runtime = substream->runtime;
 
        if (runtime->channels == 1)
                au1000_set_ac97_xmit_slots(au1000, AC97_SLOT_4);
@@ -367,10 +365,10 @@ snd_au1000_playback_prepare(snd_pcm_substream_t * substream)
 }
 
 static int
-snd_au1000_capture_prepare(snd_pcm_substream_t * substream)
+snd_au1000_capture_prepare(struct snd_pcm_substream *substream)
 {
-       au1000_t *au1000 = substream->pcm->private_data;
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_au1000 *au1000 = substream->pcm->private_data;
+       struct snd_pcm_runtime *runtime = substream->runtime;
 
        if (runtime->channels == 1)
                au1000_set_ac97_recv_slots(au1000, AC97_SLOT_4);
@@ -381,9 +379,9 @@ snd_au1000_capture_prepare(snd_pcm_substream_t * substream)
 }
 
 static int
-snd_au1000_trigger(snd_pcm_substream_t * substream, int cmd)
+snd_au1000_trigger(struct snd_pcm_substream *substream, int cmd)
 {
-       audio_stream_t *stream = substream->private_data;
+       struct audio_stream *stream = substream->private_data;
        int err = 0;
 
        spin_lock(&stream->dma_lock);
@@ -403,10 +401,10 @@ snd_au1000_trigger(snd_pcm_substream_t * substream, int cmd)
 }
 
 static snd_pcm_uframes_t
-snd_au1000_pointer(snd_pcm_substream_t * substream)
+snd_au1000_pointer(struct snd_pcm_substream *substream)
 {
-       audio_stream_t *stream = substream->private_data;
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct audio_stream *stream = substream->private_data;
+       struct snd_pcm_runtime *runtime = substream->runtime;
        long location;
 
        spin_lock(&stream->dma_lock);
@@ -418,7 +416,7 @@ snd_au1000_pointer(snd_pcm_substream_t * substream)
        return bytes_to_frames(runtime,location);
 }
 
-static snd_pcm_ops_t snd_card_au1000_playback_ops = {
+static struct snd_pcm_ops snd_card_au1000_playback_ops = {
        .open                   = snd_au1000_playback_open,
        .close                  = snd_au1000_playback_close,
        .ioctl                  = snd_pcm_lib_ioctl,
@@ -429,7 +427,7 @@ static snd_pcm_ops_t snd_card_au1000_playback_ops = {
        .pointer                = snd_au1000_pointer,
 };
 
-static snd_pcm_ops_t snd_card_au1000_capture_ops = {
+static struct snd_pcm_ops snd_card_au1000_capture_ops = {
        .open                   = snd_au1000_capture_open,
        .close                  = snd_au1000_capture_close,
        .ioctl                  = snd_pcm_lib_ioctl,
@@ -441,9 +439,9 @@ static snd_pcm_ops_t snd_card_au1000_capture_ops = {
 };
 
 static int __devinit
-snd_au1000_pcm_new(void)
+snd_au1000_pcm_new(struct snd_au1000 *au1000)
 {
-       snd_pcm_t *pcm;
+       struct snd_pcm *pcm;
        int err;
        unsigned long flags;
 
@@ -467,13 +465,13 @@ snd_au1000_pcm_new(void)
 
        flags = claim_dma_lock();
        if ((au1000->stream[PLAYBACK]->dma = request_au1000_dma(DMA_ID_AC97C_TX,
-                       "AC97 TX", au1000_dma_interrupt, SA_INTERRUPT,
+                       "AC97 TX", au1000_dma_interrupt, IRQF_DISABLED,
                        au1000->stream[PLAYBACK])) < 0) {
                release_dma_lock(flags);
                return -EBUSY;
        }
        if ((au1000->stream[CAPTURE]->dma = request_au1000_dma(DMA_ID_AC97C_RX,
-                       "AC97 RX", au1000_dma_interrupt, SA_INTERRUPT,
+                       "AC97 RX", au1000_dma_interrupt, IRQF_DISABLED,
                        au1000->stream[CAPTURE])) < 0){
                release_dma_lock(flags);
                return -EBUSY;
@@ -492,16 +490,16 @@ snd_au1000_pcm_new(void)
 /*-------------------------- AC97 CODEC Control ------------------------------*/
 
 static unsigned short
-snd_au1000_ac97_read(ac97_t *ac97, unsigned short reg)
+snd_au1000_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
 {
-       au1000_t *au1000 = ac97->private_data;
+       struct snd_au1000 *au1000 = ac97->private_data;
        u32 volatile cmd;
        u16 volatile data;
        int             i;
 
        spin_lock(&au1000->ac97_lock);
-/* would rather use the interupt than this polling but it works and I can't
-get the interupt driven case to work efficiently */
+/* would rather use the interrupt than this polling but it works and I can't
+get the interrupt driven case to work efficiently */
        for (i = 0; i < 0x5000; i++)
                if (!(au1000->ac97_ioport->status & AC97C_CP))
                        break;
@@ -518,6 +516,7 @@ get the interupt driven case to work efficiently */
                        break;
        if (i == 0x5000) {
                printk(KERN_ERR "au1000 AC97: AC97 command read timeout\n");
+               spin_unlock(&au1000->ac97_lock);
                return 0;
        }
 
@@ -530,15 +529,15 @@ get the interupt driven case to work efficiently */
 
 
 static void
-snd_au1000_ac97_write(ac97_t *ac97, unsigned short reg, unsigned short val)
+snd_au1000_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val)
 {
-       au1000_t *au1000 = ac97->private_data;
+       struct snd_au1000 *au1000 = ac97->private_data;
        u32 cmd;
        int i;
 
        spin_lock(&au1000->ac97_lock);
-/* would rather use the interupt than this polling but it works and I can't
-get the interupt driven case to work efficiently */
+/* would rather use the interrupt than this polling but it works and I can't
+get the interrupt driven case to work efficiently */
        for (i = 0; i < 0x5000; i++)
                if (!(au1000->ac97_ioport->status & AC97C_CP))
                        break;
@@ -553,18 +552,23 @@ get the interupt driven case to work efficiently */
 }
 
 static int __devinit
-snd_au1000_ac97_new(au1000_t *au1000)
+snd_au1000_ac97_new(struct snd_au1000 *au1000)
 {
        int err;
-       ac97_bus_t bus, *pbus;
-       ac97_t ac97;
-
-       if ((au1000->ac97_res_port = request_region(AC97C_CONFIG,
-                       sizeof(au1000_ac97_reg_t), "Au1x00 AC97")) == NULL) {
+       struct snd_ac97_bus *pbus;
+       struct snd_ac97_template ac97;
+       static struct snd_ac97_bus_ops ops = {
+               .write = snd_au1000_ac97_write,
+               .read = snd_au1000_ac97_read,
+       };
+
+       if ((au1000->ac97_res_port = request_mem_region(CPHYSADDR(AC97C_CONFIG),
+                       0x100000, "Au1x00 AC97")) == NULL) {
                snd_printk(KERN_ERR "ALSA AC97: can't grap AC97 port\n");
                return -EBUSY;
        }
-       au1000->ac97_ioport = (au1000_ac97_reg_t *) au1000->ac97_res_port->start;
+       au1000->ac97_ioport = (struct au1000_ac97_reg *)
+               KSEG1ADDR(au1000->ac97_res_port->start);
 
        spin_lock_init(&au1000->ac97_lock);
 
@@ -599,9 +603,9 @@ snd_au1000_ac97_new(au1000_t *au1000)
 /*------------------------------ Setup / Destroy ----------------------------*/
 
 void
-snd_au1000_free(snd_card_t *card)
+snd_au1000_free(struct snd_card *card)
 {
-       au1000_t *au1000 = card->private_data;
+       struct snd_au1000 *au1000 = card->private_data;
 
        if (au1000->ac97_res_port) {
                /* put internal AC97 block into reset */
@@ -610,41 +614,49 @@ snd_au1000_free(snd_card_t *card)
                release_and_free_resource(au1000->ac97_res_port);
        }
 
-       if (au1000->stream[PLAYBACK]->dma >= 0)
-               free_au1000_dma(au1000->stream[PLAYBACK]->dma);
-
-       if (au1000->stream[CAPTURE]->dma >= 0)
-               free_au1000_dma(au1000->stream[CAPTURE]->dma);
+       if (au1000->stream[PLAYBACK]) {
+               if (au1000->stream[PLAYBACK]->dma >= 0)
+                       free_au1000_dma(au1000->stream[PLAYBACK]->dma);
+               kfree(au1000->stream[PLAYBACK]);
+       }
 
-       kfree(au1000->stream[PLAYBACK]);
-       kfree(au1000->stream[CAPTURE]);
+       if (au1000->stream[CAPTURE]) {
+               if (au1000->stream[CAPTURE]->dma >= 0)
+                       free_au1000_dma(au1000->stream[CAPTURE]->dma);
+               kfree(au1000->stream[CAPTURE]);
+       }
 }
 
 
-static snd_card_t *au1000_card;
+static struct snd_card *au1000_card;
 
 static int __init
 au1000_init(void)
 {
        int err;
-       snd_card_t *card;
-       au1000_t *au1000;
+       struct snd_card *card;
+       struct snd_au1000 *au1000;
 
-       card = snd_card_new(-1, "AC97", THIS_MODULE, sizeof(au1000_t));
-       if (card == NULL)
-               return -ENOMEM;
+       err = snd_card_create(-1, "AC97", THIS_MODULE,
+                             sizeof(struct snd_au1000), &card);
+       if (err < 0)
+               return err;
 
        card->private_free = snd_au1000_free;
        au1000 = card->private_data;
-       /* so that snd_au1000_free will work as intended */
        au1000->card = card;
-       au1000->stream[PLAYBACK]->dma = -1;
-       au1000->stream[CAPTURE]->dma = -1;
+
+       au1000->stream[PLAYBACK] = kmalloc(sizeof(struct audio_stream), GFP_KERNEL);
+       au1000->stream[CAPTURE ] = kmalloc(sizeof(struct audio_stream), GFP_KERNEL);
+       /* so that snd_au1000_free will work as intended */
        au1000->ac97_res_port = NULL;
-       au1000->stream[PLAYBACK] = kmalloc(sizeof(audio_stream_t), GFP_KERNEL);
-       au1000->stream[CAPTURE] = kmalloc(sizeof(audio_stream_t), GFP_KERNEL);
+       if (au1000->stream[PLAYBACK])
+               au1000->stream[PLAYBACK]->dma = -1;
+       if (au1000->stream[CAPTURE ])
+               au1000->stream[CAPTURE ]->dma = -1;
+
        if (au1000->stream[PLAYBACK] == NULL ||
-           au1000->stream[CAPTURE] == NULL) {
+           au1000->stream[CAPTURE ] == NULL) {
                snd_card_free(card);
                return -ENOMEM;
        }
@@ -663,17 +675,12 @@ au1000_init(void)
        strcpy(card->shortname, "AMD Au1000-AC97");
        sprintf(card->longname, "AMD Au1000--AC97 ALSA Driver");
 
-       if ((err = snd_card_set_generic_dev(card)) < 0) {
-               snd_card_free(card);
-               return err;
-       }
-
        if ((err = snd_card_register(card)) < 0) {
                snd_card_free(card);
                return err;
        }
 
-       printk( KERN_INFO "ALSA AC97: Driver Initialized\n" );
+       printk(KERN_INFO "ALSA AC97: Driver Initialized\n");
        au1000_card = card;
        return 0;
 }