Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The Chromium OS Authors. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
Simon Glass | 593f50b | 2014-10-29 13:09:03 -0600 | [diff] [blame] | 9 | #include <environment.h> |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 10 | #include <errno.h> |
| 11 | #include <fdtdec.h> |
| 12 | #include <os.h> |
| 13 | #include <serial.h> |
| 14 | #include <stdio_dev.h> |
Simon Glass | 5c60b2a | 2014-10-22 21:37:02 -0600 | [diff] [blame] | 15 | #include <watchdog.h> |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 16 | #include <dm/lists.h> |
| 17 | #include <dm/device-internal.h> |
| 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Simon Glass | 593f50b | 2014-10-29 13:09:03 -0600 | [diff] [blame] | 21 | /* |
| 22 | * Table with supported baudrates (defined in config_xyz.h) |
| 23 | */ |
| 24 | static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE; |
| 25 | |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 26 | #ifndef CONFIG_SYS_MALLOC_F_LEN |
| 27 | #error "Serial is required before relocation - define CONFIG_SYS_MALLOC_F_LEN to make this work" |
| 28 | #endif |
| 29 | |
| 30 | static void serial_find_console_or_panic(void) |
| 31 | { |
Simon Glass | c860e3e | 2015-10-17 19:41:17 -0600 | [diff] [blame] | 32 | const void *blob = gd->fdt_blob; |
Simon Glass | a4c2e13 | 2014-11-10 18:00:20 -0700 | [diff] [blame] | 33 | struct udevice *dev; |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 34 | int node; |
| 35 | |
Simon Glass | c860e3e | 2015-10-17 19:41:17 -0600 | [diff] [blame] | 36 | if (CONFIG_IS_ENABLED(OF_CONTROL) && blob) { |
Simon Glass | c62fb99 | 2015-05-12 14:55:05 -0600 | [diff] [blame] | 37 | /* Check for a chosen console */ |
Simon Glass | c860e3e | 2015-10-17 19:41:17 -0600 | [diff] [blame] | 38 | node = fdtdec_get_chosen_node(blob, "stdout-path"); |
| 39 | if (node < 0) { |
| 40 | const char *str, *p, *name; |
| 41 | |
| 42 | /* |
| 43 | * Deal with things like |
| 44 | * stdout-path = "serial0:115200n8"; |
| 45 | * |
| 46 | * We need to look up the alias and then follow it to |
| 47 | * the correct node. |
| 48 | */ |
| 49 | str = fdtdec_get_chosen_prop(blob, "stdout-path"); |
| 50 | if (str) { |
| 51 | p = strchr(str, ':'); |
| 52 | name = fdt_get_alias_namelen(blob, str, |
| 53 | p ? p - str : strlen(str)); |
| 54 | if (name) |
| 55 | node = fdt_path_offset(blob, name); |
| 56 | } |
| 57 | } |
Simon Glass | c62fb99 | 2015-05-12 14:55:05 -0600 | [diff] [blame] | 58 | if (node < 0) |
Simon Glass | c860e3e | 2015-10-17 19:41:17 -0600 | [diff] [blame] | 59 | node = fdt_path_offset(blob, "console"); |
Simon Glass | c62fb99 | 2015-05-12 14:55:05 -0600 | [diff] [blame] | 60 | if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node, |
| 61 | &dev)) { |
Simon Glass | a4c2e13 | 2014-11-10 18:00:20 -0700 | [diff] [blame] | 62 | gd->cur_serial_dev = dev; |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 63 | return; |
Simon Glass | a4c2e13 | 2014-11-10 18:00:20 -0700 | [diff] [blame] | 64 | } |
Simon Glass | c62fb99 | 2015-05-12 14:55:05 -0600 | [diff] [blame] | 65 | |
| 66 | /* |
Stefan Roese | 88c3a88 | 2015-11-26 13:38:43 +0100 | [diff] [blame] | 67 | * If the console is not marked to be bound before relocation, |
| 68 | * bind it anyway. |
| 69 | */ |
Simon Glass | c62fb99 | 2015-05-12 14:55:05 -0600 | [diff] [blame] | 70 | if (node > 0 && |
Simon Glass | c860e3e | 2015-10-17 19:41:17 -0600 | [diff] [blame] | 71 | !lists_bind_fdt(gd->dm_root, blob, node, &dev)) { |
Simon Glass | c62fb99 | 2015-05-12 14:55:05 -0600 | [diff] [blame] | 72 | if (!device_probe(dev)) { |
| 73 | gd->cur_serial_dev = dev; |
| 74 | return; |
| 75 | } |
| 76 | } |
Simon Glass | 8579a51 | 2015-03-06 13:19:03 -0700 | [diff] [blame] | 77 | } |
Simon Glass | c860e3e | 2015-10-17 19:41:17 -0600 | [diff] [blame] | 78 | if (!SPL_BUILD || !CONFIG_IS_ENABLED(OF_CONTROL) || !blob) { |
Simon Glass | c62fb99 | 2015-05-12 14:55:05 -0600 | [diff] [blame] | 79 | /* |
Stefan Roese | 88c3a88 | 2015-11-26 13:38:43 +0100 | [diff] [blame] | 80 | * Try to use CONFIG_CONS_INDEX if available (it is numbered |
| 81 | * from 1!). |
| 82 | * |
| 83 | * Failing that, get the device with sequence number 0, or in |
| 84 | * extremis just the first serial device we can find. But we |
| 85 | * insist on having a console (even if it is silent). |
| 86 | */ |
Simon Glass | bc5aa99 | 2014-10-22 21:37:06 -0600 | [diff] [blame] | 87 | #ifdef CONFIG_CONS_INDEX |
| 88 | #define INDEX (CONFIG_CONS_INDEX - 1) |
| 89 | #else |
| 90 | #define INDEX 0 |
| 91 | #endif |
Simon Glass | c62fb99 | 2015-05-12 14:55:05 -0600 | [diff] [blame] | 92 | if (!uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) || |
| 93 | !uclass_get_device(UCLASS_SERIAL, INDEX, &dev) || |
Simon Glass | 6664077 | 2015-07-31 09:31:20 -0600 | [diff] [blame] | 94 | (!uclass_first_device(UCLASS_SERIAL, &dev) && dev)) { |
Simon Glass | c62fb99 | 2015-05-12 14:55:05 -0600 | [diff] [blame] | 95 | gd->cur_serial_dev = dev; |
| 96 | return; |
| 97 | } |
Simon Glass | bc5aa99 | 2014-10-22 21:37:06 -0600 | [diff] [blame] | 98 | #undef INDEX |
Simon Glass | c62fb99 | 2015-05-12 14:55:05 -0600 | [diff] [blame] | 99 | } |
| 100 | |
Hans de Goede | 04f8094 | 2015-08-08 17:45:18 +0200 | [diff] [blame] | 101 | #ifdef CONFIG_REQUIRE_SERIAL_CONSOLE |
Simon Glass | c62fb99 | 2015-05-12 14:55:05 -0600 | [diff] [blame] | 102 | panic_str("No serial driver found"); |
Hans de Goede | 04f8094 | 2015-08-08 17:45:18 +0200 | [diff] [blame] | 103 | #endif |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /* Called prior to relocation */ |
| 107 | int serial_init(void) |
| 108 | { |
| 109 | serial_find_console_or_panic(); |
| 110 | gd->flags |= GD_FLG_SERIAL_READY; |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /* Called after relocation */ |
| 116 | void serial_initialize(void) |
| 117 | { |
Simon Glass | 51f73f1 | 2016-03-11 22:06:51 -0700 | [diff] [blame] | 118 | serial_init(); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 119 | } |
| 120 | |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 121 | static void _serial_putc(struct udevice *dev, char ch) |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 122 | { |
Masahiro Yamada | 84df41a | 2014-10-23 22:26:06 +0900 | [diff] [blame] | 123 | struct dm_serial_ops *ops = serial_get_ops(dev); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 124 | int err; |
| 125 | |
Alison Wang | c0a9ce6 | 2016-03-02 11:00:36 +0800 | [diff] [blame] | 126 | if (ch == '\n') |
| 127 | _serial_putc(dev, '\r'); |
| 128 | |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 129 | do { |
Masahiro Yamada | 84df41a | 2014-10-23 22:26:06 +0900 | [diff] [blame] | 130 | err = ops->putc(dev, ch); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 131 | } while (err == -EAGAIN); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 132 | } |
| 133 | |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 134 | static void _serial_puts(struct udevice *dev, const char *str) |
Simon Glass | 73285a2 | 2014-10-01 19:57:23 -0600 | [diff] [blame] | 135 | { |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 136 | while (*str) |
| 137 | _serial_putc(dev, *str++); |
Simon Glass | 73285a2 | 2014-10-01 19:57:23 -0600 | [diff] [blame] | 138 | } |
| 139 | |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 140 | static int _serial_getc(struct udevice *dev) |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 141 | { |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 142 | struct dm_serial_ops *ops = serial_get_ops(dev); |
| 143 | int err; |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 144 | |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 145 | do { |
| 146 | err = ops->getc(dev); |
| 147 | if (err == -EAGAIN) |
| 148 | WATCHDOG_RESET(); |
| 149 | } while (err == -EAGAIN); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 150 | |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 151 | return err >= 0 ? err : 0; |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 152 | } |
| 153 | |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 154 | static int _serial_tstc(struct udevice *dev) |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 155 | { |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 156 | struct dm_serial_ops *ops = serial_get_ops(dev); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 157 | |
| 158 | if (ops->pending) |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 159 | return ops->pending(dev, true); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 160 | |
| 161 | return 1; |
| 162 | } |
| 163 | |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 164 | void serial_putc(char ch) |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 165 | { |
Hans de Goede | 04f8094 | 2015-08-08 17:45:18 +0200 | [diff] [blame] | 166 | if (gd->cur_serial_dev) |
| 167 | _serial_putc(gd->cur_serial_dev, ch); |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 168 | } |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 169 | |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 170 | void serial_puts(const char *str) |
| 171 | { |
Hans de Goede | 04f8094 | 2015-08-08 17:45:18 +0200 | [diff] [blame] | 172 | if (gd->cur_serial_dev) |
| 173 | _serial_puts(gd->cur_serial_dev, str); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 174 | } |
| 175 | |
Simon Glass | 73285a2 | 2014-10-01 19:57:23 -0600 | [diff] [blame] | 176 | int serial_getc(void) |
| 177 | { |
Hans de Goede | 04f8094 | 2015-08-08 17:45:18 +0200 | [diff] [blame] | 178 | if (!gd->cur_serial_dev) |
| 179 | return 0; |
| 180 | |
Simon Glass | a4c2e13 | 2014-11-10 18:00:20 -0700 | [diff] [blame] | 181 | return _serial_getc(gd->cur_serial_dev); |
Simon Glass | 73285a2 | 2014-10-01 19:57:23 -0600 | [diff] [blame] | 182 | } |
| 183 | |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 184 | int serial_tstc(void) |
| 185 | { |
Hans de Goede | 04f8094 | 2015-08-08 17:45:18 +0200 | [diff] [blame] | 186 | if (!gd->cur_serial_dev) |
| 187 | return 0; |
| 188 | |
Simon Glass | a4c2e13 | 2014-11-10 18:00:20 -0700 | [diff] [blame] | 189 | return _serial_tstc(gd->cur_serial_dev); |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void serial_setbrg(void) |
| 193 | { |
Hans de Goede | 04f8094 | 2015-08-08 17:45:18 +0200 | [diff] [blame] | 194 | struct dm_serial_ops *ops; |
| 195 | |
| 196 | if (!gd->cur_serial_dev) |
| 197 | return; |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 198 | |
Hans de Goede | 04f8094 | 2015-08-08 17:45:18 +0200 | [diff] [blame] | 199 | ops = serial_get_ops(gd->cur_serial_dev); |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 200 | if (ops->setbrg) |
Simon Glass | a4c2e13 | 2014-11-10 18:00:20 -0700 | [diff] [blame] | 201 | ops->setbrg(gd->cur_serial_dev, gd->baudrate); |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 202 | } |
| 203 | |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 204 | void serial_stdio_init(void) |
| 205 | { |
| 206 | } |
| 207 | |
Simon Glass | 30a1349 | 2015-12-13 21:36:58 -0700 | [diff] [blame] | 208 | #if defined(CONFIG_DM_STDIO) && CONFIG_IS_ENABLED(SERIAL_PRESENT) |
Simon Glass | 73285a2 | 2014-10-01 19:57:23 -0600 | [diff] [blame] | 209 | static void serial_stub_putc(struct stdio_dev *sdev, const char ch) |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 210 | { |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 211 | _serial_putc(sdev->priv, ch); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 212 | } |
Simon Glass | c058d8b | 2014-11-10 17:16:48 -0700 | [diff] [blame] | 213 | #endif |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 214 | |
| 215 | void serial_stub_puts(struct stdio_dev *sdev, const char *str) |
| 216 | { |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 217 | _serial_puts(sdev->priv, str); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | int serial_stub_getc(struct stdio_dev *sdev) |
| 221 | { |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 222 | return _serial_getc(sdev->priv); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | int serial_stub_tstc(struct stdio_dev *sdev) |
| 226 | { |
Masahiro Yamada | 93da2fc | 2014-10-23 22:26:08 +0900 | [diff] [blame] | 227 | return _serial_tstc(sdev->priv); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 228 | } |
| 229 | |
Simon Glass | 593f50b | 2014-10-29 13:09:03 -0600 | [diff] [blame] | 230 | /** |
| 231 | * on_baudrate() - Update the actual baudrate when the env var changes |
| 232 | * |
| 233 | * This will check for a valid baudrate and only apply it if valid. |
| 234 | */ |
| 235 | static int on_baudrate(const char *name, const char *value, enum env_op op, |
| 236 | int flags) |
| 237 | { |
| 238 | int i; |
| 239 | int baudrate; |
| 240 | |
| 241 | switch (op) { |
| 242 | case env_op_create: |
| 243 | case env_op_overwrite: |
| 244 | /* |
| 245 | * Switch to new baudrate if new baudrate is supported |
| 246 | */ |
| 247 | baudrate = simple_strtoul(value, NULL, 10); |
| 248 | |
| 249 | /* Not actually changing */ |
| 250 | if (gd->baudrate == baudrate) |
| 251 | return 0; |
| 252 | |
| 253 | for (i = 0; i < ARRAY_SIZE(baudrate_table); ++i) { |
| 254 | if (baudrate == baudrate_table[i]) |
| 255 | break; |
| 256 | } |
| 257 | if (i == ARRAY_SIZE(baudrate_table)) { |
| 258 | if ((flags & H_FORCE) == 0) |
| 259 | printf("## Baudrate %d bps not supported\n", |
| 260 | baudrate); |
| 261 | return 1; |
| 262 | } |
| 263 | if ((flags & H_INTERACTIVE) != 0) { |
| 264 | printf("## Switch baudrate to %d bps and press ENTER ...\n", |
| 265 | baudrate); |
| 266 | udelay(50000); |
| 267 | } |
| 268 | |
| 269 | gd->baudrate = baudrate; |
| 270 | |
| 271 | serial_setbrg(); |
| 272 | |
| 273 | udelay(50000); |
| 274 | |
| 275 | if ((flags & H_INTERACTIVE) != 0) |
| 276 | while (1) { |
| 277 | if (getc() == '\r') |
| 278 | break; |
| 279 | } |
| 280 | |
| 281 | return 0; |
| 282 | case env_op_delete: |
| 283 | printf("## Baudrate may not be deleted\n"); |
| 284 | return 1; |
| 285 | default: |
| 286 | return 0; |
| 287 | } |
| 288 | } |
| 289 | U_BOOT_ENV_CALLBACK(baudrate, on_baudrate); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 290 | |
Simon Glass | 30a1349 | 2015-12-13 21:36:58 -0700 | [diff] [blame] | 291 | #if CONFIG_IS_ENABLED(SERIAL_PRESENT) |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 292 | static int serial_post_probe(struct udevice *dev) |
| 293 | { |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 294 | struct dm_serial_ops *ops = serial_get_ops(dev); |
Simon Glass | c058d8b | 2014-11-10 17:16:48 -0700 | [diff] [blame] | 295 | #ifdef CONFIG_DM_STDIO |
Simon Glass | de0977b | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 296 | struct serial_dev_priv *upriv = dev_get_uclass_priv(dev); |
Simon Glass | c058d8b | 2014-11-10 17:16:48 -0700 | [diff] [blame] | 297 | struct stdio_dev sdev; |
| 298 | #endif |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 299 | int ret; |
| 300 | |
Michal Simek | 0ec473b | 2015-02-02 16:31:59 +0100 | [diff] [blame] | 301 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
| 302 | if (ops->setbrg) |
| 303 | ops->setbrg += gd->reloc_off; |
| 304 | if (ops->getc) |
| 305 | ops->getc += gd->reloc_off; |
| 306 | if (ops->putc) |
| 307 | ops->putc += gd->reloc_off; |
| 308 | if (ops->pending) |
| 309 | ops->pending += gd->reloc_off; |
| 310 | if (ops->clear) |
| 311 | ops->clear += gd->reloc_off; |
| 312 | #if CONFIG_POST & CONFIG_SYS_POST_UART |
| 313 | if (ops->loop) |
| 314 | ops->loop += gd->reloc_off |
| 315 | #endif |
| 316 | #endif |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 317 | /* Set the baud rate */ |
| 318 | if (ops->setbrg) { |
| 319 | ret = ops->setbrg(dev, gd->baudrate); |
| 320 | if (ret) |
| 321 | return ret; |
| 322 | } |
| 323 | |
Simon Glass | c058d8b | 2014-11-10 17:16:48 -0700 | [diff] [blame] | 324 | #ifdef CONFIG_DM_STDIO |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 325 | if (!(gd->flags & GD_FLG_RELOC)) |
| 326 | return 0; |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 327 | memset(&sdev, '\0', sizeof(sdev)); |
| 328 | |
| 329 | strncpy(sdev.name, dev->name, sizeof(sdev.name)); |
| 330 | sdev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; |
| 331 | sdev.priv = dev; |
| 332 | sdev.putc = serial_stub_putc; |
| 333 | sdev.puts = serial_stub_puts; |
| 334 | sdev.getc = serial_stub_getc; |
| 335 | sdev.tstc = serial_stub_tstc; |
| 336 | stdio_register_dev(&sdev, &upriv->sdev); |
Simon Glass | c058d8b | 2014-11-10 17:16:48 -0700 | [diff] [blame] | 337 | #endif |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | static int serial_pre_remove(struct udevice *dev) |
| 342 | { |
| 343 | #ifdef CONFIG_SYS_STDIO_DEREGISTER |
Simon Glass | de0977b | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 344 | struct serial_dev_priv *upriv = dev_get_uclass_priv(dev); |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 345 | |
Hans de Goede | 4c4150c | 2014-10-10 18:30:17 +0200 | [diff] [blame] | 346 | if (stdio_deregister_dev(upriv->sdev, 0)) |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 347 | return -EPERM; |
| 348 | #endif |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | UCLASS_DRIVER(serial) = { |
| 354 | .id = UCLASS_SERIAL, |
| 355 | .name = "serial", |
Simon Glass | 0ccb097 | 2015-01-25 08:27:05 -0700 | [diff] [blame] | 356 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
Simon Glass | 247f596 | 2014-09-04 16:27:26 -0600 | [diff] [blame] | 357 | .post_probe = serial_post_probe, |
| 358 | .pre_remove = serial_pre_remove, |
| 359 | .per_device_auto_alloc_size = sizeof(struct serial_dev_priv), |
| 360 | }; |
Simon Glass | 30a1349 | 2015-12-13 21:36:58 -0700 | [diff] [blame] | 361 | #endif |