diff mbox series

[v2,24/28] serial: smh: Initialize serial only if semihosting is enabled

Message ID 20220310205059.499269-25-sean.anderson@seco.com
State Superseded
Delegated to: Tom Rini
Headers show
Series arm: semihosting: Cleanups and new features | expand

Commit Message

Sean Anderson March 10, 2022, 8:50 p.m. UTC
If semihosting is disabled, then the user has no debugger attached, and
will not see any messages. Don't create a serial device in this
instance, to (hopefully) fall back on another working serial device.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---

Changes in v2:
- New

 drivers/serial/serial_semihosting.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/serial/serial_semihosting.c b/drivers/serial/serial_semihosting.c
index b43683c6f1..706c1aabe1 100644
--- a/drivers/serial/serial_semihosting.c
+++ b/drivers/serial/serial_semihosting.c
@@ -25,9 +25,17 @@  static const struct dm_serial_ops smh_serial_ops = {
 	.getc = smh_serial_getc,
 };
 
+static int smh_serial_bind(struct udevice *dev)
+{
+	if (semihosting_enabled())
+		return 0;
+	return -ENOENT;
+}
+
 U_BOOT_DRIVER(smh_serial) = {
 	.name	= "serial_semihosting",
 	.id	= UCLASS_SERIAL,
+	.bind	= smh_serial_bind,
 	.ops	= &smh_serial_ops,
 	.flags	= DM_FLAG_PRE_RELOC,
 };
@@ -83,7 +91,8 @@  struct serial_device serial_smh_device = {
 
 void smh_serial_initialize(void)
 {
-	serial_register(&serial_smh_device);
+	if (semihosting_enabled())
+		serial_register(&serial_smh_device);
 }
 
 __weak struct serial_device *default_serial_console(void)