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