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