ns16550.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * further modified by Josh Huber <huber@mclx.com> to support
  7. * the DUART on the Galileo Eval board. (db64360)
  8. */
  9. #include <config.h>
  10. #include "ns16550.h"
  11. #ifdef ZUMA_NTL
  12. /* no 16550 device */
  13. #else
  14. const NS16550_t COM_PORTS[] = { (NS16550_t) (CONFIG_SYS_DUART_IO + 0),
  15. (NS16550_t) (CONFIG_SYS_DUART_IO + 0x20)
  16. };
  17. volatile struct NS16550 *NS16550_init (int chan, int baud_divisor)
  18. {
  19. volatile struct NS16550 *com_port;
  20. com_port = (struct NS16550 *) COM_PORTS[chan];
  21. com_port->ier = 0x00;
  22. com_port->lcr = LCR_BKSE; /* Access baud rate */
  23. com_port->dll = baud_divisor & 0xff; /* 9600 baud */
  24. com_port->dlm = (baud_divisor >> 8) & 0xff;
  25. com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */
  26. com_port->mcr = MCR_DTR | MCR_RTS; /* RTS/DTR */
  27. /* Clear & enable FIFOs */
  28. com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR;
  29. return (com_port);
  30. }
  31. void NS16550_reinit (volatile struct NS16550 *com_port, int baud_divisor)
  32. {
  33. com_port->ier = 0x00;
  34. com_port->lcr = LCR_BKSE; /* Access baud rate */
  35. com_port->dll = baud_divisor & 0xff; /* 9600 baud */
  36. com_port->dlm = (baud_divisor >> 8) & 0xff;
  37. com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */
  38. com_port->mcr = MCR_DTR | MCR_RTS; /* RTS/DTR */
  39. /* Clear & enable FIFOs */
  40. com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR;
  41. }
  42. void NS16550_putc (volatile struct NS16550 *com_port, unsigned char c)
  43. {
  44. while ((com_port->lsr & LSR_THRE) == 0);
  45. com_port->thr = c;
  46. }
  47. unsigned char NS16550_getc (volatile struct NS16550 *com_port)
  48. {
  49. while ((com_port->lsr & LSR_DR) == 0);
  50. return (com_port->rbr);
  51. }
  52. int NS16550_tstc (volatile struct NS16550 *com_port)
  53. {
  54. return ((com_port->lsr & LSR_DR) != 0);
  55. }
  56. #endif