Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / news68k / dev / timer_hb.c
blob28ba94f63d4870e50add6392e0a204f58b37c57f
1 /* $NetBSD: timer_hb.c,v 1.15 2008/04/28 20:23:30 martin Exp $ */
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: timer_hb.c,v 1.15 2008/04/28 20:23:30 martin Exp $");
35 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/intr.h>
41 #include <uvm/uvm_extern.h>
43 #include <machine/cpu.h>
44 #include <machine/bus.h>
46 #include <dev/clock_subr.h>
48 #include <news68k/news68k/isr.h>
49 #include <news68k/news68k/clockvar.h>
51 #include <news68k/dev/hbvar.h>
53 #include "ioconf.h"
56 * interrupt level for clock
59 #define TIMER_LEVEL 6
60 #define TIMER_SIZE 8 /* XXX */
62 static int timer_hb_match(device_t, cfdata_t, void *);
63 static void timer_hb_attach(device_t, device_t, void *);
64 static void timer_hb_initclocks(int, int);
65 void clock_intr(struct clockframe *);
67 static inline void leds_intr(void);
69 extern void _isr_clock(void); /* locore.s */
71 CFATTACH_DECL_NEW(timer_hb, 0,
72 timer_hb_match, timer_hb_attach, NULL, NULL);
74 static volatile uint8_t *ctrl_timer; /* XXX */
76 extern volatile u_char *ctrl_led; /* XXX */
78 static int
79 timer_hb_match(device_t parent, cfdata_t cf, void *aux)
81 struct hb_attach_args *ha = aux;
82 static int timer_hb_matched;
84 /* Only one timer, please. */
85 if (timer_hb_matched)
86 return 0;
88 if (strcmp(ha->ha_name, timer_cd.cd_name))
89 return 0;
91 if (ha->ha_ipl == -1)
92 ha->ha_ipl = TIMER_LEVEL;
94 ha->ha_size = TIMER_SIZE;
96 timer_hb_matched = 1;
98 return 1;
101 static void
102 timer_hb_attach(device_t parent, device_t self, void *aux)
104 struct hb_attach_args *ha = aux;
106 if (ha->ha_ipl != TIMER_LEVEL)
107 panic("clock_hb_attach: wrong interrupt level");
109 ctrl_timer = (uint8_t *)IIOV(ha->ha_address); /* XXX needs bus_space */
111 printf("\n");
113 timer_config(timer_hb_initclocks);
115 #if 0 /* XXX this will be done in timer_hb_initclocks() */
116 isrlink_custom(ha->ha_ipl, (void *)_isr_clock);
117 #endif
121 * Set up the interval timer (enable clock interrupts).
122 * Leave stathz 0 since there is no secondary clock available.
123 * Note that clock interrupts MUST STAY DISABLED until here.
125 static void
126 timer_hb_initclocks(int prof, int stat)
128 int s;
130 s = splhigh();
132 /* Install isr (in locore.s) that calls clock_intr(). */
133 isrlink_custom(TIMER_LEVEL, (void *)_isr_clock);
135 /* enable the clock */
136 *ctrl_timer = 1;
137 splx(s);
141 * Clock interrupt handler.
142 * This is is called by the "custom" interrupt handler.
144 * from sun3/sun3x/clock.c -tsutsui
146 void
147 clock_intr(struct clockframe *cf)
149 #ifdef LED_IDLE_CHECK
150 extern char _Idle[]; /* locore.s */
151 #endif
153 /* Pulse the clock intr. enable low. */
154 *ctrl_timer = 0;
155 *ctrl_timer = 1;
156 intrcnt[TIMER_LEVEL]++;
158 /* Entertainment! */
159 #ifdef LED_IDLE_CHECK
160 if (cf.cf_pc == (long)_Idle)
161 #endif
162 leds_intr();
164 /* Call common clock interrupt handler. */
165 hardclock(cf);
166 uvmexp.intrs++;
169 /* heartbeat LED */
170 #define LED0 0x01
171 #define LED1 0x02
173 static inline void
174 leds_intr(void)
176 static u_char led_countdown, led_stat;
177 u_char i;
179 if (led_countdown) {
180 led_countdown--;
181 return;
184 i = led_stat ^ LED0;
185 *ctrl_led = i;
186 led_stat = i;
187 led_countdown = hz;