mtd/drivers/mtd/chips cfi_cmdset_0002.c,1.68,1.69 jedec_probe.c,1.25,1.26

Thayne Harbaugh tharbaugh at lnxi.com
Tue May 6 17:34:44 EDT 2003


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

Modified Files:
	cfi_cmdset_0002.c jedec_probe.c 
Log Message:
Add FIXME comments.
change __u32 to more correct cfi_word.
Fix problem in cfi_cmdset_0002.c erase functions for multi-byte wide parts.
use more jedec_table[] information in jedec_setup().

Index: cfi_cmdset_0002.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/chips/cfi_cmdset_0002.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- cfi_cmdset_0002.c	21 Apr 2003 23:26:25 -0000	1.68
+++ cfi_cmdset_0002.c	6 May 2003 21:34:40 -0000	1.69
@@ -76,6 +76,7 @@
 		cfi_send_gen_cmd(0xaa, 0x555, base, map, cfi, cfi->device_type, NULL);
 		cfi_send_gen_cmd(0x55, 0x2aa, base, map, cfi, cfi->device_type, NULL);
 		cfi_send_gen_cmd(0x90, 0x555, base, map, cfi, cfi->device_type, NULL);
+		/* FIXME - should have a delay before continuing */
 		cfi->mfr = cfi_read_query(map, base);
 		cfi->id = cfi_read_query(map, base + ofs_factor);    
 
@@ -107,6 +108,10 @@
 				cfi->cfiq->EraseRegionInfo[j] = swap;
 			}
 		}
+		/*
+		 * FIXME - These might already be setup (more correctly)
+		 * buy jedec_probe.c.
+		 */
 		switch (cfi->device_type) {
 		case CFI_DEVICETYPE_X8:
 			cfi->addr_unlock1 = 0x555; 
@@ -455,7 +460,7 @@
 	return ret;
 }
 
-static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned long adr, __u32 datum, int fast)
+static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned long adr, cfi_word datum, int fast)
 {
 	unsigned long timeo = jiffies + HZ;
 	unsigned int oldstatus, status, prev_oldstatus, prev_status;
@@ -646,6 +651,7 @@
 	ret = -EIO;
 	/* reset on all failures. */
 	cfi_write( map, CMD(0xF0), chip->start );
+	/* FIXME - should have reset delay before continuing */
 
  write_done:
 	DISABLE_VPP(map);
@@ -678,7 +684,7 @@
 		int i = ofs - bus_ofs;
 		int n = 0;
 		u_char tmp_buf[8];
-		__u32 datum;
+		cfi_word datum;
 
 		map->copy_from(map, tmp_buf, bus_ofs + cfi->chips[chipnum].start, CFIDEV_BUSWIDTH);
 		while (len && i < CFIDEV_BUSWIDTH)
@@ -718,7 +724,7 @@
 
 	/* We are now aligned, write as much as possible */
 	while(len >= CFIDEV_BUSWIDTH) {
-		__u32 datum;
+		cfi_word datum;
 
 		if (cfi_buswidth_is_1()) {
 			datum = *(__u8*)buf;
@@ -776,7 +782,7 @@
 	if (len & (CFIDEV_BUSWIDTH-1)) {
 		int i = 0, n = 0;
 		u_char tmp_buf[8];
-		__u32 datum;
+		cfi_word datum;
 
 		map->copy_from(map, tmp_buf, ofs + cfi->chips[chipnum].start, CFIDEV_BUSWIDTH);
 		while (len--)
@@ -811,7 +817,7 @@
 	DECLARE_WAITQUEUE(wait, current);
 	int ret = 0;
 	int ta = 0;
-	__u32 ones = 0;
+	cfi_word ones = 0;
 
  retry:
 	cfi_spin_lock(chip->mutex);
@@ -925,7 +931,16 @@
 	DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): Check 0x%.8x 0x%.8x\n",
 	       __func__, oldstatus, status );
 
-	ones = CMD( (__u8)~0 );
+	if ( cfi_buswidth_is_1() ) {
+		ones =  (__u8)~0;
+	} else if ( cfi_buswidth_is_2() ) {
+		ones = (__u16)~0;
+	} else if ( cfi_buswidth_is_4() ) {
+		ones = (__u32)~0;
+	} else {
+		printk(KERN_WARNING "Unsupported buswidth\n");
+		goto erase_failed;
+	}
 	
 	if ( oldstatus == ones && status == ones ) {
 		/* success - do nothing */
@@ -962,6 +977,7 @@
 	ret = -EIO;
 	/* reset on all failures. */
 	cfi_write( map, CMD(0xF0), chip->start );
+	/* FIXME - should have reset delay before continuing */
 
  erase_done:
 	DISABLE_VPP(map);
@@ -981,7 +997,7 @@
 	DECLARE_WAITQUEUE(wait, current);
 	int ret = 0;
 	int ta = 0;
-	__u32 ones = 0;
+	cfi_word ones = 0;
 
  retry:
 	cfi_spin_lock(chip->mutex);
@@ -1095,7 +1111,16 @@
 	DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): Check 0x%.8x 0x%.8x\n",
 	       __func__, oldstatus, status );
 
-	ones = CMD( (__u8)~0 );
+	if ( cfi_buswidth_is_1() ) {
+		ones =  (__u8)~0;
+	} else if ( cfi_buswidth_is_2() ) {
+		ones = (__u16)~0;
+	} else if ( cfi_buswidth_is_4() ) {
+		ones = (__u32)~0;
+	} else {
+		printk(KERN_WARNING "Unsupported buswidth\n");
+		goto erase_failed;
+	}
 
 	if ( oldstatus == ones && status == ones ) {
 		/* success - do nothing */
@@ -1132,6 +1157,7 @@
 	ret = -EIO;
 	/* reset on all failures. */
 	cfi_write( map, CMD(0xF0), chip->start );
+	/* FIXME - should have reset delay before continuing */
 
  erase_done:
 	DISABLE_VPP(map);

Index: jedec_probe.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/chips/jedec_probe.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- jedec_probe.c	18 Apr 2003 16:00:57 -0000	1.25
+++ jedec_probe.c	6 May 2003 21:34:41 -0000	1.26
@@ -1251,11 +1251,36 @@
 	 * this should be safe.
 	 */ 
 	cfi_send_gen_cmd(0xFF, 0, base, map, cfi, cfi->device_type, NULL);
+	/* FIXME - should have reset delay before continuing */
+}
+
+
+static inline __u8 finfo_uaddr(const struct amd_flash_info *finfo, int device_type)
+{
+	int uaddr_idx;
+	__u8 uaddr = MTD_UADDR_NOT_SUPPORTED;
+
+	switch ( device_type ) {
+	case CFI_DEVICETYPE_X8:  uaddr_idx = 0; break;
+	case CFI_DEVICETYPE_X16: uaddr_idx = 1; break;
+	case CFI_DEVICETYPE_X32: uaddr_idx = 2; break;
+	default:
+		printk(KERN_NOTICE "MTD: %s(): unknown device_type %d\n",
+		       __func__, device_type);
+		goto uaddr_done;
+	}
+
+	uaddr = finfo->uaddr[uaddr_idx];
 
+ uaddr_done:
+	return uaddr;
 }
+
+
 static int cfi_jedec_setup(struct cfi_private *p_cfi, int index)
 {
 	int i,num_erase_regions;
+	__u8 uaddr;
 
 	printk("Found: %s\n",jedec_table[index].name);
 
@@ -1278,6 +1303,19 @@
 		p_cfi->cfiq->EraseRegionInfo[i] = jedec_table[index].regions[i];
 	}
 	p_cfi->cmdset_priv = 0;
+
+	/* This may be redundant for some cases, but it doesn't hurt */
+	p_cfi->mfr = jedec_table[index].mfr_id;
+	p_cfi->id = jedec_table[index].dev_id;
+
+	uaddr = finfo_uaddr(&jedec_table[index], p_cfi->device_type);
+	if ( MTD_UADDR_NOT_SUPPORTED ) {
+		kfree( p_cfi->cfiq );
+		return 0;
+	}
+	p_cfi->addr_unlock1 = unlock_addrs[uaddr].addr1;
+	p_cfi->addr_unlock2 = unlock_addrs[uaddr].addr2;
+
 	return 1; 	/* ok */
 }
 
@@ -1296,7 +1334,6 @@
 {
 	int rc = 0;           /* failure until all tests pass */
 	u32 mfr, id;
-	__u8 uaddr_idx;
 	__u8 uaddr;
 
 	/* The ID's must match */
@@ -1304,18 +1341,19 @@
 		goto match_done;
 	}
 
-	/* unlock addresses must match */
-	switch ( cfi->device_type ) {
-	case CFI_DEVICETYPE_X8:  uaddr_idx = 0; break;
-	case CFI_DEVICETYPE_X16: uaddr_idx = 1; break;
-	case CFI_DEVICETYPE_X32: uaddr_idx = 2; break;
-	default:
-		printk(KERN_NOTICE "MTD: %s(): unknown device_type %d\n",
-		       __func__, cfi->device_type);
+	/* the part size must fit in the memory window */
+	DEBUG( MTD_DEBUG_LEVEL3,
+	       "MTD %s(): Check fit 0x%.8x + 0x%.8x = 0x%.8x\n",
+	       __func__, base, 1 << finfo->DevSize, base + (1 << finfo->DevSize) );
+	if ( base + ( 1 << finfo->DevSize ) > map->size ) {
+		DEBUG( MTD_DEBUG_LEVEL3,
+		       "MTD %s(): 0x%.4x 0x%.4x %dKiB doesn't fit\n",
+		       __func__, finfo->mfr_id, finfo->dev_id,
+		       1 << finfo->DevSize );
 		goto match_done;
 	}
 
-	uaddr = finfo->uaddr[uaddr_idx];
+	uaddr = finfo_uaddr(finfo, cfi->device_type);
 	if ( MTD_UADDR_NOT_SUPPORTED ) {
 		goto match_done;
 	}
@@ -1369,6 +1407,7 @@
 		cfi_send_gen_cmd(0x55, cfi->addr_unlock2, base, map, cfi, CFI_DEVICETYPE_X8, NULL);
 	}
 	cfi_send_gen_cmd(0x90, cfi->addr_unlock1, base, map, cfi, CFI_DEVICETYPE_X8, NULL);
+	/* FIXME - should have a delay before continuing */
 
  match_done:	
 	return rc;
@@ -1381,6 +1420,10 @@
 	int i;
 	int unlockpass = 0;
 
+	/*
+	 * FIXME - eventually replace these unlock address seeds with
+	 * information from unlock_addrs[].
+	 */
 	if (!cfi->numchips) {
 		switch (cfi->device_type) {
 		case CFI_DEVICETYPE_X8:
@@ -1439,6 +1482,7 @@
 		cfi_send_gen_cmd(0x55, cfi->addr_unlock2, base, map, cfi, CFI_DEVICETYPE_X8, NULL);
 	}
 	cfi_send_gen_cmd(0x90, cfi->addr_unlock1, base, map, cfi, CFI_DEVICETYPE_X8, NULL);
+	/* FIXME - should have a delay before continuing */
 
 	if (!cfi->numchips) {
 		/* This is the first time we're called. Set up the CFI 




More information about the linux-mtd-cvs mailing list