Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 2 | /* |
Ley Foon Tan | d5c5e3b | 2017-04-26 02:44:35 +0800 | [diff] [blame] | 3 | * Copyright (C) 2013-2017 Altera Corporation <www.altera.com> |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <asm/io.h> |
| 8 | #include <asm/arch/system_manager.h> |
Marek Vasut | 6141272 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 9 | #include <asm/arch/fpga_manager.h> |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 10 | |
Marek Vasut | 6141272 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 11 | static struct socfpga_system_manager *sysmgr_regs = |
| 12 | (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS; |
| 13 | |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 14 | /* |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 15 | * 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 | */ |
| 19 | static void populate_sysmgr_fpgaintf_module(void) |
| 20 | { |
Ley Foon Tan | d5c5e3b | 2017-04-26 02:44:35 +0800 | [diff] [blame] | 21 | u32 handoff_val = 0; |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 22 | |
| 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 See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 52 | * Configure all the pin muxes |
| 53 | */ |
| 54 | void sysmgr_pinmux_init(void) |
| 55 | { |
Ley Foon Tan | d5c5e3b | 2017-04-26 02:44:35 +0800 | [diff] [blame] | 56 | u32 regs = (u32)&sysmgr_regs->emacio[0]; |
Marek Vasut | 7b64873 | 2015-08-10 22:17:46 +0200 | [diff] [blame] | 57 | const u8 *sys_mgr_init_table; |
Marek Vasut | 1100e34 | 2015-07-25 11:09:11 +0200 | [diff] [blame] | 58 | unsigned int len; |
Marek Vasut | 6141272 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 59 | int i; |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 60 | |
Marek Vasut | 1100e34 | 2015-07-25 11:09:11 +0200 | [diff] [blame] | 61 | sysmgr_get_pinmux_table(&sys_mgr_init_table, &len); |
| 62 | |
| 63 | for (i = 0; i < len; i++) { |
Marek Vasut | 6141272 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 64 | writel(sys_mgr_init_table[i], regs); |
| 65 | regs += sizeof(regs); |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 66 | } |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 67 | |
| 68 | populate_sysmgr_fpgaintf_module(); |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 69 | } |
Dinh Nguyen | 95a2fd3 | 2015-03-30 17:01:07 -0500 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | * This bit allows the bootrom to configure the IOs after a warm reset. |
| 73 | */ |
Marek Vasut | 8306b1e | 2015-07-09 04:40:11 +0200 | [diff] [blame] | 74 | void sysmgr_config_warmrstcfgio(int enable) |
Dinh Nguyen | 95a2fd3 | 2015-03-30 17:01:07 -0500 | [diff] [blame] | 75 | { |
Marek Vasut | 8306b1e | 2015-07-09 04:40:11 +0200 | [diff] [blame] | 76 | 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 Nguyen | 95a2fd3 | 2015-03-30 17:01:07 -0500 | [diff] [blame] | 82 | } |