Home | History | Annotate | Line # | Download | only in gemini
obio_wdc.c revision 1.11
      1  1.11    andvar /*	$NetBSD: obio_wdc.c,v 1.11 2021/09/19 20:52:47 andvar Exp $	*/
      2   1.1     cliff 
      3   1.2     cliff /* adapted from iq31244/wdc_obio.c:
      4   1.2     cliff  *	NetBSD: wdc_obio.c,v 1.5 2008/04/28 20:23:16 martin Exp
      5   1.1     cliff  */
      6   1.1     cliff 
      7   1.1     cliff /*-
      8   1.1     cliff  * Copyright (c) 1998, 2003, 2005 The NetBSD Foundation, Inc.
      9   1.1     cliff  * All rights reserved.
     10   1.1     cliff  *
     11   1.1     cliff  * This code is derived from software contributed to The NetBSD Foundation
     12   1.1     cliff  * by Charles M. Hannum and by Onno van der Linden.
     13   1.1     cliff  *
     14   1.1     cliff  * Redistribution and use in source and binary forms, with or without
     15   1.1     cliff  * modification, are permitted provided that the following conditions
     16   1.1     cliff  * are met:
     17   1.1     cliff  * 1. Redistributions of source code must retain the above copyright
     18   1.1     cliff  *    notice, this list of conditions and the following disclaimer.
     19   1.1     cliff  * 2. Redistributions in binary form must reproduce the above copyright
     20   1.1     cliff  *    notice, this list of conditions and the following disclaimer in the
     21   1.1     cliff  *    documentation and/or other materials provided with the distribution.
     22   1.1     cliff  *
     23   1.1     cliff  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     24   1.1     cliff  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25   1.1     cliff  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26   1.1     cliff  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     27   1.1     cliff  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28   1.1     cliff  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29   1.1     cliff  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30   1.1     cliff  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31   1.1     cliff  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32   1.1     cliff  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33   1.1     cliff  * POSSIBILITY OF SUCH DAMAGE.
     34   1.1     cliff  */
     35   1.1     cliff 
     36   1.1     cliff #include <sys/cdefs.h>
     37  1.11    andvar __KERNEL_RCSID(0, "$NetBSD: obio_wdc.c,v 1.11 2021/09/19 20:52:47 andvar Exp $");
     38   1.1     cliff 
     39   1.1     cliff #include "locators.h"
     40   1.1     cliff 
     41   1.1     cliff #include <sys/param.h>
     42   1.1     cliff #include <sys/systm.h>
     43   1.1     cliff #include <sys/device.h>
     44   1.1     cliff #include <sys/malloc.h>
     45   1.1     cliff 
     46   1.3    dyoung #include <sys/bus.h>
     47   1.1     cliff #include <machine/intr.h>
     48   1.1     cliff 
     49   1.1     cliff #include <arm/gemini/gemini_var.h>
     50   1.1     cliff #include <arm/gemini/gemini_reg.h>
     51   1.1     cliff #include <arm/gemini/gemini_obiovar.h>
     52   1.1     cliff 
     53   1.1     cliff #include <dev/ic/wdcreg.h>
     54   1.1     cliff #include <dev/ata/atavar.h>
     55   1.1     cliff #include <dev/ic/wdcvar.h>
     56   1.1     cliff 
     57   1.1     cliff struct wdc_obio_softc {
     58   1.1     cliff 	struct	wdc_softc sc_wdcdev;
     59   1.1     cliff 	struct	ata_channel *wdc_chanlist[1];
     60   1.1     cliff 	struct	ata_channel ata_channel;
     61   1.1     cliff 	struct	wdc_regs wdc_regs;
     62   1.1     cliff 	void	*sc_ih;
     63   1.1     cliff };
     64   1.1     cliff 
     65   1.1     cliff static int	wdc_obio_match(device_t, cfdata_t, void *);
     66   1.1     cliff static void	wdc_obio_attach(device_t, device_t, void *);
     67   1.1     cliff 
     68   1.1     cliff CFATTACH_DECL_NEW(wdc_obio, sizeof(struct wdc_obio_softc),
     69   1.1     cliff     wdc_obio_match, wdc_obio_attach, NULL, NULL);
     70   1.1     cliff 
     71   1.1     cliff static int
     72   1.1     cliff wdc_obio_match(device_t parent, cfdata_t match, void *aux)
     73   1.1     cliff {
     74   1.1     cliff 	struct obio_attach_args * const obio = aux;
     75   1.1     cliff 
     76   1.1     cliff 	if (obio->obio_addr == GEMINI_MIDE_BASEn(0)
     77   1.1     cliff 	||  obio->obio_addr == GEMINI_MIDE_BASEn(1))
     78   1.1     cliff 		return 1;
     79   1.1     cliff 
     80   1.1     cliff         return 0;
     81   1.1     cliff 
     82   1.1     cliff }
     83   1.1     cliff 
     84   1.1     cliff static void
     85   1.1     cliff wdc_obio_attach(device_t parent, device_t self, void *aux)
     86   1.1     cliff {
     87   1.1     cliff 	struct wdc_obio_softc *sc = device_private(self);
     88   1.1     cliff 	struct wdc_regs *wdr;
     89   1.1     cliff 	struct obio_attach_args *obio = aux;
     90   1.1     cliff 	uint chan;
     91   1.1     cliff 	int i;
     92   1.1     cliff 
     93   1.1     cliff 	/*
     94   1.1     cliff 	 * we treat the two channels of the Gemini MIDE controller
     95   1.9   msaitoh 	 * as separate wdc controllers, because they have
     96  1.11    andvar 	 * independent interrupts.  'chan' here is a MIDE channel,
     97   1.1     cliff 	 * (not to be confused with ATA channel).
     98   1.1     cliff 	 */
     99   1.1     cliff 	switch (obio->obio_addr) {
    100   1.1     cliff 	case  GEMINI_MIDE_BASEn(0):
    101   1.1     cliff 		chan = 0;
    102   1.1     cliff 		break;
    103   1.1     cliff 	case  GEMINI_MIDE_BASEn(1):
    104   1.1     cliff 		chan = 1;
    105   1.1     cliff 		break;
    106   1.1     cliff 	default:
    107   1.1     cliff 		panic("wdc_obio_attach: bad address");
    108   1.1     cliff 	}
    109   1.1     cliff 
    110   1.1     cliff 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    111   1.1     cliff 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
    112   1.1     cliff 	wdr->cmd_iot = obio->obio_iot;
    113   1.1     cliff 	wdr->ctl_iot = obio->obio_iot;
    114   1.1     cliff 	if (bus_space_map(wdr->cmd_iot, obio->obio_addr, GEMINI_MIDE_SIZE,
    115   1.1     cliff 	    0, &wdr->cmd_baseioh)) {
    116   1.1     cliff 		aprint_error(": couldn't map registers\n");
    117   1.1     cliff 		return;
    118   1.1     cliff 	}
    119   1.1     cliff 
    120   1.1     cliff 	for (i = 0; i < 8; i++) {
    121   1.1     cliff 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
    122   1.1     cliff 		    GEMINI_MIDE_CMDBLK + i, 1, &wdr->cmd_iohs[i]) != 0) {
    123   1.1     cliff 			aprint_error(": couldn't subregion registers\n");
    124   1.1     cliff 			return;
    125   1.1     cliff 		}
    126   1.1     cliff 	}
    127   1.1     cliff 
    128   1.1     cliff 	if (bus_space_subregion(wdr->ctl_iot, wdr->cmd_baseioh,
    129   1.1     cliff 	    GEMINI_MIDE_CTLBLK, 1, &wdr->ctl_ioh) != 0) {
    130   1.1     cliff 		aprint_error(": couldn't subregion registers\n");
    131   1.1     cliff 		return;
    132   1.1     cliff 	}
    133   1.1     cliff 
    134   1.1     cliff 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    135   1.1     cliff 
    136   1.1     cliff 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    137   1.1     cliff 	sc->wdc_chanlist[0] = &sc->ata_channel;
    138   1.1     cliff 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
    139   1.1     cliff 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    140   1.6    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 2;
    141   1.1     cliff 	sc->ata_channel.ch_channel = 0;
    142   1.1     cliff 	sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    143   1.8  jdolecek 
    144   1.7  jdolecek 	wdc_init_shadow_regs(wdr);
    145   1.1     cliff 
    146   1.1     cliff 	aprint_normal("\n");
    147   1.1     cliff 
    148   1.1     cliff 	if (obio->obio_intr != OBIOCF_INTR_DEFAULT)
    149   1.1     cliff 		sc->sc_ih = intr_establish(obio->obio_intr, IPL_BIO, IST_LEVEL_HIGH,
    150   1.1     cliff 			wdcintr, &sc->ata_channel);
    151   1.1     cliff 	else {
    152   1.1     cliff 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_NOIRQ;
    153   1.1     cliff 		aprint_normal_dev(self, "Using polled I/O\n");
    154   1.1     cliff 	}
    155   1.1     cliff 
    156   1.1     cliff 	wdcattach(&sc->ata_channel);
    157   1.1     cliff }
    158