Home | History | Annotate | Line # | Download | only in eb7500atx
rside.c revision 1.1
      1  1.1  chris /*	$NetBSD: rside.c,v 1.1 2004/01/03 14:31:28 chris Exp $	*/
      2  1.1  chris 
      3  1.1  chris /*
      4  1.1  chris  * Copyright (c) 1997-1998 Mark Brinicombe
      5  1.1  chris  * Copyright (c) 1997-1998 Causality Limited
      6  1.1  chris  *
      7  1.1  chris  * Redistribution and use in source and binary forms, with or without
      8  1.1  chris  * modification, are permitted provided that the following conditions
      9  1.1  chris  * are met:
     10  1.1  chris  * 1. Redistributions of source code must retain the above copyright
     11  1.1  chris  *    notice, this list of conditions and the following disclaimer.
     12  1.1  chris  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  chris  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  chris  *    documentation and/or other materials provided with the distribution.
     15  1.1  chris  * 3. All advertising materials mentioning features or use of this software
     16  1.1  chris  *    must display the following acknowledgement:
     17  1.1  chris  *	This product includes software developed by Mark Brinicombe
     18  1.1  chris  *	for the NetBSD Project.
     19  1.1  chris  * 4. The name of the author may not be used to endorse or promote products
     20  1.1  chris  *    derived from this software without specific prior written permission.
     21  1.1  chris  *
     22  1.1  chris  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1  chris  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  chris  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  chris  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  chris  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1  chris  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1  chris  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1  chris  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1  chris  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1  chris  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1  chris  */
     33  1.1  chris 
     34  1.1  chris #include <sys/param.h>
     35  1.1  chris #include <sys/systm.h>
     36  1.1  chris #include <sys/conf.h>
     37  1.1  chris #include <sys/device.h>
     38  1.1  chris #include <sys/malloc.h>
     39  1.1  chris 
     40  1.1  chris #include <machine/intr.h>
     41  1.1  chris #include <machine/io.h>
     42  1.1  chris #include <machine/bus.h>
     43  1.1  chris #include <acorn32/eb7500atx/rsidereg.h>
     44  1.1  chris #include <machine/irqhandler.h>
     45  1.1  chris 
     46  1.1  chris #include <dev/ata/atavar.h>
     47  1.1  chris #include <dev/ic/wdcvar.h>
     48  1.1  chris #include <acorn32/eb7500atx/rsbus.h>
     49  1.1  chris 
     50  1.1  chris /*
     51  1.1  chris  * RiscStation IDE device.
     52  1.1  chris  *
     53  1.1  chris  * This probes and attaches the top level IDE device to the rsbus.
     54  1.1  chris  * It then configures any children of the IDE device.
     55  1.1  chris  * The attach args specify whether it is configuring the primary or
     56  1.1  chris  * secondary channel.
     57  1.1  chris  * The children are expected to be wdc devices using rside attachments.
     58  1.1  chris  *
     59  1.1  chris  * The hardware notes are:
     60  1.1  chris  * Two ide ports are fitted, each with registers spaced 0x40 bytes apart
     61  1.1  chris  * with the extra control register at offset 0x380 from the base of the
     62  1.1  chris  * port.
     63  1.1  chris  *
     64  1.1  chris  * Primary:
     65  1.1  chris  * 	Registers at 0x302b800 (nPCCS1 + 0x0)
     66  1.1  chris  * 	IRQ connected to nEvent1 (IRQ register D)
     67  1.1  chris  *
     68  1.1  chris  * Secondary:
     69  1.1  chris  * 	Registers at 0x302bc00 (nPCCS1 + 0x400)
     70  1.1  chris  * 	IRQ connected to nEvent2 (IRQ register D)
     71  1.1  chris  *
     72  1.1  chris  * PIO timings can be changed by modifying the access speed register in the
     73  1.1  chris  * IOMD, as there is nothing else in the nPCCS1 space.
     74  1.1  chris  *
     75  1.1  chris  * The Reset line is asserted by unsetting bit 4 in IO register
     76  1.1  chris  * IOMD + 0x121CC.
     77  1.1  chris  */
     78  1.1  chris 
     79  1.1  chris /*
     80  1.1  chris  * make a private tag so that we can use mainbus's map/unmap
     81  1.1  chris  */
     82  1.1  chris 
     83  1.1  chris static struct bus_space rside_bs_tag;
     84  1.1  chris 
     85  1.1  chris /*
     86  1.1  chris  * RiscStation IDE card softc structure.
     87  1.1  chris  *
     88  1.1  chris  * Contains the device node, podule information and global information
     89  1.1  chris  * required by the driver such as the card version and the interrupt mask.
     90  1.1  chris  */
     91  1.1  chris 
     92  1.1  chris struct rside_softc {
     93  1.1  chris 	struct wdc_softc	sc_wdcdev;	/* common wdc definitions */
     94  1.1  chris 	struct wdc_channel	*wdc_chanarray[2]; /* channels definition */
     95  1.1  chris 	struct rside_channel {
     96  1.1  chris 		struct wdc_channel wdc_channel; /* generic part */
     97  1.1  chris 		struct ata_queue wdc_chqueue; /* channel queue */
     98  1.1  chris 		irqhandler_t *wdc_ih;	/* interrupt handler */
     99  1.1  chris 	} rside_channels[2];
    100  1.1  chris };
    101  1.1  chris 
    102  1.1  chris int	rside_probe	__P((struct device *, struct cfdata *, void *));
    103  1.1  chris void	rside_attach	__P((struct device *, struct device *, void *));
    104  1.1  chris 
    105  1.1  chris CFATTACH_DECL(rside, sizeof(struct rside_softc),
    106  1.1  chris 		rside_probe, rside_attach, NULL, NULL);
    107  1.1  chris 
    108  1.1  chris /*
    109  1.1  chris  * Create an array of address structures. These define the addresses and
    110  1.1  chris  * masks needed for the different channels.
    111  1.1  chris  *
    112  1.1  chris  * index = channel
    113  1.1  chris  */
    114  1.1  chris 
    115  1.1  chris struct {
    116  1.1  chris 	u_int drive_registers;
    117  1.1  chris 	u_int aux_register;
    118  1.1  chris } rside_info[] = {
    119  1.1  chris 	{ PRIMARY_DRIVE_REGISTERS_POFFSET, PRIMARY_AUX_REGISTER_POFFSET,
    120  1.1  chris 	  },
    121  1.1  chris 	{ SECONDARY_DRIVE_REGISTERS_POFFSET, SECONDARY_AUX_REGISTER_POFFSET,
    122  1.1  chris 	   }
    123  1.1  chris };
    124  1.1  chris 
    125  1.1  chris /*
    126  1.1  chris  * Card probe function
    127  1.1  chris  */
    128  1.1  chris 
    129  1.1  chris int
    130  1.1  chris rside_probe(parent, cf, aux)
    131  1.1  chris 	struct device *parent;
    132  1.1  chris 	struct cfdata *cf;
    133  1.1  chris 	void *aux;
    134  1.1  chris {
    135  1.1  chris 	/* if we're including this, then for now assume it exists */
    136  1.1  chris 	return 1;
    137  1.1  chris }
    138  1.1  chris 
    139  1.1  chris /*
    140  1.1  chris  * Card attach function
    141  1.1  chris  *
    142  1.1  chris  * Identify the card version and configure any children.
    143  1.1  chris  */
    144  1.1  chris 
    145  1.1  chris void
    146  1.1  chris rside_attach(parent, self, aux)
    147  1.1  chris 	struct device *parent, *self;
    148  1.1  chris 	void *aux;
    149  1.1  chris {
    150  1.1  chris 	struct rside_softc *sc = (void *)self;
    151  1.1  chris 	struct rsbus_attach_args *rs = (void *)aux;
    152  1.1  chris 	int channel, i;
    153  1.1  chris 	struct rside_channel *scp;
    154  1.1  chris 	struct wdc_channel *cp;
    155  1.1  chris 
    156  1.1  chris 	printf("\n");
    157  1.1  chris 
    158  1.1  chris 	/*
    159  1.1  chris 	 * we need our own bus tag as the register spacing
    160  1.1  chris 	 * is not the default.
    161  1.1  chris 	 *
    162  1.1  chris 	 * For the rsbus the bus tag cookie is the shift
    163  1.1  chris 	 * to apply to registers
    164  1.1  chris 	 * So duplicate the bus space tag and change the
    165  1.1  chris 	 * cookie.
    166  1.1  chris 	 */
    167  1.1  chris 
    168  1.1  chris 	rside_bs_tag = *rs->sa_iot;
    169  1.1  chris 	rside_bs_tag.bs_cookie = (void *) DRIVE_REGISTER_SPACING_SHIFT;
    170  1.1  chris 
    171  1.1  chris 	/* Fill in wdc and channel infos */
    172  1.1  chris 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
    173  1.1  chris 	sc->sc_wdcdev.PIO_cap = 0;
    174  1.1  chris 	sc->sc_wdcdev.DMA_cap = 0;
    175  1.1  chris 	sc->sc_wdcdev.UDMA_cap = 0;
    176  1.1  chris 	sc->sc_wdcdev.channels = sc->wdc_chanarray;
    177  1.1  chris 	sc->sc_wdcdev.nchannels = 2;
    178  1.1  chris 	for (channel = 0 ; channel < 2; channel++) {
    179  1.1  chris 		scp = &sc->rside_channels[channel];
    180  1.1  chris 		sc->wdc_chanarray[channel] = &scp->wdc_channel;
    181  1.1  chris 		cp = &scp->wdc_channel;
    182  1.1  chris 
    183  1.1  chris 		cp->channel = channel;
    184  1.1  chris 		cp->wdc = &sc->sc_wdcdev;
    185  1.1  chris 		cp->ch_queue = &scp->wdc_chqueue;
    186  1.1  chris 		cp->cmd_iot = cp->ctl_iot = &rside_bs_tag;
    187  1.1  chris 		if (bus_space_map(cp->cmd_iot,
    188  1.1  chris 		    rside_info[channel].drive_registers,
    189  1.1  chris 		    DRIVE_REGISTERS_SPACE, 0, &cp->cmd_baseioh))
    190  1.1  chris 			panic("couldn't map drive registers channel = %d,"
    191  1.1  chris 					"registers@0x08%x\n",
    192  1.1  chris 					channel, rside_info[channel].drive_registers);
    193  1.1  chris 
    194  1.1  chris 		for (i = 0; i < WDC_NREG; i++) {
    195  1.1  chris 			if (bus_space_subregion(cp->cmd_iot, cp->cmd_baseioh,
    196  1.1  chris 				i * (DRIVE_REGISTER_BYTE_SPACING >> 2), 4,
    197  1.1  chris 				&cp->cmd_iohs[i]) != 0) {
    198  1.1  chris 				bus_space_unmap(cp->cmd_iot, cp->cmd_baseioh,
    199  1.1  chris 				    DRIVE_REGISTERS_SPACE);
    200  1.1  chris 				continue;
    201  1.1  chris 			}
    202  1.1  chris 		}
    203  1.1  chris 
    204  1.1  chris 		if (bus_space_map(cp->ctl_iot,
    205  1.1  chris 		    rside_info[channel].aux_register, 0x4, 0, &cp->ctl_ioh))
    206  1.1  chris 		{
    207  1.1  chris 			bus_space_unmap(cp->cmd_iot, cp->cmd_baseioh,
    208  1.1  chris 			    DRIVE_REGISTERS_SPACE);
    209  1.1  chris 			continue;
    210  1.1  chris 		}
    211  1.1  chris 
    212  1.1  chris 
    213  1.1  chris 		/* attach it to the interrupt */
    214  1.1  chris 		if ((scp->wdc_ih = intr_claim((channel == 0 ? IRQ_NEVENT1 : IRQ_NEVENT2), IPL_BIO,
    215  1.1  chris 			    "rside", wdcintr, cp)) == NULL)
    216  1.1  chris 			panic("%s: Cannot claim interrupt %d\n",
    217  1.1  chris 			    self->dv_xname, (channel == 0 ? IRQ_NEVENT1 : IRQ_NEVENT2));
    218  1.1  chris 
    219  1.1  chris 		wdcattach(cp);
    220  1.1  chris 	}
    221  1.1  chris }
    222