spi: Prepare for multi i/o and dummy bytes

Multi-i/o commands split SPI transactions into multiple phases that
can be transferred over 1, 2 or 4 wires. For this, we adapt `struct
spi_command` with a new enum, specifying the transfer mode, and ad-
ditional size fields.  While we are at it, move everything related
into a new header file `spi_command.h` so we won't further clutter
`flash.h`.

On the master side, we add respective feature flags for the multi-
i/o modes.

See also the comment in `spi_command.h` about multi-i/o commands.

Change-Id: I79debb845f1c8fec77e0556853ffb01735e73ab8
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.sourcearcade.org/c/flashprog/+/44
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/ichspi.c b/ichspi.c
index 0fc96ba..65c357d 100644
--- a/ichspi.c
+++ b/ichspi.c
@@ -25,6 +25,7 @@
 #include "flash.h"
 #include "programmer.h"
 #include "hwaccess_physmap.h"
+#include "spi_command.h"
 #include "spi.h"
 #include "ich_descriptors.h"
 
@@ -1520,8 +1521,8 @@
 	int ret = 0;
 	int i;
 	int oppos, preoppos;
-	for (; (cmds->writecnt || cmds->readcnt) && !ret; cmds++) {
-		if ((cmds + 1)->writecnt || (cmds + 1)->readcnt) {
+	for (; !spi_is_empty(cmds) && !ret; cmds++) {
+		if (!spi_is_empty(cmds + 1)) {
 			/* Next command is valid. */
 			preoppos = find_preop(curopcodes, cmds->writearr[0]);
 			oppos = find_opcode(curopcodes, (cmds + 1)->writearr[0]);
@@ -1546,7 +1547,8 @@
 				 * No need to bother with fixups.
 				 */
 				if (!ichspi_lock) {
-					oppos = reprogram_opcode_on_the_fly((cmds + 1)->writearr[0], (cmds + 1)->writecnt, (cmds + 1)->readcnt);
+					oppos = reprogram_opcode_on_the_fly((cmds + 1)->writearr[0],
+							spi_write_len(cmds + 1), spi_read_len(cmds + 1));
 					if (oppos == -1)
 						continue;
 					curopcodes->opcode[oppos].atomic = preoppos + 1;
@@ -1565,7 +1567,7 @@
 			 * preoppos matched, this is a normal opcode.
 			 */
 		}
-		ret = ich_spi_send_command(flash, cmds->writecnt, cmds->readcnt,
+		ret = ich_spi_send_command(flash, spi_write_len(cmds), spi_read_len(cmds),
 					   cmds->writearr, cmds->readarr);
 		/* Reset the type of all opcodes to non-atomic. */
 		for (i = 0; i < 8; i++)