2009-03-14 18:35:58 +03:00
|
|
|
/* $NetBSD: clock_pcctwo.c,v 1.14 2009/03/14 15:36:19 dsl Exp $ */
|
1999-02-14 20:54:27 +03:00
|
|
|
|
|
|
|
/*-
|
2002-02-12 23:38:09 +03:00
|
|
|
* Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
|
1999-02-14 20:54:27 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Steve C. Woodford.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
Add preliminary support for the MVME162-LX 200/300 series of boards.
Currently, the major onboard devices are supported (disk, network,
rs232 and VMEbus). However, work is still need to support the remaining
devices (eg. IndustryPack sites).
These boards are available with a dazzling array of build options. At
this time, the following options are *required*:
o Real floating point hardware (the 68LC040 model isn't tested),
o The VMEchip2 must be present,
o If offboard VMEbus RAM is not present, at least 8MB of onboard
RAM is required.
o Even if offboard VMEbus RAM *is* present, at least 4MB of onboard
RAM is required. (Boards with 1 or 2MB onboard RAM *can* be
supported with offboard RAM, but not without some funky values in
the VMEbus Master mapping registers.)
There is no support for boards other than those in the -LX 200/300 series.
2000-09-06 23:51:42 +04:00
|
|
|
* Glue for the Peripheral Channel Controller Two (PCCChip2) timers,
|
|
|
|
* the Memory Controller ASIC (MCchip, and the Mostek clock chip found
|
2002-02-12 23:38:09 +03:00
|
|
|
* on the MVME-1[67]7, MVME-1[67]2 and MVME-187 series of boards.
|
1999-02-14 20:54:27 +03:00
|
|
|
*/
|
|
|
|
|
2003-07-14 19:47:00 +04:00
|
|
|
#include <sys/cdefs.h>
|
2009-03-14 18:35:58 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: clock_pcctwo.c,v 1.14 2009/03/14 15:36:19 dsl Exp $");
|
2003-07-14 19:47:00 +04:00
|
|
|
|
1999-02-14 20:54:27 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/device.h>
|
2008-01-07 17:39:28 +03:00
|
|
|
#include <sys/timetc.h>
|
1999-02-14 20:54:27 +03:00
|
|
|
|
|
|
|
#include <machine/psl.h>
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
1999-02-14 20:54:27 +03:00
|
|
|
|
2002-02-12 23:38:09 +03:00
|
|
|
#include <dev/mvme/clockvar.h>
|
|
|
|
#include <dev/mvme/pcctwovar.h>
|
|
|
|
#include <dev/mvme/pcctworeg.h>
|
1999-02-14 20:54:27 +03:00
|
|
|
|
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
int clock_pcctwo_match(struct device *, struct cfdata *, void *);
|
|
|
|
void clock_pcctwo_attach(struct device *, struct device *, void *);
|
1999-02-14 20:54:27 +03:00
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
struct clock_pcctwo_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
struct clock_attach_args sc_clock_args;
|
|
|
|
u_char sc_clock_lvl;
|
2008-01-07 17:39:28 +03:00
|
|
|
struct timecounter sc_tc;
|
2000-03-19 01:33:02 +03:00
|
|
|
};
|
1999-02-14 20:54:27 +03:00
|
|
|
|
2005-04-14 16:36:38 +04:00
|
|
|
CFATTACH_DECL(clock_pcctwo, sizeof(struct clock_pcctwo_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
clock_pcctwo_match, clock_pcctwo_attach, NULL, NULL);
|
1999-02-14 20:54:27 +03:00
|
|
|
|
|
|
|
extern struct cfdriver clock_cd;
|
|
|
|
|
2005-02-04 05:10:35 +03:00
|
|
|
static int clock_pcctwo_profintr(void *);
|
|
|
|
static int clock_pcctwo_statintr(void *);
|
|
|
|
static void clock_pcctwo_initclocks(void *, int, int);
|
2008-01-07 17:39:28 +03:00
|
|
|
static u_int clock_pcctwo_getcount(struct timecounter *);
|
2005-02-04 05:10:35 +03:00
|
|
|
static void clock_pcctwo_shutdown(void *);
|
2000-03-19 01:33:02 +03:00
|
|
|
|
|
|
|
static struct clock_pcctwo_softc *clock_pcctwo_sc;
|
2008-01-07 17:39:28 +03:00
|
|
|
static uint32_t clock_pcctwo_count;
|
2000-03-19 01:33:02 +03:00
|
|
|
|
|
|
|
/* ARGSUSED */
|
1999-02-14 20:54:27 +03:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
clock_pcctwo_match(struct device *parent, struct cfdata *cf, void *aux)
|
1999-02-14 20:54:27 +03:00
|
|
|
{
|
2000-03-19 01:33:02 +03:00
|
|
|
struct pcctwo_attach_args *pa = aux;
|
1999-02-14 20:54:27 +03:00
|
|
|
|
|
|
|
/* Only one clock, please. */
|
2000-03-19 01:33:02 +03:00
|
|
|
if (clock_pcctwo_sc)
|
1999-02-14 20:54:27 +03:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (strcmp(pa->pa_name, clock_cd.cd_name))
|
|
|
|
return (0);
|
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
pa->pa_ipl = cf->pcctwocf_ipl;
|
1999-02-14 20:54:27 +03:00
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
/* ARGSUSED */
|
1999-02-14 20:54:27 +03:00
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
clock_pcctwo_attach(struct device *parent, struct device *self, void *aux)
|
1999-02-14 20:54:27 +03:00
|
|
|
{
|
2000-03-19 01:33:02 +03:00
|
|
|
struct clock_pcctwo_softc *sc;
|
|
|
|
struct pcctwo_attach_args *pa;
|
|
|
|
|
2006-03-29 10:51:47 +04:00
|
|
|
sc = clock_pcctwo_sc = device_private(self);
|
2000-03-19 01:33:02 +03:00
|
|
|
pa = aux;
|
1999-02-14 20:54:27 +03:00
|
|
|
|
|
|
|
if (pa->pa_ipl != CLOCK_LEVEL)
|
|
|
|
panic("clock_pcctwo_attach: wrong interrupt level");
|
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
sc->sc_clock_args.ca_arg = sc;
|
|
|
|
sc->sc_clock_args.ca_initfunc = clock_pcctwo_initclocks;
|
1999-02-14 20:54:27 +03:00
|
|
|
|
|
|
|
/* Do common portions of clock config. */
|
2001-08-12 22:33:12 +04:00
|
|
|
clock_config(self, &sc->sc_clock_args, pcctwointr_evcnt(pa->pa_ipl));
|
1999-02-14 20:54:27 +03:00
|
|
|
|
|
|
|
/* Ensure our interrupts get disabled at shutdown time. */
|
2000-03-19 01:33:02 +03:00
|
|
|
(void) shutdownhook_establish(clock_pcctwo_shutdown, NULL);
|
1999-02-14 20:54:27 +03:00
|
|
|
|
Add preliminary support for the MVME162-LX 200/300 series of boards.
Currently, the major onboard devices are supported (disk, network,
rs232 and VMEbus). However, work is still need to support the remaining
devices (eg. IndustryPack sites).
These boards are available with a dazzling array of build options. At
this time, the following options are *required*:
o Real floating point hardware (the 68LC040 model isn't tested),
o The VMEchip2 must be present,
o If offboard VMEbus RAM is not present, at least 8MB of onboard
RAM is required.
o Even if offboard VMEbus RAM *is* present, at least 4MB of onboard
RAM is required. (Boards with 1 or 2MB onboard RAM *can* be
supported with offboard RAM, but not without some funky values in
the VMEbus Master mapping registers.)
There is no support for boards other than those in the -LX 200/300 series.
2000-09-06 23:51:42 +04:00
|
|
|
sc->sc_clock_lvl = (pa->pa_ipl & PCCTWO_ICR_LEVEL_MASK) |
|
|
|
|
PCCTWO_ICR_ICLR | PCCTWO_ICR_IEN;
|
|
|
|
|
1999-02-14 20:54:27 +03:00
|
|
|
/* Attach the interrupt handlers. */
|
|
|
|
pcctwointr_establish(PCCTWOV_TIMER1, clock_pcctwo_profintr,
|
2001-05-31 22:46:07 +04:00
|
|
|
pa->pa_ipl, NULL, &clock_profcnt);
|
1999-02-14 20:54:27 +03:00
|
|
|
pcctwointr_establish(PCCTWOV_TIMER2, clock_pcctwo_statintr,
|
2001-05-31 22:46:07 +04:00
|
|
|
pa->pa_ipl, NULL, &clock_statcnt);
|
1999-02-14 20:54:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
clock_pcctwo_initclocks(void *arg, int prof_us, int stat_us)
|
1999-02-14 20:54:27 +03:00
|
|
|
{
|
2000-03-19 01:33:02 +03:00
|
|
|
struct clock_pcctwo_softc *sc;
|
|
|
|
|
|
|
|
sc = arg;
|
|
|
|
|
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER1_CONTROL, PCCTWO_TT_CTRL_COVF);
|
|
|
|
pcc2_reg_write32(sys_pcctwo, PCC2REG_TIMER1_COUNTER, 0);
|
|
|
|
pcc2_reg_write32(sys_pcctwo, PCC2REG_TIMER1_COMPARE,
|
2005-06-03 12:42:54 +04:00
|
|
|
PCCTWO_US2LIM(prof_us));
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER1_CONTROL,
|
2001-04-14 17:53:05 +04:00
|
|
|
PCCTWO_TT_CTRL_CEN | PCCTWO_TT_CTRL_COC | PCCTWO_TT_CTRL_COVF);
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER1_ICSR, sc->sc_clock_lvl);
|
|
|
|
|
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER2_CONTROL, PCCTWO_TT_CTRL_COVF);
|
|
|
|
pcc2_reg_write32(sys_pcctwo, PCC2REG_TIMER2_COUNTER, 0);
|
|
|
|
pcc2_reg_write32(sys_pcctwo, PCC2REG_TIMER2_COMPARE,
|
2005-06-03 12:42:54 +04:00
|
|
|
PCCTWO_US2LIM(stat_us));
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER2_CONTROL,
|
2001-04-14 17:53:05 +04:00
|
|
|
PCCTWO_TT_CTRL_CEN | PCCTWO_TT_CTRL_COC | PCCTWO_TT_CTRL_COVF);
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER2_ICSR, sc->sc_clock_lvl);
|
2008-01-07 17:39:28 +03:00
|
|
|
|
|
|
|
sc->sc_tc.tc_get_timecount = clock_pcctwo_getcount;
|
|
|
|
sc->sc_tc.tc_name = "pcctwo_count";
|
|
|
|
sc->sc_tc.tc_frequency = PCCTWO_TIMERFREQ;
|
|
|
|
sc->sc_tc.tc_quality = 100;
|
|
|
|
sc->sc_tc.tc_counter_mask = ~0;
|
|
|
|
tc_init(&sc->sc_tc);
|
1999-02-14 20:54:27 +03:00
|
|
|
}
|
|
|
|
|
2001-04-14 17:53:05 +04:00
|
|
|
/* ARGSUSED */
|
2008-01-07 17:39:28 +03:00
|
|
|
u_int
|
|
|
|
clock_pcctwo_getcount(struct timecounter *tc)
|
2001-04-14 17:53:05 +04:00
|
|
|
{
|
2008-01-07 17:39:28 +03:00
|
|
|
u_int cnt;
|
|
|
|
uint32_t tc1, tc2;
|
|
|
|
uint8_t cr;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splhigh();
|
2001-04-14 17:53:05 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
2008-01-07 17:39:28 +03:00
|
|
|
* Note: This only works because we're at splhigh().
|
2001-04-14 17:53:05 +04:00
|
|
|
*/
|
2008-01-07 17:39:28 +03:00
|
|
|
tc1 = pcc2_reg_read32(sys_pcctwo, PCC2REG_TIMER1_COUNTER);
|
2001-04-14 17:53:05 +04:00
|
|
|
cr = pcc2_reg_read(sys_pcctwo, PCC2REG_TIMER1_CONTROL);
|
2008-01-07 17:39:28 +03:00
|
|
|
tc2 = pcc2_reg_read32(sys_pcctwo, PCC2REG_TIMER1_COUNTER);
|
|
|
|
if (tc1 > tc2) {
|
2001-04-14 17:53:05 +04:00
|
|
|
cr = pcc2_reg_read(sys_pcctwo, PCC2REG_TIMER1_CONTROL);
|
2008-01-07 17:39:28 +03:00
|
|
|
tc1 = tc2;
|
2001-04-14 17:53:05 +04:00
|
|
|
}
|
2008-01-07 17:39:28 +03:00
|
|
|
cnt = clock_pcctwo_count;
|
|
|
|
splx(s);
|
|
|
|
/* XXX assume HZ == 100 */
|
|
|
|
cnt += tc1 + (PCCTWO_TIMERFREQ / 100) * PCCTWO_TT_CTRL_OVF(cr);
|
2001-04-14 17:53:05 +04:00
|
|
|
|
2008-01-07 17:39:28 +03:00
|
|
|
return cnt;
|
2001-04-14 17:53:05 +04:00
|
|
|
}
|
|
|
|
|
1999-02-14 20:54:27 +03:00
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
clock_pcctwo_profintr(void *frame)
|
1999-02-14 20:54:27 +03:00
|
|
|
{
|
2001-04-14 17:53:05 +04:00
|
|
|
u_int8_t cr;
|
|
|
|
u_int32_t tc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
tc = pcc2_reg_read32(sys_pcctwo, PCC2REG_TIMER1_COUNTER);
|
|
|
|
cr = pcc2_reg_read(sys_pcctwo, PCC2REG_TIMER1_CONTROL);
|
|
|
|
if (tc > pcc2_reg_read32(sys_pcctwo, PCC2REG_TIMER1_COUNTER))
|
|
|
|
cr = pcc2_reg_read(sys_pcctwo, PCC2REG_TIMER1_CONTROL);
|
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER1_CONTROL,
|
|
|
|
PCCTWO_TT_CTRL_CEN | PCCTWO_TT_CTRL_COC | PCCTWO_TT_CTRL_COVF);
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER1_ICSR,
|
|
|
|
clock_pcctwo_sc->sc_clock_lvl);
|
2001-07-06 23:00:12 +04:00
|
|
|
splx(s);
|
2001-04-14 17:53:05 +04:00
|
|
|
|
2008-01-07 17:39:28 +03:00
|
|
|
for (cr = PCCTWO_TT_CTRL_OVF(cr); cr; cr--) {
|
|
|
|
/* XXX assume HZ == 100 */
|
|
|
|
clock_pcctwo_count += PCCTWO_TIMERFREQ / 100;
|
2001-04-14 17:53:05 +04:00
|
|
|
hardclock(frame);
|
2008-01-07 17:39:28 +03:00
|
|
|
}
|
2001-04-14 17:53:05 +04:00
|
|
|
|
1999-02-14 20:54:27 +03:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-03-14 18:35:58 +03:00
|
|
|
clock_pcctwo_statintr(void *frame)
|
1999-02-14 20:54:27 +03:00
|
|
|
{
|
2000-03-19 01:33:02 +03:00
|
|
|
|
1999-02-14 20:54:27 +03:00
|
|
|
/* Disable the timer interrupt while we handle it. */
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER2_ICSR, 0);
|
|
|
|
|
|
|
|
statclock((struct clockframe *) frame);
|
1999-02-14 20:54:27 +03:00
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER2_CONTROL, PCCTWO_TT_CTRL_COVF);
|
|
|
|
pcc2_reg_write32(sys_pcctwo, PCC2REG_TIMER2_COUNTER, 0);
|
|
|
|
pcc2_reg_write32(sys_pcctwo, PCC2REG_TIMER2_COMPARE,
|
|
|
|
PCCTWO_US2LIM(CLOCK_NEWINT(clock_statvar, clock_statmin)));
|
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER2_CONTROL,
|
2001-04-14 17:53:05 +04:00
|
|
|
PCCTWO_TT_CTRL_CEN | PCCTWO_TT_CTRL_COC | PCCTWO_TT_CTRL_COVF);
|
1999-02-14 20:54:27 +03:00
|
|
|
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER2_ICSR,
|
|
|
|
clock_pcctwo_sc->sc_clock_lvl);
|
1999-02-14 20:54:27 +03:00
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
2009-03-14 18:35:58 +03:00
|
|
|
clock_pcctwo_shutdown(void *arg)
|
1999-02-14 20:54:27 +03:00
|
|
|
{
|
2000-03-19 01:33:02 +03:00
|
|
|
|
1999-02-14 20:54:27 +03:00
|
|
|
/* Make sure the timer interrupts are turned off. */
|
2000-03-19 01:33:02 +03:00
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER1_CONTROL, PCCTWO_TT_CTRL_COVF);
|
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER1_ICSR, 0);
|
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER2_CONTROL, PCCTWO_TT_CTRL_COVF);
|
|
|
|
pcc2_reg_write(sys_pcctwo, PCC2REG_TIMER2_ICSR, 0);
|
1999-02-14 20:54:27 +03:00
|
|
|
}
|