mirror of
https://github.com/torvalds/linux.git
synced 2026-07-29 02:31:27 +02:00
ALSA: usb-audio: Add audigy2nx resume support
Rewrite the code to handle LEDs on audigy2nx and co for supporting the proper resume. A new internal helper function add_single_ctl_with_resume() is introduced to manage the usb_mixer_elem_list more easily. Also while we're at it, move audigy2nx_leds[] in usb_mixer_interface struct into the private_value of each kctl, too. Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
3360b84b8e
commit
9cf3689bfe
|
|
@ -23,7 +23,6 @@ struct usb_mixer_interface {
|
||||||
struct usb_ctrlrequest *rc_setup_packet;
|
struct usb_ctrlrequest *rc_setup_packet;
|
||||||
u8 rc_buffer[6];
|
u8 rc_buffer[6];
|
||||||
|
|
||||||
u8 audigy2nx_leds[3];
|
|
||||||
u8 xonar_u1_status;
|
u8 xonar_u1_status;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,32 @@ static int snd_create_std_mono_table(struct usb_mixer_interface *mixer,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
|
||||||
|
int id,
|
||||||
|
usb_mixer_elem_resume_func_t resume,
|
||||||
|
const struct snd_kcontrol_new *knew,
|
||||||
|
struct usb_mixer_elem_list **listp)
|
||||||
|
{
|
||||||
|
struct usb_mixer_elem_list *list;
|
||||||
|
struct snd_kcontrol *kctl;
|
||||||
|
|
||||||
|
list = kzalloc(sizeof(*list), GFP_KERNEL);
|
||||||
|
if (!list)
|
||||||
|
return -ENOMEM;
|
||||||
|
if (listp)
|
||||||
|
*listp = list;
|
||||||
|
list->mixer = mixer;
|
||||||
|
list->id = id;
|
||||||
|
list->resume = resume;
|
||||||
|
kctl = snd_ctl_new1(knew, list);
|
||||||
|
if (!kctl) {
|
||||||
|
kfree(list);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
kctl->private_free = snd_usb_mixer_elem_free;
|
||||||
|
return snd_usb_mixer_add_control(list, kctl);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sound Blaster remote control configuration
|
* Sound Blaster remote control configuration
|
||||||
*
|
*
|
||||||
|
|
@ -271,84 +297,90 @@ static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
|
||||||
|
|
||||||
static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
||||||
{
|
{
|
||||||
struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
|
ucontrol->value.integer.value[0] = kcontrol->private_value >> 8;
|
||||||
int index = kcontrol->private_value;
|
|
||||||
|
|
||||||
ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
static int snd_audigy2nx_led_update(struct usb_mixer_interface *mixer,
|
||||||
|
int value, int index)
|
||||||
{
|
{
|
||||||
struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
|
struct snd_usb_audio *chip = mixer->chip;
|
||||||
int index = kcontrol->private_value;
|
int err;
|
||||||
int value = ucontrol->value.integer.value[0];
|
|
||||||
int err, changed;
|
|
||||||
|
|
||||||
if (value > 1)
|
down_read(&chip->shutdown_rwsem);
|
||||||
return -EINVAL;
|
if (chip->shutdown) {
|
||||||
changed = value != mixer->audigy2nx_leds[index];
|
|
||||||
down_read(&mixer->chip->shutdown_rwsem);
|
|
||||||
if (mixer->chip->shutdown) {
|
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (mixer->chip->usb_id == USB_ID(0x041e, 0x3042))
|
if (chip->usb_id == USB_ID(0x041e, 0x3042))
|
||||||
err = snd_usb_ctl_msg(mixer->chip->dev,
|
err = snd_usb_ctl_msg(chip->dev,
|
||||||
usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
|
usb_sndctrlpipe(chip->dev, 0), 0x24,
|
||||||
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
|
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
|
||||||
!value, 0, NULL, 0);
|
!value, 0, NULL, 0);
|
||||||
/* USB X-Fi S51 Pro */
|
/* USB X-Fi S51 Pro */
|
||||||
if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df))
|
if (chip->usb_id == USB_ID(0x041e, 0x30df))
|
||||||
err = snd_usb_ctl_msg(mixer->chip->dev,
|
err = snd_usb_ctl_msg(chip->dev,
|
||||||
usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
|
usb_sndctrlpipe(chip->dev, 0), 0x24,
|
||||||
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
|
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
|
||||||
!value, 0, NULL, 0);
|
!value, 0, NULL, 0);
|
||||||
else
|
else
|
||||||
err = snd_usb_ctl_msg(mixer->chip->dev,
|
err = snd_usb_ctl_msg(chip->dev,
|
||||||
usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
|
usb_sndctrlpipe(chip->dev, 0), 0x24,
|
||||||
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
|
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
|
||||||
value, index + 2, NULL, 0);
|
value, index + 2, NULL, 0);
|
||||||
out:
|
out:
|
||||||
up_read(&mixer->chip->shutdown_rwsem);
|
up_read(&chip->shutdown_rwsem);
|
||||||
if (err < 0)
|
return err;
|
||||||
return err;
|
|
||||||
mixer->audigy2nx_leds[index] = value;
|
|
||||||
return changed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
|
static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol,
|
||||||
{
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
{
|
||||||
.name = "CMSS LED Switch",
|
struct usb_mixer_elem_list *list = snd_kcontrol_chip(kcontrol);
|
||||||
.info = snd_audigy2nx_led_info,
|
struct usb_mixer_interface *mixer = list->mixer;
|
||||||
.get = snd_audigy2nx_led_get,
|
int index = kcontrol->private_value & 0xff;
|
||||||
.put = snd_audigy2nx_led_put,
|
int value = ucontrol->value.integer.value[0];
|
||||||
.private_value = 0,
|
int old_value = kcontrol->private_value >> 8;
|
||||||
},
|
int err;
|
||||||
{
|
|
||||||
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
if (value > 1)
|
||||||
.name = "Power LED Switch",
|
return -EINVAL;
|
||||||
.info = snd_audigy2nx_led_info,
|
if (value == old_value)
|
||||||
.get = snd_audigy2nx_led_get,
|
return 0;
|
||||||
.put = snd_audigy2nx_led_put,
|
kcontrol->private_value = (value << 8) | index;
|
||||||
.private_value = 1,
|
err = snd_audigy2nx_led_update(mixer, value, index);
|
||||||
},
|
return err < 0 ? err : 1;
|
||||||
{
|
}
|
||||||
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
||||||
.name = "Dolby Digital LED Switch",
|
static int snd_audigy2nx_led_resume(struct usb_mixer_elem_list *list)
|
||||||
.info = snd_audigy2nx_led_info,
|
{
|
||||||
.get = snd_audigy2nx_led_get,
|
int priv_value = list->kctl->private_value;
|
||||||
.put = snd_audigy2nx_led_put,
|
|
||||||
.private_value = 2,
|
return snd_audigy2nx_led_update(list->mixer, priv_value >> 8,
|
||||||
},
|
priv_value & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* name and private_value are set dynamically */
|
||||||
|
static struct snd_kcontrol_new snd_audigy2nx_control = {
|
||||||
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
||||||
|
.info = snd_audigy2nx_led_info,
|
||||||
|
.get = snd_audigy2nx_led_get,
|
||||||
|
.put = snd_audigy2nx_led_put,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char * const snd_audigy2nx_led_names[] = {
|
||||||
|
"CMSS LED Switch",
|
||||||
|
"Power LED Switch",
|
||||||
|
"Dolby Digital LED Switch",
|
||||||
};
|
};
|
||||||
|
|
||||||
static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
|
static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
|
||||||
{
|
{
|
||||||
int i, err;
|
int i, err;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
|
for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_led_names); ++i) {
|
||||||
|
struct snd_kcontrol_new knew;
|
||||||
|
|
||||||
/* USB X-Fi S51 doesn't have a CMSS LED */
|
/* USB X-Fi S51 doesn't have a CMSS LED */
|
||||||
if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
|
if ((mixer->chip->usb_id == USB_ID(0x041e, 0x3042)) && i == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -361,12 +393,16 @@ static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
|
||||||
mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
|
mixer->chip->usb_id == USB_ID(0x041e, 0x30df) ||
|
||||||
mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
|
mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
|
||||||
break;
|
break;
|
||||||
err = snd_ctl_add(mixer->chip->card,
|
|
||||||
snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
|
knew = snd_audigy2nx_control;
|
||||||
|
knew.name = snd_audigy2nx_led_names[i];
|
||||||
|
knew.private_value = (1 << 8) | i; /* LED on as default */
|
||||||
|
err = add_single_ctl_with_resume(mixer, 0,
|
||||||
|
snd_audigy2nx_led_resume,
|
||||||
|
&knew, NULL);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user