[PATCH 3/8] console: support set baudrate for fixed baudrate drivers

Antony Pavlov antonynpavlov at gmail.com
Tue Aug 17 03:04:30 PDT 2021


There are console drivers (linux, virtio, litex)
that don't support baud rate setting and has
no setbrg (set baudrate) callback, so
console_set_baudrate() returns -ENOSYS.

At the other hand console_set_baudrate() SUCCESS
return value is needed for the loadx/loady commands
correct work.

See discussion here:

  http://lists.infradead.org/pipermail/barebox/2021-May/036237.html

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 common/console.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/common/console.c b/common/console.c
index ad1a6aaab2..c902239e31 100644
--- a/common/console.c
+++ b/common/console.c
@@ -165,12 +165,12 @@ int console_set_baudrate(struct console_device *cdev, unsigned baudrate)
 	int ret;
 	unsigned char c;
 
-	if (!cdev->setbrg)
-		return -ENOSYS;
-
 	if (cdev->baudrate == baudrate)
 		return 0;
 
+	if (!cdev->setbrg)
+		return -ENOSYS;
+
 	/*
 	 * If the device is already active, change its baudrate.
 	 * The baudrate of an inactive device will be set at activation time.
@@ -336,11 +336,13 @@ int console_register(struct console_device *newcdev)
 		ret = newcdev->setbrg(newcdev, baudrate);
 		if (ret)
 			return ret;
-		newcdev->baudrate_param = newcdev->baudrate = baudrate;
+		newcdev->baudrate_param = baudrate;
 		dev_add_param_uint32(dev, "baudrate", console_baudrate_set,
 			NULL, &newcdev->baudrate_param, "%u", newcdev);
 	}
 
+	newcdev->baudrate = baudrate;
+
 	if (newcdev->putc && !newcdev->puts)
 		newcdev->puts = __console_puts;
 
-- 
2.32.0




More information about the barebox mailing list