1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2019 Broadcom.
4  */
5 
6 #ifndef SP805_WDT_H
7 #define SP805_WDT_H
8 
9 #include <drivers/wdt.h>
10 #include <kernel/interrupt.h>
11 #include <mm/core_memprot.h>
12 #include <types_ext.h>
13 
14 /* SP805 register offset */
15 #define WDT_LOAD_OFFSET		0x000
16 #define WDT_CONTROL_OFFSET	0x008
17 #define WDT_INTCLR_OFFSET	0x00c
18 #define WDT_LOCK_OFFSET		0xc00
19 #define WDT_SIZE		0xc04
20 
21 /* Magic word to unlock the wd registers */
22 #define WDT_UNLOCK_KEY		0x1ACCE551
23 #define WDT_LOCK_KEY		0x1
24 
25 /* Register field definitions */
26 #define WDT_INT_EN		BIT(0)
27 #define WDT_RESET_EN		BIT(1)
28 #define WDT_INT_CLR		BIT(0)
29 
30 #define WDT_LOAD_MIN		0x1
31 
32 typedef void (*sp805_itr_handler_func_t)(struct wdt_chip *chip);
33 
34 struct sp805_wdt_data {
35 	struct io_pa_va base;
36 	struct wdt_chip chip;
37 	uint32_t clk_rate;
38 	uint32_t load_val;
39 	uint32_t itr_num;
40 	sp805_itr_handler_func_t itr_handler;
41 };
42 
43 /*
44  * Initialize sp805 watchdog timer
45  *
46  * @pd: allocated sp805 watchdog timer platform data
47  * @base: physical base address of sp805 watchdog timer
48  * @clk_rate: rate of the clock driving the watchdog timer hardware
49  * @timeout: watchdog timer timeout in seconds
50  * Return a TEE_Result compliant status
51  */
52 TEE_Result sp805_wdt_init(struct sp805_wdt_data *pd, paddr_t base,
53 		    uint32_t clk_rate, uint32_t timeout);
54 
55 /*
56  * Optionally register sp805 watchdog timer interrupt handler
57  *
58  * @pd: platform data of sp805 watchdog timer for which interrupt handler
59  * is to be registered
60  * @itr_num: sp805 watchdog timer interrupt id
61  * @itr_flag: interrupt attributes
62  * @itr_handler: Optional interrupt handler callback
63  * Return a TEE_Result compliant status
64  */
65 TEE_Result sp805_register_itr_handler(struct sp805_wdt_data *pd,
66 				      uint32_t itr_num, uint32_t itr_flag,
67 				      sp805_itr_handler_func_t itr_handler);
68 
69 #endif /* SP805_WDT_H */
70