Blame view
common/stdio.c
9.64 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
91d3256c6 Initial revision |
2 |
/* |
3f4978c71 i2c: common chang... |
3 4 5 6 |
* Copyright (C) 2009 Sergey Kubushyn <ksi@koi8.net> * * Changes for multibus/multiadapter I2C support. * |
91d3256c6 Initial revision |
7 8 |
* (C) Copyright 2000 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it |
91d3256c6 Initial revision |
9 10 11 12 |
*/ #include <config.h> #include <common.h> |
b206cd737 dm: stdio: Plumb ... |
13 |
#include <dm.h> |
d97143a67 stdio: Provide fu... |
14 |
#include <errno.h> |
91d3256c6 Initial revision |
15 16 |
#include <stdarg.h> #include <malloc.h> |
52cb4d4fb stdio/device: rew... |
17 |
#include <stdio_dev.h> |
281e00a3b * Code cleanup |
18 |
#include <serial.h> |
5eb83c0ac splash: display s... |
19 |
#include <splash.h> |
ff58ce211 MLK-23964-1 video... |
20 |
#include <video_link.h> |
ea818dbbc i2c, soft-i2c: sw... |
21 |
|
69153988a i2c: Finish dropp... |
22 |
#if defined(CONFIG_SYS_I2C) |
91d3256c6 Initial revision |
23 |
#include <i2c.h> |
7f6c2cbc2 * Vince Husovsky,... |
24 |
#endif |
91d3256c6 Initial revision |
25 |
|
b206cd737 dm: stdio: Plumb ... |
26 |
#include <dm/device-internal.h> |
d87080b72 GCC-4.x fixes: cl... |
27 |
DECLARE_GLOBAL_DATA_PTR; |
52cb4d4fb stdio/device: rew... |
28 29 |
static struct stdio_dev devs; struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL }; |
91d3256c6 Initial revision |
30 |
char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; |
6d0f6bcf3 rename CFG_ macro... |
31 32 |
#if defined(CONFIG_SPLASH_SCREEN) && !defined(CONFIG_SYS_DEVICE_NULLDEV) #define CONFIG_SYS_DEVICE_NULLDEV 1 |
d791b1dc3 * Make sure Block... |
33 |
#endif |
869588dec Convert CONFIG_SY... |
34 |
#if CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER) |
32d019265 stdio: Add force ... |
35 36 |
#define CONFIG_SYS_DEVICE_NULLDEV 1 #endif |
d791b1dc3 * Make sure Block... |
37 |
|
6d0f6bcf3 rename CFG_ macro... |
38 |
#ifdef CONFIG_SYS_DEVICE_NULLDEV |
654f8d0f3 serial: make loca... |
39 |
static void nulldev_putc(struct stdio_dev *dev, const char c) |
91d3256c6 Initial revision |
40 |
{ |
c1de7a6da devices: merge to... |
41 |
/* nulldev is empty! */ |
91d3256c6 Initial revision |
42 |
} |
654f8d0f3 serial: make loca... |
43 |
static void nulldev_puts(struct stdio_dev *dev, const char *s) |
91d3256c6 Initial revision |
44 |
{ |
c1de7a6da devices: merge to... |
45 |
/* nulldev is empty! */ |
91d3256c6 Initial revision |
46 |
} |
654f8d0f3 serial: make loca... |
47 |
static int nulldev_input(struct stdio_dev *dev) |
91d3256c6 Initial revision |
48 |
{ |
c1de7a6da devices: merge to... |
49 50 |
/* nulldev is empty! */ return 0; |
91d3256c6 Initial revision |
51 52 |
} #endif |
654f8d0f3 serial: make loca... |
53 |
static void stdio_serial_putc(struct stdio_dev *dev, const char c) |
709ea543b stdio: Pass devic... |
54 55 56 |
{ serial_putc(c); } |
654f8d0f3 serial: make loca... |
57 |
static void stdio_serial_puts(struct stdio_dev *dev, const char *s) |
709ea543b stdio: Pass devic... |
58 59 60 |
{ serial_puts(s); } |
654f8d0f3 serial: make loca... |
61 |
static int stdio_serial_getc(struct stdio_dev *dev) |
709ea543b stdio: Pass devic... |
62 63 64 |
{ return serial_getc(); } |
654f8d0f3 serial: make loca... |
65 |
static int stdio_serial_tstc(struct stdio_dev *dev) |
709ea543b stdio: Pass devic... |
66 67 68 |
{ return serial_tstc(); } |
91d3256c6 Initial revision |
69 70 71 72 73 74 75 |
/************************************************************************** * SYSTEM DRIVERS ************************************************************************** */ static void drv_system_init (void) { |
52cb4d4fb stdio/device: rew... |
76 |
struct stdio_dev dev; |
91d3256c6 Initial revision |
77 78 79 80 |
memset (&dev, 0, sizeof (dev)); strcpy (dev.name, "serial"); |
1caf934a0 video: Drop DEV_F... |
81 |
dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; |
709ea543b stdio: Pass devic... |
82 83 84 85 |
dev.putc = stdio_serial_putc; dev.puts = stdio_serial_puts; dev.getc = stdio_serial_getc; dev.tstc = stdio_serial_tstc; |
52cb4d4fb stdio/device: rew... |
86 |
stdio_register (&dev); |
91d3256c6 Initial revision |
87 |
|
6d0f6bcf3 rename CFG_ macro... |
88 |
#ifdef CONFIG_SYS_DEVICE_NULLDEV |
91d3256c6 Initial revision |
89 90 91 |
memset (&dev, 0, sizeof (dev)); strcpy (dev.name, "nulldev"); |
1caf934a0 video: Drop DEV_F... |
92 |
dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; |
91d3256c6 Initial revision |
93 94 95 96 |
dev.putc = nulldev_putc; dev.puts = nulldev_puts; dev.getc = nulldev_input; dev.tstc = nulldev_input; |
52cb4d4fb stdio/device: rew... |
97 |
stdio_register (&dev); |
91d3256c6 Initial revision |
98 99 100 101 102 103 104 |
#endif } /************************************************************************** * DEVICES ************************************************************************** */ |
52cb4d4fb stdio/device: rew... |
105 |
struct list_head* stdio_get_list(void) |
c1de7a6da devices: merge to... |
106 107 108 |
{ return &(devs.list); } |
d8441ea27 dm: stdio: Allow ... |
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
#ifdef CONFIG_DM_VIDEO /** * stdio_probe_device() - Find a device which provides the given stdio device * * This looks for a device of the given uclass which provides a particular * stdio device. It is currently really only useful for UCLASS_VIDEO. * * Ultimately we want to be able to probe a device by its stdio name. At * present devices register in their probe function (for video devices this * is done in vidconsole_post_probe()) and we don't know what name they will * use until they do so. * TODO(sjg@chromium.org): We should be able to determine the name before * probing, and probe the required device. * * @name: stdio device name (e.g. "vidconsole") * id: Uclass ID of device to look for (e.g. UCLASS_VIDEO) * @sdevp: Returns stdout device, if found, else NULL * @return 0 if found, -ENOENT if no device found with that name, other -ve * on other error */ static int stdio_probe_device(const char *name, enum uclass_id id, struct stdio_dev **sdevp) { struct stdio_dev *sdev; struct udevice *dev; int seq, ret; *sdevp = NULL; seq = trailing_strtoln(name, NULL); if (seq == -1) |
d844efec4 stdio: Correct nu... |
139 140 141 |
seq = 0; ret = uclass_get_device_by_seq(id, seq, &dev); if (ret == -ENODEV) |
d8441ea27 dm: stdio: Allow ... |
142 |
ret = uclass_first_device_err(id, &dev); |
d8441ea27 dm: stdio: Allow ... |
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
if (ret) { debug("No %s device for seq %d (%s) ", uclass_get_name(id), seq, name); return ret; } /* The device should be be the last one registered */ sdev = list_empty(&devs.list) ? NULL : list_last_entry(&devs.list, struct stdio_dev, list); if (!sdev || strcmp(sdev->name, name)) { debug("Device '%s' did not register with stdio as '%s' ", dev->name, name); return -ENOENT; } *sdevp = sdev; return 0; } #endif |
ab29a34a5 stdio: Correct co... |
163 |
struct stdio_dev *stdio_get_by_name(const char *name) |
c1de7a6da devices: merge to... |
164 165 |
{ struct list_head *pos; |
d8441ea27 dm: stdio: Allow ... |
166 |
struct stdio_dev *sdev; |
c1de7a6da devices: merge to... |
167 |
|
ab29a34a5 stdio: Correct co... |
168 |
if (!name) |
c1de7a6da devices: merge to... |
169 170 171 |
return NULL; list_for_each(pos, &(devs.list)) { |
d8441ea27 dm: stdio: Allow ... |
172 173 174 |
sdev = list_entry(pos, struct stdio_dev, list); if (strcmp(sdev->name, name) == 0) return sdev; |
c1de7a6da devices: merge to... |
175 |
} |
d8441ea27 dm: stdio: Allow ... |
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
#ifdef CONFIG_DM_VIDEO /* * We did not find a suitable stdio device. If there is a video * driver with a name starting with 'vidconsole', we can try probing * that in the hope that it will produce the required stdio device. * * This function is sometimes called with the entire value of * 'stdout', which may include a list of devices separate by commas. * Obviously this is not going to work, so we ignore that case. The * call path in that case is console_init_r() -> search_device() -> * stdio_get_by_name(). */ if (!strncmp(name, "vidconsole", 10) && !strchr(name, ',') && !stdio_probe_device(name, UCLASS_VIDEO, &sdev)) return sdev; #endif |
c1de7a6da devices: merge to... |
192 193 194 |
return NULL; } |
52cb4d4fb stdio/device: rew... |
195 |
struct stdio_dev* stdio_clone(struct stdio_dev *dev) |
628ffd73b device: make devi... |
196 |
{ |
52cb4d4fb stdio/device: rew... |
197 |
struct stdio_dev *_dev; |
628ffd73b device: make devi... |
198 199 200 |
if(!dev) return NULL; |
52cb4d4fb stdio/device: rew... |
201 |
_dev = calloc(1, sizeof(struct stdio_dev)); |
628ffd73b device: make devi... |
202 203 204 |
if(!_dev) return NULL; |
52cb4d4fb stdio/device: rew... |
205 |
memcpy(_dev, dev, sizeof(struct stdio_dev)); |
628ffd73b device: make devi... |
206 207 208 |
return _dev; } |
91d3256c6 Initial revision |
209 |
|
d97143a67 stdio: Provide fu... |
210 |
int stdio_register_dev(struct stdio_dev *dev, struct stdio_dev **devp) |
91d3256c6 Initial revision |
211 |
{ |
52cb4d4fb stdio/device: rew... |
212 |
struct stdio_dev *_dev; |
628ffd73b device: make devi... |
213 |
|
52cb4d4fb stdio/device: rew... |
214 |
_dev = stdio_clone(dev); |
628ffd73b device: make devi... |
215 |
if(!_dev) |
d97143a67 stdio: Provide fu... |
216 |
return -ENODEV; |
3e3c026ed devices: Use list... |
217 |
list_add_tail(&(_dev->list), &(devs.list)); |
d97143a67 stdio: Provide fu... |
218 219 |
if (devp) *devp = _dev; |
91d3256c6 Initial revision |
220 221 |
return 0; } |
d97143a67 stdio: Provide fu... |
222 223 224 225 |
int stdio_register(struct stdio_dev *dev) { return stdio_register_dev(dev, NULL); } |
91d3256c6 Initial revision |
226 227 228 |
/* deregister the device "devname". * returns 0 if success, -1 if device is assigned and 1 if devname not found */ |
869588dec Convert CONFIG_SY... |
229 |
#if CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER) |
32d019265 stdio: Add force ... |
230 |
int stdio_deregister_dev(struct stdio_dev *dev, int force) |
91d3256c6 Initial revision |
231 |
{ |
c1de7a6da devices: merge to... |
232 233 |
int l; struct list_head *pos; |
03bf22f55 stdio: Fix a poss... |
234 |
char temp_names[3][16]; |
91d3256c6 Initial revision |
235 |
|
91d3256c6 Initial revision |
236 237 238 |
/* get stdio devices (ListRemoveItem changes the dev list) */ for (l=0 ; l< MAX_FILES; l++) { if (stdio_devices[l] == dev) { |
32d019265 stdio: Add force ... |
239 240 241 242 |
if (force) { strcpy(temp_names[l], "nulldev"); continue; } |
91d3256c6 Initial revision |
243 244 245 246 247 |
/* Device is assigned -> report error */ return -1; } memcpy (&temp_names[l][0], stdio_devices[l]->name, |
03bf22f55 stdio: Fix a poss... |
248 |
sizeof(temp_names[l])); |
91d3256c6 Initial revision |
249 |
} |
c1de7a6da devices: merge to... |
250 251 |
list_del(&(dev->list)); |
88274b6c4 stdio: Fix memlea... |
252 |
free(dev); |
c1de7a6da devices: merge to... |
253 |
|
91d3256c6 Initial revision |
254 |
/* reassign Device list */ |
c1de7a6da devices: merge to... |
255 |
list_for_each(pos, &(devs.list)) { |
52cb4d4fb stdio/device: rew... |
256 |
dev = list_entry(pos, struct stdio_dev, list); |
91d3256c6 Initial revision |
257 |
for (l=0 ; l< MAX_FILES; l++) { |
c1de7a6da devices: merge to... |
258 |
if(strcmp(dev->name, temp_names[l]) == 0) |
91d3256c6 Initial revision |
259 |
stdio_devices[l] = dev; |
91d3256c6 Initial revision |
260 261 262 263 |
} } return 0; } |
d97143a67 stdio: Provide fu... |
264 |
|
32d019265 stdio: Add force ... |
265 |
int stdio_deregister(const char *devname, int force) |
d97143a67 stdio: Provide fu... |
266 267 268 269 270 271 272 |
{ struct stdio_dev *dev; dev = stdio_get_by_name(devname); if (!dev) /* device not found */ return -ENODEV; |
32d019265 stdio: Add force ... |
273 |
return stdio_deregister_dev(dev, force); |
d97143a67 stdio: Provide fu... |
274 |
} |
869588dec Convert CONFIG_SY... |
275 |
#endif /* CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER) */ |
91d3256c6 Initial revision |
276 |
|
9fb02491f dm: Make driver m... |
277 |
int stdio_init_tables(void) |
91d3256c6 Initial revision |
278 |
{ |
2e5167cca Replace CONFIG_RE... |
279 |
#if defined(CONFIG_NEEDS_MANUAL_RELOC) |
521af04d8 Conditionally per... |
280 |
/* already relocated for current ARM implementation */ |
91d3256c6 Initial revision |
281 |
ulong relocation_offset = gd->reloc_off; |
3595ac497 * Patch by Rune T... |
282 |
int i; |
91d3256c6 Initial revision |
283 284 285 286 287 288 |
/* relocate device name pointers */ for (i = 0; i < (sizeof (stdio_names) / sizeof (char *)); ++i) { stdio_names[i] = (char *) (((ulong) stdio_names[i]) + relocation_offset); } |
2e5167cca Replace CONFIG_RE... |
289 |
#endif /* CONFIG_NEEDS_MANUAL_RELOC */ |
91d3256c6 Initial revision |
290 291 |
/* Initialize the list */ |
c1de7a6da devices: merge to... |
292 |
INIT_LIST_HEAD(&(devs.list)); |
91d3256c6 Initial revision |
293 |
|
9fb02491f dm: Make driver m... |
294 295 296 297 298 |
return 0; } int stdio_add_devices(void) { |
b206cd737 dm: stdio: Plumb ... |
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
#ifdef CONFIG_DM_KEYBOARD struct udevice *dev; struct uclass *uc; int ret; /* * For now we probe all the devices here. At some point this should be * done only when the devices are required - e.g. we have a list of * input devices to start up in the stdin environment variable. That * work probably makes more sense when stdio itself is converted to * driver model. * * TODO(sjg@chromium.org): Convert changing uclass_first_device() etc. * to return the device even on error. Then we could use that here. */ ret = uclass_get(UCLASS_KEYBOARD, &uc); if (ret) return ret; /* Don't report errors to the caller - assume that they are non-fatal */ uclass_foreach_dev(dev, uc) { ret = device_probe(dev); if (ret) printf("Failed to probe keyboard '%s' ", dev->name); } #endif |
3f4978c71 i2c: common chang... |
326 |
#ifdef CONFIG_SYS_I2C |
3f4978c71 i2c: common chang... |
327 |
i2c_init_all(); |
3f4978c71 i2c: common chang... |
328 |
#else |
3f4978c71 i2c: common chang... |
329 |
#endif |
e3b81c1c0 dm: stdio: video:... |
330 |
#ifdef CONFIG_DM_VIDEO |
ff58ce211 MLK-23964-1 video... |
331 332 333 334 |
#ifdef CONFIG_VIDEO_LINK video_link_init(); #endif |
d8441ea27 dm: stdio: Allow ... |
335 336 337 338 339 340 341 342 343 344 |
/* * If the console setting is not in environment variables then * console_init_r() will not be calling iomux_doenv() (which calls * search_device()). So we will not dynamically add devices by * calling stdio_probe_device(). * * So just probe all video devices now so that whichever one is * required will be available. */ #ifndef CONFIG_SYS_CONSOLE_IS_IN_ENV |
e3b81c1c0 dm: stdio: video:... |
345 |
struct udevice *vdev; |
35a1f0dfa stdio: Correct a ... |
346 347 348 |
# ifndef CONFIG_DM_KEYBOARD int ret; # endif |
e3b81c1c0 dm: stdio: video:... |
349 350 351 352 353 354 355 356 |
for (ret = uclass_first_device(UCLASS_VIDEO, &vdev); vdev; ret = uclass_next_device(&vdev)) ; if (ret) printf("%s: Video device failed (ret=%d) ", __func__, ret); |
d8441ea27 dm: stdio: Allow ... |
357 |
#endif /* !CONFIG_SYS_CONSOLE_IS_IN_ENV */ |
5eb83c0ac splash: display s... |
358 359 360 |
#if defined(CONFIG_SPLASH_SCREEN) && defined(CONFIG_CMD_BMP) splash_display(); #endif /* CONFIG_SPLASH_SCREEN && CONFIG_CMD_BMP */ |
e3b81c1c0 dm: stdio: video:... |
361 362 |
#else # if defined(CONFIG_LCD) |
91d3256c6 Initial revision |
363 |
drv_lcd_init (); |
e3b81c1c0 dm: stdio: video:... |
364 365 |
# endif # if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) |
91d3256c6 Initial revision |
366 |
drv_video_init (); |
e3b81c1c0 dm: stdio: video:... |
367 368 |
# endif #endif /* CONFIG_DM_VIDEO */ |
b206cd737 dm: stdio: Plumb ... |
369 |
#if defined(CONFIG_KEYBOARD) && !defined(CONFIG_DM_KEYBOARD) |
682011ff6 * Patches by Udi ... |
370 |
drv_keyboard_init (); |
91d3256c6 Initial revision |
371 372 |
#endif drv_system_init (); |
52cb4d4fb stdio/device: rew... |
373 |
serial_stdio_init (); |
232c150a2 Add support for S... |
374 375 376 |
#ifdef CONFIG_USB_TTY drv_usbtty_init (); #endif |
68ceb29e7 Add support for c... |
377 378 379 |
#ifdef CONFIG_NETCONSOLE drv_nc_init (); #endif |
36ea8e9ad Blackfin: support... |
380 381 382 |
#ifdef CONFIG_JTAG_CONSOLE drv_jtag_console_init (); #endif |
98ab435f7 x86: Add CBMEM co... |
383 384 385 |
#ifdef CONFIG_CBMEM_CONSOLE cbmemc_init(); #endif |
9fb02491f dm: Make driver m... |
386 387 388 389 390 391 392 393 394 395 |
return 0; } int stdio_init(void) { stdio_init_tables(); stdio_add_devices(); return 0; |
91d3256c6 Initial revision |
396 |
} |