ns16550.c 1.9 KB

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