From 8fa2f82524f595eacad76927d85b20e36ebcef10 Mon Sep 17 00:00:00 2001 From: Souvik K Chakravarty Date: Tue, 7 Mar 2017 08:56:58 +0530 Subject: [PATCH] watchdog: Add WDT driver for Atmel SAM SoCs Basic Watchdog driver for Atmel SAM family MCUs. Currently only disabling the watchdog is supported. Tested on Atmel SAMV71 Xplained Ultra Evaluation Kit. Origin: Original Jira: ZEP-1684 Change-Id: I8f717c7f53aa290c944b7935e0570c2a6f53956e Signed-off-by: Souvik K Chakravarty --- .../sam_e70_xplained/doc/sam_e70_xplained.rst | 2 + drivers/watchdog/Kconfig | 2 + drivers/watchdog/Kconfig.sam | 27 ++++++ drivers/watchdog/Makefile | 1 + drivers/watchdog/wdt_sam.c | 94 +++++++++++++++++++ 5 files changed, 126 insertions(+) create mode 100644 drivers/watchdog/Kconfig.sam create mode 100644 drivers/watchdog/wdt_sam.c diff --git a/boards/arm/sam_e70_xplained/doc/sam_e70_xplained.rst b/boards/arm/sam_e70_xplained/doc/sam_e70_xplained.rst index b1109dd1384..6e5069b9306 100644 --- a/boards/arm/sam_e70_xplained/doc/sam_e70_xplained.rst +++ b/boards/arm/sam_e70_xplained/doc/sam_e70_xplained.rst @@ -43,6 +43,8 @@ features: +-----------+------------+-------------------------------------+ | ETHERNET | on-chip | ethernet | +-----------+------------+-------------------------------------+ +| WATCHDOG | on-chip | watchdog | ++-----------+------------+-------------------------------------+ Other hardware features are not currently supported by Zephyr. diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index f202cfdf8ac..65c19c5a1b2 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -24,4 +24,6 @@ source "drivers/watchdog/Kconfig.stm32" source "drivers/watchdog/Kconfig.cmsdk_apb" +source "drivers/watchdog/Kconfig.sam" + endif diff --git a/drivers/watchdog/Kconfig.sam b/drivers/watchdog/Kconfig.sam new file mode 100644 index 00000000000..df396dff7e5 --- /dev/null +++ b/drivers/watchdog/Kconfig.sam @@ -0,0 +1,27 @@ +# Kconfig - Atmel SAM WDT configuration +# +# Copyright (C) 2017 Intel Deutschland GmbH +# +# SPDX-License-Identifier: Apache-2.0 +# + +menuconfig WDT_SAM + bool "Atmel SAM MCU Family Watchdog (WDT) Driver" + depends on SOC_FAMILY_SAM + default y + help + Enable WDT driver for Atmel SAM MCUs. + +config WDT_SAM_DISABLE_AT_BOOT + bool "Disable WDT during boot" + depends on WDT_SAM + default y + help + Select this option to disable the WDT during boot. + +config WDT_SAM_DEVICE_NAME + string "Device name for Watchdog (WDT)" + depends on WDT_SAM + default "WDT" + help + Set the name used by WDT device during registration. diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 978dad64614..6d72b2f8053 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -1,3 +1,4 @@ obj-$(CONFIG_WDT_QMSI) += wdt_qmsi.o obj-$(CONFIG_IWDG_STM32) += iwdg_stm32.o obj-$(CONFIG_WDOG_CMSDK_APB) += wdog_cmsdk_apb.o +obj-$(CONFIG_WDT_SAM) += wdt_sam.o diff --git a/drivers/watchdog/wdt_sam.c b/drivers/watchdog/wdt_sam.c new file mode 100644 index 00000000000..0358ed559e6 --- /dev/null +++ b/drivers/watchdog/wdt_sam.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2017 Intel Deutschland GmbH + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @brief Watchdog (WDT) Driver for Atmel SAM MCUs + * + * Note: + * - Once the watchdog disable bit is set, it cannot be cleared till next + * power reset, i.e, the watchdog cannot be started once stopped. + * - Since the MCU boots with WDT enabled, only basic feature (disable) is + * currently implemented for systems that don't need watchdog functionality. + * + */ + +#include +#include + +#define SYS_LOG_DOMAIN "dev/wdt_sam" +#include + +/* Device constant configuration parameters */ +struct wdt_sam_dev_cfg { + Wdt *regs; +}; + +#define DEV_CFG(dev) \ + ((const struct wdt_sam_dev_cfg *const)(dev)->config->config_info) + +static void wdt_sam_enable(struct device *dev) +{ + ARG_UNUSED(dev); + + SYS_LOG_ERR("Function not implemented!"); +} + +static void wdt_sam_disable(struct device *dev) +{ + Wdt *const wdt = DEV_CFG(dev)->regs; + + wdt->WDT_MR |= WDT_MR_WDDIS; +} + +static int wdt_sam_set_config(struct device *dev, struct wdt_config *config) +{ + ARG_UNUSED(dev); + ARG_UNUSED(config); + + SYS_LOG_ERR("Function not implemented!"); + + return -ENOTSUP; +} + +static void wdt_sam_get_config(struct device *dev, struct wdt_config *config) +{ + ARG_UNUSED(dev); + ARG_UNUSED(config); + + SYS_LOG_ERR("Function not implemented!"); +} + +static void wdt_sam_reload(struct device *dev) +{ + ARG_UNUSED(dev); + + SYS_LOG_ERR("Function not implemented!"); +} + +static const struct wdt_driver_api wdt_sam_api = { + .enable = wdt_sam_enable, + .disable = wdt_sam_disable, + .get_config = wdt_sam_get_config, + .set_config = wdt_sam_set_config, + .reload = wdt_sam_reload +}; + +static int wdt_sam_init(struct device *dev) +{ +#ifdef CONFIG_WDT_SAM_DISABLE_AT_BOOT + wdt_sam_disable(dev); +#endif + return 0; +} + +static const struct wdt_sam_dev_cfg wdt_sam_config = { + .regs = WDT +}; + +DEVICE_AND_API_INIT(wdt_sam, CONFIG_WDT_SAM_DEVICE_NAME, wdt_sam_init, + NULL, &wdt_sam_config, + PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, + &wdt_sam_api);