From 3f82ac35797b730b98d2bebeed4240b3439800ee Mon Sep 17 00:00:00 2001 From: "Vic (Chun-Ju) Yang" Date: Mon, 25 Nov 2013 17:35:34 +0800 Subject: [PATCH] mec1322: Add watchdog support This implements the basic watchdog support. For now, the watchdog doesn't warn us before it expires. This functionality will be added later using a basic timer. BUG=chrome-os-partner:24107 TEST='waitms 700' and the EC stays alive. TEST='waitms 1200' and the EC reboots. BRANCH=None Change-Id: I1cc48978ed09577ae88cc2f7a6087867e5854973 Signed-off-by: Vic (Chun-Ju) Yang Reviewed-on: https://chromium-review.googlesource.com/177736 --- board/mec1322_evb/board.h | 1 - chip/mec1322/build.mk | 1 + chip/mec1322/watchdog.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 chip/mec1322/watchdog.c diff --git a/board/mec1322_evb/board.h b/board/mec1322_evb/board.h index 269cb4fb9d..c5f14a27f9 100644 --- a/board/mec1322_evb/board.h +++ b/board/mec1322_evb/board.h @@ -19,7 +19,6 @@ #undef CONFIG_LPC #undef CONFIG_PECI #undef CONFIG_SWITCH -#undef CONFIG_WATCHDOG #ifndef __ASSEMBLER__ diff --git a/chip/mec1322/build.mk b/chip/mec1322/build.mk index ae435bf8c6..f47014ef89 100644 --- a/chip/mec1322/build.mk +++ b/chip/mec1322/build.mk @@ -13,3 +13,4 @@ CFLAGS_CPU+=-march=armv7e-m -mcpu=cortex-m4 # Required chip modules chip-y=clock.o gpio.o hwtimer.o system.o uart.o jtag.o +chip-$(CONFIG_WATCHDOG)+=watchdog.o diff --git a/chip/mec1322/watchdog.c b/chip/mec1322/watchdog.c new file mode 100644 index 0000000000..f46360f152 --- /dev/null +++ b/chip/mec1322/watchdog.c @@ -0,0 +1,32 @@ +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* Watchdog driver */ + +/* + * TODO(crosbug.com/p/24107): Use independent timer for warning before watchdog + * timer expires. + */ + +#include "hooks.h" +#include "registers.h" +#include "watchdog.h" + +void watchdog_reload(void) +{ + MEC1322_WDG_KICK = 1; +} +DECLARE_HOOK(HOOK_TICK, watchdog_reload, HOOK_PRIO_DEFAULT); + +int watchdog_init(void) +{ + /* Set timeout. It takes 1007us to decrement WDG_CNT by 1. */ + MEC1322_WDG_LOAD = WATCHDOG_PERIOD_MS * 1000 / 1007; + + /* Start watchdog */ + MEC1322_WDG_CTL |= 1; + + return EC_SUCCESS; +}