xref: /netbsd-src/sys/arch/evbarm/stand/board/epcom.c (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: epcom.c,v 1.3 2005/12/24 20:07:03 perry Exp $	*/
2 
3 /*
4  * Copyright (c) 2004 Jesse Off
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed for the NetBSD Project by
18  *	Wasabi Systems, Inc.
19  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
20  *    or promote products derived from this software without specific prior
21  *    written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 /*
37  * This file provides the cons_init() function and console I/O routines
38  * for boards that use the ep93xx ARM SoC UARTs
39  */
40 
41 #include <sys/types.h>
42 #include <arm/ep93xx/epcomreg.h>
43 #include <arm/ep93xx/ep93xxreg.h>
44 #include <lib/libsa/stand.h>
45 
46 #include "board.h"
47 
48 #define SCADDR	(EP93XX_APB_HWBASE + EP93XX_APB_SYSCON)
49 #define	EPCOM_READ(x)		*((volatile uint32_t *) (CONADDR + (EPCOM_ ## x)))
50 #define	EPCOM_WRITE(x, v)	*((volatile uint32_t *) \
51 					(CONADDR + (EPCOM_ ## x))) = (v)
52 #define	SYSCON_READ(x)		*((volatile uint32_t *) \
53 					(SCADDR + (EP93XX_SYSCON_ ## x)))
54 #define	SYSCON_WRITE(x, v)	*((volatile uint32_t *) \
55 					(SCADDR + (EP93XX_SYSCON_ ## x))) = (v)
56 
57 #define	ISSET(t,f)	((t) & (f))
58 
59 void
60 cons_init(void)
61 {
62 	unsigned long baud, pwrcnt;
63 
64 	while(!ISSET(EPCOM_READ(Flag), Flag_TXFE));
65 
66 	/* Make UART base freq 7Mhz */
67 	pwrcnt = SYSCON_READ(PwrCnt);
68 	pwrcnt &= ~(PwrCnt_UARTBAUD);
69 	SYSCON_WRITE(PwrCnt, pwrcnt);
70 
71 	baud = EPCOMSPEED2BRD(CONSPEED);
72 	EPCOM_WRITE(LinCtrlLow, baud & 0xff);
73 	EPCOM_WRITE(LinCtrlMid, baud >> 8);
74 	EPCOM_WRITE(LinCtrlHigh, LinCtrlHigh_FEN|LinCtrlHigh_WLEN);
75 }
76 
77 int
78 getchar(void)
79 {
80 	while(!ISSET(EPCOM_READ(Flag), Flag_RXFE));
81 	return (EPCOM_READ(Data) & 0xff);
82 }
83 
84 void
85 putchar(int c)
86 {
87 	while(ISSET(EPCOM_READ(Flag), Flag_TXFF));
88 
89 	if (c == '\n') {
90 		while(!ISSET(EPCOM_READ(Flag), Flag_TXFE));
91 		EPCOM_WRITE(Data, '\r');
92 	}
93 
94 	EPCOM_WRITE(Data, c);
95 }
96