blob: c377d1c32c79eb43bc8af59d9610f4a20bbd64bb [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Chin Liang See70fa4e72013-09-11 11:24:48 -05002/*
Ley Foon Tand5c5e3b2017-04-26 02:44:35 +08003 * Copyright (C) 2013-2017 Altera Corporation <www.altera.com>
Chin Liang See70fa4e72013-09-11 11:24:48 -05004 */
5
Chin Liang See70fa4e72013-09-11 11:24:48 -05006#include <asm/io.h>
7#include <asm/arch/system_manager.h>
Marek Vasut61412722014-09-08 14:08:45 +02008#include <asm/arch/fpga_manager.h>
Chin Liang See70fa4e72013-09-11 11:24:48 -05009
Chin Liang See70fa4e72013-09-11 11:24:48 -050010/*
Marek Vasutefd16d02014-09-08 14:08:45 +020011 * Populate the value for SYSMGR.FPGAINTF.MODULE based on pinmux setting.
12 * The value is not wrote to SYSMGR.FPGAINTF.MODULE but
13 * CONFIG_SYSMGR_ISWGRP_HANDOFF.
14 */
15static void populate_sysmgr_fpgaintf_module(void)
16{
Ley Foon Tand5c5e3b2017-04-26 02:44:35 +080017 u32 handoff_val = 0;
Marek Vasutefd16d02014-09-08 14:08:45 +020018
19 /* ISWGRP_HANDOFF_FPGAINTF */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080020 writel(0, socfpga_get_sysmgr_addr() + SYSMGR_ISWGRP_HANDOFF_OFFSET(2));
Marek Vasutefd16d02014-09-08 14:08:45 +020021
22 /* Enable the signal for those HPS peripherals that use FPGA. */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080023 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_NAND_USEFPGA) ==
24 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020025 handoff_val |= SYSMGR_FPGAINTF_NAND;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080026 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_RGMII1_USEFPGA) ==
27 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020028 handoff_val |= SYSMGR_FPGAINTF_EMAC1;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080029 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_SDMMC_USEFPGA) ==
30 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020031 handoff_val |= SYSMGR_FPGAINTF_SDMMC;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080032 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_RGMII0_USEFPGA) ==
33 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020034 handoff_val |= SYSMGR_FPGAINTF_EMAC0;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080035 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_SPIM0_USEFPGA) ==
36 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020037 handoff_val |= SYSMGR_FPGAINTF_SPIM0;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080038 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_SPIM1_USEFPGA) ==
39 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020040 handoff_val |= SYSMGR_FPGAINTF_SPIM1;
41
42 /* populate (not writing) the value for SYSMGR.FPGAINTF.MODULE
43 based on pinmux setting */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080044 setbits_le32(socfpga_get_sysmgr_addr() +
45 SYSMGR_ISWGRP_HANDOFF_OFFSET(2),
46 handoff_val);
Marek Vasutefd16d02014-09-08 14:08:45 +020047
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080048 handoff_val = readl(socfpga_get_sysmgr_addr() +
49 SYSMGR_ISWGRP_HANDOFF_OFFSET(2));
Marek Vasutefd16d02014-09-08 14:08:45 +020050 if (fpgamgr_test_fpga_ready()) {
51 /* Enable the required signals only */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080052 writel(handoff_val,
53 socfpga_get_sysmgr_addr() +
54 SYSMGR_GEN5_FPGAINFGRP_MODULE);
Marek Vasutefd16d02014-09-08 14:08:45 +020055 }
56}
57
58/*
Chin Liang See70fa4e72013-09-11 11:24:48 -050059 * Configure all the pin muxes
60 */
61void sysmgr_pinmux_init(void)
62{
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080063 u32 regs = (u32)socfpga_get_sysmgr_addr() + SYSMGR_GEN5_EMACIO;
Marek Vasut7b648732015-08-10 22:17:46 +020064 const u8 *sys_mgr_init_table;
Marek Vasut1100e342015-07-25 11:09:11 +020065 unsigned int len;
Marek Vasut61412722014-09-08 14:08:45 +020066 int i;
Chin Liang See70fa4e72013-09-11 11:24:48 -050067
Marek Vasut1100e342015-07-25 11:09:11 +020068 sysmgr_get_pinmux_table(&sys_mgr_init_table, &len);
69
70 for (i = 0; i < len; i++) {
Marek Vasut61412722014-09-08 14:08:45 +020071 writel(sys_mgr_init_table[i], regs);
72 regs += sizeof(regs);
Chin Liang See70fa4e72013-09-11 11:24:48 -050073 }
Marek Vasutefd16d02014-09-08 14:08:45 +020074
75 populate_sysmgr_fpgaintf_module();
Chin Liang See70fa4e72013-09-11 11:24:48 -050076}
Dinh Nguyen95a2fd32015-03-30 17:01:07 -050077
78/*
79 * This bit allows the bootrom to configure the IOs after a warm reset.
80 */
Marek Vasut8306b1e2015-07-09 04:40:11 +020081void sysmgr_config_warmrstcfgio(int enable)
Dinh Nguyen95a2fd32015-03-30 17:01:07 -050082{
Marek Vasut8306b1e2015-07-09 04:40:11 +020083 if (enable)
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080084 setbits_le32(socfpga_get_sysmgr_addr() +
85 SYSMGR_GEN5_ROMCODEGRP_CTRL,
Marek Vasut8306b1e2015-07-09 04:40:11 +020086 SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
87 else
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080088 clrbits_le32(socfpga_get_sysmgr_addr() +
89 SYSMGR_GEN5_ROMCODEGRP_CTRL,
Marek Vasut8306b1e2015-07-09 04:40:11 +020090 SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
Dinh Nguyen95a2fd32015-03-30 17:01:07 -050091}