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