sf: unify erase commands

Analysis of the flash drivers shows that they all use 0x20 if the erase
size is 4KiB, or 0xd8 if it's larger.  So with this info in hand, we can
unify all the erase functionality in one place.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
diff --git a/drivers/mtd/spi/eon.c b/drivers/mtd/spi/eon.c
index eccdf83..d9d43ca 100644
--- a/drivers/mtd/spi/eon.c
+++ b/drivers/mtd/spi/eon.c
@@ -10,10 +10,6 @@
 
 #include "spi_flash_internal.h"
 
-/* EN25Q128-specific commands */
-#define CMD_EN25Q128_SE		0x20    /* Sector Erase */
-#define CMD_EN25Q128_BE		0xd8    /* Block Erase */
-
 struct eon_spi_flash_params {
 	u8 idcode1;
 	u16 nr_sectors;
@@ -38,11 +34,6 @@
 	},
 };
 
-static int eon_erase(struct spi_flash *flash, u32 offset, size_t len)
-{
-	return spi_flash_cmd_erase(flash, CMD_EN25Q128_BE, offset, len);
-}
-
 struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
 {
 	const struct eon_spi_flash_params *params;
@@ -70,7 +61,7 @@
 	flash->name = params->name;
 
 	flash->write = spi_flash_cmd_write_multi;
-	flash->erase = eon_erase;
+	flash->erase = spi_flash_cmd_erase;
 	flash->read = spi_flash_cmd_read_fast;
 	flash->page_size = 256;
 	flash->sector_size = 256 * 16 * 16;
diff --git a/drivers/mtd/spi/macronix.c b/drivers/mtd/spi/macronix.c
index 894b1ca..5268c66 100644
--- a/drivers/mtd/spi/macronix.c
+++ b/drivers/mtd/spi/macronix.c
@@ -35,11 +35,6 @@
 
 #include "spi_flash_internal.h"
 
-/* MX25xx-specific commands */
-#define CMD_MX25XX_SE		0x20	/* Sector Erase */
-#define CMD_MX25XX_BE		0xD8	/* Block Erase */
-#define CMD_MX25XX_CE		0xc7	/* Chip Erase */
-
 struct macronix_spi_flash_params {
 	u16 idcode;
 	u16 nr_blocks;
@@ -123,11 +118,6 @@
 	return ret;
 }
 
-static int macronix_erase(struct spi_flash *flash, u32 offset, size_t len)
-{
-	return spi_flash_cmd_erase(flash, CMD_MX25XX_BE, offset, len);
-}
-
 struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
 {
 	const struct macronix_spi_flash_params *params;
@@ -156,7 +146,7 @@
 	flash->name = params->name;
 
 	flash->write = spi_flash_cmd_write_multi;
-	flash->erase = macronix_erase;
+	flash->erase = spi_flash_cmd_erase;
 	flash->read = spi_flash_cmd_read_fast;
 	flash->page_size = 256;
 	flash->sector_size = 256 * 16 * 16;
diff --git a/drivers/mtd/spi/spansion.c b/drivers/mtd/spi/spansion.c
index bedde07..9a114ac 100644
--- a/drivers/mtd/spi/spansion.c
+++ b/drivers/mtd/spi/spansion.c
@@ -31,10 +31,6 @@
 
 #include "spi_flash_internal.h"
 
-/* S25FLxx-specific commands */
-#define CMD_S25FLXX_SE		0xd8	/* Sector Erase */
-#define CMD_S25FLXX_BE		0xc7	/* Bulk Erase */
-
 struct spansion_spi_flash_params {
 	u16 idcode1;
 	u16 idcode2;
@@ -102,11 +98,6 @@
 	},
 };
 
-static int spansion_erase(struct spi_flash *flash, u32 offset, size_t len)
-{
-	return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE, offset, len);
-}
-
 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
 {
 	const struct spansion_spi_flash_params *params;
@@ -140,7 +131,7 @@
 	flash->name = params->name;
 
 	flash->write = spi_flash_cmd_write_multi;
-	flash->erase = spansion_erase;
+	flash->erase = spi_flash_cmd_erase;
 	flash->read = spi_flash_cmd_read_fast;
 	flash->page_size = 256;
 	flash->sector_size = 256 * params->pages_per_sector;
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index f689cc4..4ab4e13 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -190,8 +190,7 @@
 		CMD_READ_STATUS, STATUS_WIP);
 }
 
-int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd,
-			u32 offset, size_t len)
+int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	u32 start, end, erase_size;
 	int ret;
@@ -209,7 +208,10 @@
 		return ret;
 	}
 
-	cmd[0] = erase_cmd;
+	if (erase_size == 4096)
+		cmd[0] = CMD_ERASE_4K;
+	else
+		cmd[0] = CMD_ERASE_64K;
 	start = offset;
 	end = start + len;
 
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h
index 0c78249..3c6bccf 100644
--- a/drivers/mtd/spi/spi_flash_internal.h
+++ b/drivers/mtd/spi/spi_flash_internal.h
@@ -23,6 +23,10 @@
 #define CMD_WRITE_DISABLE		0x04
 #define CMD_READ_STATUS			0x05
 #define CMD_WRITE_ENABLE		0x06
+#define CMD_ERASE_4K			0x20
+#define CMD_ERASE_32K			0x52
+#define CMD_ERASE_64K			0xd8
+#define CMD_ERASE_CHIP			0xc7
 
 /* Common status */
 #define STATUS_WIP			0x01
@@ -88,8 +92,7 @@
 int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout);
 
 /* Erase sectors. */
-int spi_flash_cmd_erase(struct spi_flash *flash, u8 erase_cmd,
-			u32 offset, size_t len);
+int spi_flash_cmd_erase(struct spi_flash *flash, u32 offset, size_t len);
 
 /* Manufacturer-specific probe functions */
 struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode);
diff --git a/drivers/mtd/spi/sst.c b/drivers/mtd/spi/sst.c
index e51dfc7..dcc0bbe 100644
--- a/drivers/mtd/spi/sst.c
+++ b/drivers/mtd/spi/sst.c
@@ -20,7 +20,6 @@
 
 #define CMD_SST_BP		0x02	/* Byte Program */
 #define CMD_SST_AAI_WP		0xAD	/* Auto Address Increment Word Program */
-#define CMD_SST_SE		0x20	/* Sector Erase */
 
 #define SST_SR_WIP		(1 << 0)	/* Write-in-Progress */
 #define SST_SR_WEL		(1 << 1)	/* Write enable */
@@ -45,13 +44,6 @@
 	const struct sst_spi_flash_params *params;
 };
 
-static inline struct sst_spi_flash *to_sst_spi_flash(struct spi_flash *flash)
-{
-	return container_of(flash, struct sst_spi_flash, flash);
-}
-
-#define SST_SECTOR_SIZE (4 * 1024)
-#define SST_PAGE_SIZE   256
 static const struct sst_spi_flash_params sst_spi_flash_table[] = {
 	{
 		.idcode1 = 0x8d,
@@ -211,11 +203,6 @@
 	return ret;
 }
 
-static int sst_erase(struct spi_flash *flash, u32 offset, size_t len)
-{
-	return spi_flash_cmd_erase(flash, CMD_SST_SE, offset, len);
-}
-
 static int
 sst_unlock(struct spi_flash *flash)
 {
@@ -269,10 +256,10 @@
 		stm->flash.write = sst_write_wp;
 	else
 		stm->flash.write = spi_flash_cmd_write_multi;
-	stm->flash.erase = sst_erase;
+	stm->flash.erase = spi_flash_cmd_erase;
 	stm->flash.read = spi_flash_cmd_read_fast;
-	stm->flash.page_size = SST_PAGE_SIZE;
-	stm->flash.sector_size = SST_SECTOR_SIZE;
+	stm->flash.page_size = 256;
+	stm->flash.sector_size = 4096;
 	stm->flash.size = stm->flash.sector_size * params->nr_sectors;
 
 	/* Flash powers up read-only, so clear BP# bits */
diff --git a/drivers/mtd/spi/stmicro.c b/drivers/mtd/spi/stmicro.c
index 6f7b807..75d6822 100644
--- a/drivers/mtd/spi/stmicro.c
+++ b/drivers/mtd/spi/stmicro.c
@@ -34,8 +34,6 @@
 #include "spi_flash_internal.h"
 
 /* M25Pxx-specific commands */
-#define CMD_M25PXX_SE		0xd8	/* Sector Erase */
-#define CMD_M25PXX_BE		0xc7	/* Bulk Erase */
 #define CMD_M25PXX_RES		0xab	/* Release from DP, and Read Signature */
 
 struct stmicro_spi_flash_params {
@@ -96,11 +94,6 @@
 	},
 };
 
-static int stmicro_erase(struct spi_flash *flash, u32 offset, size_t len)
-{
-	return spi_flash_cmd_erase(flash, CMD_M25PXX_SE, offset, len);
-}
-
 struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
 {
 	const struct stmicro_spi_flash_params *params;
@@ -142,7 +135,7 @@
 	flash->name = params->name;
 
 	flash->write = spi_flash_cmd_write_multi;
-	flash->erase = stmicro_erase;
+	flash->erase = spi_flash_cmd_erase;
 	flash->read = spi_flash_cmd_read_fast;
 	flash->page_size = 256;
 	flash->sector_size = 256 * params->pages_per_sector;
diff --git a/drivers/mtd/spi/winbond.c b/drivers/mtd/spi/winbond.c
index d1358ea..427b71f 100644
--- a/drivers/mtd/spi/winbond.c
+++ b/drivers/mtd/spi/winbond.c
@@ -10,11 +10,6 @@
 
 #include "spi_flash_internal.h"
 
-/* M25Pxx-specific commands */
-#define CMD_W25_SE		0x20	/* Sector (4K) Erase */
-#define CMD_W25_BE		0xd8	/* Block (64K) Erase */
-#define CMD_W25_CE		0xc7	/* Chip Erase */
-
 struct winbond_spi_flash_params {
 	uint16_t	id;
 	uint16_t	nr_blocks;
@@ -69,11 +64,6 @@
 	},
 };
 
-static int winbond_erase(struct spi_flash *flash, u32 offset, size_t len)
-{
-	return spi_flash_cmd_erase(flash, CMD_W25_SE, offset, len);
-}
-
 struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
 {
 	const struct winbond_spi_flash_params *params;
@@ -102,7 +92,7 @@
 	flash->name = params->name;
 
 	flash->write = spi_flash_cmd_write_multi;
-	flash->erase = winbond_erase;
+	flash->erase = spi_flash_cmd_erase;
 	flash->read = spi_flash_cmd_read_fast;
 	flash->page_size = 4096;
 	flash->sector_size = 4096;