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