Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 079F9C636CC for ; Mon, 13 Feb 2023 13:52:40 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D909680B9C; Mon, 13 Feb 2023 14:52:37 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="pkfwBQWG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E6B3080B9A; Mon, 13 Feb 2023 14:52:35 +0100 (CET) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 251AB81421 for ; Mon, 13 Feb 2023 14:52:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=saproj@gmail.com Received: by mail-ej1-x62b.google.com with SMTP id p26so31954611ejx.13 for ; Mon, 13 Feb 2023 05:52:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=p79jJaloioiex6+RsXmehJe4a6JxqdSBrFQL/AMY3sg=; b=pkfwBQWGkHlrI+junzQ43HM6p1WFuNwScxhboOScOh5ngIbuyp/pQPdDV9XLUa1h6i xbGNvGntHhTKBirBrE0hcHzQjDiEJVRyjVhJMJfnFoyVj9ekAKh7YMDPBoUv/0MMs3vt ACIAQyW+nQ2SlO3IHfC3vzz+Ps1olEUSlxmZfjzdWQhDkTkHmllxc5Yrr6CTgHikASAM 8+cUBZDbRTgLZouXkJgiKvXWol2vHq2a2TazrVBKkwhxDPwH5U+tekFpFXZJtkiVGV9y boh0yZH3i9ZerYPd/Lao5lW0rXpv3vjNiqcgrf26jVnYDYPbEivOGr6OZYTnhBJVkL1d nxvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p79jJaloioiex6+RsXmehJe4a6JxqdSBrFQL/AMY3sg=; b=w/Hda6cdwrL2C5XDbPhvkKYXUu+SKLrnTpALDeSHmkqYNTbpSKnYlul/zMwZer+Gk1 qYeko3lzDA00yYPf6goePMxPBZatYKXtFQSbD7f2tiWtrvxyY0+Vlaz/A31UWoo4OTX9 6IGyPNgxRAC6QL2L2fA1iu6flr4bPiVvu1AWJafsbiuQNLaslPw+Qnpb2iFoNSr5SRR3 vrS4yqzIvPDINu6y1krTTjid4Ow/ApaJ11yI2Ny5Bqi5Yktu7hsjlhLZvgTQH6S1BvoV Az+8tIGHyRzG5CmX+ga2aOVANZ4uTJTYlsNP6Uu9J0j1V0fNGEcCSw2wocsakpt9bV2x invA== X-Gm-Message-State: AO0yUKXa1C7NvmQWnJFnASifnt7NLySEr6v5Ev5vldfUEKmwxd8it37w 8P0RJ1+euvzABX5F3uqPb/ZhwlHkwTM= X-Google-Smtp-Source: AK7set+1kBGhy9Bb+iiaeOInqBN9GwvgBjuVc1bfN+80abrgqHuCGkL1ydEo0saqmm+feq1vhFv/eQ== X-Received: by 2002:a17:906:1f06:b0:878:714b:5e16 with SMTP id w6-20020a1709061f0600b00878714b5e16mr25378660ejj.28.1676296350604; Mon, 13 Feb 2023 05:52:30 -0800 (PST) Received: from saproj-Latitude-5501.yandex.net ([2a02:6b8:0:40c:d591:434a:7107:941c]) by smtp.gmail.com with ESMTPSA id la2-20020a170906ad8200b008888f4120d4sm6759318ejb.129.2023.02.13.05.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 05:52:30 -0800 (PST) From: Sergei Antonov To: u-boot@lists.denx.de, sr@denx.de Cc: Sergei Antonov Subject: [PATCH] watchdog: ftwdt010: return a previously deleted driver now ported to DM Date: Mon, 13 Feb 2023 16:52:21 +0300 Message-Id: <20230213135221.1044413-1-saproj@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The ftwdt010 watchdog driver was deleted by commit 11232139e399 ("nds32: Remove the architecture") Return it to the codebase in a DM compatible form. Enable it in sandbox_defconfig to test compilability. Another platform using ftwdt010 will be submitted later. Signed-off-by: Sergei Antonov --- configs/sandbox_defconfig | 1 + drivers/watchdog/Kconfig | 7 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/ftwdt010_wdt.c | 132 ++++++++++++++++++++++++++++++++ include/faraday/ftwdt010_wdt.h | 3 - 5 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 drivers/watchdog/ftwdt010_wdt.c diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 34c342b6f587..0c57e97bcb7e 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -320,6 +320,7 @@ CONFIG_WDT=y CONFIG_WDT_GPIO=y CONFIG_WDT_SANDBOX=y CONFIG_WDT_ALARM_SANDBOX=y +CONFIG_WDT_FTWDT010=y CONFIG_FS_CBFS=y CONFIG_FS_CRAMFS=y CONFIG_ADDR_MAP=y diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index b5ac8f7f50dc..a4c8dac99046 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -161,6 +161,13 @@ config WDT_CORTINA This driver support all CPU ISAs supported by Cortina Access CAxxxx SoCs. +config WDT_FTWDT010 + bool "Faraday Technology ftwdt010 watchdog timer support" + depends on WDT + help + Faraday Technology ftwdt010 watchdog is an architecture independent + watchdog. It is usually used in SoC chip design. + config WDT_GPIO bool "External gpio watchdog support" depends on WDT diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 446d961d7d2e..fffa338bef2f 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_WDT_BOOKE) += booke_wdt.o obj-$(CONFIG_WDT_CORTINA) += cortina_wdt.o obj-$(CONFIG_WDT_ORION) += orion_wdt.o obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o +obj-$(CONFIG_WDT_FTWDT010) += ftwdt010_wdt.o obj-$(CONFIG_WDT_GPIO) += gpio_wdt.o obj-$(CONFIG_WDT_MAX6370) += max6370_wdt.o obj-$(CONFIG_WDT_MESON_GXBB) += meson_gxbb_wdt.o diff --git a/drivers/watchdog/ftwdt010_wdt.c b/drivers/watchdog/ftwdt010_wdt.c new file mode 100644 index 000000000000..5f4e42e58a47 --- /dev/null +++ b/drivers/watchdog/ftwdt010_wdt.c @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Watchdog driver for the FTWDT010 Watch Dog Driver + * + * (c) Copyright 2004 Faraday Technology Corp. (www.faraday-tech.com) + * Based on sa1100_wdt.c by Oleg Drokin + * Based on SoftDog driver by Alan Cox + * + * Copyright (C) 2011 Andes Technology Corporation + * Macpaul Lin, Andes Technology Corporation + * + * 27/11/2004 Initial release, Faraday. + * 12/01/2011 Port to u-boot, Macpaul Lin. + * 22/08/2022 Port to DM + */ + +#include +#include +#include +#include +#include +#include + +struct ftwdt010_wdt_priv { + struct ftwdt010_wdt __iomem *regs; +}; + +/* + * Set the watchdog time interval. + * Counter is 32 bit. + */ +static int ftwdt010_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) +{ + struct ftwdt010_wdt_priv *priv = dev_get_priv(dev); + struct ftwdt010_wdt *wd = priv->regs; + unsigned int reg; + + debug("Activating WDT %llu ms\n", timeout_ms); + + /* Check if disabled */ + if (readl(&wd->wdcr) & ~FTWDT010_WDCR_ENABLE) { + printf("sorry, watchdog is disabled\n"); + return -1; + } + + /* + * In a 66MHz system, + * if you set WDLOAD as 0x03EF1480 (66000000) + * the reset timer is 1 second. + */ + reg = FTWDT010_WDLOAD(timeout_ms * FTWDT010_TIMEOUT_FACTOR); + + writel(reg, &wd->wdload); + + return 0; +} + +static int ftwdt010_wdt_reset(struct udevice *dev) +{ + struct ftwdt010_wdt_priv *priv = dev_get_priv(dev); + struct ftwdt010_wdt *wd = priv->regs; + + /* clear control register */ + writel(0, &wd->wdcr); + + /* Write Magic number */ + writel(FTWDT010_WDRESTART_MAGIC, &wd->wdrestart); + + /* Enable WDT */ + writel((FTWDT010_WDCR_RST | FTWDT010_WDCR_ENABLE), &wd->wdcr); + + return 0; +} + +static int ftwdt010_wdt_stop(struct udevice *dev) +{ + struct ftwdt010_wdt_priv *priv = dev_get_priv(dev); + struct ftwdt010_wdt *wd = priv->regs; + + debug("Deactivating WDT..\n"); + + /* + * It was defined with CONFIG_WATCHDOG_NOWAYOUT in Linux + * + * Shut off the timer. + * Lock it in if it's a module and we defined ...NOWAYOUT + */ + writel(0, &wd->wdcr); + return 0; +} + +static int ftwdt010_wdt_expire_now(struct udevice *dev, ulong flags) +{ + struct ftwdt010_wdt_priv *priv = dev_get_priv(dev); + struct ftwdt010_wdt *wd = priv->regs; + + debug("Expiring WDT..\n"); + writel(FTWDT010_WDLOAD(0), &wd->wdload); + return ftwdt010_wdt_reset(dev); +} + +static int ftwdt010_wdt_probe(struct udevice *dev) +{ + struct ftwdt010_wdt_priv *priv = dev_get_priv(dev); + + priv->regs = dev_read_addr_ptr(dev); + if (!priv->regs) + return -EINVAL; + + return 0; +} + +static const struct wdt_ops ftwdt010_wdt_ops = { + .start = ftwdt010_wdt_start, + .reset = ftwdt010_wdt_reset, + .stop = ftwdt010_wdt_stop, + .expire_now = ftwdt010_wdt_expire_now, +}; + +static const struct udevice_id ftwdt010_wdt_ids[] = { + { .compatible = "faraday,ftwdt010-wdt" }, + {} +}; + +U_BOOT_DRIVER(ftwdt010_wdt) = { + .name = "ftwdt010_wdt", + .id = UCLASS_WDT, + .of_match = ftwdt010_wdt_ids, + .ops = &ftwdt010_wdt_ops, + .probe = ftwdt010_wdt_probe, + .priv_auto = sizeof(struct ftwdt010_wdt_priv), +}; diff --git a/include/faraday/ftwdt010_wdt.h b/include/faraday/ftwdt010_wdt.h index 804907d64558..d4c11e39a053 100644 --- a/include/faraday/ftwdt010_wdt.h +++ b/include/faraday/ftwdt010_wdt.h @@ -89,7 +89,4 @@ struct ftwdt010_wdt { */ #define FTWDT010_TIMEOUT_FACTOR (get_board_sys_clk() / 1000) /* 1 ms */ -void ftwdt010_wdt_reset(void); -void ftwdt010_wdt_disable(void); - #endif /* __FTWDT010_H */ -- 2.34.1