Browse Source
Watchdog driver support & enablement during platform setup Signed-off-by: Muhammad Hadi Asyrafi Abdul Halim <muhammad.hadi.asyrafi.abdul.halim@intel.com>pull/1898/head
Muhammad Hadi Asyrafi Abdul Halim
6 years ago
6 changed files with 158 additions and 1 deletions
@ -0,0 +1,58 @@ |
|||
/*
|
|||
* Copyright (c) 2019, Intel Corporation. All rights reserved. |
|||
* |
|||
* SPDX-License-Identifier: BSD-3-Clause |
|||
*/ |
|||
|
|||
#include <common/debug.h> |
|||
#include <lib/mmio.h> |
|||
#include <platform_def.h> |
|||
|
|||
#include "watchdog.h" |
|||
|
|||
|
|||
/* Reset watchdog timer */ |
|||
void watchdog_sw_rst(void) |
|||
{ |
|||
mmio_write_32(WDT_CRR, WDT_SW_RST); |
|||
} |
|||
|
|||
/* Print component information */ |
|||
void watchdog_info(void) |
|||
{ |
|||
INFO("Component Type : %x\r\n", mmio_read_32(WDT_COMP_VERSION)); |
|||
INFO("Component Version : %x\r\n", mmio_read_32(WDT_COMP_TYPE)); |
|||
} |
|||
|
|||
/* Check watchdog current status */ |
|||
void watchdog_status(void) |
|||
{ |
|||
if (mmio_read_32(WDT_CR) & 1) { |
|||
INFO("Watchdog Timer in currently enabled\n"); |
|||
INFO("Current Counter : 0x%x\r\n", mmio_read_32(WDT_CCVR)); |
|||
} else { |
|||
INFO("Watchdog Timer in currently disabled\n"); |
|||
} |
|||
} |
|||
|
|||
/* Initialize & enable watchdog */ |
|||
void watchdog_init(int watchdog_clk) |
|||
{ |
|||
uint8_t cycles_i = 0; |
|||
uint32_t wdt_cycles = WDT_MIN_CYCLES; |
|||
uint32_t top_init_cycles = WDT_PERIOD * watchdog_clk; |
|||
|
|||
while ((cycles_i < 15) && (wdt_cycles < top_init_cycles)) { |
|||
wdt_cycles = (wdt_cycles << 1); |
|||
cycles_i++; |
|||
} |
|||
|
|||
mmio_write_32(WDT_TORR, (cycles_i << 4) | cycles_i); |
|||
|
|||
watchdog_enable(); |
|||
} |
|||
|
|||
void watchdog_enable(void) |
|||
{ |
|||
mmio_write_32(WDT_CR, WDT_CR_RMOD|WDT_CR_EN); |
|||
} |
@ -0,0 +1,40 @@ |
|||
/*
|
|||
* Copyright (c) 2019, Intel Corporation. All rights reserved. |
|||
* |
|||
* SPDX-License-Identifier: BSD-3-Clause |
|||
*/ |
|||
|
|||
#ifndef __CAD_WATCHDOG_H__ |
|||
#define __CAD_WATCHDOG_H__ |
|||
|
|||
#define WDT_BASE (0xFFD00200) |
|||
#define WDT_REG_SIZE_OFFSET (0x4) |
|||
#define WDT_MIN_CYCLES (65536) |
|||
#define WDT_PERIOD (20) |
|||
|
|||
#define WDT_CR (WDT_BASE + 0x0) |
|||
#define WDT_TORR (WDT_BASE + 0x4) |
|||
|
|||
#define WDT_CRR (WDT_BASE + 0xC) |
|||
|
|||
#define WDT_CCVR (WDT_BASE + 0x8) |
|||
#define WDT_STAT (WDT_BASE + 0x10) |
|||
#define WDT_EOI (WDT_BASE + 0x14) |
|||
|
|||
#define WDT_COMP_PARAM_1 (WDT_BASE + 0xF4) |
|||
#define WDT_COMP_VERSION (WDT_BASE + 0xF8) |
|||
#define WDT_COMP_TYPE (WDT_BASE + 0XFC) |
|||
|
|||
#define WDT_CR_RMOD (0x0) |
|||
#define WDT_CR_EN (0x1) |
|||
|
|||
#define WDT_SW_RST (0x76) |
|||
|
|||
|
|||
void watchdog_init(int watchdog_clk); |
|||
void watchdog_enable(void); |
|||
void watchdog_info(void); |
|||
void watchdog_status(void); |
|||
void watchdog_sw_rst(void); |
|||
|
|||
#endif |
Loading…
Reference in new issue