Home | History | Annotate | Line # | Download | only in dev
wdc_obio.c revision 1.5
      1  1.5  dyoung /*	$NetBSD: wdc_obio.c,v 1.5 2011/07/01 19:12:53 dyoung Exp $	*/
      2  1.1     uwe 
      3  1.1     uwe /*-
      4  1.1     uwe  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
      5  1.1     uwe  * All rights reserved.
      6  1.1     uwe  *
      7  1.1     uwe  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1     uwe  * by Charles M. Hannum and by Onno van der Linden.
      9  1.1     uwe  *
     10  1.1     uwe  * Redistribution and use in source and binary forms, with or without
     11  1.1     uwe  * modification, are permitted provided that the following conditions
     12  1.1     uwe  * are met:
     13  1.1     uwe  * 1. Redistributions of source code must retain the above copyright
     14  1.1     uwe  *    notice, this list of conditions and the following disclaimer.
     15  1.1     uwe  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1     uwe  *    notice, this list of conditions and the following disclaimer in the
     17  1.1     uwe  *    documentation and/or other materials provided with the distribution.
     18  1.1     uwe  *
     19  1.1     uwe  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1     uwe  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1     uwe  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1     uwe  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1     uwe  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1     uwe  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1     uwe  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1     uwe  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1     uwe  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1     uwe  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1     uwe  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1     uwe  */
     31  1.1     uwe 
     32  1.1     uwe #include <sys/cdefs.h>
     33  1.5  dyoung __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.5 2011/07/01 19:12:53 dyoung Exp $");
     34  1.1     uwe 
     35  1.1     uwe #include <sys/types.h>
     36  1.1     uwe #include <sys/param.h>
     37  1.1     uwe #include <sys/systm.h>
     38  1.1     uwe #include <sys/device.h>
     39  1.1     uwe #include <sys/malloc.h>
     40  1.1     uwe 
     41  1.5  dyoung #include <sys/bus.h>
     42  1.1     uwe #include <machine/intr.h>
     43  1.1     uwe 
     44  1.1     uwe #include <dev/ata/atavar.h>
     45  1.1     uwe #include <dev/ic/wdcvar.h>
     46  1.1     uwe 
     47  1.1     uwe #include <landisk/dev/obiovar.h>
     48  1.1     uwe 
     49  1.1     uwe struct wdc_obio_softc {
     50  1.1     uwe 	struct	wdc_softc sc_wdcdev;
     51  1.1     uwe 	struct	ata_channel *sc_chanlist[1];
     52  1.1     uwe 	struct	ata_channel sc_channel;
     53  1.1     uwe 	struct	ata_queue sc_chqueue;
     54  1.1     uwe 	struct	wdc_regs sc_wdc_regs;
     55  1.1     uwe 	void	*sc_ih;
     56  1.1     uwe };
     57  1.1     uwe 
     58  1.2    cube static int	wdc_obio_probe(device_t, cfdata_t, void *);
     59  1.2    cube static void	wdc_obio_attach(device_t, device_t, void *);
     60  1.1     uwe 
     61  1.2    cube CFATTACH_DECL_NEW(wdc_obio, sizeof(struct wdc_obio_softc),
     62  1.1     uwe     wdc_obio_probe, wdc_obio_attach, NULL, NULL);
     63  1.1     uwe 
     64  1.1     uwe #define	WDC_OBIO_REG_NPORTS	WDC_NREG
     65  1.1     uwe #define	WDC_OBIO_REG_SIZE	(WDC_OBIO_REG_NPORTS * 2)
     66  1.1     uwe #define	WDC_OBIO_AUXREG_NPORTS	1
     67  1.1     uwe #define	WDC_OBIO_AUXREG_SIZE	(WDC_OBIO_AUXREG_NPORTS * 2)
     68  1.1     uwe #define	WDC_OBIO_AUXREG_OFFSET	0x2c
     69  1.1     uwe 
     70  1.1     uwe static int
     71  1.2    cube wdc_obio_probe(device_t parent, cfdata_t cfp, void *aux)
     72  1.1     uwe {
     73  1.1     uwe 	struct obio_attach_args *oa = aux;
     74  1.1     uwe 	struct ata_channel ch;
     75  1.1     uwe 	struct wdc_softc wdc;
     76  1.1     uwe 	struct wdc_regs wdr;
     77  1.1     uwe 	int result = 0;
     78  1.1     uwe 	int i;
     79  1.1     uwe 
     80  1.1     uwe 	if (oa->oa_nio < 1)
     81  1.1     uwe 		return (0);
     82  1.1     uwe 	if (oa->oa_nirq < 1)
     83  1.1     uwe 		return (0);
     84  1.1     uwe 
     85  1.1     uwe 	if (oa->oa_io[0].or_addr == IOBASEUNK)
     86  1.1     uwe 		return (0);
     87  1.1     uwe 	if (oa->oa_irq[0].or_irq == IRQUNK)
     88  1.1     uwe 		return (0);
     89  1.1     uwe 
     90  1.1     uwe 	memset(&wdc, 0, sizeof(wdc));
     91  1.1     uwe 	memset(&ch, 0, sizeof(ch));
     92  1.1     uwe 	ch.ch_atac = &wdc.sc_atac;
     93  1.1     uwe 	wdc.regs = &wdr;
     94  1.1     uwe 
     95  1.1     uwe 	wdr.cmd_iot = oa->oa_iot;
     96  1.1     uwe 	if (bus_space_map(wdr.cmd_iot, oa->oa_io[0].or_addr,
     97  1.1     uwe 	    WDC_OBIO_REG_SIZE, 0, &wdr.cmd_baseioh)) {
     98  1.1     uwe 		goto out;
     99  1.1     uwe 	}
    100  1.1     uwe 	for (i = 0; i < WDC_OBIO_REG_NPORTS; i++) {
    101  1.1     uwe 		if (bus_space_subregion(wdr.cmd_iot, wdr.cmd_baseioh,
    102  1.1     uwe 		    i * 2, (i == 0) ? 2 : 1, &wdr.cmd_iohs[i])) {
    103  1.1     uwe 			goto outunmap;
    104  1.1     uwe 		}
    105  1.1     uwe 	}
    106  1.1     uwe 	wdc_init_shadow_regs(&ch);
    107  1.1     uwe 
    108  1.1     uwe 	wdr.ctl_iot = oa->oa_iot;
    109  1.1     uwe 	if (bus_space_map(wdr.ctl_iot,
    110  1.1     uwe 	    oa->oa_io[0].or_addr + WDC_OBIO_AUXREG_OFFSET,
    111  1.1     uwe 	    WDC_OBIO_AUXREG_SIZE, 0, &wdr.ctl_ioh)) {
    112  1.1     uwe 		goto outunmap;
    113  1.1     uwe 	}
    114  1.1     uwe 
    115  1.1     uwe 	result = wdcprobe(&ch);
    116  1.1     uwe 	if (result) {
    117  1.1     uwe 		oa->oa_nio = 1;
    118  1.1     uwe 		oa->oa_io[0].or_size = WDC_OBIO_REG_SIZE;
    119  1.1     uwe 		oa->oa_nirq = 1;
    120  1.1     uwe 		oa->oa_niomem = 0;
    121  1.1     uwe 	}
    122  1.1     uwe 
    123  1.1     uwe 	bus_space_unmap(wdr.ctl_iot, wdr.ctl_ioh, WDC_OBIO_AUXREG_SIZE);
    124  1.1     uwe outunmap:
    125  1.1     uwe 	bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh, WDC_OBIO_REG_SIZE);
    126  1.1     uwe out:
    127  1.1     uwe 	return (result);
    128  1.1     uwe }
    129  1.1     uwe 
    130  1.1     uwe static void
    131  1.2    cube wdc_obio_attach(device_t parent, device_t self, void *aux)
    132  1.1     uwe {
    133  1.2    cube 	struct wdc_obio_softc *sc = device_private(self);
    134  1.1     uwe 	struct obio_attach_args *oa = aux;
    135  1.1     uwe 	struct wdc_regs *wdr;
    136  1.1     uwe 	int i;
    137  1.1     uwe 
    138  1.3     uwe 	aprint_naive("\n");
    139  1.2    cube 	aprint_normal("\n");
    140  1.1     uwe 
    141  1.2    cube 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    142  1.1     uwe 	sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
    143  1.1     uwe 
    144  1.1     uwe 	wdr->cmd_iot = oa->oa_iot;
    145  1.1     uwe 	wdr->ctl_iot = oa->oa_iot;
    146  1.1     uwe 	if (bus_space_map(wdr->cmd_iot, oa->oa_io[0].or_addr,
    147  1.1     uwe 	    WDC_OBIO_REG_SIZE, 0, &wdr->cmd_baseioh)
    148  1.1     uwe 	 || bus_space_map(wdr->ctl_iot,
    149  1.1     uwe 	    oa->oa_io[0].or_addr + WDC_OBIO_AUXREG_OFFSET,
    150  1.1     uwe 	    WDC_OBIO_AUXREG_SIZE, 0, &wdr->ctl_ioh)) {
    151  1.2    cube 		aprint_error_dev(self, "couldn't map registers\n");
    152  1.1     uwe 		return;
    153  1.1     uwe 	}
    154  1.1     uwe 
    155  1.1     uwe 	for (i = 0; i < WDC_OBIO_REG_NPORTS; i++) {
    156  1.1     uwe 		if (bus_space_subregion(wdr->cmd_iot,
    157  1.1     uwe 		      wdr->cmd_baseioh, i * 2, (i == 0) ? 2 : 1,
    158  1.1     uwe 		      &wdr->cmd_iohs[i]) != 0) {
    159  1.2    cube 			aprint_error_dev(self,
    160  1.2    cube 			    "couldn't subregion registers\n");
    161  1.1     uwe 			return;
    162  1.1     uwe 		}
    163  1.1     uwe 	}
    164  1.1     uwe 
    165  1.1     uwe 	sc->sc_ih = obio_intr_establish(oa->oa_irq[0].or_irq, IPL_BIO, wdcintr,
    166  1.1     uwe 	    &sc->sc_channel);
    167  1.1     uwe 
    168  1.1     uwe 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_PREATA;
    169  1.1     uwe 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    170  1.1     uwe 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    171  1.1     uwe 	sc->sc_chanlist[0] = &sc->sc_channel;
    172  1.1     uwe 	sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
    173  1.1     uwe 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    174  1.1     uwe 	sc->sc_channel.ch_channel = 0;
    175  1.1     uwe 	sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    176  1.1     uwe 	sc->sc_channel.ch_queue = &sc->sc_chqueue;
    177  1.1     uwe 	sc->sc_channel.ch_ndrive = 2;
    178  1.1     uwe 
    179  1.1     uwe 	wdc_init_shadow_regs(&sc->sc_channel);
    180  1.1     uwe 
    181  1.1     uwe 	wdcattach(&sc->sc_channel);
    182  1.1     uwe }
    183