xref: /netbsd-src/sys/arch/amiga/dev/ioblix_zbus.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: ioblix_zbus.c,v 1.17 2010/07/21 01:33:59 jklos 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.17 2010/07/21 01:33:59 jklos 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 
45 #include <machine/bus.h>
46 
47 #include <amiga/include/cpu.h>
48 
49 #include <amiga/amiga/device.h>
50 #include <amiga/amiga/drcustom.h>
51 
52 #include <amiga/dev/supio.h>
53 #include <amiga/dev/zbusvar.h>
54 
55 #include "opt_iobzclock.h"
56 
57 struct iobz_softc {
58 	struct device sc_dev;
59 	struct bus_space_tag sc_bst;
60 };
61 
62 int iobzmatch(struct device *, struct cfdata *, void *);
63 void iobzattach(struct device *, struct device *, void *);
64 int iobzprint(void *auxp, const char *);
65 void iobz_shutdown(void *);
66 
67 CFATTACH_DECL(iobl_zbus, sizeof(struct iobz_softc),
68     iobzmatch, iobzattach, NULL, NULL);
69 
70 int
71 iobzmatch(struct device *parent, struct cfdata *cfp, void *auxp)
72 {
73 
74 	struct zbus_args *zap;
75 
76 	zap = auxp;
77 
78 	if (zap->manid != 4711)
79 		return (0);
80 
81 	if (zap->prodid != 1)
82 		return (0);
83 
84 	return (1);
85 }
86 
87 struct iobz_devs {
88 	const char *name;
89 	unsigned off;
90 	int arg;
91 } iobzdevices[] = {
92 	{ "com", 0x108, 24000000 },	/* XXX see below */
93 	{ "com", 0x100, 24000000 },
94 	{ "com", 0x118, 24000000 },
95 	{ "com", 0x110, 24000000 },
96 	{ "lpt", 0x200, 0 },
97 	{ "lpt", 0x300, 0 },
98 	{ 0, 0, 0}
99 };
100 
101 #ifndef IOBZCLOCK
102 #define IOBZCLOCK 22118400;
103 #endif
104 int iobzclock = IOBZCLOCK;		/* patchable! */
105 
106 void
107 iobzattach(struct device *parent, struct device *self, void *auxp)
108 {
109 	struct iobz_softc *iobzsc;
110 	struct iobz_devs  *iobzd;
111 	struct zbus_args *zap;
112 	struct supio_attach_args supa;
113 	extern const struct amiga_bus_space_methods amiga_bus_stride_16;
114 	volatile u_int8_t *p;
115 
116 
117 	iobzsc = (struct iobz_softc *)self;
118 	zap = auxp;
119 
120 	if (parent)
121 		printf("\n");
122 
123 	iobzsc->sc_bst.base = (u_long)zap->va;
124 	iobzsc->sc_bst.absm = &amiga_bus_stride_16;
125 
126 	supa.supio_iot = &iobzsc->sc_bst;
127 	supa.supio_ipl = 6;
128 
129 	iobzd = iobzdevices;
130 
131 	while (iobzd->name) {
132 		supa.supio_name = iobzd->name;
133 		supa.supio_iobase = iobzd->off;
134 		supa.supio_arg = iobzd->arg ? iobzclock : 0 /* XXX iobzd->arg */;
135 		config_found(self, &supa, iobzprint); /* XXX */
136 		++iobzd;
137 	}
138 
139 	p = (volatile u_int8_t *)zap->va + 2;
140 	(void)shutdownhook_establish(iobz_shutdown, __UNVOLATILE(p));
141 	*p = ((*p) & 0x1F) | 0x80;
142 }
143 
144 int
145 iobzprint(void *auxp, const char *pnp)
146 {
147 	struct supio_attach_args *supa;
148 	supa = auxp;
149 
150 	if (pnp == NULL)
151 		return(QUIET);
152 
153 	aprint_normal("%s at %s port 0x%02x",
154 	    supa->supio_name, pnp, supa->supio_iobase);
155 
156 	return(UNCONF);
157 }
158 
159 /*
160  * Disable board interrupts at shutdown time.
161  */
162 
163 void
164 iobz_shutdown(void *p) {
165 	volatile int8_t *q;
166 
167 	q = p;
168 
169 	*q &= 0x1F;
170 }
171