ALSA: usb-audio: add front jack channel selector for EMU0204
PATCH v2 1/1 ALSA: usb-audio: add front jack channel selector for EMU0204
Add support for front jack channel selector which is present on EMU0204. It allows to get 4 channels out of this soundcard.
---
v2: - pass constants for bRequest and bRequestType into snd_usb_ctl_msg()
- implement control as an enum instead of a switch.
sound/usb/mixer_quirks.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)
sound/usb/mixer_quirks.c +87 -0
@@ -433,6 +433,86 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, } } +/* EMU0204 */ +static int snd_emu0204_ch_switch_info (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo) +{ +static const char *texts[4 ] = {"1/2" , +"3/4" + }; + + uinfo->type =SNDRV_CTL_ELEM_TYPE_ENUMERATED ; + uinfo->count =1 ; + uinfo->value.enumerated.items =2 ; +if (uinfo->value.enumerated.item >1 ) + uinfo->value.enumerated.item =1 ; +strcpy (uinfo->value.enumerated.name, + texts[uinfo->value.enumerated.item]); + +return 0 ; +} + +static int snd_emu0204_ch_switch_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ + ucontrol->value.enumerated.item[0 ] = kcontrol->private_value; +return 0 ; +} + +static int snd_emu0204_ch_switch_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct usb_mixer_interface *mixer =snd_kcontrol_chip (kcontrol); +int value = ucontrol->value.enumerated.item[0 ]; +int err, changed; +unsigned char buf[2 ]; + + buf[0 ] =0x01 ; + buf[1 ] = value ?0x02 :0x01 ; + + changed = value != kcontrol->private_value; +down_read (&mixer->chip->shutdown_rwsem); +if (mixer->chip->shutdown) { + err = -ENODEV ; + goto out; + } + err =snd_usb_ctl_msg (mixer->chip->dev, +usb_sndctrlpipe (mixer->chip->dev,0 ),UAC_SET_CUR , +USB_RECIP_INTERFACE |USB_TYPE_CLASS |USB_DIR_OUT , +0x0400 ,0x0e00 , buf,2 ); + out: +up_read (&mixer->chip->shutdown_rwsem); +if (err <0 ) +return err; + kcontrol->private_value = value; +return changed; +} + + +static struct snd_kcontrol_new snd_emu0204_controls[] = { + { + .iface =SNDRV_CTL_ELEM_IFACE_MIXER , + .name ="Front Jack Channels" , + .info = snd_emu0204_ch_switch_info, + .get = snd_emu0204_ch_switch_get, + .put = snd_emu0204_ch_switch_put, + .private_value =0 , + }, +}; + +static int snd_emu0204_controls_create (struct usb_mixer_interface *mixer) +{ +int i, err; + +for (i =0 ; i <ARRAY_SIZE (snd_emu0204_controls); ++i) { + err =snd_ctl_add (mixer->chip->card, +snd_ctl_new1 (&snd_emu0204_controls[i], mixer)); +if (err <0 ) +return err; + } + +return 0 ; +}/* ASUS Xonar U1 / U3 controls */ static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
@@ -1545,6 +1625,13 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) snd_audigy2nx_proc_read);break ; +/* EMU0204 */ +case USB_ID (0x041e ,0x3f19 ): + err =snd_emu0204_controls_create (mixer); +if (err <0 ) +break ; +break ; +case USB_ID (0x0763 ,0x2030 ):/* M-Audio Fast Track C400 */ case USB_ID (0x0763 ,0x2031 ):/* M-Audio Fast Track C400 */ err =snd_c400_create_mixer (mixer);
Signature · 1 line
1.8.4.2
At Wed, 13 Nov 2013 12:32:20 +0300,
Quoted 18 lines · Vasily Khoruzhick
Add support for front jack channel selector which is present on EMU0204. It allows to get 4 channels out of this soundcard.
Tested-by Yury Bushmelev <[email protected]>Signed-off-by Vasily Khoruzhick <[email protected]>---
v2: - pass constants for bRequest and bRequestType intosnd_usb_ctl_msg()
- implement control as an enum instead of a switch.sound/usb/mixer_quirks.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)sound/usb/mixer_quirks.c +0
-0
sound/usb/mixer_quirks.c static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, · line 442
Quoted 10 lines
sound/usb/mixer_quirks.c +7
-0@@ -433,6 +433,86 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, } } +/* EMU0204 */ +static int snd_emu0204_ch_switch_info (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo) +{ +static const char *texts[4 ] = {"1/2" , +"3/4" + };
The declared array size doesn't match.
Takashi
Quoted 16 lines
sound/usb/mixer_quirks.c +16
-0+ + uinfo->type =SNDRV_CTL_ELEM_TYPE_ENUMERATED ; + uinfo->count =1 ; + uinfo->value.enumerated.items =2 ; +if (uinfo->value.enumerated.item >1 ) + uinfo->value.enumerated.item =1 ; +strcpy (uinfo->value.enumerated.name, + texts[uinfo->value.enumerated.item]); + +return 0 ; +} + +static int snd_emu0204_ch_switch_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ + ucontrol->value.enumerated.item[0 ] = kcontrol->private_value;
sound/usb/mixer_quirks.c static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, · line 468
Quoted 10 lines
sound/usb/mixer_quirks.c +10
-0+return 0 ; +} + +static int snd_emu0204_ch_switch_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct usb_mixer_interface *mixer =snd_kcontrol_chip (kcontrol); +int value = ucontrol->value.enumerated.item[0 ]; +int err, changed; +unsigned char buf[2 ];
Better to have a sanity check of the value. User-space can pass any value in theory.
thanks,
Takashi
Quoted 67 lines
sound/usb/mixer_quirks.c +54
-0+ + buf[0 ] =0x01 ; + buf[1 ] = value ?0x02 :0x01 ; + + changed = value != kcontrol->private_value; +down_read (&mixer->chip->shutdown_rwsem); +if (mixer->chip->shutdown) { + err = -ENODEV ; + goto out; + } + err =snd_usb_ctl_msg (mixer->chip->dev, +usb_sndctrlpipe (mixer->chip->dev,0 ),UAC_SET_CUR , +USB_RECIP_INTERFACE |USB_TYPE_CLASS |USB_DIR_OUT , +0x0400 ,0x0e00 , buf,2 ); + out: +up_read (&mixer->chip->shutdown_rwsem); +if (err <0 ) +return err; + kcontrol->private_value = value; +return changed; +} + + +static struct snd_kcontrol_new snd_emu0204_controls[] = { + { + .iface =SNDRV_CTL_ELEM_IFACE_MIXER , + .name ="Front Jack Channels" , + .info = snd_emu0204_ch_switch_info, + .get = snd_emu0204_ch_switch_get, + .put = snd_emu0204_ch_switch_put, + .private_value =0 , + }, +}; + +static int snd_emu0204_controls_create (struct usb_mixer_interface *mixer) +{ +int i, err; + +for (i =0 ; i <ARRAY_SIZE (snd_emu0204_controls); ++i) { + err =snd_ctl_add (mixer->chip->card, +snd_ctl_new1 (&snd_emu0204_controls[i], mixer)); +if (err <0 ) +return err; + } + +return 0 ; +}/* ASUS Xonar U1 / U3 controls */ static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,@@ -1545,6 +1625,13 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) snd_audigy2nx_proc_read);break ; +/* EMU0204 */ +case USB_ID (0x041e ,0x3f19 ): + err =snd_emu0204_controls_create (mixer); +if (err <0 ) +break ; +break ; +case USB_ID (0x0763 ,0x2030 ):/* M-Audio Fast Track C400 */ case USB_ID (0x0763 ,0x2031 ):/* M-Audio Fast Track C400 */ err =snd_c400_create_mixer (mixer);Signature · 1 line
1.8.4.2
Quoted 24 lines · Takashi Iwai
At Wed, 13 Nov 2013 12:32:20 +0300,
Quoted 21 lines · Vasily Khoruzhick
Add support for front jack channel selector which is present on EMU0204. It allows to get 4 channels out of this soundcard.
Tested-by Yury Bushmelev <[email protected]>Signed-off-by Vasily Khoruzhick <[email protected]>---
v2: - pass constants for bRequest and bRequestType intosnd_usb_ctl_msg()
- implement control as an enum instead of a switch.sound/usb/mixer_quirks.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+)sound/usb/mixer_quirks.c +0
-0@@ -433,6 +433,86 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, } }
Quoted 10 lines
sound/usb/mixer_quirks.c static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, · line 442
Quoted 7 lines
sound/usb/mixer_quirks.c +7
-0+/* EMU0204 */ +static int snd_emu0204_ch_switch_info (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo) +{ +static const char *texts[4 ] = {"1/2" , +"3/4" + };The declared array size doesn't match.
Oh, sorry, my fault, will resend in few minutes.
Quoted 25 lines
Takashi
Quoted 21 lines
sound/usb/mixer_quirks.c +21
-0+ + uinfo->type =SNDRV_CTL_ELEM_TYPE_ENUMERATED ; + uinfo->count =1 ; + uinfo->value.enumerated.items =2 ; +if (uinfo->value.enumerated.item >1 ) + uinfo->value.enumerated.item =1 ; +strcpy (uinfo->value.enumerated.name, + texts[uinfo->value.enumerated.item]); + +return 0 ; +} + +static int snd_emu0204_ch_switch_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ + ucontrol->value.enumerated.item[0 ] = kcontrol->private_value; +return 0 ; +} + +static int snd_emu0204_ch_switch_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol)
Quoted 9 lines
sound/usb/mixer_quirks.c static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, · line 468
Quoted 5 lines
sound/usb/mixer_quirks.c +5
-0+{ +struct usb_mixer_interface *mixer =snd_kcontrol_chip (kcontrol); +int value = ucontrol->value.enumerated.item[0 ]; +int err, changed; +unsigned char buf[2 ];Better to have a sanity check of the value. User-space can pass any value in theory.
And return -EINVAL on non-valid values? OK
Quoted 5 lines
thanks,
Takashi
Regards
Vasily
PATCH v3 1/1 ALSA: usb-audio: add front jack channel selector for EMU0204
Add support for front jack channel selector which is present on EMU0204. It allows to get 4 channels out of this soundcard.
---
v2: - pass constants for bRequest and bRequestType into snd_usb_ctl_msg()
- implement control as an enum instead of a switch.
v3: - Fix declared array size
- Add sanity check for a passed value to snd_emu0204_ch_switch_put()
sound/usb/mixer_quirks.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+)
sound/usb/mixer_quirks.c +90 -0
@@ -433,6 +433,89 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, } } +/* EMU0204 */ +static int snd_emu0204_ch_switch_info (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo) +{ +static const char *texts[2 ] = {"1/2" , +"3/4" + }; + + uinfo->type =SNDRV_CTL_ELEM_TYPE_ENUMERATED ; + uinfo->count =1 ; + uinfo->value.enumerated.items =2 ; +if (uinfo->value.enumerated.item >1 ) + uinfo->value.enumerated.item =1 ; +strcpy (uinfo->value.enumerated.name, + texts[uinfo->value.enumerated.item]); + +return 0 ; +} + +static int snd_emu0204_ch_switch_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ + ucontrol->value.enumerated.item[0 ] = kcontrol->private_value; +return 0 ; +} + +static int snd_emu0204_ch_switch_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct usb_mixer_interface *mixer =snd_kcontrol_chip (kcontrol); +unsigned int value = ucontrol->value.enumerated.item[0 ]; +int err, changed; +unsigned char buf[2 ]; + +if (value >1 ) +return -EINVAL ; + + buf[0 ] =0x01 ; + buf[1 ] = value ?0x02 :0x01 ; + + changed = value != kcontrol->private_value; +down_read (&mixer->chip->shutdown_rwsem); +if (mixer->chip->shutdown) { + err = -ENODEV ; + goto out; + } + err =snd_usb_ctl_msg (mixer->chip->dev, +usb_sndctrlpipe (mixer->chip->dev,0 ),UAC_SET_CUR , +USB_RECIP_INTERFACE |USB_TYPE_CLASS |USB_DIR_OUT , +0x0400 ,0x0e00 , buf,2 ); + out: +up_read (&mixer->chip->shutdown_rwsem); +if (err <0 ) +return err; + kcontrol->private_value = value; +return changed; +} + + +static struct snd_kcontrol_new snd_emu0204_controls[] = { + { + .iface =SNDRV_CTL_ELEM_IFACE_MIXER , + .name ="Front Jack Channels" , + .info = snd_emu0204_ch_switch_info, + .get = snd_emu0204_ch_switch_get, + .put = snd_emu0204_ch_switch_put, + .private_value =0 , + }, +}; + +static int snd_emu0204_controls_create (struct usb_mixer_interface *mixer) +{ +int i, err; + +for (i =0 ; i <ARRAY_SIZE (snd_emu0204_controls); ++i) { + err =snd_ctl_add (mixer->chip->card, +snd_ctl_new1 (&snd_emu0204_controls[i], mixer)); +if (err <0 ) +return err; + } + +return 0 ; +}/* ASUS Xonar U1 / U3 controls */ static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
@@ -1545,6 +1628,13 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) snd_audigy2nx_proc_read);break ; +/* EMU0204 */ +case USB_ID (0x041e ,0x3f19 ): + err =snd_emu0204_controls_create (mixer); +if (err <0 ) +break ; +break ; +case USB_ID (0x0763 ,0x2030 ):/* M-Audio Fast Track C400 */ case USB_ID (0x0763 ,0x2031 ):/* M-Audio Fast Track C400 */ err =snd_c400_create_mixer (mixer);
Signature · 1 line
1.8.4.2
Takashi Iwai
AppliedAt Wed, 13 Nov 2013 13:13:35 +0300,
Quoted 6 lines · Vasily Khoruzhick
Add support for front jack channel selector which is present on EMU0204. It allows to get 4 channels out of this soundcard.
Tested-by Yury Bushmelev <[email protected]>Signed-off-by Vasily Khoruzhick <[email protected]>
Thanks, applied.
Takashi
Quoted 120 lines
---
v2: - pass constants for bRequest and bRequestType intosnd_usb_ctl_msg()
- implement control as an enum instead of a switch.
v3: - Fix declared array size
- Add sanity check for a passed value tosnd_emu0204_ch_switch_put()sound/usb/mixer_quirks.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+)sound/usb/mixer_quirks.c +90
-0@@ -433,6 +433,89 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry, } } +/* EMU0204 */ +static int snd_emu0204_ch_switch_info (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo) +{ +static const char *texts[2 ] = {"1/2" , +"3/4" + }; + + uinfo->type =SNDRV_CTL_ELEM_TYPE_ENUMERATED ; + uinfo->count =1 ; + uinfo->value.enumerated.items =2 ; +if (uinfo->value.enumerated.item >1 ) + uinfo->value.enumerated.item =1 ; +strcpy (uinfo->value.enumerated.name, + texts[uinfo->value.enumerated.item]); + +return 0 ; +} + +static int snd_emu0204_ch_switch_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ + ucontrol->value.enumerated.item[0 ] = kcontrol->private_value; +return 0 ; +} + +static int snd_emu0204_ch_switch_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct usb_mixer_interface *mixer =snd_kcontrol_chip (kcontrol); +unsigned int value = ucontrol->value.enumerated.item[0 ]; +int err, changed; +unsigned char buf[2 ]; + +if (value >1 ) +return -EINVAL ; + + buf[0 ] =0x01 ; + buf[1 ] = value ?0x02 :0x01 ; + + changed = value != kcontrol->private_value; +down_read (&mixer->chip->shutdown_rwsem); +if (mixer->chip->shutdown) { + err = -ENODEV ; + goto out; + } + err =snd_usb_ctl_msg (mixer->chip->dev, +usb_sndctrlpipe (mixer->chip->dev,0 ),UAC_SET_CUR , +USB_RECIP_INTERFACE |USB_TYPE_CLASS |USB_DIR_OUT , +0x0400 ,0x0e00 , buf,2 ); + out: +up_read (&mixer->chip->shutdown_rwsem); +if (err <0 ) +return err; + kcontrol->private_value = value; +return changed; +} + + +static struct snd_kcontrol_new snd_emu0204_controls[] = { + { + .iface =SNDRV_CTL_ELEM_IFACE_MIXER , + .name ="Front Jack Channels" , + .info = snd_emu0204_ch_switch_info, + .get = snd_emu0204_ch_switch_get, + .put = snd_emu0204_ch_switch_put, + .private_value =0 , + }, +}; + +static int snd_emu0204_controls_create (struct usb_mixer_interface *mixer) +{ +int i, err; + +for (i =0 ; i <ARRAY_SIZE (snd_emu0204_controls); ++i) { + err =snd_ctl_add (mixer->chip->card, +snd_ctl_new1 (&snd_emu0204_controls[i], mixer)); +if (err <0 ) +return err; + } + +return 0 ; +}/* ASUS Xonar U1 / U3 controls */ static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,@@ -1545,6 +1628,13 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer) snd_audigy2nx_proc_read);break ; +/* EMU0204 */ +case USB_ID (0x041e ,0x3f19 ): + err =snd_emu0204_controls_create (mixer); +if (err <0 ) +break ; +break ; +case USB_ID (0x0763 ,0x2030 ):/* M-Audio Fast Track C400 */ case USB_ID (0x0763 ,0x2031 ):/* M-Audio Fast Track C400 */ err =snd_c400_create_mixer (mixer);Signature · 1 line
1.8.4.2