blob: a88e20c0466b02326f2a6dc4b8215e83393fcf18 [file] [log] [blame]
Aditya Angadi74514e52019-04-16 11:30:25 +05301/*
Madhukar Pappireddy4c3de562023-03-22 15:27:22 -05002 * Copyright (c) 2019-2023, Arm Limited. All rights reserved.
Aditya Angadi74514e52019-04-16 11:30:25 +05303 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Bence Szépkútifddf5182019-10-25 17:48:20 +02007#include <assert.h>
8#include <stdint.h>
Aditya Angadi74514e52019-04-16 11:30:25 +05309#include <drivers/arm/sbsa.h>
10#include <lib/mmio.h>
Bence Szépkútifddf5182019-10-25 17:48:20 +020011#include <plat/common/platform.h>
Aditya Angadi74514e52019-04-16 11:30:25 +053012
13void sbsa_watchdog_offset_reg_write(uintptr_t base, uint64_t value)
14{
15 assert((value >> SBSA_WDOG_WOR_WIDTH) == 0);
16 mmio_write_32(base + SBSA_WDOG_WOR_LOW_OFFSET,
17 ((uint32_t)value & UINT32_MAX));
18 mmio_write_32(base + SBSA_WDOG_WOR_HIGH_OFFSET, (uint32_t)(value >> 32));
19}
20
21/*
22 * Start the watchdog timer at base address "base" for a
23 * period of "ms" milliseconds.The watchdog has to be
24 * refreshed within this time period.
25 */
26void sbsa_wdog_start(uintptr_t base, uint64_t ms)
27{
28 uint64_t counter_freq;
29 uint64_t offset_reg_value;
30
31 counter_freq = (uint64_t)plat_get_syscnt_freq2();
32 offset_reg_value = ms * counter_freq / 1000;
33
34 sbsa_watchdog_offset_reg_write(base, offset_reg_value);
35 mmio_write_32(base + SBSA_WDOG_WCS_OFFSET, SBSA_WDOG_WCS_EN);
36}
37
38/* Stop the watchdog */
39void sbsa_wdog_stop(uintptr_t base)
40{
41 mmio_write_32(base + SBSA_WDOG_WCS_OFFSET, (0x0));
42}
Madhukar Pappireddy4c3de562023-03-22 15:27:22 -050043
44/* Refresh the secure watchdog timer explicitly */
45void sbsa_wdog_refresh(uintptr_t refresh_base)
46{
47 mmio_write_32(refresh_base + SBSA_WDOG_WRR_OFFSET, SBSA_WDOG_WRR_REFRESH);
48}