Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2013 Freescale Semiconductor, Inc. |
Camelia Groza | 3a359c5 | 2023-07-11 15:49:25 +0300 | [diff] [blame] | 4 | * Copyright 2023 NXP |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [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> |
Zhao Qiang | d468377 | 2015-08-28 10:31:50 +0800 | [diff] [blame] | 11 | #include <hwconfig.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> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 15 | #include <netdev.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 17 | #include <linux/compiler.h> |
| 18 | #include <asm/mmu.h> |
| 19 | #include <asm/processor.h> |
| 20 | #include <asm/cache.h> |
| 21 | #include <asm/immap_85xx.h> |
Zhao Qiang | d468377 | 2015-08-28 10:31:50 +0800 | [diff] [blame] | 22 | #include <asm/fsl_fdt.h> |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 23 | #include <asm/fsl_law.h> |
| 24 | #include <asm/fsl_serdes.h> |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 25 | #include <asm/fsl_liodn.h> |
Camelia Groza | 3a359c5 | 2023-07-11 15:49:25 +0300 | [diff] [blame] | 26 | #include <clock_legacy.h> |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 27 | #include <fm_eth.h> |
Tang Yuantian | 0023352 | 2014-11-21 11:17:16 +0800 | [diff] [blame] | 28 | #include "../common/sleep.h" |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 29 | #include "t104xrdb.h" |
Prabhakar Kushwaha | 55153d6 | 2014-04-03 16:50:05 +0530 | [diff] [blame] | 30 | #include "cpld.h" |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 31 | |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
Camelia Groza | 3a359c5 | 2023-07-11 15:49:25 +0300 | [diff] [blame] | 34 | #if CONFIG_IS_ENABLED(DM_SERIAL) |
| 35 | int get_serial_clock(void) |
| 36 | { |
| 37 | return get_bus_freq(0) / 2; |
| 38 | } |
| 39 | #endif |
| 40 | |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 41 | int checkboard(void) |
| 42 | { |
| 43 | struct cpu_type *cpu = gd->arch.cpu; |
Prabhakar Kushwaha | 55153d6 | 2014-04-03 16:50:05 +0530 | [diff] [blame] | 44 | u8 sw; |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 45 | |
Tom Rini | 8214b77 | 2022-12-02 16:42:51 -0500 | [diff] [blame] | 46 | #if defined(CONFIG_TARGET_T1042D4RDB) |
Priyanka Jain | 4b6067a | 2015-06-05 15:29:02 +0530 | [diff] [blame] | 47 | printf("Board: %sD4RDB\n", cpu->name); |
| 48 | #else |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 49 | printf("Board: %sRDB\n", cpu->name); |
Priyanka Jain | 4b6067a | 2015-06-05 15:29:02 +0530 | [diff] [blame] | 50 | #endif |
Prabhakar Kushwaha | 55153d6 | 2014-04-03 16:50:05 +0530 | [diff] [blame] | 51 | printf("Board rev: 0x%02x CPLD ver: 0x%02x, ", |
| 52 | CPLD_READ(hw_ver), CPLD_READ(sw_ver)); |
| 53 | |
| 54 | sw = CPLD_READ(flash_ctl_status); |
| 55 | sw = ((sw & CPLD_LBMAP_MASK) >> CPLD_LBMAP_SHIFT); |
| 56 | |
Priyanka Jain | f2af1c3 | 2015-07-30 10:20:18 +0530 | [diff] [blame] | 57 | printf("vBank: %d\n", sw); |
Prabhakar Kushwaha | 55153d6 | 2014-04-03 16:50:05 +0530 | [diff] [blame] | 58 | |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 59 | return 0; |
| 60 | } |
| 61 | |
Tang Yuantian | 0023352 | 2014-11-21 11:17:16 +0800 | [diff] [blame] | 62 | int board_early_init_f(void) |
| 63 | { |
| 64 | #if defined(CONFIG_DEEP_SLEEP) |
| 65 | if (is_warm_boot()) |
| 66 | fsl_dp_disable_console(); |
| 67 | #endif |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 72 | int board_early_init_r(void) |
| 73 | { |
Tom Rini | 65cc0e2 | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 74 | #ifdef CFG_SYS_FLASH_BASE |
| 75 | const unsigned int flashbase = CFG_SYS_FLASH_BASE; |
York Sun | 9d04568 | 2014-06-24 21:16:20 -0700 | [diff] [blame] | 76 | int flash_esel = find_tlb_idx((void *)flashbase, 1); |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Remap Boot flash region to caching-inhibited |
| 80 | * so that flash can be erased properly. |
| 81 | */ |
| 82 | |
| 83 | /* Flush d-cache and invalidate i-cache of any FLASH data */ |
| 84 | flush_dcache(); |
| 85 | invalidate_icache(); |
| 86 | |
York Sun | 9d04568 | 2014-06-24 21:16:20 -0700 | [diff] [blame] | 87 | if (flash_esel == -1) { |
| 88 | /* very unlikely unless something is messed up */ |
| 89 | puts("Error: Could not find TLB for FLASH BASE\n"); |
| 90 | flash_esel = 2; /* give our best effort to continue */ |
| 91 | } else { |
| 92 | /* invalidate existing TLB entry for flash */ |
| 93 | disable_tlb(flash_esel); |
| 94 | } |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 95 | |
Tom Rini | 65cc0e2 | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 96 | set_tlb(1, flashbase, CFG_SYS_FLASH_BASE_PHYS, |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 97 | MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, |
| 98 | 0, flash_esel, BOOKE_PAGESZ_256M, 1); |
| 99 | #endif |
Camelia Groza | 4e69a44 | 2023-07-11 15:49:24 +0300 | [diff] [blame] | 100 | |
| 101 | pci_init(); |
| 102 | |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | int misc_init_r(void) |
| 107 | { |
Tom Rini | 5155207 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 108 | ccsr_gur_t __iomem *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR); |
Priyanka Jain | 4b6067a | 2015-06-05 15:29:02 +0530 | [diff] [blame] | 109 | u32 srds_s1; |
| 110 | |
| 111 | srds_s1 = in_be32(&gur->rcwsr[4]) >> 24; |
| 112 | |
| 113 | printf("SERDES Reference : 0x%X\n", srds_s1); |
| 114 | |
| 115 | /* select SGMII*/ |
| 116 | if (srds_s1 == 0x86) |
| 117 | CPLD_WRITE(misc_ctl_status, CPLD_READ(misc_ctl_status) | |
| 118 | MISC_CTL_SG_SEL); |
| 119 | |
| 120 | /* select SGMII and Aurora*/ |
| 121 | if (srds_s1 == 0x8E) |
| 122 | CPLD_WRITE(misc_ctl_status, CPLD_READ(misc_ctl_status) | |
| 123 | MISC_CTL_SG_SEL | MISC_CTL_AURORA_SEL); |
| 124 | |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 128 | int ft_board_setup(void *blob, struct bd_info *bd) |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 129 | { |
| 130 | phys_addr_t base; |
| 131 | phys_size_t size; |
| 132 | |
| 133 | ft_cpu_setup(blob, bd); |
| 134 | |
Simon Glass | 723806c | 2017-08-03 12:22:15 -0600 | [diff] [blame] | 135 | base = env_get_bootm_low(); |
| 136 | size = env_get_bootm_size(); |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 137 | |
| 138 | fdt_fixup_memory(blob, (u64)base, (u64)size); |
| 139 | |
| 140 | #ifdef CONFIG_PCI |
| 141 | pci_of_setup(blob, bd); |
| 142 | #endif |
| 143 | |
| 144 | fdt_fixup_liodn(blob); |
| 145 | |
| 146 | #ifdef CONFIG_HAS_FSL_DR_USB |
Sriram Dash | a5c289b | 2016-09-16 17:12:15 +0530 | [diff] [blame] | 147 | fsl_fdt_fixup_dr_usb(blob, bd); |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 148 | #endif |
| 149 | |
| 150 | #ifdef CONFIG_SYS_DPAA_FMAN |
Madalin Bucur | 564637a | 2020-04-30 15:59:58 +0300 | [diff] [blame] | 151 | #ifndef CONFIG_DM_ETH |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 152 | fdt_fixup_fman_ethernet(blob); |
| 153 | #endif |
Madalin Bucur | 564637a | 2020-04-30 15:59:58 +0300 | [diff] [blame] | 154 | #endif |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 155 | |
Zhao Qiang | d468377 | 2015-08-28 10:31:50 +0800 | [diff] [blame] | 156 | if (hwconfig("qe-tdm")) |
| 157 | fdt_del_diu(blob); |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 158 | return 0; |
Priyanka Jain | 062ef1a | 2013-10-18 17:19:06 +0530 | [diff] [blame] | 159 | } |