All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pratyush Yadav <p.yadav@ti.com>
To: u-boot@lists.denx.de
Subject: [PATCH v6 08/21] mtd: spi-nor-core: Introduce flash-specific fixup hooks
Date: Fri, 5 Jun 2020 18:14:47 +0530	[thread overview]
Message-ID: <20200605124500.17867-9-p.yadav@ti.com> (raw)
In-Reply-To: <20200605124500.17867-1-p.yadav@ti.com>

Sometimes the information in a flash's SFDP tables is wrong. Sometimes
some information just can't be expressed in the SFDP table. So,
introduce the fixup hooks to allow tailoring settings for a specific
flash.

Three hooks are added: default_init, post_sfdp, and post_bfpt. These
allow tweaking the flash settings at different point in the probe
sequence. Since the hooks reside in nor->info, set that value just
before the call to spi_nor_init_params().

The hooks and at what points they are executed mimics Linux's spi-nor
framework. One major difference is that Linux puts the struct
spi_nor_fixups in nor->info. This is not possible in U-Boot because the
spi-nor-ids list is shared between spi-nor-core.c and spi-nor-tiny.c.
Since spi-nor-tiny shouldn't have those fixup hooks populated, add a
separate function that lets flashes populate their fixup hooks.

Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
---
 drivers/mtd/spi/spi-nor-core.c | 78 ++++++++++++++++++++++++++++++++--
 include/linux/mtd/spi-nor.h    |  2 +
 2 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 28f5f877b4..2494c2e724 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -150,6 +150,31 @@ struct sfdp_bfpt {
 	u32	dwords[BFPT_DWORD_MAX];
 };
 
+/**
+ * struct spi_nor_fixups - SPI NOR fixup hooks
+ * @default_init: called after default flash parameters init. Used to tweak
+ *                flash parameters when information provided by the flash_info
+ *                table is incomplete or wrong.
+ * @post_bfpt: called after the BFPT table has been parsed
+ * @post_sfdp: called after SFDP has been parsed (is also called for SPI NORs
+ *             that do not support RDSFDP). Typically used to tweak various
+ *             parameters that could not be extracted by other means (i.e.
+ *             when information provided by the SFDP/flash_info tables are
+ *             incomplete or wrong).
+ *
+ * Those hooks can be used to tweak the SPI NOR configuration when the SFDP
+ * table is broken or not available.
+ */
+struct spi_nor_fixups {
+	void (*default_init)(struct spi_nor *nor);
+	int (*post_bfpt)(struct spi_nor *nor,
+			 const struct sfdp_parameter_header *bfpt_header,
+			 const struct sfdp_bfpt *bfpt,
+			 struct spi_nor_flash_parameter *params);
+	void (*post_sfdp)(struct spi_nor *nor,
+			  struct spi_nor_flash_parameter *params);
+};
+
 static int spi_nor_read_write_reg(struct spi_nor *nor, struct spi_mem_op
 		*op, void *buf)
 {
@@ -1747,6 +1772,18 @@ static const struct sfdp_bfpt_erase sfdp_bfpt_erases[] = {
 
 static int spi_nor_hwcaps_read2cmd(u32 hwcaps);
 
+static int
+spi_nor_post_bfpt_fixups(struct spi_nor *nor,
+			 const struct sfdp_parameter_header *bfpt_header,
+			 const struct sfdp_bfpt *bfpt,
+			 struct spi_nor_flash_parameter *params)
+{
+	if (nor->fixups && nor->fixups->post_bfpt)
+		return nor->fixups->post_bfpt(nor, bfpt_header, bfpt, params);
+
+	return 0;
+}
+
 /**
  * spi_nor_parse_bfpt() - read and parse the Basic Flash Parameter Table.
  * @nor:		pointer to a 'struct spi_nor'
@@ -1885,7 +1922,8 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 
 	/* Stop here if not JESD216 rev A or later. */
 	if (bfpt_header->length < BFPT_DWORD_MAX)
-		return 0;
+		return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt,
+						params);
 
 	/* Page size: this field specifies 'N' so the page size = 2^N bytes. */
 	params->page_size = bfpt.dwords[BFPT_DWORD(11)];
@@ -1918,7 +1956,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 		return -EINVAL;
 	}
 
-	return 0;
+	return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt, params);
 }
 
 /**
@@ -2081,6 +2119,29 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor,
 }
 #endif /* SPI_FLASH_SFDP_SUPPORT */
 
+/**
+ * spi_nor_post_sfdp_fixups() - Updates the flash's parameters and settings
+ * after SFDP has been parsed (is also called for SPI NORs that do not
+ * support RDSFDP).
+ * @nor:	pointer to a 'struct spi_nor'
+ *
+ * Typically used to tweak various parameters that could not be extracted by
+ * other means (i.e. when information provided by the SFDP/flash_info tables
+ * are incomplete or wrong).
+ */
+static void spi_nor_post_sfdp_fixups(struct spi_nor *nor,
+				     struct spi_nor_flash_parameter *params)
+{
+	if (nor->fixups && nor->fixups->post_sfdp)
+		nor->fixups->post_sfdp(nor, params);
+}
+
+static void spi_nor_default_init_fixups(struct spi_nor *nor)
+{
+	if (nor->fixups && nor->fixups->default_init)
+		nor->fixups->default_init(nor);
+}
+
 static int spi_nor_init_params(struct spi_nor *nor,
 			       const struct flash_info *info,
 			       struct spi_nor_flash_parameter *params)
@@ -2159,6 +2220,8 @@ static int spi_nor_init_params(struct spi_nor *nor,
 		}
 	}
 
+	spi_nor_default_init_fixups(nor);
+
 	/* Override the parameters with data read from SFDP tables. */
 	nor->addr_width = 0;
 	nor->mtd.erasesize = 0;
@@ -2175,6 +2238,8 @@ static int spi_nor_init_params(struct spi_nor *nor,
 		}
 	}
 
+	spi_nor_post_sfdp_fixups(nor, params);
+
 	return 0;
 }
 
@@ -2422,6 +2487,10 @@ static int spi_nor_init(struct spi_nor *nor)
 	return 0;
 }
 
+void spi_nor_set_fixups(struct spi_nor *nor)
+{
+}
+
 int spi_nor_scan(struct spi_nor *nor)
 {
 	struct spi_nor_flash_parameter params;
@@ -2470,6 +2539,10 @@ int spi_nor_scan(struct spi_nor *nor)
 	info = spi_nor_read_id(nor);
 	if (IS_ERR_OR_NULL(info))
 		return -ENOENT;
+	nor->info = info;
+
+	spi_nor_set_fixups(nor);
+
 	/* Parse the Serial Flash Discoverable Parameters table. */
 	ret = spi_nor_init_params(nor, info, &params);
 	if (ret)
@@ -2569,7 +2642,6 @@ int spi_nor_scan(struct spi_nor *nor)
 	}
 
 	/* Send all the required SPI flash commands to initialize device */
-	nor->info = info;
 	ret = spi_nor_init(nor);
 	if (ret)
 		return ret;
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 922e795ea6..5842e9d6ee 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -414,6 +414,7 @@ struct flash_info;
  * @write_proto:	the SPI protocol for write operations
  * @reg_proto		the SPI protocol for read_reg/write_reg/erase operations
  * @cmd_buf:		used by the write_reg
+ * @fixups:		flash-specific fixup hooks.
  * @prepare:		[OPTIONAL] do some preparations for the
  *			read/write/erase/lock/unlock operations
  * @unprepare:		[OPTIONAL] do some post work after the
@@ -455,6 +456,7 @@ struct spi_nor {
 	bool			sst_write_second;
 	u32			flags;
 	u8			cmd_buf[SPI_NOR_MAX_CMD_SIZE];
+	struct spi_nor_fixups	*fixups;
 
 	int (*setup)(struct spi_nor *nor, const struct flash_info *info,
 		     const struct spi_nor_flash_parameter *params,
-- 
2.27.0

  parent reply	other threads:[~2020-06-05 12:44 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-05 12:44 [PATCH v6 00/21] mtd: spi-nor-core: add xSPI Octal DTR support Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 01/21] spi: spi-mem: allow specifying whether an op is DTR or not Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 02/21] spi: spi-mem: allow specifying a command's extension Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 03/21] spi: cadence-qspi: Do not calibrate when device tree sets read delay Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 04/21] spi: cadence-qspi: Add support for octal DTR flashes Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 05/21] arm: mvebu: x530: Disable smart hwcaps selection Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 06/21] mtd: spi-nor-core: Add a ->setup() hook Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 07/21] mtd: spi-nor-core: Move SFDP related declarations to top Pratyush Yadav
2020-06-05 12:44 ` Pratyush Yadav [this message]
2020-06-05 12:44 ` [PATCH v6 09/21] mtd: spi-nor-core: Rework hwcaps selection Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 10/21] mtd: spi-nor-core: Add support for DTR protocol Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 11/21] mtd: spi-nor-core: prepare BFPT parsing for JESD216 rev D Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 12/21] mtd: spi-nor-core: Get command opcode extension type from BFPT Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 13/21] mtd: spi-nor-core: Parse xSPI Profile 1.0 table Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 14/21] mtd: spi-nor-core: Prepare Read SR and FSR for Octal DTR mode Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 15/21] mtd: spi-nor-core: Enable octal DTR mode when possible Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 16/21] mtd: spi-nor-core: Do not make invalid quad enable fatal Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 17/21] mtd: spi-nor-core: Detect Soft Reset sequence support from BFPT Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 18/21] mtd: spi-nor-core: Perform a Soft Reset on shutdown Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 19/21] mtd: spi-nor-core: Perform a Soft Reset on boot Pratyush Yadav
2020-06-05 12:44 ` [PATCH v6 20/21] mtd: spi-nor-core: Add support for Cypress Semper flash Pratyush Yadav
2020-06-05 12:45 ` [PATCH v6 21/21] mtd: spi-nor-core: Allow using Micron mt35xu512aba in Octal DTR mode Pratyush Yadav
2020-07-08 11:56   ` Jagan Teki
2020-07-13  8:25     ` Vignesh Raghavendra
2020-06-15 15:51 ` [PATCH v6 00/21] mtd: spi-nor-core: add xSPI Octal DTR support Pratyush Yadav
2020-07-07 13:30   ` Vignesh Raghavendra
2020-07-09  8:13     ` Jagan Teki
2020-07-13  8:15       ` Vignesh Raghavendra
2020-07-20 16:50         ` Jagan Teki

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=20200605124500.17867-9-p.yadav@ti.com \
    --to=p.yadav@ti.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.