>From e32e0e6c3df4ba223808ec28f8e586d46ca81378 Mon Sep 17 00:00:00 2001
From: Tadas Slotkus <devtadas@gmail.com>
Date: Wed, 17 Aug 2011 14:58:53 +0300
Subject: [carFl mem 16/21] Fix enum programmer

Move enum type declaration to flash.h as it will be needed by globals
struct. Remove unneded programmers there, move enum programmer variable
to globals.

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

diff --git a/cli_classic.c b/cli_classic.c
index e527778..c341781 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -264,8 +264,8 @@ int cli_classic(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]) {
@@ -289,7 +289,7 @@ int cli_classic(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();
@@ -339,7 +339,7 @@ int cli_classic(int argc, char *argv[])
 #endif
 
 #if CONFIG_INTERNAL == 1
-	if ((programmer != PROGRAMMER_INTERNAL) && (g->lb_part || g->lb_vendor)) {
+	if ((g->programmer != PROGRAMMER_INTERNAL) && (g->lb_part || g->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 84051f3..36bf1f2 100644
--- a/flash.h
+++ b/flash.h
@@ -276,6 +276,16 @@ int spi_send_command(unsigned int writecnt, unsigned int readcnt,
 int spi_send_multicommand(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 {
 	/* Supported buses for the current programmer. */
 	enum chipbustype buses_supported;
@@ -286,6 +296,7 @@ struct globals {
 	int partvendor_from_cbtable;
 
 	struct pci_access *pacc;
+	enum programmer programmer;
 };
 globals *get_globals(void);
 
diff --git a/flashrom.c b/flashrom.c
index c6cfefa..4aee7bf 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -94,77 +94,19 @@ static void init_globals(void)
 	g.verbose = 0;
 	g.chip_to_probe = NULL;
 
+	#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
+
 	g.lb_part = NULL, g.lb_vendor = NULL;
 	g.partvendor_from_cbtable = 0;
-
 	sync_all_globals();
 }
 
-#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
-
 static char *programmer_param = NULL;
 
 /*
@@ -570,8 +512,8 @@ int programmer_init(char *param)
 
 	programmer_param = param;
 	msg_pdbg("Initializing %s programmer\n",
-		 programmer_table[programmer].name);
-	ret = programmer_table[programmer].init();
+		 programmer_table[g.programmer].name);
+	ret = programmer_table[g.programmer].init();
 	if (programmer_param && strlen(programmer_param)) {
 		msg_perr("Unhandled programmer parameters: %s\n",
 			 programmer_param);
@@ -596,58 +538,58 @@ int programmer_shutdown(void)
 void *programmer_map_flash_region(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(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(uint8_t val, chipaddr addr)
 {
-	programmer_table[programmer].chip_writeb(val, addr);
+	programmer_table[g.programmer].chip_writeb(val, addr);
 }
 
 void chip_writew(uint16_t val, chipaddr addr)
 {
-	programmer_table[programmer].chip_writew(val, addr);
+	programmer_table[g.programmer].chip_writew(val, addr);
 }
 
 void chip_writel(uint32_t val, chipaddr addr)
 {
-	programmer_table[programmer].chip_writel(val, addr);
+	programmer_table[g.programmer].chip_writel(val, addr);
 }
 
 void chip_writen(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(const chipaddr addr)
 {
-	return programmer_table[programmer].chip_readb(addr);
+	return programmer_table[g.programmer].chip_readb(addr);
 }
 
 uint16_t chip_readw(const chipaddr addr)
 {
-	return programmer_table[programmer].chip_readw(addr);
+	return programmer_table[g.programmer].chip_readw(addr);
 }
 
 uint32_t chip_readl(const chipaddr addr)
 {
-	return programmer_table[programmer].chip_readl(addr);
+	return programmer_table[g.programmer].chip_readl(addr);
 }
 
 void chip_readn(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(int usecs)
 {
-	programmer_table[programmer].delay(usecs);
+	programmer_table[g.programmer].delay(usecs);
 }
 
 void map_flash_registers(struct flashchip *flash)
@@ -1241,11 +1183,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 0db0511..494f70e 100644
--- a/it87spi.c
+++ b/it87spi.c
@@ -139,7 +139,7 @@ static uint16_t it87spi_probe(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 9dcc6d2..157a8f7 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

