Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 2 | /* |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 3 | * Xilinx AXI platforms watchdog timer driver. |
| 4 | * |
Michal Simek | 174d7284 | 2023-07-10 14:35:49 +0200 | [diff] [blame] | 5 | * Author(s): Michal Simek <michal.simek@amd.com> |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 6 | * Shreenidhi Shedi <yesshedi@gmail.com> |
| 7 | * |
| 8 | * Copyright (c) 2011-2018 Xilinx Inc. |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 12 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 14 | #include <wdt.h> |
Simon Glass | 61b29b8 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 15 | #include <linux/err.h> |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 16 | #include <linux/io.h> |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 17 | |
| 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 | |
| 23 | struct watchdog_regs { |
| 24 | u32 twcsr0; /* 0x0 */ |
| 25 | u32 twcsr1; /* 0x4 */ |
| 26 | u32 tbr; /* 0x8 */ |
| 27 | }; |
| 28 | |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 29 | struct xlnx_wdt_plat { |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 30 | bool enable_once; |
| 31 | struct watchdog_regs *regs; |
| 32 | }; |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 33 | |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 34 | static int xlnx_wdt_reset(struct udevice *dev) |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 35 | { |
| 36 | u32 reg; |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 37 | struct xlnx_wdt_plat *plat = dev_get_plat(dev); |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 38 | |
| 39 | debug("%s ", __func__); |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 40 | |
| 41 | /* Read the current contents of TCSR0 */ |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 42 | reg = readl(&plat->regs->twcsr0); |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 43 | |
| 44 | /* Clear the watchdog WDS bit */ |
| 45 | if (reg & (XWT_CSR0_EWDT1_MASK | XWT_CSRX_EWDT2_MASK)) |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 46 | writel(reg | XWT_CSR0_WDS_MASK, &plat->regs->twcsr0); |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 47 | |
| 48 | return 0; |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 51 | static int xlnx_wdt_stop(struct udevice *dev) |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 52 | { |
| 53 | u32 reg; |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 54 | struct xlnx_wdt_plat *plat = dev_get_plat(dev); |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 55 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 56 | if (plat->enable_once) { |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 57 | debug("Can't stop Xilinx watchdog.\n"); |
| 58 | return -EBUSY; |
| 59 | } |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 60 | |
| 61 | /* Read the current contents of TCSR0 */ |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 62 | reg = readl(&plat->regs->twcsr0); |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 63 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 64 | writel(reg & ~XWT_CSR0_EWDT1_MASK, &plat->regs->twcsr0); |
| 65 | writel(~XWT_CSRX_EWDT2_MASK, &plat->regs->twcsr1); |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 66 | |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 67 | debug("Watchdog disabled!\n"); |
| 68 | |
| 69 | return 0; |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 72 | static int xlnx_wdt_start(struct udevice *dev, u64 timeout, ulong flags) |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 73 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 74 | struct xlnx_wdt_plat *plat = dev_get_plat(dev); |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 75 | |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 76 | debug("%s:\n", __func__); |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 77 | |
| 78 | writel((XWT_CSR0_WRS_MASK | XWT_CSR0_WDS_MASK | XWT_CSR0_EWDT1_MASK), |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 79 | &plat->regs->twcsr0); |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 80 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 81 | writel(XWT_CSRX_EWDT2_MASK, &plat->regs->twcsr1); |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 82 | |
| 83 | return 0; |
Michal Simek | 0f21f98 | 2013-04-22 11:23:16 +0200 | [diff] [blame] | 84 | } |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 85 | |
| 86 | static int xlnx_wdt_probe(struct udevice *dev) |
| 87 | { |
Simon Glass | 8b85dfc | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 88 | debug("%s: Probing wdt%u\n", __func__, dev_seq(dev)); |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 93 | static int xlnx_wdt_of_to_plat(struct udevice *dev) |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 94 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 95 | struct xlnx_wdt_plat *plat = dev_get_plat(dev); |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 96 | |
Johan Jonker | a12a73b | 2023-03-13 01:32:04 +0100 | [diff] [blame] | 97 | plat->regs = dev_read_addr_ptr(dev); |
| 98 | if (!plat->regs) |
| 99 | return -EINVAL; |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 100 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 101 | plat->enable_once = dev_read_u32_default(dev, "xlnx,wdt-enable-once", |
| 102 | 0); |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 103 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 104 | debug("%s: wdt-enable-once %d\n", __func__, plat->enable_once); |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static const struct wdt_ops xlnx_wdt_ops = { |
| 110 | .start = xlnx_wdt_start, |
| 111 | .reset = xlnx_wdt_reset, |
| 112 | .stop = xlnx_wdt_stop, |
| 113 | }; |
| 114 | |
| 115 | static 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 | |
| 121 | U_BOOT_DRIVER(xlnx_wdt) = { |
| 122 | .name = "xlnx_wdt", |
| 123 | .id = UCLASS_WDT, |
| 124 | .of_match = xlnx_wdt_ids, |
| 125 | .probe = xlnx_wdt_probe, |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 126 | .plat_auto = sizeof(struct xlnx_wdt_plat), |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 127 | .of_to_plat = xlnx_wdt_of_to_plat, |
Shreenidhi Shedi | e0e9caa | 2018-07-15 02:05:41 +0530 | [diff] [blame] | 128 | .ops = &xlnx_wdt_ops, |
| 129 | }; |