Merge "msm8960: Pass complete EBI memory available to kernel as memory tags"
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 5eef029..751a598 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -691,8 +691,13 @@
 		}
 	}
 
-    dprintf(SPEW, "Wrote %d blocks, expected to write %d blocks\n",
-             total_blocks, sparse_header->total_blks);
+	dprintf(INFO, "Wrote %d blocks, expected to write %d blocks\n",
+					total_blocks, sparse_header->total_blks);
+
+	if(total_blocks != sparse_header->total_blks)
+	{
+		fastboot_fail("sparse image write failure");
+	}
 
 	fastboot_okay("");
 	return;
@@ -895,6 +900,8 @@
 
 fastboot:
 
+       target_fastboot_init();
+
 	if(!usb_init)
 		udc_init(&surf_udc_device);
 
diff --git a/dev/pmic/pm8921/include/dev/pm8921.h b/dev/pmic/pm8921/include/dev/pm8921.h
new file mode 100644
index 0000000..faca8e2
--- /dev/null
+++ b/dev/pmic/pm8921/include/dev/pm8921.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2011, 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 __DEV_PM8921_H
+#define __DEV_PM8921_H
+
+#include <sys/types.h>
+
+typedef struct
+{
+	uint32_t initialized;
+
+	int (*read)(uint8_t *data, uint32_t length, uint32_t addr);
+	int (*write)(uint8_t *data, uint32_t length, uint32_t addr);
+
+} pm8921_dev_t;
+
+
+void pm8921_init(pm8921_dev_t *);
+void pm8921_boot_done(void);
+
+#endif
diff --git a/dev/pmic/pm8921/pm8921.c b/dev/pmic/pm8921/pm8921.c
new file mode 100644
index 0000000..6a47e05
--- /dev/null
+++ b/dev/pmic/pm8921/pm8921.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2011, 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 <assert.h>
+#include <sys/types.h>
+#include <dev/pm8921.h>
+#include "pm8921_hw.h"
+
+
+static pm8921_dev_t *dev;
+
+
+/* Intialize the pmic driver */
+void pm8921_init(pm8921_dev_t *pmic)
+{
+	ASSERT(pmic);
+	ASSERT(pmic->read);
+	ASSERT(pmic->write);
+
+	dev = pmic;
+
+	dev->initialized = 1;
+}
+
+/* Set the BOOT_DONE flag */
+void pm8921_boot_done(void)
+{
+	uint8_t val;
+
+	ASSERT(dev);
+	ASSERT(dev->initialized);
+
+	dev->read(&val, 1, PBL_ACCESS_2);
+	val |= PBL_ACCESS_2_ENUM_TIMER_STOP;
+	/* TODO: Remove next line when h/w is rewired for battery simulation.*/
+	val |= (0x7 << 2);
+	dev->write(&val, 1, PBL_ACCESS_2);
+
+	dev->read(&val, 1, SYS_CONFIG_2);
+	val |= (SYS_CONFIG_2_BOOT_DONE | SYS_CONFIG_2_ADAPTIVE_BOOT_DISABLE);
+	dev->write(&val, 1, SYS_CONFIG_2);
+}
diff --git a/dev/pmic/pm8921/pm8921_hw.h b/dev/pmic/pm8921/pm8921_hw.h
new file mode 100644
index 0000000..49069ee
--- /dev/null
+++ b/dev/pmic/pm8921/pm8921_hw.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011, 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.
+ */
+
+#define PBL_ACCESS_2 0x005
+#define PBL_ACCESS_2_ENUM_TIMER_STOP      (1 << 1)
+
+#define SYS_CONFIG_2 0x007
+#define SYS_CONFIG_2_BOOT_DONE             (1 << 6)
+#define SYS_CONFIG_2_ADAPTIVE_BOOT_DISABLE (1 << 7)
diff --git a/dev/pmic/pm8921/rules.mk b/dev/pmic/pm8921/rules.mk
new file mode 100644
index 0000000..e377786
--- /dev/null
+++ b/dev/pmic/pm8921/rules.mk
@@ -0,0 +1,7 @@
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+INCLUDES += -I$(LOCAL_DIR)/include
+
+OBJS += \
+	$(LOCAL_DIR)/pm8921.o
+
diff --git a/platform/msm7x27a/acpuclock.c b/platform/msm7x27a/acpuclock.c
index c36b5d6..c203813 100755
--- a/platform/msm7x27a/acpuclock.c
+++ b/platform/msm7x27a/acpuclock.c
@@ -201,7 +201,11 @@
 			clk_cntl_reg_val = clk_cntl_reg_val_7627A;
 			size = ARRAY_SIZE(clk_cntl_reg_val_7627A);
 			pll_request(2, 1);
+
+		/* TODO: Enable this PLL while switching to 800MHz */
+		#if 0
 			pll_request(4, 1);
+		#endif
 			break;
 
 		case MSM7225A:
diff --git a/platform/msm8x60/include/platform/pmic.h b/platform/msm8x60/include/platform/pmic.h
index d1c0a2d..813f290 100755
--- a/platform/msm8x60/include/platform/pmic.h
+++ b/platform/msm8x60/include/platform/pmic.h
@@ -86,6 +86,62 @@
 #define IRQ_BLOCK_SEL_USR_ADDR 0x1C0
 #define IRQ_STATUS_RT_USR_ADDR 0x1C3
 
+/* PMIC 8058 LDO module defines */
+#define PM8058_LDO_CTRL_L0   (0x009)
+#define PM8058_LDO_TEST_L0   (0x065)
+#define PM8058_LDO_CTRL_L1   (0x00A)
+#define PM8058_LDO_TEST_L1   (0x066)
+#define PM8058_LDO_CTRL_L2   (0x00B)
+#define PM8058_LDO_TEST_L2   (0x067)
+#define PM8058_LDO_CTRL_L3   (0x00C)
+#define PM8058_LDO_TEST_L3   (0x068)
+#define PM8058_LDO_CTRL_L4   (0x00D)
+#define PM8058_LDO_TEST_L4   (0x069)
+#define PM8058_LDO_CTRL_L5   (0x00E)
+#define PM8058_LDO_TEST_L5   (0x06A)
+#define PM8058_LDO_CTRL_L6   (0x00F)
+#define PM8058_LDO_TEST_L6   (0x06B)
+#define PM8058_LDO_CTRL_L7   (0x010)
+#define PM8058_LDO_TEST_L7   (0x06C)
+#define PM8058_LDO_CTRL_L8   (0x011)
+#define PM8058_LDO_TEST_L8   (0x06D)
+#define PM8058_LDO_CTRL_L9   (0x012)
+#define PM8058_LDO_TEST_L9   (0x06E)
+#define PM8058_LDO_CTRL_L10  (0x013)
+#define PM8058_LDO_TEST_L10  (0x06F)
+#define PM8058_LDO_CTRL_L11  (0x014)
+#define PM8058_LDO_TEST_L11  (0x070)
+#define PM8058_LDO_CTRL_L12  (0x015)
+#define PM8058_LDO_TEST_L12  (0x071)
+#define PM8058_LDO_CTRL_L13  (0x016)
+#define PM8058_LDO_TEST_L13  (0x072)
+#define PM8058_LDO_CTRL_L14  (0x017)
+#define PM8058_LDO_TEST_L14  (0x073)
+
+#define PM8058_LDO_CTRL_L15  (0x089)
+#define PM8058_LDO_TEST_L15  (0x0E5)
+#define PM8058_LDO_CTRL_L16  (0x08A)
+#define PM8058_LDO_TEST_L16  (0x0E6)
+#define PM8058_LDO_CTRL_L17  (0x08B)
+#define PM8058_LDO_TEST_L17  (0x0E7)
+
+#define PM8058_LDO_CTRL_L18  (0x11D)
+#define PM8058_LDO_TEST_L18  (0x125)
+#define PM8058_LDO_CTRL_L19  (0x11E)
+#define PM8058_LDO_TEST_L19  (0x126)
+#define PM8058_LDO_CTRL_L20  (0x11F)
+#define PM8058_LDO_TEST_L20  (0x127)
+#define PM8058_LDO_CTRL_L21  (0x120)
+#define PM8058_LDO_TEST_L21  (0x128)
+#define PM8058_LDO_CTRL_L22  (0x121)
+#define PM8058_LDO_TEST_L22  (0x129)
+#define PM8058_LDO_CTRL_L23  (0x122)
+#define PM8058_LDO_TEST_L23  (0x12A)
+#define PM8058_LDO_CTRL_L24  (0x123)
+#define PM8058_LDO_TEST_L24  (0x12B)
+#define PM8058_LDO_CTRL_L25  (0x124)
+#define PM8058_LDO_TEST_L25  (0x12C)
+
 typedef enum
 {
     PM_KYPD_PWRON_IRQ_ID        = 51,
diff --git a/platform/msm_shared/mmc.c b/platform/msm_shared/mmc.c
index 34b73a3..3984bf6 100644
--- a/platform/msm_shared/mmc.c
+++ b/platform/msm_shared/mmc.c
@@ -2553,23 +2553,23 @@
 /*

  * Returns offset of given partition

  */

-unsigned long long mmc_ptn_offset (unsigned char * name)

+uint64_t mmc_ptn_offset (unsigned char * name)

 {

     unsigned n;

     for(n = 0; n < mmc_partition_count; n++) {

         if(!strcmp((const char *)mbr[n].name, (const char *)name)) {

-            return (mbr[n].dfirstsec * MMC_BOOT_RD_BLOCK_LEN);

+            return ((uint64_t)mbr[n].dfirstsec * MMC_BOOT_RD_BLOCK_LEN);

         }

     }

     return 0;

 }

 

-unsigned long long mmc_ptn_size (unsigned char * name)

+uint64_t mmc_ptn_size (unsigned char * name)

 {

     unsigned n;

     for(n = 0; n < mmc_partition_count; n++) {

         if(!strcmp((const char *)mbr[n].name, (const char *)name)) {

-            return (mbr[n].dsize * MMC_BOOT_RD_BLOCK_LEN);

+            return ((uint64_t)mbr[n].dsize * MMC_BOOT_RD_BLOCK_LEN);

         }

     }

     return 0;

diff --git a/target/init.c b/target/init.c
index a771544..7285bcf 100644
--- a/target/init.c
+++ b/target/init.c
@@ -27,7 +27,7 @@
 
 #define EXPAND(NAME) #NAME
 #define TARGET(NAME) EXPAND(NAME)
-/* 
+/*
  * default implementations of these routines, if the target code
  * chooses not to implement.
  */
@@ -87,3 +87,7 @@
 {
 	sprintf(buf, "%s",TARGET(BOARD));
 }
+
+__WEAK void target_fastboot_init()
+{
+}
diff --git a/target/msm8960/init.c b/target/msm8960/init.c
old mode 100755
new mode 100644
index 45ce4df..c31a4a4
--- a/target/msm8960/init.c
+++ b/target/msm8960/init.c
@@ -36,6 +36,8 @@
 #include <platform/iomap.h>
 #include <reg.h>
 #include <dev/keys.h>
+#include <dev/pm8921.h>
+#include <dev/gpio_keypad.h>
 
 #define LINUX_MACHTYPE_8960_SIM     3230
 #define LINUX_MACHTYPE_8960_RUMI3   3231
@@ -51,12 +53,20 @@
 
 static unsigned mmc_sdc_base[] = { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE};
 
+static pm8921_dev_t pmic;
+
 void target_init(void)
 {
 	unsigned base_addr;
 	unsigned char slot;
 	dprintf(INFO, "target_init()\n");
 
+	/* Initialize PMIC driver */
+	pmic.read  = pa1_ssbi2_read_bytes;
+	pmic.write = pa1_ssbi2_write_bytes;
+
+	pm8921_init(&pmic);
+
 	/* Keypad init */
 	keys_init();
 	keypad_init();
@@ -79,33 +89,19 @@
 
 unsigned board_machtype(void)
 {
-	struct smem_board_info_v5 board_info_v5;
 	struct smem_board_info_v6 board_info_v6;
 	unsigned int board_info_len = 0;
 	unsigned smem_status = 0;
 	unsigned format = 0;
-	unsigned id = 0;
-	unsigned mach_id = LINUX_MACHTYPE_8960_RUMI3;
+	unsigned id = HW_PLATFORM_UNKNOWN;
+	unsigned mach_id;
 
-	/* Until the bootchain is in, return CDP id. */
-	return LINUX_MACHTYPE_8960_CDP;
 
 	smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION,
 					&format, sizeof(format), 0);
 	if(!smem_status)
 	{
-		if (format == 5)
-		{
-			board_info_len = sizeof(board_info_v5);
-
-			smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION,
-							&board_info_v5, board_info_len);
-			if(!smem_status)
-			{
-				id = board_info_v5.board_info_v3.hw_platform;
-			}
-		}
-		else if (format == 6)
+		if (format == 6)
 		{
 			board_info_len = sizeof(board_info_v6);
 
@@ -118,17 +114,20 @@
 		}
 	}
 
-	/* Detect virtio vs rumi */
+	/* Detect the board we are running on */
 	switch(id)
 	{
 		case HW_PLATFORM_SURF:
-			mach_id = LINUX_MACHTYPE_8960_RUMI3;
+			mach_id = LINUX_MACHTYPE_8960_CDP;
 			break;
 		case HW_PLATFORM_FFA:
-			mach_id = LINUX_MACHTYPE_8960_SIM;
+			mach_id = LINUX_MACHTYPE_8960_MTP;
+			break;
+		case HW_PLATFORM_FLUID:
+			mach_id = LINUX_MACHTYPE_8960_FLUID;
 			break;
 		default:
-			mach_id = LINUX_MACHTYPE_8960_SIM;
+			mach_id = LINUX_MACHTYPE_8960_CDP;
 	};
 
 	return mach_id;
@@ -177,3 +176,10 @@
 void target_battery_charging_enable(unsigned enable, unsigned disconnect)
 {
 }
+
+/* Do any target specific intialization needed before entering fastboot mode */
+void target_fastboot_init(void)
+{
+	/* Set the BOOT_DONE flag in PM8921 */
+	pm8921_boot_done();
+}
diff --git a/target/msm8960/rules.mk b/target/msm8960/rules.mk
index bfab671..9ffd5af 100644
--- a/target/msm8960/rules.mk
+++ b/target/msm8960/rules.mk
@@ -24,6 +24,7 @@
 
 MODULES += \
 	dev/keys \
+	dev/pmic/pm8921 \
 	lib/ptable
 
 DEFINES += \