Wed Dec 31 09:50:21 2008 UTC ()
struct device * -> device_t.


(isaki)
diff -r1.16 -r1.17 src/sys/arch/x68k/dev/xel.c
diff -r1.39 -r1.40 src/sys/arch/x68k/dev/zs.c

cvs diff -r1.16 -r1.17 src/sys/arch/x68k/dev/xel.c (switch to unified diff)

--- src/sys/arch/x68k/dev/xel.c 2008/12/18 05:56:42 1.16
+++ src/sys/arch/x68k/dev/xel.c 2008/12/31 09:50:21 1.17
@@ -1,207 +1,207 @@ @@ -1,207 +1,207 @@
1/* $NetBSD: xel.c,v 1.16 2008/12/18 05:56:42 isaki Exp $ */ 1/* $NetBSD: xel.c,v 1.17 2008/12/31 09:50:21 isaki Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Minoura Makoto. 8 * by Minoura Makoto.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * TSR Xellent30 driver. 33 * TSR Xellent30 driver.
34 * Detect Xellent30, and reserve its I/O area. 34 * Detect Xellent30, and reserve its I/O area.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: xel.c,v 1.16 2008/12/18 05:56:42 isaki Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: xel.c,v 1.17 2008/12/31 09:50:21 isaki Exp $");
39 39
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/kernel.h> 42#include <sys/kernel.h>
43#include <sys/device.h> 43#include <sys/device.h>
44 44
45#include <machine/cpu.h> 45#include <machine/cpu.h>
46#include <machine/bus.h> 46#include <machine/bus.h>
47 47
48#include <arch/x68k/dev/intiovar.h> 48#include <arch/x68k/dev/intiovar.h>
49 49
50static paddr_t xel_addr(device_t, cfdata_t, struct intio_attach_args *); 50static paddr_t xel_addr(device_t, cfdata_t, struct intio_attach_args *);
51static int xel_probe(paddr_t); 51static int xel_probe(paddr_t);
52static int xel_match(device_t, cfdata_t, void *); 52static int xel_match(device_t, cfdata_t, void *);
53static void xel_attach(device_t, device_t, void *); 53static void xel_attach(device_t, device_t, void *);
54 54
55struct xel_softc { 55struct xel_softc {
56 bus_space_tag_t sc_bst; 56 bus_space_tag_t sc_bst;
57 bus_space_handle_t sc_bh; 57 bus_space_handle_t sc_bh;
58}; 58};
59 59
60CFATTACH_DECL_NEW(xel, sizeof(struct xel_softc), 60CFATTACH_DECL_NEW(xel, sizeof(struct xel_softc),
61 xel_match, xel_attach, NULL, NULL); 61 xel_match, xel_attach, NULL, NULL);
62 62
63static paddr_t xel_addrs[] = { 0xec0000, 0xec4000, 0xec8000, 0xecc000 }; 63static paddr_t xel_addrs[] = { 0xec0000, 0xec4000, 0xec8000, 0xecc000 };
64 64
65#define XEL_MODE_RAM_LOWER 0x00 65#define XEL_MODE_RAM_LOWER 0x00
66#define XEL_MODE_RAM_HIGHER 0x01 66#define XEL_MODE_RAM_HIGHER 0x01
67#define XEL_MODE_UNMAP_RAM 0x00 67#define XEL_MODE_UNMAP_RAM 0x00
68#define XEL_MODE_MAP_RAM 0x02 68#define XEL_MODE_MAP_RAM 0x02
69#define XEL_MODE_MPU_000 0x00 69#define XEL_MODE_MPU_000 0x00
70#define XEL_MODE_MPU_030 0x04 70#define XEL_MODE_MPU_030 0x04
71 71
72#define XEL_RAM_ADDR_LOWER 0xbc0000 72#define XEL_RAM_ADDR_LOWER 0xbc0000
73#define XEL_RAM_ADDR_HIGHER 0xfc0000 73#define XEL_RAM_ADDR_HIGHER 0xfc0000
74 74
75 75
76static paddr_t 76static paddr_t
77xel_addr(device_t parent, cfdata_t match, struct intio_attach_args *ia) 77xel_addr(device_t parent, cfdata_t match, struct intio_attach_args *ia)
78{ 78{
79 paddr_t addr = 0; 79 paddr_t addr = 0;
80 80
81 if (match->cf_addr == INTIOCF_ADDR_DEFAULT) { 81 if (match->cf_addr == INTIOCF_ADDR_DEFAULT) {
82 int i; 82 int i;
83 83
84 for (i = 0; i < sizeof(xel_addrs)/sizeof(xel_addrs[0]); i++) { 84 for (i = 0; i < sizeof(xel_addrs)/sizeof(xel_addrs[0]); i++) {
85 if (xel_probe(xel_addrs[i])) { 85 if (xel_probe(xel_addrs[i])) {
86 addr = xel_addrs[i]; 86 addr = xel_addrs[i];
87 break; 87 break;
88 } 88 }
89 } 89 }
90 } else { 90 } else {
91 if (xel_probe((paddr_t) match->cf_addr)) 91 if (xel_probe((paddr_t) match->cf_addr))
92 addr = (paddr_t) match->cf_addr; 92 addr = (paddr_t) match->cf_addr;
93 } 93 }
94 94
95 if (addr) { 95 if (addr) {
96 /* found! */ 96 /* found! */
97 ia->ia_addr = (int) addr; 97 ia->ia_addr = (int) addr;
98 ia->ia_size = 0x4000; 98 ia->ia_size = 0x4000;
99 if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY) 99 if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY)
100 < 0) 100 < 0)
101 return 0; 101 return 0;
102 else 102 else
103 return addr; 103 return addr;
104 } 104 }
105 105
106 return 0; 106 return 0;
107} 107}
108 108
109extern int *nofault; 109extern int *nofault;
110 110
111static int 111static int
112xel_probe(paddr_t addr) 112xel_probe(paddr_t addr)
113{ 113{
114 u_int32_t b1, b2; 114 u_int32_t b1, b2;
115 volatile u_int16_t *start = (volatile u_int16_t *)IIOV(addr); 115 volatile u_int16_t *start = (volatile u_int16_t *)IIOV(addr);
116 label_t faultbuf; 116 label_t faultbuf;
117 volatile u_int32_t *sram = (volatile u_int32_t *)IIOV(XEL_RAM_ADDR_HIGHER); 117 volatile u_int32_t *sram = (volatile u_int32_t *)IIOV(XEL_RAM_ADDR_HIGHER);
118 118
119 if (badaddr(start)) 119 if (badaddr(start))
120 return 0; 120 return 0;
121 121
122 nofault = (int *) &faultbuf; 122 nofault = (int *) &faultbuf;
123 if (setjmp(&faultbuf)) { 123 if (setjmp(&faultbuf)) {
124 nofault = NULL; 124 nofault = NULL;
125 return 0; 125 return 0;
126 } 126 }
127 127
128 b1 = sram[0]; 128 b1 = sram[0];
129 b2 = sram[1]; 129 b2 = sram[1];
130 /* Try to map the Xellent local memory. */ 130 /* Try to map the Xellent local memory. */
131 start[0] = XEL_MODE_RAM_HIGHER | XEL_MODE_MAP_RAM | XEL_MODE_MPU_030; 131 start[0] = XEL_MODE_RAM_HIGHER | XEL_MODE_MAP_RAM | XEL_MODE_MPU_030;
132 132
133#if 0 133#if 0
134 /* the contents should be deferent. */ 134 /* the contents should be deferent. */
135 if (b1 == sram[0] && b2 == sram[1]) { 135 if (b1 == sram[0] && b2 == sram[1]) {
136 nofault = (int *) 0; 136 nofault = (int *) 0;
137 return 0; 137 return 0;
138 } 138 }
139#else 139#else
140 /* Try to write to the local memory. */ 140 /* Try to write to the local memory. */
141 sram[0] = 0x55555555; 141 sram[0] = 0x55555555;
142 sram[1] = 0xaaaaaaaa; 142 sram[1] = 0xaaaaaaaa;
143 if (sram[0] != 0x55555555 || sram[1] != 0xaaaaaaaa) { 143 if (sram[0] != 0x55555555 || sram[1] != 0xaaaaaaaa) {
144 sram[0] = b1; 144 sram[0] = b1;
145 sram[1] = b2; 145 sram[1] = b2;
146 nofault = (int *) 0; 146 nofault = (int *) 0;
147 return 0; 147 return 0;
148 } 148 }
149 sram[0] = 0xaaaaaaaa; 149 sram[0] = 0xaaaaaaaa;
150 sram[1] = 0x55555555; 150 sram[1] = 0x55555555;
151 if (sram[0] != 0xaaaaaaaa || sram[1] != 0x55555555) { 151 if (sram[0] != 0xaaaaaaaa || sram[1] != 0x55555555) {
152 sram[0] = b1; 152 sram[0] = b1;
153 sram[1] = b2; 153 sram[1] = b2;
154 nofault = (int *) 0; 154 nofault = (int *) 0;
155 return 0; 155 return 0;
156 } 156 }
157 sram[0] = b1; 157 sram[0] = b1;
158 sram[1] = b2; 158 sram[1] = b2;
159#endif 159#endif
160 160
161 /* Unmap. */ 161 /* Unmap. */
162 start[0] = XEL_MODE_UNMAP_RAM | XEL_MODE_MPU_030; 162 start[0] = XEL_MODE_UNMAP_RAM | XEL_MODE_MPU_030;
163 163
164 nofault = NULL; 164 nofault = NULL;
165 return 1; 165 return 1;
166} 166}
167 167
168static int 168static int
169xel_match(struct device *parent, cfdata_t match, void *aux) 169xel_match(device_t parent, cfdata_t match, void *aux)
170{ 170{
171 struct intio_attach_args *ia = aux; 171 struct intio_attach_args *ia = aux;
172 172
173 if (strcmp(ia->ia_name, "xel") != 0) 173 if (strcmp(ia->ia_name, "xel") != 0)
174 return 0; 174 return 0;
175 175
176 if (xel_addr(parent, match, ia)) { 176 if (xel_addr(parent, match, ia)) {
177#ifdef DIAGNOSTIC 177#ifdef DIAGNOSTIC
178 if (cputype != CPU_68030) 178 if (cputype != CPU_68030)
179 panic("Non-030 Xellent???"); 179 panic("Non-030 Xellent???");
180#endif 180#endif
181 return 1; 181 return 1;
182 } 182 }
183 return 0; 183 return 0;
184} 184}
185 185
186static void 186static void
187xel_attach(device_t parent, device_t self, void *aux) 187xel_attach(device_t parent, device_t self, void *aux)
188{ 188{
189 struct xel_softc *sc = device_private(self); 189 struct xel_softc *sc = device_private(self);
190 struct intio_attach_args *ia = aux; 190 struct intio_attach_args *ia = aux;
191 cfdata_t cf = device_cfdata(self); 191 cfdata_t cf = device_cfdata(self);
192 paddr_t addr; 192 paddr_t addr;
193 int r; 193 int r;
194 194
195 addr = xel_addr(parent, cf, aux); 195 addr = xel_addr(parent, cf, aux);
196 sc->sc_bst = ia->ia_bst; 196 sc->sc_bst = ia->ia_bst;
197 ia->ia_addr = (int) addr; 197 ia->ia_addr = (int) addr;
198 ia->ia_size = 0x4000; 198 ia->ia_size = 0x4000;
199 r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE); 199 r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
200#ifdef DIAGNOSTIC 200#ifdef DIAGNOSTIC
201 if (r) 201 if (r)
202 panic("IO map for Xellent30 corruption??"); 202 panic("IO map for Xellent30 corruption??");
203#endif 203#endif
204 aprint_normal(": Xellent30 MPU Accelerator.\n"); 204 aprint_normal(": Xellent30 MPU Accelerator.\n");
205 205
206 return; 206 return;
207} 207}

cvs diff -r1.39 -r1.40 src/sys/arch/x68k/dev/zs.c (switch to unified diff)

--- src/sys/arch/x68k/dev/zs.c 2008/12/18 05:56:42 1.39
+++ src/sys/arch/x68k/dev/zs.c 2008/12/31 09:50:21 1.40
@@ -1,636 +1,636 @@ @@ -1,636 +1,636 @@
1/* $NetBSD: zs.c,v 1.39 2008/12/18 05:56:42 isaki Exp $ */ 1/* $NetBSD: zs.c,v 1.40 2008/12/31 09:50:21 isaki Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998 Minoura Makoto 4 * Copyright (c) 1998 Minoura Makoto
5 * Copyright (c) 1996 The NetBSD Foundation, Inc. 5 * Copyright (c) 1996 The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Gordon W. Ross. 9 * by Gordon W. Ross.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright 16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the 17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution. 18 * documentation and/or other materials provided with the distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * Zilog Z8530 Dual UART driver (machine-dependent part) 34 * Zilog Z8530 Dual UART driver (machine-dependent part)
35 * 35 *
36 * X68k uses one Z8530 built-in. Channel A is for RS-232C serial port; 36 * X68k uses one Z8530 built-in. Channel A is for RS-232C serial port;
37 * while channel B is dedicated to the mouse. 37 * while channel B is dedicated to the mouse.
38 * Extra Z8530's can be installed for serial ports. This driver 38 * Extra Z8530's can be installed for serial ports. This driver
39 * supports up to 5 chips including the built-in one. 39 * supports up to 5 chips including the built-in one.
40 */ 40 */
41 41
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43__KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.39 2008/12/18 05:56:42 isaki Exp $"); 43__KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.40 2008/12/31 09:50:21 isaki Exp $");
44 44
45#include <sys/param.h> 45#include <sys/param.h>
46#include <sys/systm.h> 46#include <sys/systm.h>
47#include <sys/conf.h> 47#include <sys/conf.h>
48#include <sys/device.h> 48#include <sys/device.h>
49#include <sys/file.h> 49#include <sys/file.h>
50#include <sys/ioctl.h> 50#include <sys/ioctl.h>
51#include <sys/kernel.h> 51#include <sys/kernel.h>
52#include <sys/proc.h> 52#include <sys/proc.h>
53#include <sys/tty.h> 53#include <sys/tty.h>
54#include <sys/time.h> 54#include <sys/time.h>
55#include <sys/syslog.h> 55#include <sys/syslog.h>
56#include <sys/cpu.h> 56#include <sys/cpu.h>
57#include <sys/bus.h> 57#include <sys/bus.h>
58#include <sys/intr.h> 58#include <sys/intr.h>
59 59
60#include <arch/x68k/dev/intiovar.h> 60#include <arch/x68k/dev/intiovar.h>
61#include <machine/z8530var.h> 61#include <machine/z8530var.h>
62 62
63#include <dev/ic/z8530reg.h> 63#include <dev/ic/z8530reg.h>
64 64
65#include "ioconf.h" 65#include "ioconf.h"
66#include "zsc.h" /* NZSC */ 66#include "zsc.h" /* NZSC */
67#include "opt_zsc.h" 67#include "opt_zsc.h"
68#ifndef ZSCN_SPEED 68#ifndef ZSCN_SPEED
69#define ZSCN_SPEED 9600 69#define ZSCN_SPEED 9600
70#endif 70#endif
71#include "zstty.h" 71#include "zstty.h"
72 72
73 73
74extern void Debugger(void); 74extern void Debugger(void);
75 75
76/* 76/*
77 * Some warts needed by z8530tty.c - 77 * Some warts needed by z8530tty.c -
78 * The default parity REALLY needs to be the same as the PROM uses, 78 * The default parity REALLY needs to be the same as the PROM uses,
79 * or you can not see messages done with printf during boot-up... 79 * or you can not see messages done with printf during boot-up...
80 */ 80 */
81int zs_def_cflag = (CREAD | CS8 | HUPCL); 81int zs_def_cflag = (CREAD | CS8 | HUPCL);
82int zscn_def_cflag = (CREAD | CS8 | HUPCL); 82int zscn_def_cflag = (CREAD | CS8 | HUPCL);
83 83
84/* 84/*
85 * X68k provides a 5.0 MHz clock to the ZS chips. 85 * X68k provides a 5.0 MHz clock to the ZS chips.
86 */ 86 */
87#define PCLK (5 * 1000 * 1000) /* PCLK pin input clock rate */ 87#define PCLK (5 * 1000 * 1000) /* PCLK pin input clock rate */
88 88
89 89
90/* Default physical addresses. */ 90/* Default physical addresses. */
91#define ZS_MAXDEV 5 91#define ZS_MAXDEV 5
92static bus_addr_t zs_physaddr[ZS_MAXDEV] = { 92static bus_addr_t zs_physaddr[ZS_MAXDEV] = {
93 0x00e98000, 93 0x00e98000,
94 0x00eafc00, 94 0x00eafc00,
95 0x00eafc10, 95 0x00eafc10,
96 0x00eafc20, 96 0x00eafc20,
97 0x00eafc30 97 0x00eafc30
98}; 98};
99 99
100static uint8_t zs_init_reg[16] = { 100static uint8_t zs_init_reg[16] = {
101 0, /* 0: CMD (reset, etc.) */ 101 0, /* 0: CMD (reset, etc.) */
102 0, /* 1: No interrupts yet. */ 102 0, /* 1: No interrupts yet. */
103 0x70, /* 2: XXX: IVECT */ 103 0x70, /* 2: XXX: IVECT */
104 ZSWR3_RX_8 | ZSWR3_RX_ENABLE, 104 ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
105 ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP, 105 ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
106 ZSWR5_TX_8 | ZSWR5_TX_ENABLE, 106 ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
107 0, /* 6: TXSYNC/SYNCLO */ 107 0, /* 6: TXSYNC/SYNCLO */
108 0, /* 7: RXSYNC/SYNCHI */ 108 0, /* 7: RXSYNC/SYNCHI */
109 0, /* 8: alias for data port */ 109 0, /* 8: alias for data port */
110 ZSWR9_MASTER_IE, 110 ZSWR9_MASTER_IE,
111 ZSWR10_NRZ, /*10: Misc. TX/RX control bits */ 111 ZSWR10_NRZ, /*10: Misc. TX/RX control bits */
112 ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD, 112 ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
113 ((PCLK/32)/9600)-2, /*12: BAUDLO (default=9600) */ 113 ((PCLK/32)/9600)-2, /*12: BAUDLO (default=9600) */
114 0, /*13: BAUDHI (default=9600) */ 114 0, /*13: BAUDHI (default=9600) */
115 ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK, 115 ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
116 ZSWR15_BREAK_IE, 116 ZSWR15_BREAK_IE,
117}; 117};
118 118
119static volatile struct zschan *conschan = 0; 119static volatile struct zschan *conschan = 0;
120 120
121 121
122/**************************************************************** 122/****************************************************************
123 * Autoconfig 123 * Autoconfig
124 ****************************************************************/ 124 ****************************************************************/
125 125
126/* Definition of the driver for autoconfig. */ 126/* Definition of the driver for autoconfig. */
127static int zs_match(device_t, cfdata_t, void *); 127static int zs_match(device_t, cfdata_t, void *);
128static void zs_attach(device_t, device_t, void *); 128static void zs_attach(device_t, device_t, void *);
129static int zs_print(void *, const char *name); 129static int zs_print(void *, const char *name);
130 130
131CFATTACH_DECL_NEW(zsc, sizeof(struct zsc_softc), 131CFATTACH_DECL_NEW(zsc, sizeof(struct zsc_softc),
132 zs_match, zs_attach, NULL, NULL); 132 zs_match, zs_attach, NULL, NULL);
133 133
134static int zshard(void *); 134static int zshard(void *);
135static int zs_get_speed(struct zs_chanstate *); 135static int zs_get_speed(struct zs_chanstate *);
136 136
137 137
138/* 138/*
139 * Is the zs chip present? 139 * Is the zs chip present?
140 */ 140 */
141static int 141static int
142zs_match(device_t parent, cfdata_t cf, void *aux) 142zs_match(device_t parent, cfdata_t cf, void *aux)
143{ 143{
144 struct intio_attach_args *ia = aux; 144 struct intio_attach_args *ia = aux;
145 struct zsdevice *zsaddr = (void *)ia->ia_addr; 145 struct zsdevice *zsaddr = (void *)ia->ia_addr;
146 int i; 146 int i;
147 147
148 if (strcmp(ia->ia_name, "zsc") != 0) 148 if (strcmp(ia->ia_name, "zsc") != 0)
149 return 0; 149 return 0;
150 150
151 for (i = 0; i < ZS_MAXDEV; i++) 151 for (i = 0; i < ZS_MAXDEV; i++)
152 if (zsaddr == (void *)zs_physaddr[i]) /* XXX */ 152 if (zsaddr == (void *)zs_physaddr[i]) /* XXX */
153 break; 153 break;
154 154
155 ia->ia_size = 8; 155 ia->ia_size = 8;
156 if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY)) 156 if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY))
157 return 0; 157 return 0;
158 158
159 if (zsaddr != (void *)zs_physaddr[i]) 159 if (zsaddr != (void *)zs_physaddr[i])
160 return 0; 160 return 0;
161 if (badaddr((void *)IIOV(zsaddr))) 161 if (badaddr((void *)IIOV(zsaddr)))
162 return 0; 162 return 0;
163 163
164 return (1); 164 return (1);
165} 165}
166 166
167/* 167/*
168 * Attach a found zs. 168 * Attach a found zs.
169 */ 169 */
170static void 170static void
171zs_attach(device_t parent, device_t self, void *aux) 171zs_attach(device_t parent, device_t self, void *aux)
172{ 172{
173 struct zsc_softc *zsc = device_private(self); 173 struct zsc_softc *zsc = device_private(self);
174 struct intio_attach_args *ia = aux; 174 struct intio_attach_args *ia = aux;
175 struct zsc_attach_args zsc_args; 175 struct zsc_attach_args zsc_args;
176 volatile struct zschan *zc; 176 volatile struct zschan *zc;
177 struct zs_chanstate *cs; 177 struct zs_chanstate *cs;
178 int r, s, zs_unit, channel; 178 int r, s, zs_unit, channel;
179 179
180 zsc->zsc_dev = self; 180 zsc->zsc_dev = self;
181 aprint_normal("\n"); 181 aprint_normal("\n");
182 182
183 zs_unit = device_unit(self); 183 zs_unit = device_unit(self);
184 zsc->zsc_addr = (void *)ia->ia_addr; 184 zsc->zsc_addr = (void *)ia->ia_addr;
185 185
186 ia->ia_size = 8; 186 ia->ia_size = 8;
187 r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE); 187 r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
188#ifdef DIAGNOSTIC 188#ifdef DIAGNOSTIC
189 if (r) 189 if (r)
190 panic("zs: intio IO map corruption"); 190 panic("zs: intio IO map corruption");
191#endif 191#endif
192 192
193 /* 193 /*
194 * Initialize software state for each channel. 194 * Initialize software state for each channel.
195 */ 195 */
196 for (channel = 0; channel < 2; channel++) { 196 for (channel = 0; channel < 2; channel++) {
197 struct device *child; 197 device_t child;
198 198
199 zsc_args.channel = channel; 199 zsc_args.channel = channel;
200 zsc_args.hwflags = 0; 200 zsc_args.hwflags = 0;
201 cs = &zsc->zsc_cs_store[channel]; 201 cs = &zsc->zsc_cs_store[channel];
202 zsc->zsc_cs[channel] = cs; 202 zsc->zsc_cs[channel] = cs;
203 203
204 zs_lock_init(cs); 204 zs_lock_init(cs);
205 cs->cs_channel = channel; 205 cs->cs_channel = channel;
206 cs->cs_private = NULL; 206 cs->cs_private = NULL;
207 cs->cs_ops = &zsops_null; 207 cs->cs_ops = &zsops_null;
208 cs->cs_brg_clk = PCLK / 16; 208 cs->cs_brg_clk = PCLK / 16;
209 209
210 if (channel == 0) 210 if (channel == 0)
211 zc = (volatile void *)IIOV(&zsc->zsc_addr->zs_chan_a); 211 zc = (volatile void *)IIOV(&zsc->zsc_addr->zs_chan_a);
212 else 212 else
213 zc = (volatile void *)IIOV(&zsc->zsc_addr->zs_chan_b); 213 zc = (volatile void *)IIOV(&zsc->zsc_addr->zs_chan_b);
214 cs->cs_reg_csr = &zc->zc_csr; 214 cs->cs_reg_csr = &zc->zc_csr;
215 cs->cs_reg_data = &zc->zc_data; 215 cs->cs_reg_data = &zc->zc_data;
216 216
217 zs_init_reg[2] = ia->ia_intr; 217 zs_init_reg[2] = ia->ia_intr;
218 memcpy(cs->cs_creg, zs_init_reg, 16); 218 memcpy(cs->cs_creg, zs_init_reg, 16);
219 memcpy(cs->cs_preg, zs_init_reg, 16); 219 memcpy(cs->cs_preg, zs_init_reg, 16);
220 220
221 if (zc == conschan) { 221 if (zc == conschan) {
222 zsc_args.hwflags |= ZS_HWFLAG_CONSOLE; 222 zsc_args.hwflags |= ZS_HWFLAG_CONSOLE;
223 cs->cs_defspeed = zs_get_speed(cs); 223 cs->cs_defspeed = zs_get_speed(cs);
224 cs->cs_defcflag = zscn_def_cflag; 224 cs->cs_defcflag = zscn_def_cflag;
225 } else { 225 } else {
226 cs->cs_defspeed = 9600; 226 cs->cs_defspeed = 9600;
227 cs->cs_defcflag = zs_def_cflag; 227 cs->cs_defcflag = zs_def_cflag;
228 } 228 }
229 229
230 /* Make these correspond to cs_defcflag (-crtscts) */ 230 /* Make these correspond to cs_defcflag (-crtscts) */
231 cs->cs_rr0_dcd = ZSRR0_DCD; 231 cs->cs_rr0_dcd = ZSRR0_DCD;
232 cs->cs_rr0_cts = 0; 232 cs->cs_rr0_cts = 0;
233 cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS; 233 cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
234 cs->cs_wr5_rts = 0; 234 cs->cs_wr5_rts = 0;
235 235
236 /* 236 /*
237 * Clear the master interrupt enable. 237 * Clear the master interrupt enable.
238 * The INTENA is common to both channels, 238 * The INTENA is common to both channels,
239 * so just do it on the A channel. 239 * so just do it on the A channel.
240 */ 240 */
241 if (channel == 0) { 241 if (channel == 0) {
242 s = splzs(); 242 s = splzs();
243 zs_write_reg(cs, 9, 0); 243 zs_write_reg(cs, 9, 0);
244 splx(s); 244 splx(s);
245 } 245 }
246 246
247 /* 247 /*
248 * Look for a child driver for this channel. 248 * Look for a child driver for this channel.
249 * The child attach will setup the hardware. 249 * The child attach will setup the hardware.
250 */ 250 */
251 child = config_found(self, (void *)&zsc_args, zs_print); 251 child = config_found(self, (void *)&zsc_args, zs_print);
252#if ZSTTY > 0 252#if ZSTTY > 0
253 if (zc == conschan && 253 if (zc == conschan &&
254 ((child && strcmp(device_xname(child), "zstty0")) || 254 ((child && strcmp(device_xname(child), "zstty0")) ||
255 child == NULL)) /* XXX */ 255 child == NULL)) /* XXX */
256 panic("%s: console device mismatch", __func__); 256 panic("%s: console device mismatch", __func__);
257#endif 257#endif
258 if (child == NULL) { 258 if (child == NULL) {
259 /* No sub-driver. Just reset it. */ 259 /* No sub-driver. Just reset it. */
260 uint8_t reset = (channel == 0) ? 260 uint8_t reset = (channel == 0) ?
261 ZSWR9_A_RESET : ZSWR9_B_RESET; 261 ZSWR9_A_RESET : ZSWR9_B_RESET;
262 s = splzs(); 262 s = splzs();
263 zs_write_reg(cs, 9, reset); 263 zs_write_reg(cs, 9, reset);
264 splx(s); 264 splx(s);
265 } 265 }
266 } 266 }
267 267
268 /* 268 /*
269 * Now safe to install interrupt handlers. 269 * Now safe to install interrupt handlers.
270 */ 270 */
271 if (intio_intr_establish(ia->ia_intr, "zs", zshard, zsc)) 271 if (intio_intr_establish(ia->ia_intr, "zs", zshard, zsc))
272 panic("%s: interrupt vector busy", __func__); 272 panic("%s: interrupt vector busy", __func__);
273 zsc->zsc_softintr_cookie = softint_establish(SOFTINT_SERIAL, 273 zsc->zsc_softintr_cookie = softint_establish(SOFTINT_SERIAL,
274 (void (*)(void *))zsc_intr_soft, zsc); 274 (void (*)(void *))zsc_intr_soft, zsc);
275 /* XXX; evcnt_attach() ? */ 275 /* XXX; evcnt_attach() ? */
276 276
277 /* 277 /*
278 * Set the master interrupt enable and interrupt vector. 278 * Set the master interrupt enable and interrupt vector.
279 * (common to both channels, do it on A) 279 * (common to both channels, do it on A)
280 */ 280 */
281 cs = zsc->zsc_cs[0]; 281 cs = zsc->zsc_cs[0];
282 s = splzs(); 282 s = splzs();
283 /* interrupt vector */ 283 /* interrupt vector */
284 zs_write_reg(cs, 2, ia->ia_intr); 284 zs_write_reg(cs, 2, ia->ia_intr);
285 /* master interrupt control (enable) */ 285 /* master interrupt control (enable) */
286 zs_write_reg(cs, 9, zs_init_reg[9]); 286 zs_write_reg(cs, 9, zs_init_reg[9]);
287 splx(s); 287 splx(s);
288} 288}
289 289
290static int 290static int
291zs_print(void *aux, const char *name) 291zs_print(void *aux, const char *name)
292{ 292{
293 struct zsc_attach_args *args = aux; 293 struct zsc_attach_args *args = aux;
294 294
295 if (name != NULL) 295 if (name != NULL)
296 aprint_normal("%s: ", name); 296 aprint_normal("%s: ", name);
297 297
298 if (args->channel != -1) 298 if (args->channel != -1)
299 aprint_normal(" channel %d", args->channel); 299 aprint_normal(" channel %d", args->channel);
300 300
301 return UNCONF; 301 return UNCONF;
302} 302}
303 303
304 304
305/* 305/*
306 * For x68k-port, we don't use autovectored interrupt. 306 * For x68k-port, we don't use autovectored interrupt.
307 * We do not need to look at all of the zs chips. 307 * We do not need to look at all of the zs chips.
308 */ 308 */
309static int 309static int
310zshard(void *arg) 310zshard(void *arg)
311{ 311{
312 struct zsc_softc *zsc = arg; 312 struct zsc_softc *zsc = arg;
313 int rval; 313 int rval;
314 int s; 314 int s;
315 315
316 /* 316 /*
317 * Actually, zs hardware ipl is 5. 317 * Actually, zs hardware ipl is 5.
318 * Here we disable all interrupts to shorten the zshard 318 * Here we disable all interrupts to shorten the zshard
319 * handling time. Otherwise, too many characters are 319 * handling time. Otherwise, too many characters are
320 * dropped. 320 * dropped.
321 */ 321 */
322 s = splhigh(); 322 s = splhigh();
323 rval = zsc_intr_hard(zsc); 323 rval = zsc_intr_hard(zsc);
324 324
325 /* We are at splzs here, so no need to lock. */ 325 /* We are at splzs here, so no need to lock. */
326 if (zsc->zsc_cs[0]->cs_softreq || zsc->zsc_cs[1]->cs_softreq) 326 if (zsc->zsc_cs[0]->cs_softreq || zsc->zsc_cs[1]->cs_softreq)
327 softint_schedule(zsc->zsc_softintr_cookie); 327 softint_schedule(zsc->zsc_softintr_cookie);
328 328
329 return (rval); 329 return (rval);
330} 330}
331 331
332/* 332/*
333 * Compute the current baud rate given a ZS channel. 333 * Compute the current baud rate given a ZS channel.
334 */ 334 */
335static int 335static int
336zs_get_speed(struct zs_chanstate *cs) 336zs_get_speed(struct zs_chanstate *cs)
337{ 337{
338 int tconst; 338 int tconst;
339 339
340 tconst = zs_read_reg(cs, 12); 340 tconst = zs_read_reg(cs, 12);
341 tconst |= zs_read_reg(cs, 13) << 8; 341 tconst |= zs_read_reg(cs, 13) << 8;
342 return (TCONST_TO_BPS(cs->cs_brg_clk, tconst)); 342 return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
343} 343}
344 344
345/* 345/*
346 * MD functions for setting the baud rate and control modes. 346 * MD functions for setting the baud rate and control modes.
347 */ 347 */
348int 348int
349zs_set_speed(struct zs_chanstate *cs, int bps /* bits per second */) 349zs_set_speed(struct zs_chanstate *cs, int bps /* bits per second */)
350{ 350{
351 int tconst, real_bps; 351 int tconst, real_bps;
352 352
353 if (bps == 0) 353 if (bps == 0)
354 return (0); 354 return (0);
355 355
356#ifdef DIAGNOSTIC 356#ifdef DIAGNOSTIC
357 if (cs->cs_brg_clk == 0) 357 if (cs->cs_brg_clk == 0)
358 panic("zs_set_speed"); 358 panic("zs_set_speed");
359#endif 359#endif
360 360
361 tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps); 361 tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
362 if (tconst < 0) 362 if (tconst < 0)
363 return (EINVAL); 363 return (EINVAL);
364 364
365 /* Convert back to make sure we can do it. */ 365 /* Convert back to make sure we can do it. */
366 real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst); 366 real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
367 367
368#if 0 /* XXX */ 368#if 0 /* XXX */
369 /* XXX - Allow some tolerance here? */ 369 /* XXX - Allow some tolerance here? */
370 if (real_bps != bps) 370 if (real_bps != bps)
371 return (EINVAL); 371 return (EINVAL);
372#else 372#else
373 /* 373 /*
374 * Since our PCLK has somewhat strange value, 374 * Since our PCLK has somewhat strange value,
375 * we have to allow tolerance here. 375 * we have to allow tolerance here.
376 */ 376 */
377 if (BPS_TO_TCONST(cs->cs_brg_clk, real_bps) != tconst) 377 if (BPS_TO_TCONST(cs->cs_brg_clk, real_bps) != tconst)
378 return (EINVAL); 378 return (EINVAL);
379#endif 379#endif
380 380
381 cs->cs_preg[12] = tconst; 381 cs->cs_preg[12] = tconst;
382 cs->cs_preg[13] = tconst >> 8; 382 cs->cs_preg[13] = tconst >> 8;
383 383
384 /* Caller will stuff the pending registers. */ 384 /* Caller will stuff the pending registers. */
385 return (0); 385 return (0);
386} 386}
387 387
388int 388int
389zs_set_modes(struct zs_chanstate *cs, int cflag /* bits per second */) 389zs_set_modes(struct zs_chanstate *cs, int cflag /* bits per second */)
390{ 390{
391 int s; 391 int s;
392 392
393 /* 393 /*
394 * Output hardware flow control on the chip is horrendous: 394 * Output hardware flow control on the chip is horrendous:
395 * if carrier detect drops, the receiver is disabled, and if 395 * if carrier detect drops, the receiver is disabled, and if
396 * CTS drops, the transmitter is stoped IN MID CHARACTER! 396 * CTS drops, the transmitter is stoped IN MID CHARACTER!
397 * Therefore, NEVER set the HFC bit, and instead use the 397 * Therefore, NEVER set the HFC bit, and instead use the
398 * status interrupt to detect CTS changes. 398 * status interrupt to detect CTS changes.
399 */ 399 */
400 s = splzs(); 400 s = splzs();
401 cs->cs_rr0_pps = 0; 401 cs->cs_rr0_pps = 0;
402 if ((cflag & (CLOCAL | MDMBUF)) != 0) { 402 if ((cflag & (CLOCAL | MDMBUF)) != 0) {
403 cs->cs_rr0_dcd = 0; 403 cs->cs_rr0_dcd = 0;
404 if ((cflag & MDMBUF) == 0) 404 if ((cflag & MDMBUF) == 0)
405 cs->cs_rr0_pps = ZSRR0_DCD; 405 cs->cs_rr0_pps = ZSRR0_DCD;
406 } else 406 } else
407 cs->cs_rr0_dcd = ZSRR0_DCD; 407 cs->cs_rr0_dcd = ZSRR0_DCD;
408 if ((cflag & CRTSCTS) != 0) { 408 if ((cflag & CRTSCTS) != 0) {
409 cs->cs_wr5_dtr = ZSWR5_DTR; 409 cs->cs_wr5_dtr = ZSWR5_DTR;
410 cs->cs_wr5_rts = ZSWR5_RTS; 410 cs->cs_wr5_rts = ZSWR5_RTS;
411 cs->cs_rr0_cts = ZSRR0_CTS; 411 cs->cs_rr0_cts = ZSRR0_CTS;
412 } else if ((cflag & MDMBUF) != 0) { 412 } else if ((cflag & MDMBUF) != 0) {
413 cs->cs_wr5_dtr = 0; 413 cs->cs_wr5_dtr = 0;
414 cs->cs_wr5_rts = ZSWR5_DTR; 414 cs->cs_wr5_rts = ZSWR5_DTR;
415 cs->cs_rr0_cts = ZSRR0_DCD; 415 cs->cs_rr0_cts = ZSRR0_DCD;
416 } else { 416 } else {
417 cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS; 417 cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
418 cs->cs_wr5_rts = 0; 418 cs->cs_wr5_rts = 0;
419 cs->cs_rr0_cts = 0; 419 cs->cs_rr0_cts = 0;
420 } 420 }
421 splx(s); 421 splx(s);
422 422
423 /* Caller will stuff the pending registers. */ 423 /* Caller will stuff the pending registers. */
424 return (0); 424 return (0);
425} 425}
426 426
427 427
428/* 428/*
429 * Read or write the chip with suitable delays. 429 * Read or write the chip with suitable delays.
430 */ 430 */
431 431
432uint8_t 432uint8_t
433zs_read_reg(struct zs_chanstate *cs, uint8_t reg) 433zs_read_reg(struct zs_chanstate *cs, uint8_t reg)
434{ 434{
435 uint8_t val; 435 uint8_t val;
436 436
437 *cs->cs_reg_csr = reg; 437 *cs->cs_reg_csr = reg;
438 ZS_DELAY(); 438 ZS_DELAY();
439 val = *cs->cs_reg_csr; 439 val = *cs->cs_reg_csr;
440 ZS_DELAY(); 440 ZS_DELAY();
441 return val; 441 return val;
442} 442}
443 443
444void 444void
445zs_write_reg(struct zs_chanstate *cs, uint8_t reg, uint8_t val) 445zs_write_reg(struct zs_chanstate *cs, uint8_t reg, uint8_t val)
446{ 446{
447 *cs->cs_reg_csr = reg; 447 *cs->cs_reg_csr = reg;
448 ZS_DELAY(); 448 ZS_DELAY();
449 *cs->cs_reg_csr = val; 449 *cs->cs_reg_csr = val;
450 ZS_DELAY(); 450 ZS_DELAY();
451} 451}
452 452
453uint8_t 453uint8_t
454zs_read_csr(struct zs_chanstate *cs) 454zs_read_csr(struct zs_chanstate *cs)
455{ 455{
456 uint8_t val; 456 uint8_t val;
457 457
458 val = *cs->cs_reg_csr; 458 val = *cs->cs_reg_csr;
459 ZS_DELAY(); 459 ZS_DELAY();
460 return val; 460 return val;
461} 461}
462 462
463void 463void
464zs_write_csr(struct zs_chanstate *cs, uint8_t val) 464zs_write_csr(struct zs_chanstate *cs, uint8_t val)
465{ 465{
466 *cs->cs_reg_csr = val; 466 *cs->cs_reg_csr = val;
467 ZS_DELAY(); 467 ZS_DELAY();
468} 468}
469 469
470uint8_t 470uint8_t
471zs_read_data(struct zs_chanstate *cs) 471zs_read_data(struct zs_chanstate *cs)
472{ 472{
473 uint8_t val; 473 uint8_t val;
474 474
475 val = *cs->cs_reg_data; 475 val = *cs->cs_reg_data;
476 ZS_DELAY(); 476 ZS_DELAY();
477 return val; 477 return val;
478} 478}
479 479
480void 480void
481zs_write_data(struct zs_chanstate *cs, uint8_t val) 481zs_write_data(struct zs_chanstate *cs, uint8_t val)
482{ 482{
483 *cs->cs_reg_data = val; 483 *cs->cs_reg_data = val;
484 ZS_DELAY(); 484 ZS_DELAY();
485} 485}
486 486
487 487
488/**************************************************************** 488/****************************************************************
489 * Console support functions (x68k specific!) 489 * Console support functions (x68k specific!)
490 * Note: this code is allowed to know about the layout of 490 * Note: this code is allowed to know about the layout of
491 * the chip registers, and uses that to keep things simple. 491 * the chip registers, and uses that to keep things simple.
492 * XXX - I think I like the mvme167 code better. -gwr 492 * XXX - I think I like the mvme167 code better. -gwr
493 ****************************************************************/ 493 ****************************************************************/
494 494
495/* 495/*
496 * Handle user request to enter kernel debugger. 496 * Handle user request to enter kernel debugger.
497 */ 497 */
498void 498void
499zs_abort(struct zs_chanstate *cs) 499zs_abort(struct zs_chanstate *cs)
500{ 500{
501 int rr0; 501 int rr0;
502 502
503 /* Wait for end of break to avoid PROM abort. */ 503 /* Wait for end of break to avoid PROM abort. */
504 /* XXX - Limit the wait? */ 504 /* XXX - Limit the wait? */
505 do { 505 do {
506 rr0 = *cs->cs_reg_csr; 506 rr0 = *cs->cs_reg_csr;
507 ZS_DELAY(); 507 ZS_DELAY();
508 } while (rr0 & ZSRR0_BREAK); 508 } while (rr0 & ZSRR0_BREAK);
509 509
510#ifdef DDB 510#ifdef DDB
511 Debugger(); 511 Debugger();
512#else 512#else
513 printf("BREAK!!\n"); 513 printf("BREAK!!\n");
514#endif 514#endif
515} 515}
516 516
517 517
518#if NZSTTY > 0 518#if NZSTTY > 0
519 519
520#include <dev/cons.h> 520#include <dev/cons.h>
521cons_decl(zs); 521cons_decl(zs);
522 522
523static int zs_getc(void); 523static int zs_getc(void);
524static void zs_putc(int); 524static void zs_putc(int);
525 525
526static struct zs_chanstate zscn_cs; 526static struct zs_chanstate zscn_cs;
527 527
528/* 528/*
529 * Polled input char. 529 * Polled input char.
530 */ 530 */
531static int 531static int
532zs_getc(void) 532zs_getc(void)
533{ 533{
534 int s, c, rr0; 534 int s, c, rr0;
535 535
536 s = splzs(); 536 s = splzs();
537 /* Wait for a character to arrive. */ 537 /* Wait for a character to arrive. */
538 do { 538 do {
539 rr0 = zs_read_csr(&zscn_cs); 539 rr0 = zs_read_csr(&zscn_cs);
540 } while ((rr0 & ZSRR0_RX_READY) == 0); 540 } while ((rr0 & ZSRR0_RX_READY) == 0);
541 541
542 c = zs_read_data(&zscn_cs); 542 c = zs_read_data(&zscn_cs);
543 splx(s); 543 splx(s);
544 544
545 /* 545 /*
546 * This is used by the kd driver to read scan codes, 546 * This is used by the kd driver to read scan codes,
547 * so don't translate '\r' ==> '\n' here... 547 * so don't translate '\r' ==> '\n' here...
548 */ 548 */
549 return (c); 549 return (c);
550} 550}
551 551
552/* 552/*
553 * Polled output char. 553 * Polled output char.
554 */ 554 */
555static void 555static void
556zs_putc(int c) 556zs_putc(int c)
557{ 557{
558 int s, rr0; 558 int s, rr0;
559 559
560 s = splzs(); 560 s = splzs();
561 /* Wait for transmitter to become ready. */ 561 /* Wait for transmitter to become ready. */
562 do { 562 do {
563 rr0 = zs_read_csr(&zscn_cs); 563 rr0 = zs_read_csr(&zscn_cs);
564 } while ((rr0 & ZSRR0_TX_READY) == 0); 564 } while ((rr0 & ZSRR0_TX_READY) == 0);
565 565
566 zs_write_data(&zscn_cs, c); 566 zs_write_data(&zscn_cs, c);
567 splx(s); 567 splx(s);
568} 568}
569 569
570void 570void
571zscninit(struct consdev *cn) 571zscninit(struct consdev *cn)
572{ 572{
573 volatile struct zschan *cnchan = (volatile void *)IIOV(ZSCN_PHYSADDR); 573 volatile struct zschan *cnchan = (volatile void *)IIOV(ZSCN_PHYSADDR);
574 int s; 574 int s;
575 575
576 memset(&zscn_cs, 0, sizeof(struct zs_chanstate)); 576 memset(&zscn_cs, 0, sizeof(struct zs_chanstate));
577 zscn_cs.cs_reg_csr = &cnchan->zc_csr; 577 zscn_cs.cs_reg_csr = &cnchan->zc_csr;
578 zscn_cs.cs_reg_data = &cnchan->zc_data; 578 zscn_cs.cs_reg_data = &cnchan->zc_data;
579 zscn_cs.cs_channel = 0; 579 zscn_cs.cs_channel = 0;
580 zscn_cs.cs_brg_clk = PCLK / 16; 580 zscn_cs.cs_brg_clk = PCLK / 16;
581 memcpy(zscn_cs.cs_preg, zs_init_reg, 16); 581 memcpy(zscn_cs.cs_preg, zs_init_reg, 16);
582 zscn_cs.cs_preg[4] = ZSWR4_CLK_X16 | ZSWR4_ONESB; /* XXX */ 582 zscn_cs.cs_preg[4] = ZSWR4_CLK_X16 | ZSWR4_ONESB; /* XXX */
583 zscn_cs.cs_preg[9] = 0; 583 zscn_cs.cs_preg[9] = 0;
584 zs_set_speed(&zscn_cs, ZSCN_SPEED); 584 zs_set_speed(&zscn_cs, ZSCN_SPEED);
585 s = splzs(); 585 s = splzs();
586 zs_loadchannelregs(&zscn_cs); 586 zs_loadchannelregs(&zscn_cs);
587 splx(s); 587 splx(s);
588 conschan = cnchan; 588 conschan = cnchan;
589} 589}
590 590
591/* 591/*
592 * Polled console input putchar. 592 * Polled console input putchar.
593 */ 593 */
594int 594int
595zscngetc(dev_t dev) 595zscngetc(dev_t dev)
596{ 596{
597 return (zs_getc()); 597 return (zs_getc());
598} 598}
599 599
600/* 600/*
601 * Polled console output putchar. 601 * Polled console output putchar.
602 */ 602 */
603void 603void
604zscnputc(dev_t dev, int c) 604zscnputc(dev_t dev, int c)
605{ 605{
606 zs_putc(c); 606 zs_putc(c);
607} 607}
608 608
609void 609void
610zscnprobe(struct consdev *cd) 610zscnprobe(struct consdev *cd)
611{ 611{
612 int maj; 612 int maj;
613 extern const struct cdevsw zstty_cdevsw; 613 extern const struct cdevsw zstty_cdevsw;
614 614
615 /* locate the major number */ 615 /* locate the major number */
616 maj = cdevsw_lookup_major(&zstty_cdevsw); 616 maj = cdevsw_lookup_major(&zstty_cdevsw);
617 /* XXX: minor number is 0 */ 617 /* XXX: minor number is 0 */
618 618
619 if (maj == -1) 619 if (maj == -1)
620 cd->cn_pri = CN_DEAD; 620 cd->cn_pri = CN_DEAD;
621 else { 621 else {
622#ifdef ZSCONSOLE 622#ifdef ZSCONSOLE
623 cd->cn_pri = CN_REMOTE; /* higher than ITE (CN_INTERNAL) */ 623 cd->cn_pri = CN_REMOTE; /* higher than ITE (CN_INTERNAL) */
624#else 624#else
625 cd->cn_pri = CN_NORMAL; 625 cd->cn_pri = CN_NORMAL;
626#endif 626#endif
627 cd->cn_dev = makedev(maj, 0); 627 cd->cn_dev = makedev(maj, 0);
628 } 628 }
629} 629}
630 630
631void 631void
632zscnpollc(dev_t dev, int on) 632zscnpollc(dev_t dev, int on)
633{ 633{
634} 634}
635 635
636#endif 636#endif