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