Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <mmio.h> |
| 8 | #include <sp805.h> |
| 9 | #include <stdint.h> |
| 10 | |
| 11 | /* Inline register access functions */ |
| 12 | |
| 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 | |
| 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 | |
| 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 | |
| 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 | |
| 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 | |
| 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 | } |