ns16550.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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[] =
  10. { (NS16550_t) ((CFG_EUMB_ADDR) + 0x4500),
  11. (NS16550_t) ((CFG_EUMB_ADDR) + 0x4600) };
  12. volatile struct NS16550 *NS16550_init (int chan, int baud_divisor)
  13. {
  14. volatile struct NS16550 *com_port;
  15. com_port = (struct NS16550 *) COM_PORTS[chan];
  16. com_port->ier = 0x00;
  17. com_port->lcr = LCR_BKSE; /* Access baud rate */
  18. com_port->dll = baud_divisor & 0xff; /* 9600 baud */
  19. com_port->dlm = (baud_divisor >> 8) & 0xff;
  20. com_port->lcr = LCR_8N1; /* 8 data, 1 stop, no parity */
  21. com_port->mcr = MCR_RTS; /* RTS/DTR */
  22. com_port->fcr = FCR_FIFO_EN | FCR_RXSR | FCR_TXSR; /* Clear & enable FIFOs */
  23. return (com_port);
  24. }
  25. void 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 NS16550_getc (volatile struct NS16550 *com_port)
  41. {
  42. while ((com_port->lsr & LSR_DR) == 0);
  43. return (com_port->rbr);
  44. }
  45. int NS16550_tstc (volatile struct NS16550 *com_port)
  46. {
  47. return ((com_port->lsr & LSR_DR) != 0);
  48. }