From d4b3a86433d0c99f37dc4c94986c51e1d472712c Mon Sep 17 00:00:00 2001
From: Thomas Chou <thomas@wytron.com.tw>
Date: Mon, 31 Dec 2007 18:16:04 +0800
Subject: [PATCH] nios2: fix memory module size detection

The previous code does not work for bus width larger than 128 bits. This
patch replace the limited test cases, and should work without bus width
limitation.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
---
 .../nios2nommu/scripts/PTF/SystemPTF/Module.pm     |   17 ++---------------
 1 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/linux-2.6.x/arch/nios2nommu/scripts/PTF/SystemPTF/Module.pm b/linux-2.6.x/arch/nios2nommu/scripts/PTF/SystemPTF/Module.pm
index 48d246b..0036c36 100644
--- a/linux-2.6.x/arch/nios2nommu/scripts/PTF/SystemPTF/Module.pm
+++ b/linux-2.6.x/arch/nios2nommu/scripts/PTF/SystemPTF/Module.pm
@@ -168,21 +168,8 @@ sub getSize {
 	my $data_width = $SBI->getAssignment ('Data_Width');
 	my $addr_width = $SBI->getAssignment ('Address_Width');
 	
-	if ($data_width == 8) {
-		$size = 1 << $addr_width;
-	} elsif ($data_width == 16) {
-		$size = 1 << ($addr_width + 1);
-	} elsif ($data_width == 32) {
-		$size = 1 << ($addr_width + 2);
-	} elsif ($data_width == 64) {
-		$size = 1 << ($addr_width + 3);
-	} elsif ($data_width == 128) {
-		$size = 1 << ($addr_width + 4);
-	} else {
-		return;
-	}
-	
-	$size_text = sprintf ("%#010x", $size);
+	my $size = (1 << $addr_width) * ($data_width / 8);
+	my $size_text = sprintf ("%#010x", $size);
 	return $size_text;
 }
 
-- 
1.5.3.3

