From nobody Tue Feb 10 22:17:41 2026 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 4597A33120D for ; Mon, 26 Jan 2026 10:32:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769423535; cv=none; b=sXaZrbJHPTdnSAgs7tXffyIc0Ak5Qp1dfH6RAeYHmd89FPeRKpmyFcgWJwwWOqsdfCIJe/cFD65fl52jyjQ6oE+zxZNg+4vG+h585XH94kLleSxWbeVcsSEol+pGr68L1a27fVlOF1xiQE9TwIrsp1EdyaPOCOFucJfM6eqo5MU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769423535; c=relaxed/simple; bh=mZe19bFK/S4/K+saPikdJBeJIpbKrPgWGTChE+D5OPc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bGEU1i8z5z+qaafwLz8wUMP8nSzOorPiJq+KlJdowGpl3UqcKEhyA+8YnGxLCFH6rWYosEIV5VFCVwFUJS3xLwejj98R0+BtY0XuCfxpDXmCCuBkDJ170MmKnuZ/PlZ9VyvkPSfRsB6UfeeDlGmaCE8ugm8xok0RYXsOrTtX3m8= 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=MjQRkvpG; arc=none smtp.client-ip=209.85.128.46 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="MjQRkvpG" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4801c1ad878so48034975e9.1 for ; Mon, 26 Jan 2026 02:32:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1769423531; x=1770028331; 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=77QZXmKdSVMSMO6XhwWHW9cRB7VDPOEmlJRMnWPda5M=; b=MjQRkvpGUheDT9YszmXnNK5TstIhbsMPaCX3WkJhTvkosKI9gdLXrmfia8TrjcfWHp mXIx2r2c7pfZQq2K3rE88WuDLglWzUJYl4b8S0edSADrD4OBHb5CnrlzVrcGHD5NVxcn c3ls7BDKXB4zvQALJgbxGlAOsFnRTuwYTsR4mEfW1CgP/LoWfWu8Z+iAUYjT+76D6Clz CZ8GQ1iTXfqdVjBCdb/0rcNCjhSq3EuslFsJLbIWKtB1JzL/pRdJRKOINhfHX0E69hEO YWtXcGS7zEsuJwhmgw/3jfDr1EcNo6StTOk9DwT6NN2mhJsADtoxqRj07pRBIMt2Xsq5 6nLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769423531; x=1770028331; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=77QZXmKdSVMSMO6XhwWHW9cRB7VDPOEmlJRMnWPda5M=; b=Gm5/4zgUODdQDlr/RuSK7jtErw78SPC/TQAr5ttTIC3iHGcEgMnuHvEUWStjhc5NCS HqMhiwn2iGE8LudaH9Rgcz+Rx9WSvjAITgoLzzpp5u2zTcEHH5Wu+zAgHcsOz4El2wXe buB/qdlRAa9/WYopCJHAQ86HWrifx8C88qw+jbmazosBIuBZsQy/4MEy5PyfJiuLWaY+ SQ76jlkXKB4Rdi1RQkHNOoWuBY8hp7fnaOSfR6BYu5tMjdbo4NI60LMfc29RfOdA3xYi XhJrW+UZSI7xkqVXVcN2glqkTr1KtXxbDn0g3VkX7lnm00QtYv4RoB2hvBgopTgth/Hh UNLQ== X-Forwarded-Encrypted: i=1; AJvYcCU2EuEbsjThewK4gfMYOq/THsRBEFZwkNGy3DIVn5YNHa+jtkgTlOl5mTIR30sSGjVgFY0oUcKyCLWedQ8=@vger.kernel.org X-Gm-Message-State: AOJu0YxHLp/sQjQgwXMxZdG9wT/Oc4+q5D1tSb57slI1Xex+UKAHj0cX 14sGTymrRPEvsZz1jwkjtd1/nrRoV+cSK10Xw1enBfRd4mJ/7d6oVoBSjsg9kAmktsU= X-Gm-Gg: AZuq6aJPbZxkmLVUtFFUM8KfGTzjwxPdjSJnh9tjcSC3nStUkKk6bJ01zWK9qeT7d6W jK5l4Mp3VSJZWPtNlL35zSwpPi9CV8+8hWGF/ShfGDlWW9dWv1+f1Mh8zHfXVjgs8HjfEa4KF18 /pPRZWXs0N/6L01BglnZ49SiPYZ7WxwD2F/+6d3mvYYVi3D9wHlLmgRrUPXUtLoy+YptS6p1A4E q56HS6SdPWFIIP3yzi7pAx7NdsRoQZX0QH77UTegE0IDlMJMgYmAd1f6JQQ1DhkFQc1SHNf4PdA Rjo2VoaHJi0GH2hK4DUtYWeC/WODtw4qxLiHLplD0wOEMogbkuCirr2wJ1ko2pun8aBelRvhi2q ta/PAngb/lCs306wybFOZgDZSGau2vpMb1TCE2bbKzPCuI0OYpRHyPmVCyAVQt+WY9z4qtAa6Q6 PO58PevpB+QhdtYLFDS4yjXey+V/n4+qO8A/+VOX0= X-Received: by 2002:a05:600c:4f8a:b0:477:76bf:e1fb with SMTP id 5b1f17b1804b1-4805ce4e7e2mr71803555e9.16.1769423530663; Mon, 26 Jan 2026 02:32:10 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.31]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435b1c246ecsm29715049f8f.10.2026.01.26.02.32.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jan 2026 02:32:09 -0800 (PST) From: Claudiu X-Google-Original-From: Claudiu To: vkoul@kernel.org, biju.das.jz@bp.renesas.com, prabhakar.mahadev-lad.rj@bp.renesas.com, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, p.zabel@pengutronix.de, geert+renesas@glider.be, fabrizio.castro.jz@renesas.com Cc: claudiu.beznea@tuxon.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Claudiu Beznea Subject: [PATCH 5/7] dmaengine: sh: rz-dmac: Add suspend to RAM support Date: Mon, 26 Jan 2026 12:31:53 +0200 Message-ID: <20260126103155.2644586-6-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260126103155.2644586-1-claudiu.beznea.uj@bp.renesas.com> References: <20260126103155.2644586-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The Renesas RZ/G3S SoC supports a power saving mode in which power to most SoC components is turned off, including the DMA IP. Add suspend to RAM support to save and restore the DMA IP registers. Cyclic DMA channels require special handling. Since they can be paused and resumed during system suspend and resume, the driver restores additional registers for these channels during the resume phase. If a channel was not explicitly paused during suspend, the driver ensures that it is paused and resumed as part of the system suspend/resume flow. This might be the case of a serial device being used with no_console_suspend. For non-cyclic channels, the dev_pm_ops::prepare callback waits for all ongoing transfers to complete before allowing suspend-to-RAM to proceed. Signed-off-by: Claudiu Beznea --- drivers/dma/sh/rz-dmac.c | 183 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 175 insertions(+), 8 deletions(-) diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c index ab5f49a0b9f2..8f3e2719e639 100644 --- a/drivers/dma/sh/rz-dmac.c +++ b/drivers/dma/sh/rz-dmac.c @@ -69,11 +69,15 @@ struct rz_dmac_desc { * enum rz_dmac_chan_status: RZ DMAC channel status * @RZ_DMAC_CHAN_STATUS_ENABLED: Channel is enabled * @RZ_DMAC_CHAN_STATUS_PAUSED: Channel is paused though DMA engine callba= cks + * @RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL: Channel is paused through driver = internal logic + * @RZ_DMAC_CHAN_STATUS_SYS_SUSPENDED: Channel was prepared for system sus= pend * @RZ_DMAC_CHAN_STATUS_CYCLIC: Channel is cyclic */ enum rz_dmac_chan_status { RZ_DMAC_CHAN_STATUS_ENABLED, RZ_DMAC_CHAN_STATUS_PAUSED, + RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL, + RZ_DMAC_CHAN_STATUS_SYS_SUSPENDED, RZ_DMAC_CHAN_STATUS_CYCLIC, }; =20 @@ -94,6 +98,10 @@ struct rz_dmac_chan { u32 chctrl; int mid_rid; =20 + struct { + u32 nxla; + } pm_state; + struct list_head ld_free; struct list_head ld_queue; struct list_head ld_active; @@ -1002,10 +1010,17 @@ static int rz_dmac_device_pause(struct dma_chan *ch= an) return rz_dmac_device_pause_set(channel, RZ_DMAC_CHAN_STATUS_PAUSED); } =20 +static int rz_dmac_device_pause_internal(struct rz_dmac_chan *channel) +{ + lockdep_assert_held(&channel->vc.lock); + + return rz_dmac_device_pause_set(channel, RZ_DMAC_CHAN_STATUS_PAUSED_INTER= NAL); +} + static int rz_dmac_device_resume_set(struct rz_dmac_chan *channel, enum rz_dmac_chan_status status) { - u32 val; + u32 val, chctrl; int ret; =20 lockdep_assert_held(&channel->vc.lock); @@ -1013,14 +1028,33 @@ static int rz_dmac_device_resume_set(struct rz_dmac= _chan *channel, if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED))) return 0; =20 - rz_dmac_ch_writel(channel, CHCTRL_CLRSUS, CHCTRL, 1); - ret =3D read_poll_timeout_atomic(rz_dmac_ch_readl, val, - !(val & CHSTAT_SUS), 1, 1024, false, - channel, CHSTAT, 1); - if (ret) - return ret; + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_SYS_SUSPENDED)) { + /* + * We can be after a sleep state with power loss. If power was + * lost, the CHSTAT_SUS bit is zero. In this case, we need to + * enable the channel directly. Otherwise, just set the CLRSUS + * bit. + */ + val =3D rz_dmac_ch_readl(channel, CHSTAT, 1); + if (val & CHSTAT_SUS) + chctrl =3D CHCTRL_CLRSUS; + else + chctrl =3D CHCTRL_SETEN; + } else { + chctrl =3D CHCTRL_CLRSUS; + } + + rz_dmac_ch_writel(channel, chctrl, CHCTRL, 1); =20 - channel->status &=3D ~BIT(status); + if (chctrl & CHCTRL_CLRSUS) { + ret =3D read_poll_timeout_atomic(rz_dmac_ch_readl, val, + !(val & CHSTAT_SUS), 1, 1024, false, + channel, CHSTAT, 1); + if (ret) + return ret; + } + + channel->status &=3D ~(BIT(status) | BIT(RZ_DMAC_CHAN_STATUS_SYS_SUSPENDE= D)); =20 return 0; } @@ -1034,6 +1068,13 @@ static int rz_dmac_device_resume(struct dma_chan *ch= an) return rz_dmac_device_resume_set(channel, RZ_DMAC_CHAN_STATUS_PAUSED); } =20 +static int rz_dmac_device_resume_internal(struct rz_dmac_chan *channel) +{ + lockdep_assert_held(&channel->vc.lock); + + return rz_dmac_device_resume_set(channel, RZ_DMAC_CHAN_STATUS_PAUSED_INTE= RNAL); +} + /* * -----------------------------------------------------------------------= ------ * IRQ handling @@ -1438,6 +1479,131 @@ static void rz_dmac_remove(struct platform_device *= pdev) pm_runtime_disable(&pdev->dev); } =20 +static int rz_dmac_suspend_prepare(struct device *dev) +{ + struct rz_dmac *dmac =3D dev_get_drvdata(dev); + + for (unsigned int i =3D 0; i < dmac->n_channels; i++) { + struct rz_dmac_chan *channel =3D &dmac->channels[i]; + + guard(spinlock_irqsave)(&channel->vc.lock); + + /* Wait for transfer completion, except in cyclic case. */ + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_ENABLED) && + !(channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))) + return -EAGAIN; + } + + return 0; +} + +static void rz_dmac_suspend_recover(struct rz_dmac *dmac) +{ + for (unsigned int i =3D 0; i < dmac->n_channels; i++) { + struct rz_dmac_chan *channel =3D &dmac->channels[i]; + + guard(spinlock_irqsave)(&channel->vc.lock); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))) + continue; + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL))) + continue; + + rz_dmac_device_resume_internal(channel); + } +} + +static int rz_dmac_suspend(struct device *dev) +{ + struct rz_dmac *dmac =3D dev_get_drvdata(dev); + int ret; + + for (unsigned int i =3D 0; i < dmac->n_channels; i++) { + struct rz_dmac_chan *channel =3D &dmac->channels[i]; + + guard(spinlock_irqsave)(&channel->vc.lock); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))) + continue; + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED))) { + ret =3D rz_dmac_device_pause_internal(channel); + if (ret) { + dev_err(dev, "Failed to suspend channel %s\n", + dma_chan_name(&channel->vc.chan)); + continue; + } + } + + channel->pm_state.nxla =3D rz_dmac_ch_readl(channel, NXLA, 1); + channel->status |=3D BIT(RZ_DMAC_CHAN_STATUS_SYS_SUSPENDED); + } + + pm_runtime_put_sync(dmac->dev); + + ret =3D reset_control_assert(dmac->rstc); + if (ret) { + pm_runtime_resume_and_get(dmac->dev); + rz_dmac_suspend_recover(dmac); + } + + return ret; +} + +static int rz_dmac_resume(struct device *dev) +{ + struct rz_dmac *dmac =3D dev_get_drvdata(dev); + int ret; + + ret =3D reset_control_deassert(dmac->rstc); + if (ret) + return ret; + + ret =3D pm_runtime_resume_and_get(dmac->dev); + if (ret) { + reset_control_assert(dmac->rstc); + return ret; + } + + rz_dmac_writel(dmac, DCTRL_DEFAULT, CHANNEL_0_7_COMMON_BASE + DCTRL); + rz_dmac_writel(dmac, DCTRL_DEFAULT, CHANNEL_8_15_COMMON_BASE + DCTRL); + + for (unsigned int i =3D 0; i < dmac->n_channels; i++) { + struct rz_dmac_chan *channel =3D &dmac->channels[i]; + + guard(spinlock_irqsave)(&channel->vc.lock); + + rz_dmac_set_dma_req_no(dmac, channel->index, channel->mid_rid); + + if (!(channel->status & BIT(RZ_DMAC_CHAN_STATUS_CYCLIC))) { + rz_dmac_ch_writel(&dmac->channels[i], CHCTRL_DEFAULT, CHCTRL, 1); + continue; + } + + rz_dmac_ch_writel(channel, channel->pm_state.nxla, NXLA, 1); + rz_dmac_ch_writel(channel, channel->chcfg, CHCFG, 1); + rz_dmac_ch_writel(channel, CHCTRL_SWRST, CHCTRL, 1); + rz_dmac_ch_writel(channel, channel->chctrl, CHCTRL, 1); + + if (channel->status & BIT(RZ_DMAC_CHAN_STATUS_PAUSED_INTERNAL)) { + ret =3D rz_dmac_device_resume_internal(channel); + if (ret) { + dev_err(dev, "Failed to resume channel %s\n", + dma_chan_name(&channel->vc.chan)); + continue; + } + } + } + + return 0; +} + +static const struct dev_pm_ops rz_dmac_pm_ops =3D { + .prepare =3D rz_dmac_suspend_prepare, + SYSTEM_SLEEP_PM_OPS(rz_dmac_suspend, rz_dmac_resume) +}; + static const struct rz_dmac_info rz_dmac_v2h_info =3D { .icu_register_dma_req =3D rzv2h_icu_register_dma_req, .default_dma_req_no =3D RZV2H_ICU_DMAC_REQ_NO_DEFAULT, @@ -1464,6 +1630,7 @@ static struct platform_driver rz_dmac_driver =3D { .driver =3D { .name =3D "rz-dmac", .of_match_table =3D of_rz_dmac_match, + .pm =3D pm_sleep_ptr(&rz_dmac_pm_ops), }, .probe =3D rz_dmac_probe, .remove =3D rz_dmac_remove, --=20 2.43.0