3 #include "short_types.h"
7 DECLARE_GLOBAL_DATA_PTR;
9 #ifndef CONFIG_SYS_NS16550
10 static uint32 ComPort1;
12 uint16 SerialEcho = 1;
15 #define RECEIVER_HOLDING 0
16 #define TRANSMITTER_HOLDING 0
17 #define INTERRUPT_ENABLE 1
18 #define INTERRUPT_STATUS 2
19 #define FIFO_CONTROL 2
20 #define LINE_CONTROL 3
21 #define MODEM_CONTROL 4
23 #define MODEM_STATUS 6
26 #define DIVISOR_LATCH_LSB 0
27 #define DIVISOR_LATCH_MSB 1
28 #define PRESCALER_DIVISION 5
30 #define COM_WRITE_BYTE(reg, byte) out_byte((ComPort1+reg), byte)
31 #define COM_READ_BYTE(reg) in_byte((ComPort1+reg))
33 static int serial_init_done = 0;
35 void serial_init (void)
38 uint32 clock_divisor = 115200 / baudrate;
41 uint16 devfn = 7 << 3;
46 /* Enter configuration mode */
47 cfg = pci_read_cfg_byte (0, devfn, 0x85);
48 pci_write_cfg_byte (0, devfn, 0x85, cfg | 0x02);
50 /* Set serial port COM1 as 3F8 */
51 out_byte (0x3F0, 0xE7);
52 out_byte (0x3f1, 0xfe);
54 /* Set serial port COM2 as 2F8 */
55 out_byte (0x3f0, 0xe8);
56 out_byte (0x3f1, 0xeb);
59 out_byte (0x3f0, 0xe2);
62 out_byte (0x3f0, 0xe2);
65 /* Reset the configuration mode */
66 pci_write_cfg_byte (0, devfn, 0x85, cfg);
71 /* Disable interrupts */
72 COM_WRITE_BYTE (INTERRUPT_ENABLE, 0x00);
75 /* COM_WRITE_BYTE(LINE_CONTROL, 0x83); */
76 /* COM_WRITE_BYTE(DIVISOR_LATCH_LSB, (uint8)(clock_divisor & 0xFF)); */
77 /* COM_WRITE_BYTE(DIVISOR_LATCH_MSB, (uint8)(clock_divisor >> 8)); */
78 /* __asm__("eieio"); */
81 COM_WRITE_BYTE (LINE_CONTROL, 0x03);
85 COM_WRITE_BYTE (MODEM_CONTROL, 0x03);
86 COM_WRITE_BYTE (FIFO_CONTROL, 0x07);
92 extern int console_changed;
94 void serial_putc (const char sendme)
97 while ((in_byte (0x3FD) & 0x40) == 0);
98 out_byte (0x3f8, 0x0D);
101 while ((in_byte (0x3FD) & 0x40) == 0);
102 out_byte (0x3f8, sendme);
105 int serial_getc (void)
111 uint8 x = in_byte (0x3FD);
117 out_byte (0x3fd, 0x0c);
124 while ((in_byte (0x3FD) & 0x01) == 0) {
125 if (console_changed != 0) {
126 printf ("Console changed\n");
131 return in_byte (0x3F8);
135 int serial_tstc (void)
137 return (in_byte (0x03FD) & 0x01) != 0;
140 void serial_debug_putc (int c)
150 const NS16550_t Com0 = (NS16550_t) CONFIG_SYS_NS16550_COM1;
151 const NS16550_t Com1 = (NS16550_t) CONFIG_SYS_NS16550_COM2;
153 int serial_init (void)
155 uint32 clock_divisor = 115200 / gd->baudrate;
157 NS16550_init (Com0, clock_divisor);
158 /* NS16550_reinit(Com1, clock_divisor); */
159 /* serial_puts("COM1: 3F8h initalized"); */
165 void serial_putc (const char c)
167 NS16550_putc (Com0, c);
169 NS16550_putc (Com0, 0x0D);
172 int serial_getc (void)
174 return (int) NS16550_getc (Com0);
177 int serial_tstc (void)
179 return NS16550_tstc (Com0);
182 void serial_putc (const char sendme)
184 if (sendme == '\n') {
185 while ((in_byte (0x3FD) & 0x40) == 0);
186 out_byte (0x3f8, 0x0D);
189 while ((in_byte (0x3FD) & 0x40) == 0);
190 out_byte (0x3f8, sendme);
194 extern int console_changed;
196 int serial_getc (void)
202 uint8 x = in_byte (0x3FD);
208 out_byte (0x3fd, 0x0c);
215 while ((in_byte (0x3FD) & 0x01) == 0) {
216 if (console_changed != 0) {
222 return in_byte (0x3F8);
226 int serial_tstc (void)
228 return (in_byte (0x03FD) & 0x01) != 0;
234 void serial_puts (const char *string)
237 serial_putc (*string++);
240 void serial_setbrg (void)
242 uint32 clock_divisor = 115200 / gd->baudrate;
244 NS16550_init (Com0, clock_divisor);