Refactor remaining write wrappers

Kill duplicated code.

Annotate write functions with their chunk size.

Mark Fujitsu MBM29F400BC and ST M29F400BB as untested because their
write code no longer uses a broken layout.

Corresponding to flashrom svn r1210.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
Tested-by: Maciej Pijanka <maciej.pijanka@gmail.com>
Tested-by: Idwer Vollering <vidwer@gmail.com>
Acked-by: Idwer Vollering <vidwer@gmail.com>
Tested-by: Sean Nelson <audiohacked@gmail.com> 
Acked-by: Sean Nelson <audiohacked@gmail.com> 
diff --git a/sst28sf040.c b/sst28sf040.c
index ba22093..0c62fd6 100644
--- a/sst28sf040.c
+++ b/sst28sf040.c
@@ -30,7 +30,7 @@
 #define RESET			0xFF
 #define READ_ID			0x90
 
-static void protect_28sf040(struct flashchip *flash)
+int protect_28sf040(struct flashchip *flash)
 {
 	chipaddr bios = flash->virtual_memory;
 
@@ -41,9 +41,11 @@
 	chip_readb(bios + 0x041B);
 	chip_readb(bios + 0x0419);
 	chip_readb(bios + 0x040A);
+
+	return 0;
 }
 
-static void unprotect_28sf040(struct flashchip *flash)
+int unprotect_28sf040(struct flashchip *flash)
 {
 	chipaddr bios = flash->virtual_memory;
 
@@ -54,12 +56,15 @@
 	chip_readb(bios + 0x041B);
 	chip_readb(bios + 0x0419);
 	chip_readb(bios + 0x041A);
+
+	return 0;
 }
 
 int erase_sector_28sf040(struct flashchip *flash, unsigned int address, unsigned int sector_size)
 {
 	chipaddr bios = flash->virtual_memory;
 
+	/* This command sequence is very similar to erase_block_82802ab. */
 	chip_writeb(AUTO_PG_ERASE1, bios);
 	chip_writeb(AUTO_PG_ERASE2, bios + address);
 
@@ -101,10 +106,8 @@
 {
 	chipaddr bios = flash->virtual_memory;
 
-	unprotect_28sf040(flash);
 	chip_writeb(CHIP_ERASE, bios);
 	chip_writeb(CHIP_ERASE, bios);
-	protect_28sf040(flash);
 
 	programmer_delay(10);
 	toggle_ready_jedec(bios);
@@ -116,15 +119,10 @@
 	return 0;
 }
 
+/* chunksize is 1 */
 int write_28sf040(struct flashchip *flash, uint8_t *buf)
 {
-	unprotect_28sf040(flash);
-
-	write_sector_28sf040(flash, buf, 0, flash->total_size * 1024);
-
-	protect_28sf040(flash);
-
-	return 0;
+	return write_sector_28sf040(flash, buf, 0, flash->total_size * 1024);
 }
 
 int erase_chip_28sf040(struct flashchip *flash, unsigned int addr, unsigned int blocklen)