watchdog: tangier: Replace unused constant with a comment
[platform/kernel/u-boot.git] / drivers / watchdog / tangier_wdt.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2017 Intel Corporation
4  */
5 #include <common.h>
6 #include <watchdog.h>
7 #include <asm/scu.h>
8
9 /* Hardware timeout in seconds */
10 #define WDT_PRETIMEOUT          15
11 #define WDT_TIMEOUT_MIN         (1 + WDT_PRETIMEOUT)
12 #define WDT_TIMEOUT_MAX         170
13
14 /*
15  * Note, firmware chooses 90 seconds as a default timeout for watchdog on
16  * Intel Tangier SoC. It means that without handling it in the running code
17  * the reboot will happen.
18  */
19
20 #ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
21 #define WATCHDOG_HEARTBEAT 60000
22 #else
23 #define WATCHDOG_HEARTBEAT CONFIG_WATCHDOG_TIMEOUT_MSECS
24 #endif
25
26 enum {
27         SCU_WATCHDOG_START                      = 0,
28         SCU_WATCHDOG_STOP                       = 1,
29         SCU_WATCHDOG_KEEPALIVE                  = 2,
30         SCU_WATCHDOG_SET_ACTION_ON_TIMEOUT      = 3,
31 };
32
33 void hw_watchdog_reset(void)
34 {
35         static unsigned long last;
36         unsigned long now;
37
38         if (gd->timer)
39                 now = timer_get_us();
40         else
41                 now = rdtsc() / 1000;
42
43         /* Do not flood SCU */
44         if (last > now)
45                 last = 0;
46
47         if (unlikely((now - last) > (WDT_PRETIMEOUT / 2) * 1000000)) {
48                 last = now;
49                 scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_KEEPALIVE);
50         }
51 }
52
53 int hw_watchdog_disable(void)
54 {
55         return scu_ipc_simple_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_STOP);
56 }
57
58 void hw_watchdog_init(void)
59 {
60         u32 timeout = WATCHDOG_HEARTBEAT / 1000;
61         int in_size;
62         struct ipc_wd_start {
63                 u32 pretimeout;
64                 u32 timeout;
65         } ipc_wd_start = { timeout - WDT_PRETIMEOUT, timeout };
66
67         /*
68          * SCU expects the input size for watchdog IPC
69          * to be based on 4 bytes
70          */
71         in_size = DIV_ROUND_UP(sizeof(ipc_wd_start), 4);
72
73         scu_ipc_command(IPCMSG_WATCHDOG_TIMER, SCU_WATCHDOG_START,
74                         (u32 *)&ipc_wd_start, in_size, NULL, 0);
75 }