From nobody Sun Apr 19 20:35:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B44FEC43334 for ; Mon, 27 Jun 2022 15:31:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236836AbiF0Pbg (ORCPT ); Mon, 27 Jun 2022 11:31:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238137AbiF0Pb1 (ORCPT ); Mon, 27 Jun 2022 11:31:27 -0400 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 430F819C36 for ; Mon, 27 Jun 2022 08:31:24 -0700 (PDT) Received: from ramsan.of.borg ([84.195.186.194]) by xavier.telenet-ops.be with bizsmtp id oFXH2700W4C55Sk01FXHal; Mon, 27 Jun 2022 17:31:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5qhp-0014yY-2P; Mon, 27 Jun 2022 17:31:17 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1o5qho-004jEM-El; Mon, 27 Jun 2022 17:31:16 +0200 From: Geert Uytterhoeven To: Vignesh Raghavendra , Sergey Shtylyov , Krzysztof Kozlowski , Wolfram Sang , Lad Prabhakar , Miquel Raynal , Richard Weinberger Cc: Mark Brown , linux-mtd@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 1/7] memory: renesas-rpc-if: Always use dev in rpcif_sw_init() Date: Mon, 27 Jun 2022 17:31:08 +0200 Message-Id: <98924121e59ab3f389ddd413b6d252a8deb889cf.1656341824.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" rpcif_sw_init() already has the "dev" parameter pointing to the right device structure, so there is no need to take a detour through the platform device. Signed-off-by: Geert Uytterhoeven --- drivers/memory/renesas-rpc-if.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-i= f.c index 4316988d791a527f..829b962e8f034bdd 100644 --- a/drivers/memory/renesas-rpc-if.c +++ b/drivers/memory/renesas-rpc-if.c @@ -263,22 +263,21 @@ int rpcif_sw_init(struct rpcif *rpc, struct device *d= ev) if (IS_ERR(rpc->base)) return PTR_ERR(rpc->base); =20 - rpc->regmap =3D devm_regmap_init(&pdev->dev, NULL, rpc, &rpcif_regmap_con= fig); + rpc->regmap =3D devm_regmap_init(dev, NULL, rpc, &rpcif_regmap_config); if (IS_ERR(rpc->regmap)) { - dev_err(&pdev->dev, - "failed to init regmap for rpcif, error %ld\n", + dev_err(dev, "failed to init regmap for rpcif, error %ld\n", PTR_ERR(rpc->regmap)); return PTR_ERR(rpc->regmap); } =20 res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, "dirmap"); - rpc->dirmap =3D devm_ioremap_resource(&pdev->dev, res); + rpc->dirmap =3D devm_ioremap_resource(dev, res); if (IS_ERR(rpc->dirmap)) return PTR_ERR(rpc->dirmap); rpc->size =3D resource_size(res); =20 rpc->type =3D (uintptr_t)of_device_get_match_data(dev); - rpc->rstc =3D devm_reset_control_get_exclusive(&pdev->dev, NULL); + rpc->rstc =3D devm_reset_control_get_exclusive(dev, NULL); =20 return PTR_ERR_OR_ZERO(rpc->rstc); } --=20 2.25.1 From nobody Sun Apr 19 20:35:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAE5DC43334 for ; Mon, 27 Jun 2022 15:31:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238237AbiF0Pbp (ORCPT ); Mon, 27 Jun 2022 11:31:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238185AbiF0Pb2 (ORCPT ); Mon, 27 Jun 2022 11:31:28 -0400 Received: from andre.telenet-ops.be (andre.telenet-ops.be [IPv6:2a02:1800:120:4::f00:15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 203F519C2D for ; Mon, 27 Jun 2022 08:31:24 -0700 (PDT) Received: from ramsan.of.borg ([84.195.186.194]) by andre.telenet-ops.be with bizsmtp id oFXH2700N4C55Sk01FXHYj; Mon, 27 Jun 2022 17:31:21 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5qhp-0014yZ-1Y; Mon, 27 Jun 2022 17:31:17 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1o5qho-004jET-FY; Mon, 27 Jun 2022 17:31:16 +0200 From: Geert Uytterhoeven To: Vignesh Raghavendra , Sergey Shtylyov , Krzysztof Kozlowski , Wolfram Sang , Lad Prabhakar , Miquel Raynal , Richard Weinberger Cc: Mark Brown , linux-mtd@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 2/7] memory: renesas-rpc-if: Add dev helper to rpcif_probe() Date: Mon, 27 Jun 2022 17:31:09 +0200 Message-Id: <31051c05581d0200a45357a6d1ab4ad268a1bbf4.1656341824.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a helper variable pointing to the device structure, to avoid going through the platform device every time. Signed-off-by: Geert Uytterhoeven --- drivers/memory/renesas-rpc-if.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-i= f.c index 829b962e8f034bdd..2421a820e3c5880c 100644 --- a/drivers/memory/renesas-rpc-if.c +++ b/drivers/memory/renesas-rpc-if.c @@ -666,14 +666,15 @@ EXPORT_SYMBOL(rpcif_dirmap_read); =20 static int rpcif_probe(struct platform_device *pdev) { + struct device *dev =3D &pdev->dev; struct platform_device *vdev; struct device_node *flash; const char *name; int ret; =20 - flash =3D of_get_next_child(pdev->dev.of_node, NULL); + flash =3D of_get_next_child(dev->of_node, NULL); if (!flash) { - dev_warn(&pdev->dev, "no flash node found\n"); + dev_warn(dev, "no flash node found\n"); return -ENODEV; } =20 @@ -683,7 +684,7 @@ static int rpcif_probe(struct platform_device *pdev) name =3D "rpc-if-hyperflash"; } else { of_node_put(flash); - dev_warn(&pdev->dev, "unknown flash type\n"); + dev_warn(dev, "unknown flash type\n"); return -ENODEV; } of_node_put(flash); @@ -691,7 +692,7 @@ static int rpcif_probe(struct platform_device *pdev) vdev =3D platform_device_alloc(name, pdev->id); if (!vdev) return -ENOMEM; - vdev->dev.parent =3D &pdev->dev; + vdev->dev.parent =3D dev; platform_set_drvdata(pdev, vdev); =20 ret =3D platform_device_add(vdev); --=20 2.25.1 From nobody Sun Apr 19 20:35:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D8AFCCA486 for ; Mon, 27 Jun 2022 15:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238174AbiF0Pba (ORCPT ); Mon, 27 Jun 2022 11:31:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235959AbiF0Pb1 (ORCPT ); Mon, 27 Jun 2022 11:31:27 -0400 Received: from baptiste.telenet-ops.be (baptiste.telenet-ops.be [IPv6:2a02:1800:120:4::f00:13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 202CD19C2B for ; Mon, 27 Jun 2022 08:31:24 -0700 (PDT) Received: from ramsan.of.borg ([84.195.186.194]) by baptiste.telenet-ops.be with bizsmtp id oFXH2700d4C55Sk01FXHZH; Mon, 27 Jun 2022 17:31:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5qho-0014ya-WF; Mon, 27 Jun 2022 17:31:17 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1o5qho-004jEZ-GC; Mon, 27 Jun 2022 17:31:16 +0200 From: Geert Uytterhoeven To: Vignesh Raghavendra , Sergey Shtylyov , Krzysztof Kozlowski , Wolfram Sang , Lad Prabhakar , Miquel Raynal , Richard Weinberger Cc: Mark Brown , linux-mtd@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 3/7] memory: renesas-rpc-if: Improve Runtime PM handling Date: Mon, 27 Jun 2022 17:31:10 +0200 Message-Id: <88fa4252bb685e9a9eb6e70fe2df32bb6243d405.1656341824.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert from the deprecated pm_runtime_get_sync() to the new pm_runtime_resume_and_get(), and add error checking. Signed-off-by: Geert Uytterhoeven --- drivers/memory/renesas-rpc-if.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-i= f.c index 2421a820e3c5880c..55dbb3854b09ad43 100644 --- a/drivers/memory/renesas-rpc-if.c +++ b/drivers/memory/renesas-rpc-if.c @@ -300,12 +300,13 @@ static void rpcif_rzg2l_timing_adjust_sdr(struct rpci= f *rpc) int rpcif_hw_init(struct rpcif *rpc, bool hyperflash) { u32 dummy; + int ret; =20 - pm_runtime_get_sync(rpc->dev); + ret =3D pm_runtime_resume_and_get(rpc->dev); + if (ret) + return ret; =20 if (rpc->type =3D=3D RPCIF_RZ_G2L) { - int ret; - ret =3D reset_control_reset(rpc->rstc); if (ret) return ret; @@ -469,7 +470,9 @@ int rpcif_manual_xfer(struct rpcif *rpc) u32 smenr, smcr, pos =3D 0, max =3D rpc->bus_size =3D=3D 2 ? 8 : 4; int ret =3D 0; =20 - pm_runtime_get_sync(rpc->dev); + ret =3D pm_runtime_resume_and_get(rpc->dev); + if (ret < 0) + return ret; =20 regmap_update_bits(rpc->regmap, RPCIF_PHYCNT, RPCIF_PHYCNT_CAL, RPCIF_PHYCNT_CAL); @@ -636,11 +639,14 @@ ssize_t rpcif_dirmap_read(struct rpcif *rpc, u64 offs= , size_t len, void *buf) { loff_t from =3D offs & (rpc->size - 1); size_t size =3D rpc->size - from; + int ret; =20 if (len > size) len =3D size; =20 - pm_runtime_get_sync(rpc->dev); + ret =3D pm_runtime_resume_and_get(rpc->dev); + if (ret < 0) + return ret; =20 regmap_update_bits(rpc->regmap, RPCIF_CMNCR, RPCIF_CMNCR_MD, 0); regmap_write(rpc->regmap, RPCIF_DRCR, 0); --=20 2.25.1 From nobody Sun Apr 19 20:35:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDAF1CCA481 for ; Mon, 27 Jun 2022 15:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238278AbiF0Pbn (ORCPT ); Mon, 27 Jun 2022 11:31:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238178AbiF0Pb2 (ORCPT ); Mon, 27 Jun 2022 11:31:28 -0400 Received: from andre.telenet-ops.be (andre.telenet-ops.be [IPv6:2a02:1800:120:4::f00:15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 206C619C2E for ; Mon, 27 Jun 2022 08:31:24 -0700 (PDT) Received: from ramsan.of.borg ([84.195.186.194]) by andre.telenet-ops.be with bizsmtp id oFXH2700L4C55Sk01FXHYi; Mon, 27 Jun 2022 17:31:21 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5qhp-0014yb-1K; Mon, 27 Jun 2022 17:31:17 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1o5qho-004jEh-Gp; Mon, 27 Jun 2022 17:31:16 +0200 From: Geert Uytterhoeven To: Vignesh Raghavendra , Sergey Shtylyov , Krzysztof Kozlowski , Wolfram Sang , Lad Prabhakar , Miquel Raynal , Richard Weinberger Cc: Mark Brown , linux-mtd@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 4/7] memory: renesas-rpc-if: Split-off private data from struct rpcif Date: Mon, 27 Jun 2022 17:31:11 +0200 Message-Id: <062510dcc46c8fefe7a18527d98398c6f4c2bb0f.1656341824.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The rpcif structure is used as a common data structure, shared by the RPC-IF core driver and by the HyperBus and SPI child drivers. This poses several problems: - Most structure members describe private core driver state, which should not be accessible by the child drivers, - The structure's lifetime is controlled by the child drivers, complicating use by the core driver. Fix this by moving the private core driver state to its own structure, managed by the RPC-IF core driver, and store it in the core driver's private data field. This requires absorbing the child's platform device, as that was stored in the driver's private data field before. Signed-off-by: Geert Uytterhoeven --- drivers/memory/renesas-rpc-if.c | 75 +++++++++++++++++++++++++-------- include/memory/renesas-rpc-if.h | 16 ------- 2 files changed, 57 insertions(+), 34 deletions(-) diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-i= f.c index 55dbb3854b09ad43..78e10a7300411191 100644 --- a/drivers/memory/renesas-rpc-if.c +++ b/drivers/memory/renesas-rpc-if.c @@ -162,14 +162,36 @@ static const struct regmap_access_table rpcif_volatil= e_table =3D { .n_yes_ranges =3D ARRAY_SIZE(rpcif_volatile_ranges), }; =20 +struct rpcif_priv { + struct device *dev; + void __iomem *base; + void __iomem *dirmap; + struct regmap *regmap; + struct reset_control *rstc; + struct platform_device *vdev; + size_t size; + enum rpcif_type type; + enum rpcif_data_dir dir; + u8 bus_size; + u8 xfer_size; + void *buffer; + u32 xferlen; + u32 smcr; + u32 smadr; + u32 command; /* DRCMR or SMCMR */ + u32 option; /* DROPR or SMOPR */ + u32 enable; /* DRENR or SMENR */ + u32 dummy; /* DRDMCR or SMDMCR */ + u32 ddr; /* DRDRENR or SMDRENR */ +}; =20 /* * Custom accessor functions to ensure SM[RW]DR[01] are always accessed wi= th - * proper width. Requires rpcif.xfer_size to be correctly set before! + * proper width. Requires rpcif_priv.xfer_size to be correctly set before! */ static int rpcif_reg_read(void *context, unsigned int reg, unsigned int *v= al) { - struct rpcif *rpc =3D context; + struct rpcif_priv *rpc =3D context; =20 switch (reg) { case RPCIF_SMRDR0: @@ -205,7 +227,7 @@ static int rpcif_reg_read(void *context, unsigned int r= eg, unsigned int *val) =20 static int rpcif_reg_write(void *context, unsigned int reg, unsigned int v= al) { - struct rpcif *rpc =3D context; + struct rpcif_priv *rpc =3D context; =20 switch (reg) { case RPCIF_SMWDR0: @@ -252,13 +274,12 @@ static const struct regmap_config rpcif_regmap_config= =3D { .volatile_table =3D &rpcif_volatile_table, }; =20 -int rpcif_sw_init(struct rpcif *rpc, struct device *dev) +int rpcif_sw_init(struct rpcif *rpcif, struct device *dev) { struct platform_device *pdev =3D to_platform_device(dev); + struct rpcif_priv *rpc =3D dev_get_drvdata(dev); struct resource *res; =20 - rpc->dev =3D dev; - rpc->base =3D devm_platform_ioremap_resource_byname(pdev, "regs"); if (IS_ERR(rpc->base)) return PTR_ERR(rpc->base); @@ -278,12 +299,17 @@ int rpcif_sw_init(struct rpcif *rpc, struct device *d= ev) =20 rpc->type =3D (uintptr_t)of_device_get_match_data(dev); rpc->rstc =3D devm_reset_control_get_exclusive(dev, NULL); + if (IS_ERR(rpc->rstc)) + return PTR_ERR(rpc->rstc); =20 - return PTR_ERR_OR_ZERO(rpc->rstc); + rpcif->dev =3D dev; + rpcif->dirmap =3D rpc->dirmap; + rpcif->size =3D rpc->size; + return 0; } EXPORT_SYMBOL(rpcif_sw_init); =20 -static void rpcif_rzg2l_timing_adjust_sdr(struct rpcif *rpc) +static void rpcif_rzg2l_timing_adjust_sdr(struct rpcif_priv *rpc) { regmap_write(rpc->regmap, RPCIF_PHYWR, 0xa5390000); regmap_write(rpc->regmap, RPCIF_PHYADD, 0x80000000); @@ -297,8 +323,9 @@ static void rpcif_rzg2l_timing_adjust_sdr(struct rpcif = *rpc) regmap_write(rpc->regmap, RPCIF_PHYADD, 0x80000032); } =20 -int rpcif_hw_init(struct rpcif *rpc, bool hyperflash) +int rpcif_hw_init(struct rpcif *rpcif, bool hyperflash) { + struct rpcif_priv *rpc =3D dev_get_drvdata(rpcif->dev); u32 dummy; int ret; =20 @@ -357,7 +384,7 @@ int rpcif_hw_init(struct rpcif *rpc, bool hyperflash) } EXPORT_SYMBOL(rpcif_hw_init); =20 -static int wait_msg_xfer_end(struct rpcif *rpc) +static int wait_msg_xfer_end(struct rpcif_priv *rpc) { u32 sts; =20 @@ -366,7 +393,7 @@ static int wait_msg_xfer_end(struct rpcif *rpc) USEC_PER_SEC); } =20 -static u8 rpcif_bits_set(struct rpcif *rpc, u32 nbytes) +static u8 rpcif_bits_set(struct rpcif_priv *rpc, u32 nbytes) { if (rpc->bus_size =3D=3D 2) nbytes /=3D 2; @@ -379,9 +406,11 @@ static u8 rpcif_bit_size(u8 buswidth) return buswidth > 4 ? 2 : ilog2(buswidth); } =20 -void rpcif_prepare(struct rpcif *rpc, const struct rpcif_op *op, u64 *offs, +void rpcif_prepare(struct rpcif *rpcif, const struct rpcif_op *op, u64 *of= fs, size_t *len) { + struct rpcif_priv *rpc =3D dev_get_drvdata(rpcif->dev); + rpc->smcr =3D 0; rpc->smadr =3D 0; rpc->enable =3D 0; @@ -465,8 +494,9 @@ void rpcif_prepare(struct rpcif *rpc, const struct rpci= f_op *op, u64 *offs, } EXPORT_SYMBOL(rpcif_prepare); =20 -int rpcif_manual_xfer(struct rpcif *rpc) +int rpcif_manual_xfer(struct rpcif *rpcif) { + struct rpcif_priv *rpc =3D dev_get_drvdata(rpcif->dev); u32 smenr, smcr, pos =3D 0, max =3D rpc->bus_size =3D=3D 2 ? 8 : 4; int ret =3D 0; =20 @@ -588,7 +618,7 @@ int rpcif_manual_xfer(struct rpcif *rpc) err_out: if (reset_control_reset(rpc->rstc)) dev_err(rpc->dev, "Failed to reset HW\n"); - rpcif_hw_init(rpc, rpc->bus_size =3D=3D 2); + rpcif_hw_init(rpcif, rpc->bus_size =3D=3D 2); goto exit; } EXPORT_SYMBOL(rpcif_manual_xfer); @@ -635,8 +665,9 @@ static void memcpy_fromio_readw(void *to, } } =20 -ssize_t rpcif_dirmap_read(struct rpcif *rpc, u64 offs, size_t len, void *b= uf) +ssize_t rpcif_dirmap_read(struct rpcif *rpcif, u64 offs, size_t len, void = *buf) { + struct rpcif_priv *rpc =3D dev_get_drvdata(rpcif->dev); loff_t from =3D offs & (rpc->size - 1); size_t size =3D rpc->size - from; int ret; @@ -675,6 +706,7 @@ static int rpcif_probe(struct platform_device *pdev) struct device *dev =3D &pdev->dev; struct platform_device *vdev; struct device_node *flash; + struct rpcif_priv *rpc; const char *name; int ret; =20 @@ -695,11 +727,18 @@ static int rpcif_probe(struct platform_device *pdev) } of_node_put(flash); =20 + rpc =3D devm_kzalloc(dev, sizeof(*rpc), GFP_KERNEL); + if (!rpc) + return -ENOMEM; + vdev =3D platform_device_alloc(name, pdev->id); if (!vdev) return -ENOMEM; vdev->dev.parent =3D dev; - platform_set_drvdata(pdev, vdev); + + rpc->dev =3D dev; + rpc->vdev =3D vdev; + platform_set_drvdata(pdev, rpc); =20 ret =3D platform_device_add(vdev); if (ret) { @@ -712,9 +751,9 @@ static int rpcif_probe(struct platform_device *pdev) =20 static int rpcif_remove(struct platform_device *pdev) { - struct platform_device *vdev =3D platform_get_drvdata(pdev); + struct rpcif_priv *rpc =3D platform_get_drvdata(pdev); =20 - platform_device_unregister(vdev); + platform_device_unregister(rpc->vdev); =20 return 0; } diff --git a/include/memory/renesas-rpc-if.h b/include/memory/renesas-rpc-i= f.h index 9c0ad64b8d292d49..ddf94356752d3315 100644 --- a/include/memory/renesas-rpc-if.h +++ b/include/memory/renesas-rpc-if.h @@ -64,24 +64,8 @@ enum rpcif_type { =20 struct rpcif { struct device *dev; - void __iomem *base; void __iomem *dirmap; - struct regmap *regmap; - struct reset_control *rstc; size_t size; - enum rpcif_type type; - enum rpcif_data_dir dir; - u8 bus_size; - u8 xfer_size; - void *buffer; - u32 xferlen; - u32 smcr; - u32 smadr; - u32 command; /* DRCMR or SMCMR */ - u32 option; /* DROPR or SMOPR */ - u32 enable; /* DRENR or SMENR */ - u32 dummy; /* DRDMCR or SMDMCR */ - u32 ddr; /* DRDRENR or SMDRENR */ }; =20 int rpcif_sw_init(struct rpcif *rpc, struct device *dev); --=20 2.25.1 From nobody Sun Apr 19 20:35:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A005CCA480 for ; Mon, 27 Jun 2022 15:31:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238251AbiF0Pbj (ORCPT ); Mon, 27 Jun 2022 11:31:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238159AbiF0Pb2 (ORCPT ); Mon, 27 Jun 2022 11:31:28 -0400 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E6C819C38 for ; Mon, 27 Jun 2022 08:31:24 -0700 (PDT) Received: from ramsan.of.borg ([84.195.186.194]) by xavier.telenet-ops.be with bizsmtp id oFXH2700P4C55Sk01FXHah; Mon, 27 Jun 2022 17:31:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5qho-0014yc-VJ; Mon, 27 Jun 2022 17:31:16 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1o5qho-004jEn-HZ; Mon, 27 Jun 2022 17:31:16 +0200 From: Geert Uytterhoeven To: Vignesh Raghavendra , Sergey Shtylyov , Krzysztof Kozlowski , Wolfram Sang , Lad Prabhakar , Miquel Raynal , Richard Weinberger Cc: Mark Brown , linux-mtd@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 5/7] memory: renesas-rpc-if: Move resource acquisition to .probe() Date: Mon, 27 Jun 2022 17:31:12 +0200 Message-Id: <2fd9b9e3f60fe555d9dcad499c90e3ec869aa96e.1656341824.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" While the acquired resources are tied to the lifetime of the RPC-IF core device (through the use of managed resource functions), the actual resource acquisition is triggered from the HyperBus and SPI child drivers. Due to this mismatch, unbinding and rebinding the child drivers manually fails with -EBUSY: # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/= unbind # echo rpc-if-hyperflash > /sys/bus/platform/drivers/rpc-if-hyperflash/= bind rpc-if ee200000.spi: can't request region for resource [mem 0xee200000-= 0xee2001ff] rpc-if-hyperflash: probe of rpc-if-hyperflash failed with error -16 Fix this by moving all resource acquisition to the core driver's probe routine. Signed-off-by: Geert Uytterhoeven --- drivers/memory/renesas-rpc-if.c | 47 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-i= f.c index 78e10a7300411191..ef0336cbb4c196fb 100644 --- a/drivers/memory/renesas-rpc-if.c +++ b/drivers/memory/renesas-rpc-if.c @@ -276,31 +276,7 @@ static const struct regmap_config rpcif_regmap_config = =3D { =20 int rpcif_sw_init(struct rpcif *rpcif, struct device *dev) { - struct platform_device *pdev =3D to_platform_device(dev); struct rpcif_priv *rpc =3D dev_get_drvdata(dev); - struct resource *res; - - rpc->base =3D devm_platform_ioremap_resource_byname(pdev, "regs"); - if (IS_ERR(rpc->base)) - return PTR_ERR(rpc->base); - - rpc->regmap =3D devm_regmap_init(dev, NULL, rpc, &rpcif_regmap_config); - if (IS_ERR(rpc->regmap)) { - dev_err(dev, "failed to init regmap for rpcif, error %ld\n", - PTR_ERR(rpc->regmap)); - return PTR_ERR(rpc->regmap); - } - - res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, "dirmap"); - rpc->dirmap =3D devm_ioremap_resource(dev, res); - if (IS_ERR(rpc->dirmap)) - return PTR_ERR(rpc->dirmap); - rpc->size =3D resource_size(res); - - rpc->type =3D (uintptr_t)of_device_get_match_data(dev); - rpc->rstc =3D devm_reset_control_get_exclusive(dev, NULL); - if (IS_ERR(rpc->rstc)) - return PTR_ERR(rpc->rstc); =20 rpcif->dev =3D dev; rpcif->dirmap =3D rpc->dirmap; @@ -707,6 +683,7 @@ static int rpcif_probe(struct platform_device *pdev) struct platform_device *vdev; struct device_node *flash; struct rpcif_priv *rpc; + struct resource *res; const char *name; int ret; =20 @@ -731,6 +708,28 @@ static int rpcif_probe(struct platform_device *pdev) if (!rpc) return -ENOMEM; =20 + rpc->base =3D devm_platform_ioremap_resource_byname(pdev, "regs"); + if (IS_ERR(rpc->base)) + return PTR_ERR(rpc->base); + + rpc->regmap =3D devm_regmap_init(dev, NULL, rpc, &rpcif_regmap_config); + if (IS_ERR(rpc->regmap)) { + dev_err(dev, "failed to init regmap for rpcif, error %ld\n", + PTR_ERR(rpc->regmap)); + return PTR_ERR(rpc->regmap); + } + + res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, "dirmap"); + rpc->dirmap =3D devm_ioremap_resource(dev, res); + if (IS_ERR(rpc->dirmap)) + return PTR_ERR(rpc->dirmap); + rpc->size =3D resource_size(res); + + rpc->type =3D (uintptr_t)of_device_get_match_data(dev); + rpc->rstc =3D devm_reset_control_get_exclusive(dev, NULL); + if (IS_ERR(rpc->rstc)) + return PTR_ERR(rpc->rstc); + vdev =3D platform_device_alloc(name, pdev->id); if (!vdev) return -ENOMEM; --=20 2.25.1 From nobody Sun Apr 19 20:35:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53177C43334 for ; Mon, 27 Jun 2022 15:31:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238300AbiF0Pbw (ORCPT ); Mon, 27 Jun 2022 11:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238199AbiF0Pbf (ORCPT ); Mon, 27 Jun 2022 11:31:35 -0400 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F60719C35 for ; Mon, 27 Jun 2022 08:31:31 -0700 (PDT) Received: from ramsan.of.borg ([84.195.186.194]) by xavier.telenet-ops.be with bizsmtp id oFXJ270064C55Sk01FXJap; Mon, 27 Jun 2022 17:31:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5qhp-0014yd-Dz; Mon, 27 Jun 2022 17:31:17 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1o5qho-004jEv-IF; Mon, 27 Jun 2022 17:31:16 +0200 From: Geert Uytterhoeven To: Vignesh Raghavendra , Sergey Shtylyov , Krzysztof Kozlowski , Wolfram Sang , Lad Prabhakar , Miquel Raynal , Richard Weinberger Cc: Mark Brown , linux-mtd@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 6/7] memory: renesas-rpc-if: Pass device instead of rpcif to rpcif_*() Date: Mon, 27 Jun 2022 17:31:13 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Most rpcif_*() API functions do not need access to any other fields in the rpcif structure than the device pointer. Simplify dependencies by passing the device pointer instead. Signed-off-by: Geert Uytterhoeven Acked-by: Miquel Raynal --- drivers/memory/renesas-rpc-if.c | 32 ++++++++++++++++---------------- drivers/mtd/hyperbus/rpc-if.c | 18 +++++++++--------- drivers/spi/spi-rpc-if.c | 14 +++++++------- include/memory/renesas-rpc-if.h | 16 ++++++++-------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-i= f.c index ef0336cbb4c196fb..ec76e603ad24d214 100644 --- a/drivers/memory/renesas-rpc-if.c +++ b/drivers/memory/renesas-rpc-if.c @@ -299,13 +299,13 @@ static void rpcif_rzg2l_timing_adjust_sdr(struct rpci= f_priv *rpc) regmap_write(rpc->regmap, RPCIF_PHYADD, 0x80000032); } =20 -int rpcif_hw_init(struct rpcif *rpcif, bool hyperflash) +int rpcif_hw_init(struct device *dev, bool hyperflash) { - struct rpcif_priv *rpc =3D dev_get_drvdata(rpcif->dev); + struct rpcif_priv *rpc =3D dev_get_drvdata(dev); u32 dummy; int ret; =20 - ret =3D pm_runtime_resume_and_get(rpc->dev); + ret =3D pm_runtime_resume_and_get(dev); if (ret) return ret; =20 @@ -352,7 +352,7 @@ int rpcif_hw_init(struct rpcif *rpcif, bool hyperflash) regmap_write(rpc->regmap, RPCIF_SSLDR, RPCIF_SSLDR_SPNDL(7) | RPCIF_SSLDR_SLNDL(7) | RPCIF_SSLDR_SCKDL(7)); =20 - pm_runtime_put(rpc->dev); + pm_runtime_put(dev); =20 rpc->bus_size =3D hyperflash ? 2 : 1; =20 @@ -382,10 +382,10 @@ static u8 rpcif_bit_size(u8 buswidth) return buswidth > 4 ? 2 : ilog2(buswidth); } =20 -void rpcif_prepare(struct rpcif *rpcif, const struct rpcif_op *op, u64 *of= fs, +void rpcif_prepare(struct device *dev, const struct rpcif_op *op, u64 *off= s, size_t *len) { - struct rpcif_priv *rpc =3D dev_get_drvdata(rpcif->dev); + struct rpcif_priv *rpc =3D dev_get_drvdata(dev); =20 rpc->smcr =3D 0; rpc->smadr =3D 0; @@ -470,13 +470,13 @@ void rpcif_prepare(struct rpcif *rpcif, const struct = rpcif_op *op, u64 *offs, } EXPORT_SYMBOL(rpcif_prepare); =20 -int rpcif_manual_xfer(struct rpcif *rpcif) +int rpcif_manual_xfer(struct device *dev) { - struct rpcif_priv *rpc =3D dev_get_drvdata(rpcif->dev); + struct rpcif_priv *rpc =3D dev_get_drvdata(dev); u32 smenr, smcr, pos =3D 0, max =3D rpc->bus_size =3D=3D 2 ? 8 : 4; int ret =3D 0; =20 - ret =3D pm_runtime_resume_and_get(rpc->dev); + ret =3D pm_runtime_resume_and_get(dev); if (ret < 0) return ret; =20 @@ -588,13 +588,13 @@ int rpcif_manual_xfer(struct rpcif *rpcif) } =20 exit: - pm_runtime_put(rpc->dev); + pm_runtime_put(dev); return ret; =20 err_out: if (reset_control_reset(rpc->rstc)) - dev_err(rpc->dev, "Failed to reset HW\n"); - rpcif_hw_init(rpcif, rpc->bus_size =3D=3D 2); + dev_err(dev, "Failed to reset HW\n"); + rpcif_hw_init(dev, rpc->bus_size =3D=3D 2); goto exit; } EXPORT_SYMBOL(rpcif_manual_xfer); @@ -641,9 +641,9 @@ static void memcpy_fromio_readw(void *to, } } =20 -ssize_t rpcif_dirmap_read(struct rpcif *rpcif, u64 offs, size_t len, void = *buf) +ssize_t rpcif_dirmap_read(struct device *dev, u64 offs, size_t len, void *= buf) { - struct rpcif_priv *rpc =3D dev_get_drvdata(rpcif->dev); + struct rpcif_priv *rpc =3D dev_get_drvdata(dev); loff_t from =3D offs & (rpc->size - 1); size_t size =3D rpc->size - from; int ret; @@ -651,7 +651,7 @@ ssize_t rpcif_dirmap_read(struct rpcif *rpcif, u64 offs= , size_t len, void *buf) if (len > size) len =3D size; =20 - ret =3D pm_runtime_resume_and_get(rpc->dev); + ret =3D pm_runtime_resume_and_get(dev); if (ret < 0) return ret; =20 @@ -671,7 +671,7 @@ ssize_t rpcif_dirmap_read(struct rpcif *rpcif, u64 offs= , size_t len, void *buf) else memcpy_fromio(buf, rpc->dirmap + from, len); =20 - pm_runtime_put(rpc->dev); + pm_runtime_put(dev); =20 return len; } diff --git a/drivers/mtd/hyperbus/rpc-if.c b/drivers/mtd/hyperbus/rpc-if.c index d00d302434030b20..41734e337ac00e40 100644 --- a/drivers/mtd/hyperbus/rpc-if.c +++ b/drivers/mtd/hyperbus/rpc-if.c @@ -56,7 +56,7 @@ static void rpcif_hb_prepare_read(struct rpcif *rpc, void= *to, op.data.nbytes =3D len; op.data.buf.in =3D to; =20 - rpcif_prepare(rpc, &op, NULL, NULL); + rpcif_prepare(rpc->dev, &op, NULL, NULL); } =20 static void rpcif_hb_prepare_write(struct rpcif *rpc, unsigned long to, @@ -70,7 +70,7 @@ static void rpcif_hb_prepare_write(struct rpcif *rpc, uns= igned long to, op.data.nbytes =3D len; op.data.buf.out =3D from; =20 - rpcif_prepare(rpc, &op, NULL, NULL); + rpcif_prepare(rpc->dev, &op, NULL, NULL); } =20 static u16 rpcif_hb_read16(struct hyperbus_device *hbdev, unsigned long ad= dr) @@ -81,7 +81,7 @@ static u16 rpcif_hb_read16(struct hyperbus_device *hbdev,= unsigned long addr) =20 rpcif_hb_prepare_read(&hyperbus->rpc, &data, addr, 2); =20 - rpcif_manual_xfer(&hyperbus->rpc); + rpcif_manual_xfer(hyperbus->rpc.dev); =20 return data.x[0]; } @@ -94,7 +94,7 @@ static void rpcif_hb_write16(struct hyperbus_device *hbde= v, unsigned long addr, =20 rpcif_hb_prepare_write(&hyperbus->rpc, addr, &data, 2); =20 - rpcif_manual_xfer(&hyperbus->rpc); + rpcif_manual_xfer(hyperbus->rpc.dev); } =20 static void rpcif_hb_copy_from(struct hyperbus_device *hbdev, void *to, @@ -105,7 +105,7 @@ static void rpcif_hb_copy_from(struct hyperbus_device *= hbdev, void *to, =20 rpcif_hb_prepare_read(&hyperbus->rpc, to, from, len); =20 - rpcif_dirmap_read(&hyperbus->rpc, from, len, to); + rpcif_dirmap_read(hyperbus->rpc.dev, from, len, to); } =20 static const struct hyperbus_ops rpcif_hb_ops =3D { @@ -130,9 +130,9 @@ static int rpcif_hb_probe(struct platform_device *pdev) =20 platform_set_drvdata(pdev, hyperbus); =20 - rpcif_enable_rpm(&hyperbus->rpc); + rpcif_enable_rpm(hyperbus->rpc.dev); =20 - error =3D rpcif_hw_init(&hyperbus->rpc, true); + error =3D rpcif_hw_init(hyperbus->rpc.dev, true); if (error) goto out_disable_rpm; =20 @@ -150,7 +150,7 @@ static int rpcif_hb_probe(struct platform_device *pdev) return 0; =20 out_disable_rpm: - rpcif_disable_rpm(&hyperbus->rpc); + rpcif_disable_rpm(hyperbus->rpc.dev); return error; } =20 @@ -160,7 +160,7 @@ static int rpcif_hb_remove(struct platform_device *pdev) =20 hyperbus_unregister_device(&hyperbus->hbdev); =20 - rpcif_disable_rpm(&hyperbus->rpc); + rpcif_disable_rpm(hyperbus->rpc.dev); =20 return 0; } diff --git a/drivers/spi/spi-rpc-if.c b/drivers/spi/spi-rpc-if.c index 24ec1c83f379ceec..5063587d2c724c7c 100644 --- a/drivers/spi/spi-rpc-if.c +++ b/drivers/spi/spi-rpc-if.c @@ -58,7 +58,7 @@ static void rpcif_spi_mem_prepare(struct spi_device *spi_= dev, rpc_op.data.dir =3D RPCIF_NO_DATA; } =20 - rpcif_prepare(rpc, &rpc_op, offs, len); + rpcif_prepare(rpc->dev, &rpc_op, offs, len); } =20 static bool rpcif_spi_mem_supports_op(struct spi_mem *mem, @@ -86,7 +86,7 @@ static ssize_t rpcif_spi_mem_dirmap_read(struct spi_mem_d= irmap_desc *desc, =20 rpcif_spi_mem_prepare(desc->mem->spi, &desc->info.op_tmpl, &offs, &len); =20 - return rpcif_dirmap_read(rpc, offs, len, buf); + return rpcif_dirmap_read(rpc->dev, offs, len, buf); } =20 static int rpcif_spi_mem_dirmap_create(struct spi_mem_dirmap_desc *desc) @@ -117,7 +117,7 @@ static int rpcif_spi_mem_exec_op(struct spi_mem *mem, =20 rpcif_spi_mem_prepare(mem->spi, op, NULL, NULL); =20 - return rpcif_manual_xfer(rpc); + return rpcif_manual_xfer(rpc->dev); } =20 static const struct spi_controller_mem_ops rpcif_spi_mem_ops =3D { @@ -147,7 +147,7 @@ static int rpcif_spi_probe(struct platform_device *pdev) =20 ctlr->dev.of_node =3D parent->of_node; =20 - rpcif_enable_rpm(rpc); + rpcif_enable_rpm(rpc->dev); =20 ctlr->num_chipselect =3D 1; ctlr->mem_ops =3D &rpcif_spi_mem_ops; @@ -156,7 +156,7 @@ static int rpcif_spi_probe(struct platform_device *pdev) ctlr->mode_bits =3D SPI_CPOL | SPI_CPHA | SPI_TX_QUAD | SPI_RX_QUAD; ctlr->flags =3D SPI_CONTROLLER_HALF_DUPLEX; =20 - error =3D rpcif_hw_init(rpc, false); + error =3D rpcif_hw_init(rpc->dev, false); if (error) goto out_disable_rpm; =20 @@ -169,7 +169,7 @@ static int rpcif_spi_probe(struct platform_device *pdev) return 0; =20 out_disable_rpm: - rpcif_disable_rpm(rpc); + rpcif_disable_rpm(rpc->dev); return error; } =20 @@ -179,7 +179,7 @@ static int rpcif_spi_remove(struct platform_device *pde= v) struct rpcif *rpc =3D spi_controller_get_devdata(ctlr); =20 spi_unregister_controller(ctlr); - rpcif_disable_rpm(rpc); + rpcif_disable_rpm(rpc->dev); =20 return 0; } diff --git a/include/memory/renesas-rpc-if.h b/include/memory/renesas-rpc-i= f.h index ddf94356752d3315..d2130c2c8c82fbd5 100644 --- a/include/memory/renesas-rpc-if.h +++ b/include/memory/renesas-rpc-if.h @@ -69,20 +69,20 @@ struct rpcif { }; =20 int rpcif_sw_init(struct rpcif *rpc, struct device *dev); -int rpcif_hw_init(struct rpcif *rpc, bool hyperflash); -void rpcif_prepare(struct rpcif *rpc, const struct rpcif_op *op, u64 *offs, +int rpcif_hw_init(struct device *dev, bool hyperflash); +void rpcif_prepare(struct device *dev, const struct rpcif_op *op, u64 *off= s, size_t *len); -int rpcif_manual_xfer(struct rpcif *rpc); -ssize_t rpcif_dirmap_read(struct rpcif *rpc, u64 offs, size_t len, void *b= uf); +int rpcif_manual_xfer(struct device *dev); +ssize_t rpcif_dirmap_read(struct device *dev, u64 offs, size_t len, void *= buf); =20 -static inline void rpcif_enable_rpm(struct rpcif *rpc) +static inline void rpcif_enable_rpm(struct device *dev) { - pm_runtime_enable(rpc->dev); + pm_runtime_enable(dev); } =20 -static inline void rpcif_disable_rpm(struct rpcif *rpc) +static inline void rpcif_disable_rpm(struct device *dev) { - pm_runtime_disable(rpc->dev); + pm_runtime_disable(dev); } =20 #endif // __RENESAS_RPC_IF_H --=20 2.25.1 From nobody Sun Apr 19 20:35:23 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5FD1C43334 for ; Mon, 27 Jun 2022 15:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238287AbiF0Pbu (ORCPT ); Mon, 27 Jun 2022 11:31:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238193AbiF0Pb2 (ORCPT ); Mon, 27 Jun 2022 11:31:28 -0400 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62F0D19C3D for ; Mon, 27 Jun 2022 08:31:25 -0700 (PDT) Received: from ramsan.of.borg ([84.195.186.194]) by xavier.telenet-ops.be with bizsmtp id oFXH2700S4C55Sk01FXHaj; Mon, 27 Jun 2022 17:31:23 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o5qhp-0014ye-0o; Mon, 27 Jun 2022 17:31:17 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1o5qho-004jF0-J1; Mon, 27 Jun 2022 17:31:16 +0200 From: Geert Uytterhoeven To: Vignesh Raghavendra , Sergey Shtylyov , Krzysztof Kozlowski , Wolfram Sang , Lad Prabhakar , Miquel Raynal , Richard Weinberger Cc: Mark Brown , linux-mtd@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 7/7] memory: renesas-rpc-if: Reinitialize registers during system resume Date: Mon, 27 Jun 2022 17:31:14 +0200 Message-Id: <923c057c77b146710a82d486f89ce3a8ebda7ccd.1656341824.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" During PSCI system suspend, R-Car Gen3 SoCs may be powered down, and thus the RPC-IF register state may be lost. Consequently, when using the RPC-IF after system resume, data corruption may happen. Fix this by reinitializing the hardware state during system resume. As this requires resuming the RPC-IF core device, this can only be done when the device is under active control of the HyperBus or SPI child driver. Signed-off-by: Geert Uytterhoeven --- drivers/memory/renesas-rpc-if.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-i= f.c index ec76e603ad24d214..2a49d4511c8296c5 100644 --- a/drivers/memory/renesas-rpc-if.c +++ b/drivers/memory/renesas-rpc-if.c @@ -757,6 +757,20 @@ static int rpcif_remove(struct platform_device *pdev) return 0; } =20 +static int rpcif_resume(struct device *dev) +{ + struct rpcif_priv *rpc =3D dev_get_drvdata(dev); + + if (!pm_runtime_enabled(dev)) { + /* Not yet activated or deactivated by child device */ + return 0; + } + + return rpcif_hw_init(dev, rpc->bus_size =3D=3D 2); +} + +static DEFINE_SIMPLE_DEV_PM_OPS(rpcif_pm_ops, NULL, rpcif_resume); + static const struct of_device_id rpcif_of_match[] =3D { { .compatible =3D "renesas,rcar-gen3-rpc-if", .data =3D (void *)RPCIF_RCA= R_GEN3 }, { .compatible =3D "renesas,rzg2l-rpc-if", .data =3D (void *)RPCIF_RZ_G2L = }, @@ -770,6 +784,7 @@ static struct platform_driver rpcif_driver =3D { .driver =3D { .name =3D "rpc-if", .of_match_table =3D rpcif_of_match, + .pm =3D pm_sleep_ptr(&rpcif_pm_ops), }, }; module_platform_driver(rpcif_driver); --=20 2.25.1