mtd/drivers/mtd/maps lubbock-flash.c,1.1,1.2

David Woodhouse dwmw2 at infradead.org
Tue May 13 11:30:00 EDT 2003


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

Modified Files:
	lubbock-flash.c 
Log Message:
Register both flash devices.


Index: lubbock-flash.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/maps/lubbock-flash.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- lubbock-flash.c	10 Apr 2003 12:20:18 -0000	1.1
+++ lubbock-flash.c	13 May 2003 15:29:58 -0000	1.2
@@ -18,10 +18,12 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/map.h>
 #include <linux/mtd/partitions.h>
+#include <asm/hardware.h>
 
 
-#define WINDOW_ADDR 	0
-//#define WINDOW_ADDR 	0x04000000
+#define ROM_ADDR	0x00000000
+#define FLASH_ADDR	0x04000000
+
 #define WINDOW_SIZE 	64*1024*1024
 
 static __u8 lubbock_read8(struct map_info *map, unsigned long ofs)
@@ -64,9 +66,9 @@
 	memcpy((void *)(map->map_priv_1 + to), from, len);
 }
 
-static u_char * lubbock_point(struct map_info *map, loff_t ofs, size_t len)
+static u_char *lubbock_point(struct map_info *map, loff_t ofs, size_t len)
 {
-        return map->map_priv_1 + ofs;
+        return (u_char *)map->map_priv_1 + ofs;
 }
 
 static void lubbock_unpoint(struct map_info *map, u_char *ptr, loff_t ofs, size_t len)
@@ -74,102 +76,145 @@
         return;
 }
 
-static struct map_info lubbock_map = {
-	name: "Lubbock flash",
-	size: WINDOW_SIZE,
-	read8:		lubbock_read8,
-	read16:		lubbock_read16,
-	read32:		lubbock_read32,
-	copy_from:	lubbock_copy_from,
-	write8:		lubbock_write8,
-	write16:	lubbock_write16,
-	write32:	lubbock_write32,
-	copy_to:	lubbock_copy_to,
-	point:		lubbock_point,
-	unpoint:	lubbock_unpoint
-};
+static struct map_info lubbock_maps[2] = { {
+	.size =		WINDOW_SIZE,
+	.read8 =	lubbock_read8,
+	.read16 =	lubbock_read16,
+	.read32 =	lubbock_read32,
+	.copy_from =	lubbock_copy_from,
+	.write8 =	lubbock_write8,
+	.write16 =	lubbock_write16,
+	.write32 =	lubbock_write32,
+	.copy_to =	lubbock_copy_to,
+	.point =	lubbock_point,
+	.unpoint =	lubbock_unpoint,
+	.map_priv_2 =	0x00000000,
+}, {
+	.size =		WINDOW_SIZE,
+	.read8 =	lubbock_read8,
+	.read16 =	lubbock_read16,
+	.read32 =	lubbock_read32,
+	.copy_from =	lubbock_copy_from,
+	.write8 =	lubbock_write8,
+	.write16 =	lubbock_write16,
+	.write32 =	lubbock_write32,
+	.copy_to =	lubbock_copy_to,
+	.point =	lubbock_point,
+	.unpoint =	lubbock_unpoint,
+	.map_priv_2 =	0x04000000,
+} };
 
 static struct mtd_partition lubbock_partitions[] = {
 	{
-		name:		"Bootloader",
-		size:		0x00040000,
-		offset:		0,
-		mask_flags:	MTD_WRITEABLE  /* force read-only */
+		.name =		"Bootloader",
+		.size =		0x00040000,
+		.offset =	0,
+		.mask_flags =	MTD_WRITEABLE  /* force read-only */
 	},{
-		name:		"Kernel",
-		size:		0x00100000,
-		offset:		0x00040000,
+		.name =		"Kernel",
+		.size =		0x00100000,
+		.offset =	0x00040000,
 	},{
-		name:		"Filesystem",
-		size:		MTDPART_SIZ_FULL,
-		offset:		0x00140000
+		.name =		"Filesystem",
+		.size =		MTDPART_SIZ_FULL,
+		.offset =	0x00140000
 	}
 };
 
 #define NB_OF(x)  (sizeof(x)/sizeof(x[0]))
 
-static struct mtd_info *mymtd;
-static struct mtd_partition *parsed_parts;
+static struct mtd_info *mymtds[2];
+static struct mtd_partition *parsed_parts[2];
+static int nr_parsed_parts[2];
+static char *part_type[2];
 
 static int __init init_lubbock(void)
 {
-	struct mtd_partition *parts;
-	int nb_parts = 0;
-	int parsed_nr_parts = 0;
-	char *part_type = "static";
-
-	lubbock_map.buswidth = (BOOT_DEF & 1) ? 2 : 4;
-	printk( "Probing Lubbock flash at physical address 0x%08x (%d-bit buswidth)\n",
-		WINDOW_ADDR, lubbock_map.buswidth * 8 );
-	lubbock_map.map_priv_1 = (unsigned long)__ioremap(WINDOW_ADDR, WINDOW_SIZE, 0);
-	if (!lubbock_map.map_priv_1) {
-		printk("Failed to ioremap\n");
-		return -EIO;
-	}
-	mymtd = do_map_probe("cfi_probe", &lubbock_map);
-	if (!mymtd) {
-		iounmap((void *)lubbock_map.map_priv_1);
-		return -ENXIO;
-	}
-	mymtd->module = THIS_MODULE;
+	int flashboot = (CONF_SWITCHES & 1);
+	int ret = 0, i;
+
+	lubbock_maps[0].buswidth = lubbock_maps[1].buswidth = 
+		(BOOT_DEF & 1) ? 2 : 4;
+
+	/* Compensate for the nROMBT switch which swaps the flash banks */
+	printk(KERN_NOTICE "Lubbock configured to boot from %s (bank %d)\n",
+	       flashboot?"Flash":"ROM", flashboot);
+
+	lubbock_maps[flashboot^1].name = "Lubbock Application Flash";
+	lubbock_maps[flashboot].name = "Lubbock Boot ROM";
+
+	for (i = 0; i < 2; i++) {
+		lubbock_maps[i].map_priv_1 = (unsigned long)__ioremap(lubbock_maps[i].map_priv_2, WINDOW_SIZE, 0);
+		if (!lubbock_maps[i].map_priv_1) {
+			printk(KERN_WARNING "Failed to ioremap %s\n", lubbock_maps[i].name);
+			if (!ret)
+				ret = -ENOMEM;
+			continue;
+		}
+
+		printk(KERN_NOTICE "Probing %s at physical address 0x%08lx (%d-bit buswidth)\n",
+		       lubbock_maps[i].name, lubbock_maps[i].map_priv_2, 
+		       lubbock_maps[i].buswidth * 8);
+
+		mymtds[i] = do_map_probe("cfi_probe", &lubbock_maps[i]);
+		
+		if (!mymtds[i]) {
+			iounmap((void *)lubbock_maps[i].map_priv_1);
+			if (!ret)
+				ret = -EIO;
+			continue;
+		}
+		mymtds[i]->module = THIS_MODULE;
 
 #ifdef CONFIG_MTD_REDBOOT_PARTS
-	if (parsed_nr_parts == 0) {
-		int ret = parse_redboot_partitions(mymtd, &parsed_parts, 0);
+		int ret = parse_redboot_partitions(mymtds[i], &parsed_parts[i], 0);
 
 		if (ret > 0) {
-			part_type = "RedBoot";
-			parsed_nr_parts = ret;
+			part_type[i] = "RedBoot";
+			nr_parsed_parts[i] = ret;
 		}
-	}
 #endif
-
-	if (parsed_nr_parts > 0) {
-		parts = parsed_parts;
-		nb_parts = parsed_nr_parts;
-	} else {
-		parts = lubbock_partitions;
-		nb_parts = NB_OF(lubbock_partitions);
 	}
-	if (nb_parts) {
-		printk(KERN_NOTICE "Using %s partition definition\n", part_type);
-		add_mtd_partitions(mymtd, parts, nb_parts);
-	} else {
-		add_mtd_device(mymtd);
+
+	if (!mymtds[0] && !mymtds[1])
+		return ret;
+	
+	for (i = 0; i < 2; i++) {
+		if (!mymtds[i]) {
+			printk(KERN_WARNING "%s is absent. Skipping\n", lubbock_maps[i].name);
+		} else if (nr_parsed_parts[i]) {
+			printk("Using %s partitions on %s\n", part_type[i], 
+			       lubbock_maps[i].name);
+			add_mtd_partitions(mymtds[i], parsed_parts[i], nr_parsed_parts[i]);
+		} else if (!i) {
+			printk("Using static partitions on %s\n", lubbock_maps[i].name);
+			add_mtd_partitions(mymtds[i], lubbock_partitions, NB_OF(lubbock_partitions));
+		} else {
+			printk("Registering %s as whole device\n", lubbock_maps[i].name);
+			add_mtd_device(mymtds[i]);
+		}
 	}
 	return 0;
 }
 
 static void __exit cleanup_lubbock(void)
 {
-	if (mymtd) {
-		del_mtd_partitions(mymtd);
-		map_destroy(mymtd);
-		if (parsed_parts)
-			kfree(parsed_parts);
+	int i;
+	for (i = 0; i < 2; i++) {
+		if (!mymtds[i])
+			continue;
+
+		if (nr_parsed_parts[i])
+			del_mtd_partitions(mymtds[i]);
+		else
+			del_mtd_device(mymtds[i]);			
+
+		map_destroy(mymtds[i]);
+		iounmap((void *)lubbock_maps[i].map_priv_1);
+
+		if (parsed_parts[i])
+			kfree(parsed_parts[i]);
 	}
-	if (lubbock_map.map_priv_1)
-		iounmap((void *)lubbock_map.map_priv_1);
 }
 
 module_init(init_lubbock);




More information about the linux-mtd-cvs mailing list