Home | History | Annotate | Line # | Download | only in dev
wdc_amiga.c revision 1.3
      1 /*	$NetBSD: wdc_amiga.c,v 1.3 2000/02/10 15:51:59 aymeric Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 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  * 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/types.h>
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/malloc.h>
     43 #include <sys/device.h>
     44 
     45 #include <machine/cpu.h>
     46 #include <machine/bus.h>
     47 #include <machine/intr.h>
     48 #include <machine/bswap.h>
     49 
     50 #include <amiga/amiga/cia.h>
     51 #include <amiga/amiga/custom.h>
     52 #include <amiga/amiga/device.h>
     53 #include <amiga/amiga/gayle.h>
     54 #include <amiga/dev/zbusvar.h>
     55 
     56 #include <dev/ata/atavar.h>
     57 #include <dev/ic/wdcvar.h>
     58 
     59 struct wdc_amiga_softc {
     60 	struct wdc_softc sc_wdcdev;
     61 	struct	channel_softc *wdc_chanptr;
     62 	struct  channel_softc wdc_channel;
     63 	struct isr sc_isr;
     64 	volatile u_char *sc_intreg;
     65 	struct bus_space_tag iot;
     66 	char	sc_a1200;
     67 };
     68 
     69 int	wdc_amiga_probe	__P((struct device *, struct cfdata *, void *));
     70 void	wdc_amiga_attach	__P((struct device *, struct device *, void *));
     71 int	wdc_amiga_intr	__P((void *));
     72 
     73 struct cfattach wdc_amiga_ca = {
     74 	sizeof(struct wdc_amiga_softc), wdc_amiga_probe, wdc_amiga_attach
     75 };
     76 
     77 int
     78 wdc_amiga_probe(parent, cfp, aux)
     79 	struct device *parent;
     80 	struct cfdata *cfp;
     81 	void *aux;
     82 {
     83 	if ((!is_a4000() && !is_a1200()) || !matchname(aux, "wdc"))
     84 		return(0);
     85 	return 1;
     86 }
     87 
     88 void
     89 wdc_amiga_attach(parent, self, aux)
     90 	struct device *parent, *self;
     91 	void *aux;
     92 {
     93 	struct wdc_amiga_softc *sc = (void *)self;
     94 
     95 	printf("\n");
     96 
     97 	if (is_a4000()) {
     98 		sc->iot.base = (u_long)ztwomap(0xdd2020 + 2);
     99 		sc->sc_intreg = (u_char *)ztwomap(0xdd2020 + 0x1000);
    100 		sc->sc_a1200 = 0;
    101 	} else {
    102 		sc->iot.base = (u_long)ztwomap(0xda0000 + 2);
    103 		sc->sc_a1200 = 1;
    104 		gayle_init();
    105 		sc->sc_intreg = &gayle.intreq;
    106 		gayle.intena |= GAYLE_INT_IDE;
    107 	}
    108 	sc->iot.absm = &amiga_bus_stride_4swap;
    109 	sc->wdc_channel.cmd_iot = sc->wdc_channel.ctl_iot = &sc->iot;
    110 	if (bus_space_map(sc->wdc_channel.cmd_iot, 0, 0x40, 0,
    111 			  &sc->wdc_channel.cmd_ioh)) {
    112 		printf("%s: couldn't map registers\n",
    113 		    sc->sc_wdcdev.sc_dev.dv_xname);
    114 		return;
    115 	}
    116 	if (bus_space_subregion(sc->wdc_channel.cmd_iot,
    117 	    sc->wdc_channel.cmd_ioh, 0x406, 1, &sc->wdc_channel.ctl_ioh))
    118 		return;
    119 
    120 	sc->sc_wdcdev.cap = WDC_CAPABILITY_DATA16;
    121 	sc->sc_wdcdev.PIO_cap = 0;
    122 	sc->wdc_chanptr = &sc->wdc_channel;
    123 	sc->sc_wdcdev.channels = &sc->wdc_chanptr;
    124 	sc->sc_wdcdev.nchannels = 1;
    125 	sc->wdc_channel.channel = 0;
    126 	sc->wdc_channel.wdc = &sc->sc_wdcdev;
    127 	sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
    128 	    M_DEVBUF, M_NOWAIT);
    129 	if (sc->wdc_channel.ch_queue == NULL) {
    130 	    printf("%s: can't allocate memory for command queue",
    131 		sc->sc_wdcdev.sc_dev.dv_xname);
    132 	    return;
    133 	}
    134 	sc->sc_isr.isr_intr = wdc_amiga_intr;
    135 	sc->sc_isr.isr_arg = sc;
    136 	sc->sc_isr.isr_ipl = 2;
    137 	add_isr (&sc->sc_isr);
    138 
    139 	wdcattach(&sc->wdc_channel);
    140 
    141 }
    142 
    143 int
    144 wdc_amiga_intr(arg)
    145 	void *arg;
    146 {
    147 	struct wdc_amiga_softc *sc = (struct wdc_amiga_softc *)arg;
    148 	int ret = 0;
    149 
    150 	if (*sc->sc_intreg & 0x80) {
    151 		ret = wdcintr(&sc->wdc_channel);
    152 		if (sc->sc_a1200)
    153 			*sc->sc_intreg = 0x7c | (*sc->sc_intreg & 0x03);
    154 	}
    155 
    156 	return ret;
    157 }
    158