From c8eb6ba16a5803fab9cc0d1d0dd04a75bf91b6d5 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 17 Nov 2005 10:20:23 +0100 Subject: [ALSA] snd-dummy - Code clean-up Modules: Generic drivers Clean up snd-dummy driver code. - Make common PCM callbacks - Simplify open callback - Remove unnecessary irqsave in control callbacks Signed-off-by: Takashi Iwai --- sound/drivers/dummy.c | 126 +++++++++++++++++++------------------------------- 1 file changed, 47 insertions(+), 79 deletions(-) (limited to 'sound/drivers/dummy.c') diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index 64ef7f62851d..8dfe5d49eafc 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c @@ -172,47 +172,33 @@ typedef struct snd_card_dummy_pcm { static snd_card_t *snd_dummy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; -static void snd_card_dummy_pcm_timer_start(snd_pcm_substream_t * substream) +static inline void snd_card_dummy_pcm_timer_start(snd_card_dummy_pcm_t *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(snd_card_dummy_pcm_t *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) +static int snd_card_dummy_pcm_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; -} + snd_pcm_runtime_t *runtime = substream->runtime; + snd_dummy_card_pcm_t *dpcm = runtime->private_data; + int err = 0; -static int snd_card_dummy_capture_trigger(snd_pcm_substream_t * substream, - int cmd) -{ + spin_lock(&dpcm->lock); if (cmd == SNDRV_PCM_TRIGGER_START) { - snd_card_dummy_pcm_timer_start(substream); + snd_card_dummy_pcm_timer_start(dpcm); } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { - snd_card_dummy_pcm_timer_stop(substream); + snd_card_dummy_pcm_timer_stop(dpcm); } else { - return -EINVAL; + err = -EINVAL; } - return 0; + spin_unlock(&dpcm->lock); + return err; } static int snd_card_dummy_pcm_prepare(snd_pcm_substream_t * substream) @@ -235,42 +221,26 @@ 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; + spin_lock(&dpcm->lock); 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(&dpcm->lock); snd_pcm_period_elapsed(dpcm->substream); + spin_lock(&dpcm->lock); } - spin_unlock_irq(&dpcm->lock); + spin_unlock(&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 = 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) +static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(snd_pcm_substream_t * substream) { snd_pcm_runtime_t *runtime = substream->runtime; snd_card_dummy_pcm_t *dpcm = runtime->private_data; @@ -316,8 +286,7 @@ static snd_pcm_hardware_t snd_card_dummy_capture = static void snd_card_dummy_runtime_free(snd_pcm_runtime_t *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, @@ -331,20 +300,29 @@ static int snd_card_dummy_hw_free(snd_pcm_substream_t * substream) return snd_pcm_lib_free_pages(substream); } -static int snd_card_dummy_playback_open(snd_pcm_substream_t * substream) +static snd_card_dummy_pcm_t *new_pcm_stream(snd_pcm_substream_t *substream) { - snd_pcm_runtime_t *runtime = substream->runtime; snd_card_dummy_pcm_t *dpcm; - int err; 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(snd_pcm_substream_t * substream) +{ + snd_pcm_runtime_t *runtime = substream->runtime; + snd_card_dummy_pcm_t *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; @@ -368,14 +346,8 @@ static int snd_card_dummy_capture_open(snd_pcm_substream_t * substream) snd_card_dummy_pcm_t *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; @@ -409,9 +381,9 @@ static snd_pcm_ops_t snd_card_dummy_playback_ops = { .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 = { @@ -420,9 +392,9 @@ static snd_pcm_ops_t snd_card_dummy_capture_ops = { .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) @@ -461,20 +433,18 @@ static int snd_dummy_volume_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t static int snd_dummy_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) { snd_card_dummy_t *dummy = snd_kcontrol_chip(kcontrol); - unsigned long flags; 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) { snd_card_dummy_t *dummy = snd_kcontrol_chip(kcontrol); - unsigned long flags; int change, addr = kcontrol->private_value; int left, right; @@ -488,12 +458,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; } @@ -515,31 +485,29 @@ static int snd_dummy_capsrc_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t static int snd_dummy_capsrc_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) { snd_card_dummy_t *dummy = snd_kcontrol_chip(kcontrol); - unsigned long flags; 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) { snd_card_dummy_t *dummy = snd_kcontrol_chip(kcontrol); - unsigned long flags; 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; } -- cgit v1.2.2 From 4a4d2cfd8cbca3076742547157ea135d0be77928 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 17 Nov 2005 14:27:28 +0100 Subject: [ALSA] Remove xxx_t typedefs: Generic drivers Modules: Generic drivers Remove xxx_t typedefs from the generic drivers (dummy, mtpav, serial-u16550 and virmidi). Signed-off-by: Takashi Iwai --- sound/drivers/dummy.c | 124 ++++++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 59 deletions(-) (limited to 'sound/drivers/dummy.c') diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index 8dfe5d49eafc..9c827b154458 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c @@ -42,7 +42,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) @@ -149,15 +149,15 @@ 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; 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,27 +166,27 @@ 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; + struct snd_pcm_substream *substream; +}; -static snd_card_t *snd_dummy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; +static struct snd_card *snd_dummy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; -static inline void snd_card_dummy_pcm_timer_start(snd_card_dummy_pcm_t *dpcm) +static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm) { dpcm->timer.expires = 1 + jiffies; add_timer(&dpcm->timer); } -static inline void snd_card_dummy_pcm_timer_stop(snd_card_dummy_pcm_t *dpcm) +static inline void snd_card_dummy_pcm_timer_stop(struct snd_dummy_pcm *dpcm) { del_timer(&dpcm->timer); } -static int snd_card_dummy_pcm_trigger(snd_pcm_substream_t *substream, int cmd) +static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { - snd_pcm_runtime_t *runtime = substream->runtime; - snd_dummy_card_pcm_t *dpcm = runtime->private_data; + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_dummy_pcm *dpcm = runtime->private_data; int err = 0; spin_lock(&dpcm->lock); @@ -201,10 +201,10 @@ static int snd_card_dummy_pcm_trigger(snd_pcm_substream_t *substream, int cmd) return err; } -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; @@ -223,7 +223,7 @@ static int snd_card_dummy_pcm_prepare(snd_pcm_substream_t * 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; spin_lock(&dpcm->lock); dpcm->timer.expires = 1 + jiffies; @@ -240,15 +240,15 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data) spin_unlock(&dpcm->lock); } -static snd_pcm_uframes_t snd_card_dummy_pcm_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_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), @@ -266,7 +266,7 @@ 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), @@ -284,25 +284,25 @@ static snd_pcm_hardware_t snd_card_dummy_capture = .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) { 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 snd_card_dummy_pcm_t *new_pcm_stream(snd_pcm_substream_t *substream) +static struct snd_dummy_pcm *new_pcm_stream(struct snd_pcm_substream *substream) { - snd_card_dummy_pcm_t *dpcm; + struct snd_dummy_pcm *dpcm; dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); if (! dpcm) @@ -315,10 +315,10 @@ static snd_card_dummy_pcm_t *new_pcm_stream(snd_pcm_substream_t *substream) return dpcm; } -static int snd_card_dummy_playback_open(snd_pcm_substream_t * substream) +static int snd_card_dummy_playback_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; if ((dpcm = new_pcm_stream(substream)) == NULL) @@ -340,10 +340,10 @@ 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; if ((dpcm = new_pcm_stream(substream)) == NULL) @@ -365,17 +365,17 @@ 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, @@ -386,7 +386,7 @@ static snd_pcm_ops_t snd_card_dummy_playback_ops = { .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, @@ -397,12 +397,13 @@ static snd_pcm_ops_t snd_card_dummy_capture_ops = { .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; 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); @@ -421,7 +422,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; @@ -430,9 +432,10 @@ 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); + struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); int addr = kcontrol->private_value; spin_lock_irq(&dummy->mixer_lock); @@ -442,9 +445,10 @@ static int snd_dummy_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t 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); + struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); int change, addr = kcontrol->private_value; int left, right; @@ -473,7 +477,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; @@ -482,9 +487,10 @@ 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); + struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); int addr = kcontrol->private_value; spin_lock_irq(&dummy->mixer_lock); @@ -494,9 +500,9 @@ static int snd_dummy_capsrc_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t 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); + struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol); int change, addr = kcontrol->private_value; int left, right; @@ -511,7 +517,7 @@ static int snd_dummy_capsrc_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t 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), @@ -524,9 +530,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; @@ -543,17 +549,17 @@ static int __init snd_card_dummy_new_mixer(snd_card_dummy_t * dummy) static int __init snd_card_dummy_probe(int dev) { - snd_card_t *card; - struct snd_card_dummy *dummy; + struct snd_card *card; + struct snd_dummy *dummy; int idx, err; 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) -- cgit v1.2.2 From 6e65c1cc4458b2784224759b6137a50d4f65e610 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Thu, 17 Nov 2005 16:01:56 +0100 Subject: [ALSA] dummy - Use platform_device Modules: Generic drivers Rewrite the probe/remove code using platform_device. Added the suspend/resume support, too. Signed-off-by: Takashi Iwai --- sound/drivers/dummy.c | 106 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 80 insertions(+), 26 deletions(-) (limited to 'sound/drivers/dummy.c') diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index 9c827b154458..a276f7c80360 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c @@ -20,6 +20,8 @@ #include #include +#include +#include #include #include #include @@ -151,6 +153,7 @@ MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-16) for dummy driver."); 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]; @@ -169,8 +172,6 @@ struct snd_dummy_pcm { struct snd_pcm_substream *substream; }; -static struct snd_card *snd_dummy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; - static inline void snd_card_dummy_pcm_timer_start(struct snd_dummy_pcm *dpcm) { @@ -190,15 +191,21 @@ static int snd_card_dummy_pcm_trigger(struct snd_pcm_substream *substream, int c int err = 0; spin_lock(&dpcm->lock); - if (cmd == SNDRV_PCM_TRIGGER_START) { + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: snd_card_dummy_pcm_timer_start(dpcm); - } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { + break; + case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_SUSPEND: snd_card_dummy_pcm_timer_stop(dpcm); - } else { + break; + default: err = -EINVAL; + break; } spin_unlock(&dpcm->lock); - return err; + return 0; } static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream) @@ -251,7 +258,7 @@ static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *su 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, @@ -269,7 +276,7 @@ static struct snd_pcm_hardware snd_card_dummy_playback = 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, @@ -405,6 +412,7 @@ static int __init snd_card_dummy_pcm(struct snd_dummy *dummy, int device, int su 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; @@ -547,14 +555,13 @@ static int __init snd_card_dummy_new_mixer(struct snd_dummy *dummy) return 0; } -static int __init snd_card_dummy_probe(int dev) +static int __init snd_dummy_probe(struct platform_device *devptr) { 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_dummy)); if (card == NULL) @@ -575,11 +582,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: @@ -587,16 +593,62 @@ 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 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; } cards++; } @@ -604,17 +656,19 @@ static int __init alsa_card_dummy_init(void) #ifdef MODULE printk(KERN_ERR "Dummy soundcard not found or device busy\n"); #endif - return -ENODEV; + err = -ENODEV; + goto errout; } return 0; + + errout: + platform_driver_unregister(&snd_dummy_driver); + 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]); + platform_driver_unregister(&snd_dummy_driver); } module_init(alsa_card_dummy_init) -- cgit v1.2.2 From b32425ac93370e1ba5556110e662f896b2e143b3 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 18 Nov 2005 18:52:14 +0100 Subject: [ALSA] Fix possible races in timer callbacks Fix possible races in timer callbacks. Signed-off-by: Takashi Iwai --- sound/drivers/dummy.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'sound/drivers/dummy.c') diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index a276f7c80360..186117571745 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c @@ -231,8 +231,9 @@ static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream) static void snd_card_dummy_pcm_timer_function(unsigned long data) { struct snd_dummy_pcm *dpcm = (struct snd_dummy_pcm *)data; + unsigned long flags; - spin_lock(&dpcm->lock); + spin_lock_irqsave(&dpcm->lock, flags); dpcm->timer.expires = 1 + jiffies; add_timer(&dpcm->timer); dpcm->pcm_irq_pos += dpcm->pcm_jiffie; @@ -240,11 +241,10 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data) dpcm->pcm_buf_pos %= dpcm->pcm_size; if (dpcm->pcm_irq_pos >= dpcm->pcm_count) { dpcm->pcm_irq_pos %= dpcm->pcm_count; - spin_unlock(&dpcm->lock); + spin_unlock_irqrestore(&dpcm->lock, flags); snd_pcm_period_elapsed(dpcm->substream); - spin_lock(&dpcm->lock); - } - spin_unlock(&dpcm->lock); + } else + spin_unlock_irqrestore(&dpcm->lock, flags); } static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *substream) -- cgit v1.2.2 From f7a9275d949cb0bf1f259a1546e52a0bf518151c Mon Sep 17 00:00:00 2001 From: Clemens Ladisch Date: Wed, 7 Dec 2005 09:13:42 +0100 Subject: [ALSA] unregister platform devices Call platform_device_unregister() for all platform devices that we've registered. Signed-off-by: Clemens Ladisch --- sound/drivers/dummy.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'sound/drivers/dummy.c') diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index 186117571745..96d207051628 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c @@ -144,6 +144,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 @@ -634,6 +636,15 @@ static struct platform_driver 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; @@ -650,6 +661,7 @@ static int __init alsa_card_dummy_init(void) err = PTR_ERR(device); goto errout; } + devices[i] = device; cards++; } if (!cards) { @@ -662,13 +674,13 @@ static int __init alsa_card_dummy_init(void) return 0; errout: - platform_driver_unregister(&snd_dummy_driver); + snd_dummy_unregister_all(); return err; } static void __exit alsa_card_dummy_exit(void) { - platform_driver_unregister(&snd_dummy_driver); + snd_dummy_unregister_all(); } module_init(alsa_card_dummy_init) -- cgit v1.2.2 From 2ad5dd8dc31137a050f205525a5cd1a4be76c3f1 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 3 Jan 2006 14:27:21 +0100 Subject: [ALSA] dummy driver - added CA0106 emulation defines Modules: Generic drivers Signed-off-by: Jaroslav Kysela --- sound/drivers/dummy.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'sound/drivers/dummy.c') diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index 96d207051628..14e1a671b5cf 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c @@ -92,11 +92,27 @@ static int emu10k1_playback_constraints(struct snd_pcm_runtime *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 @@ -287,7 +303,7 @@ static struct snd_pcm_hardware 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, -- cgit v1.2.2