xref: /netbsd-src/sys/arch/amiga/dev/ioblix_zbus.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1 /*	$NetBSD: ioblix_zbus.c,v 1.21 2021/08/07 16:18:41 thorpej Exp $ */
2 
3 /*-
4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Ignatios Souvatzis.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
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
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: ioblix_zbus.c,v 1.21 2021/08/07 16:18:41 thorpej Exp $");
34 
35 /* IOBlix Zorro driver */
36 /* XXX to be done: we need to probe the com clock speed! */
37 
38 #include <sys/types.h>
39 
40 #include <sys/device.h>
41 #include <sys/conf.h>
42 #include <sys/systm.h>
43 #include <sys/param.h>
44 #include <sys/bus.h>
45 
46 #include <amiga/include/cpu.h>
47 
48 #include <amiga/amiga/device.h>
49 #include <amiga/amiga/drcustom.h>
50 
51 #include <amiga/dev/supio.h>
52 #include <amiga/dev/zbusvar.h>
53 
54 #include "opt_iobzclock.h"
55 
56 struct iobz_softc {
57 	struct bus_space_tag sc_bst;
58 };
59 
60 int iobzmatch(device_t, cfdata_t, void *);
61 void iobzattach(device_t, device_t, void *);
62 int iobzprint(void *, const char *);
63 void iobz_shutdown(void *);
64 
65 CFATTACH_DECL_NEW(iobl_zbus, sizeof(struct iobz_softc),
66     iobzmatch, iobzattach, NULL, NULL);
67 
68 int
iobzmatch(device_t parent,cfdata_t cf,void * aux)69 iobzmatch(device_t parent, cfdata_t cf, void *aux)
70 {
71 
72 	struct zbus_args *zap;
73 
74 	zap = aux;
75 
76 	if (zap->manid != 4711)
77 		return (0);
78 
79 	if (zap->prodid != 1)
80 		return (0);
81 
82 	return (1);
83 }
84 
85 struct iobz_devs {
86 	const char *name;
87 	unsigned off;
88 	int arg;
89 } iobzdevices[] = {
90 	{ "com", 0x108, 24000000 },	/* XXX see below */
91 	{ "com", 0x100, 24000000 },
92 	{ "com", 0x118, 24000000 },
93 	{ "com", 0x110, 24000000 },
94 	{ "lpt", 0x200, 0 },
95 	{ "lpt", 0x300, 0 },
96 	{ 0, 0, 0}
97 };
98 
99 #ifndef IOBZCLOCK
100 #define IOBZCLOCK 22118400;
101 #endif
102 int iobzclock = IOBZCLOCK;		/* patchable! */
103 
104 void
iobzattach(device_t parent,device_t self,void * aux)105 iobzattach(device_t parent, device_t self, void *aux)
106 {
107 	struct iobz_softc *iobzsc;
108 	struct iobz_devs  *iobzd;
109 	struct zbus_args *zap;
110 	struct supio_attach_args supa;
111 	extern const struct amiga_bus_space_methods amiga_bus_stride_16;
112 	volatile u_int8_t *p;
113 
114 
115 	iobzsc = device_private(self);
116 	zap = aux;
117 
118 	if (parent)
119 		printf("\n");
120 
121 	iobzsc->sc_bst.base = (u_long)zap->va;
122 	iobzsc->sc_bst.absm = &amiga_bus_stride_16;
123 
124 	supa.supio_iot = &iobzsc->sc_bst;
125 	supa.supio_ipl = 6;
126 
127 	iobzd = iobzdevices;
128 
129 	while (iobzd->name) {
130 		supa.supio_name = iobzd->name;
131 		supa.supio_iobase = iobzd->off;
132 		supa.supio_arg = iobzd->arg ? iobzclock : 0 /* XXX iobzd->arg */;
133 		config_found(self, &supa, iobzprint, CFARGS_NONE); /* XXX */
134 		++iobzd;
135 	}
136 
137 	p = (volatile u_int8_t *)zap->va + 2;
138 	(void)shutdownhook_establish(iobz_shutdown, __UNVOLATILE(p));
139 	*p = ((*p) & 0x1F) | 0x80;
140 }
141 
142 int
iobzprint(void * aux,const char * pnp)143 iobzprint(void *aux, const char *pnp)
144 {
145 	struct supio_attach_args *supa;
146 	supa = aux;
147 
148 	if (pnp == NULL)
149 		return(QUIET);
150 
151 	aprint_normal("%s at %s port 0x%02x",
152 	    supa->supio_name, pnp, supa->supio_iobase);
153 
154 	return(UNCONF);
155 }
156 
157 /*
158  * Disable board interrupts at shutdown time.
159  */
160 
161 void
iobz_shutdown(void * p)162 iobz_shutdown(void *p) {
163 	volatile int8_t *q;
164 
165 	q = p;
166 
167 	*q &= 0x1F;
168 }
169