Merge branch 'master' of git://git.denx.de/u-boot-spi
[platform/kernel/u-boot.git] / arch / arm / mach-socfpga / misc_gen5.c
index a7dcacc..5fa4093 100644 (file)
@@ -1,14 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  *  Copyright (C) 2012-2017 Altera Corporation <www.altera.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/io.h>
 #include <errno.h>
 #include <fdtdec.h>
-#include <libfdt.h>
+#include <linux/libfdt.h>
 #include <altera.h>
 #include <miiphy.h>
 #include <netdev.h>
@@ -39,8 +38,7 @@ static struct scu_registers *scu_regs =
  * DesignWare Ethernet initialization
  */
 #ifdef CONFIG_ETH_DESIGNWARE
-void dwmac_deassert_reset(const unsigned int of_reset_id,
-                                const u32 phymode)
+static void gen5_dwmac_reset(const u8 of_reset_id, const u8 phymode)
 {
        u32 physhift, reset;
 
@@ -64,71 +62,13 @@ void dwmac_deassert_reset(const unsigned int of_reset_id,
        socfpga_per_reset(reset, 0);
 }
 
-static u32 dwmac_phymode_to_modereg(const char *phymode, u32 *modereg)
-{
-       if (!phymode)
-               return -EINVAL;
-
-       if (!strcmp(phymode, "mii") || !strcmp(phymode, "gmii")) {
-               *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
-               return 0;
-       }
-
-       if (!strcmp(phymode, "rgmii")) {
-               *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII;
-               return 0;
-       }
-
-       if (!strcmp(phymode, "rmii")) {
-               *modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII;
-               return 0;
-       }
-
-       return -EINVAL;
-}
-
 static int socfpga_eth_reset(void)
 {
-       const void *fdt = gd->fdt_blob;
-       struct fdtdec_phandle_args args;
-       const char *phy_mode;
-       u32 phy_modereg;
-       int nodes[2];   /* Max. two GMACs */
-       int ret, count;
-       int i, node;
-
-       /* Put both GMACs into RESET state. */
+       /* Put all GMACs into RESET state. */
        socfpga_per_reset(SOCFPGA_RESET(EMAC0), 1);
        socfpga_per_reset(SOCFPGA_RESET(EMAC1), 1);
-
-       count = fdtdec_find_aliases_for_id(fdt, "ethernet",
-                                          COMPAT_ALTERA_SOCFPGA_DWMAC,
-                                          nodes, ARRAY_SIZE(nodes));
-       for (i = 0; i < count; i++) {
-               node = nodes[i];
-               if (node <= 0)
-                       continue;
-
-               ret = fdtdec_parse_phandle_with_args(fdt, node, "resets",
-                                                    "#reset-cells", 1, 0,
-                                                    &args);
-               if (ret || (args.args_count != 1)) {
-                       debug("GMAC%i: Failed to parse DT 'resets'!\n", i);
-                       continue;
-               }
-
-               phy_mode = fdt_getprop(fdt, node, "phy-mode", NULL);
-               ret = dwmac_phymode_to_modereg(phy_mode, &phy_modereg);
-               if (ret) {
-                       debug("GMAC%i: Failed to parse DT 'phy-mode'!\n", i);
-                       continue;
-               }
-
-               dwmac_deassert_reset(args.args[0], phy_modereg);
-       }
-
-       return 0;
-}
+       return socfpga_eth_reset_common(gen5_dwmac_reset);
+};
 #else
 static int socfpga_eth_reset(void)
 {
@@ -235,6 +175,29 @@ static void socfpga_nic301_slave_ns(void)
        writel(0x1, &nic301_regs->sdrdata);
 }
 
+void socfpga_sdram_remap_zero(void)
+{
+       u32 remap;
+
+       socfpga_nic301_slave_ns();
+
+       /*
+        * Private components security:
+        * U-Boot : configure private timer, global timer and cpu component
+        * access as non secure for kernel stage (as required by Linux)
+        */
+       setbits_le32(&scu_regs->sacr, 0xfff);
+
+       /* Configure the L2 controller to make SDRAM start at 0 */
+       remap = 0x1; /* remap.mpuzero */
+       /* Keep fpga bridge enabled when running from FPGA onchip RAM */
+       if (socfpga_is_booting_from_fpga())
+               remap |= 0x8; /* remap.hps2fpga */
+       writel(remap, &nic301_regs->remap);
+
+       writel(0x1, &pl310->pl310_addr_filter_start);
+}
+
 static u32 iswgrp_handoff[8];
 
 int arch_early_init_r(void)
@@ -255,22 +218,7 @@ int arch_early_init_r(void)
 
        socfpga_bridges_reset(1);
 
-       socfpga_nic301_slave_ns();
-
-       /*
-        * Private components security:
-        * U-Boot : configure private timer, global timer and cpu component
-        * access as non secure for kernel stage (as required by Linux)
-        */
-       setbits_le32(&scu_regs->sacr, 0xfff);
-
-       /* Configure the L2 controller to make SDRAM start at 0 */
-#ifdef CONFIG_SOCFPGA_VIRTUAL_TARGET
-       writel(0x2, &nic301_regs->remap);
-#else
-       writel(0x1, &nic301_regs->remap);       /* remap.mpuzero */
-       writel(0x1, &pl310->pl310_addr_filter_start);
-#endif
+       socfpga_sdram_remap_zero();
 
        /* Add device descriptor to FPGA device table */
        socfpga_fpga_add();
@@ -323,40 +271,20 @@ static void socfpga_sdram_apply_static_cfg(void)
        : : "r"(val), "r"(&sdr_ctrl->static_cfg) : "memory", "cc");
 }
 
-static int do_bridge(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+void do_bridge_reset(int enable)
 {
-       if (argc != 2)
-               return CMD_RET_USAGE;
-
-       argv++;
-
-       switch (*argv[0]) {
-       case 'e':       /* Enable */
+       if (enable) {
                writel(iswgrp_handoff[2], &sysmgr_regs->fpgaintfgrp_module);
                socfpga_sdram_apply_static_cfg();
                writel(iswgrp_handoff[3], &sdr_ctrl->fpgaport_rst);
                writel(iswgrp_handoff[0], &reset_manager_base->brg_mod_reset);
                writel(iswgrp_handoff[1], &nic301_regs->remap);
-               break;
-       case 'd':       /* Disable */
+       } else {
                writel(0, &sysmgr_regs->fpgaintfgrp_module);
                writel(0, &sdr_ctrl->fpgaport_rst);
                socfpga_sdram_apply_static_cfg();
                writel(0, &reset_manager_base->brg_mod_reset);
                writel(1, &nic301_regs->remap);
-               break;
-       default:
-               return CMD_RET_USAGE;
        }
-
-       return 0;
 }
-
-U_BOOT_CMD(
-       bridge, 2, 1, do_bridge,
-       "SoCFPGA HPS FPGA bridge control",
-       "enable  - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
-       "bridge disable - Enable HPS-to-FPGA, FPGA-to-HPS, LWHPS-to-FPGA bridges\n"
-       ""
-);
 #endif