1 // SPDX-License-Identifier: GPL-2.0+
4 * Gary Jennejohn, DENX Software Engineering GmbH, garyj@denx.de.
12 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
13 void iomux_printdevs(const int console)
16 struct stdio_dev *dev;
18 for (i = 0; i < cd_count[console]; i++) {
19 dev = console_devices[console][i];
20 printf("%s ", dev->name);
25 /* This tries to preserve the old list if an error occurs. */
26 int iomux_doenv(const int console, const char *arg)
28 char *console_args, *temp, **start;
29 int i, j, k, io_flag, cs_idx, repeat;
30 struct stdio_dev **cons_set, **old_set;
31 struct stdio_dev *dev;
33 console_args = strdup(arg);
34 if (console_args == NULL)
37 * Check whether a comma separated list of devices was
38 * entered and count how many devices were entered.
39 * The array start[] has pointers to the beginning of
40 * each device name (up to MAX_CONSARGS devices).
42 * Have to do this twice - once to count the number of
43 * commas and then again to populate start.
48 /* There's always one entry more than the number of commas. */
51 temp = strchr(temp, ',');
57 start = (char **)malloc(i * sizeof(char *));
63 start[0] = console_args;
65 temp = strchr(start[i++], ',');
71 cons_set = (struct stdio_dev **)calloc(i, sizeof(struct stdio_dev *));
72 if (cons_set == NULL) {
80 io_flag = DEV_FLAGS_INPUT;
84 io_flag = DEV_FLAGS_OUTPUT;
94 for (j = 0; j < i; j++) {
96 * Check whether the device exists and is valid.
97 * console_assign() also calls console_search_dev(),
98 * but I need the pointer to the device.
100 dev = console_search_dev(io_flag, start[j]);
104 * Prevent multiple entries for a device.
107 for (k = 0; k < cs_idx; k++) {
108 if (dev == cons_set[k]) {
116 * Try assigning the specified device.
117 * This could screw up the console settings for apps.
119 if (console_assign(console, start[j]) < 0)
121 cons_set[cs_idx++] = dev;
125 /* failed to set any console */
131 old_set = console_devices[console];
132 repeat = cd_count[console];
134 console_devices[console] = cons_set;
135 cd_count[console] = cs_idx;
137 /* Stop dropped consoles */
138 for (i = 0; i < repeat; i++) {
139 for (j = 0; j < cs_idx; j++) {
140 if (old_set[i] == cons_set[j])
144 console_stop(console, old_set[i]);
150 #endif /* CONSOLE_MUX */