]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - drivers/usb/gadget/f_dfu.c
Update from 2013.01 to 2013.07
[karo-tx-uboot.git] / drivers / usb / gadget / f_dfu.c
index 10547e3279b6aadac2cc376ea2d5efd281147ad2..37d04a19285e605a6d4e34ae9b54b989eca28891 100644 (file)
@@ -5,19 +5,14 @@
  * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
  *          Lukasz Majewski <l.majewski@samsung.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Based on OpenMoko u-boot: drivers/usb/usbdfu.c
+ * (C) 2007 by OpenMoko, Inc.
+ * Author: Harald Welte <laforge@openmoko.org>
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * based on existing SAM7DFU code from OpenPCD:
+ * (C) Copyright 2006 by Harald Welte <hwelte at hmw-consulting.de>
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <errno.h>
@@ -164,6 +159,9 @@ static void handle_getstatus(struct usb_request *req)
 
        /* send status response */
        dstat->bStatus = f_dfu->dfu_status;
+       dstat->bwPollTimeout[0] = 0;
+       dstat->bwPollTimeout[1] = 0;
+       dstat->bwPollTimeout[2] = 0;
        dstat->bState = f_dfu->dfu_state;
        dstat->iString = 0;
 }
@@ -180,6 +178,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->dfu_state = DFU_STATE_dfuIDLE;
 }
 
 static inline void to_runtime_mode(struct f_dfu *f_dfu)
@@ -230,7 +229,6 @@ static int state_app_idle(struct f_dfu *f_dfu,
        case USB_REQ_DFU_DETACH:
                f_dfu->dfu_state = DFU_STATE_appDETACH;
                to_dfu_mode(f_dfu);
-               f_dfu->dfu_state = DFU_STATE_dfuIDLE;
                value = RET_ZLP;
                break;
        default:
@@ -314,6 +312,8 @@ static int state_dfu_idle(struct f_dfu *f_dfu,
                        DFU_STATE_dfuMANIFEST_WAIT_RST;
                to_runtime_mode(f_dfu);
                f_dfu->dfu_state = DFU_STATE_appIDLE;
+
+               dfu_trigger_reset();
                break;
        default:
                f_dfu->dfu_state = DFU_STATE_dfuERROR;
@@ -586,7 +586,7 @@ static int dfu_prepare_function(struct f_dfu *f_dfu, int n)
        struct usb_interface_descriptor *d;
        int i = 0;
 
-       f_dfu->function = calloc(sizeof(struct usb_descriptor_header *), n);
+       f_dfu->function = calloc(sizeof(struct usb_descriptor_header *), n + 1);
        if (!f_dfu->function)
                goto enomem;
 
@@ -650,6 +650,8 @@ static int dfu_bind(struct usb_configuration *c, struct usb_function *f)
                        ->iInterface = id;
        }
 
+       to_dfu_mode(f_dfu);
+
        stringtab_dfu.strings = f_dfu->strings;
 
        cdev->req->context = f_dfu;