flash: Introduce 4BA shorthands

Backport some of the more trivial side of the upstream
`commit aac81424eb`. The more semantical changes are dealt
with in follow ups as dep are missing as of now.

BUG=chromium:478356
BRANCH=none
TEST=still builds

Change-Id: I4ec0c6343a143bef00d7fbb427867dbc17dc8583
Signed-off-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/flashrom/+/1672909
Reviewed-by: Sam McNally <sammc@chromium.org>
diff --git a/flash.h b/flash.h
index 8037622..5939ad4 100644
--- a/flash.h
+++ b/flash.h
@@ -127,11 +127,17 @@
 #define FEATURE_ERASE_TO_ZERO	(1 << 9)
 #define FEATURE_UNBOUND_READ	(1 << 10)
 #define FEATURE_NO_ERASE	(1 << 11)
-#define FEATURE_4BA_SUPPORT	(1 << 12)
-#define FEATURE_4BA_EXT_ADDR	(1 << 13) /**< Regular 3-byte operations can be used by writing the most
+#define FEATURE_4BA_ENTER	(1 << 12)
+#define FEATURE_4BA_ENTER_WREN	(1 << 13) /**< Can enter/exit 4BA mode with instructions 0xb7/0xe9 after WREN */
+#define FEATURE_4BA_EXT_ADDR	(1 << 14) /**< Regular 3-byte operations can be used by writing the most
 						significant address byte into an extended address register. */
-#define FEATURE_4BA_READ       (1 << 14) /**< Native 4BA read instruction (0x13) is supported. */
-#define FEATURE_4BA_WRITE      (1 << 15) /**< Native 4BA byte program (0x12) is supported. */
+#define FEATURE_4BA_READ	(1 << 15) /**< Native 4BA read instruction (0x13) is supported. */
+#define FEATURE_4BA_FAST_READ	(1 << 16) /**< Native 4BA fast read instruction (0x0c) is supported. */
+#define FEATURE_4BA_WRITE	(1 << 17) /**< Native 4BA byte program (0x12) is supported. */
+/* 4BA Shorthands */
+#define FEATURE_4BA_NATIVE	(FEATURE_4BA_READ | FEATURE_4BA_FAST_READ | FEATURE_4BA_WRITE)
+#define FEATURE_4BA		(FEATURE_4BA_ENTER | FEATURE_4BA_EXT_ADDR | FEATURE_4BA_NATIVE)
+#define FEATURE_4BA_WREN	(FEATURE_4BA_ENTER_WREN | FEATURE_4BA_EXT_ADDR | FEATURE_4BA_NATIVE)
 
 struct voltage_range {
 	uint16_t min, max;
diff --git a/flashchips.c b/flashchips.c
index 202830f..82ae71e 100644
--- a/flashchips.c
+++ b/flashchips.c
@@ -4331,7 +4331,7 @@
 		.model_id	= GIGADEVICE_GD25Q256D,
 		.total_size	= 32768,
 		.page_size	= 256,
-		.feature_bits	= FEATURE_WRSR_WREN | FEATURE_UNBOUND_READ | FEATURE_OTP | FEATURE_4BA_SUPPORT | FEATURE_4BA_READ | FEATURE_4BA_WRITE,
+		.feature_bits	= FEATURE_WRSR_WREN | FEATURE_UNBOUND_READ | FEATURE_OTP | FEATURE_4BA_WREN,
 		.tested		= TEST_OK_PREWU,
 		.probe		= probe_spi_rdid,
 		.probe_timing	= TIMING_ZERO,
@@ -4871,7 +4871,7 @@
 		.total_size	= 32768,
 		.page_size	= 256,
 		.feature_bits	=
-			FEATURE_WRSR_WREN | FEATURE_UNBOUND_READ | FEATURE_4BA_SUPPORT | FEATURE_4BA_READ | FEATURE_4BA_WRITE,
+			FEATURE_WRSR_WREN | FEATURE_UNBOUND_READ | FEATURE_4BA_WREN,
 		.tested		= TEST_UNTESTED,
 		.probe		= probe_spi_rdid,
 		.probe_timing	= TIMING_ZERO,
@@ -6203,7 +6203,7 @@
 		.page_size	= 256,
 		/* supports SFDP */
 		/* OTP: 64B total; read 0x4B, write 0x42 */
-		.feature_bits	= FEATURE_WRSR_WREN | FEATURE_UNBOUND_READ | FEATURE_OTP | FEATURE_4BA_SUPPORT | FEATURE_4BA_READ | FEATURE_4BA_WRITE,
+		.feature_bits	= FEATURE_WRSR_WREN | FEATURE_UNBOUND_READ | FEATURE_OTP | FEATURE_4BA_WREN,
 		.tested		= TEST_OK_PREWU,
 		.probe		= probe_spi_rdid,
 		.probe_timing	= TIMING_ZERO,
@@ -6235,7 +6235,7 @@
 		.page_size	= 256,
 		/* supports SFDP */
 		/* OTP: 64B total; read 0x4B, write 0x42 */
-		.feature_bits	= FEATURE_WRSR_WREN | FEATURE_OTP | FEATURE_4BA_SUPPORT | FEATURE_4BA_READ | FEATURE_4BA_WRITE,
+		.feature_bits	= FEATURE_WRSR_WREN | FEATURE_OTP | FEATURE_4BA_WREN,
 		.tested		= TEST_OK_PREW,
 		.probe		= probe_spi_rdid,
 		.probe_timing	= TIMING_ZERO,
@@ -9645,7 +9645,7 @@
 		/* supports SFDP */
 		/* OTP: 1024B total, 256B reserved; read 0x48; write 0x42, erase 0x44, read ID 0x4B */
 		/* FOUR_BYTE_ADDR: supports 4-bytes addressing mode */
-		.feature_bits	= FEATURE_WRSR_WREN | FEATURE_UNBOUND_READ | FEATURE_OTP | FEATURE_4BA_SUPPORT | FEATURE_4BA_READ | FEATURE_4BA_WRITE,
+		.feature_bits	= FEATURE_WRSR_WREN | FEATURE_UNBOUND_READ | FEATURE_OTP | FEATURE_4BA_WREN,
 		.tested		= TEST_OK_PREWU,
 		.probe		= probe_spi_rdid,
 		.probe_timing	= TIMING_ZERO,
@@ -10073,7 +10073,7 @@
 		.model_id	= WINBOND_NEX_W25Q256JV,
 		.total_size	= 32768,
 		.page_size	= 256,
-		.feature_bits	= FEATURE_WRSR_WREN | FEATURE_UNBOUND_READ | FEATURE_OTP | FEATURE_4BA_SUPPORT | FEATURE_4BA_READ | FEATURE_4BA_WRITE,
+		.feature_bits	= FEATURE_WRSR_WREN | FEATURE_UNBOUND_READ | FEATURE_OTP | FEATURE_4BA_WREN,
 		.tested		= TEST_OK_PREWU,
 		.probe		= probe_spi_rdid,
 		.probe_timing	= TIMING_ZERO,
diff --git a/flashrom.c b/flashrom.c
index 2b63c21..987c3a6 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -2034,7 +2034,7 @@
 	flash->in_4ba_mode = false;
 
 	/* Enable/disable 4-byte addressing mode if flash chip supports it */
-	if ((flash->chip->feature_bits & FEATURE_4BA_SUPPORT) && flash->chip->set_4ba) {
+	if ((flash->chip->feature_bits & FEATURE_4BA_ENTER) && flash->chip->set_4ba) {
 		if (flash->chip->set_4ba(flash)) {
 			msg_cerr("Enabling/disabling 4-byte addressing mode failed!\n");
 			return 1;
diff --git a/spi.c b/spi.c
index a4a7a2b..fbc0bb8 100644
--- a/spi.c
+++ b/spi.c
@@ -148,7 +148,7 @@
 	addrbase = spi_get_valid_read_addr(flash);
 	/* Show flash chip size warning if flash chip doesn't support
 	   4-Bytes Addressing mode and last address excedes 24 bits */
-	if (!(flash->chip->feature_bits & FEATURE_4BA_SUPPORT) &&
+	if (!(flash->chip->feature_bits & FEATURE_4BA_ENTER) &&
 	    addrbase + flash->chip->total_size * 1024 > (1 << 24)) {
 		msg_perr("Flash chip size exceeds the allowed access window. ");
 		msg_perr("Read will probably fail.\n");