summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stuge <peter@stuge.se>2008-06-24 01:22:03 +0000
committerPeter Stuge <peter@stuge.se>2008-06-24 01:22:03 +0000
commit606a207d9be0129296eda235896c9354b4e04e1f (patch)
treec7724f290c70688d0004a6bd568af063e58195e7
parent12afdd82ac6299d6ec1bb571a8043a61560a2f3a (diff)
flashrom: Slight restructure of SPI probe_ functions
Preparation for a probe optimization patch. This patch does not change any functionality. spi_probe_rdid was tested to still work on my M57SLI rev 2. The idea is to have error checks return error immediately when something fails, rather than having code inside an if block where the condition tests for success. This means: Less indentation, more clear what the code is checking. Signed-off-by: Peter Stuge <peter@stuge.se> Acked-by: Ward Vandewege <ward@gnu.org> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3386 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
-rw-r--r--util/flashrom/spi.c100
1 files changed, 53 insertions, 47 deletions
diff --git a/util/flashrom/spi.c b/util/flashrom/spi.c
index 3a25a100b9..01d8e234aa 100644
--- a/util/flashrom/spi.c
+++ b/util/flashrom/spi.c
@@ -82,35 +82,41 @@ int probe_spi_rdid(struct flashchip *flash)
unsigned char readarr[3];
uint32_t manuf_id;
uint32_t model_id;
- if (!spi_rdid(readarr)) {
- if (!oddparity(readarr[0]))
- printf_debug("RDID byte 0 parity violation.\n");
- /* Check if this is a continuation vendor ID */
- if (readarr[0] == 0x7f) {
- if (!oddparity(readarr[1]))
- printf_debug("RDID byte 1 parity violation.\n");
- manuf_id = (readarr[0] << 8) | readarr[1];
- model_id = readarr[2];
- } else {
- manuf_id = readarr[0];
- model_id = (readarr[1] << 8) | readarr[2];
- }
- printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, manuf_id, model_id);
- if (manuf_id == flash->manufacture_id &&
- model_id == flash->model_id) {
- /* Print the status register to tell the
- * user about possible write protection.
- */
- spi_prettyprint_status_register(flash);
-
- return 1;
- }
- /* Test if this is a pure vendor match. */
- if (manuf_id == flash->manufacture_id &&
- GENERIC_DEVICE_ID == flash->model_id)
- return 1;
+
+ if (spi_rdid(readarr))
+ return 0;
+
+ if (!oddparity(readarr[0]))
+ printf_debug("RDID byte 0 parity violation.\n");
+
+ /* Check if this is a continuation vendor ID */
+ if (readarr[0] == 0x7f) {
+ if (!oddparity(readarr[1]))
+ printf_debug("RDID byte 1 parity violation.\n");
+ manuf_id = (readarr[0] << 8) | readarr[1];
+ model_id = readarr[2];
+ } else {
+ manuf_id = readarr[0];
+ model_id = (readarr[1] << 8) | readarr[2];
}
+ printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, manuf_id, model_id);
+
+ if (manuf_id == flash->manufacture_id &&
+ model_id == flash->model_id) {
+ /* Print the status register to tell the
+ * user about possible write protection.
+ */
+ spi_prettyprint_status_register(flash);
+
+ return 1;
+ }
+
+ /* Test if this is a pure vendor match. */
+ if (manuf_id == flash->manufacture_id &&
+ GENERIC_DEVICE_ID == flash->model_id)
+ return 1;
+
return 0;
}
@@ -118,29 +124,29 @@ int probe_spi_res(struct flashchip *flash)
{
unsigned char readarr[3];
uint32_t model_id;
- if (!spi_rdid(readarr)) {
- /* Check if RDID returns 0xff 0xff 0xff, then we use RES. */
- if ((readarr[0] != 0xff) || (readarr[1] != 0xff) ||
- (readarr[2] != 0xff))
- return 0;
- } else {
+
+ if (spi_rdid(readarr))
/* We couldn't issue RDID, it's pointless to try RES. */
return 0;
- }
- if (!spi_res(readarr)) {
- model_id = readarr[0];
- printf_debug("%s: id 0x%x\n", __FUNCTION__, model_id);
- if (model_id == flash->model_id) {
- /* Print the status register to tell the
- * user about possible write protection.
- */
- spi_prettyprint_status_register(flash);
-
- return 1;
- }
- }
- return 0;
+ /* Check if RDID returns 0xff 0xff 0xff, then we use RES. */
+ if ((readarr[0] != 0xff) || (readarr[1] != 0xff) ||
+ (readarr[2] != 0xff))
+ return 0;
+
+ if (spi_res(readarr))
+ return 0;
+
+ model_id = readarr[0];
+ printf_debug("%s: id 0x%x\n", __FUNCTION__, model_id);
+ if (model_id != flash->model_id)
+ return 0;
+
+ /* Print the status register to tell the
+ * user about possible write protection.
+ */
+ spi_prettyprint_status_register(flash);
+ return 1;
}
uint8_t spi_read_status_register()