3 #include "short_types.h"
8 static uint32 ComPort1;
10 uint16 SerialEcho = 1;
13 #define RECEIVER_HOLDING 0
14 #define TRANSMITTER_HOLDING 0
15 #define INTERRUPT_ENABLE 1
16 #define INTERRUPT_STATUS 2
17 #define FIFO_CONTROL 2
18 #define LINE_CONTROL 3
19 #define MODEM_CONTROL 4
21 #define MODEM_STATUS 6
24 #define DIVISOR_LATCH_LSB 0
25 #define DIVISOR_LATCH_MSB 1
26 #define PRESCALER_DIVISION 5
28 #define COM_WRITE_BYTE(reg, byte) out_byte((ComPort1+reg), byte)
29 #define COM_READ_BYTE(reg) in_byte((ComPort1+reg))
31 static int serial_init_done = 0;
33 void serial_init (void)
36 uint32 clock_divisor = 115200 / baudrate;
39 uint16 devfn = 7 << 3;
44 /* Enter configuration mode */
45 cfg = pci_read_cfg_byte (0, devfn, 0x85);
46 pci_write_cfg_byte (0, devfn, 0x85, cfg | 0x02);
48 /* Set serial port COM1 as 3F8 */
49 out_byte (0x3F0, 0xE7);
50 out_byte (0x3f1, 0xfe);
52 /* Set serial port COM2 as 2F8 */
53 out_byte (0x3f0, 0xe8);
54 out_byte (0x3f1, 0xeb);
57 out_byte (0x3f0, 0xe2);
60 out_byte (0x3f0, 0xe2);
63 /* Reset the configuration mode */
64 pci_write_cfg_byte (0, devfn, 0x85, cfg);
69 /* Disable interrupts */
70 COM_WRITE_BYTE (INTERRUPT_ENABLE, 0x00);
73 /* COM_WRITE_BYTE(LINE_CONTROL, 0x83); */
74 /* COM_WRITE_BYTE(DIVISOR_LATCH_LSB, (uint8)(clock_divisor & 0xFF)); */
75 /* COM_WRITE_BYTE(DIVISOR_LATCH_MSB, (uint8)(clock_divisor >> 8)); */
79 COM_WRITE_BYTE (LINE_CONTROL, 0x03);
83 COM_WRITE_BYTE (MODEM_CONTROL, 0x03);
84 COM_WRITE_BYTE (FIFO_CONTROL, 0x07);
90 extern int console_changed;
92 void serial_putc (const char sendme)
95 while ((in_byte (0x3FD) & 0x40) == 0);
96 out_byte (0x3f8, 0x0D);
99 while ((in_byte (0x3FD) & 0x40) == 0);
100 out_byte (0x3f8, sendme);
103 int serial_getc (void)
109 uint8 x = in_byte (0x3FD);
115 out_byte (0x3fd, 0x0c);
122 while ((in_byte (0x3FD) & 0x01) == 0) {
123 if (console_changed != 0) {
124 printf ("Console changed\n");
129 return in_byte (0x3F8);
133 int serial_tstc (void)
135 return (in_byte (0x03FD) & 0x01) != 0;
138 void serial_debug_putc (int c)
148 const NS16550_t Com0 = (NS16550_t) CFG_NS16550_COM1;
149 const NS16550_t Com1 = (NS16550_t) CFG_NS16550_COM2;
151 int serial_init (void)
153 DECLARE_GLOBAL_DATA_PTR;
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 DECLARE_GLOBAL_DATA_PTR;
244 uint32 clock_divisor = 115200 / gd->baudrate;
246 NS16550_init (Com0, clock_divisor);