2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-04-22 09:23:16 +00:00
|
|
|
/*
|
2018-07-14 20:35:41 +00:00
|
|
|
* Xilinx AXI platforms watchdog timer driver.
|
|
|
|
*
|
2023-07-10 12:35:49 +00:00
|
|
|
* Author(s): Michal Simek <michal.simek@amd.com>
|
2018-07-14 20:35:41 +00:00
|
|
|
* Shreenidhi Shedi <yesshedi@gmail.com>
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011-2018 Xilinx Inc.
|
2013-04-22 09:23:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2018-07-14 20:35:41 +00:00
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-07-14 20:35:41 +00:00
|
|
|
#include <wdt.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2018-07-14 20:35:41 +00:00
|
|
|
#include <linux/io.h>
|
2013-04-22 09:23:16 +00:00
|
|
|
|
|
|
|
#define XWT_CSR0_WRS_MASK 0x00000008 /* Reset status Mask */
|
|
|
|
#define XWT_CSR0_WDS_MASK 0x00000004 /* Timer state Mask */
|
|
|
|
#define XWT_CSR0_EWDT1_MASK 0x00000002 /* Enable bit 1 Mask*/
|
|
|
|
#define XWT_CSRX_EWDT2_MASK 0x00000001 /* Enable bit 2 Mask */
|
|
|
|
|
|
|
|
struct watchdog_regs {
|
|
|
|
u32 twcsr0; /* 0x0 */
|
|
|
|
u32 twcsr1; /* 0x4 */
|
|
|
|
u32 tbr; /* 0x8 */
|
|
|
|
};
|
|
|
|
|
2020-12-03 23:55:23 +00:00
|
|
|
struct xlnx_wdt_plat {
|
2018-07-14 20:35:41 +00:00
|
|
|
bool enable_once;
|
|
|
|
struct watchdog_regs *regs;
|
|
|
|
};
|
2013-04-22 09:23:16 +00:00
|
|
|
|
2018-07-14 20:35:41 +00:00
|
|
|
static int xlnx_wdt_reset(struct udevice *dev)
|
2013-04-22 09:23:16 +00:00
|
|
|
{
|
|
|
|
u32 reg;
|
2020-12-03 23:55:23 +00:00
|
|
|
struct xlnx_wdt_plat *plat = dev_get_plat(dev);
|
2018-07-14 20:35:41 +00:00
|
|
|
|
|
|
|
debug("%s ", __func__);
|
2013-04-22 09:23:16 +00:00
|
|
|
|
|
|
|
/* Read the current contents of TCSR0 */
|
2020-12-03 23:55:18 +00:00
|
|
|
reg = readl(&plat->regs->twcsr0);
|
2013-04-22 09:23:16 +00:00
|
|
|
|
|
|
|
/* Clear the watchdog WDS bit */
|
|
|
|
if (reg & (XWT_CSR0_EWDT1_MASK | XWT_CSRX_EWDT2_MASK))
|
2020-12-03 23:55:18 +00:00
|
|
|
writel(reg | XWT_CSR0_WDS_MASK, &plat->regs->twcsr0);
|
2018-07-14 20:35:41 +00:00
|
|
|
|
|
|
|
return 0;
|
2013-04-22 09:23:16 +00:00
|
|
|
}
|
|
|
|
|
2018-07-14 20:35:41 +00:00
|
|
|
static int xlnx_wdt_stop(struct udevice *dev)
|
2013-04-22 09:23:16 +00:00
|
|
|
{
|
|
|
|
u32 reg;
|
2020-12-03 23:55:23 +00:00
|
|
|
struct xlnx_wdt_plat *plat = dev_get_plat(dev);
|
2018-07-14 20:35:41 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
if (plat->enable_once) {
|
2018-07-14 20:35:41 +00:00
|
|
|
debug("Can't stop Xilinx watchdog.\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
2013-04-22 09:23:16 +00:00
|
|
|
|
|
|
|
/* Read the current contents of TCSR0 */
|
2020-12-03 23:55:18 +00:00
|
|
|
reg = readl(&plat->regs->twcsr0);
|
2018-07-14 20:35:41 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
writel(reg & ~XWT_CSR0_EWDT1_MASK, &plat->regs->twcsr0);
|
|
|
|
writel(~XWT_CSRX_EWDT2_MASK, &plat->regs->twcsr1);
|
2013-04-22 09:23:16 +00:00
|
|
|
|
2018-07-14 20:35:41 +00:00
|
|
|
debug("Watchdog disabled!\n");
|
2013-04-22 09:23:16 +00:00
|
|
|
|
2018-07-14 20:35:41 +00:00
|
|
|
return 0;
|
2013-04-22 09:23:16 +00:00
|
|
|
}
|
|
|
|
|
2018-07-14 20:35:41 +00:00
|
|
|
static int xlnx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
|
2013-04-22 09:23:16 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct xlnx_wdt_plat *plat = dev_get_plat(dev);
|
2018-07-14 20:35:41 +00:00
|
|
|
|
|
|
|
debug("%s:\n", __func__);
|
|
|
|
|
|
|
|
writel((XWT_CSR0_WRS_MASK | XWT_CSR0_WDS_MASK | XWT_CSR0_EWDT1_MASK),
|
2020-12-03 23:55:18 +00:00
|
|
|
&plat->regs->twcsr0);
|
2018-07-14 20:35:41 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
writel(XWT_CSRX_EWDT2_MASK, &plat->regs->twcsr1);
|
2018-07-14 20:35:41 +00:00
|
|
|
|
|
|
|
return 0;
|
2013-04-22 09:23:16 +00:00
|
|
|
}
|
|
|
|
|
2018-07-14 20:35:41 +00:00
|
|
|
static int xlnx_wdt_probe(struct udevice *dev)
|
2013-04-22 09:23:16 +00:00
|
|
|
{
|
2020-12-17 04:20:07 +00:00
|
|
|
debug("%s: Probing wdt%u\n", __func__, dev_seq(dev));
|
2013-04-22 09:23:16 +00:00
|
|
|
|
2018-07-14 20:35:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-04-22 09:23:16 +00:00
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int xlnx_wdt_of_to_plat(struct udevice *dev)
|
2018-07-14 20:35:41 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct xlnx_wdt_plat *plat = dev_get_plat(dev);
|
2018-07-14 20:35:41 +00:00
|
|
|
|
2023-03-13 00:32:04 +00:00
|
|
|
plat->regs = dev_read_addr_ptr(dev);
|
|
|
|
if (!plat->regs)
|
|
|
|
return -EINVAL;
|
2018-07-14 20:35:41 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
plat->enable_once = dev_read_u32_default(dev, "xlnx,wdt-enable-once",
|
|
|
|
0);
|
2018-07-14 20:35:41 +00:00
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
debug("%s: wdt-enable-once %d\n", __func__, plat->enable_once);
|
2018-07-14 20:35:41 +00:00
|
|
|
|
|
|
|
return 0;
|
2013-04-22 09:23:16 +00:00
|
|
|
}
|
2018-07-14 20:35:41 +00:00
|
|
|
|
|
|
|
static const struct wdt_ops xlnx_wdt_ops = {
|
|
|
|
.start = xlnx_wdt_start,
|
|
|
|
.reset = xlnx_wdt_reset,
|
|
|
|
.stop = xlnx_wdt_stop,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id xlnx_wdt_ids[] = {
|
|
|
|
{ .compatible = "xlnx,xps-timebase-wdt-1.00.a", },
|
|
|
|
{ .compatible = "xlnx,xps-timebase-wdt-1.01.a", },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(xlnx_wdt) = {
|
|
|
|
.name = "xlnx_wdt",
|
|
|
|
.id = UCLASS_WDT,
|
|
|
|
.of_match = xlnx_wdt_ids,
|
|
|
|
.probe = xlnx_wdt_probe,
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct xlnx_wdt_plat),
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = xlnx_wdt_of_to_plat,
|
2018-07-14 20:35:41 +00:00
|
|
|
.ops = &xlnx_wdt_ops,
|
|
|
|
};
|