Wasim Khan | 54e44ef | 2020-01-06 12:05:57 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2019-2020 NXP |
| 4 | * |
| 5 | * PCIe DT fixup for NXP Layerscape SoCs |
| 6 | * Author: Wasim Khan <wasim.khan@nxp.com> |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 11 | #include <init.h> |
Wasim Khan | 54e44ef | 2020-01-06 12:05:57 +0000 | [diff] [blame] | 12 | #include <asm/arch/clock.h> |
| 13 | #include <asm/arch/soc.h> |
| 14 | #include "pcie_layerscape_fixup_common.h" |
| 15 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 16 | void ft_pci_setup(void *blob, struct bd_info *bd) |
Wasim Khan | 54e44ef | 2020-01-06 12:05:57 +0000 | [diff] [blame] | 17 | { |
| 18 | #if defined(CONFIG_PCIE_LAYERSCAPE_GEN4) |
| 19 | uint svr; |
| 20 | |
| 21 | svr = SVR_SOC_VER(get_svr()); |
| 22 | |
| 23 | if (svr == SVR_LX2160A && IS_SVR_REV(get_svr(), 1, 0)) |
| 24 | ft_pci_setup_ls_gen4(blob, bd); |
| 25 | else |
| 26 | #endif /* CONFIG_PCIE_LAYERSCAPE_GEN4 */ |
| 27 | ft_pci_setup_ls(blob, bd); |
| 28 | } |
Wasim Khan | 9d3d230 | 2020-01-06 12:05:59 +0000 | [diff] [blame] | 29 | |
| 30 | #if defined(CONFIG_FSL_LAYERSCAPE) |
Wasim Khan | 70bec5c | 2020-01-06 12:06:00 +0000 | [diff] [blame] | 31 | int lx2_board_fix_fdt(void *fdt) |
| 32 | { |
| 33 | char *reg_name, *old_str, *new_str; |
| 34 | const char *reg_names; |
| 35 | int names_len, old_str_len, new_str_len, remaining_str_len; |
| 36 | struct str_map { |
| 37 | char *old_str; |
| 38 | char *new_str; |
| 39 | } reg_names_map[] = { |
| 40 | { "csr_axi_slave", "regs" }, |
| 41 | { "config_axi_slave", "config" } |
| 42 | }; |
| 43 | int off = -1, i; |
Hou Zhiqiang | fdb1dff | 2020-09-13 23:12:50 +0800 | [diff] [blame] | 44 | const fdt32_t *prop; |
| 45 | u32 ob_wins, ib_wins; |
Wasim Khan | 70bec5c | 2020-01-06 12:06:00 +0000 | [diff] [blame] | 46 | |
| 47 | off = fdt_node_offset_by_compatible(fdt, -1, "fsl,lx2160a-pcie"); |
| 48 | while (off != -FDT_ERR_NOTFOUND) { |
| 49 | fdt_setprop(fdt, off, "compatible", "fsl,ls2088a-pcie", |
| 50 | strlen("fsl,ls2088a-pcie") + 1); |
| 51 | |
| 52 | reg_names = fdt_getprop(fdt, off, "reg-names", &names_len); |
| 53 | if (!reg_names) |
| 54 | continue; |
| 55 | reg_name = (char *)reg_names; |
| 56 | remaining_str_len = names_len - (reg_name - reg_names); |
| 57 | i = 0; |
| 58 | while ((i < ARRAY_SIZE(reg_names_map)) && remaining_str_len) { |
| 59 | old_str = reg_names_map[i].old_str; |
| 60 | new_str = reg_names_map[i].new_str; |
| 61 | old_str_len = strlen(old_str); |
| 62 | new_str_len = strlen(new_str); |
| 63 | if (memcmp(reg_name, old_str, old_str_len) == 0) { |
| 64 | /* first only leave required bytes for new_str |
| 65 | * and copy rest of the string after it |
| 66 | */ |
| 67 | memcpy(reg_name + new_str_len, |
| 68 | reg_name + old_str_len, |
| 69 | remaining_str_len - old_str_len); |
| 70 | |
| 71 | /* Now copy new_str */ |
| 72 | memcpy(reg_name, new_str, new_str_len); |
| 73 | names_len -= old_str_len; |
| 74 | names_len += new_str_len; |
| 75 | i++; |
| 76 | } |
| 77 | |
| 78 | reg_name = memchr(reg_name, '\0', remaining_str_len); |
| 79 | if (!reg_name) |
| 80 | break; |
| 81 | reg_name += 1; |
| 82 | |
| 83 | remaining_str_len = names_len - (reg_name - reg_names); |
| 84 | } |
| 85 | fdt_setprop(fdt, off, "reg-names", reg_names, names_len); |
| 86 | fdt_delprop(fdt, off, "apio-wins"); |
| 87 | fdt_delprop(fdt, off, "ppio-wins"); |
| 88 | off = fdt_node_offset_by_compatible(fdt, off, |
| 89 | "fsl,lx2160a-pcie"); |
| 90 | } |
Hou Zhiqiang | fdb1dff | 2020-09-13 23:12:50 +0800 | [diff] [blame] | 91 | |
| 92 | /* Fixup PCIe EP nodes */ |
| 93 | off = -1; |
| 94 | off = fdt_node_offset_by_compatible(fdt, off, "fsl,lx2160a-pcie-ep"); |
| 95 | while (off != -FDT_ERR_NOTFOUND) { |
| 96 | fdt_setprop_string(fdt, off, "compatible", |
| 97 | "fsl,lx2160ar2-pcie-ep"); |
| 98 | prop = fdt_getprop(fdt, off, "apio-wins", NULL); |
| 99 | if (!prop) { |
| 100 | printf("%s: Failed to fixup PCIe EP node @0x%x\n", |
| 101 | __func__, off); |
Hou Zhiqiang | e1a8443 | 2020-10-26 11:57:42 +0800 | [diff] [blame] | 102 | off = fdt_node_offset_by_compatible(fdt, off, |
| 103 | "fsl,lx2160a-pcie-ep"); |
Hou Zhiqiang | fdb1dff | 2020-09-13 23:12:50 +0800 | [diff] [blame] | 104 | continue; |
| 105 | } |
| 106 | |
| 107 | ob_wins = fdt32_to_cpu(*prop); |
| 108 | ib_wins = (ob_wins == 256) ? 24 : 8; |
| 109 | fdt_setprop_u32(fdt, off, "num-ib-windows", ib_wins); |
| 110 | fdt_setprop_u32(fdt, off, "num-ob-windows", ob_wins); |
| 111 | fdt_delprop(fdt, off, "apio-wins"); |
| 112 | |
| 113 | off = fdt_node_offset_by_compatible(fdt, off, |
| 114 | "fsl,lx2160a-pcie-ep"); |
| 115 | } |
| 116 | |
Wasim Khan | 70bec5c | 2020-01-06 12:06:00 +0000 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | int pcie_board_fix_fdt(void *fdt) |
| 121 | { |
| 122 | uint svr; |
| 123 | |
| 124 | svr = SVR_SOC_VER(get_svr()); |
| 125 | |
Meenakshi Aggarwal | ccb5d5d | 2020-10-29 19:16:16 +0530 | [diff] [blame] | 126 | if ((svr == SVR_LX2160A || svr == SVR_LX2162A || |
| 127 | svr == SVR_LX2120A || svr == SVR_LX2080A || |
| 128 | svr == SVR_LX2122A || svr == SVR_LX2082A) && |
| 129 | IS_SVR_REV(get_svr(), 2, 0)) |
Wasim Khan | 70bec5c | 2020-01-06 12:06:00 +0000 | [diff] [blame] | 130 | return lx2_board_fix_fdt(fdt); |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
Meenakshi Aggarwal | ccb5d5d | 2020-10-29 19:16:16 +0530 | [diff] [blame] | 135 | #if defined(CONFIG_ARCH_LX2160A) || defined(CONFIG_ARCH_LX2162A) |
Wasim Khan | 9d3d230 | 2020-01-06 12:05:59 +0000 | [diff] [blame] | 136 | /* returns the next available streamid for pcie, -errno if failed */ |
| 137 | int pcie_next_streamid(int currentid, int idx) |
| 138 | { |
| 139 | if (currentid > FSL_PEX_STREAM_ID_END) |
| 140 | return -EINVAL; |
| 141 | |
| 142 | return currentid | ((idx + 1) << 11); |
| 143 | } |
| 144 | #else |
| 145 | /* returns the next available streamid for pcie, -errno if failed */ |
| 146 | int pcie_next_streamid(int currentid, int idx) |
| 147 | { |
| 148 | static int next_stream_id = FSL_PEX_STREAM_ID_START; |
| 149 | |
| 150 | if (next_stream_id > FSL_PEX_STREAM_ID_END) |
| 151 | return -EINVAL; |
| 152 | |
| 153 | return next_stream_id++; |
| 154 | } |
| 155 | #endif |
| 156 | #endif /* CONFIG_FSL_LAYERSCAPE */ |