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 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <config.h> |
| 29 | #include <common.h> |
| 30 | #include <stdarg.h> |
| 31 | #include <malloc.h> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 32 | #include <stdio_dev.h> |
wdenk | 281e00a | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 33 | #include <serial.h> |
wdenk | 7f6c2cb | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 34 | #ifdef CONFIG_LOGBUFFER |
| 35 | #include <logbuff.h> |
| 36 | #endif |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame^] | 37 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) || \ |
| 38 | defined(CONFIG_SYS_I2C_ADAPTERS) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 39 | #include <i2c.h> |
wdenk | 7f6c2cb | 2002-11-10 22:06:23 +0000 | [diff] [blame] | 40 | #endif |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 41 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 42 | DECLARE_GLOBAL_DATA_PTR; |
| 43 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 44 | static struct stdio_dev devs; |
| 45 | struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL }; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 46 | char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; |
| 47 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 48 | #if defined(CONFIG_SPLASH_SCREEN) && !defined(CONFIG_SYS_DEVICE_NULLDEV) |
| 49 | #define CONFIG_SYS_DEVICE_NULLDEV 1 |
wdenk | d791b1d | 2003-04-20 14:04:18 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
| 52 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 53 | #ifdef CONFIG_SYS_DEVICE_NULLDEV |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 54 | void nulldev_putc(const char c) |
| 55 | { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 56 | /* nulldev is empty! */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void nulldev_puts(const char *s) |
| 60 | { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 61 | /* nulldev is empty! */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | int nulldev_input(void) |
| 65 | { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 66 | /* nulldev is empty! */ |
| 67 | return 0; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 68 | } |
| 69 | #endif |
| 70 | |
| 71 | /************************************************************************** |
| 72 | * SYSTEM DRIVERS |
| 73 | ************************************************************************** |
| 74 | */ |
| 75 | |
| 76 | static void drv_system_init (void) |
| 77 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 78 | struct stdio_dev dev; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 79 | |
| 80 | memset (&dev, 0, sizeof (dev)); |
| 81 | |
| 82 | strcpy (dev.name, "serial"); |
| 83 | dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 84 | dev.putc = serial_putc; |
| 85 | dev.puts = serial_puts; |
| 86 | dev.getc = serial_getc; |
| 87 | dev.tstc = serial_tstc; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 88 | stdio_register (&dev); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 89 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 90 | #ifdef CONFIG_SYS_DEVICE_NULLDEV |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 91 | memset (&dev, 0, sizeof (dev)); |
| 92 | |
| 93 | strcpy (dev.name, "nulldev"); |
| 94 | dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM; |
| 95 | dev.putc = nulldev_putc; |
| 96 | dev.puts = nulldev_puts; |
| 97 | dev.getc = nulldev_input; |
| 98 | dev.tstc = nulldev_input; |
| 99 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 100 | stdio_register (&dev); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 101 | #endif |
| 102 | } |
| 103 | |
| 104 | /************************************************************************** |
| 105 | * DEVICES |
| 106 | ************************************************************************** |
| 107 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 108 | struct list_head* stdio_get_list(void) |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 109 | { |
| 110 | return &(devs.list); |
| 111 | } |
| 112 | |
Mike Frysinger | d7be305 | 2010-10-20 07:18:03 -0400 | [diff] [blame] | 113 | struct stdio_dev* stdio_get_by_name(const char *name) |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 114 | { |
| 115 | struct list_head *pos; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 116 | struct stdio_dev *dev; |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 117 | |
| 118 | if(!name) |
| 119 | return NULL; |
| 120 | |
| 121 | list_for_each(pos, &(devs.list)) { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 122 | dev = list_entry(pos, struct stdio_dev, list); |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 123 | if(strcmp(dev->name, name) == 0) |
| 124 | return dev; |
| 125 | } |
| 126 | |
| 127 | return NULL; |
| 128 | } |
| 129 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 130 | struct stdio_dev* stdio_clone(struct stdio_dev *dev) |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 131 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 132 | struct stdio_dev *_dev; |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 133 | |
| 134 | if(!dev) |
| 135 | return NULL; |
| 136 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 137 | _dev = calloc(1, sizeof(struct stdio_dev)); |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 138 | |
| 139 | if(!_dev) |
| 140 | return NULL; |
| 141 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 142 | memcpy(_dev, dev, sizeof(struct stdio_dev)); |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 143 | |
| 144 | return _dev; |
| 145 | } |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 146 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 147 | int stdio_register (struct stdio_dev * dev) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 148 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 149 | struct stdio_dev *_dev; |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 150 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 151 | _dev = stdio_clone(dev); |
Jean-Christophe PLAGNIOL-VILLARD | 628ffd7 | 2008-09-01 17:11:26 +0200 | [diff] [blame] | 152 | if(!_dev) |
| 153 | return -1; |
Stefan Roese | 3e3c026 | 2008-09-05 10:47:46 +0200 | [diff] [blame] | 154 | list_add_tail(&(_dev->list), &(devs.list)); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | /* deregister the device "devname". |
| 159 | * returns 0 if success, -1 if device is assigned and 1 if devname not found |
| 160 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 161 | #ifdef CONFIG_SYS_STDIO_DEREGISTER |
Mike Frysinger | d7be305 | 2010-10-20 07:18:03 -0400 | [diff] [blame] | 162 | int stdio_deregister(const char *devname) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 163 | { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 164 | int l; |
| 165 | struct list_head *pos; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 166 | struct stdio_dev *dev; |
Bradley Bolen | 03bf22f | 2011-08-22 11:48:05 +0000 | [diff] [blame] | 167 | char temp_names[3][16]; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 168 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 169 | dev = stdio_get_by_name(devname); |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 170 | |
| 171 | if(!dev) /* device not found */ |
| 172 | return -1; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 173 | /* get stdio devices (ListRemoveItem changes the dev list) */ |
| 174 | for (l=0 ; l< MAX_FILES; l++) { |
| 175 | if (stdio_devices[l] == dev) { |
| 176 | /* Device is assigned -> report error */ |
| 177 | return -1; |
| 178 | } |
| 179 | memcpy (&temp_names[l][0], |
| 180 | stdio_devices[l]->name, |
Bradley Bolen | 03bf22f | 2011-08-22 11:48:05 +0000 | [diff] [blame] | 181 | sizeof(temp_names[l])); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 182 | } |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 183 | |
| 184 | list_del(&(dev->list)); |
| 185 | |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 186 | /* reassign Device list */ |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 187 | list_for_each(pos, &(devs.list)) { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 188 | dev = list_entry(pos, struct stdio_dev, list); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 189 | for (l=0 ; l< MAX_FILES; l++) { |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 190 | if(strcmp(dev->name, temp_names[l]) == 0) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 191 | stdio_devices[l] = dev; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | return 0; |
| 195 | } |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 196 | #endif /* CONFIG_SYS_STDIO_DEREGISTER */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 197 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 198 | int stdio_init (void) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 199 | { |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 200 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 201 | /* already relocated for current ARM implementation */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 202 | ulong relocation_offset = gd->reloc_off; |
wdenk | 3595ac4 | 2003-06-22 17:18:28 +0000 | [diff] [blame] | 203 | int i; |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 204 | |
| 205 | /* relocate device name pointers */ |
| 206 | for (i = 0; i < (sizeof (stdio_names) / sizeof (char *)); ++i) { |
| 207 | stdio_names[i] = (char *) (((ulong) stdio_names[i]) + |
| 208 | relocation_offset); |
| 209 | } |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 210 | #endif /* CONFIG_NEEDS_MANUAL_RELOC */ |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 211 | |
| 212 | /* Initialize the list */ |
Jean-Christophe PLAGNIOL-VILLARD | c1de7a6 | 2008-08-31 04:24:55 +0200 | [diff] [blame] | 213 | INIT_LIST_HEAD(&(devs.list)); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 214 | |
Michal Simek | e70fb53 | 2013-01-22 23:40:06 +0000 | [diff] [blame] | 215 | #ifdef CONFIG_ARM_DCC |
Jean-Christophe PLAGNIOL-VILLARD | 4f57289 | 2009-02-22 15:49:28 +0100 | [diff] [blame] | 216 | drv_arm_dcc_init (); |
| 217 | #endif |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame^] | 218 | #ifdef CONFIG_SYS_I2C |
| 219 | #ifdef CONFIG_SYS_I2C_ADAPTERS |
| 220 | i2c_init_all(); |
| 221 | #endif |
| 222 | #else |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 223 | #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 224 | i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 225 | #endif |
Heiko Schocher | 3f4978c | 2012-01-16 21:12:24 +0000 | [diff] [blame^] | 226 | #endif |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 227 | #ifdef CONFIG_LCD |
| 228 | drv_lcd_init (); |
| 229 | #endif |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 230 | #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 231 | drv_video_init (); |
| 232 | #endif |
wdenk | 682011f | 2003-06-03 23:54:09 +0000 | [diff] [blame] | 233 | #ifdef CONFIG_KEYBOARD |
| 234 | drv_keyboard_init (); |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 235 | #endif |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 236 | #ifdef CONFIG_LOGBUFFER |
| 237 | drv_logbuff_init (); |
| 238 | #endif |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 239 | drv_system_init (); |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 240 | serial_stdio_init (); |
wdenk | 232c150 | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 241 | #ifdef CONFIG_USB_TTY |
| 242 | drv_usbtty_init (); |
| 243 | #endif |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 244 | #ifdef CONFIG_NETCONSOLE |
| 245 | drv_nc_init (); |
| 246 | #endif |
Mike Frysinger | 36ea8e9 | 2008-10-11 21:51:20 -0400 | [diff] [blame] | 247 | #ifdef CONFIG_JTAG_CONSOLE |
| 248 | drv_jtag_console_init (); |
| 249 | #endif |
Vadim Bendebury | 98ab435 | 2012-10-12 18:48:47 +0000 | [diff] [blame] | 250 | #ifdef CONFIG_CBMEM_CONSOLE |
| 251 | cbmemc_init(); |
| 252 | #endif |
wdenk | 91d3256 | 2002-09-18 21:21:13 +0000 | [diff] [blame] | 253 | return (0); |
| 254 | } |