> Date: Mon, 14 Feb 2022 00:04:50 +0100
> From: Tobias Heider <[email protected]>
> 
> On Sun, Feb 13, 2022 at 03:47:28PM +0100, Mark Kettenis wrote:
> > 
> > I'm not sure this code should share a driver with the A3700 code.  The
> > hardware doesn't seem to share any commonalities except for the
> > Marvell name.  Linux has a separate driver which it calls "orion_wdt".
> > So maybe mvodog(4) is a good name for a separate driver.
> > 
> > Also, since this block doesn't seem to be used on any 64-bit SoCs, the
> > driver probably belongs in sys/arch/armv7/marvell/.
> > 
> > Cheers,
> > 
> > Mark
> > 
> 
> Makes sense. Below is a diff adding mvodog(4) for armv7.
> I also renamed the constants to A380_* for patrick@

One small nit below.  Otherwise, ok kettenis@

> diff --git sys/arch/armv7/conf/GENERIC sys/arch/armv7/conf/GENERIC
> index d8cf637e1c6..c2ded46e895 100644
> --- sys/arch/armv7/conf/GENERIC
> +++ sys/arch/armv7/conf/GENERIC
> @@ -187,6 +187,7 @@ usb*              at dwctwo?
>  # Marvell SoC
>  mvacc*               at fdt? early 1
>  mvagc*               at fdt?
> +mvodog*              at fdt?
>  mvsysctrl*   at fdt?
>  mvmbus*              at fdt?
>  mvxhci*              at fdt?
> diff --git sys/arch/armv7/conf/RAMDISK sys/arch/armv7/conf/RAMDISK
> index eb969297500..57375f10497 100644
> --- sys/arch/armv7/conf/RAMDISK
> +++ sys/arch/armv7/conf/RAMDISK
> @@ -173,6 +173,7 @@ usb*              at dwctwo?
>  # Marvell SoC
>  mvacc*               at fdt? early 1
>  mvagc*               at fdt?
> +mvodog*              at fdt?
>  mvsysctrl*   at fdt?
>  mvmbus*              at fdt?
>  mvxhci*              at fdt?
> diff --git sys/arch/armv7/marvell/files.marvell 
> sys/arch/armv7/marvell/files.marvell
> index b0ceb1768e2..d9e67565f96 100644
> --- sys/arch/armv7/marvell/files.marvell
> +++ sys/arch/armv7/marvell/files.marvell
> @@ -35,3 +35,7 @@ file        arch/armv7/marvell/mvpcie.c                     
> mvpcie
>  device mvpxa: sdmmcbus, sdhc
>  attach mvpxa at fdt
>  file arch/armv7/marvell/mvpxa.c                      mvpxa
> +
> +device mvodog
> +attach mvodog at fdt
> +file arch/armv7/marvell/mvodog.c                     mvodog
> diff --git sys/arch/armv7/marvell/mvodog.c sys/arch/armv7/marvell/mvodog.c
> new file mode 100644
> index 00000000000..c011cb1cffe
> --- /dev/null
> +++ sys/arch/armv7/marvell/mvodog.c
> @@ -0,0 +1,99 @@
> +/* $OpenBSD$ */
> +/*
> + * Copyright (c) 2022 Tobias Heider <[email protected]>
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#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 A380_RSTOUT_MASK_BIT (1 << 10)
> +#define A380_RSTOUT_ENABLE_BIT       (1 << 8)
> +#define A380_WDT_ENABLE_BIT  (1 << 8)
> +
> +struct mvodog_softc {
> +     struct device            sc_dev;
> +     bus_space_tag_t          sc_iot;
> +     bus_space_handle_t       sc_ioh;
> +     bus_space_handle_t       sc_ioh_rout;
> +     bus_space_handle_t       sc_ioh_routmask;
> +};
> +
> +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) {

That should be < 3 since you need at least 3 register blocks.

> +             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_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_ioh_rout)) {
> +             printf(": can't map registers\n");
> +             return;
> +     }
> +     if (bus_space_map(sc->sc_iot, faa->fa_reg[2].addr,
> +         faa->fa_reg[2].size, 0, &sc->sc_ioh_routmask)) {
> +             printf(": can't map registers\n");
> +             return;
> +     }
> +
> +     /* Disable watchdog timer. */
> +     bus_space_write_4(sc->sc_iot, sc->sc_ioh_routmask, 0,
> +         bus_space_read_4(sc->sc_iot, sc->sc_ioh_routmask, 0) |
> +         A380_RSTOUT_MASK_BIT);
> +     bus_space_write_4(sc->sc_iot, sc->sc_ioh_rout, 0,
> +         bus_space_read_4(sc->sc_iot, sc->sc_ioh_rout, 0) &
> +         ~A380_RSTOUT_ENABLE_BIT);
> +     bus_space_write_4(sc->sc_iot, sc->sc_ioh, 0,
> +         bus_space_read_4(sc->sc_iot, sc->sc_ioh, 0) &
> +         ~A380_WDT_ENABLE_BIT);
> +
> +     printf("\n");
> +}
> 

Reply via email to