Home | History | Annotate | Line # | Download | only in isa
fdc_isa.c revision 1.1
      1  1.1  thorpej /*	$NetBSD: fdc_isa.c,v 1.1 2000/04/23 16:47:45 thorpej 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  * 3. All advertising materials mentioning features or use of this software
     19  1.1  thorpej  *    must display the following acknowledgement:
     20  1.1  thorpej  *        This product includes software developed by the NetBSD
     21  1.1  thorpej  *        Foundation, Inc. and its contributors.
     22  1.1  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  thorpej  *    contributors may be used to endorse or promote products derived
     24  1.1  thorpej  *    from this software without specific prior written permission.
     25  1.1  thorpej  *
     26  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  thorpej  */
     38  1.1  thorpej 
     39  1.1  thorpej /*-
     40  1.1  thorpej  * Copyright (c) 1990 The Regents of the University of California.
     41  1.1  thorpej  * All rights reserved.
     42  1.1  thorpej  *
     43  1.1  thorpej  * This code is derived from software contributed to Berkeley by
     44  1.1  thorpej  * Don Ahn.
     45  1.1  thorpej  *
     46  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     47  1.1  thorpej  * modification, are permitted provided that the following conditions
     48  1.1  thorpej  * are met:
     49  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     50  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     51  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     53  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     54  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     55  1.1  thorpej  *    must display the following acknowledgement:
     56  1.1  thorpej  *	This product includes software developed by the University of
     57  1.1  thorpej  *	California, Berkeley and its contributors.
     58  1.1  thorpej  * 4. Neither the name of the University nor the names of its contributors
     59  1.1  thorpej  *    may be used to endorse or promote products derived from this software
     60  1.1  thorpej  *    without specific prior written permission.
     61  1.1  thorpej  *
     62  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     63  1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     64  1.1  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     65  1.1  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     66  1.1  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     67  1.1  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     68  1.1  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     69  1.1  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     70  1.1  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     71  1.1  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     72  1.1  thorpej  * SUCH DAMAGE.
     73  1.1  thorpej  *
     74  1.1  thorpej  *	@(#)fd.c	7.4 (Berkeley) 5/25/91
     75  1.1  thorpej  */
     76  1.1  thorpej 
     77  1.1  thorpej #include "rnd.h"
     78  1.1  thorpej 
     79  1.1  thorpej #include <sys/param.h>
     80  1.1  thorpej #include <sys/systm.h>
     81  1.1  thorpej #include <sys/callout.h>
     82  1.1  thorpej #include <sys/device.h>
     83  1.1  thorpej #include <sys/buf.h>
     84  1.1  thorpej #include <sys/queue.h>
     85  1.1  thorpej #if NRND > 0
     86  1.1  thorpej #include <sys/rnd.h>
     87  1.1  thorpej #endif
     88  1.1  thorpej 
     89  1.1  thorpej #include <machine/bus.h>
     90  1.1  thorpej #include <machine/intr.h>
     91  1.1  thorpej 
     92  1.1  thorpej #include <dev/isa/isavar.h>
     93  1.1  thorpej #include <dev/isa/isadmavar.h>
     94  1.1  thorpej 
     95  1.1  thorpej #include <dev/isa/fdreg.h>
     96  1.1  thorpej #include <dev/isa/fdcvar.h>
     97  1.1  thorpej 
     98  1.1  thorpej int	fdc_isa_probe(struct device *, struct cfdata *, void *);
     99  1.1  thorpej void	fdc_isa_attach(struct device *, struct device *, void *);
    100  1.1  thorpej 
    101  1.1  thorpej struct cfattach fdc_isa_ca = {
    102  1.1  thorpej 	sizeof(struct fdc_softc), fdc_isa_probe, fdc_isa_attach
    103  1.1  thorpej };
    104  1.1  thorpej 
    105  1.1  thorpej #ifdef NEWCONFIG
    106  1.1  thorpej void	fdc_isa_forceintr(void *);
    107  1.1  thorpej #endif
    108  1.1  thorpej 
    109  1.1  thorpej int
    110  1.1  thorpej fdc_isa_probe(struct device *parent,
    111  1.1  thorpej     struct cfdata *match,
    112  1.1  thorpej     void *aux)
    113  1.1  thorpej {
    114  1.1  thorpej 	struct isa_attach_args *ia = aux;
    115  1.1  thorpej 	bus_space_tag_t iot;
    116  1.1  thorpej 	bus_space_handle_t ioh, ctl_ioh;
    117  1.1  thorpej 	int rv;
    118  1.1  thorpej 
    119  1.1  thorpej 	iot = ia->ia_iot;
    120  1.1  thorpej 	rv = 0;
    121  1.1  thorpej 
    122  1.1  thorpej 	/* Disallow wildcarded I/O addresses. */
    123  1.1  thorpej 	if (ia->ia_iobase == IOBASEUNK)
    124  1.1  thorpej 		return (0);
    125  1.1  thorpej 
    126  1.1  thorpej 	/* Map the I/O space. */
    127  1.1  thorpej 	if (bus_space_map(iot, ia->ia_iobase, 6 /* FDC_NPORT */, 0, &ioh))
    128  1.1  thorpej 		return (0);
    129  1.1  thorpej 
    130  1.1  thorpej 	if (bus_space_map(iot, ia->ia_iobase + fdctl, 1, 0, &ctl_ioh)) {
    131  1.1  thorpej 		bus_space_unmap(iot, ioh, 6);
    132  1.1  thorpej 		return (0);
    133  1.1  thorpej 	}
    134  1.1  thorpej 
    135  1.1  thorpej 	/* Not needed for the rest of the probe. */
    136  1.1  thorpej 	bus_space_unmap(iot, ctl_ioh, 1);
    137  1.1  thorpej 
    138  1.1  thorpej 	/* reset */
    139  1.1  thorpej 	bus_space_write_1(iot, ioh, fdout, 0);
    140  1.1  thorpej 	delay(100);
    141  1.1  thorpej 	bus_space_write_1(iot, ioh, fdout, FDO_FRST);
    142  1.1  thorpej 
    143  1.1  thorpej 	/* see if it can handle a command */
    144  1.1  thorpej 	if (out_fdc(iot, ioh, NE7CMD_SPECIFY) < 0)
    145  1.1  thorpej 		goto out;
    146  1.1  thorpej 	out_fdc(iot, ioh, 0xdf);
    147  1.1  thorpej 	out_fdc(iot, ioh, 2);
    148  1.1  thorpej 
    149  1.1  thorpej #ifdef NEWCONFIG
    150  1.1  thorpej 	if (ia->ia_iobase = IOBASEUNK || ia->ia_drq == DRQUNK)
    151  1.1  thorpej 		return (0);
    152  1.1  thorpej 
    153  1.1  thorpej 	if (ia->ia_irq == IRQUNK) {
    154  1.1  thorpej 		ia->ia_irq = isa_discoverintr(fdc_isa_forceintr, aux);
    155  1.1  thorpej 		if (ia->ia_irq == IRQNONE)
    156  1.1  thorpej 			goto out;
    157  1.1  thorpej 
    158  1.1  thorpej 		/* reset it again */
    159  1.1  thorpej 		bus_space_write_1(iot, ioh, fdout, 0);
    160  1.1  thorpej 		delay(100);
    161  1.1  thorpej 		bus_space_write_1(iot, ioh, fdout, FDO_FRST);
    162  1.1  thorpej 	}
    163  1.1  thorpej #endif
    164  1.1  thorpej 
    165  1.1  thorpej 	rv = 1;
    166  1.1  thorpej 	ia->ia_iosize = FDC_NPORT;
    167  1.1  thorpej 	ia->ia_msize = 0;
    168  1.1  thorpej 
    169  1.1  thorpej  out:
    170  1.1  thorpej 	bus_space_unmap(iot, ioh, 6 /* FDC_NPORT */);
    171  1.1  thorpej 	return (rv);
    172  1.1  thorpej }
    173  1.1  thorpej 
    174  1.1  thorpej #ifdef NEWCONFIG
    175  1.1  thorpej /*
    176  1.1  thorpej  * XXX This is broken, and needs fixing.  In general, the interface needs
    177  1.1  thorpej  * XXX to change.
    178  1.1  thorpej  */
    179  1.1  thorpej void
    180  1.1  thorpej fdc_isa_forceintr(void *aux)
    181  1.1  thorpej {
    182  1.1  thorpej 	struct isa_attach_args *ia = aux;
    183  1.1  thorpej 	int iobase = ia->ia_iobase;
    184  1.1  thorpej 
    185  1.1  thorpej 	/*
    186  1.1  thorpej 	 * The motor is off; this should generate an error with or
    187  1.1  thorpej 	 * without a disk drive present.
    188  1.1  thorpej 	 */
    189  1.1  thorpej 	out_fdc(iot, ioh, NE7CMD_SEEK);
    190  1.1  thorpej 	out_fdc(iot, ioh, 0);
    191  1.1  thorpej 	out_fdc(iot, ioh, 0);
    192  1.1  thorpej }
    193  1.1  thorpej #endif
    194  1.1  thorpej 
    195  1.1  thorpej void
    196  1.1  thorpej fdc_isa_attach(struct device *parent,
    197  1.1  thorpej     struct device *self,
    198  1.1  thorpej     void *aux)
    199  1.1  thorpej {
    200  1.1  thorpej 	struct fdc_softc *fdc = (void *) self;
    201  1.1  thorpej 	struct isa_attach_args *ia = aux;
    202  1.1  thorpej 
    203  1.1  thorpej 	printf("\n");
    204  1.1  thorpej 
    205  1.1  thorpej 	fdc->sc_iot = ia->ia_iot;
    206  1.1  thorpej 	fdc->sc_ic = ia->ia_ic;
    207  1.1  thorpej 	fdc->sc_drq = ia->ia_drq;
    208  1.1  thorpej 
    209  1.1  thorpej 	if (bus_space_map(fdc->sc_iot, ia->ia_iobase, 6 /* FDC_NPORT */, 0,
    210  1.1  thorpej 	    &fdc->sc_ioh)) {
    211  1.1  thorpej 		printf("%s: unable to map I/O space\n", fdc->sc_dev.dv_xname);
    212  1.1  thorpej 		return;
    213  1.1  thorpej 	}
    214  1.1  thorpej 
    215  1.1  thorpej 	if (bus_space_map(fdc->sc_iot, ia->ia_iobase + fdctl, 1, 0,
    216  1.1  thorpej 	    &fdc->sc_fdctlioh)) {
    217  1.1  thorpej 		printf("%s: unable to map CTL I/O space\n",
    218  1.1  thorpej 		    fdc->sc_dev.dv_xname);
    219  1.1  thorpej 		return;
    220  1.1  thorpej 	}
    221  1.1  thorpej 
    222  1.1  thorpej 	fdc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    223  1.1  thorpej 	    IPL_BIO, fdcintr, fdc);
    224  1.1  thorpej 
    225  1.1  thorpej 	fdcattach(fdc);
    226  1.1  thorpej }
    227