>From 590a528c09fd77a572b95d5a0200b5e09c6b40af Mon Sep 17 00:00:00 2001
From: Tadas Slotkus <devtadas@gmail.com>
Date: Fri, 19 Aug 2011 15:10:15 +0300
Subject: [carFl mem 19/65] Globalisation pass 1: jedec.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>
---
 jedec.c |  226 +++++++++++++++++++++++++++++++-------------------------------
 1 files changed, 113 insertions(+), 113 deletions(-)

diff --git a/jedec.c b/jedec.c
index b96f5fd..efa2055 100644
--- a/jedec.c
+++ b/jedec.c
@@ -38,17 +38,17 @@ uint8_t oddparity(uint8_t val)
 	return (val ^ (val >> 1)) & 0x1;
 }
 
-static void toggle_ready_jedec_common(chipaddr dst, int delay)
+static void toggle_ready_jedec_common(globals *g, chipaddr dst, int delay)
 {
 	unsigned int i = 0;
 	uint8_t tmp1, tmp2;
 
-	tmp1 = chip_readb(dst) & 0x40;
+	tmp1 = chip_readb(g, dst) & 0x40;
 
 	while (i++ < 0xFFFFFFF) {
 		if (delay)
-			programmer_delay(delay);
-		tmp2 = chip_readb(dst) & 0x40;
+			programmer_delay(g, delay);
+		tmp2 = chip_readb(g, dst) & 0x40;
 		if (tmp1 == tmp2) {
 			break;
 		}
@@ -58,9 +58,9 @@ static void toggle_ready_jedec_common(chipaddr dst, int delay)
 		msg_cdbg("%s: excessive loops, i=0x%x\n", __func__, i);
 }
 
-void toggle_ready_jedec(chipaddr dst)
+void toggle_ready_jedec(globals *g, chipaddr dst)
 {
-	toggle_ready_jedec_common(dst, 0);
+	toggle_ready_jedec_common(g, dst, 0);
 }
 
 /* Some chips require a minimum delay between toggle bit reads.
@@ -70,12 +70,12 @@ void toggle_ready_jedec(chipaddr dst)
  * Given that erase is slow on all chips, it is recommended to use 
  * toggle_ready_jedec_slow in erase functions.
  */
-static void toggle_ready_jedec_slow(chipaddr dst)
+static void toggle_ready_jedec_slow(globals *g, chipaddr dst)
 {
-	toggle_ready_jedec_common(dst, 8 * 1000);
+	toggle_ready_jedec_common(g, dst, 8 * 1000);
 }
 
-void data_polling_jedec(chipaddr dst, uint8_t data)
+void data_polling_jedec(globals *g, chipaddr dst, uint8_t data)
 {
 	unsigned int i = 0;
 	uint8_t tmp;
@@ -83,7 +83,7 @@ void data_polling_jedec(chipaddr dst, uint8_t data)
 	data &= 0x80;
 
 	while (i++ < 0xFFFFFFF) {
-		tmp = chip_readb(dst) & 0x80;
+		tmp = chip_readb(g, dst) & 0x80;
 		if (tmp == data) {
 			break;
 		}
@@ -111,15 +111,15 @@ static int getaddrmask(struct flashchip *flash)
 	}
 }
 
-static void start_program_jedec_common(struct flashchip *flash, unsigned int mask)
+static void start_program_jedec_common(globals *g, struct flashchip *flash, unsigned int mask)
 {
 	chipaddr bios = flash->virtual_memory;
-	chip_writeb(0xAA, bios + (0x5555 & mask));
-	chip_writeb(0x55, bios + (0x2AAA & mask));
-	chip_writeb(0xA0, bios + (0x5555 & mask));
+	chip_writeb(g, 0xAA, bios + (0x5555 & mask));
+	chip_writeb(g, 0x55, bios + (0x2AAA & mask));
+	chip_writeb(g, 0xA0, bios + (0x5555 & mask));
 }
 
-static int probe_jedec_common(struct flashchip *flash, unsigned int mask)
+static int probe_jedec_common(globals *g, struct flashchip *flash, unsigned int mask)
 {
 	chipaddr bios = flash->virtual_memory;
 	uint8_t id1, id2;
@@ -147,80 +147,80 @@ static int probe_jedec_common(struct flashchip *flash, unsigned int mask)
 	 * reset command.
 	 */
 	if (probe_timing_enter)
-		programmer_delay(probe_timing_enter);
+		programmer_delay(g, probe_timing_enter);
 	/* Reset chip to a clean slate */
 	if ((flash->feature_bits & FEATURE_RESET_MASK) == FEATURE_LONG_RESET)
 	{
-		chip_writeb(0xAA, bios + (0x5555 & mask));
+		chip_writeb(g, 0xAA, bios + (0x5555 & mask));
 		if (probe_timing_exit)
-			programmer_delay(10);
-		chip_writeb(0x55, bios + (0x2AAA & mask));
+			programmer_delay(g, 10);
+		chip_writeb(g, 0x55, bios + (0x2AAA & mask));
 		if (probe_timing_exit)
-			programmer_delay(10);
+			programmer_delay(g, 10);
 	}
-	chip_writeb(0xF0, bios + (0x5555 & mask));
+	chip_writeb(g, 0xF0, bios + (0x5555 & mask));
 	if (probe_timing_exit)
-		programmer_delay(probe_timing_exit);
+		programmer_delay(g, probe_timing_exit);
 
 	/* Issue JEDEC Product ID Entry command */
-	chip_writeb(0xAA, bios + (0x5555 & mask));
+	chip_writeb(g, 0xAA, bios + (0x5555 & mask));
 	if (probe_timing_enter)
-		programmer_delay(10);
-	chip_writeb(0x55, bios + (0x2AAA & mask));
+		programmer_delay(g, 10);
+	chip_writeb(g, 0x55, bios + (0x2AAA & mask));
 	if (probe_timing_enter)
-		programmer_delay(10);
-	chip_writeb(0x90, bios + (0x5555 & mask));
+		programmer_delay(g, 10);
+	chip_writeb(g, 0x90, bios + (0x5555 & mask));
 	if (probe_timing_enter)
-		programmer_delay(probe_timing_enter);
+		programmer_delay(g, probe_timing_enter);
 
 	/* Read product ID */
-	id1 = chip_readb(bios);
-	id2 = chip_readb(bios + 0x01);
+	id1 = chip_readb(g, bios);
+	id2 = chip_readb(g, bios + 0x01);
 	largeid1 = id1;
 	largeid2 = id2;
 
 	/* Check if it is a continuation ID, this should be a while loop. */
 	if (id1 == 0x7F) {
 		largeid1 <<= 8;
-		id1 = chip_readb(bios + 0x100);
+		id1 = chip_readb(g, bios + 0x100);
 		largeid1 |= id1;
 	}
 	if (id2 == 0x7F) {
 		largeid2 <<= 8;
-		id2 = chip_readb(bios + 0x101);
+		id2 = chip_readb(g, bios + 0x101);
 		largeid2 |= id2;
 	}
 
 	/* Issue JEDEC Product ID Exit command */
 	if ((flash->feature_bits & FEATURE_RESET_MASK) == FEATURE_LONG_RESET)
 	{
-		chip_writeb(0xAA, bios + (0x5555 & mask));
+		chip_writeb(g, 0xAA, bios + (0x5555 & mask));
 		if (probe_timing_exit)
-			programmer_delay(10);
-		chip_writeb(0x55, bios + (0x2AAA & mask));
+			programmer_delay(g, 10);
+		chip_writeb(g, 0x55, bios + (0x2AAA & mask));
 		if (probe_timing_exit)
-			programmer_delay(10);
+			programmer_delay(g, 10);
 	}
-	chip_writeb(0xF0, bios + (0x5555 & mask));
+	chip_writeb(g, 0xF0, bios + (0x5555 & mask));
 	if (probe_timing_exit)
-		programmer_delay(probe_timing_exit);
+		programmer_delay(g, probe_timing_exit);
 
 	msg_cdbg("%s: id1 0x%02x, id2 0x%02x", __func__, largeid1, largeid2);
 	if (!oddparity(id1))
 		msg_cdbg(", id1 parity violation");
 
 	/* Read the product ID location again. We should now see normal flash contents. */
-	flashcontent1 = chip_readb(bios);
-	flashcontent2 = chip_readb(bios + 0x01);
+	flashcontent1 = chip_readb(g, bios);
+	flashcontent2 = chip_readb(g, bios + 0x01);
 
 	/* Check if it is a continuation ID, this should be a while loop. */
 	if (flashcontent1 == 0x7F) {
 		flashcontent1 <<= 8;
-		flashcontent1 |= chip_readb(bios + 0x100);
+		flashcontent1 |= chip_readb(g, bios + 0x100);
 	}
 	if (flashcontent2 == 0x7F) {
 		flashcontent2 <<= 8;
-		flashcontent2 |= chip_readb(bios + 0x101);
+		flashcontent2 |= chip_readb(g, bios + 0x101);
 	}
 
 	if (largeid1 == flashcontent1)
@@ -233,12 +233,12 @@ static int probe_jedec_common(struct flashchip *flash, unsigned int mask)
 		return 0;
 
 	if (flash->feature_bits & FEATURE_REGISTERMAP)
-		map_flash_registers(flash);
+		map_flash_registers(g, flash);
 
 	return 1;
 }
 
-static int erase_sector_jedec_common(struct flashchip *flash, unsigned int page,
+static int erase_sector_jedec_common(globals *g, struct flashchip *flash, unsigned int page,
 			      unsigned int pagesize, unsigned int mask)
 {
 	chipaddr bios = flash->virtual_memory;
@@ -247,28 +247,28 @@ static int erase_sector_jedec_common(struct flashchip *flash, unsigned int page,
 	        delay_us = 10;
 
 	/*  Issue the Sector Erase command   */
-	chip_writeb(0xAA, bios + (0x5555 & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x55, bios + (0x2AAA & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x80, bios + (0x5555 & mask));
-	programmer_delay(delay_us);
-
-	chip_writeb(0xAA, bios + (0x5555 & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x55, bios + (0x2AAA & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x30, bios + page);
-	programmer_delay(delay_us);
+	chip_writeb(g, 0xAA, bios + (0x5555 & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x55, bios + (0x2AAA & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x80, bios + (0x5555 & mask));
+	programmer_delay(g, delay_us);
+
+	chip_writeb(g, 0xAA, bios + (0x5555 & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x55, bios + (0x2AAA & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x30, bios + page);
+	programmer_delay(g, delay_us);
 
 	/* wait for Toggle bit ready         */
-	toggle_ready_jedec_slow(bios);
+	toggle_ready_jedec_slow(g, bios);
 
 	/* FIXME: Check the status register for errors. */
 	return 0;
 }
 
-static int erase_block_jedec_common(struct flashchip *flash, unsigned int block,
+static int erase_block_jedec_common(globals *g, struct flashchip *flash, unsigned int block,
 			     unsigned int blocksize, unsigned int mask)
 {
 	chipaddr bios = flash->virtual_memory;
@@ -277,28 +277,28 @@ static int erase_block_jedec_common(struct flashchip *flash, unsigned int block,
 	        delay_us = 10;
 
 	/*  Issue the Sector Erase command   */
-	chip_writeb(0xAA, bios + (0x5555 & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x55, bios + (0x2AAA & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x80, bios + (0x5555 & mask));
-	programmer_delay(delay_us);
-
-	chip_writeb(0xAA, bios + (0x5555 & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x55, bios + (0x2AAA & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x50, bios + block);
-	programmer_delay(delay_us);
+	chip_writeb(g, 0xAA, bios + (0x5555 & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x55, bios + (0x2AAA & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x80, bios + (0x5555 & mask));
+	programmer_delay(g, delay_us);
+
+	chip_writeb(g, 0xAA, bios + (0x5555 & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x55, bios + (0x2AAA & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x50, bios + block);
+	programmer_delay(g, delay_us);
 
 	/* wait for Toggle bit ready         */
-	toggle_ready_jedec_slow(bios);
+	toggle_ready_jedec_slow(g, bios);
 
 	/* FIXME: Check the status register for errors. */
 	return 0;
 }
 
-static int erase_chip_jedec_common(struct flashchip *flash, unsigned int mask)
+static int erase_chip_jedec_common(globals *g, struct flashchip *flash, unsigned int mask)
 {
 	chipaddr bios = flash->virtual_memory;
 	int delay_us = 0;
@@ -306,27 +306,27 @@ static int erase_chip_jedec_common(struct flashchip *flash, unsigned int mask)
 	        delay_us = 10;
 
 	/*  Issue the JEDEC Chip Erase command   */
-	chip_writeb(0xAA, bios + (0x5555 & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x55, bios + (0x2AAA & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x80, bios + (0x5555 & mask));
-	programmer_delay(delay_us);
-
-	chip_writeb(0xAA, bios + (0x5555 & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x55, bios + (0x2AAA & mask));
-	programmer_delay(delay_us);
-	chip_writeb(0x10, bios + (0x5555 & mask));
-	programmer_delay(delay_us);
-
-	toggle_ready_jedec_slow(bios);
+	chip_writeb(g, 0xAA, bios + (0x5555 & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x55, bios + (0x2AAA & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x80, bios + (0x5555 & mask));
+	programmer_delay(g, delay_us);
+
+	chip_writeb(g, 0xAA, bios + (0x5555 & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x55, bios + (0x2AAA & mask));
+	programmer_delay(g, delay_us);
+	chip_writeb(g, 0x10, bios + (0x5555 & mask));
+	programmer_delay(g, delay_us);
+
+	toggle_ready_jedec_slow(g, bios);
 
 	/* FIXME: Check the status register for errors. */
 	return 0;
 }
 
-static int write_byte_program_jedec_common(struct flashchip *flash, uint8_t *src,
+static int write_byte_program_jedec_common(globals *g, struct flashchip *flash, uint8_t *src,
 			     chipaddr dst, unsigned int mask)
 {
 	int tried = 0, failed = 0;
@@ -339,13 +339,13 @@ static int write_byte_program_jedec_common(struct flashchip *flash, uint8_t *src
 
 retry:
 	/* Issue JEDEC Byte Program command */
-	start_program_jedec_common(flash, mask);
+	start_program_jedec_common(g, flash, mask);
 
 	/* transfer data from source to destination */
-	chip_writeb(*src, dst);
-	toggle_ready_jedec(bios);
+	chip_writeb(g, *src, dst);
+	toggle_ready_jedec(g, bios);
 
-	if (chip_readb(dst) != *src && tried++ < MAX_REFLASH_TRIES) {
+	if (chip_readb(g, dst) != *src && tried++ < MAX_REFLASH_TRIES) {
 		goto retry;
 	}
 
@@ -356,7 +356,7 @@ retry:
 }
 
 /* chunksize is 1 */
-int write_jedec_1(struct flashchip *flash, uint8_t *src, int start, int len)
+int write_jedec_1(globals *g, struct flashchip *flash, uint8_t *src, int start, int len)
 {
 	int i, failed = 0;
 	chipaddr dst = flash->virtual_memory + start;
@@ -367,7 +367,7 @@ int write_jedec_1(struct flashchip *flash, uint8_t *src, int start, int len)
 
 	olddst = dst;
 	for (i = 0; i < len; i++) {
-		if (write_byte_program_jedec_common(flash, src, dst, mask))
+		if (write_byte_program_jedec_common(g, flash, src, dst, mask))
 			failed = 1;
 		dst++, src++;
 	}
@@ -377,7 +377,7 @@ int write_jedec_1(struct flashchip *flash, uint8_t *src, int start, int len)
 	return failed;
 }
 
-int write_page_write_jedec_common(struct flashchip *flash, uint8_t *src, int start, int page_size)
+int write_page_write_jedec_common(globals *g, struct flashchip *flash, uint8_t *src, int start, int page_size)
 {
 	int i, tried = 0, failed;
 	uint8_t *s = src;
@@ -390,22 +390,22 @@ int write_page_write_jedec_common(struct flashchip *flash, uint8_t *src, int sta
 
 retry:
 	/* Issue JEDEC Start Program command */
-	start_program_jedec_common(flash, mask);
+	start_program_jedec_common(g, flash, mask);
 
 	/* transfer data from source to destination */
 	for (i = 0; i < page_size; i++) {
 		/* If the data is 0xFF, don't program it */
 		if (*src != 0xFF)
-			chip_writeb(*src, dst);
+			chip_writeb(g, *src, dst);
 		dst++;
 		src++;
 	}
 
-	toggle_ready_jedec(dst - 1);
+	toggle_ready_jedec(g, dst - 1);
 
 	dst = d;
 	src = s;
-	failed = verify_range(flash, src, start, page_size, NULL);
+	failed = verify_range(g, flash, src, start, page_size, NULL);
 
 	if (failed && tried++ < MAX_REFLASH_TRIES) {
 		msg_cerr("retrying.\n");
@@ -425,7 +425,7 @@ retry:
  * This function is a slightly modified copy of spi_write_chunked.
  * Each page is written separately in chunks with a maximum size of chunksize.
  */
-int write_jedec(struct flashchip *flash, uint8_t *buf, int start, int len)
+int write_jedec(globals *g, struct flashchip *flash, uint8_t *buf, int start, int len)
 {
 	int i, starthere, lenhere;
 	/* FIXME: page_size is the wrong variable. We need max_writechunk_size
@@ -451,7 +451,7 @@ int write_jedec(struct flashchip *flash, uint8_t *buf, int start, int len)
 		/* Length of bytes in the range in this page. */
 		lenhere = min(start + len, (i + 1) * page_size) - starthere;
 
-		if (write_page_write_jedec_common(flash, buf + starthere - start, starthere, lenhere))
+		if (write_page_write_jedec_common(g, flash, buf + starthere - start, starthere, lenhere))
 			return 1;
 	}
 
@@ -459,7 +459,7 @@ int write_jedec(struct flashchip *flash, uint8_t *buf, int start, int len)
 }
 
 /* erase chip with block_erase() prototype */
-int erase_chip_block_jedec(struct flashchip *flash, unsigned int addr,
+int erase_chip_block_jedec(globals *g, struct flashchip *flash, unsigned int addr,
 			   unsigned int blocksize)
 {
 	int mask;
@@ -470,37 +470,37 @@ int erase_chip_block_jedec(struct flashchip *flash, unsigned int addr,
 			__func__);
 		return -1;
 	}
-	return erase_chip_jedec_common(flash, mask);
+	return erase_chip_jedec_common(g, flash, mask);
 }
 
-int probe_jedec(struct flashchip *flash)
+int probe_jedec(globals *g, struct flashchip *flash)
 {
 	int mask;
 
 	mask = getaddrmask(flash);
-	return probe_jedec_common(flash, mask);
+	return probe_jedec_common(g, flash, mask);
 }
 
-int erase_sector_jedec(struct flashchip *flash, unsigned int page, unsigned int size)
+int erase_sector_jedec(globals *g, struct flashchip *flash, unsigned int page, unsigned int size)
 {
 	int mask;
 
 	mask = getaddrmask(flash);
-	return erase_sector_jedec_common(flash, page, size, mask);
+	return erase_sector_jedec_common(g, flash, page, size, mask);
 }
 
-int erase_block_jedec(struct flashchip *flash, unsigned int page, unsigned int size)
+int erase_block_jedec(globals *g, struct flashchip *flash, unsigned int page, unsigned int size)
 {
 	int mask;
 
 	mask = getaddrmask(flash);
-	return erase_block_jedec_common(flash, page, size, mask);
+	return erase_block_jedec_common(g, flash, page, size, mask);
 }
 
-int erase_chip_jedec(struct flashchip *flash)
+int erase_chip_jedec(globals *g, struct flashchip *flash)
 {
 	int mask;
 
 	mask = getaddrmask(flash);
-	return erase_chip_jedec_common(flash, mask);
+	return erase_chip_jedec_common(g, flash, mask);
 }
-- 
1.7.6

