Home | History | Annotate | Line # | Download | only in dev
wdc_amiga.c revision 1.10.6.1
      1  1.10.6.1    skrll /*	$NetBSD: wdc_amiga.c,v 1.10.6.1 2004/08/03 10:31:54 skrll Exp $ */
      2       1.1   mhitch 
      3       1.1   mhitch /*-
      4  1.10.6.1    skrll  * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.
      5       1.1   mhitch  * All rights reserved.
      6       1.1   mhitch  *
      7       1.1   mhitch  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1   mhitch  * by Michael L. Hitch.
      9       1.1   mhitch  *
     10       1.1   mhitch  * Redistribution and use in source and binary forms, with or without
     11       1.1   mhitch  * modification, are permitted provided that the following conditions
     12       1.1   mhitch  * are met:
     13       1.1   mhitch  * 1. Redistributions of source code must retain the above copyright
     14       1.1   mhitch  *    notice, this list of conditions and the following disclaimer.
     15       1.1   mhitch  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   mhitch  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   mhitch  *    documentation and/or other materials provided with the distribution.
     18       1.1   mhitch  * 3. All advertising materials mentioning features or use of this software
     19       1.1   mhitch  *    must display the following acknowledgement:
     20       1.1   mhitch  *        This product includes software developed by the NetBSD
     21       1.1   mhitch  *        Foundation, Inc. and its contributors.
     22       1.1   mhitch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1   mhitch  *    contributors may be used to endorse or promote products derived
     24       1.1   mhitch  *    from this software without specific prior written permission.
     25       1.1   mhitch  *
     26       1.1   mhitch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1   mhitch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1   mhitch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1   mhitch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1   mhitch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1   mhitch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1   mhitch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1   mhitch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1   mhitch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1   mhitch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1   mhitch  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1   mhitch  */
     38       1.8  aymeric 
     39       1.8  aymeric #include <sys/cdefs.h>
     40  1.10.6.1    skrll __KERNEL_RCSID(0, "$NetBSD: wdc_amiga.c,v 1.10.6.1 2004/08/03 10:31:54 skrll Exp $");
     41       1.1   mhitch 
     42       1.1   mhitch #include <sys/types.h>
     43       1.1   mhitch #include <sys/param.h>
     44       1.1   mhitch #include <sys/systm.h>
     45       1.1   mhitch #include <sys/malloc.h>
     46       1.1   mhitch #include <sys/device.h>
     47       1.1   mhitch 
     48       1.1   mhitch #include <machine/cpu.h>
     49       1.1   mhitch #include <machine/bus.h>
     50       1.1   mhitch #include <machine/intr.h>
     51       1.1   mhitch #include <machine/bswap.h>
     52       1.1   mhitch 
     53       1.1   mhitch #include <amiga/amiga/cia.h>
     54       1.1   mhitch #include <amiga/amiga/custom.h>
     55       1.1   mhitch #include <amiga/amiga/device.h>
     56       1.1   mhitch #include <amiga/amiga/gayle.h>
     57       1.1   mhitch #include <amiga/dev/zbusvar.h>
     58       1.1   mhitch 
     59       1.1   mhitch #include <dev/ata/atavar.h>
     60       1.1   mhitch #include <dev/ic/wdcvar.h>
     61       1.1   mhitch 
     62       1.1   mhitch struct wdc_amiga_softc {
     63       1.1   mhitch 	struct wdc_softc sc_wdcdev;
     64  1.10.6.1    skrll 	struct	wdc_channel *wdc_chanlist[1];
     65  1.10.6.1    skrll 	struct  wdc_channel wdc_channel;
     66  1.10.6.1    skrll 	struct	ata_queue wdc_chqueue;
     67       1.1   mhitch 	struct isr sc_isr;
     68       1.1   mhitch 	volatile u_char *sc_intreg;
     69       1.4  aymeric 	struct bus_space_tag cmd_iot;
     70       1.4  aymeric 	struct bus_space_tag ctl_iot;
     71       1.1   mhitch 	char	sc_a1200;
     72       1.1   mhitch };
     73       1.1   mhitch 
     74       1.7  aymeric int	wdc_amiga_probe(struct device *, struct cfdata *, void *);
     75       1.7  aymeric void	wdc_amiga_attach(struct device *, struct device *, void *);
     76       1.7  aymeric int	wdc_amiga_intr(void *);
     77       1.1   mhitch 
     78      1.10  thorpej CFATTACH_DECL(wdc_amiga, sizeof(struct wdc_amiga_softc),
     79      1.10  thorpej     wdc_amiga_probe, wdc_amiga_attach, NULL, NULL);
     80       1.1   mhitch 
     81       1.1   mhitch int
     82       1.7  aymeric wdc_amiga_probe(struct device *parent, struct cfdata *cfp, void *aux)
     83       1.1   mhitch {
     84       1.2  aymeric 	if ((!is_a4000() && !is_a1200()) || !matchname(aux, "wdc"))
     85       1.1   mhitch 		return(0);
     86       1.1   mhitch 	return 1;
     87       1.1   mhitch }
     88       1.1   mhitch 
     89       1.1   mhitch void
     90       1.7  aymeric wdc_amiga_attach(struct device *parent, struct device *self, void *aux)
     91       1.1   mhitch {
     92       1.1   mhitch 	struct wdc_amiga_softc *sc = (void *)self;
     93  1.10.6.1    skrll 	int i;
     94       1.1   mhitch 
     95       1.1   mhitch 	printf("\n");
     96       1.1   mhitch 
     97       1.1   mhitch 	if (is_a4000()) {
     98       1.4  aymeric 		sc->cmd_iot.base = (u_long)ztwomap(0xdd2020 + 2);
     99       1.1   mhitch 		sc->sc_intreg = (u_char *)ztwomap(0xdd2020 + 0x1000);
    100       1.3  aymeric 		sc->sc_a1200 = 0;
    101       1.1   mhitch 	} else {
    102       1.4  aymeric 		sc->cmd_iot.base = (u_long) ztwomap(0xda0000 + 2);
    103       1.4  aymeric 		sc->ctl_iot.base = (u_long) ztwomap(0xda4000);
    104       1.2  aymeric 		gayle_init();
    105       1.1   mhitch 		sc->sc_intreg = &gayle.intreq;
    106       1.4  aymeric 		sc->sc_a1200 = 1;
    107       1.1   mhitch 	}
    108       1.4  aymeric 	sc->cmd_iot.absm = sc->ctl_iot.absm = &amiga_bus_stride_4swap;
    109       1.4  aymeric 	sc->wdc_channel.cmd_iot = &sc->cmd_iot;
    110       1.4  aymeric 	sc->wdc_channel.ctl_iot = &sc->ctl_iot;
    111       1.4  aymeric 
    112       1.1   mhitch 	if (bus_space_map(sc->wdc_channel.cmd_iot, 0, 0x40, 0,
    113  1.10.6.1    skrll 			  &sc->wdc_channel.cmd_baseioh)) {
    114       1.1   mhitch 		printf("%s: couldn't map registers\n",
    115       1.1   mhitch 		    sc->sc_wdcdev.sc_dev.dv_xname);
    116       1.1   mhitch 		return;
    117       1.1   mhitch 	}
    118       1.4  aymeric 
    119  1.10.6.1    skrll 	for (i = 0; i < WDC_NREG; i++) {
    120  1.10.6.1    skrll 		if (bus_space_subregion(sc->wdc_channel.cmd_iot,
    121  1.10.6.1    skrll 		    sc->wdc_channel.cmd_baseioh, i, i == 0 ? 4 : 1,
    122  1.10.6.1    skrll 		    &sc->wdc_channel.cmd_iohs[i]) != 0) {
    123  1.10.6.1    skrll 
    124  1.10.6.1    skrll 			bus_space_unmap(sc->wdc_channel.cmd_iot,
    125  1.10.6.1    skrll 			    sc->wdc_channel.cmd_baseioh, 0x40);
    126  1.10.6.1    skrll 			printf("%s: couldn't map registers\n",
    127  1.10.6.1    skrll 			    sc->sc_wdcdev.sc_dev.dv_xname);
    128  1.10.6.1    skrll 			return;
    129  1.10.6.1    skrll 		}
    130  1.10.6.1    skrll 	}
    131  1.10.6.1    skrll 	wdc_init_shadow_regs(&sc->wdc_channel);
    132  1.10.6.1    skrll 
    133       1.6     tron 	if (sc->sc_a1200)
    134       1.4  aymeric 		sc->wdc_channel.ctl_ioh = sc->ctl_iot.base;
    135       1.4  aymeric 	else if (bus_space_subregion(sc->wdc_channel.cmd_iot,
    136  1.10.6.1    skrll 	    sc->wdc_channel.cmd_baseioh, 0x406, 1, &sc->wdc_channel.ctl_ioh))
    137       1.1   mhitch 		return;
    138       1.1   mhitch 
    139       1.3  aymeric 	sc->sc_wdcdev.cap = WDC_CAPABILITY_DATA16;
    140       1.1   mhitch 	sc->sc_wdcdev.PIO_cap = 0;
    141  1.10.6.1    skrll 	sc->wdc_chanlist[0] = &sc->wdc_channel;
    142  1.10.6.1    skrll 	sc->sc_wdcdev.channels = sc->wdc_chanlist;
    143       1.1   mhitch 	sc->sc_wdcdev.nchannels = 1;
    144  1.10.6.1    skrll 	sc->wdc_channel.ch_channel = 0;
    145  1.10.6.1    skrll 	sc->wdc_channel.ch_wdc = &sc->sc_wdcdev;
    146  1.10.6.1    skrll 	sc->wdc_channel.ch_queue = &sc->wdc_chqueue;
    147       1.1   mhitch 	sc->sc_isr.isr_intr = wdc_amiga_intr;
    148       1.1   mhitch 	sc->sc_isr.isr_arg = sc;
    149       1.1   mhitch 	sc->sc_isr.isr_ipl = 2;
    150       1.1   mhitch 	add_isr (&sc->sc_isr);
    151       1.1   mhitch 
    152       1.6     tron 	if (sc->sc_a1200)
    153       1.5  aymeric 		gayle.intena |= GAYLE_INT_IDE;
    154       1.4  aymeric 
    155       1.1   mhitch 	wdcattach(&sc->wdc_channel);
    156       1.1   mhitch }
    157       1.1   mhitch 
    158       1.1   mhitch int
    159       1.7  aymeric wdc_amiga_intr(void *arg)
    160       1.1   mhitch {
    161       1.1   mhitch 	struct wdc_amiga_softc *sc = (struct wdc_amiga_softc *)arg;
    162       1.4  aymeric 	u_char intreq = *sc->sc_intreg;
    163       1.3  aymeric 	int ret = 0;
    164       1.1   mhitch 
    165       1.4  aymeric 	if (intreq & GAYLE_INT_IDE) {
    166       1.4  aymeric 		if (sc->sc_a1200)
    167       1.4  aymeric 			gayle.intreq = 0x7c | (intreq & 0x03);
    168       1.3  aymeric 		ret = wdcintr(&sc->wdc_channel);
    169       1.3  aymeric 	}
    170       1.3  aymeric 
    171       1.3  aymeric 	return ret;
    172       1.1   mhitch }
    173