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 /* |
| 89 * And a little while for the other end to get ready for the |
| 90 * madness ahead. |
| 91 */ |
| 92 udelay(100); |
| 93 } |
| 94 |
67 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ | 95 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ |
68 | 96 |
69 void NS16550_putc (NS16550_t com_port, char c) | 97 void NS16550_putc (NS16550_t com_port, char c) |
70 { | 98 { |
71 while ((serial_in(&com_port->lsr) & UART_LSR_THRE) == 0); | 99 while ((serial_in(&com_port->lsr) & UART_LSR_THRE) == 0); |
72 serial_out(c, &com_port->thr); | 100 serial_out(c, &com_port->thr); |
73 } | 101 } |
74 | 102 |
75 #ifndef CONFIG_NS16550_MIN_FUNCTIONS | 103 #ifndef CONFIG_NS16550_MIN_FUNCTIONS |
76 char NS16550_getc (NS16550_t com_port) | 104 char NS16550_getc (NS16550_t com_port) |
77 { | 105 { |
78 while ((serial_in(&com_port->lsr) & UART_LSR_DR) == 0) { | 106 while ((serial_in(&com_port->lsr) & UART_LSR_DR) == 0) { |
79 #ifdef CONFIG_USB_TTY | 107 #ifdef CONFIG_USB_TTY |
80 extern void usbtty_poll(void); | 108 extern void usbtty_poll(void); |
81 usbtty_poll(); | 109 usbtty_poll(); |
82 #endif | 110 #endif |
83 WATCHDOG_RESET(); | 111 WATCHDOG_RESET(); |
84 } | 112 } |
85 return serial_in(&com_port->rbr); | 113 return serial_in(&com_port->rbr); |
86 } | 114 } |
87 | 115 |
88 int NS16550_tstc (NS16550_t com_port) | 116 int NS16550_tstc (NS16550_t com_port) |
89 { | 117 { |
90 return ((serial_in(&com_port->lsr) & UART_LSR_DR) != 0); | 118 return ((serial_in(&com_port->lsr) & UART_LSR_DR) != 0); |
91 } | 119 } |
92 | 120 |
93 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ | 121 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ |
OLD | NEW |