ns16550.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * COM1 NS16550 support
  3. * originally from linux source (arch/ppc/boot/ns16550.c)
  4. * modified to use CFG_ISA_MEM and new defines
  5. */
  6. #include <config.h>
  7. #ifdef CFG_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 = baud_divisor & 0xff;
  20. com_port->dlm = (baud_divisor >> 8) & 0xff;
  21. com_port->lcr = LCRVAL;
  22. com_port->mcr = MCRVAL;
  23. com_port->fcr = FCRVAL;
  24. #if defined(CONFIG_OMAP)
  25. #if defined(CONFIG_APTIX)
  26. com_port->mdr1 = 3; /* /13 mode so Aptix 6MHz can hit 115200 */
  27. #else
  28. com_port->mdr1 = 0; /* /16 is proper to hit 115200 with 48MHz */
  29. #endif
  30. #endif
  31. }
  32. void NS16550_reinit (NS16550_t com_port, int baud_divisor)
  33. {
  34. com_port->ier = 0x00;
  35. com_port->lcr = LCR_BKSE;
  36. com_port->dll = baud_divisor & 0xff;
  37. com_port->dlm = (baud_divisor >> 8) & 0xff;
  38. com_port->lcr = LCRVAL;
  39. com_port->mcr = MCRVAL;
  40. com_port->fcr = FCRVAL;
  41. }
  42. void NS16550_putc (NS16550_t com_port, char c)
  43. {
  44. while ((com_port->lsr & LSR_THRE) == 0);
  45. com_port->thr = c;
  46. }
  47. char NS16550_getc (NS16550_t com_port)
  48. {
  49. while ((com_port->lsr & LSR_DR) == 0) {
  50. #ifdef CONFIG_USB_TTY
  51. extern void usbtty_poll(void);
  52. usbtty_poll();
  53. #endif
  54. }
  55. return (com_port->rbr);
  56. }
  57. int NS16550_tstc (NS16550_t com_port)
  58. {
  59. return ((com_port->lsr & LSR_DR) != 0);
  60. }
  61. #endif