blob: 2cd651b943fbf5876209cf3d38fafbb06bc88180 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +05302/*
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +05303 * Copyright 2017-2018 NXP
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +05304 */
5
6#include <common.h>
Simon Glass807765b2019-12-28 10:44:54 -07007#include <fdt_support.h>
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +05308#include <i2c.h>
Simon Glass90526e92020-05-10 11:39:56 -06009#include <asm/cache.h>
Simon Glass691d7192020-05-10 11:40:02 -060010#include <init.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +053012#include <asm/io.h>
13#include <asm/arch/clock.h>
14#include <asm/arch/fsl_serdes.h>
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +053015#ifdef CONFIG_FSL_LS_PPA
16#include <asm/arch/ppa.h>
17#endif
York Sun4961eaf2017-03-06 09:02:34 -080018#include <asm/arch/mmu.h>
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +053019#include <asm/arch/soc.h>
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +053020#include <fsl_esdhc.h>
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +053021#include <hwconfig.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060022#include <env_internal.h>
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +053023#include <fsl_mmdc.h>
24#include <netdev.h>
Vinitha V Pillai2d91b532018-05-23 11:03:31 +053025#include <fsl_sec.h>
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +053026
27DECLARE_GLOBAL_DATA_PTR;
28
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +053029static inline int get_board_version(void)
30{
Pramod Kumar1deae0c2018-08-14 09:49:55 +053031 uint32_t val;
32#ifdef CONFIG_TARGET_LS1012AFRDM
33 val = 0;
34#else
35 struct ccsr_gpio *pgpio = (void *)(GPIO2_BASE_ADDR);
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +053036
Pramod Kumar1deae0c2018-08-14 09:49:55 +053037 val = in_be32(&pgpio->gpdat) & BOARD_REV_MASK;/*Get GPIO2 11,12,14*/
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +053038
Pramod Kumar1deae0c2018-08-14 09:49:55 +053039#endif
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +053040 return val;
41}
42
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +053043int checkboard(void)
44{
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +053045#ifdef CONFIG_TARGET_LS1012AFRDM
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +053046 puts("Board: LS1012AFRDM ");
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +053047#else
48 int rev;
49
50 rev = get_board_version();
51
52 puts("Board: FRWY-LS1012A ");
53
54 puts("Version");
55
56 switch (rev) {
Pramod Kumar1deae0c2018-08-14 09:49:55 +053057 case BOARD_REV_A_B:
58 puts(": RevA/B ");
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +053059 break;
Pramod Kumar1deae0c2018-08-14 09:49:55 +053060 case BOARD_REV_C:
61 puts(": RevC ");
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +053062 break;
63 default:
64 puts(": unknown");
65 break;
66 }
67#endif
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +053068
69 return 0;
70}
71
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +053072#ifdef CONFIG_TARGET_LS1012AFRWY
73int esdhc_status_fixup(void *blob, const char *compat)
74{
75 char esdhc0_path[] = "/soc/esdhc@1560000";
76 char esdhc1_path[] = "/soc/esdhc@1580000";
77
78 do_fixup_by_path(blob, esdhc0_path, "status", "okay",
79 sizeof("okay"), 1);
80
81 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
82 sizeof("disabled"), 1);
83 return 0;
84}
85#endif
86
Rajesh Bhagat7f91b652018-11-05 18:03:08 +000087#ifdef CONFIG_TFABOOT
88int dram_init(void)
89{
90#ifdef CONFIG_TARGET_LS1012AFRWY
91 int board_rev;
92#endif
93
94 gd->ram_size = tfa_get_dram_size();
95
96 if (!gd->ram_size) {
97#ifdef CONFIG_TARGET_LS1012AFRWY
98 board_rev = get_board_version();
99
100 if (board_rev & BOARD_REV_C)
101 gd->ram_size = SYS_SDRAM_SIZE_1024;
102 else
103 gd->ram_size = SYS_SDRAM_SIZE_512;
104#else
105 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
106#endif
107 }
108 return 0;
109}
110#else
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +0530111int dram_init(void)
112{
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +0530113#ifdef CONFIG_TARGET_LS1012AFRWY
114 int board_rev;
115#endif
116 struct fsl_mmdc_info mparam = {
York Sun1fdcc8d2016-09-26 08:09:25 -0700117 0x04180000, /* mdctl */
118 0x00030035, /* mdpdc */
119 0x12554000, /* mdotc */
120 0xbabf7954, /* mdcfg0 */
121 0xdb328f64, /* mdcfg1 */
122 0x01ff00db, /* mdcfg2 */
123 0x00001680, /* mdmisc */
124 0x0f3c8000, /* mdref */
125 0x00002000, /* mdrwd */
126 0x00bf1023, /* mdor */
127 0x0000003f, /* mdasp */
128 0x0000022a, /* mpodtctrl */
129 0xa1390003, /* mpzqhwctrl */
130 };
131
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +0530132#ifdef CONFIG_TARGET_LS1012AFRWY
133 board_rev = get_board_version();
134
Pramod Kumar1deae0c2018-08-14 09:49:55 +0530135 if (board_rev == BOARD_REV_C) {
Bhaskar Upadhaya9629ccd2018-05-23 11:03:30 +0530136 mparam.mdctl = 0x05180000;
137 gd->ram_size = SYS_SDRAM_SIZE_1024;
138 } else {
139 gd->ram_size = SYS_SDRAM_SIZE_512;
140 }
141#else
142 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
143#endif
York Sun1fdcc8d2016-09-26 08:09:25 -0700144 mmdc_init(&mparam);
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +0530145
York Sun4961eaf2017-03-06 09:02:34 -0800146#if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
147 /* This will break-before-make MMU for DDR */
148 update_early_mmu_table();
149#endif
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +0530150
151 return 0;
152}
Rajesh Bhagat7f91b652018-11-05 18:03:08 +0000153#endif
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +0530154
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +0530155int board_early_init_f(void)
156{
157 fsl_lsch2_early_init_f();
158
159 return 0;
160}
161
162int board_init(void)
163{
Ashish Kumar63b23162017-08-11 11:09:14 +0530164 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
165 CONFIG_SYS_CCI400_OFFSET);
166
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +0530167 /*
168 * Set CCI-400 control override register to enable barrier
169 * transaction
170 */
Rajesh Bhagat7f91b652018-11-05 18:03:08 +0000171 if (current_el() == 3)
172 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +0530173
174#ifdef CONFIG_ENV_IS_NOWHERE
175 gd->env_addr = (ulong)&default_environment[0];
176#endif
177
Vinitha V Pillai2d91b532018-05-23 11:03:31 +0530178#ifdef CONFIG_FSL_CAAM
179 sec_init();
180#endif
181
Prabhakar Kushwaha5b404be2017-01-30 17:05:35 +0530182#ifdef CONFIG_FSL_LS_PPA
183 ppa_init();
184#endif
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +0530185 return 0;
186}
187
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900188int ft_board_setup(void *blob, struct bd_info *bd)
Prabhakar Kushwahaff78aa22016-06-03 18:41:36 +0530189{
190 arch_fixup_fdt(blob);
191
192 ft_cpu_setup(blob, bd);
193
194 return 0;
195}