summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorEric Bénard <eric@eukrea.com>2012-01-04 10:36:47 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2012-01-04 14:18:46 +0100
commitf7aaa2249325c963b80654a7c2de14223b8e4165 (patch)
tree83e9ff43334cefdfde37e396062b0845ca933b59 /commands
parenteb98425068297fc26a07e3acf889f38cac4045cf (diff)
downloadbarebox-f7aaa2249325c963b80654a7c2de14223b8e4165.tar.gz
barebox-f7aaa2249325c963b80654a7c2de14223b8e4165.tar.xz
serial gadget: enable/disable on request
- add a usbserial command to enable/disable the serial gadget - allow dfu and usbserial to cohexist in the same barebox - add a timeout in u_serial so that we don't get locked if the user enable usbserial from a UART console but doesn't consume the data on the usbserial port created on the PC - remove debug or verbose printf - tested on i.MX25 & i.MX35 & usb-a926x Signed-off-by: Eric Bénard <eric@eukrea.com> Tested-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/Makefile1
-rw-r--r--commands/usbserial.c108
2 files changed, 109 insertions, 0 deletions
diff --git a/commands/Makefile b/commands/Makefile
index 24753be80d..43630e1274 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_CMD_LSMOD) += lsmod.o
obj-$(CONFIG_CMD_INSMOD) += insmod.o
obj-$(CONFIG_CMD_BMP) += bmp.o
obj-$(CONFIG_USB_GADGET_DFU) += dfu.o
+obj-$(CONFIG_USB_GADGET_SERIAL) += usbserial.o
obj-$(CONFIG_CMD_GPIO) += gpio.o
obj-$(CONFIG_CMD_UNCOMPRESS) += uncompress.o
obj-$(CONFIG_CMD_I2C) += i2c.o
diff --git a/commands/usbserial.c b/commands/usbserial.c
new file mode 100644
index 0000000000..eb31934d76
--- /dev/null
+++ b/commands/usbserial.c
@@ -0,0 +1,108 @@
+/*
+ * usbserial.c - usb serial gadget command
+ *
+ * Copyright (c) 2011 Eric Bénard <eric@eukrea.com>, Eukréa Electromatique
+ * based on dfu.c which is :
+ * Copyright (c) 2009 Sascha Hauer <s.hauer@pengutronix.de>, 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.
+ *
+ * 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 <common.h>
+#include <command.h>
+#include <errno.h>
+#include <malloc.h>
+#include <getopt.h>
+#include <fs.h>
+#include <xfuncs.h>
+#include <usb/usbserial.h>
+
+static int do_usbserial(struct command *cmdtp, int argc, char *argv[])
+{
+ int opt;
+ struct usb_serial_pdata pdata;
+ char *argstr;
+ char *manufacturer = "barebox";
+ char *productname = CONFIG_BOARDINFO;
+ u16 idVendor = 0, idProduct = 0;
+ int mode = 0;
+
+ while ((opt = getopt(argc, argv, "m:p:V:P:asd")) > 0) {
+ switch (opt) {
+ case 'm':
+ manufacturer = optarg;
+ break;
+ case 'p':
+ productname = optarg;
+ break;
+ case 'V':
+ idVendor = simple_strtoul(optarg, NULL, 0);
+ break;
+ case 'P':
+ idProduct = simple_strtoul(optarg, NULL, 0);
+ break;
+ case 'a':
+ mode = 0;
+ break;
+#ifdef HAVE_OBEX
+ case 'o':
+ mode = 1;
+ break;
+#endif
+ case 's':
+ mode = 2;
+ break;
+ case 'd':
+ usb_serial_unregister();
+ return 0;
+ }
+ }
+
+ argstr = argv[optind];
+
+ pdata.manufacturer = manufacturer;
+ pdata.productname = productname;
+ pdata.idVendor = idVendor;
+ pdata.idProduct = idProduct;
+ pdata.mode = mode;
+
+ return usb_serial_register(&pdata);
+}
+
+BAREBOX_CMD_HELP_START(usbserial)
+BAREBOX_CMD_HELP_USAGE("usbserial [OPTIONS] <description>\n")
+BAREBOX_CMD_HELP_SHORT("Enable/disable a serial gadget on the USB device interface.\n")
+BAREBOX_CMD_HELP_OPT ("-m <str>", "Manufacturer string (barebox)\n")
+BAREBOX_CMD_HELP_OPT ("-p <str>", "product string (" CONFIG_BOARDINFO ")\n")
+BAREBOX_CMD_HELP_OPT ("-V <id>", "vendor id\n")
+BAREBOX_CMD_HELP_OPT ("-P <id>", "product id\n")
+BAREBOX_CMD_HELP_OPT ("-a", "CDC ACM (default)\n")
+#ifdef HAVE_OBEX
+BAREBOX_CMD_HELP_OPT ("-o", "CDC OBEX\n")
+#endif
+BAREBOX_CMD_HELP_OPT ("-s", "Generic Serial\n")
+BAREBOX_CMD_HELP_OPT ("-d", "Disable the serial gadget\n")
+BAREBOX_CMD_HELP_END
+
+/**
+ * @page usbserial_command
+ */
+
+BAREBOX_CMD_START(usbserial)
+ .cmd = do_usbserial,
+ .usage = "Serial gadget enable/disable",
+ BAREBOX_CMD_HELP(cmd_usbserial_help)
+BAREBOX_CMD_END