blob: 2318c40d85fedd26721cc3fc0dd12963c1dbb349 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8#include <debug.h>
Antonio Nino Diaz639bff92019-01-11 13:12:58 +00009#include <drivers/arm/sp805.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020010#include <mmio.h>
11#include <platform_def.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020012#include <stdint.h>
13
14static inline uint32_t sp805_read_wdog_load(unsigned long base)
15{
16 assert(base);
17 return mmio_read_32(base + SP805_WDOG_LOAD_OFF);
18}
19
20static inline void sp805_write_wdog_load(unsigned long base, uint32_t value)
21{
22 assert(base);
23 mmio_write_32(base + SP805_WDOG_LOAD_OFF, value);
24}
25
26static inline uint32_t sp805_read_wdog_value(unsigned long base)
27{
28 assert(base);
29 return mmio_read_32(base + SP805_WDOG_VALUE_0FF);
30}
31
32static inline uint32_t sp805_read_wdog_ctrl(unsigned long base)
33{
34 assert(base);
35 return mmio_read_32(base + SP805_WDOG_CTRL_OFF) & SP805_WDOG_CTRL_MASK;
36}
37
38static inline void sp805_write_wdog_ctrl(unsigned long base, uint32_t value)
39{
40 assert(base);
41 /* Not setting reserved bits */
42 assert(!(value & ~SP805_WDOG_CTRL_MASK));
43 mmio_write_32(base + SP805_WDOG_CTRL_OFF, value);
44}
45
46static inline void sp805_write_wdog_int_clr(unsigned long base, uint32_t value)
47{
48 assert(base);
49 mmio_write_32(base + SP805_WDOG_INT_CLR_OFF, value);
50}
51
52static inline uint32_t sp805_read_wdog_ris(unsigned long base)
53{
54 assert(base);
55 return mmio_read_32(base + SP805_WDOG_RIS_OFF) & SP805_WDOG_RIS_MASK;
56}
57
58static inline uint32_t sp805_read_wdog_mis(unsigned long base)
59{
60 assert(base);
61 return mmio_read_32(base + SP805_WDOG_MIS_OFF) & SP805_WDOG_MIS_MASK;
62}
63
64static inline uint32_t sp805_read_wdog_lock(unsigned long base)
65{
66 assert(base);
67 return mmio_read_32(base + SP805_WDOG_LOCK_OFF);
68}
69
70static inline void sp805_write_wdog_lock(unsigned long base, uint32_t value)
71{
72 assert(base);
73 mmio_write_32(base + SP805_WDOG_LOCK_OFF, value);
74}
75
76static inline uint32_t sp805_read_wdog_itcr(unsigned long base)
77{
78 assert(base);
79 return mmio_read_32(base + SP805_WDOG_ITCR_OFF) & SP805_WDOG_ITCR_MASK;
80}
81
82static inline void sp805_write_wdog_itcr(unsigned long base, uint32_t value)
83{
84 assert(base);
85 /* Not setting reserved bits */
86 assert(!(value & ~SP805_WDOG_ITCR_MASK));
87 mmio_write_32(base + SP805_WDOG_ITCR_OFF, value);
88}
89
90static inline void sp805_write_wdog_itop(unsigned long base, uint32_t value)
91{
92 assert(base);
93 /* Not setting reserved bits */
94 assert(!(value & ~SP805_WDOG_ITOP_MASK));
95 mmio_write_32(base + SP805_WDOG_ITOP_OFF, value);
96}
97
98static inline uint32_t sp805_read_wdog_periph_id(unsigned long base, unsigned int id)
99{
100 assert(base);
101 assert(id < 4);
102 return mmio_read_32(base + SP805_WDOG_PERIPH_ID_OFF + (id << 2));
103}
104
105static inline uint32_t sp805_read_wdog_pcell_id(unsigned long base, unsigned int id)
106{
107 assert(base);
108 assert(id < 4);
109 return mmio_read_32(base + SP805_WDOG_PCELL_ID_OFF + (id << 2));
110}
111
112void sp805_wdog_start(uint32_t wdog_cycles)
113{
114 /* Unlock to access the watchdog registers */
115 sp805_write_wdog_lock(SP805_WDOG_BASE, SP805_WDOG_UNLOCK_ACCESS);
116
117 /* Write the number of cycles needed */
118 sp805_write_wdog_load(SP805_WDOG_BASE, wdog_cycles);
119
120 /* Enable reset interrupt and watchdog interrupt on expiry */
121 sp805_write_wdog_ctrl(SP805_WDOG_BASE,
122 SP805_WDOG_CTRL_RESEN | SP805_WDOG_CTRL_INTEN);
123
124 /* Lock registers so that they can't be accidently overwritten */
125 sp805_write_wdog_lock(SP805_WDOG_BASE, 0x0);
126}
127
128void sp805_wdog_stop(void)
129{
130 /* Unlock to access the watchdog registers */
131 sp805_write_wdog_lock(SP805_WDOG_BASE, SP805_WDOG_UNLOCK_ACCESS);
132
133 /* Clearing INTEN bit stops the counter */
134 sp805_write_wdog_ctrl(SP805_WDOG_BASE, 0x00);
135
136 /* Lock registers so that they can't be accidently overwritten */
137 sp805_write_wdog_lock(SP805_WDOG_BASE, 0x0);
138}
139
140void sp805_wdog_refresh(void)
141{
142 /* Unlock to access the watchdog registers */
143 sp805_write_wdog_lock(SP805_WDOG_BASE, SP805_WDOG_UNLOCK_ACCESS);
144
145 /*
146 * Write of any value to WdogIntClr clears interrupt and reloads
147 * the counter from the value in WdogLoad Register.
148 */
149 sp805_write_wdog_int_clr(SP805_WDOG_BASE, 1);
150
151 /* Lock registers so that they can't be accidently overwritten */
152 sp805_write_wdog_lock(SP805_WDOG_BASE, 0x0);
153}