mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 32/50] ARM: omap: usbboot: Enable USB communication when needed
Date: Fri,  3 Mar 2023 10:21:13 +0100	[thread overview]
Message-ID: <20230303092131.3063587-33-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20230303092131.3063587-1-s.hauer@pengutronix.de>

Instead of activating USB communication unconditionally in an initcall,
let the users activate it once they need it. This gets us rid of an
initcall that is not protected against running on foreign SoCs.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/archosg9/board.c      | 12 ++++++++----
 arch/arm/mach-omap/omap4_rom_usb.c    |  4 +++-
 drivers/serial/serial_omap4_usbboot.c |  6 ++++++
 fs/omap4_usbbootfs.c                  |  3 ++-
 include/mach/omap/omap4_rom_usb.h     | 13 +++++++++++++
 5 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/arch/arm/boards/archosg9/board.c b/arch/arm/boards/archosg9/board.c
index 8aa35262d3..547d21d6ca 100644
--- a/arch/arm/boards/archosg9/board.c
+++ b/arch/arm/boards/archosg9/board.c
@@ -33,13 +33,17 @@
 
 static int archosg9_console_init(void)
 {
+	int ret;
+
 	barebox_set_model("Archos G9");
 	barebox_set_hostname("g9");
 
-	if (IS_ENABLED(CONFIG_DRIVER_SERIAL_OMAP4_USBBOOT) &&
-			omap4_usbboot_ready()) {
-		add_generic_device("serial_omap4_usbboot", DEVICE_ID_DYNAMIC
-			, NULL, 0, 0, 0, NULL);
+	if (IS_ENABLED(CONFIG_DRIVER_SERIAL_OMAP4_USBBOOT)) {
+		ret = omap4_usbboot_open();
+		if (!ret) {
+			add_generic_device("serial_omap4_usbboot", DEVICE_ID_DYNAMIC
+				, NULL, 0, 0, 0, NULL);
+		}
 	}
 	if (IS_ENABLED(CONFIG_DRIVER_SERIAL_NS16550)) {
 		omap44xx_add_uart1();
diff --git a/arch/arm/mach-omap/omap4_rom_usb.c b/arch/arm/mach-omap/omap4_rom_usb.c
index a3e447128f..01c5565a68 100644
--- a/arch/arm/mach-omap/omap4_rom_usb.c
+++ b/arch/arm/mach-omap/omap4_rom_usb.c
@@ -46,6 +46,9 @@ int omap4_usbboot_open(void)
 	int n;
 	u32 base;
 
+	if (omap4_usbboot_ready())
+		return 0;
+
 	if (omap4_revision() >= OMAP4460_ES1_0)
 		base = PUBLIC_API_BASE_4460;
 	else
@@ -82,7 +85,6 @@ int omap4_usbboot_open(void)
 	omap4_usbboot_puts("USB communications initialized\n");
 	return 0;
 }
-core_initcall(omap4_usbboot_open);
 
 int omap4_usbboot_ready(void){
 	return omap4_usbboot_data.ready;
diff --git a/drivers/serial/serial_omap4_usbboot.c b/drivers/serial/serial_omap4_usbboot.c
index 463d217f97..709398966f 100644
--- a/drivers/serial/serial_omap4_usbboot.c
+++ b/drivers/serial/serial_omap4_usbboot.c
@@ -49,6 +49,12 @@ static int serial_omap4_usbboot_getc(struct console_device *cdev)
 static int serial_omap4_usbboot_probe(struct device *dev)
 {
 	struct serial_omap4_usbboot_priv *priv;
+	int ret;
+
+	ret = omap4_usbboot_open();
+	if (ret)
+		return ret;
+	
 	priv = xzalloc(sizeof(*priv));
 
 	priv->cdev.dev = dev;
diff --git a/fs/omap4_usbbootfs.c b/fs/omap4_usbbootfs.c
index 9b0755d539..30392d1192 100644
--- a/fs/omap4_usbbootfs.c
+++ b/fs/omap4_usbbootfs.c
@@ -143,8 +143,9 @@ static int omap4_usbbootfs_stat(struct device *dev, const char *filename,
 
 static int omap4_usbbootfs_probe(struct device *dev)
 {
-	return 0;
+	return omap4_usbboot_open();
 }
+
 static void omap4_usbbootfs_remove(struct device *dev)
 {
 }
diff --git a/include/mach/omap/omap4_rom_usb.h b/include/mach/omap/omap4_rom_usb.h
index bf8bd159ad..66295eb11e 100644
--- a/include/mach/omap/omap4_rom_usb.h
+++ b/include/mach/omap/omap4_rom_usb.h
@@ -125,8 +125,21 @@ struct omap4_usbboot {
 	int ready;
 };
 
+#ifdef CONFIG_OMAP4_USBBOOT
 int omap4_usbboot_open(void);
 int omap4_usbboot_ready(void);
+#else
+static inline int omap4_usbboot_open(void)
+{
+	return -ENODEV;
+}
+
+static inline int omap4_usbboot_ready(void)
+{
+	return 0;
+}
+#endif
+
 void omap4_usbboot_close(void);
 
 void omap4_usbboot_queue_read(void *data, unsigned len);
-- 
2.30.2




  parent reply	other threads:[~2023-03-03  9:26 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-03  9:20 [PATCH 00/50] ARM: multi-arch support Sascha Hauer
2023-03-03  9:20 ` [PATCH 01/50] ARM: i.MX: Move mach header files to include/mach/imx Sascha Hauer
2023-03-03  9:20 ` [PATCH 02/50] ARM: Rockchip: Move mach header files to include/mach/rockchip Sascha Hauer
2023-03-03  9:20 ` [PATCH 03/50] ARM: Zynqmp: Move mach header files to include/mach/zynqmp Sascha Hauer
2023-03-03  9:20 ` [PATCH 04/50] ARM: mvebu: Move mach header files to include/mach/mvebu Sascha Hauer
2023-03-03  9:20 ` [PATCH 05/50] ARM: davinci: Move mach header files to include/mach/davinci Sascha Hauer
2023-03-03  9:20 ` [PATCH 06/50] ARM: bcm283x: Move mach header files to include/mach/bcm283x Sascha Hauer
2023-03-03  9:20 ` [PATCH 07/50] ARM: stm32mp: Move mach header files to include/mach/stm32mp Sascha Hauer
2023-03-03  9:20 ` [PATCH 08/50] ARM: zynq: Move mach header files to include/mach/zynq Sascha Hauer
2023-03-03  9:20 ` [PATCH 09/50] ARM: vexpress: Move mach header files to include/mach/vexpress Sascha Hauer
2023-03-03  9:20 ` [PATCH 10/50] ARM: versatile: Move mach header files to include/mach/versatile Sascha Hauer
2023-03-03  9:20 ` [PATCH 11/50] ARM: layerscape: Move mach header files to include/mach/layerscape Sascha Hauer
2023-03-03  9:20 ` [PATCH 12/50] ARM: tegra: Move mach header files to include/mach/tegra Sascha Hauer
2023-03-03  9:20 ` [PATCH 13/50] ARM: uemd: Move mach header files to include/mach/uemd Sascha Hauer
2023-03-03  9:20 ` [PATCH 14/50] ARM: socfpga: Move mach header files to include/mach/socfpga Sascha Hauer
2023-03-03  9:20 ` [PATCH 15/50] ARM: pxa: Move mach header files to include/mach/pxa Sascha Hauer
2023-03-03  9:20 ` [PATCH 16/50] ARM: omap: Move mach header files to include/mach/omap Sascha Hauer
2023-03-03  9:20 ` [PATCH 17/50] ARM: nomadik: Move mach header files to include/mach/nomadik Sascha Hauer
2023-03-03  9:20 ` [PATCH 18/50] ARM: mxs: Move mach header files to include/mach/mxs Sascha Hauer
2023-03-03  9:21 ` [PATCH 19/50] ARM: ep93xx: Move mach header files to include/mach/ep93xx Sascha Hauer
2023-03-03  9:21 ` [PATCH 20/50] ARM: digic: Move mach header files to include/mach/digic Sascha Hauer
2023-03-03  9:21 ` [PATCH 21/50] ARM: clps711x: Move mach header files to include/mach/clps711x Sascha Hauer
2023-03-03  9:21 ` [PATCH 22/50] ARM: at91: Move mach header files to include/mach/at91 Sascha Hauer
2023-03-03  9:21 ` [PATCH 23/50] ARM: Drop mach dir include path Sascha Hauer
2023-03-03  9:21 ` [PATCH 24/50] include/mach/: use unique double inclusion protectors Sascha Hauer
2023-03-03  9:21 ` [PATCH 25/50] ARM: i.MX: Only provide PUTC_LL() when activated Sascha Hauer
2023-03-03  9:21 ` [PATCH 26/50] debug_ll ns16550: Do not define PUTC_LL() Sascha Hauer
2023-03-03  9:21 ` [PATCH 27/50] debug_ll ns16550: Use CONFIG_BAUDRATE Sascha Hauer
2023-03-03  9:21 ` [PATCH 28/50] ARM: Rockchip: Use ns16550 debug_ll helper Sascha Hauer
2023-03-03  9:21 ` [PATCH 29/50] ARM: Rockchip: Only provide PUTC_LL() when activated Sascha Hauer
2023-03-03  9:21 ` [PATCH 30/50] ARM: omap: Use ns16550 debug_ll helper Sascha Hauer
2023-03-03  9:21 ` [PATCH 31/50] ARM: omap: Only provide PUTC_LL() when activated Sascha Hauer
2023-03-03  9:21 ` Sascha Hauer [this message]
2023-03-03  9:21 ` [PATCH 33/50] ARM: omap: Make multi-arch safe Sascha Hauer
2023-03-03  9:21 ` [PATCH 34/50] ARM: Rockchip: Make safe for multi-arch Sascha Hauer
2023-03-03  9:21 ` [PATCH 35/50] pm_domains: Enable explicitly when we have power-domain providers Sascha Hauer
2023-03-03  9:21 ` [PATCH 36/50] ARM: add multi-arch support Sascha Hauer
2023-03-03  9:21 ` [PATCH 37/50] ARM: omap: Add support for multi-arch Sascha Hauer
2023-03-03  9:21 ` [PATCH 38/50] ARM: zynqmp: Add multi-arch support Sascha Hauer
2023-03-03  9:21 ` [PATCH 39/50] ARM: i.MX: Add missing include Sascha Hauer
2023-03-03  9:21 ` [PATCH 40/50] ARM: i.MX: move board selection into menu Sascha Hauer
2023-03-03  9:21 ` [PATCH 41/50] ARM: stm32mp: Only provide PUTC_LL() when activated Sascha Hauer
2023-03-03  9:21 ` [PATCH 42/50] ARM: stm32mp: Make safe for multi-arch Sascha Hauer
2023-03-03  9:21 ` [PATCH 43/50] ARM: stm32mp: Add multi-arch support Sascha Hauer
2023-03-03  9:21 ` [PATCH 44/50] ARM: vexpress: Drop unnecessary initcall Sascha Hauer
2023-03-03  9:21 ` [PATCH 45/50] ARM: vexpress: Only provide PUTC_LL() when activated Sascha Hauer
2023-03-03  9:21 ` [PATCH 46/50] ARM: vexpress: Add multi-arch support Sascha Hauer
2023-03-03  9:21 ` [PATCH 47/50] ARM: bcm283x: Only provide PUTC_LL() when activated Sascha Hauer
2023-03-03  9:21 ` [PATCH 48/50] ARM: bcm283x: Add multi-arch support Sascha Hauer
2023-03-03  9:21 ` [PATCH 49/50] ARM: Add multi_v7_defconfig Sascha Hauer
2023-03-03  9:21 ` [PATCH 50/50] ARM: Add multi_v8_defconfig Sascha Hauer

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=20230303092131.3063587-33-s.hauer@pengutronix.de \
    --to=s.hauer@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