Home | History | Annotate | Line # | Download | only in isa
mcclock_isa.c revision 1.6
      1  1.6      agc /*	$NetBSD: mcclock_isa.c,v 1.6 2003/08/07 16:26:50 agc Exp $	*/
      2  1.1     soda /*	$OpenBSD: clock_mc.c,v 1.9 1998/03/16 09:38:26 pefo Exp $	*/
      3  1.1     soda /*	NetBSD: clock_mc.c,v 1.2 1995/06/28 04:30:30 cgd Exp 	*/
      4  1.1     soda 
      5  1.1     soda /*
      6  1.1     soda  * Copyright (c) 1992, 1993
      7  1.1     soda  *	The Regents of the University of California.  All rights reserved.
      8  1.1     soda  *
      9  1.1     soda  * This code is derived from software contributed to Berkeley by
     10  1.1     soda  * the Systems Programming Group of the University of Utah Computer
     11  1.1     soda  * Science Department and Ralph Campbell.
     12  1.1     soda  *
     13  1.1     soda  * Redistribution and use in source and binary forms, with or without
     14  1.1     soda  * modification, are permitted provided that the following conditions
     15  1.1     soda  * are met:
     16  1.1     soda  * 1. Redistributions of source code must retain the above copyright
     17  1.1     soda  *    notice, this list of conditions and the following disclaimer.
     18  1.1     soda  * 2. Redistributions in binary form must reproduce the above copyright
     19  1.1     soda  *    notice, this list of conditions and the following disclaimer in the
     20  1.1     soda  *    documentation and/or other materials provided with the distribution.
     21  1.6      agc  * 3. Neither the name of the University nor the names of its contributors
     22  1.6      agc  *    may be used to endorse or promote products derived from this software
     23  1.6      agc  *    without specific prior written permission.
     24  1.6      agc  *
     25  1.6      agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  1.6      agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  1.6      agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  1.6      agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  1.6      agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  1.6      agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  1.6      agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  1.6      agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  1.6      agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  1.6      agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  1.6      agc  * SUCH DAMAGE.
     36  1.6      agc  *
     37  1.6      agc  * from: Utah Hdr: clock.c 1.18 91/01/21
     38  1.6      agc  *
     39  1.6      agc  *	@(#)clock.c	8.1 (Berkeley) 6/10/93
     40  1.6      agc  */
     41  1.6      agc /*
     42  1.6      agc  * Copyright (c) 1988 University of Utah.
     43  1.6      agc  *
     44  1.6      agc  * This code is derived from software contributed to Berkeley by
     45  1.6      agc  * the Systems Programming Group of the University of Utah Computer
     46  1.6      agc  * Science Department and Ralph Campbell.
     47  1.6      agc  *
     48  1.6      agc  * Redistribution and use in source and binary forms, with or without
     49  1.6      agc  * modification, are permitted provided that the following conditions
     50  1.6      agc  * are met:
     51  1.6      agc  * 1. Redistributions of source code must retain the above copyright
     52  1.6      agc  *    notice, this list of conditions and the following disclaimer.
     53  1.6      agc  * 2. Redistributions in binary form must reproduce the above copyright
     54  1.6      agc  *    notice, this list of conditions and the following disclaimer in the
     55  1.6      agc  *    documentation and/or other materials provided with the distribution.
     56  1.1     soda  * 3. All advertising materials mentioning features or use of this software
     57  1.1     soda  *    must display the following acknowledgement:
     58  1.1     soda  *	This product includes software developed by the University of
     59  1.1     soda  *	California, Berkeley and its contributors.
     60  1.1     soda  * 4. Neither the name of the University nor the names of its contributors
     61  1.1     soda  *    may be used to endorse or promote products derived from this software
     62  1.1     soda  *    without specific prior written permission.
     63  1.1     soda  *
     64  1.1     soda  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     65  1.1     soda  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     66  1.1     soda  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     67  1.1     soda  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     68  1.1     soda  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     69  1.1     soda  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     70  1.1     soda  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     71  1.1     soda  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     72  1.1     soda  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     73  1.1     soda  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     74  1.1     soda  * SUCH DAMAGE.
     75  1.1     soda  *
     76  1.1     soda  * from: Utah Hdr: clock.c 1.18 91/01/21
     77  1.1     soda  *
     78  1.1     soda  *	@(#)clock.c	8.1 (Berkeley) 6/10/93
     79  1.1     soda  */
     80  1.5    lukem 
     81  1.5    lukem #include <sys/cdefs.h>
     82  1.6      agc __KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.6 2003/08/07 16:26:50 agc Exp $");
     83  1.1     soda 
     84  1.1     soda #include <sys/param.h>
     85  1.1     soda #include <sys/systm.h>
     86  1.1     soda #include <sys/device.h>
     87  1.1     soda 
     88  1.1     soda #include <machine/bus.h>
     89  1.1     soda 
     90  1.1     soda #include <dev/isa/isareg.h>
     91  1.1     soda #include <dev/isa/isavar.h>
     92  1.1     soda 
     93  1.1     soda #include <dev/ic/mc146818reg.h>
     94  1.1     soda 
     95  1.1     soda #include <arc/dev/mcclockvar.h>
     96  1.1     soda #include <arc/isa/mcclock_isavar.h>
     97  1.1     soda 
     98  1.1     soda int mcclock_isa_match __P((struct device *, struct cfdata *, void *));
     99  1.1     soda void mcclock_isa_attach __P((struct device *, struct device *, void *));
    100  1.1     soda 
    101  1.4  thorpej CFATTACH_DECL(mcclock_isa, sizeof(struct mcclock_softc),
    102  1.4  thorpej     mcclock_isa_match, mcclock_isa_attach, NULL, NULL);
    103  1.1     soda 
    104  1.1     soda /* Deskstation clock access code */
    105  1.1     soda u_int mc_isa_read __P((struct mcclock_softc *, u_int));
    106  1.1     soda void mc_isa_write __P((struct mcclock_softc *, u_int, u_int));
    107  1.1     soda 
    108  1.1     soda struct mcclock_busfns mcclock_isa_busfns = {
    109  1.1     soda 	mc_isa_read, mc_isa_write
    110  1.1     soda };
    111  1.1     soda 
    112  1.1     soda int mcclock_isa_conf = 0;
    113  1.1     soda 
    114  1.1     soda int
    115  1.1     soda mcclock_isa_match(parent, match, aux)
    116  1.1     soda 	struct device *parent;
    117  1.1     soda 	struct cfdata *match;
    118  1.1     soda 	void *aux;
    119  1.1     soda {
    120  1.1     soda 	struct isa_attach_args *ia = aux;
    121  1.1     soda 	bus_space_handle_t ioh;
    122  1.1     soda 
    123  1.2  thorpej 	if (ia->ia_nio < 1 ||
    124  1.2  thorpej 	    (ia->ia_io[0].ir_addr != ISACF_PORT_DEFAULT &&
    125  1.2  thorpej 	     ia->ia_io[0].ir_addr != 0x70))
    126  1.2  thorpej 		return (0);
    127  1.2  thorpej 
    128  1.2  thorpej 	if (ia->ia_niomem > 0 &&
    129  1.2  thorpej 	    (ia->ia_iomem[0].ir_addr != ISACF_IOMEM_DEFAULT))
    130  1.2  thorpej 		return (0);
    131  1.2  thorpej 
    132  1.2  thorpej 	if (ia->ia_nirq > 0 &&
    133  1.2  thorpej 	    (ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT))
    134  1.2  thorpej 		return (0);
    135  1.2  thorpej 
    136  1.2  thorpej 	if (ia->ia_ndrq > 0 &&
    137  1.2  thorpej 	    (ia->ia_drq[0].ir_drq != ISACF_DRQ_DEFAULT))
    138  1.1     soda 		return (0);
    139  1.1     soda 
    140  1.1     soda 	if (!mcclock_isa_conf)
    141  1.1     soda 		return (0);
    142  1.1     soda 
    143  1.2  thorpej 	if (bus_space_map(ia->ia_iot, 0x70, 0x02, 0, &ioh))
    144  1.1     soda 		return (0);
    145  1.1     soda 
    146  1.2  thorpej 	bus_space_unmap(ia->ia_iot, ioh, 0x02);
    147  1.1     soda 
    148  1.2  thorpej 	ia->ia_nio = 1;
    149  1.2  thorpej 	ia->ia_io[0].ir_addr = 0x70;
    150  1.2  thorpej 	ia->ia_io[0].ir_size = 0x02;
    151  1.2  thorpej 
    152  1.2  thorpej 	ia->ia_niomem = 0;
    153  1.2  thorpej 	ia->ia_nirq = 0;
    154  1.2  thorpej 	ia->ia_ndrq = 0;
    155  1.1     soda 
    156  1.1     soda 	return (1);
    157  1.1     soda }
    158  1.1     soda 
    159  1.1     soda void
    160  1.1     soda mcclock_isa_attach(parent, self, aux)
    161  1.1     soda 	struct device *parent;
    162  1.1     soda 	struct device *self;
    163  1.1     soda 	void *aux;
    164  1.1     soda {
    165  1.1     soda 	struct mcclock_softc *sc = (struct mcclock_softc *)self;
    166  1.1     soda 	struct isa_attach_args *ia = aux;
    167  1.1     soda 
    168  1.1     soda 	sc->sc_iot = ia->ia_iot;
    169  1.2  thorpej 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
    170  1.2  thorpej 	    ia->ia_io[0].ir_size, 0, &sc->sc_ioh))
    171  1.1     soda 		panic("mcclock_isa_attach: couldn't map clock I/O space");
    172  1.1     soda 
    173  1.1     soda 	mcclock_attach(sc, &mcclock_isa_busfns, 80);
    174  1.1     soda 
    175  1.1     soda 	/* Turn interrupts off, just in case. */
    176  1.1     soda 	mc146818_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
    177  1.1     soda }
    178  1.1     soda 
    179  1.1     soda u_int
    180  1.1     soda mc_isa_read(sc, reg)
    181  1.1     soda 	struct mcclock_softc *sc;
    182  1.1     soda 	u_int reg;
    183  1.1     soda {
    184  1.1     soda 
    185  1.1     soda 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, reg);
    186  1.1     soda 	return (bus_space_read_1(sc->sc_iot, sc->sc_ioh, 1));
    187  1.1     soda }
    188  1.1     soda 
    189  1.1     soda void
    190  1.1     soda mc_isa_write(sc, reg, datum)
    191  1.1     soda 	struct mcclock_softc *sc;
    192  1.1     soda 	u_int reg, datum;
    193  1.1     soda {
    194  1.1     soda 
    195  1.1     soda 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, reg);
    196  1.1     soda 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, 1, datum);
    197  1.1     soda }
    198  1.1     soda 
    199