From nobody Fri Jun 19 20:17:24 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 E2548C433EF for ; Tue, 29 Mar 2022 09:15:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234549AbiC2JRG (ORCPT ); Tue, 29 Mar 2022 05:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232677AbiC2JRD (ORCPT ); Tue, 29 Mar 2022 05:17:03 -0400 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76CF19AE5E for ; Tue, 29 Mar 2022 02:15:18 -0700 (PDT) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed40:d553:ff0a:6830:6bde]) by laurent.telenet-ops.be with bizsmtp id C9FD2700F49QC44019FDU9; Tue, 29 Mar 2022 11:15:15 +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 1nZ7wW-007EWe-QI; Tue, 29 Mar 2022 11:15:12 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1nZ7wW-00BsDN-9q; Tue, 29 Mar 2022 11:15:12 +0200 From: Geert Uytterhoeven To: Wolfram Sang , Krzysztof Kozlowski Cc: Sergey Shtylyov , Dung Nguyen , Lad Prabhakar , Andrew Gabbasov , Mark Brown , linux-renesas-soc@vger.kernel.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v3] memory: renesas-rpc-if: Fix HF/OSPI data transfer in Manual mode Date: Tue, 29 Mar 2022 11:15:08 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 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" HyperFlash devices fail to probe: rpc-if-hyperflash rpc-if-hyperflash: probing of hyperbus device failed In HyperFlash or Octal-SPI Flash mode, the Transfer Data Enable bits (SPIDE) in the Manual Mode Enable Setting Register (SMENR) are derived from half of the transfer size, cfr. the rpcif_bits_set() helper function. However, rpcif_reg_{read,write}() does not take the bus size into account, and does not double all Manual Mode Data Register access sizes when communicating with a HyperFlash or Octal-SPI Flash device. Fix this, and avoid the back-and-forth conversion between transfer size and Transfer Data Enable bits, by explicitly storing the transfer size in struct rpcif, and using that value to determine access size in rpcif_reg_{read,write}(). Enforce that the "high" Manual Mode Read/Write Data Registers (SM[RW]DR1) are only used for 8-byte data accesses. While at it, forbid writing to the Manual Mode Read Data Registers, as they are read-only. Fixes: fff53a551db50f5e ("memory: renesas-rpc-if: Correct QSPI data transfe= r in Manual mode") Signed-off-by: Geert Uytterhoeven Tested-by: Lad Prabhakar [QSPI] Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang --- Lightly (read-only) tested on: - Salvator-XS, ULCB, Ebisu-4D, and Draak (with R-Car H3 ES1.1 and ES2.0, M3-W ES1.0, M3-N ES1.0, E3 ES1.0, and D3 ES1.0) with HyperFlash, - Falcon with R-Car V3U ES1.0 with QSPI. v3: - Add Tested-by, - Update comments to match changed code, - Add explicit {read,write}l() for the 4/8 byte case, to increase readability, - Remove redundant break statements, - Tested HyperFlash on more boards and SoCs. v2: - Use rpc->xfer_size instead of SPIDE register reads and rpc->bus_size. Note: Alternatively, rpcif_manual_xfer() could bypass regmap and use {read,write}[bwl]() directly, cfr. commit 0d37f69cacb33435 ("memory: renesas-rpc-if: Correct QSPI data transfer in Manual mode") in the BSP. - HF dirmap reads are confirmed to work on R-Car M3-W, - Drop RFC. --- drivers/memory/renesas-rpc-if.c | 60 +++++++++++++++++++++++++-------- include/memory/renesas-rpc-if.h | 1 + 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-i= f.c index e4cc64f560196d55..64582b54400da2ba 100644 --- a/drivers/memory/renesas-rpc-if.c +++ b/drivers/memory/renesas-rpc-if.c @@ -164,25 +164,39 @@ static const struct regmap_access_table rpcif_volatil= e_table =3D { =20 =20 /* - * Custom accessor functions to ensure SMRDR0 and SMWDR0 are always access= ed - * with proper width. Requires SMENR_SPIDE to be correctly set before! + * 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! */ static int rpcif_reg_read(void *context, unsigned int reg, unsigned int *v= al) { struct rpcif *rpc =3D context; =20 - if (reg =3D=3D RPCIF_SMRDR0 || reg =3D=3D RPCIF_SMWDR0) { - u32 spide =3D readl(rpc->base + RPCIF_SMENR) & RPCIF_SMENR_SPIDE(0xF); - - if (spide =3D=3D 0x8) { + switch (reg) { + case RPCIF_SMRDR0: + case RPCIF_SMWDR0: + switch (rpc->xfer_size) { + case 1: *val =3D readb(rpc->base + reg); return 0; - } else if (spide =3D=3D 0xC) { + + case 2: *val =3D readw(rpc->base + reg); return 0; - } else if (spide !=3D 0xF) { + + case 4: + case 8: + *val =3D readl(rpc->base + reg); + return 0; + + default: return -EILSEQ; } + + case RPCIF_SMRDR1: + case RPCIF_SMWDR1: + if (rpc->xfer_size !=3D 8) + return -EILSEQ; + break; } =20 *val =3D readl(rpc->base + reg); @@ -193,18 +207,34 @@ static int rpcif_reg_write(void *context, unsigned in= t reg, unsigned int val) { struct rpcif *rpc =3D context; =20 - if (reg =3D=3D RPCIF_SMRDR0 || reg =3D=3D RPCIF_SMWDR0) { - u32 spide =3D readl(rpc->base + RPCIF_SMENR) & RPCIF_SMENR_SPIDE(0xF); - - if (spide =3D=3D 0x8) { + switch (reg) { + case RPCIF_SMWDR0: + switch (rpc->xfer_size) { + case 1: writeb(val, rpc->base + reg); return 0; - } else if (spide =3D=3D 0xC) { + + case 2: writew(val, rpc->base + reg); return 0; - } else if (spide !=3D 0xF) { + + case 4: + case 8: + writel(val, rpc->base + reg); + return 0; + + default: return -EILSEQ; } + + case RPCIF_SMWDR1: + if (rpc->xfer_size !=3D 8) + return -EILSEQ; + break; + + case RPCIF_SMRDR0: + case RPCIF_SMRDR1: + return -EPERM; } =20 writel(val, rpc->base + reg); @@ -469,6 +499,7 @@ int rpcif_manual_xfer(struct rpcif *rpc) =20 smenr |=3D RPCIF_SMENR_SPIDE(rpcif_bits_set(rpc, nbytes)); regmap_write(rpc->regmap, RPCIF_SMENR, smenr); + rpc->xfer_size =3D nbytes; =20 memcpy(data, rpc->buffer + pos, nbytes); if (nbytes =3D=3D 8) { @@ -533,6 +564,7 @@ int rpcif_manual_xfer(struct rpcif *rpc) regmap_write(rpc->regmap, RPCIF_SMENR, smenr); regmap_write(rpc->regmap, RPCIF_SMCR, rpc->smcr | RPCIF_SMCR_SPIE); + rpc->xfer_size =3D nbytes; ret =3D wait_msg_xfer_end(rpc); if (ret) goto err_out; diff --git a/include/memory/renesas-rpc-if.h b/include/memory/renesas-rpc-i= f.h index 7c93f5177532f187..9c0ad64b8d292d49 100644 --- a/include/memory/renesas-rpc-if.h +++ b/include/memory/renesas-rpc-if.h @@ -72,6 +72,7 @@ struct rpcif { enum rpcif_type type; enum rpcif_data_dir dir; u8 bus_size; + u8 xfer_size; void *buffer; u32 xferlen; u32 smcr; --=20 2.25.1