2 * This code was rescued from arch/x86_64/exec/serialrawio.c before x86-64 port update.
3 * Perhaps it can be useful in future, however it's questionable whether it is really
4 * needed for debugging console.
8 #include <hardware/uart.h>
11 #define SER_UART_INS8250 1
12 #define SER_UART_NS16450 2
13 #define SER_UART_NS16550A 3
14 #define SER_UART_NS16C552 4
16 unsigned char __ser_UARTType(short port
)
18 outb_p(0xAA, port
+ UART_LCR
); /* set Divisor-Latch */
19 if (inb_p(port
+ UART_LCR
) != 0xAA)
21 outb_p(0x55, port
+ UART_DLM
); /* write Divisor */
22 if (inb_p(port
+ UART_DLM
) != 0x55)
24 outb_p(0x55, port
+ UART_LCR
); /* clear Divisor-Latch */
25 if (inb_p(port
+ UART_LCR
) != 0x55)
27 outb_p(0x55, port
+ UART_IER
);
28 if (inb_p(port
+ UART_IER
) != 0x05)
30 outb_p(0, port
+ UART_FCR
); /* clear FIFO and IRQ */
31 outb_p(0, port
+ UART_IER
);
32 if (inb_p(port
+ UART_IIR
) != 1)
34 outb_p(0xF5, port
+ UART_MCR
);
35 if (inb_p(port
+ UART_MCR
) != 0x15)
37 outb_p(UART_MCR_LOOP
, port
+ UART_MCR
); /* Looping */
38 inb_p(port
+ UART_MSR
);
39 if ((inb_p(port
+ UART_MSR
) & 0xF0) != 0)
41 outb_p(0x1F, port
+ UART_MCR
);
42 if ((inb_p(port
+ UART_MSR
) & 0xF0) != 0xF0)
44 outb_p(SER_MCR_DTR
| SER_MCR_RTS
, port
+ UART_MCR
);
46 outb_p(0x55, port
+ UART_SCR
); /* Scratch-Register ?*/
47 if (inb_p(port
+ UART_SCR
) != 0x55)
48 return SER_UART_INS8250
;
49 outb_p(0, port
+ UART_SCR
);
51 outb_p(0xCF, port
+ UART_FCR
); /* FIFO ? */
52 if ((inb_p(port
+ UART_IIR
) & 0xC0) != 0xC0)
53 return SER_UART_NS16450
;
54 outb_p(0, port
+ UART_FCR
);
56 outb_p(UART_LCR_DLAB
, port
+ UART_LCR
); /* Alternate-Function Register ? */
57 outb_p(0x07, port
+ UART_EFR
);
58 if (inb_p(port
+ UART_EFR
) != 0x07)
60 outb_p(0, port
+ UART_LCR
);
61 return SER_UART_NS16550A
;
63 outb_p(0, port
+ UART_LCR
); /* reset registers */
64 outb_p(0, port
+ UART_EFR
);
65 return SER_UART_NS16C552
;
68 static void __ser_FIFOLevel(short port
, BYTE level
)
71 outb_p(level
| UART_FCR_ENABLE_FIFO
, port
+ UART_FCR
);
73 outb_p(UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
, port
+ UART_FCR
);