ns16550.c 1.9 KB

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