[PATCH v1 10/11] IOMUX: Introduce iomux_replace_device()
Andy Shevchenko
andriy.shevchenko at linux.intel.com
Thu Feb 11 16:09:43 CET 2021
Some console devices may appear or disappear at run time. In order to
support such a hotplug mechanism introduce a new iomux_replace_device()
helper to update the list of devices without altering environment.
Signed-off-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
---
common/iomux.c | 33 +++++++++++++++++++++++++++++++++
include/iomux.h | 1 +
2 files changed, 34 insertions(+)
diff --git a/common/iomux.c b/common/iomux.c
index 5290b13b668b..b9088aa3b58b 100644
--- a/common/iomux.c
+++ b/common/iomux.c
@@ -139,4 +139,37 @@ int iomux_doenv(const int console, const char *arg)
free(old_set);
return 0;
}
+
+int iomux_replace_device(const int console, const char *old, const char *new)
+{
+ struct stdio_dev *dev;
+ char *arg = NULL; /* Initial empty list */
+ int size = 1; /* For NUL terminator */
+ int i, ret;
+
+ for_each_console_dev(i, console, dev) {
+ const char *name = strcmp(dev->name, old) ? dev->name : new;
+ char *tmp;
+
+ /* Append name with a ',' (comma) separator */
+ tmp = realloc(arg, size + strlen(name) + 1);
+ if (!tmp) {
+ free(arg);
+ return -ENOMEM;
+ }
+
+ strcat(tmp, ",");
+ strcat(tmp, name);
+
+ arg = tmp;
+ size = strlen(tmp) + 1;
+ }
+
+ ret = iomux_doenv(console, arg);
+ if (ret)
+ ret = -EINVAL;
+
+ free(arg);
+ return ret;
+}
#endif /* CONSOLE_MUX */
diff --git a/include/iomux.h b/include/iomux.h
index bd4a143b1e60..37f5f6dee69f 100644
--- a/include/iomux.h
+++ b/include/iomux.h
@@ -31,6 +31,7 @@ extern int cd_count[MAX_FILES];
int iomux_match_device(struct stdio_dev **, const int, struct stdio_dev *);
int iomux_doenv(const int, const char *);
+int iomux_replace_device(const int, const char *, const char *);
void iomux_printdevs(const int);
#endif /* _IO_MUX_H */
--
2.30.0
More information about the U-Boot
mailing list