Home | History | Annotate | Line # | Download | only in iq31244
wdc_obio.c revision 1.6
      1  1.6    dyoung /*	$NetBSD: wdc_obio.c,v 1.6 2011/07/01 20:41:16 dyoung Exp $ */
      2  1.1  rearnsha 
      3  1.1  rearnsha /*-
      4  1.1  rearnsha  * Copyright (c) 1998, 2003, 2005 The NetBSD Foundation, Inc.
      5  1.1  rearnsha  * All rights reserved.
      6  1.1  rearnsha  *
      7  1.1  rearnsha  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  rearnsha  * by Charles M. Hannum and by Onno van der Linden.
      9  1.1  rearnsha  *
     10  1.1  rearnsha  * Redistribution and use in source and binary forms, with or without
     11  1.1  rearnsha  * modification, are permitted provided that the following conditions
     12  1.1  rearnsha  * are met:
     13  1.1  rearnsha  * 1. Redistributions of source code must retain the above copyright
     14  1.1  rearnsha  *    notice, this list of conditions and the following disclaimer.
     15  1.1  rearnsha  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  rearnsha  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  rearnsha  *    documentation and/or other materials provided with the distribution.
     18  1.1  rearnsha  *
     19  1.1  rearnsha  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  rearnsha  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  rearnsha  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  rearnsha  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  rearnsha  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  rearnsha  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  rearnsha  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  rearnsha  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  rearnsha  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  rearnsha  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  rearnsha  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  rearnsha  */
     31  1.1  rearnsha 
     32  1.1  rearnsha #include <sys/cdefs.h>
     33  1.6    dyoung __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.6 2011/07/01 20:41:16 dyoung Exp $");
     34  1.1  rearnsha 
     35  1.1  rearnsha #include <sys/param.h>
     36  1.1  rearnsha #include <sys/systm.h>
     37  1.1  rearnsha #include <sys/device.h>
     38  1.1  rearnsha #include <sys/malloc.h>
     39  1.1  rearnsha 
     40  1.6    dyoung #include <sys/bus.h>
     41  1.1  rearnsha #include <machine/intr.h>
     42  1.1  rearnsha 
     43  1.1  rearnsha #include <arm/xscale/i80321var.h>
     44  1.1  rearnsha #include <evbarm/iq80321/iq80321reg.h>
     45  1.1  rearnsha #include <evbarm/iq80321/obiovar.h>
     46  1.1  rearnsha 
     47  1.1  rearnsha #include <evbarm/iq31244/iq31244reg.h>
     48  1.1  rearnsha 
     49  1.1  rearnsha #include <dev/ic/wdcreg.h>
     50  1.1  rearnsha #include <dev/ata/atavar.h>
     51  1.1  rearnsha #include <dev/ic/wdcvar.h>
     52  1.1  rearnsha 
     53  1.1  rearnsha struct wdc_obio_softc {
     54  1.1  rearnsha 	struct	wdc_softc sc_wdcdev;
     55  1.1  rearnsha 	struct	ata_channel *wdc_chanlist[1];
     56  1.1  rearnsha 	struct	ata_channel ata_channel;
     57  1.1  rearnsha 	struct	ata_queue wdc_chqueue;
     58  1.1  rearnsha 	struct	wdc_regs wdc_regs;
     59  1.1  rearnsha 	void	*sc_ih;
     60  1.1  rearnsha };
     61  1.1  rearnsha 
     62  1.4      cube static int	wdc_obio_probe(device_t, cfdata_t, void *);
     63  1.4      cube static void	wdc_obio_attach(device_t, device_t, void *);
     64  1.1  rearnsha 
     65  1.4      cube CFATTACH_DECL_NEW(wdc_obio, sizeof(struct wdc_obio_softc),
     66  1.1  rearnsha     wdc_obio_probe, wdc_obio_attach, NULL, NULL);
     67  1.1  rearnsha 
     68  1.1  rearnsha static int
     69  1.4      cube wdc_obio_probe(device_t parent, cfdata_t match, void *aux)
     70  1.1  rearnsha {
     71  1.1  rearnsha 	return 1;
     72  1.1  rearnsha }
     73  1.1  rearnsha 
     74  1.1  rearnsha static void
     75  1.4      cube wdc_obio_attach(device_t parent, device_t self, void *aux)
     76  1.1  rearnsha {
     77  1.4      cube 	struct wdc_obio_softc *sc = device_private(self);
     78  1.1  rearnsha 	struct wdc_regs *wdr;
     79  1.1  rearnsha 	struct obio_attach_args *oba = aux;
     80  1.1  rearnsha 	int i;
     81  1.1  rearnsha 
     82  1.4      cube 	sc->sc_wdcdev.sc_atac.atac_dev = self;
     83  1.1  rearnsha 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
     84  1.1  rearnsha 	wdr->cmd_iot = oba->oba_st;
     85  1.1  rearnsha 	wdr->ctl_iot = oba->oba_st;
     86  1.1  rearnsha 	if (bus_space_map(wdr->cmd_iot, oba->oba_addr, IQ31244_CFLASH_SIZE,
     87  1.1  rearnsha 	    0, &wdr->cmd_baseioh)) {
     88  1.4      cube 		aprint_error(": couldn't map registers\n");
     89  1.1  rearnsha 		return;
     90  1.1  rearnsha 	}
     91  1.1  rearnsha 
     92  1.1  rearnsha 	for (i = 0; i < 8; i++) {
     93  1.1  rearnsha 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
     94  1.1  rearnsha 		    IQ31244_CFLASH_CMD_BASE + i, 1, &wdr->cmd_iohs[i]) != 0) {
     95  1.4      cube 			aprint_error(": couldn't subregion registers\n");
     96  1.1  rearnsha 			return;
     97  1.1  rearnsha 		}
     98  1.1  rearnsha 	}
     99  1.1  rearnsha 
    100  1.1  rearnsha 	if (bus_space_subregion(wdr->ctl_iot, wdr->cmd_baseioh,
    101  1.1  rearnsha 	    IQ31244_CFLASH_CTL_BASE, 1, &wdr->ctl_ioh) != 0) {
    102  1.4      cube 		aprint_error(": couldn't subregion registers\n");
    103  1.1  rearnsha 		return;
    104  1.1  rearnsha 	}
    105  1.1  rearnsha 
    106  1.1  rearnsha 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    107  1.1  rearnsha 
    108  1.1  rearnsha 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    109  1.1  rearnsha 	sc->wdc_chanlist[0] = &sc->ata_channel;
    110  1.1  rearnsha 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
    111  1.1  rearnsha 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    112  1.1  rearnsha 	sc->ata_channel.ch_channel = 0;
    113  1.1  rearnsha 	sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    114  1.1  rearnsha 	sc->ata_channel.ch_queue = &sc->wdc_chqueue;
    115  1.3    bouyer 	sc->ata_channel.ch_ndrive = 2;
    116  1.1  rearnsha 	wdc_init_shadow_regs(&sc->ata_channel);
    117  1.1  rearnsha 
    118  1.4      cube 	aprint_normal("\n");
    119  1.1  rearnsha 
    120  1.1  rearnsha 	/*
    121  1.1  rearnsha 	 * The interrupt line is controlled by a jumper.  We can't detect
    122  1.1  rearnsha 	 * this, except by allowing a request to time out, so assume that
    123  1.1  rearnsha 	 * if the config file hasn't specified the IRQ, then the jumper isn't
    124  1.1  rearnsha 	 * fitted.
    125  1.1  rearnsha 	 */
    126  1.1  rearnsha 	if (oba->oba_irq != -1)
    127  1.1  rearnsha 		sc->sc_ih = i80321_intr_establish(oba->oba_irq, IPL_BIO,
    128  1.1  rearnsha 			wdcintr, &sc->ata_channel);
    129  1.1  rearnsha 	else {
    130  1.1  rearnsha 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_NOIRQ;
    131  1.4      cube 		aprint_normal_dev(self, "Using polled I/O\n");
    132  1.1  rearnsha 	}
    133  1.1  rearnsha 
    134  1.1  rearnsha 	wdcattach(&sc->ata_channel);
    135  1.1  rearnsha }
    136