blob: ffca1ced5b87195b0cc06fb149525e1140a15dd8 [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
Juan Castillo5f64eff2014-07-08 17:20:41 +01007#include <stdint.h>
8
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <drivers/arm/sp805.h>
10#include <lib/mmio.h>
11
Juan Castillo5f64eff2014-07-08 17:20:41 +010012/* Inline register access functions */
13
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010014static inline void sp805_write_wdog_load(uintptr_t base, uint32_t value)
Juan Castillo5f64eff2014-07-08 17:20:41 +010015{
16 mmio_write_32(base + SP805_WDOG_LOAD_OFF, value);
17}
18
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010019static inline void sp805_write_wdog_ctrl(uintptr_t base, uint32_t value)
Juan Castillo5f64eff2014-07-08 17:20:41 +010020{
21 mmio_write_32(base + SP805_WDOG_CTR_OFF, value);
22}
23
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010024static inline void sp805_write_wdog_lock(uintptr_t base, uint32_t value)
Juan Castillo5f64eff2014-07-08 17:20:41 +010025{
26 mmio_write_32(base + SP805_WDOG_LOCK_OFF, value);
27}
28
29
30/* Public API implementation */
31
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010032void sp805_start(uintptr_t base, unsigned int ticks)
Juan Castillo5f64eff2014-07-08 17:20:41 +010033{
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 Diaz045b6fd2018-07-24 11:27:52 +010037 sp805_write_wdog_lock(base, 0U);
Juan Castillo5f64eff2014-07-08 17:20:41 +010038}
39
40void sp805_stop(uintptr_t base)
41{
42 sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY);
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010043 sp805_write_wdog_ctrl(base, 0U);
Juan Castillo5f64eff2014-07-08 17:20:41 +010044}
45
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010046void sp805_refresh(uintptr_t base, unsigned int ticks)
Juan Castillo5f64eff2014-07-08 17:20:41 +010047{
48 sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY);
49 sp805_write_wdog_load(base, ticks);
Antonio Nino Diaz045b6fd2018-07-24 11:27:52 +010050 sp805_write_wdog_lock(base, 0U);
Juan Castillo5f64eff2014-07-08 17:20:41 +010051}