Add IT87xx SPI as external flasher option

This is a fast way to test if a IT87xx board_enable() would work.

Corresponding to flashrom svn r557.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Tested-by: Harald Gutmann <harald.gutmann@gmx.net>
Acked-by: Harald Gutmann <harald.gutmann@gmx.net>
diff --git a/flash.h b/flash.h
index c056f6e..becab69 100644
--- a/flash.h
+++ b/flash.h
@@ -84,6 +84,7 @@
 #define PROGRAMMER_DUMMY	0x01
 #define PROGRAMMER_NIC3COM	0x02
 #define PROGRAMMER_SATASII	0x03
+#define PROGRAMMER_IT87SPI	0x04
 
 struct programmer_entry {
 	const char *vendor;
@@ -752,6 +753,7 @@
 extern uint16_t it8716f_flashport;
 void enter_conf_mode_ite(uint16_t port);
 void exit_conf_mode_ite(uint16_t port);
+int it87spi_init(void);
 int it87xx_probe_spi_flash(const char *name);
 int it8716f_spi_command(unsigned int writecnt, unsigned int readcnt,
 			const unsigned char *writearr, unsigned char *readarr);
diff --git a/flashrom.8 b/flashrom.8
index 193fc28..8a7baba 100644
--- a/flashrom.8
+++ b/flashrom.8
@@ -133,6 +133,8 @@
 .sp
 .BR "* satasii" " (for flash ROMs on Silicon Image SATA/IDE controllers)"
 .sp
+.BR "* it87spi" " (for flash ROMs behind a IT87xx SuperI/O LPC/SPI translation unit)"
+.sp
 If you have multiple supported PCI cards which can program flash chips
 (NICs, SATA/IDE controllers, etc.) in your system, you must use the
 .B "flashrom -p xxxx=bb:dd.f"
diff --git a/flashrom.c b/flashrom.c
index c47c6fd..5113a6b 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -87,6 +87,19 @@
 		.chip_writel		= fallback_chip_writel,
 	},
 
+	{
+		.init			= it87spi_init,
+		.shutdown		= dummy_shutdown,
+		.map_flash_region	= dummy_map,
+		.unmap_flash_region	= dummy_unmap,
+		.chip_readb		= dummy_chip_readb,
+		.chip_readw		= dummy_chip_readw,
+		.chip_readl		= dummy_chip_readl,
+		.chip_writeb		= dummy_chip_writeb,
+		.chip_writew		= dummy_chip_writew,
+		.chip_writel		= dummy_chip_writel,
+	},
+
 	{},
 };
 
@@ -400,7 +413,7 @@
 	     "   -i | --image <name>:              only flash image name from flash layout\n"
 	     "   -L | --list-supported:            print supported devices\n"
 	     "   -p | --programmer <name>:         specify the programmer device\n"
-	     "                                     (internal, dummy, nic3com, satasii)\n"
+	     "                                     (internal, dummy, nic3com, satasii, it87spi)\n"
 	     "   -h | --help:                      print this help text\n"
 	     "   -R | --version:                   print the version (release)\n"
 	     "\nIf no file is specified, then all that happens"
@@ -532,6 +545,8 @@
 				programmer = PROGRAMMER_SATASII;
 				if (optarg[7] == '=')
 					pcidev_bdf = strdup(optarg + 8);
+			} else if (strncmp(optarg, "it87spi", 7) == 0) {
+				programmer = PROGRAMMER_IT87SPI;
 			} else {
 				printf("Error: Unknown programmer.\n");
 				exit(1);
diff --git a/it87spi.c b/it87spi.c
index 2a7be85..d9f93e6 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -93,7 +93,7 @@
 	return flashport;
 }
 
-int it87xx_probe_spi_flash(const char *name)
+int it87spi_common_init(void)
 {
 	it8716f_flashport = find_ite_spi_flash_port(ITE_SUPERIO_PORT1);
 
@@ -106,6 +106,19 @@
 	return (!it8716f_flashport);
 }
 
+
+int it87spi_init(void)
+{
+	get_io_perms();
+
+	return it87spi_common_init();
+}
+
+int it87xx_probe_spi_flash(const char *name)
+{
+	return it87spi_common_init();
+}
+
 /*
  * The IT8716F only supports commands with length 1,2,4,5 bytes including
  * command byte and can not read more than 3 bytes from the device.
@@ -241,7 +254,7 @@
 	int i;
 	fast_spi = 0;
 
-	if (total_size > 512 * 1024) {
+	if ((programmer == PROGRAMMER_IT87SPI) || (total_size > 512 * 1024)) {
 		for (i = 0; i < total_size; i += 3) {
 			int toread = 3;
 			if (total_size - i < toread)
@@ -264,7 +277,7 @@
 	 * IT8716F only allows maximum of 512 kb SPI chip size for memory
 	 * mapped access.
 	 */
-	if (total_size > 512 * 1024) {
+	if ((programmer == PROGRAMMER_IT87SPI) || (total_size > 512 * 1024)) {
 		it8716f_spi_chip_write_1(flash, buf);
 	} else {
 		for (i = 0; i < total_size / 256; i++) {