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