aboutsummaryrefslogtreecommitdiff
path: root/common/console.c
diff options
context:
space:
mode:
authorAndy Shevchenko2020-12-21 14:30:01 +0200
committerTom Rini2021-01-15 14:37:03 -0500
commit95aaf40254b44d614dc2eaca89b31f98598e4f27 (patch)
treec3a7ffa91b3bd9f971fb8bc2143221f07579d83b /common/console.c
parent41f668b97c7ac8d519f15961b67fc52817115701 (diff)
console: Keep ->start() and ->stop() balanced
There is no need to call ->start() for already started device. All the same, there is no need to call ->stop() for devices still in use. For now enforce this only for IOMUX case. Cc: Simon Glass <sjg@chromium.org> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/common/console.c b/common/console.c
index 5b113da9d57..92e9bc0ec13 100644
--- a/common/console.c
+++ b/common/console.c
@@ -237,6 +237,32 @@ static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev)
console_devices[file][0] = dev;
}
+/**
+ * console_needs_start_stop() - check if we need to start or stop the STDIO device
+ * @file: STDIO file
+ * @sdev: STDIO device in question
+ *
+ * This function checks if we need to start or stop the stdio device used for
+ * a console. For IOMUX case it simply enforces one time start and one time
+ * stop of the device independently of how many STDIO files are using it. In
+ * other words, we start console once before first STDIO device wants it and
+ * stop after the last is gone.
+ */
+static bool console_needs_start_stop(int file, struct stdio_dev *sdev)
+{
+ int i, j;
+
+ for (i = 0; i < ARRAY_SIZE(cd_count); i++) {
+ if (i == file)
+ continue;
+
+ for (j = 0; j < cd_count[i]; j++)
+ if (console_devices[i][j] == sdev)
+ return false;
+ }
+ return true;
+}
+
/*
* This depends on tstc() always being called before getchar().
* This is guaranteed to be true because this routine is called
@@ -346,6 +372,11 @@ static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev)
{
}
+static inline bool console_needs_start_stop(int file, struct stdio_dev *sdev)
+{
+ return true;
+}
+
static inline int console_getc(int file)
{
return stdio_devices[file]->getc(stdio_devices[file]);
@@ -389,6 +420,9 @@ int console_start(int file, struct stdio_dev *sdev)
{
int error;
+ if (!console_needs_start_stop(file, sdev))
+ return 0;
+
/* Start new device */
if (sdev->start) {
error = sdev->start(sdev);
@@ -401,6 +435,9 @@ int console_start(int file, struct stdio_dev *sdev)
void console_stop(int file, struct stdio_dev *sdev)
{
+ if (!console_needs_start_stop(file, sdev))
+ return;
+
if (sdev->stop)
sdev->stop(sdev);
}