xref: /netbsd-src/sys/arch/hpc/stand/hpcboot/arm/arm_sa1100_console.h (revision 3af75740f5a44cd2edb17ea23c968757b456a801)
1*3af75740Srafal /* -*-C++-*-	$NetBSD: arm_sa1100_console.h,v 1.1 2008/03/08 02:26:03 rafal Exp $	*/
2*3af75740Srafal 
3*3af75740Srafal /*-
4*3af75740Srafal  * Copyright (c) 2008 The NetBSD Foundation, Inc.
5*3af75740Srafal  * All rights reserved.
6*3af75740Srafal  *
7*3af75740Srafal  * This code is derived from software contributed to The NetBSD Foundation
8*3af75740Srafal  * by Rafal K. Boni.
9*3af75740Srafal  *
10*3af75740Srafal  * Redistribution and use in source and binary forms, with or without
11*3af75740Srafal  * modification, are permitted provided that the following conditions
12*3af75740Srafal  * are met:
13*3af75740Srafal  * 1. Redistributions of source code must retain the above copyright
14*3af75740Srafal  *    notice, this list of conditions and the following disclaimer.
15*3af75740Srafal  * 2. Redistributions in binary form must reproduce the above copyright
16*3af75740Srafal  *    notice, this list of conditions and the following disclaimer in the
17*3af75740Srafal  *    documentation and/or other materials provided with the distribution.
18*3af75740Srafal  *
19*3af75740Srafal  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*3af75740Srafal  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*3af75740Srafal  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*3af75740Srafal  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*3af75740Srafal  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*3af75740Srafal  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*3af75740Srafal  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*3af75740Srafal  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*3af75740Srafal  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*3af75740Srafal  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*3af75740Srafal  * POSSIBILITY OF SUCH DAMAGE.
30*3af75740Srafal  */
31*3af75740Srafal 
32*3af75740Srafal #ifndef _HPCBOOT_ARM_SA1100_CONSOLE_H_
33*3af75740Srafal #define	_HPCBOOT_ARM_SA1100_CONSOLE_H_
34*3af75740Srafal 
35*3af75740Srafal #include <hpcboot.h>
36*3af75740Srafal #include <memory.h>
37*3af75740Srafal #include <arm/arm_console.h>
38*3af75740Srafal 
39*3af75740Srafal class SA1100Console : public ARMConsole {
40*3af75740Srafal 	friend class ARMConsole;
41*3af75740Srafal 
42*3af75740Srafal private:
43*3af75740Srafal 	MemoryManager *&_mem;
44*3af75740Srafal 	vaddr_t _uart_base;
45*3af75740Srafal 
46*3af75740Srafal private:
SA1100Console(MemoryManager * & mem)47*3af75740Srafal 	SA1100Console(MemoryManager *& mem) : _mem(mem), _uart_base(~0) { }
~SA1100Console()48*3af75740Srafal 	virtual ~SA1100Console() {
49*3af75740Srafal 		if (_uart_base != ~0)
50*3af75740Srafal 			_mem->unmapPhysicalPage(_uart_base);
51*3af75740Srafal 	}
52*3af75740Srafal 
__tx_busy(void)53*3af75740Srafal 	void __tx_busy(void) {
54*3af75740Srafal 		uint8_t reg;
55*3af75740Srafal 		do
56*3af75740Srafal 			reg = VOLATILE_REF8(_uart_base + 0x20);
57*3af75740Srafal 		while ((reg & 0x1) == 0x1 ||(reg & 0x4) == 0);
58*3af75740Srafal 	}
59*3af75740Srafal 
__putc(const char s)60*3af75740Srafal 	virtual void __putc(const char s) {
61*3af75740Srafal 		__tx_busy(); // wait until previous transmit done.
62*3af75740Srafal 		VOLATILE_REF8(_uart_base + 0x14) =
63*3af75740Srafal 		    static_cast <uint8_t>(0xff & s);
64*3af75740Srafal 	}
65*3af75740Srafal 
66*3af75740Srafal public:
init(void)67*3af75740Srafal 	virtual BOOL init(void) {
68*3af75740Srafal 		if (!SerialConsole::init())
69*3af75740Srafal 			return FALSE;
70*3af75740Srafal 
71*3af75740Srafal 		_uart_base =
72*3af75740Srafal 		    _mem->mapPhysicalPage(0x80050000, 0x100, PAGE_READWRITE);
73*3af75740Srafal 
74*3af75740Srafal 		if (_uart_base == ~0)
75*3af75740Srafal 			return FALSE;
76*3af75740Srafal 
77*3af75740Srafal 		return TRUE;
78*3af75740Srafal 	}
79*3af75740Srafal };
80*3af75740Srafal #endif //_HPCBOOT_ARM_SA1100_CONSOLE_H_
81