Home | History | Annotate | Line # | Download | only in tsarm
wdc_ts.c revision 1.10
      1  1.10  jdolecek /*	$NetBSD: wdc_ts.c,v 1.10 2017/10/07 19:58:53 jdolecek 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.10  jdolecek __KERNEL_RCSID(0, "$NetBSD: wdc_ts.c,v 1.10 2017/10/07 19:58:53 jdolecek 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	wdc_regs wdc_regs;
     55   1.1      joff 	void	*sc_ih;
     56   1.1      joff };
     57   1.1      joff 
     58   1.4      cube static int	wdc_ts_probe(device_t, cfdata_t, void *);
     59   1.4      cube static void	wdc_ts_attach(device_t, device_t, void *);
     60   1.1      joff 
     61   1.4      cube CFATTACH_DECL_NEW(wdc_ts, sizeof(struct wdc_ts_softc),
     62   1.1      joff     wdc_ts_probe, wdc_ts_attach, NULL, NULL);
     63   1.1      joff 
     64   1.1      joff static int
     65   1.4      cube wdc_ts_probe(device_t parent, cfdata_t match, void *aux)
     66   1.1      joff {
     67   1.1      joff 	return 1;
     68   1.1      joff }
     69   1.1      joff 
     70   1.1      joff static void
     71   1.4      cube wdc_ts_attach(device_t parent, device_t self, void *aux)
     72   1.1      joff {
     73   1.4      cube 	struct wdc_ts_softc *sc = device_private(self);
     74   1.1      joff 	struct wdc_regs *wdr;
     75   1.1      joff 	struct tspld_attach_args *ta = aux;
     76   1.1      joff 	int i;
     77   1.1      joff 
     78   1.4      cube 	sc->sc_wdcdev.sc_atac.atac_dev = self;
     79   1.1      joff 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
     80   1.1      joff 	wdr->cmd_iot = ta->ta_iot;
     81   1.1      joff 	wdr->ctl_iot = ta->ta_iot;
     82   1.1      joff 	if (bus_space_map(wdr->cmd_iot, 0x11000000, 8, 0, &wdr->cmd_baseioh) ||
     83   1.1      joff 	    bus_space_map(wdr->ctl_iot, 0x10400006, 1, 0, &wdr->ctl_ioh)) {
     84   1.4      cube 		aprint_error(": couldn't map registers\n");
     85   1.1      joff 		return;
     86   1.1      joff 	}
     87   1.1      joff 
     88   1.1      joff 	for (i = 0; i < 8; i++) {
     89   1.1      joff 		if (bus_space_subregion(wdr->cmd_iot,
     90   1.1      joff 		      wdr->cmd_baseioh, i, 1, &wdr->cmd_iohs[i]) != 0) {
     91   1.4      cube 			aprint_error(": couldn't subregion registers\n");
     92   1.1      joff 			return;
     93   1.1      joff 		}
     94   1.1      joff 	}
     95   1.1      joff 
     96   1.1      joff 
     97   1.1      joff 	if (bus_space_map(wdr->cmd_iot, 0x21000000, 2, 0, &wdr->cmd_iohs[0])) {
     98   1.4      cube 		aprint_error(": couldn't map registers\n");
     99   1.1      joff 		return;
    100   1.1      joff 	}
    101   1.1      joff 
    102   1.1      joff 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_PREATA;
    103   1.1      joff 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    104   1.1      joff 
    105   1.1      joff 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    106   1.1      joff 	sc->wdc_chanlist[0] = &sc->ata_channel;
    107   1.1      joff 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
    108   1.1      joff 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    109   1.9    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 2;
    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.10  jdolecek 	sc->ata_channel.ch_queue = ata_queue_alloc(1);
    113  1.10  jdolecek 	wdc_init_shadow_regs(wdr);
    114   1.1      joff 
    115   1.4      cube 	aprint_normal("\n");
    116   1.1      joff 
    117   1.1      joff 	sc->sc_ih = ep93xx_intr_establish(32, IPL_BIO, wdcintr, &sc->ata_channel);
    118   1.1      joff 
    119   1.1      joff 	wdcattach(&sc->ata_channel);
    120   1.1      joff }
    121