[4/7] mtd: spi-nor: Split spi_nor_init_params()
diff mbox series

Message ID 20190731090315.26798-5-tudor.ambarus@microchip.com
State New
Delegated to: Vignesh R
Headers show
Series
  • mtd: spi-nor: move manuf out of the core - batch 1
Related show

Commit Message

Ambarus Tudor July 31, 2019, 9:03 a.m. UTC
From: Tudor Ambarus <tudor.ambarus@microchip.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@microchip.com>
---
 drivers/mtd/spi-nor/spi-nor.c | 58 ++++++++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 26 deletions(-)

Comments

Boris Brezillon Aug. 1, 2019, 6:31 a.m. UTC | #1
On Wed, 31 Jul 2019 09:03:33 +0000
<Tudor.Ambarus@microchip.com> wrote:

> From: Tudor Ambarus <tudor.ambarus@microchip.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@microchip.com>

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.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, &params);
> -	if (ret)
> -		return ret;
> +	/* Init flash parameters based on flash_info struct and SFDP */
> +	spi_nor_init_params(nor, &params);
>  
>  	if (!mtd->name)
>  		mtd->name = dev_name(dev);

Patch
diff mbox series

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, &params);
-	if (ret)
-		return ret;
+	/* Init flash parameters based on flash_info struct and SFDP */
+	spi_nor_init_params(nor, &params);
 
 	if (!mtd->name)
 		mtd->name = dev_name(dev);