blob: 09caebb3c882a4cdd0bea9457a9564b6a16e84df [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
6#include <common.h>
7#include <asm/io.h>
8#include <asm/arch/system_manager.h>
Marek Vasut61412722014-09-08 14:08:45 +02009#include <asm/arch/fpga_manager.h>
Chin Liang See70fa4e72013-09-11 11:24:48 -050010
Chin Liang See70fa4e72013-09-11 11:24:48 -050011/*
Marek Vasutefd16d02014-09-08 14:08:45 +020012 * Populate the value for SYSMGR.FPGAINTF.MODULE based on pinmux setting.
13 * The value is not wrote to SYSMGR.FPGAINTF.MODULE but
14 * CONFIG_SYSMGR_ISWGRP_HANDOFF.
15 */
16static void populate_sysmgr_fpgaintf_module(void)
17{
Ley Foon Tand5c5e3b2017-04-26 02:44:35 +080018 u32 handoff_val = 0;
Marek Vasutefd16d02014-09-08 14:08:45 +020019
20 /* ISWGRP_HANDOFF_FPGAINTF */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080021 writel(0, socfpga_get_sysmgr_addr() + SYSMGR_ISWGRP_HANDOFF_OFFSET(2));
Marek Vasutefd16d02014-09-08 14:08:45 +020022
23 /* Enable the signal for those HPS peripherals that use FPGA. */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080024 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_NAND_USEFPGA) ==
25 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020026 handoff_val |= SYSMGR_FPGAINTF_NAND;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080027 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_RGMII1_USEFPGA) ==
28 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020029 handoff_val |= SYSMGR_FPGAINTF_EMAC1;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080030 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_SDMMC_USEFPGA) ==
31 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020032 handoff_val |= SYSMGR_FPGAINTF_SDMMC;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080033 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_RGMII0_USEFPGA) ==
34 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020035 handoff_val |= SYSMGR_FPGAINTF_EMAC0;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080036 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_SPIM0_USEFPGA) ==
37 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020038 handoff_val |= SYSMGR_FPGAINTF_SPIM0;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080039 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_SPIM1_USEFPGA) ==
40 SYSMGR_FPGAINTF_USEFPGA)
Marek Vasutefd16d02014-09-08 14:08:45 +020041 handoff_val |= SYSMGR_FPGAINTF_SPIM1;
42
43 /* populate (not writing) the value for SYSMGR.FPGAINTF.MODULE
44 based on pinmux setting */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080045 setbits_le32(socfpga_get_sysmgr_addr() +
46 SYSMGR_ISWGRP_HANDOFF_OFFSET(2),
47 handoff_val);
Marek Vasutefd16d02014-09-08 14:08:45 +020048
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080049 handoff_val = readl(socfpga_get_sysmgr_addr() +
50 SYSMGR_ISWGRP_HANDOFF_OFFSET(2));
Marek Vasutefd16d02014-09-08 14:08:45 +020051 if (fpgamgr_test_fpga_ready()) {
52 /* Enable the required signals only */
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080053 writel(handoff_val,
54 socfpga_get_sysmgr_addr() +
55 SYSMGR_GEN5_FPGAINFGRP_MODULE);
Marek Vasutefd16d02014-09-08 14:08:45 +020056 }
57}
58
59/*
Chin Liang See70fa4e72013-09-11 11:24:48 -050060 * Configure all the pin muxes
61 */
62void sysmgr_pinmux_init(void)
63{
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080064 u32 regs = (u32)socfpga_get_sysmgr_addr() + SYSMGR_GEN5_EMACIO;
Marek Vasut7b648732015-08-10 22:17:46 +020065 const u8 *sys_mgr_init_table;
Marek Vasut1100e342015-07-25 11:09:11 +020066 unsigned int len;
Marek Vasut61412722014-09-08 14:08:45 +020067 int i;
Chin Liang See70fa4e72013-09-11 11:24:48 -050068
Marek Vasut1100e342015-07-25 11:09:11 +020069 sysmgr_get_pinmux_table(&sys_mgr_init_table, &len);
70
71 for (i = 0; i < len; i++) {
Marek Vasut61412722014-09-08 14:08:45 +020072 writel(sys_mgr_init_table[i], regs);
73 regs += sizeof(regs);
Chin Liang See70fa4e72013-09-11 11:24:48 -050074 }
Marek Vasutefd16d02014-09-08 14:08:45 +020075
76 populate_sysmgr_fpgaintf_module();
Chin Liang See70fa4e72013-09-11 11:24:48 -050077}
Dinh Nguyen95a2fd32015-03-30 17:01:07 -050078
79/*
80 * This bit allows the bootrom to configure the IOs after a warm reset.
81 */
Marek Vasut8306b1e2015-07-09 04:40:11 +020082void sysmgr_config_warmrstcfgio(int enable)
Dinh Nguyen95a2fd32015-03-30 17:01:07 -050083{
Marek Vasut8306b1e2015-07-09 04:40:11 +020084 if (enable)
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080085 setbits_le32(socfpga_get_sysmgr_addr() +
86 SYSMGR_GEN5_ROMCODEGRP_CTRL,
Marek Vasut8306b1e2015-07-09 04:40:11 +020087 SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
88 else
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080089 clrbits_le32(socfpga_get_sysmgr_addr() +
90 SYSMGR_GEN5_ROMCODEGRP_CTRL,
Marek Vasut8306b1e2015-07-09 04:40:11 +020091 SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
Dinh Nguyen95a2fd32015-03-30 17:01:07 -050092}