1 /* $NetBSD: wdc_amiga.c,v 1.40 2017/10/20 07:06:06 jdolecek Exp $ */ 2 3 /*- 4 * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Michael L. Hitch. 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: wdc_amiga.c,v 1.40 2017/10/20 07:06:06 jdolecek Exp $"); 34 35 #include <sys/types.h> 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/malloc.h> 39 #include <sys/device.h> 40 #include <sys/bus.h> 41 42 #include <machine/cpu.h> 43 #include <machine/intr.h> 44 #include <sys/bswap.h> 45 46 #include <amiga/amiga/cia.h> 47 #include <amiga/amiga/custom.h> 48 #include <amiga/amiga/device.h> 49 #include <amiga/amiga/gayle.h> 50 #include <amiga/dev/zbusvar.h> 51 52 #include <dev/ata/atavar.h> 53 #include <dev/ic/wdcvar.h> 54 55 struct wdc_amiga_softc { 56 struct wdc_softc sc_wdcdev; 57 struct ata_channel *sc_chanlist[1]; 58 struct ata_channel sc_channel; 59 struct wdc_regs sc_wdc_regs; 60 struct isr sc_isr; 61 struct bus_space_tag cmd_iot; 62 struct bus_space_tag ctl_iot; 63 bool gayle_intr; 64 }; 65 66 int wdc_amiga_probe(device_t, cfdata_t, void *); 67 void wdc_amiga_attach(device_t, device_t, void *); 68 int wdc_amiga_intr(void *); 69 70 CFATTACH_DECL_NEW(wdc_amiga, sizeof(struct wdc_amiga_softc), 71 wdc_amiga_probe, wdc_amiga_attach, NULL, NULL); 72 73 int 74 wdc_amiga_probe(device_t parent, cfdata_t cfp, void *aux) 75 { 76 if ((!is_a4000() && !is_a1200() && !is_a600()) || 77 !matchname(aux, "wdc")) 78 return(0); 79 return 1; 80 } 81 82 void 83 wdc_amiga_attach(device_t parent, device_t self, void *aux) 84 { 85 struct wdc_amiga_softc *sc = device_private(self); 86 struct wdc_regs *wdr; 87 int i; 88 89 aprint_normal("\n"); 90 91 sc->sc_wdcdev.sc_atac.atac_dev = self; 92 sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs; 93 94 gayle_init(); 95 96 if (is_a4000()) { 97 sc->cmd_iot.base = (bus_addr_t) ztwomap(GAYLE_IDE_BASE_A4000 + 2); 98 sc->gayle_intr = false; 99 } else { 100 sc->cmd_iot.base = (bus_addr_t) ztwomap(GAYLE_IDE_BASE + 2); 101 sc->gayle_intr = true; 102 } 103 104 sc->cmd_iot.absm = sc->ctl_iot.absm = &amiga_bus_stride_4swap; 105 wdr->cmd_iot = &sc->cmd_iot; 106 wdr->ctl_iot = &sc->ctl_iot; 107 108 if (bus_space_map(wdr->cmd_iot, 0, 0x40, 0, 109 &wdr->cmd_baseioh)) { 110 aprint_error_dev(self, "couldn't map registers\n"); 111 return; 112 } 113 114 for (i = 0; i < WDC_NREG; i++) { 115 if (bus_space_subregion(wdr->cmd_iot, 116 wdr->cmd_baseioh, i, i == 0 ? 4 : 1, 117 &wdr->cmd_iohs[i]) != 0) { 118 119 bus_space_unmap(wdr->cmd_iot, 120 wdr->cmd_baseioh, 0x40); 121 aprint_error_dev(self, "couldn't map registers\n"); 122 return; 123 } 124 } 125 126 if (bus_space_subregion(wdr->cmd_iot, 127 wdr->cmd_baseioh, 0x406, 1, &wdr->ctl_ioh)) 128 return; 129 130 sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16; 131 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0; 132 sc->sc_chanlist[0] = &sc->sc_channel; 133 sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist; 134 sc->sc_wdcdev.sc_atac.atac_nchannels = 1; 135 sc->sc_wdcdev.wdc_maxdrives = 2; 136 sc->sc_channel.ch_channel = 0; 137 sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac; 138 139 wdc_init_shadow_regs(wdr); 140 141 sc->sc_isr.isr_intr = wdc_amiga_intr; 142 sc->sc_isr.isr_arg = sc; 143 sc->sc_isr.isr_ipl = 2; 144 add_isr (&sc->sc_isr); 145 146 if (sc->gayle_intr) 147 gayle_intr_enable_set(GAYLE_INT_IDE); 148 149 wdcattach(&sc->sc_channel); 150 } 151 152 int 153 wdc_amiga_intr(void *arg) 154 { 155 struct wdc_amiga_softc *sc; 156 uint8_t intreq; 157 int ret; 158 159 sc = (struct wdc_amiga_softc *)arg; 160 ret = 0; 161 intreq = gayle_intr_status(); 162 163 if (intreq & GAYLE_INT_IDE) { 164 if (sc->gayle_intr) 165 gayle_intr_ack(0x7C | (intreq & GAYLE_INT_IDEACK)); 166 ret = wdcintr(&sc->sc_channel); 167 } 168 169 return ret; 170 } 171 172