xref: /aosp_15_r20/external/arm-trusted-firmware/drivers/arm/sbsa/sbsa.c (revision 54fd6939e177f8ff529b10183254802c76df6d08)
1*54fd6939SJiyong Park /*
2*54fd6939SJiyong Park  * Copyright (c) 2019, ARM Limited. All rights reserved.
3*54fd6939SJiyong Park  *
4*54fd6939SJiyong Park  * SPDX-License-Identifier: BSD-3-Clause
5*54fd6939SJiyong Park  */
6*54fd6939SJiyong Park 
7*54fd6939SJiyong Park #include <assert.h>
8*54fd6939SJiyong Park #include <stdint.h>
9*54fd6939SJiyong Park #include <drivers/arm/sbsa.h>
10*54fd6939SJiyong Park #include <lib/mmio.h>
11*54fd6939SJiyong Park #include <plat/common/platform.h>
12*54fd6939SJiyong Park 
sbsa_watchdog_offset_reg_write(uintptr_t base,uint64_t value)13*54fd6939SJiyong Park void sbsa_watchdog_offset_reg_write(uintptr_t base, uint64_t value)
14*54fd6939SJiyong Park {
15*54fd6939SJiyong Park 	assert((value >> SBSA_WDOG_WOR_WIDTH) == 0);
16*54fd6939SJiyong Park 	mmio_write_32(base + SBSA_WDOG_WOR_LOW_OFFSET,
17*54fd6939SJiyong Park 		 ((uint32_t)value & UINT32_MAX));
18*54fd6939SJiyong Park 	mmio_write_32(base + SBSA_WDOG_WOR_HIGH_OFFSET, (uint32_t)(value >> 32));
19*54fd6939SJiyong Park }
20*54fd6939SJiyong Park 
21*54fd6939SJiyong Park /*
22*54fd6939SJiyong Park  * Start the watchdog timer at base address "base" for a
23*54fd6939SJiyong Park  * period of "ms" milliseconds.The watchdog has to be
24*54fd6939SJiyong Park  * refreshed within this time period.
25*54fd6939SJiyong Park  */
sbsa_wdog_start(uintptr_t base,uint64_t ms)26*54fd6939SJiyong Park void sbsa_wdog_start(uintptr_t base, uint64_t ms)
27*54fd6939SJiyong Park {
28*54fd6939SJiyong Park 	uint64_t counter_freq;
29*54fd6939SJiyong Park 	uint64_t offset_reg_value;
30*54fd6939SJiyong Park 
31*54fd6939SJiyong Park 	counter_freq = (uint64_t)plat_get_syscnt_freq2();
32*54fd6939SJiyong Park 	offset_reg_value = ms * counter_freq / 1000;
33*54fd6939SJiyong Park 
34*54fd6939SJiyong Park 	sbsa_watchdog_offset_reg_write(base, offset_reg_value);
35*54fd6939SJiyong Park 	mmio_write_32(base + SBSA_WDOG_WCS_OFFSET, SBSA_WDOG_WCS_EN);
36*54fd6939SJiyong Park }
37*54fd6939SJiyong Park 
38*54fd6939SJiyong Park /* Stop the watchdog */
sbsa_wdog_stop(uintptr_t base)39*54fd6939SJiyong Park void sbsa_wdog_stop(uintptr_t base)
40*54fd6939SJiyong Park {
41*54fd6939SJiyong Park 	mmio_write_32(base + SBSA_WDOG_WCS_OFFSET, (0x0));
42*54fd6939SJiyong Park }
43