#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/bus.h>
#include <machine/fdt.h>
#include <armv7/armv7/armv7_machdep.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/fdt.h>
#define WTCON 0x00
#define WTDAT 0x04
#define WTCNT 0x08
#define WTCLRINT 0x0C
#define WTCON_RESET (1 << 0)
#define WTCON_INT (1 << 2)
#define WTCON_CLKSEL_16 (0x0 << 3)
#define WTCON_CLKSEL_32 (0x1 << 3)
#define WTCON_CLKSEL_64 (0x2 << 3)
#define WTCON_CLKSEL_128 (0x3 << 3)
#define WTCON_EN (1 << 5)
#define WTCON_PRESCALER(x) (((x) & 0xff) << 8)
struct exdog_softc {
struct device sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
};
struct exdog_softc *exdog_sc;
int exdog_match(struct device *parent, void *v, void *aux);
void exdog_attach(struct device *parent, struct device *self, void *args);
void exdog_stop(void);
void exdog_reset(void);
const struct cfattach exdog_ca = {
sizeof (struct exdog_softc), exdog_match, exdog_attach
};
struct cfdriver exdog_cd = {
NULL, "exdog", DV_DULL
};
int
exdog_match(struct device *parent, void *cfdata, void *aux)
{
struct fdt_attach_args *fa = aux;
return (OF_is_compatible(fa->fa_node, "samsung,exynos5250-wdt") ||
OF_is_compatible(fa->fa_node, "samsung,exynos5420-wdt"));
}
void
exdog_attach(struct device *parent, struct device *self, void *aux)
{
struct exdog_softc *sc = (struct exdog_softc *)self;
struct fdt_attach_args *fa = aux;
sc->sc_iot = fa->fa_iot;
if (bus_space_map(sc->sc_iot, fa->fa_reg[0].addr,
fa->fa_reg[0].size, 0, &sc->sc_ioh))
panic("%s: bus_space_map failed!", __func__);
printf("\n");
exdog_sc = sc;
if (cpuresetfn == NULL)
cpuresetfn = exdog_reset;
}
void
exdog_stop(void)
{
uint32_t wtcon;
if (exdog_sc == NULL)
return;
wtcon = bus_space_read_4(exdog_sc->sc_iot, exdog_sc->sc_ioh, WTCON);
wtcon &= ~(WTCON_EN | WTCON_INT | WTCON_RESET);
bus_space_write_4(exdog_sc->sc_iot, exdog_sc->sc_ioh, WTCON, wtcon);
}
void
exdog_reset(void)
{
uint32_t wtcon;
if (exdog_sc == NULL)
return;
exdog_stop();
wtcon = bus_space_read_4(exdog_sc->sc_iot, exdog_sc->sc_ioh, WTCON);
wtcon |= WTCON_EN | WTCON_CLKSEL_128;
wtcon &= ~WTCON_INT;
wtcon |= WTCON_RESET;
wtcon |= WTCON_PRESCALER(0xff);
bus_space_write_4(exdog_sc->sc_iot, exdog_sc->sc_ioh, WTDAT, 1);
bus_space_write_4(exdog_sc->sc_iot, exdog_sc->sc_ioh, WTCNT, 1);
bus_space_write_4(exdog_sc->sc_iot, exdog_sc->sc_ioh, WTCON, wtcon);
delay(100000);
}