1 /* $NetBSD: wdc_obio.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */ 2 3 /*- 4 * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum and by Onno van der Linden. 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 39 #include <sys/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.1 2006/09/01 21:26:18 uwe Exp $"); 41 42 #include <sys/types.h> 43 #include <sys/param.h> 44 #include <sys/systm.h> 45 #include <sys/device.h> 46 #include <sys/malloc.h> 47 48 #include <machine/bus.h> 49 #include <machine/intr.h> 50 51 #include <dev/ata/atavar.h> 52 #include <dev/ic/wdcvar.h> 53 54 #include <landisk/dev/obiovar.h> 55 56 struct wdc_obio_softc { 57 struct wdc_softc sc_wdcdev; 58 struct ata_channel *sc_chanlist[1]; 59 struct ata_channel sc_channel; 60 struct ata_queue sc_chqueue; 61 struct wdc_regs sc_wdc_regs; 62 void *sc_ih; 63 }; 64 65 static int wdc_obio_probe(struct device *, struct cfdata *, void *); 66 static void wdc_obio_attach(struct device *, struct device *, void *); 67 68 CFATTACH_DECL(wdc_obio, sizeof(struct wdc_obio_softc), 69 wdc_obio_probe, wdc_obio_attach, NULL, NULL); 70 71 #define WDC_OBIO_REG_NPORTS WDC_NREG 72 #define WDC_OBIO_REG_SIZE (WDC_OBIO_REG_NPORTS * 2) 73 #define WDC_OBIO_AUXREG_NPORTS 1 74 #define WDC_OBIO_AUXREG_SIZE (WDC_OBIO_AUXREG_NPORTS * 2) 75 #define WDC_OBIO_AUXREG_OFFSET 0x2c 76 77 static int 78 wdc_obio_probe(struct device *parent, struct cfdata *cfp, void *aux) 79 { 80 struct obio_attach_args *oa = aux; 81 struct ata_channel ch; 82 struct wdc_softc wdc; 83 struct wdc_regs wdr; 84 int result = 0; 85 int i; 86 87 if (oa->oa_nio < 1) 88 return (0); 89 if (oa->oa_nirq < 1) 90 return (0); 91 92 if (oa->oa_io[0].or_addr == IOBASEUNK) 93 return (0); 94 if (oa->oa_irq[0].or_irq == IRQUNK) 95 return (0); 96 97 memset(&wdc, 0, sizeof(wdc)); 98 memset(&ch, 0, sizeof(ch)); 99 ch.ch_atac = &wdc.sc_atac; 100 wdc.regs = &wdr; 101 102 wdr.cmd_iot = oa->oa_iot; 103 if (bus_space_map(wdr.cmd_iot, oa->oa_io[0].or_addr, 104 WDC_OBIO_REG_SIZE, 0, &wdr.cmd_baseioh)) { 105 goto out; 106 } 107 for (i = 0; i < WDC_OBIO_REG_NPORTS; i++) { 108 if (bus_space_subregion(wdr.cmd_iot, wdr.cmd_baseioh, 109 i * 2, (i == 0) ? 2 : 1, &wdr.cmd_iohs[i])) { 110 goto outunmap; 111 } 112 } 113 wdc_init_shadow_regs(&ch); 114 115 wdr.ctl_iot = oa->oa_iot; 116 if (bus_space_map(wdr.ctl_iot, 117 oa->oa_io[0].or_addr + WDC_OBIO_AUXREG_OFFSET, 118 WDC_OBIO_AUXREG_SIZE, 0, &wdr.ctl_ioh)) { 119 goto outunmap; 120 } 121 122 result = wdcprobe(&ch); 123 if (result) { 124 oa->oa_nio = 1; 125 oa->oa_io[0].or_size = WDC_OBIO_REG_SIZE; 126 oa->oa_nirq = 1; 127 oa->oa_niomem = 0; 128 } 129 130 bus_space_unmap(wdr.ctl_iot, wdr.ctl_ioh, WDC_OBIO_AUXREG_SIZE); 131 outunmap: 132 bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh, WDC_OBIO_REG_SIZE); 133 out: 134 return (result); 135 } 136 137 static void 138 wdc_obio_attach(struct device *parent, struct device *self, void *aux) 139 { 140 struct wdc_obio_softc *sc = (void *)self; 141 struct obio_attach_args *oa = aux; 142 struct wdc_regs *wdr; 143 int i; 144 145 printf("\n"); 146 147 sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs; 148 149 wdr->cmd_iot = oa->oa_iot; 150 wdr->ctl_iot = oa->oa_iot; 151 if (bus_space_map(wdr->cmd_iot, oa->oa_io[0].or_addr, 152 WDC_OBIO_REG_SIZE, 0, &wdr->cmd_baseioh) 153 || bus_space_map(wdr->ctl_iot, 154 oa->oa_io[0].or_addr + WDC_OBIO_AUXREG_OFFSET, 155 WDC_OBIO_AUXREG_SIZE, 0, &wdr->ctl_ioh)) { 156 printf(": couldn't map registers\n"); 157 return; 158 } 159 160 for (i = 0; i < WDC_OBIO_REG_NPORTS; i++) { 161 if (bus_space_subregion(wdr->cmd_iot, 162 wdr->cmd_baseioh, i * 2, (i == 0) ? 2 : 1, 163 &wdr->cmd_iohs[i]) != 0) { 164 printf(": couldn't subregion registers\n"); 165 return; 166 } 167 } 168 169 sc->sc_ih = obio_intr_establish(oa->oa_irq[0].or_irq, IPL_BIO, wdcintr, 170 &sc->sc_channel); 171 172 sc->sc_wdcdev.cap |= WDC_CAPABILITY_PREATA; 173 sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16; 174 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0; 175 sc->sc_chanlist[0] = &sc->sc_channel; 176 sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist; 177 sc->sc_wdcdev.sc_atac.atac_nchannels = 1; 178 sc->sc_channel.ch_channel = 0; 179 sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac; 180 sc->sc_channel.ch_queue = &sc->sc_chqueue; 181 sc->sc_channel.ch_ndrive = 2; 182 183 wdc_init_shadow_regs(&sc->sc_channel); 184 185 wdcattach(&sc->sc_channel); 186 } 187