1 /*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <mmio.h>
8 #include <sp805.h>
9 #include <stdint.h>
10
11 /* Inline register access functions */
12
sp805_write_wdog_load(uintptr_t base,unsigned long value)13 static 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
sp805_write_wdog_ctrl(uintptr_t base,unsigned long value)18 static 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
sp805_write_wdog_lock(uintptr_t base,unsigned long value)23 static 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
sp805_start(uintptr_t base,unsigned long ticks)31 void 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
sp805_stop(uintptr_t base)39 void sp805_stop(uintptr_t base)
40 {
41 sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY);
42 sp805_write_wdog_ctrl(base, 0);
43 }
44
sp805_refresh(uintptr_t base,unsigned long ticks)45 void 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 }
51