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> |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 11 | |
| 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 14 | /* |
| 15 | * Configure all the pin muxes |
| 16 | */ |
| 17 | void 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 | */ |
| 28 | void 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 Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 33 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_NAND_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 34 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 35 | handoff_val |= SYSMGR_FPGAINTF_NAND; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 36 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SDMMC_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 37 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 38 | handoff_val |= SYSMGR_FPGAINTF_SDMMC; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 39 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM0_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 40 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 41 | handoff_val |= SYSMGR_FPGAINTF_SPIM0; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 42 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_SPIM1_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 43 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 44 | handoff_val |= SYSMGR_FPGAINTF_SPIM1; |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 45 | writel(handoff_val, |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 46 | socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN2); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 47 | |
| 48 | handoff_val = 0; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 49 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC0_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 50 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 51 | handoff_val |= SYSMGR_FPGAINTF_EMAC0; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 52 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC1_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 53 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 54 | handoff_val |= SYSMGR_FPGAINTF_EMAC1; |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 55 | if (readl(socfpga_get_sysmgr_addr() + SYSMGR_SOC64_EMAC2_USEFPGA) == |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 56 | SYSMGR_FPGAINTF_USEFPGA) |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 57 | handoff_val |= SYSMGR_FPGAINTF_EMAC2; |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 58 | writel(handoff_val, |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 59 | socfpga_get_sysmgr_addr() + SYSMGR_SOC64_FPGAINTF_EN3); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Configure all the pin muxes |
| 64 | */ |
| 65 | void populate_sysmgr_pinmux(void) |
| 66 | { |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 67 | u32 len, i; |
Tien Fong Chee | df89b50 | 2021-08-10 11:26:29 +0800 | [diff] [blame] | 68 | 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 Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 72 | |
| 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 Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 78 | |
| 79 | /* setup the pin sel */ |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 80 | 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] | 81 | socfpga_handoff_read((void *)SOC64_HANDOFF_MUX, handoff_table, len); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 82 | for (i = 0; i < len; i = i + 2) { |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 83 | writel(handoff_table[i + 1], |
| 84 | handoff_table[i] + |
| 85 | (u8 *)socfpga_get_sysmgr_addr() + |
| 86 | SYSMGR_SOC64_PINSEL0); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* setup the pin ctrl */ |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 90 | 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] | 91 | socfpga_handoff_read((void *)SOC64_HANDOFF_IOCTL, handoff_table, len); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 92 | for (i = 0; i < len; i = i + 2) { |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 93 | writel(handoff_table[i + 1], |
| 94 | handoff_table[i] + |
| 95 | (u8 *)socfpga_get_sysmgr_addr() + |
| 96 | SYSMGR_SOC64_IOCTRL0); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /* setup the fpga use */ |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 100 | 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] | 101 | socfpga_handoff_read((void *)SOC64_HANDOFF_FPGA, handoff_table, len); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 102 | for (i = 0; i < len; i = i + 2) { |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 103 | writel(handoff_table[i + 1], |
| 104 | handoff_table[i] + |
Ley Foon Tan | 3d3a860 | 2019-11-08 10:38:20 +0800 | [diff] [blame] | 105 | (u8 *)socfpga_get_sysmgr_addr() + |
Ley Foon Tan | 0b1680e | 2019-11-27 15:55:18 +0800 | [diff] [blame] | 106 | SYSMGR_SOC64_EMAC0_USEFPGA); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /* setup the IO delay */ |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 110 | 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] | 111 | socfpga_handoff_read((void *)SOC64_HANDOFF_DELAY, handoff_table, len); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 112 | for (i = 0; i < len; i = i + 2) { |
Siew Chin Lim | ff1eec3 | 2021-03-24 13:11:38 +0800 | [diff] [blame] | 113 | writel(handoff_table[i + 1], |
| 114 | handoff_table[i] + |
| 115 | (u8 *)socfpga_get_sysmgr_addr() + |
| 116 | SYSMGR_SOC64_IODELAY0); |
Ley Foon Tan | 7cdb912 | 2018-05-18 22:05:24 +0800 | [diff] [blame] | 117 | } |
| 118 | } |