1*ce099b40Smartin /* $NetBSD: com.c,v 1.4 2008/04/28 20:23:21 martin Exp $ */
2f8bc0014Sigy
3f8bc0014Sigy /*-
4f8bc0014Sigy * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
5f8bc0014Sigy * All rights reserved.
6f8bc0014Sigy *
7f8bc0014Sigy * This code is derived from software contributed to The NetBSD Foundation
8f8bc0014Sigy * by Charles M. Hannum.
9f8bc0014Sigy *
10f8bc0014Sigy * Redistribution and use in source and binary forms, with or without
11f8bc0014Sigy * modification, are permitted provided that the following conditions
12f8bc0014Sigy * are met:
13f8bc0014Sigy * 1. Redistributions of source code must retain the above copyright
14f8bc0014Sigy * notice, this list of conditions and the following disclaimer.
15f8bc0014Sigy * 2. Redistributions in binary form must reproduce the above copyright
16f8bc0014Sigy * notice, this list of conditions and the following disclaimer in the
17f8bc0014Sigy * documentation and/or other materials provided with the distribution.
18f8bc0014Sigy *
19f8bc0014Sigy * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20f8bc0014Sigy * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21f8bc0014Sigy * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22f8bc0014Sigy * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23f8bc0014Sigy * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24f8bc0014Sigy * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25f8bc0014Sigy * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26f8bc0014Sigy * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27f8bc0014Sigy * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28f8bc0014Sigy * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29f8bc0014Sigy * POSSIBILITY OF SUCH DAMAGE.
30f8bc0014Sigy */
31f8bc0014Sigy
32f8bc0014Sigy /*
33f8bc0014Sigy * Copyright (c) 1991 The Regents of the University of California.
34f8bc0014Sigy * All rights reserved.
35f8bc0014Sigy *
36f8bc0014Sigy * Redistribution and use in source and binary forms, with or without
37f8bc0014Sigy * modification, are permitted provided that the following conditions
38f8bc0014Sigy * are met:
39f8bc0014Sigy * 1. Redistributions of source code must retain the above copyright
40f8bc0014Sigy * notice, this list of conditions and the following disclaimer.
41f8bc0014Sigy * 2. Redistributions in binary form must reproduce the above copyright
42f8bc0014Sigy * notice, this list of conditions and the following disclaimer in the
43f8bc0014Sigy * documentation and/or other materials provided with the distribution.
44aad01611Sagc * 3. Neither the name of the University nor the names of its contributors
45f8bc0014Sigy * may be used to endorse or promote products derived from this software
46f8bc0014Sigy * without specific prior written permission.
47f8bc0014Sigy *
48f8bc0014Sigy * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49f8bc0014Sigy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50f8bc0014Sigy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51f8bc0014Sigy * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52f8bc0014Sigy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53f8bc0014Sigy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54f8bc0014Sigy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55f8bc0014Sigy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56f8bc0014Sigy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57f8bc0014Sigy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58f8bc0014Sigy * SUCH DAMAGE.
59f8bc0014Sigy *
60f8bc0014Sigy * @(#)com.c 7.5 (Berkeley) 5/16/91
61f8bc0014Sigy */
62f8bc0014Sigy
63f8bc0014Sigy #include <sys/param.h>
64f8bc0014Sigy
65f8bc0014Sigy #include <lib/libsa/stand.h>
66f8bc0014Sigy
67f8bc0014Sigy #include <hpcmips/vr/vripreg.h>
68f8bc0014Sigy #include <hpcmips/vr/cmureg.h>
69f8bc0014Sigy
70f8bc0014Sigy #include <dev/ic/comreg.h>
71f8bc0014Sigy #include <dev/ic/ns16550reg.h>
72f8bc0014Sigy #include <dev/ic/st16650reg.h>
73f8bc0014Sigy #define com_lcr com_cfcr
74f8bc0014Sigy
75f8bc0014Sigy #include "extern.h"
76f8bc0014Sigy
77f8bc0014Sigy #if 0
78f8bc0014Sigy #define VRCOM_FREQ 18432000 /* 18.432kHz */
79f8bc0014Sigy #endif
80f8bc0014Sigy
81f8bc0014Sigy int
iskey(void)82f8bc0014Sigy iskey(void)
83f8bc0014Sigy {
84f8bc0014Sigy return ISSET(REGREAD_1(VR4181_SIU_ADDR, com_lsr), LSR_RXRDY);
85f8bc0014Sigy }
86f8bc0014Sigy
87f8bc0014Sigy int
getchar(void)88f8bc0014Sigy getchar(void)
89f8bc0014Sigy {
90f8bc0014Sigy u_int8_t stat;
91f8bc0014Sigy u_int8_t c;
92f8bc0014Sigy
93f8bc0014Sigy /* block until a character becomes available */
94f8bc0014Sigy while (!ISKEY)
95f8bc0014Sigy ;
96f8bc0014Sigy
97f8bc0014Sigy c = REGREAD_1(VR4181_SIU_ADDR, com_data);
98f8bc0014Sigy stat = REGREAD_1(VR4181_SIU_ADDR, com_iir);
99f8bc0014Sigy
100f8bc0014Sigy return c;
101f8bc0014Sigy }
102f8bc0014Sigy
103f8bc0014Sigy static void
comcnputc(int c)104f8bc0014Sigy comcnputc(int c)
105f8bc0014Sigy {
106f8bc0014Sigy int timo;
107f8bc0014Sigy
108f8bc0014Sigy /* wait for any pending transmission to finish */
109f8bc0014Sigy timo = 150000;
110f8bc0014Sigy while (!ISSET(REGREAD_1(VR4181_SIU_ADDR, com_lsr), LSR_TXRDY)
111f8bc0014Sigy && --timo)
112f8bc0014Sigy continue;
113f8bc0014Sigy
114f8bc0014Sigy REGWRITE_1(VR4181_SIU_ADDR, com_data, c);
115f8bc0014Sigy
116f8bc0014Sigy /* wait for this transmission to complete */
117f8bc0014Sigy timo = 1500000;
118f8bc0014Sigy while (!ISSET(REGREAD_1(VR4181_SIU_ADDR, com_lsr), LSR_TXRDY)
119f8bc0014Sigy && --timo)
120f8bc0014Sigy continue;
121f8bc0014Sigy }
122f8bc0014Sigy
123f8bc0014Sigy void
putchar(int c)124f8bc0014Sigy putchar(int c)
125f8bc0014Sigy {
126f8bc0014Sigy if (c == '\n')
127f8bc0014Sigy comcnputc('\r');
128f8bc0014Sigy comcnputc(c);
129f8bc0014Sigy }
130f8bc0014Sigy
131f8bc0014Sigy /*
132f8bc0014Sigy * Initialize UART for use as console or KGDB line.
133f8bc0014Sigy */
134f8bc0014Sigy void
comcninit(void)135f8bc0014Sigy comcninit(void)
136f8bc0014Sigy {
137f8bc0014Sigy int rate;
138f8bc0014Sigy
139f8bc0014Sigy /* enable divisor latch access and set bit rate */
140f8bc0014Sigy REGWRITE_1(VR4181_SIU_ADDR, com_lcr, LCR_DLAB);
141f8bc0014Sigy rate = 10; /* 115200bps with VRCOM_FREQ */
142f8bc0014Sigy REGWRITE_1(VR4181_SIU_ADDR, com_dlbl, rate);
143f8bc0014Sigy REGWRITE_1(VR4181_SIU_ADDR, com_dlbh, rate >> 8);
144f8bc0014Sigy
145f8bc0014Sigy /*
146f8bc0014Sigy * disable divisor latch access and,
147f8bc0014Sigy * set "8bit non-parity 1 stop bit"
148f8bc0014Sigy */
149f8bc0014Sigy REGWRITE_1(VR4181_SIU_ADDR, com_lcr, LCR_8BITS);
150f8bc0014Sigy
151f8bc0014Sigy /* disable all interrupt */
152f8bc0014Sigy REGWRITE_1(VR4181_SIU_ADDR, com_ier, 0);
153f8bc0014Sigy
154f8bc0014Sigy /* enable FIFO */
155f8bc0014Sigy REGWRITE_1(VR4181_SIU_ADDR, com_fifo,
156f8bc0014Sigy FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
157f8bc0014Sigy
158f8bc0014Sigy /* set DTR and RTS low */
159f8bc0014Sigy REGWRITE_1(VR4181_SIU_ADDR, com_mcr, MCR_DTR | MCR_RTS);
160f8bc0014Sigy }
161