All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <l.majewski@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 1/7] dfu:usb: Support for g_dnl composite download gadget.
Date: Mon, 06 Aug 2012 14:41:05 +0200	[thread overview]
Message-ID: <1344256871-20466-2-git-send-email-l.majewski@samsung.com> (raw)
In-Reply-To: <1344256871-20466-1-git-send-email-l.majewski@samsung.com>

Composite USB download gadget support (g_dnl) for download functions.
This code works on top of composite gadget.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Marek Vasut <marex@denx.de>

---
Changes for v2:

- G_DNL_{VENDOR_NUM, PRODUCT_NUM and MANUFACTURER} defined at
./include/configs/<board>.h
- Suspend and resume stub methods removed
- '\0' repleaced with plain 0

Changes for v3:
- Remove unused #includes
- Replace strncpy and strncat with strcpy and strcat. It was possible
  due to new approach to g_dnl name generation (at g_dnl_register function)
- Rename the g_dnl_{init|cleanup} to g_dnl_{register|unregister}
- Replace the G_DNL_* CONFIG_G_DNL_*

Changes for v4:
- Remove unnecessary otg calls
- odin prefix replaced with g_dnl
- Single space indentation between type and variable name

Changes for v5:
- None
---
 drivers/usb/gadget/Makefile |    1 +
 drivers/usb/gadget/g_dnl.c  |  202 +++++++++++++++++++++++++++++++++++++++++++
 include/g_dnl.h             |   33 +++++++
 3 files changed, 236 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/gadget/g_dnl.c
 create mode 100644 include/g_dnl.h

diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 87d1918..2c067c8 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -29,6 +29,7 @@ LIB	:= $(obj)libusb_gadget.o
 ifdef CONFIG_USB_GADGET
 COBJS-y += epautoconf.o config.o usbstring.o
 COBJS-$(CONFIG_USB_GADGET_S3C_UDC_OTG) += s3c_udc_otg.o
+COBJS-$(CONFIG_USBDOWNLOAD_GADGET) += g_dnl.o
 endif
 ifdef CONFIG_USB_ETHER
 COBJS-y += ether.o epautoconf.o config.o usbstring.o
diff --git a/drivers/usb/gadget/g_dnl.c b/drivers/usb/gadget/g_dnl.c
new file mode 100644
index 0000000..7d87050
--- /dev/null
+++ b/drivers/usb/gadget/g_dnl.c
@@ -0,0 +1,202 @@
+/*
+ * g_dnl.c -- USB Downloader Gadget
+ *
+ * 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
+ */
+
+#include <errno.h>
+#include <common.h>
+#include <malloc.h>
+
+#include <mmc.h>
+#include <part.h>
+
+#include <g_dnl.h>
+#include "f_dfu.h"
+
+#include "gadget_chips.h"
+#include "composite.c"
+
+/*
+ * One needs to define the following:
+ * CONFIG_G_DNL_VENDOR_NUM
+ * CONFIG_G_DNL_PRODUCT_NUM
+ * CONFIG_G_DNL_MANUFACTURER
+ * at e.g. ./include/configs/<board>.h
+ */
+
+#define STRING_MANUFACTURER 25
+#define STRING_PRODUCT 2
+#define STRING_USBDOWN 2
+#define CONFIG_USBDOWNLOADER 2
+
+#define DRIVER_VERSION		"usb_dnl 2.0"
+
+static const char shortname[] = "usb_dnl_";
+static const char product[] = "USB download gadget";
+static const char manufacturer[] = CONFIG_G_DNL_MANUFACTURER;
+
+static struct usb_device_descriptor device_desc = {
+	.bLength = sizeof device_desc,
+	.bDescriptorType = USB_DT_DEVICE,
+
+	.bcdUSB = __constant_cpu_to_le16(0x0200),
+	.bDeviceClass = USB_CLASS_COMM,
+	.bDeviceSubClass = 0x02, /*0x02:CDC-modem , 0x00:CDC-serial*/
+
+	.idVendor = __constant_cpu_to_le16(CONFIG_G_DNL_VENDOR_NUM),
+	.idProduct = __constant_cpu_to_le16(CONFIG_G_DNL_PRODUCT_NUM),
+	.iProduct = STRING_PRODUCT,
+	.bNumConfigurations = 1,
+};
+
+/* static strings, in UTF-8 */
+static struct usb_string g_dnl_string_defs[] = {
+	{ 0, manufacturer, },
+	{ 1, product, },
+};
+
+static struct usb_gadget_strings g_dnl_string_tab = {
+	.language = 0x0409, /* en-us */
+	.strings = g_dnl_string_defs,
+};
+
+static struct usb_gadget_strings *g_dnl_composite_strings[] = {
+	&g_dnl_string_tab,
+	NULL,
+};
+
+static int g_dnl_unbind(struct usb_composite_dev *cdev)
+{
+	debug("%s\n", __func__);
+	return 0;
+}
+
+static int g_dnl_do_config(struct usb_configuration *c)
+{
+	const char *s = c->cdev->driver->name;
+	int ret = -1;
+
+	debug("%s: configuration: 0x%p composite dev: 0x%p\n",
+	      __func__, c, c->cdev);
+
+	printf("GADGET DRIVER: %s\n", s);
+	if (!strcmp(s, "usb_dnl_dfu"))
+		ret = dfu_add(c);
+
+	return ret;
+}
+
+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,
+		.iConfiguration =	STRING_USBDOWN,
+
+		.bind = g_dnl_do_config,
+	};
+
+	return usb_add_config(cdev, &config);
+}
+
+static int g_dnl_bind(struct usb_composite_dev *cdev)
+{
+	struct usb_gadget *gadget = cdev->gadget;
+	int id, ret;
+	int gcnum;
+
+	debug("%s: gadget: 0x%p cdev: 0x%p\n", __func__, gadget, cdev);
+
+	id = usb_string_id(cdev);
+
+	if (id < 0)
+		return id;
+	g_dnl_string_defs[0].id = id;
+	device_desc.iManufacturer = id;
+
+	id = usb_string_id(cdev);
+	if (id < 0)
+		return id;
+
+	g_dnl_string_defs[1].id = id;
+	device_desc.iProduct = id;
+
+	ret = g_dnl_config_register(cdev);
+	if (ret)
+		goto error;
+
+	gcnum = usb_gadget_controller_number(gadget);
+
+	debug("gcnum: %d\n", gcnum);
+	if (gcnum >= 0)
+		device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
+	else {
+		debug("%s: controller '%s' not recognized\n",
+			shortname, gadget->name);
+		device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
+	}
+
+	return 0;
+
+ error:
+	g_dnl_unbind(cdev);
+	return -ENOMEM;
+}
+
+static struct usb_composite_driver g_dnl_driver = {
+	.name = NULL,
+	.dev = &device_desc,
+	.strings = g_dnl_composite_strings,
+
+	.bind = g_dnl_bind,
+	.unbind = g_dnl_unbind,
+};
+
+int g_dnl_register(const char *type)
+{
+	/* We only allow "dfu" atm, so 3 should be enough */
+	static char name[sizeof(shortname) + 3];
+	int ret;
+
+	if (!strcmp(type, "dfu")) {
+		strcpy(name, shortname);
+		strcat(name, type);
+	} else {
+		printf("%s: unknown command: %s\n", __func__, type);
+		return -EINVAL;
+	}
+
+	g_dnl_driver.name = name;
+
+	debug("%s: g_dnl_driver.name: %s\n", __func__, g_dnl_driver.name);
+	ret = usb_composite_register(&g_dnl_driver);
+
+	if (ret) {
+		printf("%s: failed!, error: %d\n", __func__, ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+void g_dnl_unregister(void)
+{
+	usb_composite_unregister(&g_dnl_driver);
+}
diff --git a/include/g_dnl.h b/include/g_dnl.h
new file mode 100644
index 0000000..0ec7440
--- /dev/null
+++ b/include/g_dnl.h
@@ -0,0 +1,33 @@
+/*
+ *  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
+ */
+
+#ifndef __G_DOWNLOAD_H_
+#define __G_DOWNLOAD_H_
+
+#include <linux/usb/ch9.h>
+#include <usbdescriptors.h>
+#include <linux/usb/gadget.h>
+
+int g_dnl_register(const char *s);
+void g_dnl_unregister(void);
+
+/* USB initialization declaration - board specific */
+void board_usb_init(void);
+#endif /* __G_DOWNLOAD_H_ */
-- 
1.7.2.3

  reply	other threads:[~2012-08-06 12:41 UTC|newest]

Thread overview: 147+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-03  9:38 [U-Boot] [PATCH 0/7] dfu:usb: Composite USB download gadget with DFU function Lukasz Majewski
2012-07-03  9:38 ` [U-Boot] [PATCH 1/7] dfu:usb: Support for g_dnl composite download gadget Lukasz Majewski
2012-07-03 18:41   ` Marek Vasut
2012-07-04  7:42     ` Lukasz Majewski
2012-07-20  4:14   ` Mike Frysinger
2012-07-23 15:25     ` Lukasz Majewski
2012-07-24 17:50       ` Mike Frysinger
2012-07-03  9:38 ` [U-Boot] [PATCH 2/7] dfu:usb: DFU USB function (f_dfu) support for g_dnl composite gadget Lukasz Majewski
2012-07-03 21:21   ` Marek Vasut
2012-07-04  8:39     ` Lukasz Majewski
2012-07-04 14:35       ` Marek Vasut
2012-07-04 15:04         ` Lukasz Majewski
2012-07-04 16:21           ` Marek Vasut
2012-07-03  9:38 ` [U-Boot] [PATCH 3/7] dfu: DFU backend implementation Lukasz Majewski
2012-07-03 21:28   ` Marek Vasut
2012-07-04  8:56     ` Lukasz Majewski
2012-07-04 14:36       ` Marek Vasut
2012-07-04 15:07         ` Lukasz Majewski
2012-07-04 16:22           ` Marek Vasut
2012-07-20  4:32   ` Mike Frysinger
2012-07-23 16:11     ` Lukasz Majewski
2012-07-03  9:38 ` [U-Boot] [PATCH 4/7] dfu: MMC specific routines for DFU operation Lukasz Majewski
2012-07-03 21:29   ` Marek Vasut
2012-07-03 21:55     ` Tom Rini
2012-07-03 22:01       ` Marek Vasut
2012-07-03 22:06         ` Tom Rini
2012-07-03 22:31           ` Marek Vasut
2012-07-03 22:33             ` Tom Rini
2012-07-03 23:07               ` Stephen Warren
2012-07-03 23:38                 ` Tom Rini
2012-07-03 23:58                   ` Stephen Warren
2012-07-04  0:13               ` Marek Vasut
2012-07-20  4:25                 ` Mike Frysinger
2012-07-04  9:10         ` Lukasz Majewski
2012-07-04 14:38           ` Marek Vasut
2012-07-04 15:13             ` Lukasz Majewski
2012-07-03  9:38 ` [U-Boot] [PATCH 5/7] dfu:cmd: Support for DFU u-boot command Lukasz Majewski
2012-07-03 21:32   ` Marek Vasut
2012-07-04  9:28     ` Lukasz Majewski
2012-07-04 14:39       ` Marek Vasut
2012-07-20  4:23         ` Mike Frysinger
2012-07-20 11:33           ` Marek Vasut
2012-07-20 14:43             ` Mike Frysinger
2012-07-20 21:11               ` Marek Vasut
2012-07-21 17:20                 ` Mike Frysinger
2012-07-21 17:21                   ` Marek Vasut
2012-07-20  4:22     ` Mike Frysinger
2012-07-20 11:35       ` Marek Vasut
2012-07-20  4:20   ` Mike Frysinger
2012-07-23 16:01     ` Lukasz Majewski
2012-07-24 18:00       ` Mike Frysinger
2012-07-24 20:48         ` Lukasz Majewski
2012-07-03  9:38 ` [U-Boot] [PATCH 6/7] arm:trats: Support for USB UDC driver at TRATS board Lukasz Majewski
2012-07-04  0:20   ` Minkyu Kang
2012-07-04  9:33     ` Lukasz Majewski
2012-07-03  9:38 ` [U-Boot] [PATCH 7/7] arm:trats: Enable g_dnl composite USB gadget with embedded DFU function on TRATS Lukasz Majewski
2012-07-04  0:22   ` Minkyu Kang
2012-07-03 12:52 ` [U-Boot] [PATCH 0/7] dfu:usb: Composite USB download gadget with DFU function Otavio Salvador
2012-07-03 12:59   ` Marek Vasut
2012-07-04 15:48 ` [U-Boot] [PATCH v2 " Lukasz Majewski
2012-07-04 15:48   ` [U-Boot] [PATCH v2 1/7] dfu:usb: Support for g_dnl composite download gadget Lukasz Majewski
2012-07-09 16:30     ` Marek Vasut
2012-07-04 15:48   ` [U-Boot] [PATCH v2 2/7] dfu:usb: DFU USB function (f_dfu) support for g_dnl composite gadget Lukasz Majewski
2012-07-09 16:34     ` Marek Vasut
2012-07-04 15:48   ` [U-Boot] [PATCH v2 3/7] dfu: DFU backend implementation Lukasz Majewski
2012-07-09 16:35     ` Marek Vasut
2012-07-27 11:58     ` Wolfgang Denk
2012-07-27 13:15       ` Lukasz Majewski
2012-07-27 13:35         ` Wolfgang Denk
2012-07-27 13:47           ` Lukasz Majewski
2012-07-04 15:48   ` [U-Boot] [PATCH v2 4/7] dfu: MMC specific routines for DFU operation Lukasz Majewski
2012-07-09 16:36     ` Marek Vasut
2012-07-10  8:45     ` Tom Rini
2012-07-10 10:38       ` Lukasz Majewski
2012-07-11 11:54         ` Tom Rini
2012-07-12 12:39           ` Lukasz Majewski
2012-07-12 12:46             ` Tom Rini
2012-07-13 10:29               ` Marek Vasut
2012-07-13 21:27                 ` Andy Fleming
2012-07-27 12:36     ` Wolfgang Denk
2012-07-27 12:43       ` Marek Vasut
2012-07-27 12:57         ` Wolfgang Denk
2012-07-27 13:15           ` Marek Vasut
2012-07-27 13:38             ` Wolfgang Denk
2012-07-27 13:33       ` Lukasz Majewski
2012-07-27 13:47         ` Wolfgang Denk
2012-07-04 15:48   ` [U-Boot] [PATCH v2 5/7] dfu:cmd: Support for DFU u-boot command Lukasz Majewski
2012-07-04 15:48   ` [U-Boot] [PATCH v2 6/7] arm:trats: Support for USB UDC driver at TRATS board Lukasz Majewski
2012-07-04 15:48   ` [U-Boot] [PATCH v2 7/7] arm:trats: Enable g_dnl composite USB gadget with embedded DFU function on TRATS Lukasz Majewski
2012-07-09 11:28   ` [U-Boot] [PATCH v2 0/7] dfu:usb: Composite USB download gadget with DFU function Lukasz Majewski
2012-07-09 11:46     ` Tom Rini
2012-07-09 16:25       ` Marek Vasut
2012-07-10  8:27         ` Lukasz Majewski
2012-07-10  9:28           ` Marek Vasut
2012-07-18 12:51 ` [U-Boot] [PATCH " Marek Vasut
2012-07-23  7:57   ` Lukasz Majewski
2012-07-23 10:57     ` Marek Vasut
2012-07-31  6:36 ` [U-Boot] [PATCH v3 0/7] dfu:usb: DFU support via USB Download gadget Lukasz Majewski
2012-07-31  6:36   ` [U-Boot] [PATCH v3 1/7] dfu:usb: Support for g_dnl composite download gadget Lukasz Majewski
2012-08-01 22:40     ` Mike Frysinger
2012-08-02  9:55       ` Lukasz Majewski
2012-07-31  6:36   ` [U-Boot] [PATCH v3 2/7] dfu:usb: DFU USB function (f_dfu) support for g_dnl composite gadget Lukasz Majewski
2012-08-01 22:45     ` Mike Frysinger
2012-08-02 10:54       ` Lukasz Majewski
2012-07-31  6:36   ` [U-Boot] [PATCH v3 3/7] dfu: DFU backend implementation Lukasz Majewski
2012-08-01 22:57     ` Mike Frysinger
2012-08-02 13:55       ` Lukasz Majewski
2012-08-03 23:19         ` Mike Frysinger
2012-08-04  7:47           ` Marek Vasut
2012-08-04 16:28             ` Mike Frysinger
2012-07-31  6:37   ` [U-Boot] [PATCH v3 4/7] dfu: MMC specific routines for DFU operation Lukasz Majewski
2012-08-01 23:00     ` Mike Frysinger
2012-08-02 14:47       ` Lukasz Majewski
2012-07-31  6:37   ` [U-Boot] [PATCH v3 5/7] dfu:cmd: Support for DFU u-boot command Lukasz Majewski
2012-07-31 17:14     ` Stephen Warren
2012-08-01  7:16       ` Lukasz Majewski
2012-08-01 17:13         ` Stephen Warren
2012-08-02  8:31           ` Lukasz Majewski
2012-08-02 15:52             ` Stephen Warren
2012-08-03  6:13               ` Lukasz Majewski
2012-08-03 15:32                 ` Stephen Warren
2012-08-06  7:13                   ` Lukasz Majewski
2012-08-01 18:04     ` Mike Frysinger
2012-08-02  7:16       ` Marek Vasut
2012-08-02 15:28         ` Lukasz Majewski
2012-08-02 17:47         ` Mike Frysinger
2012-07-31  6:37   ` [U-Boot] [PATCH v3 6/7] arm:trats: Support for USB UDC driver at TRATS board Lukasz Majewski
2012-07-31  8:31     ` Minkyu Kang
2012-07-31  6:37   ` [U-Boot] [PATCH v3 7/7] arm:trats: Enable g_dnl composite USB gadget with embedded DFU function on TRATS Lukasz Majewski
2012-07-31  8:32     ` Minkyu Kang
2012-08-03  7:45 ` [U-Boot] [PATCH v4 0/7] dfu:usb: DFU support via USB Download gadget Lukasz Majewski
2012-08-03  7:45   ` [U-Boot] [PATCH v4 1/7] dfu:usb: Support for g_dnl composite download gadget Lukasz Majewski
2012-08-03  7:45   ` [U-Boot] [PATCH v4 2/7] dfu:usb: DFU USB function (f_dfu) support for g_dnl composite gadget Lukasz Majewski
2012-08-03  7:45   ` [U-Boot] [PATCH v4 3/7] dfu: DFU backend implementation Lukasz Majewski
2012-08-03  7:45   ` [U-Boot] [PATCH v4 4/7] dfu: MMC specific routines for DFU operation Lukasz Majewski
2012-08-03  7:45   ` [U-Boot] [PATCH v4 5/7] dfu:cmd: Support for DFU u-boot command Lukasz Majewski
2012-08-03  7:45   ` [U-Boot] [PATCH v4 6/7] arm:trats: Support for USB UDC driver at TRATS board Lukasz Majewski
2012-08-03  7:45   ` [U-Boot] [PATCH v4 7/7] arm:trats: Enable g_dnl composite USB gadget with embedded DFU function on TRATS Lukasz Majewski
2012-08-06 12:41 ` [U-Boot] [PATCH v5 0/7] dfu:usb: DFU support via USB Download gadget Lukasz Majewski
2012-08-06 12:41   ` Lukasz Majewski [this message]
2012-08-06 12:41   ` [U-Boot] [PATCH v5 2/7] dfu:usb: DFU USB function (f_dfu) support for g_dnl composite gadget Lukasz Majewski
2012-08-06 12:41   ` [U-Boot] [PATCH v5 3/7] dfu: DFU backend implementation Lukasz Majewski
2012-08-06 12:41   ` [U-Boot] [PATCH v5 4/7] dfu: MMC specific routines for DFU operation Lukasz Majewski
2012-08-06 12:41   ` [U-Boot] [PATCH v5 5/7] dfu:cmd: Support for DFU u-boot command Lukasz Majewski
2012-08-06 12:41   ` [U-Boot] [PATCH v5 6/7] arm:trats: Support for USB UDC driver at TRATS board Lukasz Majewski
2012-08-06 12:41   ` [U-Boot] [PATCH v5 7/7] arm:trats: Enable g_dnl composite USB gadget with embedded DFU function on TRATS Lukasz Majewski
2012-08-06 20:31   ` [U-Boot] [PATCH v5 0/7] dfu:usb: DFU support via USB Download gadget Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1344256871-20466-2-git-send-email-l.majewski@samsung.com \
    --to=l.majewski@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.