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