diff options
author | Clemens Ladisch <clemens@ladisch.de> | 2008-09-22 11:01:11 +0400 |
---|---|---|
committer | Clemens Ladisch <clemens@ladisch.de> | 2008-09-22 11:01:11 +0400 |
commit | c3f00739c5e45b4bf6f759172a5318256b92f2b2 (patch) | |
tree | 0ad1987783d637d13daa8731b634217f6be4ea3e /sound/pci | |
parent | fe10662c3c7e1a77cac7949a4b269622da663c2e (diff) | |
download | linux-c3f00739c5e45b4bf6f759172a5318256b92f2b2.tar.xz |
ALSA: virtuoso: create common functions for GPIO bit switch controls
Factor out the common code of the mixer callbacks that handle controls
that just switch a single GPIO bit.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Diffstat (limited to 'sound/pci')
-rw-r--r-- | sound/pci/oxygen/virtuoso.c | 53 |
1 files changed, 15 insertions, 38 deletions
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c index c4ac91f80235..34baff19ad36 100644 --- a/sound/pci/oxygen/virtuoso.c +++ b/sound/pci/oxygen/virtuoso.c @@ -444,29 +444,31 @@ static void xonar_gpio_changed(struct oxygen *chip) } } -static int alt_switch_get(struct snd_kcontrol *ctl, - struct snd_ctl_elem_value *value) +static int gpio_bit_switch_get(struct snd_kcontrol *ctl, + struct snd_ctl_elem_value *value) { struct oxygen *chip = ctl->private_data; + u16 bit = ctl->private_value; value->value.integer.value[0] = - !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_D2_ALT); + !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit); return 0; } -static int alt_switch_put(struct snd_kcontrol *ctl, - struct snd_ctl_elem_value *value) +static int gpio_bit_switch_put(struct snd_kcontrol *ctl, + struct snd_ctl_elem_value *value) { struct oxygen *chip = ctl->private_data; + u16 bit = ctl->private_value; u16 old_bits, new_bits; int changed; spin_lock_irq(&chip->reg_lock); old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA); if (value->value.integer.value[0]) - new_bits = old_bits | GPIO_D2_ALT; + new_bits = old_bits | bit; else - new_bits = old_bits & ~GPIO_D2_ALT; + new_bits = old_bits & ~bit; changed = new_bits != old_bits; if (changed) oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits); @@ -478,43 +480,18 @@ static const struct snd_kcontrol_new alt_switch = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Analog Loopback Switch", .info = snd_ctl_boolean_mono_info, - .get = alt_switch_get, - .put = alt_switch_put, + .get = gpio_bit_switch_get, + .put = gpio_bit_switch_put, + .private_value = GPIO_D2_ALT, }; -static int front_panel_get(struct snd_kcontrol *ctl, - struct snd_ctl_elem_value *value) -{ - struct oxygen *chip = ctl->private_data; - - value->value.integer.value[0] = - !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DX_FRONT_PANEL); - return 0; -} - -static int front_panel_put(struct snd_kcontrol *ctl, - struct snd_ctl_elem_value *value) -{ - struct oxygen *chip = ctl->private_data; - u16 old_reg, new_reg; - - spin_lock_irq(&chip->reg_lock); - old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA); - if (value->value.integer.value[0]) - new_reg = old_reg | GPIO_DX_FRONT_PANEL; - else - new_reg = old_reg & ~GPIO_DX_FRONT_PANEL; - oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg); - spin_unlock_irq(&chip->reg_lock); - return old_reg != new_reg; -} - static const struct snd_kcontrol_new front_panel_switch = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Front Panel Switch", .info = snd_ctl_boolean_mono_info, - .get = front_panel_get, - .put = front_panel_put, + .get = gpio_bit_switch_get, + .put = gpio_bit_switch_put, + .private_value = GPIO_DX_FRONT_PANEL, }; static void xonar_d1_ac97_switch(struct oxygen *chip, |