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 57174C001B0 for ; Mon, 24 Jul 2023 06:25:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8CC0986821; Mon, 24 Jul 2023 08:25:41 +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="PUFV59Tk"; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=kernel-space.org header.i=@kernel-space.org header.b="PhstyzxK"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2DB698671F; Mon, 24 Jul 2023 08:25:40 +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 7D01C86810 for ; Mon, 24 Jul 2023 08:25:37 +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 0514331c; Mon, 24 Jul 2023 06:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=simple; d=kernel-space.org; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s=default; bh=tTChoZgNa5Vw1P5l908dC0xaClY=; b=PUFV59TkvJs2xo1638LQUs/T/ppw hYeQzH0JUnvW+GbiLQI86E0XvKPmb+KLd2bx6A9foUUNwKHHGLBjaGWrf9arRLip VY6o0xFtVj3hjq4bapHyQ4BCrG2VQBM/z8eKsUuXlamJHVlxc++cG0PHVCG8WZ9R KcSUTwYTvExa5g8= DomainKey-Signature: a=rsa-sha1; c=simple; d=kernel-space.org; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; q=dns; s= default; b=Zp3jMUm+tjEDW//6Bwok5fjCsDpmyG1V8Uzt4UklRaSS2Ga4I/utL FNJr/gZUjmT/PhVHHkAKB2A+6j8JYUlVXi5K9Pbv9fXuMZbLociAQNjcC6kQuniM xPi9oxO8MBAIOl2kuUNNot7NkA1M8wVeHD8QsmA4Lq9ck6Iv2vw4QA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-space.org; s=20190913; t=1690179937; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OFQgL/jDoc2ANvSVflgDXcIEd7uWv85Zl6OlGVVicUA=; b=PhstyzxK/QDTwlvVRSavaKa5bSRIOYe34zQvHf8JeMg5bxfXU9CRx1iIrCQL+n2i1GQcn7 3LTSZCtPk2qY1Z7xs504RJHxHsNponHvxEcgEjFhJmkfH6a9P+NPguOgXPOVLH6V3EdfcX oHb8d1cbucRP7e6niVvKvq2BWkKRaIY= Received: from [192.168.0.2] (host-79-54-54-35.retail.telecomitalia.it [79.54.54.35]) by ziongate (OpenSMTPD) with ESMTPSA id 35da29dd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 24 Jul 2023 06:25:36 +0000 (UTC) Message-ID: <37beda66-7691-7c63-1d4e-ae388d981825@kernel-space.org> Date: Mon, 24 Jul 2023 08:25:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Betterbird/102.11.0 Subject: Re: [PATCH v2 1/5] drivers: watchdog: add mcf watchdog support To: Stefan Roese , trini@konsulko.com Cc: u-boot@lists.denx.de References: <20230723213520.807731-1-angelo@kernel-space.org> <20230723213520.807731-2-angelo@kernel-space.org> <884fbe13-0b44-fa3a-c16a-8fecf0d15911@denx.de> Content-Language: en-US From: Angelo Dureghello In-Reply-To: <884fbe13-0b44-fa3a-c16a-8fecf0d15911@denx.de> Content-Type: text/plain; charset=UTF-8; format=flowed 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 Hi Stefan, On 24/07/23 8:21 AM, Stefan Roese wrote: > Hi Angelo, > > On 7/23/23 23:35, Angelo Dureghello wrote: >> 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 > > Perfect, thanks! > >> - 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; > > Hmmm, all the calculations are overwritten here. This does not seem to > be correct. Please check again. > ops, thanks for catching it, i had a reflog reset at a certain point, and this test left in. Fixing. > Thanks, > Stefan > >> + >> +    /* 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, >> +}; > > Viele Grüße, > Stefan Roese > Regards, angelo