1 /* $NetBSD: amps.c,v 1.7 2002/10/05 17:16:34 chs Exp $ */ 2 3 /*- 4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Mark Brinicombe of Causality Limited. 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 * Card driver and probe and attach functions to use generic 16550 com 39 * driver for the Atomwide multiport serial podule 40 */ 41 42 /* 43 * Thanks to Martin Coulson, Atomwide, for providing the hardware 44 */ 45 46 #include <sys/param.h> 47 #include <sys/systm.h> 48 #include <sys/ioctl.h> 49 #include <sys/select.h> 50 #include <sys/tty.h> 51 #include <sys/proc.h> 52 #include <sys/user.h> 53 #include <sys/conf.h> 54 #include <sys/file.h> 55 #include <sys/uio.h> 56 #include <sys/kernel.h> 57 #include <sys/syslog.h> 58 #include <sys/types.h> 59 #include <sys/device.h> 60 61 #include <machine/intr.h> 62 #include <machine/io.h> 63 #include <machine/bus.h> 64 #include <acorn32/podulebus/podulebus.h> 65 #include <acorn32/podulebus/ampsreg.h> 66 #include <dev/ic/comreg.h> 67 #include <dev/ic/comvar.h> 68 #include <dev/podulebus/podules.h> 69 70 #include "locators.h" 71 72 /* 73 * Atomwide Mulit-port serial podule device. 74 * 75 * This probes and attaches the top level multi-port serial device to the 76 * podulebus. It then configures the child com devices. 77 */ 78 79 /* 80 * Atomwide Multi-port serial card softc structure. 81 * 82 * Contains the device node, podule information and global information 83 * required by the driver such as the card version and the interrupt mask. 84 */ 85 86 struct amps_softc { 87 struct device sc_dev; /* device node */ 88 podule_t *sc_podule; /* Our podule info */ 89 int sc_podule_number; /* Our podule number */ 90 bus_space_tag_t sc_iot; /* Bus tag */ 91 }; 92 93 int amps_probe(struct device *, struct cfdata *, void *); 94 void amps_attach(struct device *, struct device *, void *); 95 96 CFATTACH_DECL(amps, sizeof(struct amps_softc), 97 amps_probe, amps_attach, NULL, NULL); 98 99 int amps_print(void *, const char *); 100 void amps_shutdown(void *); 101 102 /* 103 * Attach arguments for child devices. 104 * Pass the podule details, the parent softc and the channel 105 */ 106 107 struct amps_attach_args { 108 bus_space_tag_t aa_iot; /* bus space tag */ 109 unsigned int aa_base; /* base address for port */ 110 int aa_port; /* serial port number */ 111 podulebus_intr_handle_t aa_irq; /* IRQ number */ 112 }; 113 114 /* 115 * Define prototypes for custom bus space functions. 116 */ 117 118 /* Print function used during child config */ 119 120 int 121 amps_print(aux, name) 122 void *aux; 123 const char *name; 124 { 125 struct amps_attach_args *aa = aux; 126 127 if (!name) 128 printf(", port %d", aa->aa_port); 129 130 return(QUIET); 131 } 132 133 /* 134 * Card probe function 135 * 136 * Just match the manufacturer and podule ID's 137 */ 138 139 int 140 amps_probe(parent, cf, aux) 141 struct device *parent; 142 struct cfdata *cf; 143 void *aux; 144 { 145 struct podule_attach_args *pa = (void *)aux; 146 147 return (pa->pa_product == PODULE_ATOMWIDE_SERIAL); 148 } 149 150 /* 151 * Card attach function 152 * 153 * Identify the card version and configure any children. 154 * Install a shutdown handler to kill interrupts on shutdown 155 */ 156 157 void 158 amps_attach(parent, self, aux) 159 struct device *parent, *self; 160 void *aux; 161 { 162 struct amps_softc *sc = (void *)self; 163 struct podule_attach_args *pa = (void *)aux; 164 struct amps_attach_args aa; 165 166 /* Note the podule number and validate */ 167 168 if (pa->pa_podule_number == -1) 169 panic("Podule has disappeared !"); 170 171 sc->sc_podule_number = pa->pa_podule_number; 172 sc->sc_podule = pa->pa_podule; 173 podules[sc->sc_podule_number].attached = 1; 174 175 sc->sc_iot = pa->pa_iot; 176 177 /* Install a clean up handler to make sure IRQ's are disabled */ 178 /* if (shutdownhook_establish(amps_shutdown, (void *)sc) == NULL) 179 panic("%s: Cannot install shutdown handler", self->dv_xname);*/ 180 181 /* Set the interrupt info for this podule */ 182 183 /* sc->sc_podule->irq_addr = pa->pa_podule->slow_base +;*/ /* XXX */ 184 /* sc->sc_podule->irq_mask = ;*/ 185 186 printf("\n"); 187 188 /* Configure the children */ 189 190 aa.aa_iot = sc->sc_iot; 191 aa.aa_base = pa->pa_podule->slow_base + AMPS_BASE_OFFSET; 192 aa.aa_base += MAX_AMPS_PORTS * AMPS_PORT_SPACING; 193 aa.aa_irq = pa->pa_podule->interrupt; 194 for (aa.aa_port = 0; aa.aa_port < MAX_AMPS_PORTS; ++aa.aa_port) { 195 aa.aa_base -= AMPS_PORT_SPACING; 196 config_found_sm(self, &aa, amps_print, NULL); 197 } 198 } 199 200 /* 201 * Card shutdown function 202 * 203 * Called via do_shutdown_hooks() during kernel shutdown. 204 * Clear the cards's interrupt mask to stop any podule interrupts. 205 */ 206 207 /*void 208 amps_shutdown(arg) 209 void *arg; 210 { 211 }*/ 212 213 /* 214 * Atomwide Multi-Port Serial probe and attach code for the com device. 215 * 216 * This provides a different pair of probe and attach functions 217 * for attaching the com device (dev/ic/com.c) to the Atomwide serial card. 218 */ 219 220 struct com_amps_softc { 221 struct com_softc sc_com; /* real "com" softc */ 222 void *sc_ih; /* interrupt handler */ 223 struct evcnt sc_intrcnt; /* interrupt count */ 224 }; 225 226 /* Prototypes for functions */ 227 228 static int com_amps_probe __P((struct device *, struct cfdata *, void *)); 229 static void com_amps_attach __P((struct device *, struct device *, void *)); 230 231 /* device attach structure */ 232 233 CFATTACH_DECL(com_amps, sizeof(struct com_amps_softc), 234 com_amps_probe, com_amps_attach, NULL, NULL); 235 236 /* 237 * Controller probe function 238 * 239 * Map all the required I/O space for this channel, make sure interrupts 240 * are disabled and probe the bus. 241 */ 242 243 int 244 com_amps_probe(parent, cf, aux) 245 struct device *parent; 246 struct cfdata *cf; 247 void *aux; 248 { 249 bus_space_tag_t iot; 250 bus_space_handle_t ioh; 251 int iobase; 252 int rv = 1; 253 struct amps_attach_args *aa = aux; 254 255 iot = aa->aa_iot; 256 iobase = aa->aa_base; 257 258 /* if it's in use as console, it's there. */ 259 if (!com_is_console(iot, iobase, 0)) { 260 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) { 261 return 0; 262 } 263 /* 264 * We don't use the generic comprobe1() function as it 265 * is not good enough to identify which ports are present. 266 * 267 * Instead test for the presence of the scratch register 268 */ 269 270 bus_space_write_1(iot, ioh, com_scratch, 0x55); 271 bus_space_write_1(iot, ioh, com_ier, 0); 272 (void)bus_space_read_1(iot, ioh, com_data); 273 if (bus_space_read_1(iot, ioh, com_scratch) != 0x55) 274 rv = 0; 275 bus_space_write_1(iot, ioh, com_scratch, 0xaa); 276 bus_space_write_1(iot, ioh, com_ier, 0); 277 (void)bus_space_read_1(iot, ioh, com_data); 278 if (bus_space_read_1(iot, ioh, com_scratch) != 0xaa) 279 rv = 0; 280 281 bus_space_unmap(iot, ioh, COM_NPORTS); 282 } 283 return (rv); 284 } 285 286 /* 287 * Controller attach function 288 * 289 * Map all the required I/O space for this port and attach the driver 290 * The generic attach will probe and attach any device. 291 * Install an interrupt handler and we are ready to rock. 292 */ 293 294 void 295 com_amps_attach(parent, self, aux) 296 struct device *parent, *self; 297 void *aux; 298 { 299 struct com_amps_softc *asc = (void *)self; 300 struct com_softc *sc = &asc->sc_com; 301 u_int iobase; 302 bus_space_tag_t iot; 303 struct amps_attach_args *aa = aux; 304 305 iot = sc->sc_iot = aa->aa_iot; 306 iobase = sc->sc_iobase = aa->aa_base; 307 308 if (!com_is_console(iot, iobase, &sc->sc_ioh) 309 && bus_space_map(iot, iobase, COM_NPORTS, 0, &sc->sc_ioh)) 310 panic("comattach: io mapping failed"); 311 312 sc->sc_frequency = AMPS_FREQ; 313 com_attach_subr(sc); 314 315 evcnt_attach_dynamic(&asc->sc_intrcnt, EVCNT_TYPE_INTR, NULL, 316 self->dv_xname, "intr"); 317 asc->sc_ih = podulebus_irq_establish(aa->aa_irq, IPL_SERIAL, comintr, 318 sc, &asc->sc_intrcnt); 319 } 320