blob: cdda881efd717bc6f77b5c8c0b597ad2f2b9dfb8 [file] [log] [blame]
Ley Foon Tan7cdb9122018-05-18 22:05:24 +08001// 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
11DECLARE_GLOBAL_DATA_PTR;
12
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080013/*
14 * Configure all the pin muxes
15 */
16void 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 */
27void 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 Tan0b1680e2019-11-27 15:55:18 +080032 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NAND_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080033 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080034 handoff_val |= SYSMGR_FPGAINTF_NAND;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080035 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SDMMC_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080036 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080037 handoff_val |= SYSMGR_FPGAINTF_SDMMC;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080038 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM0_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080039 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080040 handoff_val |= SYSMGR_FPGAINTF_SPIM0;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080041 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM1_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080042 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080043 handoff_val |= SYSMGR_FPGAINTF_SPIM1;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080044 writel(handoff_val,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080045 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN2);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080046
47 handoff_val = 0;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080048 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC0_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080049 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080050 handoff_val |= SYSMGR_FPGAINTF_EMAC0;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080051 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC1_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080052 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080053 handoff_val |= SYSMGR_FPGAINTF_EMAC1;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080054 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC2_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080055 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080056 handoff_val |= SYSMGR_FPGAINTF_EMAC2;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080057 writel(handoff_val,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080058 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN3);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080059}
60
61/*
62 * Configure all the pin muxes
63 */
64void 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 Tan3d3a8602019-11-08 10:38:20 +080073 sys_mgr_table_u32[i] +
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080074 (u8 *)socfpga_get_sysmgr_addr() + SYSMGR_SOC64_PINSEL0);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080075 }
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 Tan3d3a8602019-11-08 10:38:20 +080081 sys_mgr_table_u32[i] +
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080082 (u8 *)socfpga_get_sysmgr_addr() + SYSMGR_SOC64_IOCTRL0);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080083 }
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 Tan3d3a8602019-11-08 10:38:20 +080090 (u8 *)socfpga_get_sysmgr_addr() +
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080091 SYSMGR_SOC64_EMAC0_USEFPGA);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080092 }
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 Tan3d3a8602019-11-08 10:38:20 +080098 sys_mgr_table_u32[i] +
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080099 (u8 *)socfpga_get_sysmgr_addr() + SYSMGR_SOC64_IODELAY0);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +0800100 }
101}