aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>2012-09-06 14:11:17 -0400
committerFelipe Balbi <balbi@ti.com>2012-09-10 09:11:31 -0400
commit5a175bb84d7344fbe5e26cf61b597129e7c80564 (patch)
tree67e016b9c2ab90f5b3f12dff99faea6b8cfbded9 /drivers/usb/gadget
parente1f15ccbae40b55a4e2591373ea5f1808cf29855 (diff)
usb: gadget: make g_printer enumerate again
This was broken in 2e87edf49 ("usb: gadget: make g_printer use composite"). The USB-strings were not setup properly and were not used. No function was added which results in an empty USB config. While fixing this, the interface number is now auto generated and not hard coded to 0. Cc: stable@vger.kernel.org # v3.5 Acked-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/printer.c128
1 files changed, 65 insertions, 63 deletions
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index 3d3d20d258f6..51b6e7bf413e 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -138,18 +138,14 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR);
138 * descriptors are built on demand. 138 * descriptors are built on demand.
139 */ 139 */
140 140
141#define STRING_MANUFACTURER 1 141#define STRING_MANUFACTURER 0
142#define STRING_PRODUCT 2 142#define STRING_PRODUCT 1
143#define STRING_SERIALNUM 3 143#define STRING_SERIALNUM 2
144 144
145/* holds our biggest descriptor */ 145/* holds our biggest descriptor */
146#define USB_DESC_BUFSIZE 256 146#define USB_DESC_BUFSIZE 256
147#define USB_BUFSIZE 8192 147#define USB_BUFSIZE 8192
148 148
149/* This device advertises one configuration. */
150#define DEV_CONFIG_VALUE 1
151#define PRINTER_INTERFACE 0
152
153static struct usb_device_descriptor device_desc = { 149static struct usb_device_descriptor device_desc = {
154 .bLength = sizeof device_desc, 150 .bLength = sizeof device_desc,
155 .bDescriptorType = USB_DT_DEVICE, 151 .bDescriptorType = USB_DT_DEVICE,
@@ -159,16 +155,12 @@ static struct usb_device_descriptor device_desc = {
159 .bDeviceProtocol = 0, 155 .bDeviceProtocol = 0,
160 .idVendor = cpu_to_le16(PRINTER_VENDOR_NUM), 156 .idVendor = cpu_to_le16(PRINTER_VENDOR_NUM),
161 .idProduct = cpu_to_le16(PRINTER_PRODUCT_NUM), 157 .idProduct = cpu_to_le16(PRINTER_PRODUCT_NUM),
162 .iManufacturer = STRING_MANUFACTURER,
163 .iProduct = STRING_PRODUCT,
164 .iSerialNumber = STRING_SERIALNUM,
165 .bNumConfigurations = 1 158 .bNumConfigurations = 1
166}; 159};
167 160
168static struct usb_interface_descriptor intf_desc = { 161static struct usb_interface_descriptor intf_desc = {
169 .bLength = sizeof intf_desc, 162 .bLength = sizeof intf_desc,
170 .bDescriptorType = USB_DT_INTERFACE, 163 .bDescriptorType = USB_DT_INTERFACE,
171 .bInterfaceNumber = PRINTER_INTERFACE,
172 .bNumEndpoints = 2, 164 .bNumEndpoints = 2,
173 .bInterfaceClass = USB_CLASS_PRINTER, 165 .bInterfaceClass = USB_CLASS_PRINTER,
174 .bInterfaceSubClass = 1, /* Printer Sub-Class */ 166 .bInterfaceSubClass = 1, /* Printer Sub-Class */
@@ -257,9 +249,9 @@ static char pnp_string [1024] =
257 249
258/* static strings, in UTF-8 */ 250/* static strings, in UTF-8 */
259static struct usb_string strings [] = { 251static struct usb_string strings [] = {
260 { STRING_MANUFACTURER, manufacturer, }, 252 [STRING_MANUFACTURER].s = manufacturer,
261 { STRING_PRODUCT, product_desc, }, 253 [STRING_PRODUCT].s = product_desc,
262 { STRING_SERIALNUM, serial_num, }, 254 [STRING_SERIALNUM].s = serial_num,
263 { } /* end of list */ 255 { } /* end of list */
264}; 256};
265 257
@@ -868,25 +860,13 @@ static int set_interface(struct printer_dev *dev, unsigned number)
868 int result = 0; 860 int result = 0;
869 861
870 /* Free the current interface */ 862 /* Free the current interface */
871 switch (dev->interface) { 863 printer_reset_interface(dev);
872 case PRINTER_INTERFACE:
873 printer_reset_interface(dev);
874 break;
875 }
876 864
877 switch (number) { 865 result = set_printer_interface(dev);
878 case PRINTER_INTERFACE: 866 if (result)
879 result = set_printer_interface(dev); 867 printer_reset_interface(dev);
880 if (result) { 868 else
881 printer_reset_interface(dev); 869 dev->interface = number;
882 } else {
883 dev->interface = PRINTER_INTERFACE;
884 }
885 break;
886 default:
887 result = -EINVAL;
888 /* FALL THROUGH */
889 }
890 870
891 if (!result) 871 if (!result)
892 INFO(dev, "Using interface %x\n", number); 872 INFO(dev, "Using interface %x\n", number);
@@ -969,7 +949,7 @@ static int printer_func_setup(struct usb_function *f,
969 switch (ctrl->bRequest) { 949 switch (ctrl->bRequest) {
970 case 0: /* Get the IEEE-1284 PNP String */ 950 case 0: /* Get the IEEE-1284 PNP String */
971 /* Only one printer interface is supported. */ 951 /* Only one printer interface is supported. */
972 if ((wIndex>>8) != PRINTER_INTERFACE) 952 if ((wIndex>>8) != dev->interface)
973 break; 953 break;
974 954
975 value = (pnp_string[0]<<8)|pnp_string[1]; 955 value = (pnp_string[0]<<8)|pnp_string[1];
@@ -980,7 +960,7 @@ static int printer_func_setup(struct usb_function *f,
980 960
981 case 1: /* Get Port Status */ 961 case 1: /* Get Port Status */
982 /* Only one printer interface is supported. */ 962 /* Only one printer interface is supported. */
983 if (wIndex != PRINTER_INTERFACE) 963 if (wIndex != dev->interface)
984 break; 964 break;
985 965
986 *(u8 *)req->buf = dev->printer_status; 966 *(u8 *)req->buf = dev->printer_status;
@@ -989,7 +969,7 @@ static int printer_func_setup(struct usb_function *f,
989 969
990 case 2: /* Soft Reset */ 970 case 2: /* Soft Reset */
991 /* Only one printer interface is supported. */ 971 /* Only one printer interface is supported. */
992 if (wIndex != PRINTER_INTERFACE) 972 if (wIndex != dev->interface)
993 break; 973 break;
994 974
995 printer_soft_reset(dev); 975 printer_soft_reset(dev);
@@ -1017,6 +997,37 @@ unknown:
1017static int __init printer_func_bind(struct usb_configuration *c, 997static int __init printer_func_bind(struct usb_configuration *c,
1018 struct usb_function *f) 998 struct usb_function *f)
1019{ 999{
1000 struct printer_dev *dev = container_of(f, struct printer_dev, function);
1001 struct usb_composite_dev *cdev = c->cdev;
1002 struct usb_ep *in_ep, *out_ep;
1003 int id;
1004
1005 id = usb_interface_id(c, f);
1006 if (id < 0)
1007 return id;
1008 intf_desc.bInterfaceNumber = id;
1009
1010 /* all we really need is bulk IN/OUT */
1011 in_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_in_desc);
1012 if (!in_ep) {
1013autoconf_fail:
1014 dev_err(&cdev->gadget->dev, "can't autoconfigure on %s\n",
1015 cdev->gadget->name);
1016 return -ENODEV;
1017 }
1018 in_ep->driver_data = in_ep; /* claim */
1019
1020 out_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_out_desc);
1021 if (!out_ep)
1022 goto autoconf_fail;
1023 out_ep->driver_data = out_ep; /* claim */
1024
1025 /* assumes that all endpoints are dual-speed */
1026 hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
1027 hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
1028
1029 dev->in_ep = in_ep;
1030 dev->out_ep = out_ep;
1020 return 0; 1031 return 0;
1021} 1032}
1022 1033
@@ -1032,7 +1043,8 @@ static int printer_func_set_alt(struct usb_function *f,
1032 int ret = -ENOTSUPP; 1043 int ret = -ENOTSUPP;
1033 1044
1034 if (!alt) 1045 if (!alt)
1035 ret = set_interface(dev, PRINTER_INTERFACE); 1046 ret = set_interface(dev, intf);
1047
1036 return ret; 1048 return ret;
1037} 1049}
1038 1050
@@ -1104,13 +1116,14 @@ static int __init printer_bind_config(struct usb_configuration *c)
1104{ 1116{
1105 struct usb_gadget *gadget = c->cdev->gadget; 1117 struct usb_gadget *gadget = c->cdev->gadget;
1106 struct printer_dev *dev; 1118 struct printer_dev *dev;
1107 struct usb_ep *in_ep, *out_ep;
1108 int status = -ENOMEM; 1119 int status = -ENOMEM;
1109 int gcnum; 1120 int gcnum;
1110 size_t len; 1121 size_t len;
1111 u32 i; 1122 u32 i;
1112 struct usb_request *req; 1123 struct usb_request *req;
1113 1124
1125 usb_ep_autoconfig_reset(gadget);
1126
1114 dev = &usb_printer_gadget; 1127 dev = &usb_printer_gadget;
1115 1128
1116 dev->function.name = shortname; 1129 dev->function.name = shortname;
@@ -1122,6 +1135,10 @@ static int __init printer_bind_config(struct usb_configuration *c)
1122 dev->function.set_alt = printer_func_set_alt; 1135 dev->function.set_alt = printer_func_set_alt;
1123 dev->function.disable = printer_func_disable; 1136 dev->function.disable = printer_func_disable;
1124 1137
1138 status = usb_add_function(c, &dev->function);
1139 if (status)
1140 return status;
1141
1125 /* Setup the sysfs files for the printer gadget. */ 1142 /* Setup the sysfs files for the printer gadget. */
1126 dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno, 1143 dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno,
1127 NULL, "g_printer"); 1144 NULL, "g_printer");
@@ -1166,26 +1183,6 @@ static int __init printer_bind_config(struct usb_configuration *c)
1166 pnp_string[0] = (len >> 8) & 0xFF; 1183 pnp_string[0] = (len >> 8) & 0xFF;
1167 pnp_string[1] = len & 0xFF; 1184 pnp_string[1] = len & 0xFF;
1168 1185
1169 /* all we really need is bulk IN/OUT */
1170 usb_ep_autoconfig_reset(gadget);
1171 in_ep = usb_ep_autoconfig(gadget, &fs_ep_in_desc);
1172 if (!in_ep) {
1173autoconf_fail:
1174 dev_err(&gadget->dev, "can't autoconfigure on %s\n",
1175 gadget->name);
1176 return -ENODEV;
1177 }
1178 in_ep->driver_data = in_ep; /* claim */
1179
1180 out_ep = usb_ep_autoconfig(gadget, &fs_ep_out_desc);
1181 if (!out_ep)
1182 goto autoconf_fail;
1183 out_ep->driver_data = out_ep; /* claim */
1184
1185 /* assumes that all endpoints are dual-speed */
1186 hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
1187 hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
1188
1189 usb_gadget_set_selfpowered(gadget); 1186 usb_gadget_set_selfpowered(gadget);
1190 1187
1191 if (gadget->is_otg) { 1188 if (gadget->is_otg) {
@@ -1212,9 +1209,6 @@ autoconf_fail:
1212 dev->current_rx_bytes = 0; 1209 dev->current_rx_bytes = 0;
1213 dev->current_rx_buf = NULL; 1210 dev->current_rx_buf = NULL;
1214 1211
1215 dev->in_ep = in_ep;
1216 dev->out_ep = out_ep;
1217
1218 for (i = 0; i < QLEN; i++) { 1212 for (i = 0; i < QLEN; i++) {
1219 req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL); 1213 req = printer_req_alloc(dev->in_ep, USB_BUFSIZE, GFP_KERNEL);
1220 if (!req) { 1214 if (!req) {
@@ -1247,8 +1241,6 @@ autoconf_fail:
1247 dev->gadget = gadget; 1241 dev->gadget = gadget;
1248 1242
1249 INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc); 1243 INFO(dev, "%s, version: " DRIVER_VERSION "\n", driver_desc);
1250 INFO(dev, "using %s, OUT %s IN %s\n", gadget->name, out_ep->name,
1251 in_ep->name);
1252 return 0; 1244 return 0;
1253 1245
1254fail: 1246fail:
@@ -1263,7 +1255,17 @@ static int printer_unbind(struct usb_composite_dev *cdev)
1263 1255
1264static int __init printer_bind(struct usb_composite_dev *cdev) 1256static int __init printer_bind(struct usb_composite_dev *cdev)
1265{ 1257{
1266 return usb_add_config(cdev, &printer_cfg_driver, printer_bind_config); 1258 int ret;
1259
1260 ret = usb_string_ids_tab(cdev, strings);
1261 if (ret < 0)
1262 return ret;
1263 device_desc.iManufacturer = strings[STRING_MANUFACTURER].id;
1264 device_desc.iProduct = strings[STRING_PRODUCT].id;
1265 device_desc.iSerialNumber = strings[STRING_SERIALNUM].id;
1266
1267 ret = usb_add_config(cdev, &printer_cfg_driver, printer_bind_config);
1268 return ret;
1267} 1269}
1268 1270
1269static __refdata struct usb_composite_driver printer_driver = { 1271static __refdata struct usb_composite_driver printer_driver = {