2001-04-14 17:53:05 +04:00
|
|
|
/* $NetBSD: clock_pcc.c,v 1.7 2001/04/14 13:53:05 scw Exp $ */
|
1996-04-26 22:59:58 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
1997-10-09 12:37:20 +04:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1996-04-26 22:59:58 +04:00
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Glue for the Peripheral Channel Controller timers and the
|
|
|
|
* Mostek clock chip found on the MVME-147.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <machine/psl.h>
|
2000-03-19 01:33:02 +03:00
|
|
|
#include <machine/bus.h>
|
1996-04-26 22:59:58 +04:00
|
|
|
|
|
|
|
#include <mvme68k/mvme68k/clockreg.h>
|
|
|
|
#include <mvme68k/mvme68k/clockvar.h>
|
|
|
|
#include <mvme68k/dev/pccreg.h>
|
|
|
|
#include <mvme68k/dev/pccvar.h>
|
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
int clock_pcc_match __P((struct device *, struct cfdata *, void *));
|
|
|
|
void clock_pcc_attach __P((struct device *, struct device *, void *));
|
1996-04-26 22:59:58 +04:00
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
struct clock_pcc_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
struct clock_attach_args sc_clock_args;
|
|
|
|
u_char sc_clock_lvl;
|
|
|
|
};
|
1996-04-26 22:59:58 +04:00
|
|
|
|
|
|
|
struct cfattach clock_pcc_ca = {
|
2000-03-19 01:33:02 +03:00
|
|
|
sizeof(struct clock_pcc_softc), clock_pcc_match, clock_pcc_attach
|
1996-04-26 22:59:58 +04:00
|
|
|
};
|
|
|
|
|
1998-01-12 22:51:03 +03:00
|
|
|
extern struct cfdriver clock_cd;
|
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
|
|
|
|
static int clock_pcc_profintr __P((void *));
|
|
|
|
static int clock_pcc_statintr __P((void *));
|
|
|
|
static void clock_pcc_initclocks __P((void *, int, int));
|
2001-04-14 17:53:05 +04:00
|
|
|
static long clock_pcc_microtime __P((void *));
|
2000-03-19 01:33:02 +03:00
|
|
|
static void clock_pcc_shutdown __P((void *));
|
|
|
|
|
|
|
|
static struct clock_pcc_softc *clock_pcc_sc;
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
1996-04-26 22:59:58 +04:00
|
|
|
int
|
1997-03-19 19:24:38 +03:00
|
|
|
clock_pcc_match(parent, cf, aux)
|
1996-04-26 22:59:58 +04:00
|
|
|
struct device *parent;
|
1997-03-19 19:24:38 +03:00
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1996-04-26 22:59:58 +04:00
|
|
|
{
|
2000-03-19 01:33:02 +03:00
|
|
|
struct pcc_attach_args *pa;
|
|
|
|
|
|
|
|
pa = aux;
|
1996-04-26 22:59:58 +04:00
|
|
|
|
|
|
|
/* Only one clock, please. */
|
2000-03-19 01:33:02 +03:00
|
|
|
if (clock_pcc_sc)
|
1996-04-26 22:59:58 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (strcmp(pa->pa_name, clock_cd.cd_name))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
pa->pa_ipl = cf->pcccf_ipl;
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
/* ARGSUSED */
|
1996-04-26 22:59:58 +04:00
|
|
|
void
|
|
|
|
clock_pcc_attach(parent, self, aux)
|
2000-03-19 01:33:02 +03:00
|
|
|
struct device *parent;
|
|
|
|
struct device *self;
|
1996-04-26 22:59:58 +04:00
|
|
|
void *aux;
|
|
|
|
{
|
2000-03-19 01:33:02 +03:00
|
|
|
struct pcc_attach_args *pa;
|
|
|
|
struct clock_pcc_softc *sc;
|
|
|
|
|
|
|
|
sc = (struct clock_pcc_softc *) self;
|
|
|
|
pa = aux;
|
1996-04-26 22:59:58 +04:00
|
|
|
|
|
|
|
if (pa->pa_ipl != CLOCK_LEVEL)
|
|
|
|
panic("clock_pcc_attach: wrong interrupt level");
|
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
clock_pcc_sc = sc;
|
|
|
|
|
|
|
|
/* Map the RTC's registers */
|
|
|
|
sc->sc_clock_args.ca_bust = pa->pa_bust;
|
|
|
|
bus_space_map(pa->pa_bust, pa->pa_offset,
|
|
|
|
MK48T_REGSIZE, 0, &sc->sc_clock_args.ca_bush);
|
|
|
|
|
|
|
|
sc->sc_clock_args.ca_arg = sc;
|
|
|
|
sc->sc_clock_args.ca_initfunc = clock_pcc_initclocks;
|
2001-04-14 17:53:05 +04:00
|
|
|
sc->sc_clock_args.ca_microtime = clock_pcc_microtime;
|
1996-04-26 22:59:58 +04:00
|
|
|
|
|
|
|
/* Do common portions of clock config. */
|
2000-03-19 01:33:02 +03:00
|
|
|
clock_config(self, &sc->sc_clock_args);
|
1996-04-26 22:59:58 +04:00
|
|
|
|
1996-09-12 09:10:44 +04:00
|
|
|
/* Ensure our interrupts get disabled at shutdown time. */
|
2000-03-19 01:33:02 +03:00
|
|
|
(void) shutdownhook_establish(clock_pcc_shutdown, NULL);
|
1996-09-12 09:10:44 +04:00
|
|
|
|
|
|
|
/* Attach the interrupt handlers. */
|
|
|
|
pccintr_establish(PCCV_TIMER1, clock_pcc_profintr, pa->pa_ipl, NULL);
|
|
|
|
pccintr_establish(PCCV_TIMER2, clock_pcc_statintr, pa->pa_ipl, NULL);
|
2000-03-19 01:33:02 +03:00
|
|
|
sc->sc_clock_lvl = pa->pa_ipl | PCC_IENABLE | PCC_TIMERACK;
|
1996-04-26 22:59:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-03-19 01:33:02 +03:00
|
|
|
clock_pcc_initclocks(arg, proftick, stattick)
|
|
|
|
void *arg;
|
|
|
|
int proftick;
|
|
|
|
int stattick;
|
1996-04-26 22:59:58 +04:00
|
|
|
{
|
2000-03-19 01:33:02 +03:00
|
|
|
struct clock_pcc_softc *sc = arg;
|
|
|
|
|
|
|
|
pcc_reg_write16(sys_pcc, PCCREG_TMR1_PRELOAD,
|
|
|
|
pcc_timer_us2lim(proftick));
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR1_CONTROL, PCC_TIMERCLEAR);
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR1_CONTROL, PCC_TIMERSTART);
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR1_INTR_CTRL, sc->sc_clock_lvl);
|
|
|
|
|
|
|
|
pcc_reg_write16(sys_pcc, PCCREG_TMR2_PRELOAD,
|
|
|
|
pcc_timer_us2lim(stattick));
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR2_CONTROL, PCC_TIMERCLEAR);
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR2_CONTROL, PCC_TIMERSTART);
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR2_INTR_CTRL, sc->sc_clock_lvl);
|
1996-04-26 22:59:58 +04:00
|
|
|
}
|
|
|
|
|
2001-04-14 17:53:05 +04:00
|
|
|
/* ARGSUSED */
|
|
|
|
long
|
|
|
|
clock_pcc_microtime(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
static int ovfl_adj[] = {
|
|
|
|
0, 10000, 20000, 30000,
|
|
|
|
40000, 50000, 60000, 70000,
|
|
|
|
80000, 90000, 100000, 110000,
|
|
|
|
120000, 130000, 140000, 150000};
|
|
|
|
u_int8_t cr;
|
|
|
|
u_int16_t tc, tc2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There's no way to latch the counter and overflow registers
|
|
|
|
* without pausing the clock, so compensate for the possible
|
|
|
|
* race by checking for counter wrap-around and re-reading the
|
|
|
|
* overflow counter if necessary.
|
|
|
|
*
|
|
|
|
* Note: This only works because we're called at splhigh().
|
|
|
|
*/
|
|
|
|
tc = pcc_reg_read16(sys_pcc, PCCREG_TMR1_COUNT);
|
|
|
|
cr = pcc_reg_read(sys_pcc, PCCREG_TMR1_CONTROL);
|
|
|
|
if (tc > (tc2 = pcc_reg_read16(sys_pcc, PCCREG_TMR1_COUNT))) {
|
|
|
|
cr = pcc_reg_read(sys_pcc, PCCREG_TMR1_CONTROL);
|
|
|
|
tc = tc2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((long) pcc_timer_cnt2us(tc) + ovfl_adj[cr>>PCC_TIMEROVFLSHIFT]);
|
|
|
|
}
|
|
|
|
|
1996-04-26 22:59:58 +04:00
|
|
|
int
|
1996-09-12 09:10:44 +04:00
|
|
|
clock_pcc_profintr(frame)
|
1996-04-26 22:59:58 +04:00
|
|
|
void *frame;
|
|
|
|
{
|
2001-04-14 17:53:05 +04:00
|
|
|
u_int8_t cr;
|
|
|
|
u_int16_t tc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
tc = pcc_reg_read16(sys_pcc, PCCREG_TMR1_COUNT);
|
|
|
|
cr = pcc_reg_read(sys_pcc, PCCREG_TMR1_CONTROL);
|
|
|
|
if (tc > pcc_reg_read16(sys_pcc, PCCREG_TMR1_COUNT))
|
|
|
|
cr = pcc_reg_read(sys_pcc, PCCREG_TMR1_CONTROL);
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR1_CONTROL, PCC_TIMERSTART);
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR1_INTR_CTRL,
|
|
|
|
clock_pcc_sc->sc_clock_lvl);
|
2001-04-14 17:53:05 +04:00
|
|
|
__asm __volatile("movw %0,%%sr" : : "di" (s));
|
|
|
|
|
|
|
|
for (cr >>= PCC_TIMEROVFLSHIFT; cr; cr--) {
|
|
|
|
hardclock(frame);
|
|
|
|
clock_profcnt.ev_count++;
|
|
|
|
}
|
|
|
|
|
1996-09-12 09:10:44 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
clock_pcc_statintr(frame)
|
|
|
|
void *frame;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Disable the timer interrupt while we handle it. */
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR2_INTR_CTRL, 0);
|
|
|
|
|
|
|
|
statclock((struct clockframe *) frame);
|
2001-04-14 17:53:05 +04:00
|
|
|
clock_statcnt.ev_count++;
|
1996-09-12 09:10:44 +04:00
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc_reg_write16(sys_pcc, PCCREG_TMR2_PRELOAD,
|
|
|
|
pcc_timer_us2lim(CLOCK_NEWINT(clock_statvar, clock_statmin)));
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR2_CONTROL, PCC_TIMERCLEAR);
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR2_CONTROL, PCC_TIMERSTART);
|
1996-09-12 09:10:44 +04:00
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR2_INTR_CTRL,
|
|
|
|
clock_pcc_sc->sc_clock_lvl);
|
1996-09-12 09:10:44 +04:00
|
|
|
|
1996-04-26 22:59:58 +04:00
|
|
|
return (1);
|
|
|
|
}
|
1996-09-12 09:10:44 +04:00
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
|
|
|
clock_pcc_shutdown(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Make sure the timer interrupts are turned off. */
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR1_CONTROL, PCC_TIMERCLEAR);
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR1_INTR_CTRL, 0);
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR2_CONTROL, PCC_TIMERCLEAR);
|
|
|
|
pcc_reg_write(sys_pcc, PCCREG_TMR2_INTR_CTRL, 0);
|
1996-09-12 09:10:44 +04:00
|
|
|
}
|