2 * ether.c -- Ethernet gadget driver, with CDC and non-CDC options
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <asm/errno.h>
26 #include <linux/usb/ch9.h>
27 #include <linux/usb/gadget.h>
28 #include <linux/ctype.h>
29 #include <normal_mode.h>
30 #include "gadget_chips.h"
35 #define spin_unlock(x)
38 unsigned packet_received, packet_sent;
40 #define DEV_CONFIG_CDC 1
41 #define GFP_ATOMIC ((gfp_t) 0)
42 #define GFP_KERNEL ((gfp_t) 0)
45 #define DRIVER_DESC "fastboot Gadget"
46 /* Based on linux 2.6.27 version */
47 #define DRIVER_VERSION "May Day 2005"
49 static const char shortname[] = "fastboot";
50 static const char driver_desc[] = DRIVER_DESC;
52 #define RX_EXTRA 20 /* guard against rx overflows */
54 /* CDC support the same host-chosen outgoing packet filters. */
55 #define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
56 |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
57 |USB_CDC_PACKET_TYPE_PROMISCUOUS \
58 |USB_CDC_PACKET_TYPE_DIRECTED)
60 #define USB_CONNECT_TIMEOUT (3 * CONFIG_SYS_HZ)
62 /*-------------------------------------------------------------------------*/
64 struct usb_gadget *gadget;
65 struct usb_request *req; /* for control responses */
66 struct usb_request *stat_req; /* for cdc status */
69 struct usb_ep *in_ep, *out_ep;
70 const struct usb_endpoint_descriptor
73 struct usb_request *tx_req, *rx_req;
76 unsigned network_started:1;
79 static struct fastboot_dev l_fbdev;
80 static struct usb_gadget_driver fastboot_driver;
82 /*-------------------------------------------------------------------------*/
84 #define DEFAULT_QLEN 2 /* double buffering by default */
86 /* peak bulk transfer bits-per-second */
87 #define HS_BPS (13 * 512 * 8 * 1000 * 8)
88 #define FS_BPS (19 * 64 * 1 * 1000 * 8)
90 #ifdef CONFIG_USB_GADGET_DUALSPEED
91 #define DEVSPEED USB_SPEED_HIGH
93 /* for dual-speed hardware, use deeper queues at highspeed */
94 #define qlen(gadget) \
95 (DEFAULT_QLEN*((gadget->speed == USB_SPEED_HIGH) ? qmult : 1))
97 static inline int BITRATE(struct usb_gadget *g)
99 return (g->speed == USB_SPEED_HIGH) ? HS_BPS : FS_BPS;
102 #else /* full speed (low speed doesn't do bulk) */
106 #define DEVSPEED USB_SPEED_FULL
108 #define qlen(gadget) DEFAULT_QLEN
110 static inline int BITRATE(struct usb_gadget *g)
118 * Thanks to NetChip Technologies for donating this product ID.
119 * It's for devices with only CDC Ethernet configurations.
121 #define FASTBOOT_VENDOR_NUM 0x18D1 /* Goolge VID */
122 #define FASTBOOT_PRODUCT_NUM 0x0FFF /* Fastboot Product ID */
123 //#define FASTBOOT_PRODUCT_NUM 0x0C02 /* Linux-USB Ethernet Gadget */
128 * Some systems will want different product identifers published in the
129 * device descriptor, either numbers or strings or both. These string
130 * parameters are in UTF-8 (superset of ASCII's 7 bit characters).
133 static ushort bcdDevice;
135 static char *iManufacturer = "Spreadtrum";
137 static char *iProduct;
138 static char *iSerialNumber = "20080823";
140 /*-------------------------------------------------------------------------*/
143 * USB DRIVER HOOKUP (to the hardware driver, below us), mostly
144 * ep0 implementation: descriptors, config management, setup().
145 * also optional class-specific notification interrupt transfer.
149 * DESCRIPTORS ... most are static, but strings and (full) configuration
150 * descriptors are built on demand. For now we do either full CDC, or
154 #define STRING_MANUFACTURER 1
155 #define STRING_PRODUCT 2
156 #define STRING_ETHADDR 3
157 #define STRING_DATA 4
158 #define STRING_CONTROL 5
160 #define STRING_SUBSET 8
161 #define STRING_SERIALNUMBER 10
163 /* holds our biggest descriptor */
164 #define USB_BUFSIZ 256
167 * This device advertises one configuration, eth_config,
168 * on hardware supporting at least two configs.
170 * FIXME define some higher-powered configurations to make it easier
171 * to recharge batteries ...
174 #define DEV_CONFIG_VALUE 1 /* cdc or subset */
176 static struct usb_device_descriptor
178 .bLength = sizeof device_desc,
179 .bDescriptorType = USB_DT_DEVICE,
181 .bcdUSB = __constant_cpu_to_le16(0x0200),
183 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
184 .bDeviceSubClass = 0,
185 .bDeviceProtocol = 0,
187 .idVendor = __constant_cpu_to_le16(FASTBOOT_VENDOR_NUM),
188 .idProduct = __constant_cpu_to_le16(FASTBOOT_PRODUCT_NUM),
189 .iManufacturer = STRING_MANUFACTURER,
190 .iProduct = STRING_PRODUCT,
191 .bNumConfigurations = 1,
194 static struct usb_config_descriptor
196 .bLength = sizeof fastboot_config,
197 .bDescriptorType = USB_DT_CONFIG,
199 /* compute wTotalLength on the fly */
201 .bConfigurationValue = DEV_CONFIG_VALUE,
202 .iConfiguration = STRING_CDC,
203 .bmAttributes = USB_CONFIG_ATT_ONE,// | USB_CONFIG_ATT_SELFPOWER,
209 /* ... but the "real" data interface has two bulk endpoints */
211 static const struct usb_interface_descriptor
213 .bLength = sizeof data_intf,
214 .bDescriptorType = USB_DT_INTERFACE,
216 .bInterfaceNumber = 0,
217 .bAlternateSetting = 0,
219 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
220 .bInterfaceSubClass = 0x42,
221 .bInterfaceProtocol = 3,
222 .iInterface = STRING_DATA,
226 static struct usb_endpoint_descriptor
228 .bLength = USB_DT_ENDPOINT_SIZE,
229 .bDescriptorType = USB_DT_ENDPOINT,
231 .bEndpointAddress = USB_DIR_IN,
232 .bmAttributes = USB_ENDPOINT_XFER_BULK,
235 static struct usb_endpoint_descriptor
237 .bLength = USB_DT_ENDPOINT_SIZE,
238 .bDescriptorType = USB_DT_ENDPOINT,
240 .bEndpointAddress = USB_DIR_OUT,
241 .bmAttributes = USB_ENDPOINT_XFER_BULK,
244 static const struct usb_descriptor_header *fs_fastboot_function[] = {
245 // (struct usb_descriptor_header *) &otg_descriptor,
246 #ifdef DEV_CONFIG_CDC
247 /* "cdc" mode descriptors */
248 // (struct usb_descriptor_header *) &control_intf,
249 // (struct usb_descriptor_header *) &header_desc,
250 // (struct usb_descriptor_header *) &union_desc,
251 // (struct usb_descriptor_header *) ðer_desc,
252 /* NOTE: status endpoint may need to be removed */
253 // (struct usb_descriptor_header *) &fs_status_desc,
254 /* data interface, with altsetting */
255 (struct usb_descriptor_header *) &data_intf,
256 (struct usb_descriptor_header *) &fs_source_desc,
257 (struct usb_descriptor_header *) &fs_sink_desc,
259 #endif /* DEV_CONFIG_CDC */
264 * usb 2.0 devices need to expose both high speed and full speed
265 * descriptors, unless they only run at full speed.
268 static struct usb_endpoint_descriptor
270 .bLength = USB_DT_ENDPOINT_SIZE,
271 .bDescriptorType = USB_DT_ENDPOINT,
273 .bmAttributes = USB_ENDPOINT_XFER_BULK,
274 .wMaxPacketSize = __constant_cpu_to_le16(512),
277 static struct usb_endpoint_descriptor
279 .bLength = USB_DT_ENDPOINT_SIZE,
280 .bDescriptorType = USB_DT_ENDPOINT,
282 .bmAttributes = USB_ENDPOINT_XFER_BULK,
283 .wMaxPacketSize = __constant_cpu_to_le16(512),
286 static struct usb_qualifier_descriptor
288 .bLength = sizeof dev_qualifier,
289 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
291 .bcdUSB = __constant_cpu_to_le16(0x0200),
292 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
294 .bNumConfigurations = 1,
297 static const struct usb_descriptor_header *hs_fastboot_function[] = {
298 // (struct usb_descriptor_header *) &otg_descriptor,
299 #ifdef DEV_CONFIG_CDC
300 /* "cdc" mode descriptors */
301 // (struct usb_descriptor_header *) &control_intf,
302 // (struct usb_descriptor_header *) &header_desc,
303 // (struct usb_descriptor_header *) &union_desc,
304 // (struct usb_descriptor_header *) ðer_desc,
305 /* NOTE: status endpoint may need to be removed */
306 // (struct usb_descriptor_header *) &hs_status_desc,
307 /* data interface, with altsetting */
308 // (struct usb_descriptor_header *) &data_nop_intf,
309 (struct usb_descriptor_header *) &data_intf,
310 (struct usb_descriptor_header *) &hs_source_desc,
311 (struct usb_descriptor_header *) &hs_sink_desc,
313 #endif /* DEV_CONFIG_CDC */
317 /* maxpacket and other transfer characteristics vary by speed. */
318 static inline struct usb_endpoint_descriptor *
319 ep_choose(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
320 struct usb_endpoint_descriptor *fs)
322 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
327 /*-------------------------------------------------------------------------*/
329 /* descriptors that are built on-demand */
331 static char manufacturer[50];
332 static char product_desc[40] = DRIVER_DESC;
333 static char serial_number[SP09_MAX_SN_LEN];
336 /* static strings, in UTF-8 */
337 static struct usb_string strings[] = {
338 { STRING_MANUFACTURER, manufacturer, },
339 { STRING_PRODUCT, product_desc, },
340 { STRING_SERIALNUMBER, serial_number, },
341 { STRING_DATA, "fastboot Data", },
342 #ifdef DEV_CONFIG_CDC
343 { STRING_CDC, "fastboot Ethernet", },
344 { STRING_CONTROL, "fastboot Communications Control", },
346 { } /* end of list */
349 static struct usb_gadget_strings stringtab = {
350 .language = 0x0409, /* en-us */
354 /*============================================================================*/
355 static u8 control_req[USB_BUFSIZ] __attribute__ ((aligned(4)));
358 * strlcpy - Copy a %NUL terminated string into a sized buffer
359 * @dest: Where to copy the string to
360 * @src: Where to copy the string from
361 * @size: size of destination buffer
363 * Compatible with *BSD: the result is always a valid
364 * NUL-terminated string that fits in the buffer (unless,
365 * of course, the buffer size is zero). It does not pad
366 * out the result like strncpy() does.
368 size_t strlcpy(char *dest, const char *src, size_t size)
370 size_t ret = strlen(src);
373 size_t len = (ret >= size) ? size - 1 : ret;
374 memcpy(dest, src, len);
380 /*============================================================================*/
383 * one config, two interfaces: control, data.
384 * complications: class descriptors, and an altsetting.
387 config_buf(struct usb_gadget *g, u8 *buf, u8 type, unsigned index, int is_otg)
390 const struct usb_config_descriptor *config;
391 const struct usb_descriptor_header **function;
394 if (gadget_is_dualspeed(g)) {
395 hs = (g->speed == USB_SPEED_HIGH);
396 if (type == USB_DT_OTHER_SPEED_CONFIG)
399 #define which_fn(t) (hs ? hs_ ## t ## _function : fs_ ## t ## _function)
401 debug("%s , type :%d, index %d\n", __func__, type, index);
402 if (index >= device_desc.bNumConfigurations)
405 config = &fastboot_config;
406 function = which_fn(fastboot);
408 /* for now, don't advertise srp-only devices */
413 len = usb_gadget_config_buf(config, buf, USB_BUFSIZ, function);
416 ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
420 /*-------------------------------------------------------------------------*/
422 static int alloc_requests(struct fastboot_dev *dev, unsigned n, gfp_t gfp_flags);
425 set_fastboot_config(struct fastboot_dev *dev, gfp_t gfp_flags)
428 struct usb_gadget *gadget = dev->gadget;
431 dev->in = ep_choose(gadget, &hs_source_desc, &fs_source_desc);
432 dev->in_ep->driver_data = dev;
434 dev->out = ep_choose(gadget, &hs_sink_desc, &fs_sink_desc);
435 dev->out_ep->driver_data = dev;
438 result = usb_ep_enable(dev->in_ep, dev->in);
440 debug("enable %s --> %d\n",
441 dev->in_ep->name, result);
445 result = usb_ep_enable(dev->out_ep, dev->out);
447 debug("enable %s --> %d\n",
448 dev->out_ep->name, result);
454 result = alloc_requests(dev, 1, gfp_flags);
456 /* on error, disable any endpoints */
458 (void) usb_ep_disable(dev->in_ep);
459 (void) usb_ep_disable(dev->out_ep);
464 /* caller is responsible for cleanup on error */
468 static void fastboot_reset_config(struct fastboot_dev *dev)
470 if (dev->config == 0)
473 debug("%s\n", __func__);
476 * disable endpoints, forcing (synchronous) completion of
477 * pending i/o. then free the requests.
481 usb_ep_disable(dev->in_ep);
483 usb_ep_free_request(dev->in_ep, dev->tx_req);
488 usb_ep_disable(dev->out_ep);
490 usb_ep_free_request(dev->out_ep, dev->rx_req);
498 * change our operational config. must agree with the code
499 * that returns config descriptors, and altsetting code.
501 static int fastboot_set_config(struct fastboot_dev *dev, unsigned number,
505 struct usb_gadget *gadget = dev->gadget;
507 fastboot_reset_config(dev);
510 case DEV_CONFIG_VALUE:
511 result = set_fastboot_config(dev, gfp_flags);
522 fastboot_reset_config(dev);
523 usb_gadget_vbus_draw(dev->gadget,
524 gadget_is_otg(dev->gadget) ? 8 : 100);
529 power = 2 * fastboot_config.bMaxPower;
530 usb_gadget_vbus_draw(dev->gadget, power);
532 switch (gadget->speed) {
534 speed = "full"; break;
535 #ifdef CONFIG_USB_GADGET_DUALSPEED
537 speed = "high"; break;
543 dev->config = number;
544 debug("%s speed config #%d: %d mA, %s\n",
545 speed, number, power, driver_desc);
551 /*-------------------------------------------------------------------------*/
553 static void fastboot_setup_complete(struct usb_ep *ep, struct usb_request *req)
555 if (req->status || req->actual != req->length)
556 debug("setup complete --> %d, %d/%d\n",
557 req->status, req->actual, req->length);
561 * The setup() callback implements all the ep0 functionality that's not
562 * handled lower down. CDC has a number of less-common features:
564 * - two interfaces: control, and ethernet data
565 * - Ethernet data interface has two altsettings: default, and active
566 * - class-specific descriptors for the control interface
567 * - class-specific control requests
570 fastboot_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
572 struct fastboot_dev *dev = get_gadget_data(gadget);
573 struct usb_request *req = dev->req;
574 int value = -EOPNOTSUPP;
575 u16 wIndex = le16_to_cpu(ctrl->wIndex);
576 u16 wValue = le16_to_cpu(ctrl->wValue);
577 u16 wLength = le16_to_cpu(ctrl->wLength);
580 * descriptors just go into the pre-allocated ep0 buffer,
581 * while config change events may enable network traffic.
584 debug("%s\n", __func__);
586 req->complete = fastboot_setup_complete;
587 switch (ctrl->bRequest) {
589 case USB_REQ_GET_DESCRIPTOR:
590 if (ctrl->bRequestType != USB_DIR_IN)
592 switch (wValue >> 8) {
595 value = min(wLength, (u16) sizeof device_desc);
596 memcpy(req->buf, &device_desc, value);
598 case USB_DT_DEVICE_QUALIFIER:
599 if (!gadget_is_dualspeed(gadget))
601 value = min(wLength, (u16) sizeof dev_qualifier);
602 memcpy(req->buf, &dev_qualifier, value);
605 case USB_DT_OTHER_SPEED_CONFIG:
606 if (!gadget_is_dualspeed(gadget))
610 value = config_buf(gadget, req->buf,
613 gadget_is_otg(gadget));
615 value = min(wLength, (u16) value);
619 value = usb_gadget_get_string(&stringtab,
620 wValue & 0xff, req->buf);
623 value = min(wLength, (u16) value);
629 case USB_REQ_SET_CONFIGURATION:
630 if (ctrl->bRequestType != 0)
632 value = fastboot_set_config(dev, wValue, GFP_ATOMIC);
633 l_fbdev.network_started = 1;
635 case USB_REQ_GET_CONFIGURATION:
636 if (ctrl->bRequestType != USB_DIR_IN)
638 *(u8 *)req->buf = dev->config;
639 value = min(wLength, (u16) 1);
642 case USB_REQ_SET_INTERFACE:
643 if (ctrl->bRequestType != USB_RECIP_INTERFACE
648 * FIXME this is wrong, as is the assumption that
649 * all non-PXA hardware talks real CDC ...
651 debug("set_interface ignored!\n");
656 case USB_REQ_GET_INTERFACE:
657 if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE)
663 /* for CDC, iff carrier is on, data interface is active. */
667 /* *(u8 *)req->buf = netif_carrier_ok (dev->net) ? 1 : 0; */
668 /* carrier always ok ...*/
669 *(u8 *)req->buf = 1 ;
671 value = min(wLength, (u16) 1);
674 debug("unknown control req%02x.%02x v%04x i%04x l%d\n",
675 ctrl->bRequestType, ctrl->bRequest,
676 wValue, wIndex, wLength);
679 /* respond with data transfer before status phase? */
681 debug("respond with data transfer before status phase\n");
683 req->zero = value < wLength
684 && (value % gadget->ep0->maxpacket) == 0;
685 value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
687 debug("ep_queue --> %d\n", value);
689 fastboot_setup_complete(gadget->ep0, req);
693 /* host either stalls (value < 0) or reports success */
697 /*-------------------------------------------------------------------------*/
699 static void rx_complete(struct usb_ep *ep, struct usb_request *req);
701 static int rx_submit(struct fastboot_dev *dev, struct usb_request *req,
704 int retval = -ENOMEM;
708 * Padding up to RX_EXTRA handles minor disagreements with host.
709 * Normally we use the USB "terminate on short read" convention;
710 * so allow up to (N*maxpacket), since that memory is normally
711 * already allocated. Some hardware doesn't deal well with short
712 * reads (e.g. DMA must be N*maxpacket), so for now don't trim a
713 * byte off the end (to force hardware errors on overflow).
716 debug("%s\n", __func__);
718 size = (ETHER_HDR_SIZE + dev->mtu + RX_EXTRA);
719 size += dev->out_ep->maxpacket - 1;
720 size -= size % dev->out_ep->maxpacket;
723 * Some platforms perform better when IP packets are aligned,
724 * but on at least one, checksumming fails otherwise.
727 req->buf = (u8 *) NetRxPackets[0];
729 req->complete = rx_complete;
731 retval = usb_ep_queue(dev->out_ep, req, gfp_flags);
734 error("rx submit --> %d", retval);
739 static void rx_complete(struct usb_ep *ep, struct usb_request *req)
741 struct fastboot_dev *dev = ep->driver_data;
743 debug("%s: status %d\n", __func__, req->status);
749 static int alloc_requests(struct fastboot_dev *dev, unsigned n, gfp_t gfp_flags)
753 dev->tx_req = usb_ep_alloc_request(dev->in_ep, 0);
758 dev->rx_req = usb_ep_alloc_request(dev->out_ep, 0);
766 usb_ep_free_request(dev->in_ep, dev->tx_req);
768 error("can't alloc requests");
774 static void tx_complete(struct usb_ep *ep, struct usb_request *req)
776 debug("%s: status %s\n", __func__, (req->status) ? "failed" : "ok");
780 static void fastboot_unbind(struct usb_gadget *gadget)
782 struct fastboot_dev *dev = get_gadget_data(gadget);
784 debug("%s...\n", __func__);
786 /* we've already been disconnected ... no i/o is active */
788 usb_ep_free_request(gadget->ep0, dev->req);
793 usb_ep_free_request(dev->in_ep, dev->tx_req);
798 usb_ep_free_request(dev->out_ep, dev->rx_req);
802 set_gadget_data(gadget, NULL);
805 static void fastboot_disconnect(struct usb_gadget *gadget)
807 fastboot_reset_config(get_gadget_data(gadget));
810 static void fastboot_suspend(struct usb_gadget *gadget)
815 static void fastboot_resume(struct usb_gadget *gadget)
820 /*-------------------------------------------------------------------------*/
822 static int fastboot_bind(struct usb_gadget *gadget)
824 struct fastboot_dev *dev = &l_fbdev;
826 struct usb_ep *in_ep, *out_ep;
830 debug("%s controller :%s recognized\n", __func__, gadget->name);
831 gcnum = usb_gadget_controller_number(gadget);
833 device_desc.bcdDevice = cpu_to_le16(0x0300 + gcnum);
836 * can't assume CDC works. don't want to default to
837 * anything less functional on CDC-capable hardware,
838 * so we fail in this case.
840 error("controller '%s' not recognized",
846 device_desc.bcdDevice = cpu_to_le16(bcdDevice);
848 strlcpy(manufacturer, iManufacturer, sizeof manufacturer);
850 strlcpy(product_desc, iProduct, sizeof product_desc);
852 iSerialNumber = get_product_sn();
853 device_desc.iSerialNumber = STRING_SERIALNUMBER,
854 strlcpy(serial_number, iSerialNumber, sizeof serial_number);
856 /* all we really need is bulk IN/OUT */
857 usb_ep_autoconfig_reset(gadget);
858 in_ep = usb_ep_autoconfig(gadget, &fs_source_desc);
861 error("can't autoconfigure on %s\n",
865 in_ep->driver_data = in_ep; /* claim */
867 out_ep = usb_ep_autoconfig(gadget, &fs_sink_desc);
870 out_ep->driver_data = out_ep; /* claim */
873 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
874 usb_gadget_set_selfpowered(gadget);
876 if (gadget_is_dualspeed(gadget)) {
878 /* assumes ep0 uses the same value for both speeds ... */
879 dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
881 /* and that all endpoints are dual-speed */
882 hs_source_desc.bEndpointAddress =
883 fs_source_desc.bEndpointAddress;
884 hs_sink_desc.bEndpointAddress =
885 fs_sink_desc.bEndpointAddress;
888 dev->network_started = 0;
890 dev->out_ep = out_ep;
894 /* preallocate control message data and buffer */
895 dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL);
898 dev->req->buf = control_req;
899 dev->req->complete = fastboot_setup_complete;
901 /* ... and maybe likewise for status transfer */
903 /* finish hookup to lower layer ... */
904 dev->gadget = gadget;
905 set_gadget_data(gadget, dev);
906 gadget->ep0->driver_data = dev;
908 debug("bind controller with the driver\n");
910 * two kinds of host-initiated state changes:
911 * - iff DATA transfer is active, carrier is "on"
912 * - tx queueing enabled if open *and* carrier is "on"
917 error("%s failed", __func__);
918 fastboot_unbind(gadget);
922 static int usb_fastboot_start(void)
924 struct fastboot_dev *dev = &l_fbdev;
926 while(!dev->network_started)
927 usb_gadget_handle_interrupts();
930 if (packet_received) {
931 debug("%s: packet received\n", __func__);
933 NetReceive(NetRxPackets[0], dev->rx_req->length);
936 rx_submit(dev, dev->rx_req, 0);
938 error("dev->rx_req invalid");
944 static struct usb_gadget_driver fastboot_driver = {
947 .bind = fastboot_bind,
948 .unbind = fastboot_unbind,
950 .setup = fastboot_setup,
951 .disconnect = fastboot_disconnect,
953 .suspend = fastboot_suspend,
954 .resume = fastboot_resume,
957 #define mdelay(n) udelay((n)*1000)
959 #define BASE_ADDR 0x00000000
960 #define DEFAULT_CMDLINE "mem=128M console=null";
962 #define TAGS_ADDR (BASE_ADDR + 0x00000100)
963 #define KERNEL_ADDR (BASE_ADDR + 0x00800000)
964 #define RAMDISK_ADDR (BASE_ADDR + 0x01000000)
965 //(BASE_ADDR + 0x02000000)
967 extern int fastboot_init(void *base, unsigned size, struct usb_ep * in, struct usb_ep *out);
969 int usb_fastboot_initialize(void)
974 fastboot_register("boot", cmd_boot);
975 fastboot_register("erase:", cmd_erase);
976 fastboot_register("flash:", cmd_flash);
977 fastboot_register("continue", cmd_continue);
978 fastboot_publish("product", "swordfish");
979 fastboot_publish("kernel", "lk");
982 status = usb_gadget_register_driver(&fastboot_driver);
984 usb_fastboot_start();
986 fastboot_init((void*) SCRATCH_ADDR, FB_DOWNLOAD_BUF_SIZE, l_fbdev.in_ep, l_fbdev.out_ep);
995 error("%s failed. error = %d", __func__, status);