ns16550.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_OMAP1510
  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_OMAP1510) || defined(CONFIG_OMAP1610)
  25. com_port->mdr1 = 0; /* select uart mode */
  26. #endif
  27. }
  28. void NS16550_reinit (NS16550_t com_port, int baud_divisor)
  29. {
  30. com_port->ier = 0x00;
  31. com_port->lcr = LCR_BKSE;
  32. com_port->dll = baud_divisor & 0xff;
  33. com_port->dlm = (baud_divisor >> 8) & 0xff;
  34. com_port->lcr = LCRVAL;
  35. com_port->mcr = MCRVAL;
  36. com_port->fcr = FCRVAL;
  37. }
  38. void NS16550_putc (NS16550_t com_port, char c)
  39. {
  40. while ((com_port->lsr & LSR_THRE) == 0);
  41. com_port->thr = c;
  42. }
  43. char NS16550_getc (NS16550_t com_port)
  44. {
  45. while ((com_port->lsr & LSR_DR) == 0) {
  46. #ifdef CONFIG_USB_TTY
  47. extern void usbtty_poll(void);
  48. usbtty_poll();
  49. #endif
  50. }
  51. return (com_port->rbr);
  52. }
  53. int NS16550_tstc (NS16550_t com_port)
  54. {
  55. return ((com_port->lsr & LSR_DR) != 0);
  56. }
  57. #endif