3 * Gary Jennejohn, DENX Software Engineering GmbH, garyj@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #ifdef CONFIG_CONSOLE_MUX
29 void iomux_printdevs(const int console)
34 for (i = 0; i < cd_count[console]; i++) {
35 dev = console_devices[console][i];
36 printf("%s ", dev->name);
41 /* This tries to preserve the old list if an error occurs. */
42 int iomux_doenv(const int console, const char *arg)
44 char *console_args, *temp, **start;
45 int i, j, k, io_flag, cs_idx, repeat;
49 console_args = strdup(arg);
50 if (console_args == NULL)
53 * Check whether a comma separated list of devices was
54 * entered and count how many devices were entered.
55 * The array start[] has pointers to the beginning of
56 * each device name (up to MAX_CONSARGS devices).
58 * Have to do this twice - once to count the number of
59 * commas and then again to populate start.
64 temp = strchr(temp, ',');
70 /* There's always one entry more than the number of commas. */
74 start = (char **)malloc(i * sizeof(char *));
80 start[0] = console_args;
82 temp = strchr(start[i++], ',');
88 cons_set = (device_t **)calloc(i, sizeof(device_t *));
89 if (cons_set == NULL) {
97 io_flag = DEV_FLAGS_INPUT;
101 io_flag = DEV_FLAGS_OUTPUT;
111 for (j = 0; j < i; j++) {
113 * Check whether the device exists and is valid.
114 * console_assign() also calls search_device(),
115 * but I need the pointer to the device.
117 dev = search_device(io_flag, start[j]);
121 * Prevent multiple entries for a device.
124 for (k = 0; k < cs_idx; k++) {
125 if (dev == cons_set[k]) {
133 * Try assigning the specified device.
134 * This could screw up the console settings for apps.
136 if (console_assign(console, start[j]) < 0)
138 #ifdef CONFIG_SERIAL_MULTI
140 * This was taken from common/cmd_nvedit.c.
141 * This will never work because serial_assign() returns
142 * 1 upon error, not -1.
143 * This would almost always return an error anyway because
144 * serial_assign() expects the name of a serial device, like
145 * serial_smc, but the user generally only wants to set serial.
147 if (serial_assign(start[j]) < 0)
150 cons_set[cs_idx++] = dev;
154 /* failed to set any console */
159 /* Works even if console_devices[console] is NULL. */
160 console_devices[console] =
161 (device_t **)realloc(console_devices[console],
162 cs_idx * sizeof(device_t *));
163 if (console_devices[console] == NULL) {
167 memcpy(console_devices[console], cons_set, cs_idx *
170 cd_count[console] = cs_idx;
175 #endif /* CONFIG_CONSOLE_MUX */