public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Michael Walle <mwalle@kernel.org>
To: Tudor Ambarus <tudor.ambarus@linaro.org>,
	Pratyush Yadav <pratyush@kernel.org>,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>
Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,
	Michael Walle <mwalle@kernel.org>
Subject: [PATCH v1 2/6] mtd: spi-nor: get rid of non-power-of-2 page size handling
Date: Fri, 12 Apr 2024 15:44:01 +0200	[thread overview]
Message-ID: <20240412134405.381832-3-mwalle@kernel.org> (raw)
In-Reply-To: <20240412134405.381832-1-mwalle@kernel.org>

The Xilinx flashes were the only user of the page sized that were no
power of 2. Support for them were dropped, thus we can also get rid of
the special page size handling for it.

Signed-off-by: Michael Walle <mwalle@kernel.org>
---
 drivers/mtd/spi-nor/core.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index cbe5f92eb0af..fb76e0522665 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -2098,7 +2098,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 	size_t *retlen, const u_char *buf)
 {
 	struct spi_nor *nor = mtd_to_spi_nor(mtd);
-	size_t page_offset, page_remain, i;
+	size_t i;
 	ssize_t ret;
 	u32 page_size = nor->params->page_size;
 
@@ -2111,21 +2111,9 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 	for (i = 0; i < len; ) {
 		ssize_t written;
 		loff_t addr = to + i;
-
-		/*
-		 * If page_size is a power of two, the offset can be quickly
-		 * calculated with an AND operation. On the other cases we
-		 * need to do a modulus operation (more expensive).
-		 */
-		if (is_power_of_2(page_size)) {
-			page_offset = addr & (page_size - 1);
-		} else {
-			u64 aux = addr;
-
-			page_offset = do_div(aux, page_size);
-		}
+		size_t page_offset = addr & (page_size - 1);
 		/* the size of data remaining on the first page */
-		page_remain = min_t(size_t, page_size - page_offset, len - i);
+		size_t page_remain = min_t(size_t, page_size - page_offset, len - i);
 
 		addr = spi_nor_convert_addr(nor, addr);
 
@@ -3054,7 +3042,14 @@ static int spi_nor_init_params(struct spi_nor *nor)
 		spi_nor_init_params_deprecated(nor);
 	}
 
-	return spi_nor_late_init_params(nor);
+	ret = spi_nor_late_init_params(nor);
+	if (ret)
+		return ret;
+
+	if (WARN_ON(!is_power_of_2(nor->params->page_size)))
+		return -EINVAL;
+
+	return 0;
 }
 
 /** spi_nor_set_octal_dtr() - enable or disable Octal DTR I/O.
-- 
2.39.2


  parent reply	other threads:[~2024-04-12 13:44 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12 13:43 [PATCH v1 0/6] mtd: spi-nor: spring cleaning Michael Walle
2024-04-12 13:44 ` [PATCH v1 1/6] mtd: spi-nor: Remove support for Xilinx S3AN flashes Michael Walle
2024-04-12 13:53   ` Tudor Ambarus
2024-04-12 14:01     ` Michael Walle
2024-04-15 15:26       ` Pratyush Yadav
2024-04-16  4:45         ` Tudor Ambarus
2024-04-12 13:44 ` Michael Walle [this message]
2024-04-12 13:58   ` [PATCH v1 2/6] mtd: spi-nor: get rid of non-power-of-2 page size handling Tudor Ambarus
2024-04-15 15:49   ` Pratyush Yadav
2024-04-12 13:44 ` [PATCH v1 3/6] mtd: spi-nor: get rid of SPI_NOR_NO_FR Michael Walle
2024-04-12 14:00   ` Tudor Ambarus
2024-04-12 14:03     ` Michael Walle
2024-04-16  4:47       ` Tudor Ambarus
2024-04-17 13:39   ` Pratyush Yadav
2024-04-17 14:43     ` Michael Walle
2024-04-17 15:37       ` Pratyush Yadav
2024-04-17 15:45         ` Michael Walle
2024-04-17 15:54           ` Pratyush Yadav
2024-04-12 13:44 ` [PATCH v1 4/6] mtd: spi-nor: remove .setup() callback Michael Walle
2024-04-12 14:02   ` Tudor Ambarus
2024-04-12 13:44 ` [PATCH v1 5/6] mtd: spi-nor: simplify spi_nor_get_flash_info() Michael Walle
2024-04-17 14:18   ` Pratyush Yadav
2024-04-12 13:44 ` [RFC PATCH v1 6/6] mtd: spi-nor: introduce support for displaying deprecation message Michael Walle
2024-04-12 14:10   ` Tudor Ambarus
2024-04-17 14:36   ` Pratyush Yadav
2024-04-17 14:52     ` Michael Walle
2024-04-17 15:52       ` Pratyush Yadav
2024-04-18  9:57         ` Michael Walle
2024-04-18 11:20           ` Pratyush Yadav
2024-04-16  4:57 ` [PATCH v1 0/6] mtd: spi-nor: spring cleaning Tudor Ambarus
2024-04-17 15:02   ` Michael Walle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240412134405.381832-3-mwalle@kernel.org \
    --to=mwalle@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=tudor.ambarus@linaro.org \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox