blob: 98df7e2152a04bffc5ecad056c6432b73f84c8ed [file] [log] [blame]
Juan Castillo5f64eff2014-07-08 17:20:41 +01001/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo5f64eff2014-07-08 17:20:41 +01005 */
6
7#include <mmio.h>
8#include <sp805.h>
9#include <stdint.h>
10
11/* Inline register access functions */
12
13static inline void sp805_write_wdog_load(uintptr_t base, unsigned long value)
14{
15 mmio_write_32(base + SP805_WDOG_LOAD_OFF, value);
16}
17
18static inline void sp805_write_wdog_ctrl(uintptr_t base, unsigned long value)
19{
20 mmio_write_32(base + SP805_WDOG_CTR_OFF, value);
21}
22
23static inline void sp805_write_wdog_lock(uintptr_t base, unsigned long value)
24{
25 mmio_write_32(base + SP805_WDOG_LOCK_OFF, value);
26}
27
28
29/* Public API implementation */
30
31void sp805_start(uintptr_t base, unsigned long ticks)
32{
33 sp805_write_wdog_load(base, ticks);
34 sp805_write_wdog_ctrl(base, SP805_CTR_RESEN | SP805_CTR_INTEN);
35 /* Lock registers access */
36 sp805_write_wdog_lock(base, 0);
37}
38
39void sp805_stop(uintptr_t base)
40{
41 sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY);
42 sp805_write_wdog_ctrl(base, 0);
43}
44
45void sp805_refresh(uintptr_t base, unsigned long ticks)
46{
47 sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY);
48 sp805_write_wdog_load(base, ticks);
49 sp805_write_wdog_lock(base, 0);
50}