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 168F1C001B0 for ; Mon, 24 Jul 2023 06:49:55 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A84E7865B0; Mon, 24 Jul 2023 08:49:51 +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="t0kMyhuL"; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=kernel-space.org header.i=@kernel-space.org header.b="bkKXHce9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2A53C84460; Mon, 24 Jul 2023 08:49:45 +0200 (CEST) Received: from mail.kernel-space.org (mail.kernel-space.org [195.201.34.187]) (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 1DA8E856A7 for ; Mon, 24 Jul 2023 08:49:39 +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 4ed7ac1b; Mon, 24 Jul 2023 06:49:38 +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=0j10wmOvPUwYxtuvRkC6RT E0cC4=; b=t0kMyhuLi6fHAz/GLre/jmmR/nWJB6w1ZVok6uzPaRJpFRbn+OeH5x pgWFlC9aqfijMfR43ptLs6E3Bh9onxdyndDre+zc2q9CfhXSrJMOfFYF0ANzrvPh r27rGKerbGbKrpiAidd2Y5Qpc2S+7vxxh0O9n+QA4KzxRYJVweqR0= 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=Z2OXTaf61VzP34SB wrM1S5sE5DLydopFkMeVLbDGb2htVB2tyS3pDHQjNEdiqDXRLomQWJbQOwGnGwjS 4HAhEhJ7eq2b9Q5hjOUUmRkFcXaCr5JHqHdp1N3cvPG5LK/92q4H4b/0bgCCh3iW BHk/fNlhk5F4jlUojkqOrg/ghss= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-space.org; s=20190913; t=1690181377; 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=wpL/9OT1N6oceTTEQnpfHYb+Z3OJZRKSPIGcInkA7oM=; b=bkKXHce9ny66bZiFHUoM++e9yTyG1xdMu6Ysvvfy6zREtfI3kUHeHscVZeWhbbO6JO1XNJ ANLOVHxSOXBT5Ya0nsXfvIsqRYqL3SWLOvoI7AnVL6+m3rX+SbefBqz8m/Q1/y8C1QI1TM wrUuMQ0pG928BifMmEFHn/ErPypbMAE= Received: from localhost.localdomain (host-79-54-54-35.retail.telecomitalia.it [79.54.54.35]) by ziongate (OpenSMTPD) with ESMTPSA id c3ea92d6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 24 Jul 2023 06:49:37 +0000 (UTC) From: Angelo Dureghello To: trini@konsulko.com, sr@denx.de Cc: u-boot@lists.denx.de, Angelo Dureghello Subject: [PATCH v3 1/5] drivers: watchdog: add mcf watchdog support Date: Mon, 24 Jul 2023 08:49:11 +0200 Message-ID: <20230724064915.56445-2-angelo@kernel-space.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230724064915.56445-1-angelo@kernel-space.org> References: <20230724064915.56445-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 Changes for v3: - remove hardcoded 4s test --- drivers/watchdog/Kconfig | 7 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/mcf_wdt.c | 135 +++++++++++++++++++++++++++++++++++++ 3 files changed, 143 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..b36488bb5b --- /dev/null +++ b/drivers/watchdog/mcf_wdt.c @@ -0,0 +1,135 @@ +// 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; + + /* 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