[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190801083151.5c96741d@collabora.com>
Date: Thu, 1 Aug 2019 08:31:51 +0200
From: Boris Brezillon <boris.brezillon@...labora.com>
To: <Tudor.Ambarus@...rochip.com>
Cc: <marek.vasut@...il.com>, <vigneshr@...com>, <dwmw2@...radead.org>,
<computersforpeace@...il.com>, <miquel.raynal@...tlin.com>,
<richard@....at>, <linux-mtd@...ts.infradead.org>,
<linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 4/7] mtd: spi-nor: Split spi_nor_init_params()
On Wed, 31 Jul 2019 09:03:33 +0000
<Tudor.Ambarus@...rochip.com> wrote:
> From: Tudor Ambarus <tudor.ambarus@...rochip.com>
>
> Add functions to delimit what the chunks of code do:
>
> static void spi_nor_init_params()
> {
> spi_nor_default_init_params()
> spi_nor_manufacturer_init_params()
> spi_nor_sfdp_init_params()
> }
>
> spi_nor_init_params() becomes of type void, as all its children
> return void.
>
> Signed-off-by: Tudor Ambarus <tudor.ambarus@...rochip.com>
Reviewed-by: Boris Brezillon <boris.brezillon@...labora.com>
> ---
> drivers/mtd/spi-nor/spi-nor.c | 58 ++++++++++++++++++++++++-------------------
> 1 file changed, 32 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index a906c36260c8..b2e72668e7ab 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -4312,6 +4312,25 @@ static void spi_nor_mfr_init_params(struct spi_nor *nor,
> }
> }
>
> +static void spi_nor_sfdp_init_params(struct spi_nor *nor,
> + struct spi_nor_flash_parameter *params)
> +{
> + struct spi_nor_flash_parameter sfdp_params;
> + struct spi_nor_erase_map prev_map;
> +
> + memcpy(&sfdp_params, params, sizeof(sfdp_params));
> + memcpy(&prev_map, &nor->erase_map, sizeof(prev_map));
> +
> + if (spi_nor_parse_sfdp(nor, &sfdp_params)) {
> + nor->addr_width = 0;
> + nor->flags &= ~SNOR_F_4B_OPCODES;
> + /* restore previous erase map */
> + memcpy(&nor->erase_map, &prev_map, sizeof(nor->erase_map));
> + } else {
> + memcpy(params, &sfdp_params, sizeof(*params));
> + }
> +}
> +
> static void
> spi_nor_manufacturer_init_params(struct spi_nor *nor,
> struct spi_nor_flash_parameter *params)
> @@ -4323,8 +4342,8 @@ spi_nor_manufacturer_init_params(struct spi_nor *nor,
> return nor->info->fixups->default_init(nor, params);
> }
>
> -static int spi_nor_init_params(struct spi_nor *nor,
> - struct spi_nor_flash_parameter *params)
> +static void spi_nor_default_init_params(struct spi_nor *nor,
> + struct spi_nor_flash_parameter *params)
> {
> struct spi_nor_erase_map *map = &nor->erase_map;
> const struct flash_info *info = nor->info;
> @@ -4397,29 +4416,18 @@ static int spi_nor_init_params(struct spi_nor *nor,
> spi_nor_set_erase_type(&map->erase_type[i], info->sector_size,
> SPINOR_OP_SE);
> spi_nor_init_uniform_erase_map(map, erase_mask, params->size);
> +}
>
> - spi_nor_manufacturer_init_params(nor, params);
> -
> - if ((info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)) &&
> - !(info->flags & SPI_NOR_SKIP_SFDP)) {
> - struct spi_nor_flash_parameter sfdp_params;
> - struct spi_nor_erase_map prev_map;
> -
> - memcpy(&sfdp_params, params, sizeof(sfdp_params));
> - memcpy(&prev_map, &nor->erase_map, sizeof(prev_map));
> +static void spi_nor_init_params(struct spi_nor *nor,
> + struct spi_nor_flash_parameter *params)
> +{
> + spi_nor_default_init_params(nor, params);
>
> - if (spi_nor_parse_sfdp(nor, &sfdp_params)) {
> - nor->addr_width = 0;
> - nor->flags &= ~SNOR_F_4B_OPCODES;
> - /* restore previous erase map */
> - memcpy(&nor->erase_map, &prev_map,
> - sizeof(nor->erase_map));
> - } else {
> - memcpy(params, &sfdp_params, sizeof(*params));
> - }
> - }
> + spi_nor_manufacturer_init_params(nor, params);
>
> - return 0;
> + if ((nor->info->flags & (SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ)) &&
> + !(nor->info->flags & SPI_NOR_SKIP_SFDP))
> + spi_nor_sfdp_init_params(nor, params);
> }
>
> static int spi_nor_select_read(struct spi_nor *nor,
> @@ -4794,10 +4802,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
> /* Kept only for backward compatibility purpose. */
> nor->quad_enable = spansion_quad_enable;
>
> - /* Parse the Serial Flash Discoverable Parameters table. */
> - ret = spi_nor_init_params(nor, ¶ms);
> - if (ret)
> - return ret;
> + /* Init flash parameters based on flash_info struct and SFDP */
> + spi_nor_init_params(nor, ¶ms);
>
> if (!mtd->name)
> mtd->name = dev_name(dev);
Powered by blists - more mailing lists