Commit 5854d4a6 authored by Tudor Ambarus's avatar Tudor Ambarus

mtd: spi-nor: Get rid of nor->page_size

nor->page_size duplicated what nor->params->page_size indicates
for no good reason. page_size is a flash parameter of fixed value
and it is better suited to be found in nor->params->page_size.
Signed-off-by: default avatarTudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: default avatarPratyush Yadav <p.yadav@ti.com>
Reviewed-by: default avatarMichael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20211029172633.886453-5-tudor.ambarus@microchip.com
parent 7158c86e
...@@ -1952,6 +1952,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1952,6 +1952,7 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
struct spi_nor *nor = mtd_to_spi_nor(mtd); struct spi_nor *nor = mtd_to_spi_nor(mtd);
size_t page_offset, page_remain, i; size_t page_offset, page_remain, i;
ssize_t ret; ssize_t ret;
u32 page_size = nor->params->page_size;
dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len); dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
...@@ -1968,16 +1969,15 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -1968,16 +1969,15 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
* calculated with an AND operation. On the other cases we * calculated with an AND operation. On the other cases we
* need to do a modulus operation (more expensive). * need to do a modulus operation (more expensive).
*/ */
if (is_power_of_2(nor->page_size)) { if (is_power_of_2(page_size)) {
page_offset = addr & (nor->page_size - 1); page_offset = addr & (page_size - 1);
} else { } else {
uint64_t aux = addr; uint64_t aux = addr;
page_offset = do_div(aux, nor->page_size); page_offset = do_div(aux, page_size);
} }
/* the size of data remaining on the first page */ /* the size of data remaining on the first page */
page_remain = min_t(size_t, page_remain = min_t(size_t, page_size - page_offset, len - i);
nor->page_size - page_offset, len - i);
addr = spi_nor_convert_addr(nor, addr); addr = spi_nor_convert_addr(nor, addr);
...@@ -3094,7 +3094,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, ...@@ -3094,7 +3094,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
* We need the bounce buffer early to read/write registers when going * We need the bounce buffer early to read/write registers when going
* through the spi-mem layer (buffers have to be DMA-able). * through the spi-mem layer (buffers have to be DMA-able).
* For spi-mem drivers, we'll reallocate a new buffer if * For spi-mem drivers, we'll reallocate a new buffer if
* nor->page_size turns out to be greater than PAGE_SIZE (which * nor->params->page_size turns out to be greater than PAGE_SIZE (which
* shouldn't happen before long since NOR pages are usually less * shouldn't happen before long since NOR pages are usually less
* than 1KB) after spi_nor_scan() returns. * than 1KB) after spi_nor_scan() returns.
*/ */
...@@ -3170,8 +3170,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, ...@@ -3170,8 +3170,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
mtd->flags |= MTD_NO_ERASE; mtd->flags |= MTD_NO_ERASE;
mtd->dev.parent = dev; mtd->dev.parent = dev;
nor->page_size = nor->params->page_size; mtd->writebufsize = nor->params->page_size;
mtd->writebufsize = nor->page_size;
if (of_property_read_bool(np, "broken-flash-reset")) if (of_property_read_bool(np, "broken-flash-reset"))
nor->flags |= SNOR_F_BROKEN_RESET; nor->flags |= SNOR_F_BROKEN_RESET;
...@@ -3340,8 +3339,8 @@ static int spi_nor_probe(struct spi_mem *spimem) ...@@ -3340,8 +3339,8 @@ static int spi_nor_probe(struct spi_mem *spimem)
* and add this logic so that if anyone ever adds support for such * and add this logic so that if anyone ever adds support for such
* a NOR we don't end up with buffer overflows. * a NOR we don't end up with buffer overflows.
*/ */
if (nor->page_size > PAGE_SIZE) { if (nor->params->page_size > PAGE_SIZE) {
nor->bouncebuf_size = nor->page_size; nor->bouncebuf_size = nor->params->page_size;
devm_kfree(nor->dev, nor->bouncebuf); devm_kfree(nor->dev, nor->bouncebuf);
nor->bouncebuf = devm_kmalloc(nor->dev, nor->bouncebuf = devm_kmalloc(nor->dev,
nor->bouncebuf_size, nor->bouncebuf_size,
......
...@@ -28,11 +28,12 @@ static const struct flash_info xilinx_parts[] = { ...@@ -28,11 +28,12 @@ static const struct flash_info xilinx_parts[] = {
*/ */
static u32 s3an_convert_addr(struct spi_nor *nor, u32 addr) static u32 s3an_convert_addr(struct spi_nor *nor, u32 addr)
{ {
u32 page_size = nor->params->page_size;
u32 offset, page; u32 offset, page;
offset = addr % nor->page_size; offset = addr % page_size;
page = addr / nor->page_size; page = addr / page_size;
page <<= (nor->page_size > 512) ? 10 : 9; page <<= (page_size > 512) ? 10 : 9;
return page | offset; return page | offset;
} }
...@@ -40,6 +41,7 @@ static u32 s3an_convert_addr(struct spi_nor *nor, u32 addr) ...@@ -40,6 +41,7 @@ static u32 s3an_convert_addr(struct spi_nor *nor, u32 addr)
static int xilinx_nor_setup(struct spi_nor *nor, static int xilinx_nor_setup(struct spi_nor *nor,
const struct spi_nor_hwcaps *hwcaps) const struct spi_nor_hwcaps *hwcaps)
{ {
u32 page_size;
int ret; int ret;
ret = spi_nor_xread_sr(nor, nor->bouncebuf); ret = spi_nor_xread_sr(nor, nor->bouncebuf);
...@@ -64,10 +66,11 @@ static int xilinx_nor_setup(struct spi_nor *nor, ...@@ -64,10 +66,11 @@ static int xilinx_nor_setup(struct spi_nor *nor,
*/ */
if (nor->bouncebuf[0] & XSR_PAGESIZE) { if (nor->bouncebuf[0] & XSR_PAGESIZE) {
/* Flash in Power of 2 mode */ /* Flash in Power of 2 mode */
nor->page_size = (nor->page_size == 264) ? 256 : 512; page_size = (nor->params->page_size == 264) ? 256 : 512;
nor->mtd.writebufsize = nor->page_size; nor->params->page_size = page_size;
nor->mtd.size = 8 * nor->page_size * nor->info->n_sectors; nor->mtd.writebufsize = page_size;
nor->mtd.erasesize = 8 * nor->page_size; nor->mtd.size = 8 * page_size * nor->info->n_sectors;
nor->mtd.erasesize = 8 * page_size;
} else { } else {
/* Flash in Default addressing mode */ /* Flash in Default addressing mode */
nor->params->convert_addr = s3an_convert_addr; nor->params->convert_addr = s3an_convert_addr;
......
...@@ -371,7 +371,6 @@ struct spi_nor_flash_parameter; ...@@ -371,7 +371,6 @@ struct spi_nor_flash_parameter;
* @bouncebuf_size: size of the bounce buffer * @bouncebuf_size: size of the bounce buffer
* @info: SPI NOR part JEDEC MFR ID and other info * @info: SPI NOR part JEDEC MFR ID and other info
* @manufacturer: SPI NOR manufacturer * @manufacturer: SPI NOR manufacturer
* @page_size: the page size of the SPI NOR
* @addr_width: number of address bytes * @addr_width: number of address bytes
* @erase_opcode: the opcode for erasing a sector * @erase_opcode: the opcode for erasing a sector
* @read_opcode: the read opcode * @read_opcode: the read opcode
...@@ -401,7 +400,6 @@ struct spi_nor { ...@@ -401,7 +400,6 @@ struct spi_nor {
size_t bouncebuf_size; size_t bouncebuf_size;
const struct flash_info *info; const struct flash_info *info;
const struct spi_nor_manufacturer *manufacturer; const struct spi_nor_manufacturer *manufacturer;
u32 page_size;
u8 addr_width; u8 addr_width;
u8 erase_opcode; u8 erase_opcode;
u8 read_opcode; u8 read_opcode;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment