]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/usb/gadget/f_dfu.c
karo: fdt: fix panel-dpi support
[karo-tx-uboot.git] / drivers / usb / gadget / f_dfu.c
index a045864d730686448c4740eccd56585a80291f54..77a1567a944c71b95fc5c11d077138e7cc6df563 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/usb/composite.h>
 
 #include <dfu.h>
+#include <g_dnl.h>
 #include "f_dfu.h"
 
 struct f_dfu {
@@ -80,14 +81,6 @@ static struct usb_descriptor_header *dfu_runtime_descs[] = {
        NULL,
 };
 
-static const struct usb_qualifier_descriptor dev_qualifier = {
-       .bLength =              sizeof dev_qualifier,
-       .bDescriptorType =      USB_DT_DEVICE_QUALIFIER,
-       .bcdUSB =               __constant_cpu_to_le16(0x0200),
-       .bDeviceClass =         USB_CLASS_VENDOR_SPEC,
-       .bNumConfigurations =   1,
-};
-
 static const char dfu_name[] = "Device Firmware Upgrade";
 
 /*
@@ -161,18 +154,42 @@ static void dfu_set_poll_timeout(struct dfu_status *dstat, unsigned int ms)
 static void dnload_request_complete(struct usb_ep *ep, struct usb_request *req)
 {
        struct f_dfu *f_dfu = req->context;
+       int ret;
 
-       dfu_write(dfu_get_entity(f_dfu->altsetting), req->buf,
-                 req->length, f_dfu->blk_seq_num);
+       ret = dfu_write(dfu_get_entity(f_dfu->altsetting), req->buf,
+                       req->length, f_dfu->blk_seq_num);
+       if (ret) {
+               f_dfu->dfu_status = DFU_STATUS_errUNKNOWN;
+               f_dfu->dfu_state = DFU_STATE_dfuERROR;
+       }
+}
 
-       if (req->length == 0)
-               puts("DOWNLOAD ... OK\nCtrl+C to exit ...\n");
+static void dnload_request_flush(struct usb_ep *ep, struct usb_request *req)
+{
+       struct f_dfu *f_dfu = req->context;
+       int ret;
+
+       ret = dfu_flush(dfu_get_entity(f_dfu->altsetting), req->buf,
+                       req->length, f_dfu->blk_seq_num);
+       if (ret) {
+               f_dfu->dfu_status = DFU_STATUS_errUNKNOWN;
+               f_dfu->dfu_state = DFU_STATE_dfuERROR;
+       }
+}
+
+static inline int dfu_get_manifest_timeout(struct dfu_entity *dfu)
+{
+       return dfu->poll_timeout ? dfu->poll_timeout(dfu) :
+               DFU_MANIFEST_POLL_TIMEOUT;
 }
 
 static void handle_getstatus(struct usb_request *req)
 {
        struct dfu_status *dstat = (struct dfu_status *)req->buf;
        struct f_dfu *f_dfu = req->context;
+       struct dfu_entity *dfu = dfu_get_entity(f_dfu->altsetting);
+
+       dfu_set_poll_timeout(dstat, 0);
 
        switch (f_dfu->dfu_state) {
        case DFU_STATE_dfuDNLOAD_SYNC:
@@ -180,13 +197,15 @@ static void handle_getstatus(struct usb_request *req)
                f_dfu->dfu_state = DFU_STATE_dfuDNLOAD_IDLE;
                break;
        case DFU_STATE_dfuMANIFEST_SYNC:
+               f_dfu->dfu_state = DFU_STATE_dfuMANIFEST;
+               break;
+       case DFU_STATE_dfuMANIFEST:
+               dfu_set_poll_timeout(dstat, dfu_get_manifest_timeout(dfu));
                break;
        default:
                break;
        }
 
-       dfu_set_poll_timeout(dstat, 0);
-
        if (f_dfu->poll_timeout)
                if (!(f_dfu->blk_seq_num %
                      (dfu_get_buf_size() / DFU_USB_BUFSIZ)))
@@ -210,6 +229,7 @@ static inline void to_dfu_mode(struct f_dfu *f_dfu)
 {
        f_dfu->usb_function.strings = dfu_strings;
        f_dfu->usb_function.hs_descriptors = f_dfu->function;
+       f_dfu->usb_function.descriptors = f_dfu->function;
        f_dfu->dfu_state = DFU_STATE_dfuIDLE;
 }
 
@@ -217,6 +237,7 @@ static inline void to_runtime_mode(struct f_dfu *f_dfu)
 {
        f_dfu->usb_function.strings = NULL;
        f_dfu->usb_function.hs_descriptors = dfu_runtime_descs;
+       f_dfu->usb_function.descriptors = dfu_runtime_descs;
 }
 
 static int handle_upload(struct usb_request *req, u16 len)
@@ -345,7 +366,7 @@ static int state_dfu_idle(struct f_dfu *f_dfu,
                to_runtime_mode(f_dfu);
                f_dfu->dfu_state = DFU_STATE_appIDLE;
 
-               dfu_trigger_reset();
+               g_dnl_trigger_detach();
                break;
        default:
                f_dfu->dfu_state = DFU_STATE_dfuERROR;
@@ -446,10 +467,11 @@ static int state_dfu_manifest_sync(struct f_dfu *f_dfu,
        switch (ctrl->bRequest) {
        case USB_REQ_DFU_GETSTATUS:
                /* We're MainfestationTolerant */
-               f_dfu->dfu_state = DFU_STATE_dfuIDLE;
+               f_dfu->dfu_state = DFU_STATE_dfuMANIFEST;
                handle_getstatus(req);
                f_dfu->blk_seq_num = 0;
                value = RET_STAT_LEN;
+               req->complete = dnload_request_flush;
                break;
        case USB_REQ_DFU_GETSTATE:
                handle_getstate(req);
@@ -463,6 +485,33 @@ static int state_dfu_manifest_sync(struct f_dfu *f_dfu,
        return value;
 }
 
+static int state_dfu_manifest(struct f_dfu *f_dfu,
+                             const struct usb_ctrlrequest *ctrl,
+                             struct usb_gadget *gadget,
+                             struct usb_request *req)
+{
+       int value = 0;
+
+       switch (ctrl->bRequest) {
+       case USB_REQ_DFU_GETSTATUS:
+               /* We're MainfestationTolerant */
+               f_dfu->dfu_state = DFU_STATE_dfuIDLE;
+               handle_getstatus(req);
+               f_dfu->blk_seq_num = 0;
+               value = RET_STAT_LEN;
+               puts("DOWNLOAD ... OK\nCtrl+C to exit ...\n");
+               break;
+       case USB_REQ_DFU_GETSTATE:
+               handle_getstate(req);
+               break;
+       default:
+               f_dfu->dfu_state = DFU_STATE_dfuERROR;
+               value = RET_STALL;
+               break;
+       }
+       return value;
+}
+
 static int state_dfu_upload_idle(struct f_dfu *f_dfu,
                                 const struct usb_ctrlrequest *ctrl,
                                 struct usb_gadget *gadget,
@@ -539,7 +588,7 @@ static dfu_state_fn dfu_state[] = {
        state_dfu_dnbusy,        /* DFU_STATE_dfuDNBUSY */
        state_dfu_dnload_idle,   /* DFU_STATE_dfuDNLOAD_IDLE */
        state_dfu_manifest_sync, /* DFU_STATE_dfuMANIFEST_SYNC */
-       NULL,                    /* DFU_STATE_dfuMANIFEST */
+       state_dfu_manifest,      /* DFU_STATE_dfuMANIFEST */
        NULL,                    /* DFU_STATE_dfuMANIFEST_WAIT_RST */
        state_dfu_upload_idle,   /* DFU_STATE_dfuUPLOAD_IDLE */
        state_dfu_error          /* DFU_STATE_dfuERROR */
@@ -725,10 +774,19 @@ static int dfu_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
        debug("%s: intf:%d alt:%d\n", __func__, intf, alt);
 
        f_dfu->altsetting = alt;
+       f_dfu->dfu_state = DFU_STATE_dfuIDLE;
+       f_dfu->dfu_status = DFU_STATUS_OK;
 
        return 0;
 }
 
+static int __dfu_get_alt(struct usb_function *f, unsigned intf)
+{
+       struct f_dfu *f_dfu = func_to_dfu(f);
+
+       return f_dfu->altsetting;
+}
+
 /* TODO: is this really what we need here? */
 static void dfu_disable(struct usb_function *f)
 {
@@ -751,9 +809,11 @@ static int dfu_bind_config(struct usb_configuration *c)
                return -ENOMEM;
        f_dfu->usb_function.name = "dfu";
        f_dfu->usb_function.hs_descriptors = dfu_runtime_descs;
+       f_dfu->usb_function.descriptors = dfu_runtime_descs;
        f_dfu->usb_function.bind = dfu_bind;
        f_dfu->usb_function.unbind = dfu_unbind;
        f_dfu->usb_function.set_alt = dfu_set_alt;
+       f_dfu->usb_function.get_alt = __dfu_get_alt;
        f_dfu->usb_function.disable = dfu_disable;
        f_dfu->usb_function.strings = dfu_generic_strings;
        f_dfu->usb_function.setup = dfu_handle;
@@ -781,3 +841,5 @@ int dfu_add(struct usb_configuration *c)
 
        return dfu_bind_config(c);
 }
+
+DECLARE_GADGET_BIND_CALLBACK(usb_dnl_dfu, dfu_add);