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