sp805.c 1.16 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
7
8
 */

#include <stdint.h>

9
10
11
#include <drivers/arm/sp805.h>
#include <lib/mmio.h>

12
13
/* Inline register access functions */

14
static inline void sp805_write_wdog_load(uintptr_t base, uint32_t value)
15
16
17
18
{
	mmio_write_32(base + SP805_WDOG_LOAD_OFF, value);
}

19
static inline void sp805_write_wdog_ctrl(uintptr_t base, uint32_t value)
20
21
22
23
{
	mmio_write_32(base + SP805_WDOG_CTR_OFF, value);
}

24
static inline void sp805_write_wdog_lock(uintptr_t base, uint32_t value)
25
26
27
28
29
30
31
{
	mmio_write_32(base + SP805_WDOG_LOCK_OFF, value);
}


/* Public API implementation */

32
void sp805_start(uintptr_t base, unsigned int ticks)
33
34
35
36
{
	sp805_write_wdog_load(base, ticks);
	sp805_write_wdog_ctrl(base, SP805_CTR_RESEN | SP805_CTR_INTEN);
	/* Lock registers access */
37
	sp805_write_wdog_lock(base, 0U);
38
39
40
41
42
}

void sp805_stop(uintptr_t base)
{
	sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY);
43
	sp805_write_wdog_ctrl(base, 0U);
44
45
}

46
void sp805_refresh(uintptr_t base, unsigned int ticks)
47
48
49
{
	sp805_write_wdog_lock(base, WDOG_UNLOCK_KEY);
	sp805_write_wdog_load(base, ticks);
50
	sp805_write_wdog_lock(base, 0U);
51
}