aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/composite.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/composite.c')
-rw-r--r--drivers/usb/gadget/composite.c238
1 files changed, 177 insertions, 61 deletions
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 1160c55de7f2..5cbb1a41c223 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -24,6 +24,7 @@
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/utsname.h>
27 28
28#include <linux/usb/composite.h> 29#include <linux/usb/composite.h>
29 30
@@ -39,8 +40,9 @@
39#define USB_BUFSIZ 1024 40#define USB_BUFSIZ 1024
40 41
41static struct usb_composite_driver *composite; 42static struct usb_composite_driver *composite;
43static int (*composite_gadget_bind)(struct usb_composite_dev *cdev);
42 44
43/* Some systems will need runtime overrides for the product identifers 45/* Some systems will need runtime overrides for the product identifiers
44 * published in the device descriptor, either numbers or strings or both. 46 * published in the device descriptor, either numbers or strings or both.
45 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters). 47 * String parameters are in UTF-8 (superset of ASCII's 7 bit characters).
46 */ 48 */
@@ -69,6 +71,8 @@ static char *iSerialNumber;
69module_param(iSerialNumber, charp, 0); 71module_param(iSerialNumber, charp, 0);
70MODULE_PARM_DESC(iSerialNumber, "SerialNumber string"); 72MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");
71 73
74static char composite_manufacturer[50];
75
72/*-------------------------------------------------------------------------*/ 76/*-------------------------------------------------------------------------*/
73 77
74/** 78/**
@@ -201,14 +205,14 @@ int usb_function_activate(struct usb_function *function)
201 * usb_interface_id() is called from usb_function.bind() callbacks to 205 * usb_interface_id() is called from usb_function.bind() callbacks to
202 * allocate new interface IDs. The function driver will then store that 206 * allocate new interface IDs. The function driver will then store that
203 * ID in interface, association, CDC union, and other descriptors. It 207 * ID in interface, association, CDC union, and other descriptors. It
204 * will also handle any control requests targetted at that interface, 208 * will also handle any control requests targeted at that interface,
205 * particularly changing its altsetting via set_alt(). There may 209 * particularly changing its altsetting via set_alt(). There may
206 * also be class-specific or vendor-specific requests to handle. 210 * also be class-specific or vendor-specific requests to handle.
207 * 211 *
208 * All interface identifier should be allocated using this routine, to 212 * All interface identifier should be allocated using this routine, to
209 * ensure that for example different functions don't wrongly assign 213 * ensure that for example different functions don't wrongly assign
210 * different meanings to the same identifier. Note that since interface 214 * different meanings to the same identifier. Note that since interface
211 * identifers are configuration-specific, functions used in more than 215 * identifiers are configuration-specific, functions used in more than
212 * one configuration (or more than once in a given configuration) need 216 * one configuration (or more than once in a given configuration) need
213 * multiple versions of the relevant descriptors. 217 * multiple versions of the relevant descriptors.
214 * 218 *
@@ -457,12 +461,23 @@ static int set_config(struct usb_composite_dev *cdev,
457 reset_config(cdev); 461 reset_config(cdev);
458 goto done; 462 goto done;
459 } 463 }
464
465 if (result == USB_GADGET_DELAYED_STATUS) {
466 DBG(cdev,
467 "%s: interface %d (%s) requested delayed status\n",
468 __func__, tmp, f->name);
469 cdev->delayed_status++;
470 DBG(cdev, "delayed_status count %d\n",
471 cdev->delayed_status);
472 }
460 } 473 }
461 474
462 /* when we return, be sure our power usage is valid */ 475 /* when we return, be sure our power usage is valid */
463 power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW; 476 power = c->bMaxPower ? (2 * c->bMaxPower) : CONFIG_USB_GADGET_VBUS_DRAW;
464done: 477done:
465 usb_gadget_vbus_draw(gadget, power); 478 usb_gadget_vbus_draw(gadget, power);
479 if (result >= 0 && cdev->delayed_status)
480 result = USB_GADGET_DELAYED_STATUS;
466 return result; 481 return result;
467} 482}
468 483
@@ -470,18 +485,20 @@ done:
470 * usb_add_config() - add a configuration to a device. 485 * usb_add_config() - add a configuration to a device.
471 * @cdev: wraps the USB gadget 486 * @cdev: wraps the USB gadget
472 * @config: the configuration, with bConfigurationValue assigned 487 * @config: the configuration, with bConfigurationValue assigned
488 * @bind: the configuration's bind function
473 * Context: single threaded during gadget setup 489 * Context: single threaded during gadget setup
474 * 490 *
475 * One of the main tasks of a composite driver's bind() routine is to 491 * One of the main tasks of a composite @bind() routine is to
476 * add each of the configurations it supports, using this routine. 492 * add each of the configurations it supports, using this routine.
477 * 493 *
478 * This function returns the value of the configuration's bind(), which 494 * This function returns the value of the configuration's @bind(), which
479 * is zero for success else a negative errno value. Binding configurations 495 * is zero for success else a negative errno value. Binding configurations
480 * assigns global resources including string IDs, and per-configuration 496 * assigns global resources including string IDs, and per-configuration
481 * resources such as interface IDs and endpoints. 497 * resources such as interface IDs and endpoints.
482 */ 498 */
483int usb_add_config(struct usb_composite_dev *cdev, 499int usb_add_config(struct usb_composite_dev *cdev,
484 struct usb_configuration *config) 500 struct usb_configuration *config,
501 int (*bind)(struct usb_configuration *))
485{ 502{
486 int status = -EINVAL; 503 int status = -EINVAL;
487 struct usb_configuration *c; 504 struct usb_configuration *c;
@@ -490,7 +507,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
490 config->bConfigurationValue, 507 config->bConfigurationValue,
491 config->label, config); 508 config->label, config);
492 509
493 if (!config->bConfigurationValue || !config->bind) 510 if (!config->bConfigurationValue || !bind)
494 goto done; 511 goto done;
495 512
496 /* Prevent duplicate configuration identifiers */ 513 /* Prevent duplicate configuration identifiers */
@@ -507,7 +524,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
507 INIT_LIST_HEAD(&config->functions); 524 INIT_LIST_HEAD(&config->functions);
508 config->next_interface_id = 0; 525 config->next_interface_id = 0;
509 526
510 status = config->bind(config); 527 status = bind(config);
511 if (status < 0) { 528 if (status < 0) {
512 list_del(&config->list); 529 list_del(&config->list);
513 config->cdev = NULL; 530 config->cdev = NULL;
@@ -533,7 +550,7 @@ int usb_add_config(struct usb_composite_dev *cdev,
533 } 550 }
534 } 551 }
535 552
536 /* set_alt(), or next config->bind(), sets up 553 /* set_alt(), or next bind(), sets up
537 * ep->driver_data as needed. 554 * ep->driver_data as needed.
538 */ 555 */
539 usb_ep_autoconfig_reset(cdev->gadget); 556 usb_ep_autoconfig_reset(cdev->gadget);
@@ -599,6 +616,7 @@ static int get_string(struct usb_composite_dev *cdev,
599 struct usb_configuration *c; 616 struct usb_configuration *c;
600 struct usb_function *f; 617 struct usb_function *f;
601 int len; 618 int len;
619 const char *str;
602 620
603 /* Yes, not only is USB's I18N support probably more than most 621 /* Yes, not only is USB's I18N support probably more than most
604 * folk will ever care about ... also, it's all supported here. 622 * folk will ever care about ... also, it's all supported here.
@@ -638,9 +656,29 @@ static int get_string(struct usb_composite_dev *cdev,
638 return s->bLength; 656 return s->bLength;
639 } 657 }
640 658
641 /* Otherwise, look up and return a specified string. String IDs 659 /* Otherwise, look up and return a specified string. First
642 * are device-scoped, so we look up each string table we're told 660 * check if the string has not been overridden.
643 * about. These lookups are infrequent; simpler-is-better here. 661 */
662 if (cdev->manufacturer_override == id)
663 str = iManufacturer ?: composite->iManufacturer ?:
664 composite_manufacturer;
665 else if (cdev->product_override == id)
666 str = iProduct ?: composite->iProduct;
667 else if (cdev->serial_override == id)
668 str = iSerialNumber;
669 else
670 str = NULL;
671 if (str) {
672 struct usb_gadget_strings strings = {
673 .language = language,
674 .strings = &(struct usb_string) { 0xff, str }
675 };
676 return usb_gadget_get_string(&strings, 0xff, buf);
677 }
678
679 /* String IDs are device-scoped, so we look up each string
680 * table we're told about. These lookups are infrequent;
681 * simpler-is-better here.
644 */ 682 */
645 if (composite->strings) { 683 if (composite->strings) {
646 len = lookup_string(composite->strings, buf, language, id); 684 len = lookup_string(composite->strings, buf, language, id);
@@ -786,7 +824,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
786 */ 824 */
787 req->zero = 0; 825 req->zero = 0;
788 req->complete = composite_setup_complete; 826 req->complete = composite_setup_complete;
789 req->length = USB_BUFSIZ; 827 req->length = 0;
790 gadget->ep0->driver_data = cdev; 828 gadget->ep0->driver_data = cdev;
791 829
792 switch (ctrl->bRequest) { 830 switch (ctrl->bRequest) {
@@ -860,7 +898,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
860 case USB_REQ_SET_INTERFACE: 898 case USB_REQ_SET_INTERFACE:
861 if (ctrl->bRequestType != USB_RECIP_INTERFACE) 899 if (ctrl->bRequestType != USB_RECIP_INTERFACE)
862 goto unknown; 900 goto unknown;
863 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) 901 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
864 break; 902 break;
865 f = cdev->config->interface[intf]; 903 f = cdev->config->interface[intf];
866 if (!f) 904 if (!f)
@@ -868,11 +906,19 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
868 if (w_value && !f->set_alt) 906 if (w_value && !f->set_alt)
869 break; 907 break;
870 value = f->set_alt(f, w_index, w_value); 908 value = f->set_alt(f, w_index, w_value);
909 if (value == USB_GADGET_DELAYED_STATUS) {
910 DBG(cdev,
911 "%s: interface %d (%s) requested delayed status\n",
912 __func__, intf, f->name);
913 cdev->delayed_status++;
914 DBG(cdev, "delayed_status count %d\n",
915 cdev->delayed_status);
916 }
871 break; 917 break;
872 case USB_REQ_GET_INTERFACE: 918 case USB_REQ_GET_INTERFACE:
873 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)) 919 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
874 goto unknown; 920 goto unknown;
875 if (!cdev->config || w_index >= MAX_CONFIG_INTERFACES) 921 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
876 break; 922 break;
877 f = cdev->config->interface[intf]; 923 f = cdev->config->interface[intf];
878 if (!f) 924 if (!f)
@@ -901,6 +947,8 @@ unknown:
901 */ 947 */
902 switch (ctrl->bRequestType & USB_RECIP_MASK) { 948 switch (ctrl->bRequestType & USB_RECIP_MASK) {
903 case USB_RECIP_INTERFACE: 949 case USB_RECIP_INTERFACE:
950 if (!cdev->config || intf >= MAX_CONFIG_INTERFACES)
951 break;
904 f = cdev->config->interface[intf]; 952 f = cdev->config->interface[intf];
905 break; 953 break;
906 954
@@ -929,7 +977,7 @@ unknown:
929 } 977 }
930 978
931 /* respond with data transfer before status phase? */ 979 /* respond with data transfer before status phase? */
932 if (value >= 0) { 980 if (value >= 0 && value != USB_GADGET_DELAYED_STATUS) {
933 req->length = value; 981 req->length = value;
934 req->zero = value < w_length; 982 req->zero = value < w_length;
935 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); 983 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
@@ -938,6 +986,10 @@ unknown:
938 req->status = 0; 986 req->status = 0;
939 composite_setup_complete(gadget->ep0, req); 987 composite_setup_complete(gadget->ep0, req);
940 } 988 }
989 } else if (value == USB_GADGET_DELAYED_STATUS && w_length != 0) {
990 WARN(cdev,
991 "%s: Delayed status not supported for w_length != 0",
992 __func__);
941 } 993 }
942 994
943done: 995done:
@@ -1019,32 +1071,23 @@ composite_unbind(struct usb_gadget *gadget)
1019 kfree(cdev->req->buf); 1071 kfree(cdev->req->buf);
1020 usb_ep_free_request(gadget->ep0, cdev->req); 1072 usb_ep_free_request(gadget->ep0, cdev->req);
1021 } 1073 }
1074 device_remove_file(&gadget->dev, &dev_attr_suspended);
1022 kfree(cdev); 1075 kfree(cdev);
1023 set_gadget_data(gadget, NULL); 1076 set_gadget_data(gadget, NULL);
1024 device_remove_file(&gadget->dev, &dev_attr_suspended);
1025 composite = NULL; 1077 composite = NULL;
1026} 1078}
1027 1079
1028static void 1080static u8 override_id(struct usb_composite_dev *cdev, u8 *desc)
1029string_override_one(struct usb_gadget_strings *tab, u8 id, const char *s)
1030{ 1081{
1031 struct usb_string *str = tab->strings; 1082 if (!*desc) {
1032 1083 int ret = usb_string_id(cdev);
1033 for (str = tab->strings; str->s; str++) { 1084 if (unlikely(ret < 0))
1034 if (str->id == id) { 1085 WARNING(cdev, "failed to override string ID\n");
1035 str->s = s; 1086 else
1036 return; 1087 *desc = ret;
1037 }
1038 } 1088 }
1039}
1040 1089
1041static void 1090 return *desc;
1042string_override(struct usb_gadget_strings **tab, u8 id, const char *s)
1043{
1044 while (*tab) {
1045 string_override_one(*tab, id, s);
1046 tab++;
1047 }
1048} 1091}
1049 1092
1050static int composite_bind(struct usb_gadget *gadget) 1093static int composite_bind(struct usb_gadget *gadget)
@@ -1074,7 +1117,13 @@ static int composite_bind(struct usb_gadget *gadget)
1074 cdev->bufsiz = USB_BUFSIZ; 1117 cdev->bufsiz = USB_BUFSIZ;
1075 cdev->driver = composite; 1118 cdev->driver = composite;
1076 1119
1077 usb_gadget_set_selfpowered(gadget); 1120 /*
1121 * As per USB compliance update, a device that is actively drawing
1122 * more than 100mA from USB must report itself as bus-powered in
1123 * the GetStatus(DEVICE) call.
1124 */
1125 if (CONFIG_USB_GADGET_VBUS_DRAW <= USB_SELF_POWER_VBUS_MAX_DRAW)
1126 usb_gadget_set_selfpowered(gadget);
1078 1127
1079 /* interface and string IDs start at zero via kzalloc. 1128 /* interface and string IDs start at zero via kzalloc.
1080 * we force endpoints to start unassigned; few controller 1129 * we force endpoints to start unassigned; few controller
@@ -1082,38 +1131,53 @@ static int composite_bind(struct usb_gadget *gadget)
1082 */ 1131 */
1083 usb_ep_autoconfig_reset(cdev->gadget); 1132 usb_ep_autoconfig_reset(cdev->gadget);
1084 1133
1085 /* standardized runtime overrides for device ID data */
1086 if (idVendor)
1087 cdev->desc.idVendor = cpu_to_le16(idVendor);
1088 if (idProduct)
1089 cdev->desc.idProduct = cpu_to_le16(idProduct);
1090 if (bcdDevice)
1091 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
1092
1093 /* composite gadget needs to assign strings for whole device (like 1134 /* composite gadget needs to assign strings for whole device (like
1094 * serial number), register function drivers, potentially update 1135 * serial number), register function drivers, potentially update
1095 * power state and consumption, etc 1136 * power state and consumption, etc
1096 */ 1137 */
1097 status = composite->bind(cdev); 1138 status = composite_gadget_bind(cdev);
1098 if (status < 0) 1139 if (status < 0)
1099 goto fail; 1140 goto fail;
1100 1141
1101 cdev->desc = *composite->dev; 1142 cdev->desc = *composite->dev;
1102 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket; 1143 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1103 1144
1104 /* strings can't be assigned before bind() allocates the 1145 /* standardized runtime overrides for device ID data */
1105 * releavnt identifiers 1146 if (idVendor)
1106 */ 1147 cdev->desc.idVendor = cpu_to_le16(idVendor);
1107 if (cdev->desc.iManufacturer && iManufacturer) 1148 if (idProduct)
1108 string_override(composite->strings, 1149 cdev->desc.idProduct = cpu_to_le16(idProduct);
1109 cdev->desc.iManufacturer, iManufacturer); 1150 if (bcdDevice)
1110 if (cdev->desc.iProduct && iProduct) 1151 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
1111 string_override(composite->strings, 1152
1112 cdev->desc.iProduct, iProduct); 1153 /* string overrides */
1113 if (cdev->desc.iSerialNumber && iSerialNumber) 1154 if (iManufacturer || !cdev->desc.iManufacturer) {
1114 string_override(composite->strings, 1155 if (!iManufacturer && !composite->iManufacturer &&
1115 cdev->desc.iSerialNumber, iSerialNumber); 1156 !*composite_manufacturer)
1157 snprintf(composite_manufacturer,
1158 sizeof composite_manufacturer,
1159 "%s %s with %s",
1160 init_utsname()->sysname,
1161 init_utsname()->release,
1162 gadget->name);
1163
1164 cdev->manufacturer_override =
1165 override_id(cdev, &cdev->desc.iManufacturer);
1166 }
1167
1168 if (iProduct || (!cdev->desc.iProduct && composite->iProduct))
1169 cdev->product_override =
1170 override_id(cdev, &cdev->desc.iProduct);
1171
1172 if (iSerialNumber)
1173 cdev->serial_override =
1174 override_id(cdev, &cdev->desc.iSerialNumber);
1116 1175
1176 /* has userspace failed to provide a serial number? */
1177 if (composite->needs_serial && !cdev->desc.iSerialNumber)
1178 WARNING(cdev, "userspace failed to provide iSerialNumber\n");
1179
1180 /* finish up */
1117 status = device_create_file(&gadget->dev, &dev_attr_suspended); 1181 status = device_create_file(&gadget->dev, &dev_attr_suspended);
1118 if (status) 1182 if (status)
1119 goto fail; 1183 goto fail;
@@ -1148,6 +1212,8 @@ composite_suspend(struct usb_gadget *gadget)
1148 composite->suspend(cdev); 1212 composite->suspend(cdev);
1149 1213
1150 cdev->suspended = 1; 1214 cdev->suspended = 1;
1215
1216 usb_gadget_vbus_draw(gadget, 2);
1151} 1217}
1152 1218
1153static void 1219static void
@@ -1155,6 +1221,7 @@ composite_resume(struct usb_gadget *gadget)
1155{ 1221{
1156 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1222 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1157 struct usb_function *f; 1223 struct usb_function *f;
1224 u8 maxpower;
1158 1225
1159 /* REVISIT: should we have config level 1226 /* REVISIT: should we have config level
1160 * suspend/resume callbacks? 1227 * suspend/resume callbacks?
@@ -1167,6 +1234,11 @@ composite_resume(struct usb_gadget *gadget)
1167 if (f->resume) 1234 if (f->resume)
1168 f->resume(f); 1235 f->resume(f);
1169 } 1236 }
1237
1238 maxpower = cdev->config->bMaxPower;
1239
1240 usb_gadget_vbus_draw(gadget, maxpower ?
1241 (2 * maxpower) : CONFIG_USB_GADGET_VBUS_DRAW);
1170 } 1242 }
1171 1243
1172 cdev->suspended = 0; 1244 cdev->suspended = 0;
@@ -1177,7 +1249,6 @@ composite_resume(struct usb_gadget *gadget)
1177static struct usb_gadget_driver composite_driver = { 1249static struct usb_gadget_driver composite_driver = {
1178 .speed = USB_SPEED_HIGH, 1250 .speed = USB_SPEED_HIGH,
1179 1251
1180 .bind = composite_bind,
1181 .unbind = composite_unbind, 1252 .unbind = composite_unbind,
1182 1253
1183 .setup = composite_setup, 1254 .setup = composite_setup,
@@ -1192,8 +1263,12 @@ static struct usb_gadget_driver composite_driver = {
1192}; 1263};
1193 1264
1194/** 1265/**
1195 * usb_composite_register() - register a composite driver 1266 * usb_composite_probe() - register a composite driver
1196 * @driver: the driver to register 1267 * @driver: the driver to register
1268 * @bind: the callback used to allocate resources that are shared across the
1269 * whole device, such as string IDs, and add its configurations using
1270 * @usb_add_config(). This may fail by returning a negative errno
1271 * value; it should return zero on successful initialization.
1197 * Context: single threaded during gadget setup 1272 * Context: single threaded during gadget setup
1198 * 1273 *
1199 * This function is used to register drivers using the composite driver 1274 * This function is used to register drivers using the composite driver
@@ -1206,18 +1281,22 @@ static struct usb_gadget_driver composite_driver = {
1206 * while it was binding. That would usually be done in order to wait for 1281 * while it was binding. That would usually be done in order to wait for
1207 * some userspace participation. 1282 * some userspace participation.
1208 */ 1283 */
1209int usb_composite_register(struct usb_composite_driver *driver) 1284int usb_composite_probe(struct usb_composite_driver *driver,
1285 int (*bind)(struct usb_composite_dev *cdev))
1210{ 1286{
1211 if (!driver || !driver->dev || !driver->bind || composite) 1287 if (!driver || !driver->dev || !bind || composite)
1212 return -EINVAL; 1288 return -EINVAL;
1213 1289
1214 if (!driver->name) 1290 if (!driver->name)
1215 driver->name = "composite"; 1291 driver->name = "composite";
1292 if (!driver->iProduct)
1293 driver->iProduct = driver->name;
1216 composite_driver.function = (char *) driver->name; 1294 composite_driver.function = (char *) driver->name;
1217 composite_driver.driver.name = driver->name; 1295 composite_driver.driver.name = driver->name;
1218 composite = driver; 1296 composite = driver;
1297 composite_gadget_bind = bind;
1219 1298
1220 return usb_gadget_register_driver(&composite_driver); 1299 return usb_gadget_probe_driver(&composite_driver, composite_bind);
1221} 1300}
1222 1301
1223/** 1302/**
@@ -1233,3 +1312,40 @@ void usb_composite_unregister(struct usb_composite_driver *driver)
1233 return; 1312 return;
1234 usb_gadget_unregister_driver(&composite_driver); 1313 usb_gadget_unregister_driver(&composite_driver);
1235} 1314}
1315
1316/**
1317 * usb_composite_setup_continue() - Continue with the control transfer
1318 * @cdev: the composite device who's control transfer was kept waiting
1319 *
1320 * This function must be called by the USB function driver to continue
1321 * with the control transfer's data/status stage in case it had requested to
1322 * delay the data/status stages. A USB function's setup handler (e.g. set_alt())
1323 * can request the composite framework to delay the setup request's data/status
1324 * stages by returning USB_GADGET_DELAYED_STATUS.
1325 */
1326void usb_composite_setup_continue(struct usb_composite_dev *cdev)
1327{
1328 int value;
1329 struct usb_request *req = cdev->req;
1330 unsigned long flags;
1331
1332 DBG(cdev, "%s\n", __func__);
1333 spin_lock_irqsave(&cdev->lock, flags);
1334
1335 if (cdev->delayed_status == 0) {
1336 WARN(cdev, "%s: Unexpected call\n", __func__);
1337
1338 } else if (--cdev->delayed_status == 0) {
1339 DBG(cdev, "%s: Completing delayed status\n", __func__);
1340 req->length = 0;
1341 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
1342 if (value < 0) {
1343 DBG(cdev, "ep_queue --> %d\n", value);
1344 req->status = 0;
1345 composite_setup_complete(cdev->gadget->ep0, req);
1346 }
1347 }
1348
1349 spin_unlock_irqrestore(&cdev->lock, flags);
1350}
1351