ar_console.c revision 1.1 1 1.1 matt /* $NetBSD: ar_console.c,v 1.1 2011/07/07 05:06:44 matt Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Matt Thomas of 3am Software Foundry.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt *
19 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
30 1.1 matt */
31 1.1 matt
32 1.1 matt /*
33 1.1 matt * This file implement an Atheros dependent early console.
34 1.1 matt */
35 1.1 matt #include <sys/cdefs.h>
36 1.1 matt __KERNEL_RCSID(0, "$NetBSD: ar_console.c,v 1.1 2011/07/07 05:06:44 matt Exp $");
37 1.1 matt
38 1.1 matt #include <sys/param.h>
39 1.1 matt #include <sys/systm.h>
40 1.1 matt #include <sys/kernel.h>
41 1.1 matt #include <sys/termios.h>
42 1.1 matt
43 1.1 matt #include <dev/cons.h>
44 1.1 matt
45 1.1 matt #include <mips/cache.h>
46 1.1 matt #include <mips/locore.h>
47 1.1 matt #include <mips/cpuregs.h>
48 1.1 matt
49 1.1 matt #include <mips/atheros/include/platform.h>
50 1.1 matt #include <mips/atheros/include/arbusvar.h>
51 1.1 matt
52 1.1 matt #include <machine/locore.h>
53 1.1 matt #include "com.h"
54 1.1 matt
55 1.1 matt #include <dev/ic/ns16450reg.h>
56 1.1 matt #include <dev/ic/comreg.h>
57 1.1 matt #include <dev/ic/comvar.h>
58 1.1 matt
59 1.1 matt void
60 1.1 matt atheros_consinit(void)
61 1.1 matt {
62 1.1 matt /*
63 1.1 matt * Everything related to console initialization is done
64 1.1 matt * in mach_init().
65 1.1 matt */
66 1.1 matt #if NCOM > 0
67 1.1 matt /* Setup polled serial for early console I/O */
68 1.1 matt /* XXX: pass in CONSPEED? */
69 1.1 matt com_arbus_cnattach(platformsw->apsw_uart0_base, atheros_get_bus_freq());
70 1.1 matt #else
71 1.1 matt panic("Not configured to use serial console!\n");
72 1.1 matt /* not going to see that message now, are we? */
73 1.1 matt #endif
74 1.1 matt }
75 1.1 matt
76 1.1 matt /*
77 1.1 matt * Early console support.
78 1.1 matt */
79 1.1 matt static void
80 1.1 matt earlycons_putc(dev_t dev, int c)
81 1.1 matt {
82 1.1 matt volatile uint32_t * const uart =
83 1.1 matt (volatile uint32_t *)MIPS_PHYS_TO_KSEG1(platformsw->apsw_uart0_base);
84 1.1 matt
85 1.1 matt while (!(uart[com_lsr] & htobe32(LSR_TXRDY)))
86 1.1 matt continue;
87 1.1 matt
88 1.1 matt uart[com_data] = htobe32(c);
89 1.1 matt }
90 1.1 matt
91 1.1 matt static int
92 1.1 matt earlycons_getc(dev_t dev)
93 1.1 matt {
94 1.1 matt volatile uint32_t * const uart =
95 1.1 matt (volatile uint32_t *)MIPS_PHYS_TO_KSEG1(platformsw->apsw_uart0_base);
96 1.1 matt
97 1.1 matt while (!(uart[com_lsr] & htobe32(LSR_RXRDY)))
98 1.1 matt continue;
99 1.1 matt
100 1.1 matt return (uint8_t) be32toh(uart[com_data]);
101 1.1 matt }
102 1.1 matt
103 1.1 matt static void
104 1.1 matt earlycons_flush(dev_t dev)
105 1.1 matt {
106 1.1 matt volatile uint32_t * const uart =
107 1.1 matt (volatile uint32_t *)MIPS_PHYS_TO_KSEG1(platformsw->apsw_uart0_base);
108 1.1 matt
109 1.1 matt while (!(uart[com_lsr] & htobe32(LSR_TSRE)))
110 1.1 matt continue;
111 1.1 matt }
112 1.1 matt
113 1.1 matt
114 1.1 matt void
115 1.1 matt atheros_early_consinit(void)
116 1.1 matt {
117 1.1 matt static struct consdev earlycons_cn = {
118 1.1 matt .cn_probe = NULL,
119 1.1 matt .cn_init = NULL,
120 1.1 matt .cn_getc = earlycons_getc,
121 1.1 matt .cn_putc = earlycons_putc,
122 1.1 matt .cn_pollc = nullcnpollc,
123 1.1 matt .cn_bell = NULL,
124 1.1 matt .cn_halt = NULL,
125 1.1 matt .cn_flush = earlycons_flush,
126 1.1 matt .cn_dev = makedev(0, 0),
127 1.1 matt .cn_pri = CN_DEAD,
128 1.1 matt };
129 1.1 matt
130 1.1 matt cn_tab = &earlycons_cn;
131 1.1 matt }
132