1 /* $NetBSD: hyper.c,v 1.24 2021/08/07 16:18:41 thorpej 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 *
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: hyper.c,v 1.24 2021/08/07 16:18:41 thorpej Exp $");
34
35 /*
36 * zbus HyperCom driver
37 */
38
39 #include <sys/types.h>
40
41 #include <sys/device.h>
42 #include <sys/conf.h>
43 #include <sys/systm.h>
44 #include <sys/param.h>
45 #include <sys/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
56 struct hyper_softc {
57 struct bus_space_tag sc_bst;
58 };
59
60 int hypermatch(device_t, cfdata_t, void *);
61 void hyperattach(device_t, device_t, void *);
62 int hyperprint(void *, const char *);
63
64 CFATTACH_DECL_NEW(hyper, sizeof(struct hyper_softc),
65 hypermatch, hyperattach, NULL, NULL);
66
67 struct hyper_prods {
68 const char *name;
69 unsigned baseoff;
70 } hyperproducts [] = {
71 {0, 0}, /* 0: not used */
72 {0, 0}, /* 1: handled by aster driver */
73 {"4", 1}, /* 2 */
74 {"Z3", 0}, /* 3 */
75 {0, 0}, /* 4: not used */
76 {0, 0}, /* 5: not used */
77 {"4+", 0x8000}, /* 6 */
78 {"3+", 0x8000} /* 7 */
79 };
80
81 int
hypermatch(device_t parent,cfdata_t cf,void * aux)82 hypermatch(device_t parent, cfdata_t cf, void *aux)
83 {
84 struct zbus_args *zap;
85
86 zap = aux;
87
88 if (zap->manid != 5001)
89 return (0);
90
91 if (zap->prodid < sizeof(hyperproducts)/sizeof(*hyperproducts) &&
92 hyperproducts[zap->prodid].name)
93
94 return (1);
95
96 return (0);
97 }
98
99 #define HYPERPROD3 (1<<3)
100 #define HYPERPROD4 (1<<2)
101 #define HYPERPROD4PLUS (1<<6)
102 #define HYPERPROD3PLUS (1<<7)
103
104 struct hyper_devs {
105 const char *name;
106 unsigned off;
107 int arg;
108 u_int32_t productmask; /* XXX only prodid 0..31 */
109 } hyperdevices[] = {
110 { "com", 0x00, 115200 * 16 * 4, HYPERPROD3 | HYPERPROD4 },
111 { "com", 0x08, 115200 * 16 * 4, HYPERPROD3 | HYPERPROD4 },
112 { "com", 0x10, 115200 * 16 * 4, HYPERPROD4 },
113 { "com", 0x18, 115200 * 16 * 4, HYPERPROD4 },
114 /* not yet { "lpt", 0x40, 0, HYPERPROD3 }, */
115 { "com", 0x0400, 115200 * 16 * 4, HYPERPROD3PLUS | HYPERPROD4PLUS },
116 { "com", 0x0000, 115200 * 16 * 4, HYPERPROD3PLUS | HYPERPROD4PLUS },
117 { "com", 0x0c00, 115200 * 16 * 4, HYPERPROD4PLUS },
118 { "com", 0x1000, 115200 * 16 * 4, HYPERPROD4PLUS },
119 { "lpt", 0x0800, 0, HYPERPROD3PLUS | HYPERPROD4PLUS },
120 { "lpt", 0x1400, 0, HYPERPROD4PLUS },
121 };
122
123 void
hyperattach(device_t parent,device_t self,void * aux)124 hyperattach(device_t parent, device_t self, void *aux)
125 {
126 struct hyper_softc *hprsc;
127 struct hyper_devs *hprsd;
128 struct zbus_args *zap;
129 struct supio_attach_args supa;
130 struct hyper_prods *hprpp;
131
132 hprsc = device_private(self);
133 zap = aux;
134 hprpp = &hyperproducts[zap->prodid];
135
136 if (parent)
137 printf(": Hypercom %s\n", hprpp->name);
138
139 hprsc->sc_bst.base = (u_long)zap->va + hprpp->baseoff;
140 hprsc->sc_bst.absm = &amiga_bus_stride_4;
141
142 supa.supio_iot = &hprsc->sc_bst;
143 supa.supio_ipl = 6;
144
145 hprsd = hyperdevices;
146
147 while (hprsd->name) {
148 if (hprsd->productmask & (1 << zap->prodid)) {
149 supa.supio_name = hprsd->name;
150 supa.supio_iobase = hprsd->off;
151 supa.supio_arg = hprsd->arg;
152 config_found(self, &supa, hyperprint, CFARGS_NONE); /* XXX */
153 }
154 ++hprsd;
155 }
156 }
157
158 int
hyperprint(void * aux,const char * pnp)159 hyperprint(void *aux, const char *pnp)
160 {
161 struct supio_attach_args *supa;
162 supa = aux;
163
164 if (pnp == NULL)
165 return(QUIET);
166
167 aprint_normal("%s at %s port 0x%02x",
168 supa->supio_name, pnp, supa->supio_iobase);
169
170 return(UNCONF);
171 }
172