ns16550.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #ifdef CONFIG_OMAP1510
  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. return (com_port->rbr);
  47. }
  48. int NS16550_tstc (NS16550_t com_port)
  49. {
  50. return ((com_port->lsr & LSR_DR) != 0);
  51. }
  52. #endif