blob: 5cacfd273803e3140994b3af06155076b7398a29 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Camelia Groza0d2518e2023-07-11 15:49:20 +03004 * Copyright 2023 NXP
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +08005 */
6
Tom Rinidec7ea02024-05-20 13:35:03 -06007#include <config.h>
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +08008#include <command.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06009#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070010#include <fdt_support.h>
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +080011#include <i2c.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060012#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +080014#include <netdev.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +080016#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 Lan8e4f3ff2014-04-14 18:42:06 +080023#include <asm/fsl_liodn.h>
Camelia Groza0d2518e2023-07-11 15:49:20 +030024#include <clock_legacy.h>
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +080025#include <fm_eth.h>
26
27#include "t4rdb.h"
Chunhe Lanc3eb88d2014-09-12 14:47:09 +080028#include "cpld.h"
Ying Zhangff779052016-01-22 12:15:13 +080029#include "../common/vid.h"
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +080030
31DECLARE_GLOBAL_DATA_PTR;
32
Camelia Groza0d2518e2023-07-11 15:49:20 +030033#if CONFIG_IS_ENABLED(DM_SERIAL)
34int get_serial_clock(void)
35{
36 return get_bus_freq(0) / 2;
37}
38#endif
39
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +080040int checkboard(void)
41{
42 struct cpu_type *cpu = gd->arch.cpu;
Chunhe Lanc3eb88d2014-09-12 14:47:09 +080043 u8 sw;
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +080044
45 printf("Board: %sRDB, ", cpu->name);
Chunhe Lanc3eb88d2014-09-12 14:47:09 +080046 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 Lan8e4f3ff2014-04-14 18:42:06 +080056
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
64int board_early_init_r(void)
65{
Tom Rini6a5dccc2022-11-16 13:10:41 -050066 const unsigned int flashbase = CFG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -070067 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +080068
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 Sun220c3462014-06-24 21:16:20 -070078 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 Lan8e4f3ff2014-04-14 18:42:06 +080086
Tom Rini6a5dccc2022-11-16 13:10:41 -050087 set_tlb(1, flashbase, CFG_SYS_FLASH_BASE_PHYS,
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +080088 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
89 0, flash_esel, BOOKE_PAGESZ_256M, 1);
90
Ying Zhangff779052016-01-22 12:15:13 +080091 /*
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 Groza14f4dc82023-07-11 15:49:19 +030098 pci_init();
99
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +0800100 return 0;
101}
102
103int misc_init_r(void)
104{
105 return 0;
106}
107
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900108int ft_board_setup(void *blob, struct bd_info *bd)
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +0800109{
110 phys_addr_t base;
111 phys_size_t size;
112
113 ft_cpu_setup(blob, bd);
114
Simon Glassda1a1342017-08-03 12:22:15 -0600115 base = env_get_bootm_low();
116 size = env_get_bootm_size();
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +0800117
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 Dash9fd465c2016-09-16 17:12:15 +0530125 fsl_fdt_fixup_dr_usb(blob, bd);
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +0800126
127#ifdef CONFIG_SYS_DPAA_FMAN
Madalin Bucur70848512020-04-30 15:59:58 +0300128#ifndef CONFIG_DM_ETH
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +0800129 fdt_fixup_fman_ethernet(blob);
Madalin Bucur70848512020-04-30 15:59:58 +0300130#endif
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +0800131 fdt_fixup_board_enet(blob);
132#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600133
134 return 0;
Chunhe Lan8e4f3ff2014-04-14 18:42:06 +0800135}
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 */
149void 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 Singhff47bb72021-08-10 11:20:11 +0530165
166ulong *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}