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