blob: aee90164acd07182618d8c484af0d9156af71924 [file] [log] [blame]
Juan Castillo5f64eff2014-07-08 17:20:41 +01001/*
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +01002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Juan Castillo5f64eff2014-07-08 17:20:41 +01003 *
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
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010013static inline void sp805_write_wdog_load(uintptr_t base, uint32_t value)
Juan Castillo5f64eff2014-07-08 17:20:41 +010014{
15 mmio_write_32(base + SP805_WDOG_LOAD_OFF, value);
16}
17
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010018static inline void sp805_write_wdog_ctrl(uintptr_t base, uint32_t value)
Juan Castillo5f64eff2014-07-08 17:20:41 +010019{
20 mmio_write_32(base + SP805_WDOG_CTR_OFF, value);
21}
22
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010023static inline void sp805_write_wdog_lock(uintptr_t base, uint32_t value)
Juan Castillo5f64eff2014-07-08 17:20:41 +010024{
25 mmio_write_32(base + SP805_WDOG_LOCK_OFF, value);
26}
27
28
29/* Public API implementation */
30
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010031void sp805_start(uintptr_t base, unsigned int ticks)
Juan Castillo5f64eff2014-07-08 17:20:41 +010032{
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 Diaz045b6fd2018-07-24 11:27:52 +010036 sp805_write_wdog_lock(base, 0U);
Juan Castillo5f64eff2014-07-08 17:20:41 +010037}
38
39void sp805_stop(uintptr_t base)
40{
41 sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY);
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010042 sp805_write_wdog_ctrl(base, 0U);
Juan Castillo5f64eff2014-07-08 17:20:41 +010043}
44
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010045void sp805_refresh(uintptr_t base, unsigned int ticks)
Juan Castillo5f64eff2014-07-08 17:20:41 +010046{
47 sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY);
48 sp805_write_wdog_load(base, ticks);
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010049 sp805_write_wdog_lock(base, 0U);
Juan Castillo5f64eff2014-07-08 17:20:41 +010050}