diff mbox

[U-Boot,1/4] usb: gadget: fastboot: add CONFIG_FASTBOOT_NO_GADGET support

Message ID 1421793730-8179-2-git-send-email-srae@broadcom.com
State Rejected
Delegated to: Ɓukasz Majewski
Headers show

Commit Message

Steve Rae Jan. 20, 2015, 10:42 p.m. UTC
Implement fastboot_func_init() which provides a minimalistic setup
of the USB endpoints and requests required by the fastboot gadget.

Signed-off-by: Steve Rae <srae@broadcom.com>
---

 drivers/usb/gadget/f_fastboot.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
diff mbox

Patch

diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 6d3f05b..455f768 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -47,15 +47,18 @@  struct f_fastboot {
 	struct usb_request *in_req, *out_req;
 };
 
+#ifndef CONFIG_FASTBOOT_NO_GADGET
 static inline struct f_fastboot *func_to_fastboot(struct usb_function *f)
 {
 	return container_of(f, struct f_fastboot, usb_function);
 }
+#endif
 
 static struct f_fastboot *fastboot_func;
 static unsigned int download_size;
 static unsigned int download_bytes;
 
+#ifndef CONFIG_FASTBOOT_NO_GADGET
 static struct usb_endpoint_descriptor fs_ep_in = {
 	.bLength            = USB_DT_ENDPOINT_SIZE,
 	.bDescriptorType    = USB_DT_ENDPOINT,
@@ -120,6 +123,7 @@  static struct usb_gadget_strings *fastboot_strings[] = {
 	&stringtab_fastboot,
 	NULL,
 };
+#endif
 
 static void rx_handler_command(struct usb_ep *ep, struct usb_request *req);
 
@@ -131,6 +135,7 @@  static void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
 	printf("status: %d ep '%s' trans: %d\n", status, ep->name, req->actual);
 }
 
+#ifndef CONFIG_FASTBOOT_NO_GADGET
 static int fastboot_bind(struct usb_configuration *c, struct usb_function *f)
 {
 	int id;
@@ -293,6 +298,7 @@  static int fastboot_add(struct usb_configuration *c)
 	return status;
 }
 DECLARE_GADGET_BIND_CALLBACK(usb_dnl_fastboot, fastboot_add);
+#endif
 
 static int fastboot_tx_write(const char *buffer, unsigned int buffer_size)
 {
@@ -576,3 +582,36 @@  static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
 		usb_ep_queue(ep, req, 0);
 	}
 }
+
+#ifdef CONFIG_FASTBOOT_NO_GADGET
+void fastboot_func_init(struct usb_ep *in_ep, struct usb_ep *out_ep,
+			struct usb_request *in_req, struct usb_request *out_req)
+{
+	struct f_fastboot *f_fb = fastboot_func;
+
+	/* see above: fastboot_add() */
+	if (!f_fb) {
+		f_fb = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*f_fb));
+		if (!f_fb) {
+			printf("%s: fatal!\n", __func__);
+			return;
+		}
+
+		fastboot_func = f_fb;
+		memset(f_fb, 0, sizeof(*f_fb));
+	}
+
+	/* initialize IN/OUT EP's and corresponding requests */
+	f_fb->in_ep = in_ep;
+	f_fb->out_ep = out_ep;
+	f_fb->in_req = in_req;
+	f_fb->out_req = out_req;
+
+	/* initialize 'complete' handlers */
+	f_fb->in_req->complete = fastboot_complete;
+	f_fb->out_req->complete = rx_handler_command;
+
+	/* initialize data */
+	f_fb->out_req->length = EP_BUFFER_SIZE;
+}
+#endif