serial.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #ifndef __SERIAL_H__
  2. #define __SERIAL_H__
  3. #include <post.h>
  4. struct serial_device {
  5. /* enough bytes to match alignment of following func pointer */
  6. char name[16];
  7. int (*start)(void);
  8. int (*stop)(void);
  9. void (*setbrg)(void);
  10. int (*getc)(void);
  11. int (*tstc)(void);
  12. void (*putc)(const char c);
  13. void (*puts)(const char *s);
  14. #if CONFIG_POST & CONFIG_SYS_POST_UART
  15. void (*loop)(int);
  16. #endif
  17. struct serial_device *next;
  18. };
  19. void default_serial_puts(const char *s);
  20. extern struct serial_device serial_smc_device;
  21. extern struct serial_device serial_scc_device;
  22. extern struct serial_device *default_serial_console(void);
  23. #if defined(CONFIG_405GP) || \
  24. defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
  25. defined(CONFIG_405EX) || defined(CONFIG_440) || \
  26. defined(CONFIG_MPC5xxx) || \
  27. defined(CONFIG_MPC83xx) || defined(CONFIG_MPC85xx) || \
  28. defined(CONFIG_MPC86xx) || defined(CONFIG_SYS_SC520) || \
  29. defined(CONFIG_TEGRA) || defined(CONFIG_SYS_COREBOOT) || \
  30. defined(CONFIG_MICROBLAZE)
  31. extern struct serial_device serial0_device;
  32. extern struct serial_device serial1_device;
  33. #endif
  34. extern struct serial_device eserial1_device;
  35. extern struct serial_device eserial2_device;
  36. extern struct serial_device eserial3_device;
  37. extern struct serial_device eserial4_device;
  38. extern struct serial_device eserial5_device;
  39. extern struct serial_device eserial6_device;
  40. extern void serial_register(struct serial_device *);
  41. extern void serial_initialize(void);
  42. extern void serial_stdio_init(void);
  43. extern int serial_assign(const char *name);
  44. extern void serial_reinit_all(void);
  45. /* For usbtty */
  46. #ifdef CONFIG_USB_TTY
  47. extern int usbtty_getc(void);
  48. extern void usbtty_putc(const char c);
  49. extern void usbtty_puts(const char *str);
  50. extern int usbtty_tstc(void);
  51. #else
  52. /* stubs */
  53. #define usbtty_getc() 0
  54. #define usbtty_putc(a)
  55. #define usbtty_puts(a)
  56. #define usbtty_tstc() 0
  57. #endif /* CONFIG_USB_TTY */
  58. #if defined(CONFIG_MPC512X)
  59. extern struct stdio_dev *open_port(int num, int baudrate);
  60. extern int close_port(int num);
  61. extern int write_port(struct stdio_dev *port, char *buf);
  62. extern int read_port(struct stdio_dev *port, char *buf, int size);
  63. #endif
  64. struct udevice;
  65. /**
  66. * struct struct dm_serial_ops - Driver model serial operations
  67. *
  68. * The uclass interface is implemented by all serial devices which use
  69. * driver model.
  70. */
  71. struct dm_serial_ops {
  72. /**
  73. * setbrg() - Set up the baud rate generator
  74. *
  75. * Adjust baud rate divisors to set up a new baud rate for this
  76. * device. Not all devices will support all rates. If the rate
  77. * cannot be supported, the driver is free to select the nearest
  78. * available rate. or return -EINVAL if this is not possible.
  79. *
  80. * @dev: Device pointer
  81. * @baudrate: New baud rate to use
  82. * @return 0 if OK, -ve on error
  83. */
  84. int (*setbrg)(struct udevice *dev, int baudrate);
  85. /**
  86. * getc() - Read a character and return it
  87. *
  88. * If no character is available, this should return -EAGAIN without
  89. * waiting.
  90. *
  91. * @dev: Device pointer
  92. * @return character (0..255), -ve on error
  93. */
  94. int (*getc)(struct udevice *dev);
  95. /**
  96. * putc() - Write a character
  97. *
  98. * @dev: Device pointer
  99. * @ch: character to write
  100. * @return 0 if OK, -ve on error
  101. */
  102. int (*putc)(struct udevice *dev, const char ch);
  103. /**
  104. * pending() - Check if input/output characters are waiting
  105. *
  106. * This can be used to return an indication of the number of waiting
  107. * characters if the driver knows this (e.g. by looking at the FIFO
  108. * level). It is acceptable to return 1 if an indeterminant number
  109. * of characters is waiting.
  110. *
  111. * This method is optional.
  112. *
  113. * @dev: Device pointer
  114. * @input: true to check input characters, false for output
  115. * @return number of waiting characters, 0 for none, -ve on error
  116. */
  117. int (*pending)(struct udevice *dev, bool input);
  118. /**
  119. * clear() - Clear the serial FIFOs/holding registers
  120. *
  121. * This method is optional.
  122. *
  123. * This quickly clears any input/output characters from the UART.
  124. * If this is not possible, but characters still exist, then it
  125. * is acceptable to return -EAGAIN (try again) or -EINVAL (not
  126. * supported).
  127. *
  128. * @dev: Device pointer
  129. * @return 0 if OK, -ve on error
  130. */
  131. int (*clear)(struct udevice *dev);
  132. #if CONFIG_POST & CONFIG_SYS_POST_UART
  133. /**
  134. * loop() - Control serial device loopback mode
  135. *
  136. * @dev: Device pointer
  137. * @on: 1 to turn loopback on, 0 to turn if off
  138. */
  139. int (*loop)(struct udevice *dev, int on);
  140. #endif
  141. };
  142. /**
  143. * struct serial_dev_priv - information about a device used by the uclass
  144. *
  145. * @sdev: stdio device attached to this uart
  146. */
  147. struct serial_dev_priv {
  148. struct stdio_dev *sdev;
  149. };
  150. /* Access the serial operations for a device */
  151. #define serial_get_ops(dev) ((struct dm_serial_ops *)(dev)->driver->ops)
  152. void amirix_serial_initialize(void);
  153. void arc_serial_initialize(void);
  154. void arm_dcc_initialize(void);
  155. void asc_serial_initialize(void);
  156. void atmel_serial_initialize(void);
  157. void au1x00_serial_initialize(void);
  158. void bfin_jtag_initialize(void);
  159. void bfin_serial_initialize(void);
  160. void bmw_serial_initialize(void);
  161. void clps7111_serial_initialize(void);
  162. void cogent_serial_initialize(void);
  163. void cpci750_serial_initialize(void);
  164. void evb64260_serial_initialize(void);
  165. void imx_serial_initialize(void);
  166. void iop480_serial_initialize(void);
  167. void jz_serial_initialize(void);
  168. void leon2_serial_initialize(void);
  169. void leon3_serial_initialize(void);
  170. void lh7a40x_serial_initialize(void);
  171. void lpc32xx_serial_initialize(void);
  172. void marvell_serial_initialize(void);
  173. void max3100_serial_initialize(void);
  174. void mcf_serial_initialize(void);
  175. void ml2_serial_initialize(void);
  176. void mpc512x_serial_initialize(void);
  177. void mpc5xx_serial_initialize(void);
  178. void mpc8260_scc_serial_initialize(void);
  179. void mpc8260_smc_serial_initialize(void);
  180. void mpc85xx_serial_initialize(void);
  181. void mpc8xx_serial_initialize(void);
  182. void mxc_serial_initialize(void);
  183. void mxs_auart_initialize(void);
  184. void ns16550_serial_initialize(void);
  185. void oc_serial_initialize(void);
  186. void p3mx_serial_initialize(void);
  187. void pl01x_serial_initialize(void);
  188. void pxa_serial_initialize(void);
  189. void s3c24xx_serial_initialize(void);
  190. void s5p_serial_initialize(void);
  191. void sa1100_serial_initialize(void);
  192. void sandbox_serial_initialize(void);
  193. void sconsole_serial_initialize(void);
  194. void sh_serial_initialize(void);
  195. void uartlite_serial_initialize(void);
  196. void zynq_serial_initialize(void);
  197. #endif