blob: 5580764da7ce8d88fe1a6f8c65af28668f94447b [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 *
5 * Author(s): Michal Simek <michal.simek@xilinx.com>
6 * 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>
13#include <wdt.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070014#include <linux/err.h>
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053015#include <linux/io.h>
Michal Simek80e045f2013-04-22 11:23:16 +020016
17#define XWT_CSR0_WRS_MASK 0x00000008 /* Reset status Mask */
18#define XWT_CSR0_WDS_MASK 0x00000004 /* Timer state Mask */
19#define XWT_CSR0_EWDT1_MASK 0x00000002 /* Enable bit 1 Mask*/
20#define XWT_CSRX_EWDT2_MASK 0x00000001 /* Enable bit 2 Mask */
21
22struct watchdog_regs {
23 u32 twcsr0; /* 0x0 */
24 u32 twcsr1; /* 0x4 */
25 u32 tbr; /* 0x8 */
26};
27
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053028struct xlnx_wdt_platdata {
29 bool enable_once;
30 struct watchdog_regs *regs;
31};
Michal Simek80e045f2013-04-22 11:23:16 +020032
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053033static int xlnx_wdt_reset(struct udevice *dev)
Michal Simek80e045f2013-04-22 11:23:16 +020034{
35 u32 reg;
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053036 struct xlnx_wdt_platdata *platdata = dev_get_platdata(dev);
37
38 debug("%s ", __func__);
Michal Simek80e045f2013-04-22 11:23:16 +020039
40 /* Read the current contents of TCSR0 */
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053041 reg = readl(&platdata->regs->twcsr0);
Michal Simek80e045f2013-04-22 11:23:16 +020042
43 /* Clear the watchdog WDS bit */
44 if (reg & (XWT_CSR0_EWDT1_MASK | XWT_CSRX_EWDT2_MASK))
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053045 writel(reg | XWT_CSR0_WDS_MASK, &platdata->regs->twcsr0);
46
47 return 0;
Michal Simek80e045f2013-04-22 11:23:16 +020048}
49
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053050static int xlnx_wdt_stop(struct udevice *dev)
Michal Simek80e045f2013-04-22 11:23:16 +020051{
52 u32 reg;
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053053 struct xlnx_wdt_platdata *platdata = dev_get_platdata(dev);
54
55 if (platdata->enable_once) {
56 debug("Can't stop Xilinx watchdog.\n");
57 return -EBUSY;
58 }
Michal Simek80e045f2013-04-22 11:23:16 +020059
60 /* Read the current contents of TCSR0 */
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053061 reg = readl(&platdata->regs->twcsr0);
Michal Simek80e045f2013-04-22 11:23:16 +020062
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053063 writel(reg & ~XWT_CSR0_EWDT1_MASK, &platdata->regs->twcsr0);
64 writel(~XWT_CSRX_EWDT2_MASK, &platdata->regs->twcsr1);
Michal Simek80e045f2013-04-22 11:23:16 +020065
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053066 debug("Watchdog disabled!\n");
67
68 return 0;
Michal Simek80e045f2013-04-22 11:23:16 +020069}
70
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053071static int xlnx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
Michal Simek80e045f2013-04-22 11:23:16 +020072{
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053073 struct xlnx_wdt_platdata *platdata = dev_get_platdata(dev);
74
75 debug("%s:\n", __func__);
76
77 writel((XWT_CSR0_WRS_MASK | XWT_CSR0_WDS_MASK | XWT_CSR0_EWDT1_MASK),
78 &platdata->regs->twcsr0);
79
80 writel(XWT_CSRX_EWDT2_MASK, &platdata->regs->twcsr1);
81
82 return 0;
Michal Simek80e045f2013-04-22 11:23:16 +020083}
84
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053085static int xlnx_wdt_probe(struct udevice *dev)
Michal Simek80e045f2013-04-22 11:23:16 +020086{
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053087 debug("%s: Probing wdt%u\n", __func__, dev->seq);
Michal Simek80e045f2013-04-22 11:23:16 +020088
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053089 return 0;
90}
Michal Simek80e045f2013-04-22 11:23:16 +020091
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +053092static int xlnx_wdt_ofdata_to_platdata(struct udevice *dev)
93{
94 struct xlnx_wdt_platdata *platdata = dev_get_platdata(dev);
95
96 platdata->regs = (struct watchdog_regs *)dev_read_addr(dev);
97 if (IS_ERR(platdata->regs))
98 return PTR_ERR(platdata->regs);
99
100 platdata->enable_once = dev_read_u32_default(dev,
101 "xlnx,wdt-enable-once", 0);
102
103 debug("%s: wdt-enable-once %d\n", __func__, platdata->enable_once);
104
105 return 0;
Michal Simek80e045f2013-04-22 11:23:16 +0200106}
Shreenidhi Shedi335fb5b2018-07-15 02:05:41 +0530107
108static const struct wdt_ops xlnx_wdt_ops = {
109 .start = xlnx_wdt_start,
110 .reset = xlnx_wdt_reset,
111 .stop = xlnx_wdt_stop,
112};
113
114static const struct udevice_id xlnx_wdt_ids[] = {
115 { .compatible = "xlnx,xps-timebase-wdt-1.00.a", },
116 { .compatible = "xlnx,xps-timebase-wdt-1.01.a", },
117 {},
118};
119
120U_BOOT_DRIVER(xlnx_wdt) = {
121 .name = "xlnx_wdt",
122 .id = UCLASS_WDT,
123 .of_match = xlnx_wdt_ids,
124 .probe = xlnx_wdt_probe,
125 .platdata_auto_alloc_size = sizeof(struct xlnx_wdt_platdata),
126 .ofdata_to_platdata = xlnx_wdt_ofdata_to_platdata,
127 .ops = &xlnx_wdt_ops,
128};