1 /* $NetBSD: ar5312.c,v 1.2 2006/09/04 05:17:26 gdamore Exp $ */
4 * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
5 * Copyright (c) 2006 Garrett D'Amore.
8 * Portions of this code were written by Garrett D'Amore for the
9 * Champaign-Urbana Community Wireless Network Project.
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgements:
22 * This product includes software developed by the Urbana-Champaign
23 * Independent Media Center.
24 * This product includes software developed by Garrett D'Amore.
25 * 4. Urbana-Champaign Independent Media Center's name and Garrett
26 * D'Amore's name may not be used to endorse or promote products
27 * derived from this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE URBANA-CHAMPAIGN INDEPENDENT
30 * MEDIA CENTER AND GARRETT D'AMORE ``AS IS'' AND ANY EXPRESS OR
31 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE URBANA-CHAMPAIGN INDEPENDENT
34 * MEDIA CENTER OR GARRETT D'AMORE BE LIABLE FOR ANY DIRECT, INDIRECT,
35 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 * This file includes a implementation specific console for AR5312.
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD$");
53 #include "opt_memsize.h"
54 #include <sys/param.h>
55 #include <sys/systm.h>
56 #include <sys/kernel.h>
61 #include <mips/cache.h>
62 #include <mips/locore.h>
63 #include <mips/cpuregs.h>
65 #include <mips/atheros/include/ar5312reg.h>
66 #include <mips/atheros/include/ar531xvar.h>
67 #include <mips/atheros/include/arbusvar.h>
74 * Everything related to console initialization is done
78 /* Setup polled serial for early console I/O */
79 /* XXX: pass in CONSPEED? */
80 com_arbus_cnattach(AR5312_UART0_BASE
, ar531x_bus_freq());
82 panic("Not configured to use serial console!\n");
83 /* not going to see that message now, are we? */
88 * Early console support.
90 #define STRIDE(x) ((x*4) + MIPS_PHYS_TO_KSEG1(AR5312_UART0_BASE + 3))
93 #define DLBL STRIDE(0)
94 #define DLBH STRIDE(1)
100 #define MSR STRIDE(6)
101 #define SCRATCH STRIDE(7)
102 #define INB(x) (*(volatile char *)(x))
103 #define OUTB(x, v) (*(volatile char *)(x) = (v))
105 /* line status register */
106 #define LSR_RCV_FIFO 0x80
107 #define LSR_TSRE 0x40 /* Transmitter empty: byte sent */
108 #define LSR_TXRDY 0x20 /* Transmitter buffer empty */
109 #define LSR_BI 0x10 /* Break detected */
110 #define LSR_FE 0x08 /* Framing error: bad stop bit */
111 #define LSR_PE 0x04 /* Parity error */
112 #define LSR_OE 0x02 /* Overrun, lost incoming byte */
113 #define LSR_RXRDY 0x01 /* Byte ready in Receive Buffer */
114 #define LSR_RCV_MASK 0x1f /* Mask for incoming data or error */
117 ar5312_putc(dev_t dev
, int c
)
119 unsigned char lsr
= 0;
121 while (!(lsr
& LSR_TXRDY
)) {
128 ar5312_getc(dev_t dev
)
130 unsigned char lsr
= 0, dat
;
132 while (!(lsr
& LSR_RXRDY
)) {
140 ar5312_flush(dev_t dev
)
142 unsigned char lsr
= 0;
143 while (!(lsr
& LSR_TSRE
)) {
150 ar531x_early_console(void)
152 static struct consdev promcn
= {
155 .cn_getc
= ar5312_getc
,
156 .cn_putc
= ar5312_putc
,
157 .cn_pollc
= nullcnpollc
,
160 .cn_flush
= ar5312_flush
,
161 .cn_dev
= makedev(0, 0),