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