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+
17 #include <stdio_dev.h>
19 #ifdef CONFIG_LOGBUFFER
23 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SYS_I2C)
27 DECLARE_GLOBAL_DATA_PTR;
29 static struct stdio_dev devs;
30 struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL };
31 char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
33 #if defined(CONFIG_SPLASH_SCREEN) && !defined(CONFIG_SYS_DEVICE_NULLDEV)
34 #define CONFIG_SYS_DEVICE_NULLDEV 1
37 #ifdef CONFIG_SYS_STDIO_DEREGISTER
38 #define CONFIG_SYS_DEVICE_NULLDEV 1
41 #ifdef CONFIG_SYS_DEVICE_NULLDEV
42 static void nulldev_putc(struct stdio_dev *dev, const char c)
44 /* nulldev is empty! */
47 static void nulldev_puts(struct stdio_dev *dev, const char *s)
49 /* nulldev is empty! */
52 static int nulldev_input(struct stdio_dev *dev)
54 /* nulldev is empty! */
59 static void stdio_serial_putc(struct stdio_dev *dev, const char c)
64 static void stdio_serial_puts(struct stdio_dev *dev, const char *s)
69 static int stdio_serial_getc(struct stdio_dev *dev)
74 static int stdio_serial_tstc(struct stdio_dev *dev)
79 /**************************************************************************
81 **************************************************************************
84 static void drv_system_init (void)
88 memset (&dev, 0, sizeof (dev));
90 strcpy (dev.name, "serial");
91 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
92 dev.putc = stdio_serial_putc;
93 dev.puts = stdio_serial_puts;
94 dev.getc = stdio_serial_getc;
95 dev.tstc = stdio_serial_tstc;
96 stdio_register (&dev);
98 #ifdef CONFIG_SYS_DEVICE_NULLDEV
99 memset (&dev, 0, sizeof (dev));
101 strcpy (dev.name, "nulldev");
102 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
103 dev.putc = nulldev_putc;
104 dev.puts = nulldev_puts;
105 dev.getc = nulldev_input;
106 dev.tstc = nulldev_input;
108 stdio_register (&dev);
112 /**************************************************************************
114 **************************************************************************
116 struct list_head* stdio_get_list(void)
121 struct stdio_dev* stdio_get_by_name(const char *name)
123 struct list_head *pos;
124 struct stdio_dev *dev;
129 list_for_each(pos, &(devs.list)) {
130 dev = list_entry(pos, struct stdio_dev, list);
131 if(strcmp(dev->name, name) == 0)
138 struct stdio_dev* stdio_clone(struct stdio_dev *dev)
140 struct stdio_dev *_dev;
145 _dev = calloc(1, sizeof(struct stdio_dev));
150 memcpy(_dev, dev, sizeof(struct stdio_dev));
155 int stdio_register_dev(struct stdio_dev *dev, struct stdio_dev **devp)
157 struct stdio_dev *_dev;
159 _dev = stdio_clone(dev);
162 list_add_tail(&(_dev->list), &(devs.list));
169 int stdio_register(struct stdio_dev *dev)
171 return stdio_register_dev(dev, NULL);
174 /* deregister the device "devname".
175 * returns 0 if success, -1 if device is assigned and 1 if devname not found
177 #ifdef CONFIG_SYS_STDIO_DEREGISTER
178 int stdio_deregister_dev(struct stdio_dev *dev, int force)
181 struct list_head *pos;
182 char temp_names[3][16];
184 /* get stdio devices (ListRemoveItem changes the dev list) */
185 for (l=0 ; l< MAX_FILES; l++) {
186 if (stdio_devices[l] == dev) {
188 strcpy(temp_names[l], "nulldev");
191 /* Device is assigned -> report error */
194 memcpy (&temp_names[l][0],
195 stdio_devices[l]->name,
196 sizeof(temp_names[l]));
199 list_del(&(dev->list));
202 /* reassign Device list */
203 list_for_each(pos, &(devs.list)) {
204 dev = list_entry(pos, struct stdio_dev, list);
205 for (l=0 ; l< MAX_FILES; l++) {
206 if(strcmp(dev->name, temp_names[l]) == 0)
207 stdio_devices[l] = dev;
213 int stdio_deregister(const char *devname, int force)
215 struct stdio_dev *dev;
217 dev = stdio_get_by_name(devname);
219 if (!dev) /* device not found */
222 return stdio_deregister_dev(dev, force);
224 #endif /* CONFIG_SYS_STDIO_DEREGISTER */
226 int stdio_init_tables(void)
228 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
229 /* already relocated for current ARM implementation */
230 ulong relocation_offset = gd->reloc_off;
233 /* relocate device name pointers */
234 for (i = 0; i < (sizeof (stdio_names) / sizeof (char *)); ++i) {
235 stdio_names[i] = (char *) (((ulong) stdio_names[i]) +
238 #endif /* CONFIG_NEEDS_MANUAL_RELOC */
240 /* Initialize the list */
241 INIT_LIST_HEAD(&(devs.list));
246 int stdio_add_devices(void)
248 #ifdef CONFIG_SYS_I2C
251 #if defined(CONFIG_HARD_I2C)
252 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
258 #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
261 #ifdef CONFIG_KEYBOARD
262 drv_keyboard_init ();
264 #ifdef CONFIG_LOGBUFFER
268 serial_stdio_init ();
269 #ifdef CONFIG_USB_TTY
272 #ifdef CONFIG_NETCONSOLE
275 #ifdef CONFIG_JTAG_CONSOLE
276 drv_jtag_console_init ();
278 #ifdef CONFIG_CBMEM_CONSOLE