u-boot/drivers/watchdog/mpc8xxx_wdt.c
Christophe Leroy 21eaade449 watchdog: mpc8xx: Rename it mpc8xxx
mpc8xx, mpc83xx and mpc86xx have similar watchdog with almost same
memory registers.

Rename it mpc8xxx which is the generic name used for drivers supporting
several mpc families.

The driver will be made more generic in following patch.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
2023-04-05 19:46:18 +02:00

75 lines
1.6 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright 2017 CS Systemes d'Information
*/
#include <common.h>
#include <env.h>
#include <dm.h>
#include <wdt.h>
#include <mpc8xx.h>
#include <asm/cpm_8xx.h>
#include <asm/io.h>
void hw_watchdog_reset(void)
{
immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
out_be16(&immap->im_siu_conf.sc_swsr, 0x556c); /* write magic1 */
out_be16(&immap->im_siu_conf.sc_swsr, 0xaa39); /* write magic2 */
}
static int mpc8xxx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
{
immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
u32 val = CONFIG_SYS_SYPCR;
const char *mode = env_get("watchdog_mode");
if (strcmp(mode, "off") == 0)
val = val & ~(SYPCR_SWE | SYPCR_SWRI);
else if (strcmp(mode, "nmi") == 0)
val = (val & ~SYPCR_SWRI) | SYPCR_SWE;
out_be32(&immap->im_siu_conf.sc_sypcr, val);
if (!(in_be32(&immap->im_siu_conf.sc_sypcr) & SYPCR_SWE))
return -EBUSY;
return 0;
}
static int mpc8xxx_wdt_stop(struct udevice *dev)
{
immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
out_be32(&immap->im_siu_conf.sc_sypcr, CONFIG_SYS_SYPCR & ~SYPCR_SWE);
if (in_be32(&immap->im_siu_conf.sc_sypcr) & SYPCR_SWE)
return -EBUSY;
return 0;
}
static int mpc8xxx_wdt_reset(struct udevice *dev)
{
hw_watchdog_reset();
return 0;
}
static const struct wdt_ops mpc8xxx_wdt_ops = {
.start = mpc8xxx_wdt_start,
.reset = mpc8xxx_wdt_reset,
.stop = mpc8xxx_wdt_stop,
};
static const struct udevice_id mpc8xxx_wdt_ids[] = {
{ .compatible = "fsl,pq1-wdt" },
{}
};
U_BOOT_DRIVER(wdt_mpc8xxx) = {
.name = "wdt_mpc8xxx",
.id = UCLASS_WDT,
.of_match = mpc8xxx_wdt_ids,
.ops = &mpc8xxx_wdt_ops,
};