#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <machine/bus.h>
#include <machine/fdt.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_misc.h>
#include <dev/ofw/fdt.h>
#define WDT_ENABLE (1 << 8)
#define RSTOUT_ENABLE (1 << 8)
#define RSTOUT_MASK (1 << 10)
#define HREAD4(sc, ioh, reg) \
(bus_space_read_4((sc)->sc_iot, (ioh), (reg)))
#define HWRITE4(sc, ioh, reg, val) \
bus_space_write_4((sc)->sc_iot, (ioh), (reg), (val))
#define HSET4(sc, ioh, reg, bits) \
HWRITE4((sc), (ioh), (reg), HREAD4((sc), (ioh), (reg)) | (bits))
#define HCLR4(sc, ioh, reg, bits) \
HWRITE4((sc), (ioh), (reg), HREAD4((sc), (ioh), (reg)) & ~(bits))
struct mvodog_softc {
struct device sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_reg_ioh;
bus_space_handle_t sc_rstout_ioh;
bus_space_handle_t sc_rstout_mask_ioh;
};
int mvodog_match(struct device *, void *, void *);
void mvodog_attach(struct device *, struct device *, void *);
const struct cfattach mvodog_ca = {
sizeof (struct mvodog_softc), mvodog_match, mvodog_attach
};
struct cfdriver mvodog_cd = {
NULL, "mvodog", DV_DULL
};
int
mvodog_match(struct device *parent, void *cfdata, void *aux)
{
struct fdt_attach_args *faa = aux;
return OF_is_compatible(faa->fa_node, "marvell,armada-380-wdt");
}
void
mvodog_attach(struct device *parent, struct device *self, void *aux)
{
struct mvodog_softc *sc = (struct mvodog_softc *)self;
struct fdt_attach_args *faa = aux;
if (faa->fa_nreg < 1) {
printf(": no registers\n");
return;
}
sc->sc_iot = faa->fa_iot;
if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr,
faa->fa_reg[0].size, 0, &sc->sc_reg_ioh)) {
printf(": can't map registers\n");
return;
}
if (bus_space_map(sc->sc_iot, faa->fa_reg[1].addr,
faa->fa_reg[1].size, 0, &sc->sc_rstout_ioh)) {
printf(": can't map rstout\n");
return;
}
if (bus_space_map(sc->sc_iot, faa->fa_reg[2].addr,
faa->fa_reg[2].size, 0, &sc->sc_rstout_mask_ioh)) {
printf(": can't map rstout mask\n");
return;
}
printf("\n");
HSET4(sc, sc->sc_rstout_mask_ioh, 0, RSTOUT_MASK);
HCLR4(sc, sc->sc_rstout_ioh, 0, RSTOUT_ENABLE);
HCLR4(sc, sc->sc_reg_ioh, 0, WDT_ENABLE);
}