Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
[sfrench/cifs-2.6.git] / sound / usb / usbmixer.c
index e74eb1bc8d8778e97eb6fd93e65c2b60568b7fe5..89c63d073cc6fac8f0c00ca1646377994157c64b 100644 (file)
@@ -26,7 +26,6 @@
  *
  */
 
-#include <sound/driver.h>
 #include <linux/bitops.h>
 #include <linux/init.h>
 #include <linux/list.h>
@@ -360,7 +359,7 @@ static int get_ctl_value(struct usb_mixer_elem_info *cval, int request, int vali
                                    request,
                                    USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
                                    validx, cval->mixer->ctrlif | (cval->id << 8),
-                                   buf, val_len, 100) >= 0) {
+                                   buf, val_len, 100) >= val_len) {
                        *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len));
                        return 0;
                }
@@ -1483,7 +1482,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
        struct snd_kcontrol *kctl;
        char **namelist;
 
-       if (! num_ins || desc[0] < 6 + num_ins) {
+       if (! num_ins || desc[0] < 5 + num_ins) {
                snd_printk(KERN_ERR "invalid SELECTOR UNIT descriptor %d\n", unitid);
                return -EINVAL;
        }
@@ -1526,7 +1525,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
                namelist[i] = kmalloc(MAX_ITEM_NAME_LEN, GFP_KERNEL);
                if (! namelist[i]) {
                        snd_printk(KERN_ERR "cannot malloc\n");
-                       while (--i > 0)
+                       while (i--)
                                kfree(namelist[i]);
                        kfree(namelist);
                        kfree(cval);
@@ -1703,6 +1702,11 @@ static void snd_usb_mixer_memory_change(struct usb_mixer_interface *mixer,
        case 19: /* speaker out jacks */
        case 20: /* headphones out jack */
                break;
+       /* live24ext: 4 = line-in jack */
+       case 3: /* hp-out jack (may actuate Mute) */
+               if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040))
+                       snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
+               break;
        default:
                snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
                break;
@@ -1888,14 +1892,7 @@ static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
        return 0;
 }
 
-static int snd_audigy2nx_led_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
-{
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
-       uinfo->count = 1;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = 1;
-       return 0;
-}
+#define snd_audigy2nx_led_info         snd_ctl_boolean_mono_info
 
 static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
@@ -1958,6 +1955,9 @@ static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
        int i, err;
 
        for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
+               if (i > 1 &&  /* Live24ext has 2 LEDs only */
+                       mixer->chip->usb_id == USB_ID(0x041e, 0x3040))
+                       break; 
                err = snd_ctl_add(mixer->chip->card,
                                  snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
                if (err < 0)
@@ -1970,28 +1970,42 @@ static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
 static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
                                    struct snd_info_buffer *buffer)
 {
-       static const struct {
+       static const struct sb_jack {
                int unitid;
                const char *name;
-       } jacks[] = {
+       }  jacks_audigy2nx[] = {
                {4,  "dig in "},
                {7,  "line in"},
                {19, "spk out"},
                {20, "hph out"},
+               {-1, NULL}
+       }, jacks_live24ext[] = {
+               {4,  "line in"}, /* &1=Line, &2=Mic*/
+               {3,  "hph out"}, /* headphones */
+               {0,  "RC     "}, /* last command, 6 bytes see rc_config above */
+               {-1, NULL}
        };
+       const struct sb_jack *jacks;
        struct usb_mixer_interface *mixer = entry->private_data;
        int i, err;
        u8 buf[3];
 
        snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
-       for (i = 0; i < ARRAY_SIZE(jacks); ++i) {
+       if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
+               jacks = jacks_audigy2nx;
+       else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040))
+               jacks = jacks_live24ext;
+       else
+               return;
+
+       for (i = 0; jacks[i].name; ++i) {
                snd_iprintf(buffer, "%s: ", jacks[i].name);
                err = snd_usb_ctl_msg(mixer->chip->dev,
                                      usb_rcvctrlpipe(mixer->chip->dev, 0),
                                      GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
                                      USB_RECIP_INTERFACE, 0,
                                      jacks[i].unitid << 8, buf, 3, 100);
-               if (err == 3 && buf[0] == 3)
+               if (err == 3 && (buf[0] == 3 || buf[0] == 6))
                        snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
                else
                        snd_iprintf(buffer, "?\n");
@@ -2029,7 +2043,8 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif)
        if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
                goto _error;
 
-       if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) {
+       if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) ||
+           mixer->chip->usb_id == USB_ID(0x041e, 0x3040)) {
                struct snd_info_entry *entry;
 
                if ((err = snd_audigy2nx_controls_create(mixer)) < 0)