Home | History | Annotate | Line # | Download | only in isa
mcclock_isa.c revision 1.9
      1  1.9   tsutsui /*	$NetBSD: mcclock_isa.c,v 1.9 2005/01/22 07:35:34 tsutsui 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.9   tsutsui __KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.9 2005/01/22 07:35:34 tsutsui 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.7   tsutsui #include <dev/clock_subr.h>
     94  1.7   tsutsui 
     95  1.1      soda #include <dev/ic/mc146818reg.h>
     96  1.7   tsutsui #include <dev/ic/mc146818var.h>
     97  1.1      soda 
     98  1.1      soda #include <arc/isa/mcclock_isavar.h>
     99  1.1      soda 
    100  1.7   tsutsui int mcclock_isa_match(struct device *, struct cfdata *, void *);
    101  1.7   tsutsui void mcclock_isa_attach(struct device *, struct device *, void *);
    102  1.1      soda 
    103  1.7   tsutsui CFATTACH_DECL(mcclock_isa, sizeof(struct mc146818_softc),
    104  1.4   thorpej     mcclock_isa_match, mcclock_isa_attach, NULL, NULL);
    105  1.1      soda 
    106  1.1      soda /* Deskstation clock access code */
    107  1.7   tsutsui static u_int mc_isa_read(struct mc146818_softc *, u_int);
    108  1.7   tsutsui static void mc_isa_write(struct mc146818_softc *, u_int, u_int);
    109  1.1      soda 
    110  1.1      soda int mcclock_isa_conf = 0;
    111  1.1      soda 
    112  1.1      soda int
    113  1.9   tsutsui mcclock_isa_match(struct device *parent, struct cfdata *match, void *aux)
    114  1.1      soda {
    115  1.1      soda 	struct isa_attach_args *ia = aux;
    116  1.1      soda 	bus_space_handle_t ioh;
    117  1.1      soda 
    118  1.2   thorpej 	if (ia->ia_nio < 1 ||
    119  1.8  drochner 	    (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
    120  1.2   thorpej 	     ia->ia_io[0].ir_addr != 0x70))
    121  1.9   tsutsui 		return 0;
    122  1.2   thorpej 
    123  1.2   thorpej 	if (ia->ia_niomem > 0 &&
    124  1.8  drochner 	    (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
    125  1.9   tsutsui 		return 0;
    126  1.2   thorpej 
    127  1.2   thorpej 	if (ia->ia_nirq > 0 &&
    128  1.8  drochner 	    (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ))
    129  1.9   tsutsui 		return 0;
    130  1.2   thorpej 
    131  1.2   thorpej 	if (ia->ia_ndrq > 0 &&
    132  1.8  drochner 	    (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
    133  1.9   tsutsui 		return 0;
    134  1.1      soda 
    135  1.1      soda 	if (!mcclock_isa_conf)
    136  1.9   tsutsui 		return 0;
    137  1.1      soda 
    138  1.2   thorpej 	if (bus_space_map(ia->ia_iot, 0x70, 0x02, 0, &ioh))
    139  1.9   tsutsui 		return 0;
    140  1.1      soda 
    141  1.2   thorpej 	bus_space_unmap(ia->ia_iot, ioh, 0x02);
    142  1.1      soda 
    143  1.2   thorpej 	ia->ia_nio = 1;
    144  1.2   thorpej 	ia->ia_io[0].ir_addr = 0x70;
    145  1.2   thorpej 	ia->ia_io[0].ir_size = 0x02;
    146  1.2   thorpej 
    147  1.2   thorpej 	ia->ia_niomem = 0;
    148  1.2   thorpej 	ia->ia_nirq = 0;
    149  1.2   thorpej 	ia->ia_ndrq = 0;
    150  1.1      soda 
    151  1.9   tsutsui 	return 1;
    152  1.1      soda }
    153  1.1      soda 
    154  1.1      soda void
    155  1.9   tsutsui mcclock_isa_attach(struct device *parent, struct device *self, void *aux)
    156  1.1      soda {
    157  1.7   tsutsui 	struct mc146818_softc *sc = (void *)self;
    158  1.1      soda 	struct isa_attach_args *ia = aux;
    159  1.1      soda 
    160  1.7   tsutsui 	sc->sc_bst = ia->ia_iot;
    161  1.7   tsutsui 	if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr,
    162  1.7   tsutsui 	    ia->ia_io[0].ir_size, 0, &sc->sc_bsh))
    163  1.1      soda 		panic("mcclock_isa_attach: couldn't map clock I/O space");
    164  1.1      soda 
    165  1.7   tsutsui 	sc->sc_year0 = 1980;
    166  1.7   tsutsui 	sc->sc_mcread  = mc_isa_read;
    167  1.7   tsutsui 	sc->sc_mcwrite = mc_isa_write;
    168  1.7   tsutsui 
    169  1.7   tsutsui 	mc146818_attach(sc);
    170  1.7   tsutsui 
    171  1.7   tsutsui 	printf("\n");
    172  1.1      soda 
    173  1.1      soda 	/* Turn interrupts off, just in case. */
    174  1.7   tsutsui 	mc_isa_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
    175  1.7   tsutsui 
    176  1.7   tsutsui 	todr_attach(&sc->sc_handle);
    177  1.1      soda }
    178  1.1      soda 
    179  1.1      soda u_int
    180  1.9   tsutsui mc_isa_read(struct mc146818_softc *sc, u_int reg)
    181  1.1      soda {
    182  1.1      soda 
    183  1.7   tsutsui 	bus_space_write_1(sc->sc_bst, sc->sc_bsh, 0, reg);
    184  1.7   tsutsui 	return bus_space_read_1(sc->sc_bst, sc->sc_bsh, 1);
    185  1.1      soda }
    186  1.1      soda 
    187  1.1      soda void
    188  1.9   tsutsui mc_isa_write(struct mc146818_softc *sc, u_int reg, u_int datum)
    189  1.1      soda {
    190  1.1      soda 
    191  1.7   tsutsui 	bus_space_write_1(sc->sc_bst, sc->sc_bsh, 0, reg);
    192  1.7   tsutsui 	bus_space_write_1(sc->sc_bst, sc->sc_bsh, 1, datum);
    193  1.1      soda }
    194  1.1      soda 
    195