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