Home | History | Annotate | Line # | Download | only in dev
wdc_amiga.c revision 1.32
      1 /*	$NetBSD: wdc_amiga.c,v 1.32 2011/01/13 22:02:05 phx Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2000, 2003 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: wdc_amiga.c,v 1.32 2011/01/13 22:02:05 phx Exp $");
     34 
     35 #include <sys/types.h>
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/malloc.h>
     39 #include <sys/device.h>
     40 
     41 #include <machine/cpu.h>
     42 #include <machine/bus.h>
     43 #include <machine/intr.h>
     44 #include <sys/bswap.h>
     45 
     46 #include <amiga/amiga/cia.h>
     47 #include <amiga/amiga/custom.h>
     48 #include <amiga/amiga/device.h>
     49 #include <amiga/amiga/gayle.h>
     50 #include <amiga/dev/zbusvar.h>
     51 
     52 #include <dev/ata/atavar.h>
     53 #include <dev/ic/wdcvar.h>
     54 
     55 struct wdc_amiga_softc {
     56 	struct wdc_softc sc_wdcdev;
     57 	struct	ata_channel *sc_chanlist[1];
     58 	struct  ata_channel sc_channel;
     59 	struct	ata_queue sc_chqueue;
     60 	struct wdc_regs sc_wdc_regs;
     61 	struct isr sc_isr;
     62 	volatile u_char *sc_intreg;
     63 	struct bus_space_tag cmd_iot;
     64 	struct bus_space_tag ctl_iot;
     65 	char	sc_a1200;
     66 };
     67 
     68 int	wdc_amiga_probe(device_t, cfdata_t, void *);
     69 void	wdc_amiga_attach(device_t, device_t, void *);
     70 int	wdc_amiga_intr(void *);
     71 
     72 CFATTACH_DECL_NEW(wdc_amiga, sizeof(struct wdc_amiga_softc),
     73     wdc_amiga_probe, wdc_amiga_attach, NULL, NULL);
     74 
     75 int
     76 wdc_amiga_probe(device_t parent, cfdata_t cfp, void *aux)
     77 {
     78 	if ((!is_a4000() && !is_a1200() && !is_a600()) ||
     79 	    !matchname(aux, "wdc"))
     80 		return(0);
     81 	return 1;
     82 }
     83 
     84 void
     85 wdc_amiga_attach(device_t parent, device_t self, void *aux)
     86 {
     87 	struct wdc_amiga_softc *sc = device_private(self);
     88 	struct wdc_regs *wdr;
     89 	int i;
     90 
     91 	aprint_normal("\n");
     92 
     93 	sc->sc_wdcdev.sc_atac.atac_dev = self;
     94 	sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
     95 
     96 	if (is_a4000()) {
     97 		sc->cmd_iot.base = (u_long)ztwomap(0xdd2020 + 2);
     98 		sc->sc_intreg = (volatile u_char *)ztwomap(0xdd2020 + 0x1000);
     99 		sc->sc_a1200 = 0;
    100 	} else {
    101 		sc->cmd_iot.base = (u_long) ztwomap(0xda0000 + 2);
    102 		gayle_init();
    103 		sc->sc_intreg = &gayle.intreq;
    104 		sc->sc_a1200 = 1;
    105 	}
    106 	sc->cmd_iot.absm = sc->ctl_iot.absm = &amiga_bus_stride_4swap;
    107 	wdr->cmd_iot = &sc->cmd_iot;
    108 	wdr->ctl_iot = &sc->ctl_iot;
    109 
    110 	if (bus_space_map(wdr->cmd_iot, 0, 0x40, 0,
    111 			  &wdr->cmd_baseioh)) {
    112 		aprint_error_dev(self, "couldn't map registers\n");
    113 		return;
    114 	}
    115 
    116 	for (i = 0; i < WDC_NREG; i++) {
    117 		if (bus_space_subregion(wdr->cmd_iot,
    118 		    wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
    119 		    &wdr->cmd_iohs[i]) != 0) {
    120 
    121 			bus_space_unmap(wdr->cmd_iot,
    122 			    wdr->cmd_baseioh, 0x40);
    123 			aprint_error_dev(self, "couldn't map registers\n");
    124 			return;
    125 		}
    126 	}
    127 
    128 	if (bus_space_subregion(wdr->cmd_iot,
    129 	    wdr->cmd_baseioh, 0x406, 1, &wdr->ctl_ioh))
    130 		return;
    131 
    132 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
    133 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    134 	sc->sc_chanlist[0] = &sc->sc_channel;
    135 	sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
    136 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    137 	sc->sc_channel.ch_channel = 0;
    138 	sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    139 	sc->sc_channel.ch_queue = &sc->sc_chqueue;
    140 	sc->sc_channel.ch_ndrive = 2;
    141 
    142 	wdc_init_shadow_regs(&sc->sc_channel);
    143 
    144 	sc->sc_isr.isr_intr = wdc_amiga_intr;
    145 	sc->sc_isr.isr_arg = sc;
    146 	sc->sc_isr.isr_ipl = 2;
    147 	add_isr (&sc->sc_isr);
    148 
    149 	if (sc->sc_a1200)
    150 		gayle.intena |= GAYLE_INT_IDE;
    151 
    152 	wdcattach(&sc->sc_channel);
    153 }
    154 
    155 int
    156 wdc_amiga_intr(void *arg)
    157 {
    158 	struct wdc_amiga_softc *sc = (struct wdc_amiga_softc *)arg;
    159 	u_char intreq = *sc->sc_intreg;
    160 	int ret = 0;
    161 
    162 	if (intreq & GAYLE_INT_IDE) {
    163 		if (sc->sc_a1200)
    164 			gayle.intreq = 0x7c | (intreq & 0x03);
    165 		ret = wdcintr(&sc->sc_channel);
    166 	}
    167 
    168 	return ret;
    169 }
    170