Home | History | Annotate | Line # | Download | only in mainbus
wdc_pioc.c revision 1.28.28.2
      1 /*	$NetBSD: wdc_pioc.c,v 1.28.28.2 2017/09/27 07:19:33 jdolecek Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997-1998 Mark Brinicombe.
      5  * Copyright (c) 1997 Causality Limited.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Mark Brinicombe
     18  *	for the NetBSD Project.
     19  * 4. The name of the company nor the name of the author may be used to
     20  *    endorse or promote products derived from this software without specific
     21  *    prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     24  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     27  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 __KERNEL_RCSID(0, "$NetBSD: wdc_pioc.c,v 1.28.28.2 2017/09/27 07:19:33 jdolecek Exp $");
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/device.h>
     42 #include <sys/malloc.h>
     43 #include <sys/bus.h>
     44 
     45 #include <machine/intr.h>
     46 
     47 #include <acorn32/mainbus/piocvar.h>
     48 
     49 #include <dev/ata/atavar.h>
     50 #include <dev/ic/wdcreg.h>
     51 #include <dev/ic/wdcvar.h>
     52 
     53 #include "locators.h"
     54 
     55 #define WDC_PIOC_REG_NPORTS	8
     56 #define WDC_PIOC_AUXREG_OFFSET	(0x206 * 4)
     57 #define WDC_PIOC_AUXREG_NPORTS	1
     58 
     59 struct wdc_pioc_softc {
     60 	struct	wdc_softc sc_wdcdev;
     61 	struct	ata_channel *sc_chanlist[1];
     62 	struct	ata_channel sc_channel;
     63 	struct	wdc_regs sc_wdc_regs;
     64 	void	*sc_ih;
     65 };
     66 
     67 /* prototypes for functions */
     68 static int  wdc_pioc_probe  (device_t, cfdata_t, void *);
     69 static void wdc_pioc_attach (device_t, device_t, void *);
     70 
     71 /* device attach structure */
     72 CFATTACH_DECL_NEW(wdc_pioc, sizeof(struct wdc_pioc_softc),
     73     wdc_pioc_probe, wdc_pioc_attach, NULL, NULL);
     74 
     75 /*
     76  * int wdc_pioc_probe(device_t parent, cfdata_t cf, void *aux)
     77  *
     78  * Make sure we are trying to attach a wdc device and then
     79  * probe for one.
     80  */
     81 
     82 static int
     83 wdc_pioc_probe(device_t parent, cfdata_t cf, void *aux)
     84 {
     85 	struct pioc_attach_args *pa = aux;
     86 	struct wdc_regs wdr;
     87 	int res, i;
     88 	u_int iobase;
     89 
     90 	if (pa->pa_name && strcmp(pa->pa_name, "wdc") != 0)
     91 		return(0);
     92 
     93 	/* We need an offset */
     94 	if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
     95 		return(0);
     96 
     97 	iobase = pa->pa_iobase + pa->pa_offset;
     98 	wdr.cmd_iot = pa->pa_iot;
     99 	wdr.ctl_iot = pa->pa_iot;
    100 
    101 	if (bus_space_map(wdr.cmd_iot, iobase, WDC_PIOC_REG_NPORTS, 0,
    102 	    &wdr.cmd_baseioh))
    103 		return(0);
    104 	for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
    105 		if (bus_space_subregion(wdr.cmd_iot, wdr.cmd_baseioh, i,
    106 			i == 0 ? 4 : 1, &wdr.cmd_iohs[i]) != 0) {
    107 			bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh,
    108 			    WDC_PIOC_REG_NPORTS);
    109 			return 0;
    110 		}
    111 	}
    112 	wdc_init_shadow_regs(&wdr);
    113 
    114 	if (bus_space_map(wdr.ctl_iot, iobase + WDC_PIOC_AUXREG_OFFSET,
    115 	    WDC_PIOC_AUXREG_NPORTS, 0, &wdr.ctl_ioh)) {
    116 		bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh,
    117 		    WDC_PIOC_REG_NPORTS);
    118 		return(0);
    119 	}
    120 
    121 	res = wdcprobe(&wdr);
    122 
    123 	bus_space_unmap(wdr.ctl_iot, wdr.ctl_ioh, WDC_PIOC_AUXREG_NPORTS);
    124 	bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh, WDC_PIOC_REG_NPORTS);
    125 
    126 	if (res)
    127 		 pa->pa_iosize = WDC_PIOC_REG_NPORTS;
    128 	return(res);
    129 }
    130 
    131 /*
    132  * void wdc_pioc_attach(device_t parent, device_t self, void *aux)
    133  *
    134  * attach the wdc device
    135  */
    136 
    137 static void
    138 wdc_pioc_attach(device_t parent, device_t self, void *aux)
    139 {
    140 	struct wdc_pioc_softc *sc = device_private(self);
    141 	struct wdc_regs *wdr;
    142 	struct pioc_attach_args *pa = aux;
    143 	u_int iobase;
    144 	int i;
    145 
    146 	aprint_normal("\n");
    147 
    148 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    149 	sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
    150 	iobase = pa->pa_iobase + pa->pa_offset;
    151 	wdr->cmd_iot = pa->pa_iot;
    152 	wdr->ctl_iot = pa->pa_iot;
    153 	if (bus_space_map(wdr->cmd_iot, iobase,
    154 	    WDC_PIOC_REG_NPORTS, 0, &wdr->cmd_baseioh))
    155 		panic("%s: couldn't map drive registers", device_xname(self));
    156 	for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
    157 		if (bus_space_subregion(wdr->cmd_iot,
    158 			wdr->cmd_baseioh, i,	i == 0 ? 4 : 1,
    159 			&wdr->cmd_iohs[i]) != 0)
    160 			panic("%s: couldn't submap drive registers",
    161 			    device_xname(self));
    162 	}
    163 
    164 	if (bus_space_map(wdr->ctl_iot,
    165 	    iobase + WDC_PIOC_AUXREG_OFFSET, WDC_PIOC_AUXREG_NPORTS, 0,
    166 	    &wdr->ctl_ioh))
    167 		panic("%s: couldn't map aux registers", device_xname(self));
    168 
    169 	sc->sc_ih = intr_claim(pa->pa_irq, IPL_BIO, "wdc",  wdcintr,
    170 	     &sc->sc_channel);
    171 	if (!sc->sc_ih)
    172 		panic("%s: Cannot claim IRQ %d", device_xname(self),
    173 		    pa->pa_irq);
    174 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    175 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    176 	sc->sc_chanlist[0] = &sc->sc_channel;
    177 	sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
    178 	sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    179 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    180 	sc->sc_wdcdev.wdc_maxdrives = 2;
    181 	sc->sc_channel.ch_channel = 0;
    182 	sc->sc_channel.ch_queue = ata_queue_alloc(1);
    183 
    184 	wdc_init_shadow_regs(wdr);
    185 
    186 	wdcattach(&sc->sc_channel);
    187 }
    188 
    189 /* End of wdc_pioc.c */
    190