Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: dummy: Add customizable volume min/max.

Add module parameters to support customized min/max volume leveling,
which will be useful to test devices with different volume granularity.

Signed-off-by: YJ Lee <yunjunlee@chromium.org>
Link: https://lore.kernel.org/r/20220912072945.760949-1-yunjunlee@chromium.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

YJ Lee and committed by
Takashi Iwai
446bc11f 7ae22bdf

+24 -10
+24 -10
sound/drivers/dummy.c
··· 42 42 #define USE_CHANNELS_MAX 2 43 43 #define USE_PERIODS_MIN 1 44 44 #define USE_PERIODS_MAX 1024 45 + #define USE_MIXER_VOLUME_LEVEL_MIN -50 46 + #define USE_MIXER_VOLUME_LEVEL_MAX 100 45 47 46 48 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 47 49 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ ··· 52 50 static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; 53 51 static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8}; 54 52 //static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; 53 + static int mixer_volume_level_min = USE_MIXER_VOLUME_LEVEL_MIN; 54 + static int mixer_volume_level_max = USE_MIXER_VOLUME_LEVEL_MAX; 55 55 #ifdef CONFIG_HIGH_RES_TIMERS 56 56 static bool hrtimer = 1; 57 57 #endif ··· 73 69 MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-128) for dummy driver."); 74 70 //module_param_array(midi_devs, int, NULL, 0444); 75 71 //MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver."); 72 + module_param(mixer_volume_level_min, int, 0444); 73 + MODULE_PARM_DESC(mixer_volume_level_min, "Minimum mixer volume level for dummy driver. Default: -50"); 74 + module_param(mixer_volume_level_max, int, 0444); 75 + MODULE_PARM_DESC(mixer_volume_level_max, "Maximum mixer volume level for dummy driver. Default: 100"); 76 76 module_param(fake_buffer, bool, 0444); 77 77 MODULE_PARM_DESC(fake_buffer, "Fake buffer allocations."); 78 78 #ifdef CONFIG_HIGH_RES_TIMERS ··· 721 713 { 722 714 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 723 715 uinfo->count = 2; 724 - uinfo->value.integer.min = -50; 725 - uinfo->value.integer.max = 100; 716 + uinfo->value.integer.min = mixer_volume_level_min; 717 + uinfo->value.integer.max = mixer_volume_level_max; 726 718 return 0; 727 719 } 728 720 ··· 747 739 int left, right; 748 740 749 741 left = ucontrol->value.integer.value[0]; 750 - if (left < -50) 751 - left = -50; 752 - if (left > 100) 753 - left = 100; 742 + if (left < mixer_volume_level_min) 743 + left = mixer_volume_level_min; 744 + if (left > mixer_volume_level_max) 745 + left = mixer_volume_level_max; 754 746 right = ucontrol->value.integer.value[1]; 755 - if (right < -50) 756 - right = -50; 757 - if (right > 100) 758 - right = 100; 747 + if (right < mixer_volume_level_min) 748 + right = mixer_volume_level_min; 749 + if (right > mixer_volume_level_max) 750 + right = mixer_volume_level_max; 759 751 spin_lock_irq(&dummy->mixer_lock); 760 752 change = dummy->mixer_volume[addr][0] != left || 761 753 dummy->mixer_volume[addr][1] != right; ··· 1084 1076 dummy->pcm_hw.channels_max = m->channels_max; 1085 1077 } 1086 1078 1079 + if (mixer_volume_level_min > mixer_volume_level_max) { 1080 + pr_warn("snd-dummy: Invalid mixer volume level: min=%d, max=%d. Fall back to default value.\n", 1081 + mixer_volume_level_min, mixer_volume_level_max); 1082 + mixer_volume_level_min = USE_MIXER_VOLUME_LEVEL_MIN; 1083 + mixer_volume_level_max = USE_MIXER_VOLUME_LEVEL_MAX; 1084 + } 1087 1085 err = snd_card_dummy_new_mixer(dummy); 1088 1086 if (err < 0) 1089 1087 return err;