wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <config.h> |
| 9 | #include <common.h> |
| 10 | #include <stdarg.h> |
| 11 | #include <malloc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 12 | #include <stdio_dev.h> |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 13 | #include <serial.h> |
wdenk | 7f6c2cb | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 14 | #ifdef CONFIG_LOGBUFFER |
| 15 | #include <logbuff.h> |
| 16 | #endif |
| 17 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 18 | #include <i2c.h> |
wdenk | 7f6c2cb | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 19 | #endif |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 20 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 23 | static struct stdio_dev devs; |
| 24 | struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL }; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 25 | char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; |
| 26 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 27 | #if defined(CONFIG_SPLASH_SCREEN) && !defined(CONFIG_SYS_DEVICE_NULLDEV) |
| 28 | #define CONFIG_SYS_DEVICE_NULLDEV 1 |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 29 | #endif |
| 30 | |
| 31 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 32 | #ifdef CONFIG_SYS_DEVICE_NULLDEV |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 33 | void nulldev_putc(const char c) |
| 34 | { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 35 | /* nulldev is empty! */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void nulldev_puts(const char *s) |
| 39 | { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 40 | /* nulldev is empty! */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int nulldev_input(void) |
| 44 | { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 45 | /* nulldev is empty! */ |
| 46 | return 0; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 47 | } |
| 48 | #endif |
| 49 | |
| 50 | /************************************************************************** |
| 51 | * SYSTEM DRIVERS |
| 52 | ************************************************************************** |
| 53 | */ |
| 54 | |
| 55 | static void drv_system_init (void) |
| 56 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 57 | struct stdio_dev dev; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 58 | |
| 59 | memset (&dev, 0, sizeof (dev)); |
| 60 | |
| 61 | strcpy (dev.name, "serial"); |
| 62 | dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 63 | dev.putc = serial_putc; |
| 64 | dev.puts = serial_puts; |
| 65 | dev.getc = serial_getc; |
| 66 | dev.tstc = serial_tstc; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 67 | stdio_register (&dev); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 68 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 69 | #ifdef CONFIG_SYS_DEVICE_NULLDEV |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 70 | memset (&dev, 0, sizeof (dev)); |
| 71 | |
| 72 | strcpy (dev.name, "nulldev"); |
| 73 | dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM; |
| 74 | dev.putc = nulldev_putc; |
| 75 | dev.puts = nulldev_puts; |
| 76 | dev.getc = nulldev_input; |
| 77 | dev.tstc = nulldev_input; |
| 78 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 79 | stdio_register (&dev); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 80 | #endif |
| 81 | } |
| 82 | |
| 83 | /************************************************************************** |
| 84 | * DEVICES |
| 85 | ************************************************************************** |
| 86 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 87 | struct list_head* stdio_get_list(void) |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 88 | { |
| 89 | return &(devs.list); |
| 90 | } |
| 91 | |
Mike Frysinger | d7be305 | 2010-10-20 07:18:03 -0400 | [diff] [blame] | 92 | struct stdio_dev* stdio_get_by_name(const char *name) |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 93 | { |
| 94 | struct list_head *pos; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 95 | struct stdio_dev *dev; |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 96 | |
| 97 | if(!name) |
| 98 | return NULL; |
| 99 | |
| 100 | list_for_each(pos, &(devs.list)) { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 101 | dev = list_entry(pos, struct stdio_dev, list); |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 102 | if(strcmp(dev->name, name) == 0) |
| 103 | return dev; |
| 104 | } |
| 105 | |
| 106 | return NULL; |
| 107 | } |
| 108 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 109 | struct stdio_dev* stdio_clone(struct stdio_dev *dev) |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 110 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 111 | struct stdio_dev *_dev; |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 112 | |
| 113 | if(!dev) |
| 114 | return NULL; |
| 115 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 116 | _dev = calloc(1, sizeof(struct stdio_dev)); |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 117 | |
| 118 | if(!_dev) |
| 119 | return NULL; |
| 120 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 121 | memcpy(_dev, dev, sizeof(struct stdio_dev)); |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 122 | |
| 123 | return _dev; |
| 124 | } |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 125 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 126 | int stdio_register (struct stdio_dev * dev) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 127 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 128 | struct stdio_dev *_dev; |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 129 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 130 | _dev = stdio_clone(dev); |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 131 | if(!_dev) |
| 132 | return -1; |
Stefan Roese | 3e3c026 | 2008-09-05 10:47:46 +0200 | [diff] [blame] | 133 | list_add_tail(&(_dev->list), &(devs.list)); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | /* deregister the device "devname". |
| 138 | * returns 0 if success, -1 if device is assigned and 1 if devname not found |
| 139 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 140 | #ifdef CONFIG_SYS_STDIO_DEREGISTER |
Mike Frysinger | d7be305 | 2010-10-20 07:18:03 -0400 | [diff] [blame] | 141 | int stdio_deregister(const char *devname) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 142 | { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 143 | int l; |
| 144 | struct list_head *pos; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 145 | struct stdio_dev *dev; |
Bradley Bolen | 03bf22f | 2011-08-22 11:48:05 +0000 | [diff] [blame] | 146 | char temp_names[3][16]; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 147 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 148 | dev = stdio_get_by_name(devname); |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 149 | |
| 150 | if(!dev) /* device not found */ |
| 151 | return -1; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 152 | /* get stdio devices (ListRemoveItem changes the dev list) */ |
| 153 | for (l=0 ; l< MAX_FILES; l++) { |
| 154 | if (stdio_devices[l] == dev) { |
| 155 | /* Device is assigned -> report error */ |
| 156 | return -1; |
| 157 | } |
| 158 | memcpy (&temp_names[l][0], |
| 159 | stdio_devices[l]->name, |
Bradley Bolen | 03bf22f | 2011-08-22 11:48:05 +0000 | [diff] [blame] | 160 | sizeof(temp_names[l])); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 161 | } |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 162 | |
| 163 | list_del(&(dev->list)); |
| 164 | |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 165 | /* reassign Device list */ |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 166 | list_for_each(pos, &(devs.list)) { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 167 | dev = list_entry(pos, struct stdio_dev, list); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 168 | for (l=0 ; l< MAX_FILES; l++) { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 169 | if(strcmp(dev->name, temp_names[l]) == 0) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 170 | stdio_devices[l] = dev; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | return 0; |
| 174 | } |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 175 | #endif /* CONFIG_SYS_STDIO_DEREGISTER */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 176 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 177 | int stdio_init (void) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 178 | { |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 179 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 180 | /* already relocated for current ARM implementation */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 181 | ulong relocation_offset = gd->reloc_off; |
wdenk | 3595ac4 | 2003-06-22 17:18:28 +0000 | [diff] [blame] | 182 | int i; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 183 | |
| 184 | /* relocate device name pointers */ |
| 185 | for (i = 0; i < (sizeof (stdio_names) / sizeof (char *)); ++i) { |
| 186 | stdio_names[i] = (char *) (((ulong) stdio_names[i]) + |
| 187 | relocation_offset); |
| 188 | } |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 189 | #endif /* CONFIG_NEEDS_MANUAL_RELOC */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 190 | |
| 191 | /* Initialize the list */ |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 192 | INIT_LIST_HEAD(&(devs.list)); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 193 | |
Michal Simek | e70fb53 | 2013-01-22 23:40:06 +0000 | [diff] [blame] | 194 | #ifdef CONFIG_ARM_DCC |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 195 | drv_arm_dcc_init (); |
| 196 | #endif |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 197 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 198 | i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 199 | #endif |
| 200 | #ifdef CONFIG_LCD |
| 201 | drv_lcd_init (); |
| 202 | #endif |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 203 | #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 204 | drv_video_init (); |
| 205 | #endif |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 206 | #ifdef CONFIG_KEYBOARD |
| 207 | drv_keyboard_init (); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 208 | #endif |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 209 | #ifdef CONFIG_LOGBUFFER |
| 210 | drv_logbuff_init (); |
| 211 | #endif |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 212 | drv_system_init (); |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 213 | serial_stdio_init (); |
wdenk | 232c150 | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 214 | #ifdef CONFIG_USB_TTY |
| 215 | drv_usbtty_init (); |
| 216 | #endif |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 217 | #ifdef CONFIG_NETCONSOLE |
| 218 | drv_nc_init (); |
| 219 | #endif |
Mike Frysinger | 36ea8e9 | 2008-10-11 21:51:20 -0400 | [diff] [blame] | 220 | #ifdef CONFIG_JTAG_CONSOLE |
| 221 | drv_jtag_console_init (); |
| 222 | #endif |
Vadim Bendebury | 98ab435 | 2012-10-12 18:48:47 +0000 | [diff] [blame] | 223 | #ifdef CONFIG_CBMEM_CONSOLE |
| 224 | cbmemc_init(); |
| 225 | #endif |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 226 | return (0); |
| 227 | } |