ns16550.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * COM1 NS16550 support
  3. * originally from linux source (arch/ppc/boot/ns16550.c)
  4. * modified to use CONFIG_SYS_ISA_MEM and new defines
  5. */
  6. #include <config.h>
  7. #include <ns16550.h>
  8. #define UART_LCRVAL UART_LCR_8N1 /* 8 data, 1 stop, no parity */
  9. #define UART_MCRVAL (UART_MCR_DTR | \
  10. UART_MCR_RTS) /* RTS/DTR */
  11. #define UART_FCRVAL (UART_FCR_FIFO_EN | \
  12. UART_FCR_RXSR | \
  13. UART_FCR_TXSR) /* Clear & enable FIFOs */
  14. void NS16550_init (NS16550_t com_port, int baud_divisor)
  15. {
  16. com_port->ier = 0x00;
  17. #if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2)
  18. com_port->mdr1 = 0x7; /* mode select reset TL16C750*/
  19. #endif
  20. com_port->lcr = UART_LCR_BKSE | UART_LCRVAL;
  21. com_port->dll = 0;
  22. com_port->dlm = 0;
  23. com_port->lcr = UART_LCRVAL;
  24. com_port->mcr = UART_MCRVAL;
  25. com_port->fcr = UART_FCRVAL;
  26. com_port->lcr = UART_LCR_BKSE | UART_LCRVAL;
  27. com_port->dll = baud_divisor & 0xff;
  28. com_port->dlm = (baud_divisor >> 8) & 0xff;
  29. com_port->lcr = UART_LCRVAL;
  30. #if defined(CONFIG_OMAP) && !defined(CONFIG_OMAP3_ZOOM2)
  31. #if defined(CONFIG_APTIX)
  32. com_port->mdr1 = 3; /* /13 mode so Aptix 6MHz can hit 115200 */
  33. #else
  34. com_port->mdr1 = 0; /* /16 is proper to hit 115200 with 48MHz */
  35. #endif
  36. #endif /* CONFIG_OMAP */
  37. }
  38. #ifndef CONFIG_NS16550_MIN_FUNCTIONS
  39. void NS16550_reinit (NS16550_t com_port, int baud_divisor)
  40. {
  41. com_port->ier = 0x00;
  42. com_port->lcr = UART_LCR_BKSE | UART_LCRVAL;
  43. com_port->dll = 0;
  44. com_port->dlm = 0;
  45. com_port->lcr = UART_LCRVAL;
  46. com_port->mcr = UART_MCRVAL;
  47. com_port->fcr = UART_FCRVAL;
  48. com_port->lcr = UART_LCR_BKSE;
  49. com_port->dll = baud_divisor & 0xff;
  50. com_port->dlm = (baud_divisor >> 8) & 0xff;
  51. com_port->lcr = UART_LCRVAL;
  52. }
  53. #endif /* CONFIG_NS16550_MIN_FUNCTIONS */
  54. void NS16550_putc (NS16550_t com_port, char c)
  55. {
  56. while ((com_port->lsr & UART_LSR_THRE) == 0);
  57. com_port->thr = c;
  58. }
  59. #ifndef CONFIG_NS16550_MIN_FUNCTIONS
  60. char NS16550_getc (NS16550_t com_port)
  61. {
  62. while ((com_port->lsr & UART_LSR_DR) == 0) {
  63. #ifdef CONFIG_USB_TTY
  64. extern void usbtty_poll(void);
  65. usbtty_poll();
  66. #endif
  67. }
  68. return (com_port->rbr);
  69. }
  70. int NS16550_tstc (NS16550_t com_port)
  71. {
  72. return ((com_port->lsr & UART_LSR_DR) != 0);
  73. }
  74. #endif /* CONFIG_NS16550_MIN_FUNCTIONS */