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 20 /* Magic word to unlock the wd registers */ 21 #define WDT_UNLOCK_KEY 0x1ACCE551 22 #define WDT_LOCK_KEY 0x1 23 24 /* Register field definitions */ 25 #define WDT_INT_EN BIT(0) 26 #define WDT_RESET_EN BIT(1) 27 #define WDT_INT_CLR BIT(0) 28 29 #define WDT_LOAD_MIN 0x1 30 31 typedef void (*sp805_itr_handler_func_t)(struct wdt_chip *chip); 32 33 struct sp805_wdt_data { 34 struct io_pa_va base; 35 struct wdt_chip chip; 36 uint32_t clk_rate; 37 uint32_t load_val; 38 uint32_t itr_num; 39 sp805_itr_handler_func_t itr_handler; 40 }; 41 42 /* 43 * Initialize sp805 watchdog timer 44 * 45 * @pd: allocated sp805 watchdog timer platform data 46 * @base: physical base address of sp805 watchdog timer 47 * @clk_rate: rate of the clock driving the watchdog timer hardware 48 * @timeout: watchdog timer timeout in seconds 49 * Return a TEE_Result compliant status 50 */ 51 TEE_Result sp805_wdt_init(struct sp805_wdt_data *pd, paddr_t base, 52 uint32_t clk_rate, uint32_t timeout); 53 54 /* 55 * Optionally register sp805 watchdog timer interrupt handler 56 * 57 * @pd: platform data of sp805 watchdog timer for which interrupt handler 58 * is to be registered 59 * @itr_num: sp805 watchdog timer interrupt id 60 * @itr_flag: interrupt attributes 61 * @itr_handler: Optional interrupt handler callback 62 * Return a TEE_Result compliant status 63 */ 64 TEE_Result sp805_register_itr_handler(struct sp805_wdt_data *pd, 65 uint32_t itr_num, uint32_t itr_flag, 66 sp805_itr_handler_func_t itr_handler); 67 68 #endif /* SP805_WDT_H */ 69