summaryrefslogtreecommitdiffstats
path: root/sound/drivers/dummy.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/drivers/dummy.c')
-rw-r--r--sound/drivers/dummy.c364
1 files changed, 210 insertions, 154 deletions
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index 64ef7f62851d..14e1a671b5cf 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -20,6 +20,8 @@
#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>
@@ -42,7 +44,7 @@ MODULE_SUPPORTED_DEVICE("{{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)
@@ -90,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
@@ -142,6 +160,8 @@ MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver.");
//module_param_array(midi_devs, int, NULL, 0444);
//MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
+static struct platform_device *devices[SNDRV_CARDS];
+
#define MIXER_ADDR_MASTER 0
#define MIXER_ADDR_LINE 1
#define MIXER_ADDR_MIC 2
@@ -149,15 +169,16 @@ MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver.");
#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;
@@ -166,59 +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 void snd_card_dummy_pcm_timer_start(snd_pcm_substream_t * substream)
+static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm)
{
- snd_pcm_runtime_t *runtime = substream->runtime;
- snd_card_dummy_pcm_t *dpcm = runtime->private_data;
-
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 = runtime->private_data;
-
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)
+static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *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;
+ 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 = runtime->private_data;
+ struct snd_pcm_runtime *runtime = substream->runtime;
+ struct snd_dummy_pcm *dpcm = runtime->private_data;
unsigned int bps;
bps = runtime->rate * runtime->channels;
@@ -235,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_card_dummy_pcm_t *)data;
+ 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);
+ } else
+ spin_unlock_irqrestore(&dpcm->lock, flags);
}
-static snd_pcm_uframes_t snd_card_dummy_playback_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 = runtime->private_data;
+ 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_uframes_t snd_card_dummy_capture_pointer(snd_pcm_substream_t * substream)
-{
- snd_pcm_runtime_t *runtime = substream->runtime;
- snd_card_dummy_pcm_t *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,
@@ -296,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,
@@ -308,43 +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 = runtime->private_data;
- kfree(dpcm);
+ kfree(runtime->private_data);
}
-static int snd_card_dummy_hw_params(snd_pcm_substream_t * substream,
- snd_pcm_hw_params_t * hw_params)
+static int snd_card_dummy_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *hw_params)
{
return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
}
-static int snd_card_dummy_hw_free(snd_pcm_substream_t * substream)
+static int snd_card_dummy_hw_free(struct snd_pcm_substream *substream)
{
return snd_pcm_lib_free_pages(substream);
}
-static int snd_card_dummy_playback_open(snd_pcm_substream_t * substream)
+static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream)
{
- snd_pcm_runtime_t *runtime = substream->runtime;
- snd_card_dummy_pcm_t *dpcm;
- int err;
+ struct snd_dummy_pcm *dpcm;
dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
- if (dpcm == NULL)
- return -ENOMEM;
+ 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;
@@ -362,20 +365,14 @@ static int snd_card_dummy_playback_open(snd_pcm_substream_t * substream)
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 = kzalloc(sizeof(*dpcm), GFP_KERNEL);
- if (dpcm == NULL)
+ if ((dpcm = new_pcm_stream(substream)) == NULL)
return -ENOMEM;
- 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;
@@ -393,45 +390,47 @@ static int snd_card_dummy_capture_open(snd_pcm_substream_t * substream)
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)
{
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)
{
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_pcm_lib_ioctl,
.hw_params = snd_card_dummy_hw_params,
.hw_free = snd_card_dummy_hw_free,
- .prepare = snd_card_dummy_playback_prepare,
- .trigger = snd_card_dummy_playback_trigger,
- .pointer = snd_card_dummy_playback_pointer,
+ .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_pcm_lib_ioctl,
.hw_params = snd_card_dummy_hw_params,
.hw_free = snd_card_dummy_hw_free,
- .prepare = snd_card_dummy_capture_prepare,
- .trigger = snd_card_dummy_capture_trigger,
- .pointer = snd_card_dummy_capture_pointer,
+ .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;
@@ -449,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;
@@ -458,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;
@@ -488,12 +488,12 @@ 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;
}
@@ -503,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;
@@ -512,38 +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;
}
-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),
@@ -556,9 +556,9 @@ DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
DUMMY_CAPSRC("CD Capture Switch", 0, MIXER_ADDR_MASTER)
};
-static 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;
@@ -573,19 +573,18 @@ static int __init snd_card_dummy_new_mixer(snd_card_dummy_t * dummy)
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)
@@ -601,11 +600,10 @@ static int __init snd_card_dummy_probe(int dev)
strcpy(card->shortname, "Dummy");
sprintf(card->longname, "Dummy %i", dev + 1);
- if ((err = snd_card_set_generic_dev(card)) < 0)
- goto __nodev;
+ 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:
@@ -613,34 +611,92 @@ 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)
{
- int dev, cards;
+ snd_card_free(platform_get_drvdata(devptr));
+ platform_set_drvdata(devptr, NULL);
+ return 0;
+}
- 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);
+#ifdef CONFIG_PM
+static int snd_dummy_suspend(struct platform_device *pdev, pm_message_t state)
+{
+ struct snd_card *card = platform_get_drvdata(pdev);
+ struct snd_dummy *dummy = card->private_data;
+
+ 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 && enable[i]; i++) {
+ struct platform_device *device;
+ device = platform_device_register_simple(SND_DUMMY_DRIVER,
+ i, NULL, 0);
+ if (IS_ERR(device)) {
+ err = PTR_ERR(device);
+ goto errout;
}
+ devices[i] = device;
cards++;
}
if (!cards) {
#ifdef MODULE
printk(KERN_ERR "Dummy soundcard not found or device busy\n");
#endif
- return -ENODEV;
+ err = -ENODEV;
+ goto errout;
}
return 0;
+
+ errout:
+ snd_dummy_unregister_all();
+ return err;
}
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)