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