From mboxrd@z Thu Jan 1 00:00:00 1970 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 CA871C001B0 for ; Sun, 23 Jul 2023 21:35:56 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D6A39866D0; Sun, 23 Jul 2023 23:35:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=quarantine dis=none) header.from=kernel-space.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=kernel-space.org header.i=@kernel-space.org header.b="feUMZ42l"; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=kernel-space.org header.i=@kernel-space.org header.b="VzNvjQkJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 70EED863E4; Sun, 23 Jul 2023 23:35:43 +0200 (CEST) Received: from mail.kernel-space.org (unknown [IPv6:2a01:4f8:c2c:5a84::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C460586661 for ; Sun, 23 Jul 2023 23:35:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=kernel-space.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=angelo@kernel-space.org Received: from ziongate (localhost [127.0.0.1]) by ziongate (OpenSMTPD) with ESMTP id d720fc40; Sun, 23 Jul 2023 21:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=simple; d=kernel-space.org; h=from:to :cc:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=default; bh=2LlCNUMXwk1k1mHL70sEUh c2nlI=; b=feUMZ42lj1Q1+x7H6qbaw0Vibe6G98Y4rbIqbwLzWgJ9Bv8haCo2Yh Eg1Fhg/biXbgmUTcpzc6E3maz0A+EDoFH0XP2UWq5DGeXW0Nwt3/wzoJIDSXnnu5 uUD0ONpr6jcX7PxmnSzAWPkXHQn0VvfW6RY+LRvEjTLOJoibEQA6Y= DomainKey-Signature: a=rsa-sha1; c=simple; d=kernel-space.org; h=from:to :cc:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=default; b=FWJImKDh8PDibOqU pYijfrfb/UNPBGqBEAz51kMfKWC27UHw2JvNVRX6R363l03grKZXcD+SNksJx5hV pk7AVyGVO6Kbcsic2BUvjPIrLVuUkYuVkJBB2lS6ZK2/Pm37Ukbp3KGxpHRgWgsb e/FPkSuuyf91dRjGfMpRL4mJZtk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-space.org; s=20190913; t=1690148138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MWIgq4UkYmup4SkYOSTg24r+hlyW5pT8Diy4TPkOtgI=; b=VzNvjQkJep1mK8gaRaFobSI7BlvM3Myu5PzDR0Kgu0hTx6b8ouM3Bb30FvuLfxxopojwL7 vpGDaCa/iBhZoB2yyjr1ZkGd0UZXQhV/6Xz36HU2G2afEiYLkQNPvEPdJ3UEv1W2vjXMSA /H1ONGCvG6NotT4KQVkzIydi4a8DZAM= Received: from localhost.localdomain (host-79-54-54-35.retail.telecomitalia.it [79.54.54.35]) by ziongate (OpenSMTPD) with ESMTPSA id ac0a69b4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sun, 23 Jul 2023 21:35:38 +0000 (UTC) From: Angelo Dureghello To: trini@konsulko.com, sr@denx.de Cc: u-boot@lists.denx.de, Angelo Dureghello Subject: [PATCH v2 1/5] drivers: watchdog: add mcf watchdog support Date: Sun, 23 Jul 2023 23:35:16 +0200 Message-ID: <20230723213520.807731-2-angelo@kernel-space.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230723213520.807731-1-angelo@kernel-space.org> References: <20230723213520.807731-1-angelo@kernel-space.org> 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.8 at phobos.denx.de X-Virus-Status: Clean This watchdog driver applies to the following mcf families: - mcf52x2 (5271 5275 5282) - mcf532x (5329 5373) - mcf523x (5235) Cpu's not listed for each family does not have WDT module. Note, after some attempts testing by qemu on 5208 i finally abandoned, watchdog seems not implemented properly. The driver has been tested in a real M5282EVM. Signed-off-by: Angelo Dureghello --- Changes for v2: - remove unnecessary hardcoded timeouts - remove unnecessary hw_watchdog_xxx stuff - rewrite wdog module reg calculation - using IS_ENABLED() where possible --- drivers/watchdog/Kconfig | 7 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/mcf_wdt.c | 137 +++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 drivers/watchdog/mcf_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 646663528a..07fc4940e9 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -178,6 +178,13 @@ config WDT_MAX6370 help Select this to enable max6370 watchdog timer. +config WDT_MCF + bool "ColdFire family watchdog timer support" + depends on WDT + help + Select this to enable ColdFire watchdog timer, + which supports mcf52x2 mcf532x mcf523x families. + config WDT_MESON_GXBB bool "Amlogic watchdog timer support" depends on WDT diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index fd5d9c7376..eef786f5e7 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -31,6 +31,7 @@ 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_MCF) += mcf_wdt.o obj-$(CONFIG_WDT_MESON_GXBB) += meson_gxbb_wdt.o obj-$(CONFIG_WDT_MPC8xxx) += mpc8xxx_wdt.o obj-$(CONFIG_WDT_MT7620) += mt7620_wdt.o diff --git a/drivers/watchdog/mcf_wdt.c b/drivers/watchdog/mcf_wdt.c new file mode 100644 index 0000000000..cad6097a7d --- /dev/null +++ b/drivers/watchdog/mcf_wdt.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * mcf_wdt.c - driver for ColdFire on-chip watchdog + * + * Author: Angelo Dureghello + * + */ + +#include +#include +#include +#include +#include +#include + +#define DIVIDER_5XXX 4096 +#define DIVIDER_5282 8192 + +#define WCR_EN BIT(0) +#define WCR_HALTED BIT(1) +#define WCR_DOZE BIT(2) +#define WCR_WAIT BIT(3) + +struct watchdog_regs { + u16 wcr; /* Control */ + u16 wmr; /* Service */ + u16 wcntr; /* Counter */ + u16 wsr; /* Reset Status */ +}; + +static void mcf_watchdog_reset(struct watchdog_regs *wdog) +{ + if (!IS_ENABLED(CONFIG_WATCHDOG_RESET_DISABLE)) { + writew(0x5555, &wdog->wsr); + writew(0xaaaa, &wdog->wsr); + } +} + +static void mcf_watchdog_init(struct watchdog_regs *wdog, u32 fixed_divider, + u64 timeout_msecs) +{ + u32 wdog_module, cycles_per_sec; + + cycles_per_sec = CFG_SYS_CLK / fixed_divider; + + wdog_module = cycles_per_sec * ((u32)timeout_msecs / 1000); + wdog_module += (cycles_per_sec / 1000) * ((u32)timeout_msecs % 1000); + + /* Limit check, max 16 bits */ + if (wdog_module > 0xffff) + wdog_module = 0xffff; + + wdog_module = 0x8000; + + /* Set timeout and enable watchdog */ + writew((u16)wdog_module, &wdog->wmr); + writew(WCR_EN, &wdog->wcr); + + mcf_watchdog_reset(wdog); +} + +struct mcf_wdt_priv { + void __iomem *base; + u32 fixed_divider; +}; + +static int mcf_wdt_expire_now(struct udevice *dev, ulong flags) +{ + hang(); + + return 0; +} + +static int mcf_wdt_reset(struct udevice *dev) +{ + struct mcf_wdt_priv *priv = dev_get_priv(dev); + + mcf_watchdog_reset(priv->base); + + return 0; +} + +static int mcf_wdt_start(struct udevice *dev, u64 timeout, ulong flags) +{ + struct mcf_wdt_priv *priv = dev_get_priv(dev); + + /* Timeout from fdt (timeout) comes in milliseconds */ + mcf_watchdog_init(priv->base, priv->fixed_divider, timeout); + + return 0; +} + +static int mcf_wdt_stop(struct udevice *dev) +{ + struct mcf_wdt_priv *priv = dev_get_priv(dev); + struct watchdog_regs *wdog = (struct watchdog_regs *)priv->base; + + setbits_be16(&wdog->wcr, WCR_HALTED); + + return 0; +} + +static int mcf_wdt_probe(struct udevice *dev) +{ + struct mcf_wdt_priv *priv = dev_get_priv(dev); + + priv->base = dev_read_addr_ptr(dev); + if (!priv->base) + return -ENOENT; + + priv->fixed_divider = (u32)dev_get_driver_data(dev); + + return 0; +} + +static const struct wdt_ops mcf_wdt_ops = { + .start = mcf_wdt_start, + .stop = mcf_wdt_stop, + .reset = mcf_wdt_reset, + .expire_now = mcf_wdt_expire_now, +}; + +static const struct udevice_id mcf_wdt_ids[] = { + { .compatible = "fsl,mcf5208-wdt", .data = DIVIDER_5XXX }, + { .compatible = "fsl,mcf5282-wdt", .data = DIVIDER_5282 }, + {} +}; + +U_BOOT_DRIVER(mcf_wdt) = { + .name = "mcf_wdt", + .id = UCLASS_WDT, + .of_match = mcf_wdt_ids, + .probe = mcf_wdt_probe, + .ops = &mcf_wdt_ops, + .priv_auto = sizeof(struct mcf_wdt_priv), + .flags = DM_FLAG_PRE_RELOC, +}; -- 2.41.0