copper: Enable UART and USB drivers.

Change-Id: I07425290fc603440e5016c878d9b75862ab543df
diff --git a/platform/copper/acpuclock.c b/platform/copper/acpuclock.c
index 7019518..ec8ff10 100644
--- a/platform/copper/acpuclock.c
+++ b/platform/copper/acpuclock.c
@@ -56,3 +56,10 @@
 
 }
 
+/* Configure UART clock based on the UART block id*/
+void clock_config_uart_dm(uint8_t id)
+{
+       /* Enable blsp_uart_clk */
+      /* Turned on by simulation by default */
+
+}
diff --git a/platform/copper/gpio.c b/platform/copper/gpio.c
new file mode 100644
index 0000000..86b9e40
--- /dev/null
+++ b/platform/copper/gpio.c
@@ -0,0 +1,62 @@
+/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *  * Neither the name of Code Aurora Forum, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <debug.h>
+#include <reg.h>
+#include <platform/iomap.h>
+#include <platform/gpio.h>
+#include <gsbi.h>
+
+void gpio_tlmm_config(uint32_t gpio, uint8_t func,
+		      uint8_t dir, uint8_t pull,
+		      uint8_t drvstr, uint32_t enable)
+{
+	uint32_t val = 0;
+	val |= pull;
+	val |= func << 2;
+	val |= drvstr << 6;
+	val |= enable << 9;
+	writel(val, (unsigned int *)GPIO_CONFIG_ADDR(gpio));
+	return;
+}
+
+void gpio_set(uint32_t gpio, uint32_t dir)
+{
+	writel(dir, (unsigned int *)GPIO_CONFIG_ADDR(gpio));
+	return;
+}
+
+/* Configure gpio for blsp uart 2 */
+void gpio_config_uart_dm(uint8_t id)
+{
+	gpio_tlmm_config(0, 2, GPIO_OUTPUT, GPIO_NO_PULL,
+				GPIO_8MA, GPIO_DISABLE);
+
+	gpio_tlmm_config(1, 2, GPIO_INPUT, GPIO_NO_PULL,
+				GPIO_8MA, GPIO_DISABLE);
+}
diff --git a/platform/copper/include/platform/clock.h b/platform/copper/include/platform/clock.h
index e47aa3d..179d281 100644
--- a/platform/copper/include/platform/clock.h
+++ b/platform/copper/include/platform/clock.h
@@ -26,6 +26,12 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+/* Included temporarily  for compilation.
+ * Needs to be changed later for the
+ * correct clock rate
+ */
+#define UART_DM_CLK_RX_TX_BIT_RATE        0xFF
+
 void clock_init_mmc(uint32_t interface);
 void clock_config_mmc(uint32_t interface, uint32_t freq);
-void clock_config(uint32_t ns, uint32_t md, uint32_t ns_addr, uint32_t md_addr);
+void clock_config_uart_dm(uint8_t id);
diff --git a/platform/copper/include/platform/gpio.h b/platform/copper/include/platform/gpio.h
new file mode 100644
index 0000000..cdbab00
--- /dev/null
+++ b/platform/copper/include/platform/gpio.h
@@ -0,0 +1,58 @@
+/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials provided
+ *    with the distribution.
+ *  * Neither the name of Code Aurora Forum, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __PLATFORM_COPPER_GPIO_H
+#define __PLATFORM_COPPER_GPIO_H
+
+/* GPIO TLMM: Direction */
+#define GPIO_INPUT      0
+#define GPIO_OUTPUT     1
+
+/* GPIO TLMM: Pullup/Pulldown */
+#define GPIO_NO_PULL    0
+#define GPIO_PULL_DOWN  1
+#define GPIO_KEEPER     2
+#define GPIO_PULL_UP    3
+
+/* GPIO TLMM: Drive Strength */
+#define GPIO_2MA        0
+#define GPIO_4MA        1
+#define GPIO_6MA        2
+#define GPIO_8MA        3
+#define GPIO_10MA       4
+#define GPIO_12MA       5
+#define GPIO_14MA       6
+#define GPIO_16MA       7
+
+/* GPIO TLMM: Status */
+#define GPIO_ENABLE     0
+#define GPIO_DISABLE    1
+
+void gpio_config_uart_dm(uint8_t id);
+
+#endif
diff --git a/platform/copper/include/platform/iomap.h b/platform/copper/include/platform/iomap.h
index 8178ee1..4190de3 100644
--- a/platform/copper/include/platform/iomap.h
+++ b/platform/copper/include/platform/iomap.h
@@ -48,11 +48,11 @@
 #define MSM_SDC3_BASE               (PERIPH_SS_BASE + 0x00064000)
 #define MSM_SDC2_BASE               (PERIPH_SS_BASE + 0x000A4000)
 #define MSM_SDC4_BASE               (PERIPH_SS_BASE + 0x000E4000)
-#define BLSP2_BASE                  (PERIPH_SS_BASE + 0x00140000)
-#define BLSP2_UART2_BASE            (BLSP2_BASE + 0x1F000)
+#define BLSP1_UART0_BASE            (PERIPH_SS_BASE + 0x0011D000)
+#define MSM_USB_BASE                (PERIPH_SS_BASE + 0x00255000)
 
 #define CLK_CTL_BASE                0xFC400000
-#define TLMM_BASE_ADDR              0xFD400000
+#define TLMM_BASE_ADDR              0xFD500000
 
 #define GPIO_CONFIG_ADDR(x)         (TLMM_BASE_ADDR + 0x1000 + (x)*0x10)
 #define GPIO_IN_OUT_ADDR(x)         (TLMM_BASE_ADDR + 0x1004 + (x)*0x10)
diff --git a/platform/copper/include/platform/irqs.h b/platform/copper/include/platform/irqs.h
index 57912b1..2d8df00 100644
--- a/platform/copper/include/platform/irqs.h
+++ b/platform/copper/include/platform/irqs.h
@@ -45,6 +45,8 @@
 
 #define USB1_HS_BAM_IRQ                        (GIC_SPI_START + 135)
 #define USB1_HS_IRQ                            (GIC_SPI_START + 134)
+#define USB2_IRQ                               (GIC_SPI_START + 141)
+#define USB1_IRQ                               (GIC_SPI_START + 142)
 
 /* Retrofit universal macro names */
 #define INT_USB_HS                             USB1_HS_IRQ
diff --git a/platform/copper/rules.mk b/platform/copper/rules.mk
index 8b6a0f1..5e0c78a 100644
--- a/platform/copper/rules.mk
+++ b/platform/copper/rules.mk
@@ -8,6 +8,7 @@
 
 MMC_SLOT         := 1
 
+DEFINES += PERIPH_BLK_BLSP=1 
 DEFINES += WITH_CPU_EARLY_INIT=0 WITH_CPU_WARM_BOOT=0 \
 	   MMC_SLOT=$(MMC_SLOT)
 
@@ -15,7 +16,8 @@
 
 OBJS += \
 	$(LOCAL_DIR)/platform.o \
-	$(LOCAL_DIR)/acpuclock.o
+	$(LOCAL_DIR)/acpuclock.o \
+	$(LOCAL_DIR)/gpio.o
 
 LINKER_SCRIPT += $(BUILDDIR)/system-onesegment.ld
 
diff --git a/platform/msm_shared/include/uart_dm.h b/platform/msm_shared/include/uart_dm.h
index f7746de..3421666 100644
--- a/platform/msm_shared/include/uart_dm.h
+++ b/platform/msm_shared/include/uart_dm.h
@@ -81,7 +81,7 @@
 
 /* UART DM TX FIFO Registers - 4 */
 #if PERIPH_BLK_BLSP
-#define MSM_BOOT_UART_DM_TF(base, x)         ((base + 0x100+(4*(x)))
+#define MSM_BOOT_UART_DM_TF(base, x)         ((base) + 0x100+(4*(x)))
 #else
 #define MSM_BOOT_UART_DM_TF(base, x)         ((base) + 0x70+(4*(x)))
 #endif
diff --git a/platform/msm_shared/rules.mk b/platform/msm_shared/rules.mk
index 5ae6935..b36e831 100644
--- a/platform/msm_shared/rules.mk
+++ b/platform/msm_shared/rules.mk
@@ -60,7 +60,8 @@
 	OBJS += $(LOCAL_DIR)/qgic.o \
 			$(LOCAL_DIR)/qtimer.o \
 			$(LOCAL_DIR)/qtimer_cp15.o \
-			$(LOCAL_DIR)/interrupts.o
+			$(LOCAL_DIR)/interrupts.o \
+			$(LOCAL_DIR)/uart_dm.o
 endif
 
 ifeq ($(PLATFORM),msm7x27a)
diff --git a/project/copper.mk b/project/copper.mk
index 808c582..175bf54 100644
--- a/project/copper.mk
+++ b/project/copper.mk
@@ -9,5 +9,5 @@
 DEBUG := 1
 
 #DEFINES += WITH_DEBUG_DCC=1
-#DEFINES += WITH_DEBUG_UART=1
+DEFINES += WITH_DEBUG_UART=1
 #DEFINES += WITH_DEBUG_FBCON=1
diff --git a/target/copper/atags.c b/target/copper/atags.c
index f2ee81b..a0e9ff9 100644
--- a/target/copper/atags.c
+++ b/target/copper/atags.c
@@ -41,7 +41,3 @@
 	return ((void *)SCRATCH_ADDR);
 }
 
-unsigned target_get_max_flash_size(void)
-{
-	return 0;
-}
diff --git a/target/copper/init.c b/target/copper/init.c
index 3881ebd..382581f 100644
--- a/target/copper/init.c
+++ b/target/copper/init.c
@@ -35,6 +35,7 @@
 #include <reg.h>
 #include <target.h>
 #include <platform.h>
+#include <uart_dm.h>
 
 static unsigned int target_id;
 extern void dmb(void);
@@ -56,6 +57,8 @@
 	uint32_t base_addr;
 	uint8_t slot;
 
+	uart_dm_init(0, 0, BLSP1_UART0_BASE);
+
 	dprintf(INFO, "target_init()\n");
 
 	target_id = COPPER_TARGET_ID;
diff --git a/target/copper/rules.mk b/target/copper/rules.mk
index a9a3401..f57f35a 100644
--- a/target/copper/rules.mk
+++ b/target/copper/rules.mk
@@ -14,7 +14,6 @@
 RAMDISK_ADDR     := BASE_ADDR+0x01000000
 SCRATCH_ADDR     := 0x00000000
 
-
 MODULES += \
 	dev/keys \
     lib/ptable