blob: 75a65f3e62369cec486bf70549a15592b8dcceb6 [file] [log] [blame]
Chin Liang See5d649d22013-09-11 11:24:48 -05001/*
Marek Vasut665e4ca2014-09-08 14:08:45 +02002 * Copyright (C) 2013 Altera Corporation <www.altera.com>
Chin Liang See5d649d22013-09-11 11:24:48 -05003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <asm/arch/system_manager.h>
Marek Vasut665e4ca2014-09-08 14:08:45 +020010#include <asm/arch/fpga_manager.h>
Chin Liang See5d649d22013-09-11 11:24:48 -050011
12DECLARE_GLOBAL_DATA_PTR;
13
Marek Vasut665e4ca2014-09-08 14:08:45 +020014static struct socfpga_system_manager *sysmgr_regs =
15 (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
16
Chin Liang See5d649d22013-09-11 11:24:48 -050017/*
Marek Vasut807abb12014-09-08 14:08:45 +020018 * Populate the value for SYSMGR.FPGAINTF.MODULE based on pinmux setting.
19 * The value is not wrote to SYSMGR.FPGAINTF.MODULE but
20 * CONFIG_SYSMGR_ISWGRP_HANDOFF.
21 */
22static void populate_sysmgr_fpgaintf_module(void)
23{
24 uint32_t handoff_val = 0;
25
26 /* ISWGRP_HANDOFF_FPGAINTF */
27 writel(0, &sysmgr_regs->iswgrp_handoff[2]);
28
29 /* Enable the signal for those HPS peripherals that use FPGA. */
30 if (readl(&sysmgr_regs->nandusefpga) == SYSMGR_FPGAINTF_USEFPGA)
31 handoff_val |= SYSMGR_FPGAINTF_NAND;
32 if (readl(&sysmgr_regs->rgmii1usefpga) == SYSMGR_FPGAINTF_USEFPGA)
33 handoff_val |= SYSMGR_FPGAINTF_EMAC1;
34 if (readl(&sysmgr_regs->sdmmcusefpga) == SYSMGR_FPGAINTF_USEFPGA)
35 handoff_val |= SYSMGR_FPGAINTF_SDMMC;
36 if (readl(&sysmgr_regs->rgmii0usefpga) == SYSMGR_FPGAINTF_USEFPGA)
37 handoff_val |= SYSMGR_FPGAINTF_EMAC0;
38 if (readl(&sysmgr_regs->spim0usefpga) == SYSMGR_FPGAINTF_USEFPGA)
39 handoff_val |= SYSMGR_FPGAINTF_SPIM0;
40 if (readl(&sysmgr_regs->spim1usefpga) == SYSMGR_FPGAINTF_USEFPGA)
41 handoff_val |= SYSMGR_FPGAINTF_SPIM1;
42
43 /* populate (not writing) the value for SYSMGR.FPGAINTF.MODULE
44 based on pinmux setting */
45 setbits_le32(&sysmgr_regs->iswgrp_handoff[2], handoff_val);
46
47 handoff_val = readl(&sysmgr_regs->iswgrp_handoff[2]);
48 if (fpgamgr_test_fpga_ready()) {
49 /* Enable the required signals only */
50 writel(handoff_val, &sysmgr_regs->fpgaintfgrp_module);
51 }
52}
53
54/*
Chin Liang See5d649d22013-09-11 11:24:48 -050055 * Configure all the pin muxes
56 */
57void sysmgr_pinmux_init(void)
58{
Marek Vasut665e4ca2014-09-08 14:08:45 +020059 uint32_t regs = (uint32_t)&sysmgr_regs->emacio[0];
Marek Vasutcc9429a2015-08-10 22:17:46 +020060 const u8 *sys_mgr_init_table;
Marek Vasut2d779b32015-07-25 11:09:11 +020061 unsigned int len;
Marek Vasut665e4ca2014-09-08 14:08:45 +020062 int i;
Chin Liang See5d649d22013-09-11 11:24:48 -050063
Marek Vasut2d779b32015-07-25 11:09:11 +020064 sysmgr_get_pinmux_table(&sys_mgr_init_table, &len);
65
66 for (i = 0; i < len; i++) {
Marek Vasut665e4ca2014-09-08 14:08:45 +020067 writel(sys_mgr_init_table[i], regs);
68 regs += sizeof(regs);
Chin Liang See5d649d22013-09-11 11:24:48 -050069 }
Marek Vasut807abb12014-09-08 14:08:45 +020070
71 populate_sysmgr_fpgaintf_module();
Chin Liang See5d649d22013-09-11 11:24:48 -050072}
Dinh Nguyen08e463e2015-03-30 17:01:07 -050073
74/*
75 * This bit allows the bootrom to configure the IOs after a warm reset.
76 */
Marek Vasut40687b42015-07-09 04:40:11 +020077void sysmgr_config_warmrstcfgio(int enable)
Dinh Nguyen08e463e2015-03-30 17:01:07 -050078{
Marek Vasut40687b42015-07-09 04:40:11 +020079 if (enable)
80 setbits_le32(&sysmgr_regs->romcodegrp_ctrl,
81 SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
82 else
83 clrbits_le32(&sysmgr_regs->romcodegrp_ctrl,
84 SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO);
Dinh Nguyen08e463e2015-03-30 17:01:07 -050085}