10 #include <linux/kernel.h>
11 #include <linux/device.h>
12 #include <linux/module.h>
13 #include <linux/usb/ch9.h>
16 #ifdef CONFIG_USB_G_DBGP_SERIAL
20 #define DRIVER_VENDOR_ID 0x0525
21 #define DRIVER_PRODUCT_ID 0xc0de
23 #define USB_DEBUG_MAX_PACKET_SIZE 8
24 #define DBGP_REQ_EP0_LEN 128
25 #define DBGP_REQ_LEN 512
32 #ifdef CONFIG_USB_G_DBGP_SERIAL
38 .bLength =
sizeof device_desc,
44 .bNumConfigurations = 1,
48 .bLength =
sizeof dbg_desc,
66 #ifdef CONFIG_USB_G_DBGP_PRINTK
67 static int dbgp_consume(
char *
buf,
unsigned len)
82 static void __disable_ep(
struct usb_ep *ep)
90 static void dbgp_disable_ep(
void)
92 __disable_ep(dbgp.i_ep);
93 __disable_ep(dbgp.o_ep);
102 if (ep == dbgp.i_ep) {
125 usb_ep_free_request(dbgp.o_ep, req);
129 "complete: failure (%d:%d) ==> %d\n", stp, err, status);
132 static int dbgp_enable_ep_req(
struct usb_ep *ep)
164 usb_ep_free_request(dbgp.o_ep, req);
167 "enable ep req: failure (%d:%d)\n", stp, err);
175 err = usb_ep_enable(ep);
180 static int dbgp_enable_ep(
void)
184 err = __enable_ep(dbgp.i_ep, &i_desc);
190 err = __enable_ep(dbgp.o_ep, &o_desc);
196 err = dbgp_enable_ep_req(dbgp.o_ep);
205 __disable_ep(dbgp.o_ep);
207 __disable_ep(dbgp.i_ep);
209 dev_dbg(&dbgp.gadget->dev,
"enable ep: failure (%d:%d)\n", stp, err);
214 static void dbgp_disconnect(
struct usb_gadget *gadget)
216 #ifdef CONFIG_USB_G_DBGP_PRINTK
223 static void dbgp_unbind(
struct usb_gadget *gadget)
225 #ifdef CONFIG_USB_G_DBGP_SERIAL
229 kfree(dbgp.req->buf);
230 usb_ep_free_request(gadget->
ep0, dbgp.req);
233 gadget->
ep0->driver_data =
NULL;
248 dbgp.i_ep->driver_data = gadget;
254 dbgp.i_ep->driver_data =
NULL;
259 dbgp.o_ep->driver_data = gadget;
266 #ifdef CONFIG_USB_G_DBGP_SERIAL
267 dbgp.serial->in = dbgp.i_ep;
268 dbgp.serial->out = dbgp.o_ep;
270 dbgp.serial->in->desc = &i_desc;
271 dbgp.serial->out->desc = &o_desc;
281 dbgp.o_ep->driver_data =
NULL;
286 dbgp.i_ep->driver_data =
NULL;
288 dev_dbg(&dbgp.gadget->dev,
"ep config: failure (%d)\n", stp);
297 dbgp.gadget = gadget;
307 if (!dbgp.req->buf) {
314 gadget->
ep0->driver_data = gadget;
316 #ifdef CONFIG_USB_G_DBGP_SERIAL
324 err = dbgp_configure_endpoints(gadget);
330 dev_dbg(&dbgp.gadget->dev,
"bind: success\n");
334 dev_dbg(&gadget->
dev,
"bind: failure (%d:%d)\n", stp, err);
339 static void dbgp_setup_complete(
struct usb_ep *ep,
342 dev_dbg(&dbgp.gadget->dev,
"setup complete: %d, %d/%d\n",
346 static int dbgp_setup(
struct usb_gadget *gadget,
357 gadget->
ep0->driver_data = gadget;
362 dev_dbg(&dbgp.gadget->dev,
"setup: desc device\n");
363 len =
sizeof device_desc;
368 dev_dbg(&dbgp.gadget->dev,
"setup: desc debug\n");
369 len =
sizeof dbg_desc;
378 dev_dbg(&dbgp.gadget->dev,
"setup: feat debug\n");
379 #ifdef CONFIG_USB_G_DBGP_PRINTK
380 err = dbgp_enable_ep();
394 req->
complete = dbgp_setup_complete;
399 "setup: failure req %x v %x\n", request, value);
407 .unbind = dbgp_unbind,
409 .disconnect = dbgp_disconnect,
416 static int __init dbgp_init(
void)
421 static void __exit dbgp_exit(
void)
424 #ifdef CONFIG_USB_G_DBGP_SERIAL