From patchwork Mon Aug 5 20:03:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 817005 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 755AB16A37C; Mon, 5 Aug 2024 20:04:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722888272; cv=none; b=ihmJ2LIZtVM6HwOC00lU5ZqFJx39dYpPz2XZEawMsMWnLvY80EXJQJ48I4Zv50ml0HePshvADy5ZbPFaSoOfqGU/Y2+fz2MC4atEV3tLecWENJ/B5L/R5hzBHlhqmRhYRDevVK0AlOlZWhVg5CZjGZLkgD/0DU8NUk49mjB1e8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722888272; c=relaxed/simple; bh=iODb6OQrUL58ALslEvQpLTnfs/KQiMyRxQemMVqXOG8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kT+22KjG/yOF/QYmv8RCYn8nVjeTrm6Evk+h00xfem7lMNbyMpJOQajXa4WMChOQtC3nP40IRZlVkQLfSk3hbao111b0IM1GZWmATbz8tvPb67ZGQ+ghht26YNcPaILm+HS4fI4Vl2wjNfn1uvB2X0CbynwIjs17U6Qn7Lmn38I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XofljPCG; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XofljPCG" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-42803bbf842so99666765e9.1; Mon, 05 Aug 2024 13:04:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722888269; x=1723493069; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=heUghuk8oELrcN0EwSv5IDiZOEj9GvKbyKkKqB/gu6c=; b=XofljPCGR4DqGSEiEtwtMNrljseBNpTicgRY3/VCHLoLbNUTC6elnJSEqusN6MKyIT 17kX8Hq2ybaqvebzYSRiWRyHUlyTk/fNl3vBF3r2aXEE4UiocFmTVdP/NHslASVQJMPp Bl5JitOt2epGKlq/ajk9eVYfOGZW4xsrHK0TCCRDOm6c/HlDUhKmFmoHkLUJPC20kBO6 kBlDW694tN5rduEItJ6LUpJUBTVLjSRl3Ih78IjEGJ61MYhb2JjJm16GwtpeipKIQALh ybS6354mqGzPz4k+ip1es8AGs33rJNzEKrjk1888g3iDqshF3+PkAlDmqpXp4oCv3rnQ 47KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722888269; x=1723493069; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=heUghuk8oELrcN0EwSv5IDiZOEj9GvKbyKkKqB/gu6c=; b=LUvJC2waqVi0wdWcy8THnzw52Lhefb9mtXFyLwnIG6+izhKidfv/EhWalmh4sqGwg1 d54rVcjkfhWptoiyob0Ax5n4aaikhLNmJ6kb89sZprXWfqFBbee5AdZwjxyFV4AHegAY x3/+Tg0N1iIFNHzoS3Nn1xUKRku5TBkIhSDWJfMokVXlYB96rNjzo33+L+BX7C1SWIt2 GxXowsG3cLSDGzg/ygV70nwoNRBCxaV+AuA/GzzGyUpfHyhrlUQM1nTduc/OEYbA/jKC ofdeAlRWNmhdFbUgalinC0WdPAnBhW2RRDAI3T3Cg+2fxbOz7XV4DWxwQEukb/dHJXCw tHSQ== X-Forwarded-Encrypted: i=1; AJvYcCVjouUDrp3r/MpUigPNcwrX35PZZ9Ehd/ggpsVODMqgFTWzIqNykOkcp89lf9VPZxbT+amuSB8ekcEgCUW+LfNORsz0la5taywjIx2K+Y/Z4SSSa80emSE6mTAMxm7B4TPyVTOVeFoM/lgTSTjrz7I0AXaGre1NTYySboknaQMDVjJF61Lud4AW8Zgh20vc/w== X-Gm-Message-State: AOJu0Yylsdqmx0mFXYmBKG5o01nmnXiDyRR1L97DNsezxsEFBKToKopw +qjGOjiamZgrQF+whjOYWx9mKFlksq9bllapnrb8oxeHpLCnj55o X-Google-Smtp-Source: AGHT+IGSctFthWy1jry9/5qDYog27Heb6dpJXjOd6FXa2yBvvGqMDYcZp96iEn83vhfRTJMb8rurzg== X-Received: by 2002:a05:600c:4713:b0:426:593c:9359 with SMTP id 5b1f17b1804b1-428e6b954cfmr130704735e9.32.1722888268626; Mon, 05 Aug 2024 13:04:28 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2500:a01:25b8:5324:d26c:319c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4282bba283fsm212967405e9.46.2024.08.05.13.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 13:04:28 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Wim Van Sebroeck , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , Geert Uytterhoeven , Magnus Damm , Wolfram Sang , linux-watchdog@vger.kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Fabrizio Castro , Lad Prabhakar , Conor Dooley Subject: [PATCH v3 1/2] dt-bindings: watchdog: renesas, wdt: Document RZ/V2H(P) SoC Date: Mon, 5 Aug 2024 21:03:59 +0100 Message-Id: <20240805200400.54267-2-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240805200400.54267-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20240805200400.54267-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Lad Prabhakar Add support for the Watchdog Timer (WDT) hardware found in the Renesas RZ/V2H(P) SoC to the `renesas,wdt` device tree bindings. The RZ/V2H(P) SoC features a WDT that is compatible with existing Renesas watchdog drivers. Signed-off-by: Lad Prabhakar Reviewed-by: Conor Dooley --- v2->v3 - No change v1->v2 - Included RB tag --- .../bindings/watchdog/renesas,wdt.yaml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/watchdog/renesas,wdt.yaml b/Documentation/devicetree/bindings/watchdog/renesas,wdt.yaml index eba454d1680f..29ada89fdcdc 100644 --- a/Documentation/devicetree/bindings/watchdog/renesas,wdt.yaml +++ b/Documentation/devicetree/bindings/watchdog/renesas,wdt.yaml @@ -75,6 +75,8 @@ properties: - renesas,r8a779h0-wdt # R-Car V4M - const: renesas,rcar-gen4-wdt # R-Car Gen4 + - const: renesas,r9a09g057-wdt # RZ/V2H(P) + reg: maxItems: 1 @@ -113,7 +115,6 @@ properties: required: - compatible - reg - - interrupts - clocks allOf: @@ -137,6 +138,7 @@ allOf: compatible: contains: enum: + - renesas,r9a09g057-wdt - renesas,rzg2l-wdt - renesas,rzv2m-wdt then: @@ -171,6 +173,19 @@ allOf: interrupts: maxItems: 1 + - if: + properties: + compatible: + contains: + const: renesas,r9a09g057-wdt + then: + properties: + interrupts: false + interrupt-names: false + else: + required: + - interrupts + additionalProperties: false examples: From patchwork Mon Aug 5 20:04:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 818019 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3042D16C685; Mon, 5 Aug 2024 20:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722888274; cv=none; b=BQys/S5ZwjX5HyfUkykkGT6sc7elfHknX1dUYI2KvGkWX0cBpdHLQH4dI7EuVjwhk7DA6QMUhphNxzwPKfQcDMP+jfSNVD8ZJhiTQNP92yVU8yBMUB2uZ9vJhAoSQX7KxJlO7Fz1DXAblNEFGF6O6gK2kjrUOE5ncnctemMd338= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722888274; c=relaxed/simple; bh=P53qhd6+ozI4VEk0c54iusDCvkZgQjpmPtYALpJIwII=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IvLSCkbiSXCZ3LwC/4vJhGEYj9E8+SCL/nAWzd8kCvoxmbz9h767eVpmnVQVn9Lb4nHp5u/D/xCwUYoTkD1fHjdAKlg0Czwin9dZALdLD6xz9jSRXn0gKltMMr8YwnJo3blmKGaGphc8iFiUqMyEEjXJAQyRON4E11UYmBP/hek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=curZFmry; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="curZFmry" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-428101fa30aso74595355e9.3; Mon, 05 Aug 2024 13:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722888270; x=1723493070; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rfmAkqMppQmXn3G0HuffGmjKEV6LkBFo2k/rVR8mfPs=; b=curZFmrylxh5zcaeYbziobamjzVK/ObbY1gSarVJupeiwJvWOoiGQipreDCwiBxnR0 502zsEuKtuSCGeLQMPGk/bYYtaTNxaxetwL5M28Ssbw+YFqnmoCV6mGhmEOLgYC9fxHv ypG68Ob50ne6bg8bjQ8sZB0GhrrBtsADGj2CXCrrdi1aLavL4rEYh7FZq/Jjx4d6kAOr amvFJidIJtUmv5YszY7QfVcjjUe4ObZf6ZBP0xnqMMl1rEEfsP5sRhTMDxur4VoCbtzZ B9DQTdnbrdeyxUjSiwqW/WQMqDVTRP9FbwqBU00mOaZOi5MavhweseItz88EdjClI2p4 vlNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722888270; x=1723493070; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rfmAkqMppQmXn3G0HuffGmjKEV6LkBFo2k/rVR8mfPs=; b=ByX23VQhY2bGpkpwnhMcNmNemDlwEoz+Tki24VlUH83HJ4CWihQIGJmFoRNC+4JFfp uSeNSBpbQ5L3CxbC82Z7ca79MgABD4aqqypeKAN2+vJz+Cc4zGIZG3K9ABhWfCSjnekv W1tckuF6HSZ5FEasFw2gouFbVRVK/a4RIN/GFd36PzMejQUACiDzX7bOWk4IraACJgnL XbkpwEwTEqPg9j9FOV3YCiHoTTObrcqT6P69raVc6TbgexXTytUKOReVCfTUhgghe1bv 04kVrXVETtU+fb31IX/9o1rIKbDKfRZygbe2QIg6B7Uw51THedX4qKcRZNPZe231p52o 9EJQ== X-Forwarded-Encrypted: i=1; AJvYcCVKkXkyG8L7v+HJy2xYEArNsuFkNmaDDDxF58HjpvOCTB1OvmvmbDADT1dMynXM+Opes9nSr5nLb3ZMdSi3kkkW1xp5WpEm/jJHCMya52zN5ihDlpu2gIFntIjiqZOr3FcwWnyfF9zH8am0jXnQB5kOcg94n6M1KCD3DGW39w2sre+mgjAg0fNPa9dOWbHm9Q== X-Gm-Message-State: AOJu0YzbvQ1OhD25XvOywBOr52CsXP+98t6PAXK347fM672DzihnAc/2 CARIRk6PTmEamH20pAUcK8rcnRzTuaPLniNF/xz1RcYtnwSSSGPb X-Google-Smtp-Source: AGHT+IGksU58etR9fGFysfwddVc4povaE5jcK+o+C9eACWjj/T9NP7nXwRaxc/+9Sz+IgOJUYfYNzA== X-Received: by 2002:a05:600c:358b:b0:426:63ff:f763 with SMTP id 5b1f17b1804b1-428e6b942femr82420685e9.36.1722888270274; Mon, 05 Aug 2024 13:04:30 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2500:a01:25b8:5324:d26c:319c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4282bba283fsm212967405e9.46.2024.08.05.13.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Aug 2024 13:04:29 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Wim Van Sebroeck , Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Philipp Zabel , Geert Uytterhoeven , Magnus Damm , Wolfram Sang , linux-watchdog@vger.kernel.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Biju Das , Fabrizio Castro , Lad Prabhakar Subject: [PATCH v3 2/2] watchdog: Add Watchdog Timer driver for RZ/V2H(P) Date: Mon, 5 Aug 2024 21:04:00 +0100 Message-Id: <20240805200400.54267-3-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240805200400.54267-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20240805200400.54267-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-watchdog@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Lad Prabhakar Add Watchdog Timer driver for RZ/V2H(P) SoC. Signed-off-by: Lad Prabhakar --- v2->v3 - Fixed dependency, ARCH_R9A09G011->ARCH_R9A09G057 - Added dependency for PM - Added delay after de-assert operation as clks are halted temporarily after de-assert operation - clearing WDTSR register v1->v2 - Stopped using PM runtime calls in restart handler - Dropped rstc deassert from probe --- drivers/watchdog/Kconfig | 9 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/rzv2h_wdt.c | 259 +++++++++++++++++++++++++++++++++++ 3 files changed, 269 insertions(+) create mode 100644 drivers/watchdog/rzv2h_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index bae1d97cce89..684b9fe84fff 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -953,6 +953,15 @@ config RENESAS_RZG2LWDT This driver adds watchdog support for the integrated watchdogs in the Renesas RZ/G2L SoCs. These watchdogs can be used to reset a system. +config RENESAS_RZV2HWDT + tristate "Renesas RZ/V2H(P) WDT Watchdog" + depends on ARCH_R9A09G057 || COMPILE_TEST + depends on PM || COMPILE_TEST + select WATCHDOG_CORE + help + This driver adds watchdog support for the integrated watchdogs in the + Renesas RZ/V2H(P) SoCs. These watchdogs can be used to reset a system. + config ASPEED_WATCHDOG tristate "Aspeed BMC watchdog support" depends on ARCH_ASPEED || COMPILE_TEST diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index b51030f035a6..ab6f2b41e38e 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -86,6 +86,7 @@ obj-$(CONFIG_RENESAS_WDT) += renesas_wdt.o obj-$(CONFIG_RENESAS_RZAWDT) += rza_wdt.o obj-$(CONFIG_RENESAS_RZN1WDT) += rzn1_wdt.o obj-$(CONFIG_RENESAS_RZG2LWDT) += rzg2l_wdt.o +obj-$(CONFIG_RENESAS_RZV2HWDT) += rzv2h_wdt.o obj-$(CONFIG_ASPEED_WATCHDOG) += aspeed_wdt.o obj-$(CONFIG_STM32_WATCHDOG) += stm32_iwdg.o obj-$(CONFIG_UNIPHIER_WATCHDOG) += uniphier_wdt.o diff --git a/drivers/watchdog/rzv2h_wdt.c b/drivers/watchdog/rzv2h_wdt.c new file mode 100644 index 000000000000..b6183940b221 --- /dev/null +++ b/drivers/watchdog/rzv2h_wdt.c @@ -0,0 +1,259 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Renesas RZ/V2H(P) WDT Watchdog Driver + * + * Copyright (C) 2024 Renesas Electronics Corporation. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define WDTRR 0x00 /* RW, 8 */ +#define WDTCR 0x02 /* RW, 16 */ +#define WDTSR 0x04 /* RW, 16 */ +#define WDTRCR 0x06 /* RW, 8 */ + +#define WDTCR_TOPS_1024 0x00 +#define WDTCR_TOPS_16384 0x03 + +#define WDTCR_CKS_CLK_1 0x00 +#define WDTCR_CKS_CLK_256 0x50 + +#define WDTCR_RPES_0 0x300 +#define WDTCR_RPES_75 0x000 + +#define WDTCR_RPSS_25 0x00 +#define WDTCR_RPSS_100 0x3000 + +#define WDTRCR_RSTIRQS BIT(7) + +#define CLOCK_DIV_BY_256 256 + +#define WDT_DEFAULT_TIMEOUT 60U + +static bool nowayout = WATCHDOG_NOWAYOUT; +module_param(nowayout, bool, 0); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +struct rzv2h_wdt_priv { + void __iomem *base; + struct clk *pclk; + struct clk *oscclk; + struct reset_control *rstc; + struct watchdog_device wdev; + unsigned long oscclk_rate; +}; + +static int rzv2h_wdt_ping(struct watchdog_device *wdev) +{ + struct rzv2h_wdt_priv *priv = watchdog_get_drvdata(wdev); + static unsigned long delay; + + writeb(0x0, priv->base + WDTRR); + writeb(0xFF, priv->base + WDTRR); + + /* + * Refreshing the down-counter requires up to 4 cycles + * of the signal for counting + */ + if (!delay) + delay = 4 * div64_ul(CLOCK_DIV_BY_256 * MICRO, priv->oscclk_rate); + udelay(delay); + + return 0; +} + +static void rzv2h_wdt_setup(struct watchdog_device *wdev, u16 wdtcr) +{ + struct rzv2h_wdt_priv *priv = watchdog_get_drvdata(wdev); + + writew(wdtcr, priv->base + WDTCR); + + writeb(0, priv->base + WDTRCR); + + writew(0, priv->base + WDTSR); +} + +static int rzv2h_wdt_start(struct watchdog_device *wdev) +{ + struct rzv2h_wdt_priv *priv = watchdog_get_drvdata(wdev); + int ret; + + ret = reset_control_deassert(priv->rstc); + if (ret) + return ret; + + udelay(5); + + ret = pm_runtime_resume_and_get(wdev->parent); + if (ret) { + reset_control_assert(priv->rstc); + return ret; + } + + /* + * WDTCR + * - CKS[7:4] - Clock Division Ratio Select - 0101b: oscclk/256 + * - RPSS[13:12] - Window Start Position Select - 11b: 100% + * - RPES[9:8] - Window End Position Select - 11b: 0% + * - TOPS[1:0] - Timeout Period Select - 11b: 16384 cycles (3FFFh) + */ + rzv2h_wdt_setup(wdev, WDTCR_CKS_CLK_256 | WDTCR_RPSS_100 | + WDTCR_RPES_0 | WDTCR_TOPS_16384); + + rzv2h_wdt_ping(wdev); + + return 0; +} + +static int rzv2h_wdt_stop(struct watchdog_device *wdev) +{ + struct rzv2h_wdt_priv *priv = watchdog_get_drvdata(wdev); + int ret; + + ret = pm_runtime_put(wdev->parent); + if (ret < 0) + return ret; + + return reset_control_assert(priv->rstc); +} + +static const struct watchdog_info rzv2h_wdt_ident = { + .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT, + .identity = "Renesas RZ/V2H WDT Watchdog", +}; + +static int rzv2h_wdt_restart(struct watchdog_device *wdev, + unsigned long action, void *data) +{ + struct rzv2h_wdt_priv *priv = watchdog_get_drvdata(wdev); + int ret; + + ret = reset_control_deassert(priv->rstc); + if (ret) + return ret; + + /* delay to handle clock halt after de-assert operation */ + udelay(5); + + ret = clk_enable(priv->pclk); + if (ret) { + reset_control_assert(priv->rstc); + return ret; + } + + ret = clk_enable(priv->oscclk); + if (ret) { + clk_disable(priv->pclk); + reset_control_assert(priv->rstc); + return ret; + } + + /* + * WDTCR + * - CKS[7:4] - Clock Division Ratio Select - 0000b: oscclk/1 + * - RPSS[13:12] - Window Start Position Select - 00b: 25% + * - RPES[9:8] - Window End Position Select - 00b: 75% + * - TOPS[1:0] - Timeout Period Select - 00b: 1024 cycles (03FFh) + */ + rzv2h_wdt_setup(wdev, WDTCR_CKS_CLK_1 | WDTCR_RPSS_25 | + WDTCR_RPES_75 | WDTCR_TOPS_1024); + rzv2h_wdt_ping(wdev); + + /* wait for underflow to trigger... */ + mdelay(500); + + return 0; +} + +static const struct watchdog_ops rzv2h_wdt_ops = { + .owner = THIS_MODULE, + .start = rzv2h_wdt_start, + .stop = rzv2h_wdt_stop, + .ping = rzv2h_wdt_ping, + .restart = rzv2h_wdt_restart, +}; + +static int rzv2h_wdt_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct rzv2h_wdt_priv *priv; + unsigned long rate; + int ret; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + priv->pclk = devm_clk_get_prepared(&pdev->dev, "pclk"); + if (IS_ERR(priv->pclk)) + return dev_err_probe(&pdev->dev, PTR_ERR(priv->pclk), "no pclk"); + + priv->oscclk = devm_clk_get_prepared(&pdev->dev, "oscclk"); + if (IS_ERR(priv->oscclk)) + return dev_err_probe(&pdev->dev, PTR_ERR(priv->oscclk), "no oscclk"); + + priv->oscclk_rate = clk_get_rate(priv->oscclk); + if (!priv->oscclk_rate) + return dev_err_probe(&pdev->dev, -EINVAL, "oscclk rate is 0"); + + priv->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); + if (IS_ERR(priv->rstc)) + return dev_err_probe(&pdev->dev, PTR_ERR(priv->rstc), + "failed to get cpg reset"); + + rate = priv->oscclk_rate / 256; + priv->wdev.max_hw_heartbeat_ms = (1000 * 16383) / rate; + dev_dbg(dev, "max hw timeout of %dms\n", + priv->wdev.max_hw_heartbeat_ms); + + ret = devm_pm_runtime_enable(&pdev->dev); + if (ret) + return ret; + + priv->wdev.min_timeout = 1; + priv->wdev.timeout = WDT_DEFAULT_TIMEOUT; + priv->wdev.info = &rzv2h_wdt_ident; + priv->wdev.ops = &rzv2h_wdt_ops; + priv->wdev.parent = dev; + watchdog_set_drvdata(&priv->wdev, priv); + watchdog_set_nowayout(&priv->wdev, nowayout); + watchdog_stop_on_unregister(&priv->wdev); + + ret = watchdog_init_timeout(&priv->wdev, 0, dev); + if (ret) + dev_warn(dev, "Specified timeout invalid, using default"); + + return devm_watchdog_register_device(&pdev->dev, &priv->wdev); +} + +static const struct of_device_id rzv2h_wdt_ids[] = { + { .compatible = "renesas,r9a09g057-wdt", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, rzv2h_wdt_ids); + +static struct platform_driver rzv2h_wdt_driver = { + .driver = { + .name = "rzv2h_wdt", + .of_match_table = rzv2h_wdt_ids, + }, + .probe = rzv2h_wdt_probe, +}; +module_platform_driver(rzv2h_wdt_driver); +MODULE_AUTHOR("Lad Prabhakar "); +MODULE_DESCRIPTION("Renesas RZ/V2H(P) WDT Watchdog Driver");