diff options
author | Adrian Knoth <adi@drcomp.erfurt.thur.de> | 2012-12-03 08:55:49 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2012-12-03 09:29:45 -0500 |
commit | bf0ff87bef59fbc60b259b8843ae7fbed2cc44bd (patch) | |
tree | 1351735f1dd88069e67149c3f3cb9929a1776253 /sound/pci | |
parent | b6adb57df1b7ae03094978973d55bec59c4ce098 (diff) |
ALSA: hdspm - Implement generic function to toggle settings
The driver contains at least six similar functions that change only a
single bit in the control register, only the bit position varies.
This patch implements a generic function to toggle a certain bit
position that will be used to replace the old code.
Signed-off-by: Adrian Knoth <adi@drcomp.erfurt.thur.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci')
-rw-r--r-- | sound/pci/rme9652/hdspm.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c index 748e36c66603..002e692bd346 100644 --- a/sound/pci/rme9652/hdspm.c +++ b/sound/pci/rme9652/hdspm.c | |||
@@ -2887,6 +2887,63 @@ static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol, | |||
2887 | return 0; | 2887 | return 0; |
2888 | } | 2888 | } |
2889 | 2889 | ||
2890 | #define HDSPM_TOGGLE_SETTING(xname, xindex) \ | ||
2891 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | ||
2892 | .name = xname, \ | ||
2893 | .private_value = xindex, \ | ||
2894 | .info = snd_hdspm_info_toggle_setting, \ | ||
2895 | .get = snd_hdspm_get_toggle_setting, \ | ||
2896 | .put = snd_hdspm_put_toggle_setting \ | ||
2897 | } | ||
2898 | |||
2899 | static int hdspm_toggle_setting(struct hdspm *hdspm, u32 regmask) | ||
2900 | { | ||
2901 | return (hdspm->control_register & regmask) ? 1 : 0; | ||
2902 | } | ||
2903 | |||
2904 | static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out) | ||
2905 | { | ||
2906 | if (out) | ||
2907 | hdspm->control_register |= regmask; | ||
2908 | else | ||
2909 | hdspm->control_register &= ~regmask; | ||
2910 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); | ||
2911 | |||
2912 | return 0; | ||
2913 | } | ||
2914 | |||
2915 | #define snd_hdspm_info_toggle_setting snd_ctl_boolean_mono_info | ||
2916 | |||
2917 | static int snd_hdspm_get_toggle_setting(struct snd_kcontrol *kcontrol, | ||
2918 | struct snd_ctl_elem_value *ucontrol) | ||
2919 | { | ||
2920 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | ||
2921 | u32 regmask = kcontrol->private_value; | ||
2922 | |||
2923 | spin_lock_irq(&hdspm->lock); | ||
2924 | ucontrol->value.integer.value[0] = hdspm_toggle_setting(hdspm, regmask); | ||
2925 | spin_unlock_irq(&hdspm->lock); | ||
2926 | return 0; | ||
2927 | } | ||
2928 | |||
2929 | static int snd_hdspm_put_toggle_setting(struct snd_kcontrol *kcontrol, | ||
2930 | struct snd_ctl_elem_value *ucontrol) | ||
2931 | { | ||
2932 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | ||
2933 | u32 regmask = kcontrol->private_value; | ||
2934 | int change; | ||
2935 | unsigned int val; | ||
2936 | |||
2937 | if (!snd_hdspm_use_is_exclusive(hdspm)) | ||
2938 | return -EBUSY; | ||
2939 | val = ucontrol->value.integer.value[0] & 1; | ||
2940 | spin_lock_irq(&hdspm->lock); | ||
2941 | change = (int) val != hdspm_toggle_setting(hdspm, regmask); | ||
2942 | hdspm_set_toggle_setting(hdspm, regmask, val); | ||
2943 | spin_unlock_irq(&hdspm->lock); | ||
2944 | return change; | ||
2945 | } | ||
2946 | |||
2890 | 2947 | ||
2891 | #define HDSPM_LINE_OUT(xname, xindex) \ | 2948 | #define HDSPM_LINE_OUT(xname, xindex) \ |
2892 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | 2949 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |