blob: 9d04aea2a8ebff4ea82cf3d83463159b3adf44a2 [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
Marek Vasut61412722014-09-08 14:08:45 +020011static struct socfpga_system_manager *sysmgr_regs =
12 (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
13
Chin Liang See70fa4e72013-09-11 11:24:48 -050014/*
Marek Vasutefd16d02014-09-08 14:08:45 +020015 * Populate the value for SYSMGR.FPGAINTF.MODULE based on pinmux setting.
16 * The value is not wrote to SYSMGR.FPGAINTF.MODULE but
17 * CONFIG_SYSMGR_ISWGRP_HANDOFF.
18 */
19static void populate_sysmgr_fpgaintf_module(void)
20{
Ley Foon Tand5c5e3b2017-04-26 02:44:35 +080021 u32 handoff_val = 0;
Marek Vasutefd16d02014-09-08 14:08:45 +020022
23 /* ISWGRP_HANDOFF_FPGAINTF */
24 writel(0, &sysmgr_regs->iswgrp_handoff[2]);
25
26 /* Enable the signal for those HPS peripherals that use FPGA. */
27 if (readl(&sysmgr_regs->nandusefpga) == SYSMGR_FPGAINTF_USEFPGA)
28 handoff_val |= SYSMGR_FPGAINTF_NAND;
29 if (readl(&sysmgr_regs->rgmii1usefpga) == SYSMGR_FPGAINTF_USEFPGA)
30 handoff_val |= SYSMGR_FPGAINTF_EMAC1;
31 if (readl(&sysmgr_regs->sdmmcusefpga) == SYSMGR_FPGAINTF_USEFPGA)
32 handoff_val |= SYSMGR_FPGAINTF_SDMMC;
33 if (readl(&sysmgr_regs->rgmii0usefpga) == SYSMGR_FPGAINTF_USEFPGA)
34 handoff_val |= SYSMGR_FPGAINTF_EMAC0;
35 if (readl(&sysmgr_regs->spim0usefpga) == SYSMGR_FPGAINTF_USEFPGA)
36 handoff_val |= SYSMGR_FPGAINTF_SPIM0;
37 if (readl(&sysmgr_regs->spim1usefpga) == SYSMGR_FPGAINTF_USEFPGA)
38 handoff_val |= SYSMGR_FPGAINTF_SPIM1;
39
40 /* populate (not writing) the value for SYSMGR.FPGAINTF.MODULE
41 based on pinmux setting */
42 setbits_le32(&sysmgr_regs->iswgrp_handoff[2], handoff_val);
43
44 handoff_val = readl(&sysmgr_regs->iswgrp_handoff[2]);
45 if (fpgamgr_test_fpga_ready()) {
46 /* Enable the required signals only */
47 writel(handoff_val, &sysmgr_regs->fpgaintfgrp_module);
48 }
49}
50
51/*
Chin Liang See70fa4e72013-09-11 11:24:48 -050052 * Configure all the pin muxes
53 */
54void sysmgr_pinmux_init(void)
55{
Ley Foon Tand5c5e3b2017-04-26 02:44:35 +080056 u32 regs = (u32)&sysmgr_regs->emacio[0];
Marek Vasut7b648732015-08-10 22:17:46 +020057 const u8 *sys_mgr_init_table;
Marek Vasut1100e342015-07-25 11:09:11 +020058 unsigned int len;
Marek Vasut61412722014-09-08 14:08:45 +020059 int i;
Chin Liang See70fa4e72013-09-11 11:24:48 -050060
Marek Vasut1100e342015-07-25 11:09:11 +020061 sysmgr_get_pinmux_table(&sys_mgr_init_table, &len);
62
63 for (i = 0; i < len; i++) {
Marek Vasut61412722014-09-08 14:08:45 +020064 writel(sys_mgr_init_table[i], regs);
65 regs += sizeof(regs);
Chin Liang See70fa4e72013-09-11 11:24:48 -050066 }
Marek Vasutefd16d02014-09-08 14:08:45 +020067
68 populate_sysmgr_fpgaintf_module();
Chin Liang See70fa4e72013-09-11 11:24:48 -050069}
Dinh Nguyen95a2fd32015-03-30 17:01:07 -050070
71/*
72 * This bit allows the bootrom to configure the IOs after a warm reset.
73 */
Marek Vasut8306b1e2015-07-09 04:40:11 +020074void sysmgr_config_warmrstcfgio(int enable)
Dinh Nguyen95a2fd32015-03-30 17:01:07 -050075{
Marek Vasut8306b1e2015-07-09 04:40:11 +020076 if (enable)
77 setbits_le32(&sysmgr_regs->romcodegrp_ctrl,
78 SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
79 else
80 clrbits_le32(&sysmgr_regs->romcodegrp_ctrl,
81 SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
Dinh Nguyen95a2fd32015-03-30 17:01:07 -050082}