+// SPDX-License-Identifier: GPL-2.0
/*
* Cadence WDT driver - Used by Xilinx Zynq
* Reference: Linux kernel Cadence watchdog driver.
*
* Author(s): Shreenidhi Shedi <yesshedi@gmail.com>
- *
- * SPDX-License-Identifier: GPL-2.0
*/
#include <common.h>
#include <dm.h>
+#include <log.h>
#include <wdt.h>
#include <clk.h>
+#include <div64.h>
+#include <dm/device_compat.h>
+#include <linux/err.h>
#include <linux/io.h>
-DECLARE_GLOBAL_DATA_PTR;
-
struct cdns_regs {
u32 zmr; /* WD Zero mode register, offset - 0x0 */
u32 ccr; /* Counter Control Register offset - 0x4 */
struct cdns_wdt_priv {
bool rst;
- u32 timeout;
struct cdns_regs *regs;
};
return -1;
}
- debug("%s: CLK_FREQ %ld, timeout %lld\n", __func__, clk_f, timeout);
+ /* Calculate timeout in seconds and restrict to min and max value */
+ do_div(timeout, 1000);
+ timeout = max_t(u64, timeout, CDNS_WDT_MIN_TIMEOUT);
+ timeout = min_t(u64, timeout, CDNS_WDT_MAX_TIMEOUT);
- if ((timeout < CDNS_WDT_MIN_TIMEOUT) ||
- (timeout > CDNS_WDT_MAX_TIMEOUT)) {
- timeout = priv->timeout;
- }
+ debug("%s: CLK_FREQ %ld, timeout %lld\n", __func__, clk_f, timeout);
if (clk_f <= CDNS_WDT_CLK_75MHZ) {
prescaler = CDNS_WDT_PRESCALE_512;
{
debug("%s: Probing wdt%u\n", __func__, dev->seq);
- cdns_wdt_stop(dev);
-
return 0;
}
static int cdns_wdt_ofdata_to_platdata(struct udevice *dev)
{
- int node = dev_of_offset(dev);
struct cdns_wdt_priv *priv = dev_get_priv(dev);
- priv->regs = devfdt_get_addr_ptr(dev);
+ priv->regs = (struct cdns_regs *)dev_read_addr(dev);
if (IS_ERR(priv->regs))
return PTR_ERR(priv->regs);
- priv->timeout = fdtdec_get_int(gd->fdt_blob, node, "timeout-sec",
- CDNS_WDT_DEFAULT_TIMEOUT);
-
- priv->rst = fdtdec_get_bool(gd->fdt_blob, node, "reset-on-timeout");
+ priv->rst = dev_read_bool(dev, "reset-on-timeout");
- debug("%s: timeout %d, reset %d\n", __func__, priv->timeout, priv->rst);
+ debug("%s: reset %d\n", __func__, priv->rst);
return 0;
}
.start = cdns_wdt_start,
.reset = cdns_wdt_reset,
.stop = cdns_wdt_stop,
+ /* There is no bit/reg/support in IP for expire_now functionality */
};
static const struct udevice_id cdns_wdt_ids[] = {
.id = UCLASS_WDT,
.of_match = cdns_wdt_ids,
.probe = cdns_wdt_probe,
- .priv_auto_alloc_size = sizeof(struct cdns_wdt_priv),
+ .priv_auto = sizeof(struct cdns_wdt_priv),
.ofdata_to_platdata = cdns_wdt_ofdata_to_platdata,
.ops = &cdns_wdt_ops,
};