From: <Tudor.Ambarus@microchip.com>
To: <boris.brezillon@collabora.com>, <marek.vasut@gmail.com>,
<vigneshr@ti.com>
Cc: Tudor.Ambarus@microchip.com, richard@nod.at,
linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,
miquel.raynal@bootlin.com, computersforpeace@gmail.com,
dwmw2@infradead.org
Subject: [PATCH 4/7] mtd: spi-nor: Split spi_nor_init_params()
Date: Wed, 31 Jul 2019 09:03:33 +0000 [thread overview]
Message-ID: <20190731090315.26798-5-tudor.ambarus@microchip.com> (raw)
In-Reply-To: <20190731090315.26798-1-tudor.ambarus@microchip.com>
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(-)
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);
--
2.9.5
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2019-07-31 9:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-31 9:03 [PATCH 0/7] mtd: spi-nor: move manuf out of the core - batch 1 Tudor.Ambarus
2019-07-31 9:03 ` [PATCH 1/7] mtd: spi-nor: Add default_init() hook to tweak flash parameters Tudor.Ambarus
2019-08-01 6:24 ` Boris Brezillon
2019-07-31 9:03 ` [PATCH 2/7] mtd: spi-nor: Add a default_init() fixup hook for gd25q256 Tudor.Ambarus
2019-07-31 9:03 ` [PATCH 3/7] mtd: spi_nor: Rework quad_enable() Tudor.Ambarus
2019-08-01 6:29 ` Boris Brezillon
2019-08-05 7:43 ` Tudor.Ambarus
2019-07-31 9:03 ` Tudor.Ambarus [this message]
2019-08-01 6:31 ` [PATCH 4/7] mtd: spi-nor: Split spi_nor_init_params() Boris Brezillon
2019-07-31 9:03 ` [PATCH 5/7] mtd: spi-nor: Create a ->set_4byte() method Tudor.Ambarus
2019-07-31 9:03 ` [PATCH 6/7] mtd: spi-nor: Rework the SPI NOR lock/unlock logic Tudor.Ambarus
2019-08-04 14:36 ` Vignesh Raghavendra
2019-08-05 8:00 ` Tudor.Ambarus
2019-08-05 11:29 ` Vignesh Raghavendra
2019-07-31 9:03 ` [PATCH 7/7] mtd: spi-nor: Rework the disabling of write protection at init Tudor.Ambarus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190731090315.26798-5-tudor.ambarus@microchip.com \
--to=tudor.ambarus@microchip.com \
--cc=boris.brezillon@collabora.com \
--cc=computersforpeace@gmail.com \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).