2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2018-03-16 16:21:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 CS Systemes d'Information
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-02-19 16:50:15 +00:00
|
|
|
#include <env.h>
|
2018-11-21 08:51:45 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <wdt.h>
|
2018-03-16 16:21:01 +00:00
|
|
|
#include <mpc8xx.h>
|
|
|
|
#include <asm/cpm_8xx.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
2020-02-20 07:39:51 +00:00
|
|
|
void hw_watchdog_reset(void)
|
2018-03-16 16:21:01 +00:00
|
|
|
{
|
|
|
|
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 */
|
|
|
|
}
|
|
|
|
|
2018-11-21 08:51:45 +00:00
|
|
|
static int mpc8xx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
|
|
|
|
{
|
|
|
|
immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
|
2020-02-19 16:50:15 +00:00
|
|
|
u32 val = CONFIG_SYS_SYPCR;
|
|
|
|
const char *mode = env_get("watchdog_mode");
|
2018-11-21 08:51:45 +00:00
|
|
|
|
2020-02-19 16:50:15 +00:00
|
|
|
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);
|
2018-11-21 08:51:45 +00:00
|
|
|
|
|
|
|
if (!(in_be32(&immap->im_siu_conf.sc_sypcr) & SYPCR_SWE))
|
|
|
|
return -EBUSY;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mpc8xx_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 mpc8xx_wdt_reset(struct udevice *dev)
|
|
|
|
{
|
|
|
|
hw_watchdog_reset();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wdt_ops mpc8xx_wdt_ops = {
|
|
|
|
.start = mpc8xx_wdt_start,
|
|
|
|
.reset = mpc8xx_wdt_reset,
|
|
|
|
.stop = mpc8xx_wdt_stop,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id mpc8xx_wdt_ids[] = {
|
|
|
|
{ .compatible = "fsl,pq1-wdt" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(wdt_mpc8xx) = {
|
|
|
|
.name = "wdt_mpc8xx",
|
|
|
|
.id = UCLASS_WDT,
|
|
|
|
.of_match = mpc8xx_wdt_ids,
|
|
|
|
.ops = &mpc8xx_wdt_ops,
|
|
|
|
};
|