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 / dummy.c
index e707b8f..ffeafaf 100644 (file)
 
 #include <sound/driver.h>
 #include <linux/init.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
 #include <linux/jiffies.h>
 #include <linux/slab.h>
 #include <linux/time.h>
 #include <linux/wait.h>
+#include <linux/moduleparam.h>
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/pcm.h>
 #include <sound/rawmidi.h>
-#define SNDRV_GET_ID
 #include <sound/initval.h>
 
 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
 MODULE_DESCRIPTION("Dummy soundcard (/dev/null)");
 MODULE_LICENSE("GPL");
-MODULE_CLASSES("{sound}");
-MODULE_DEVICES("{{ALSA,Dummy soundcard}}");
+MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}");
 
 #define MAX_PCM_DEVICES                4
 #define MAX_PCM_SUBSTREAMS     16
@@ -43,7 +44,7 @@ MODULE_DEVICES("{{ALSA,Dummy soundcard}}");
 
 #if 0 /* emu10k1 emulation */
 #define MAX_BUFFER_SIZE                (128 * 1024)
-static int emu10k1_playback_constraints(snd_pcm_runtime_t *runtime)
+static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime)
 {
        int err;
        if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
@@ -91,11 +92,27 @@ static int emu10k1_playback_constraints(snd_pcm_runtime_t *runtime)
 #define USE_RATE_MAX           48000
 #endif
 
+#if 0 /* CA0106 */
+#define USE_FORMATS            SNDRV_PCM_FMTBIT_S16_LE
+#define USE_CHANNELS_MIN       2
+#define USE_CHANNELS_MAX       2
+#define USE_RATE               (SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000) 
+#define USE_RATE_MIN           48000 
+#define USE_RATE_MAX           192000
+#define MAX_BUFFER_SIZE                ((65536-64)*8)
+#define MAX_PERIOD_SIZE                (65536-64)
+#define USE_PERIODS_MIN                2
+#define USE_PERIODS_MAX                8
+#endif
+
 
 /* defaults */
 #ifndef MAX_BUFFER_SIZE
 #define MAX_BUFFER_SIZE                (64*1024)
 #endif
+#ifndef MAX_PERIOD_SIZE
+#define MAX_PERIOD_SIZE                MAX_BUFFER_SIZE
+#endif
 #ifndef USE_FORMATS
 #define USE_FORMATS            (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
 #endif
@@ -130,24 +147,20 @@ static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
 static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8};
 //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
 
-MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for dummy soundcard.");
-MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
-MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
+module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string for dummy soundcard.");
-MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
-MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable this dummy soundcard.");
-MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
-MODULE_PARM(pcm_devs, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+module_param_array(pcm_devs, int, NULL, 0444);
 MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver.");
-MODULE_PARM_SYNTAX(pcm_devs, SNDRV_ENABLED ",allows:{{0,4}},default:1,dialog:list");
-MODULE_PARM(pcm_substreams, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+module_param_array(pcm_substreams, int, NULL, 0444);
 MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver.");
-MODULE_PARM_SYNTAX(pcm_substreams, SNDRV_ENABLED ",allows:{{1,16}},default:8,dialog:list");
-//MODULE_PARM(midi_devs, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
+//module_param_array(midi_devs, int, NULL, 0444);
 //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
-//MODULE_PARM_SYNTAX(midi_devs, SNDRV_ENABLED ",allows:{{0,2}},default:8,dialog:list");
+
+static struct platform_device *devices[SNDRV_CARDS];
 
 #define MIXER_ADDR_MASTER      0
 #define MIXER_ADDR_LINE                1
@@ -156,15 +169,16 @@ MODULE_PARM_SYNTAX(pcm_substreams, SNDRV_ENABLED ",allows:{{1,16}},default:8,dia
 #define MIXER_ADDR_CD          4
 #define MIXER_ADDR_LAST                4
 
-typedef struct snd_card_dummy {
-       snd_card_t *card;
+struct snd_dummy {
+       struct snd_card *card;
+       struct snd_pcm *pcm;
        spinlock_t mixer_lock;
        int mixer_volume[MIXER_ADDR_LAST+1][2];
        int capture_source[MIXER_ADDR_LAST+1][2];
-} snd_card_dummy_t;
+};
 
-typedef struct snd_card_dummy_pcm {
-       snd_card_dummy_t *dummy;
+struct snd_dummy_pcm {
+       struct snd_dummy *dummy;
        spinlock_t lock;
        struct timer_list timer;
        unsigned int pcm_size;
@@ -173,73 +187,49 @@ typedef struct snd_card_dummy_pcm {
        unsigned int pcm_jiffie;        /* bytes per one jiffie */
        unsigned int pcm_irq_pos;       /* IRQ position */
        unsigned int pcm_buf_pos;       /* position in buffer */
-       snd_pcm_substream_t *substream;
-} snd_card_dummy_pcm_t;
-
-static snd_card_t *snd_dummy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
+       struct snd_pcm_substream *substream;
+};
 
 
-static int snd_card_dummy_playback_ioctl(snd_pcm_substream_t * substream,
-                                        unsigned int cmd,
-                                        void *arg)
+static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm)
 {
-       return snd_pcm_lib_ioctl(substream, cmd, arg);
-}
-
-static int snd_card_dummy_capture_ioctl(snd_pcm_substream_t * substream,
-                                       unsigned int cmd,
-                                       void *arg)
-{
-       return snd_pcm_lib_ioctl(substream, cmd, arg);
-}
-
-static void snd_card_dummy_pcm_timer_start(snd_pcm_substream_t * substream)
-{
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_card_dummy_pcm_t *dpcm = snd_magic_cast(snd_card_dummy_pcm_t, runtime->private_data, return);
-
        dpcm->timer.expires = 1 + jiffies;
        add_timer(&dpcm->timer);
 }
 
-static void snd_card_dummy_pcm_timer_stop(snd_pcm_substream_t * substream)
+static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm)
 {
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_card_dummy_pcm_t *dpcm = snd_magic_cast(snd_card_dummy_pcm_t, runtime->private_data, return);
-
        del_timer(&dpcm->timer);
 }
 
-static int snd_card_dummy_playback_trigger(snd_pcm_substream_t * substream,
-                                          int cmd)
-{
-       if (cmd == SNDRV_PCM_TRIGGER_START) {
-               snd_card_dummy_pcm_timer_start(substream);
-       } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
-               snd_card_dummy_pcm_timer_stop(substream);
-       } else {
-               return -EINVAL;
-       }
-       return 0;
-}
-
-static int snd_card_dummy_capture_trigger(snd_pcm_substream_t * substream,
-                                         int cmd)
-{
-       if (cmd == SNDRV_PCM_TRIGGER_START) {
-               snd_card_dummy_pcm_timer_start(substream);
-       } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
-               snd_card_dummy_pcm_timer_stop(substream);
-       } else {
-               return -EINVAL;
+static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_dummy_pcm *dpcm = runtime->private_data;
+       int err = 0;
+
+       spin_lock(&dpcm->lock);
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
+               snd_card_dummy_pcm_timer_start(dpcm);
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
+               snd_card_dummy_pcm_timer_stop(dpcm);
+               break;
+       default:
+               err = -EINVAL;
+               break;
        }
+       spin_unlock(&dpcm->lock);
        return 0;
 }
 
-static int snd_card_dummy_pcm_prepare(snd_pcm_substream_t * substream)
+static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
 {
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_card_dummy_pcm_t *dpcm = snd_magic_cast(snd_card_dummy_pcm_t, runtime->private_data, return -ENXIO);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_dummy_pcm *dpcm = runtime->private_data;
        unsigned int bps;
 
        bps = runtime->rate * runtime->channels;
@@ -256,53 +246,37 @@ static int snd_card_dummy_pcm_prepare(snd_pcm_substream_t * substream)
        return 0;
 }
 
-static int snd_card_dummy_playback_prepare(snd_pcm_substream_t * substream)
-{
-       return snd_card_dummy_pcm_prepare(substream);
-}
-
-static int snd_card_dummy_capture_prepare(snd_pcm_substream_t * substream)
-{
-       return snd_card_dummy_pcm_prepare(substream);
-}
-
 static void snd_card_dummy_pcm_timer_function(unsigned long data)
 {
-       snd_card_dummy_pcm_t *dpcm = snd_magic_cast(snd_card_dummy_pcm_t, (void *)data, return);
+       struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data;
+       unsigned long flags;
        
+       spin_lock_irqsave(&dpcm->lock, flags);
        dpcm->timer.expires = 1 + jiffies;
        add_timer(&dpcm->timer);
-       spin_lock_irq(&dpcm->lock);
        dpcm->pcm_irq_pos += dpcm->pcm_jiffie;
        dpcm->pcm_buf_pos += dpcm->pcm_jiffie;
        dpcm->pcm_buf_pos %= dpcm->pcm_size;
        if (dpcm->pcm_irq_pos >= dpcm->pcm_count) {
                dpcm->pcm_irq_pos %= dpcm->pcm_count;
+               spin_unlock_irqrestore(&dpcm->lock, flags);
                snd_pcm_period_elapsed(dpcm->substream);
-       }
-       spin_unlock_irq(&dpcm->lock);   
-}
-
-static snd_pcm_uframes_t snd_card_dummy_playback_pointer(snd_pcm_substream_t * substream)
-{
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_card_dummy_pcm_t *dpcm = snd_magic_cast(snd_card_dummy_pcm_t, runtime->private_data, return -ENXIO);
-
-       return bytes_to_frames(runtime, dpcm->pcm_buf_pos);
+       } else
+               spin_unlock_irqrestore(&dpcm->lock, flags);
 }
 
-static snd_pcm_uframes_t snd_card_dummy_capture_pointer(snd_pcm_substream_t * substream)
+static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream)
 {
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_card_dummy_pcm_t *dpcm = snd_magic_cast(snd_card_dummy_pcm_t, runtime->private_data, return -ENXIO);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_dummy_pcm *dpcm = runtime->private_data;
 
        return bytes_to_frames(runtime, dpcm->pcm_buf_pos);
 }
 
-static snd_pcm_hardware_t snd_card_dummy_playback =
+static struct snd_pcm_hardware snd_card_dummy_playback =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                                SNDRV_PCM_INFO_MMAP_VALID),
+                                SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
        .formats =              USE_FORMATS,
        .rates =                USE_RATE,
        .rate_min =             USE_RATE_MIN,
@@ -317,10 +291,10 @@ static snd_pcm_hardware_t snd_card_dummy_playback =
        .fifo_size =            0,
 };
 
-static snd_pcm_hardware_t snd_card_dummy_capture =
+static struct snd_pcm_hardware snd_card_dummy_capture =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                                SNDRV_PCM_INFO_MMAP_VALID),
+                                SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
        .formats =              USE_FORMATS,
        .rates =                USE_RATE,
        .rate_min =             USE_RATE_MIN,
@@ -329,36 +303,51 @@ static snd_pcm_hardware_t snd_card_dummy_capture =
        .channels_max =         USE_CHANNELS_MAX,
        .buffer_bytes_max =     MAX_BUFFER_SIZE,
        .period_bytes_min =     64,
-       .period_bytes_max =     MAX_BUFFER_SIZE,
+       .period_bytes_max =     MAX_PERIOD_SIZE,
        .periods_min =          USE_PERIODS_MIN,
        .periods_max =          USE_PERIODS_MAX,
        .fifo_size =            0,
 };
 
-static void snd_card_dummy_runtime_free(snd_pcm_runtime_t *runtime)
+static void snd_card_dummy_runtime_free(struct snd_pcm_runtime *runtime)
 {
-       snd_card_dummy_pcm_t *dpcm = snd_magic_cast(snd_card_dummy_pcm_t, runtime->private_data, return);
-       snd_magic_kfree(dpcm);
+       kfree(runtime->private_data);
 }
 
-static int snd_card_dummy_playback_open(snd_pcm_substream_t * substream)
+static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream,
+                                   struct snd_pcm_hw_params *hw_params)
 {
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_card_dummy_pcm_t *dpcm;
-       int err;
+       return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
+}
 
-       dpcm = snd_magic_kcalloc(snd_card_dummy_pcm_t, 0, GFP_KERNEL);
-       if (dpcm == NULL)
-               return -ENOMEM;
-       if ((runtime->dma_area = snd_malloc_pages_fallback(MAX_BUFFER_SIZE, GFP_KERNEL, &runtime->dma_bytes)) == NULL) {
-               snd_magic_kfree(dpcm);
-               return -ENOMEM;
-       }
+static int snd_card_dummy_hw_free(struct snd_pcm_substream *substream)
+{
+       return snd_pcm_lib_free_pages(substream);
+}
+
+static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream)
+{
+       struct snd_dummy_pcm *dpcm;
+
+       dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
+       if (! dpcm)
+               return dpcm;
        init_timer(&dpcm->timer);
        dpcm->timer.data = (unsigned long) dpcm;
        dpcm->timer.function = snd_card_dummy_pcm_timer_function;
        spin_lock_init(&dpcm->lock);
        dpcm->substream = substream;
+       return dpcm;
+}
+
+static int snd_card_dummy_playback_open(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_dummy_pcm *dpcm;
+       int err;
+
+       if ((dpcm = new_pcm_stream(substream)) == NULL)
+               return -ENOMEM;
        runtime->private_data = dpcm;
        runtime->private_free = snd_card_dummy_runtime_free;
        runtime->hw = snd_card_dummy_playback;
@@ -369,32 +358,21 @@ static int snd_card_dummy_playback_open(snd_pcm_substream_t * substream)
        if (substream->pcm->device & 2)
                runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
        if ((err = add_playback_constraints(runtime)) < 0) {
-               snd_magic_kfree(dpcm);
+               kfree(dpcm);
                return err;
        }
 
        return 0;
 }
 
-static int snd_card_dummy_capture_open(snd_pcm_substream_t * substream)
+static int snd_card_dummy_capture_open(struct snd_pcm_substream *substream)
 {
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_card_dummy_pcm_t *dpcm;
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_dummy_pcm *dpcm;
        int err;
 
-       dpcm = snd_magic_kcalloc(snd_card_dummy_pcm_t, 0, GFP_KERNEL);
-       if (dpcm == NULL)
+       if ((dpcm = new_pcm_stream(substream)) == NULL)
                return -ENOMEM;
-       if ((runtime->dma_area = snd_malloc_pages_fallback(MAX_BUFFER_SIZE, GFP_KERNEL, &runtime->dma_bytes)) == NULL) {
-               snd_magic_kfree(dpcm);
-               return -ENOMEM;
-       }
-       memset(runtime->dma_area, 0, runtime->dma_bytes);
-       init_timer(&dpcm->timer);
-       dpcm->timer.data = (unsigned long) dpcm;
-       dpcm->timer.function = snd_card_dummy_pcm_timer_function;
-       spin_lock_init(&dpcm->lock);
-       dpcm->substream = substream;
        runtime->private_data = dpcm;
        runtime->private_free = snd_card_dummy_runtime_free;
        runtime->hw = snd_card_dummy_capture;
@@ -405,59 +383,62 @@ static int snd_card_dummy_capture_open(snd_pcm_substream_t * substream)
        if (substream->pcm->device & 2)
                runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP|SNDRV_PCM_INFO_MMAP_VALID);
        if ((err = add_capture_constraints(runtime)) < 0) {
-               snd_magic_kfree(dpcm);
+               kfree(dpcm);
                return err;
        }
 
        return 0;
 }
 
-static int snd_card_dummy_playback_close(snd_pcm_substream_t * substream)
+static int snd_card_dummy_playback_close(struct snd_pcm_substream *substream)
 {
-       snd_pcm_runtime_t *runtime = substream->runtime;
-
-       snd_free_pages(runtime->dma_area, runtime->dma_bytes);
        return 0;
 }
 
-static int snd_card_dummy_capture_close(snd_pcm_substream_t * substream)
+static int snd_card_dummy_capture_close(struct snd_pcm_substream *substream)
 {
-       snd_pcm_runtime_t *runtime = substream->runtime;
-
-       snd_free_pages(runtime->dma_area, runtime->dma_bytes);
        return 0;
 }
 
-static snd_pcm_ops_t snd_card_dummy_playback_ops = {
+static struct snd_pcm_ops snd_card_dummy_playback_ops = {
        .open =                 snd_card_dummy_playback_open,
        .close =                snd_card_dummy_playback_close,
-       .ioctl =                snd_card_dummy_playback_ioctl,
-       .prepare =              snd_card_dummy_playback_prepare,
-       .trigger =              snd_card_dummy_playback_trigger,
-       .pointer =              snd_card_dummy_playback_pointer,
+       .ioctl =                snd_pcm_lib_ioctl,
+       .hw_params =            snd_card_dummy_hw_params,
+       .hw_free =              snd_card_dummy_hw_free,
+       .prepare =              snd_card_dummy_pcm_prepare,
+       .trigger =              snd_card_dummy_pcm_trigger,
+       .pointer =              snd_card_dummy_pcm_pointer,
 };
 
-static snd_pcm_ops_t snd_card_dummy_capture_ops = {
+static struct snd_pcm_ops snd_card_dummy_capture_ops = {
        .open =                 snd_card_dummy_capture_open,
        .close =                snd_card_dummy_capture_close,
-       .ioctl =                snd_card_dummy_capture_ioctl,
-       .prepare =              snd_card_dummy_capture_prepare,
-       .trigger =              snd_card_dummy_capture_trigger,
-       .pointer =              snd_card_dummy_capture_pointer,
+       .ioctl =                snd_pcm_lib_ioctl,
+       .hw_params =            snd_card_dummy_hw_params,
+       .hw_free =              snd_card_dummy_hw_free,
+       .prepare =              snd_card_dummy_pcm_prepare,
+       .trigger =              snd_card_dummy_pcm_trigger,
+       .pointer =              snd_card_dummy_pcm_pointer,
 };
 
-static int __init snd_card_dummy_pcm(snd_card_dummy_t *dummy, int device, int substreams)
+static int __init snd_card_dummy_pcm(struct snd_dummy *dummy, int device, int substreams)
 {
-       snd_pcm_t *pcm;
+       struct snd_pcm *pcm;
        int err;
 
-       if ((err = snd_pcm_new(dummy->card, "Dummy PCM", device, substreams, substreams, &pcm)) < 0)
+       if ((err = snd_pcm_new(dummy->card, "Dummy PCM", device,
+                              substreams, substreams, &pcm)) < 0)
                return err;
+       dummy->pcm = pcm;
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_dummy_playback_ops);
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_dummy_capture_ops);
        pcm->private_data = dummy;
        pcm->info_flags = 0;
        strcpy(pcm->name, "Dummy PCM");
+       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
+                                             snd_dma_continuous_data(GFP_KERNEL),
+                                             0, 64*1024);
        return 0;
 }
 
@@ -467,7 +448,8 @@ static int __init snd_card_dummy_pcm(snd_card_dummy_t *dummy, int device, int su
   .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \
   .private_value = addr }
 
-static int snd_dummy_volume_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
        uinfo->count = 2;
@@ -476,23 +458,23 @@ static int snd_dummy_volume_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t
        return 0;
 }
  
-static int snd_dummy_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
 {
-       snd_card_dummy_t *dummy = _snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
        int addr = kcontrol->private_value;
 
-       spin_lock_irqsave(&dummy->mixer_lock, flags);
+       spin_lock_irq(&dummy->mixer_lock);
        ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0];
        ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1];
-       spin_unlock_irqrestore(&dummy->mixer_lock, flags);
+       spin_unlock_irq(&dummy->mixer_lock);
        return 0;
-}                                                                                                                                                                                                                                                                                                            
+}
 
-static int snd_dummy_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
 {
-       snd_card_dummy_t *dummy = _snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
        int change, addr = kcontrol->private_value;
        int left, right;
 
@@ -506,14 +488,14 @@ static int snd_dummy_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
                right = -50;
        if (right > 100)
                right = 100;
-       spin_lock_irqsave(&dummy->mixer_lock, flags);
+       spin_lock_irq(&dummy->mixer_lock);
        change = dummy->mixer_volume[addr][0] != left ||
                 dummy->mixer_volume[addr][1] != right;
        dummy->mixer_volume[addr][0] = left;
        dummy->mixer_volume[addr][1] = right;
-       spin_unlock_irqrestore(&dummy->mixer_lock, flags);
+       spin_unlock_irq(&dummy->mixer_lock);
        return change;
-}                                                                                                                                                                                                                                                                                                            
+}
 
 #define DUMMY_CAPSRC(xname, xindex, addr) \
 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
@@ -521,7 +503,8 @@ static int snd_dummy_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
   .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \
   .private_value = addr }
 
-static int snd_dummy_capsrc_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_dummy_capsrc_info(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
        uinfo->count = 2;
@@ -530,40 +513,37 @@ static int snd_dummy_capsrc_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t
        return 0;
 }
  
-static int snd_dummy_capsrc_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
 {
-       snd_card_dummy_t *dummy = _snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
        int addr = kcontrol->private_value;
 
-       spin_lock_irqsave(&dummy->mixer_lock, flags);
+       spin_lock_irq(&dummy->mixer_lock);
        ucontrol->value.integer.value[0] = dummy->capture_source[addr][0];
        ucontrol->value.integer.value[1] = dummy->capture_source[addr][1];
-       spin_unlock_irqrestore(&dummy->mixer_lock, flags);
+       spin_unlock_irq(&dummy->mixer_lock);
        return 0;
 }
 
-static int snd_dummy_capsrc_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       snd_card_dummy_t *dummy = _snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
        int change, addr = kcontrol->private_value;
        int left, right;
 
        left = ucontrol->value.integer.value[0] & 1;
        right = ucontrol->value.integer.value[1] & 1;
-       spin_lock_irqsave(&dummy->mixer_lock, flags);
+       spin_lock_irq(&dummy->mixer_lock);
        change = dummy->capture_source[addr][0] != left &&
                 dummy->capture_source[addr][1] != right;
        dummy->capture_source[addr][0] = left;
        dummy->capture_source[addr][1] = right;
-       spin_unlock_irqrestore(&dummy->mixer_lock, flags);
+       spin_unlock_irq(&dummy->mixer_lock);
        return change;
-}                                                                                                                                                                                                                                                                                                            
-
-#define DUMMY_CONTROLS (sizeof(snd_dummy_controls)/sizeof(snd_kcontrol_new_t))
+}
 
-static snd_kcontrol_new_t snd_dummy_controls[] = {
+static struct snd_kcontrol_new snd_dummy_controls[] = {
 DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
 DUMMY_CAPSRC("Master Capture Switch", 0, MIXER_ADDR_MASTER),
 DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH),
@@ -576,9 +556,9 @@ DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
 DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_MASTER)
 };
 
-int __init snd_card_dummy_new_mixer(snd_card_dummy_t * dummy)
+static int __init snd_card_dummy_new_mixer(struct snd_dummy *dummy)
 {
-       snd_card_t *card = dummy->card;
+       struct snd_card *card = dummy->card;
        unsigned int idx;
        int err;
 
@@ -586,26 +566,25 @@ int __init snd_card_dummy_new_mixer(snd_card_dummy_t * dummy)
        spin_lock_init(&dummy->mixer_lock);
        strcpy(card->mixername, "Dummy Mixer");
 
-       for (idx = 0; idx < DUMMY_CONTROLS; idx++) {
+       for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) {
                if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy))) < 0)
                        return err;
        }
        return 0;
 }
 
-static int __init snd_card_dummy_probe(int dev)
+static int __init snd_dummy_probe(struct platform_device *devptr)
 {
-       snd_card_t *card;
-       struct snd_card_dummy *dummy;
+       struct snd_card *card;
+       struct snd_dummy *dummy;
        int idx, err;
+       int dev = devptr->id;
 
-       if (!enable[dev])
-               return -ENODEV;
        card = snd_card_new(index[dev], id[dev], THIS_MODULE,
-                           sizeof(struct snd_card_dummy));
+                           sizeof(struct snd_dummy));
        if (card == NULL)
                return -ENOMEM;
-       dummy = (struct snd_card_dummy *)card->private_data;
+       dummy = card->private_data;
        dummy->card = card;
        for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) {
                if (pcm_substreams[dev] < 1)
@@ -620,8 +599,11 @@ static int __init snd_card_dummy_probe(int dev)
        strcpy(card->driver, "Dummy");
        strcpy(card->shortname, "Dummy");
        sprintf(card->longname, "Dummy %i", dev + 1);
+
+       snd_card_set_dev(card, &devptr->dev);
+
        if ((err = snd_card_register(card)) == 0) {
-               snd_dummy_cards[dev] = card;
+               platform_set_drvdata(devptr, card);
                return 0;
        }
       __nodev:
@@ -629,23 +611,84 @@ static int __init snd_card_dummy_probe(int dev)
        return err;
 }
 
-static int __init alsa_card_dummy_init(void)
+static int snd_dummy_remove(struct platform_device *devptr)
+{
+       snd_card_free(platform_get_drvdata(devptr));
+       platform_set_drvdata(devptr, NULL);
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int snd_dummy_suspend(struct platform_device *pdev, pm_message_t state)
 {
-       int dev, cards;
+       struct snd_card *card = platform_get_drvdata(pdev);
+       struct snd_dummy *dummy = card->private_data;
 
-       for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
-               if (snd_card_dummy_probe(dev) < 0) {
-#ifdef MODULE
-                       printk(KERN_ERR "Dummy soundcard #%i not found or device busy\n", dev + 1);
+       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+       snd_pcm_suspend_all(dummy->pcm);
+       return 0;
+}
+       
+static int snd_dummy_resume(struct platform_device *pdev)
+{
+       struct snd_card *card = platform_get_drvdata(pdev);
+
+       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
+       return 0;
+}
+#endif
+
+#define SND_DUMMY_DRIVER       "snd_dummy"
+
+static struct platform_driver snd_dummy_driver = {
+       .probe          = snd_dummy_probe,
+       .remove         = snd_dummy_remove,
+#ifdef CONFIG_PM
+       .suspend        = snd_dummy_suspend,
+       .resume         = snd_dummy_resume,
 #endif
-                       break;
+       .driver         = {
+               .name   = SND_DUMMY_DRIVER
+       },
+};
+
+static void __init_or_module snd_dummy_unregister_all(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(devices); ++i)
+               platform_device_unregister(devices[i]);
+       platform_driver_unregister(&snd_dummy_driver);
+}
+
+static int __init alsa_card_dummy_init(void)
+{
+       int i, cards, err;
+
+       if ((err = platform_driver_register(&snd_dummy_driver)) < 0)
+               return err;
+
+       cards = 0;
+       for (i = 0; i < SNDRV_CARDS; i++) {
+               struct platform_device *device;
+               if (! enable[i])
+                       continue;
+               device = platform_device_register_simple(SND_DUMMY_DRIVER,
+                                                        i, NULL, 0);
+               if (IS_ERR(device))
+                       continue;
+               if (!platform_get_drvdata(device)) {
+                       platform_device_unregister(device);
+                       continue;
                }
+               devices[i] = device;
                cards++;
        }
        if (!cards) {
 #ifdef MODULE
                printk(KERN_ERR "Dummy soundcard not found or device busy\n");
 #endif
+               snd_dummy_unregister_all();
                return -ENODEV;
        }
        return 0;
@@ -653,35 +696,8 @@ static int __init alsa_card_dummy_init(void)
 
 static void __exit alsa_card_dummy_exit(void)
 {
-       int idx;
-
-       for (idx = 0; idx < SNDRV_CARDS; idx++)
-               snd_card_free(snd_dummy_cards[idx]);
+       snd_dummy_unregister_all();
 }
 
 module_init(alsa_card_dummy_init)
 module_exit(alsa_card_dummy_exit)
-
-#ifndef MODULE
-
-/* format is: snd-dummy=enable,index,id,
-                       pcm_devs,pcm_substreams */
-
-static int __init alsa_card_dummy_setup(char *str)
-{
-       static unsigned __initdata nr_dev = 0;
-
-       if (nr_dev >= SNDRV_CARDS)
-               return 0;
-       (void)(get_option(&str,&enable[nr_dev]) == 2 &&
-              get_option(&str,&index[nr_dev]) == 2 &&
-              get_id(&str,&id[nr_dev]) == 2 &&
-              get_option(&str,&pcm_devs[nr_dev]) == 2 &&
-              get_option(&str,&pcm_substreams[nr_dev]) == 2);
-       nr_dev++;
-       return 1;
-}
-
-__setup("snd-dummy=", alsa_card_dummy_setup);
-
-#endif /* ifndef MODULE */