Kill global variables, constants and functions if local scope suffices

Constify variables where possible.
Initialize programmer-related variables explicitly in programmer_init to
allow running programmer_init from a clean state after
programmer_shutdown.
Prohibit registering programmer shutdown functions before init or after
shutdown.
Kill some dead code.
Rename global variables with namespace-polluting names.
Use a previously unused locking helper function in sst49lfxxxc.c.

This is needed for libflashrom.

Effects on the binary size of flashrom are minimal (300 bytes
shrinkage), but the data section shrinks by 4384 bytes, and that's a
good thing if flashrom is operating in constrained envionments.

Corresponding to flashrom svn r1068.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Michael Karcher <flashrom@mkarcher.dialup.fu-berlin.de>
diff --git a/dediprog.c b/dediprog.c
index 206d860..0b92983 100644
--- a/dediprog.c
+++ b/dediprog.c
@@ -24,19 +24,21 @@
 #include "spi.h"
 
 #define DEFAULT_TIMEOUT 3000
-usb_dev_handle *dediprog_handle;
+static usb_dev_handle *dediprog_handle;
 
-int dediprog_do_stuff(void);
-
-void print_hex(void *buf, size_t len)
+#if 0
+/* Might be useful for other pieces of code as well. */
+static void print_hex(void *buf, size_t len)
 {
 	size_t i;
 
 	for (i = 0; i < len; i++)
 		msg_pdbg(" %02x", ((uint8_t *)buf)[i]);
 }
+#endif
 
-struct usb_device *get_device_by_vid_pid(uint16_t vid, uint16_t pid)
+/* Might be useful for other USB devices as well. static for now. */
+static struct usb_device *get_device_by_vid_pid(uint16_t vid, uint16_t pid)
 {
 	struct usb_bus *bus;
 	struct usb_device *dev;
@@ -52,7 +54,7 @@
 
 //int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout);
 
-int dediprog_set_spi_voltage(uint16_t voltage)
+static int dediprog_set_spi_voltage(uint16_t voltage)
 {
 	int ret;
 	unsigned int mv;
@@ -85,6 +87,7 @@
 	return 0;
 }
 
+#if 0
 /* After dediprog_set_spi_speed, the original app always calls
  * dediprog_set_spi_voltage(0) and then
  * dediprog_check_devicestring() four times in a row.
@@ -92,7 +95,7 @@
  * This looks suspiciously like the microprocessor in the SF100 has to be
  * restarted/reinitialized in case the speed changes.
  */
-int dediprog_set_spi_speed(uint16_t speed)
+static int dediprog_set_spi_speed(uint16_t speed)
 {
 	int ret;
 	unsigned int khz;
@@ -140,6 +143,7 @@
 	}
 	return 0;
 }
+#endif
 
 int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len)
 {
@@ -183,7 +187,7 @@
 	return 0;
 }
 
-int dediprog_check_devicestring(void)
+static int dediprog_check_devicestring(void)
 {
 	int ret;
 	char buf[0x11];
@@ -223,7 +227,7 @@
  * dediprog_check_devicestring (often) or Command A (often) or
  * Command F (once).
  */
-int dediprog_command_a(void)
+static int dediprog_command_a(void)
 {
 	int ret;
 	char buf[0x1];
@@ -242,7 +246,7 @@
  * dediprog_command_a(); dediprog_check_devicestring() sequence in each session.
  * I'm tempted to call this one start_SPI_engine or finish_init.
  */
-int dediprog_command_c(void)
+static int dediprog_command_c(void)
 {
 	int ret;
 
@@ -254,11 +258,12 @@
 	return 0;
 }
 
+#if 0
 /* Very strange. Seems to be a programmer keepalive or somesuch.
  * Wait unsuccessfully for timeout ms to read one byte.
  * Is usually called after setting voltage to 0.
  */
-int dediprog_command_f(int timeout)
+static int dediprog_command_f(int timeout)
 {
 	int ret;
 	char buf[0x1];
@@ -271,6 +276,7 @@
 	}
 	return 0;
 }
+#endif
 
 /* URB numbers refer to the first log ever captured. */
 int dediprog_init(void)
@@ -323,10 +329,11 @@
 	return 0;
 }
 
+#if 0
 /* Leftovers from reverse engineering. Keep for documentation purposes until
  * completely understood.
  */
-int dediprog_do_stuff(void)
+static int dediprog_do_stuff(void)
 {
 	char buf[0x4];
 	/* SPI command processing starts here. */
@@ -341,7 +348,6 @@
 		return 1;
 	msg_pdbg("Receiving response: ");
 	print_hex(buf, JEDEC_RDID_INSIZE);
-#if 0
 	/* URB 14-27 are more SPI commands. */
 	/* URB 28. Command Set SPI Voltage. */
 	if (dediprog_set_spi_voltage(0x0))
@@ -369,12 +375,10 @@
 	/* Command I is probably Start Bulk Read. Data is u16 blockcount, u16 blocksize. */
 	/* Command J is probably Start Bulk Write. Data is u16 blockcount, u16 blocksize. */
 	/* Bulk transfer sizes for Command I/J are always 512 bytes, rest is filled with 0xff. */
-#endif	
 
-	msg_pinfo("All probes will fail because this driver is not hooked up "
-		  "to the SPI infrastructure yet.");
 	return 0;
 }
+#endif	
 
 int dediprog_shutdown(void)
 {