mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v1] usbgadget command: provide -m option to set usb mode
@ 2017-11-14  8:00 Oleksij Rempel
  2017-12-06  8:49 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Oleksij Rempel @ 2017-11-14  8:00 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

if we optimize barebox for speed, then we can't use usbgadget autostart,
which would set otg.mode automatically.
Provide an option for usbgadget command to set otg.mode.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 commands/usbgadget.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/commands/usbgadget.c b/commands/usbgadget.c
index 507871edd2..e5109f99cb 100644
--- a/commands/usbgadget.c
+++ b/commands/usbgadget.c
@@ -34,15 +34,19 @@ static int do_usbgadget(int argc, char *argv[])
 {
 	int opt, ret;
 	int acm = 1, create_serial = 0, fastboot_set = 0, fastboot_export_bbu = 0;
+	int usb_mode_set = 0;
 	const char *fastboot_opts = NULL, *dfu_opts = NULL;
 	struct f_multi_opts *opts;
 
-	while ((opt = getopt(argc, argv, "asdA::D:b")) > 0) {
+	while ((opt = getopt(argc, argv, "amsdA::D:b")) > 0) {
 		switch (opt) {
 		case 'a':
 			acm = 1;
 			create_serial = 1;
 			break;
+		case 'm':
+			usb_mode_set = 1;
+			break;
 		case 's':
 			acm = 0;
 			create_serial = 1;
@@ -101,6 +105,9 @@ static int do_usbgadget(int argc, char *argv[])
 		opts->create_acm = acm;
 	}
 
+	if (usb_mode_set)
+		setenv("otg.mode", "peripheral");
+
 	ret = usb_multi_register(opts);
 	if (ret)
 		usb_multi_opts_release(opts);
@@ -120,6 +127,7 @@ BAREBOX_CMD_HELP_TEXT("Enable / disable a USB composite gadget on the USB device
 BAREBOX_CMD_HELP_TEXT("")
 BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT ("-a",   "Create CDC ACM function")
+BAREBOX_CMD_HELP_OPT ("-m",   "Automatically set USB OTG mode to peripheral")
 BAREBOX_CMD_HELP_OPT ("-s",   "Create Generic Serial function")
 BAREBOX_CMD_HELP_OPT ("-A [desc]",	"Create Android Fastboot function. If 'desc' is not provided,")
 BAREBOX_CMD_HELP_OPT ("",		"trying to use 'global.usbgadget.fastboot_function' variable.")
@@ -131,7 +139,7 @@ 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_OPTS("[-amsdAD]")
 	BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
 	BAREBOX_CMD_HELP(cmd_usbgadget_help)
 BAREBOX_CMD_END
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] usbgadget command: provide -m option to set usb mode
  2017-11-14  8:00 [PATCH v1] usbgadget command: provide -m option to set usb mode Oleksij Rempel
@ 2017-12-06  8:49 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2017-12-06  8:49 UTC (permalink / raw)
  To: Oleksij Rempel; +Cc: barebox

On Tue, Nov 14, 2017 at 09:00:56AM +0100, Oleksij Rempel wrote:
> if we optimize barebox for speed, then we can't use usbgadget autostart,
> which would set otg.mode automatically.
> Provide an option for usbgadget command to set otg.mode.
> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  commands/usbgadget.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/commands/usbgadget.c b/commands/usbgadget.c
> index 507871edd2..e5109f99cb 100644
> --- a/commands/usbgadget.c
> +++ b/commands/usbgadget.c
> @@ -34,15 +34,19 @@ static int do_usbgadget(int argc, char *argv[])
>  {
>  	int opt, ret;
>  	int acm = 1, create_serial = 0, fastboot_set = 0, fastboot_export_bbu = 0;
> +	int usb_mode_set = 0;
>  	const char *fastboot_opts = NULL, *dfu_opts = NULL;
>  	struct f_multi_opts *opts;
>  
> -	while ((opt = getopt(argc, argv, "asdA::D:b")) > 0) {
> +	while ((opt = getopt(argc, argv, "amsdA::D:b")) > 0) {
>  		switch (opt) {
>  		case 'a':
>  			acm = 1;
>  			create_serial = 1;
>  			break;
> +		case 'm':
> +			usb_mode_set = 1;
> +			break;
>  		case 's':
>  			acm = 0;
>  			create_serial = 1;
> @@ -101,6 +105,9 @@ static int do_usbgadget(int argc, char *argv[])
>  		opts->create_acm = acm;
>  	}
>  
> +	if (usb_mode_set)
> +		setenv("otg.mode", "peripheral");
> +

I introduced this otg device since I needed some way to switch otg to the
different modes specifically on i.MX. It was not meant as a general concept,
I'm thus a bit reluctant to put this into different commands.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-06  8:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-14  8:00 [PATCH v1] usbgadget command: provide -m option to set usb mode Oleksij Rempel
2017-12-06  8:49 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox