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