Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2016-2018 Intel Corporation <www.intel.com> |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/system_manager.h> |
| 10 | |
| 11 | DECLARE_GLOBAL_DATA_PTR; |
| 12 | |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 13 | /* |
| 14 | * Configure all the pin muxes |
| 15 | */ |
| 16 | void sysmgr_pinmux_init(void) |
| 17 | { |
| 18 | populate_sysmgr_pinmux(); |
| 19 | populate_sysmgr_fpgaintf_module(); |
| 20 | } |
| 21 | |
| 22 | /* |
| 23 | * Populate the value for SYSMGR.FPGAINTF.MODULE based on pinmux setting. |
| 24 | * The value is not wrote to SYSMGR.FPGAINTF.MODULE but |
| 25 | * CONFIG_SYSMGR_ISWGRP_HANDOFF. |
| 26 | */ |
| 27 | void populate_sysmgr_fpgaintf_module(void) |
| 28 | { |
| 29 | u32 handoff_val = 0; |
| 30 | |
| 31 | /* Enable the signal for those HPS peripherals that use FPGA. */ |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 32 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NAND_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 33 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 34 | handoff_val |= SYSMGR_FPGAINTF_NAND; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 35 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SDMMC_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 36 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 37 | handoff_val |= SYSMGR_FPGAINTF_SDMMC; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 38 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM0_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 39 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 40 | handoff_val |= SYSMGR_FPGAINTF_SPIM0; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 41 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM1_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 42 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 43 | handoff_val |= SYSMGR_FPGAINTF_SPIM1; |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 44 | writel(handoff_val, |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 45 | socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN2); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 46 | |
| 47 | handoff_val = 0; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 48 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC0_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 49 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 50 | handoff_val |= SYSMGR_FPGAINTF_EMAC0; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 51 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC1_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 52 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 53 | handoff_val |= SYSMGR_FPGAINTF_EMAC1; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 54 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC2_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 55 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 56 | handoff_val |= SYSMGR_FPGAINTF_EMAC2; |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 57 | writel(handoff_val, |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 58 | socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN3); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* |
| 62 | * Configure all the pin muxes |
| 63 | */ |
| 64 | void populate_sysmgr_pinmux(void) |
| 65 | { |
| 66 | const u32 *sys_mgr_table_u32; |
| 67 | unsigned int len, i; |
| 68 | |
| 69 | /* setup the pin sel */ |
| 70 | sysmgr_pinmux_table_sel(&sys_mgr_table_u32, &len); |
| 71 | for (i = 0; i < len; i = i + 2) { |
| 72 | writel(sys_mgr_table_u32[i + 1], |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 73 | sys_mgr_table_u32[i] + |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 74 | (u8 *)socfpga_get_sysmgr_addr() + SYSMGR_SOC64_PINSEL0); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* setup the pin ctrl */ |
| 78 | sysmgr_pinmux_table_ctrl(&sys_mgr_table_u32, &len); |
| 79 | for (i = 0; i < len; i = i + 2) { |
| 80 | writel(sys_mgr_table_u32[i + 1], |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 81 | sys_mgr_table_u32[i] + |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 82 | (u8 *)socfpga_get_sysmgr_addr() + SYSMGR_SOC64_IOCTRL0); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /* setup the fpga use */ |
| 86 | sysmgr_pinmux_table_fpga(&sys_mgr_table_u32, &len); |
| 87 | for (i = 0; i < len; i = i + 2) { |
| 88 | writel(sys_mgr_table_u32[i + 1], |
| 89 | sys_mgr_table_u32[i] + |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 90 | (u8 *)socfpga_get_sysmgr_addr() + |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 91 | SYSMGR_SOC64_EMAC0_USEFPGA); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* setup the IO delay */ |
| 95 | sysmgr_pinmux_table_delay(&sys_mgr_table_u32, &len); |
| 96 | for (i = 0; i < len; i = i + 2) { |
| 97 | writel(sys_mgr_table_u32[i + 1], |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 98 | sys_mgr_table_u32[i] + |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 99 | (u8 *)socfpga_get_sysmgr_addr() + SYSMGR_SOC64_IODELAY0); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 100 | } |
| 101 | } |