* [PATCH v2 0/3] mtd: spi-nor: move manuf out of the core - batch 3
@ 2019-08-24 12:19 Tudor.Ambarus
2019-08-24 12:19 ` [PATCH v2 1/3] mtd: spi-nor: Bring flash params init together Tudor.Ambarus
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Tudor.Ambarus @ 2019-08-24 12:19 UTC (permalink / raw)
To: boris.brezillon, marek.vasut, vigneshr, miquel.raynal, richard,
linux-mtd, linux-kernel
Cc: Tudor.Ambarus
From: Tudor Ambarus <tudor.ambarus@microchip.com>
Trim spi_nor_scan() huge function.
Depends on 'mtd: spi-nor: move manuf out of the core - batch 2' series:
https://patchwork.ozlabs.org/project/linux-mtd/list/?series=127122
which depends on:
Depends on 'mtd: spi-nor: move manuf out of the core - batch 1' series:
https://patchwork.ozlabs.org/project/linux-mtd/list/?series=127121
which depends on:
Depends on 'mtd: spi-nor: move manuf out of the core - batch 0' series:
https://patchwork.ozlabs.org/project/linux-mtd/list/?series=127030
All batches can be found at:
https://github.com/ambarus/linux-0day/tree/spi-nor/manuf-drv
Tudor Ambarus (3):
mtd: spi-nor: Bring flash params init together
mtd: spi_nor: Introduce spi_nor_set_addr_width()
mtd: spi-nor: Introduce spi_nor_get_flash_info()
drivers/mtd/spi-nor/spi-nor.c | 155 +++++++++++++++++++++++-------------------
1 file changed, 85 insertions(+), 70 deletions(-)
--
2.9.5
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] mtd: spi-nor: Bring flash params init together
2019-08-24 12:19 [PATCH v2 0/3] mtd: spi-nor: move manuf out of the core - batch 3 Tudor.Ambarus
@ 2019-08-24 12:19 ` Tudor.Ambarus
2019-08-25 12:39 ` Boris Brezillon
2019-08-24 12:19 ` [PATCH v2 2/3] mtd: spi_nor: Introduce spi_nor_set_addr_width() Tudor.Ambarus
2019-08-24 12:19 ` [PATCH v2 3/3] mtd: spi-nor: Introduce spi_nor_get_flash_info() Tudor.Ambarus
2 siblings, 1 reply; 5+ messages in thread
From: Tudor.Ambarus @ 2019-08-24 12:19 UTC (permalink / raw)
To: boris.brezillon, marek.vasut, vigneshr, miquel.raynal, richard,
linux-mtd, linux-kernel
Cc: Tudor.Ambarus
From: Tudor Ambarus <tudor.ambarus@microchip.com>
Bring all flash parameters default initialization in
spi_nor_legacy_params_init().
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
---
drivers/mtd/spi-nor/spi-nor.c | 29 +++++++++++------------------
1 file changed, 11 insertions(+), 18 deletions(-)
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index e76c23d1c54a..7e6da0ace2c7 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -4469,6 +4469,7 @@ static void spi_nor_legacy_init_params(struct spi_nor *nor)
struct spi_nor_flash_parameter *params = &nor->params;
struct spi_nor_erase_map *map = ¶ms->erase_map;
const struct flash_info *info = nor->info;
+ struct device_node *np = spi_nor_get_flash_node(nor);
u8 i, erase_mask;
/* Initialize legacy flash parameters and settings. */
@@ -4480,18 +4481,25 @@ static void spi_nor_legacy_init_params(struct spi_nor *nor)
params->size = (u64)info->sector_size * info->n_sectors;
params->page_size = info->page_size;
+ if (!(info->flags & SPI_NOR_NO_FR)) {
+ /* Default to Fast Read for DT and non-DT platform devices. */
+ params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
+
+ /* Mask out Fast Read if not requested at DT instantiation. */
+ if (np && !of_property_read_bool(np, "m25p,fast-read"))
+ params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
+ }
+
/* (Fast) Read settings. */
params->hwcaps.mask |= SNOR_HWCAPS_READ;
spi_nor_set_read_settings(¶ms->reads[SNOR_CMD_READ],
0, 0, SPINOR_OP_READ,
SNOR_PROTO_1_1_1);
- if (!(info->flags & SPI_NOR_NO_FR)) {
- params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
+ if (params->hwcaps.mask & SNOR_HWCAPS_READ_FAST)
spi_nor_set_read_settings(¶ms->reads[SNOR_CMD_READ_FAST],
0, 8, SPINOR_OP_READ_FAST,
SNOR_PROTO_1_1_1);
- }
if (info->flags & SPI_NOR_DUAL_READ) {
params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_2;
@@ -4897,24 +4905,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
nor->page_size = params->page_size;
mtd->writebufsize = nor->page_size;
- if (np) {
- /* If we were instantiated by DT, use it */
- if (of_property_read_bool(np, "m25p,fast-read"))
- params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
- else
- params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
- } else {
- /* If we weren't instantiated by DT, default to fast-read */
- params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
- }
-
if (of_property_read_bool(np, "broken-flash-reset"))
nor->flags |= SNOR_F_BROKEN_RESET;
- /* Some devices cannot do fast-read, no matter what DT tells us */
- if (info->flags & SPI_NOR_NO_FR)
- params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
-
/*
* Configure the SPI memory:
* - select op codes for (Fast) Read, Page Program and Sector Erase.
--
2.9.5
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] mtd: spi_nor: Introduce spi_nor_set_addr_width()
2019-08-24 12:19 [PATCH v2 0/3] mtd: spi-nor: move manuf out of the core - batch 3 Tudor.Ambarus
2019-08-24 12:19 ` [PATCH v2 1/3] mtd: spi-nor: Bring flash params init together Tudor.Ambarus
@ 2019-08-24 12:19 ` Tudor.Ambarus
2019-08-24 12:19 ` [PATCH v2 3/3] mtd: spi-nor: Introduce spi_nor_get_flash_info() Tudor.Ambarus
2 siblings, 0 replies; 5+ messages in thread
From: Tudor.Ambarus @ 2019-08-24 12:19 UTC (permalink / raw)
To: boris.brezillon, marek.vasut, vigneshr, miquel.raynal, richard,
linux-mtd, linux-kernel
Cc: Tudor.Ambarus
From: Tudor Ambarus <tudor.ambarus@microchip.com>
Parsing of flash parameters were interleaved with setting of the
nor addr width. Dedicate a function for setting nor addr width.
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/mtd/spi-nor/spi-nor.c | 50 ++++++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 20 deletions(-)
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 7e6da0ace2c7..449d2c4918ca 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -4780,6 +4780,33 @@ static const struct flash_info *spi_nor_match_id(const char *name)
return NULL;
}
+static int spi_nor_set_addr_width(struct spi_nor *nor)
+{
+ if (nor->addr_width) {
+ /* already configured from SFDP */
+ } else if (nor->info->addr_width) {
+ nor->addr_width = nor->info->addr_width;
+ } else if (nor->mtd.size > 0x1000000) {
+ /* enable 4-byte addressing if the device exceeds 16MiB */
+ nor->addr_width = 4;
+ } else {
+ nor->addr_width = 3;
+ }
+
+ if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) {
+ dev_err(nor->dev, "address width is too large: %u\n",
+ nor->addr_width);
+ return -EINVAL;
+ }
+
+ /* Set 4byte opcodes when possible. */
+ if (nor->addr_width == 4 && nor->flags & SNOR_F_4B_OPCODES &&
+ !(nor->flags & SNOR_F_HAS_4BAIT))
+ spi_nor_set_4byte_opcodes(nor);
+
+ return 0;
+}
+
int spi_nor_scan(struct spi_nor *nor, const char *name,
const struct spi_nor_hwcaps *hwcaps)
{
@@ -4918,29 +4945,12 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
if (ret)
return ret;
- if (nor->addr_width) {
- /* already configured from SFDP */
- } else if (info->addr_width) {
- nor->addr_width = info->addr_width;
- } else if (mtd->size > 0x1000000) {
- /* enable 4-byte addressing if the device exceeds 16MiB */
- nor->addr_width = 4;
- } else {
- nor->addr_width = 3;
- }
-
if (info->flags & SPI_NOR_4B_OPCODES)
nor->flags |= SNOR_F_4B_OPCODES;
- if (nor->addr_width == 4 && nor->flags & SNOR_F_4B_OPCODES &&
- !(nor->flags & SNOR_F_HAS_4BAIT))
- spi_nor_set_4byte_opcodes(nor);
-
- if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) {
- dev_err(dev, "address width is too large: %u\n",
- nor->addr_width);
- return -EINVAL;
- }
+ ret = spi_nor_set_addr_width(nor);
+ if (ret)
+ return ret;
/* Send all the required SPI flash commands to initialize device */
ret = spi_nor_init(nor);
--
2.9.5
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] mtd: spi-nor: Introduce spi_nor_get_flash_info()
2019-08-24 12:19 [PATCH v2 0/3] mtd: spi-nor: move manuf out of the core - batch 3 Tudor.Ambarus
2019-08-24 12:19 ` [PATCH v2 1/3] mtd: spi-nor: Bring flash params init together Tudor.Ambarus
2019-08-24 12:19 ` [PATCH v2 2/3] mtd: spi_nor: Introduce spi_nor_set_addr_width() Tudor.Ambarus
@ 2019-08-24 12:19 ` Tudor.Ambarus
2 siblings, 0 replies; 5+ messages in thread
From: Tudor.Ambarus @ 2019-08-24 12:19 UTC (permalink / raw)
To: boris.brezillon, marek.vasut, vigneshr, miquel.raynal, richard,
linux-mtd, linux-kernel
Cc: Tudor.Ambarus
From: Tudor Ambarus <tudor.ambarus@microchip.com>
Dedicate a function for getting the pointer to the flash_info
const struct. Trim a bit the spi_nor_scan() huge function.
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/mtd/spi-nor/spi-nor.c | 76 +++++++++++++++++++++++++------------------
1 file changed, 44 insertions(+), 32 deletions(-)
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 449d2c4918ca..1896d36a7d11 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -4807,10 +4807,50 @@ static int spi_nor_set_addr_width(struct spi_nor *nor)
return 0;
}
+static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
+ const char *name)
+{
+ const struct flash_info *info = NULL;
+
+ if (name)
+ info = spi_nor_match_id(name);
+ /* Try to auto-detect if chip name wasn't specified or not found */
+ if (!info)
+ info = spi_nor_read_id(nor);
+ if (IS_ERR_OR_NULL(info))
+ return ERR_PTR(-ENOENT);
+
+ /*
+ * If caller has specified name of flash model that can normally be
+ * detected using JEDEC, let's verify it.
+ */
+ if (name && info->id_len) {
+ const struct flash_info *jinfo;
+
+ jinfo = spi_nor_read_id(nor);
+ if (IS_ERR(jinfo)) {
+ return jinfo;
+ } else if (jinfo != info) {
+ /*
+ * JEDEC knows better, so overwrite platform ID. We
+ * can't trust partitions any longer, but we'll let
+ * mtd apply them anyway, since some partitions may be
+ * marked read-only, and we don't want to lose that
+ * information, even if it's not 100% accurate.
+ */
+ dev_warn(nor->dev, "found %s, expected %s\n",
+ jinfo->name, info->name);
+ info = jinfo;
+ }
+ }
+
+ return info;
+}
+
int spi_nor_scan(struct spi_nor *nor, const char *name,
const struct spi_nor_hwcaps *hwcaps)
{
- const struct flash_info *info = NULL;
+ const struct flash_info *info;
struct device *dev = nor->dev;
struct mtd_info *mtd = &nor->mtd;
struct device_node *np = spi_nor_get_flash_node(nor);
@@ -4841,37 +4881,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
if (!nor->bouncebuf)
return -ENOMEM;
- if (name)
- info = spi_nor_match_id(name);
- /* Try to auto-detect if chip name wasn't specified or not found */
- if (!info)
- info = spi_nor_read_id(nor);
- if (IS_ERR_OR_NULL(info))
- return -ENOENT;
-
- /*
- * If caller has specified name of flash model that can normally be
- * detected using JEDEC, let's verify it.
- */
- if (name && info->id_len) {
- const struct flash_info *jinfo;
-
- jinfo = spi_nor_read_id(nor);
- if (IS_ERR(jinfo)) {
- return PTR_ERR(jinfo);
- } else if (jinfo != info) {
- /*
- * JEDEC knows better, so overwrite platform ID. We
- * can't trust partitions any longer, but we'll let
- * mtd apply them anyway, since some partitions may be
- * marked read-only, and we don't want to lose that
- * information, even if it's not 100% accurate.
- */
- dev_warn(dev, "found %s, expected %s\n",
- jinfo->name, info->name);
- info = jinfo;
- }
- }
+ info = spi_nor_get_flash_info(nor, name);
+ if (IS_ERR(info))
+ return PTR_ERR(info);
nor->info = info;
--
2.9.5
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/3] mtd: spi-nor: Bring flash params init together
2019-08-24 12:19 ` [PATCH v2 1/3] mtd: spi-nor: Bring flash params init together Tudor.Ambarus
@ 2019-08-25 12:39 ` Boris Brezillon
0 siblings, 0 replies; 5+ messages in thread
From: Boris Brezillon @ 2019-08-25 12:39 UTC (permalink / raw)
To: Tudor.Ambarus
Cc: vigneshr, richard, linux-kernel, marek.vasut, linux-mtd, miquel.raynal
On Sat, 24 Aug 2019 12:19:20 +0000
<Tudor.Ambarus@microchip.com> wrote:
> From: Tudor Ambarus <tudor.ambarus@microchip.com>
>
> Bring all flash parameters default initialization in
> spi_nor_legacy_params_init().
>
> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> drivers/mtd/spi-nor/spi-nor.c | 29 +++++++++++------------------
> 1 file changed, 11 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index e76c23d1c54a..7e6da0ace2c7 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -4469,6 +4469,7 @@ static void spi_nor_legacy_init_params(struct spi_nor *nor)
> struct spi_nor_flash_parameter *params = &nor->params;
> struct spi_nor_erase_map *map = ¶ms->erase_map;
> const struct flash_info *info = nor->info;
> + struct device_node *np = spi_nor_get_flash_node(nor);
> u8 i, erase_mask;
>
> /* Initialize legacy flash parameters and settings. */
> @@ -4480,18 +4481,25 @@ static void spi_nor_legacy_init_params(struct spi_nor *nor)
> params->size = (u64)info->sector_size * info->n_sectors;
> params->page_size = info->page_size;
>
> + if (!(info->flags & SPI_NOR_NO_FR)) {
> + /* Default to Fast Read for DT and non-DT platform devices. */
> + params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
> +
> + /* Mask out Fast Read if not requested at DT instantiation. */
> + if (np && !of_property_read_bool(np, "m25p,fast-read"))
> + params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
> + }
> +
> /* (Fast) Read settings. */
> params->hwcaps.mask |= SNOR_HWCAPS_READ;
> spi_nor_set_read_settings(¶ms->reads[SNOR_CMD_READ],
> 0, 0, SPINOR_OP_READ,
> SNOR_PROTO_1_1_1);
>
> - if (!(info->flags & SPI_NOR_NO_FR)) {
> - params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
> + if (params->hwcaps.mask & SNOR_HWCAPS_READ_FAST)
> spi_nor_set_read_settings(¶ms->reads[SNOR_CMD_READ_FAST],
> 0, 8, SPINOR_OP_READ_FAST,
> SNOR_PROTO_1_1_1);
> - }
>
> if (info->flags & SPI_NOR_DUAL_READ) {
> params->hwcaps.mask |= SNOR_HWCAPS_READ_1_1_2;
> @@ -4897,24 +4905,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
> nor->page_size = params->page_size;
> mtd->writebufsize = nor->page_size;
>
> - if (np) {
> - /* If we were instantiated by DT, use it */
> - if (of_property_read_bool(np, "m25p,fast-read"))
> - params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
> - else
> - params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
> - } else {
> - /* If we weren't instantiated by DT, default to fast-read */
> - params->hwcaps.mask |= SNOR_HWCAPS_READ_FAST;
> - }
> -
> if (of_property_read_bool(np, "broken-flash-reset"))
> nor->flags |= SNOR_F_BROKEN_RESET;
>
> - /* Some devices cannot do fast-read, no matter what DT tells us */
> - if (info->flags & SPI_NOR_NO_FR)
> - params->hwcaps.mask &= ~SNOR_HWCAPS_READ_FAST;
> -
> /*
> * Configure the SPI memory:
> * - select op codes for (Fast) Read, Page Program and Sector Erase.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-08-25 12:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-24 12:19 [PATCH v2 0/3] mtd: spi-nor: move manuf out of the core - batch 3 Tudor.Ambarus
2019-08-24 12:19 ` [PATCH v2 1/3] mtd: spi-nor: Bring flash params init together Tudor.Ambarus
2019-08-25 12:39 ` Boris Brezillon
2019-08-24 12:19 ` [PATCH v2 2/3] mtd: spi_nor: Introduce spi_nor_set_addr_width() Tudor.Ambarus
2019-08-24 12:19 ` [PATCH v2 3/3] mtd: spi-nor: Introduce spi_nor_get_flash_info() Tudor.Ambarus
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).