Home | History | Annotate | Line # | Download | only in jazz
mcclock_jazzio.c revision 1.5
      1 /*	$NetBSD: mcclock_jazzio.c,v 1.5 2003/08/07 16:26:51 agc 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_jazzio.c,v 1.5 2003/08/07 16:26:51 agc Exp $");
     83 
     84 #include <sys/param.h>
     85 #include <sys/systm.h>
     86 #include <sys/device.h>
     87 
     88 #include <machine/autoconf.h>
     89 #include <machine/bus.h>
     90 
     91 #include <dev/ic/mc146818reg.h>
     92 
     93 #include <arc/dev/mcclockvar.h>
     94 #include <arc/jazz/jazziovar.h>
     95 #include <arc/jazz/mcclock_jazziovar.h>
     96 
     97 int mcclock_jazzio_match __P((struct device *, struct cfdata *, void *));
     98 void mcclock_jazzio_attach __P((struct device *, struct device *, void *));
     99 
    100 CFATTACH_DECL(mcclock_jazzio, sizeof(struct mcclock_softc),
    101     mcclock_jazzio_match, mcclock_jazzio_attach, NULL, NULL);
    102 
    103 struct mcclock_jazzio_config *mcclock_jazzio_conf = NULL;
    104 int mcclock_jazzio_found = 0;
    105 
    106 int
    107 mcclock_jazzio_match(parent, match, aux)
    108 	struct device *parent;
    109 	struct cfdata *match;
    110 	void *aux;
    111 {
    112 	struct jazzio_attach_args *ja = aux;
    113 
    114 	/* make sure that we're looking for this type of device. */
    115 	if (strcmp(ja->ja_name, "dallas_rtc") != 0)
    116 		return (0);
    117 
    118 	if (mcclock_jazzio_found)
    119 		return (0);
    120 
    121 	return (1);
    122 }
    123 
    124 void
    125 mcclock_jazzio_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 jazzio_attach_args *ja = aux;
    132 
    133 	if (mcclock_jazzio_conf == NULL)
    134 		panic("mcclock_jazzio_conf isn't initialized");
    135 
    136 	sc->sc_iot = ja->ja_bust;
    137 	if (bus_space_map(sc->sc_iot,
    138 	    ja->ja_addr, mcclock_jazzio_conf->mjc_iosize, 0, &sc->sc_ioh)) {
    139 		printf(": unable to map I/O space\n");
    140 		return;
    141 	}
    142 
    143 	mcclock_attach(sc, &mcclock_jazzio_conf->mjc_mcbusfns, 80);
    144 
    145 	/* Turn interrupts off, just in case. */
    146 	mc146818_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
    147 
    148 	mcclock_jazzio_found = 1;
    149 }
    150