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