Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 2 | /* |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 3 | * 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 Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 12 | #include <dm.h> |
| 13 | #include <wdt.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 14 | #include <linux/err.h> |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 15 | #include <linux/io.h> |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 16 | |
| 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 | |
| 22 | struct watchdog_regs { |
| 23 | u32 twcsr0; /* 0x0 */ |
| 24 | u32 twcsr1; /* 0x4 */ |
| 25 | u32 tbr; /* 0x8 */ |
| 26 | }; |
| 27 | |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 28 | struct xlnx_wdt_platdata { |
| 29 | bool enable_once; |
| 30 | struct watchdog_regs *regs; |
| 31 | }; |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 32 | |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 33 | static int xlnx_wdt_reset(struct udevice *dev) |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 34 | { |
| 35 | u32 reg; |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 36 | struct xlnx_wdt_platdata *platdata = dev_get_platdata(dev); |
| 37 | |
| 38 | debug("%s ", __func__); |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 39 | |
| 40 | /* Read the current contents of TCSR0 */ |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 41 | reg = readl(&platdata->regs->twcsr0); |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 42 | |
| 43 | /* Clear the watchdog WDS bit */ |
| 44 | if (reg & (XWT_CSR0_EWDT1_MASK | XWT_CSRX_EWDT2_MASK)) |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 45 | writel(reg | XWT_CSR0_WDS_MASK, &platdata->regs->twcsr0); |
| 46 | |
| 47 | return 0; |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 48 | } |
| 49 | |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 50 | static int xlnx_wdt_stop(struct udevice *dev) |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 51 | { |
| 52 | u32 reg; |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 53 | 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 Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 59 | |
| 60 | /* Read the current contents of TCSR0 */ |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 61 | reg = readl(&platdata->regs->twcsr0); |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 62 | |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 63 | writel(reg & ~XWT_CSR0_EWDT1_MASK, &platdata->regs->twcsr0); |
| 64 | writel(~XWT_CSRX_EWDT2_MASK, &platdata->regs->twcsr1); |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 65 | |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 66 | debug("Watchdog disabled!\n"); |
| 67 | |
| 68 | return 0; |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 69 | } |
| 70 | |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 71 | static int xlnx_wdt_start(struct udevice *dev, u64 timeout, ulong flags) |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 72 | { |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 73 | 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 Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 85 | static int xlnx_wdt_probe(struct udevice *dev) |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 86 | { |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 87 | debug("%s: Probing wdt%u\n", __func__, dev->seq); |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 88 | |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 89 | return 0; |
| 90 | } |
Michal Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 91 | |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 92 | static 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 Simek | 80e045f | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 106 | } |
Shreenidhi Shedi | 335fb5b | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 107 | |
| 108 | static const struct wdt_ops xlnx_wdt_ops = { |
| 109 | .start = xlnx_wdt_start, |
| 110 | .reset = xlnx_wdt_reset, |
| 111 | .stop = xlnx_wdt_stop, |
| 112 | }; |
| 113 | |
| 114 | static 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 | |
| 120 | U_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 | }; |