From bfb7aa1e191628699b87b1a5b8428e454728d435 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 10 Jul 2014 23:33:30 +0200 Subject: USB: gadget: Add a multi function gadget Similar to the Kernel multi function this gadget driver is used for creating a USB device with multiple functions. This is created and removed with the newly created 'usbgadget' command. Based on the options it creates combinations of DFU, fastboot and serial USB functions. Signed-off-by: Sascha Hauer --- commands/Kconfig | 5 +++ commands/Makefile | 1 + commands/usbgadget.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 commands/usbgadget.c (limited to 'commands') diff --git a/commands/Kconfig b/commands/Kconfig index 174a5b602d..506b3d0a4e 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -1831,6 +1831,11 @@ config CMD_USB Options: -f force rescan +config CMD_USBGADGET + bool + depends on USB_GADGET + prompt "usbgadget" + config CMD_WD bool depends on WATCHDOG diff --git a/commands/Makefile b/commands/Makefile index d42aca5c0c..f3cacebf6e 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -100,3 +100,4 @@ obj-$(CONFIG_CMD_MENUTREE) += menutree.o obj-$(CONFIG_CMD_2048) += 2048.o obj-$(CONFIG_CMD_REGULATOR) += regulator.o obj-$(CONFIG_CMD_LSPCI) += lspci.o +obj-$(CONFIG_CMD_USBGADGET) += usbgadget.o diff --git a/commands/usbgadget.c b/commands/usbgadget.c new file mode 100644 index 0000000000..fc2252ad09 --- /dev/null +++ b/commands/usbgadget.c @@ -0,0 +1,108 @@ +/* + * usbserial.c - usb serial gadget command + * + * Copyright (c) 2011 Eric Bénard , Eukréa Electromatique + * based on dfu.c which is : + * Copyright (c) 2009 Sascha Hauer , Pengutronix + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * 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. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int do_usbgadget(int argc, char *argv[]) +{ + int opt; + int acm = 1, create_serial = 0; + char *fastboot_opts = NULL, *dfu_opts = NULL; + struct f_multi_opts opts = {}; + + while ((opt = getopt(argc, argv, "asdA:D:")) > 0) { + switch (opt) { + case 'a': + acm = 1; + create_serial = 1; + break; + case 's': + acm = 0; + create_serial = 1; + break; + case 'D': + dfu_opts = optarg; + break; + case 'A': + fastboot_opts = optarg; + break; + case 'd': + usb_multi_unregister(); + return 0; + default: + return -EINVAL; + } + } + + if (!dfu_opts && !fastboot_opts && !create_serial) + return COMMAND_ERROR_USAGE; + + /* + * Creating a gadget with both DFU and Fastboot doesn't work. + * Both client tools seem to assume that the device only has + * a single configuration + */ + if (fastboot_opts && dfu_opts) { + printf("Only one of Fastboot and DFU allowed\n"); + return -EINVAL; + } + + if (fastboot_opts) { + opts.fastboot_opts.files = file_list_parse(fastboot_opts); + } + + if (dfu_opts) { + opts.dfu_opts.files = file_list_parse(dfu_opts); + } + + if (create_serial) { + opts.create_acm = acm; + } + + return usb_multi_register(&opts); +} + +BAREBOX_CMD_HELP_START(usbgadget) +BAREBOX_CMD_HELP_TEXT("Enable / disable a USB composite gadget on the USB device interface.") +BAREBOX_CMD_HELP_TEXT("") +BAREBOX_CMD_HELP_TEXT("Options:") +BAREBOX_CMD_HELP_OPT ("-a", "Create CDC ACM function") +BAREBOX_CMD_HELP_OPT ("-s", "Create Generic Serial function") +BAREBOX_CMD_HELP_OPT ("-A ", "Create Android Fastboot function") +BAREBOX_CMD_HELP_OPT ("-D ", "Create DFU function") +BAREBOX_CMD_HELP_OPT ("-d", "Disable the serial gadget") +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(usbgadget) + .cmd = do_usbgadget, + BAREBOX_CMD_DESC("Create USB Gadget multifunction device") + BAREBOX_CMD_OPTS("[-asdAD]") + BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP) + BAREBOX_CMD_HELP(cmd_usbgadget_help) +BAREBOX_CMD_END -- cgit v1.2.3