xref: /netbsd-src/sys/arch/hpc/stand/hpcboot/arm/arm_pxa2x0_console.h (revision 3af75740f5a44cd2edb17ea23c968757b456a801)
1*3af75740Srafal /* -*-C++-*-	$NetBSD: arm_pxa2x0_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_PXA2X0_CONSOLE_H_
33*3af75740Srafal #define _HPCBOOT_ARM_PXA2X0_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 PXA2x0Console : 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:
PXA2x0Console(MemoryManager * & mem)47*3af75740Srafal 	PXA2x0Console(MemoryManager *& mem) : _mem(mem), _uart_base(~0) { }
~PXA2x0Console()48*3af75740Srafal 	virtual ~PXA2x0Console() {
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 + 0x14);
57*3af75740Srafal 		while (!(reg & 0x20));
58*3af75740Srafal 	}
59*3af75740Srafal 
__clr_intr(void)60*3af75740Srafal 	void __clr_intr(void) {
61*3af75740Srafal 		uint8_t reg = VOLATILE_REF8(_uart_base + 0x08);
62*3af75740Srafal 	}
63*3af75740Srafal 
__putc(const char s)64*3af75740Srafal 	virtual void __putc(const char s) {
65*3af75740Srafal 		__tx_busy(); // wait until previous transmit done.
66*3af75740Srafal 		VOLATILE_REF8(_uart_base + 0x00) =
67*3af75740Srafal 		    static_cast <uint8_t>(0xff & s);
68*3af75740Srafal 		__tx_busy();  // wait until this transmit done.
69*3af75740Srafal 		__clr_intr(); // clear interrupt register
70*3af75740Srafal 	}
71*3af75740Srafal 
72*3af75740Srafal public:
init(void)73*3af75740Srafal 	virtual BOOL init(void) {
74*3af75740Srafal 		if (!SerialConsole::init())
75*3af75740Srafal 			return FALSE;
76*3af75740Srafal 
77*3af75740Srafal 		_uart_base =
78*3af75740Srafal 		    _mem->mapPhysicalPage(0x40100000, 0x100, PAGE_READWRITE);
79*3af75740Srafal 
80*3af75740Srafal 		if (_uart_base == ~0)
81*3af75740Srafal 			return FALSE;
82*3af75740Srafal 
83*3af75740Srafal 		return TRUE;
84*3af75740Srafal 	}
85*3af75740Srafal };
86*3af75740Srafal #endif //_HPCBOOT_ARM_PXA2X0_CONSOLE_H_
87