Home | History | Annotate | Line # | Download | only in dev
wdc_buddha.c revision 1.2.30.1
      1  1.2.30.1  mjf /*	$NetBSD: wdc_buddha.c,v 1.2.30.1 2008/04/03 12:42:11 mjf Exp $	*/
      2       1.1   is 
      3       1.1   is /*-
      4       1.1   is  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5       1.1   is  * All rights reserved.
      6       1.1   is  *
      7       1.1   is  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1   is  * by Michael L. Hitch and Ignatios Souvatzis.
      9       1.1   is  *
     10       1.1   is  * Redistribution and use in source and binary forms, with or without
     11       1.1   is  * modification, are permitted provided that the following conditions
     12       1.1   is  * are met:
     13       1.1   is  * 1. Redistributions of source code must retain the above copyright
     14       1.1   is  *    notice, this list of conditions and the following disclaimer.
     15       1.1   is  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   is  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   is  *    documentation and/or other materials provided with the distribution.
     18       1.1   is  * 3. All advertising materials mentioning features or use of this software
     19       1.1   is  *    must display the following acknowledgement:
     20       1.1   is  *        This product includes software developed by the NetBSD
     21       1.1   is  *        Foundation, Inc. and its contributors.
     22       1.1   is  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1   is  *    contributors may be used to endorse or promote products derived
     24       1.1   is  *    from this software without specific prior written permission.
     25       1.1   is  *
     26       1.1   is  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1   is  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1   is  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1   is  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1   is  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1   is  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1   is  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1   is  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1   is  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1   is  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1   is  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1   is  */
     38       1.1   is 
     39       1.1   is #include <sys/types.h>
     40       1.1   is #include <sys/param.h>
     41       1.1   is #include <sys/systm.h>
     42       1.1   is #include <sys/malloc.h>
     43       1.1   is #include <sys/device.h>
     44       1.1   is 
     45       1.1   is #include <machine/cpu.h>
     46       1.1   is #include <machine/bus.h>
     47       1.1   is #include <machine/intr.h>
     48       1.1   is #include <machine/bswap.h>
     49       1.1   is 
     50       1.1   is #include <amiga/amiga/cia.h>
     51       1.1   is #include <amiga/amiga/custom.h>
     52       1.1   is #include <amiga/amiga/device.h>
     53       1.1   is #include <amiga/dev/zbusvar.h>
     54       1.1   is 
     55       1.1   is #include <dev/ata/atavar.h>
     56       1.1   is #include <dev/ic/wdcvar.h>
     57       1.1   is 
     58       1.1   is #define BUDDHA_MAX_CHANNELS 3
     59       1.1   is 
     60       1.1   is struct wdc_buddha_softc {
     61       1.1   is 	struct wdc_softc sc_wdcdev;
     62       1.1   is 	struct ata_channel *wdc_chanarray[BUDDHA_MAX_CHANNELS];
     63       1.1   is 	struct ata_channel channels[BUDDHA_MAX_CHANNELS];
     64       1.1   is 	struct bus_space_tag sc_iot;
     65       1.1   is 	struct isr sc_isr;
     66       1.1   is 	volatile char *ba;
     67       1.1   is };
     68       1.1   is 
     69  1.2.30.1  mjf int	wdc_buddha_probe(device_t, cfdata_t, void *);
     70  1.2.30.1  mjf void	wdc_buddha_attach(device_t, device_t, void *);
     71       1.1   is int	wdc_buddha_intr(void *);
     72       1.1   is 
     73  1.2.30.1  mjf CFATTACH_DECL_NEW(wdc_buddha, sizeof(struct wdc_buddha_softc),
     74       1.1   is     wdc_buddha_probe, wdc_buddha_attach, NULL, NULL);
     75       1.1   is 
     76       1.1   is int
     77  1.2.30.1  mjf wdc_buddha_probe(device_t parent, cfdata_t cfp, void *aux)
     78       1.1   is {
     79       1.1   is 	struct zbus_args *zap;
     80       1.1   is 
     81       1.1   is 	zap = aux;
     82       1.1   is 
     83       1.1   is 	if (zap->manid != 4626)
     84       1.1   is 		return 0;
     85       1.1   is 
     86       1.1   is 	if ((zap->prodid != 0) &&	/* Buddha */
     87       1.1   is 	    (zap->prodid != 42))	/* Catweasel */
     88       1.1   is 		return 0;
     89       1.1   is 
     90       1.1   is 	return 1;
     91       1.1   is }
     92       1.1   is 
     93       1.1   is void
     94  1.2.30.1  mjf wdc_buddha_attach(device_t parent, device_t self, void *aux)
     95       1.1   is {
     96       1.1   is 	struct wdc_buddha_softc *sc;
     97       1.1   is 	struct zbus_args *zap;
     98       1.1   is 	int nchannels;
     99       1.1   is 	int ch;
    100       1.1   is 
    101  1.2.30.1  mjf 	sc = device_private(self);
    102  1.2.30.1  mjf 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    103       1.1   is 	zap = aux;
    104       1.1   is 
    105       1.1   is 	sc->ba = zap->va;
    106       1.1   is 
    107       1.1   is 	sc->sc_iot.base = (bus_addr_t)sc->ba;
    108       1.1   is 	sc->sc_iot.absm = &amiga_bus_stride_4swap;
    109       1.1   is 
    110       1.1   is 	nchannels = 2;
    111       1.1   is 	if (zap->prodid == 42) {
    112  1.2.30.1  mjf 		aprint_normal(": Catweasel Z2\n");
    113       1.1   is 		nchannels = 3;
    114       1.1   is 	} else if (zap->serno == 0)
    115  1.2.30.1  mjf 		aprint_normal(": Buddha\n");
    116       1.1   is 	else
    117  1.2.30.1  mjf 		aprint_normal(": Buddha Flash\n");
    118       1.1   is 
    119       1.1   is 	/* XXX pio mode setting not implemented yet. */
    120       1.2   is 	sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
    121       1.2   is 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    122       1.2   is 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
    123       1.2   is 	sc->sc_wdcdev.sc_atac.atac_nchannels = nchannels;
    124       1.2   is 
    125       1.2   is 	wdc_allocate_regs(&sc->sc_wdcdev);
    126       1.2   is 
    127       1.2   is 	for (ch = 0; ch < nchannels; ch++) {
    128       1.2   is 		struct ata_channel *cp;
    129       1.2   is 		struct wdc_regs *wdr;
    130       1.2   is 		int i;
    131       1.2   is 
    132       1.2   is 		cp = &sc->channels[ch];
    133       1.2   is 		sc->wdc_chanarray[ch] = cp;
    134       1.2   is 
    135       1.2   is 		cp->ch_channel = ch;
    136       1.2   is 		cp->ch_atac = &sc->sc_wdcdev.sc_atac;
    137       1.2   is 		cp->ch_queue =
    138       1.2   is 		    malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
    139       1.2   is 		if (cp->ch_queue == NULL) {
    140  1.2.30.1  mjf 			aprint_error_dev(self,
    141  1.2.30.1  mjf 			    "can't allocate memory for command queue\n");
    142       1.2   is 			return;
    143       1.2   is 		}
    144       1.2   is 		cp->ch_ndrive = 2;
    145       1.1   is 
    146       1.1   is 		/*
    147       1.1   is 		 * XXX According to the Buddha docs, we should use a method
    148       1.1   is 		 * array that adds 0x40 to the address for byte accesses, to
    149       1.1   is 		 * get the slow timing for command accesses, and the 0x00
    150       1.1   is 		 * offset for the word (fast) accesses. This will be
    151       1.1   is 		 * reconsidered when implementing setting the timing.
    152       1.1   is 		 *
    153       1.1   is 		 * XXX We also could consider to abuse the 32bit capability, or
    154       1.1   is 		 * 32bit accesses to the words (which will read in two words)
    155       1.1   is 		 * for better performance.
    156       1.1   is 		 *		-is
    157       1.1   is 		 */
    158       1.2   is 		wdr = CHAN_TO_WDC_REGS(cp);
    159       1.1   is 
    160       1.1   is 		wdr->cmd_iot = &sc->sc_iot;
    161       1.1   is 		if (bus_space_map(wdr->cmd_iot, 0x210+ch*0x80, 8, 0,
    162       1.1   is 		    &wdr->cmd_baseioh)) {
    163  1.2.30.1  mjf 			aprint_error_dev(self, "couldn't map cmd registers\n");
    164       1.1   is 			return;
    165       1.1   is 		}
    166       1.1   is 
    167       1.1   is 		wdr->ctl_iot = &sc->sc_iot;
    168       1.1   is 		if (bus_space_map(wdr->ctl_iot, 0x250+ch*0x80, 2, 0,
    169       1.1   is 		    &wdr->ctl_ioh)) {
    170       1.2   is 			bus_space_unmap(wdr->cmd_iot, wdr->cmd_baseioh, 8);
    171  1.2.30.1  mjf 			aprint_error_dev(self, "couldn't map ctl registers\n");
    172       1.1   is 			return;
    173       1.1   is 		}
    174       1.1   is 
    175       1.1   is 		for (i = 0; i < WDC_NREG; i++) {
    176       1.2   is 			if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
    177       1.2   is 			    i, i == 0 ? 4 : 1, &wdr->cmd_iohs[i]) != 0) {
    178  1.2.30.1  mjf 				aprint_error_dev(self,
    179  1.2.30.1  mjf 				    "couldn't subregion cmd regs\n");
    180       1.2   is 				return;
    181       1.2   is 			}
    182       1.2   is 		}
    183       1.1   is 
    184       1.2   is 		wdc_init_shadow_regs(cp);
    185       1.1   is 		wdcattach(cp);
    186       1.1   is 	}
    187       1.1   is 
    188       1.1   is 	sc->sc_isr.isr_intr = wdc_buddha_intr;
    189       1.1   is 	sc->sc_isr.isr_arg = sc;
    190       1.1   is 	sc->sc_isr.isr_ipl = 2;
    191       1.1   is 	add_isr (&sc->sc_isr);
    192       1.1   is 	sc->ba[0xfc0] = 0;	/* enable interrupts */
    193       1.1   is }
    194       1.1   is 
    195       1.1   is int
    196       1.1   is wdc_buddha_intr(void *arg)
    197       1.1   is {
    198       1.1   is 	struct wdc_buddha_softc *sc = (struct wdc_buddha_softc *)arg;
    199       1.1   is 	int nchannels, i, ret;
    200       1.1   is 	volatile char *p;
    201       1.1   is 
    202       1.1   is 	ret = 0;
    203       1.1   is 	nchannels = sc->sc_wdcdev.sc_atac.atac_nchannels;
    204       1.1   is 	p = sc->ba;
    205       1.1   is 
    206       1.1   is 	for (i=0; i<nchannels; i++) {
    207       1.1   is 		if (p[0xf00 + 0x40*i] & 0x80) {
    208       1.1   is 			wdcintr(&sc->channels[i]);
    209       1.1   is 			ret = 1;
    210       1.1   is 		}
    211       1.1   is 	}
    212       1.1   is 
    213       1.1   is 	return ret;
    214       1.1   is }
    215