Home | History | Annotate | Line # | Download | only in dev
wdc_obio.c revision 1.11
      1  1.11   thorpej /*	$NetBSD: wdc_obio.c,v 1.11 2023/12/20 15:00:08 thorpej Exp $	*/
      2   1.1       uwe 
      3   1.1       uwe /*-
      4   1.1       uwe  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
      5   1.1       uwe  * All rights reserved.
      6   1.1       uwe  *
      7   1.1       uwe  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1       uwe  * by Charles M. Hannum and by Onno van der Linden.
      9   1.1       uwe  *
     10   1.1       uwe  * Redistribution and use in source and binary forms, with or without
     11   1.1       uwe  * modification, are permitted provided that the following conditions
     12   1.1       uwe  * are met:
     13   1.1       uwe  * 1. Redistributions of source code must retain the above copyright
     14   1.1       uwe  *    notice, this list of conditions and the following disclaimer.
     15   1.1       uwe  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       uwe  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       uwe  *    documentation and/or other materials provided with the distribution.
     18   1.1       uwe  *
     19   1.1       uwe  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1       uwe  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1       uwe  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1       uwe  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1       uwe  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1       uwe  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1       uwe  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1       uwe  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1       uwe  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1       uwe  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1       uwe  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1       uwe  */
     31   1.1       uwe 
     32   1.1       uwe #include <sys/cdefs.h>
     33  1.11   thorpej __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.11 2023/12/20 15:00:08 thorpej Exp $");
     34   1.1       uwe 
     35   1.1       uwe #include <sys/types.h>
     36   1.1       uwe #include <sys/param.h>
     37   1.1       uwe #include <sys/systm.h>
     38   1.1       uwe #include <sys/device.h>
     39   1.1       uwe 
     40   1.5    dyoung #include <sys/bus.h>
     41   1.1       uwe #include <machine/intr.h>
     42   1.1       uwe 
     43   1.1       uwe #include <dev/ata/atavar.h>
     44   1.1       uwe #include <dev/ic/wdcvar.h>
     45   1.1       uwe 
     46   1.1       uwe #include <landisk/dev/obiovar.h>
     47   1.1       uwe 
     48   1.1       uwe struct wdc_obio_softc {
     49   1.1       uwe 	struct	wdc_softc sc_wdcdev;
     50   1.1       uwe 	struct	ata_channel *sc_chanlist[1];
     51   1.1       uwe 	struct	ata_channel sc_channel;
     52   1.1       uwe 	struct	wdc_regs sc_wdc_regs;
     53   1.1       uwe 	void	*sc_ih;
     54   1.1       uwe };
     55   1.1       uwe 
     56   1.2      cube static int	wdc_obio_probe(device_t, cfdata_t, void *);
     57   1.2      cube static void	wdc_obio_attach(device_t, device_t, void *);
     58   1.1       uwe 
     59   1.2      cube CFATTACH_DECL_NEW(wdc_obio, sizeof(struct wdc_obio_softc),
     60   1.1       uwe     wdc_obio_probe, wdc_obio_attach, NULL, NULL);
     61   1.1       uwe 
     62   1.1       uwe #define	WDC_OBIO_REG_NPORTS	WDC_NREG
     63   1.1       uwe #define	WDC_OBIO_REG_SIZE	(WDC_OBIO_REG_NPORTS * 2)
     64   1.1       uwe #define	WDC_OBIO_AUXREG_NPORTS	1
     65   1.1       uwe #define	WDC_OBIO_AUXREG_SIZE	(WDC_OBIO_AUXREG_NPORTS * 2)
     66   1.1       uwe #define	WDC_OBIO_AUXREG_OFFSET	0x2c
     67   1.1       uwe 
     68   1.1       uwe static int
     69   1.2      cube wdc_obio_probe(device_t parent, cfdata_t cfp, void *aux)
     70   1.1       uwe {
     71   1.1       uwe 	struct obio_attach_args *oa = aux;
     72   1.1       uwe 	struct wdc_regs wdr;
     73   1.1       uwe 	int result = 0;
     74   1.1       uwe 	int i;
     75   1.1       uwe 
     76   1.1       uwe 	if (oa->oa_nio < 1)
     77   1.1       uwe 		return (0);
     78   1.1       uwe 	if (oa->oa_nirq < 1)
     79   1.1       uwe 		return (0);
     80   1.1       uwe 
     81   1.1       uwe 	if (oa->oa_io[0].or_addr == IOBASEUNK)
     82   1.1       uwe 		return (0);
     83   1.1       uwe 	if (oa->oa_irq[0].or_irq == IRQUNK)
     84   1.1       uwe 		return (0);
     85   1.1       uwe 
     86   1.1       uwe 	wdr.cmd_iot = oa->oa_iot;
     87   1.1       uwe 	if (bus_space_map(wdr.cmd_iot, oa->oa_io[0].or_addr,
     88   1.1       uwe 	    WDC_OBIO_REG_SIZE, 0, &wdr.cmd_baseioh)) {
     89   1.1       uwe 		goto out;
     90   1.1       uwe 	}
     91   1.1       uwe 	for (i = 0; i < WDC_OBIO_REG_NPORTS; i++) {
     92   1.1       uwe 		if (bus_space_subregion(wdr.cmd_iot, wdr.cmd_baseioh,
     93   1.1       uwe 		    i * 2, (i == 0) ? 2 : 1, &wdr.cmd_iohs[i])) {
     94   1.1       uwe 			goto outunmap;
     95   1.1       uwe 		}
     96   1.1       uwe 	}
     97   1.9  jdolecek 	wdc_init_shadow_regs(&wdr);
     98   1.1       uwe 
     99   1.1       uwe 	wdr.ctl_iot = oa->oa_iot;
    100   1.1       uwe 	if (bus_space_map(wdr.ctl_iot,
    101   1.1       uwe 	    oa->oa_io[0].or_addr + WDC_OBIO_AUXREG_OFFSET,
    102   1.1       uwe 	    WDC_OBIO_AUXREG_SIZE, 0, &wdr.ctl_ioh)) {
    103   1.1       uwe 		goto outunmap;
    104   1.1       uwe 	}
    105   1.1       uwe 
    106   1.9  jdolecek 	result = wdcprobe(&wdr);
    107   1.1       uwe 	if (result) {
    108   1.1       uwe 		oa->oa_nio = 1;
    109   1.1       uwe 		oa->oa_io[0].or_size = WDC_OBIO_REG_SIZE;
    110   1.1       uwe 		oa->oa_nirq = 1;
    111   1.1       uwe 		oa->oa_niomem = 0;
    112   1.1       uwe 	}
    113   1.1       uwe 
    114   1.1       uwe 	bus_space_unmap(wdr.ctl_iot, wdr.ctl_ioh, WDC_OBIO_AUXREG_SIZE);
    115   1.1       uwe outunmap:
    116   1.1       uwe 	bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh, WDC_OBIO_REG_SIZE);
    117   1.1       uwe out:
    118   1.1       uwe 	return (result);
    119   1.1       uwe }
    120   1.1       uwe 
    121   1.1       uwe static void
    122   1.2      cube wdc_obio_attach(device_t parent, device_t self, void *aux)
    123   1.1       uwe {
    124   1.2      cube 	struct wdc_obio_softc *sc = device_private(self);
    125   1.1       uwe 	struct obio_attach_args *oa = aux;
    126   1.1       uwe 	struct wdc_regs *wdr;
    127   1.1       uwe 	int i;
    128   1.1       uwe 
    129   1.3       uwe 	aprint_naive("\n");
    130   1.2      cube 	aprint_normal("\n");
    131   1.1       uwe 
    132   1.2      cube 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    133   1.1       uwe 	sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
    134   1.1       uwe 
    135   1.1       uwe 	wdr->cmd_iot = oa->oa_iot;
    136   1.1       uwe 	wdr->ctl_iot = oa->oa_iot;
    137   1.1       uwe 	if (bus_space_map(wdr->cmd_iot, oa->oa_io[0].or_addr,
    138   1.1       uwe 	    WDC_OBIO_REG_SIZE, 0, &wdr->cmd_baseioh)
    139   1.1       uwe 	 || bus_space_map(wdr->ctl_iot,
    140   1.1       uwe 	    oa->oa_io[0].or_addr + WDC_OBIO_AUXREG_OFFSET,
    141   1.1       uwe 	    WDC_OBIO_AUXREG_SIZE, 0, &wdr->ctl_ioh)) {
    142   1.2      cube 		aprint_error_dev(self, "couldn't map registers\n");
    143   1.1       uwe 		return;
    144   1.1       uwe 	}
    145   1.1       uwe 
    146   1.1       uwe 	for (i = 0; i < WDC_OBIO_REG_NPORTS; i++) {
    147   1.1       uwe 		if (bus_space_subregion(wdr->cmd_iot,
    148   1.1       uwe 		      wdr->cmd_baseioh, i * 2, (i == 0) ? 2 : 1,
    149   1.1       uwe 		      &wdr->cmd_iohs[i]) != 0) {
    150   1.2      cube 			aprint_error_dev(self,
    151   1.2      cube 			    "couldn't subregion registers\n");
    152   1.1       uwe 			return;
    153   1.1       uwe 		}
    154   1.1       uwe 	}
    155   1.1       uwe 
    156   1.1       uwe 	sc->sc_ih = obio_intr_establish(oa->oa_irq[0].or_irq, IPL_BIO, wdcintr,
    157   1.1       uwe 	    &sc->sc_channel);
    158   1.1       uwe 
    159   1.1       uwe 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_PREATA;
    160   1.1       uwe 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    161   1.1       uwe 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    162   1.1       uwe 	sc->sc_chanlist[0] = &sc->sc_channel;
    163   1.1       uwe 	sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
    164   1.1       uwe 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    165   1.8    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 2;
    166   1.1       uwe 	sc->sc_channel.ch_channel = 0;
    167   1.1       uwe 	sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    168   1.1       uwe 
    169   1.9  jdolecek 	wdc_init_shadow_regs(wdr);
    170   1.1       uwe 
    171   1.1       uwe 	wdcattach(&sc->sc_channel);
    172   1.1       uwe }
    173