Indentation fix, cleanup.
[AROS.git] / arch / all-native / bootconsole / serial_16450.c
blobb45f9ee18bc43f17cce06cbdfd31f7522e9eef1e
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: 16450 serial UART serial console.
6 */
8 #include <asm/io.h>
9 #include <hardware/uart.h>
11 #include <bootconsole.h>
12 #include <stdlib.h>
14 #include "console.h"
16 #define SER_MAXBAUD 115200
18 /* These settings can be kept across warm reboots in kickstart */
19 unsigned short Serial_Base = 0x03F8;
20 static unsigned int baudRate = 115200;
22 #ifdef __ppc__
23 #define outb_p outb
24 #define inb_p inb
26 void *IO_Base;
27 #endif
29 /* Standard base addresses for four PC AT serial ports */
30 static unsigned short standard_ports[] =
32 0x03F8,
33 0x02F8,
34 0x03E8,
35 0x02E8
38 void serial_Init(char *opts)
40 port_t base;
41 unsigned short uDivisor;
42 unsigned char tmp;
44 if (opts)
46 /* Command line option format: debug=serial[:N][@baud] */
47 if (opts[0] == ':')
49 unsigned short port = strtoul(++opts, &opts, 0);
51 /* N can be either port number (0 - 4) or direct base address specification */
52 if (port < 4)
53 Serial_Base = standard_ports[port];
54 else
55 Serial_Base = port;
58 /* Set baud rate */
59 if (opts[0] == '@')
61 unsigned int baud = strtoul(++opts, NULL, 10);
63 if (baud <= SER_MAXBAUD)
64 baudRate = baud;
68 #ifdef __ppc__
69 base = IO_Base + Serial_Base;
70 #else
71 base = Serial_Base;
72 #endif
74 uDivisor = SER_MAXBAUD / baudRate;
75 tmp = inb_p(base + UART_LCR);
76 outb_p(tmp | UART_LCR_DLAB, base + UART_LCR);
77 outb_p(uDivisor & 0xFF, base + UART_DLL);
78 outb_p(uDivisor >> 8, base + UART_DLM);
79 outb_p(tmp, base + UART_LCR);
81 outb_p(UART_LCR_WLEN8, base + UART_LCR);
82 inb_p(base + UART_RX);
85 static void serial_RawPutc(char data)
87 port_t base;
89 #ifdef __ppc__
90 base = IO_Base + Serial_Base;
91 #else
92 base = Serial_Base;
93 #endif
95 /* Wait until the transmitter is empty */
96 while (!(inb_p(base + UART_LSR) & UART_LSR_TEMT));
98 /* Send out the byte */
99 outb_p(data, base + UART_TX);
102 void serial_Putc(char chr)
104 switch (chr)
106 /* Ignore null bytes, they are output by formatting routines as terminators */
107 case 0:
108 return;
110 /* Prepend CR to LF */
111 case '\n':
112 serial_RawPutc('\r');
115 serial_RawPutc(chr);