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