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