From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 11/12] usbgadget: refactor usbgadget_register to accept array
Date: Mon, 15 Feb 2021 11:37:04 +0100 [thread overview]
Message-ID: <20210215103704.32537-12-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20210215103704.32537-1-a.fatoum@pengutronix.de>
usbgadget_register currently takes 6 arguments. Instead of increasing
them to 8 to support the new usb mass storage gadget, rewrite it to
accept a pointer to a struct with all the options instead.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/usbgadget.c | 19 +++++++++----------
common/usbgadget.c | 31 +++++++++++++++++++++----------
include/usb/gadget-multi.h | 15 ++++++++++++---
3 files changed, 42 insertions(+), 23 deletions(-)
diff --git a/commands/usbgadget.c b/commands/usbgadget.c
index 3b115f147d80..07094026db71 100644
--- a/commands/usbgadget.c
+++ b/commands/usbgadget.c
@@ -18,26 +18,25 @@
static int do_usbgadget(int argc, char *argv[])
{
+ struct usbgadget_funcs funcs = {};
int opt;
- bool acm = false, dfu = false, fastboot = false, export_bbu = false;
- const char *fastboot_opts = NULL, *dfu_opts = NULL;
while ((opt = getopt(argc, argv, "asdA::D::b")) > 0) {
switch (opt) {
case 'a':
case 's':
- acm = true;
+ funcs.flags |= USBGADGET_ACM;
break;
case 'D':
- dfu = true;
- dfu_opts = optarg;
+ funcs.flags |= USBGADGET_DFU;
+ funcs.dfu_opts = optarg;
break;
case 'A':
- fastboot = true;
- fastboot_opts = optarg;
+ funcs.flags |= USBGADGET_FASTBOOT;
+ funcs.fastboot_opts = optarg;
break;
case 'b':
- export_bbu = true;
+ funcs.flags |= USBGADGET_EXPORT_BBU;
break;
case 'd':
usb_multi_unregister();
@@ -47,8 +46,8 @@ static int do_usbgadget(int argc, char *argv[])
}
}
- return usbgadget_register(dfu, dfu_opts, fastboot, fastboot_opts, acm,
- export_bbu);
+
+ return usbgadget_register(&funcs);
}
BAREBOX_CMD_HELP_START(usbgadget)
diff --git a/common/usbgadget.c b/common/usbgadget.c
index feec0b6634be..48e2ea9a349c 100644
--- a/common/usbgadget.c
+++ b/common/usbgadget.c
@@ -32,14 +32,20 @@ static struct file_list *parse(const char *files)
return list;
}
-int usbgadget_register(bool dfu, const char *dfu_opts,
- bool fastboot, const char *fastboot_opts,
- bool acm, bool export_bbu)
+int usbgadget_register(const struct usbgadget_funcs *funcs)
{
int ret;
+ int flags = funcs->flags;
struct device_d *dev;
struct f_multi_opts *opts;
const char *fastboot_partitions = get_fastboot_partitions();
+ const char *dfu_opts = funcs->dfu_opts;
+ const char *fastboot_opts = funcs->fastboot_opts;
+ bool dfu, fastboot, acm;
+
+ dfu = flags & USBGADGET_DFU;
+ fastboot = flags & USBGADGET_FASTBOOT;
+ acm = flags & USBGADGET_ACM;
if (dfu && !dfu_opts && dfu_function && *dfu_function)
dfu_opts = dfu_function;
@@ -66,7 +72,7 @@ int usbgadget_register(bool dfu, const char *dfu_opts,
if (fastboot_opts) {
opts->fastboot_opts.files = parse(fastboot_opts);
- opts->fastboot_opts.export_bbu = export_bbu;
+ opts->fastboot_opts.export_bbu = flags & USBGADGET_EXPORT_BBU;
}
if (dfu_opts)
@@ -93,18 +99,23 @@ int usbgadget_register(bool dfu, const char *dfu_opts,
static int usbgadget_autostart_set(struct param_d *param, void *ctx)
{
+ struct usbgadget_funcs funcs = {};
static bool started;
- bool fastboot_bbu = get_fastboot_bbu();
- int err;
if (!IS_ENABLED(CONFIG_USB_GADGET_AUTOSTART) || !autostart || started)
return 0;
- err = usbgadget_register(true, NULL, true, NULL, acm, fastboot_bbu);
- if (!err)
- started = true;
+ if (get_fastboot_bbu())
+ funcs.flags |= USBGADGET_EXPORT_BBU;
+
+ if (acm)
+ funcs.flags |= USBGADGET_ACM;
+
+ funcs.flags |= USBGADGET_DFU | USBGADGET_FASTBOOT;
+
+ started = 1;
- return err;
+ return usbgadget_register(&funcs);
}
static int usbgadget_globalvars_init(void)
diff --git a/include/usb/gadget-multi.h b/include/usb/gadget-multi.h
index 9bb6c889f3e9..244bdd946f91 100644
--- a/include/usb/gadget-multi.h
+++ b/include/usb/gadget-multi.h
@@ -16,8 +16,17 @@ int usb_multi_register(struct f_multi_opts *opts);
void usb_multi_unregister(void);
void usb_multi_opts_release(struct f_multi_opts *opts);
-int usbgadget_register(bool dfu, const char *dfu_opts,
- bool fastboot, const char *fastboot_opts,
- bool acm, bool export_bbu);
+#define USBGADGET_EXPORT_BBU (1 << 0)
+#define USBGADGET_ACM (1 << 1)
+#define USBGADGET_DFU (1 << 2)
+#define USBGADGET_FASTBOOT (1 << 3)
+
+struct usbgadget_funcs {
+ int flags;
+ const char *fastboot_opts;
+ const char *dfu_opts;
+};
+
+int usbgadget_register(const struct usbgadget_funcs *funcs);
#endif /* __USB_GADGET_MULTI_H */
--
2.29.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-02-15 10:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-15 10:36 [PATCH 00/12] poller: run pollers as proper coroutines (green threads) Ahmad Fatoum
2021-02-15 10:36 ` [PATCH 01/12] common: add coroutine support Ahmad Fatoum
2021-02-15 10:36 ` [PATCH 02/12] poller: run pollers as proper coroutines if architecture supports it Ahmad Fatoum
2021-02-15 10:36 ` [PATCH 03/12] ARM: asm: setjmp: annotate setjmp/longjmp for GCC Ahmad Fatoum
2021-02-15 10:36 ` [PATCH 04/12] ARM: asm: setjmp: implement coroutine dependency initjmp() Ahmad Fatoum
2021-02-15 10:36 ` [PATCH 05/12] sandbox: asm: implement setjmp/longjmp/initjmp Ahmad Fatoum
2021-02-15 10:36 ` [PATCH 06/12] poller: command: add new coroutine check Ahmad Fatoum
2021-02-15 10:37 ` [PATCH 07/12] slice: have assert_command_context() yield until true if possible Ahmad Fatoum
2021-02-15 10:37 ` [PATCH 08/12] poller: implement basic Linux-like completion API Ahmad Fatoum
2021-02-15 10:37 ` [PATCH 09/12] include: add kthread wrappers for pollers Ahmad Fatoum
2021-02-15 12:31 ` Sascha Hauer
2021-02-15 10:37 ` [PATCH 10/12] usbgadget: ums: run gadget loop in a background coroutine if possible Ahmad Fatoum
2021-02-15 10:37 ` Ahmad Fatoum [this message]
2021-02-15 10:37 ` [PATCH 12/12] usbgadget: multi: wire mass storage gadget into composite gadget Ahmad Fatoum
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=20210215103704.32537-12-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox