Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Keystone2: Architecture initialization |
| 3 | * |
| 4 | * (C) Copyright 2012-2014 |
| 5 | * Texas Instruments Incorporated, <www.ti.com> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Murali Karicheri | afee59c | 2014-05-29 18:57:12 +0300 | [diff] [blame] | 11 | #include <ns16550.h> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 12 | #include <asm/io.h> |
Hao Zhang | 20187fd | 2014-07-16 00:59:24 +0300 | [diff] [blame] | 13 | #include <asm/arch/msmc.h> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 14 | #include <asm/arch/clock.h> |
| 15 | #include <asm/arch/hardware.h> |
Hao Zhang | b66604f | 2014-10-22 16:32:32 +0300 | [diff] [blame] | 16 | #include <asm/arch/psc_defs.h> |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 17 | |
Karicheri, Muralidharan | 58927a9 | 2014-12-09 14:32:26 -0500 | [diff] [blame] | 18 | #define MAX_PCI_PORTS 2 |
| 19 | enum pci_mode { |
| 20 | ENDPOINT, |
| 21 | LEGACY_ENDPOINT, |
| 22 | ROOTCOMPLEX, |
| 23 | }; |
| 24 | |
| 25 | #define DEVCFG_MODE_MASK (BIT(2) | BIT(1)) |
| 26 | #define DEVCFG_MODE_SHIFT 1 |
| 27 | |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 28 | void chip_configuration_unlock(void) |
| 29 | { |
Khoronzhuk, Ivan | 3d31538 | 2014-07-09 23:44:44 +0300 | [diff] [blame] | 30 | __raw_writel(KS2_KICK0_MAGIC, KS2_KICK0); |
| 31 | __raw_writel(KS2_KICK1_MAGIC, KS2_KICK1); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Hao Zhang | b66604f | 2014-10-22 16:32:32 +0300 | [diff] [blame] | 34 | #ifdef CONFIG_SOC_K2L |
| 35 | void osr_init(void) |
| 36 | { |
| 37 | u32 i; |
| 38 | u32 j; |
| 39 | u32 val; |
| 40 | u32 base = KS2_OSR_CFG_BASE; |
| 41 | u32 ecc_ctrl[KS2_OSR_NUM_RAM_BANKS]; |
| 42 | |
| 43 | /* Enable the OSR clock domain */ |
| 44 | psc_enable_module(KS2_LPSC_OSR); |
| 45 | |
| 46 | /* Disable OSR ECC check for all the ram banks */ |
| 47 | for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++) { |
| 48 | val = i | KS2_OSR_ECC_VEC_TRIG_RD | |
| 49 | (KS2_OSR_ECC_CTRL << KS2_OSR_ECC_VEC_RD_ADDR_SH); |
| 50 | |
| 51 | writel(val , base + KS2_OSR_ECC_VEC); |
| 52 | |
| 53 | /** |
| 54 | * wait till read is done. |
| 55 | * Print should be added after earlyprintk support is added. |
| 56 | */ |
| 57 | for (j = 0; j < 10000; j++) { |
| 58 | val = readl(base + KS2_OSR_ECC_VEC); |
| 59 | if (val & KS2_OSR_ECC_VEC_RD_DONE) |
| 60 | break; |
| 61 | } |
| 62 | |
| 63 | ecc_ctrl[i] = readl(base + KS2_OSR_ECC_CTRL) ^ |
| 64 | KS2_OSR_ECC_CTRL_CHK; |
| 65 | |
| 66 | writel(ecc_ctrl[i], KS2_MSMC_DATA_BASE + i * 4); |
| 67 | writel(ecc_ctrl[i], base + KS2_OSR_ECC_CTRL); |
| 68 | } |
| 69 | |
| 70 | /* Reset OSR memory to all zeros */ |
| 71 | for (i = 0; i < KS2_OSR_SIZE; i += 4) |
| 72 | writel(0, KS2_OSR_DATA_BASE + i); |
| 73 | |
| 74 | /* Enable OSR ECC check for all the ram banks */ |
| 75 | for (i = 0; i < KS2_OSR_NUM_RAM_BANKS; i++) |
| 76 | writel(ecc_ctrl[i] | |
| 77 | KS2_OSR_ECC_CTRL_CHK, base + KS2_OSR_ECC_CTRL); |
| 78 | } |
| 79 | #endif |
| 80 | |
Karicheri, Muralidharan | 58927a9 | 2014-12-09 14:32:26 -0500 | [diff] [blame] | 81 | /* Function to set up PCIe mode */ |
| 82 | static void config_pcie_mode(int pcie_port, enum pci_mode mode) |
| 83 | { |
| 84 | u32 val = __raw_readl(KS2_DEVCFG); |
| 85 | |
| 86 | if (pcie_port >= MAX_PCI_PORTS) |
| 87 | return; |
| 88 | |
| 89 | /** |
| 90 | * each pci port has two bits for mode and it starts at |
| 91 | * bit 1. So use port number to get the right bit position. |
| 92 | */ |
| 93 | pcie_port <<= 1; |
| 94 | val &= ~(DEVCFG_MODE_MASK << pcie_port); |
| 95 | val |= ((mode << DEVCFG_MODE_SHIFT) << pcie_port); |
| 96 | __raw_writel(val, KS2_DEVCFG); |
| 97 | } |
| 98 | |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 99 | int arch_cpu_init(void) |
| 100 | { |
| 101 | chip_configuration_unlock(); |
| 102 | icache_enable(); |
| 103 | |
Hao Zhang | bc45d57 | 2014-10-22 16:32:30 +0300 | [diff] [blame] | 104 | msmc_share_all_segments(KS2_MSMC_SEGMENT_TETRIS); |
| 105 | msmc_share_all_segments(KS2_MSMC_SEGMENT_NETCP); |
Vitaly Andrianov | 11d8222 | 2015-09-19 16:26:46 +0530 | [diff] [blame] | 106 | #ifdef KS2_MSMC_SEGMENT_QM_PDSP |
Hao Zhang | bc45d57 | 2014-10-22 16:32:30 +0300 | [diff] [blame] | 107 | msmc_share_all_segments(KS2_MSMC_SEGMENT_QM_PDSP); |
Vitaly Andrianov | 11d8222 | 2015-09-19 16:26:46 +0530 | [diff] [blame] | 108 | #endif |
Hao Zhang | bc45d57 | 2014-10-22 16:32:30 +0300 | [diff] [blame] | 109 | msmc_share_all_segments(KS2_MSMC_SEGMENT_PCIE0); |
Karicheri, Muralidharan | 58927a9 | 2014-12-09 14:32:26 -0500 | [diff] [blame] | 110 | |
| 111 | /* Initialize the PCIe-0 to work as Root Complex */ |
| 112 | config_pcie_mode(0, ROOTCOMPLEX); |
Hao Zhang | bc45d57 | 2014-10-22 16:32:30 +0300 | [diff] [blame] | 113 | #if defined(CONFIG_SOC_K2E) || defined(CONFIG_SOC_K2L) |
| 114 | msmc_share_all_segments(KS2_MSMC_SEGMENT_PCIE1); |
Karicheri, Muralidharan | 58927a9 | 2014-12-09 14:32:26 -0500 | [diff] [blame] | 115 | /* Initialize the PCIe-1 to work as Root Complex */ |
| 116 | config_pcie_mode(1, ROOTCOMPLEX); |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 117 | #endif |
Hao Zhang | b66604f | 2014-10-22 16:32:32 +0300 | [diff] [blame] | 118 | #ifdef CONFIG_SOC_K2L |
| 119 | osr_init(); |
| 120 | #endif |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 121 | |
Murali Karicheri | afee59c | 2014-05-29 18:57:12 +0300 | [diff] [blame] | 122 | /* |
| 123 | * just initialise the COM2 port so that TI specific |
| 124 | * UART register PWREMU_MGMT is initialized. Linux UART |
| 125 | * driver doesn't handle this. |
| 126 | */ |
Lokesh Vutla | 8c80b19 | 2015-09-19 15:00:16 +0530 | [diff] [blame] | 127 | #ifndef CONFIG_DM_SERIAL |
Murali Karicheri | afee59c | 2014-05-29 18:57:12 +0300 | [diff] [blame] | 128 | NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM2), |
| 129 | CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); |
Lokesh Vutla | 8c80b19 | 2015-09-19 15:00:16 +0530 | [diff] [blame] | 130 | #endif |
Murali Karicheri | afee59c | 2014-05-29 18:57:12 +0300 | [diff] [blame] | 131 | |
Vitaly Andrianov | ef509b9 | 2014-04-04 13:16:53 -0400 | [diff] [blame] | 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | void reset_cpu(ulong addr) |
| 136 | { |
| 137 | volatile u32 *rstctrl = (volatile u32 *)(KS2_RSTCTRL); |
| 138 | u32 tmp; |
| 139 | |
| 140 | tmp = *rstctrl & KS2_RSTCTRL_MASK; |
| 141 | *rstctrl = tmp | KS2_RSTCTRL_KEY; |
| 142 | |
| 143 | *rstctrl &= KS2_RSTCTRL_SWRST; |
| 144 | |
| 145 | for (;;) |
| 146 | ; |
| 147 | } |
| 148 | |
| 149 | void enable_caches(void) |
| 150 | { |
| 151 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 152 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 153 | dcache_enable(); |
| 154 | #endif |
| 155 | } |
Lokesh Vutla | aeabe65 | 2015-07-28 14:16:42 +0530 | [diff] [blame] | 156 | |
| 157 | #if defined(CONFIG_DISPLAY_CPUINFO) |
| 158 | int print_cpuinfo(void) |
| 159 | { |
| 160 | u16 cpu = get_part_number(); |
| 161 | u8 rev = cpu_revision(); |
| 162 | |
| 163 | puts("CPU: "); |
| 164 | switch (cpu) { |
| 165 | case CPU_66AK2Hx: |
| 166 | puts("66AK2Hx SR"); |
| 167 | break; |
| 168 | case CPU_66AK2Lx: |
| 169 | puts("66AK2Lx SR"); |
| 170 | break; |
| 171 | case CPU_66AK2Ex: |
| 172 | puts("66AK2Ex SR"); |
| 173 | break; |
Lokesh Vutla | f11a328 | 2015-09-19 16:26:38 +0530 | [diff] [blame] | 174 | case CPU_66AK2Gx: |
| 175 | puts("66AK2Gx SR"); |
| 176 | break; |
Lokesh Vutla | aeabe65 | 2015-07-28 14:16:42 +0530 | [diff] [blame] | 177 | default: |
| 178 | puts("Unknown\n"); |
| 179 | } |
| 180 | |
| 181 | if (rev == 2) |
| 182 | puts("2.0\n"); |
| 183 | else if (rev == 1) |
| 184 | puts("1.1\n"); |
| 185 | else if (rev == 0) |
| 186 | puts("1.0\n"); |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | #endif |