ipq807x: Fixed the AQ phy reset

Removing the delay for boot time.

Change-Id: Iab968986d58aa5bc930b7c03bb16f5b1041be3b1
Signed-off-by: Sham Muthayyan <smuthayy@codeaurora.org>
diff --git a/board/qca/arm/common/board_init.c b/board/qca/arm/common/board_init.c
index 9f032d2..fbd7970 100644
--- a/board/qca/arm/common/board_init.c
+++ b/board/qca/arm/common/board_init.c
@@ -157,6 +157,8 @@
 		printf("WARN: ipq_board_usb_init failed\n");
 	}
 
+	aquantia_phy_reset_init();
+
 	return 0;
 }
 
diff --git a/board/qca/arm/common/cmd_bootqca.c b/board/qca/arm/common/cmd_bootqca.c
index b5ea739..94669a5 100644
--- a/board/qca/arm/common/cmd_bootqca.c
+++ b/board/qca/arm/common/cmd_bootqca.c
@@ -781,7 +781,8 @@
 
 	ret = qca_scm_call(SCM_SVC_FUSE, QFPROM_IS_AUTHENTICATE_CMD, &buf, sizeof(char));
 
-	aquantia_phy_reset();
+	aquantia_phy_reset_init_done();
+
 	if (ret == 0 && buf == 1) {
 		ret = do_boot_signedimg(cmdtp, flag, argc, argv);
 	} else if (ret == 0 || ret == -EOPNOTSUPP) {
diff --git a/board/qca/arm/ipq807x/ipq807x.c b/board/qca/arm/ipq807x/ipq807x.c
index 83a0ab9..1d95cef 100644
--- a/board/qca/arm/ipq807x/ipq807x.c
+++ b/board/qca/arm/ipq807x/ipq807x.c
@@ -288,7 +288,20 @@
 	writel(readl(MSM_SDC1_MCI_HC_MODE) | (0x1), MSM_SDC1_MCI_HC_MODE);
 }
 
-void aquantia_phy_reset(void)
+int get_aquantia_gpio()
+{
+	int aquantia_gpio = -1, node;
+
+	node = fdt_path_offset(gd->fdt_blob, "/ess-switch");
+	if (node >= 0)
+		aquantia_gpio = fdtdec_get_uint(gd->fdt_blob, node, "aquantia_gpio", -1);
+	else
+		return node;
+
+	return aquantia_gpio;
+}
+
+void aquantia_phy_reset_init(void)
 {
 	int aquantia_gpio = -1, node;
 	unsigned int *aquantia_gpio_base;
@@ -301,14 +314,22 @@
 		if (aquantia_gpio >=0) {
 			aquantia_gpio_base = (unsigned int *)GPIO_CONFIG_ADDR(aquantia_gpio);
 			writel(0x203, aquantia_gpio_base);
-			gpio_set_value(aquantia_gpio, 0x0);
-			mdelay(500);
-			gpio_set_value(aquantia_gpio, 0x1);
-			mdelay(500);
+			gpio_direction_output(aquantia_gpio, 0x0);
 		}
 		aq_phy_initialised = 1;
 	}
 }
+
+void aquantia_phy_reset_init_done(void)
+{
+	int aquantia_gpio;
+
+	aquantia_gpio = get_aquantia_gpio();
+	if (aquantia_gpio >= 0) {
+		gpio_set_value(aquantia_gpio, 0x1);
+	}
+}
+
 void eth_clock_enable(void)
 {
 	int tlmm_base = 0x1025000;
@@ -372,7 +393,10 @@
 	writel(2, tlmm_base + 0x4);
 	writel(7, tlmm_base + 0x1f000);
 	writel(7, tlmm_base + 0x20000);
-	aquantia_phy_reset();
+	aquantia_phy_reset_init();
+	mdelay(500);
+	aquantia_phy_reset_init_done();
+	mdelay(500);
 }
 
 int board_eth_init(bd_t *bis)
diff --git a/drivers/gpio/ipq_gpio.c b/drivers/gpio/ipq_gpio.c
index f5f65d7..2bacd37 100644
--- a/drivers/gpio/ipq_gpio.c
+++ b/drivers/gpio/ipq_gpio.c
@@ -73,6 +73,17 @@
 	return (val & 1);
 }
 
+void gpio_direction_output(unsigned int gpio, unsigned int out)
+{
+	unsigned int *addr = (unsigned int *)GPIO_CONFIG_ADDR(gpio);
+	unsigned int val = 0;
+
+	gpio_set_value(gpio, out);
+	val = readl(addr);
+	val |= 1 << 9;
+	writel(val, addr);
+}
+
 int qca_gpio_init(int offset)
 {
 	struct qca_gpio_config gpio_config;