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