From nobody Thu Apr 2 22:04:18 2026 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 183E240B6F6 for ; Thu, 26 Mar 2026 16:26:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774542375; cv=none; b=KiR+7VI+WA9tJHGU0qakoN39HCzz2QDm0bTfh4Mdy4+Zaho+HYq0hbq+GAJQ5gchQFJ1zWwf+4lic4OfbPytirD7oWAHs9UEJy0xM8cs18THVJ6CBPHnDJXhNZpMl0QmD5OHoJ3nhTRFUD+BEigRBtkHio2HtyhYw7gU5d6twYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774542375; c=relaxed/simple; bh=680RajdrfFQHYk34GhPzZobTqjn51SOaRR2nKdw15W4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Qy7Qf+HvLEcHtlwz67Hr2045ztG4vIDlMuBBuK+pJrRmvnwd97yy4CyIJrg1W3wKlkhBbesNkfj2Bscf6y6pMYjbsi5bHMTkruBS4lsA66Je2+fAChjNMZK8PN8iVKSL3ruR+yZI0D18eO085kyuRGRC+U/6KnwdgVHhmpE+rqY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=M2lKDKd9; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="M2lKDKd9" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 11D79C5506D; Thu, 26 Mar 2026 16:26:41 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id C396F601FA; Thu, 26 Mar 2026 16:26:12 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 279B110450C89; Thu, 26 Mar 2026 17:26:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1774542372; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=No2FU9QfdRqbWVypforHQbPWeUdzW3YtFHj8aG5zOTE=; b=M2lKDKd9D0WXooDNyS9sGpXtV/vLkVc76lcRrVgNzczHEKneXifP+Fb0FBsYL6IceU0I50 afvLqxyX7tp+SxxJZqY88MG14+9ZYePcd5EX7X0n8xBDE1PYGj2YPN2Qxi69Pc/DU99PpP lZZcKGVpZPXHxZzmA9JJmHU1wburAcNKOlZi2wpR29T1cHYrVfi6u8k8ELXA5pDogYaU15 t7yQkYWRvgJliWkhvo9cwKxf9Gkdb6ukrXzTNIKxx6Dcezn23a73qyjLU36J1/bStEEleD sfH2+U3dB+J1IaTAyXY9gomnUNG2tHdLBmiG9gsO7lwM3NR+c7nIV8kIRWctVw== From: Miquel Raynal Date: Thu, 26 Mar 2026 17:25:51 +0100 Subject: [PATCH v2 04/11] spi: spi-mem: Transform the read operation template Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260326-winbond-v6-18-rc1-cont-read-v2-4-643de97a68a3@bootlin.com> References: <20260326-winbond-v6-18-rc1-cont-read-v2-0-643de97a68a3@bootlin.com> In-Reply-To: <20260326-winbond-v6-18-rc1-cont-read-v2-0-643de97a68a3@bootlin.com> To: Mark Brown , Richard Weinberger , Vignesh Raghavendra , Michael Walle , Miquel Raynal Cc: Pratyush Yadav , Thomas Petazzoni , Steam Lin , Santhosh Kumar K , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org X-Mailer: b4 0.14.3 X-Last-TLS-Session-Version: TLSv1.3 As of now, we only use a single operation template when creating SPI memory direct mappings. With the idea to extend this possibility to 2, rename the template to reflect that we are currently setting the "primary" operation, and create a pointer in the same structure to point to it. From a user point of view, the op_tmpl name remains but becomes a pointer, leading to minor changes in both the SPI NAND and SPI NOR cores. There is no functional change. Acked-by: Mark Brown Signed-off-by: Miquel Raynal --- drivers/mtd/nand/spi/core.c | 15 ++++++++------- drivers/mtd/spi-nor/core.c | 22 ++++++++++++---------- drivers/spi/spi-mem.c | 15 ++++++++------- include/linux/spi/spi-mem.h | 3 ++- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 663f5d6a6bd7..a66510747b31 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -491,9 +491,9 @@ static int spinand_read_from_cache_op(struct spinand_de= vice *spinand, =20 if (nand->ecc.engine->integration =3D=3D NAND_ECC_ENGINE_INTEGRATION_PIPE= LINED && req->mode !=3D MTD_OPS_RAW) - rdesc->info.op_tmpl.data.ecc =3D true; + rdesc->info.op_tmpl->data.ecc =3D true; else - rdesc->info.op_tmpl.data.ecc =3D false; + rdesc->info.op_tmpl->data.ecc =3D false; =20 if (spinand->flags & SPINAND_HAS_READ_PLANE_SELECT_BIT) column |=3D req->pos.plane << fls(nanddev_page_size(nand)); @@ -586,9 +586,9 @@ static int spinand_write_to_cache_op(struct spinand_dev= ice *spinand, =20 if (nand->ecc.engine->integration =3D=3D NAND_ECC_ENGINE_INTEGRATION_PIPE= LINED && req->mode !=3D MTD_OPS_RAW) - wdesc->info.op_tmpl.data.ecc =3D true; + wdesc->info.op_tmpl->data.ecc =3D true; else - wdesc->info.op_tmpl.data.ecc =3D false; + wdesc->info.op_tmpl->data.ecc =3D false; =20 if (spinand->flags & SPINAND_HAS_PROG_PLANE_SELECT_BIT) column |=3D req->pos.plane << fls(nanddev_page_size(nand)); @@ -1247,7 +1247,8 @@ static int spinand_create_dirmap(struct spinand_devic= e *spinand, =20 /* Write descriptor */ info.length =3D nanddev_page_size(nand) + nanddev_per_page_oobsize(nand); - info.op_tmpl.data.ecc =3D enable_ecc; + info.primary_op_tmpl =3D *spinand->op_templates->update_cache; + info.primary_op_tmpl.data.ecc =3D enable_ecc; desc =3D devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev, spinand->spimem, &info); if (IS_ERR(desc)) @@ -1256,8 +1257,8 @@ static int spinand_create_dirmap(struct spinand_devic= e *spinand, spinand->dirmaps[plane].wdesc =3D desc; =20 /* Read descriptor */ - info.op_tmpl =3D *spinand->op_templates->read_cache; - info.op_tmpl.data.ecc =3D enable_ecc; + info.primary_op_tmpl =3D *spinand->op_templates->read_cache; + info.primary_op_tmpl.data.ecc =3D enable_ecc; desc =3D spinand_create_rdesc(spinand, &info); if (IS_ERR(desc)) return PTR_ERR(desc); diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 8ffeb41c3e08..84b98d6b12cd 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -3641,14 +3641,15 @@ EXPORT_SYMBOL_GPL(spi_nor_scan); static int spi_nor_create_read_dirmap(struct spi_nor *nor) { struct spi_mem_dirmap_info info =3D { - .op_tmpl =3D SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), - SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), - SPI_MEM_OP_DUMMY(nor->read_dummy, 0), - SPI_MEM_OP_DATA_IN(0, NULL, 0)), + .op_tmpl =3D &info.primary_op_tmpl, + .primary_op_tmpl =3D SPI_MEM_OP(SPI_MEM_OP_CMD(nor->read_opcode, 0), + SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), + SPI_MEM_OP_DUMMY(nor->read_dummy, 0), + SPI_MEM_OP_DATA_IN(0, NULL, 0)), .offset =3D 0, .length =3D nor->params->size, }; - struct spi_mem_op *op =3D &info.op_tmpl; + struct spi_mem_op *op =3D info.op_tmpl; =20 spi_nor_spimem_setup_op(nor, op, nor->read_proto); =20 @@ -3672,14 +3673,15 @@ static int spi_nor_create_read_dirmap(struct spi_no= r *nor) static int spi_nor_create_write_dirmap(struct spi_nor *nor) { struct spi_mem_dirmap_info info =3D { - .op_tmpl =3D SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 0), - SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), - SPI_MEM_OP_NO_DUMMY, - SPI_MEM_OP_DATA_OUT(0, NULL, 0)), + .op_tmpl =3D &info.primary_op_tmpl, + .primary_op_tmpl =3D SPI_MEM_OP(SPI_MEM_OP_CMD(nor->program_opcode, 0), + SPI_MEM_OP_ADDR(nor->addr_nbytes, 0, 0), + SPI_MEM_OP_NO_DUMMY, + SPI_MEM_OP_DATA_OUT(0, NULL, 0)), .offset =3D 0, .length =3D nor->params->size, }; - struct spi_mem_op *op =3D &info.op_tmpl; + struct spi_mem_op *op =3D info.op_tmpl; =20 if (nor->program_opcode =3D=3D SPINOR_OP_AAI_WP && nor->sst_write_second) op->addr.nbytes =3D 0; diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c index a09371a075d2..e2eaa1ba4ff6 100644 --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -647,7 +647,7 @@ EXPORT_SYMBOL_GPL(spi_mem_calc_op_duration); static ssize_t spi_mem_no_dirmap_read(struct spi_mem_dirmap_desc *desc, u64 offs, size_t len, void *buf) { - struct spi_mem_op op =3D desc->info.op_tmpl; + struct spi_mem_op op =3D *desc->info.op_tmpl; int ret; =20 op.addr.val =3D desc->info.offset + offs; @@ -667,7 +667,7 @@ static ssize_t spi_mem_no_dirmap_read(struct spi_mem_di= rmap_desc *desc, static ssize_t spi_mem_no_dirmap_write(struct spi_mem_dirmap_desc *desc, u64 offs, size_t len, const void *buf) { - struct spi_mem_op op =3D desc->info.op_tmpl; + struct spi_mem_op op =3D *desc->info.op_tmpl; int ret; =20 op.addr.val =3D desc->info.offset + offs; @@ -706,11 +706,11 @@ spi_mem_dirmap_create(struct spi_mem *mem, int ret =3D -ENOTSUPP; =20 /* Make sure the number of address cycles is between 1 and 8 bytes. */ - if (!info->op_tmpl.addr.nbytes || info->op_tmpl.addr.nbytes > 8) + if (!info->primary_op_tmpl.addr.nbytes || info->primary_op_tmpl.addr.nbyt= es > 8) return ERR_PTR(-EINVAL); =20 /* data.dir should either be SPI_MEM_DATA_IN or SPI_MEM_DATA_OUT. */ - if (info->op_tmpl.data.dir =3D=3D SPI_MEM_NO_DATA) + if (info->primary_op_tmpl.data.dir =3D=3D SPI_MEM_NO_DATA) return ERR_PTR(-EINVAL); =20 desc =3D kzalloc_obj(*desc); @@ -719,6 +719,7 @@ spi_mem_dirmap_create(struct spi_mem *mem, =20 desc->mem =3D mem; desc->info =3D *info; + desc->info.op_tmpl =3D &desc->info.primary_op_tmpl; if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create) { ret =3D spi_mem_access_start(mem); if (ret) { @@ -733,7 +734,7 @@ spi_mem_dirmap_create(struct spi_mem *mem, =20 if (ret) { desc->nodirmap =3D true; - if (!spi_mem_supports_op(desc->mem, &desc->info.op_tmpl)) + if (!spi_mem_supports_op(desc->mem, &desc->info.primary_op_tmpl)) ret =3D -EOPNOTSUPP; else ret =3D 0; @@ -857,7 +858,7 @@ ssize_t spi_mem_dirmap_read(struct spi_mem_dirmap_desc = *desc, struct spi_controller *ctlr =3D desc->mem->spi->controller; ssize_t ret; =20 - if (desc->info.op_tmpl.data.dir !=3D SPI_MEM_DATA_IN) + if (desc->info.op_tmpl->data.dir !=3D SPI_MEM_DATA_IN) return -EINVAL; =20 if (!len) @@ -903,7 +904,7 @@ ssize_t spi_mem_dirmap_write(struct spi_mem_dirmap_desc= *desc, struct spi_controller *ctlr =3D desc->mem->spi->controller; ssize_t ret; =20 - if (desc->info.op_tmpl.data.dir !=3D SPI_MEM_DATA_OUT) + if (desc->info.op_tmpl->data.dir !=3D SPI_MEM_DATA_OUT) return -EINVAL; =20 if (!len) diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h index 5774e554c0f0..3cba7fe4bed5 100644 --- a/include/linux/spi/spi-mem.h +++ b/include/linux/spi/spi-mem.h @@ -225,7 +225,8 @@ struct spi_mem_op { * direction is directly encoded in the ->op_tmpl.data.dir field. */ struct spi_mem_dirmap_info { - struct spi_mem_op op_tmpl; + struct spi_mem_op *op_tmpl; + struct spi_mem_op primary_op_tmpl; u64 offset; u64 length; }; --=20 2.51.1