xref: /netbsd/sys/arch/amiga/dev/hyper.c (revision bf9ec67e)
1 /*	$NetBSD: hyper.c,v 1.12 2002/01/28 09:56:57 aymeric Exp $ */
2 
3 /*-
4  * Copyright (c) 1997,1998 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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: hyper.c,v 1.12 2002/01/28 09:56:57 aymeric Exp $");
41 
42 /*
43  * zbus HyperCom driver
44  */
45 
46 #include <sys/types.h>
47 
48 #include <sys/conf.h>
49 #include <sys/device.h>
50 #include <sys/systm.h>
51 #include <sys/param.h>
52 
53 #include <machine/bus.h>
54 #include <machine/conf.h>
55 
56 #include <amiga/include/cpu.h>
57 
58 #include <amiga/amiga/device.h>
59 #include <amiga/amiga/drcustom.h>
60 
61 #include <amiga/dev/supio.h>
62 #include <amiga/dev/zbusvar.h>
63 
64 
65 struct hyper_softc {
66 	struct device sc_dev;
67 	struct bus_space_tag sc_bst;
68 };
69 
70 int hypermatch(struct device *, struct cfdata *, void *);
71 void hyperattach(struct device *, struct device *, void *);
72 int hyperprint(void *auxp, const char *);
73 
74 struct cfattach hyper_ca = {
75 	sizeof(struct hyper_softc), hypermatch, hyperattach
76 };
77 
78 struct hyper_prods {
79 	char *name;
80 	unsigned baseoff;
81 } hyperproducts [] = {
82 	{0, 0},			/* 0: not used */
83 	{0, 0},			/* 1: handled by aster driver */
84 	{"4", 1},		/* 2 */
85 	{"Z3", 0},		/* 3 */
86 	{0, 0},			/* 4: not used */
87 	{0, 0},			/* 5: not used */
88 	{"4+", 0x8000},		/* 6 */
89 	{"3+", 0x8000}		/* 7 */
90 };
91 
92 int
93 hypermatch(struct device *parent, struct cfdata *cfp, void *auxp)
94 {
95 
96 	struct zbus_args *zap;
97 
98 	zap = auxp;
99 
100 	if (zap->manid != 5001)
101 		return (0);
102 
103 	if (zap->prodid < sizeof(hyperproducts)/sizeof(*hyperproducts) &&
104 	    hyperproducts[zap->prodid].name)
105 
106 		return (1);
107 
108 	return (0);
109 }
110 
111 #define HYPERPROD3	(1<<3)
112 #define HYPERPROD4	(1<<2)
113 #define HYPERPROD4PLUS	(1<<6)
114 #define HYPERPROD3PLUS	(1<<7)
115 
116 struct hyper_devs {
117 	char *name;
118 	unsigned off;
119 	int arg;
120 	u_int32_t productmask;	/* XXX only prodid 0..31 */
121 } hyperdevices[] = {
122 	{ "com", 0x00, 115200 * 16 * 4, HYPERPROD3 | HYPERPROD4 },
123 	{ "com", 0x08, 115200 * 16 * 4, HYPERPROD3 | HYPERPROD4 },
124 	{ "com", 0x10, 115200 * 16 * 4, HYPERPROD4 },
125 	{ "com", 0x18, 115200 * 16 * 4, HYPERPROD4 },
126 	/* not yet { "lpt", 0x40, 0, HYPERPROD3 }, */
127 	{ "com", 0x0400, 115200 * 16 * 4, HYPERPROD3PLUS | HYPERPROD4PLUS },
128 	{ "com", 0x0000, 115200 * 16 * 4, HYPERPROD3PLUS | HYPERPROD4PLUS },
129 	{ "com", 0x0c00, 115200 * 16 * 4, HYPERPROD4PLUS },
130 	{ "com", 0x1000, 115200 * 16 * 4, HYPERPROD4PLUS },
131 	{ "lpt", 0x0800, 0, HYPERPROD3PLUS | HYPERPROD4PLUS },
132 	{ "lpt", 0x1400, 0, HYPERPROD4PLUS },
133 };
134 
135 void
136 hyperattach(struct device *parent, struct device *self, void *auxp)
137 {
138 	struct hyper_softc *hprsc;
139 	struct hyper_devs  *hprsd;
140 	struct zbus_args *zap;
141 	struct supio_attach_args supa;
142 	struct hyper_prods *hprpp;
143 
144 	hprsc = (struct hyper_softc *)self;
145 	zap = auxp;
146 	hprpp = &hyperproducts[zap->prodid];
147 
148 	if (parent)
149 		printf(": Hypercom %s\n", hprpp->name);
150 
151 	hprsc->sc_bst.base = (u_long)zap->va + hprpp->baseoff;
152 	hprsc->sc_bst.absm = &amiga_bus_stride_4;
153 
154 	supa.supio_iot = &hprsc->sc_bst;
155 	supa.supio_ipl = 6;
156 
157 	hprsd = hyperdevices;
158 
159 	while (hprsd->name) {
160 		if (hprsd->productmask & (1 << zap->prodid)) {
161 			supa.supio_name = hprsd->name;
162 			supa.supio_iobase = hprsd->off;
163 			supa.supio_arg = hprsd->arg;
164 			config_found(self, &supa, hyperprint); /* XXX */
165 		}
166 		++hprsd;
167 	}
168 }
169 
170 int
171 hyperprint(void *auxp, const char *pnp)
172 {
173 	struct supio_attach_args *supa;
174 	supa = auxp;
175 
176 	if (pnp == NULL)
177 		return(QUIET);
178 
179 	printf("%s at %s port 0x%02x",
180 	    supa->supio_name, pnp, supa->supio_iobase);
181 
182 	return(UNCONF);
183 }
184