1 1.2 matt /* $NetBSD: ar_console.c,v 1.2 2011/07/10 06:26:02 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.2 matt __KERNEL_RCSID(0, "$NetBSD: ar_console.c,v 1.2 2011/07/10 06:26:02 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.2 matt #include <mips/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.2 matt com_arbus_cnattach(platformsw->apsw_uart0_base, 70 1.2 matt atheros_get_uart_freq()); 71 1.1 matt #else 72 1.1 matt panic("Not configured to use serial console!\n"); 73 1.1 matt /* not going to see that message now, are we? */ 74 1.1 matt #endif 75 1.1 matt } 76 1.1 matt 77 1.1 matt /* 78 1.1 matt * Early console support. 79 1.1 matt */ 80 1.1 matt static void 81 1.1 matt earlycons_putc(dev_t dev, int c) 82 1.1 matt { 83 1.1 matt volatile uint32_t * const uart = 84 1.1 matt (volatile uint32_t *)MIPS_PHYS_TO_KSEG1(platformsw->apsw_uart0_base); 85 1.1 matt 86 1.1 matt while (!(uart[com_lsr] & htobe32(LSR_TXRDY))) 87 1.1 matt continue; 88 1.1 matt 89 1.1 matt uart[com_data] = htobe32(c); 90 1.1 matt } 91 1.1 matt 92 1.1 matt static int 93 1.1 matt earlycons_getc(dev_t dev) 94 1.1 matt { 95 1.1 matt volatile uint32_t * const uart = 96 1.1 matt (volatile uint32_t *)MIPS_PHYS_TO_KSEG1(platformsw->apsw_uart0_base); 97 1.1 matt 98 1.1 matt while (!(uart[com_lsr] & htobe32(LSR_RXRDY))) 99 1.1 matt continue; 100 1.1 matt 101 1.1 matt return (uint8_t) be32toh(uart[com_data]); 102 1.1 matt } 103 1.1 matt 104 1.1 matt static void 105 1.1 matt earlycons_flush(dev_t dev) 106 1.1 matt { 107 1.1 matt volatile uint32_t * const uart = 108 1.1 matt (volatile uint32_t *)MIPS_PHYS_TO_KSEG1(platformsw->apsw_uart0_base); 109 1.1 matt 110 1.1 matt while (!(uart[com_lsr] & htobe32(LSR_TSRE))) 111 1.1 matt continue; 112 1.1 matt } 113 1.1 matt 114 1.1 matt 115 1.1 matt void 116 1.1 matt atheros_early_consinit(void) 117 1.1 matt { 118 1.1 matt static struct consdev earlycons_cn = { 119 1.1 matt .cn_probe = NULL, 120 1.1 matt .cn_init = NULL, 121 1.1 matt .cn_getc = earlycons_getc, 122 1.1 matt .cn_putc = earlycons_putc, 123 1.1 matt .cn_pollc = nullcnpollc, 124 1.1 matt .cn_bell = NULL, 125 1.1 matt .cn_halt = NULL, 126 1.1 matt .cn_flush = earlycons_flush, 127 1.1 matt .cn_dev = makedev(0, 0), 128 1.1 matt .cn_pri = CN_DEAD, 129 1.1 matt }; 130 1.1 matt 131 1.1 matt cn_tab = &earlycons_cn; 132 1.1 matt } 133