ns16550.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #include "ns16550.h"
  8. typedef struct NS16550 *NS16550_t;
  9. const NS16550_t COM_PORTS[] = { (NS16550_t) ((CFG_EUMB_ADDR) + 0x4500), (NS16550_t) ((CFG_EUMB_ADDR) + 0x4600)};
  10. volatile struct NS16550 *
  11. NS16550_init(int chan, int baud_divisor)
  12. {
  13. volatile struct NS16550 *com_port;
  14. com_port = (struct NS16550 *) COM_PORTS[chan];
  15. com_port->ier = 0x00;
  16. com_port->lcr = LCR_BKSE; /* Access baud rate */
  17. com_port->dll = baud_divisor & 0xff; /* 9600 baud */
  18. com_port->dlm = (baud_divisor >> 8) & 0xff;
  19. com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */
  20. com_port->mcr = MCR_RTS; /* RTS/DTR */
  21. com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; /* Clear & enable FIFOs */
  22. return (com_port);
  23. }
  24. void
  25. NS16550_reinit(volatile struct NS16550 *com_port, int baud_divisor)
  26. {
  27. com_port->ier = 0x00;
  28. com_port->lcr = LCR_BKSE; /* Access baud rate */
  29. com_port->dll = baud_divisor & 0xff; /* 9600 baud */
  30. com_port->dlm = (baud_divisor >> 8) & 0xff;
  31. com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */
  32. com_port->mcr = MCR_RTS; /* RTS/DTR */
  33. com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; /* Clear & enable FIFOs */
  34. }
  35. void NS16550_putc(volatile struct NS16550 *com_port, unsigned char c)
  36. {
  37. while ((com_port->lsr & LSR_THRE) == 0) ;
  38. com_port->thr = c;
  39. }
  40. unsigned char
  41. NS16550_getc(volatile struct NS16550 *com_port)
  42. {
  43. while ((com_port->lsr & LSR_DR) == 0) ;
  44. return (com_port->rbr);
  45. }
  46. int NS16550_tstc(volatile struct NS16550 *com_port)
  47. {
  48. return ((com_port->lsr & LSR_DR) != 0);
  49. }