Home | History | Annotate | Line # | Download | only in isa
fdc_isa.c revision 1.19.6.1
      1  1.19.6.1  jdolecek /*	$NetBSD: fdc_isa.c,v 1.19.6.1 2017/12/03 11:37:04 jdolecek Exp $	*/
      2       1.1   thorpej 
      3       1.1   thorpej /*-
      4       1.1   thorpej  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.1   thorpej  * All rights reserved.
      6       1.1   thorpej  *
      7       1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1   thorpej  * by Charles M. Hannum.
      9       1.1   thorpej  *
     10       1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     11       1.1   thorpej  * modification, are permitted provided that the following conditions
     12       1.1   thorpej  * are met:
     13       1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     14       1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     15       1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     18       1.1   thorpej  *
     19       1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1   thorpej  */
     31       1.1   thorpej 
     32       1.1   thorpej /*-
     33       1.1   thorpej  * Copyright (c) 1990 The Regents of the University of California.
     34       1.1   thorpej  * All rights reserved.
     35       1.1   thorpej  *
     36       1.1   thorpej  * This code is derived from software contributed to Berkeley by
     37       1.1   thorpej  * Don Ahn.
     38       1.1   thorpej  *
     39       1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     40       1.1   thorpej  * modification, are permitted provided that the following conditions
     41       1.1   thorpej  * are met:
     42       1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     43       1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     44       1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     45       1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     46       1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     47       1.8       agc  * 3. Neither the name of the University nor the names of its contributors
     48       1.1   thorpej  *    may be used to endorse or promote products derived from this software
     49       1.1   thorpej  *    without specific prior written permission.
     50       1.1   thorpej  *
     51       1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     52       1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     53       1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     54       1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     55       1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     56       1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     57       1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     58       1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     59       1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     60       1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     61       1.1   thorpej  * SUCH DAMAGE.
     62       1.1   thorpej  *
     63       1.1   thorpej  *	@(#)fd.c	7.4 (Berkeley) 5/25/91
     64       1.1   thorpej  */
     65       1.3     lukem 
     66       1.3     lukem #include <sys/cdefs.h>
     67  1.19.6.1  jdolecek __KERNEL_RCSID(0, "$NetBSD: fdc_isa.c,v 1.19.6.1 2017/12/03 11:37:04 jdolecek Exp $");
     68       1.1   thorpej 
     69       1.1   thorpej #include <sys/param.h>
     70       1.1   thorpej #include <sys/systm.h>
     71       1.1   thorpej #include <sys/callout.h>
     72       1.1   thorpej #include <sys/device.h>
     73       1.1   thorpej #include <sys/buf.h>
     74       1.1   thorpej #include <sys/queue.h>
     75       1.1   thorpej 
     76      1.15        ad #include <sys/bus.h>
     77      1.15        ad #include <sys/intr.h>
     78       1.1   thorpej 
     79       1.1   thorpej #include <dev/isa/isavar.h>
     80       1.1   thorpej #include <dev/isa/isadmavar.h>
     81       1.1   thorpej 
     82       1.1   thorpej #include <dev/isa/fdreg.h>
     83       1.1   thorpej #include <dev/isa/fdcvar.h>
     84       1.1   thorpej 
     85      1.17      cube static int	fdc_isa_probe(device_t, cfdata_t, void *);
     86      1.16    dyoung static void	fdc_isa_attach(device_t, device_t, void *);
     87      1.16    dyoung static int	fdc_isa_detach(device_t, int);
     88       1.1   thorpej 
     89       1.2   thorpej struct fdc_isa_softc {
     90       1.2   thorpej 	struct fdc_softc sc_fdc;	/* base fdc device */
     91       1.2   thorpej 
     92       1.2   thorpej 	bus_space_handle_t sc_baseioh;	/* base I/O handle */
     93       1.2   thorpej };
     94       1.2   thorpej 
     95      1.17      cube CFATTACH_DECL2_NEW(fdc_isa, sizeof(struct fdc_isa_softc),
     96      1.16    dyoung     fdc_isa_probe, fdc_isa_attach, fdc_isa_detach, NULL, NULL, fdc_childdet);
     97       1.1   thorpej 
     98       1.1   thorpej #ifdef NEWCONFIG
     99       1.1   thorpej void	fdc_isa_forceintr(void *);
    100       1.1   thorpej #endif
    101       1.1   thorpej 
    102      1.16    dyoung static int
    103      1.17      cube fdc_isa_probe(device_t parent, cfdata_t match, void *aux)
    104       1.1   thorpej {
    105       1.1   thorpej 	struct isa_attach_args *ia = aux;
    106       1.1   thorpej 	bus_space_tag_t iot;
    107       1.2   thorpej 	bus_space_handle_t ioh, ctl_ioh, base_ioh;
    108       1.4   thorpej 	int rv, iobase;
    109       1.1   thorpej 
    110       1.1   thorpej 	iot = ia->ia_iot;
    111       1.1   thorpej 	rv = 0;
    112       1.1   thorpej 
    113       1.4   thorpej 	if (ia->ia_nio < 1)
    114       1.4   thorpej 		return (0);
    115       1.4   thorpej 	if (ia->ia_nirq < 1)
    116       1.4   thorpej 		return (0);
    117       1.4   thorpej 	if (ia->ia_ndrq < 1)
    118       1.4   thorpej 		return (0);
    119       1.4   thorpej 
    120       1.4   thorpej 	if (ISA_DIRECT_CONFIG(ia))
    121       1.4   thorpej 		return (0);
    122       1.4   thorpej 
    123       1.1   thorpej 	/* Disallow wildcarded I/O addresses. */
    124      1.11  drochner 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
    125       1.4   thorpej 		return (0);
    126       1.4   thorpej 
    127       1.4   thorpej 	/* Don't allow wildcarded IRQ/DRQ. */
    128      1.11  drochner 	if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
    129       1.4   thorpej 		return (0);
    130       1.4   thorpej 
    131      1.11  drochner 	if (ia->ia_drq[0].ir_drq == ISA_UNKNOWN_DRQ)
    132       1.1   thorpej 		return (0);
    133       1.1   thorpej 
    134       1.1   thorpej 	/* Map the I/O space. */
    135       1.4   thorpej 	iobase = ia->ia_io[0].ir_addr;
    136       1.4   thorpej 	if (bus_space_map(iot, iobase, 6 /* FDC_NPORT */, 0, &base_ioh))
    137       1.1   thorpej 		return (0);
    138       1.1   thorpej 
    139       1.2   thorpej 	if (bus_space_subregion(iot, base_ioh, 2, 4, &ioh)) {
    140       1.2   thorpej 		bus_space_unmap(iot, base_ioh, 6);
    141       1.2   thorpej 		return (0);
    142       1.2   thorpej 	}
    143       1.2   thorpej 
    144       1.4   thorpej 	if (bus_space_map(iot, iobase + fdctl + 2, 1, 0, &ctl_ioh)) {
    145       1.2   thorpej 		bus_space_unmap(iot, base_ioh, 6);
    146       1.1   thorpej 		return (0);
    147       1.1   thorpej 	}
    148       1.1   thorpej 
    149       1.1   thorpej 	/* Not needed for the rest of the probe. */
    150       1.1   thorpej 	bus_space_unmap(iot, ctl_ioh, 1);
    151       1.1   thorpej 
    152       1.1   thorpej 	/* reset */
    153       1.1   thorpej 	bus_space_write_1(iot, ioh, fdout, 0);
    154       1.1   thorpej 	delay(100);
    155       1.1   thorpej 	bus_space_write_1(iot, ioh, fdout, FDO_FRST);
    156       1.1   thorpej 
    157       1.1   thorpej 	/* see if it can handle a command */
    158       1.1   thorpej 	if (out_fdc(iot, ioh, NE7CMD_SPECIFY) < 0)
    159       1.1   thorpej 		goto out;
    160       1.1   thorpej 	out_fdc(iot, ioh, 0xdf);
    161       1.1   thorpej 	out_fdc(iot, ioh, 2);
    162       1.1   thorpej 
    163       1.4   thorpej 	rv = 1;
    164       1.4   thorpej 	ia->ia_nio = 1;
    165       1.4   thorpej 	ia->ia_io[0].ir_size = FDC_NPORT;
    166       1.1   thorpej 
    167       1.4   thorpej 	ia->ia_nirq = 1;
    168       1.4   thorpej 	ia->ia_ndrq = 1;
    169       1.1   thorpej 
    170       1.4   thorpej 	ia->ia_niomem = 0;
    171       1.1   thorpej 
    172       1.1   thorpej  out:
    173       1.2   thorpej 	bus_space_unmap(iot, base_ioh, 6 /* FDC_NPORT */);
    174       1.1   thorpej 	return (rv);
    175       1.1   thorpej }
    176       1.1   thorpej 
    177      1.16    dyoung static int
    178      1.16    dyoung fdc_isa_detach(device_t self, int flags)
    179       1.1   thorpej {
    180      1.16    dyoung 	int rc;
    181      1.16    dyoung 	struct fdc_isa_softc *isc = device_private(self);
    182      1.16    dyoung 	struct fdc_softc *fdc = &isc->sc_fdc;
    183      1.16    dyoung 
    184      1.16    dyoung 	if ((rc = fdcdetach(self, flags)) != 0)
    185      1.16    dyoung 		return rc;
    186      1.16    dyoung 
    187      1.16    dyoung 	isa_intr_disestablish(fdc->sc_ic, fdc->sc_ih);
    188      1.16    dyoung 
    189      1.16    dyoung 	bus_space_unmap(fdc->sc_iot, fdc->sc_fdctlioh, 1);
    190      1.16    dyoung 
    191      1.16    dyoung 	bus_space_unmap(fdc->sc_iot, isc->sc_baseioh, 6 /* FDC_NPORT */);
    192      1.16    dyoung 
    193      1.16    dyoung 	return 0;
    194      1.16    dyoung }
    195      1.16    dyoung 
    196      1.16    dyoung static void
    197      1.16    dyoung fdc_isa_attach(device_t parent, device_t self, void *aux)
    198      1.16    dyoung {
    199      1.16    dyoung 	struct fdc_isa_softc *isc = device_private(self);
    200      1.16    dyoung 	struct fdc_softc *fdc = &isc->sc_fdc;
    201       1.1   thorpej 	struct isa_attach_args *ia = aux;
    202       1.1   thorpej 
    203      1.17      cube 	aprint_naive("\n");
    204      1.17      cube 	aprint_normal("\n");
    205       1.1   thorpej 
    206      1.17      cube 	fdc->sc_dev = self;
    207       1.1   thorpej 	fdc->sc_iot = ia->ia_iot;
    208       1.1   thorpej 	fdc->sc_ic = ia->ia_ic;
    209       1.4   thorpej 	fdc->sc_drq = ia->ia_drq[0].ir_drq;
    210       1.1   thorpej 
    211       1.4   thorpej 	if (bus_space_map(fdc->sc_iot, ia->ia_io[0].ir_addr,
    212       1.4   thorpej 	    6 /* FDC_NPORT */, 0, &isc->sc_baseioh)) {
    213      1.17      cube 		aprint_normal_dev(fdc->sc_dev, "unable to map I/O space\n");
    214       1.2   thorpej 		return;
    215       1.2   thorpej 	}
    216       1.2   thorpej 
    217       1.2   thorpej 	if (bus_space_subregion(fdc->sc_iot, isc->sc_baseioh, 2, 4,
    218       1.1   thorpej 	    &fdc->sc_ioh)) {
    219      1.17      cube 		aprint_normal_dev(fdc->sc_dev,
    220      1.16    dyoung 		    "unable to subregion I/O space\n");
    221       1.1   thorpej 		return;
    222       1.1   thorpej 	}
    223       1.1   thorpej 
    224       1.4   thorpej 	if (bus_space_map(fdc->sc_iot, ia->ia_io[0].ir_addr + fdctl + 2, 1, 0,
    225       1.1   thorpej 	    &fdc->sc_fdctlioh)) {
    226      1.17      cube 		aprint_normal_dev(fdc->sc_dev,
    227      1.16    dyoung 		    "unable to map CTL I/O space\n");
    228       1.1   thorpej 		return;
    229       1.1   thorpej 	}
    230       1.1   thorpej 
    231       1.4   thorpej 	fdc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    232       1.4   thorpej 	    IST_EDGE, IPL_BIO, fdcintr, fdc);
    233       1.1   thorpej 
    234      1.10   mycroft 	fdcattach(fdc);
    235       1.1   thorpej }
    236