- Moved hlt() to it's own header.
[coreboot.git] / src / pc80 / serial.inc
1 #include <part/fallback_boot.h>
2
3
4 /* Base Address */
5 #ifndef TTYS0_BASE
6 #define TTYS0_BASE      0x3f8
7 #endif
8
9 /* Baud Rate */
10 #ifndef TTYS0_BAUD
11 #define TTYS0_BAUD 115200
12 #endif
13
14 #if ((115200%TTYS0_BAUD) != 0)
15 #error Bad ttys0 baud rate
16 #endif
17
18 /* Baud Rate Divisor */
19 #define TTYS0_DIV       (115200/TTYS0_BAUD)
20 #define TTYS0_DIV_LO    (TTYS0_DIV&0xFF)
21 #define TTYS0_DIV_HI    ((TTYS0_DIV >> 8)&0xFF)
22
23 /* Line Control Settings */
24 #ifndef TTYS0_LCS
25 /* Set 8bit, 1 stop bit, no parity */
26 #define TTYS0_LCS       0x3
27 #endif
28
29 /* Data */
30 #define TTYS0_RBR (TTYS0_BASE+0x00)
31
32 /* Control */
33 #define TTYS0_TBR TTYS0_RBR
34 #define TTYS0_IER (TTYS0_BASE+0x01)
35 #define TTYS0_IIR (TTYS0_BASE+0x02)
36 #define TTYS0_FCR TTYS0_IIR
37 #define TTYS0_LCR (TTYS0_BASE+0x03)
38 #define TTYS0_MCR (TTYS0_BASE+0x04)
39 #define TTYS0_DLL TTYS0_RBR
40 #define TTYS0_DLM TTYS0_IER
41
42 /* Status */
43 #define TTYS0_LSR (TTYS0_BASE+0x05)
44 #define TTYS0_MSR (TTYS0_BASE+0x06)
45 #define TTYS0_SCR (TTYS0_BASE+0x07)
46
47 #if USE_OPTION_TABLE == 1
48 .section ".rom.data"
49         .type    div,@object
50         .size    div,8
51 div:
52 .byte 1,2,3,6,12,24,48,96
53
54 .previous
55 #endif
56
57         jmp     serial0
58
59         /* uses:        ax, dx */
60 #define TTYS0_TX_AL             \
61         mov     %al, %ah        ; \
62 9:      mov     $TTYS0_LSR, %dx ; \
63         inb     %dx, %al        ; \
64         test    $0x20, %al      ; \
65         je      9b              ; \
66         mov     $TTYS0_TBR, %dx ; \
67         mov     %ah, %al        ; \
68         outb    %al, %dx
69
70 serial_init:
71         /* Set 115.2Kbps,8n1 */
72         /* Set 8bit, 1 stop bit, no parity, DLAB */
73         mov     $TTYS0_LCR, %dx
74         mov     $(TTYS0_LCS | 0x80), %al
75         out     %al, %dx
76
77         /* set Baud Rate Divisor to 1 ==> 115200 Buad */
78 #if USE_OPTION_TABLE == 1
79
80         movb    $(RTC_BOOT_BYTE+1), %al
81         outb    %al, $0x70
82         xorl    %edx,%edx
83         inb     $0x71, %al
84         andb    $7,%al
85         movb    %al,%dl
86         movb    div(%edx),%al
87         mov     $TTYS0_DLL, %dx
88         out     %al, %dx
89         mov     $TTYS0_DLM, %dx
90         xorb    %al,%al
91         out     %al, %dx
92 #else
93         mov     $TTYS0_DLL, %dx
94         mov     $TTYS0_DIV_LO, %al
95         out     %al, %dx
96         mov     $TTYS0_DLM, %dx
97         mov     $TTYS0_DIV_HI, %al
98         out     %al, %dx
99 #endif
100         /* Disable DLAB */
101         mov     $TTYS0_LCR, %dx
102         mov     $(TTYS0_LCS & 0x7f), %al
103         out     %al, %dx
104         RETSP
105
106 serial0:
107         CALLSP(serial_init)