#include <exports.h>
#include <env_internal.h>
#include <watchdog.h>
+#include <asm/global_data.h>
#include <linux/delay.h>
DECLARE_GLOBAL_DATA_PTR;
struct stdio_dev **console_devices[MAX_FILES];
int cd_count[MAX_FILES];
-static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev)
+static void console_devices_set(int file, struct stdio_dev *dev)
{
console_devices[file][0] = dev;
+ cd_count[file] = 1;
+}
+
+/**
+ * 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;
+
+ for (i = 0; i < ARRAY_SIZE(cd_count); i++) {
+ if (i == file)
+ continue;
+
+ if (iomux_match_device(console_devices[i], cd_count[i], sdev) >= 0)
+ return false;
+ }
+ return true;
}
/*
int prev;
prev = disable_ctrlc(1);
- for (i = 0; i < cd_count[file]; i++) {
- dev = console_devices[file][i];
+ for_each_console_dev(i, file, dev) {
if (dev->tstc != NULL) {
ret = dev->tstc(dev);
if (ret > 0) {
int i;
struct stdio_dev *dev;
- for (i = 0; i < cd_count[file]; i++) {
- dev = console_devices[file][i];
+ for_each_console_dev(i, file, dev) {
if (dev->putc != NULL)
dev->putc(dev, c);
}
int i;
struct stdio_dev *dev;
- for (i = 0; i < cd_count[file]; i++) {
- bool is_serial;
+ for_each_console_dev(i, file, dev) {
+ bool is_serial = console_dev_is_serial(dev);
- dev = console_devices[file][i];
- is_serial = console_dev_is_serial(dev);
if (dev->puts && serial_only == is_serial)
dev->puts(dev, s);
}
int i;
struct stdio_dev *dev;
- for (i = 0; i < cd_count[file]; i++) {
- dev = console_devices[file][i];
+ for_each_console_dev(i, file, dev) {
if (dev->puts != NULL)
dev->puts(dev, s);
}
#endif
#else
-static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev)
+static void 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]);
#endif
#endif /* CONIFIG_IS_ENABLED(CONSOLE_MUX) */
+static void __maybe_unused console_setfile_and_devices(int file, struct stdio_dev *dev)
+{
+ console_setfile(file, dev);
+ console_devices_set(file, dev);
+}
+
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);
void console_stop(int file, struct stdio_dev *sdev)
{
+ if (!console_needs_start_stop(file, sdev))
+ return;
+
if (sdev->stop)
sdev->stop(sdev);
}
/** U-Boot INIT FUNCTIONS *************************************************/
-struct stdio_dev *search_device(int flags, const char *name)
+struct stdio_dev *console_search_dev(int flags, const char *name)
{
struct stdio_dev *dev;
struct stdio_dev *dev;
/* Check for valid file */
- switch (file) {
- case stdin:
- flag = DEV_FLAGS_INPUT;
- break;
- case stdout:
- case stderr:
- flag = DEV_FLAGS_OUTPUT;
- break;
- default:
- return -1;
- }
+ flag = stdio_file_to_flags(file);
+ if (flag < 0)
+ return flag;
/* Check for valid device name */
- dev = search_device(flag, devname);
+ dev = console_search_dev(flag, devname);
if (dev)
return console_setfile(file, dev);
stderrname = env_get("stderr");
if (OVERWRITE_CONSOLE == 0) { /* if not overwritten by config switch */
- inputdev = search_device(DEV_FLAGS_INPUT, stdinname);
- outputdev = search_device(DEV_FLAGS_OUTPUT, stdoutname);
- errdev = search_device(DEV_FLAGS_OUTPUT, stderrname);
+ inputdev = console_search_dev(DEV_FLAGS_INPUT, stdinname);
+ outputdev = console_search_dev(DEV_FLAGS_OUTPUT, stdoutname);
+ errdev = console_search_dev(DEV_FLAGS_OUTPUT, stderrname);
if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
iomux_err = iomux_doenv(stdin, stdinname);
iomux_err += iomux_doenv(stdout, stdoutname);
}
/* if the devices are overwritten or not found, use default device */
if (inputdev == NULL) {
- inputdev = search_device(DEV_FLAGS_INPUT, "serial");
+ inputdev = console_search_dev(DEV_FLAGS_INPUT, "serial");
}
if (outputdev == NULL) {
- outputdev = search_device(DEV_FLAGS_OUTPUT, "serial");
+ outputdev = console_search_dev(DEV_FLAGS_OUTPUT, "serial");
}
if (errdev == NULL) {
- errdev = search_device(DEV_FLAGS_OUTPUT, "serial");
+ errdev = console_search_dev(DEV_FLAGS_OUTPUT, "serial");
}
/* Initializes output console first */
if (outputdev != NULL) {
gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
-#if 0
- /* If nothing usable installed, use only the initial console */
- if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
- return 0;
-#endif
print_pre_console_buffer(flushpoint);
return 0;
}
*/
if (IS_ENABLED(CONFIG_SPLASH_SCREEN) && env_get("splashimage")) {
if (!(gd->flags & GD_FLG_SILENT))
- outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
+ outputdev = console_search_dev (DEV_FLAGS_OUTPUT, "serial");
}
/* Scan devices looking for input and output devices */
/* Initializes output console first */
if (outputdev != NULL) {
- console_setfile(stdout, outputdev);
- console_setfile(stderr, outputdev);
- console_devices_set(stdout, outputdev);
- console_devices_set(stderr, outputdev);
+ console_setfile_and_devices(stdout, outputdev);
+ console_setfile_and_devices(stderr, outputdev);
}
/* Initializes input console */
- if (inputdev != NULL) {
- console_setfile(stdin, inputdev);
- console_devices_set(stdin, inputdev);
- }
+ if (inputdev != NULL)
+ console_setfile_and_devices(stdin, inputdev);
if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET))
stdio_print_current_devices();
gd->flags |= GD_FLG_DEVINIT; /* device initialization completed */
-#if 0
- /* If nothing usable installed, use only the initial console */
- if ((stdio_devices[stdin] == NULL) && (stdio_devices[stdout] == NULL))
- return 0;
-#endif
print_pre_console_buffer(flushpoint);
return 0;
}