Home | History | Annotate | Line # | Download | only in isa
mcclock_isa.c revision 1.8
      1  1.8  drochner /*	$NetBSD: mcclock_isa.c,v 1.8 2004/09/14 20:32:48 drochner 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.8  drochner __KERNEL_RCSID(0, "$NetBSD: mcclock_isa.c,v 1.8 2004/09/14 20:32:48 drochner 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.1      soda mcclock_isa_match(parent, match, aux)
    114  1.1      soda 	struct device *parent;
    115  1.1      soda 	struct cfdata *match;
    116  1.1      soda 	void *aux;
    117  1.1      soda {
    118  1.1      soda 	struct isa_attach_args *ia = aux;
    119  1.1      soda 	bus_space_handle_t ioh;
    120  1.1      soda 
    121  1.2   thorpej 	if (ia->ia_nio < 1 ||
    122  1.8  drochner 	    (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT &&
    123  1.2   thorpej 	     ia->ia_io[0].ir_addr != 0x70))
    124  1.2   thorpej 		return (0);
    125  1.2   thorpej 
    126  1.2   thorpej 	if (ia->ia_niomem > 0 &&
    127  1.8  drochner 	    (ia->ia_iomem[0].ir_addr != ISA_UNKNOWN_IOMEM))
    128  1.2   thorpej 		return (0);
    129  1.2   thorpej 
    130  1.2   thorpej 	if (ia->ia_nirq > 0 &&
    131  1.8  drochner 	    (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ))
    132  1.2   thorpej 		return (0);
    133  1.2   thorpej 
    134  1.2   thorpej 	if (ia->ia_ndrq > 0 &&
    135  1.8  drochner 	    (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ))
    136  1.1      soda 		return (0);
    137  1.1      soda 
    138  1.1      soda 	if (!mcclock_isa_conf)
    139  1.1      soda 		return (0);
    140  1.1      soda 
    141  1.2   thorpej 	if (bus_space_map(ia->ia_iot, 0x70, 0x02, 0, &ioh))
    142  1.1      soda 		return (0);
    143  1.1      soda 
    144  1.2   thorpej 	bus_space_unmap(ia->ia_iot, ioh, 0x02);
    145  1.1      soda 
    146  1.2   thorpej 	ia->ia_nio = 1;
    147  1.2   thorpej 	ia->ia_io[0].ir_addr = 0x70;
    148  1.2   thorpej 	ia->ia_io[0].ir_size = 0x02;
    149  1.2   thorpej 
    150  1.2   thorpej 	ia->ia_niomem = 0;
    151  1.2   thorpej 	ia->ia_nirq = 0;
    152  1.2   thorpej 	ia->ia_ndrq = 0;
    153  1.1      soda 
    154  1.1      soda 	return (1);
    155  1.1      soda }
    156  1.1      soda 
    157  1.1      soda void
    158  1.1      soda mcclock_isa_attach(parent, self, aux)
    159  1.1      soda 	struct device *parent;
    160  1.1      soda 	struct device *self;
    161  1.1      soda 	void *aux;
    162  1.1      soda {
    163  1.7   tsutsui 	struct mc146818_softc *sc = (void *)self;
    164  1.1      soda 	struct isa_attach_args *ia = aux;
    165  1.1      soda 
    166  1.7   tsutsui 	sc->sc_bst = ia->ia_iot;
    167  1.7   tsutsui 	if (bus_space_map(sc->sc_bst, ia->ia_io[0].ir_addr,
    168  1.7   tsutsui 	    ia->ia_io[0].ir_size, 0, &sc->sc_bsh))
    169  1.1      soda 		panic("mcclock_isa_attach: couldn't map clock I/O space");
    170  1.1      soda 
    171  1.7   tsutsui 	sc->sc_year0 = 1980;
    172  1.7   tsutsui 	sc->sc_mcread  = mc_isa_read;
    173  1.7   tsutsui 	sc->sc_mcwrite = mc_isa_write;
    174  1.7   tsutsui 
    175  1.7   tsutsui 	mc146818_attach(sc);
    176  1.7   tsutsui 
    177  1.7   tsutsui 	printf("\n");
    178  1.1      soda 
    179  1.1      soda 	/* Turn interrupts off, just in case. */
    180  1.7   tsutsui 	mc_isa_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
    181  1.7   tsutsui 
    182  1.7   tsutsui 	todr_attach(&sc->sc_handle);
    183  1.1      soda }
    184  1.1      soda 
    185  1.1      soda u_int
    186  1.1      soda mc_isa_read(sc, reg)
    187  1.7   tsutsui 	struct mc146818_softc *sc;
    188  1.1      soda 	u_int reg;
    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 	return bus_space_read_1(sc->sc_bst, sc->sc_bsh, 1);
    193  1.1      soda }
    194  1.1      soda 
    195  1.1      soda void
    196  1.1      soda mc_isa_write(sc, reg, datum)
    197  1.7   tsutsui 	struct mc146818_softc *sc;
    198  1.1      soda 	u_int reg, datum;
    199  1.1      soda {
    200  1.1      soda 
    201  1.7   tsutsui 	bus_space_write_1(sc->sc_bst, sc->sc_bsh, 0, reg);
    202  1.7   tsutsui 	bus_space_write_1(sc->sc_bst, sc->sc_bsh, 1, datum);
    203  1.1      soda }
    204  1.1      soda 
    205