composite.c (cc2683c318a5bf192b75cd5c343b51009db0cf6c) | composite.c (721e2e91945bc2520d57d795dfe1b502ecec567c) |
---|---|
1/* 2 * composite.c - infrastructure for Composite USB Gadgets 3 * 4 * Copyright (C) 2006-2008 David Brownell 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 140 unchanged lines hidden (view full) --- 149 if (comp_desc->bMaxBurst != 0) 150 ERROR(cdev, "ep0 bMaxBurst must be 0\n"); 151 _ep->maxburst = 1; 152 break; 153 } 154 } 155 return 0; 156} | 1/* 2 * composite.c - infrastructure for Composite USB Gadgets 3 * 4 * Copyright (C) 2006-2008 David Brownell 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 140 unchanged lines hidden (view full) --- 149 if (comp_desc->bMaxBurst != 0) 150 ERROR(cdev, "ep0 bMaxBurst must be 0\n"); 151 _ep->maxburst = 1; 152 break; 153 } 154 } 155 return 0; 156} |
157EXPORT_SYMBOL_GPL(config_ep_by_speed); |
|
157 158/** 159 * usb_add_function() - add a function to a configuration 160 * @config: the configuration 161 * @function: the function being added 162 * Context: single threaded during gadget setup 163 * 164 * After initialization, each configuration must have one or more --- 42 unchanged lines hidden (view full) --- 207 config->superspeed = true; 208 209done: 210 if (value) 211 DBG(config->cdev, "adding '%s'/%p --> %d\n", 212 function->name, function, value); 213 return value; 214} | 158 159/** 160 * usb_add_function() - add a function to a configuration 161 * @config: the configuration 162 * @function: the function being added 163 * Context: single threaded during gadget setup 164 * 165 * After initialization, each configuration must have one or more --- 42 unchanged lines hidden (view full) --- 208 config->superspeed = true; 209 210done: 211 if (value) 212 DBG(config->cdev, "adding '%s'/%p --> %d\n", 213 function->name, function, value); 214 return value; 215} |
216EXPORT_SYMBOL_GPL(usb_add_function); |
|
215 216/** 217 * usb_function_deactivate - prevent function and gadget enumeration 218 * @function: the function that isn't yet ready to respond 219 * 220 * Blocks response of the gadget driver to host enumeration by 221 * preventing the data line pullup from being activated. This is 222 * normally called during @bind() processing to change from the --- 20 unchanged lines hidden (view full) --- 243 if (cdev->deactivations == 0) 244 status = usb_gadget_disconnect(cdev->gadget); 245 if (status == 0) 246 cdev->deactivations++; 247 248 spin_unlock_irqrestore(&cdev->lock, flags); 249 return status; 250} | 217 218/** 219 * usb_function_deactivate - prevent function and gadget enumeration 220 * @function: the function that isn't yet ready to respond 221 * 222 * Blocks response of the gadget driver to host enumeration by 223 * preventing the data line pullup from being activated. This is 224 * normally called during @bind() processing to change from the --- 20 unchanged lines hidden (view full) --- 245 if (cdev->deactivations == 0) 246 status = usb_gadget_disconnect(cdev->gadget); 247 if (status == 0) 248 cdev->deactivations++; 249 250 spin_unlock_irqrestore(&cdev->lock, flags); 251 return status; 252} |
253EXPORT_SYMBOL_GPL(usb_function_deactivate); |
|
251 252/** 253 * usb_function_activate - allow function and gadget enumeration 254 * @function: function on which usb_function_activate() was called 255 * 256 * Reverses effect of usb_function_deactivate(). If no more functions 257 * are delaying their activation, the gadget driver will respond to 258 * host enumeration procedures. --- 14 unchanged lines hidden (view full) --- 273 cdev->deactivations--; 274 if (cdev->deactivations == 0) 275 status = usb_gadget_connect(cdev->gadget); 276 } 277 278 spin_unlock_irqrestore(&cdev->lock, flags); 279 return status; 280} | 254 255/** 256 * usb_function_activate - allow function and gadget enumeration 257 * @function: function on which usb_function_activate() was called 258 * 259 * Reverses effect of usb_function_deactivate(). If no more functions 260 * are delaying their activation, the gadget driver will respond to 261 * host enumeration procedures. --- 14 unchanged lines hidden (view full) --- 276 cdev->deactivations--; 277 if (cdev->deactivations == 0) 278 status = usb_gadget_connect(cdev->gadget); 279 } 280 281 spin_unlock_irqrestore(&cdev->lock, flags); 282 return status; 283} |
284EXPORT_SYMBOL_GPL(usb_function_activate); |
|
281 282/** 283 * usb_interface_id() - allocate an unused interface ID 284 * @config: configuration associated with the interface 285 * @function: function handling the interface 286 * Context: single threaded during gadget setup 287 * 288 * usb_interface_id() is called from usb_function.bind() callbacks to --- 20 unchanged lines hidden (view full) --- 309 310 if (id < MAX_CONFIG_INTERFACES) { 311 config->interface[id] = function; 312 config->next_interface_id = id + 1; 313 return id; 314 } 315 return -ENODEV; 316} | 285 286/** 287 * usb_interface_id() - allocate an unused interface ID 288 * @config: configuration associated with the interface 289 * @function: function handling the interface 290 * Context: single threaded during gadget setup 291 * 292 * usb_interface_id() is called from usb_function.bind() callbacks to --- 20 unchanged lines hidden (view full) --- 313 314 if (id < MAX_CONFIG_INTERFACES) { 315 config->interface[id] = function; 316 config->next_interface_id = id + 1; 317 return id; 318 } 319 return -ENODEV; 320} |
321EXPORT_SYMBOL_GPL(usb_interface_id); |
|
317 318static int config_buf(struct usb_configuration *config, 319 enum usb_device_speed speed, void *buf, u8 type) 320{ 321 struct usb_config_descriptor *c = buf; 322 void *next = buf + USB_DT_CONFIG_SIZE; 323 int len; 324 struct usb_function *f; --- 424 unchanged lines hidden (view full) --- 749 usb_ep_autoconfig_reset(cdev->gadget); 750 751done: 752 if (status) 753 DBG(cdev, "added config '%s'/%u --> %d\n", config->label, 754 config->bConfigurationValue, status); 755 return status; 756} | 322 323static int config_buf(struct usb_configuration *config, 324 enum usb_device_speed speed, void *buf, u8 type) 325{ 326 struct usb_config_descriptor *c = buf; 327 void *next = buf + USB_DT_CONFIG_SIZE; 328 int len; 329 struct usb_function *f; --- 424 unchanged lines hidden (view full) --- 754 usb_ep_autoconfig_reset(cdev->gadget); 755 756done: 757 if (status) 758 DBG(cdev, "added config '%s'/%u --> %d\n", config->label, 759 config->bConfigurationValue, status); 760 return status; 761} |
762EXPORT_SYMBOL_GPL(usb_add_config); |
|
757 758static void remove_config(struct usb_composite_dev *cdev, 759 struct usb_configuration *config) 760{ 761 while (!list_empty(&config->functions)) { 762 struct usb_function *f; 763 764 f = list_first_entry(&config->functions, --- 177 unchanged lines hidden (view full) --- 942 /* string id 0 is reserved by USB spec for list of 943 * supported languages */ 944 /* 255 reserved as well? -- mina86 */ 945 cdev->next_string_id++; 946 return cdev->next_string_id; 947 } 948 return -ENODEV; 949} | 763 764static void remove_config(struct usb_composite_dev *cdev, 765 struct usb_configuration *config) 766{ 767 while (!list_empty(&config->functions)) { 768 struct usb_function *f; 769 770 f = list_first_entry(&config->functions, --- 177 unchanged lines hidden (view full) --- 948 /* string id 0 is reserved by USB spec for list of 949 * supported languages */ 950 /* 255 reserved as well? -- mina86 */ 951 cdev->next_string_id++; 952 return cdev->next_string_id; 953 } 954 return -ENODEV; 955} |
956EXPORT_SYMBOL_GPL(usb_string_id); |
|
950 951/** 952 * usb_string_ids() - allocate unused string IDs in batch 953 * @cdev: the device whose string descriptor IDs are being allocated 954 * @str: an array of usb_string objects to assign numbers to 955 * Context: single threaded during gadget setup 956 * 957 * @usb_string_ids() is called from bind() callbacks to allocate --- 15 unchanged lines hidden (view full) --- 973 return -ENODEV; 974 str->id = ++next; 975 } 976 977 cdev->next_string_id = next; 978 979 return 0; 980} | 957 958/** 959 * usb_string_ids() - allocate unused string IDs in batch 960 * @cdev: the device whose string descriptor IDs are being allocated 961 * @str: an array of usb_string objects to assign numbers to 962 * Context: single threaded during gadget setup 963 * 964 * @usb_string_ids() is called from bind() callbacks to allocate --- 15 unchanged lines hidden (view full) --- 980 return -ENODEV; 981 str->id = ++next; 982 } 983 984 cdev->next_string_id = next; 985 986 return 0; 987} |
988EXPORT_SYMBOL_GPL(usb_string_ids_tab); |
|
981 982/** 983 * usb_string_ids_n() - allocate unused string IDs in batch 984 * @c: the device whose string descriptor IDs are being allocated 985 * @n: number of string IDs to allocate 986 * Context: single threaded during gadget setup 987 * 988 * Returns the first requested ID. This ID and next @n-1 IDs are now --- 12 unchanged lines hidden (view full) --- 1001int usb_string_ids_n(struct usb_composite_dev *c, unsigned n) 1002{ 1003 unsigned next = c->next_string_id; 1004 if (unlikely(n > 254 || (unsigned)next + n > 254)) 1005 return -ENODEV; 1006 c->next_string_id += n; 1007 return next + 1; 1008} | 989 990/** 991 * usb_string_ids_n() - allocate unused string IDs in batch 992 * @c: the device whose string descriptor IDs are being allocated 993 * @n: number of string IDs to allocate 994 * Context: single threaded during gadget setup 995 * 996 * Returns the first requested ID. This ID and next @n-1 IDs are now --- 12 unchanged lines hidden (view full) --- 1009int usb_string_ids_n(struct usb_composite_dev *c, unsigned n) 1010{ 1011 unsigned next = c->next_string_id; 1012 if (unlikely(n > 254 || (unsigned)next + n > 254)) 1013 return -ENODEV; 1014 c->next_string_id += n; 1015 return next + 1; 1016} |
1017EXPORT_SYMBOL_GPL(usb_string_ids_n); |
|
1009 | 1018 |
1010 | |
1011/*-------------------------------------------------------------------------*/ 1012 1013static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req) 1014{ 1015 if (req->status || req->actual != req->length) 1016 DBG((struct usb_composite_dev *) ep->driver_data, 1017 "setup complete --> %d, %d/%d\n", 1018 req->status, req->actual, req->length); --- 548 unchanged lines hidden (view full) --- 1567 gadget_driver = &driver->gadget_driver; 1568 1569 gadget_driver->function = (char *) driver->name; 1570 gadget_driver->driver.name = driver->name; 1571 gadget_driver->max_speed = driver->max_speed; 1572 1573 return usb_gadget_probe_driver(gadget_driver); 1574} | 1019/*-------------------------------------------------------------------------*/ 1020 1021static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req) 1022{ 1023 if (req->status || req->actual != req->length) 1024 DBG((struct usb_composite_dev *) ep->driver_data, 1025 "setup complete --> %d, %d/%d\n", 1026 req->status, req->actual, req->length); --- 548 unchanged lines hidden (view full) --- 1575 gadget_driver = &driver->gadget_driver; 1576 1577 gadget_driver->function = (char *) driver->name; 1578 gadget_driver->driver.name = driver->name; 1579 gadget_driver->max_speed = driver->max_speed; 1580 1581 return usb_gadget_probe_driver(gadget_driver); 1582} |
1583EXPORT_SYMBOL_GPL(usb_composite_probe); |
|
1575 1576/** 1577 * usb_composite_unregister() - unregister a composite driver 1578 * @driver: the driver to unregister 1579 * 1580 * This function is used to unregister drivers using the composite 1581 * driver framework. 1582 */ 1583void usb_composite_unregister(struct usb_composite_driver *driver) 1584{ 1585 usb_gadget_unregister_driver(&driver->gadget_driver); 1586} | 1584 1585/** 1586 * usb_composite_unregister() - unregister a composite driver 1587 * @driver: the driver to unregister 1588 * 1589 * This function is used to unregister drivers using the composite 1590 * driver framework. 1591 */ 1592void usb_composite_unregister(struct usb_composite_driver *driver) 1593{ 1594 usb_gadget_unregister_driver(&driver->gadget_driver); 1595} |
1596EXPORT_SYMBOL_GPL(usb_composite_unregister); |
|
1587 1588/** 1589 * usb_composite_setup_continue() - Continue with the control transfer 1590 * @cdev: the composite device who's control transfer was kept waiting 1591 * 1592 * This function must be called by the USB function driver to continue 1593 * with the control transfer's data/status stage in case it had requested to 1594 * delay the data/status stages. A USB function's setup handler (e.g. set_alt()) --- 20 unchanged lines hidden (view full) --- 1615 DBG(cdev, "ep_queue --> %d\n", value); 1616 req->status = 0; 1617 composite_setup_complete(cdev->gadget->ep0, req); 1618 } 1619 } 1620 1621 spin_unlock_irqrestore(&cdev->lock, flags); 1622} | 1597 1598/** 1599 * usb_composite_setup_continue() - Continue with the control transfer 1600 * @cdev: the composite device who's control transfer was kept waiting 1601 * 1602 * This function must be called by the USB function driver to continue 1603 * with the control transfer's data/status stage in case it had requested to 1604 * delay the data/status stages. A USB function's setup handler (e.g. set_alt()) --- 20 unchanged lines hidden (view full) --- 1625 DBG(cdev, "ep_queue --> %d\n", value); 1626 req->status = 0; 1627 composite_setup_complete(cdev->gadget->ep0, req); 1628 } 1629 } 1630 1631 spin_unlock_irqrestore(&cdev->lock, flags); 1632} |
1633EXPORT_SYMBOL_GPL(usb_composite_setup_continue); |
|
1623 1624static char *composite_default_mfr(struct usb_gadget *gadget) 1625{ 1626 char *mfr; 1627 int len; 1628 1629 len = snprintf(NULL, 0, "%s %s with %s", init_utsname()->sysname, 1630 init_utsname()->release, gadget->name); --- 36 unchanged lines hidden (view full) --- 1667 dev_str[USB_GADGET_MANUFACTURER_IDX].s = cdev->def_manufacturer; 1668 } 1669 1670 if (covr->product) { 1671 desc->iProduct = dev_str[USB_GADGET_PRODUCT_IDX].id; 1672 dev_str[USB_GADGET_PRODUCT_IDX].s = covr->product; 1673 } 1674} | 1634 1635static char *composite_default_mfr(struct usb_gadget *gadget) 1636{ 1637 char *mfr; 1638 int len; 1639 1640 len = snprintf(NULL, 0, "%s %s with %s", init_utsname()->sysname, 1641 init_utsname()->release, gadget->name); --- 36 unchanged lines hidden (view full) --- 1678 dev_str[USB_GADGET_MANUFACTURER_IDX].s = cdev->def_manufacturer; 1679 } 1680 1681 if (covr->product) { 1682 desc->iProduct = dev_str[USB_GADGET_PRODUCT_IDX].id; 1683 dev_str[USB_GADGET_PRODUCT_IDX].s = covr->product; 1684 } 1685} |
1686EXPORT_SYMBOL_GPL(usb_composite_overwrite_options); |
|