1 /* $NetBSD: if_bah_zbus.c,v 1.17 2017/10/23 09:21:40 msaitoh Exp $ */ 2 3 /*- 4 * Copyright (c) 1994, 1995, 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 #ifdef __m68k__ 33 #include "opt_m68k_arch.h" 34 #endif 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: if_bah_zbus.c,v 1.17 2017/10/23 09:21:40 msaitoh Exp $"); 38 39 /* 40 * Driver frontend for the Commodore Busines Machines and the 41 * Ameristar ARCnet card. 42 */ 43 44 #include <sys/types.h> 45 #include <sys/param.h> 46 47 #include <sys/conf.h> 48 #include <sys/device.h> 49 #include <sys/mbuf.h> 50 #include <sys/socket.h> 51 #include <sys/systm.h> 52 #include <sys/kernel.h> 53 #include <sys/bus.h> 54 55 #include <machine/cpu.h> 56 #include <machine/intr.h> 57 58 #include <net/if.h> 59 #include <net/route.h> 60 61 #include <net/if_arc.h> 62 63 #include <amiga/amiga/device.h> 64 #include <amiga/dev/zbusvar.h> 65 66 #include <dev/ic/smc90cx6var.h> 67 68 /* 69 * A2060 software status per interface 70 */ 71 struct bah_zbus_softc { 72 struct bah_softc sc_bah; 73 struct bus_space_tag sc_bst; 74 struct isr sc_isr; 75 }; 76 77 int bah_zbus_match(device_t, cfdata_t, void *); 78 void bah_zbus_attach(device_t, device_t, void *); 79 void bah_zbus_reset(struct bah_softc *, int); 80 81 CFATTACH_DECL_NEW(bah_zbus, sizeof(struct bah_zbus_softc), 82 bah_zbus_match, bah_zbus_attach, NULL, NULL); 83 84 int 85 bah_zbus_match(device_t parent, cfdata_t cf, void *aux) 86 { 87 struct zbus_args *zap = aux; 88 89 if ((zap->manid == 514 || zap->manid == 1053) && zap->prodid == 9) 90 return (1); 91 92 return (0); 93 } 94 95 void 96 bah_zbus_attach(device_t parent, device_t self, void *aux) 97 { 98 struct bah_zbus_softc *bsc = device_private(self); 99 struct bah_softc *sc = &bsc->sc_bah; 100 struct zbus_args *zap = aux; 101 int rv; 102 103 sc->sc_dev = self; 104 #if (defined(BAH_DEBUG) && (BAH_DEBUG > 2)) 105 printf("\n%s: attach(0x%p, 0x%p, 0x%p)\n", 106 device_xname(self), parent, self, aux); 107 #endif 108 bsc->sc_bst.base = (bus_addr_t)zap->va; 109 bsc->sc_bst.absm = &amiga_bus_stride_2; 110 111 sc->sc_bst_r = &bsc->sc_bst; 112 sc->sc_regs = bsc->sc_bst.base + 0x4000; 113 114 sc->sc_bst_m = &bsc->sc_bst; 115 sc->sc_mem = bsc->sc_bst.base + 0x8000; 116 117 sc->sc_reset = bah_zbus_reset; 118 119 rv = bah_attach_subr(sc); 120 if (rv != 0) { 121 aprint_error_dev(self, "bah_attach_subr failed(%d)\n", rv); 122 return; 123 } 124 125 bsc->sc_isr.isr_intr = bahintr; 126 bsc->sc_isr.isr_arg = sc; 127 bsc->sc_isr.isr_ipl = 2; 128 add_isr(&bsc->sc_isr); 129 } 130 131 void 132 bah_zbus_reset(struct bah_softc *sc, int onoff) 133 { 134 struct bah_zbus_softc *bsc; 135 volatile u_int8_t *p; 136 137 bsc = (struct bah_zbus_softc *)sc; 138 139 p = (volatile u_int8_t *)bsc->sc_bst.base; 140 141 p[0x0000] = 0; /* A2060 reset flipflop */ 142 p[0xc000] = 0; /* A560 reset flipflop */ 143 144 if (!onoff) 145 return; 146 147 #ifdef M68060 148 /* make sure we flush the store buffer before the delay */ 149 (void)p[0x8000]; 150 #endif 151 DELAY(200); 152 153 p[0x0000] = 0xff; 154 p[0xc000] = 0xff; 155 156 return; 157 } 158