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 | |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 11 | /* |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 12 | * 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 | */ |
| 16 | static void populate_sysmgr_fpgaintf_module(void) |
| 17 | { |
Ley Foon Tan | d5c5e3b | 2017-04-26 02:44:35 +0800 | [diff] [blame] | 18 | u32 handoff_val = 0; |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 19 | |
| 20 | /* ISWGRP_HANDOFF_FPGAINTF */ |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 21 | writel(0, socfpga_get_sysmgr_addr() + SYSMGR_ISWGRP_HANDOFF_OFFSET(2)); |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 22 | |
| 23 | /* Enable the signal for those HPS peripherals that use FPGA. */ |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 24 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_NAND_USEFPGA) == |
| 25 | SYSMGR_FPGAINTF_USEFPGA) |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 26 | handoff_val |= SYSMGR_FPGAINTF_NAND; |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 27 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_RGMII1_USEFPGA) == |
| 28 | SYSMGR_FPGAINTF_USEFPGA) |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 29 | handoff_val |= SYSMGR_FPGAINTF_EMAC1; |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 30 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_SDMMC_USEFPGA) == |
| 31 | SYSMGR_FPGAINTF_USEFPGA) |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 32 | handoff_val |= SYSMGR_FPGAINTF_SDMMC; |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 33 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_RGMII0_USEFPGA) == |
| 34 | SYSMGR_FPGAINTF_USEFPGA) |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 35 | handoff_val |= SYSMGR_FPGAINTF_EMAC0; |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 36 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_SPIM0_USEFPGA) == |
| 37 | SYSMGR_FPGAINTF_USEFPGA) |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 38 | handoff_val |= SYSMGR_FPGAINTF_SPIM0; |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 39 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_GEN5_SPIM1_USEFPGA) == |
| 40 | SYSMGR_FPGAINTF_USEFPGA) |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 41 | handoff_val |= SYSMGR_FPGAINTF_SPIM1; |
| 42 | |
| 43 | /* populate (not writing) the value for SYSMGR.FPGAINTF.MODULE |
| 44 | based on pinmux setting */ |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 45 | setbits_le32(socfpga_get_sysmgr_addr() + |
| 46 | SYSMGR_ISWGRP_HANDOFF_OFFSET(2), |
| 47 | handoff_val); |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 48 | |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 49 | handoff_val = readl(socfpga_get_sysmgr_addr() + |
| 50 | SYSMGR_ISWGRP_HANDOFF_OFFSET(2)); |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 51 | if (fpgamgr_test_fpga_ready()) { |
| 52 | /* Enable the required signals only */ |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 53 | writel(handoff_val, |
| 54 | socfpga_get_sysmgr_addr() + |
| 55 | SYSMGR_GEN5_FPGAINFGRP_MODULE); |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
| 59 | /* |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 60 | * Configure all the pin muxes |
| 61 | */ |
| 62 | void sysmgr_pinmux_init(void) |
| 63 | { |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 64 | u32 regs = (u32)socfpga_get_sysmgr_addr() + SYSMGR_GEN5_EMACIO; |
Marek Vasut | 7b64873 | 2015-08-10 22:17:46 +0200 | [diff] [blame] | 65 | const u8 *sys_mgr_init_table; |
Marek Vasut | 1100e34 | 2015-07-25 11:09:11 +0200 | [diff] [blame] | 66 | unsigned int len; |
Marek Vasut | 6141272 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 67 | int i; |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 68 | |
Marek Vasut | 1100e34 | 2015-07-25 11:09:11 +0200 | [diff] [blame] | 69 | sysmgr_get_pinmux_table(&sys_mgr_init_table, &len); |
| 70 | |
| 71 | for (i = 0; i < len; i++) { |
Marek Vasut | 6141272 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 72 | writel(sys_mgr_init_table[i], regs); |
| 73 | regs += sizeof(regs); |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 74 | } |
Marek Vasut | efd16d0 | 2014-09-08 14:08:45 +0200 | [diff] [blame] | 75 | |
| 76 | populate_sysmgr_fpgaintf_module(); |
Chin Liang See | 70fa4e7 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 77 | } |
Dinh Nguyen | 95a2fd3 | 2015-03-30 17:01:07 -0500 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * This bit allows the bootrom to configure the IOs after a warm reset. |
| 81 | */ |
Marek Vasut | 8306b1e | 2015-07-09 04:40:11 +0200 | [diff] [blame] | 82 | void sysmgr_config_warmrstcfgio(int enable) |
Dinh Nguyen | 95a2fd3 | 2015-03-30 17:01:07 -0500 | [diff] [blame] | 83 | { |
Marek Vasut | 8306b1e | 2015-07-09 04:40:11 +0200 | [diff] [blame] | 84 | if (enable) |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 85 | setbits_le32(socfpga_get_sysmgr_addr() + |
| 86 | SYSMGR_GEN5_ROMCODEGRP_CTRL, |
Marek Vasut | 8306b1e | 2015-07-09 04:40:11 +0200 | [diff] [blame] | 87 | SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO); |
| 88 | else |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 89 | clrbits_le32(socfpga_get_sysmgr_addr() + |
| 90 | SYSMGR_GEN5_ROMCODEGRP_CTRL, |
Marek Vasut | 8306b1e | 2015-07-09 04:40:11 +0200 | [diff] [blame] | 91 | SYSMGR_ROMCODEGRP_CTRL_WARMRSTCFGIO); |
Dinh Nguyen | 95a2fd3 | 2015-03-30 17:01:07 -0500 | [diff] [blame] | 92 | } |