Home | History | Annotate | Line # | Download | only in jazz
      1 /*	$NetBSD: timer_jazzio.c,v 1.11 2012/10/27 17:17:35 chs Exp $	*/
      2 /*	$OpenBSD: clock.c,v 1.6 1998/10/15 21:30:15 imp Exp $	*/
      3 
      4 /*
      5  * Copyright (c) 1992, 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * the Systems Programming Group of the University of Utah Computer
     10  * Science Department and Ralph Campbell.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  * from: Utah Hdr: clock.c 1.18 91/01/21
     37  *
     38  *	from: @(#)clock.c	8.1 (Berkeley) 6/10/93
     39  */
     40 
     41 /*
     42  * Copyright (c) 1997 Per Fogelstrom.
     43  * Copyright (c) 1988 University of Utah.
     44  *
     45  * This code is derived from software contributed to Berkeley by
     46  * the Systems Programming Group of the University of Utah Computer
     47  * Science Department and Ralph Campbell.
     48  *
     49  * Redistribution and use in source and binary forms, with or without
     50  * modification, are permitted provided that the following conditions
     51  * are met:
     52  * 1. Redistributions of source code must retain the above copyright
     53  *    notice, this list of conditions and the following disclaimer.
     54  * 2. Redistributions in binary form must reproduce the above copyright
     55  *    notice, this list of conditions and the following disclaimer in the
     56  *    documentation and/or other materials provided with the distribution.
     57  * 3. All advertising materials mentioning features or use of this software
     58  *    must display the following acknowledgement:
     59  *	This product includes software developed by the University of
     60  *	California, Berkeley and its contributors.
     61  * 4. Neither the name of the University nor the names of its contributors
     62  *    may be used to endorse or promote products derived from this software
     63  *    without specific prior written permission.
     64  *
     65  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     66  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     67  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     68  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     69  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     70  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     71  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     72  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     73  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     74  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     75  * SUCH DAMAGE.
     76  *
     77  * from: Utah Hdr: clock.c 1.18 91/01/21
     78  *
     79  *	from: @(#)clock.c	8.1 (Berkeley) 6/10/93
     80  */
     81 
     82 #include <sys/cdefs.h>
     83 __KERNEL_RCSID(0, "$NetBSD: timer_jazzio.c,v 1.11 2012/10/27 17:17:35 chs Exp $");
     84 
     85 #include <sys/param.h>
     86 #include <sys/kernel.h>
     87 #include <sys/systm.h>
     88 #include <sys/device.h>
     89 
     90 #include <machine/autoconf.h>
     91 #include <machine/platform.h>
     92 
     93 #include <dev/isa/isavar.h>
     94 
     95 #include <arc/arc/timervar.h>
     96 #include <arc/jazz/jazziovar.h>
     97 #include <arc/jazz/timer_jazziovar.h>
     98 
     99 /* Definition of the driver for autoconfig. */
    100 static int timer_jazzio_match(device_t , cfdata_t, void *);
    101 static void timer_jazzio_attach(device_t , device_t , void *);
    102 
    103 CFATTACH_DECL_NEW(timer_jazzio, 0,
    104     timer_jazzio_match, timer_jazzio_attach, NULL, NULL);
    105 
    106 /* Jazz timer access code */
    107 static void timer_jazzio_init(device_t);
    108 
    109 struct timerfns timerfns_jazzio = {
    110 	timer_jazzio_init,
    111 };
    112 
    113 struct timer_jazzio_config *timer_jazzio_conf = NULL;
    114 struct evcnt timer_jazzio_ev =
    115     EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "jazzio", "timer");
    116 
    117 static int timer_jazzio_found = 0;
    118 
    119 static int
    120 timer_jazzio_match(device_t parent, cfdata_t cf, void *aux)
    121 {
    122 	struct jazzio_attach_args *ja = aux;
    123 
    124 	/* make sure that we're looking for this type of device. */
    125 	if (strcmp(ja->ja_name, "timer") != 0)
    126 		return 0;
    127 
    128 	if (timer_jazzio_found)
    129 		return 0;
    130 
    131 	return 1;
    132 }
    133 
    134 static void
    135 timer_jazzio_attach(device_t parent, device_t self, void *aux)
    136 {
    137 
    138 	if (timer_jazzio_conf == NULL)
    139 		panic("timer_jazzio_conf isn't initialized");
    140 
    141 	aprint_normal("\n");
    142 
    143 	evcnt_attach_static(&timer_jazzio_ev);
    144 	(*platform->set_intr)(timer_jazzio_conf->tjc_intr_mask,
    145 	    timer_jazzio_conf->tjc_intr, ARC_INTPRI_TIMER_INT);
    146 
    147 	timerattach(self, &timerfns_jazzio);
    148 
    149 	timer_jazzio_found = 1;
    150 }
    151 
    152 void
    153 timer_jazzio_init(device_t sc)
    154 {
    155 
    156 	(*timer_jazzio_conf->tjc_init)(1000 / hz);
    157 }
    158