Blame view
common/stdio.c
9.42 KB
91d3256c6 Initial revision |
1 |
/* |
3f4978c71 i2c: common chang... |
2 3 4 5 |
* Copyright (C) 2009 Sergey Kubushyn <ksi@koi8.net> * * Changes for multibus/multiadapter I2C support. * |
91d3256c6 Initial revision |
6 7 8 |
* (C) Copyright 2000 * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it * |
1a4596601 Add GPL-2.0+ SPDX... |
9 |
* SPDX-License-Identifier: GPL-2.0+ |
91d3256c6 Initial revision |
10 11 12 13 |
*/ #include <config.h> #include <common.h> |
b206cd737 dm: stdio: Plumb ... |
14 |
#include <dm.h> |
d97143a67 stdio: Provide fu... |
15 |
#include <errno.h> |
91d3256c6 Initial revision |
16 17 |
#include <stdarg.h> #include <malloc.h> |
52cb4d4fb stdio/device: rew... |
18 |
#include <stdio_dev.h> |
281e00a3b * Code cleanup |
19 |
#include <serial.h> |
ea818dbbc i2c, soft-i2c: sw... |
20 |
|
69153988a i2c: Finish dropp... |
21 |
#if defined(CONFIG_SYS_I2C) |
91d3256c6 Initial revision |
22 |
#include <i2c.h> |
7f6c2cbc2 * Vince Husovsky,... |
23 |
#endif |
91d3256c6 Initial revision |
24 |
|
b206cd737 dm: stdio: Plumb ... |
25 |
#include <dm/device-internal.h> |
d87080b72 GCC-4.x fixes: cl... |
26 |
DECLARE_GLOBAL_DATA_PTR; |
52cb4d4fb stdio/device: rew... |
27 28 |
static struct stdio_dev devs; struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL }; |
91d3256c6 Initial revision |
29 |
char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" }; |
6d0f6bcf3 rename CFG_ macro... |
30 31 |
#if defined(CONFIG_SPLASH_SCREEN) && !defined(CONFIG_SYS_DEVICE_NULLDEV) #define CONFIG_SYS_DEVICE_NULLDEV 1 |
d791b1dc3 * Make sure Block... |
32 |
#endif |
869588dec Convert CONFIG_SY... |
33 |
#if CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER) |
32d019265 stdio: Add force ... |
34 35 |
#define CONFIG_SYS_DEVICE_NULLDEV 1 #endif |
d791b1dc3 * Make sure Block... |
36 |
|
6d0f6bcf3 rename CFG_ macro... |
37 |
#ifdef CONFIG_SYS_DEVICE_NULLDEV |
654f8d0f3 serial: make loca... |
38 |
static void nulldev_putc(struct stdio_dev *dev, const char c) |
91d3256c6 Initial revision |
39 |
{ |
c1de7a6da devices: merge to... |
40 |
/* nulldev is empty! */ |
91d3256c6 Initial revision |
41 |
} |
654f8d0f3 serial: make loca... |
42 |
static void nulldev_puts(struct stdio_dev *dev, const char *s) |
91d3256c6 Initial revision |
43 |
{ |
c1de7a6da devices: merge to... |
44 |
/* nulldev is empty! */ |
91d3256c6 Initial revision |
45 |
} |
654f8d0f3 serial: make loca... |
46 |
static int nulldev_input(struct stdio_dev *dev) |
91d3256c6 Initial revision |
47 |
{ |
c1de7a6da devices: merge to... |
48 49 |
/* nulldev is empty! */ return 0; |
91d3256c6 Initial revision |
50 51 |
} #endif |
654f8d0f3 serial: make loca... |
52 |
static void stdio_serial_putc(struct stdio_dev *dev, const char c) |
709ea543b stdio: Pass devic... |
53 54 55 |
{ serial_putc(c); } |
654f8d0f3 serial: make loca... |
56 |
static void stdio_serial_puts(struct stdio_dev *dev, const char *s) |
709ea543b stdio: Pass devic... |
57 58 59 |
{ serial_puts(s); } |
654f8d0f3 serial: make loca... |
60 |
static int stdio_serial_getc(struct stdio_dev *dev) |
709ea543b stdio: Pass devic... |
61 62 63 |
{ return serial_getc(); } |
654f8d0f3 serial: make loca... |
64 |
static int stdio_serial_tstc(struct stdio_dev *dev) |
709ea543b stdio: Pass devic... |
65 66 67 |
{ return serial_tstc(); } |
91d3256c6 Initial revision |
68 69 70 71 72 73 74 |
/************************************************************************** * SYSTEM DRIVERS ************************************************************************** */ static void drv_system_init (void) { |
52cb4d4fb stdio/device: rew... |
75 |
struct stdio_dev dev; |
91d3256c6 Initial revision |
76 77 78 79 |
memset (&dev, 0, sizeof (dev)); strcpy (dev.name, "serial"); |
1caf934a0 video: Drop DEV_F... |
80 |
dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; |
709ea543b stdio: Pass devic... |
81 82 83 84 |
dev.putc = stdio_serial_putc; dev.puts = stdio_serial_puts; dev.getc = stdio_serial_getc; dev.tstc = stdio_serial_tstc; |
52cb4d4fb stdio/device: rew... |
85 |
stdio_register (&dev); |
91d3256c6 Initial revision |
86 |
|
6d0f6bcf3 rename CFG_ macro... |
87 |
#ifdef CONFIG_SYS_DEVICE_NULLDEV |
91d3256c6 Initial revision |
88 89 90 |
memset (&dev, 0, sizeof (dev)); strcpy (dev.name, "nulldev"); |
1caf934a0 video: Drop DEV_F... |
91 |
dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; |
91d3256c6 Initial revision |
92 93 94 95 |
dev.putc = nulldev_putc; dev.puts = nulldev_puts; dev.getc = nulldev_input; dev.tstc = nulldev_input; |
52cb4d4fb stdio/device: rew... |
96 |
stdio_register (&dev); |
91d3256c6 Initial revision |
97 98 99 100 101 102 103 |
#endif } /************************************************************************** * DEVICES ************************************************************************** */ |
52cb4d4fb stdio/device: rew... |
104 |
struct list_head* stdio_get_list(void) |
c1de7a6da devices: merge to... |
105 106 107 |
{ return &(devs.list); } |
d8441ea27 dm: stdio: Allow ... |
108 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 |
#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... |
138 139 140 |
seq = 0; ret = uclass_get_device_by_seq(id, seq, &dev); if (ret == -ENODEV) |
d8441ea27 dm: stdio: Allow ... |
141 |
ret = uclass_first_device_err(id, &dev); |
d8441ea27 dm: stdio: Allow ... |
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
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... |
162 |
struct stdio_dev *stdio_get_by_name(const char *name) |
c1de7a6da devices: merge to... |
163 164 |
{ struct list_head *pos; |
d8441ea27 dm: stdio: Allow ... |
165 |
struct stdio_dev *sdev; |
c1de7a6da devices: merge to... |
166 |
|
ab29a34a5 stdio: Correct co... |
167 |
if (!name) |
c1de7a6da devices: merge to... |
168 169 170 |
return NULL; list_for_each(pos, &(devs.list)) { |
d8441ea27 dm: stdio: Allow ... |
171 172 173 |
sdev = list_entry(pos, struct stdio_dev, list); if (strcmp(sdev->name, name) == 0) return sdev; |
c1de7a6da devices: merge to... |
174 |
} |
d8441ea27 dm: stdio: Allow ... |
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
#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... |
191 192 193 |
return NULL; } |
52cb4d4fb stdio/device: rew... |
194 |
struct stdio_dev* stdio_clone(struct stdio_dev *dev) |
628ffd73b device: make devi... |
195 |
{ |
52cb4d4fb stdio/device: rew... |
196 |
struct stdio_dev *_dev; |
628ffd73b device: make devi... |
197 198 199 |
if(!dev) return NULL; |
52cb4d4fb stdio/device: rew... |
200 |
_dev = calloc(1, sizeof(struct stdio_dev)); |
628ffd73b device: make devi... |
201 202 203 |
if(!_dev) return NULL; |
52cb4d4fb stdio/device: rew... |
204 |
memcpy(_dev, dev, sizeof(struct stdio_dev)); |
628ffd73b device: make devi... |
205 206 207 |
return _dev; } |
91d3256c6 Initial revision |
208 |
|
d97143a67 stdio: Provide fu... |
209 |
int stdio_register_dev(struct stdio_dev *dev, struct stdio_dev **devp) |
91d3256c6 Initial revision |
210 |
{ |
52cb4d4fb stdio/device: rew... |
211 |
struct stdio_dev *_dev; |
628ffd73b device: make devi... |
212 |
|
52cb4d4fb stdio/device: rew... |
213 |
_dev = stdio_clone(dev); |
628ffd73b device: make devi... |
214 |
if(!_dev) |
d97143a67 stdio: Provide fu... |
215 |
return -ENODEV; |
3e3c026ed devices: Use list... |
216 |
list_add_tail(&(_dev->list), &(devs.list)); |
d97143a67 stdio: Provide fu... |
217 218 |
if (devp) *devp = _dev; |
91d3256c6 Initial revision |
219 220 |
return 0; } |
d97143a67 stdio: Provide fu... |
221 222 223 224 |
int stdio_register(struct stdio_dev *dev) { return stdio_register_dev(dev, NULL); } |
91d3256c6 Initial revision |
225 226 227 |
/* deregister the device "devname". * returns 0 if success, -1 if device is assigned and 1 if devname not found */ |
869588dec Convert CONFIG_SY... |
228 |
#if CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER) |
32d019265 stdio: Add force ... |
229 |
int stdio_deregister_dev(struct stdio_dev *dev, int force) |
91d3256c6 Initial revision |
230 |
{ |
c1de7a6da devices: merge to... |
231 232 |
int l; struct list_head *pos; |
03bf22f55 stdio: Fix a poss... |
233 |
char temp_names[3][16]; |
91d3256c6 Initial revision |
234 |
|
91d3256c6 Initial revision |
235 236 237 |
/* get stdio devices (ListRemoveItem changes the dev list) */ for (l=0 ; l< MAX_FILES; l++) { if (stdio_devices[l] == dev) { |
32d019265 stdio: Add force ... |
238 239 240 241 |
if (force) { strcpy(temp_names[l], "nulldev"); continue; } |
91d3256c6 Initial revision |
242 243 244 245 246 |
/* Device is assigned -> report error */ return -1; } memcpy (&temp_names[l][0], stdio_devices[l]->name, |
03bf22f55 stdio: Fix a poss... |
247 |
sizeof(temp_names[l])); |
91d3256c6 Initial revision |
248 |
} |
c1de7a6da devices: merge to... |
249 250 |
list_del(&(dev->list)); |
88274b6c4 stdio: Fix memlea... |
251 |
free(dev); |
c1de7a6da devices: merge to... |
252 |
|
91d3256c6 Initial revision |
253 |
/* reassign Device list */ |
c1de7a6da devices: merge to... |
254 |
list_for_each(pos, &(devs.list)) { |
52cb4d4fb stdio/device: rew... |
255 |
dev = list_entry(pos, struct stdio_dev, list); |
91d3256c6 Initial revision |
256 |
for (l=0 ; l< MAX_FILES; l++) { |
c1de7a6da devices: merge to... |
257 |
if(strcmp(dev->name, temp_names[l]) == 0) |
91d3256c6 Initial revision |
258 |
stdio_devices[l] = dev; |
91d3256c6 Initial revision |
259 260 261 262 |
} } return 0; } |
d97143a67 stdio: Provide fu... |
263 |
|
32d019265 stdio: Add force ... |
264 |
int stdio_deregister(const char *devname, int force) |
d97143a67 stdio: Provide fu... |
265 266 267 268 269 270 271 |
{ struct stdio_dev *dev; dev = stdio_get_by_name(devname); if (!dev) /* device not found */ return -ENODEV; |
32d019265 stdio: Add force ... |
272 |
return stdio_deregister_dev(dev, force); |
d97143a67 stdio: Provide fu... |
273 |
} |
869588dec Convert CONFIG_SY... |
274 |
#endif /* CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER) */ |
91d3256c6 Initial revision |
275 |
|
9fb02491f dm: Make driver m... |
276 |
int stdio_init_tables(void) |
91d3256c6 Initial revision |
277 |
{ |
2e5167cca Replace CONFIG_RE... |
278 |
#if defined(CONFIG_NEEDS_MANUAL_RELOC) |
521af04d8 Conditionally per... |
279 |
/* already relocated for current ARM implementation */ |
91d3256c6 Initial revision |
280 |
ulong relocation_offset = gd->reloc_off; |
3595ac497 * Patch by Rune T... |
281 |
int i; |
91d3256c6 Initial revision |
282 283 284 285 286 287 |
/* 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... |
288 |
#endif /* CONFIG_NEEDS_MANUAL_RELOC */ |
91d3256c6 Initial revision |
289 290 |
/* Initialize the list */ |
c1de7a6da devices: merge to... |
291 |
INIT_LIST_HEAD(&(devs.list)); |
91d3256c6 Initial revision |
292 |
|
9fb02491f dm: Make driver m... |
293 294 295 296 297 |
return 0; } int stdio_add_devices(void) { |
b206cd737 dm: stdio: Plumb ... |
298 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 |
#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... |
325 |
#ifdef CONFIG_SYS_I2C |
3f4978c71 i2c: common chang... |
326 |
i2c_init_all(); |
3f4978c71 i2c: common chang... |
327 |
#else |
3f4978c71 i2c: common chang... |
328 |
#endif |
e3b81c1c0 dm: stdio: video:... |
329 |
#ifdef CONFIG_DM_VIDEO |
d8441ea27 dm: stdio: Allow ... |
330 331 332 333 334 335 336 337 338 339 |
/* * 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:... |
340 |
struct udevice *vdev; |
35a1f0dfa stdio: Correct a ... |
341 342 343 |
# ifndef CONFIG_DM_KEYBOARD int ret; # endif |
e3b81c1c0 dm: stdio: video:... |
344 345 346 347 348 349 350 351 |
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 ... |
352 |
#endif /* !CONFIG_SYS_CONSOLE_IS_IN_ENV */ |
e3b81c1c0 dm: stdio: video:... |
353 354 |
#else # if defined(CONFIG_LCD) |
91d3256c6 Initial revision |
355 |
drv_lcd_init (); |
e3b81c1c0 dm: stdio: video:... |
356 357 |
# endif # if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) |
91d3256c6 Initial revision |
358 |
drv_video_init (); |
e3b81c1c0 dm: stdio: video:... |
359 360 |
# endif #endif /* CONFIG_DM_VIDEO */ |
b206cd737 dm: stdio: Plumb ... |
361 |
#if defined(CONFIG_KEYBOARD) && !defined(CONFIG_DM_KEYBOARD) |
682011ff6 * Patches by Udi ... |
362 |
drv_keyboard_init (); |
91d3256c6 Initial revision |
363 364 |
#endif drv_system_init (); |
52cb4d4fb stdio/device: rew... |
365 |
serial_stdio_init (); |
232c150a2 Add support for S... |
366 367 368 |
#ifdef CONFIG_USB_TTY drv_usbtty_init (); #endif |
68ceb29e7 Add support for c... |
369 370 371 |
#ifdef CONFIG_NETCONSOLE drv_nc_init (); #endif |
36ea8e9ad Blackfin: support... |
372 373 374 |
#ifdef CONFIG_JTAG_CONSOLE drv_jtag_console_init (); #endif |
98ab435f7 x86: Add CBMEM co... |
375 376 377 |
#ifdef CONFIG_CBMEM_CONSOLE cbmemc_init(); #endif |
9fb02491f dm: Make driver m... |
378 379 380 381 382 383 384 385 386 387 |
return 0; } int stdio_init(void) { stdio_init_tables(); stdio_add_devices(); return 0; |
91d3256c6 Initial revision |
388 |
} |