Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
Tien Fong Chee | df89b50 | 2021-08-10 11:26:29 +0800 | [diff] [blame] | 3 | * Copyright (C) 2016-2021 Intel Corporation <www.intel.com> |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 4 | * |
| 5 | */ |
| 6 | |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 7 | #include <asm/arch/handoff_soc64.h> |
| 8 | #include <asm/arch/system_manager.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 10 | #include <asm/io.h> |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 11 | #include <common.h> |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 12 | |
| 13 | DECLARE_GLOBAL_DATA_PTR; |
| 14 | |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 15 | /* |
| 16 | * Configure all the pin muxes |
| 17 | */ |
| 18 | void 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 | */ |
| 29 | void 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 Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 34 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NAND_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 35 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 36 | handoff_val |= SYSMGR_FPGAINTF_NAND; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 37 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SDMMC_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 38 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 39 | handoff_val |= SYSMGR_FPGAINTF_SDMMC; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 40 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM0_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 41 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 42 | handoff_val |= SYSMGR_FPGAINTF_SPIM0; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 43 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM1_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 44 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 45 | handoff_val |= SYSMGR_FPGAINTF_SPIM1; |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 46 | writel(handoff_val, |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 47 | socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN2); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 48 | |
| 49 | handoff_val = 0; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 50 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC0_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 51 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 52 | handoff_val |= SYSMGR_FPGAINTF_EMAC0; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 53 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC1_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 54 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 55 | handoff_val |= SYSMGR_FPGAINTF_EMAC1; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 56 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC2_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 57 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 58 | handoff_val |= SYSMGR_FPGAINTF_EMAC2; |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 59 | writel(handoff_val, |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 60 | socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN3); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Configure all the pin muxes |
| 65 | */ |
| 66 | void populate_sysmgr_pinmux(void) |
| 67 | { |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 68 | u32 len, i; |
Tien Fong Chee | df89b50 | 2021-08-10 11:26:29 +0800 | [diff] [blame] | 69 | 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 Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 73 | |
| 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 Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 79 | |
| 80 | /* setup the pin sel */ |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 81 | len = (len_mux < SOC64_HANDOFF_MUX_LEN) ? len_mux : SOC64_HANDOFF_MUX_LEN; |
Tien Fong Chee | df89b50 | 2021-08-10 11:26:29 +0800 | [diff] [blame] | 82 | socfpga_handoff_read((void *)SOC64_HANDOFF_MUX, handoff_table, len); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 83 | for (i = 0; i < len; i = i + 2) { |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 84 | writel(handoff_table[i + 1], |
| 85 | handoff_table[i] + |
| 86 | (u8 *)socfpga_get_sysmgr_addr() + |
| 87 | SYSMGR_SOC64_PINSEL0); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* setup the pin ctrl */ |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 91 | len = (len_ioctl < SOC64_HANDOFF_IOCTL_LEN) ? len_ioctl : SOC64_HANDOFF_IOCTL_LEN; |
Tien Fong Chee | df89b50 | 2021-08-10 11:26:29 +0800 | [diff] [blame] | 92 | socfpga_handoff_read((void *)SOC64_HANDOFF_IOCTL, handoff_table, len); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 93 | for (i = 0; i < len; i = i + 2) { |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 94 | writel(handoff_table[i + 1], |
| 95 | handoff_table[i] + |
| 96 | (u8 *)socfpga_get_sysmgr_addr() + |
| 97 | SYSMGR_SOC64_IOCTRL0); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /* setup the fpga use */ |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 101 | len = (len_fpga < SOC64_HANDOFF_FPGA_LEN) ? len_fpga : SOC64_HANDOFF_FPGA_LEN; |
Tien Fong Chee | df89b50 | 2021-08-10 11:26:29 +0800 | [diff] [blame] | 102 | socfpga_handoff_read((void *)SOC64_HANDOFF_FPGA, handoff_table, len); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 103 | for (i = 0; i < len; i = i + 2) { |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 104 | writel(handoff_table[i + 1], |
| 105 | handoff_table[i] + |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 106 | (u8 *)socfpga_get_sysmgr_addr() + |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 107 | SYSMGR_SOC64_EMAC0_USEFPGA); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* setup the IO delay */ |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 111 | len = (len_delay < SOC64_HANDOFF_DELAY_LEN) ? len_delay : SOC64_HANDOFF_DELAY_LEN; |
Tien Fong Chee | df89b50 | 2021-08-10 11:26:29 +0800 | [diff] [blame] | 112 | socfpga_handoff_read((void *)SOC64_HANDOFF_DELAY, handoff_table, len); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 113 | for (i = 0; i < len; i = i + 2) { |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 114 | writel(handoff_table[i + 1], |
| 115 | handoff_table[i] + |
| 116 | (u8 *)socfpga_get_sysmgr_addr() + |
| 117 | SYSMGR_SOC64_IODELAY0); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 118 | } |
| 119 | } |