Prepare v2023.10
[platform/kernel/u-boot.git] / board / freescale / t4rdb / t4240rdb.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2014 Freescale Semiconductor, Inc.
4  * Copyright 2023 NXP
5  */
6
7 #include <common.h>
8 #include <command.h>
9 #include <env.h>
10 #include <fdt_support.h>
11 #include <i2c.h>
12 #include <image.h>
13 #include <init.h>
14 #include <netdev.h>
15 #include <asm/global_data.h>
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>
23 #include <asm/fsl_liodn.h>
24 #include <clock_legacy.h>
25 #include <fm_eth.h>
26
27 #include "t4rdb.h"
28 #include "cpld.h"
29 #include "../common/vid.h"
30
31 DECLARE_GLOBAL_DATA_PTR;
32
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
40 int checkboard(void)
41 {
42         struct cpu_type *cpu = gd->arch.cpu;
43         u8 sw;
44
45         printf("Board: %sRDB, ", cpu->name);
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);
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 {
66         const unsigned int flashbase = CFG_SYS_FLASH_BASE;
67         int flash_esel = find_tlb_idx((void *)flashbase, 1);
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
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         }
86
87         set_tlb(1, flashbase, CFG_SYS_FLASH_BASE_PHYS,
88                 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
89                 0, flash_esel, BOOKE_PAGESZ_256M, 1);
90
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
98         pci_init();
99
100         return 0;
101 }
102
103 int misc_init_r(void)
104 {
105         return 0;
106 }
107
108 int ft_board_setup(void *blob, struct bd_info *bd)
109 {
110         phys_addr_t base;
111         phys_size_t size;
112
113         ft_cpu_setup(blob, bd);
114
115         base = env_get_bootm_low();
116         size = env_get_bootm_size();
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);
125         fsl_fdt_fixup_dr_usb(blob, bd);
126
127 #ifdef CONFIG_SYS_DPAA_FMAN
128 #ifndef CONFIG_DM_ETH
129         fdt_fixup_fman_ethernet(blob);
130 #endif
131         fdt_fixup_board_enet(blob);
132 #endif
133
134         return 0;
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 }
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 }