ALSA: snd-usb-caiaq: Simplify single case to an 'if'
[safe/jmp/linux-2.6] / sound / drivers / dummy.c
index e8e29bf..7f41990 100644 (file)
@@ -33,6 +33,7 @@
 #include <sound/tlv.h>
 #include <sound/pcm.h>
 #include <sound/rawmidi.h>
+#include <sound/info.h>
 #include <sound/initval.h>
 
 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
@@ -41,118 +42,33 @@ MODULE_LICENSE("GPL");
 MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}");
 
 #define MAX_PCM_DEVICES                4
-#define MAX_PCM_SUBSTREAMS     16
+#define MAX_PCM_SUBSTREAMS     128
 #define MAX_MIDI_DEVICES       2
 
-#if 0 /* emu10k1 emulation */
-#define MAX_BUFFER_SIZE                (128 * 1024)
-static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime)
-{
-       int err;
-       err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
-       if (err < 0)
-               return err;
-       err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX);
-       if (err < 0)
-               return err;
-       return 0;
-}
-#define add_playback_constraints emu10k1_playback_constraints
-#endif
-
-#if 0 /* RME9652 emulation */
-#define MAX_BUFFER_SIZE                (26 * 64 * 1024)
-#define USE_FORMATS            SNDRV_PCM_FMTBIT_S32_LE
-#define USE_CHANNELS_MIN       26
-#define USE_CHANNELS_MAX       26
-#define USE_PERIODS_MIN                2
-#define USE_PERIODS_MAX                2
-#endif
-
-#if 0 /* ICE1712 emulation */
-#define MAX_BUFFER_SIZE                (256 * 1024)
-#define USE_FORMATS            SNDRV_PCM_FMTBIT_S32_LE
-#define USE_CHANNELS_MIN       10
-#define USE_CHANNELS_MAX       10
-#define USE_PERIODS_MIN                1
-#define USE_PERIODS_MAX                1024
-#endif
-
-#if 0 /* UDA1341 emulation */
-#define MAX_BUFFER_SIZE                (16380)
-#define USE_FORMATS            SNDRV_PCM_FMTBIT_S16_LE
-#define USE_CHANNELS_MIN       2
-#define USE_CHANNELS_MAX       2
-#define USE_PERIODS_MIN                2
-#define USE_PERIODS_MAX                255
-#endif
-
-#if 0 /* simple AC97 bridge (intel8x0) with 48kHz AC97 only codec */
-#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
-#define USE_RATE_MIN           48000
-#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 MIN_PERIOD_SIZE                64
 #define MAX_PERIOD_SIZE                MAX_BUFFER_SIZE
-#endif
-#ifndef USE_FORMATS
 #define USE_FORMATS            (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
-#endif
-#ifndef USE_RATE
 #define USE_RATE               SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000
 #define USE_RATE_MIN           5500
 #define USE_RATE_MAX           48000
-#endif
-#ifndef USE_CHANNELS_MIN
 #define USE_CHANNELS_MIN       1
-#endif
-#ifndef USE_CHANNELS_MAX
 #define USE_CHANNELS_MAX       2
-#endif
-#ifndef USE_PERIODS_MIN
 #define USE_PERIODS_MIN        1
-#endif
-#ifndef USE_PERIODS_MAX
 #define USE_PERIODS_MAX        1024
-#endif
-#ifndef add_playback_constraints
-#define add_playback_constraints(x) 0
-#endif
-#ifndef add_capture_constraints
-#define add_capture_constraints(x) 0
-#endif
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
 static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
+static char *model[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = NULL};
 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};
 #ifdef CONFIG_HIGH_RES_TIMERS
 static int hrtimer = 1;
 #endif
+static int fake_buffer = 1;
 
 module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for dummy soundcard.");
@@ -160,12 +76,16 @@ module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string for dummy soundcard.");
 module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable this dummy soundcard.");
+module_param_array(model, charp, NULL, 0444);
+MODULE_PARM_DESC(model, "Soundcard model.");
 module_param_array(pcm_devs, int, NULL, 0444);
 MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver.");
 module_param_array(pcm_substreams, int, NULL, 0444);
-MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver.");
+MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-128) for dummy driver.");
 //module_param_array(midi_devs, int, NULL, 0444);
 //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
+module_param(fake_buffer, bool, 0444);
+MODULE_PARM_DESC(fake_buffer, "Fake buffer allocations.");
 #ifdef CONFIG_HIGH_RES_TIMERS
 module_param(hrtimer, bool, 0644);
 MODULE_PARM_DESC(hrtimer, "Use hrtimer as the timer source.");
@@ -189,9 +109,28 @@ struct dummy_timer_ops {
        snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *);
 };
 
+struct dummy_model {
+       const char *name;
+       int (*playback_constraints)(struct snd_pcm_runtime *runtime);
+       int (*capture_constraints)(struct snd_pcm_runtime *runtime);
+       u64 formats;
+       size_t buffer_bytes_max;
+       size_t period_bytes_min;
+       size_t period_bytes_max;
+       unsigned int periods_min;
+       unsigned int periods_max;
+       unsigned int rates;
+       unsigned int rate_min;
+       unsigned int rate_max;
+       unsigned int channels_min;
+       unsigned int channels_max;
+};
+
 struct snd_dummy {
        struct snd_card *card;
+       struct dummy_model *model;
        struct snd_pcm *pcm;
+       struct snd_pcm_hardware pcm_hw;
        spinlock_t mixer_lock;
        int mixer_volume[MIXER_ADDR_LAST+1][2];
        int capture_source[MIXER_ADDR_LAST+1][2];
@@ -199,6 +138,92 @@ struct snd_dummy {
 };
 
 /*
+ * card models
+ */
+
+static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime)
+{
+       int err;
+       err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
+       if (err < 0)
+               return err;
+       err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX);
+       if (err < 0)
+               return err;
+       return 0;
+}
+
+struct dummy_model model_emu10k1 = {
+       .name = "emu10k1",
+       .playback_constraints = emu10k1_playback_constraints,
+       .buffer_bytes_max = 128 * 1024,
+};
+
+struct dummy_model model_rme9652 = {
+       .name = "rme9652",
+       .buffer_bytes_max = 26 * 64 * 1024,
+       .formats = SNDRV_PCM_FMTBIT_S32_LE,
+       .channels_min = 26,
+       .channels_max = 26,
+       .periods_min = 2,
+       .periods_max = 2,
+};
+
+struct dummy_model model_ice1712 = {
+       .name = "ice1712",
+       .buffer_bytes_max = 256 * 1024,
+       .formats = SNDRV_PCM_FMTBIT_S32_LE,
+       .channels_min = 10,
+       .channels_max = 10,
+       .periods_min = 1,
+       .periods_max = 1024,
+};
+
+struct dummy_model model_uda1341 = {
+       .name = "uda1341",
+       .buffer_bytes_max = 16380,
+       .formats = SNDRV_PCM_FMTBIT_S16_LE,
+       .channels_min = 2,
+       .channels_max = 2,
+       .periods_min = 2,
+       .periods_max = 255,
+};
+
+struct dummy_model model_ac97 = {
+       .name = "ac97",
+       .formats = SNDRV_PCM_FMTBIT_S16_LE,
+       .channels_min = 2,
+       .channels_max = 2,
+       .rates = SNDRV_PCM_RATE_48000,
+       .rate_min = 48000,
+       .rate_max = 48000,
+};
+
+struct dummy_model model_ca0106 = {
+       .name = "ca0106",
+       .formats = SNDRV_PCM_FMTBIT_S16_LE,
+       .buffer_bytes_max = ((65536-64)*8),
+       .period_bytes_max = (65536-64),
+       .periods_min = 2,
+       .periods_max = 8,
+       .channels_min = 2,
+       .channels_max = 2,
+       .rates = SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000,
+       .rate_min = 48000,
+       .rate_max = 192000,
+};
+
+struct dummy_model *dummy_models[] = {
+       &model_emu10k1,
+       &model_rme9652,
+       &model_ice1712,
+       &model_uda1341,
+       &model_ac97,
+       &model_ca0106,
+       NULL
+};
+
+/*
  * system timer interface
  */
 
@@ -481,11 +506,8 @@ static int dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 
 static int dummy_pcm_prepare(struct snd_pcm_substream *substream)
 {
-       struct snd_pcm_runtime *runtime = substream->runtime;
        struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
 
-       snd_pcm_format_set_silence(runtime->format, runtime->dma_area,
-                       bytes_to_samples(runtime, runtime->dma_bytes));
        return dummy->timer_ops->prepare(substream);
 }
 
@@ -508,7 +530,7 @@ static struct snd_pcm_hardware dummy_pcm_hardware = {
        .channels_min =         USE_CHANNELS_MIN,
        .channels_max =         USE_CHANNELS_MAX,
        .buffer_bytes_max =     MAX_BUFFER_SIZE,
-       .period_bytes_min =     64,
+       .period_bytes_min =     MIN_PERIOD_SIZE,
        .period_bytes_max =     MAX_PERIOD_SIZE,
        .periods_min =          USE_PERIODS_MIN,
        .periods_max =          USE_PERIODS_MAX,
@@ -518,18 +540,26 @@ static struct snd_pcm_hardware dummy_pcm_hardware = {
 static int dummy_pcm_hw_params(struct snd_pcm_substream *substream,
                               struct snd_pcm_hw_params *hw_params)
 {
+       if (fake_buffer) {
+               /* runtime->dma_bytes has to be set manually to allow mmap */
+               substream->runtime->dma_bytes = params_buffer_bytes(hw_params);
+               return 0;
+       }
        return snd_pcm_lib_malloc_pages(substream,
                                        params_buffer_bytes(hw_params));
 }
 
 static int dummy_pcm_hw_free(struct snd_pcm_substream *substream)
 {
+       if (fake_buffer)
+               return 0;
        return snd_pcm_lib_free_pages(substream);
 }
 
 static int dummy_pcm_open(struct snd_pcm_substream *substream)
 {
        struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
+       struct dummy_model *model = dummy->model;
        struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
@@ -543,7 +573,7 @@ static int dummy_pcm_open(struct snd_pcm_substream *substream)
        if (err < 0)
                return err;
 
-       runtime->hw = dummy_pcm_hardware;
+       runtime->hw = dummy->pcm_hw;
        if (substream->pcm->device & 1) {
                runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED;
                runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
@@ -552,10 +582,16 @@ static int dummy_pcm_open(struct snd_pcm_substream *substream)
                runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP |
                                      SNDRV_PCM_INFO_MMAP_VALID);
 
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-               err = add_playback_constraints(substream->runtime);
-       else
-               err = add_capture_constraints(substream->runtime);
+       if (model == NULL)
+               return 0;
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+               if (model->playback_constraints)
+                       err = model->playback_constraints(substream->runtime);
+       } else {
+               if (model->capture_constraints)
+                       err = model->capture_constraints(substream->runtime);
+       }
        if (err < 0) {
                dummy->timer_ops->free(substream);
                return err;
@@ -570,6 +606,60 @@ static int dummy_pcm_close(struct snd_pcm_substream *substream)
        return 0;
 }
 
+/*
+ * dummy buffer handling
+ */
+
+static void *dummy_page[2];
+
+static void free_fake_buffer(void)
+{
+       if (fake_buffer) {
+               int i;
+               for (i = 0; i < 2; i++)
+                       if (dummy_page[i]) {
+                               free_page((unsigned long)dummy_page[i]);
+                               dummy_page[i] = NULL;
+                       }
+       }
+}
+
+static int alloc_fake_buffer(void)
+{
+       int i;
+
+       if (!fake_buffer)
+               return 0;
+       for (i = 0; i < 2; i++) {
+               dummy_page[i] = (void *)get_zeroed_page(GFP_KERNEL);
+               if (!dummy_page[i]) {
+                       free_fake_buffer();
+                       return -ENOMEM;
+               }
+       }
+       return 0;
+}
+
+static int dummy_pcm_copy(struct snd_pcm_substream *substream,
+                         int channel, snd_pcm_uframes_t pos,
+                         void __user *dst, snd_pcm_uframes_t count)
+{
+       return 0; /* do nothing */
+}
+
+static int dummy_pcm_silence(struct snd_pcm_substream *substream,
+                            int channel, snd_pcm_uframes_t pos,
+                            snd_pcm_uframes_t count)
+{
+       return 0; /* do nothing */
+}
+
+static struct page *dummy_pcm_page(struct snd_pcm_substream *substream,
+                                  unsigned long offset)
+{
+       return virt_to_page(dummy_page[substream->stream]); /* the same page */
+}
+
 static struct snd_pcm_ops dummy_pcm_ops = {
        .open =         dummy_pcm_open,
        .close =        dummy_pcm_close,
@@ -581,10 +671,25 @@ static struct snd_pcm_ops dummy_pcm_ops = {
        .pointer =      dummy_pcm_pointer,
 };
 
+static struct snd_pcm_ops dummy_pcm_ops_no_buf = {
+       .open =         dummy_pcm_open,
+       .close =        dummy_pcm_close,
+       .ioctl =        snd_pcm_lib_ioctl,
+       .hw_params =    dummy_pcm_hw_params,
+       .hw_free =      dummy_pcm_hw_free,
+       .prepare =      dummy_pcm_prepare,
+       .trigger =      dummy_pcm_trigger,
+       .pointer =      dummy_pcm_pointer,
+       .copy =         dummy_pcm_copy,
+       .silence =      dummy_pcm_silence,
+       .page =         dummy_pcm_page,
+};
+
 static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device,
                                        int substreams)
 {
        struct snd_pcm *pcm;
+       struct snd_pcm_ops *ops;
        int err;
 
        err = snd_pcm_new(dummy->card, "Dummy PCM", device,
@@ -592,17 +697,28 @@ static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device,
        if (err < 0)
                return err;
        dummy->pcm = pcm;
-       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &dummy_pcm_ops);
-       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &dummy_pcm_ops);
+       if (fake_buffer)
+               ops = &dummy_pcm_ops_no_buf;
+       else
+               ops = &dummy_pcm_ops;
+       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, ops);
+       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_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);
+       if (!fake_buffer) {
+               snd_pcm_lib_preallocate_pages_for_all(pcm,
+                       SNDRV_DMA_TYPE_CONTINUOUS,
+                       snd_dma_continuous_data(GFP_KERNEL),
+                       0, 64*1024);
+       }
        return 0;
 }
 
+/*
+ * mixer interface
+ */
+
 #define DUMMY_VOLUME(xname, xindex, addr) \
 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
   .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
@@ -720,8 +836,6 @@ static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
        unsigned int idx;
        int err;
 
-       if (snd_BUG_ON(!dummy))
-               return -EINVAL;
        spin_lock_init(&dummy->mixer_lock);
        strcpy(card->mixername, "Dummy Mixer");
 
@@ -733,10 +847,141 @@ static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
        return 0;
 }
 
+#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_PROC_FS)
+/*
+ * proc interface
+ */
+static void print_formats(struct snd_dummy *dummy,
+                         struct snd_info_buffer *buffer)
+{
+       int i;
+
+       for (i = 0; i < SNDRV_PCM_FORMAT_LAST; i++) {
+               if (dummy->pcm_hw.formats & (1ULL << i))
+                       snd_iprintf(buffer, " %s", snd_pcm_format_name(i));
+       }
+}
+
+static void print_rates(struct snd_dummy *dummy,
+                       struct snd_info_buffer *buffer)
+{
+       static int rates[] = {
+               5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000,
+               64000, 88200, 96000, 176400, 192000,
+       };
+       int i;
+
+       if (dummy->pcm_hw.rates & SNDRV_PCM_RATE_CONTINUOUS)
+               snd_iprintf(buffer, " continuous");
+       if (dummy->pcm_hw.rates & SNDRV_PCM_RATE_KNOT)
+               snd_iprintf(buffer, " knot");
+       for (i = 0; i < ARRAY_SIZE(rates); i++)
+               if (dummy->pcm_hw.rates & (1 << i))
+                       snd_iprintf(buffer, " %d", rates[i]);
+}
+
+#define get_dummy_int_ptr(dummy, ofs) \
+       (unsigned int *)((char *)&((dummy)->pcm_hw) + (ofs))
+#define get_dummy_ll_ptr(dummy, ofs) \
+       (unsigned long long *)((char *)&((dummy)->pcm_hw) + (ofs))
+
+struct dummy_hw_field {
+       const char *name;
+       const char *format;
+       unsigned int offset;
+       unsigned int size;
+};
+#define FIELD_ENTRY(item, fmt) {                  \
+       .name = #item,                             \
+       .format = fmt,                             \
+       .offset = offsetof(struct snd_pcm_hardware, item), \
+       .size = sizeof(dummy_pcm_hardware.item) }
+
+static struct dummy_hw_field fields[] = {
+       FIELD_ENTRY(formats, "%#llx"),
+       FIELD_ENTRY(rates, "%#x"),
+       FIELD_ENTRY(rate_min, "%d"),
+       FIELD_ENTRY(rate_max, "%d"),
+       FIELD_ENTRY(channels_min, "%d"),
+       FIELD_ENTRY(channels_max, "%d"),
+       FIELD_ENTRY(buffer_bytes_max, "%ld"),
+       FIELD_ENTRY(period_bytes_min, "%ld"),
+       FIELD_ENTRY(period_bytes_max, "%ld"),
+       FIELD_ENTRY(periods_min, "%d"),
+       FIELD_ENTRY(periods_max, "%d"),
+};
+
+static void dummy_proc_read(struct snd_info_entry *entry,
+                           struct snd_info_buffer *buffer)
+{
+       struct snd_dummy *dummy = entry->private_data;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(fields); i++) {
+               snd_iprintf(buffer, "%s ", fields[i].name);
+               if (fields[i].size == sizeof(int))
+                       snd_iprintf(buffer, fields[i].format,
+                               *get_dummy_int_ptr(dummy, fields[i].offset));
+               else
+                       snd_iprintf(buffer, fields[i].format,
+                               *get_dummy_ll_ptr(dummy, fields[i].offset));
+               if (!strcmp(fields[i].name, "formats"))
+                       print_formats(dummy, buffer);
+               else if (!strcmp(fields[i].name, "rates"))
+                       print_rates(dummy, buffer);
+               snd_iprintf(buffer, "\n");
+       }
+}
+
+static void dummy_proc_write(struct snd_info_entry *entry,
+                            struct snd_info_buffer *buffer)
+{
+       struct snd_dummy *dummy = entry->private_data;
+       char line[64];
+
+       while (!snd_info_get_line(buffer, line, sizeof(line))) {
+               char item[20];
+               const char *ptr;
+               unsigned long long val;
+               int i;
+
+               ptr = snd_info_get_str(item, line, sizeof(item));
+               for (i = 0; i < ARRAY_SIZE(fields); i++) {
+                       if (!strcmp(item, fields[i].name))
+                               break;
+               }
+               if (i >= ARRAY_SIZE(fields))
+                       continue;
+               snd_info_get_str(item, ptr, sizeof(item));
+               if (strict_strtoull(item, 0, &val))
+                       continue;
+               if (fields[i].size == sizeof(int))
+                       *get_dummy_int_ptr(dummy, fields[i].offset) = val;
+               else
+                       *get_dummy_ll_ptr(dummy, fields[i].offset) = val;
+       }
+}
+
+static void __devinit dummy_proc_init(struct snd_dummy *chip)
+{
+       struct snd_info_entry *entry;
+
+       if (!snd_card_proc_new(chip->card, "dummy_pcm", &entry)) {
+               snd_info_set_text_ops(entry, chip, dummy_proc_read);
+               entry->c.text.write = dummy_proc_write;
+               entry->mode |= S_IWUSR;
+               entry->private_data = chip;
+       }
+}
+#else
+#define dummy_proc_init(x)
+#endif /* CONFIG_SND_DEBUG && CONFIG_PROC_FS */
+
 static int __devinit snd_dummy_probe(struct platform_device *devptr)
 {
        struct snd_card *card;
        struct snd_dummy *dummy;
+       struct dummy_model *m = NULL, **mdl;
        int idx, err;
        int dev = devptr->id;
 
@@ -746,6 +991,15 @@ static int __devinit snd_dummy_probe(struct platform_device *devptr)
                return err;
        dummy = card->private_data;
        dummy->card = card;
+       for (mdl = dummy_models; *mdl && model[dev]; mdl++) {
+               if (strcmp(model[dev], (*mdl)->name) == 0) {
+                       printk(KERN_INFO
+                               "snd-dummy: Using model '%s' for card %i\n",
+                               (*mdl)->name, card->number);
+                       m = dummy->model = *mdl;
+                       break;
+               }
+       }
        for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) {
                if (pcm_substreams[dev] < 1)
                        pcm_substreams[dev] = 1;
@@ -755,6 +1009,33 @@ static int __devinit snd_dummy_probe(struct platform_device *devptr)
                if (err < 0)
                        goto __nodev;
        }
+
+       dummy->pcm_hw = dummy_pcm_hardware;
+       if (m) {
+               if (m->formats)
+                       dummy->pcm_hw.formats = m->formats;
+               if (m->buffer_bytes_max)
+                       dummy->pcm_hw.buffer_bytes_max = m->buffer_bytes_max;
+               if (m->period_bytes_min)
+                       dummy->pcm_hw.period_bytes_min = m->period_bytes_min;
+               if (m->period_bytes_max)
+                       dummy->pcm_hw.period_bytes_max = m->period_bytes_max;
+               if (m->periods_min)
+                       dummy->pcm_hw.periods_min = m->periods_min;
+               if (m->periods_max)
+                       dummy->pcm_hw.periods_max = m->periods_max;
+               if (m->rates)
+                       dummy->pcm_hw.rates = m->rates;
+               if (m->rate_min)
+                       dummy->pcm_hw.rate_min = m->rate_min;
+               if (m->rate_max)
+                       dummy->pcm_hw.rate_max = m->rate_max;
+               if (m->channels_min)
+                       dummy->pcm_hw.channels_min = m->channels_min;
+               if (m->channels_max)
+                       dummy->pcm_hw.channels_max = m->channels_max;
+       }
+
        err = snd_card_dummy_new_mixer(dummy);
        if (err < 0)
                goto __nodev;
@@ -762,6 +1043,8 @@ static int __devinit snd_dummy_probe(struct platform_device *devptr)
        strcpy(card->shortname, "Dummy");
        sprintf(card->longname, "Dummy %i", dev + 1);
 
+       dummy_proc_init(dummy);
+
        snd_card_set_dev(card, &devptr->dev);
 
        err = snd_card_register(card);
@@ -822,6 +1105,7 @@ static void snd_dummy_unregister_all(void)
        for (i = 0; i < ARRAY_SIZE(devices); ++i)
                platform_device_unregister(devices[i]);
        platform_driver_unregister(&snd_dummy_driver);
+       free_fake_buffer();
 }
 
 static int __init alsa_card_dummy_init(void)
@@ -832,6 +1116,12 @@ static int __init alsa_card_dummy_init(void)
        if (err < 0)
                return err;
 
+       err = alloc_fake_buffer();
+       if (err < 0) {
+               platform_driver_unregister(&snd_dummy_driver);
+               return err;
+       }
+
        cards = 0;
        for (i = 0; i < SNDRV_CARDS; i++) {
                struct platform_device *device;