blob: 4b42158be9d9731eaa02939f33a4fc3961ec8b68 [file] [log] [blame]
Ley Foon Tan7cdb9122018-05-18 22:05:24 +08001// SPDX-License-Identifier: GPL-2.0
2/*
Tien Fong Cheedf89b502021-08-10 11:26:29 +08003 * Copyright (C) 2016-2021 Intel Corporation <www.intel.com>
Ley Foon Tan7cdb9122018-05-18 22:05:24 +08004 *
5 */
6
Siew Chin Limff1eec32021-03-24 13:11:38 +08007#include <asm/arch/handoff_soc64.h>
8#include <asm/arch/system_manager.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080010#include <asm/io.h>
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080011
12DECLARE_GLOBAL_DATA_PTR;
13
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080014/*
15 * Configure all the pin muxes
16 */
17void sysmgr_pinmux_init(void)
18{
19 populate_sysmgr_pinmux();
20 populate_sysmgr_fpgaintf_module();
21}
22
23/*
24 * Populate the value for SYSMGR.FPGAINTF.MODULE based on pinmux setting.
25 * The value is not wrote to SYSMGR.FPGAINTF.MODULE but
26 * CONFIG_SYSMGR_ISWGRP_HANDOFF.
27 */
28void populate_sysmgr_fpgaintf_module(void)
29{
30 u32 handoff_val = 0;
31
32 /* Enable the signal for those HPS peripherals that use FPGA. */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080033 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NAND_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080034 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080035 handoff_val |= SYSMGR_FPGAINTF_NAND;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080036 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SDMMC_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080037 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080038 handoff_val |= SYSMGR_FPGAINTF_SDMMC;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080039 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM0_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080040 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080041 handoff_val |= SYSMGR_FPGAINTF_SPIM0;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080042 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM1_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080043 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080044 handoff_val |= SYSMGR_FPGAINTF_SPIM1;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080045 writel(handoff_val,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080046 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN2);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080047
48 handoff_val = 0;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080049 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC0_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080050 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080051 handoff_val |= SYSMGR_FPGAINTF_EMAC0;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080052 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC1_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080053 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080054 handoff_val |= SYSMGR_FPGAINTF_EMAC1;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080055 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC2_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080056 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080057 handoff_val |= SYSMGR_FPGAINTF_EMAC2;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080058 writel(handoff_val,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080059 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN3);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080060}
61
62/*
63 * Configure all the pin muxes
64 */
65void populate_sysmgr_pinmux(void)
66{
Siew Chin Limff1eec32021-03-24 13:11:38 +080067 u32 len, i;
Tien Fong Cheedf89b502021-08-10 11:26:29 +080068 u32 len_mux = socfpga_get_handoff_size((void *)SOC64_HANDOFF_MUX);
69 u32 len_ioctl = socfpga_get_handoff_size((void *)SOC64_HANDOFF_IOCTL);
70 u32 len_fpga = socfpga_get_handoff_size((void *)SOC64_HANDOFF_FPGA);
71 u32 len_delay = socfpga_get_handoff_size((void *)SOC64_HANDOFF_DELAY);
Siew Chin Limff1eec32021-03-24 13:11:38 +080072
73 len = (len_mux > len_ioctl) ? len_mux : len_ioctl;
74 len = (len > len_fpga) ? len : len_fpga;
75 len = (len > len_delay) ? len : len_delay;
76
77 u32 handoff_table[len];
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080078
79 /* setup the pin sel */
Siew Chin Limff1eec32021-03-24 13:11:38 +080080 len = (len_mux < SOC64_HANDOFF_MUX_LEN) ? len_mux : SOC64_HANDOFF_MUX_LEN;
Tien Fong Cheedf89b502021-08-10 11:26:29 +080081 socfpga_handoff_read((void *)SOC64_HANDOFF_MUX, handoff_table, len);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080082 for (i = 0; i < len; i = i + 2) {
Siew Chin Limff1eec32021-03-24 13:11:38 +080083 writel(handoff_table[i + 1],
84 handoff_table[i] +
85 (u8 *)socfpga_get_sysmgr_addr() +
86 SYSMGR_SOC64_PINSEL0);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080087 }
88
89 /* setup the pin ctrl */
Siew Chin Limff1eec32021-03-24 13:11:38 +080090 len = (len_ioctl < SOC64_HANDOFF_IOCTL_LEN) ? len_ioctl : SOC64_HANDOFF_IOCTL_LEN;
Tien Fong Cheedf89b502021-08-10 11:26:29 +080091 socfpga_handoff_read((void *)SOC64_HANDOFF_IOCTL, handoff_table, len);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080092 for (i = 0; i < len; i = i + 2) {
Siew Chin Limff1eec32021-03-24 13:11:38 +080093 writel(handoff_table[i + 1],
94 handoff_table[i] +
95 (u8 *)socfpga_get_sysmgr_addr() +
96 SYSMGR_SOC64_IOCTRL0);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080097 }
98
99 /* setup the fpga use */
Siew Chin Limff1eec32021-03-24 13:11:38 +0800100 len = (len_fpga < SOC64_HANDOFF_FPGA_LEN) ? len_fpga : SOC64_HANDOFF_FPGA_LEN;
Tien Fong Cheedf89b502021-08-10 11:26:29 +0800101 socfpga_handoff_read((void *)SOC64_HANDOFF_FPGA, handoff_table, len);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +0800102 for (i = 0; i < len; i = i + 2) {
Siew Chin Limff1eec32021-03-24 13:11:38 +0800103 writel(handoff_table[i + 1],
104 handoff_table[i] +
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800105 (u8 *)socfpga_get_sysmgr_addr() +
Ley Foon Tan0b1680e2019-11-27 15:55:18 +0800106 SYSMGR_SOC64_EMAC0_USEFPGA);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +0800107 }
108
109 /* setup the IO delay */
Siew Chin Limff1eec32021-03-24 13:11:38 +0800110 len = (len_delay < SOC64_HANDOFF_DELAY_LEN) ? len_delay : SOC64_HANDOFF_DELAY_LEN;
Tien Fong Cheedf89b502021-08-10 11:26:29 +0800111 socfpga_handoff_read((void *)SOC64_HANDOFF_DELAY, handoff_table, len);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +0800112 for (i = 0; i < len; i = i + 2) {
Siew Chin Limff1eec32021-03-24 13:11:38 +0800113 writel(handoff_table[i + 1],
114 handoff_table[i] +
115 (u8 *)socfpga_get_sysmgr_addr() +
116 SYSMGR_SOC64_IODELAY0);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +0800117 }
118}