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.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 09289bb1e20f..391d169f8d07 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -36,7 +36,7 @@
36 */ 36 */
37 37
38/* big enough to hold our biggest descriptor */ 38/* big enough to hold our biggest descriptor */
39#define USB_BUFSIZ 512 39#define USB_BUFSIZ 1024
40 40
41static struct usb_composite_driver *composite; 41static struct usb_composite_driver *composite;
42 42
@@ -85,7 +85,7 @@ MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");
85 * This function returns the value of the function's bind(), which is 85 * This function returns the value of the function's bind(), which is
86 * zero for success else a negative errno value. 86 * zero for success else a negative errno value.
87 */ 87 */
88int __init usb_add_function(struct usb_configuration *config, 88int usb_add_function(struct usb_configuration *config,
89 struct usb_function *function) 89 struct usb_function *function)
90{ 90{
91 int value = -EINVAL; 91 int value = -EINVAL;
@@ -215,7 +215,7 @@ int usb_function_activate(struct usb_function *function)
215 * Returns the interface ID which was allocated; or -ENODEV if no 215 * Returns the interface ID which was allocated; or -ENODEV if no
216 * more interface IDs can be allocated. 216 * more interface IDs can be allocated.
217 */ 217 */
218int __init usb_interface_id(struct usb_configuration *config, 218int usb_interface_id(struct usb_configuration *config,
219 struct usb_function *function) 219 struct usb_function *function)
220{ 220{
221 unsigned id = config->next_interface_id; 221 unsigned id = config->next_interface_id;
@@ -480,7 +480,7 @@ done:
480 * assigns global resources including string IDs, and per-configuration 480 * assigns global resources including string IDs, and per-configuration
481 * resources such as interface IDs and endpoints. 481 * resources such as interface IDs and endpoints.
482 */ 482 */
483int __init usb_add_config(struct usb_composite_dev *cdev, 483int usb_add_config(struct usb_composite_dev *cdev,
484 struct usb_configuration *config) 484 struct usb_configuration *config)
485{ 485{
486 int status = -EINVAL; 486 int status = -EINVAL;
@@ -677,7 +677,7 @@ static int get_string(struct usb_composite_dev *cdev,
677 * ensure that for example different functions don't wrongly assign 677 * ensure that for example different functions don't wrongly assign
678 * different meanings to the same identifier. 678 * different meanings to the same identifier.
679 */ 679 */
680int __init usb_string_id(struct usb_composite_dev *cdev) 680int usb_string_id(struct usb_composite_dev *cdev)
681{ 681{
682 if (cdev->next_string_id < 254) { 682 if (cdev->next_string_id < 254) {
683 /* string id 0 is reserved */ 683 /* string id 0 is reserved */
@@ -898,7 +898,19 @@ static void composite_disconnect(struct usb_gadget *gadget)
898 898
899/*-------------------------------------------------------------------------*/ 899/*-------------------------------------------------------------------------*/
900 900
901static void /* __init_or_exit */ 901static ssize_t composite_show_suspended(struct device *dev,
902 struct device_attribute *attr,
903 char *buf)
904{
905 struct usb_gadget *gadget = dev_to_usb_gadget(dev);
906 struct usb_composite_dev *cdev = get_gadget_data(gadget);
907
908 return sprintf(buf, "%d\n", cdev->suspended);
909}
910
911static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL);
912
913static void
902composite_unbind(struct usb_gadget *gadget) 914composite_unbind(struct usb_gadget *gadget)
903{ 915{
904 struct usb_composite_dev *cdev = get_gadget_data(gadget); 916 struct usb_composite_dev *cdev = get_gadget_data(gadget);
@@ -944,10 +956,11 @@ composite_unbind(struct usb_gadget *gadget)
944 } 956 }
945 kfree(cdev); 957 kfree(cdev);
946 set_gadget_data(gadget, NULL); 958 set_gadget_data(gadget, NULL);
959 device_remove_file(&gadget->dev, &dev_attr_suspended);
947 composite = NULL; 960 composite = NULL;
948} 961}
949 962
950static void __init 963static void
951string_override_one(struct usb_gadget_strings *tab, u8 id, const char *s) 964string_override_one(struct usb_gadget_strings *tab, u8 id, const char *s)
952{ 965{
953 struct usb_string *str = tab->strings; 966 struct usb_string *str = tab->strings;
@@ -960,7 +973,7 @@ string_override_one(struct usb_gadget_strings *tab, u8 id, const char *s)
960 } 973 }
961} 974}
962 975
963static void __init 976static void
964string_override(struct usb_gadget_strings **tab, u8 id, const char *s) 977string_override(struct usb_gadget_strings **tab, u8 id, const char *s)
965{ 978{
966 while (*tab) { 979 while (*tab) {
@@ -969,7 +982,7 @@ string_override(struct usb_gadget_strings **tab, u8 id, const char *s)
969 } 982 }
970} 983}
971 984
972static int __init composite_bind(struct usb_gadget *gadget) 985static int composite_bind(struct usb_gadget *gadget)
973{ 986{
974 struct usb_composite_dev *cdev; 987 struct usb_composite_dev *cdev;
975 int status = -ENOMEM; 988 int status = -ENOMEM;
@@ -1004,6 +1017,14 @@ static int __init composite_bind(struct usb_gadget *gadget)
1004 */ 1017 */
1005 usb_ep_autoconfig_reset(cdev->gadget); 1018 usb_ep_autoconfig_reset(cdev->gadget);
1006 1019
1020 /* standardized runtime overrides for device ID data */
1021 if (idVendor)
1022 cdev->desc.idVendor = cpu_to_le16(idVendor);
1023 if (idProduct)
1024 cdev->desc.idProduct = cpu_to_le16(idProduct);
1025 if (bcdDevice)
1026 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
1027
1007 /* composite gadget needs to assign strings for whole device (like 1028 /* composite gadget needs to assign strings for whole device (like
1008 * serial number), register function drivers, potentially update 1029 * serial number), register function drivers, potentially update
1009 * power state and consumption, etc 1030 * power state and consumption, etc
@@ -1015,14 +1036,6 @@ static int __init composite_bind(struct usb_gadget *gadget)
1015 cdev->desc = *composite->dev; 1036 cdev->desc = *composite->dev;
1016 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket; 1037 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1017 1038
1018 /* standardized runtime overrides for device ID data */
1019 if (idVendor)
1020 cdev->desc.idVendor = cpu_to_le16(idVendor);
1021 if (idProduct)
1022 cdev->desc.idProduct = cpu_to_le16(idProduct);
1023 if (bcdDevice)
1024 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
1025
1026 /* strings can't be assigned before bind() allocates the 1039 /* strings can't be assigned before bind() allocates the
1027 * releavnt identifiers 1040 * releavnt identifiers
1028 */ 1041 */
@@ -1036,6 +1049,10 @@ static int __init composite_bind(struct usb_gadget *gadget)
1036 string_override(composite->strings, 1049 string_override(composite->strings,
1037 cdev->desc.iSerialNumber, iSerialNumber); 1050 cdev->desc.iSerialNumber, iSerialNumber);
1038 1051
1052 status = device_create_file(&gadget->dev, &dev_attr_suspended);
1053 if (status)
1054 goto fail;
1055
1039 INFO(cdev, "%s ready\n", composite->name); 1056 INFO(cdev, "%s ready\n", composite->name);
1040 return 0; 1057 return 0;
1041 1058
@@ -1064,6 +1081,8 @@ composite_suspend(struct usb_gadget *gadget)
1064 } 1081 }
1065 if (composite->suspend) 1082 if (composite->suspend)
1066 composite->suspend(cdev); 1083 composite->suspend(cdev);
1084
1085 cdev->suspended = 1;
1067} 1086}
1068 1087
1069static void 1088static void
@@ -1084,6 +1103,8 @@ composite_resume(struct usb_gadget *gadget)
1084 f->resume(f); 1103 f->resume(f);
1085 } 1104 }
1086 } 1105 }
1106
1107 cdev->suspended = 0;
1087} 1108}
1088 1109
1089/*-------------------------------------------------------------------------*/ 1110/*-------------------------------------------------------------------------*/
@@ -1092,7 +1113,6 @@ static struct usb_gadget_driver composite_driver = {
1092 .speed = USB_SPEED_HIGH, 1113 .speed = USB_SPEED_HIGH,
1093 1114
1094 .bind = composite_bind, 1115 .bind = composite_bind,
1095 /* .unbind = __exit_p(composite_unbind), */
1096 .unbind = composite_unbind, 1116 .unbind = composite_unbind,
1097 1117
1098 .setup = composite_setup, 1118 .setup = composite_setup,
@@ -1121,7 +1141,7 @@ static struct usb_gadget_driver composite_driver = {
1121 * while it was binding. That would usually be done in order to wait for 1141 * while it was binding. That would usually be done in order to wait for
1122 * some userspace participation. 1142 * some userspace participation.
1123 */ 1143 */
1124int __init usb_composite_register(struct usb_composite_driver *driver) 1144int usb_composite_register(struct usb_composite_driver *driver)
1125{ 1145{
1126 if (!driver || !driver->dev || !driver->bind || composite) 1146 if (!driver || !driver->dev || !driver->bind || composite)
1127 return -EINVAL; 1147 return -EINVAL;
@@ -1142,7 +1162,7 @@ int __init usb_composite_register(struct usb_composite_driver *driver)
1142 * This function is used to unregister drivers using the composite 1162 * This function is used to unregister drivers using the composite
1143 * driver framework. 1163 * driver framework.
1144 */ 1164 */
1145void /* __exit */ usb_composite_unregister(struct usb_composite_driver *driver) 1165void usb_composite_unregister(struct usb_composite_driver *driver)
1146{ 1166{
1147 if (composite != driver) 1167 if (composite != driver)
1148 return; 1168 return;