>From 5acdefd0fa9a03a8e797462e88afca2f46cf9e04 Mon Sep 17 00:00:00 2001
From: Tadas Slotkus <devtadas@gmail.com>
Date: Fri, 19 Aug 2011 13:39:15 +0300
Subject: [carFl mem 43/65] enum programmer: move to globals

Move enum programmer type implementation to flash.h and remove
unsupported programmers.

Move variable of this type to globals structure. Move it's
initialisation to globals init function.

Signed-off-by: Tadas Slotkus <devtadas@gmail.com>
---
 cli_classic.c |    8 ++--
 flash.h       |   11 ++++++
 flashrom.c    |  101 ++++++++++++--------------------------------------------
 it87spi.c     |    2 +-
 programmer.h  |   60 ----------------------------------
 5 files changed, 38 insertions(+), 144 deletions(-)

diff --git a/cli_classic.c b/cli_classic.c
index e9dec65..1544d5e 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -257,8 +257,8 @@ int cli_classic(globals *g, int argc, char *argv[])
 #endif
 			break;
 		case 'p':
-			for (programmer = 0; programmer < PROGRAMMER_INVALID; programmer++) {
-				name = programmer_table[programmer].name;
+			for (g->programmer = 0; g->programmer < PROGRAMMER_INVALID; g->programmer++) {
+				name = programmer_table[g->programmer].name;
 				namelen = strlen(name);
 				if (strncmp(optarg, name, namelen) == 0) {
 					switch (optarg[namelen]) {
@@ -282,7 +282,7 @@ int cli_classic(globals *g, int argc, char *argv[])
 					break;
 				}
 			}
-			if (programmer == PROGRAMMER_INVALID) {
+			if (g->programmer == PROGRAMMER_INVALID) {
 				fprintf(stderr, "Error: Unknown programmer "
 					"%s.\n", optarg);
 				cli_classic_abort_usage();
@@ -332,7 +332,7 @@ int cli_classic(globals *g, int argc, char *argv[])
 #endif
 
 #if CONFIG_INTERNAL == 1
-	if ((programmer != PROGRAMMER_INTERNAL) && (lb_part || lb_vendor)) {
+	if ((g->programmer != PROGRAMMER_INTERNAL) && (lb_part || lb_vendor)) {
 		fprintf(stderr, "Error: --mainboard requires the internal "
 				"programmer. Aborting.\n");
 		cli_classic_abort_usage();
diff --git a/flash.h b/flash.h
index 7b88370..47b433b 100644
--- a/flash.h
+++ b/flash.h
@@ -279,7 +279,18 @@ int spi_send_command(globals *g, unsigned int writecnt, unsigned int readcnt,
 int spi_send_multicommand(globals *g, struct spi_command *cmds);
 uint32_t spi_get_valid_read_addr(void);
 
+enum programmer {
+#if CONFIG_INTERNAL == 1
+	PROGRAMMER_INTERNAL,
+#endif
+#if CONFIG_DUMMY == 1
+	PROGRAMMER_DUMMY,
+#endif
+	PROGRAMMER_INVALID /* This must always be the last entry. */
+};
+
 struct globals {
+	enum programmer programmer;
 };
 void init_globals(globals *g);
 
diff --git a/flashrom.c b/flashrom.c
index a217954..f425385 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -42,72 +42,15 @@ const char flashrom_version[] = "carFl";
 char *chip_to_probe = NULL;
 int verbose = 0;
 
-#if CONFIG_INTERNAL == 1
-enum programmer programmer = PROGRAMMER_INTERNAL;
-#elif CONFIG_DUMMY == 1
-enum programmer programmer = PROGRAMMER_DUMMY;
-#else
-/* If neither internal nor dummy are selected, we must pick a sensible default.
- * Since there is no reason to prefer a particular external programmer, we fail
- * if more than one of them is selected. If only one is selected, it is clear
- * that the user wants that one to become the default.
- */
-#if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT+CONFIG_FT2232_SPI+CONFIG_SERPROG+CONFIG_BUSPIRATE_SPI+CONFIG_DEDIPROG+CONFIG_RAYER_SPI+CONFIG_NICINTEL+CONFIG_NICINTEL_SPI+CONFIG_OGP_SPI+CONFIG_SATAMV > 1
-#error Please enable either CONFIG_DUMMY or CONFIG_INTERNAL or disable support for all programmers except one.
-#endif
-enum programmer programmer =
-#if CONFIG_NIC3COM == 1
-	PROGRAMMER_NIC3COM
-#endif
-#if CONFIG_NICREALTEK == 1
-	PROGRAMMER_NICREALTEK
-#endif
-#if CONFIG_NICNATSEMI == 1
-	PROGRAMMER_NICNATSEMI
-#endif
-#if CONFIG_GFXNVIDIA == 1
-	PROGRAMMER_GFXNVIDIA
-#endif
-#if CONFIG_DRKAISER == 1
-	PROGRAMMER_DRKAISER
-#endif
-#if CONFIG_SATASII == 1
-	PROGRAMMER_SATASII
-#endif
-#if CONFIG_ATAHPT == 1
-	PROGRAMMER_ATAHPT
-#endif
-#if CONFIG_FT2232_SPI == 1
-	PROGRAMMER_FT2232_SPI
-#endif
-#if CONFIG_SERPROG == 1
-	PROGRAMMER_SERPROG
-#endif
-#if CONFIG_BUSPIRATE_SPI == 1
-	PROGRAMMER_BUSPIRATE_SPI
-#endif
-#if CONFIG_DEDIPROG == 1
-	PROGRAMMER_DEDIPROG
-#endif
-#if CONFIG_RAYER_SPI == 1
-	PROGRAMMER_RAYER_SPI
-#endif
-#if CONFIG_NICINTEL == 1
-	PROGRAMMER_NICINTEL
-#endif
-#if CONFIG_NICINTEL_SPI == 1
-	PROGRAMMER_NICINTEL_SPI
-#endif
-#if CONFIG_OGP_SPI == 1
-	PROGRAMMER_OGP_SPI
-#endif
-#if CONFIG_SATAMV == 1
-	PROGRAMMER_SATAMV
-#endif
-;
-#endif
 void init_globals(globals *g)
 {
+	#if CONFIG_INTERNAL == 1
+	g->programmer = PROGRAMMER_INTERNAL;
+	#elif CONFIG_DUMMY == 1
+	g->programmer = PROGRAMMER_DUMMY;
+	#else
+	#error Please enable either CONFIG_DUMMY or CONFIG_INTERNAL
+	#endif
 }
 
 static char *programmer_param = NULL;
@@ -518,8 +461,8 @@ int programmer_init(globals *g, char *param)
 
 	programmer_param = param;
 	msg_pdbg("Initializing %s programmer\n",
-		 programmer_table[programmer].name);
-	ret = programmer_table[programmer].init(g);
+		 programmer_table[g->programmer].name);
+	ret = programmer_table[g->programmer].init(g);
 	if (programmer_param && strlen(programmer_param)) {
 		msg_perr("Unhandled programmer parameters: %s\n",
 			 programmer_param);
@@ -544,58 +487,58 @@ int programmer_shutdown(void)
 void *programmer_map_flash_region(globals *g, const char *descr, unsigned long phys_addr,
 				  size_t len)
 {
-	return programmer_table[programmer].map_flash_region(descr,
+	return programmer_table[g->programmer].map_flash_region(descr,
 							     phys_addr, len);
 }
 
 void programmer_unmap_flash_region(globals *g, void *virt_addr, size_t len)
 {
-	programmer_table[programmer].unmap_flash_region(virt_addr, len);
+	programmer_table[g->programmer].unmap_flash_region(virt_addr, len);
 }
 
 void chip_writeb(globals *g, uint8_t val, chipaddr addr)
 {
-	programmer_table[programmer].chip_writeb(val, addr);
+	programmer_table[g->programmer].chip_writeb(val, addr);
 }
 
 void chip_writew(globals *g, uint16_t val, chipaddr addr)
 {
-	programmer_table[programmer].chip_writew(val, addr);
+	programmer_table[g->programmer].chip_writew(val, addr);
 }
 
 void chip_writel(globals *g, uint32_t val, chipaddr addr)
 {
-	programmer_table[programmer].chip_writel(val, addr);
+	programmer_table[g->programmer].chip_writel(val, addr);
 }
 
 void chip_writen(globals *g, uint8_t *buf, chipaddr addr, size_t len)
 {
-	programmer_table[programmer].chip_writen(buf, addr, len);
+	programmer_table[g->programmer].chip_writen(buf, addr, len);
 }
 
 uint8_t chip_readb(globals *g, const chipaddr addr)
 {
-	return programmer_table[programmer].chip_readb(addr);
+	return programmer_table[g->programmer].chip_readb(addr);
 }
 
 uint16_t chip_readw(globals *g, const chipaddr addr)
 {
-	return programmer_table[programmer].chip_readw(addr);
+	return programmer_table[g->programmer].chip_readw(addr);
 }
 
 uint32_t chip_readl(globals *g, const chipaddr addr)
 {
-	return programmer_table[programmer].chip_readl(addr);
+	return programmer_table[g->programmer].chip_readl(addr);
 }
 
 void chip_readn(globals *g, uint8_t *buf, chipaddr addr, size_t len)
 {
-	programmer_table[programmer].chip_readn(buf, addr, len);
+	programmer_table[g->programmer].chip_readn(buf, addr, len);
 }
 
 void programmer_delay(globals *g, int usecs)
 {
-	programmer_table[programmer].delay(usecs);
+	programmer_table[g->programmer].delay(usecs);
 }
 
 void map_flash_registers(globals *g, struct flashchip *flash)
@@ -1189,11 +1132,11 @@ notfound:
 		return -1;
 
 #if CONFIG_INTERNAL == 1
-	if (programmer_table[programmer].map_flash_region == physmap)
+	if (programmer_table[g->programmer].map_flash_region == physmap)
 		snprintf(location, sizeof(location), "at physical address 0x%lx", base);
 	else
 #endif
-		snprintf(location, sizeof(location), "on %s", programmer_table[programmer].name);
+		snprintf(location, sizeof(location), "on %s", programmer_table[g->programmer].name);
 
 	tmp = flashbuses_to_text(flash->bustype);
 	msg_cinfo("%s %s flash chip \"%s\" (%d kB, %s) %s.\n",
diff --git a/it87spi.c b/it87spi.c
index 33c27fd..3c01bcb 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -132,7 +132,7 @@ static uint16_t it87spi_probe(globals *g, uint16_t port)
 	/* If IT87SPI was not explicitly selected, we want to check
 	 * quickly if LPC->SPI translation is active.
 	 */
-	if ((programmer == PROGRAMMER_INTERNAL) && !(tmp & (0x0E))) {
+	if ((g->programmer == PROGRAMMER_INTERNAL) && !(tmp & (0x0E))) {
 		msg_pdbg("No IT87* serial flash segment enabled.\n");
 		exit_conf_mode_ite(port);
 		/* Nothing to do. */
diff --git a/programmer.h b/programmer.h
index abebf68..dc8d8d9 100644
--- a/programmer.h
+++ b/programmer.h
@@ -24,66 +24,6 @@
 #ifndef __PROGRAMMER_H__
 #define __PROGRAMMER_H__ 1
 
-enum programmer {
-#if CONFIG_INTERNAL == 1
-	PROGRAMMER_INTERNAL,
-#endif
-#if CONFIG_DUMMY == 1
-	PROGRAMMER_DUMMY,
-#endif
-#if CONFIG_NIC3COM == 1
-	PROGRAMMER_NIC3COM,
-#endif
-#if CONFIG_NICREALTEK == 1
-	PROGRAMMER_NICREALTEK,
-#endif
-#if CONFIG_NICNATSEMI == 1
-	PROGRAMMER_NICNATSEMI,
-#endif
-#if CONFIG_GFXNVIDIA == 1
-	PROGRAMMER_GFXNVIDIA,
-#endif
-#if CONFIG_DRKAISER == 1
-	PROGRAMMER_DRKAISER,
-#endif
-#if CONFIG_SATASII == 1
-	PROGRAMMER_SATASII,
-#endif
-#if CONFIG_ATAHPT == 1
-	PROGRAMMER_ATAHPT,
-#endif
-#if CONFIG_FT2232_SPI == 1
-	PROGRAMMER_FT2232_SPI,
-#endif
-#if CONFIG_SERPROG == 1
-	PROGRAMMER_SERPROG,
-#endif
-#if CONFIG_BUSPIRATE_SPI == 1
-	PROGRAMMER_BUSPIRATE_SPI,
-#endif
-#if CONFIG_DEDIPROG == 1
-	PROGRAMMER_DEDIPROG,
-#endif
-#if CONFIG_RAYER_SPI == 1
-	PROGRAMMER_RAYER_SPI,
-#endif
-#if CONFIG_NICINTEL == 1
-	PROGRAMMER_NICINTEL,
-#endif
-#if CONFIG_NICINTEL_SPI == 1
-	PROGRAMMER_NICINTEL_SPI,
-#endif
-#if CONFIG_OGP_SPI == 1
-	PROGRAMMER_OGP_SPI,
-#endif
-#if CONFIG_SATAMV == 1
-	PROGRAMMER_SATAMV,
-#endif
-	PROGRAMMER_INVALID /* This must always be the last entry. */
-};
-
-extern enum programmer programmer;
-
 struct programmer_entry {
 	const char *vendor;
 	const char *name;
-- 
1.7.6

