Home | History | Annotate | Line # | Download | only in isa
mcclock_isa.c revision 1.2
      1 /*	$NetBSD: mcclock_isa.c,v 1.2 2002/01/07 21:46:57 thorpej 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 int mcclock_isa_match __P((struct device *, struct cfdata *, void *));
     62 void mcclock_isa_attach __P((struct device *, struct device *, void *));
     63 
     64 struct cfattach mcclock_isa_ca = {
     65 	sizeof(struct mcclock_softc),
     66 	mcclock_isa_match, mcclock_isa_attach
     67 };
     68 
     69 /* Deskstation clock access code */
     70 u_int mc_isa_read __P((struct mcclock_softc *, u_int));
     71 void mc_isa_write __P((struct mcclock_softc *, u_int, u_int));
     72 
     73 struct mcclock_busfns mcclock_isa_busfns = {
     74 	mc_isa_read, mc_isa_write
     75 };
     76 
     77 int mcclock_isa_conf = 0;
     78 
     79 int
     80 mcclock_isa_match(parent, match, aux)
     81 	struct device *parent;
     82 	struct cfdata *match;
     83 	void *aux;
     84 {
     85 	struct isa_attach_args *ia = aux;
     86 	bus_space_handle_t ioh;
     87 
     88 	if (ia->ia_nio < 1 ||
     89 	    (ia->ia_io[0].ir_addr != ISACF_PORT_DEFAULT &&
     90 	     ia->ia_io[0].ir_addr != 0x70))
     91 		return (0);
     92 
     93 	if (ia->ia_niomem > 0 &&
     94 	    (ia->ia_iomem[0].ir_addr != ISACF_IOMEM_DEFAULT))
     95 		return (0);
     96 
     97 	if (ia->ia_nirq > 0 &&
     98 	    (ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT))
     99 		return (0);
    100 
    101 	if (ia->ia_ndrq > 0 &&
    102 	    (ia->ia_drq[0].ir_drq != ISACF_DRQ_DEFAULT))
    103 		return (0);
    104 
    105 	if (!mcclock_isa_conf)
    106 		return (0);
    107 
    108 	if (bus_space_map(ia->ia_iot, 0x70, 0x02, 0, &ioh))
    109 		return (0);
    110 
    111 	bus_space_unmap(ia->ia_iot, ioh, 0x02);
    112 
    113 	ia->ia_nio = 1;
    114 	ia->ia_io[0].ir_addr = 0x70;
    115 	ia->ia_io[0].ir_size = 0x02;
    116 
    117 	ia->ia_niomem = 0;
    118 	ia->ia_nirq = 0;
    119 	ia->ia_ndrq = 0;
    120 
    121 	return (1);
    122 }
    123 
    124 void
    125 mcclock_isa_attach(parent, self, aux)
    126 	struct device *parent;
    127 	struct device *self;
    128 	void *aux;
    129 {
    130 	struct mcclock_softc *sc = (struct mcclock_softc *)self;
    131 	struct isa_attach_args *ia = aux;
    132 
    133 	sc->sc_iot = ia->ia_iot;
    134 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr,
    135 	    ia->ia_io[0].ir_size, 0, &sc->sc_ioh))
    136 		panic("mcclock_isa_attach: couldn't map clock I/O space");
    137 
    138 	mcclock_attach(sc, &mcclock_isa_busfns, 80);
    139 
    140 	/* Turn interrupts off, just in case. */
    141 	mc146818_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
    142 }
    143 
    144 u_int
    145 mc_isa_read(sc, reg)
    146 	struct mcclock_softc *sc;
    147 	u_int reg;
    148 {
    149 
    150 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, reg);
    151 	return (bus_space_read_1(sc->sc_iot, sc->sc_ioh, 1));
    152 }
    153 
    154 void
    155 mc_isa_write(sc, reg, datum)
    156 	struct mcclock_softc *sc;
    157 	u_int reg, datum;
    158 {
    159 
    160 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, reg);
    161 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, 1, datum);
    162 }
    163 
    164