xref: /netbsd-src/sys/arch/arc/jazz/timer_jazzio.c (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: timer_jazzio.c,v 1.8 2005/12/11 12:16:39 christos 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.8 2005/12/11 12:16:39 christos 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 struct timer_jazzio_softc {
100 	struct device	sc_dev;
101 };
102 
103 /* Definition of the driver for autoconfig. */
104 int timer_jazzio_match(struct device *, struct cfdata *, void *);
105 void timer_jazzio_attach(struct device *, struct device *, void *);
106 
107 CFATTACH_DECL(timer_jazzio, sizeof(struct timer_jazzio_softc),
108     timer_jazzio_match, timer_jazzio_attach, NULL, NULL);
109 
110 /* Jazz timer access code */
111 void timer_jazzio_init(struct device *sc);
112 
113 struct timerfns timerfns_jazzio = {
114 	timer_jazzio_init,
115 };
116 
117 struct timer_jazzio_config *timer_jazzio_conf = NULL;
118 int timer_jazzio_found = 0;
119 struct evcnt timer_jazzio_ev =
120     EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "jazzio", "timer");
121 
122 int
123 timer_jazzio_match(struct device *parent, struct cfdata *match, void *aux)
124 {
125 	struct jazzio_attach_args *ja = aux;
126 
127 	/* make sure that we're looking for this type of device. */
128 	if (strcmp(ja->ja_name, "timer") != 0)
129 		return 0;
130 
131 	if (timer_jazzio_found)
132 		return 0;
133 
134 	return 1;
135 }
136 
137 void
138 timer_jazzio_attach(struct device *parent, struct device *self, void *aux)
139 {
140 	struct timer_jazzio_softc *sc = (struct timer_jazzio_softc *)self;
141 
142 	if (timer_jazzio_conf == NULL)
143 		panic("timer_jazzio_conf isn't initialized");
144 
145 	printf("\n");
146 
147 	evcnt_attach_static(&timer_jazzio_ev);
148 	(*platform->set_intr)(timer_jazzio_conf->tjc_intr_mask,
149 	    timer_jazzio_conf->tjc_intr, 1);
150 
151 	timerattach(&sc->sc_dev, &timerfns_jazzio);
152 
153 	timer_jazzio_found = 1;
154 }
155 
156 void
157 timer_jazzio_init(struct device *sc)
158 {
159 
160 	(*timer_jazzio_conf->tjc_init)(1000 / hz);
161 }
162