summaryrefslogtreecommitdiff
path: root/arch/arm/mach-aspeed/ast_wdt.c
blob: 895fba3366cd5a897f92d7b5dc947638e14dbba3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * (C) Copyright 2016 Google, Inc
 *
 * SPDX-License-Identifier:     GPL-2.0+
 */

#include <common.h>
#include <asm/io.h>
#include <asm/arch/wdt.h>
#include <linux/err.h>

u32 ast_reset_mode_from_flags(ulong flags)
{
	return flags & WDT_CTRL_RESET_MASK;
}

u32 ast_reset_mask_from_flags(ulong flags)
{
	return flags >> 2;
}

ulong ast_flags_from_reset_mode_mask(u32 reset_mode, u32 reset_mask)
{
	ulong ret = reset_mode & WDT_CTRL_RESET_MASK;

	if (ret == WDT_CTRL_RESET_SOC)
		ret |= (reset_mask << 2);

	return ret;
}

#ifndef CONFIG_WDT
void wdt_stop(struct ast_wdt *wdt)
{
	clrbits_le32(&wdt->ctrl, WDT_CTRL_EN);
}

void wdt_start(struct ast_wdt *wdt, u32 timeout)
{
	writel(timeout, &wdt->counter_reload_val);
	writel(WDT_COUNTER_RESTART_VAL, &wdt->counter_restart);
	/*
	 * Setting CLK1MHZ bit is just for compatibility with ast2400 part.
	 * On ast2500 watchdog timer clock is fixed at 1MHz and the bit is
	 * read-only
	 */
	setbits_le32(&wdt->ctrl,
		     WDT_CTRL_EN | WDT_CTRL_RESET | WDT_CTRL_CLK1MHZ);
}
#endif  /* CONFIG_WDT */

int ast_wdt_reset_masked(struct ast_wdt *wdt, u32 mask)
{
#ifdef CONFIG_ASPEED_AST2500
	if (!mask)
		return -EINVAL;

	writel(mask, &wdt->reset_mask);
	clrbits_le32(&wdt->ctrl,
		     WDT_CTRL_RESET_MASK << WDT_CTRL_RESET_MODE_SHIFT);
	wdt_start(wdt, 1);

	/* Wait for WDT to reset */
	while (readl(&wdt->ctrl) & WDT_CTRL_EN)
		;
	wdt_stop(wdt);

	return 0;
#else
	return -EINVAL;
#endif
}

struct ast_wdt *ast_get_wdt(u8 wdt_number)
{
	if (wdt_number > CONFIG_WDT_NUM - 1)
		return ERR_PTR(-EINVAL);

	return (struct ast_wdt *)(WDT_BASE +
				  sizeof(struct ast_wdt) * wdt_number);
}