Home | History | Annotate | Line # | Download | only in mpc85xx
      1  1.1      matt /*-
      2  1.1      matt  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
      3  1.1      matt  * All rights reserved.
      4  1.1      matt  *
      5  1.1      matt  * This code is derived from software contributed to The NetBSD Foundation
      6  1.1      matt  * by Matt Thomas of 3am Software Foundry.
      7  1.1      matt  *
      8  1.1      matt  * Redistribution and use in source and binary forms, with or without
      9  1.1      matt  * modification, are permitted provided that the following conditions
     10  1.1      matt  * are met:
     11  1.1      matt  * 1. Redistributions of source code must retain the above copyright
     12  1.1      matt  *    notice, this list of conditions and the following disclaimer.
     13  1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     15  1.1      matt  *    documentation and/or other materials provided with the distribution.
     16  1.1      matt  *
     17  1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18  1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21  1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     28  1.1      matt  */
     29  1.1      matt 
     30  1.1      matt #include "locators.h"
     31  1.1      matt 
     32  1.1      matt #include <sys/cdefs.h>
     33  1.1      matt 
     34  1.8  riastrad __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.8 2022/02/12 02:40:28 riastradh Exp $");
     35  1.1      matt 
     36  1.1      matt #include <sys/param.h>
     37  1.1      matt #include <sys/cpu.h>
     38  1.1      matt #include <sys/device.h>
     39  1.1      matt #include <sys/tty.h>
     40  1.1      matt 
     41  1.1      matt #include "ioconf.h"
     42  1.1      matt 
     43  1.1      matt #include <sys/intr.h>
     44  1.1      matt #include <sys/bus.h>
     45  1.1      matt 
     46  1.1      matt #include <powerpc/booke/cpuvar.h>
     47  1.1      matt 
     48  1.1      matt #include <dev/ic/wdcreg.h>
     49  1.1      matt #include <dev/ata/atavar.h>
     50  1.1      matt #include <dev/ic/wdcvar.h>
     51  1.1      matt 
     52  1.1      matt struct wdc_obio_softc {
     53  1.1      matt 	struct	wdc_softc sc_wdcdev;
     54  1.1      matt 	struct	ata_channel *wdc_chanlist[1];
     55  1.1      matt 	struct	ata_channel ata_channel;
     56  1.1      matt 	struct	wdc_regs wdc_regs;
     57  1.1      matt 	void	*sc_ih;
     58  1.1      matt };
     59  1.1      matt 
     60  1.1      matt #define WDC_OBIO_AUXREG_OFFSET (WDC_NREG + 6)
     61  1.1      matt 
     62  1.1      matt static int wdc_obio_match(device_t, cfdata_t, void *);
     63  1.1      matt static void wdc_obio_attach(device_t, device_t, void *);
     64  1.1      matt 
     65  1.1      matt CFATTACH_DECL_NEW(wdc_obio, sizeof(struct wdc_obio_softc),
     66  1.1      matt     wdc_obio_match, wdc_obio_attach, NULL, NULL);
     67  1.1      matt 
     68  1.1      matt static bool
     69  1.1      matt wdc_obio_initregmap(struct wdc_regs *wdr, bus_space_tag_t bst,
     70  1.1      matt 	bus_addr_t addr, bus_size_t size)
     71  1.1      matt {
     72  1.1      matt 	int error;
     73  1.1      matt 
     74  1.1      matt 	wdr->cmd_iot = bst;
     75  1.1      matt 	wdr->ctl_iot = bst;
     76  1.1      matt 
     77  1.1      matt 	error = bus_space_map(wdr->cmd_iot, addr, size, 0, &wdr->cmd_baseioh);
     78  1.1      matt 	if (error) {
     79  1.1      matt 		wdr->cmd_baseioh = 0;
     80  1.1      matt 		return false;
     81  1.1      matt 	}
     82  1.1      matt 
     83  1.1      matt 	for (u_int i = 0; i < WDC_NREG; i++) {
     84  1.1      matt 		if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
     85  1.1      matt 		    i, (i == 0) ? 2 : 1, &wdr->cmd_iohs[i])) {
     86  1.1      matt 			return false;
     87  1.1      matt 		}
     88  1.1      matt 	}
     89  1.1      matt 
     90  1.1      matt 	if (bus_space_subregion(wdr->ctl_iot, wdr->cmd_baseioh,
     91  1.1      matt 	    WDC_OBIO_AUXREG_OFFSET, 1, &wdr->ctl_ioh)) {
     92  1.1      matt 		return false;
     93  1.1      matt 	}
     94  1.1      matt 
     95  1.1      matt 	return true;
     96  1.1      matt }
     97  1.1      matt 
     98  1.1      matt static int
     99  1.1      matt wdc_obio_match(device_t parent, cfdata_t cf, void *aux)
    100  1.1      matt {
    101  1.1      matt 	struct generic_attach_args * const ga = aux;
    102  1.1      matt 	bus_size_t size = ga->ga_size;
    103  1.1      matt 	struct wdc_regs wdr;
    104  1.1      matt 	int rv = 0;
    105  1.1      matt 
    106  1.1      matt 	if (ga->ga_addr == OBIOCF_ADDR_DEFAULT)
    107  1.1      matt 		return 0;
    108  1.1      matt 	if (size == OBIOCF_SIZE_DEFAULT  || size > PAGE_SIZE)
    109  1.1      matt 		size = 2 * WDC_NREG;
    110  1.1      matt 
    111  1.1      matt 	/*
    112  1.1      matt 	 * We need to see if a CF is attached in True-IDE mode
    113  1.1      matt 	 */
    114  1.1      matt 	memset(&wdr, 0, sizeof(wdr));
    115  1.1      matt 
    116  1.1      matt 	if (wdc_obio_initregmap(&wdr, ga->ga_bst, ga->ga_addr, size)) {
    117  1.7  jdolecek 		wdc_init_shadow_regs(&wdr);
    118  1.7  jdolecek 		rv = wdcprobe(&wdr);
    119  1.1      matt 		bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh, size);
    120  1.1      matt 	}
    121  1.1      matt 
    122  1.1      matt 	return rv;
    123  1.1      matt }
    124  1.1      matt 
    125  1.1      matt static void
    126  1.1      matt wdc_obio_attach(device_t parent, device_t self, void *aux)
    127  1.1      matt {
    128  1.1      matt 	struct wdc_obio_softc *sc = device_private(self);
    129  1.1      matt 	struct wdc_regs * const wdr = &sc->wdc_regs;
    130  1.1      matt 	struct generic_attach_args * const ga = aux;
    131  1.1      matt 	bus_size_t size = ga->ga_size;
    132  1.1      matt 
    133  1.1      matt 	if (size == OBIOCF_SIZE_DEFAULT || size > PAGE_SIZE)
    134  1.1      matt 		size = 2 * WDC_NREG;
    135  1.1      matt 
    136  1.1      matt 	sc->sc_wdcdev.sc_atac.atac_dev = self;
    137  1.1      matt 	sc->sc_wdcdev.regs = wdr;
    138  1.1      matt 	if (!wdc_obio_initregmap(wdr, ga->ga_bst, ga->ga_addr, size)) {
    139  1.1      matt 		aprint_error(": couldn't map registers\n");
    140  1.1      matt 		return;
    141  1.1      matt 	}
    142  1.1      matt 
    143  1.1      matt 	//sc->sc_wdcdev.cap |= WDC_CAPABILITY_NO_EXTRA_RESETS;
    144  1.1      matt 	sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
    145  1.1      matt 
    146  1.1      matt 	sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
    147  1.1      matt 	sc->wdc_chanlist[0] = &sc->ata_channel;
    148  1.1      matt 	sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
    149  1.1      matt 	sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
    150  1.4    bouyer 	sc->sc_wdcdev.wdc_maxdrives = 2;
    151  1.1      matt 	sc->ata_channel.ch_channel = 0;
    152  1.1      matt 	sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
    153  1.6  jdolecek 
    154  1.5  jdolecek 	wdc_init_shadow_regs(wdr);
    155  1.1      matt 
    156  1.1      matt 	/*
    157  1.1      matt 	 * The interrupt line is controlled by a jumper.  We can't detect
    158  1.1      matt 	 * this, except by allowing a request to time out, so assume that
    159  1.1      matt 	 * if the config file hasn't specified the IRQ, then the jumper isn't
    160  1.1      matt 	 * fitted.
    161  1.1      matt 	 */
    162  1.1      matt 	if (ga->ga_irq != OBIOCF_IRQ_DEFAULT) {
    163  1.1      matt 		sc->sc_ih = intr_establish(ga->ga_irq, IPL_BIO, IST_EDGE,
    164  1.1      matt 		    wdcintr, &sc->ata_channel);
    165  1.1      matt 		aprint_normal(": interrupting at irq %d\n", ga->ga_irq);
    166  1.1      matt 	} else {
    167  1.1      matt 		sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_NOIRQ;
    168  1.1      matt 		aprint_normal(": using polled I/O\n");
    169  1.1      matt 	}
    170  1.1      matt 
    171  1.1      matt 	wdcattach(&sc->ata_channel);
    172  1.1      matt }
    173