[coreboot-gerrit] Change in coreboot[master]: drivers/spi: Add flash probe callbacks to spi_ctrlr structure

Furquan Shaikh (Code Review) gerrit at coreboot.org
Tue May 16 10:15:14 CEST 2017


Furquan Shaikh has uploaded a new change for review. ( https://review.coreboot.org/19708 )

Change subject: drivers/spi: Add flash probe callbacks to spi_ctrlr structure
......................................................................

drivers/spi: Add flash probe callbacks to spi_ctrlr structure

In order to support some specialized SPI controllers that are actually
SPI flash controllers, add two new members to spi_ctrlr structure:

1. flash_probe: Specialized probe function provided by the spi flash
controller.
2. try_generic_probe_first: Check if the controllers wants the flash
driver to perform generic probing before trying out the specialized
probing.

With this change, the specialized spi flash probe functions are now
associated with a particular spi ctrlr structure and no longer
disconnected from the spi controller.

BUG=b:38330715
TEST=Verified with the entire patch series that spi flash driver still
works fine on poppy.

Change-Id: I35f3bd8ddc5e71515df3ef0c1c4b1a68ee56bf4b
---
M src/drivers/spi/spi_flash.c
M src/include/spi-generic.h
M src/include/spi_flash.h
M src/soc/intel/common/block/fast_spi/fast_spi_flash.c
M src/soc/mediatek/mt8173/flash_controller.c
M src/soc/mediatek/mt8173/include/soc/spi.h
M src/soc/mediatek/mt8173/spi.c
M src/southbridge/intel/common/spi.c
8 files changed, 65 insertions(+), 64 deletions(-)


  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/19708/1

diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c
index 205afd7..fb295d5 100644
--- a/src/drivers/spi/spi_flash.c
+++ b/src/drivers/spi/spi_flash.c
@@ -281,15 +281,6 @@
 };
 #define IDCODE_LEN (IDCODE_CONT_LEN + IDCODE_PART_LEN)
 
-int
-__attribute__((weak)) spi_flash_programmer_probe(const struct spi_slave *spi,
-						 int force,
-						 struct spi_flash *flash)
-{
-	/* Default weak implementation. Do nothing. */
-	return -1;
-}
-
 static int __spi_flash_probe(const struct spi_slave *spi,
 				struct spi_flash *flash)
 {
@@ -330,14 +321,22 @@
 int spi_flash_probe(unsigned int bus, unsigned int cs, struct spi_flash *flash)
 {
 	struct spi_slave spi;
+	bool try_generic_probe_first = false;
 
 	if (spi_setup_slave(bus, cs, &spi)) {
 		printk(BIOS_WARNING, "SF: Failed to set up slave\n");
 		return -1;
 	}
 
-	/* Try special programmer probe if any (without force). */
-	if (spi_flash_programmer_probe(&spi, 0, flash) == 0)
+	if (spi.ctrlr->try_generic_probe_first)
+		try_generic_probe_first = spi.ctrlr->try_generic_probe_first();
+	/*
+	 * Try special programmer probe if present and generic probing is not
+	 * requested.
+	 */
+	if (spi.ctrlr->flash_probe &&
+	    (try_generic_probe_first != true) &&
+	    (spi.ctrlr->flash_probe(&spi, flash) == 0))
 		goto flash_found;
 
 	/* If flash is not found, try generic spi flash probe. */
@@ -345,7 +344,8 @@
 		goto flash_found;
 
 	/* If flash is not yet found, force special programmer probe if any. */
-	if (spi_flash_programmer_probe(&spi, 1, flash) == 0)
+	if (spi.ctrlr->flash_probe &&
+	    (spi.ctrlr->flash_probe(&spi, flash) == 0))
 		goto flash_found;
 
 	/* Give up -- nothing more to try if flash is not found. */
diff --git a/src/include/spi-generic.h b/src/include/spi-generic.h
index 56353bb..1d217cd 100644
--- a/src/include/spi-generic.h
+++ b/src/include/spi-generic.h
@@ -94,6 +94,8 @@
  */
 #define SPI_CTRLR_DEFAULT_MAX_XFER_SIZE	(UINT32_MAX)
 
+struct spi_flash;
+
 /*-----------------------------------------------------------------------
  * Representation of a SPI controller.
  *
@@ -108,6 +110,12 @@
  * deduct_cmd_len:	Whether cmd_len should be deducted from max_xfer_size
  *			when calculating max_data_size
  *
+ * Following members are provided by specialized SPI controllers that are
+ * actually SPI flash controllers:
+ *
+ * flash_probe:		Specialized probing of the SPI flash chip.
+ * try_generic_probe_first:	If SPI flash probing should try the generic
+ *				probing functions first.
  */
 struct spi_ctrlr {
 	int (*claim_bus)(const struct spi_slave *slave);
@@ -119,6 +127,9 @@
 			struct spi_op vectors[], size_t count);
 	uint32_t max_xfer_size;
 	bool deduct_cmd_len;
+	int (*flash_probe)(const struct spi_slave *slave,
+				struct spi_flash *flash);
+	bool (*try_generic_probe_first)(void);
 };
 
 /*-----------------------------------------------------------------------
diff --git a/src/include/spi_flash.h b/src/include/spi_flash.h
index bc0318c..99e8a53 100644
--- a/src/include/spi_flash.h
+++ b/src/include/spi_flash.h
@@ -65,21 +65,6 @@
  * non-zero = error
  */
 int spi_flash_probe(unsigned int bus, unsigned int cs, struct spi_flash *flash);
-/*
- * Specialized probing performed by platform. This is a weak function which can
- * be overriden by platform driver.
- *
- * Params:
- * spi   = Pointer to spi_slave structure.
- * force = Indicates if the platform driver can skip specialized probing.
- * flash = Pointer to spi_flash structure that needs to be filled.
- *
- * Return value:
- * 0 = success
- * non-zero = error
- */
-int spi_flash_programmer_probe(const struct spi_slave *spi, int force,
-				struct spi_flash *flash);
 
 /* All the following functions return 0 on success and non-zero on error. */
 int spi_flash_read(const struct spi_flash *flash, u32 offset, size_t len,
diff --git a/src/soc/intel/common/block/fast_spi/fast_spi_flash.c b/src/soc/intel/common/block/fast_spi/fast_spi_flash.c
index 7780144..fc36553 100644
--- a/src/soc/intel/common/block/fast_spi/fast_spi_flash.c
+++ b/src/soc/intel/common/block/fast_spi/fast_spi_flash.c
@@ -280,8 +280,8 @@
  * The size of the flash component is always taken from density field in the
  * SFDP table. FLCOMP.C0DEN is no longer used by the Flash Controller.
  */
-int spi_flash_programmer_probe(const struct spi_slave *dev,
-				int force, struct spi_flash *flash)
+static int fast_spi_flash_probe(const struct spi_slave *dev,
+				struct spi_flash *flash)
 {
 	BOILERPLATE_CREATE_CTX(ctx);
 	uint32_t flash_bits;
@@ -362,4 +362,5 @@
 const struct spi_ctrlr fast_spi_flash_ctrlr = {
 	.setup = fast_spi_flash_ctrlr_setup,
 	.max_xfer_size = SPI_CTRLR_DEFAULT_MAX_XFER_SIZE,
+	.flash_probe = fast_spi_flash_probe,
 };
diff --git a/src/soc/mediatek/mt8173/flash_controller.c b/src/soc/mediatek/mt8173/flash_controller.c
index ee950b8..44cd05c 100644
--- a/src/soc/mediatek/mt8173/flash_controller.c
+++ b/src/soc/mediatek/mt8173/flash_controller.c
@@ -27,6 +27,7 @@
 #include <timer.h>
 #include <soc/flash_controller.h>
 #include <soc/mmu_operations.h>
+#include <soc/spi.h>
 
 #define get_nth_byte(d, n)	((d >> (8 * n)) & 0xff)
 
@@ -228,8 +229,7 @@
 	return 0;
 }
 
-int spi_flash_programmer_probe(const struct spi_slave *spi,
-			       int force, struct spi_flash *flash)
+int mtk_spi_flash_probe(const struct spi_slave *spi, struct spi_flash *flash)
 {
 	static int done;
 
diff --git a/src/soc/mediatek/mt8173/include/soc/spi.h b/src/soc/mediatek/mt8173/include/soc/spi.h
index 52f4f4c..dbe1f50 100644
--- a/src/soc/mediatek/mt8173/include/soc/spi.h
+++ b/src/soc/mediatek/mt8173/include/soc/spi.h
@@ -106,4 +106,6 @@
 
 void mtk_spi_init(unsigned int bus, unsigned int pad_select,
 		  unsigned int speed_hz);
+
+int mtk_spi_flash_probe(const struct spi_slave *spi, struct spi_flash *flash);
 #endif
diff --git a/src/soc/mediatek/mt8173/spi.c b/src/soc/mediatek/mt8173/spi.c
index 188bdc2..b8ee423 100644
--- a/src/soc/mediatek/mt8173/spi.c
+++ b/src/soc/mediatek/mt8173/spi.c
@@ -295,6 +295,7 @@
 	.xfer = spi_ctrlr_xfer,
 	.xfer_vector = spi_xfer_two_vectors,
 	.max_xfer_size = 65535,
+	.flash_probe = mtk_spi_flash_probe,
 };
 
 int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
diff --git a/src/southbridge/intel/common/spi.c b/src/southbridge/intel/common/spi.c
index 110c29c..e59f7d8 100644
--- a/src/southbridge/intel/common/spi.c
+++ b/src/southbridge/intel/common/spi.c
@@ -66,8 +66,6 @@
 	pci_write_config32(dev, reg, val)
 #endif /* !__SMM__ */
 
-static int spi_is_multichip(void);
-
 typedef struct spi_slave ich_spi_slave;
 
 static int ichspi_lock = 0;
@@ -498,13 +496,6 @@
 	return -1;
 }
 
-static int spi_is_multichip (void)
-{
-	if (!(cntlr.hsfs & HSFS_FDV))
-		return 0;
-	return !!((cntlr.flmap0 >> 8) & 3);
-}
-
 static int spi_ctrlr_xfer(const struct spi_slave *slave, const void *dout,
 		size_t bytesout, void *din, size_t bytesin)
 {
@@ -650,20 +641,6 @@
 	/* Clear atomic preop now that xfer is done */
 	writew_(0, cntlr.preop);
 
-	return 0;
-}
-
-static const struct spi_ctrlr spi_ctrlr = {
-	.xfer = spi_ctrlr_xfer,
-	.xfer_vector = spi_xfer_two_vectors,
-	.max_xfer_size = member_size(ich9_spi_regs, fdata),
-};
-
-int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
-{
-	slave->bus = bus;
-	slave->cs = cs;
-	slave->ctrlr = &spi_ctrlr;
 	return 0;
 }
 
@@ -899,18 +876,26 @@
 	return 0;
 }
 
-int spi_flash_programmer_probe(const struct spi_slave *spi,
-			       int force, struct spi_flash *flash)
+static int spi_is_multichip(void)
+{
+	if (!(cntlr.hsfs & HSFS_FDV))
+		return 0;
+	return !!((cntlr.flmap0 >> 8) & 3);
+}
+
+static bool spi_flash_try_generic_probe_first(void)
+{
+	/* Perform generic probing first only if spi_is_multichip returns 0. */
+	if (!spi_is_multichip())
+		return true;
+
+	return false;
+}
+
+static int spi_flash_programmer_probe(const struct spi_slave *spi,
+					struct spi_flash *flash)
 {
 	uint32_t flcomp;
-
-	/*
-	 * Perform SPI flash probing only if:
-	 * 1. spi_is_multichip returns 1 or
-	 * 2. Specialized probing is forced by SPI flash driver.
-	 */
-	if (!spi_is_multichip() && !force)
-		return -1;
 
 	memcpy(&flash->spi, spi, sizeof(*spi));
 	flash->name = "Opaque HW-sequencing";
@@ -946,3 +931,19 @@
 
 	return 0;
 }
+
+static const struct spi_ctrlr spi_ctrlr = {
+	.xfer = spi_ctrlr_xfer,
+	.xfer_vector = spi_xfer_two_vectors,
+	.max_xfer_size = member_size(ich9_spi_regs, fdata),
+	.flash_probe = spi_flash_programmer_probe,
+	.try_generic_probe_first = spi_flash_try_generic_probe_first,
+};
+
+int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
+{
+	slave->bus = bus;
+	slave->cs = cs;
+	slave->ctrlr = &spi_ctrlr;
+	return 0;
+}

-- 
To view, visit https://review.coreboot.org/19708
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I35f3bd8ddc5e71515df3ef0c1c4b1a68ee56bf4b
Gerrit-PatchSet: 1
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Owner: Furquan Shaikh <furquan at google.com>



More information about the coreboot-gerrit mailing list