mtd/drivers/mtd/nand nand.c,1.49,1.50

David Woodhouse dwmw2 at infradead.org
Wed Jul 2 09:09:02 EDT 2003


Update of /home/cvs/mtd/drivers/mtd/nand
In directory phoenix.infradead.org:/tmp/cvs-serv24515/drivers/mtd/nand

Modified Files:
	nand.c 
Log Message:
abstract write_byte and read_byte too

Index: nand.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/nand/nand.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- nand.c	2 Jul 2003 11:00:24 -0000	1.49
+++ nand.c	2 Jul 2003 13:09:00 -0000	1.50
@@ -174,6 +174,18 @@
 static void nand_sync (struct mtd_info *mtd);
 static int nand_write_page (struct mtd_info *mtd, struct nand_chip *this, int page, u_char *oob_buf,  struct nand_oobinfo *oobsel);
 
+static u_char nand_read_byte(struct mtd_info *mtd)
+{
+	struct nand_chip *this = mtd->priv;
+	return readb(this->IO_ADDR_R);
+}
+
+static void nand_write_byte(struct mtd_info *mtd, u_char byte)
+{
+	struct nand_chip *this = mtd->priv;
+	writeb(byte, this->IO_ADDR_W);
+}
+
 static void nand_select_chip(struct mtd_info *mtd, int chip)
 {
 	struct nand_chip *this = mtd->priv;
@@ -219,7 +231,6 @@
 static void nand_command (struct mtd_info *mtd, unsigned command, int column, int page_addr)
 {
 	register struct nand_chip *this = mtd->priv;
-	register unsigned long NAND_IO_ADDR = this->IO_ADDR_W;
 
 	/* Begin command latch cycle */
 	this->hwcontrol(mtd, NAND_CTL_SETCLE);
@@ -227,25 +238,25 @@
 	 * Write out the command to the device.
 	 */
 	if (command != NAND_CMD_SEQIN)
-		writeb (command, NAND_IO_ADDR);
+		this->write_byte(mtd, command);
 	else {
 		if (mtd->oobblock == 256 && column >= 256) {
 			column -= 256;
-			writeb (NAND_CMD_READOOB, NAND_IO_ADDR);
-			writeb (NAND_CMD_SEQIN, NAND_IO_ADDR);
+			this->write_byte(mtd, NAND_CMD_READOOB);
+			this->write_byte(mtd, NAND_CMD_SEQIN);
 		} else if (mtd->oobblock == 512 && column >= 256) {
 			if (column < 512) {
 				column -= 256;
-				writeb (NAND_CMD_READ1, NAND_IO_ADDR);
-				writeb (NAND_CMD_SEQIN, NAND_IO_ADDR);
+				this->write_byte(mtd, NAND_CMD_READ1);
+				this->write_byte(mtd, NAND_CMD_SEQIN);
 			} else {
 				column -= 512;
-				writeb (NAND_CMD_READOOB, NAND_IO_ADDR);
-				writeb (NAND_CMD_SEQIN, NAND_IO_ADDR);
+				this->write_byte(mtd, NAND_CMD_READOOB);
+				this->write_byte(mtd, NAND_CMD_SEQIN);
 			}
 		} else {
-			writeb (NAND_CMD_READ0, NAND_IO_ADDR);
-			writeb (NAND_CMD_SEQIN, NAND_IO_ADDR);
+			this->write_byte(mtd, NAND_CMD_READ0);
+			this->write_byte(mtd, NAND_CMD_SEQIN);
 		}
 	}
 
@@ -257,13 +268,13 @@
 
 		/* Serially input address */
 		if (column != -1)
-			writeb (column, NAND_IO_ADDR);
+			this->write_byte(mtd, column);
 		if (page_addr != -1) {
-			writeb ((unsigned char) (page_addr & 0xff), NAND_IO_ADDR);
-			writeb ((unsigned char) ((page_addr >> 8) & 0xff), NAND_IO_ADDR);
+			this->write_byte(mtd, (unsigned char) (page_addr & 0xff));
+			this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff));
 			/* One more address cycle for higher density devices */
 			if (mtd->size & 0x0c000000) 
-				writeb ((unsigned char) ((page_addr >> 16) & 0x0f), NAND_IO_ADDR);
+				this->write_byte(mtd, (unsigned char) ((page_addr >> 16) & 0x0f));
 		}
 		/* Latch in address */
 		this->hwcontrol(mtd, NAND_CTL_CLRALE);
@@ -286,9 +297,9 @@
 		if (this->dev_ready)	
 			break;
 		this->hwcontrol(mtd, NAND_CTL_SETCLE);
-		writeb (NAND_CMD_STATUS, NAND_IO_ADDR);
+		this->write_byte(mtd, NAND_CMD_STATUS);
 		this->hwcontrol(mtd, NAND_CTL_CLRCLE);
-		while ( !(readb (this->IO_ADDR_R) & 0x40));
+		while ( !(this->read_byte(mtd) & 0x40));
 		return;
 
 	/* This applies to read commands */	
@@ -378,14 +389,14 @@
 			if (this->dev_ready(mtd))
 				break;
 		}
-		if (readb (this->IO_ADDR_R) & 0x40)
+		if (this->read_byte(mtd) & 0x40)
 			break;
 						
 		spin_unlock_bh (&this->chip_lock);
 		yield ();
 		spin_lock_bh (&this->chip_lock);
 	}
-	status = (int) readb (this->IO_ADDR_R);
+	status = (int) this->read_byte(mtd);
 	spin_unlock_bh (&this->chip_lock);
 
 	return status;
@@ -677,7 +688,7 @@
 
 		/* read oobdata */
 		for (j = 0; j <  mtd->oobsize; j++) 
-			oob_data[oob + j] = readb (this->IO_ADDR_R);
+			oob_data[oob + j] = this->read_byte(mtd);
 		
 		/* Skip ECC, if not active */
 		if (eccmode == NAND_ECC_NONE)
@@ -851,7 +862,7 @@
 
 	/* Check the WP bit */
 	this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1);
-	if (!(readb (this->IO_ADDR_R) & 0x80)) {
+	if (!(this->read_byte(mtd) & 0x80)) {
 		DEBUG (MTD_DEBUG_LEVEL0, "nand_write_ecc: Device is write protected!!!\n");
 		ret = -EIO;
 		goto out;
@@ -929,7 +940,7 @@
 
 	/* Check the WP bit */
 	this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1);
-	if (!(readb (this->IO_ADDR_R) & 0x80)) {
+	if (!(this->read_byte(mtd) & 0x80)) {
 		DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: Device is write protected!!!\n");
 		ret = -EIO;
 		goto out;
@@ -964,7 +975,7 @@
 
 	/* Loop through and verify the data */
 	for (i = 0; i < len; i++) {
-		if (buf[i] != readb (this->IO_ADDR_R)) {
+		if (buf[i] != this->read_byte(mtd)) {
 			DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write verify, page 0x%08x\n", page);
 			ret = -EIO;
 			goto out;
@@ -1036,7 +1047,7 @@
 
 	/* Check the WP bit */
 	this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1);
-	if (!(readb (this->IO_ADDR_R) & 0x80)) {
+	if (!(this->read_byte(mtd) & 0x80)) {
 		DEBUG (MTD_DEBUG_LEVEL0, "nand_writev: Device is write protected!!!\n");
 		ret = -EIO;
 		goto out;
@@ -1150,7 +1161,7 @@
 
 	/* Check the WP bit */
 	this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1);
-	if (!(readb (this->IO_ADDR_R) & 0x80)) {
+	if (!(this->read_byte(mtd) & 0x80)) {
 		DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: Device is write protected!!!\n");
 		instr->state = MTD_ERASE_FAILED;
 		goto erase_exit;
@@ -1164,7 +1175,7 @@
 	while (len) {
 		/* Check if we have a bad block, we do not erase bad blocks ! */
 		this->cmdfunc (mtd, NAND_CMD_READOOB, NAND_BADBLOCK_POS, page);
-		if (readb (this->IO_ADDR_R) != 0xff) {
+		if (this->read_byte(mtd) != 0xff) {
 			printk (KERN_WARNING "nand_erase: attempt to erase a bad block at page 0x%08x\n", page);
 			instr->state = MTD_ERASE_FAILED;
 			goto erase_exit;
@@ -1299,6 +1310,10 @@
 
 	if (!this->select_chip)
 		this->select_chip = nand_select_chip;
+	if (!this->write_byte)
+		this->write_byte = nand_write_byte;
+	if (!this->read_byte)
+		this->read_byte = nand_read_byte;
 	if (!this->write_buf)
 		this->write_buf = nand_write_buf;
 	if (!this->read_buf)
@@ -1313,8 +1328,8 @@
 	this->cmdfunc (mtd, NAND_CMD_READID, 0x00, -1);
 
 	/* Read manufacturer and device IDs */
-	nand_maf_id = readb (this->IO_ADDR_R);
-	nand_dev_id = readb (this->IO_ADDR_R);
+	nand_maf_id = this->read_byte(mtd);
+	nand_dev_id = this->read_byte(mtd);
 
 	/* Print and store flash device information */
 	for (i = 0; nand_flash_ids[i].name != NULL; i++) {




More information about the linux-mtd-cvs mailing list