From patchwork Wed Jun 19 12:09:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13703757 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 8DE1113E3F2 for ; Wed, 19 Jun 2024 12:09:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798988; cv=none; b=sYix5JN10RBaY/9eYXzPsPxcU4jLB/voWsJusvGOAe1J5atY9ISSgK7f9Lvv+7XqQXbNCCr+BO8byXGED6w7OzQ8LaxCUQmHAkCBhObsnX24/s1JslMPH0MhPmhFbpjotWHrpcTlicB/CneQL4kO9H3z2kE8zetzRvIdT2x6dcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798988; c=relaxed/simple; bh=KLqszOBKq4UmcEK8dgplUQIW8Sbc/rgdmN5Zvo5C8vo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jMrqh4A5Mlob2WuRasSbm70l4hMcsy6KmgC5NvEIzX04292qiRnvAs2MImbqw08fICAeseeXTmgf63hFlrUUyeK/Gac4AwMjcl3fqB1AXMG4Mg1+FBSjpQfvvm4FkUVfiyHb5QV1eP2sOEhAAkh4d/ld6H6ittCntZhlcEZ5xRg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=HH/SuoGS; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="HH/SuoGS" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a62ef52e837so838919066b.3 for ; Wed, 19 Jun 2024 05:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1718798985; x=1719403785; 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=repF/9O8y233ry+RsrFhVhQxIwnZs5AMfgnT6lVaZq8=; b=HH/SuoGSfXZMTan3gmpSo/HF4q2FSJ0kzlVBGGaDVb5ofp+graaFrmv39ac42krIsz Myeqwg+nRL0fWvszjQ5/TXf8KCDnyGpQOvsS05I0sjvztM94fs4EjoFX6JBpQ459jCuO RjxP/SmKXglQhuFZPl9W/Nhpf5ABJ88SKO4K3XncNSRogXlY9FZ56/JxUsGHgt9kf3d8 7X0Q1cic8Re2xgSr04WI4cNvMo5Kk8N9KHVNL2RSOOspvzL1lMp+l1OTO0WXmMYR/zUI x14jlnGEfKNSjWVN3FWUltFgF1RyPTJgtPghQjvyybmRFWJhtL+3XJhKV3Y94ZMjtyme WLsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718798985; x=1719403785; 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=repF/9O8y233ry+RsrFhVhQxIwnZs5AMfgnT6lVaZq8=; b=va8fpzrfI1sYCtzL/3l6bx4sbymexq1Hsqtn19SsqdvMibGVbdXBuqhiTzv7ophd/j t5aEP8DIf0fOE9TOgLepyfJsW4WLGzGAZXKJqNyIDEk/tASx+DemZNh44PnMxLnWn/Um Bqd/lkpAYTIsChPExhW6iQzM9jfjjYPDVX+dblabkmChup/PKw4mNSI9uiKW27YIP04g K/qRe6PXmlxwUVJ+QPf9vtPQqFtfmhJ7nrL6bjva0GqJmRk5UadunF4ZFyZaeVhIi3Yb DCtC8Oar8lfTCYhkq+Jak0M7EbWJcxOO5dJRjvXtzTaXPWc3xx3sHg9/YJqYJ2KE4p5g Afew== X-Forwarded-Encrypted: i=1; AJvYcCXYbjfjxGJJy5cU7lRNWeyI3jqVTl1uMrQCLBH69pBsgSODjCZpulvODKSkrXIURQBcoQNiYXj4E+YaHkJ/iiTyKoWWqKOAKQXK2GpNyjy/DMw= X-Gm-Message-State: AOJu0YyIeBSANkYc2W97yqs36b2/s3bsNiFq+XVPPmH/YnmPsfONuvEq 6v/YF7QnIL3G/HRwMFwQskf/6Q05us5MvmnyZ30WJhwSRQZAVe/QKUGUeCWOLPQ= X-Google-Smtp-Source: AGHT+IEFsYgFlNsijCDzTIVv0iYZUa1HsZiHTq3BILY+nUISrrrwCJfk4oLG1DUHWcQA7IKgxnV5zw== X-Received: by 2002:a17:907:c78c:b0:a6f:6063:6bab with SMTP id a640c23a62f3a-a6fab607200mr197334766b.16.1718798984925; Wed, 19 Jun 2024 05:09:44 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f56da43fbsm659014066b.39.2024.06.19.05.09.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 05:09:44 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: ulf.hansson@linaro.org, wim@linux-watchdog.org, linux@roeck-us.net, rafael@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org, claudiu.beznea@tuxon.dev, geert+renesas@glider.be, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH RFC 1/3] pmdomain: core: Add a helper to power on the restart devices Date: Wed, 19 Jun 2024 15:09:18 +0300 Message-Id: <20240619120920.2703605-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240619120920.2703605-1-claudiu.beznea.uj@bp.renesas.com> References: <20240619120920.2703605-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Claudiu Beznea Restart devices (e.g., watchdog) may be part of a software-controlled power domain. In the case of watchdog devices, if they implement the struct watchdog::restart() API, this is called though: kernel_restart() -> machine_restart() -> do_kernel_restart() -> atomic_notifier_call_chain() -> watchdog_restart_notifier() The watchdog_restart_notifier() is called with local interrupts disabled and SMP disabled (machine_restart() calls local_irq_disable() and smp_send_stop() before calling do_kernel_restart()). If the restart device (e.g., watchdog) is part of a software-controlled power domain and this domain is off at the moment of restart, we need to power it on before configuring the watchdog device. Add the dev_pm_genpd_resume_restart_dev() function to power on a restart device in these scenarios. Signed-off-by: Claudiu Beznea --- drivers/pmdomain/core.c | 18 ++++++++++++++++++ include/linux/pm_domain.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c index 83d978743659..d05bd72f6cfe 100644 --- a/drivers/pmdomain/core.c +++ b/drivers/pmdomain/core.c @@ -1540,6 +1540,24 @@ void dev_pm_genpd_resume(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_genpd_resume); +/** + * dev_pm_genpd_resume_restart_dev - Try to synchronously resume the genpd for + * a reset device + * @dev: The reset device that is attached to the genpd, which needs to be + * resumed. + * + * This routine should tipicaly be called for a restart device (e.g. watchdog) + * that needs to be resumed during system restart phase. + */ +void dev_pm_genpd_resume_restart_dev(struct device *dev) +{ + if (system_state != SYSTEM_RESTART) + return; + + dev_pm_genpd_resume(dev); +} +EXPORT_SYMBOL_GPL(dev_pm_genpd_resume_restart_dev); + #else /* !CONFIG_PM_SLEEP */ #define genpd_prepare NULL diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 71e4f0fb8867..9f8ecfa0bf3c 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -347,9 +347,11 @@ static inline void dev_pm_genpd_synced_poweroff(struct device *dev) #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP void dev_pm_genpd_suspend(struct device *dev); void dev_pm_genpd_resume(struct device *dev); +void dev_pm_genpd_resume_restart_dev(struct device *dev); #else static inline void dev_pm_genpd_suspend(struct device *dev) {} static inline void dev_pm_genpd_resume(struct device *dev) {} +static inline void dev_pm_genpd_resume_restart_dev(struct device *dev) {} #endif /* OF PM domain providers */ From patchwork Wed Jun 19 12:09:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13703758 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 3035A13F42B for ; Wed, 19 Jun 2024 12:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798989; cv=none; b=h5ir6I1j8KUrk/Esi/Feqaz9VQ/iz/wTy7BPYmIwqBIQID+5m6XDH0HKkt95Hoh/k7JySGEJWoMlUoHo7TxNYZZGx1Zb4ATmh575dZEk/PAc/Gv/D1yaivEQPD5IIHo0KU5gFwI7hJZvlDsd7VlnAVV1eEDX6ewxJXRLk/r4Lvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798989; c=relaxed/simple; bh=dwRL4BzskUTNnkpIMgL22DLU9dpDbS12/wL0pywWeXI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DFLsY0Xg1+u3w+JkFu7p/wgI25xxzVyD9xijb9ZR0Cijh0wozkHhdhUIABtDN10i6LPzsuEeJAydQexI9WB67XNyNrScG0h0ltzzGy1UNoYx954FXus5/NYYnDkCEqLJ2EI0OdUnFKFEtKiMhixs5I0NfEVNLPLXGeU0nlXY+XQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=b96uwaDA; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="b96uwaDA" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a6269885572so123440066b.1 for ; Wed, 19 Jun 2024 05:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1718798986; x=1719403786; 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=l37Xgsbrk/W/CaUfhlMyXOo5T2v0G6wEI2diCQGNTyY=; b=b96uwaDA9a1Qc/tVcKSVREL724fYS7Cp6PUW5QB2776XazuQc+Ys6jqLoKhyS0gnzh FTWLnI7lP8E/CQvHWEzoT+/9Ognl0zEbQJyC1jTIWzYaP8kwOouKul2HzgzHpjAYZjRF pa5MeY+LpgRkQx/MFju2DAq3sM+ezmoPp85AO8iHdv6OgTuHItjrcyDbIf4cOtmAQc6R AOuWWSbiGNYjTdQvtafG6WRzPFnt58TYfwVPN4dpAWoFe6TiY2ZiKFkcVycCUAp2lbPQ M3cepOB5wJmq5jffD2RlxqM3sDZ6PxfFvdy9KlEqjVSAdwM866gJ/cZHnoaPBBkDDHig aNmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718798986; x=1719403786; 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=l37Xgsbrk/W/CaUfhlMyXOo5T2v0G6wEI2diCQGNTyY=; b=gnEJFXfFmHMKXWHjm6+Ns4AJ7SWXXD7tJYCHeppowsmVmYoKSJlrQjzRJJby+gg716 hXKTyl98CX3G3jrExT+jQ5+hsFgfrM+tPkXHthb1Ageb/WdRcxnzYN5sbHk9P1+B9V7d 2rn+9SXmo2dg+j1JfGY9uEHD87hO2/XNrVZ6Hu+ZevCiU+czlCaqiAU+59QxA+V3Q9MH 2yLDKZvu0ifgoxgFbv03YhxLjyY88Z5Ab2WCph6Us/xKZhfzrpOdoOjbKeP/CawtuZri dMzKboiMhpviPXbHojc9AGu0yeovIkvRjpl/TgTGU/GN6DrVIwQihlawwX25vMY5LiPU 296g== X-Forwarded-Encrypted: i=1; AJvYcCW2C6utPfARQrpzNpETseQmiqhCXqzyu3KbthM46OgBjVSztW2zVQqgO3/WvfMHaR0QKxYG30aVjGtpIrppgd/QImetx6b6F6+ajFGU1+QLVNo= X-Gm-Message-State: AOJu0YyZ5cy4OvjPLHuAM798gh5AzntS+mQKWyDYllEKY9bPjvKObsVa D1e5exPEI6rGtm00tbwC2Bks2NFSp0taGB2UM8FQhsCrCt/PSd/6kKATlhhugzI= X-Google-Smtp-Source: AGHT+IE7mmdZtzwF3jv3n7R6o+Q3QczWuCZ6SkHDb6bjWUSTkUbSSYTk1wTyLPZI29mLO3zORsFkUw== X-Received: by 2002:a17:906:80cb:b0:a6f:6f98:e3dc with SMTP id a640c23a62f3a-a6f94e1f5c9mr321104066b.10.1718798986592; Wed, 19 Jun 2024 05:09:46 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f56da43fbsm659014066b.39.2024.06.19.05.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 05:09:46 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: ulf.hansson@linaro.org, wim@linux-watchdog.org, linux@roeck-us.net, rafael@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org, claudiu.beznea@tuxon.dev, geert+renesas@glider.be, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH RFC 2/3] watchdog: rzg2l_wdt: Keep the clocks prepared Date: Wed, 19 Jun 2024 15:09:19 +0300 Message-Id: <20240619120920.2703605-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240619120920.2703605-1-claudiu.beznea.uj@bp.renesas.com> References: <20240619120920.2703605-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Claudiu Beznea The watchdog restart handler is called with interrupts disabled. In rzg2l_wdt_restart() we call clk_prepare_enable() to enable the watchdog clocks. The prepare part of clk_prepare_enable() may sleep. Sleep in atomic context should not happen. The clock drivers for all the micro-architectures where the RZ/G2L watchdog driver is used are not implementing struct clk_ops::prepare(). Even so, to be sure we are not hitted by this at some point, keep the watchdog clocks prepared and only enable them in restart handler. It is guaranteed that clk_enable() can be called in atomic context. Reported-by: Ulf Hansson Closes: https://lore.kernel.org/all/CAPDyKFq1+cL1M9qGY0P58ETHUZHGymxQL0w92emUJPMe7a_GxA@mail.gmail.com Signed-off-by: Claudiu Beznea --- drivers/watchdog/rzg2l_wdt.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/drivers/watchdog/rzg2l_wdt.c b/drivers/watchdog/rzg2l_wdt.c index 2a35f890a288..6e3d7512f38c 100644 --- a/drivers/watchdog/rzg2l_wdt.c +++ b/drivers/watchdog/rzg2l_wdt.c @@ -166,8 +166,8 @@ static int rzg2l_wdt_restart(struct watchdog_device *wdev, struct rzg2l_wdt_priv *priv = watchdog_get_drvdata(wdev); int ret; - clk_prepare_enable(priv->pclk); - clk_prepare_enable(priv->osc_clk); + clk_enable(priv->pclk); + clk_enable(priv->osc_clk); if (priv->devtype == WDT_RZG2L) { ret = reset_control_deassert(priv->rstc); @@ -226,11 +226,28 @@ static const struct watchdog_ops rzg2l_wdt_ops = { .restart = rzg2l_wdt_restart, }; +static int rzg2l_clks_prepare(struct rzg2l_wdt_priv *priv) +{ + int ret; + + ret = clk_prepare(priv->pclk); + if (ret) + return ret; + + ret = clk_prepare(priv->osc_clk); + if (ret) + clk_unprepare(priv->pclk); + + return ret; +} + static void rzg2l_wdt_pm_disable(void *data) { - struct watchdog_device *wdev = data; + struct rzg2l_wdt_priv *priv = data; - pm_runtime_disable(wdev->parent); + pm_runtime_disable(priv->wdev.parent); + clk_unprepare(priv->osc_clk); + clk_unprepare(priv->pclk); } static int rzg2l_wdt_probe(struct platform_device *pdev) @@ -275,6 +292,10 @@ static int rzg2l_wdt_probe(struct platform_device *pdev) priv->devtype = (uintptr_t)of_device_get_match_data(dev); + ret = rzg2l_clks_prepare(priv); + if (ret) + return ret; + pm_runtime_enable(&pdev->dev); priv->wdev.info = &rzg2l_wdt_ident; @@ -287,7 +308,7 @@ static int rzg2l_wdt_probe(struct platform_device *pdev) watchdog_set_drvdata(&priv->wdev, priv); dev_set_drvdata(dev, priv); - ret = devm_add_action_or_reset(&pdev->dev, rzg2l_wdt_pm_disable, &priv->wdev); + ret = devm_add_action_or_reset(&pdev->dev, rzg2l_wdt_pm_disable, &priv); if (ret) return ret; From patchwork Wed Jun 19 12:09:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 13703759 X-Patchwork-Delegate: geert@linux-m68k.org Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.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 02B7B13F42B for ; Wed, 19 Jun 2024 12:09:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798991; cv=none; b=tc72yuUPRSJjKybNxAJrbQB9vk5IDyh1h9rhVTDgB25JIEirIw6TtmOjJCFsAZoxMYMUYINmoKXnTMVF+bUmfnB0ndD+wZxW+1PXGptpZuS+TSTyUpAsxgmpDhRZub2IeTOiZHCwoW766MrO160xBMPWF/8N5bfeLLuI1EeFlUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798991; c=relaxed/simple; bh=AWXmdY3rXYMSjyADn2ws2KVH0wuevnkDpCzm8/QmWWI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Qy2WV17QwNR1JaK1n/XGpH71I3kRQ5yrawqKv5ntyRTeQGuwTFFk6M9ee9BBuFkQ4DBaS/o8/EL13WXFWZLEQqd4IRBlqkNwDFUw1YbYo+I/ovv0Yy4wQxBLyUHpg4DThPPp5WRPJQOQlHiy6rj5B1YjVTlYWx0mu7++P/Ggvww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=UBEEQmtD; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="UBEEQmtD" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a6f8ebbd268so139083866b.0 for ; Wed, 19 Jun 2024 05:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1718798988; x=1719403788; 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=54/0ynllrtFkceQQjV8JTld4EwzpadxoNpmSQm229aE=; b=UBEEQmtDJEz3H4kkEHWMgnYqOJy1Y0hwFKSkHHuGnszABnC2KXCl2yKRBtYNgakOx8 IRCEV0ROopn28PL3LMEn9kST+OTL8SY3rV1PoYPMPIWycOR35AOFgwMyJr3+WmlwPUtp doHR5W+6Ept3wPCFYDwdUNEFMwQQYNs+Os/t0ZRq/Bqp2zRnlE0ovlEjsYVCur3jZrBE eILtbrX97ZNHByVoCU+VOPU6g6tDYqqWvbtH0OH0sGFqVwP8LECl/Tkw2QehKviLxAPn AkC1SgCeBz0/aOSe8HO8n/SwpSOBcPeft2puJb/FJowjGux4fp//PbGgU8QyoNvQmmCD j8gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718798988; x=1719403788; 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=54/0ynllrtFkceQQjV8JTld4EwzpadxoNpmSQm229aE=; b=AGjl6+Y2bHIsazBVnzWzZnscZz7NneUaTINPxoGXaavMqqOB0iAe5XNqbLLLoQIpuq 3g+lnUFKr+63q3/iVkYZ4ssS0TTEZQGuT2q1r+86LvChTPpNEZb4/LGSlj0ahGR6tsnR gS4XJNT9desBIGr/qUPQFMQvPAEW0YT1QBVlHCJtfG+1speUEDYCYujnuMeYuGWv/NDD mDOkSXZx3iw2ztJdfP3JYaIM57EwGurQ8gnyVYH2Zgd42Vwu+cxxFxPG1L3EVtSGTRYh xoNOHJmBl+FPAZ6KwGh3A9AVD4KknUvLw1BtwywZIkjTGtZzWFRPJ3SnQKwQUJPYhC75 eu1g== X-Forwarded-Encrypted: i=1; AJvYcCUh80fln6EzpJLS1HuMX64Bh+1VBg3kJ3D8iPu9cko1fbDJpaFt4Y4sP8H/7u7nopQGtJiAlHlEeEUdghUN1EJV1UPJ3EFfLGQTQwaf2HrJhG8= X-Gm-Message-State: AOJu0YzmLUkNMzoQ7AEjlFGFedfQE5HlgyRVATxeOY0eLggnsuJZPye6 TTn7FJp0mKdGvc3JObTIMeM9K3D2OPFBWD/9yTnAvB9sgKTwY2o9DgqaJCCQjDc= X-Google-Smtp-Source: AGHT+IHJOKe6kBXUNHgR9qDl5dDG/jclLXow93dX2013HdXfIPrJid9GCPxLPrnwMA4R1Tfsu5wZ4Q== X-Received: by 2002:a17:906:bf45:b0:a6f:77bb:1703 with SMTP id a640c23a62f3a-a6fa4109c43mr154657966b.13.1718798988338; Wed, 19 Jun 2024 05:09:48 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.70]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6f56da43fbsm659014066b.39.2024.06.19.05.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jun 2024 05:09:47 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: ulf.hansson@linaro.org, wim@linux-watchdog.org, linux@roeck-us.net, rafael@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org, claudiu.beznea@tuxon.dev, geert+renesas@glider.be, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH RFC 3/3] watchdog: rzg2l_wdt: Power on the PM domain in rzg2l_wdt_restart() Date: Wed, 19 Jun 2024 15:09:20 +0300 Message-Id: <20240619120920.2703605-4-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240619120920.2703605-1-claudiu.beznea.uj@bp.renesas.com> References: <20240619120920.2703605-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Claudiu Beznea The rzg2l_wdt_restart() is called in atomic context. Calling pm_runtime_{get_sync, resume_and_get}() or any other runtime PM resume APIs is not an option as it may lead to issues as described in commit e4cf89596c1f ("watchdog: rzg2l_wdt: Fix 'BUG: Invalid wait context'") that removed the pm_runtime_get_sync() and enabled directly the clocks. Starting with RZ/G3S the watchdog could be part of its own software-controlled power domain. In case the watchdog is not used the power domain is off and accessing watchdog registers leads to aborts. To solve this, the patch powers on the power domain using dev_pm_genpd_resume_restart_dev() API after enabling its clock. This is not sleeping or taking any other locks as the watchdog power domain is not registered with GENPD_FLAG_IRQ_SAFE flags. Signed-off-by: Claudiu Beznea --- drivers/watchdog/rzg2l_wdt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/watchdog/rzg2l_wdt.c b/drivers/watchdog/rzg2l_wdt.c index 6e3d7512f38c..bbdbbaa7b82b 100644 --- a/drivers/watchdog/rzg2l_wdt.c +++ b/drivers/watchdog/rzg2l_wdt.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -169,6 +170,17 @@ static int rzg2l_wdt_restart(struct watchdog_device *wdev, clk_enable(priv->pclk); clk_enable(priv->osc_clk); + /* + * The device may be part of a power domain that is currently + * powered off. We need to power it on before accessing registers. + * We don't undo the dev_pm_genpd_resume_restart_dev() as the device + * need to be on for the reboot to happen. Also, as we are in atomic + * context here, there is no need to increment PM runtime usage counter + * (to make sure pm_runtime_active() doesn't return wrong code). + */ + if (!pm_runtime_active(wdev->parent)) + dev_pm_genpd_resume_restart_dev(wdev->parent); + if (priv->devtype == WDT_RZG2L) { ret = reset_control_deassert(priv->rstc); if (ret)