aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorClemens Ladisch <clemens@ladisch.de>2008-09-22 03:01:11 -0400
committerClemens Ladisch <clemens@ladisch.de>2008-09-22 03:01:11 -0400
commitc3f00739c5e45b4bf6f759172a5318256b92f2b2 (patch)
tree0ad1987783d637d13daa8731b634217f6be4ea3e /sound
parentfe10662c3c7e1a77cac7949a4b269622da663c2e (diff)
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')
-rw-r--r--sound/pci/oxygen/virtuoso.c53
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)
444 } 444 }
445} 445}
446 446
447static int alt_switch_get(struct snd_kcontrol *ctl, 447static int gpio_bit_switch_get(struct snd_kcontrol *ctl,
448 struct snd_ctl_elem_value *value) 448 struct snd_ctl_elem_value *value)
449{ 449{
450 struct oxygen *chip = ctl->private_data; 450 struct oxygen *chip = ctl->private_data;
451 u16 bit = ctl->private_value;
451 452
452 value->value.integer.value[0] = 453 value->value.integer.value[0] =
453 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_D2_ALT); 454 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & bit);
454 return 0; 455 return 0;
455} 456}
456 457
457static int alt_switch_put(struct snd_kcontrol *ctl, 458static int gpio_bit_switch_put(struct snd_kcontrol *ctl,
458 struct snd_ctl_elem_value *value) 459 struct snd_ctl_elem_value *value)
459{ 460{
460 struct oxygen *chip = ctl->private_data; 461 struct oxygen *chip = ctl->private_data;
462 u16 bit = ctl->private_value;
461 u16 old_bits, new_bits; 463 u16 old_bits, new_bits;
462 int changed; 464 int changed;
463 465
464 spin_lock_irq(&chip->reg_lock); 466 spin_lock_irq(&chip->reg_lock);
465 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA); 467 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
466 if (value->value.integer.value[0]) 468 if (value->value.integer.value[0])
467 new_bits = old_bits | GPIO_D2_ALT; 469 new_bits = old_bits | bit;
468 else 470 else
469 new_bits = old_bits & ~GPIO_D2_ALT; 471 new_bits = old_bits & ~bit;
470 changed = new_bits != old_bits; 472 changed = new_bits != old_bits;
471 if (changed) 473 if (changed)
472 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits); 474 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
@@ -478,43 +480,18 @@ static const struct snd_kcontrol_new alt_switch = {
478 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 480 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
479 .name = "Analog Loopback Switch", 481 .name = "Analog Loopback Switch",
480 .info = snd_ctl_boolean_mono_info, 482 .info = snd_ctl_boolean_mono_info,
481 .get = alt_switch_get, 483 .get = gpio_bit_switch_get,
482 .put = alt_switch_put, 484 .put = gpio_bit_switch_put,
485 .private_value = GPIO_D2_ALT,
483}; 486};
484 487
485static int front_panel_get(struct snd_kcontrol *ctl,
486 struct snd_ctl_elem_value *value)
487{
488 struct oxygen *chip = ctl->private_data;
489
490 value->value.integer.value[0] =
491 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DX_FRONT_PANEL);
492 return 0;
493}
494
495static int front_panel_put(struct snd_kcontrol *ctl,
496 struct snd_ctl_elem_value *value)
497{
498 struct oxygen *chip = ctl->private_data;
499 u16 old_reg, new_reg;
500
501 spin_lock_irq(&chip->reg_lock);
502 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
503 if (value->value.integer.value[0])
504 new_reg = old_reg | GPIO_DX_FRONT_PANEL;
505 else
506 new_reg = old_reg & ~GPIO_DX_FRONT_PANEL;
507 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
508 spin_unlock_irq(&chip->reg_lock);
509 return old_reg != new_reg;
510}
511
512static const struct snd_kcontrol_new front_panel_switch = { 488static const struct snd_kcontrol_new front_panel_switch = {
513 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
514 .name = "Front Panel Switch", 490 .name = "Front Panel Switch",
515 .info = snd_ctl_boolean_mono_info, 491 .info = snd_ctl_boolean_mono_info,
516 .get = front_panel_get, 492 .get = gpio_bit_switch_get,
517 .put = front_panel_put, 493 .put = gpio_bit_switch_put,
494 .private_value = GPIO_DX_FRONT_PANEL,
518}; 495};
519 496
520static void xonar_d1_ac97_switch(struct oxygen *chip, 497static void xonar_d1_ac97_switch(struct oxygen *chip,