blob: 895fba3366cd5a897f92d7b5dc947638e14dbba3 [file] [log] [blame]
maxims@google.comf57bd002017-01-18 13:44:55 -08001/*
2 * (C) Copyright 2016 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <asm/arch/wdt.h>
10#include <linux/err.h>
11
maxims@google.comdf35df22017-04-17 12:00:22 -070012u32 ast_reset_mode_from_flags(ulong flags)
13{
14 return flags & WDT_CTRL_RESET_MASK;
15}
16
17u32 ast_reset_mask_from_flags(ulong flags)
18{
19 return flags >> 2;
20}
21
22ulong ast_flags_from_reset_mode_mask(u32 reset_mode, u32 reset_mask)
23{
24 ulong ret = reset_mode & WDT_CTRL_RESET_MASK;
25
26 if (ret == WDT_CTRL_RESET_SOC)
27 ret |= (reset_mask << 2);
28
29 return ret;
30}
31
32#ifndef CONFIG_WDT
maxims@google.comf57bd002017-01-18 13:44:55 -080033void wdt_stop(struct ast_wdt *wdt)
34{
35 clrbits_le32(&wdt->ctrl, WDT_CTRL_EN);
36}
37
38void wdt_start(struct ast_wdt *wdt, u32 timeout)
39{
40 writel(timeout, &wdt->counter_reload_val);
41 writel(WDT_COUNTER_RESTART_VAL, &wdt->counter_restart);
42 /*
43 * Setting CLK1MHZ bit is just for compatibility with ast2400 part.
44 * On ast2500 watchdog timer clock is fixed at 1MHz and the bit is
45 * read-only
46 */
47 setbits_le32(&wdt->ctrl,
48 WDT_CTRL_EN | WDT_CTRL_RESET | WDT_CTRL_CLK1MHZ);
49}
maxims@google.comdf35df22017-04-17 12:00:22 -070050#endif /* CONFIG_WDT */
maxims@google.comf57bd002017-01-18 13:44:55 -080051
52int ast_wdt_reset_masked(struct ast_wdt *wdt, u32 mask)
53{
54#ifdef CONFIG_ASPEED_AST2500
55 if (!mask)
56 return -EINVAL;
57
58 writel(mask, &wdt->reset_mask);
59 clrbits_le32(&wdt->ctrl,
60 WDT_CTRL_RESET_MASK << WDT_CTRL_RESET_MODE_SHIFT);
61 wdt_start(wdt, 1);
62
63 /* Wait for WDT to reset */
64 while (readl(&wdt->ctrl) & WDT_CTRL_EN)
65 ;
66 wdt_stop(wdt);
67
68 return 0;
69#else
70 return -EINVAL;
71#endif
72}
maxims@google.comdf35df22017-04-17 12:00:22 -070073
74struct ast_wdt *ast_get_wdt(u8 wdt_number)
75{
76 if (wdt_number > CONFIG_WDT_NUM - 1)
77 return ERR_PTR(-EINVAL);
78
79 return (struct ast_wdt *)(WDT_BASE +
80 sizeof(struct ast_wdt) * wdt_number);
81}