]> git.sur5r.net Git - u-boot/blobdiff - drivers/usb/gadget/g_dnl.c
usb:g_dnl:dfu: Download gadget and DFU function code clean up
[u-boot] / drivers / usb / gadget / g_dnl.c
index a5a4c1fe65f3cd0b79a008c0f3ed86a1a1548622..40868c034e42fcde8416d407552e38e2e2daf75b 100644 (file)
@@ -4,22 +4,9 @@
  * Copyright (C) 2012 Samsung Electronics
  * 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.
- *
- * 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.
- *
- * 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>
 #include <common.h>
 #include <malloc.h>
 
@@ -27,7 +14,8 @@
 #include <part.h>
 
 #include <g_dnl.h>
-#include "f_dfu.h"
+#include <usb_mass_storage.h>
+#include <dfu.h>
 
 #include "gadget_chips.h"
 #include "composite.c"
 
 #define STRING_MANUFACTURER 25
 #define STRING_PRODUCT 2
+/* Index of String Descriptor describing this configuration */
 #define STRING_USBDOWN 2
-#define CONFIG_USBDOWNLOADER 2
+/* Number of supported configurations */
+#define CONFIGURATION_NUMBER 1
 
 #define DRIVER_VERSION         "usb_dnl 2.0"
 
@@ -65,11 +55,14 @@ static struct usb_device_descriptor device_desc = {
        .bNumConfigurations = 1,
 };
 
-/* static strings, in UTF-8 */
+/*
+ * static strings, in UTF-8
+ * IDs for those strings are assigned dynamically at g_dnl_bind()
+ */
 static struct usb_string g_dnl_string_defs[] = {
-       { 0, manufacturer, },
-       { 1, product, },
-       {  }            /* end of list */
+       {.s = manufacturer},
+       {.s = product},
+       {             /* end of list */
 };
 
 static struct usb_gadget_strings g_dnl_string_tab = {
@@ -104,6 +97,8 @@ static int g_dnl_do_config(struct usb_configuration *c)
        printf("GADGET DRIVER: %s\n", s);
        if (!strcmp(s, "usb_dnl_dfu"))
                ret = dfu_add(c);
+       else if (!strcmp(s, "usb_dnl_ums"))
+               ret = fsg_add(c);
 
        return ret;
 }
@@ -113,7 +108,7 @@ static int g_dnl_config_register(struct usb_composite_dev *cdev)
        static struct usb_configuration config = {
                .label = "usb_dnload",
                .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
-               .bConfigurationValue =  CONFIG_USBDOWNLOADER,
+               .bConfigurationValue =  CONFIGURATION_NUMBER,
                .iConfiguration =       STRING_USBDOWN,
 
                .bind = g_dnl_do_config,
@@ -122,6 +117,12 @@ static int g_dnl_config_register(struct usb_composite_dev *cdev)
        return usb_add_config(cdev, &config);
 }
 
+__weak
+int g_dnl_bind_fixup(struct usb_device_descriptor *dev)
+{
+       return 0;
+}
+
 static int g_dnl_bind(struct usb_composite_dev *cdev)
 {
        struct usb_gadget *gadget = cdev->gadget;
@@ -144,6 +145,7 @@ static int g_dnl_bind(struct usb_composite_dev *cdev)
        g_dnl_string_defs[1].id = id;
        device_desc.iProduct = id;
 
+       g_dnl_bind_fixup(&device_desc);
        ret = g_dnl_config_register(cdev);
        if (ret)
                goto error;
@@ -188,6 +190,9 @@ int g_dnl_register(const char *type)
        if (!strcmp(type, "dfu")) {
                strcpy(name, shortname);
                strcat(name, type);
+       } else if (!strcmp(type, "ums")) {
+               strcpy(name, shortname);
+               strcat(name, type);
        } else {
                printf("%s: unknown command: %s\n", __func__, type);
                return -EINVAL;