Home | History | Annotate | Line # | Download | only in marvell
mvsoctmr.c revision 1.13.6.1
      1  1.13.6.1     skrll /*	$NetBSD: mvsoctmr.c,v 1.13.6.1 2017/02/05 13:40:04 skrll Exp $	*/
      2       1.1  kiyohara /*
      3      1.10  kiyohara  * Copyright (c) 2007, 2008, 2010 KIYOHARA Takashi
      4       1.1  kiyohara  * All rights reserved.
      5       1.1  kiyohara  *
      6       1.1  kiyohara  * Redistribution and use in source and binary forms, with or without
      7       1.1  kiyohara  * modification, are permitted provided that the following conditions
      8       1.1  kiyohara  * are met:
      9       1.1  kiyohara  * 1. Redistributions of source code must retain the above copyright
     10       1.1  kiyohara  *    notice, this list of conditions and the following disclaimer.
     11       1.1  kiyohara  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1  kiyohara  *    notice, this list of conditions and the following disclaimer in the
     13       1.1  kiyohara  *    documentation and/or other materials provided with the distribution.
     14       1.1  kiyohara  *
     15       1.1  kiyohara  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16       1.1  kiyohara  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17       1.1  kiyohara  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18       1.1  kiyohara  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     19       1.1  kiyohara  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     20       1.1  kiyohara  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21       1.1  kiyohara  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22       1.1  kiyohara  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     23       1.1  kiyohara  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     24       1.1  kiyohara  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25       1.1  kiyohara  * POSSIBILITY OF SUCH DAMAGE.
     26       1.1  kiyohara  */
     27       1.1  kiyohara #include <sys/cdefs.h>
     28  1.13.6.1     skrll __KERNEL_RCSID(0, "$NetBSD: mvsoctmr.c,v 1.13.6.1 2017/02/05 13:40:04 skrll Exp $");
     29       1.4      hans 
     30       1.4      hans #include "opt_ddb.h"
     31       1.9   rkujawa #include "opt_mvsoc.h"
     32       1.1  kiyohara 
     33       1.1  kiyohara #include <sys/param.h>
     34       1.1  kiyohara #include <sys/atomic.h>
     35       1.1  kiyohara #include <sys/bus.h>
     36       1.1  kiyohara #include <sys/device.h>
     37       1.1  kiyohara #include <sys/errno.h>
     38       1.1  kiyohara #include <sys/kernel.h>
     39       1.1  kiyohara #include <sys/time.h>
     40       1.1  kiyohara #include <sys/timetc.h>
     41       1.1  kiyohara #include <sys/systm.h>
     42       1.4      hans #include <sys/wdog.h>
     43       1.1  kiyohara 
     44       1.1  kiyohara #include <machine/intr.h>
     45       1.1  kiyohara 
     46       1.1  kiyohara #include <arm/cpufunc.h>
     47       1.1  kiyohara 
     48       1.1  kiyohara #include <arm/marvell/mvsocreg.h>
     49       1.1  kiyohara #include <arm/marvell/mvsocvar.h>
     50       1.1  kiyohara #include <arm/marvell/mvsoctmrreg.h>
     51       1.1  kiyohara 
     52      1.10  kiyohara #include <dev/marvell/marvellreg.h>
     53       1.1  kiyohara #include <dev/marvell/marvellvar.h>
     54       1.1  kiyohara 
     55       1.4      hans #include <dev/sysmon/sysmonvar.h>
     56       1.4      hans 
     57       1.4      hans #ifdef DDB
     58       1.4      hans #include <machine/db_machdep.h>
     59       1.4      hans #include <ddb/db_extern.h>
     60       1.4      hans #endif
     61       1.4      hans 
     62       1.1  kiyohara 
     63       1.1  kiyohara struct mvsoctmr_softc {
     64       1.1  kiyohara 	device_t sc_dev;
     65       1.1  kiyohara 
     66       1.4      hans 	struct sysmon_wdog sc_wdog;
     67       1.4      hans 	uint32_t sc_wdog_period;
     68       1.4      hans 	uint32_t sc_wdog_armed;
     69       1.4      hans 
     70       1.1  kiyohara 	bus_space_tag_t sc_iot;
     71       1.1  kiyohara 	bus_space_handle_t sc_ioh;
     72       1.9   rkujawa 	int sc_irq;
     73      1.10  kiyohara 
     74      1.11  kiyohara #define TMR_FLAGS_NOBRIDGE	(1 << 0)
     75      1.11  kiyohara #define TMR_FLAGS_25MHZ		(1 << 1)
     76      1.11  kiyohara #define TMR_FLAGS_SYSCLK	(1 << 2)
     77      1.10  kiyohara 	int sc_flags;
     78       1.1  kiyohara };
     79       1.1  kiyohara 
     80       1.1  kiyohara 
     81       1.1  kiyohara static int mvsoctmr_match(device_t, struct cfdata *, void *);
     82       1.1  kiyohara static void mvsoctmr_attach(device_t, device_t, void *);
     83       1.1  kiyohara 
     84       1.1  kiyohara static int clockhandler(void *);
     85       1.1  kiyohara 
     86       1.1  kiyohara static u_int mvsoctmr_get_timecount(struct timecounter *);
     87       1.1  kiyohara 
     88       1.1  kiyohara static void mvsoctmr_cntl(struct mvsoctmr_softc *, int, u_int, int, int);
     89       1.1  kiyohara 
     90       1.4      hans static int mvsoctmr_wdog_tickle(struct sysmon_wdog *);
     91       1.4      hans static int mvsoctmr_wdog_setmode(struct sysmon_wdog *);
     92       1.4      hans 
     93       1.4      hans #ifdef DDB
     94       1.4      hans static void mvsoctmr_wdog_ddb_trap(int);
     95       1.4      hans #endif
     96       1.4      hans 
     97      1.11  kiyohara static int mvsoctmr_freq;
     98      1.11  kiyohara 
     99      1.11  kiyohara #define MVSOC_WDOG_MAX_PERIOD	(0xffffffff / mvsoctmr_freq)
    100       1.4      hans 
    101       1.1  kiyohara static struct mvsoctmr_softc *mvsoctmr_sc;
    102       1.1  kiyohara static struct timecounter mvsoctmr_timecounter = {
    103       1.1  kiyohara 	mvsoctmr_get_timecount,	/* get_timecount */
    104       1.1  kiyohara 	0,			/* no poll_pps */
    105       1.1  kiyohara 	~0u,			/* counter_mask */
    106       1.1  kiyohara 	0,			/* frequency  (set by cpu_initclocks()) */
    107       1.1  kiyohara 	"mvsoctmr",		/* name */
    108       1.1  kiyohara 	100,			/* quality */
    109       1.1  kiyohara 	NULL,			/* prev */
    110       1.1  kiyohara 	NULL,			/* next */
    111       1.1  kiyohara };
    112       1.1  kiyohara 
    113       1.1  kiyohara CFATTACH_DECL_NEW(mvsoctmr, sizeof(struct mvsoctmr_softc),
    114       1.1  kiyohara     mvsoctmr_match, mvsoctmr_attach, NULL, NULL);
    115       1.1  kiyohara 
    116       1.1  kiyohara 
    117       1.1  kiyohara /* ARGSUSED */
    118       1.1  kiyohara static int
    119       1.1  kiyohara mvsoctmr_match(device_t parent, struct cfdata *match, void *aux)
    120       1.1  kiyohara {
    121       1.1  kiyohara 	struct marvell_attach_args *mva = aux;
    122       1.1  kiyohara 
    123       1.1  kiyohara 	if (strcmp(mva->mva_name, match->cf_name) != 0)
    124       1.1  kiyohara 		return 0;
    125      1.10  kiyohara 	if (mva->mva_offset == MVA_OFFSET_DEFAULT ||
    126      1.10  kiyohara 	    mva->mva_irq == MVA_IRQ_DEFAULT)
    127       1.1  kiyohara 		return 0;
    128       1.1  kiyohara 
    129       1.1  kiyohara 	mva->mva_size = MVSOCTMR_SIZE;
    130       1.1  kiyohara 	return 1;
    131       1.1  kiyohara }
    132       1.1  kiyohara 
    133       1.1  kiyohara /* ARGSUSED */
    134       1.1  kiyohara static void
    135       1.1  kiyohara mvsoctmr_attach(device_t parent, device_t self, void *aux)
    136       1.1  kiyohara {
    137  1.13.6.1     skrll 	struct mvsoctmr_softc *sc = device_private(self);
    138       1.1  kiyohara 	struct marvell_attach_args *mva = aux;
    139       1.4      hans 	uint32_t rstoutn;
    140       1.1  kiyohara 
    141       1.1  kiyohara 	aprint_naive("\n");
    142       1.1  kiyohara 	aprint_normal(": Marvell SoC Timer\n");
    143       1.1  kiyohara 
    144       1.1  kiyohara 	if (mvsoctmr_sc == NULL)
    145       1.1  kiyohara 		mvsoctmr_sc = sc;
    146       1.1  kiyohara 
    147       1.1  kiyohara 	sc->sc_dev = self;
    148       1.1  kiyohara 	sc->sc_iot = mva->mva_iot;
    149       1.1  kiyohara 	if (bus_space_subregion(mva->mva_iot, mva->mva_ioh,
    150       1.1  kiyohara 	    mva->mva_offset, mva->mva_size, &sc->sc_ioh))
    151       1.1  kiyohara 		panic("%s: Cannot map registers", device_xname(self));
    152      1.10  kiyohara 	sc->sc_irq = mva->mva_irq;
    153      1.10  kiyohara 
    154      1.10  kiyohara 	switch (mva->mva_model) {
    155      1.10  kiyohara 	case MARVELL_ARMADAXP_MV78130:
    156      1.10  kiyohara 	case MARVELL_ARMADAXP_MV78160:
    157      1.10  kiyohara 	case MARVELL_ARMADAXP_MV78230:
    158      1.10  kiyohara 	case MARVELL_ARMADAXP_MV78260:
    159      1.10  kiyohara 	case MARVELL_ARMADAXP_MV78460:
    160      1.11  kiyohara 		sc->sc_flags = TMR_FLAGS_25MHZ | TMR_FLAGS_NOBRIDGE;
    161      1.11  kiyohara 		break;
    162      1.11  kiyohara 	case MARVELL_ARMADA370_MV6707:
    163      1.11  kiyohara 	case MARVELL_ARMADA370_MV6710:
    164      1.11  kiyohara 	case MARVELL_ARMADA370_MV6W11:
    165      1.11  kiyohara 		sc->sc_flags = TMR_FLAGS_NOBRIDGE | TMR_FLAGS_SYSCLK;
    166      1.10  kiyohara 		break;
    167      1.10  kiyohara 	}
    168       1.2  jakllsch 
    169       1.2  jakllsch 	mvsoctmr_timecounter.tc_name = device_xname(self);
    170       1.2  jakllsch 	mvsoctmr_cntl(sc, MVSOCTMR_TIMER1, 0xffffffff, 1, 1);
    171       1.4      hans 
    172       1.4      hans 	/*
    173       1.4      hans 	 * stop watchdog timer, enable watchdog timer resets
    174       1.4      hans 	 */
    175       1.5  jakllsch 	mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG, 0xffffffff, 0, 0);
    176       1.8  jakllsch 	write_mlmbreg(MVSOC_MLMB_MLMBICR,
    177       1.8  jakllsch 	    ~(1<<MVSOC_MLMB_MLMBI_CPUWDTIMERINTREQ));
    178       1.4      hans 	rstoutn = read_mlmbreg(MVSOC_MLMB_RSTOUTNMASKR);
    179       1.4      hans 	write_mlmbreg(MVSOC_MLMB_RSTOUTNMASKR,
    180       1.4      hans 		      rstoutn | MVSOC_MLMB_RSTOUTNMASKR_WDRSTOUTEN);
    181       1.4      hans 
    182       1.4      hans #ifdef DDB
    183       1.4      hans 	db_trap_callback = mvsoctmr_wdog_ddb_trap;
    184       1.4      hans #endif
    185       1.4      hans 
    186      1.12    martin 	if (sc->sc_flags & TMR_FLAGS_25MHZ)
    187      1.12    martin 		/* We set global timer and counter to 25 MHz mode */
    188      1.12    martin 		mvsoctmr_freq = 25000000;
    189      1.12    martin 	else if (sc->sc_flags & TMR_FLAGS_SYSCLK)
    190      1.12    martin 		mvsoctmr_freq = mvSysclk;
    191      1.12    martin 	else
    192      1.12    martin 		mvsoctmr_freq = mvTclk;
    193      1.12    martin 
    194       1.4      hans 	sc->sc_wdog.smw_name = device_xname(self);
    195       1.4      hans 	sc->sc_wdog.smw_cookie = sc;
    196       1.4      hans 	sc->sc_wdog.smw_setmode = mvsoctmr_wdog_setmode;
    197       1.4      hans 	sc->sc_wdog.smw_tickle = mvsoctmr_wdog_tickle;
    198       1.4      hans 	sc->sc_wdog.smw_period = MVSOC_WDOG_MAX_PERIOD;
    199       1.4      hans 
    200       1.4      hans 	if (sysmon_wdog_register(&sc->sc_wdog) != 0)
    201       1.4      hans 		aprint_error_dev(self,
    202       1.4      hans 				 "unable to register watchdog with sysmon\n");
    203       1.1  kiyohara }
    204       1.1  kiyohara 
    205       1.1  kiyohara /*
    206       1.1  kiyohara  * clockhandler:
    207       1.1  kiyohara  *
    208       1.1  kiyohara  *	Handle the hardclock interrupt.
    209       1.1  kiyohara  */
    210       1.1  kiyohara static int
    211       1.1  kiyohara clockhandler(void *arg)
    212       1.1  kiyohara {
    213       1.1  kiyohara 	struct clockframe *frame = arg;
    214       1.1  kiyohara 
    215       1.9   rkujawa #if defined(ARMADAXP)
    216      1.10  kiyohara 	KASSERT(mvsoctmr_sc != NULL);
    217      1.10  kiyohara 
    218      1.11  kiyohara 	if (mvsoctmr_sc->sc_flags & TMR_FLAGS_NOBRIDGE)
    219      1.10  kiyohara 		/* Acknowledge all timers-related interrupts */
    220      1.10  kiyohara 		bus_space_write_4(mvsoctmr_sc->sc_iot, mvsoctmr_sc->sc_ioh,
    221      1.10  kiyohara 		    MVSOCTMR_TESR, 0x0);
    222       1.9   rkujawa #endif
    223       1.9   rkujawa 
    224       1.1  kiyohara 	hardclock(frame);
    225       1.1  kiyohara 
    226       1.1  kiyohara 	return 1;
    227       1.1  kiyohara }
    228       1.1  kiyohara 
    229       1.1  kiyohara /*
    230       1.1  kiyohara  * setstatclockrate:
    231       1.1  kiyohara  *
    232       1.1  kiyohara  *	Set the rate of the statistics clock.
    233       1.1  kiyohara  */
    234       1.1  kiyohara /* ARGSUSED */
    235       1.1  kiyohara void
    236       1.1  kiyohara setstatclockrate(int newhz)
    237       1.1  kiyohara {
    238       1.1  kiyohara }
    239       1.1  kiyohara 
    240       1.1  kiyohara /*
    241       1.1  kiyohara  * cpu_initclocks:
    242       1.1  kiyohara  *
    243       1.1  kiyohara  *	Initialize the clock and get them going.
    244       1.1  kiyohara  */
    245       1.1  kiyohara void
    246       1.3      matt cpu_initclocks(void)
    247       1.1  kiyohara {
    248       1.1  kiyohara 	struct mvsoctmr_softc *sc;
    249       1.1  kiyohara 	void *clock_ih;
    250       1.1  kiyohara 	const int en = 1, autoen = 1;
    251       1.2  jakllsch 	uint32_t timer0_tval;
    252       1.1  kiyohara 
    253       1.1  kiyohara 	sc = mvsoctmr_sc;
    254       1.1  kiyohara 	if (sc == NULL)
    255       1.1  kiyohara 		panic("cpu_initclocks: mvsoctmr not found");
    256       1.1  kiyohara 
    257      1.11  kiyohara 	mvsoctmr_timecounter.tc_priv = sc;
    258      1.11  kiyohara 	mvsoctmr_timecounter.tc_frequency = mvsoctmr_freq;
    259       1.1  kiyohara 
    260      1.11  kiyohara 	timer0_tval = (mvsoctmr_freq * 2) / (u_long) hz;
    261       1.2  jakllsch 	timer0_tval = (timer0_tval / 2) + (timer0_tval & 1);
    262       1.2  jakllsch 
    263       1.2  jakllsch 	mvsoctmr_cntl(sc, MVSOCTMR_TIMER0, timer0_tval, en, autoen);
    264       1.2  jakllsch 	mvsoctmr_cntl(sc, MVSOCTMR_TIMER1, 0xffffffff, en, autoen);
    265       1.1  kiyohara 
    266      1.11  kiyohara 	if (sc->sc_flags & TMR_FLAGS_NOBRIDGE) {
    267      1.10  kiyohara 		/*
    268      1.10  kiyohara 		 * Establishing timer interrupts is slightly different for
    269      1.10  kiyohara 		 * Armada XP than for other supported SoCs from Marvell.
    270      1.10  kiyohara 		 * Timer interrupt is no different from any other interrupt
    271      1.10  kiyohara 		 * in Armada XP, so we use generic marvell_intr_establish().
    272      1.10  kiyohara 		 */
    273      1.10  kiyohara 		clock_ih = marvell_intr_establish(sc->sc_irq, IPL_CLOCK,
    274      1.10  kiyohara 		    clockhandler, NULL);
    275      1.10  kiyohara 	} else
    276      1.10  kiyohara 		clock_ih = mvsoc_bridge_intr_establish(
    277      1.10  kiyohara 		    MVSOC_MLMB_MLMBI_CPUTIMER0INTREQ, IPL_CLOCK, clockhandler,
    278      1.10  kiyohara 		    NULL);
    279       1.1  kiyohara 	if (clock_ih == NULL)
    280       1.1  kiyohara 		panic("cpu_initclocks: unable to register timer interrupt");
    281       1.1  kiyohara 
    282       1.1  kiyohara 	tc_init(&mvsoctmr_timecounter);
    283       1.1  kiyohara }
    284       1.1  kiyohara 
    285       1.1  kiyohara void
    286       1.1  kiyohara delay(unsigned int n)
    287       1.1  kiyohara {
    288       1.1  kiyohara 	struct mvsoctmr_softc *sc;
    289       1.1  kiyohara 	unsigned int cur_tick, initial_tick;
    290       1.1  kiyohara 	int remaining;
    291       1.1  kiyohara 
    292       1.1  kiyohara 	sc = mvsoctmr_sc;
    293       1.1  kiyohara #ifdef DEBUG
    294       1.1  kiyohara 	if (sc == NULL) {
    295       1.1  kiyohara 		printf("%s: called before start mvsoctmr\n", __func__);
    296       1.1  kiyohara 		return;
    297       1.1  kiyohara 	}
    298       1.1  kiyohara #endif
    299       1.1  kiyohara 
    300       1.1  kiyohara 	/*
    301       1.1  kiyohara 	 * Read the counter first, so that the rest of the setup overhead is
    302       1.1  kiyohara 	 * counted.
    303       1.1  kiyohara 	 */
    304       1.1  kiyohara 	initial_tick = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    305       1.2  jakllsch 	    MVSOCTMR_TIMER(MVSOCTMR_TIMER1));
    306       1.1  kiyohara 
    307      1.11  kiyohara 	if (n <= UINT_MAX / mvsoctmr_freq) {
    308       1.1  kiyohara 		/*
    309       1.1  kiyohara 		 * For unsigned arithmetic, division can be replaced with
    310       1.1  kiyohara 		 * multiplication with the inverse and a shift.
    311       1.1  kiyohara 		 */
    312      1.11  kiyohara 		remaining = n * mvsoctmr_freq / 1000000;
    313       1.1  kiyohara 	} else {
    314       1.1  kiyohara 		/*
    315       1.1  kiyohara 		 * This is a very long delay.
    316       1.1  kiyohara 		 * Being slow here doesn't matter.
    317       1.1  kiyohara 		 */
    318      1.11  kiyohara 		remaining = (unsigned long long) n * mvsoctmr_freq / 1000000;
    319       1.1  kiyohara 	}
    320       1.1  kiyohara 
    321       1.1  kiyohara 	while (remaining > 0) {
    322       1.1  kiyohara 		cur_tick = bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    323       1.2  jakllsch 		    MVSOCTMR_TIMER(MVSOCTMR_TIMER1));
    324       1.1  kiyohara 		if (cur_tick > initial_tick)
    325       1.2  jakllsch 			remaining -= 0xffffffff - cur_tick + initial_tick;
    326       1.1  kiyohara 		else
    327       1.1  kiyohara 			remaining -= (initial_tick - cur_tick);
    328       1.1  kiyohara 		initial_tick = cur_tick;
    329       1.1  kiyohara 	}
    330       1.1  kiyohara }
    331       1.1  kiyohara 
    332       1.1  kiyohara static u_int
    333       1.1  kiyohara mvsoctmr_get_timecount(struct timecounter *tc)
    334       1.1  kiyohara {
    335       1.2  jakllsch 	struct mvsoctmr_softc *sc = tc->tc_priv;
    336       1.1  kiyohara 
    337       1.2  jakllsch 	return 0xffffffff - bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    338       1.2  jakllsch 	    MVSOCTMR_TIMER(MVSOCTMR_TIMER1));
    339       1.1  kiyohara }
    340       1.1  kiyohara 
    341       1.1  kiyohara static void
    342       1.1  kiyohara mvsoctmr_cntl(struct mvsoctmr_softc *sc, int num, u_int ticks, int en,
    343       1.1  kiyohara 	      int autoen)
    344       1.1  kiyohara {
    345       1.1  kiyohara 	uint32_t ctrl;
    346       1.1  kiyohara 
    347      1.10  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVSOCTMR_RELOAD(num), ticks);
    348       1.1  kiyohara 
    349       1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVSOCTMR_TIMER(num), ticks);
    350       1.1  kiyohara 
    351       1.1  kiyohara 	ctrl = bus_space_read_4(sc->sc_iot, sc->sc_ioh, MVSOCTMR_CTCR);
    352       1.1  kiyohara 	if (en)
    353       1.1  kiyohara 		ctrl |= MVSOCTMR_CTCR_CPUTIMEREN(num);
    354       1.1  kiyohara 	else
    355       1.1  kiyohara 		ctrl &= ~MVSOCTMR_CTCR_CPUTIMEREN(num);
    356       1.1  kiyohara 	if (autoen)
    357       1.1  kiyohara 		ctrl |= MVSOCTMR_CTCR_CPUTIMERAUTO(num);
    358       1.1  kiyohara 	else
    359       1.1  kiyohara 		ctrl &= ~MVSOCTMR_CTCR_CPUTIMERAUTO(num);
    360      1.11  kiyohara 	if (sc->sc_flags & TMR_FLAGS_25MHZ)
    361      1.10  kiyohara 		/* Set timer and counter to 25MHz mode */
    362      1.10  kiyohara 		ctrl |= MVSOCTMR_CTCR_25MHZEN(num);
    363       1.1  kiyohara 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, MVSOCTMR_CTCR, ctrl);
    364       1.1  kiyohara }
    365       1.4      hans 
    366       1.4      hans static int
    367       1.4      hans mvsoctmr_wdog_setmode(struct sysmon_wdog *smw)
    368       1.4      hans {
    369       1.4      hans 	struct mvsoctmr_softc *sc = smw->smw_cookie;
    370       1.4      hans 
    371       1.4      hans 	if ((smw->smw_mode & WDOG_MODE_MASK) == WDOG_MODE_DISARMED) {
    372       1.4      hans 		sc->sc_wdog_armed = 0;
    373       1.5  jakllsch 		mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG, 0xffffffff, 0, 0);
    374       1.4      hans 	} else {
    375       1.4      hans 		sc->sc_wdog_armed = 1;
    376       1.4      hans 		if (smw->smw_period == WDOG_PERIOD_DEFAULT)
    377       1.4      hans 			smw->smw_period = MVSOC_WDOG_MAX_PERIOD;
    378       1.4      hans 		else if (smw->smw_period > MVSOC_WDOG_MAX_PERIOD ||
    379       1.4      hans 			 smw->smw_period <= 0)
    380       1.4      hans 			return (EOPNOTSUPP);
    381      1.11  kiyohara 		sc->sc_wdog_period = smw->smw_period * mvsoctmr_freq;
    382       1.4      hans 		mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG, sc->sc_wdog_period, 1, 0);
    383       1.4      hans 	}
    384       1.4      hans 
    385       1.4      hans 	return (0);
    386       1.4      hans }
    387       1.4      hans 
    388       1.4      hans static int
    389       1.4      hans mvsoctmr_wdog_tickle(struct sysmon_wdog *smw)
    390       1.4      hans {
    391       1.4      hans 	struct mvsoctmr_softc *sc = smw->smw_cookie;
    392       1.4      hans 
    393       1.4      hans 	mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG, sc->sc_wdog_period, 1, 0);
    394       1.4      hans 
    395       1.4      hans 	return (0);
    396       1.4      hans }
    397       1.4      hans 
    398       1.4      hans #ifdef DDB
    399       1.4      hans static void
    400       1.4      hans mvsoctmr_wdog_ddb_trap(int enter)
    401       1.4      hans {
    402       1.6  jakllsch 	struct mvsoctmr_softc *sc = mvsoctmr_sc;
    403       1.4      hans 
    404       1.4      hans 	if (sc == NULL)
    405       1.4      hans 		return;
    406       1.4      hans 
    407       1.4      hans 	if (sc->sc_wdog_armed) {
    408       1.4      hans 		if (enter)
    409       1.5  jakllsch 			mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG, 0xffffffff, 0, 0);
    410       1.4      hans 		else
    411       1.4      hans 			mvsoctmr_cntl(sc, MVSOCTMR_WATCHDOG,
    412       1.4      hans 				      sc->sc_wdog_period, 1, 0);
    413       1.4      hans 	}
    414       1.4      hans }
    415       1.4      hans #endif
    416