blob: 958bb5107b5b96fd17e3bdc2bdd2c37878552d78 [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>
Siew Chin Limff1eec32021-03-24 13:11:38 +080011#include <common.h>
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080012
13DECLARE_GLOBAL_DATA_PTR;
14
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080015/*
16 * Configure all the pin muxes
17 */
18void sysmgr_pinmux_init(void)
19{
20 populate_sysmgr_pinmux();
21 populate_sysmgr_fpgaintf_module();
22}
23
24/*
25 * Populate the value for SYSMGR.FPGAINTF.MODULE based on pinmux setting.
26 * The value is not wrote to SYSMGR.FPGAINTF.MODULE but
27 * CONFIG_SYSMGR_ISWGRP_HANDOFF.
28 */
29void populate_sysmgr_fpgaintf_module(void)
30{
31 u32 handoff_val = 0;
32
33 /* Enable the signal for those HPS peripherals that use FPGA. */
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080034 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NAND_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080035 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080036 handoff_val |= SYSMGR_FPGAINTF_NAND;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080037 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SDMMC_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080038 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080039 handoff_val |= SYSMGR_FPGAINTF_SDMMC;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080040 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM0_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080041 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080042 handoff_val |= SYSMGR_FPGAINTF_SPIM0;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080043 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM1_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080044 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080045 handoff_val |= SYSMGR_FPGAINTF_SPIM1;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080046 writel(handoff_val,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080047 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN2);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080048
49 handoff_val = 0;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080050 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC0_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080051 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080052 handoff_val |= SYSMGR_FPGAINTF_EMAC0;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080053 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC1_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080054 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080055 handoff_val |= SYSMGR_FPGAINTF_EMAC1;
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080056 if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC2_USEFPGA) ==
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080057 SYSMGR_FPGAINTF_USEFPGA)
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080058 handoff_val |= SYSMGR_FPGAINTF_EMAC2;
Ley Foon Tan3d3a8602019-11-08 10:38:20 +080059 writel(handoff_val,
Ley Foon Tan0b1680e2019-11-27 15:55:18 +080060 socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN3);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080061}
62
63/*
64 * Configure all the pin muxes
65 */
66void populate_sysmgr_pinmux(void)
67{
Siew Chin Limff1eec32021-03-24 13:11:38 +080068 u32 len, i;
Tien Fong Cheedf89b502021-08-10 11:26:29 +080069 u32 len_mux = socfpga_get_handoff_size((void *)SOC64_HANDOFF_MUX);
70 u32 len_ioctl = socfpga_get_handoff_size((void *)SOC64_HANDOFF_IOCTL);
71 u32 len_fpga = socfpga_get_handoff_size((void *)SOC64_HANDOFF_FPGA);
72 u32 len_delay = socfpga_get_handoff_size((void *)SOC64_HANDOFF_DELAY);
Siew Chin Limff1eec32021-03-24 13:11:38 +080073
74 len = (len_mux > len_ioctl) ? len_mux : len_ioctl;
75 len = (len > len_fpga) ? len : len_fpga;
76 len = (len > len_delay) ? len : len_delay;
77
78 u32 handoff_table[len];
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080079
80 /* setup the pin sel */
Siew Chin Limff1eec32021-03-24 13:11:38 +080081 len = (len_mux < SOC64_HANDOFF_MUX_LEN) ? len_mux : SOC64_HANDOFF_MUX_LEN;
Tien Fong Cheedf89b502021-08-10 11:26:29 +080082 socfpga_handoff_read((void *)SOC64_HANDOFF_MUX, handoff_table, len);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080083 for (i = 0; i < len; i = i + 2) {
Siew Chin Limff1eec32021-03-24 13:11:38 +080084 writel(handoff_table[i + 1],
85 handoff_table[i] +
86 (u8 *)socfpga_get_sysmgr_addr() +
87 SYSMGR_SOC64_PINSEL0);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080088 }
89
90 /* setup the pin ctrl */
Siew Chin Limff1eec32021-03-24 13:11:38 +080091 len = (len_ioctl < SOC64_HANDOFF_IOCTL_LEN) ? len_ioctl : SOC64_HANDOFF_IOCTL_LEN;
Tien Fong Cheedf89b502021-08-10 11:26:29 +080092 socfpga_handoff_read((void *)SOC64_HANDOFF_IOCTL, handoff_table, len);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080093 for (i = 0; i < len; i = i + 2) {
Siew Chin Limff1eec32021-03-24 13:11:38 +080094 writel(handoff_table[i + 1],
95 handoff_table[i] +
96 (u8 *)socfpga_get_sysmgr_addr() +
97 SYSMGR_SOC64_IOCTRL0);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +080098 }
99
100 /* setup the fpga use */
Siew Chin Limff1eec32021-03-24 13:11:38 +0800101 len = (len_fpga < SOC64_HANDOFF_FPGA_LEN) ? len_fpga : SOC64_HANDOFF_FPGA_LEN;
Tien Fong Cheedf89b502021-08-10 11:26:29 +0800102 socfpga_handoff_read((void *)SOC64_HANDOFF_FPGA, handoff_table, len);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +0800103 for (i = 0; i < len; i = i + 2) {
Siew Chin Limff1eec32021-03-24 13:11:38 +0800104 writel(handoff_table[i + 1],
105 handoff_table[i] +
Ley Foon Tan3d3a8602019-11-08 10:38:20 +0800106 (u8 *)socfpga_get_sysmgr_addr() +
Ley Foon Tan0b1680e2019-11-27 15:55:18 +0800107 SYSMGR_SOC64_EMAC0_USEFPGA);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +0800108 }
109
110 /* setup the IO delay */
Siew Chin Limff1eec32021-03-24 13:11:38 +0800111 len = (len_delay < SOC64_HANDOFF_DELAY_LEN) ? len_delay : SOC64_HANDOFF_DELAY_LEN;
Tien Fong Cheedf89b502021-08-10 11:26:29 +0800112 socfpga_handoff_read((void *)SOC64_HANDOFF_DELAY, handoff_table, len);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +0800113 for (i = 0; i < len; i = i + 2) {
Siew Chin Limff1eec32021-03-24 13:11:38 +0800114 writel(handoff_table[i + 1],
115 handoff_table[i] +
116 (u8 *)socfpga_get_sysmgr_addr() +
117 SYSMGR_SOC64_IODELAY0);
Ley Foon Tan7cdb9122018-05-18 22:05:24 +0800118 }
119}