blob: b38c400016118630d4821a868c156a604d275858 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek80e045f2013-04-22 11:23:16 +02002/*
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +05303 * Xilinx AXI platforms watchdog timer driver.
4 *
Michal Simeka8c94362023-07-10 14:35:49 +02005 * Author(s): Michal Simek <michal.simek@amd.com>
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +05306 * Shreenidhi Shedi <yesshedi@gmail.com>
7 *
8 * Copyright (c) 2011-2018 Xilinx Inc.
Michal Simek80e045f2013-04-22 11:23:16 +02009 */
10
11#include <common.h>
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053012#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053014#include <wdt.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070015#include <linux/err.h>
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053016#include <linux/io.h>
Michal Simek80e045f2013-04-22 11:23:16 +020017
18#define XWT_CSR0_WRS_MASK 0x00000008 /* Reset status Mask */
19#define XWT_CSR0_WDS_MASK 0x00000004 /* Timer state Mask */
20#define XWT_CSR0_EWDT1_MASK 0x00000002 /* Enable bit 1 Mask*/
21#define XWT_CSRX_EWDT2_MASK 0x00000001 /* Enable bit 2 Mask */
22
23struct watchdog_regs {
24 u32 twcsr0; /* 0x0 */
25 u32 twcsr1; /* 0x4 */
26 u32 tbr; /* 0x8 */
27};
28
Simon Glassb75b15b2020-12-03 16:55:23 -070029struct xlnx_wdt_plat {
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053030 bool enable_once;
31 struct watchdog_regs *regs;
32};
Michal Simek80e045f2013-04-22 11:23:16 +020033
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053034static int xlnx_wdt_reset(struct udevice *dev)
Michal Simek80e045f2013-04-22 11:23:16 +020035{
36 u32 reg;
Simon Glassb75b15b2020-12-03 16:55:23 -070037 struct xlnx_wdt_plat *plat = dev_get_plat(dev);
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053038
39 debug("%s ", __func__);
Michal Simek80e045f2013-04-22 11:23:16 +020040
41 /* Read the current contents of TCSR0 */
Simon Glass71fa5b42020-12-03 16:55:18 -070042 reg = readl(&plat->regs->twcsr0);
Michal Simek80e045f2013-04-22 11:23:16 +020043
44 /* Clear the watchdog WDS bit */
45 if (reg & (XWT_CSR0_EWDT1_MASK | XWT_CSRX_EWDT2_MASK))
Simon Glass71fa5b42020-12-03 16:55:18 -070046 writel(reg | XWT_CSR0_WDS_MASK, &plat->regs->twcsr0);
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053047
48 return 0;
Michal Simek80e045f2013-04-22 11:23:16 +020049}
50
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053051static int xlnx_wdt_stop(struct udevice *dev)
Michal Simek80e045f2013-04-22 11:23:16 +020052{
53 u32 reg;
Simon Glassb75b15b2020-12-03 16:55:23 -070054 struct xlnx_wdt_plat *plat = dev_get_plat(dev);
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053055
Simon Glass71fa5b42020-12-03 16:55:18 -070056 if (plat->enable_once) {
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053057 debug("Can't stop Xilinx watchdog.\n");
58 return -EBUSY;
59 }
Michal Simek80e045f2013-04-22 11:23:16 +020060
61 /* Read the current contents of TCSR0 */
Simon Glass71fa5b42020-12-03 16:55:18 -070062 reg = readl(&plat->regs->twcsr0);
Michal Simek80e045f2013-04-22 11:23:16 +020063
Simon Glass71fa5b42020-12-03 16:55:18 -070064 writel(reg & ~XWT_CSR0_EWDT1_MASK, &plat->regs->twcsr0);
65 writel(~XWT_CSRX_EWDT2_MASK, &plat->regs->twcsr1);
Michal Simek80e045f2013-04-22 11:23:16 +020066
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053067 debug("Watchdog disabled!\n");
68
69 return 0;
Michal Simek80e045f2013-04-22 11:23:16 +020070}
71
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053072static int xlnx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
Michal Simek80e045f2013-04-22 11:23:16 +020073{
Simon Glassb75b15b2020-12-03 16:55:23 -070074 struct xlnx_wdt_plat *plat = dev_get_plat(dev);
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053075
76 debug("%s:\n", __func__);
77
78 writel((XWT_CSR0_WRS_MASK | XWT_CSR0_WDS_MASK | XWT_CSR0_EWDT1_MASK),
Simon Glass71fa5b42020-12-03 16:55:18 -070079 &plat->regs->twcsr0);
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053080
Simon Glass71fa5b42020-12-03 16:55:18 -070081 writel(XWT_CSRX_EWDT2_MASK, &plat->regs->twcsr1);
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053082
83 return 0;
Michal Simek80e045f2013-04-22 11:23:16 +020084}
85
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053086static int xlnx_wdt_probe(struct udevice *dev)
Michal Simek80e045f2013-04-22 11:23:16 +020087{
Simon Glass75e534b2020-12-16 21:20:07 -070088 debug("%s: Probing wdt%u\n", __func__, dev_seq(dev));
Michal Simek80e045f2013-04-22 11:23:16 +020089
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053090 return 0;
91}
Michal Simek80e045f2013-04-22 11:23:16 +020092
Simon Glassaad29ae2020-12-03 16:55:21 -070093static int xlnx_wdt_of_to_plat(struct udevice *dev)
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053094{
Simon Glassb75b15b2020-12-03 16:55:23 -070095 struct xlnx_wdt_plat *plat = dev_get_plat(dev);
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053096
Johan Jonker8d5d8e02023-03-13 01:32:04 +010097 plat->regs = dev_read_addr_ptr(dev);
98 if (!plat->regs)
99 return -EINVAL;
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +0530100
Simon Glass71fa5b42020-12-03 16:55:18 -0700101 plat->enable_once = dev_read_u32_default(dev, "xlnx,wdt-enable-once",
102 0);
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +0530103
Simon Glass71fa5b42020-12-03 16:55:18 -0700104 debug("%s: wdt-enable-once %d\n", __func__, plat->enable_once);
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +0530105
106 return 0;
Michal Simek80e045f2013-04-22 11:23:16 +0200107}
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +0530108
109static const struct wdt_ops xlnx_wdt_ops = {
110 .start = xlnx_wdt_start,
111 .reset = xlnx_wdt_reset,
112 .stop = xlnx_wdt_stop,
113};
114
115static const struct udevice_id xlnx_wdt_ids[] = {
116 { .compatible = "xlnx,xps-timebase-wdt-1.00.a", },
117 { .compatible = "xlnx,xps-timebase-wdt-1.01.a", },
118 {},
119};
120
121U_BOOT_DRIVER(xlnx_wdt) = {
122 .name = "xlnx_wdt",
123 .id = UCLASS_WDT,
124 .of_match = xlnx_wdt_ids,
125 .probe = xlnx_wdt_probe,
Simon Glassb75b15b2020-12-03 16:55:23 -0700126 .plat_auto = sizeof(struct xlnx_wdt_plat),
Simon Glassaad29ae2020-12-03 16:55:21 -0700127 .of_to_plat = xlnx_wdt_of_to_plat,
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +0530128 .ops = &xlnx_wdt_ops,
129};