Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 2 | /* |
Heiko Schocher | e0e55bc | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 3 | * Copyright (C) 2009 Sergey Kubushyn <ksi@koi8.net> |
| 4 | * |
| 5 | * Changes for multibus/multiadapter I2C support. |
| 6 | * |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 7 | * (C) Copyright 2000 |
| 8 | * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <config.h> |
Simon Glass | d3d4035 | 2015-10-18 21:17:15 -0600 | [diff] [blame] | 12 | #include <dm.h> |
Simon Glass | 5d609ce | 2014-07-23 06:55:05 -0600 | [diff] [blame] | 13 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 15 | #include <stdarg.h> |
| 16 | #include <malloc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 17 | #include <stdio_dev.h> |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 18 | #include <serial.h> |
Igor Opaniuk | 1f6bfad | 2019-05-29 09:01:43 +0000 | [diff] [blame] | 19 | #include <splash.h> |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 20 | #include <i2c.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 21 | #include <asm/global_data.h> |
Simon Glass | d3d4035 | 2015-10-18 21:17:15 -0600 | [diff] [blame] | 22 | #include <dm/device-internal.h> |
| 23 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 26 | static struct stdio_dev devs; |
| 27 | struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL }; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 28 | char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; |
| 29 | |
Andy Shevchenko | 9433102 | 2021-02-11 17:09:36 +0200 | [diff] [blame] | 30 | int stdio_file_to_flags(const int file) |
| 31 | { |
| 32 | switch (file) { |
| 33 | case stdin: |
| 34 | return DEV_FLAGS_INPUT; |
| 35 | case stdout: |
| 36 | case stderr: |
| 37 | return DEV_FLAGS_OUTPUT; |
| 38 | default: |
| 39 | return -EINVAL; |
| 40 | } |
| 41 | } |
| 42 | |
Andy Shevchenko | 2066f39 | 2021-02-11 17:09:35 +0200 | [diff] [blame] | 43 | #if CONFIG_IS_ENABLED(SYS_DEVICE_NULLDEV) |
Jeroen Hofstee | 169eda6 | 2014-10-08 22:57:44 +0200 | [diff] [blame] | 44 | static void nulldev_putc(struct stdio_dev *dev, const char c) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 45 | { |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 46 | /* nulldev is empty! */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Jeroen Hofstee | 169eda6 | 2014-10-08 22:57:44 +0200 | [diff] [blame] | 49 | static void nulldev_puts(struct stdio_dev *dev, const char *s) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 50 | { |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 51 | /* nulldev is empty! */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Jeroen Hofstee | 169eda6 | 2014-10-08 22:57:44 +0200 | [diff] [blame] | 54 | static int nulldev_input(struct stdio_dev *dev) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 55 | { |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 56 | /* nulldev is empty! */ |
| 57 | return 0; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 58 | } |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 59 | |
Andy Shevchenko | 2066f39 | 2021-02-11 17:09:35 +0200 | [diff] [blame] | 60 | static void nulldev_register(void) |
| 61 | { |
| 62 | struct stdio_dev dev; |
| 63 | |
| 64 | memset(&dev, '\0', sizeof(dev)); |
| 65 | |
| 66 | strcpy(dev.name, "nulldev"); |
| 67 | dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; |
| 68 | dev.putc = nulldev_putc; |
| 69 | dev.puts = nulldev_puts; |
| 70 | dev.getc = nulldev_input; |
| 71 | dev.tstc = nulldev_input; |
| 72 | |
| 73 | stdio_register(&dev); |
| 74 | } |
| 75 | #else |
| 76 | static inline void nulldev_register(void) {} |
| 77 | #endif /* SYS_DEVICE_NULLDEV */ |
| 78 | |
Jeroen Hofstee | 169eda6 | 2014-10-08 22:57:44 +0200 | [diff] [blame] | 79 | static void stdio_serial_putc(struct stdio_dev *dev, const char c) |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 80 | { |
| 81 | serial_putc(c); |
| 82 | } |
| 83 | |
Jeroen Hofstee | 169eda6 | 2014-10-08 22:57:44 +0200 | [diff] [blame] | 84 | static void stdio_serial_puts(struct stdio_dev *dev, const char *s) |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 85 | { |
| 86 | serial_puts(s); |
| 87 | } |
| 88 | |
Pali Rohár | a48a24f | 2022-09-05 11:31:19 +0200 | [diff] [blame] | 89 | #ifdef CONFIG_CONSOLE_FLUSH_SUPPORT |
| 90 | static void stdio_serial_flush(struct stdio_dev *dev) |
| 91 | { |
| 92 | serial_flush(); |
| 93 | } |
| 94 | #endif |
| 95 | |
Jeroen Hofstee | 169eda6 | 2014-10-08 22:57:44 +0200 | [diff] [blame] | 96 | static int stdio_serial_getc(struct stdio_dev *dev) |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 97 | { |
| 98 | return serial_getc(); |
| 99 | } |
| 100 | |
Jeroen Hofstee | 169eda6 | 2014-10-08 22:57:44 +0200 | [diff] [blame] | 101 | static int stdio_serial_tstc(struct stdio_dev *dev) |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 102 | { |
| 103 | return serial_tstc(); |
| 104 | } |
| 105 | |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 106 | /************************************************************************** |
| 107 | * SYSTEM DRIVERS |
| 108 | ************************************************************************** |
| 109 | */ |
| 110 | |
| 111 | static void drv_system_init (void) |
| 112 | { |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 113 | struct stdio_dev dev; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 114 | |
| 115 | memset (&dev, 0, sizeof (dev)); |
| 116 | |
| 117 | strcpy (dev.name, "serial"); |
Bin Meng | 6abe4b6 | 2015-11-03 23:23:37 -0800 | [diff] [blame] | 118 | dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 119 | dev.putc = stdio_serial_putc; |
| 120 | dev.puts = stdio_serial_puts; |
Pali Rohár | a48a24f | 2022-09-05 11:31:19 +0200 | [diff] [blame] | 121 | STDIO_DEV_ASSIGN_FLUSH(&dev, stdio_serial_flush); |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 122 | dev.getc = stdio_serial_getc; |
| 123 | dev.tstc = stdio_serial_tstc; |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 124 | stdio_register (&dev); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 125 | |
Andy Shevchenko | 2066f39 | 2021-02-11 17:09:35 +0200 | [diff] [blame] | 126 | nulldev_register(); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /************************************************************************** |
| 130 | * DEVICES |
| 131 | ************************************************************************** |
| 132 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 133 | struct list_head* stdio_get_list(void) |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 134 | { |
Simon Glass | 4b1e309 | 2020-08-11 11:23:40 -0600 | [diff] [blame] | 135 | return &devs.list; |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 136 | } |
| 137 | |
Simon Glass | 4af407f | 2016-10-05 20:42:16 -0600 | [diff] [blame] | 138 | /** |
| 139 | * stdio_probe_device() - Find a device which provides the given stdio device |
| 140 | * |
| 141 | * This looks for a device of the given uclass which provides a particular |
| 142 | * stdio device. It is currently really only useful for UCLASS_VIDEO. |
| 143 | * |
| 144 | * Ultimately we want to be able to probe a device by its stdio name. At |
| 145 | * present devices register in their probe function (for video devices this |
| 146 | * is done in vidconsole_post_probe()) and we don't know what name they will |
| 147 | * use until they do so. |
| 148 | * TODO(sjg@chromium.org): We should be able to determine the name before |
| 149 | * probing, and probe the required device. |
| 150 | * |
| 151 | * @name: stdio device name (e.g. "vidconsole") |
| 152 | * id: Uclass ID of device to look for (e.g. UCLASS_VIDEO) |
| 153 | * @sdevp: Returns stdout device, if found, else NULL |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 154 | * Return: 0 if found, -ENOENT if no device found with that name, other -ve |
Simon Glass | 4af407f | 2016-10-05 20:42:16 -0600 | [diff] [blame] | 155 | * on other error |
| 156 | */ |
| 157 | static int stdio_probe_device(const char *name, enum uclass_id id, |
| 158 | struct stdio_dev **sdevp) |
| 159 | { |
| 160 | struct stdio_dev *sdev; |
| 161 | struct udevice *dev; |
| 162 | int seq, ret; |
| 163 | |
| 164 | *sdevp = NULL; |
| 165 | seq = trailing_strtoln(name, NULL); |
| 166 | if (seq == -1) |
Simon Glass | 927e631 | 2016-11-13 14:22:00 -0700 | [diff] [blame] | 167 | seq = 0; |
| 168 | ret = uclass_get_device_by_seq(id, seq, &dev); |
| 169 | if (ret == -ENODEV) |
Simon Glass | 4af407f | 2016-10-05 20:42:16 -0600 | [diff] [blame] | 170 | ret = uclass_first_device_err(id, &dev); |
Simon Glass | 4af407f | 2016-10-05 20:42:16 -0600 | [diff] [blame] | 171 | if (ret) { |
| 172 | debug("No %s device for seq %d (%s)\n", uclass_get_name(id), |
| 173 | seq, name); |
| 174 | return ret; |
| 175 | } |
| 176 | /* The device should be be the last one registered */ |
| 177 | sdev = list_empty(&devs.list) ? NULL : |
| 178 | list_last_entry(&devs.list, struct stdio_dev, list); |
| 179 | if (!sdev || strcmp(sdev->name, name)) { |
| 180 | debug("Device '%s' did not register with stdio as '%s'\n", |
| 181 | dev->name, name); |
| 182 | return -ENOENT; |
| 183 | } |
| 184 | *sdevp = sdev; |
| 185 | |
| 186 | return 0; |
| 187 | } |
Simon Glass | 4af407f | 2016-10-05 20:42:16 -0600 | [diff] [blame] | 188 | |
Simon Glass | 913d761 | 2016-11-13 14:21:59 -0700 | [diff] [blame] | 189 | struct stdio_dev *stdio_get_by_name(const char *name) |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 190 | { |
| 191 | struct list_head *pos; |
Simon Glass | 4af407f | 2016-10-05 20:42:16 -0600 | [diff] [blame] | 192 | struct stdio_dev *sdev; |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 193 | |
Simon Glass | 913d761 | 2016-11-13 14:21:59 -0700 | [diff] [blame] | 194 | if (!name) |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 195 | return NULL; |
| 196 | |
Simon Glass | 4b1e309 | 2020-08-11 11:23:40 -0600 | [diff] [blame] | 197 | list_for_each(pos, &devs.list) { |
Simon Glass | 4af407f | 2016-10-05 20:42:16 -0600 | [diff] [blame] | 198 | sdev = list_entry(pos, struct stdio_dev, list); |
| 199 | if (strcmp(sdev->name, name) == 0) |
| 200 | return sdev; |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 201 | } |
Simon Glass | 52cb504 | 2022-10-18 07:46:31 -0600 | [diff] [blame] | 202 | if (IS_ENABLED(CONFIG_VIDEO)) { |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 203 | /* |
| 204 | * We did not find a suitable stdio device. If there is a video |
| 205 | * driver with a name starting with 'vidconsole', we can try |
| 206 | * probing that in the hope that it will produce the required |
| 207 | * stdio device. |
| 208 | * |
| 209 | * This function is sometimes called with the entire value of |
| 210 | * 'stdout', which may include a list of devices separate by |
| 211 | * commas. Obviously this is not going to work, so we ignore |
| 212 | * that case. The call path in that case is |
Andy Shevchenko | cfaed7f | 2020-12-21 14:30:03 +0200 | [diff] [blame] | 213 | * console_init_r() -> console_search_dev() -> stdio_get_by_name() |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 214 | */ |
| 215 | if (!strncmp(name, "vidconsole", 10) && !strchr(name, ',') && |
| 216 | !stdio_probe_device(name, UCLASS_VIDEO, &sdev)) |
| 217 | return sdev; |
| 218 | } |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 219 | |
| 220 | return NULL; |
| 221 | } |
| 222 | |
Simon Glass | 5b4c122 | 2020-08-11 11:23:41 -0600 | [diff] [blame] | 223 | struct stdio_dev *stdio_clone(struct stdio_dev *dev) |
Jean-Christophe PLAGNIOL-VILLARD | 3d85c43 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 224 | { |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 225 | struct stdio_dev *_dev; |
Jean-Christophe PLAGNIOL-VILLARD | 3d85c43 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 226 | |
Simon Glass | 5b4c122 | 2020-08-11 11:23:41 -0600 | [diff] [blame] | 227 | if (!dev) |
Jean-Christophe PLAGNIOL-VILLARD | 3d85c43 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 228 | return NULL; |
| 229 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 230 | _dev = calloc(1, sizeof(struct stdio_dev)); |
Simon Glass | 5b4c122 | 2020-08-11 11:23:41 -0600 | [diff] [blame] | 231 | if (!_dev) |
Jean-Christophe PLAGNIOL-VILLARD | 3d85c43 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 232 | return NULL; |
| 233 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 234 | memcpy(_dev, dev, sizeof(struct stdio_dev)); |
Jean-Christophe PLAGNIOL-VILLARD | 3d85c43 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 235 | |
| 236 | return _dev; |
| 237 | } |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 238 | |
Simon Glass | 5d609ce | 2014-07-23 06:55:05 -0600 | [diff] [blame] | 239 | int stdio_register_dev(struct stdio_dev *dev, struct stdio_dev **devp) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 240 | { |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 241 | struct stdio_dev *_dev; |
Jean-Christophe PLAGNIOL-VILLARD | 3d85c43 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 242 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 243 | _dev = stdio_clone(dev); |
Simon Glass | 5b4c122 | 2020-08-11 11:23:41 -0600 | [diff] [blame] | 244 | if (!_dev) |
Simon Glass | 5d609ce | 2014-07-23 06:55:05 -0600 | [diff] [blame] | 245 | return -ENODEV; |
Simon Glass | 4b1e309 | 2020-08-11 11:23:40 -0600 | [diff] [blame] | 246 | list_add_tail(&_dev->list, &devs.list); |
Simon Glass | 5d609ce | 2014-07-23 06:55:05 -0600 | [diff] [blame] | 247 | if (devp) |
| 248 | *devp = _dev; |
| 249 | |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 250 | return 0; |
| 251 | } |
| 252 | |
Simon Glass | 5d609ce | 2014-07-23 06:55:05 -0600 | [diff] [blame] | 253 | int stdio_register(struct stdio_dev *dev) |
| 254 | { |
| 255 | return stdio_register_dev(dev, NULL); |
| 256 | } |
| 257 | |
Hans de Goede | 1a58638 | 2014-09-20 16:54:37 +0200 | [diff] [blame] | 258 | int stdio_deregister_dev(struct stdio_dev *dev, int force) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 259 | { |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 260 | struct list_head *pos; |
Heinrich Schuchardt | f570565 | 2023-09-29 02:47:17 +0200 | [diff] [blame] | 261 | char temp_names[3][STDIO_NAME_LEN]; |
Simon Glass | 5b4c122 | 2020-08-11 11:23:41 -0600 | [diff] [blame] | 262 | int i; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 263 | |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 264 | /* get stdio devices (ListRemoveItem changes the dev list) */ |
Simon Glass | 5b4c122 | 2020-08-11 11:23:41 -0600 | [diff] [blame] | 265 | for (i = 0 ; i < MAX_FILES; i++) { |
| 266 | if (stdio_devices[i] == dev) { |
Hans de Goede | 1a58638 | 2014-09-20 16:54:37 +0200 | [diff] [blame] | 267 | if (force) { |
Simon Glass | 5b4c122 | 2020-08-11 11:23:41 -0600 | [diff] [blame] | 268 | strcpy(temp_names[i], "nulldev"); |
Hans de Goede | 1a58638 | 2014-09-20 16:54:37 +0200 | [diff] [blame] | 269 | continue; |
| 270 | } |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 271 | /* Device is assigned -> report error */ |
Simon Glass | 5b4c122 | 2020-08-11 11:23:41 -0600 | [diff] [blame] | 272 | return -EBUSY; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 273 | } |
Heinrich Schuchardt | f570565 | 2023-09-29 02:47:17 +0200 | [diff] [blame] | 274 | strlcpy(&temp_names[i][0], stdio_devices[i]->name, |
| 275 | sizeof(temp_names[i])); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 276 | } |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 277 | |
Simon Glass | 4b1e309 | 2020-08-11 11:23:40 -0600 | [diff] [blame] | 278 | list_del(&dev->list); |
Hans de Goede | 35e116c | 2014-09-24 14:06:09 +0200 | [diff] [blame] | 279 | free(dev); |
Jean-Christophe PLAGNIOL-VILLARD | 8a4a784 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 280 | |
Simon Glass | 5b4c122 | 2020-08-11 11:23:41 -0600 | [diff] [blame] | 281 | /* reassign device list */ |
Simon Glass | 4b1e309 | 2020-08-11 11:23:40 -0600 | [diff] [blame] | 282 | list_for_each(pos, &devs.list) { |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 283 | dev = list_entry(pos, struct stdio_dev, list); |
Simon Glass | 5b4c122 | 2020-08-11 11:23:41 -0600 | [diff] [blame] | 284 | for (i = 0 ; i < MAX_FILES; i++) { |
| 285 | if (strcmp(dev->name, temp_names[i]) == 0) |
| 286 | stdio_devices[i] = dev; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
Simon Glass | 5b4c122 | 2020-08-11 11:23:41 -0600 | [diff] [blame] | 289 | |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 290 | return 0; |
| 291 | } |
Simon Glass | 5d609ce | 2014-07-23 06:55:05 -0600 | [diff] [blame] | 292 | |
Simon Glass | 712da5e | 2014-09-03 17:37:01 -0600 | [diff] [blame] | 293 | int stdio_init_tables(void) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 294 | { |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 295 | /* Initialize the list */ |
Simon Glass | 4b1e309 | 2020-08-11 11:23:40 -0600 | [diff] [blame] | 296 | INIT_LIST_HEAD(&devs.list); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 297 | |
Simon Glass | 712da5e | 2014-09-03 17:37:01 -0600 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | int stdio_add_devices(void) |
| 302 | { |
Simon Glass | d3d4035 | 2015-10-18 21:17:15 -0600 | [diff] [blame] | 303 | struct udevice *dev; |
Simon Glass | d3d4035 | 2015-10-18 21:17:15 -0600 | [diff] [blame] | 304 | int ret; |
| 305 | |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 306 | if (IS_ENABLED(CONFIG_DM_KEYBOARD)) { |
| 307 | /* |
| 308 | * For now we probe all the devices here. At some point this |
| 309 | * should be done only when the devices are required - e.g. we |
| 310 | * have a list of input devices to start up in the stdin |
| 311 | * environment variable. That work probably makes more sense |
| 312 | * when stdio itself is converted to driver model. |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 313 | */ |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * Don't report errors to the caller - assume that they are |
| 317 | * non-fatal |
| 318 | */ |
Michal Suchanek | 73ba676 | 2022-10-12 21:57:55 +0200 | [diff] [blame] | 319 | for (ret = uclass_first_device_check(UCLASS_KEYBOARD, &dev); |
| 320 | dev; |
| 321 | ret = uclass_next_device_check(&dev)) { |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 322 | if (ret) |
Michal Suchanek | 73ba676 | 2022-10-12 21:57:55 +0200 | [diff] [blame] | 323 | printf("%s: Failed to probe keyboard '%s' (ret=%d)\n", |
| 324 | __func__, dev->name, ret); |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 325 | } |
Simon Glass | d3d4035 | 2015-10-18 21:17:15 -0600 | [diff] [blame] | 326 | } |
Tom Rini | 52b2e26 | 2021-08-18 23:12:24 -0400 | [diff] [blame] | 327 | #if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) |
Heiko Schocher | e0e55bc | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 328 | i2c_init_all(); |
Heiko Schocher | e0e55bc | 2012-01-16 21:12:24 +0000 | [diff] [blame] | 329 | #endif |
Simon Glass | 52cb504 | 2022-10-18 07:46:31 -0600 | [diff] [blame] | 330 | if (IS_ENABLED(CONFIG_VIDEO)) { |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 331 | /* |
| 332 | * If the console setting is not in environment variables then |
| 333 | * console_init_r() will not be calling iomux_doenv() (which |
Andy Shevchenko | cfaed7f | 2020-12-21 14:30:03 +0200 | [diff] [blame] | 334 | * calls console_search_dev()). So we will not dynamically add |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 335 | * devices by calling stdio_probe_device(). |
| 336 | * |
| 337 | * So just probe all video devices now so that whichever one is |
| 338 | * required will be available. |
| 339 | */ |
| 340 | struct udevice *vdev; |
| 341 | int ret; |
| 342 | |
| 343 | if (!IS_ENABLED(CONFIG_SYS_CONSOLE_IS_IN_ENV)) { |
Michal Suchanek | 73ba676 | 2022-10-12 21:57:55 +0200 | [diff] [blame] | 344 | for (ret = uclass_first_device_check(UCLASS_VIDEO, |
| 345 | &vdev); |
| 346 | vdev; |
| 347 | ret = uclass_next_device_check(&vdev)) { |
| 348 | if (ret) |
| 349 | printf("%s: Failed to probe video device '%s' (ret=%d)\n", |
| 350 | __func__, vdev->name, ret); |
| 351 | } |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 352 | } |
| 353 | if (IS_ENABLED(CONFIG_SPLASH_SCREEN) && |
| 354 | IS_ENABLED(CONFIG_CMD_BMP)) |
| 355 | splash_display(); |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 356 | } |
Simon Glass | 0005cb2 | 2016-01-18 19:52:23 -0700 | [diff] [blame] | 357 | |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 358 | drv_system_init(); |
| 359 | serial_stdio_init(); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 360 | #ifdef CONFIG_USB_TTY |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 361 | drv_usbtty_init(); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 362 | #endif |
Loic Poulain | eb78f83 | 2021-11-25 18:16:15 +0100 | [diff] [blame] | 363 | #ifdef CONFIG_USB_FUNCTION_ACM |
| 364 | drv_usbacm_init (); |
| 365 | #endif |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 366 | if (IS_ENABLED(CONFIG_NETCONSOLE)) |
| 367 | drv_nc_init(); |
Mike Frysinger | 7504e97 | 2008-10-11 21:51:20 -0400 | [diff] [blame] | 368 | #ifdef CONFIG_JTAG_CONSOLE |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 369 | drv_jtag_console_init(); |
Vadim Bendebury | 263a8bd | 2012-10-12 18:48:47 +0000 | [diff] [blame] | 370 | #endif |
Simon Glass | 5a36d82 | 2020-08-11 11:23:39 -0600 | [diff] [blame] | 371 | if (IS_ENABLED(CONFIG_CBMEM_CONSOLE)) |
| 372 | cbmemc_init(); |
Simon Glass | 712da5e | 2014-09-03 17:37:01 -0600 | [diff] [blame] | 373 | |
| 374 | return 0; |
| 375 | } |