1 // SPDX-License-Identifier: GPL-2.0-or-later
5 #include <linux/init.h>
6 #include <linux/slab.h>
14 * combine bytes and get an integer value
16 unsigned int snd_usb_combine_bytes(unsigned char *bytes, int size)
19 case 1: return *bytes;
20 case 2: return combine_word(bytes);
21 case 3: return combine_triple(bytes);
22 case 4: return combine_quad(bytes);
28 * parse descriptor buffer and return the pointer starting the given
31 void *snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype)
43 if (p[1] == dtype && (!after || (void *)p > after)) {
52 * find a class-specified interface descriptor with the given subtype.
54 void *snd_usb_find_csint_desc(void *buffer, int buflen, void *after, u8 dsubtype)
56 unsigned char *p = after;
58 while ((p = snd_usb_find_desc(buffer, buflen, p,
59 USB_DT_CS_INTERFACE)) != NULL) {
60 if (p[0] >= 3 && p[2] == dsubtype)
67 * Wrapper for usb_control_msg().
68 * Allocates a temp buffer to prevent dmaing from/to the stack.
70 int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
71 __u8 requesttype, __u16 value, __u16 index, void *data,
78 if (usb_pipe_type_check(dev, pipe))
82 buf = kmemdup(data, size, GFP_KERNEL);
87 if (requesttype & USB_DIR_IN)
88 timeout = USB_CTRL_GET_TIMEOUT;
90 timeout = USB_CTRL_SET_TIMEOUT;
92 err = usb_control_msg(dev, pipe, request, requesttype,
93 value, index, buf, size, timeout);
96 memcpy(data, buf, size);
100 snd_usb_ctl_msg_quirk(dev, pipe, request, requesttype,
101 value, index, data, size);
106 unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip,
107 struct usb_host_interface *alts)
109 switch (snd_usb_get_speed(chip->dev)) {
111 case USB_SPEED_SUPER:
112 case USB_SPEED_SUPER_PLUS:
113 if (get_endpoint(alts, 0)->bInterval >= 1 &&
114 get_endpoint(alts, 0)->bInterval <= 4)
115 return get_endpoint(alts, 0)->bInterval - 1;
123 struct usb_host_interface *
124 snd_usb_get_host_interface(struct snd_usb_audio *chip, int ifnum, int altsetting)
126 struct usb_interface *iface;
128 iface = usb_ifnum_to_if(chip->dev, ifnum);
131 return usb_altnum_to_altsetting(iface, altsetting);