xref: /netbsd-src/sys/arch/evbarm/stand/board/epcom.c (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /*	$NetBSD: epcom.c,v 1.5 2009/10/23 00:39:30 snj 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  *
16  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /*
30  * This file provides the cons_init() function and console I/O routines
31  * for boards that use the ep93xx ARM SoC UARTs
32  */
33 
34 #include <sys/types.h>
35 #include <arm/ep93xx/epcomreg.h>
36 #include <arm/ep93xx/ep93xxreg.h>
37 #include <lib/libsa/stand.h>
38 
39 #include "board.h"
40 
41 #define SCADDR	(EP93XX_APB_HWBASE + EP93XX_APB_SYSCON)
42 #define	EPCOM_READ(x)		*((volatile uint32_t *) (CONADDR + (EPCOM_ ## x)))
43 #define	EPCOM_WRITE(x, v)	*((volatile uint32_t *) \
44 					(CONADDR + (EPCOM_ ## x))) = (v)
45 #define	SYSCON_READ(x)		*((volatile uint32_t *) \
46 					(SCADDR + (EP93XX_SYSCON_ ## x)))
47 #define	SYSCON_WRITE(x, v)	*((volatile uint32_t *) \
48 					(SCADDR + (EP93XX_SYSCON_ ## x))) = (v)
49 
50 #define	ISSET(t,f)	((t) & (f))
51 
52 void
53 cons_init(void)
54 {
55 	unsigned long baud, pwrcnt;
56 
57 	while(!ISSET(EPCOM_READ(Flag), Flag_TXFE));
58 
59 	/* Make UART base freq 7 MHz */
60 	pwrcnt = SYSCON_READ(PwrCnt);
61 	pwrcnt &= ~(PwrCnt_UARTBAUD);
62 	SYSCON_WRITE(PwrCnt, pwrcnt);
63 
64 	baud = EPCOMSPEED2BRD(CONSPEED);
65 	EPCOM_WRITE(LinCtrlLow, baud & 0xff);
66 	EPCOM_WRITE(LinCtrlMid, baud >> 8);
67 	EPCOM_WRITE(LinCtrlHigh, LinCtrlHigh_FEN|LinCtrlHigh_WLEN);
68 }
69 
70 int
71 getchar(void)
72 {
73 	while(!ISSET(EPCOM_READ(Flag), Flag_RXFE));
74 	return (EPCOM_READ(Data) & 0xff);
75 }
76 
77 void
78 putchar(int c)
79 {
80 	while(ISSET(EPCOM_READ(Flag), Flag_TXFF));
81 
82 	if (c == '\n') {
83 		while(!ISSET(EPCOM_READ(Flag), Flag_TXFE));
84 		EPCOM_WRITE(Data, '\r');
85 	}
86 
87 	EPCOM_WRITE(Data, c);
88 }
89