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