>From d26ace077b737fa5f52678debcf4f20aa03d5794 Mon Sep 17 00:00:00 2001
From: Tadas Slotkus <devtadas@gmail.com>
Date: Fri, 19 Aug 2011 14:36:22 +0300
Subject: [carFl mem 12/65] Globalisation pass 1: 82802ab.c

This commit breaks builds until "Globalistation pass 1: fixes".

It does nothing more, just passes globals structure across function
calls.

Signed-off-by: Tadas Slotkus <devtadas@gmail.com>
---
 82802ab.c |   78 ++++++++++++++++++++++++++++++------------------------------
 1 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/82802ab.c b/82802ab.c
index cd59c07..6118146 100644
--- a/82802ab.c
+++ b/82802ab.c
@@ -40,27 +40,27 @@ void print_status_82802ab(uint8_t status)
 	msg_cdbg("%s", status & 0x2 ? "WP|TBL#|WP#,ABORT:" : "UNLOCK:");
 }
 
-int probe_82802ab(struct flashchip *flash)
+int probe_82802ab(globals *g, struct flashchip *flash)
 {
 	chipaddr bios = flash->virtual_memory;
 	uint8_t id1, id2, flashcontent1, flashcontent2;
 	int shifted = (flash->feature_bits & FEATURE_ADDR_SHIFTED) != 0;
 
 	/* Reset to get a clean state */
-	chip_writeb(0xFF, bios);
-	programmer_delay(10);
+	chip_writeb(g, 0xFF, bios);
+	programmer_delay(g, 10);
 
 	/* Enter ID mode */
-	chip_writeb(0x90, bios);
-	programmer_delay(10);
+	chip_writeb(g, 0x90, bios);
+	programmer_delay(g, 10);
 
-	id1 = chip_readb(bios + (0x00 << shifted));
-	id2 = chip_readb(bios + (0x01 << shifted));
+	id1 = chip_readb(g, bios + (0x00 << shifted));
+	id2 = chip_readb(g, bios + (0x01 << shifted));
 
 	/* Leave ID mode */
-	chip_writeb(0xFF, bios);
+	chip_writeb(g, 0xFF, bios);
 
-	programmer_delay(10);
+	programmer_delay(g, 10);
 
 	msg_cdbg("%s: id1 0x%02x, id2 0x%02x", __func__, id1, id2);
 
@@ -71,8 +71,8 @@ int probe_82802ab(struct flashchip *flash)
 	 * Read the product ID location again. We should now see normal
 	 * flash contents.
 	 */
-	flashcontent1 = chip_readb(bios + (0x00 << shifted));
-	flashcontent2 = chip_readb(bios + (0x01 << shifted));
+	flashcontent1 = chip_readb(g, bios + (0x00 << shifted));
+	flashcontent2 = chip_readb(g, bios + (0x01 << shifted));
 
 	if (id1 == flashcontent1)
 		msg_cdbg(", id1 is normal flash content");
@@ -84,56 +84,56 @@ int probe_82802ab(struct flashchip *flash)
 		return 0;
 
 	if (flash->feature_bits & FEATURE_REGISTERMAP)
-		map_flash_registers(flash);
+		map_flash_registers(g, flash);
 
 	return 1;
 }
 
-uint8_t wait_82802ab(struct flashchip *flash)
+uint8_t wait_82802ab(globals *g, struct flashchip *flash)
 {
 	uint8_t status;
 	chipaddr bios = flash->virtual_memory;
 
-	chip_writeb(0x70, bios);
-	if ((chip_readb(bios) & 0x80) == 0) {	// it's busy
-		while ((chip_readb(bios) & 0x80) == 0) ;
+	chip_writeb(g, 0x70, bios);
+	if ((chip_readb(g, bios) & 0x80) == 0) {	// it's busy
+		while ((chip_readb(g, bios) & 0x80) == 0) ;
 	}
 
-	status = chip_readb(bios);
+	status = chip_readb(g, bios);
 
 	/* Reset to get a clean state */
-	chip_writeb(0xFF, bios);
+	chip_writeb(g, 0xFF, bios);
 
 	return status;
 }
 
-int unlock_82802ab(struct flashchip *flash)
+int unlock_82802ab(globals *g, struct flashchip *flash)
 {
 	int i;
 	//chipaddr wrprotect = flash->virtual_registers + page + 2;
 
 	for (i = 0; i < flash->total_size * 1024; i+= flash->page_size)
-		chip_writeb(0, flash->virtual_registers + i + 2);
+		chip_writeb(g, 0, flash->virtual_registers + i + 2);
 
 	return 0;
 }
 
-int erase_block_82802ab(struct flashchip *flash, unsigned int page,
+int erase_block_82802ab(globals *g, struct flashchip *flash, unsigned int page,
 			unsigned int pagesize)
 {
 	chipaddr bios = flash->virtual_memory;
 	uint8_t status;
 
 	// clear status register
-	chip_writeb(0x50, bios + page);
+	chip_writeb(g, 0x50, bios + page);
 
 	// now start it
-	chip_writeb(0x20, bios + page);
-	chip_writeb(0xd0, bios + page);
-	programmer_delay(10);
+	chip_writeb(g, 0x20, bios + page);
+	chip_writeb(g, 0xd0, bios + page);
+	programmer_delay(g, 10);
 
 	// now let's see what the register is
-	status = wait_82802ab(flash);
+	status = wait_82802ab(g, flash);
 	print_status_82802ab(status);
 
 	/* FIXME: Check the status register for errors. */
@@ -141,36 +141,36 @@ int erase_block_82802ab(struct flashchip *flash, unsigned int page,
 }
 
 /* chunksize is 1 */
-int write_82802ab(struct flashchip *flash, uint8_t *src, int start, int len)
+int write_82802ab(globals *g, struct flashchip *flash, uint8_t *src, int start, int len)
 {
 	int i;
 	chipaddr dst = flash->virtual_memory + start;
 
 	for (i = 0; i < len; i++) {
 		/* transfer data from source to destination */
-		chip_writeb(0x40, dst);
-		chip_writeb(*src++, dst++);
-		wait_82802ab(flash);
+		chip_writeb(g, 0x40, dst);
+		chip_writeb(g, *src++, dst++);
+		wait_82802ab(g, flash);
 	}
 
 	/* FIXME: Ignore errors for now. */
 	return 0;
 }
 
-int unlock_28f004s5(struct flashchip *flash)
+int unlock_28f004s5(globals *g, struct flashchip *flash)
 {
 	chipaddr bios = flash->virtual_memory;
 	uint8_t mcfg, bcfg, need_unlock = 0, can_unlock = 0;
 	int i;
 
 	/* Clear status register */
-	chip_writeb(0x50, bios);
+	chip_writeb(g, 0x50, bios);
 
 	/* Read identifier codes */
-	chip_writeb(0x90, bios);
+	chip_writeb(g, 0x90, bios);
 
 	/* Read master lock-bit */
-	mcfg = chip_readb(bios + 0x3);
+	mcfg = chip_readb(g, bios + 0x3);
 	msg_cdbg("master lock is ");
 	if (mcfg) {
 		msg_cdbg("locked!\n");
@@ -181,7 +181,7 @@ int unlock_28f004s5(struct flashchip *flash)
 
 	/* Read block lock-bits */
 	for (i = 0; i < flash->total_size * 1024; i+= (64 * 1024)) {
-		bcfg = chip_readb(bios + i + 2); // read block lock config
+		bcfg = chip_readb(g, bios + i + 2); // read block lock config
 		msg_cdbg("block lock at %06x is %slocked!\n", i, bcfg ? "" : "un");
 		if (bcfg) {
 			need_unlock = 1;
@@ -189,14 +189,14 @@ int unlock_28f004s5(struct flashchip *flash)
 	}
 
 	/* Reset chip */
-	chip_writeb(0xFF, bios);
+	chip_writeb(g, 0xFF, bios);
 
 	/* Unlock: clear block lock-bits, if needed */
 	if (can_unlock && need_unlock) {
 		msg_cdbg("Unlock: ");
-		chip_writeb(0x60, bios);
-		chip_writeb(0xD0, bios);
-		chip_writeb(0xFF, bios);
+		chip_writeb(g, 0x60, bios);
+		chip_writeb(g, 0xD0, bios);
+		chip_writeb(g, 0xFF, bios);
 		msg_cdbg("Done!\n");
 	}
 
-- 
1.7.6

