qca: ipq40xx: Enabled full boot chain for eMMC

Change-Id: I5e795ff87d2c7a28ef5bd6cf2bbaabdc26cd48e7
Signed-off-by: Gowtham Siddarth Dhandapani <gdhandap@codeaurora.org>
diff --git a/arch/arm/cpu/armv7/qca/common/cmd_bootqca.c b/arch/arm/cpu/armv7/qca/common/cmd_bootqca.c
index 7ac89c0..2145131 100644
--- a/arch/arm/cpu/armv7/qca/common/cmd_bootqca.c
+++ b/arch/arm/cpu/armv7/qca/common/cmd_bootqca.c
@@ -21,6 +21,7 @@
 #include <linux/mtd/ubi.h>
 #include <asm/arch-qcom-common/smem.h>
 #include <mmc.h>
+#include <part_efi.h>
 
 #define DLOAD_MAGIC_COOKIE0x10
 #define XMK_STR(x)#x
@@ -301,15 +302,18 @@
 		if (smem_bootconfig_info() == 0) {
 			active_part = get_rootfs_active_partition();
 			if (active_part) {
-				ret = find_part_efi(blk_dev, "0:HLOS_1", &disk_info);
+				ret = get_partition_info_efi_by_name(blk_dev,
+						"0:HLOS_1", &disk_info);
 			} else {
-				ret = find_part_efi(blk_dev, "0:HLOS", &disk_info);
+				ret = get_partition_info_efi_by_name(blk_dev,
+						"0:HLOS", &disk_info);
 			}
 		} else {
-			ret = find_part_efi(blk_dev, "0:HLOS", &disk_info);
+			ret = get_partition_info_efi_by_name(blk_dev,
+						"0:HLOS", &disk_info);
 		}
 
-		if (ret > 0) {
+		if (ret == 0) {
 			snprintf(runcmd, sizeof(runcmd), "mmc read 0x%x 0x%X 0x%X",
 				 CONFIG_SYS_LOAD_ADDR,
 				 (uint)disk_info.start, (uint)disk_info.size);
@@ -484,15 +488,18 @@
 		if (smem_bootconfig_info() == 0) {
 			active_part = get_rootfs_active_partition();
 			if (active_part) {
-				ret = find_part_efi(blk_dev, "0:HLOS_1", &disk_info);
+				ret = get_partition_info_efi_by_name(blk_dev,
+						"0:HLOS_1", &disk_info);
 			} else {
-				ret = find_part_efi(blk_dev, "0:HLOS", &disk_info);
+				ret = get_partition_info_efi_by_name(blk_dev,
+						"0:HLOS", &disk_info);
 			}
 		} else {
-			ret = find_part_efi(blk_dev, "0:HLOS", &disk_info);
+			ret = get_partition_info_efi_by_name(blk_dev,
+						"0:HLOS", &disk_info);
 		}
 
-		if (ret > 0) {
+		if (ret == 0) {
 			snprintf(runcmd, sizeof(runcmd), "mmc read 0x%x 0x%x 0x%x",
 				 CONFIG_SYS_LOAD_ADDR,
 				 (uint)disk_info.start, (uint)disk_info.size);
diff --git a/arch/arm/include/asm/arch-qcom-common/qca_common.h b/arch/arm/include/asm/arch-qcom-common/qca_common.h
new file mode 100644
index 0000000..dd36f5a
--- /dev/null
+++ b/arch/arm/include/asm/arch-qcom-common/qca_common.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
+
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef ___QCA_COMMON_H_
+#define ___QCA_COMMON_H_
+#include <asm/u-boot.h>
+
+typedef struct {
+	uint base;
+	uint clk_mode;
+	struct mmc *mmc;
+	int dev_num;
+} qca_mmc;
+
+int qca_mmc_init(bd_t *, qca_mmc *);
+void board_mmc_deinit(void);
+
+#define MSM_SDC1_BASE		0x7824000
+#define MMC_IDENTIFY_MODE	0
+#define MMC_DATA_TRANSFER_MODE	1
+#define MMC_MODE_HC		0x800
+
+#endif  /*  __QCA_COMMON_H_ */
diff --git a/board/qca/ipq40xx/ipq40xx.c b/board/qca/ipq40xx/ipq40xx.c
index 8968ffa..b3f9d51 100644
--- a/board/qca/ipq40xx/ipq40xx.c
+++ b/board/qca/ipq40xx/ipq40xx.c
@@ -29,6 +29,8 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+qca_mmc mmc_host;
+
 loff_t board_env_offset;
 loff_t board_env_range;
 loff_t board_env_size;
@@ -44,6 +46,12 @@
 extern int ipq_spi_init(u16);
 extern int fdt_node_set_part_info(void *blob, int parent_offset,
 				  struct mtd_device *dev);
+extern int mmc_env_init(void);
+extern void mmc_env_relocate_spec(void);
+extern int mmc_saveenv(void);
+extern env_t *mmc_env_ptr;
+extern char *mmc_env_name_spec;
+
 /*
  * Don't have this as a '.bss' variable. The '.bss' and '.rel.dyn'
  * sections seem to overlap.
@@ -650,9 +658,10 @@
 		}
 	}
 	blk_dev = mmc_get_dev(mmc_host.dev_num);
-	ret = find_part_efi(blk_dev, "0:APPSBLENV", &disk_info);
+	ret = get_partition_info_efi_by_name(blk_dev,
+				"0:APPSBLENV", &disk_info);
 
-	if (ret > 0) {
+	if (ret == 0) {
 		board_env_offset = disk_info.start * disk_info.blksz;
 		board_env_size = disk_info.size * disk_info.blksz;
 		board_env_range = board_env_size;
diff --git a/board/qca/ipq40xx/ipq40xx.h b/board/qca/ipq40xx/ipq40xx.h
index 2de77f1..2f38a54 100644
--- a/board/qca/ipq40xx/ipq40xx.h
+++ b/board/qca/ipq40xx/ipq40xx.h
@@ -16,6 +16,7 @@
 
 #include <configs/ipq40xx.h>
 #include <asm/arch-qcom-common/gpio.h>
+#include <asm/arch-qcom-common/qca_common.h>
 #include <asm/u-boot.h>
 #include <phy.h>
 
@@ -26,6 +27,7 @@
 #define MAX_CONF_NAME		5
 
 unsigned int smem_get_board_machtype(void);
+extern qca_mmc mmc_host;
 
 #define IPQ40XX_EDMA_DEV	1
 typedef struct {
diff --git a/board/qca/ipq40xx/ipq40xx_board_param.h b/board/qca/ipq40xx/ipq40xx_board_param.h
index 28a97eb..083273d 100644
--- a/board/qca/ipq40xx/ipq40xx_board_param.h
+++ b/board/qca/ipq40xx/ipq40xx_board_param.h
@@ -1003,8 +1003,8 @@
 #ifdef CONFIG_IPQ40XX_I2C
 		.i2c_cfg = &i2c0,
 #endif
-		//.mmc_gpio = mmc_ap_dk04,
-		//.mmc_gpio_count = ARRAY_SIZE(mmc_ap_dk04),
+		.mmc_gpio = mmc_ap_dk04,
+		.mmc_gpio_count = ARRAY_SIZE(mmc_ap_dk04),
 		.spi_nand_available = 0,
 		.nor_nand_available = 0,
 		.nor_emmc_available = 0,
@@ -1035,8 +1035,8 @@
 #ifdef CONFIG_IPQ40XX_I2C
 		.i2c_cfg = &i2c0,
 #endif
-		//.mmc_gpio = mmc_ap_dk04,
-		//.mmc_gpio_count = ARRAY_SIZE(mmc_ap_dk04),
+		.mmc_gpio = mmc_ap_dk04,
+		.mmc_gpio_count = ARRAY_SIZE(mmc_ap_dk04),
 		.spi_nand_available = 0,
 		.nor_nand_available = 0,
 		.nor_emmc_available = 0,
@@ -1065,8 +1065,8 @@
 					0, 1, 2, 3, 4)
 		},
 #endif
-		//.mmc_gpio = mmc_ap_dk04,
-		//.mmc_gpio_count = ARRAY_SIZE(mmc_ap_dk04),
+		.mmc_gpio = mmc_ap_dk04,
+		.mmc_gpio_count = ARRAY_SIZE(mmc_ap_dk04),
 		.spi_nand_available = 0,
 		.nor_nand_available = 0,
 		.nor_emmc_available = 0,
@@ -1088,8 +1088,8 @@
 					0, 1, 2, 3, 4)
 		},
 #endif
-		//.mmc_gpio = mmc_ap_dk04,
-		//.mmc_gpio_count = ARRAY_SIZE(mmc_ap_dk04),
+		.mmc_gpio = mmc_ap_dk04,
+		.mmc_gpio_count = ARRAY_SIZE(mmc_ap_dk04),
 		.spi_nand_available = 0,
 		.nor_nand_available = 0,
 		.nor_emmc_available = 1,
diff --git a/board/qca/ipq807x/ipq807x.c b/board/qca/ipq807x/ipq807x.c
index a476abd..3b0bec8 100644
--- a/board/qca/ipq807x/ipq807x.c
+++ b/board/qca/ipq807x/ipq807x.c
@@ -17,7 +17,7 @@
 #include <environment.h>
 
 #include "ipq807x.h"
-#include "../common/qca_common.h"
+#include <asm/arch-qcom-common/qca_common.h>
 #include <asm/arch-qcom-common/qpic_nand.h>
 #include <fdtdec.h>
 
diff --git a/common/env_mmc.c b/common/env_mmc.c
index 9639822..17f6d67 100644
--- a/common/env_mmc.c
+++ b/common/env_mmc.c
@@ -22,12 +22,12 @@
 #error CONFIG_ENV_SIZE_REDUND should be the same as CONFIG_ENV_SIZE
 #endif
 
-char *env_name_spec = "MMC";
+char *mmc_env_name_spec = "MMC";
 
 #ifdef ENV_IS_EMBEDDED
-env_t *env_ptr = &environment;
+env_t *mmc_env_ptr = &environment;
 #else /* ! ENV_IS_EMBEDDED */
-env_t *env_ptr;
+env_t *mmc_env_ptr;
 #endif /* ENV_IS_EMBEDDED */
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -54,7 +54,7 @@
 	return 0;
 }
 
-int env_init(void)
+int mmc_env_init(void)
 {
 	/* use default */
 	gd->env_addr	= (ulong)&default_environment[0];
@@ -137,7 +137,7 @@
 static unsigned char env_flags;
 #endif
 
-int saveenv(void)
+int mmc_saveenv(void)
 {
 	ALLOC_CACHE_ALIGN_BUFFER(env_t, env_new, 1);
 	struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV);
@@ -207,7 +207,7 @@
 }
 
 #ifdef CONFIG_ENV_OFFSET_REDUND
-void env_relocate_spec(void)
+void mmc_env_relocate_spec(void)
 {
 #if !defined(ENV_IS_EMBEDDED)
 	struct mmc *mmc;
@@ -295,7 +295,7 @@
 #endif
 }
 #else /* ! CONFIG_ENV_OFFSET_REDUND */
-void env_relocate_spec(void)
+void mmc_env_relocate_spec(void)
 {
 #if !defined(ENV_IS_EMBEDDED)
 	ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
diff --git a/include/configs/ipq40xx.h b/include/configs/ipq40xx.h
index c3f5255..80c5302 100644
--- a/include/configs/ipq40xx.h
+++ b/include/configs/ipq40xx.h
@@ -213,4 +213,18 @@
 
 #define CONFIG_BOOTDELAY	2
 
+#define CONFIG_LIB_UUID
+
+#define CONFIG_QCA_MMC  1
+
+#ifdef CONFIG_QCA_MMC
+#define CONFIG_MMC
+#define CONFIG_ENV_IS_IN_MMC
+#define CONFIG_CMD_MMC
+#define CONFIG_SDHCI_QCOM
+#define CONFIG_GENERIC_MMC
+#define CONFIG_EFI_PARTITION
+#define CONFIG_SYS_MMC_ENV_DEV  0
+#endif
+
 #endif /* _IPQ40XX_H */