Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / sound / drivers / vx / vx_pcm.c
index 9ee1c80..7e65a10 100644 (file)
 #include <sound/driver.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/delay.h>
 #include <sound/core.h>
 #include <sound/asoundef.h>
 #include <sound/pcm.h>
 #include <sound/vx_core.h>
 #include "vx_cmd.h"
 
-#define chip_t vx_core_t
-
 
 /*
  * we use a vmalloc'ed (sg-)buffer
  */
 
 /* get the physical page pointer on the given offset */
-static struct page *snd_pcm_get_vmalloc_page(snd_pcm_substream_t *subs, unsigned long offset)
+static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
+                                            unsigned long offset)
 {
        void *pageptr = subs->runtime->dma_area + offset;
        return vmalloc_to_page(pageptr);
@@ -73,14 +73,14 @@ static struct page *snd_pcm_get_vmalloc_page(snd_pcm_substream_t *subs, unsigned
  * called from hw_params
  * NOTE: this may be called not only once per pcm open!
  */
-static int snd_pcm_alloc_vmalloc_buffer(snd_pcm_substream_t *subs, size_t size)
+static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t size)
 {
-       snd_pcm_runtime_t *runtime = subs->runtime;
+       struct snd_pcm_runtime *runtime = subs->runtime;
        if (runtime->dma_area) {
                /* already allocated */
                if (runtime->dma_bytes >= size)
                        return 0; /* already enough large */
-               vfree_nocheck(runtime->dma_area); /* bypass the memory wrapper */
+               vfree(runtime->dma_area);
        }
        runtime->dma_area = vmalloc_32(size);
        if (! runtime->dma_area)
@@ -95,13 +95,12 @@ static int snd_pcm_alloc_vmalloc_buffer(snd_pcm_substream_t *subs, size_t size)
  * called from hw_free callback
  * NOTE: this may be called not only once per pcm open!
  */
-static int snd_pcm_free_vmalloc_buffer(snd_pcm_substream_t *subs)
+static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs)
 {
-       snd_pcm_runtime_t *runtime = subs->runtime;
-       if (runtime->dma_area) {
-               vfree_nocheck(runtime->dma_area); /* bypass the memory wrapper */
-               runtime->dma_area = NULL;
-       }
+       struct snd_pcm_runtime *runtime = subs->runtime;
+
+       vfree(runtime->dma_area);
+       runtime->dma_area = NULL;
        return 0;
 }
 
@@ -109,7 +108,8 @@ static int snd_pcm_free_vmalloc_buffer(snd_pcm_substream_t *subs)
 /*
  * read three pending pcm bytes via inb()
  */
-static void vx_pcm_read_per_bytes(vx_core_t *chip, snd_pcm_runtime_t *runtime, vx_pipe_t *pipe)
+static void vx_pcm_read_per_bytes(struct vx_core *chip, struct snd_pcm_runtime *runtime,
+                                 struct vx_pipe *pipe)
 {
        int offset = pipe->hw_ptr;
        unsigned char *buf = (unsigned char *)(runtime->dma_area + offset);
@@ -136,7 +136,8 @@ static void vx_pcm_read_per_bytes(vx_core_t *chip, snd_pcm_runtime_t *runtime, v
  * @pc_time: the pointer for the PC-time to set
  * @dsp_time: the pointer for RMH status time array
  */
-static void vx_set_pcx_time(vx_core_t *chip, pcx_time_t *pc_time, unsigned int *dsp_time)
+static void vx_set_pcx_time(struct vx_core *chip, pcx_time_t *pc_time,
+                           unsigned int *dsp_time)
 {
        dsp_time[0] = (unsigned int)((*pc_time) >> 24) & PCX_TIME_HI_MASK;
        dsp_time[1] = (unsigned int)(*pc_time) &  MASK_DSP_WORD;
@@ -152,7 +153,8 @@ static void vx_set_pcx_time(vx_core_t *chip, pcx_time_t *pc_time, unsigned int *
  *
  * returns the increase of the command length.
  */
-static int vx_set_differed_time(vx_core_t *chip, struct vx_rmh *rmh, vx_pipe_t *pipe)
+static int vx_set_differed_time(struct vx_core *chip, struct vx_rmh *rmh,
+                               struct vx_pipe *pipe)
 {
        /* Update The length added to the RMH command by the timestamp */
        if (! (pipe->differed_type & DC_DIFFERED_DELAY))
@@ -185,7 +187,8 @@ static int vx_set_differed_time(vx_core_t *chip, struct vx_rmh *rmh, vx_pipe_t *
  * @pipe: the affected pipe
  * @data: format bitmask
  */
-static int vx_set_stream_format(vx_core_t *chip, vx_pipe_t *pipe, unsigned int data)
+static int vx_set_stream_format(struct vx_core *chip, struct vx_pipe *pipe,
+                               unsigned int data)
 {
        struct vx_rmh rmh;
 
@@ -211,8 +214,8 @@ static int vx_set_stream_format(vx_core_t *chip, vx_pipe_t *pipe, unsigned int d
  *
  * returns 0 if successful, or a negative error code.
  */
-static int vx_set_format(vx_core_t *chip, vx_pipe_t *pipe,
-                        snd_pcm_runtime_t *runtime)
+static int vx_set_format(struct vx_core *chip, struct vx_pipe *pipe,
+                        struct snd_pcm_runtime *runtime)
 {
        unsigned int header = HEADER_FMT_BASE;
 
@@ -240,7 +243,7 @@ static int vx_set_format(vx_core_t *chip, vx_pipe_t *pipe,
 /*
  * set / query the IBL size
  */
-static int vx_set_ibl(vx_core_t *chip, struct vx_ibl_info *info)
+static int vx_set_ibl(struct vx_core *chip, struct vx_ibl_info *info)
 {
        int err;
        struct vx_rmh rmh;
@@ -270,7 +273,7 @@ static int vx_set_ibl(vx_core_t *chip, struct vx_ibl_info *info)
  *
  * called from trigger callback only
  */
-static int vx_get_pipe_state(vx_core_t *chip, vx_pipe_t *pipe, int *state)
+static int vx_get_pipe_state(struct vx_core *chip, struct vx_pipe *pipe, int *state)
 {
        int err;
        struct vx_rmh rmh;
@@ -295,7 +298,7 @@ static int vx_get_pipe_state(vx_core_t *chip, vx_pipe_t *pipe, int *state)
  *       you'll need to disconnect the host to get back to the
  *       normal mode.
  */
-static int vx_query_hbuffer_size(vx_core_t *chip, vx_pipe_t *pipe)
+static int vx_query_hbuffer_size(struct vx_core *chip, struct vx_pipe *pipe)
 {
        int result;
        struct vx_rmh rmh;
@@ -319,7 +322,7 @@ static int vx_query_hbuffer_size(vx_core_t *chip, vx_pipe_t *pipe)
  *
  * called from trigger callback only
  */
-static int vx_pipe_can_start(vx_core_t *chip, vx_pipe_t *pipe)
+static int vx_pipe_can_start(struct vx_core *chip, struct vx_pipe *pipe)
 {
        int err;
        struct vx_rmh rmh;
@@ -340,7 +343,7 @@ static int vx_pipe_can_start(vx_core_t *chip, vx_pipe_t *pipe)
  * vx_conf_pipe - tell the pipe to stand by and wait for IRQA.
  * @pipe: the pipe to be configured
  */
-static int vx_conf_pipe(vx_core_t *chip, vx_pipe_t *pipe)
+static int vx_conf_pipe(struct vx_core *chip, struct vx_pipe *pipe)
 {
        struct vx_rmh rmh;
 
@@ -354,7 +357,7 @@ static int vx_conf_pipe(vx_core_t *chip, vx_pipe_t *pipe)
 /*
  * vx_send_irqa - trigger IRQA
  */
-static int vx_send_irqa(vx_core_t *chip)
+static int vx_send_irqa(struct vx_core *chip)
 {
        struct vx_rmh rmh;
 
@@ -379,9 +382,9 @@ static int vx_send_irqa(vx_core_t *chip)
  * called from trigger callback only
  *
  */
-static int vx_toggle_pipe(vx_core_t *chip, vx_pipe_t *pipe, int state)
+static int vx_toggle_pipe(struct vx_core *chip, struct vx_pipe *pipe, int state)
 {
-       int err, i, cur_state, delay;
+       int err, i, cur_state;
 
        /* Check the pipe is not already in the requested state */
        if (vx_get_pipe_state(chip, pipe, &cur_state) < 0)
@@ -394,17 +397,14 @@ static int vx_toggle_pipe(vx_core_t *chip, vx_pipe_t *pipe, int state)
         * enough sound buffer for this pipe)
         */
        if (state) {
-               int delay = CAN_START_DELAY;
                for (i = 0 ; i < MAX_WAIT_FOR_DSP; i++) {
-                       snd_vx_delay(chip, delay);
                        err = vx_pipe_can_start(chip, pipe);
                        if (err > 0)
                                break;
                        /* Wait for a few, before asking again
                         * to avoid flooding the DSP with our requests
                         */
-                       if ((i % 4 ) == 0)
-                               delay <<= 1;
+                       mdelay(1);
                }
        }
     
@@ -418,15 +418,12 @@ static int vx_toggle_pipe(vx_core_t *chip, vx_pipe_t *pipe, int state)
         * reaching the expected state before returning
         * Check one pipe only (since they are synchronous)
         */
-       delay = WAIT_STATE_DELAY;
        for (i = 0; i < MAX_WAIT_FOR_DSP; i++) {
-               snd_vx_delay(chip, delay);
                err = vx_get_pipe_state(chip, pipe, &cur_state);
                if (err < 0 || cur_state == state)
                        break;
                err = -EIO;
-               if ((i % 4 ) == 0)
-                       delay <<= 1;
+               mdelay(1);
        }
        return err < 0 ? -EIO : 0;
 }
@@ -438,7 +435,7 @@ static int vx_toggle_pipe(vx_core_t *chip, vx_pipe_t *pipe, int state)
  *
  * called from trigger callback only
  */
-static int vx_stop_pipe(vx_core_t *chip, vx_pipe_t *pipe)
+static int vx_stop_pipe(struct vx_core *chip, struct vx_pipe *pipe)
 {
        struct vx_rmh rmh;
        vx_init_rmh(&rmh, CMD_STOP_PIPE);
@@ -456,16 +453,16 @@ static int vx_stop_pipe(vx_core_t *chip, vx_pipe_t *pipe)
  *
  * return 0 on success, or a negative error code.
  */
-static int vx_alloc_pipe(vx_core_t *chip, int capture,
+static int vx_alloc_pipe(struct vx_core *chip, int capture,
                         int audioid, int num_audio,
-                        vx_pipe_t **pipep)
+                        struct vx_pipe **pipep)
 {
        int err;
-       vx_pipe_t *pipe;
+       struct vx_pipe *pipe;
        struct vx_rmh rmh;
        int data_mode;
 
-       *pipep = 0;
+       *pipep = NULL;
        vx_init_rmh(&rmh, CMD_RES_PIPE);
        vx_set_pipe_cmd_params(&rmh, capture, audioid, num_audio);
 #if 0  // NYI
@@ -480,7 +477,7 @@ static int vx_alloc_pipe(vx_core_t *chip, int capture,
                return err;
 
        /* initialize the pipe record */
-       pipe = snd_magic_kcalloc(vx_pipe_t, 0, GFP_KERNEL);
+       pipe = kzalloc(sizeof(*pipe), GFP_KERNEL);
        if (! pipe) {
                /* release the pipe */
                vx_init_rmh(&rmh, CMD_FREE_PIPE);
@@ -506,7 +503,7 @@ static int vx_alloc_pipe(vx_core_t *chip, int capture,
  * vx_free_pipe - release a pipe
  * @pipe: pipe to be released
  */
-static int vx_free_pipe(vx_core_t *chip, vx_pipe_t *pipe)
+static int vx_free_pipe(struct vx_core *chip, struct vx_pipe *pipe)
 {
        struct vx_rmh rmh;
 
@@ -514,7 +511,7 @@ static int vx_free_pipe(vx_core_t *chip, vx_pipe_t *pipe)
        vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0);
        vx_send_msg(chip, &rmh);
 
-       snd_magic_kfree(pipe);
+       kfree(pipe);
        return 0;
 }
 
@@ -524,7 +521,7 @@ static int vx_free_pipe(vx_core_t *chip, vx_pipe_t *pipe)
  *
  * called from trigger callback only
  */
-static int vx_start_stream(vx_core_t *chip, vx_pipe_t *pipe)
+static int vx_start_stream(struct vx_core *chip, struct vx_pipe *pipe)
 {
        struct vx_rmh rmh;
 
@@ -540,7 +537,7 @@ static int vx_start_stream(vx_core_t *chip, vx_pipe_t *pipe)
  *
  * called from trigger callback only
  */
-static int vx_stop_stream(vx_core_t *chip, vx_pipe_t *pipe)
+static int vx_stop_stream(struct vx_core *chip, struct vx_pipe *pipe)
 {
        struct vx_rmh rmh;
 
@@ -554,10 +551,12 @@ static int vx_stop_stream(vx_core_t *chip, vx_pipe_t *pipe)
  * playback hw information
  */
 
-static snd_pcm_hardware_t vx_pcm_playback_hw = {
+static struct snd_pcm_hardware vx_pcm_playback_hw = {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                                SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID),
-       .formats =              /*SNDRV_PCM_FMTBIT_U8 |*/ SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE,
+                                SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID /*|*/
+                                /*SNDRV_PCM_INFO_RESUME*/),
+       .formats =              (/*SNDRV_PCM_FMTBIT_U8 |*/
+                                SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE),
        .rates =                SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
        .rate_min =             5000,
        .rate_max =             48000,
@@ -577,11 +576,11 @@ static void vx_pcm_delayed_start(unsigned long arg);
 /*
  * vx_pcm_playback_open - open callback for playback
  */
-static int vx_pcm_playback_open(snd_pcm_substream_t *subs)
+static int vx_pcm_playback_open(struct snd_pcm_substream *subs)
 {
-       snd_pcm_runtime_t *runtime = subs->runtime;
-       vx_core_t *chip = snd_pcm_substream_chip(subs);
-       vx_pipe_t *pipe = 0;
+       struct snd_pcm_runtime *runtime = subs->runtime;
+       struct vx_core *chip = snd_pcm_substream_chip(subs);
+       struct vx_pipe *pipe = NULL;
        unsigned int audio;
        int err;
 
@@ -621,18 +620,18 @@ static int vx_pcm_playback_open(snd_pcm_substream_t *subs)
 /*
  * vx_pcm_playback_close - close callback for playback
  */
-static int vx_pcm_playback_close(snd_pcm_substream_t *subs)
+static int vx_pcm_playback_close(struct snd_pcm_substream *subs)
 {
-       vx_core_t *chip = snd_pcm_substream_chip(subs);
-       vx_pipe_t *pipe;
+       struct vx_core *chip = snd_pcm_substream_chip(subs);
+       struct vx_pipe *pipe;
 
        if (! subs->runtime->private_data)
                return -EINVAL;
 
-       pipe = snd_magic_cast(vx_pipe_t, subs->runtime->private_data, return -EINVAL);
+       pipe = subs->runtime->private_data;
 
        if (--pipe->references == 0) {
-               chip->playback_pipes[pipe->number] = 0;
+               chip->playback_pipes[pipe->number] = NULL;
                vx_free_pipe(chip, pipe);
        }
 
@@ -647,7 +646,7 @@ static int vx_pcm_playback_close(snd_pcm_substream_t *subs)
  *
  * NB: call with a certain lock.
  */
-static int vx_notify_end_of_buffer(vx_core_t *chip, vx_pipe_t *pipe)
+static int vx_notify_end_of_buffer(struct vx_core *chip, struct vx_pipe *pipe)
 {
        int err;
        struct vx_rmh rmh;  /* use a temporary rmh here */
@@ -675,7 +674,9 @@ static int vx_notify_end_of_buffer(vx_core_t *chip, vx_pipe_t *pipe)
  *
  * return 0 if ok.
  */
-static int vx_pcm_playback_transfer_chunk(vx_core_t *chip, snd_pcm_runtime_t *runtime, vx_pipe_t *pipe, int size)
+static int vx_pcm_playback_transfer_chunk(struct vx_core *chip,
+                                         struct snd_pcm_runtime *runtime,
+                                         struct vx_pipe *pipe, int size)
 {
        int space, err = 0;
 
@@ -711,7 +712,9 @@ static int vx_pcm_playback_transfer_chunk(vx_core_t *chip, snd_pcm_runtime_t *ru
  * so that the caller can check the total transferred size later
  * (to call snd_pcm_period_elapsed).
  */
-static int vx_update_pipe_position(vx_core_t *chip, snd_pcm_runtime_t *runtime, vx_pipe_t *pipe)
+static int vx_update_pipe_position(struct vx_core *chip,
+                                  struct snd_pcm_runtime *runtime,
+                                  struct vx_pipe *pipe)
 {
        struct vx_rmh rmh;
        int err, update;
@@ -737,10 +740,12 @@ static int vx_update_pipe_position(vx_core_t *chip, snd_pcm_runtime_t *runtime,
  * transfer the pending playback buffer data to DSP
  * called from interrupt handler
  */
-static void vx_pcm_playback_transfer(vx_core_t *chip, snd_pcm_substream_t *subs, vx_pipe_t *pipe, int nchunks)
+static void vx_pcm_playback_transfer(struct vx_core *chip,
+                                    struct snd_pcm_substream *subs,
+                                    struct vx_pipe *pipe, int nchunks)
 {
        int i, err;
-       snd_pcm_runtime_t *runtime = subs->runtime;
+       struct snd_pcm_runtime *runtime = subs->runtime;
 
        if (! pipe->prepared || (chip->chip_status & VX_STAT_IS_STALE))
                return;
@@ -755,10 +760,12 @@ static void vx_pcm_playback_transfer(vx_core_t *chip, snd_pcm_substream_t *subs,
  * update the playback position and call snd_pcm_period_elapsed() if necessary
  * called from interrupt handler
  */
-static void vx_pcm_playback_update(vx_core_t *chip, snd_pcm_substream_t *subs, vx_pipe_t *pipe)
+static void vx_pcm_playback_update(struct vx_core *chip,
+                                  struct snd_pcm_substream *subs,
+                                  struct vx_pipe *pipe)
 {
        int err;
-       snd_pcm_runtime_t *runtime = subs->runtime;
+       struct snd_pcm_runtime *runtime = subs->runtime;
 
        if (pipe->running && ! (chip->chip_status & VX_STAT_IS_STALE)) {
                if ((err = vx_update_pipe_position(chip, runtime, pipe)) < 0)
@@ -777,9 +784,9 @@ static void vx_pcm_playback_update(vx_core_t *chip, snd_pcm_substream_t *subs, v
  */
 static void vx_pcm_delayed_start(unsigned long arg)
 {
-       snd_pcm_substream_t *subs = (snd_pcm_substream_t *)arg;
-       vx_core_t *chip = snd_magic_cast(vx_core_t, subs->pcm->private_data, return);
-       vx_pipe_t *pipe = snd_magic_cast(vx_pipe_t, subs->runtime->private_data, return);
+       struct snd_pcm_substream *subs = (struct snd_pcm_substream *)arg;
+       struct vx_core *chip = subs->pcm->private_data;
+       struct vx_pipe *pipe = subs->runtime->private_data;
        int err;
 
        /*  printk( KERN_DEBUG "DDDD tasklet delayed start jiffies = %ld\n", jiffies);*/
@@ -798,10 +805,10 @@ static void vx_pcm_delayed_start(unsigned long arg)
 /*
  * vx_pcm_playback_trigger - trigger callback for playback
  */
-static int vx_pcm_trigger(snd_pcm_substream_t *subs, int cmd)
+static int vx_pcm_trigger(struct snd_pcm_substream *subs, int cmd)
 {
-       vx_core_t *chip = snd_pcm_substream_chip(subs);
-       vx_pipe_t *pipe = snd_magic_cast(vx_pipe_t, subs->runtime->private_data, return -EINVAL);
+       struct vx_core *chip = snd_pcm_substream_chip(subs);
+       struct vx_pipe *pipe = subs->runtime->private_data;
        int err;
 
        if (chip->chip_status & VX_STAT_IS_STALE)
@@ -809,6 +816,7 @@ static int vx_pcm_trigger(snd_pcm_substream_t *subs, int cmd)
                
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
                if (! pipe->is_capture)
                        vx_pcm_playback_transfer(chip, subs, pipe, 2);
                /* FIXME:
@@ -820,6 +828,7 @@ static int vx_pcm_trigger(snd_pcm_substream_t *subs, int cmd)
                pipe->running = 1;
                break;
        case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
                vx_toggle_pipe(chip, pipe, 0);
                vx_stop_pipe(chip, pipe);
                vx_stop_stream(chip, pipe);
@@ -843,18 +852,18 @@ static int vx_pcm_trigger(snd_pcm_substream_t *subs, int cmd)
 /*
  * vx_pcm_playback_pointer - pointer callback for playback
  */
-static snd_pcm_uframes_t vx_pcm_playback_pointer(snd_pcm_substream_t *subs)
+static snd_pcm_uframes_t vx_pcm_playback_pointer(struct snd_pcm_substream *subs)
 {
-       snd_pcm_runtime_t *runtime = subs->runtime;
-       vx_pipe_t *pipe = snd_magic_cast(vx_pipe_t, runtime->private_data, return -EINVAL);
+       struct snd_pcm_runtime *runtime = subs->runtime;
+       struct vx_pipe *pipe = runtime->private_data;
        return pipe->position;
 }
 
 /*
  * vx_pcm_hw_params - hw_params callback for playback and capture
  */
-static int vx_pcm_hw_params(snd_pcm_substream_t *subs,
-                                    snd_pcm_hw_params_t *hw_params)
+static int vx_pcm_hw_params(struct snd_pcm_substream *subs,
+                                    struct snd_pcm_hw_params *hw_params)
 {
        return snd_pcm_alloc_vmalloc_buffer(subs, params_buffer_bytes(hw_params));
 }
@@ -862,7 +871,7 @@ static int vx_pcm_hw_params(snd_pcm_substream_t *subs,
 /*
  * vx_pcm_hw_free - hw_free callback for playback and capture
  */
-static int vx_pcm_hw_free(snd_pcm_substream_t *subs)
+static int vx_pcm_hw_free(struct snd_pcm_substream *subs)
 {
        return snd_pcm_free_vmalloc_buffer(subs);
 }
@@ -870,11 +879,11 @@ static int vx_pcm_hw_free(snd_pcm_substream_t *subs)
 /*
  * vx_pcm_prepare - prepare callback for playback and capture
  */
-static int vx_pcm_prepare(snd_pcm_substream_t *subs)
+static int vx_pcm_prepare(struct snd_pcm_substream *subs)
 {
-       vx_core_t *chip = snd_pcm_substream_chip(subs);
-       snd_pcm_runtime_t *runtime = subs->runtime;
-       vx_pipe_t *pipe = snd_magic_cast(vx_pipe_t, runtime->private_data, return -EINVAL);
+       struct vx_core *chip = snd_pcm_substream_chip(subs);
+       struct snd_pcm_runtime *runtime = subs->runtime;
+       struct vx_pipe *pipe = runtime->private_data;
        int err, data_mode;
        // int max_size, nchunks;
 
@@ -901,7 +910,8 @@ static int vx_pcm_prepare(snd_pcm_substream_t *subs)
        }
 
        if (chip->pcm_running && chip->freq != runtime->rate) {
-               snd_printk(KERN_ERR "vx: cannot set different clock %d from the current %d\n", runtime->rate, chip->freq);
+               snd_printk(KERN_ERR "vx: cannot set different clock %d "
+                          "from the current %d\n", runtime->rate, chip->freq);
                return -EINVAL;
        }
        vx_set_clock(chip, runtime->rate);
@@ -934,7 +944,7 @@ static int vx_pcm_prepare(snd_pcm_substream_t *subs)
 /*
  * operators for PCM playback
  */
-static snd_pcm_ops_t vx_pcm_playback_ops = {
+static struct snd_pcm_ops vx_pcm_playback_ops = {
        .open =         vx_pcm_playback_open,
        .close =        vx_pcm_playback_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -951,10 +961,12 @@ static snd_pcm_ops_t vx_pcm_playback_ops = {
  * playback hw information
  */
 
-static snd_pcm_hardware_t vx_pcm_capture_hw = {
+static struct snd_pcm_hardware vx_pcm_capture_hw = {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                                SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID),
-       .formats =              /*SNDRV_PCM_FMTBIT_U8 |*/ SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE,
+                                SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP_VALID /*|*/
+                                /*SNDRV_PCM_INFO_RESUME*/),
+       .formats =              (/*SNDRV_PCM_FMTBIT_U8 |*/
+                                SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_3LE),
        .rates =                SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
        .rate_min =             5000,
        .rate_max =             48000,
@@ -972,12 +984,12 @@ static snd_pcm_hardware_t vx_pcm_capture_hw = {
 /*
  * vx_pcm_capture_open - open callback for capture
  */
-static int vx_pcm_capture_open(snd_pcm_substream_t *subs)
+static int vx_pcm_capture_open(struct snd_pcm_substream *subs)
 {
-       snd_pcm_runtime_t *runtime = subs->runtime;
-       vx_core_t *chip = snd_pcm_substream_chip(subs);
-       vx_pipe_t *pipe;
-       vx_pipe_t *pipe_out_monitoring = NULL;
+       struct snd_pcm_runtime *runtime = subs->runtime;
+       struct vx_core *chip = snd_pcm_substream_chip(subs);
+       struct vx_pipe *pipe;
+       struct vx_pipe *pipe_out_monitoring = NULL;
        unsigned int audio;
        int err;
 
@@ -1008,9 +1020,11 @@ static int vx_pcm_capture_open(snd_pcm_substream_t *subs)
                   if an output pipe is available, it's audios still may need to be 
                   unmuted. hence we'll have to call a mixer entry point.
                */
-               vx_set_monitor_level(chip, audio, chip->audio_monitor[audio], chip->audio_monitor_active[audio]);
+               vx_set_monitor_level(chip, audio, chip->audio_monitor[audio],
+                                    chip->audio_monitor_active[audio]);
                /* assuming stereo */
-               vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1], chip->audio_monitor_active[audio+1]); 
+               vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1],
+                                    chip->audio_monitor_active[audio+1]); 
        }
 
        pipe->monitoring_pipe = pipe_out_monitoring; /* default value NULL */
@@ -1029,16 +1043,16 @@ static int vx_pcm_capture_open(snd_pcm_substream_t *subs)
 /*
  * vx_pcm_capture_close - close callback for capture
  */
-static int vx_pcm_capture_close(snd_pcm_substream_t *subs)
+static int vx_pcm_capture_close(struct snd_pcm_substream *subs)
 {
-       vx_core_t *chip = snd_pcm_substream_chip(subs);
-       vx_pipe_t *pipe;
-       vx_pipe_t *pipe_out_monitoring;
+       struct vx_core *chip = snd_pcm_substream_chip(subs);
+       struct vx_pipe *pipe;
+       struct vx_pipe *pipe_out_monitoring;
        
        if (! subs->runtime->private_data)
                return -EINVAL;
-       pipe = snd_magic_cast(vx_pipe_t, subs->runtime->private_data, return -EINVAL);
-       chip->capture_pipes[pipe->number] = 0;
+       pipe = subs->runtime->private_data;
+       chip->capture_pipes[pipe->number] = NULL;
 
        pipe_out_monitoring = pipe->monitoring_pipe;
 
@@ -1049,8 +1063,8 @@ static int vx_pcm_capture_close(snd_pcm_substream_t *subs)
        if (pipe_out_monitoring) {
                if (--pipe_out_monitoring->references == 0) {
                        vx_free_pipe(chip, pipe_out_monitoring);
-                       chip->playback_pipes[pipe->number] = 0;
-                       pipe->monitoring_pipe = 0;
+                       chip->playback_pipes[pipe->number] = NULL;
+                       pipe->monitoring_pipe = NULL;
                }
        }
        
@@ -1065,10 +1079,11 @@ static int vx_pcm_capture_close(snd_pcm_substream_t *subs)
 /*
  * vx_pcm_capture_update - update the capture buffer
  */
-static void vx_pcm_capture_update(vx_core_t *chip, snd_pcm_substream_t *subs, vx_pipe_t *pipe)
+static void vx_pcm_capture_update(struct vx_core *chip, struct snd_pcm_substream *subs,
+                                 struct vx_pipe *pipe)
 {
        int size, space, count;
-       snd_pcm_runtime_t *runtime = subs->runtime;
+       struct snd_pcm_runtime *runtime = subs->runtime;
 
        if (! pipe->prepared || (chip->chip_status & VX_STAT_IS_STALE))
                return;
@@ -1138,17 +1153,17 @@ static void vx_pcm_capture_update(vx_core_t *chip, snd_pcm_substream_t *subs, vx
 /*
  * vx_pcm_capture_pointer - pointer callback for capture
  */
-static snd_pcm_uframes_t vx_pcm_capture_pointer(snd_pcm_substream_t *subs)
+static snd_pcm_uframes_t vx_pcm_capture_pointer(struct snd_pcm_substream *subs)
 {
-       snd_pcm_runtime_t *runtime = subs->runtime;
-       vx_pipe_t *pipe = snd_magic_cast(vx_pipe_t, runtime->private_data, return -EINVAL);
+       struct snd_pcm_runtime *runtime = subs->runtime;
+       struct vx_pipe *pipe = runtime->private_data;
        return bytes_to_frames(runtime, pipe->hw_ptr);
 }
 
 /*
  * operators for PCM capture
  */
-static snd_pcm_ops_t vx_pcm_capture_ops = {
+static struct snd_pcm_ops vx_pcm_capture_ops = {
        .open =         vx_pcm_capture_open,
        .close =        vx_pcm_capture_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1164,10 +1179,10 @@ static snd_pcm_ops_t vx_pcm_capture_ops = {
 /*
  * interrupt handler for pcm streams
  */
-void vx_pcm_update_intr(vx_core_t *chip, unsigned int events)
+void vx_pcm_update_intr(struct vx_core *chip, unsigned int events)
 {
        unsigned int i;
-       vx_pipe_t *pipe;
+       struct vx_pipe *pipe;
 
 #define EVENT_MASK     (END_OF_BUFFER_EVENTS_PENDING|ASYNC_EVENTS_PENDING)
 
@@ -1221,7 +1236,7 @@ void vx_pcm_update_intr(vx_core_t *chip, unsigned int events)
 /*
  * vx_init_audio_io - check the availabe audio i/o and allocate pipe arrays
  */
-static int vx_init_audio_io(vx_core_t *chip)
+static int vx_init_audio_io(struct vx_core *chip)
 {
        struct vx_rmh rmh;
        int preferred;
@@ -1237,19 +1252,21 @@ static int vx_init_audio_io(vx_core_t *chip)
        chip->audio_info = rmh.Stat[1];
 
        /* allocate pipes */
-       chip->playback_pipes = kmalloc(sizeof(vx_pipe_t *) * chip->audio_outs, GFP_KERNEL);
-       chip->capture_pipes = kmalloc(sizeof(vx_pipe_t *) * chip->audio_ins, GFP_KERNEL);
-       if (! chip->playback_pipes || ! chip->capture_pipes)
+       chip->playback_pipes = kcalloc(chip->audio_outs, sizeof(struct vx_pipe *), GFP_KERNEL);
+       if (!chip->playback_pipes)
                return -ENOMEM;
-
-       memset(chip->playback_pipes, 0, sizeof(vx_pipe_t *) * chip->audio_outs);
-       memset(chip->capture_pipes, 0, sizeof(vx_pipe_t *) * chip->audio_ins);
+       chip->capture_pipes = kcalloc(chip->audio_ins, sizeof(struct vx_pipe *), GFP_KERNEL);
+       if (!chip->capture_pipes) {
+               kfree(chip->playback_pipes);
+               return -ENOMEM;
+       }
 
        preferred = chip->ibl.size;
        chip->ibl.size = 0;
        vx_set_ibl(chip, &chip->ibl); /* query the info */
        if (preferred > 0) {
-               chip->ibl.size = ((preferred + chip->ibl.granularity - 1) / chip->ibl.granularity) * chip->ibl.granularity;
+               chip->ibl.size = ((preferred + chip->ibl.granularity - 1) /
+                                 chip->ibl.granularity) * chip->ibl.granularity;
                if (chip->ibl.size > chip->ibl.max_size)
                        chip->ibl.size = chip->ibl.max_size;
        } else
@@ -1263,26 +1280,22 @@ static int vx_init_audio_io(vx_core_t *chip)
 /*
  * free callback for pcm
  */
-static void snd_vx_pcm_free(snd_pcm_t *pcm)
+static void snd_vx_pcm_free(struct snd_pcm *pcm)
 {
-       vx_core_t *chip = snd_magic_cast(vx_core_t, pcm->private_data, return);
+       struct vx_core *chip = pcm->private_data;
        chip->pcm[pcm->device] = NULL;
-       if (chip->playback_pipes) {
-               kfree(chip->playback_pipes);
-               chip->playback_pipes = 0;
-       }
-       if (chip->capture_pipes) {
-               kfree(chip->capture_pipes);
-               chip->capture_pipes = 0;
-       }
+       kfree(chip->playback_pipes);
+       chip->playback_pipes = NULL;
+       kfree(chip->capture_pipes);
+       chip->capture_pipes = NULL;
 }
 
 /*
  * snd_vx_pcm_new - create and initialize a pcm
  */
-int snd_vx_pcm_new(vx_core_t *chip)
+int snd_vx_pcm_new(struct vx_core *chip)
 {
-       snd_pcm_t *pcm;
+       struct snd_pcm *pcm;
        unsigned int i;
        int err;