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 CB996C433F5 for ; Thu, 5 May 2022 09:36:25 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 486F683D7D; Thu, 5 May 2022 11:36:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="FKtx4OMq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D905783B19; Thu, 5 May 2022 11:36:19 +0200 (CEST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D8E9A83D7D for ; Thu, 5 May 2022 11:36:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 14DB56134E; Thu, 5 May 2022 09:36:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29F16C385A4; Thu, 5 May 2022 09:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651743372; bh=bf60q9vJS7CyMoBDjZIh8U2VnbgZyInyyXoKb9iAJ+c=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FKtx4OMqyRcyMukW5892elWYaosAC74kJtrIZbwRZoiIbvF5usIqfcTz7XUftkgEI F8ehmaepHILK505Gpob1SZsUrs61iZrJWvR1InVzATf/iqMPscDY/qqSAePeGs4H5Z hh/OFnvXPjcu9Md0HccgQZmjIqsbGsnhxXJy8zL+TTYNAmdStI+SqdxyP9WlaLh7zS LgXlHgFpcX81zBNhTraJARtdjZmI5qerUApi3ShYoFeutEwSn2ItV2bDsiiBOGsd4q TSRlwoJ1VRFTHEgrfldGW4dybkU2zXzWCVB05tou1Q6bAkPZEHtgn+9WM5+urclOLG i6F3f8WkquFtg== Received: by pali.im (Postfix) id 3F92F7A6; Thu, 5 May 2022 11:36:09 +0200 (CEST) Date: Thu, 5 May 2022 11:36:09 +0200 From: Pali =?utf-8?B?Um9ow6Fy?= To: Stefan Roese Cc: u-boot@lists.denx.de Subject: Re: [PATCH] watchdog: Add MAX6370 watchdog timer driver Message-ID: <20220505093609.a34un3akw77imubf@pali> References: <20220502164107.11017-1-pali@kernel.org> <665bb2a0-b809-6e65-5c5c-1714b2488890@denx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <665bb2a0-b809-6e65-5c5c-1714b2488890@denx.de> User-Agent: NeoMutt/20180716 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.5 at phobos.denx.de X-Virus-Status: Clean On Tuesday 03 May 2022 07:16:34 Stefan Roese wrote: > On 02.05.22 18:41, Pali Rohár wrote: > > MAX6370 watchdog is available e.g. on Freescale P1/P2 RDB-PC boards. > > > > Signed-off-by: Pali Rohár > > --- > > drivers/watchdog/Kconfig | 7 ++ > > drivers/watchdog/Makefile | 1 + > > drivers/watchdog/max6370_wdt.c | 119 +++++++++++++++++++++++++++++++++ > > 3 files changed, 127 insertions(+) > > create mode 100644 drivers/watchdog/max6370_wdt.c > > > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig > > index f90f0ca02bce..1801698ac512 100644 > > --- a/drivers/watchdog/Kconfig > > +++ b/drivers/watchdog/Kconfig > > @@ -167,6 +167,13 @@ config WDT_GPIO > > doc/device-tree-bindings/watchdog/gpio-wdt.txt for > > information on how to describe the watchdog in device tree. > > +config WDT_MAX6370 > > + bool "MAX6370 watchdog timer support" > > + depends on WDT > > + select DM_GPIO > > + help > > + Select this to enable max6370 watchdog timer. > > + > > config WDT_MPC8xx > > bool "MPC8xx watchdog timer support" > > depends on WDT && MPC8xx > > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile > > index a35bd559f51b..f999e4126b4f 100644 > > --- a/drivers/watchdog/Makefile > > +++ b/drivers/watchdog/Makefile > > @@ -27,6 +27,7 @@ obj-$(CONFIG_WDT_CORTINA) += cortina_wdt.o > > obj-$(CONFIG_WDT_ORION) += orion_wdt.o > > obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o > > obj-$(CONFIG_WDT_GPIO) += gpio_wdt.o > > +obj-$(CONFIG_WDT_MAX6370) += max6370_wdt.o > > obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o > > obj-$(CONFIG_WDT_MT7620) += mt7620_wdt.o > > obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.o > > diff --git a/drivers/watchdog/max6370_wdt.c b/drivers/watchdog/max6370_wdt.c > > new file mode 100644 > > index 000000000000..556c6a4b6d6b > > --- /dev/null > > +++ b/drivers/watchdog/max6370_wdt.c > > @@ -0,0 +1,119 @@ > > +// SPDX-License-Identifier: GPL-2.0+ > > +// (C) 2022 Pali Rohár > > + > > +#include > > AFAIK, it's not recommended any more to include "common.h" in general. Hello! I checked that driver compiles without any errors/warnings also when common.h is removed. So it can be dropped. > Looks good, other than this: > > Reviewed-by: Stefan Roese > > Thanks, > Stefan > > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#define MAX6370_SET_MASK 0x7 > > +#define MAX6370_SET_1MS 0x0 > > +#define MAX6370_SET_10MS 0x1 > > +#define MAX6370_SET_30MS 0x2 > > +#define MAX6370_SET_DISABLE 0x3 > > +#define MAX6370_SET_100MS 0x4 > > +#define MAX6370_SET_1S 0x5 > > +#define MAX6370_SET_10S 0x6 > > +#define MAX6370_SET_60S 0x7 > > + > > +#define MAX6370_WDI 0x8 > > + > > +struct max6370_wdt { > > + void __iomem *reg; > > + struct gpio_desc gpio_wdi; > > +}; > > + > > +static int max6370_wdt_start(struct udevice *dev, u64 ms, ulong flags) > > +{ > > + struct max6370_wdt *wdt = dev_get_priv(dev); > > + u8 val; > > + > > + val = readb(wdt->reg); > > + val &= ~MAX6370_SET_MASK; > > + > > + if (ms <= 1) > > + val |= MAX6370_SET_1MS; > > + else if (ms <= 10) > > + val |= MAX6370_SET_10MS; > > + else if (ms <= 30) > > + val |= MAX6370_SET_30MS; > > + else if (ms <= 100) > > + val |= MAX6370_SET_100MS; > > + else if (ms <= 1000) > > + val |= MAX6370_SET_1S; > > + else if (ms <= 10000) > > + val |= MAX6370_SET_10S; > > + else > > + val |= MAX6370_SET_60S; > > + > > + writeb(val, wdt->reg); > > + > > + return 0; > > +} > > + > > +static int max6370_wdt_stop(struct udevice *dev) > > +{ > > + struct max6370_wdt *wdt = dev_get_priv(dev); > > + u8 val; > > + > > + val = readb(wdt->reg); > > + val &= ~MAX6370_SET_MASK; > > + val |= MAX6370_SET_DISABLE; > > + writeb(val, wdt->reg); > > + > > + return 0; > > +} > > + > > +static int max6370_wdt_reset(struct udevice *dev) > > +{ > > + struct max6370_wdt *wdt = dev_get_priv(dev); > > + u8 val; > > + > > + if (dm_gpio_is_valid(&wdt->gpio_wdi)) { > > + dm_gpio_set_value(&wdt->gpio_wdi, 1); > > + udelay(1); > > + dm_gpio_set_value(&wdt->gpio_wdi, 0); > > + } else { > > + val = readb(wdt->reg); > > + writeb(val | MAX6370_WDI, wdt->reg); > > + writeb(val & ~MAX6370_WDI, wdt->reg); > > + } > > + > > + return 0; > > +} > > + > > +static int max6370_wdt_probe(struct udevice *dev) > > +{ > > + struct max6370_wdt *wdt = dev_get_priv(dev); > > + > > + wdt->reg = dev_read_addr_ptr(dev); > > + if (!wdt->reg) > > + return -EINVAL; > > + > > + /* WDI gpio is optional */ > > + gpio_request_by_name(dev, "gpios", 0, &wdt->gpio_wdi, GPIOD_IS_OUT); > > + > > + return 0; > > +} > > + > > +static const struct wdt_ops max6370_wdt_ops = { > > + .start = max6370_wdt_start, > > + .stop = max6370_wdt_stop, > > + .reset = max6370_wdt_reset, > > +}; > > + > > +static const struct udevice_id max6370_wdt_ids[] = { > > + { .compatible = "maxim,max6370" }, > > + {} > > +}; > > + > > +U_BOOT_DRIVER(max6370_wdt) = { > > + .name = "max6370_wdt", > > + .id = UCLASS_WDT, > > + .of_match = max6370_wdt_ids, > > + .probe = max6370_wdt_probe, > > + .priv_auto = sizeof(struct max6370_wdt), > > + .ops = &max6370_wdt_ops, > > +}; > > Viele Grüße, > Stefan Roese > > -- > DENX Software Engineering GmbH, Managing Director: Wolfgang Denk > HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany > Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de