OLD | NEW |
1 /* | 1 /* |
2 * COM1 NS16550 support | 2 * COM1 NS16550 support |
3 * originally from linux source (arch/powerpc/boot/ns16550.c) | 3 * originally from linux source (arch/powerpc/boot/ns16550.c) |
4 * modified to use CONFIG_SYS_ISA_MEM and new defines | 4 * modified to use CONFIG_SYS_ISA_MEM and new defines |
5 */ | 5 */ |
6 | 6 |
7 #include <config.h> | 7 #include <config.h> |
8 #include <ns16550.h> | 8 #include <ns16550.h> |
9 #include <watchdog.h> | 9 #include <watchdog.h> |
10 #include <linux/types.h> | 10 #include <linux/types.h> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 serial_out(0, &com_port->dll); | 57 serial_out(0, &com_port->dll); |
58 serial_out(0, &com_port->dlm); | 58 serial_out(0, &com_port->dlm); |
59 serial_out(UART_LCRVAL, &com_port->lcr); | 59 serial_out(UART_LCRVAL, &com_port->lcr); |
60 serial_out(UART_MCRVAL, &com_port->mcr); | 60 serial_out(UART_MCRVAL, &com_port->mcr); |
61 serial_out(UART_FCRVAL, &com_port->fcr); | 61 serial_out(UART_FCRVAL, &com_port->fcr); |
62 serial_out(UART_LCR_BKSE, &com_port->lcr); | 62 serial_out(UART_LCR_BKSE, &com_port->lcr); |
63 serial_out(baud_divisor & 0xff, &com_port->dll); | 63 serial_out(baud_divisor & 0xff, &com_port->dll); |
64 serial_out((baud_divisor >> 8) & 0xff, &com_port->dlm); | 64 serial_out((baud_divisor >> 8) & 0xff, &com_port->dlm); |
65 serial_out(UART_LCRVAL, &com_port->lcr); | 65 serial_out(UART_LCRVAL, &com_port->lcr); |
66 } | 66 } |
| 67 |
| 68 /* Clear the UART's RX FIFO */ |
| 69 |
| 70 void NS16550_clear(NS16550_t com_port) |
| 71 { |
| 72 /* Reset RX fifo */ |
| 73 serial_out(UART_FCR_FIFO_EN | UART_FCR_RXSR, &com_port->fcr); |
| 74 |
| 75 /* Remove any pending characters */ |
| 76 while (NS16550_tstc(com_port)) |
| 77 NS16550_getc(com_port); |
| 78 } |
| 79 |
| 80 /* Wait for the UART's output buffer and holding register to drain */ |
| 81 |
| 82 void NS16550_drain(NS16550_t com_port) |
| 83 { |
| 84 /* Wait for the UART to finish sending */ |
| 85 while(!(serial_in(&com_port->lsr) & UART_LSR_TEMT)) |
| 86 udelay(100); |
| 87 } |
| 88 |
67 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ | 89 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ |
68 | 90 |
69 void NS16550_putc (NS16550_t com_port, char c) | 91 void NS16550_putc (NS16550_t com_port, char c) |
70 { | 92 { |
71 while ((serial_in(&com_port->lsr) & UART_LSR_THRE) == 0); | 93 while ((serial_in(&com_port->lsr) & UART_LSR_THRE) == 0); |
72 serial_out(c, &com_port->thr); | 94 serial_out(c, &com_port->thr); |
73 } | 95 } |
74 | 96 |
75 #ifndef CONFIG_NS16550_MIN_FUNCTIONS | 97 #ifndef CONFIG_NS16550_MIN_FUNCTIONS |
76 char NS16550_getc (NS16550_t com_port) | 98 char NS16550_getc (NS16550_t com_port) |
77 { | 99 { |
78 while ((serial_in(&com_port->lsr) & UART_LSR_DR) == 0) { | 100 while ((serial_in(&com_port->lsr) & UART_LSR_DR) == 0) { |
79 #ifdef CONFIG_USB_TTY | 101 #ifdef CONFIG_USB_TTY |
80 extern void usbtty_poll(void); | 102 extern void usbtty_poll(void); |
81 usbtty_poll(); | 103 usbtty_poll(); |
82 #endif | 104 #endif |
83 WATCHDOG_RESET(); | 105 WATCHDOG_RESET(); |
84 } | 106 } |
85 return serial_in(&com_port->rbr); | 107 return serial_in(&com_port->rbr); |
86 } | 108 } |
87 | 109 |
88 int NS16550_tstc (NS16550_t com_port) | 110 int NS16550_tstc (NS16550_t com_port) |
89 { | 111 { |
90 return ((serial_in(&com_port->lsr) & UART_LSR_DR) != 0); | 112 return ((serial_in(&com_port->lsr) & UART_LSR_DR) != 0); |
91 } | 113 } |
92 | 114 |
93 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ | 115 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ |
OLD | NEW |