Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / evbarm / stand / board / epcom.c
blobf37d287fc1b89dc3c285021b4c3c39e925344197
1 /* $NetBSD: epcom.c,v 1.4 2006/03/08 23:46:23 lukem Exp $ */
3 /*
4 * Copyright (c) 2004 Jesse Off
5 * All rights reserved.
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.
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.
29 /*
30 * This file provides the cons_init() function and console I/O routines
31 * for boards that use the ep93xx ARM SoC UARTs
34 #include <sys/types.h>
35 #include <arm/ep93xx/epcomreg.h>
36 #include <arm/ep93xx/ep93xxreg.h>
37 #include <lib/libsa/stand.h>
39 #include "board.h"
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)
50 #define ISSET(t,f) ((t) & (f))
52 void
53 cons_init(void)
55 unsigned long baud, pwrcnt;
57 while(!ISSET(EPCOM_READ(Flag), Flag_TXFE));
59 /* Make UART base freq 7 MHz */
60 pwrcnt = SYSCON_READ(PwrCnt);
61 pwrcnt &= ~(PwrCnt_UARTBAUD);
62 SYSCON_WRITE(PwrCnt, pwrcnt);
64 baud = EPCOMSPEED2BRD(CONSPEED);
65 EPCOM_WRITE(LinCtrlLow, baud & 0xff);
66 EPCOM_WRITE(LinCtrlMid, baud >> 8);
67 EPCOM_WRITE(LinCtrlHigh, LinCtrlHigh_FEN|LinCtrlHigh_WLEN);
70 int
71 getchar(void)
73 while(!ISSET(EPCOM_READ(Flag), Flag_RXFE));
74 return (EPCOM_READ(Data) & 0xff);
77 void
78 putchar(int c)
80 while(ISSET(EPCOM_READ(Flag), Flag_TXFF));
82 if (c == '\n') {
83 while(!ISSET(EPCOM_READ(Flag), Flag_TXFE));
84 EPCOM_WRITE(Data, '\r');
87 EPCOM_WRITE(Data, c);