Lines Matching +full:mic +full:- +full:pos
1 // SPDX-License-Identifier: GPL-2.0-or-later
45 #define USE_MIXER_VOLUME_LEVEL_MIN -50
48 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
50 static bool enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
51 static char *model[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = NULL};
52 static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
53 static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8};
54 //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
71 MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver.");
73 MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-128) for dummy driver.");
75 //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
77 MODULE_PARM_DESC(mixer_volume_level_min, "Minimum mixer volume level for dummy driver. Default: -50…
106 (*(const struct dummy_timer_ops **)(substream)->runtime->private_data)
203 .buffer_bytes_max = ((65536-64)*8),
204 .period_bytes_max = (65536-64),
245 mod_timer(&dpcm->timer, jiffies + in dummy_systimer_rearm()
246 DIV_ROUND_UP(dpcm->frac_period_rest, dpcm->rate)); in dummy_systimer_rearm()
253 delta = jiffies - dpcm->base_time; in dummy_systimer_update()
256 dpcm->base_time += delta; in dummy_systimer_update()
257 delta *= dpcm->rate; in dummy_systimer_update()
258 dpcm->frac_pos += delta; in dummy_systimer_update()
259 while (dpcm->frac_pos >= dpcm->frac_buffer_size) in dummy_systimer_update()
260 dpcm->frac_pos -= dpcm->frac_buffer_size; in dummy_systimer_update()
261 while (dpcm->frac_period_rest <= delta) { in dummy_systimer_update()
262 dpcm->elapsed++; in dummy_systimer_update()
263 dpcm->frac_period_rest += dpcm->frac_period_size; in dummy_systimer_update()
265 dpcm->frac_period_rest -= delta; in dummy_systimer_update()
270 struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; in dummy_systimer_start()
271 spin_lock(&dpcm->lock); in dummy_systimer_start()
272 dpcm->base_time = jiffies; in dummy_systimer_start()
274 spin_unlock(&dpcm->lock); in dummy_systimer_start()
280 struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; in dummy_systimer_stop()
281 spin_lock(&dpcm->lock); in dummy_systimer_stop()
282 del_timer(&dpcm->timer); in dummy_systimer_stop()
283 spin_unlock(&dpcm->lock); in dummy_systimer_stop()
289 struct snd_pcm_runtime *runtime = substream->runtime; in dummy_systimer_prepare()
290 struct dummy_systimer_pcm *dpcm = runtime->private_data; in dummy_systimer_prepare()
292 dpcm->frac_pos = 0; in dummy_systimer_prepare()
293 dpcm->rate = runtime->rate; in dummy_systimer_prepare()
294 dpcm->frac_buffer_size = runtime->buffer_size * HZ; in dummy_systimer_prepare()
295 dpcm->frac_period_size = runtime->period_size * HZ; in dummy_systimer_prepare()
296 dpcm->frac_period_rest = dpcm->frac_period_size; in dummy_systimer_prepare()
297 dpcm->elapsed = 0; in dummy_systimer_prepare()
308 spin_lock_irqsave(&dpcm->lock, flags); in dummy_systimer_callback()
311 elapsed = dpcm->elapsed; in dummy_systimer_callback()
312 dpcm->elapsed = 0; in dummy_systimer_callback()
313 spin_unlock_irqrestore(&dpcm->lock, flags); in dummy_systimer_callback()
315 snd_pcm_period_elapsed(dpcm->substream); in dummy_systimer_callback()
321 struct dummy_systimer_pcm *dpcm = substream->runtime->private_data; in dummy_systimer_pointer()
322 snd_pcm_uframes_t pos; in dummy_systimer_pointer() local
324 spin_lock(&dpcm->lock); in dummy_systimer_pointer()
326 pos = dpcm->frac_pos / HZ; in dummy_systimer_pointer()
327 spin_unlock(&dpcm->lock); in dummy_systimer_pointer()
328 return pos; in dummy_systimer_pointer()
337 return -ENOMEM; in dummy_systimer_create()
338 substream->runtime->private_data = dpcm; in dummy_systimer_create()
339 timer_setup(&dpcm->timer, dummy_systimer_callback, 0); in dummy_systimer_create()
340 spin_lock_init(&dpcm->lock); in dummy_systimer_create()
341 dpcm->substream = substream; in dummy_systimer_create()
347 kfree(substream->runtime->private_data); in dummy_systimer_free()
379 if (!atomic_read(&dpcm->running)) in dummy_hrtimer_callback()
385 snd_pcm_period_elapsed(dpcm->substream); in dummy_hrtimer_callback()
386 if (!atomic_read(&dpcm->running)) in dummy_hrtimer_callback()
389 hrtimer_forward_now(timer, dpcm->period_time); in dummy_hrtimer_callback()
395 struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data; in dummy_hrtimer_start()
397 dpcm->base_time = hrtimer_cb_get_time(&dpcm->timer); in dummy_hrtimer_start()
398 hrtimer_start(&dpcm->timer, dpcm->period_time, HRTIMER_MODE_REL_SOFT); in dummy_hrtimer_start()
399 atomic_set(&dpcm->running, 1); in dummy_hrtimer_start()
405 struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data; in dummy_hrtimer_stop()
407 atomic_set(&dpcm->running, 0); in dummy_hrtimer_stop()
408 if (!hrtimer_callback_running(&dpcm->timer)) in dummy_hrtimer_stop()
409 hrtimer_cancel(&dpcm->timer); in dummy_hrtimer_stop()
415 hrtimer_cancel(&dpcm->timer); in dummy_hrtimer_sync()
421 struct snd_pcm_runtime *runtime = substream->runtime; in dummy_hrtimer_pointer()
422 struct dummy_hrtimer_pcm *dpcm = runtime->private_data; in dummy_hrtimer_pointer()
424 u32 pos; in dummy_hrtimer_pointer() local
426 delta = ktime_us_delta(hrtimer_cb_get_time(&dpcm->timer), in dummy_hrtimer_pointer()
427 dpcm->base_time); in dummy_hrtimer_pointer()
428 delta = div_u64(delta * runtime->rate + 999999, 1000000); in dummy_hrtimer_pointer()
429 div_u64_rem(delta, runtime->buffer_size, &pos); in dummy_hrtimer_pointer()
430 return pos; in dummy_hrtimer_pointer()
435 struct snd_pcm_runtime *runtime = substream->runtime; in dummy_hrtimer_prepare()
436 struct dummy_hrtimer_pcm *dpcm = runtime->private_data; in dummy_hrtimer_prepare()
442 period = runtime->period_size; in dummy_hrtimer_prepare()
443 rate = runtime->rate; in dummy_hrtimer_prepare()
446 nsecs = div_u64((u64)period * 1000000000UL + rate - 1, rate); in dummy_hrtimer_prepare()
447 dpcm->period_time = ktime_set(sec, nsecs); in dummy_hrtimer_prepare()
458 return -ENOMEM; in dummy_hrtimer_create()
459 substream->runtime->private_data = dpcm; in dummy_hrtimer_create()
460 hrtimer_init(&dpcm->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT); in dummy_hrtimer_create()
461 dpcm->timer.function = dummy_hrtimer_callback; in dummy_hrtimer_create()
462 dpcm->substream = substream; in dummy_hrtimer_create()
463 atomic_set(&dpcm->running, 0); in dummy_hrtimer_create()
469 struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data; in dummy_hrtimer_free()
494 return get_dummy_ops(substream)->start(substream); in dummy_pcm_trigger()
497 return get_dummy_ops(substream)->stop(substream); in dummy_pcm_trigger()
499 return -EINVAL; in dummy_pcm_trigger()
504 return get_dummy_ops(substream)->prepare(substream); in dummy_pcm_prepare()
509 return get_dummy_ops(substream)->pointer(substream); in dummy_pcm_pointer()
535 /* runtime->dma_bytes has to be set manually to allow mmap */ in dummy_pcm_hw_params()
536 substream->runtime->dma_bytes = params_buffer_bytes(hw_params); in dummy_pcm_hw_params()
545 const struct dummy_model *model = dummy->model; in dummy_pcm_open()
546 struct snd_pcm_runtime *runtime = substream->runtime; in dummy_pcm_open()
556 err = ops->create(substream); in dummy_pcm_open()
561 runtime->hw = dummy->pcm_hw; in dummy_pcm_open()
562 if (substream->pcm->device & 1) { in dummy_pcm_open()
563 runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; in dummy_pcm_open()
564 runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; in dummy_pcm_open()
566 if (substream->pcm->device & 2) in dummy_pcm_open()
567 runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP | in dummy_pcm_open()
573 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { in dummy_pcm_open()
574 if (model->playback_constraints) in dummy_pcm_open()
575 err = model->playback_constraints(substream->runtime); in dummy_pcm_open()
577 if (model->capture_constraints) in dummy_pcm_open()
578 err = model->capture_constraints(substream->runtime); in dummy_pcm_open()
581 get_dummy_ops(substream)->free(substream); in dummy_pcm_open()
589 get_dummy_ops(substream)->free(substream); in dummy_pcm_close()
621 return -ENOMEM; in alloc_fake_buffer()
628 int channel, unsigned long pos, in dummy_pcm_copy() argument
635 int channel, unsigned long pos, in dummy_pcm_silence() argument
644 return virt_to_page(dummy_page[substream->stream]); /* the same page */ in dummy_pcm_page()
675 err = snd_pcm_new(dummy->card, "Dummy PCM", device, in snd_card_dummy_pcm()
679 dummy->pcm = pcm; in snd_card_dummy_pcm()
686 pcm->private_data = dummy; in snd_card_dummy_pcm()
687 pcm->info_flags = 0; in snd_card_dummy_pcm()
688 strcpy(pcm->name, "Dummy PCM"); in snd_card_dummy_pcm()
714 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in snd_dummy_volume_info()
715 uinfo->count = 2; in snd_dummy_volume_info()
716 uinfo->value.integer.min = mixer_volume_level_min; in snd_dummy_volume_info()
717 uinfo->value.integer.max = mixer_volume_level_max; in snd_dummy_volume_info()
725 int addr = kcontrol->private_value; in snd_dummy_volume_get()
727 spin_lock_irq(&dummy->mixer_lock); in snd_dummy_volume_get()
728 ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0]; in snd_dummy_volume_get()
729 ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1]; in snd_dummy_volume_get()
730 spin_unlock_irq(&dummy->mixer_lock); in snd_dummy_volume_get()
738 int change, addr = kcontrol->private_value; in snd_dummy_volume_put()
741 left = ucontrol->value.integer.value[0]; in snd_dummy_volume_put()
746 right = ucontrol->value.integer.value[1]; in snd_dummy_volume_put()
751 spin_lock_irq(&dummy->mixer_lock); in snd_dummy_volume_put()
752 change = dummy->mixer_volume[addr][0] != left || in snd_dummy_volume_put()
753 dummy->mixer_volume[addr][1] != right; in snd_dummy_volume_put()
754 dummy->mixer_volume[addr][0] = left; in snd_dummy_volume_put()
755 dummy->mixer_volume[addr][1] = right; in snd_dummy_volume_put()
756 spin_unlock_irq(&dummy->mixer_lock); in snd_dummy_volume_put()
760 static const DECLARE_TLV_DB_SCALE(db_scale_dummy, -4500, 30, 0);
774 int addr = kcontrol->private_value; in snd_dummy_capsrc_get()
776 spin_lock_irq(&dummy->mixer_lock); in snd_dummy_capsrc_get()
777 ucontrol->value.integer.value[0] = dummy->capture_source[addr][0]; in snd_dummy_capsrc_get()
778 ucontrol->value.integer.value[1] = dummy->capture_source[addr][1]; in snd_dummy_capsrc_get()
779 spin_unlock_irq(&dummy->mixer_lock); in snd_dummy_capsrc_get()
786 int change, addr = kcontrol->private_value; in snd_dummy_capsrc_put()
789 left = ucontrol->value.integer.value[0] & 1; in snd_dummy_capsrc_put()
790 right = ucontrol->value.integer.value[1] & 1; in snd_dummy_capsrc_put()
791 spin_lock_irq(&dummy->mixer_lock); in snd_dummy_capsrc_put()
792 change = dummy->capture_source[addr][0] != left && in snd_dummy_capsrc_put()
793 dummy->capture_source[addr][1] != right; in snd_dummy_capsrc_put()
794 dummy->capture_source[addr][0] = left; in snd_dummy_capsrc_put()
795 dummy->capture_source[addr][1] = right; in snd_dummy_capsrc_put()
796 spin_unlock_irq(&dummy->mixer_lock); in snd_dummy_capsrc_put()
813 value->value.enumerated.item[0] = dummy->iobox; in snd_dummy_iobox_get()
823 if (value->value.enumerated.item[0] > 1) in snd_dummy_iobox_put()
824 return -EINVAL; in snd_dummy_iobox_put()
826 changed = value->value.enumerated.item[0] != dummy->iobox; in snd_dummy_iobox_put()
828 dummy->iobox = value->value.enumerated.item[0]; in snd_dummy_iobox_put()
830 if (dummy->iobox) { in snd_dummy_iobox_put()
831 dummy->cd_volume_ctl->vd[0].access &= in snd_dummy_iobox_put()
833 dummy->cd_switch_ctl->vd[0].access &= in snd_dummy_iobox_put()
836 dummy->cd_volume_ctl->vd[0].access |= in snd_dummy_iobox_put()
838 dummy->cd_switch_ctl->vd[0].access |= in snd_dummy_iobox_put()
842 snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO, in snd_dummy_iobox_put()
843 &dummy->cd_volume_ctl->id); in snd_dummy_iobox_put()
844 snd_ctl_notify(dummy->card, SNDRV_CTL_EVENT_MASK_INFO, in snd_dummy_iobox_put()
845 &dummy->cd_switch_ctl->id); in snd_dummy_iobox_put()
858 DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
859 DUMMY_CAPSRC("Mic Capture Switch", 0, MIXER_ADDR_MIC),
873 struct snd_card *card = dummy->card; in snd_card_dummy_new_mixer()
878 spin_lock_init(&dummy->mixer_lock); in snd_card_dummy_new_mixer()
879 strcpy(card->mixername, "Dummy Mixer"); in snd_card_dummy_new_mixer()
880 dummy->iobox = 1; in snd_card_dummy_new_mixer()
887 if (!strcmp(kcontrol->id.name, "CD Volume")) in snd_card_dummy_new_mixer()
888 dummy->cd_volume_ctl = kcontrol; in snd_card_dummy_new_mixer()
889 else if (!strcmp(kcontrol->id.name, "CD Capture Switch")) in snd_card_dummy_new_mixer()
890 dummy->cd_switch_ctl = kcontrol; in snd_card_dummy_new_mixer()
906 if (dummy->pcm_hw.formats & pcm_format_to_bits(i)) in print_formats()
920 if (dummy->pcm_hw.rates & SNDRV_PCM_RATE_CONTINUOUS) in print_rates()
922 if (dummy->pcm_hw.rates & SNDRV_PCM_RATE_KNOT) in print_rates()
925 if (dummy->pcm_hw.rates & (1 << i)) in print_rates()
930 (unsigned int *)((char *)&((dummy)->pcm_hw) + (ofs))
932 (unsigned long long *)((char *)&((dummy)->pcm_hw) + (ofs))
963 struct snd_dummy *dummy = entry->private_data; in dummy_proc_read()
985 struct snd_dummy *dummy = entry->private_data; in dummy_proc_write()
1013 snd_card_rw_proc_new(chip->card, "dummy_pcm", chip, in dummy_proc_init()
1026 int dev = devptr->id; in snd_dummy_probe()
1028 err = snd_devm_card_new(&devptr->dev, index[dev], id[dev], THIS_MODULE, in snd_dummy_probe()
1032 dummy = card->private_data; in snd_dummy_probe()
1033 dummy->card = card; in snd_dummy_probe()
1035 if (strcmp(model[dev], (*mdl)->name) == 0) { in snd_dummy_probe()
1036 pr_info("snd-dummy: Using model '%s' for card %i\n", in snd_dummy_probe()
1037 (*mdl)->name, card->number); in snd_dummy_probe()
1038 m = dummy->model = *mdl; in snd_dummy_probe()
1052 dummy->pcm_hw = dummy_pcm_hardware; in snd_dummy_probe()
1054 if (m->formats) in snd_dummy_probe()
1055 dummy->pcm_hw.formats = m->formats; in snd_dummy_probe()
1056 if (m->buffer_bytes_max) in snd_dummy_probe()
1057 dummy->pcm_hw.buffer_bytes_max = m->buffer_bytes_max; in snd_dummy_probe()
1058 if (m->period_bytes_min) in snd_dummy_probe()
1059 dummy->pcm_hw.period_bytes_min = m->period_bytes_min; in snd_dummy_probe()
1060 if (m->period_bytes_max) in snd_dummy_probe()
1061 dummy->pcm_hw.period_bytes_max = m->period_bytes_max; in snd_dummy_probe()
1062 if (m->periods_min) in snd_dummy_probe()
1063 dummy->pcm_hw.periods_min = m->periods_min; in snd_dummy_probe()
1064 if (m->periods_max) in snd_dummy_probe()
1065 dummy->pcm_hw.periods_max = m->periods_max; in snd_dummy_probe()
1066 if (m->rates) in snd_dummy_probe()
1067 dummy->pcm_hw.rates = m->rates; in snd_dummy_probe()
1068 if (m->rate_min) in snd_dummy_probe()
1069 dummy->pcm_hw.rate_min = m->rate_min; in snd_dummy_probe()
1070 if (m->rate_max) in snd_dummy_probe()
1071 dummy->pcm_hw.rate_max = m->rate_max; in snd_dummy_probe()
1072 if (m->channels_min) in snd_dummy_probe()
1073 dummy->pcm_hw.channels_min = m->channels_min; in snd_dummy_probe()
1074 if (m->channels_max) in snd_dummy_probe()
1075 dummy->pcm_hw.channels_max = m->channels_max; in snd_dummy_probe()
1079 pr_warn("snd-dummy: Invalid mixer volume level: min=%d, max=%d. Fall back to default value.\n", in snd_dummy_probe()
1087 strcpy(card->driver, "Dummy"); in snd_dummy_probe()
1088 strcpy(card->shortname, "Dummy"); in snd_dummy_probe()
1089 sprintf(card->longname, "Dummy %i", dev + 1); in snd_dummy_probe()
1173 return -ENODEV; in alsa_card_dummy_init()