Home | History | Annotate | Line # | Download | only in gemini
      1  1.12     skrll /*	$NetBSD: obio_wdc.c,v 1.12 2022/09/27 06:36:41 skrll 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.12     skrll __KERNEL_RCSID(0, "$NetBSD: obio_wdc.c,v 1.12 2022/09/27 06:36:41 skrll 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 
     45   1.3    dyoung #include <sys/bus.h>
     46   1.1     cliff #include <machine/intr.h>
     47   1.1     cliff 
     48   1.1     cliff #include <arm/gemini/gemini_var.h>
     49   1.1     cliff #include <arm/gemini/gemini_reg.h>
     50   1.1     cliff #include <arm/gemini/gemini_obiovar.h>
     51   1.1     cliff 
     52   1.1     cliff #include <dev/ic/wdcreg.h>
     53   1.1     cliff #include <dev/ata/atavar.h>
     54   1.1     cliff #include <dev/ic/wdcvar.h>
     55   1.1     cliff 
     56   1.1     cliff struct wdc_obio_softc {
     57   1.1     cliff 	struct	wdc_softc sc_wdcdev;
     58   1.1     cliff 	struct	ata_channel *wdc_chanlist[1];
     59   1.1     cliff 	struct	ata_channel ata_channel;
     60   1.1     cliff 	struct	wdc_regs wdc_regs;
     61   1.1     cliff 	void	*sc_ih;
     62   1.1     cliff };
     63   1.1     cliff 
     64   1.1     cliff static int	wdc_obio_match(device_t, cfdata_t, void *);
     65   1.1     cliff static void	wdc_obio_attach(device_t, device_t, void *);
     66   1.1     cliff 
     67   1.1     cliff CFATTACH_DECL_NEW(wdc_obio, sizeof(struct wdc_obio_softc),
     68   1.1     cliff     wdc_obio_match, wdc_obio_attach, NULL, NULL);
     69   1.1     cliff 
     70   1.1     cliff static int
     71   1.1     cliff wdc_obio_match(device_t parent, cfdata_t match, void *aux)
     72   1.1     cliff {
     73   1.1     cliff 	struct obio_attach_args * const obio = aux;
     74   1.1     cliff 
     75   1.1     cliff 	if (obio->obio_addr == GEMINI_MIDE_BASEn(0)
     76   1.1     cliff 	||  obio->obio_addr == GEMINI_MIDE_BASEn(1))
     77   1.1     cliff 		return 1;
     78   1.1     cliff 
     79   1.1     cliff         return 0;
     80   1.1     cliff 
     81   1.1     cliff }
     82   1.1     cliff 
     83   1.1     cliff static void
     84   1.1     cliff wdc_obio_attach(device_t parent, device_t self, void *aux)
     85   1.1     cliff {
     86   1.1     cliff 	struct wdc_obio_softc *sc = device_private(self);
     87   1.1     cliff 	struct wdc_regs *wdr;
     88   1.1     cliff 	struct obio_attach_args *obio = aux;
     89   1.1     cliff 	uint chan;
     90   1.1     cliff 	int i;
     91   1.1     cliff 
     92   1.1     cliff 	/*
     93   1.1     cliff 	 * we treat the two channels of the Gemini MIDE controller
     94   1.9   msaitoh 	 * as separate wdc controllers, because they have
     95  1.11    andvar 	 * independent interrupts.  'chan' here is a MIDE channel,
     96   1.1     cliff 	 * (not to be confused with ATA channel).
     97   1.1     cliff 	 */
     98   1.1     cliff 	switch (obio->obio_addr) {
     99   1.1     cliff 	case  GEMINI_MIDE_BASEn(0):
    100   1.1     cliff 		chan = 0;
    101   1.1     cliff 		break;
    102   1.1     cliff 	case  GEMINI_MIDE_BASEn(1):
    103   1.1     cliff 		chan = 1;
    104   1.1     cliff 		break;
    105   1.1     cliff 	default:
    106   1.1     cliff 		panic("wdc_obio_attach: bad address");
    107   1.1     cliff 	}
    108   1.1     cliff 
    109   1.1     cliff 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    110   1.1     cliff 	sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
    111   1.1     cliff 	wdr->cmd_iot = obio->obio_iot;
    112   1.1     cliff 	wdr->ctl_iot = obio->obio_iot;
    113   1.1     cliff 	if (bus_space_map(wdr->cmd_iot, obio->obio_addr, GEMINI_MIDE_SIZE,
    114   1.1     cliff 	    0, &wdr->cmd_baseioh)) {
    115   1.1     cliff 		aprint_error(": couldn't map registers\n");
    116   1.1     cliff 		return;
    117   1.1     cliff 	}
    118   1.1     cliff 
    119   1.1     cliff 	for (i = 0; i < 8; i++) {
    120   1.1     cliff 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
    121   1.1     cliff 		    GEMINI_MIDE_CMDBLK + i, 1, &wdr->cmd_iohs[i]) != 0) {
    122   1.1     cliff 			aprint_error(": couldn't subregion registers\n");
    123   1.1     cliff 			return;
    124   1.1     cliff 		}
    125   1.1     cliff 	}
    126   1.1     cliff 
    127   1.1     cliff 	if (bus_space_subregion(wdr->ctl_iot, wdr->cmd_baseioh,
    128   1.1     cliff 	    GEMINI_MIDE_CTLBLK, 1, &wdr->ctl_ioh) != 0) {
    129   1.1     cliff 		aprint_error(": couldn't subregion registers\n");
    130   1.1     cliff 		return;
    131   1.1     cliff 	}
    132   1.1     cliff 
    133   1.1     cliff 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    134   1.1     cliff 
    135   1.1     cliff 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    136   1.1     cliff 	sc->wdc_chanlist[0] = &sc->ata_channel;
    137   1.1     cliff 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
    138   1.1     cliff 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    139   1.6    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 2;
    140   1.1     cliff 	sc->ata_channel.ch_channel = 0;
    141   1.1     cliff 	sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    142   1.8  jdolecek 
    143   1.7  jdolecek 	wdc_init_shadow_regs(wdr);
    144   1.1     cliff 
    145   1.1     cliff 	aprint_normal("\n");
    146   1.1     cliff 
    147   1.1     cliff 	if (obio->obio_intr != OBIOCF_INTR_DEFAULT)
    148   1.1     cliff 		sc->sc_ih = intr_establish(obio->obio_intr, IPL_BIO, IST_LEVEL_HIGH,
    149   1.1     cliff 			wdcintr, &sc->ata_channel);
    150   1.1     cliff 	else {
    151   1.1     cliff 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_NOIRQ;
    152   1.1     cliff 		aprint_normal_dev(self, "Using polled I/O\n");
    153   1.1     cliff 	}
    154   1.1     cliff 
    155   1.1     cliff 	wdcattach(&sc->ata_channel);
    156   1.1     cliff }
    157