1*482eef70Srin /* $NetBSD: mvsoctmr.c,v 1.15 2020/05/29 12:30:39 rin Exp $ */
252d286fbSkiyohara /*
33e4b99ebSkiyohara * Copyright (c) 2007, 2008, 2010 KIYOHARA Takashi
452d286fbSkiyohara * All rights reserved.
552d286fbSkiyohara *
652d286fbSkiyohara * Redistribution and use in source and binary forms, with or without
752d286fbSkiyohara * modification, are permitted provided that the following conditions
852d286fbSkiyohara * are met:
952d286fbSkiyohara * 1. Redistributions of source code must retain the above copyright
1052d286fbSkiyohara * notice, this list of conditions and the following disclaimer.
1152d286fbSkiyohara * 2. Redistributions in binary form must reproduce the above copyright
1252d286fbSkiyohara * notice, this list of conditions and the following disclaimer in the
1352d286fbSkiyohara * documentation and/or other materials provided with the distribution.
1452d286fbSkiyohara *
1552d286fbSkiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1652d286fbSkiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1752d286fbSkiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1852d286fbSkiyohara * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
1952d286fbSkiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2052d286fbSkiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2152d286fbSkiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2252d286fbSkiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2352d286fbSkiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2452d286fbSkiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2552d286fbSkiyohara * POSSIBILITY OF SUCH DAMAGE.
2652d286fbSkiyohara */
2752d286fbSkiyohara #include <sys/cdefs.h>
28*482eef70Srin __KERNEL_RCSID(0, "$NetBSD: mvsoctmr.c,v 1.15 2020/05/29 12:30:39 rin Exp $");
2910b3ec2cShans
3010b3ec2cShans #include "opt_ddb.h"
31f6e8c184Srkujawa #include "opt_mvsoc.h"
3252d286fbSkiyohara
3352d286fbSkiyohara #include <sys/param.h>
3452d286fbSkiyohara #include <sys/atomic.h>
3552d286fbSkiyohara #include <sys/bus.h>
3652d286fbSkiyohara #include <sys/device.h>
3752d286fbSkiyohara #include <sys/errno.h>
3852d286fbSkiyohara #include <sys/kernel.h>
3952d286fbSkiyohara #include <sys/time.h>
4052d286fbSkiyohara #include <sys/timetc.h>
4152d286fbSkiyohara #include <sys/systm.h>
4210b3ec2cShans #include <sys/wdog.h>
4352d286fbSkiyohara
4452d286fbSkiyohara #include <machine/intr.h>
4552d286fbSkiyohara
4652d286fbSkiyohara #include <arm/cpufunc.h>
4752d286fbSkiyohara
4852d286fbSkiyohara #include <arm/marvell/mvsocreg.h>
4952d286fbSkiyohara #include <arm/marvell/mvsocvar.h>
5052d286fbSkiyohara #include <arm/marvell/mvsoctmrreg.h>
5152d286fbSkiyohara
523e4b99ebSkiyohara #include <dev/marvell/marvellreg.h>
5352d286fbSkiyohara #include <dev/marvell/marvellvar.h>
5452d286fbSkiyohara
5510b3ec2cShans #include <dev/sysmon/sysmonvar.h>
5610b3ec2cShans
5710b3ec2cShans #ifdef DDB
5810b3ec2cShans #include <machine/db_machdep.h>
5910b3ec2cShans #include <ddb/db_extern.h>
6010b3ec2cShans #endif
6110b3ec2cShans
6252d286fbSkiyohara
6352d286fbSkiyohara struct mvsoctmr_softc {
6452d286fbSkiyohara device_t sc_dev;
6552d286fbSkiyohara
6610b3ec2cShans struct sysmon_wdog sc_wdog;
6710b3ec2cShans uint32_t sc_wdog_period;
6810b3ec2cShans uint32_t sc_wdog_armed;
6910b3ec2cShans
7052d286fbSkiyohara bus_space_tag_t sc_iot;
7152d286fbSkiyohara bus_space_handle_t sc_ioh;
72f6e8c184Srkujawa int sc_irq;
733e4b99ebSkiyohara
7466c5f060Skiyohara #define TMR_FLAGS_NOBRIDGE (1 << 0)
7566c5f060Skiyohara #define TMR_FLAGS_25MHZ (1 << 1)
7666c5f060Skiyohara #define TMR_FLAGS_SYSCLK (1 << 2)
773e4b99ebSkiyohara int sc_flags;
7852d286fbSkiyohara };
7952d286fbSkiyohara
8052d286fbSkiyohara
8152d286fbSkiyohara static int mvsoctmr_match(device_t, struct cfdata *, void *);
8252d286fbSkiyohara static void mvsoctmr_attach(device_t, device_t, void *);
8352d286fbSkiyohara
8452d286fbSkiyohara static int clockhandler(void *);
8552d286fbSkiyohara
8652d286fbSkiyohara static u_int mvsoctmr_get_timecount(struct timecounter *);
8752d286fbSkiyohara
8852d286fbSkiyohara static void mvsoctmr_cntl(struct mvsoctmr_softc *, int, u_int, int, int);
8952d286fbSkiyohara
9010b3ec2cShans static int mvsoctmr_wdog_tickle(struct sysmon_wdog *);
9110b3ec2cShans static int mvsoctmr_wdog_setmode(struct sysmon_wdog *);
9210b3ec2cShans
9310b3ec2cShans #ifdef DDB
9410b3ec2cShans static void mvsoctmr_wdog_ddb_trap(int);
9510b3ec2cShans #endif
9610b3ec2cShans
9766c5f060Skiyohara static int mvsoctmr_freq;
9866c5f060Skiyohara
9966c5f060Skiyohara #define MVSOC_WDOG_MAX_PERIOD (0xffffffff / mvsoctmr_freq)
10010b3ec2cShans
10152d286fbSkiyohara static struct mvsoctmr_softc *mvsoctmr_sc;
10252d286fbSkiyohara static struct timecounter mvsoctmr_timecounter = {
103*482eef70Srin .tc_get_timecount = mvsoctmr_get_timecount,
104*482eef70Srin .tc_counter_mask = ~0u,
105*482eef70Srin .tc_name = "mvsoctmr",
106*482eef70Srin .tc_quality = 100,
10752d286fbSkiyohara };
10852d286fbSkiyohara
10952d286fbSkiyohara CFATTACH_DECL_NEW(mvsoctmr, sizeof(struct mvsoctmr_softc),
11052d286fbSkiyohara mvsoctmr_match, mvsoctmr_attach, NULL, NULL);
11152d286fbSkiyohara
11252d286fbSkiyohara
11352d286fbSkiyohara /* ARGSUSED */
11452d286fbSkiyohara static int
mvsoctmr_match(device_t parent,struct cfdata * match,void * aux)11552d286fbSkiyohara mvsoctmr_match(device_t parent, struct cfdata *match, void *aux)
11652d286fbSkiyohara {
11752d286fbSkiyohara struct marvell_attach_args *mva = aux;
11852d286fbSkiyohara
11952d286fbSkiyohara if (strcmp(mva->mva_name, match->cf_name) != 0)
12052d286fbSkiyohara return 0;
1213e4b99ebSkiyohara if (mva->mva_offset == MVA_OFFSET_DEFAULT ||
1223e4b99ebSkiyohara mva->mva_irq == MVA_IRQ_DEFAULT)
12352d286fbSkiyohara return 0;
12452d286fbSkiyohara
12552d286fbSkiyohara mva->mva_size = MVSOCTMR_SIZE;
12652d286fbSkiyohara return 1;
12752d286fbSkiyohara }
12852d286fbSkiyohara
12952d286fbSkiyohara /* ARGSUSED */
13052d286fbSkiyohara static void
mvsoctmr_attach(device_t parent,device_t self,void * aux)13152d286fbSkiyohara mvsoctmr_attach(device_t parent, device_t self, void *aux)
13252d286fbSkiyohara {
13352d286fbSkiyohara struct mvsoctmr_softc *sc = device_private(self);
13452d286fbSkiyohara struct marvell_attach_args *mva = aux;
13510b3ec2cShans uint32_t rstoutn;
13652d286fbSkiyohara
13752d286fbSkiyohara aprint_naive("\n");
13852d286fbSkiyohara aprint_normal(": Marvell SoC Timer\n");
13952d286fbSkiyohara
14052d286fbSkiyohara if (mvsoctmr_sc == NULL)
14152d286fbSkiyohara mvsoctmr_sc = sc;
14252d286fbSkiyohara
14352d286fbSkiyohara sc->sc_dev = self;
14452d286fbSkiyohara sc->sc_iot = mva->mva_iot;
14552d286fbSkiyohara if (bus_space_subregion(mva->mva_iot, mva->mva_ioh,
14652d286fbSkiyohara mva->mva_offset, mva->mva_size, &sc->sc_ioh))
14752d286fbSkiyohara panic("%s: Cannot map registers", device_xname(self));
1483e4b99ebSkiyohara sc->sc_irq = mva->mva_irq;
1493e4b99ebSkiyohara
1503e4b99ebSkiyohara switch (mva->mva_model) {
1513e4b99ebSkiyohara case MARVELL_ARMADAXP_MV78130:
1523e4b99ebSkiyohara case MARVELL_ARMADAXP_MV78160:
1533e4b99ebSkiyohara case MARVELL_ARMADAXP_MV78230:
1543e4b99ebSkiyohara case MARVELL_ARMADAXP_MV78260:
1553e4b99ebSkiyohara case MARVELL_ARMADAXP_MV78460:
15666c5f060Skiyohara sc->sc_flags = TMR_FLAGS_25MHZ | TMR_FLAGS_NOBRIDGE;
1573e4b99ebSkiyohara break;
15866c5f060Skiyohara case MARVELL_ARMADA370_MV6707:
15966c5f060Skiyohara case MARVELL_ARMADA370_MV6710:
16066c5f060Skiyohara case MARVELL_ARMADA370_MV6W11:
16166c5f060Skiyohara sc->sc_flags = TMR_FLAGS_NOBRIDGE | TMR_FLAGS_SYSCLK;
16266c5f060Skiyohara break;
1633e4b99ebSkiyohara }
16490849d0bSjakllsch
16590849d0bSjakllsch mvsoctmr_timecounter.tc_name = device_xname(self);
16690849d0bSjakllsch mvsoctmr_cntl(sc, MVSOCTMR_TIMER1, 0xffffffff, 1, 1);
16710b3ec2cShans
16810b3ec2cShans /*
16910b3ec2cShans * stop watchdog timer, enable watchdog timer resets
17010b3ec2cShans */
17164a87148Sjakllsch mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG, 0xffffffff, 0, 0);
172a0cf75abSjakllsch write_mlmbreg(MVSOC_MLMB_MLMBICR,
173a0cf75abSjakllsch ~(1<<MVSOC_MLMB_MLMBI_CPUWDTIMERINTREQ));
17410b3ec2cShans rstoutn = read_mlmbreg(MVSOC_MLMB_RSTOUTNMASKR);
17510b3ec2cShans write_mlmbreg(MVSOC_MLMB_RSTOUTNMASKR,
17610b3ec2cShans rstoutn | MVSOC_MLMB_RSTOUTNMASKR_WDRSTOUTEN);
17710b3ec2cShans
17810b3ec2cShans #ifdef DDB
17910b3ec2cShans db_trap_callback = mvsoctmr_wdog_ddb_trap;
18010b3ec2cShans #endif
18110b3ec2cShans
18289b2222cSmartin if (sc->sc_flags & TMR_FLAGS_25MHZ)
18389b2222cSmartin /* We set global timer and counter to 25 MHz mode */
18489b2222cSmartin mvsoctmr_freq = 25000000;
18589b2222cSmartin else if (sc->sc_flags & TMR_FLAGS_SYSCLK)
18689b2222cSmartin mvsoctmr_freq = mvSysclk;
18789b2222cSmartin else
18889b2222cSmartin mvsoctmr_freq = mvTclk;
18989b2222cSmartin
19010b3ec2cShans sc->sc_wdog.smw_name = device_xname(self);
19110b3ec2cShans sc->sc_wdog.smw_cookie = sc;
19210b3ec2cShans sc->sc_wdog.smw_setmode = mvsoctmr_wdog_setmode;
19310b3ec2cShans sc->sc_wdog.smw_tickle = mvsoctmr_wdog_tickle;
19410b3ec2cShans sc->sc_wdog.smw_period = MVSOC_WDOG_MAX_PERIOD;
19510b3ec2cShans
19610b3ec2cShans if (sysmon_wdog_register(&sc->sc_wdog) != 0)
19710b3ec2cShans aprint_error_dev(self,
19810b3ec2cShans "unable to register watchdog with sysmon\n");
19952d286fbSkiyohara }
20052d286fbSkiyohara
20152d286fbSkiyohara /*
20252d286fbSkiyohara * clockhandler:
20352d286fbSkiyohara *
20452d286fbSkiyohara * Handle the hardclock interrupt.
20552d286fbSkiyohara */
20652d286fbSkiyohara static int
clockhandler(void * arg)20752d286fbSkiyohara clockhandler(void *arg)
20852d286fbSkiyohara {
20952d286fbSkiyohara struct clockframe *frame = arg;
21052d286fbSkiyohara
211f6e8c184Srkujawa #if defined(ARMADAXP)
2123e4b99ebSkiyohara KASSERT(mvsoctmr_sc != NULL);
2133e4b99ebSkiyohara
21466c5f060Skiyohara if (mvsoctmr_sc->sc_flags & TMR_FLAGS_NOBRIDGE)
215f6e8c184Srkujawa /* Acknowledge all timers-related interrupts */
216f6e8c184Srkujawa bus_space_write_4(mvsoctmr_sc->sc_iot, mvsoctmr_sc->sc_ioh,
217f6e8c184Srkujawa MVSOCTMR_TESR, 0x0);
218f6e8c184Srkujawa #endif
219f6e8c184Srkujawa
22052d286fbSkiyohara hardclock(frame);
22152d286fbSkiyohara
22252d286fbSkiyohara return 1;
22352d286fbSkiyohara }
22452d286fbSkiyohara
22552d286fbSkiyohara /*
22652d286fbSkiyohara * setstatclockrate:
22752d286fbSkiyohara *
22852d286fbSkiyohara * Set the rate of the statistics clock.
22952d286fbSkiyohara */
23052d286fbSkiyohara /* ARGSUSED */
23152d286fbSkiyohara void
setstatclockrate(int newhz)23252d286fbSkiyohara setstatclockrate(int newhz)
23352d286fbSkiyohara {
23452d286fbSkiyohara }
23552d286fbSkiyohara
23652d286fbSkiyohara /*
23752d286fbSkiyohara * cpu_initclocks:
23852d286fbSkiyohara *
23952d286fbSkiyohara * Initialize the clock and get them going.
24052d286fbSkiyohara */
24152d286fbSkiyohara void
cpu_initclocks(void)2421d7f24eaSmatt cpu_initclocks(void)
24352d286fbSkiyohara {
24452d286fbSkiyohara struct mvsoctmr_softc *sc;
24552d286fbSkiyohara void *clock_ih;
24652d286fbSkiyohara const int en = 1, autoen = 1;
24790849d0bSjakllsch uint32_t timer0_tval;
24852d286fbSkiyohara
24952d286fbSkiyohara sc = mvsoctmr_sc;
25052d286fbSkiyohara if (sc == NULL)
25152d286fbSkiyohara panic("cpu_initclocks: mvsoctmr not found");
25252d286fbSkiyohara
25366c5f060Skiyohara mvsoctmr_timecounter.tc_priv = sc;
25466c5f060Skiyohara mvsoctmr_timecounter.tc_frequency = mvsoctmr_freq;
25566c5f060Skiyohara
25666c5f060Skiyohara timer0_tval = (mvsoctmr_freq * 2) / (u_long) hz;
25790849d0bSjakllsch timer0_tval = (timer0_tval / 2) + (timer0_tval & 1);
25890849d0bSjakllsch
25990849d0bSjakllsch mvsoctmr_cntl(sc, MVSOCTMR_TIMER0, timer0_tval, en, autoen);
26090849d0bSjakllsch mvsoctmr_cntl(sc, MVSOCTMR_TIMER1, 0xffffffff, en, autoen);
26152d286fbSkiyohara
26266c5f060Skiyohara if (sc->sc_flags & TMR_FLAGS_NOBRIDGE) {
263f6e8c184Srkujawa /*
2643e4b99ebSkiyohara * Establishing timer interrupts is slightly different for
2653e4b99ebSkiyohara * Armada XP than for other supported SoCs from Marvell.
2663e4b99ebSkiyohara * Timer interrupt is no different from any other interrupt
2673e4b99ebSkiyohara * in Armada XP, so we use generic marvell_intr_establish().
268f6e8c184Srkujawa */
269f6e8c184Srkujawa clock_ih = marvell_intr_establish(sc->sc_irq, IPL_CLOCK,
270f6e8c184Srkujawa clockhandler, NULL);
2713e4b99ebSkiyohara } else
2723e4b99ebSkiyohara clock_ih = mvsoc_bridge_intr_establish(
2733e4b99ebSkiyohara MVSOC_MLMB_MLMBI_CPUTIMER0INTREQ, IPL_CLOCK, clockhandler,
2743e4b99ebSkiyohara NULL);
27552d286fbSkiyohara if (clock_ih == NULL)
27652d286fbSkiyohara panic("cpu_initclocks: unable to register timer interrupt");
27752d286fbSkiyohara
27852d286fbSkiyohara tc_init(&mvsoctmr_timecounter);
27952d286fbSkiyohara }
28052d286fbSkiyohara
28152d286fbSkiyohara void
delay(unsigned int n)28252d286fbSkiyohara delay(unsigned int n)
28352d286fbSkiyohara {
28452d286fbSkiyohara struct mvsoctmr_softc *sc;
28552d286fbSkiyohara unsigned int cur_tick, initial_tick;
28652d286fbSkiyohara int remaining;
28752d286fbSkiyohara
28852d286fbSkiyohara sc = mvsoctmr_sc;
28952d286fbSkiyohara #ifdef DEBUG
29052d286fbSkiyohara if (sc == NULL) {
29152d286fbSkiyohara printf("%s: called before start mvsoctmr\n", __func__);
29252d286fbSkiyohara return;
29352d286fbSkiyohara }
29452d286fbSkiyohara #endif
29552d286fbSkiyohara
29652d286fbSkiyohara /*
29752d286fbSkiyohara * Read the counter first, so that the rest of the setup overhead is
29852d286fbSkiyohara * counted.
29952d286fbSkiyohara */
30052d286fbSkiyohara initial_tick = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
30190849d0bSjakllsch MVSOCTMR_TIMER(MVSOCTMR_TIMER1));
30252d286fbSkiyohara
30366c5f060Skiyohara if (n <= UINT_MAX / mvsoctmr_freq) {
30452d286fbSkiyohara /*
30552d286fbSkiyohara * For unsigned arithmetic, division can be replaced with
30652d286fbSkiyohara * multiplication with the inverse and a shift.
30752d286fbSkiyohara */
30866c5f060Skiyohara remaining = n * mvsoctmr_freq / 1000000;
30952d286fbSkiyohara } else {
31052d286fbSkiyohara /*
31152d286fbSkiyohara * This is a very long delay.
31252d286fbSkiyohara * Being slow here doesn't matter.
31352d286fbSkiyohara */
31466c5f060Skiyohara remaining = (unsigned long long) n * mvsoctmr_freq / 1000000;
31552d286fbSkiyohara }
31652d286fbSkiyohara
31752d286fbSkiyohara while (remaining > 0) {
31852d286fbSkiyohara cur_tick = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
31990849d0bSjakllsch MVSOCTMR_TIMER(MVSOCTMR_TIMER1));
32052d286fbSkiyohara if (cur_tick > initial_tick)
32190849d0bSjakllsch remaining -= 0xffffffff - cur_tick + initial_tick;
32252d286fbSkiyohara else
32352d286fbSkiyohara remaining -= (initial_tick - cur_tick);
32452d286fbSkiyohara initial_tick = cur_tick;
32552d286fbSkiyohara }
32652d286fbSkiyohara }
32752d286fbSkiyohara
32852d286fbSkiyohara static u_int
mvsoctmr_get_timecount(struct timecounter * tc)32952d286fbSkiyohara mvsoctmr_get_timecount(struct timecounter *tc)
33052d286fbSkiyohara {
33190849d0bSjakllsch struct mvsoctmr_softc *sc = tc->tc_priv;
33252d286fbSkiyohara
33390849d0bSjakllsch return 0xffffffff - bus_space_read_4(sc->sc_iot, sc->sc_ioh,
33490849d0bSjakllsch MVSOCTMR_TIMER(MVSOCTMR_TIMER1));
33552d286fbSkiyohara }
33652d286fbSkiyohara
33752d286fbSkiyohara static void
mvsoctmr_cntl(struct mvsoctmr_softc * sc,int num,u_int ticks,int en,int autoen)33852d286fbSkiyohara mvsoctmr_cntl(struct mvsoctmr_softc *sc, int num, u_int ticks, int en,
33952d286fbSkiyohara int autoen)
34052d286fbSkiyohara {
34152d286fbSkiyohara uint32_t ctrl;
34252d286fbSkiyohara
3433e4b99ebSkiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVSOCTMR_RELOAD(num), ticks);
34452d286fbSkiyohara
34552d286fbSkiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVSOCTMR_TIMER(num), ticks);
34652d286fbSkiyohara
34752d286fbSkiyohara ctrl = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVSOCTMR_CTCR);
34852d286fbSkiyohara if (en)
34952d286fbSkiyohara ctrl |= MVSOCTMR_CTCR_CPUTIMEREN(num);
35052d286fbSkiyohara else
35152d286fbSkiyohara ctrl &= ~MVSOCTMR_CTCR_CPUTIMEREN(num);
35252d286fbSkiyohara if (autoen)
35352d286fbSkiyohara ctrl |= MVSOCTMR_CTCR_CPUTIMERAUTO(num);
35452d286fbSkiyohara else
35552d286fbSkiyohara ctrl &= ~MVSOCTMR_CTCR_CPUTIMERAUTO(num);
35666c5f060Skiyohara if (sc->sc_flags & TMR_FLAGS_25MHZ)
357f6e8c184Srkujawa /* Set timer and counter to 25MHz mode */
358f6e8c184Srkujawa ctrl |= MVSOCTMR_CTCR_25MHZEN(num);
35952d286fbSkiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVSOCTMR_CTCR, ctrl);
36052d286fbSkiyohara }
36110b3ec2cShans
36210b3ec2cShans static int
mvsoctmr_wdog_setmode(struct sysmon_wdog * smw)36310b3ec2cShans mvsoctmr_wdog_setmode(struct sysmon_wdog *smw)
36410b3ec2cShans {
36510b3ec2cShans struct mvsoctmr_softc *sc = smw->smw_cookie;
36610b3ec2cShans
36710b3ec2cShans if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
36810b3ec2cShans sc->sc_wdog_armed = 0;
36964a87148Sjakllsch mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG, 0xffffffff, 0, 0);
37010b3ec2cShans } else {
37110b3ec2cShans sc->sc_wdog_armed = 1;
37210b3ec2cShans if (smw->smw_period == WDOG_PERIOD_DEFAULT)
37310b3ec2cShans smw->smw_period = MVSOC_WDOG_MAX_PERIOD;
37410b3ec2cShans else if (smw->smw_period > MVSOC_WDOG_MAX_PERIOD ||
37510b3ec2cShans smw->smw_period <= 0)
37610b3ec2cShans return (EOPNOTSUPP);
37766c5f060Skiyohara sc->sc_wdog_period = smw->smw_period * mvsoctmr_freq;
37810b3ec2cShans mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG, sc->sc_wdog_period, 1, 0);
37910b3ec2cShans }
38010b3ec2cShans
38110b3ec2cShans return (0);
38210b3ec2cShans }
38310b3ec2cShans
38410b3ec2cShans static int
mvsoctmr_wdog_tickle(struct sysmon_wdog * smw)38510b3ec2cShans mvsoctmr_wdog_tickle(struct sysmon_wdog *smw)
38610b3ec2cShans {
38710b3ec2cShans struct mvsoctmr_softc *sc = smw->smw_cookie;
38810b3ec2cShans
38910b3ec2cShans mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG, sc->sc_wdog_period, 1, 0);
39010b3ec2cShans
39110b3ec2cShans return (0);
39210b3ec2cShans }
39310b3ec2cShans
39410b3ec2cShans #ifdef DDB
39510b3ec2cShans static void
mvsoctmr_wdog_ddb_trap(int enter)39610b3ec2cShans mvsoctmr_wdog_ddb_trap(int enter)
39710b3ec2cShans {
398170dab62Sjakllsch struct mvsoctmr_softc *sc = mvsoctmr_sc;
39910b3ec2cShans
40010b3ec2cShans if (sc == NULL)
40110b3ec2cShans return;
40210b3ec2cShans
40310b3ec2cShans if (sc->sc_wdog_armed) {
40410b3ec2cShans if (enter)
40564a87148Sjakllsch mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG, 0xffffffff, 0, 0);
40610b3ec2cShans else
40710b3ec2cShans mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG,
40810b3ec2cShans sc->sc_wdog_period, 1, 0);
40910b3ec2cShans }
41010b3ec2cShans }
41110b3ec2cShans #endif
412