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