Update of /cvsroot/alsa/alsa-kernel/usb
In directory sc8-pr-cvs1:/tmp/cvs-serv3841/usb

Modified Files:
        usbaudio.c 
Log Message:
[PATCH: usbaudio-init.dif]

- initialize the USB interfaces at creation of PCM streams.
  hopefully this will fix the invalid state of USB interfaces
  at the start (which needed to use qinit program ocasionally).



Index: usbaudio.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usbaudio.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- usbaudio.c  19 Dec 2002 12:15:23 -0000      1.31
+++ usbaudio.c  7 Jan 2003 10:27:55 -0000       1.32
@@ -931,6 +931,70 @@
 
 
 /*
+ * initialize the picth control and sample rate
+ */
+static int init_usb_pitch(struct usb_device *dev, int iface,
+                         struct usb_host_interface *alts,
+                         struct audioformat *fmt)
+{
+       unsigned int ep;
+       unsigned char data[1];
+       int err;
+
+       ep = get_endpoint(alts, 0)->bEndpointAddress;
+       /* if endpoint has pitch control, enable it */
+       if (fmt->attributes & EP_CS_ATTR_PITCH_CONTROL) {
+               data[0] = 1;
+               if ((err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR,
+                                          
+USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, 
+                                          PITCH_CONTROL << 8, ep, data, 1, HZ)) < 0) {
+                       snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n",
+                                  dev->devnum, iface, ep);
+                       return err;
+               }
+       }
+       return 0;
+}
+
+static int init_usb_sample_rate(struct usb_device *dev, int iface,
+                               struct usb_host_interface *alts,
+                               struct audioformat *fmt, int rate)
+{
+       unsigned int ep;
+       unsigned char data[3];
+       int err;
+
+       ep = get_endpoint(alts, 0)->bEndpointAddress;
+       /* if endpoint has sampling rate control, set it */
+       if (fmt->attributes & EP_CS_ATTR_SAMPLE_RATE) {
+               int crate;
+               data[0] = rate;
+               data[1] = rate >> 8;
+               data[2] = rate >> 16;
+               if ((err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR,
+                                          
+USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, 
+                                          SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 
+HZ)) < 0) {
+                       snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep 
+0x%x\n",
+                                  dev->devnum, iface, fmt->altsetting, rate, ep);
+                       return err;
+               }
+               if ((err = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR,
+                                          
+USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN,
+                                          SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 
+HZ)) < 0) {
+                       snd_printk(KERN_ERR "%d:%d:%d: cannot get freq at ep 0x%x\n",
+                                  dev->devnum, iface, fmt->altsetting, ep);
+                       return err;
+               }
+               crate = data[0] | (data[1] << 8) | (data[2] << 16);
+               if (crate != rate) {
+                       snd_printd(KERN_WARNING "current rate %d is different from the 
+runtime rate %d\n", crate, rate);
+                       // runtime->rate = crate;
+               }
+       }
+       return 0;
+}
+
+/*
  * find a matching format and set up the interface
  */
 static int set_format(snd_usb_substream_t *subs, snd_pcm_runtime_t *runtime)
@@ -942,7 +1006,6 @@
        struct usb_interface *iface;
        struct audioformat *fmt;
        unsigned int ep, attr;
-       unsigned char data[3];
        int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
        int err;
 
@@ -1015,44 +1078,11 @@
                subs->syncinterval = get_endpoint(alts, 1)->bRefresh;
        }
 
-       ep = get_endpoint(alts, 0)->bEndpointAddress;
-       /* if endpoint has pitch control, enable it */
-       if (fmt->attributes & EP_CS_ATTR_PITCH_CONTROL) {
-               data[0] = 1;
-               if ((err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR,
-                                          
USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, 
-                                          PITCH_CONTROL << 8, ep, data, 1, HZ)) < 0) {
-                       snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n",
-                                  dev->devnum, subs->interface, ep);
-                       return err;
-               }
-       }
-       /* if endpoint has sampling rate control, set it */
-       if (fmt->attributes & EP_CS_ATTR_SAMPLE_RATE) {
-               int crate;
-               data[0] = runtime->rate;
-               data[1] = runtime->rate >> 8;
-               data[2] = runtime->rate >> 16;
-               if ((err = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR,
-                                          
USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, 
-                                          SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 
HZ)) < 0) {
-                       snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep 
0x%x\n",
-                                  dev->devnum, subs->interface, fmt->altsetting, 
runtime->rate, ep);
-                       return err;
-               }
-               if ((err = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR,
-                                          
USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN,
-                                          SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 
HZ)) < 0) {
-                       snd_printk(KERN_ERR "%d:%d:%d: cannot get freq at ep 0x%x\n",
-                                  dev->devnum, subs->interface, fmt->altsetting, ep);
-                       return err;
-               }
-               crate = data[0] | (data[1] << 8) | (data[2] << 16);
-               if (crate != runtime->rate) {
-                       snd_printd(KERN_WARNING "current rate %d is different from the 
runtime rate %d\n", crate, runtime->rate);
-                       // runtime->rate = crate;
-               }
-       }
+       if ((err = init_usb_pitch(dev, subs->interface, alts, fmt)) < 0 ||
+           (err = init_usb_sample_rate(dev, subs->interface, alts, fmt,
+                                       runtime->rate)) < 0)
+               return err;
+
        /* always fill max packet size */
        if (fmt->attributes & EP_CS_ATTR_FILL_MAX)
                subs->fill_max = 1;
@@ -1828,6 +1858,10 @@
                        kfree(fp);
                        return err;
                }
+               /* try to set the interface... */
+               usb_set_interface(chip->dev, iface_no, i);
+               init_usb_pitch(chip->dev, iface_no, alts, fp);
+               init_usb_sample_rate(chip->dev, iface_no, alts, fp, fp->rate_max);
        }
        return 0;
 }
@@ -1890,9 +1924,10 @@
                        /* skip non-supported classes */
                        continue;
                }
-               parse_audio_endpoints(chip, buffer, buflen, j);
-               usb_set_interface(dev, j, 0); /* reset the current interface */
-               usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1);
+               if (! parse_audio_endpoints(chip, buffer, buflen, j)) {
+                       usb_set_interface(dev, j, 0); /* reset the current interface */
+                       usb_driver_claim_interface(&usb_audio_driver, iface, (void 
+*)-1);
+               }
        }
 
        return 0;



-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Alsa-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/alsa-cvslog

Reply via email to