Commit 9cd2b9e47e0ea48f8f5c737044a8cb23528c7318
Committed by
Tom Rini
1 parent
dee1941604
Exists in
master
and in
54 other branches
kerneldoc: Annotate drivers/serial/serial.c
Add kerneldoc annotations into serial core. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Marek Vasut <marek.vasut@gmail.com> Cc: Tom Rini <trini@ti.com>
Showing 1 changed file with 165 additions and 0 deletions Side-by-side Diff
drivers/serial/serial.c
... | ... | @@ -33,10 +33,28 @@ |
33 | 33 | static struct serial_device *serial_devices; |
34 | 34 | static struct serial_device *serial_current; |
35 | 35 | |
36 | +/** | |
37 | + * serial_null() - Void registration routine of a serial driver | |
38 | + * | |
39 | + * This routine implements a void registration routine of a serial | |
40 | + * driver. The registration routine of a particular driver is aliased | |
41 | + * to this empty function in case the driver is not compiled into | |
42 | + * U-Boot. | |
43 | + */ | |
36 | 44 | static void serial_null(void) |
37 | 45 | { |
38 | 46 | } |
39 | 47 | |
48 | +/** | |
49 | + * serial_initfunc() - Forward declare of driver registration routine | |
50 | + * @name: Name of the real driver registration routine. | |
51 | + * | |
52 | + * This macro expands onto forward declaration of a driver registration | |
53 | + * routine, which is then used below in serial_initialize() function. | |
54 | + * The declaration is made weak and aliases to serial_null() so in case | |
55 | + * the driver is not compiled in, the function is still declared and can | |
56 | + * be used, but aliases to serial_null() and thus is optimized away. | |
57 | + */ | |
40 | 58 | #define serial_initfunc(name) \ |
41 | 59 | void name(void) \ |
42 | 60 | __attribute__((weak, alias("serial_null"))); |
... | ... | @@ -95,6 +113,16 @@ |
95 | 113 | serial_initfunc(sa1100_serial_initialize); |
96 | 114 | serial_initfunc(sh_serial_initialize); |
97 | 115 | |
116 | +/** | |
117 | + * serial_register() - Register serial driver with serial driver core | |
118 | + * @dev: Pointer to the serial driver structure | |
119 | + * | |
120 | + * This function registers the serial driver supplied via @dev with | |
121 | + * serial driver core, thus making U-Boot aware of it and making it | |
122 | + * available for U-Boot to use. On platforms that still require manual | |
123 | + * relocation of constant variables, relocation of the supplied structure | |
124 | + * is performed. | |
125 | + */ | |
98 | 126 | void serial_register(struct serial_device *dev) |
99 | 127 | { |
100 | 128 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
... | ... | @@ -118,6 +146,15 @@ |
118 | 146 | serial_devices = dev; |
119 | 147 | } |
120 | 148 | |
149 | +/** | |
150 | + * serial_initialize() - Register all compiled-in serial port drivers | |
151 | + * | |
152 | + * This function registers all serial port drivers that are compiled | |
153 | + * into the U-Boot binary with the serial core, thus making them | |
154 | + * available to U-Boot to use. Lastly, this function assigns a default | |
155 | + * serial port to the serial core. That serial port is then used as a | |
156 | + * default output. | |
157 | + */ | |
121 | 158 | void serial_initialize(void) |
122 | 159 | { |
123 | 160 | mpc8xx_serial_initialize(); |
... | ... | @@ -177,6 +214,13 @@ |
177 | 214 | serial_assign(default_serial_console()->name); |
178 | 215 | } |
179 | 216 | |
217 | +/** | |
218 | + * serial_stdio_init() - Register serial ports with STDIO core | |
219 | + * | |
220 | + * This function generates a proxy driver for each serial port driver. | |
221 | + * These proxy drivers then register with the STDIO core, making the | |
222 | + * serial drivers available as STDIO devices. | |
223 | + */ | |
180 | 224 | void serial_stdio_init(void) |
181 | 225 | { |
182 | 226 | struct stdio_dev dev; |
... | ... | @@ -201,6 +245,18 @@ |
201 | 245 | } |
202 | 246 | } |
203 | 247 | |
248 | +/** | |
249 | + * serial_assign() - Select the serial output device by name | |
250 | + * @name: Name of the serial driver to be used as default output | |
251 | + * | |
252 | + * This function configures the serial output multiplexing by | |
253 | + * selecting which serial device will be used as default. In case | |
254 | + * the STDIO "serial" device is selected as stdin/stdout/stderr, | |
255 | + * the serial device previously configured by this function will be | |
256 | + * used for the particular operation. | |
257 | + * | |
258 | + * Returns 0 on success, negative on error. | |
259 | + */ | |
204 | 260 | int serial_assign(const char *name) |
205 | 261 | { |
206 | 262 | struct serial_device *s; |
... | ... | @@ -215,6 +271,12 @@ |
215 | 271 | return -EINVAL; |
216 | 272 | } |
217 | 273 | |
274 | +/** | |
275 | + * serial_reinit_all() - Reinitialize all compiled-in serial ports | |
276 | + * | |
277 | + * This function reinitializes all serial ports that are compiled | |
278 | + * into U-Boot by calling their serial_start() functions. | |
279 | + */ | |
218 | 280 | void serial_reinit_all(void) |
219 | 281 | { |
220 | 282 | struct serial_device *s; |
... | ... | @@ -223,6 +285,21 @@ |
223 | 285 | s->start(); |
224 | 286 | } |
225 | 287 | |
288 | +/** | |
289 | + * get_current() - Return pointer to currently selected serial port | |
290 | + * | |
291 | + * This function returns a pointer to currently selected serial port. | |
292 | + * The currently selected serial port is altered by serial_assign() | |
293 | + * function. | |
294 | + * | |
295 | + * In case this function is called before relocation or before any serial | |
296 | + * port is configured, this function calls default_serial_console() to | |
297 | + * determine the serial port. Otherwise, the configured serial port is | |
298 | + * returned. | |
299 | + * | |
300 | + * Returns pointer to the currently selected serial port on success, | |
301 | + * NULL on error. | |
302 | + */ | |
226 | 303 | static struct serial_device *get_current(void) |
227 | 304 | { |
228 | 305 | struct serial_device *dev; |
229 | 306 | |
230 | 307 | |
231 | 308 | |
232 | 309 | |
233 | 310 | |
234 | 311 | |
... | ... | @@ -247,36 +324,113 @@ |
247 | 324 | return dev; |
248 | 325 | } |
249 | 326 | |
327 | +/** | |
328 | + * serial_init() - Initialize currently selected serial port | |
329 | + * | |
330 | + * This function initializes the currently selected serial port. This | |
331 | + * usually involves setting up the registers of that particular port, | |
332 | + * enabling clock and such. This function uses the get_current() call | |
333 | + * to determine which port is selected. | |
334 | + * | |
335 | + * Returns 0 on success, negative on error. | |
336 | + */ | |
250 | 337 | int serial_init(void) |
251 | 338 | { |
252 | 339 | return get_current()->start(); |
253 | 340 | } |
254 | 341 | |
342 | +/** | |
343 | + * serial_setbrg() - Configure baud-rate of currently selected serial port | |
344 | + * | |
345 | + * This function configures the baud-rate of the currently selected | |
346 | + * serial port. The baud-rate is retrieved from global data within | |
347 | + * the serial port driver. This function uses the get_current() call | |
348 | + * to determine which port is selected. | |
349 | + * | |
350 | + * Returns 0 on success, negative on error. | |
351 | + */ | |
255 | 352 | void serial_setbrg(void) |
256 | 353 | { |
257 | 354 | get_current()->setbrg(); |
258 | 355 | } |
259 | 356 | |
357 | +/** | |
358 | + * serial_getc() - Read character from currently selected serial port | |
359 | + * | |
360 | + * This function retrieves a character from currently selected serial | |
361 | + * port. In case there is no character waiting on the serial port, | |
362 | + * this function will block and wait for the character to appear. This | |
363 | + * function uses the get_current() call to determine which port is | |
364 | + * selected. | |
365 | + * | |
366 | + * Returns the character on success, negative on error. | |
367 | + */ | |
260 | 368 | int serial_getc(void) |
261 | 369 | { |
262 | 370 | return get_current()->getc(); |
263 | 371 | } |
264 | 372 | |
373 | +/** | |
374 | + * serial_tstc() - Test if data is available on currently selected serial port | |
375 | + * | |
376 | + * This function tests if one or more characters are available on | |
377 | + * currently selected serial port. This function never blocks. This | |
378 | + * function uses the get_current() call to determine which port is | |
379 | + * selected. | |
380 | + * | |
381 | + * Returns positive if character is available, zero otherwise. | |
382 | + */ | |
265 | 383 | int serial_tstc(void) |
266 | 384 | { |
267 | 385 | return get_current()->tstc(); |
268 | 386 | } |
269 | 387 | |
388 | +/** | |
389 | + * serial_putc() - Output character via currently selected serial port | |
390 | + * @c: Single character to be output from the serial port. | |
391 | + * | |
392 | + * This function outputs a character via currently selected serial | |
393 | + * port. This character is passed to the serial port driver responsible | |
394 | + * for controlling the hardware. The hardware may still be in process | |
395 | + * of transmitting another character, therefore this function may block | |
396 | + * for a short amount of time. This function uses the get_current() | |
397 | + * call to determine which port is selected. | |
398 | + */ | |
270 | 399 | void serial_putc(const char c) |
271 | 400 | { |
272 | 401 | get_current()->putc(c); |
273 | 402 | } |
274 | 403 | |
404 | +/** | |
405 | + * serial_puts() - Output string via currently selected serial port | |
406 | + * @s: Zero-terminated string to be output from the serial port. | |
407 | + * | |
408 | + * This function outputs a zero-terminated string via currently | |
409 | + * selected serial port. This function behaves as an accelerator | |
410 | + * in case the hardware can queue multiple characters for transfer. | |
411 | + * The whole string that is to be output is available to the function | |
412 | + * implementing the hardware manipulation. Transmitting the whole | |
413 | + * string may take some time, thus this function may block for some | |
414 | + * amount of time. This function uses the get_current() call to | |
415 | + * determine which port is selected. | |
416 | + */ | |
275 | 417 | void serial_puts(const char *s) |
276 | 418 | { |
277 | 419 | get_current()->puts(s); |
278 | 420 | } |
279 | 421 | |
422 | +/** | |
423 | + * default_serial_puts() - Output string by calling serial_putc() in loop | |
424 | + * @s: Zero-terminated string to be output from the serial port. | |
425 | + * | |
426 | + * This function outputs a zero-terminated string by calling serial_putc() | |
427 | + * in a loop. Most drivers do not support queueing more than one byte for | |
428 | + * transfer, thus this function precisely implements their serial_puts(). | |
429 | + * | |
430 | + * To optimize the number of get_current() calls, this function only | |
431 | + * calls get_current() once and then directly accesses the putc() call | |
432 | + * of the &struct serial_device . | |
433 | + */ | |
280 | 434 | void default_serial_puts(const char *s) |
281 | 435 | { |
282 | 436 | struct serial_device *dev = get_current(); |
... | ... | @@ -287,6 +441,17 @@ |
287 | 441 | #if CONFIG_POST & CONFIG_SYS_POST_UART |
288 | 442 | static const int bauds[] = CONFIG_SYS_BAUDRATE_TABLE; |
289 | 443 | |
444 | +/** | |
445 | + * uart_post_test() - Test the currently selected serial port using POST | |
446 | + * @flags: POST framework flags | |
447 | + * | |
448 | + * Do a loopback test of the currently selected serial port. This | |
449 | + * function is only useful in the context of the POST testing framwork. | |
450 | + * The serial port is firstly configured into loopback mode and then | |
451 | + * characters are sent through it. | |
452 | + * | |
453 | + * Returns 0 on success, value otherwise. | |
454 | + */ | |
290 | 455 | /* Mark weak until post/cpu/.../uart.c migrate over */ |
291 | 456 | __weak |
292 | 457 | int uart_post_test(int flags) |