Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 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 | |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 13 | static inline void sp805_write_wdog_load(uintptr_t base, uint32_t value) |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 14 | { |
| 15 | mmio_write_32(base + SP805_WDOG_LOAD_OFF, value); |
| 16 | } |
| 17 | |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 18 | static inline void sp805_write_wdog_ctrl(uintptr_t base, uint32_t value) |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 19 | { |
| 20 | mmio_write_32(base + SP805_WDOG_CTR_OFF, value); |
| 21 | } |
| 22 | |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 23 | static inline void sp805_write_wdog_lock(uintptr_t base, uint32_t value) |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 24 | { |
| 25 | mmio_write_32(base + SP805_WDOG_LOCK_OFF, value); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | /* Public API implementation */ |
| 30 | |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 31 | void sp805_start(uintptr_t base, unsigned int ticks) |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 32 | { |
| 33 | sp805_write_wdog_load(base, ticks); |
| 34 | sp805_write_wdog_ctrl(base, SP805_CTR_RESEN | SP805_CTR_INTEN); |
| 35 | /* Lock registers access */ |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 36 | sp805_write_wdog_lock(base, 0U); |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void sp805_stop(uintptr_t base) |
| 40 | { |
| 41 | sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY); |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 42 | sp805_write_wdog_ctrl(base, 0U); |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 45 | void sp805_refresh(uintptr_t base, unsigned int ticks) |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 46 | { |
| 47 | sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY); |
| 48 | sp805_write_wdog_load(base, ticks); |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 49 | sp805_write_wdog_lock(base, 0U); |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 50 | } |