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