mtd/drivers/mtd/maps mtx-1_flash.c, NONE, 1.1 Kconfig, 1.58, 1.59 Makefile.common, 1.31, 1.32 mphysmap.c, 1.2, 1.3

joern at infradead.org joern at infradead.org
Sun Sep 18 06:46:45 EDT 2005


Update of /home/cvs/mtd/drivers/mtd/maps
In directory phoenix.infradead.org:/home/joern/mtd/drivers/mtd/maps

Modified Files:
	Kconfig Makefile.common mphysmap.c 
Added Files:
	mtx-1_flash.c 
Log Message:
Add support for "4G Systems MTX-1 Flash device", better known as meshcube.

From: Bruno Randolf <bruno.randolf at 4g-systems.biz>



--- NEW FILE mtx-1_flash.c ---
/*
 * Flash memory access on 4G Systems MTX-1 boards
 *
 * $Id: mtx-1_flash.c,v 1.1 2005/09/18 10:46:41 joern Exp $
 *
 * (C) 2005 Bruno Randolf <bruno.randolf at 4g-systems.biz>
 * (C) 2005 Jörn Engel <joern at wohnheim.fh-wedel.de>
 *
 */

#include <linux/config.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/kernel.h>

#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>

#include <asm/io.h>

static struct map_info mtx1_map = {
	.name = "MTX-1 flash",
	.bankwidth = 4,
	.size = 0x2000000,
	.phys = 0x1E000000,
};

static struct mtd_partition mtx1_partitions[] = {
        {
                .name = "filesystem",
                .size = 0x01C00000,
                .offset = 0,
        },{
                .name = "yamon",
                .size = 0x00100000,
                .offset = MTDPART_OFS_APPEND,
                .mask_flags = MTD_WRITEABLE,
        },{
                .name = "kernel",
                .size = 0x002c0000,
                .offset = MTDPART_OFS_APPEND,
        },{
                .name = "yamon env",
                .size = 0x00040000,
                .offset = MTDPART_OFS_APPEND,
        }
};

static struct mtd_info *mtx1_mtd;

int __init mtx1_mtd_init(void)
{
	int ret = -ENXIO;

	simple_map_init(&mtx1_map);

	mtx1_map.virt = ioremap(mtx1_map.phys, mtx1_map.size);
	if (!mtx1_map.virt)
		return -EIO;

	mtx1_mtd = do_map_probe("cfi_probe", &mtx1_map);
	if (!mtx1_mtd)
		goto err;

	mtx1_mtd->owner = THIS_MODULE;

	ret = add_mtd_partitions(mtx1_mtd, mtx1_partitions, 
			ARRAY_SIZE(mtx1_partitions));
	if (ret)
		goto err;

	return 0;

err:
       iounmap(mtx1_map.virt);
       return ret;
}

static void __exit mtx1_mtd_cleanup(void)
{
	if (mtx1_mtd) {
		del_mtd_partitions(mtx1_mtd);
		map_destroy(mtx1_mtd);
	}
	if (mtx1_map.virt)
		iounmap(mtx1_map.virt);
}

module_init(mtx1_mtd_init);
module_exit(mtx1_mtd_cleanup);

MODULE_AUTHOR("Bruno Randolf <bruno.randolf at 4g-systems.biz>");
MODULE_DESCRIPTION("MTX-1 flash map");
MODULE_LICENSE("GPL");

Index: Kconfig
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/maps/Kconfig,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- Kconfig	14 Sep 2005 19:14:13 -0000	1.58
+++ Kconfig	18 Sep 2005 10:46:41 -0000	1.59
@@ -303,6 +303,13 @@
 	help
 	  Flash memory access on AMD Alchemy Pb/Db/RDK Reference Boards
 
+config MTD_MTX1
+	tristate "4G Systems MTX-1 Flash device"
+	depends on MIPS && MIPS_MTX1
+	help
+	  Flash memory access on 4G Systems MTX-1 Board. If you have one of
+	  these boards and would like to use the flash chips on it, say 'Y'.
+
 config MTD_DILNETPC
 	tristate "CFI Flash device mapped on DIL/Net PC"
 	depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT

Index: Makefile.common
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/maps/Makefile.common,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- Makefile.common	14 Sep 2005 19:14:13 -0000	1.31
+++ Makefile.common	18 Sep 2005 10:46:41 -0000	1.32
@@ -72,3 +72,4 @@
 obj-$(CONFIG_MTD_PLATRAM)	+= plat-ram.o
 obj-$(CONFIG_MTD_OMAP_NOR)	+= omap_nor.o
 obj-$(CONFIG_MTD_PQ2FADS)	+= pq2fads.o
+obj-$(CONFIG_MTD_MTX1)		+= mtx-1_flash.o

Index: mphysmap.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/maps/mphysmap.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- mphysmap.c	7 Mar 2005 23:15:48 -0000	1.2
+++ mphysmap.c	18 Sep 2005 10:46:41 -0000	1.3
@@ -9,10 +9,11 @@
 #include <linux/module.h>
 #include <linux/mtd/map.h>
 #include <linux/mtd/mtd.h>
+#ifdef CONFIG_MTD_PARTITIONS
+#include <linux/mtd/partitions.h>
+#endif
 
-
-#define NO_DEVICES 8
-struct map_info maps[NO_DEVICES] = {
+static struct map_info mphysmap_static_maps[] = {
 #if CONFIG_MTD_MULTI_PHYSMAP_1_WIDTH
 	{
 		.name		= CONFIG_MTD_MULTI_PHYSMAP_1_NAME,
@@ -45,24 +46,39 @@
 		.bankwidth	= CONFIG_MTD_MULTI_PHYSMAP_4_WIDTH,
 	},
 #endif
-	{
-		.name = NULL,
-	},
 };
+
 DECLARE_MUTEX(map_mutex);
 
 
-static int map_one(struct map_info *map)
+static int mphysmap_map_device(struct map_info *map)
 {
-	struct mtd_info *mtd;
-
+	static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
+	const char **type;
+	struct mtd_info* mtd;
+#ifdef CONFIG_MTD_PARTITIONS
+       struct mtd_partition* mtd_parts;
+       int mtd_parts_nb;
+       static const char *part_probes[] __initdata = {
+#ifdef CONFIG_MTD_CMDLINE_PARTS       
+       "cmdlinepart", 
+#endif
+#ifdef CONFIG_MTD_REDBOOT_PARTS       
+       "RedBoot", 
+#endif       
+       NULL};
+#endif
 	map->virt = ioremap(map->phys, map->size);
 	if (!map->virt)
 		return -EIO;
 
 	simple_map_init(map);
-
-	mtd = do_map_probe("cfi_probe", map);
+	mtd = NULL;
+	type = rom_probe_types;
+	for(; !mtd && *type; type++) {
+		mtd = do_map_probe(*type, map);
+	}
+	
 	if (!mtd) {
 		iounmap(map->virt);
 		return -ENXIO;
@@ -70,25 +86,48 @@
 
 	map->map_priv_1 = (unsigned long)mtd;
 	mtd->owner = THIS_MODULE;
-	/* TODO: partitioning */
-	return add_mtd_device(mtd);
+
+#ifdef CONFIG_MTD_PARTITIONS
+	mtd_parts_nb = parse_mtd_partitions(mtd, part_probes, 
+					    &mtd_parts, 0);
+	if (mtd_parts_nb > 0)
+	{
+		add_mtd_partitions (mtd, mtd_parts, mtd_parts_nb);
+		map->map_priv_2=(unsigned long)mtd_parts;
+	}
+	else
+	{
+		add_mtd_device(mtd);
+		map->map_priv_2=(unsigned long)NULL;
+        };
+#else
+	add_mtd_device(mtd);
+#endif	
+	return 0;
 }
 
 
-static void unmap_one(struct map_info *map)
+static void mphysmap_unmap_device(struct map_info *map)
 {
-	struct mtd_info *mtd = (struct mtd_info*)map->map_priv_1;
-
-	if (map->map_priv_2)
-		kfree(map->name);
-
+	struct mtd_info* mtd = (struct mtd_info*)map->map_priv_1;
+#ifdef CONFIG_MTD_PARTITIONS
+       struct mtd_partition* mtd_parts=(struct mtd_partition*)map->map_priv_2;
+#endif
+	BUG_ON(!mtd);
 	if (!map->virt)
 		return;
 
-	BUG_ON(!mtd);
-	BUG_ON(map->map_priv_2 > 1);
-
+#ifdef CONFIG_MTD_PARTITIONS
+	if (mtd_parts)
+	{
+		del_mtd_partitions(mtd);
+		kfree(mtd_parts);
+	}
+	else
+	    del_mtd_device(mtd);
+#else
 	del_mtd_device(mtd);
+#endif	
 	map_destroy(mtd);
 	iounmap(map->virt);
 
@@ -98,165 +137,23 @@
 }
 
 
-static struct map_info *next_free_map(void)
-{
-	int i;
-	for (i=0; i<NO_DEVICES; i++) {
-		struct map_info *map = &maps[i];
-		if (!map->virt)
-			return map;
-	}
-	return NULL;
-}
-
-
-static int add_one_map(const char *name, unsigned long start,
-		unsigned long len, int width)
-{
-	struct map_info *map = next_free_map();
-	if (!map)
-		return -ENOSPC;
-	
-	map->name = kmalloc(strlen(name)+1, GFP_KERNEL);
-	if (!name)
-		return -ENOMEM;
-
-	strcpy(map->name, name);
-	map->phys = start;
-	map->size = len;
-	map->bankwidth = width;
-	map->map_priv_2 = 1; /* marker to free map->name */
-
-	return map_one(map);
-}
-
-
-static int parse_ulong(unsigned long *num, const char *token)
-{
-	char *endp;
-	unsigned long n;
-
-	n = ustrtoul(token, &endp, 0);
-	if (*endp)
-		return -EINVAL;
-
-	*num = n;
-	return 0;
-}
-
-
-static int parse_uint(unsigned int *num, const char *token)
-{
-	char *endp;
-	unsigned long n;
-
-	n = ustrtoul(token, &endp, 0);
-	if (*endp)
-		return -EINVAL;
-	if ((int)n != n)
-		return -EINVAL;
-
-	*num = n;
-	return 0;
-}
-
-
-static int parse_name(char **pname, const char *token, int limit)
-{
-	size_t len;
-	char *name;
-
-	len = strlen(token) + 1;
-	if (len > limit)
-		return -ENOSPC;
-
-	name = kmalloc(len, GFP_KERNEL);
-	if (!name)
-		return -ENOMEM;
-
-	memcpy(name, token, len);
-
-	*pname = name;
-	return 0;
-}
-
-
-static inline void kill_final_newline(char *str)
-{
-	char *newline = strrchr(str, '\n');
-	if (newline && !newline[1])
-		*newline = 0;
-}
-
-
-#define parse_err(fmt, args...) do {	\
-	printk(KERN_ERR fmt "\n", ## args);	\
-	return 0;			\
-} while(0)
-
-/* mphysmap=name,start,len,width */
-static int mphysmap_setup(const char *val, struct kernel_param *kp)
-{
-	char buf[64+14+14+14], *str = buf;
-	char *token[4];
-	char *name;
-	unsigned long start;
-	unsigned long len;
-	unsigned int width;
-	int i, ret;
-
-	if (strnlen(val, sizeof(buf)) >= sizeof(buf))
-		parse_err("parameter too long");
-
-	strcpy(str, val);
-	kill_final_newline(str);
-
-	for (i=0; i<4; i++)
-		token[i] = strsep(&str, ",");
-
-	if (str)
-		parse_err("too many arguments");
-	if (!token[3])
-		parse_err("not enough arguments");
-
-	ret = parse_name(&name, token[0], 64);
-	if (ret == -ENOMEM)
-		parse_err("out of memory");
-	if (ret == -ENOSPC)
-		parse_err("name too long");
-	if (ret)
-		parse_err("illegal name: %d", ret);
-
-	ret = parse_ulong(&start, token[1]);
-	if (ret)
-		parse_err("illegal start address");
-
-	ret = parse_ulong(&len, token[2]);
-	if (ret)
-		parse_err("illegal length");
-
-	ret = parse_uint(&width, token[3]);
-	if (ret)
-		parse_err("illegal bus width");
-
-	down(&map_mutex);
-	ret = add_one_map(name, start, len, width);
-	up(&map_mutex);
-	if (ret == -ENOSPC)
-		parse_err("no free space for new map");
-	if (ret)
-		parse_err("error while mapping: %d", ret);
-
-	return 0;
-}
 
 
 static int __init mphysmap_init(void)
 {
 	int i;
 	down(&map_mutex);
-	for (i=0; i<NO_DEVICES; i++)
-		map_one(&maps[i]);
+	for (i=0; 
+	     i<sizeof(mphysmap_static_maps)/sizeof(mphysmap_static_maps[0]);
+	     i++)
+	{
+	        if (strcmp(mphysmap_static_maps[i].name,"")!=0 &&
+		    mphysmap_static_maps[i].size!=0 &&
+		    mphysmap_static_maps[i].bankwidth!=0)
+		{		    
+		    mphysmap_map_device(&mphysmap_static_maps[i]);
+		};   
+	};	
 	up(&map_mutex);
 	return 0;
 }
@@ -266,14 +163,21 @@
 {
 	int i;
 	down(&map_mutex);
-	for (i=0; i<NO_DEVICES; i++)
-		unmap_one(&maps[i]);
+	for (i=0; 
+	     i<sizeof(mphysmap_static_maps)/sizeof(mphysmap_static_maps[0]);
+	     i++)
+	{
+	        if (strcmp(mphysmap_static_maps[i].name,"")!=0 &&
+		    mphysmap_static_maps[i].size!=0 &&
+		    mphysmap_static_maps[i].bankwidth!=0)
+		{		    
+		    mphysmap_unmap_device(&mphysmap_static_maps[i]);
+		};   
+	};	
 	up(&map_mutex);
 }
 
 
-__module_param_call("", mphysmap, mphysmap_setup, NULL, NULL, 0600);
-
 module_init(mphysmap_init);
 module_exit(mphysmap_exit);
 





More information about the linux-mtd-cvs mailing list