]>
git.saurik.com Git - apple/xnu.git/blob - pexpert/i386/pe_serial.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 * Polled-mode 16x50 UART driver.
28 #include <pexpert/protos.h>
29 #include <pexpert/pexpert.h>
31 void serial_putc(char);
32 int serial_getc(void);
33 int serial_init(void);
35 /* standard port addresses */
37 COM1_PORT_ADDR
= 0x3f8,
38 COM2_PORT_ADDR
= 0x2f8
41 /* UART register offsets */
43 UART_RBR
= 0, /* receive buffer Register (R) */
44 UART_THR
= 0, /* transmit holding register (W) */
45 UART_DLL
= 0, /* DLAB = 1, divisor latch (LSB) */
46 UART_IER
= 1, /* interrupt enable register */
47 UART_DLM
= 1, /* DLAB = 1, divisor latch (MSB) */
48 UART_IIR
= 2, /* interrupt ident register (R) */
49 UART_FCR
= 2, /* fifo control register (W) */
50 UART_LCR
= 3, /* line control register */
51 UART_MCR
= 4, /* modem control register */
52 UART_LSR
= 5, /* line status register */
53 UART_MSR
= 6 /* modem status register */
57 UART_LCR_8BITS
= 0x03,
73 #define UART_BAUD_RATE 115200
74 #define UART_PORT_ADDR COM1_PORT_ADDR
76 #define WRITE(r, v) outb(UART_PORT_ADDR + UART_##r, v)
77 #define READ(r) inb(UART_PORT_ADDR + UART_##r)
78 #define DELAY(x) { volatile int _d_; for (_d_ = 0; _d_ < (10000*x); _d_++) ; }
80 static int uart_initted
= 0; /* 1 if init'ed */
85 /* Verify that the Divisor Register is accessible */
87 WRITE( LCR
, UART_LCR_DLAB
);
89 if (READ(DLL
) != 0x5a) return 0;
91 if (READ(DLL
) != 0xa5) return 0;
97 uart_set_baud_rate( unsigned long baud_rate
)
99 #define UART_CLOCK 1843200 /* 1.8432 MHz clock */
101 const unsigned char lcr
= READ( LCR
);
104 if (baud_rate
== 0) baud_rate
= 9600;
105 div
= UART_CLOCK
/ 16 / baud_rate
;
106 WRITE( LCR
, lcr
| UART_LCR_DLAB
);
107 WRITE( DLM
, (unsigned char)(div
>> 8) );
108 WRITE( DLL
, (unsigned char) div
);
109 WRITE( LCR
, lcr
& ~UART_LCR_DLAB
);
115 if (!uart_initted
) return;
117 /* Wait for THR empty */
118 while ( !(READ(LSR
) & UART_LSR_THRE
) ) DELAY(1);
123 int serial_init( void )
125 if ( /*uart_initted ||*/ uart_probe() == 0 ) return 0;
127 /* Disable hardware interrupts */
132 /* Disable FIFO's for 16550 devices */
136 /* Set for 8-bit, no parity, DLAB bit cleared */
138 WRITE( LCR
, UART_LCR_8BITS
);
142 uart_set_baud_rate( UART_BAUD_RATE
);
144 /* Assert DTR# and RTS# lines (OUT2?) */
146 WRITE( MCR
, UART_MCR_DTR
| UART_MCR_RTS
);
148 /* Clear any garbage in the input buffer */
157 void serial_putc( char c
)
160 if (c
== '\n') uart_putc('\r');
163 int serial_getc( void )
165 return 0; /* not supported */