ns16550.c 2.2 KB

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