Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 1 | /* |
Ley Foon Tan | d5c5e3b | 2017-04-26 02:44:35 +0800 | [diff] [blame] | 2 | * Copyright (C) 2013-2017 Altera Corporation <www.altera.com> |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 3 | * |
| 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 Vasut | 6141272 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 10 | #include <asm/arch/fpga_manager.h> |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 11 | |
Marek Vasut | 6141272 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 12 | static struct socfpga_system_manager *sysmgr_regs = |
| 13 | (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS; |
| 14 | |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 15 | /* |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 16 | * Populate the value for SYSMGR.FPGAINTF.MODULE based on pinmux setting. |
| 17 | * The value is not wrote to SYSMGR.FPGAINTF.MODULE but |
| 18 | * CONFIG_SYSMGR_ISWGRP_HANDOFF. |
| 19 | */ |
| 20 | static void populate_sysmgr_fpgaintf_module(void) |
| 21 | { |
Ley Foon Tan | d5c5e3b | 2017-04-26 02:44:35 +0800 | [diff] [blame] | 22 | u32 handoff_val = 0; |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 23 | |
| 24 | /* ISWGRP_HANDOFF_FPGAINTF */ |
| 25 | writel(0, &sysmgr_regs->iswgrp_handoff[2]); |
| 26 | |
| 27 | /* Enable the signal for those HPS peripherals that use FPGA. */ |
| 28 | if (readl(&sysmgr_regs->nandusefpga) == SYSMGR_FPGAINTF_USEFPGA) |
| 29 | handoff_val |= SYSMGR_FPGAINTF_NAND; |
| 30 | if (readl(&sysmgr_regs->rgmii1usefpga) == SYSMGR_FPGAINTF_USEFPGA) |
| 31 | handoff_val |= SYSMGR_FPGAINTF_EMAC1; |
| 32 | if (readl(&sysmgr_regs->sdmmcusefpga) == SYSMGR_FPGAINTF_USEFPGA) |
| 33 | handoff_val |= SYSMGR_FPGAINTF_SDMMC; |
| 34 | if (readl(&sysmgr_regs->rgmii0usefpga) == SYSMGR_FPGAINTF_USEFPGA) |
| 35 | handoff_val |= SYSMGR_FPGAINTF_EMAC0; |
| 36 | if (readl(&sysmgr_regs->spim0usefpga) == SYSMGR_FPGAINTF_USEFPGA) |
| 37 | handoff_val |= SYSMGR_FPGAINTF_SPIM0; |
| 38 | if (readl(&sysmgr_regs->spim1usefpga) == SYSMGR_FPGAINTF_USEFPGA) |
| 39 | handoff_val |= SYSMGR_FPGAINTF_SPIM1; |
| 40 | |
| 41 | /* populate (not writing) the value for SYSMGR.FPGAINTF.MODULE |
| 42 | based on pinmux setting */ |
| 43 | setbits_le32(&sysmgr_regs->iswgrp_handoff[2], handoff_val); |
| 44 | |
| 45 | handoff_val = readl(&sysmgr_regs->iswgrp_handoff[2]); |
| 46 | if (fpgamgr_test_fpga_ready()) { |
| 47 | /* Enable the required signals only */ |
| 48 | writel(handoff_val, &sysmgr_regs->fpgaintfgrp_module); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /* |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 53 | * Configure all the pin muxes |
| 54 | */ |
| 55 | void sysmgr_pinmux_init(void) |
| 56 | { |
Ley Foon Tan | d5c5e3b | 2017-04-26 02:44:35 +0800 | [diff] [blame] | 57 | u32 regs = (u32)&sysmgr_regs->emacio[0]; |
Marek Vasut | 7b64873 | 2015-08-10 22:17:46 +0200 | [diff] [blame] | 58 | const u8 *sys_mgr_init_table; |
Marek Vasut | 1100e34 | 2015-07-25 11:09:11 +0200 | [diff] [blame] | 59 | unsigned int len; |
Marek Vasut | 6141272 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 60 | int i; |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 61 | |
Marek Vasut | 1100e34 | 2015-07-25 11:09:11 +0200 | [diff] [blame] | 62 | sysmgr_get_pinmux_table(&sys_mgr_init_table, &len); |
| 63 | |
| 64 | for (i = 0; i < len; i++) { |
Marek Vasut | 6141272 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 65 | writel(sys_mgr_init_table[i], regs); |
| 66 | regs += sizeof(regs); |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 67 | } |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 68 | |
| 69 | populate_sysmgr_fpgaintf_module(); |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 70 | } |
Dinh Nguyen | 95a2fd3 | 2015-03-30 17:01:07 -0500 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * This bit allows the bootrom to configure the IOs after a warm reset. |
| 74 | */ |
Marek Vasut | 8306b1e | 2015-07-09 04:40:11 +0200 | [diff] [blame] | 75 | void sysmgr_config_warmrstcfgio(int enable) |
Dinh Nguyen | 95a2fd3 | 2015-03-30 17:01:07 -0500 | [diff] [blame] | 76 | { |
Marek Vasut | 8306b1e | 2015-07-09 04:40:11 +0200 | [diff] [blame] | 77 | if (enable) |
| 78 | setbits_le32(&sysmgr_regs->romcodegrp_ctrl, |
| 79 | SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO); |
| 80 | else |
| 81 | clrbits_le32(&sysmgr_regs->romcodegrp_ctrl, |
| 82 | SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO); |
Dinh Nguyen | 95a2fd3 | 2015-03-30 17:01:07 -0500 | [diff] [blame] | 83 | } |