Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Freescale Semiconductor, Inc. |
Camelia Groza | a325e7e | 2023-07-11 15:49:20 +0300 | [diff] [blame] | 4 | * Copyright 2023 NXP |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <command.h> |
Simon Glass | 7b51b57 | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 9 | #include <env.h> |
Simon Glass | 807765b | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 10 | #include <fdt_support.h> |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 11 | #include <i2c.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 12 | #include <image.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 13 | #include <init.h> |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 14 | #include <netdev.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 16 | #include <linux/compiler.h> |
| 17 | #include <asm/mmu.h> |
| 18 | #include <asm/processor.h> |
| 19 | #include <asm/cache.h> |
| 20 | #include <asm/immap_85xx.h> |
| 21 | #include <asm/fsl_law.h> |
| 22 | #include <asm/fsl_serdes.h> |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 23 | #include <asm/fsl_liodn.h> |
Camelia Groza | a325e7e | 2023-07-11 15:49:20 +0300 | [diff] [blame] | 24 | #include <clock_legacy.h> |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 25 | #include <fm_eth.h> |
| 26 | |
| 27 | #include "t4rdb.h" |
Chunhe Lan | ab06b23 | 2014-09-12 14:47:09 +0800 | [diff] [blame] | 28 | #include "cpld.h" |
Ying Zhang | 2f66a82 | 2016-01-22 12:15:13 +0800 | [diff] [blame] | 29 | #include "../common/vid.h" |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
Camelia Groza | a325e7e | 2023-07-11 15:49:20 +0300 | [diff] [blame] | 33 | #if CONFIG_IS_ENABLED(DM_SERIAL) |
| 34 | int get_serial_clock(void) |
| 35 | { |
| 36 | return get_bus_freq(0) / 2; |
| 37 | } |
| 38 | #endif |
| 39 | |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 40 | int checkboard(void) |
| 41 | { |
| 42 | struct cpu_type *cpu = gd->arch.cpu; |
Chunhe Lan | ab06b23 | 2014-09-12 14:47:09 +0800 | [diff] [blame] | 43 | u8 sw; |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 44 | |
| 45 | printf("Board: %sRDB, ", cpu->name); |
Chunhe Lan | ab06b23 | 2014-09-12 14:47:09 +0800 | [diff] [blame] | 46 | printf("Board rev: 0x%02x CPLD ver: 0x%02x%02x, ", |
| 47 | CPLD_READ(hw_ver), CPLD_READ(sw_maj_ver), CPLD_READ(sw_min_ver)); |
| 48 | |
| 49 | sw = CPLD_READ(vbank); |
| 50 | sw = sw & CPLD_BANK_SEL_MASK; |
| 51 | |
| 52 | if (sw <= 7) |
| 53 | printf("vBank: %d\n", sw); |
| 54 | else |
| 55 | printf("Unsupported Bank=%x\n", sw); |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 56 | |
| 57 | puts("SERDES Reference Clocks:\n"); |
| 58 | printf(" SERDES1=100MHz SERDES2=156.25MHz\n" |
| 59 | " SERDES3=100MHz SERDES4=100MHz\n"); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | int board_early_init_r(void) |
| 65 | { |
Tom Rini | 65cc0e2 | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 66 | const unsigned int flashbase = CFG_SYS_FLASH_BASE; |
York Sun | 9d04568 | 2014-06-24 21:16:20 -0700 | [diff] [blame] | 67 | int flash_esel = find_tlb_idx((void *)flashbase, 1); |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * Remap Boot flash + PROMJET region to caching-inhibited |
| 71 | * so that flash can be erased properly. |
| 72 | */ |
| 73 | |
| 74 | /* Flush d-cache and invalidate i-cache of any FLASH data */ |
| 75 | flush_dcache(); |
| 76 | invalidate_icache(); |
| 77 | |
York Sun | 9d04568 | 2014-06-24 21:16:20 -0700 | [diff] [blame] | 78 | if (flash_esel == -1) { |
| 79 | /* very unlikely unless something is messed up */ |
| 80 | puts("Error: Could not find TLB for FLASH BASE\n"); |
| 81 | flash_esel = 2; /* give our best effort to continue */ |
| 82 | } else { |
| 83 | /* invalidate existing TLB entry for flash + promjet */ |
| 84 | disable_tlb(flash_esel); |
| 85 | } |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 86 | |
Tom Rini | 65cc0e2 | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 87 | set_tlb(1, flashbase, CFG_SYS_FLASH_BASE_PHYS, |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 88 | MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, |
| 89 | 0, flash_esel, BOOKE_PAGESZ_256M, 1); |
| 90 | |
Ying Zhang | 2f66a82 | 2016-01-22 12:15:13 +0800 | [diff] [blame] | 91 | /* |
| 92 | * Adjust core voltage according to voltage ID |
| 93 | * This function changes I2C mux to channel 2. |
| 94 | */ |
| 95 | if (adjust_vdd(0)) |
| 96 | printf("Warning: Adjusting core voltage failed.\n"); |
| 97 | |
Camelia Groza | baa807f | 2023-07-11 15:49:19 +0300 | [diff] [blame] | 98 | pci_init(); |
| 99 | |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | int misc_init_r(void) |
| 104 | { |
| 105 | return 0; |
| 106 | } |
| 107 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 108 | int ft_board_setup(void *blob, struct bd_info *bd) |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 109 | { |
| 110 | phys_addr_t base; |
| 111 | phys_size_t size; |
| 112 | |
| 113 | ft_cpu_setup(blob, bd); |
| 114 | |
Simon Glass | 723806c | 2017-08-03 12:22:15 -0600 | [diff] [blame] | 115 | base = env_get_bootm_low(); |
| 116 | size = env_get_bootm_size(); |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 117 | |
| 118 | fdt_fixup_memory(blob, (u64)base, (u64)size); |
| 119 | |
| 120 | #ifdef CONFIG_PCI |
| 121 | pci_of_setup(blob, bd); |
| 122 | #endif |
| 123 | |
| 124 | fdt_fixup_liodn(blob); |
Sriram Dash | a5c289b | 2016-09-16 17:12:15 +0530 | [diff] [blame] | 125 | fsl_fdt_fixup_dr_usb(blob, bd); |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 126 | |
| 127 | #ifdef CONFIG_SYS_DPAA_FMAN |
Madalin Bucur | 564637a | 2020-04-30 15:59:58 +0300 | [diff] [blame] | 128 | #ifndef CONFIG_DM_ETH |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 129 | fdt_fixup_fman_ethernet(blob); |
Madalin Bucur | 564637a | 2020-04-30 15:59:58 +0300 | [diff] [blame] | 130 | #endif |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 131 | fdt_fixup_board_enet(blob); |
| 132 | #endif |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 133 | |
| 134 | return 0; |
Chunhe Lan | 0b2e13d | 2014-04-14 18:42:06 +0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* |
| 138 | * This function is called by bdinfo to print detail board information. |
| 139 | * As an exmaple for future board, we organize the messages into |
| 140 | * several sections. If applicable, the message is in the format of |
| 141 | * <name> = <value> |
| 142 | * It should aligned with normal output of bdinfo command. |
| 143 | * |
| 144 | * Voltage: Core, DDR and another configurable voltages |
| 145 | * Clock : Critical clocks which are not printed already |
| 146 | * RCW : RCW source if not printed already |
| 147 | * Misc : Other important information not in above catagories |
| 148 | */ |
| 149 | void board_detail(void) |
| 150 | { |
| 151 | int rcwsrc; |
| 152 | |
| 153 | /* RCW section SW3[4] */ |
| 154 | rcwsrc = 0x0; |
| 155 | puts("RCW source = "); |
| 156 | switch (rcwsrc & 0x1) { |
| 157 | case 0x1: |
| 158 | puts("SDHC/eMMC\n"); |
| 159 | break; |
| 160 | default: |
| 161 | puts("I2C normal addressing\n"); |
| 162 | break; |
| 163 | } |
| 164 | } |
Kuldeep Singh | 3bd5ea5 | 2021-08-10 11:20:11 +0530 | [diff] [blame] | 165 | |
| 166 | ulong *cs4340_get_fw_addr(void) |
| 167 | { |
| 168 | ulong cortina_fw_addr = CONFIG_CORTINA_FW_ADDR; |
| 169 | |
| 170 | #ifdef CONFIG_SYS_CORTINA_FW_IN_NOR |
| 171 | u8 sw; |
| 172 | |
| 173 | sw = CPLD_READ(vbank); |
| 174 | sw = sw & CPLD_BANK_SEL_MASK; |
| 175 | |
| 176 | if (sw == 0) |
| 177 | cortina_fw_addr = CORTINA_FW_ADDR_IFCNOR; |
| 178 | else if (sw == 4) |
| 179 | cortina_fw_addr = CORTINA_FW_ADDR_IFCNOR_ALTBANK; |
| 180 | #endif |
| 181 | |
| 182 | return (ulong *)cortina_fw_addr; |
| 183 | } |