Lines Matching +full:hs +full:- +full:usb +full:- +full:if
1 // SPDX-License-Identifier: GPL-2.0+
3 * usb/gadget/config.c -- simplify building config descriptors
16 #include <linux/usb/ch9.h>
17 #include <linux/usb/gadget.h>
18 #include <linux/usb/composite.h>
19 #include <linux/usb/otg.h>
22 * usb_descriptor_fillbuf - fill buffer with descriptors
28 * negative error code if they can't all be copied. Useful when
39 if (!src) in usb_descriptor_fillbuf()
40 return -EINVAL; in usb_descriptor_fillbuf()
44 unsigned len = (*src)->bLength; in usb_descriptor_fillbuf()
46 if (len > buflen) in usb_descriptor_fillbuf()
47 return -EINVAL; in usb_descriptor_fillbuf()
49 buflen -= len; in usb_descriptor_fillbuf()
52 return dest - (u8 *)buf; in usb_descriptor_fillbuf()
57 * usb_gadget_config_buf - builts a complete configuration descriptor
60 * @desc: Null-terminated vector of pointers to the descriptors (interface,
63 * @length: Length of buffer. If this is not big enough to hold the
74 * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
87 if (length < USB_DT_CONFIG_SIZE || !desc) in usb_gadget_config_buf()
88 return -EINVAL; in usb_gadget_config_buf()
93 length - USB_DT_CONFIG_SIZE, desc); in usb_gadget_config_buf()
94 if (len < 0) in usb_gadget_config_buf()
97 if (len > 0xffff) in usb_gadget_config_buf()
98 return -EINVAL; in usb_gadget_config_buf()
101 cp->bLength = USB_DT_CONFIG_SIZE; in usb_gadget_config_buf()
102 cp->bDescriptorType = USB_DT_CONFIG; in usb_gadget_config_buf()
103 cp->wTotalLength = cpu_to_le16(len); in usb_gadget_config_buf()
104 cp->bmAttributes |= USB_CONFIG_ATT_ONE; in usb_gadget_config_buf()
110 * usb_copy_descriptors - copy a vector of USB descriptors
111 * @src: null-terminated vector to copy
114 * This makes a copy of a vector of USB descriptors. Its primary use
132 bytes += (*tmp)->bLength; in usb_copy_descriptors()
136 if (!mem) in usb_copy_descriptors()
147 memcpy(mem, *src, (*src)->bLength); in usb_copy_descriptors()
150 mem += (*src)->bLength; in usb_copy_descriptors()
161 struct usb_descriptor_header **hs, in usb_assign_descriptors() argument
165 struct usb_gadget *g = f->config->cdev->gadget; in usb_assign_descriptors()
167 /* super-speed-plus descriptor falls back to super-speed one, in usb_assign_descriptors()
168 * if such a descriptor was provided, thus avoiding a NULL in usb_assign_descriptors()
169 * pointer dereference if a 5gbps capable gadget is used with in usb_assign_descriptors()
172 if (!ssp) in usb_assign_descriptors()
175 if (fs) { in usb_assign_descriptors()
176 f->fs_descriptors = usb_copy_descriptors(fs); in usb_assign_descriptors()
177 if (!f->fs_descriptors) in usb_assign_descriptors()
180 if (hs && gadget_is_dualspeed(g)) { in usb_assign_descriptors()
181 f->hs_descriptors = usb_copy_descriptors(hs); in usb_assign_descriptors()
182 if (!f->hs_descriptors) in usb_assign_descriptors()
185 if (ss && gadget_is_superspeed(g)) { in usb_assign_descriptors()
186 f->ss_descriptors = usb_copy_descriptors(ss); in usb_assign_descriptors()
187 if (!f->ss_descriptors) in usb_assign_descriptors()
190 if (ssp && gadget_is_superspeed_plus(g)) { in usb_assign_descriptors()
191 f->ssp_descriptors = usb_copy_descriptors(ssp); in usb_assign_descriptors()
192 if (!f->ssp_descriptors) in usb_assign_descriptors()
198 return -ENOMEM; in usb_assign_descriptors()
204 usb_free_descriptors(f->fs_descriptors); in usb_free_all_descriptors()
205 f->fs_descriptors = NULL; in usb_free_all_descriptors()
206 usb_free_descriptors(f->hs_descriptors); in usb_free_all_descriptors()
207 f->hs_descriptors = NULL; in usb_free_all_descriptors()
208 usb_free_descriptors(f->ss_descriptors); in usb_free_all_descriptors()
209 f->ss_descriptors = NULL; in usb_free_all_descriptors()
210 usb_free_descriptors(f->ssp_descriptors); in usb_free_all_descriptors()
211 f->ssp_descriptors = NULL; in usb_free_all_descriptors()
221 if (gadget->otg_caps && (gadget->otg_caps->otg_rev >= 0x0200)) in usb_otg_descriptor_alloc()
236 struct usb_otg_caps *otg_caps = gadget->otg_caps; in usb_otg_descriptor_init()
239 if (!otg_desc) in usb_otg_descriptor_init()
240 return -EINVAL; in usb_otg_descriptor_init()
242 if (otg_caps && otg_caps->otg_rev) { in usb_otg_descriptor_init()
243 if (otg_caps->hnp_support) in usb_otg_descriptor_init()
245 if (otg_caps->srp_support) in usb_otg_descriptor_init()
247 if (otg_caps->adp_support && (otg_caps->otg_rev >= 0x0200)) in usb_otg_descriptor_init()
253 if (otg_caps && (otg_caps->otg_rev >= 0x0200)) { in usb_otg_descriptor_init()
255 otg20_desc->bLength = sizeof(struct usb_otg20_descriptor); in usb_otg_descriptor_init()
256 otg20_desc->bDescriptorType = USB_DT_OTG; in usb_otg_descriptor_init()
257 otg20_desc->bmAttributes = otg_attributes; in usb_otg_descriptor_init()
258 otg20_desc->bcdOTG = cpu_to_le16(otg_caps->otg_rev); in usb_otg_descriptor_init()
261 otg1x_desc->bLength = sizeof(struct usb_otg_descriptor); in usb_otg_descriptor_init()
262 otg1x_desc->bDescriptorType = USB_DT_OTG; in usb_otg_descriptor_init()
263 otg1x_desc->bmAttributes = otg_attributes; in usb_otg_descriptor_init()