3 #define DEFAULT_SERIAL_PORT 0x3f8 /* ttyS0 */
9 #define TXR 0 /* Transmit register (WRITE) */
10 #define RXR 0 /* Receive register (READ) */
11 #define IER 1 /* Interrupt Enable */
12 #define IIR 2 /* Interrupt ID */
13 #define FCR 2 /* FIFO control */
14 #define LCR 3 /* Line control */
15 #define MCR 4 /* Modem control */
16 #define LSR 5 /* Line Status */
17 #define MSR 6 /* Modem Status */
18 #define DLL 0 /* Divisor Latch Low */
19 #define DLH 1 /* Divisor latch High */
21 #define DEFAULT_BAUD 9600
23 static void early_serial_init(int port
, int baud
)
28 outb(0x3, port
+ LCR
); /* 8n1 */
29 outb(0, port
+ IER
); /* no interrupt */
30 outb(0, port
+ FCR
); /* no fifo */
31 outb(0x3, port
+ MCR
); /* DTR + RTS */
33 divisor
= 115200 / baud
;
35 outb(c
| DLAB
, port
+ LCR
);
36 outb(divisor
& 0xff, port
+ DLL
);
37 outb((divisor
>> 8) & 0xff, port
+ DLH
);
38 outb(c
& ~DLAB
, port
+ LCR
);
40 early_serial_base
= port
;
43 static void parse_earlyprintk(void)
45 int baud
= DEFAULT_BAUD
;
50 if (cmdline_find_option("earlyprintk", arg
, sizeof arg
) > 0) {
53 if (!strncmp(arg
, "serial", 6)) {
54 port
= DEFAULT_SERIAL_PORT
;
63 * "serial,0x3f8,115200"
64 * "serial,ttyS0,115200"
67 if (pos
== 7 && !strncmp(arg
+ pos
, "0x", 2)) {
68 port
= simple_strtoull(arg
+ pos
, &e
, 16);
69 if (port
== 0 || arg
+ pos
== e
)
70 port
= DEFAULT_SERIAL_PORT
;
73 } else if (!strncmp(arg
+ pos
, "ttyS", 4)) {
74 static const int bases
[] = { 0x3f8, 0x2f8 };
77 if (!strncmp(arg
+ pos
, "ttyS", 4))
80 if (arg
[pos
++] == '1')
89 baud
= simple_strtoull(arg
+ pos
, &e
, 0);
90 if (baud
== 0 || arg
+ pos
== e
)
95 early_serial_init(port
, baud
);
98 #define BASE_BAUD (1843200/16)
99 static unsigned int probe_baud(int port
)
101 unsigned char lcr
, dll
, dlh
;
104 lcr
= inb(port
+ LCR
);
105 outb(lcr
| DLAB
, port
+ LCR
);
106 dll
= inb(port
+ DLL
);
107 dlh
= inb(port
+ DLH
);
108 outb(lcr
, port
+ LCR
);
109 quot
= (dlh
<< 8) | dll
;
111 return BASE_BAUD
/ quot
;
114 static void parse_console_uart8250(void)
116 char optstr
[64], *options
;
117 int baud
= DEFAULT_BAUD
;
121 * console=uart8250,io,0x3f8,115200n8
122 * need to make sure it is last one console !
124 if (cmdline_find_option("console", optstr
, sizeof optstr
) <= 0)
129 if (!strncmp(options
, "uart8250,io,", 12))
130 port
= simple_strtoull(options
+ 12, &options
, 0);
131 else if (!strncmp(options
, "uart,io,", 8))
132 port
= simple_strtoull(options
+ 8, &options
, 0);
136 if (options
&& (options
[0] == ','))
137 baud
= simple_strtoull(options
+ 1, &options
, 0);
139 baud
= probe_baud(port
);
142 early_serial_init(port
, baud
);
145 void console_init(void)
149 if (!early_serial_base
)
150 parse_console_uart8250();