From nobody Tue Dec 16 14:52:17 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (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 456F5322B81 for ; Fri, 5 Dec 2025 19:39:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764963592; cv=none; b=D8uxYSX7nEaV43ehROlDOkz/3k6dKyGllpnO+MPTRamyWQaGBPtIxy8QVCli1cAnUEcmIKy89WSNHPV/yNFW52w87OqKs9E8apq4SGfbDcBCvR83HnHLlevj0XkrLFCFY3fx7jUuk7QtJY+X9kqvYdeXgmOwDjGuz4UIHEZ1jOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764963592; c=relaxed/simple; bh=NtGMTPcvwLs/cyAIQMv0WvoA4poN06nbQoGZCMYKOQU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KMcOwNepZtwZ8gSW/fN6TrF39kNSUqsAaFJelbHJofGZe6XZ4AQPPHKn9PPv0RVFpxCjk3MRH3W9xBzIwEDNdVtPlsqr0G0WZ8zWP7Dh05KrZFRE8TRTTPbk78mdsCT8upamatlfnJY4pxvsYfNcPi9NELlZkC6KKFuY+jWbx7k= 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=qZdm467v; arc=none smtp.client-ip=185.246.85.4 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="qZdm467v" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id E1ED64E41A73; Fri, 5 Dec 2025 19:39:48 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id B2E06606AC; Fri, 5 Dec 2025 19:39:48 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id A2979102F17A8; Fri, 5 Dec 2025 20:39:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1764963587; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=rzut/2vscrbvO9lhGJS+PxaQwT5GezE0dsfH+zXVtxg=; b=qZdm467v7LenNWq01VJrJCVXwBEoTdtnu3Rj4uoqGcO1qAc7pJqZZEyz5nRmFRtYYrq6FW 6QzmoUbSXY89q8xCsXnVTi9W+pMBcJPf/zPJsXHGbAAGaIv+xfmd+SQC7KYvjbg/kZLv1+ O7lS7ER+RAnQNL87qEQPATl2fSf3/yiOuBaEQIdrrlQy/LGABPJiogIaFsqVvn6XnGjAgI pfH5ADEOm+BzLbfgEKfnPMIbej9dc4J2m8XMzi8ZHH8sXBzbjf1I4CBjgYLA1JuGDDw2yO 9gvCe+G97ApIDkCGC2fpDRNaDVF8d2NjC5LX5e6hcElWaVkl/aWCmWXp2+4H9w== From: Miquel Raynal Date: Fri, 05 Dec 2025 20:38:55 +0100 Subject: [PATCH RFC 4/8] 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: <20251205-winbond-v6-18-rc1-cont-read-v1-4-01bc48631c73@bootlin.com> References: <20251205-winbond-v6-18-rc1-cont-read-v1-0-01bc48631c73@bootlin.com> In-Reply-To: <20251205-winbond-v6-18-rc1-cont-read-v1-0-01bc48631c73@bootlin.com> To: Mark Brown , Richard Weinberger , Vignesh Raghavendra , Michael Walle Cc: Tudor Ambarus , Pratyush Yadav , Thomas Petazzoni , Steam Lin , Santhosh Kumar K , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Miquel Raynal 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. Signed-off-by: Miquel Raynal Acked-by: Mark Brown --- drivers/mtd/nand/spi/core.c | 15 ++++++++------- drivers/mtd/spi-nor/core.c | 20 ++++++++++---------- drivers/spi/spi-mem.c | 15 ++++++++------- include/linux/spi/spi-mem.h | 3 ++- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 086c9f293373..209146f21326 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -401,9 +401,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)); @@ -496,9 +496,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)); @@ -1149,7 +1149,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)) @@ -1158,8 +1159,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 20ea80450f22..4de0a2b66e56 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -3631,14 +3631,14 @@ 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)), + .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 @@ -3662,14 +3662,14 @@ 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)), + .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 71e3eaf59df9..50f16943dc73 100644 --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -642,7 +642,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; @@ -662,7 +662,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; @@ -701,11 +701,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(sizeof(*desc), GFP_KERNEL); @@ -714,12 +714,13 @@ 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 ctlr->mem_ops->dirmap_create(desc); =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; @@ -843,7 +844,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) @@ -889,7 +890,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 e4db0924898c..3092caefa0b6 100644 --- a/include/linux/spi/spi-mem.h +++ b/include/linux/spi/spi-mem.h @@ -217,7 +217,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