Skip to content

Commit 9539d12

Browse files
mwallePratyush Yadav
authored andcommitted
mtd: spi-nor: get rid of non-power-of-2 page size handling
The Xilinx flashes were the only users of page sizes that were not power of 2. Support for them has been dropped, thus we can also get rid of the special page size handling for it. Signed-off-by: Michael Walle <mwalle@kernel.org> Acked-by: Tudor Ambarus <tudor.ambarus@linaro.org> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> [pratyush@kernel.org: fixup minor typos and grammar in commit message] Signed-off-by: Pratyush Yadav <pratyush@kernel.org> Link: https://lore.kernel.org/r/20240419141249.609534-3-mwalle@kernel.org
1 parent be1d1a7 commit 9539d12

File tree

2 files changed

+11
-34
lines changed

2 files changed

+11
-34
lines changed

drivers/mtd/spi-nor/core.c

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,23 +1463,13 @@ static void spi_nor_unlock_and_unprep_rd(struct spi_nor *nor, loff_t start, size
14631463
spi_nor_unprep(nor);
14641464
}
14651465

1466-
static u32 spi_nor_convert_addr(struct spi_nor *nor, loff_t addr)
1467-
{
1468-
if (!nor->params->convert_addr)
1469-
return addr;
1470-
1471-
return nor->params->convert_addr(nor, addr);
1472-
}
1473-
14741466
/*
14751467
* Initiate the erasure of a single sector
14761468
*/
14771469
int spi_nor_erase_sector(struct spi_nor *nor, u32 addr)
14781470
{
14791471
int i;
14801472

1481-
addr = spi_nor_convert_addr(nor, addr);
1482-
14831473
if (nor->spimem) {
14841474
struct spi_mem_op op =
14851475
SPI_NOR_SECTOR_ERASE_OP(nor->erase_opcode,
@@ -2064,8 +2054,6 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
20642054
while (len) {
20652055
loff_t addr = from;
20662056

2067-
addr = spi_nor_convert_addr(nor, addr);
2068-
20692057
ret = spi_nor_read_data(nor, addr, len, buf);
20702058
if (ret == 0) {
20712059
/* We shouldn't see 0-length reads */
@@ -2098,7 +2086,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
20982086
size_t *retlen, const u_char *buf)
20992087
{
21002088
struct spi_nor *nor = mtd_to_spi_nor(mtd);
2101-
size_t page_offset, page_remain, i;
2089+
size_t i;
21022090
ssize_t ret;
21032091
u32 page_size = nor->params->page_size;
21042092

@@ -2111,23 +2099,9 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
21112099
for (i = 0; i < len; ) {
21122100
ssize_t written;
21132101
loff_t addr = to + i;
2114-
2115-
/*
2116-
* If page_size is a power of two, the offset can be quickly
2117-
* calculated with an AND operation. On the other cases we
2118-
* need to do a modulus operation (more expensive).
2119-
*/
2120-
if (is_power_of_2(page_size)) {
2121-
page_offset = addr & (page_size - 1);
2122-
} else {
2123-
u64 aux = addr;
2124-
2125-
page_offset = do_div(aux, page_size);
2126-
}
2102+
size_t page_offset = addr & (page_size - 1);
21272103
/* the size of data remaining on the first page */
2128-
page_remain = min_t(size_t, page_size - page_offset, len - i);
2129-
2130-
addr = spi_nor_convert_addr(nor, addr);
2104+
size_t page_remain = min_t(size_t, page_size - page_offset, len - i);
21312105

21322106
ret = spi_nor_lock_device(nor);
21332107
if (ret)
@@ -3054,7 +3028,14 @@ static int spi_nor_init_params(struct spi_nor *nor)
30543028
spi_nor_init_params_deprecated(nor);
30553029
}
30563030

3057-
return spi_nor_late_init_params(nor);
3031+
ret = spi_nor_late_init_params(nor);
3032+
if (ret)
3033+
return ret;
3034+
3035+
if (WARN_ON(!is_power_of_2(nor->params->page_size)))
3036+
return -EINVAL;
3037+
3038+
return 0;
30583039
}
30593040

30603041
/** spi_nor_set_octal_dtr() - enable or disable Octal DTR I/O.

drivers/mtd/spi-nor/core.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,6 @@ struct spi_nor_otp {
366366
* @set_octal_dtr: enables or disables SPI NOR octal DTR mode.
367367
* @quad_enable: enables SPI NOR quad mode.
368368
* @set_4byte_addr_mode: puts the SPI NOR in 4 byte addressing mode.
369-
* @convert_addr: converts an absolute address into something the flash
370-
* will understand. Particularly useful when pagesize is
371-
* not a power-of-2.
372369
* @setup: (optional) configures the SPI NOR memory. Useful for
373370
* SPI NOR flashes that have peculiarities to the SPI NOR
374371
* standard e.g. different opcodes, specific address
@@ -403,7 +400,6 @@ struct spi_nor_flash_parameter {
403400
int (*set_octal_dtr)(struct spi_nor *nor, bool enable);
404401
int (*quad_enable)(struct spi_nor *nor);
405402
int (*set_4byte_addr_mode)(struct spi_nor *nor, bool enable);
406-
u32 (*convert_addr)(struct spi_nor *nor, u32 addr);
407403
int (*setup)(struct spi_nor *nor, const struct spi_nor_hwcaps *hwcaps);
408404
int (*ready)(struct spi_nor *nor);
409405

0 commit comments

Comments
 (0)