2 * Copyright (C) 2009 Sergey Kubushyn <ksi@koi8.net>
4 * Changes for multibus/multiadapter I2C support.
7 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
9 * See file CREDITS for list of people who contributed to this
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.
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.
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,
32 #include <stdio_dev.h>
34 #ifdef CONFIG_LOGBUFFER
37 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) || \
38 defined(CONFIG_SYS_I2C_ADAPTERS)
42 DECLARE_GLOBAL_DATA_PTR;
44 static struct stdio_dev devs;
45 struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL };
46 char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
48 #if defined(CONFIG_SPLASH_SCREEN) && !defined(CONFIG_SYS_DEVICE_NULLDEV)
49 #define CONFIG_SYS_DEVICE_NULLDEV 1
53 #ifdef CONFIG_SYS_DEVICE_NULLDEV
54 void nulldev_putc(const char c)
56 /* nulldev is empty! */
59 void nulldev_puts(const char *s)
61 /* nulldev is empty! */
64 int nulldev_input(void)
66 /* nulldev is empty! */
71 /**************************************************************************
73 **************************************************************************
76 static void drv_system_init (void)
80 memset (&dev, 0, sizeof (dev));
82 strcpy (dev.name, "serial");
83 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
84 dev.putc = serial_putc;
85 dev.puts = serial_puts;
86 dev.getc = serial_getc;
87 dev.tstc = serial_tstc;
88 stdio_register (&dev);
90 #ifdef CONFIG_SYS_DEVICE_NULLDEV
91 memset (&dev, 0, sizeof (dev));
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;
100 stdio_register (&dev);
104 /**************************************************************************
106 **************************************************************************
108 struct list_head* stdio_get_list(void)
113 struct stdio_dev* stdio_get_by_name(const char *name)
115 struct list_head *pos;
116 struct stdio_dev *dev;
121 list_for_each(pos, &(devs.list)) {
122 dev = list_entry(pos, struct stdio_dev, list);
123 if(strcmp(dev->name, name) == 0)
130 struct stdio_dev* stdio_clone(struct stdio_dev *dev)
132 struct stdio_dev *_dev;
137 _dev = calloc(1, sizeof(struct stdio_dev));
142 memcpy(_dev, dev, sizeof(struct stdio_dev));
147 int stdio_register (struct stdio_dev * dev)
149 struct stdio_dev *_dev;
151 _dev = stdio_clone(dev);
154 list_add_tail(&(_dev->list), &(devs.list));
158 /* deregister the device "devname".
159 * returns 0 if success, -1 if device is assigned and 1 if devname not found
161 #ifdef CONFIG_SYS_STDIO_DEREGISTER
162 int stdio_deregister(const char *devname)
165 struct list_head *pos;
166 struct stdio_dev *dev;
167 char temp_names[3][16];
169 dev = stdio_get_by_name(devname);
171 if(!dev) /* device not found */
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 */
179 memcpy (&temp_names[l][0],
180 stdio_devices[l]->name,
181 sizeof(temp_names[l]));
184 list_del(&(dev->list));
186 /* reassign Device list */
187 list_for_each(pos, &(devs.list)) {
188 dev = list_entry(pos, struct stdio_dev, list);
189 for (l=0 ; l< MAX_FILES; l++) {
190 if(strcmp(dev->name, temp_names[l]) == 0)
191 stdio_devices[l] = dev;
196 #endif /* CONFIG_SYS_STDIO_DEREGISTER */
198 int stdio_init (void)
200 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
201 /* already relocated for current ARM implementation */
202 ulong relocation_offset = gd->reloc_off;
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]) +
210 #endif /* CONFIG_NEEDS_MANUAL_RELOC */
212 /* Initialize the list */
213 INIT_LIST_HEAD(&(devs.list));
215 #ifdef CONFIG_ARM_DCC
218 #ifdef CONFIG_SYS_I2C
219 #ifdef CONFIG_SYS_I2C_ADAPTERS
223 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
224 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
230 #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
233 #ifdef CONFIG_KEYBOARD
234 drv_keyboard_init ();
236 #ifdef CONFIG_LOGBUFFER
240 serial_stdio_init ();
241 #ifdef CONFIG_USB_TTY
244 #ifdef CONFIG_NETCONSOLE
247 #ifdef CONFIG_JTAG_CONSOLE
248 drv_jtag_console_init ();
250 #ifdef CONFIG_CBMEM_CONSOLE