mtd/drivers/mtd/nand diskonchip.c,1.5,1.6

David Woodhouse dwmw2 at infradead.org
Fri Oct 17 08:48:09 EDT 2003


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

Modified Files:
	diskonchip.c 
Log Message:
Optional dword access


Index: diskonchip.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/nand/diskonchip.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- diskonchip.c	25 Aug 2003 10:34:41 -0000	1.5
+++ diskonchip.c	17 Oct 2003 12:48:06 -0000	1.6
@@ -19,6 +19,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/doc2000.h>
+#include <linux/mtd/compatmac.h>
 
 struct doc_priv {
 	unsigned long virtadr;
@@ -39,6 +40,9 @@
 static int debug=0;
 MODULE_PARM(debug, "i");
 
+static int try_dword=1;
+MODULE_PARM(try_dword, "i");
+
 static void DoC_Delay(struct doc_priv *doc, unsigned short cycles)
 {
 	volatile char dummy;
@@ -137,13 +141,30 @@
 	if (debug)printk("readbuf of %d bytes: ", len);
 
 	for (i=0; i < len; i++) {
-		buf[i] = ReadDOC(docptr, 2k_CDSN_IO);
-		if (debug && i < 16)
-			printk("%02x ", buf[i]);
+		buf[i] = ReadDOC(docptr, 2k_CDSN_IO + i);
 	}
-	if (debug) printk("\n");
 }
 
+static void doc2000_readbuf_dword(struct mtd_info *mtd, 
+			    u_char *buf, int len)
+{
+	struct nand_chip *this = mtd->priv;
+	struct doc_priv *doc = (void *)this->priv;
+	unsigned long docptr = doc->virtadr;
+ 	int i;
+
+	if (debug) printk("readbuf_dword of %d bytes: ", len);
+
+	if (unlikely((((unsigned long)buf)|len) & 3)) {
+		for (i=0; i < len; i++) {
+			*(uint8_t *)(&buf[i]) = ReadDOC(docptr, 2k_CDSN_IO + i);
+		}
+	} else {
+		for (i=0; i < len; i+=4) {
+			*(uint32_t*)(&buf[i]) = readl(docptr + DoC_2k_CDSN_IO + i);
+		}
+	}
+}
 
 static int doc2000_verifybuf(struct mtd_info *mtd, 
 			      const u_char *buf, int len)
@@ -174,6 +195,30 @@
 	ret = doc2000_read_byte(mtd) << 8;
 	ret |= doc2000_read_byte(mtd);
 
+	if (try_dword && !nr) {
+		/* First chip probe. See if we get same results by 32-bit access */
+		union {
+			uint32_t dword;
+			uint8_t byte[4];
+		} ident;
+		struct nand_chip *this = mtd->priv;
+		struct doc_priv *doc = (void *)this->priv;
+		unsigned long docptr = doc->virtadr;
+
+		doc200x_hwcontrol(mtd, NAND_CTL_SETCLE);
+		doc2000_write_byte(mtd, NAND_CMD_READID);
+		doc200x_hwcontrol(mtd, NAND_CTL_CLRCLE);
+		doc200x_hwcontrol(mtd, NAND_CTL_SETALE);
+		doc2000_write_byte(mtd, 0);
+		doc200x_hwcontrol(mtd, NAND_CTL_CLRALE);
+
+		ident.dword = readl(docptr + DoC_2k_CDSN_IO);
+		if (((ident.byte[0] << 8) | ident.byte[1]) == ret) {
+			printk(KERN_INFO "DiskOnChip 2000 responds to DWORD access\n");
+			this->read_buf = &doc2000_readbuf_dword;
+		}
+	}
+		
 	return ret;
 }
 




More information about the linux-mtd-cvs mailing list