Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Intel Corporation |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 4 | */ |
| 5 | #include <common.h> |
Andy Shevchenko | c974a3d | 2019-06-21 13:28:08 +0300 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <wdt.h> |
| 8 | #include <div64.h> |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 9 | #include <asm/scu.h> |
| 10 | |
| 11 | /* Hardware timeout in seconds */ |
| 12 | #define WDT_PRETIMEOUT 15 |
| 13 | #define WDT_TIMEOUT_MIN (1 + WDT_PRETIMEOUT) |
| 14 | #define WDT_TIMEOUT_MAX 170 |
Andy Shevchenko | 8b295a2 | 2019-06-21 13:28:07 +0300 | [diff] [blame] | 15 | |
| 16 | /* |
| 17 | * Note, firmware chooses 90 seconds as a default timeout for watchdog on |
| 18 | * Intel Tangier SoC. It means that without handling it in the running code |
| 19 | * the reboot will happen. |
| 20 | */ |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 21 | |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 22 | enum { |
| 23 | SCU_WATCHDOG_START = 0, |
| 24 | SCU_WATCHDOG_STOP = 1, |
| 25 | SCU_WATCHDOG_KEEPALIVE = 2, |
| 26 | SCU_WATCHDOG_SET_ACTION_ON_TIMEOUT = 3, |
| 27 | }; |
| 28 | |
Andy Shevchenko | c974a3d | 2019-06-21 13:28:08 +0300 | [diff] [blame] | 29 | static int tangier_wdt_reset(struct udevice *dev) |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 30 | { |
Andy Shevchenko | c974a3d | 2019-06-21 13:28:08 +0300 | [diff] [blame] | 31 | scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_KEEPALIVE); |
| 32 | return 0; |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 33 | } |
| 34 | |
Andy Shevchenko | c974a3d | 2019-06-21 13:28:08 +0300 | [diff] [blame] | 35 | static int tangier_wdt_stop(struct udevice *dev) |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 36 | { |
| 37 | return scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_STOP); |
| 38 | } |
| 39 | |
Andy Shevchenko | c974a3d | 2019-06-21 13:28:08 +0300 | [diff] [blame] | 40 | static int tangier_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 41 | { |
Andy Shevchenko | c974a3d | 2019-06-21 13:28:08 +0300 | [diff] [blame] | 42 | u32 timeout_sec; |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 43 | int in_size; |
| 44 | struct ipc_wd_start { |
| 45 | u32 pretimeout; |
| 46 | u32 timeout; |
Andy Shevchenko | c974a3d | 2019-06-21 13:28:08 +0300 | [diff] [blame] | 47 | } ipc_wd_start; |
| 48 | |
| 49 | /* Calculate timeout in seconds and restrict to min and max value */ |
| 50 | do_div(timeout_ms, 1000); |
| 51 | timeout_sec = clamp_t(u32, timeout_ms, WDT_TIMEOUT_MIN, WDT_TIMEOUT_MAX); |
| 52 | |
| 53 | /* Update values in the IPC request */ |
| 54 | ipc_wd_start.pretimeout = timeout_sec - WDT_PRETIMEOUT; |
| 55 | ipc_wd_start.timeout = timeout_sec; |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 56 | |
| 57 | /* |
| 58 | * SCU expects the input size for watchdog IPC |
| 59 | * to be based on 4 bytes |
| 60 | */ |
| 61 | in_size = DIV_ROUND_UP(sizeof(ipc_wd_start), 4); |
| 62 | |
| 63 | scu_ipc_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_START, |
| 64 | (u32 *)&ipc_wd_start, in_size, NULL, 0); |
Andy Shevchenko | c974a3d | 2019-06-21 13:28:08 +0300 | [diff] [blame] | 65 | |
| 66 | return 0; |
Felipe Balbi | 8f8a12d | 2017-07-05 20:33:20 +0300 | [diff] [blame] | 67 | } |
Andy Shevchenko | c974a3d | 2019-06-21 13:28:08 +0300 | [diff] [blame] | 68 | |
| 69 | static const struct wdt_ops tangier_wdt_ops = { |
| 70 | .reset = tangier_wdt_reset, |
| 71 | .start = tangier_wdt_start, |
| 72 | .stop = tangier_wdt_stop, |
| 73 | }; |
| 74 | |
| 75 | static const struct udevice_id tangier_wdt_ids[] = { |
| 76 | { .compatible = "intel,tangier-wdt" }, |
| 77 | { /* sentinel */ } |
| 78 | }; |
| 79 | |
| 80 | static int tangier_wdt_probe(struct udevice *dev) |
| 81 | { |
| 82 | debug("%s: Probing wdt%u\n", __func__, dev->seq); |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | U_BOOT_DRIVER(wdt_tangier) = { |
| 87 | .name = "wdt_tangier", |
| 88 | .id = UCLASS_WDT, |
| 89 | .of_match = tangier_wdt_ids, |
| 90 | .ops = &tangier_wdt_ops, |
| 91 | .probe = tangier_wdt_probe, |
| 92 | }; |