Message ID | 20230807-mtd-flash-info-db-rework-v1-7-3d3d5bef4ba4@kernel.org |
---|---|
State | Changes Requested |
Delegated to: | Ambarus Tudor |
Headers | show |
Series | mtd: spi-nor: clean the flash_info database up | expand |
Hi Michael, mwalle@kernel.org wrote on Mon, 07 Aug 2023 15:21:01 +0200: > First, fixups might want to replace the n_banks parameter, thus we need > it in the (writable) parameter struct. Secondly, this way we can have a > default in the core and just skip setting the n_banks in the flash_info > database. Most of the flashes doesn't have more than one bank. > > Signed-off-by: Michael Walle <mwalle@kernel.org> > --- > drivers/mtd/spi-nor/core.c | 7 ++++--- > drivers/mtd/spi-nor/core.h | 2 ++ > 2 files changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c > index 138bc1e0a67c..ea94fb0da1e5 100644 > --- a/drivers/mtd/spi-nor/core.c > +++ b/drivers/mtd/spi-nor/core.c > @@ -2861,7 +2861,7 @@ static void spi_nor_init_flags(struct spi_nor *nor) > if (flags & NO_CHIP_ERASE) > nor->flags |= SNOR_F_NO_OP_CHIP_ERASE; > > - if (flags & SPI_NOR_RWW && nor->info->n_banks > 1 && > + if (flags & SPI_NOR_RWW && nor->params->n_banks > 1 && > !nor->controller_ops) > nor->flags |= SNOR_F_RWW; > } > @@ -2925,8 +2925,8 @@ static int spi_nor_late_init_params(struct spi_nor *nor) > if (nor->flags & SNOR_F_HAS_LOCK && !nor->params->locking_ops) > spi_nor_init_default_locking_ops(nor); > > - if (nor->info->n_banks > 1) > - params->bank_size = div64_u64(params->size, nor->info->n_banks); > + if (params->n_banks > 1) > + params->bank_size = div64_u64(params->size, params->n_banks); > > return 0; > } > @@ -2996,6 +2996,7 @@ static void spi_nor_init_default_params(struct spi_nor *nor) > params->size = info->size; > params->bank_size = params->size; > params->page_size = info->page_size ?: SPI_NOR_DEFAULT_PAGE_SIZE; > + params->n_banks = info->n_banks; > > if (!(info->flags & SPI_NOR_NO_FR)) { > /* Default to Fast Read for DT and non-DT platform devices. */ > diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h > index 25bc18197614..fe1ce232a6c8 100644 > --- a/drivers/mtd/spi-nor/core.h > +++ b/drivers/mtd/spi-nor/core.h > @@ -358,6 +358,7 @@ struct spi_nor_otp { > * in octal DTR mode. > * @rdsr_addr_nbytes: dummy address bytes needed for Read Status Register > * command in octal DTR mode. > + * @n_banks: the number of banks. just "number of banks" would make it, but that's nitpicking. > * @n_dice: number of dice in the flash memory. > * @vreg_offset: volatile register offset for each die. > * @hwcaps: describes the read and page program hardware > @@ -394,6 +395,7 @@ struct spi_nor_flash_parameter { > u8 addr_mode_nbytes; > u8 rdsr_dummy; > u8 rdsr_addr_nbytes; > + u8 n_banks; > u8 n_dice; > u32 *vreg_offset; > > Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com> Thanks, Miquèl
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 138bc1e0a67c..ea94fb0da1e5 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -2861,7 +2861,7 @@ static void spi_nor_init_flags(struct spi_nor *nor) if (flags & NO_CHIP_ERASE) nor->flags |= SNOR_F_NO_OP_CHIP_ERASE; - if (flags & SPI_NOR_RWW && nor->info->n_banks > 1 && + if (flags & SPI_NOR_RWW && nor->params->n_banks > 1 && !nor->controller_ops) nor->flags |= SNOR_F_RWW; } @@ -2925,8 +2925,8 @@ static int spi_nor_late_init_params(struct spi_nor *nor) if (nor->flags & SNOR_F_HAS_LOCK && !nor->params->locking_ops) spi_nor_init_default_locking_ops(nor); - if (nor->info->n_banks > 1) - params->bank_size = div64_u64(params->size, nor->info->n_banks); + if (params->n_banks > 1) + params->bank_size = div64_u64(params->size, params->n_banks); return 0; } @@ -2996,6 +2996,7 @@ static void spi_nor_init_default_params(struct spi_nor *nor) params->size = info->size; params->bank_size = params->size; params->page_size = info->page_size ?: SPI_NOR_DEFAULT_PAGE_SIZE; + params->n_banks = info->n_banks; if (!(info->flags & SPI_NOR_NO_FR)) { /* Default to Fast Read for DT and non-DT platform devices. */ diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index 25bc18197614..fe1ce232a6c8 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -358,6 +358,7 @@ struct spi_nor_otp { * in octal DTR mode. * @rdsr_addr_nbytes: dummy address bytes needed for Read Status Register * command in octal DTR mode. + * @n_banks: the number of banks. * @n_dice: number of dice in the flash memory. * @vreg_offset: volatile register offset for each die. * @hwcaps: describes the read and page program hardware @@ -394,6 +395,7 @@ struct spi_nor_flash_parameter { u8 addr_mode_nbytes; u8 rdsr_dummy; u8 rdsr_addr_nbytes; + u8 n_banks; u8 n_dice; u32 *vreg_offset;
First, fixups might want to replace the n_banks parameter, thus we need it in the (writable) parameter struct. Secondly, this way we can have a default in the core and just skip setting the n_banks in the flash_info database. Most of the flashes doesn't have more than one bank. Signed-off-by: Michael Walle <mwalle@kernel.org> --- drivers/mtd/spi-nor/core.c | 7 ++++--- drivers/mtd/spi-nor/core.h | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-)