From 98d46e88ffe23a9adcf6ae1acf19b210d5ac3737 Mon Sep 17 00:00:00 2001
From: Vikram Pandita <vikram.pandita@ti.com>
Date: Thu, 20 Aug 2009 17:16:24 -0500
Subject: [PATCH 3/5] OMAP: Zoom2: Add DEBUG_LL interface using external Quart

This patch adds DEBUG_LL interface for Zoom2 board.
The low level debug uart now points corrctly to External Quad uart
controller on detachable debug board.

The Quad uart is available over GPMC chip select with physical address
0x10000000.

This physical address has been mapped to virtual address 0xFB000000
as per static mapping.

Also the register accesses to Quad uart have a requirement of shift=1
based on the h/w mapping of the registers

This patch is adapted from a version by Erik Gilling:
http://android.git.kernel.org/?p=kernel/omap.git;
a=commit;h=e9d72efdd88877d2d6ea74a08983ace0dcc771d3

Signed-off-by: Vikram Pandita <vikram.pandita@ti.com>
Cc: Erik Gilling <konkers@android.com>
---
 arch/arm/mach-omap2/board-zoom-debugboard.c   |    5 +++--
 arch/arm/mach-omap2/board-zoom2.c             |   15 +++++++++++++++
 arch/arm/plat-omap/include/mach/debug-macro.S |   14 ++++++++++++--
 arch/arm/plat-omap/include/mach/io.h          |    6 ++++++
 arch/arm/plat-omap/include/mach/uncompress.h  |    7 +++++++
 5 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-omap2/board-zoom-debugboard.c b/arch/arm/mach-omap2/board-zoom-debugboard.c
index f546063..f8b0726 100644
--- a/arch/arm/mach-omap2/board-zoom-debugboard.c
+++ b/arch/arm/mach-omap2/board-zoom-debugboard.c
@@ -82,9 +82,10 @@ static inline void __init zoom2_init_smsc911x(void)
 
 static struct plat_serial8250_port serial_platform_data[] = {
 	{
-		.mapbase	= 0x10000000,
+		.membase	= IOMEM(ZOOM2_EXT_QUART_VIRT),
+		.mapbase	= ZOOM2_EXT_QUART_PHYS,
 		.irq		= OMAP_GPIO_IRQ(102),
-		.flags		= UPF_BOOT_AUTOCONF|UPF_IOREMAP|UPF_SHARE_IRQ,
+		.flags		= UPF_BOOT_AUTOCONF|UPF_SHARE_IRQ,
 		.irqflags	= IRQF_SHARED | IRQF_TRIGGER_RISING,
 		.iotype		= UPIO_MEM,
 		.regshift	= 1,
diff --git a/arch/arm/mach-omap2/board-zoom2.c b/arch/arm/mach-omap2/board-zoom2.c
index 58baee3..fc27b07 100644
--- a/arch/arm/mach-omap2/board-zoom2.c
+++ b/arch/arm/mach-omap2/board-zoom2.c
@@ -16,9 +16,11 @@
 #include <linux/gpio.h>
 #include <linux/i2c/twl4030.h>
 #include <linux/regulator/machine.h>
+#include <linux/io.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
+#include <asm/mach/map.h>
 
 #include <mach/common.h>
 #include <mach/usb.h>
@@ -273,9 +275,22 @@ static void __init omap_zoom2_init(void)
 	usb_musb_init();
 }
 
+static struct map_desc zoom2_io_desc[] __initdata = {
+	{
+		.virtual        = ZOOM2_EXT_QUART_VIRT,
+		.pfn            = __phys_to_pfn(ZOOM2_EXT_QUART_PHYS),
+		.length         = ZOOM2_EXT_QUART_SIZE,
+		.type           = MT_DEVICE
+	}
+};
+
 static void __init omap_zoom2_map_io(void)
 {
 	omap2_set_globals_343x();
+
+	/* Map external quad UART virt to phy mapping */
+	iotable_init(zoom2_io_desc, ARRAY_SIZE(zoom2_io_desc));
+
 	omap2_map_common_io();
 }
 
diff --git a/arch/arm/plat-omap/include/mach/debug-macro.S b/arch/arm/plat-omap/include/mach/debug-macro.S
index f546d6c..a97f2fb 100644
--- a/arch/arm/plat-omap/include/mach/debug-macro.S
+++ b/arch/arm/plat-omap/include/mach/debug-macro.S
@@ -12,6 +12,14 @@
 */
 #include "io.h"
 
+#if (CONFIG_OMAP_DEBUG_LL_UART_PHY_ADDR == 0x10000000)
+#define REGSHIFT 1
+#define UART_VIRT_TO_PHY_OFFSET ZOOM2_EXT_QUART_PHY_TO_VIRT_OFF
+#else
+#define REGSHIFT 2
+#define UART_VIRT_TO_PHY_OFFSET OMAP2_IO_OFFSET
+#endif
+
 		.macro	addruart,rx
 		mrc	p15, 0, \rx, c1, c0
 		tst	\rx, #1			@ MMU enabled?
@@ -22,7 +30,7 @@
 #else
 					/* omap2/omap3/omap4 */
 		ldr	\rx, =CONFIG_OMAP_DEBUG_LL_UART_PHY_ADDR @ physical base address
-		orrne	\rx, \rx, #OMAP2_IO_OFFSET	 @ virtual base
+		orrne	\rx, \rx, #UART_VIRT_TO_PHY_OFFSET	 @ virtual base
 #endif
 		.endm
 
@@ -31,13 +39,15 @@
 		.endm
 
 		.macro	busyuart,rd,rx
-1001:		ldrb	\rd, [\rx, #(0x5 << 2)]	@ OMAP-1510 and friends
+1001:		ldrb	\rd, [\rx, #(0x5 << REGSHIFT)] @ OMAP-1510 and friends
 		and	\rd, \rd, #0x60
 		teq	\rd, #0x60
+#if (CONFIG_OMAP_DEBUG_LL_UART_PHY_ADDR != 0x10000000)
 		beq	1002f
 		ldrb	\rd, [\rx, #(0x5 << 0)]	@ OMAP-730 only
 		and	\rd, \rd, #0x60
 		teq	\rd, #0x60
+#endif
 		bne	1001b
 1002:
 		.endm
diff --git a/arch/arm/plat-omap/include/mach/io.h b/arch/arm/plat-omap/include/mach/io.h
index 8d32df3..97702e6 100644
--- a/arch/arm/plat-omap/include/mach/io.h
+++ b/arch/arm/plat-omap/include/mach/io.h
@@ -169,6 +169,12 @@
 #define DSP_MMU_34XX_VIRT	0xe2000000
 #define DSP_MMU_34XX_SIZE	SZ_4K
 
+/* Map External Quad UART for Zoom2 board */
+#define ZOOM2_EXT_QUART_PHYS		0x10000000 /* PHY address if fixed */
+#define ZOOM2_EXT_QUART_PHY_TO_VIRT_OFF	0xeb000000
+#define ZOOM2_EXT_QUART_VIRT		0xfb000000
+#define ZOOM2_EXT_QUART_SIZE		SZ_16
+
 /*
  * ----------------------------------------------------------------------------
  * Omap4 specific IO mapping
diff --git a/arch/arm/plat-omap/include/mach/uncompress.h b/arch/arm/plat-omap/include/mach/uncompress.h
index 0e21eb3..959195a 100644
--- a/arch/arm/plat-omap/include/mach/uncompress.h
+++ b/arch/arm/plat-omap/include/mach/uncompress.h
@@ -41,6 +41,13 @@ static void putc(int c)
 #if defined(CONFIG_DEBUG_LL)
 	uart = (volatile u8 *)(CONFIG_OMAP_DEBUG_LL_UART_PHY_ADDR);
 
+#if (CONFIG_OMAP_DEBUG_LL_UART_PHY_ADDR == 0x10000000)
+	/* External UART has a shift=1 requirement
+	 * Internal OMAP UARTs have shift=2 requirement
+	 */
+	shift = 1;
+#endif
+
 #ifdef CONFIG_ARCH_OMAP1
 	/* Determine which serial port to use */
 	do {
-- 
1.6.3.2

