From b42d7fbd85f2a9b9ea9c5ddb70a7d3bf0751a95c Mon Sep 17 00:00:00 2001
From: Nishanth Menon <nm@ti.com>
Date: Thu, 12 Mar 2009 13:46:34 -0500
Subject: [PATCH] MISC: dummy driver to test ioremap
 the script such as the following tests ioremap on sdp3430
 bootargs mem=64M for sdp3430 for the test
 slee()
 {
 	echo "Sleep "
 }
 try=1
 while [ $try -lt 13 ]; do
	i=0
 	while [ $i -lt 100 ]; do
 		echo "insmod $i base=0x87000000 size=0x600000 try=$try"
 		insmod  ./dummy.ko base=0x87000000 size=0x600000 try=$try
 		if [ $? -ne 0 ]; then
 			echo "QUIT IN INSMOD $i"
 			exit 1;
 		fi
 		slee
 		echo "rmmod $i"
 		rmmod dummy
 		if [ $? -ne 0 ]; then
 			echo "QUIT IN RMMOD $i"
 			exit 1;
 		fi
 		i=`expr $i + 1`
 		slee
 	done
 	try=$(( $try + 1 ))
 done


Signed-off-by: Nishanth Menon <nm@ti.com>
---
 drivers/misc/Kconfig  |    4 ++
 drivers/misc/Makefile |    1 +
 drivers/misc/dummy.c  |   91 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/dummy.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index a11e2a0..2934c4a 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -13,6 +13,10 @@ menuconfig MISC_DEVICES
 
 if MISC_DEVICES
 
+config MISC_DUMMY
+	tristate "dummy lil driver"
+	default m
+
 config ATMEL_PWM
 	tristate "Atmel AT32/AT91 PWM support"
 	depends on AVR32 || ARCH_AT91SAM9263 || ARCH_AT91SAM9RL || ARCH_AT91CAP9
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 78be134..9e7b2a6 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -2,6 +2,7 @@
 # Makefile for misc devices that really don't fit anywhere else.
 #
 obj- := misc.o	# Dummy rule to force built-in.o to be made
+obj-$(CONFIG_MISC_DUMMY)	+= dummy.o
 
 obj-$(CONFIG_IBM_ASM)		+= ibmasm/
 obj-$(CONFIG_HDPU_FEATURES)	+= hdpuftrs/
diff --git a/drivers/misc/dummy.c b/drivers/misc/dummy.c
new file mode 100644
index 0000000..9c6500f
--- /dev/null
+++ b/drivers/misc/dummy.c
@@ -0,0 +1,91 @@
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/mm.h>
+#include <linux/dma-mapping.h>
+
+static int size;
+module_param(size, int, 0);
+MODULE_PARM_DESC(size, "size default =0x87000000");
+
+static int base;
+module_param(base, int, 0);
+MODULE_PARM_DESC(base, "Baseaddress default 0x6000000");
+
+struct mem_s {
+	void *vir;
+	u32 phy;
+	u32 size;
+};
+
+static struct mem_s b[] = {
+	{0, 0, 0},		/* Fill me up scotty */
+	{0, 0x5d000000, 4096},
+	{0, 0x5c7f8000, 98304},
+	{0, 0x5ce00000, 32768},
+	{0, 0x5cf04000, 81920},
+	{0, 0x48306000, 4096},
+	{0, 0x48004000, 4096},
+	{0, 0x48094000, 4096},
+	{0, 0x48002000, 4096},
+	{0, 0x48005000, 4096},
+	{0, 0x48307000, 4096},
+	{0, 0x48306a00, 4096},
+};
+
+static int try;
+module_param(try, int, (sizeof(b) / sizeof(struct mem_s)));
+MODULE_PARM_DESC(try, "try=12");
+
+static int __init dummy_init(void)
+{
+	int i;
+	b[0].phy = base;
+	b[0].size = size;
+	if (!try)
+		try = (sizeof(b) / sizeof(struct mem_s));
+	if (!base)
+		base = 0x87000000;
+	if (!size)
+		size = 0x600000;
+	if (try > (sizeof(b) / sizeof(struct mem_s))) {
+		printk(KERN_ERR "Give me proper try value\n");
+		return -EINVAL;
+	}
+	for (i = 0; i < try; i++) {
+		b[i].vir = ioremap(b[i].phy, b[i].size);
+		printk(KERN_INFO
+		       "Map[%d] - virt=0x%08X phy=0x%08X size=0x%08X\n", i,
+		       (u32) (b[i].vir), b[i].phy, b[i].size);
+		if (b[i].vir == NULL) {
+			printk(KERN_ERR "Allocation failed idx=%d\n", i);
+			/* Free up all the prev allocs */
+			i--;
+			while (i >= 0) {
+				iounmap(b[i].vir);
+				i--;
+			}
+			return -ENOMEM;
+
+		}
+	}
+	return 0;
+}
+
+module_init(dummy_init);
+
+static void __exit dummy_exit(void)
+{
+	int i;
+	for (i = 0; i < try; i++) {
+		printk(KERN_INFO
+		       "Unmap[%d] - virt=0x%08X phy=0x%08X size=0x%08X\n", i,
+		       (u32) b[i].vir, b[i].phy, b[i].size);
+		iounmap(b[i].vir);
+	}
+}
+
+module_exit(dummy_exit);
+
+MODULE_LICENSE("GPL");
-- 
1.5.4.3

