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 * SPDX-License-Identifier: GPL-2.0+
16 #include <stdio_dev.h>
18 #ifdef CONFIG_LOGBUFFER
22 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
26 DECLARE_GLOBAL_DATA_PTR;
28 static struct stdio_dev devs;
29 struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL };
30 char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
32 #if defined(CONFIG_SPLASH_SCREEN) && !defined(CONFIG_SYS_DEVICE_NULLDEV)
33 #define CONFIG_SYS_DEVICE_NULLDEV 1
37 #ifdef CONFIG_SYS_DEVICE_NULLDEV
38 void nulldev_putc(const char c)
40 /* nulldev is empty! */
43 void nulldev_puts(const char *s)
45 /* nulldev is empty! */
48 int nulldev_input(void)
50 /* nulldev is empty! */
55 /**************************************************************************
57 **************************************************************************
60 static void drv_system_init (void)
64 memset (&dev, 0, sizeof (dev));
66 strcpy (dev.name, "serial");
67 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
68 dev.putc = serial_putc;
69 dev.puts = serial_puts;
70 dev.getc = serial_getc;
71 dev.tstc = serial_tstc;
72 stdio_register (&dev);
74 #ifdef CONFIG_SYS_DEVICE_NULLDEV
75 memset (&dev, 0, sizeof (dev));
77 strcpy (dev.name, "nulldev");
78 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
79 dev.putc = nulldev_putc;
80 dev.puts = nulldev_puts;
81 dev.getc = nulldev_input;
82 dev.tstc = nulldev_input;
84 stdio_register (&dev);
88 /**************************************************************************
90 **************************************************************************
92 struct list_head* stdio_get_list(void)
97 struct stdio_dev* stdio_get_by_name(const char *name)
99 struct list_head *pos;
100 struct stdio_dev *dev;
105 list_for_each(pos, &(devs.list)) {
106 dev = list_entry(pos, struct stdio_dev, list);
107 if(strcmp(dev->name, name) == 0)
114 struct stdio_dev* stdio_clone(struct stdio_dev *dev)
116 struct stdio_dev *_dev;
121 _dev = calloc(1, sizeof(struct stdio_dev));
126 memcpy(_dev, dev, sizeof(struct stdio_dev));
131 int stdio_register (struct stdio_dev * dev)
133 struct stdio_dev *_dev;
135 _dev = stdio_clone(dev);
138 list_add_tail(&(_dev->list), &(devs.list));
142 /* deregister the device "devname".
143 * returns 0 if success, -1 if device is assigned and 1 if devname not found
145 #ifdef CONFIG_SYS_STDIO_DEREGISTER
146 int stdio_deregister(const char *devname)
149 struct list_head *pos;
150 struct stdio_dev *dev;
151 char temp_names[3][16];
153 dev = stdio_get_by_name(devname);
155 if(!dev) /* device not found */
157 /* get stdio devices (ListRemoveItem changes the dev list) */
158 for (l=0 ; l< MAX_FILES; l++) {
159 if (stdio_devices[l] == dev) {
160 /* Device is assigned -> report error */
163 memcpy (&temp_names[l][0],
164 stdio_devices[l]->name,
165 sizeof(temp_names[l]));
168 list_del(&(dev->list));
170 /* reassign Device list */
171 list_for_each(pos, &(devs.list)) {
172 dev = list_entry(pos, struct stdio_dev, list);
173 for (l=0 ; l< MAX_FILES; l++) {
174 if(strcmp(dev->name, temp_names[l]) == 0)
175 stdio_devices[l] = dev;
180 #endif /* CONFIG_SYS_STDIO_DEREGISTER */
182 int stdio_init (void)
184 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
185 /* already relocated for current ARM implementation */
186 ulong relocation_offset = gd->reloc_off;
189 /* relocate device name pointers */
190 for (i = 0; i < (sizeof (stdio_names) / sizeof (char *)); ++i) {
191 stdio_names[i] = (char *) (((ulong) stdio_names[i]) +
194 #endif /* CONFIG_NEEDS_MANUAL_RELOC */
196 /* Initialize the list */
197 INIT_LIST_HEAD(&(devs.list));
199 #ifdef CONFIG_SYS_I2C
202 #if defined(CONFIG_HARD_I2C)
203 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
209 #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
212 #ifdef CONFIG_KEYBOARD
213 drv_keyboard_init ();
215 #ifdef CONFIG_LOGBUFFER
219 serial_stdio_init ();
220 #ifdef CONFIG_USB_TTY
223 #ifdef CONFIG_NETCONSOLE
226 #ifdef CONFIG_JTAG_CONSOLE
227 drv_jtag_console_init ();
229 #ifdef CONFIG_CBMEM_CONSOLE