2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/usb.h>
26 * combine bytes and get an integer value
28 unsigned int snd_usb_combine_bytes(unsigned char *bytes
, int size
)
31 case 1: return *bytes
;
32 case 2: return combine_word(bytes
);
33 case 3: return combine_triple(bytes
);
34 case 4: return combine_quad(bytes
);
40 * parse descriptor buffer and return the pointer starting the given
43 void *snd_usb_find_desc(void *descstart
, int desclen
, void *after
, u8 dtype
)
55 if (p
[1] == dtype
&& (!after
|| (void *)p
> after
)) {
64 * find a class-specified interface descriptor with the given subtype.
66 void *snd_usb_find_csint_desc(void *buffer
, int buflen
, void *after
, u8 dsubtype
)
68 unsigned char *p
= after
;
70 while ((p
= snd_usb_find_desc(buffer
, buflen
, p
,
71 USB_DT_CS_INTERFACE
)) != NULL
) {
72 if (p
[0] >= 3 && p
[2] == dsubtype
)
79 * Wrapper for usb_control_msg().
80 * Allocates a temp buffer to prevent dmaing from/to the stack.
82 int snd_usb_ctl_msg(struct usb_device
*dev
, unsigned int pipe
, __u8 request
,
83 __u8 requesttype
, __u16 value
, __u16 index
, void *data
,
84 __u16 size
, int timeout
)
90 buf
= kmemdup(data
, size
, GFP_KERNEL
);
94 err
= usb_control_msg(dev
, pipe
, request
, requesttype
,
95 value
, index
, buf
, size
, timeout
);
97 memcpy(data
, buf
, size
);
103 unsigned char snd_usb_parse_datainterval(struct snd_usb_audio
*chip
,
104 struct usb_host_interface
*alts
)
106 if (snd_usb_get_speed(chip
->dev
) == USB_SPEED_HIGH
&&
107 get_endpoint(alts
, 0)->bInterval
>= 1 &&
108 get_endpoint(alts
, 0)->bInterval
<= 4)
109 return get_endpoint(alts
, 0)->bInterval
- 1;