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