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 | |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | #include <drivers/arm/sp805.h> |
| 10 | #include <lib/mmio.h> |
| 11 | |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 12 | /* Inline register access functions */ |
| 13 | |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 14 | 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] | 15 | { |
| 16 | mmio_write_32(base + SP805_WDOG_LOAD_OFF, value); |
| 17 | } |
| 18 | |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 19 | 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] | 20 | { |
| 21 | mmio_write_32(base + SP805_WDOG_CTR_OFF, value); |
| 22 | } |
| 23 | |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 24 | 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] | 25 | { |
| 26 | mmio_write_32(base + SP805_WDOG_LOCK_OFF, value); |
| 27 | } |
| 28 | |
| 29 | |
| 30 | /* Public API implementation */ |
| 31 | |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 32 | void sp805_start(uintptr_t base, unsigned int ticks) |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 33 | { |
| 34 | sp805_write_wdog_load(base, ticks); |
| 35 | sp805_write_wdog_ctrl(base, SP805_CTR_RESEN | SP805_CTR_INTEN); |
| 36 | /* Lock registers access */ |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 37 | sp805_write_wdog_lock(base, 0U); |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void sp805_stop(uintptr_t base) |
| 41 | { |
| 42 | sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY); |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 43 | sp805_write_wdog_ctrl(base, 0U); |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 44 | } |
| 45 | |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 46 | void sp805_refresh(uintptr_t base, unsigned int ticks) |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 47 | { |
| 48 | sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY); |
| 49 | sp805_write_wdog_load(base, ticks); |
Antonio Nino Diaz | 045b6fd | 2018-07-24 11:27:52 +0100 | [diff] [blame] | 50 | sp805_write_wdog_lock(base, 0U); |
Juan Castillo | 5f64eff | 2014-07-08 17:20:41 +0100 | [diff] [blame] | 51 | } |