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