blob: f505e82fb963967b942eac14702f2774efbdc702 [file] [log] [blame]
Priyanka Jainfd45ca02018-11-28 13:04:27 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
Wasim Khan4c4c1f82021-06-17 09:12:59 +02003 * Copyright 2018-2021 NXP
Priyanka Jainfd45ca02018-11-28 13:04:27 +00004 */
5
6#include <common.h>
Simon Glass85d65312019-12-28 10:44:58 -07007#include <clock_legacy.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +00008#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +000011#include <dm/platform_data/serial_pl01x.h>
12#include <i2c.h>
13#include <malloc.h>
14#include <errno.h>
15#include <netdev.h>
16#include <fsl_ddr.h>
17#include <fsl_sec.h>
18#include <asm/io.h>
19#include <fdt_support.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060020#include <linux/bitops.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +000021#include <linux/libfdt.h>
Yangbo Lue1a3cc72020-06-17 18:08:59 +080022#include <linux/delay.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +000023#include <fsl-mc/fsl_mc.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060024#include <env_internal.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +000025#include <efi_loader.h>
26#include <asm/arch/mmu.h>
27#include <hwconfig.h>
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +000028#include <asm/arch/clock.h>
29#include <asm/arch/config.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +000030#include <asm/arch/fsl_serdes.h>
31#include <asm/arch/soc.h>
Stephen Carlson70b1e8c2021-06-22 16:43:03 -070032#include "../common/i2c_mux.h"
33
Priyanka Jainfd45ca02018-11-28 13:04:27 +000034#include "../common/qixis.h"
35#include "../common/vid.h"
36#include <fsl_immap.h>
Laurentiu Tudor7085d072019-10-18 09:01:55 +000037#include <asm/arch-fsl-layerscape/fsl_icid.h>
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +053038#include "lx2160a.h"
Priyanka Jainfd45ca02018-11-28 13:04:27 +000039
Meenakshi Aggarwal936a68d2018-11-30 22:32:12 +053040#ifdef CONFIG_EMC2305
41#include "../common/emc2305.h"
42#endif
43
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +053044#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +000045#define CFG_MUX_I2C_SDHC(reg, value) ((reg & 0x3f) | value)
46#define SET_CFG_MUX1_SDHC1_SDHC(reg) (reg & 0x3f)
47#define SET_CFG_MUX2_SDHC1_SPI(reg, value) ((reg & 0xcf) | value)
48#define SET_CFG_MUX3_SDHC1_SPI(reg, value) ((reg & 0xf8) | value)
49#define SET_CFG_MUX_SDHC2_DSPI(reg, value) ((reg & 0xf8) | value)
50#define SET_CFG_MUX1_SDHC1_DSPI(reg, value) ((reg & 0x3f) | value)
51#define SDHC1_BASE_PMUX_DSPI 2
52#define SDHC2_BASE_PMUX_DSPI 2
53#define IIC5_PMUX_SPI3 3
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +053054#endif /* CONFIG_TARGET_LX2160AQDS or CONFIG_TARGET_LX2162AQDS */
Pankaj Bansal338baa32019-02-08 10:29:58 +000055
Priyanka Jainfd45ca02018-11-28 13:04:27 +000056DECLARE_GLOBAL_DATA_PTR;
57
Simon Glassb75b15b2020-12-03 16:55:23 -070058static struct pl01x_serial_plat serial0 = {
Priyanka Jainfd45ca02018-11-28 13:04:27 +000059#if CONFIG_CONS_INDEX == 0
60 .base = CONFIG_SYS_SERIAL0,
61#elif CONFIG_CONS_INDEX == 1
62 .base = CONFIG_SYS_SERIAL1,
63#else
64#error "Unsupported console index value."
65#endif
66 .type = TYPE_PL011,
67};
68
Simon Glass1d8364a2020-12-28 20:34:54 -070069U_BOOT_DRVINFO(nxp_serial0) = {
Priyanka Jainfd45ca02018-11-28 13:04:27 +000070 .name = "serial_pl01x",
Simon Glass71fa5b42020-12-03 16:55:18 -070071 .plat = &serial0,
Priyanka Jainfd45ca02018-11-28 13:04:27 +000072};
73
Simon Glassb75b15b2020-12-03 16:55:23 -070074static struct pl01x_serial_plat serial1 = {
Priyanka Jainfd45ca02018-11-28 13:04:27 +000075 .base = CONFIG_SYS_SERIAL1,
76 .type = TYPE_PL011,
77};
78
Simon Glass1d8364a2020-12-28 20:34:54 -070079U_BOOT_DRVINFO(nxp_serial1) = {
Priyanka Jainfd45ca02018-11-28 13:04:27 +000080 .name = "serial_pl01x",
Simon Glass71fa5b42020-12-03 16:55:18 -070081 .plat = &serial1,
Priyanka Jainfd45ca02018-11-28 13:04:27 +000082};
83
Priyanka Jainfd45ca02018-11-28 13:04:27 +000084static void uart_get_clock(void)
85{
86 serial0.clock = get_serial_clock();
87 serial1.clock = get_serial_clock();
88}
89
90int board_early_init_f(void)
91{
92#ifdef CONFIG_SYS_I2C_EARLY_INIT
93 i2c_early_init_f();
94#endif
95 /* get required clock for UART IP */
96 uart_get_clock();
97
Meenakshi Aggarwal936a68d2018-11-30 22:32:12 +053098#ifdef CONFIG_EMC2305
Stephen Carlson70b1e8c2021-06-22 16:43:03 -070099 select_i2c_ch_pca9547(I2C_MUX_CH_EMC2305, 0);
Wasim Khan14241982020-08-27 19:13:34 +0530100 emc2305_init(I2C_EMC2305_ADDR);
101 set_fan_speed(I2C_EMC2305_PWM, I2C_EMC2305_ADDR);
Stephen Carlson70b1e8c2021-06-22 16:43:03 -0700102 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Meenakshi Aggarwal936a68d2018-11-30 22:32:12 +0530103#endif
104
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000105 fsl_lsch3_early_init_f();
106 return 0;
107}
108
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000109#ifdef CONFIG_OF_BOARD_FIXUP
110int board_fix_fdt(void *fdt)
111{
112 char *reg_names, *reg_name;
113 int names_len, old_name_len, new_name_len, remaining_names_len;
114 struct str_map {
115 char *old_str;
116 char *new_str;
117 } reg_names_map[] = {
Pankaj Bansal58ace212019-11-20 09:12:47 +0000118 { "ccsr", "dbi" },
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000119 { "pf_ctrl", "ctrl" }
120 };
Pankaj Bansal844e0ed2020-01-15 05:57:00 +0000121 int off = -1, i = 0;
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000122
123 if (IS_SVR_REV(get_svr(), 1, 0))
124 return 0;
125
126 off = fdt_node_offset_by_compatible(fdt, -1, "fsl,lx2160a-pcie");
127 while (off != -FDT_ERR_NOTFOUND) {
128 fdt_setprop(fdt, off, "compatible", "fsl,ls-pcie",
129 strlen("fsl,ls-pcie") + 1);
130
131 reg_names = (char *)fdt_getprop(fdt, off, "reg-names",
132 &names_len);
133 if (!reg_names)
134 continue;
135
136 reg_name = reg_names;
137 remaining_names_len = names_len - (reg_name - reg_names);
Vikas Singh1fe634a2020-02-12 13:47:09 +0530138 i = 0;
Pankaj Bansal844e0ed2020-01-15 05:57:00 +0000139 while ((i < ARRAY_SIZE(reg_names_map)) && remaining_names_len) {
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000140 old_name_len = strlen(reg_names_map[i].old_str);
141 new_name_len = strlen(reg_names_map[i].new_str);
142 if (memcmp(reg_name, reg_names_map[i].old_str,
143 old_name_len) == 0) {
144 /* first only leave required bytes for new_str
145 * and copy rest of the string after it
146 */
147 memcpy(reg_name + new_name_len,
148 reg_name + old_name_len,
149 remaining_names_len - old_name_len);
150 /* Now copy new_str */
151 memcpy(reg_name, reg_names_map[i].new_str,
152 new_name_len);
153 names_len -= old_name_len;
154 names_len += new_name_len;
Pankaj Bansal844e0ed2020-01-15 05:57:00 +0000155 i++;
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000156 }
157
158 reg_name = memchr(reg_name, '\0', remaining_names_len);
159 if (!reg_name)
160 break;
161
162 reg_name += 1;
163
164 remaining_names_len = names_len -
165 (reg_name - reg_names);
166 }
167
168 fdt_setprop(fdt, off, "reg-names", reg_names, names_len);
169 off = fdt_node_offset_by_compatible(fdt, off,
170 "fsl,lx2160a-pcie");
171 }
172
173 return 0;
174}
175#endif
176
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530177#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000178void esdhc_dspi_status_fixup(void *blob)
179{
180 const char esdhc0_path[] = "/soc/esdhc@2140000";
181 const char esdhc1_path[] = "/soc/esdhc@2150000";
Xiaowei Bao3a13e292020-01-08 14:29:54 +0800182 const char dspi0_path[] = "/soc/spi@2100000";
183 const char dspi1_path[] = "/soc/spi@2110000";
184 const char dspi2_path[] = "/soc/spi@2120000";
Pankaj Bansal338baa32019-02-08 10:29:58 +0000185
186 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
187 u32 sdhc1_base_pmux;
188 u32 sdhc2_base_pmux;
189 u32 iic5_pmux;
190
191 /* Check RCW field sdhc1_base_pmux to enable/disable
192 * esdhc0/dspi0 DT node
193 */
194 sdhc1_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
195 & FSL_CHASSIS3_SDHC1_BASE_PMUX_MASK;
196 sdhc1_base_pmux >>= FSL_CHASSIS3_SDHC1_BASE_PMUX_SHIFT;
197
198 if (sdhc1_base_pmux == SDHC1_BASE_PMUX_DSPI) {
199 do_fixup_by_path(blob, dspi0_path, "status", "okay",
200 sizeof("okay"), 1);
201 do_fixup_by_path(blob, esdhc0_path, "status", "disabled",
202 sizeof("disabled"), 1);
203 } else {
204 do_fixup_by_path(blob, esdhc0_path, "status", "okay",
205 sizeof("okay"), 1);
206 do_fixup_by_path(blob, dspi0_path, "status", "disabled",
207 sizeof("disabled"), 1);
208 }
209
210 /* Check RCW field sdhc2_base_pmux to enable/disable
211 * esdhc1/dspi1 DT node
212 */
213 sdhc2_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR13_REGSR - 1])
214 & FSL_CHASSIS3_SDHC2_BASE_PMUX_MASK;
215 sdhc2_base_pmux >>= FSL_CHASSIS3_SDHC2_BASE_PMUX_SHIFT;
216
217 if (sdhc2_base_pmux == SDHC2_BASE_PMUX_DSPI) {
218 do_fixup_by_path(blob, dspi1_path, "status", "okay",
219 sizeof("okay"), 1);
220 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
221 sizeof("disabled"), 1);
222 } else {
223 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
224 sizeof("okay"), 1);
225 do_fixup_by_path(blob, dspi1_path, "status", "disabled",
226 sizeof("disabled"), 1);
227 }
228
229 /* Check RCW field IIC5 to enable dspi2 DT node */
230 iic5_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
231 & FSL_CHASSIS3_IIC5_PMUX_MASK;
232 iic5_pmux >>= FSL_CHASSIS3_IIC5_PMUX_SHIFT;
233
Xiaowei Bao3a13e292020-01-08 14:29:54 +0800234 if (iic5_pmux == IIC5_PMUX_SPI3)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000235 do_fixup_by_path(blob, dspi2_path, "status", "okay",
236 sizeof("okay"), 1);
Xiaowei Bao3a13e292020-01-08 14:29:54 +0800237 else
238 do_fixup_by_path(blob, dspi2_path, "status", "disabled",
239 sizeof("disabled"), 1);
Pankaj Bansal338baa32019-02-08 10:29:58 +0000240}
241#endif
242
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000243int esdhc_status_fixup(void *blob, const char *compat)
244{
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530245#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000246 /* Enable esdhc and dspi DT nodes based on RCW fields */
247 esdhc_dspi_status_fixup(blob);
248#else
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000249 /* Enable both esdhc DT nodes for LX2160ARDB */
250 do_fixup_by_compat(blob, compat, "status", "okay",
251 sizeof("okay"), 1);
Pankaj Bansal338baa32019-02-08 10:29:58 +0000252#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000253 return 0;
254}
255
256#if defined(CONFIG_VID)
257int i2c_multiplexer_select_vid_channel(u8 channel)
258{
Stephen Carlson70b1e8c2021-06-22 16:43:03 -0700259 return select_i2c_ch_pca9547(channel, 0);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000260}
261
Priyanka Jaine94c3242019-02-04 06:32:36 +0000262int init_func_vid(void)
263{
Meenakshi Aggarwalcdc12002020-02-26 16:46:48 +0530264 int set_vid;
265
266 if (IS_SVR_REV(get_svr(), 1, 0))
267 set_vid = adjust_vdd(800);
268 else
269 set_vid = adjust_vdd(0);
270
271 if (set_vid < 0)
Priyanka Jaine94c3242019-02-04 06:32:36 +0000272 printf("core voltage not adjusted\n");
273
274 return 0;
275}
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000276#endif
277
278int checkboard(void)
279{
280 enum boot_src src = get_boot_src();
281 char buf[64];
282 u8 sw;
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530283#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000284 int clock;
285 static const char *const freq[] = {"100", "125", "156.25",
286 "161.13", "322.26", "", "", "",
287 "", "", "", "", "", "", "",
288 "100 separate SSCG"};
289#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000290
291 cpu_name(buf);
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530292#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000293 printf("Board: %s-QDS, ", buf);
294#else
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000295 printf("Board: %s-RDB, ", buf);
Pankaj Bansal338baa32019-02-08 10:29:58 +0000296#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000297
298 sw = QIXIS_READ(arch);
299 printf("Board version: %c, boot from ", (sw & 0xf) - 1 + 'A');
300
301 if (src == BOOT_SOURCE_SD_MMC) {
302 puts("SD\n");
Meenakshi Aggarwal74bd4992020-01-23 17:55:10 +0530303 } else if (src == BOOT_SOURCE_SD_MMC2) {
304 puts("eMMC\n");
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000305 } else {
306 sw = QIXIS_READ(brdcfg[0]);
307 sw = (sw >> QIXIS_XMAP_SHIFT) & QIXIS_XMAP_MASK;
308 switch (sw) {
309 case 0:
310 case 4:
311 puts("FlexSPI DEV#0\n");
312 break;
313 case 1:
314 puts("FlexSPI DEV#1\n");
315 break;
316 case 2:
317 case 3:
318 puts("FlexSPI EMU\n");
319 break;
320 default:
321 printf("invalid setting, xmap: %d\n", sw);
322 break;
323 }
324 }
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530325#if defined(CONFIG_TARGET_LX2160ARDB)
326 printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
327
328 puts("SERDES1 Reference: Clock1 = 161.13MHz Clock2 = 161.13MHz\n");
329 puts("SERDES2 Reference: Clock1 = 100MHz Clock2 = 100MHz\n");
330 puts("SERDES3 Reference: Clock1 = 100MHz Clock2 = 100MHz\n");
331#else
Pankaj Bansal338baa32019-02-08 10:29:58 +0000332 printf("FPGA: v%d (%s), build %d",
333 (int)QIXIS_READ(scver), qixis_read_tag(buf),
334 (int)qixis_read_minor());
335 /* the timestamp string contains "\n" at the end */
336 printf(" on %s", qixis_read_time(buf));
337
338 puts("SERDES1 Reference : ");
339 sw = QIXIS_READ(brdcfg[2]);
340 clock = sw >> 4;
341 printf("Clock1 = %sMHz ", freq[clock]);
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530342#if defined(CONFIG_TARGET_LX2160AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000343 clock = sw & 0x0f;
344 printf("Clock2 = %sMHz", freq[clock]);
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530345#endif
Pankaj Bansal338baa32019-02-08 10:29:58 +0000346 sw = QIXIS_READ(brdcfg[3]);
347 puts("\nSERDES2 Reference : ");
348 clock = sw >> 4;
349 printf("Clock1 = %sMHz ", freq[clock]);
350 clock = sw & 0x0f;
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530351 printf("Clock2 = %sMHz\n", freq[clock]);
352#if defined(CONFIG_TARGET_LX2160AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000353 sw = QIXIS_READ(brdcfg[12]);
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530354 puts("SERDES3 Reference : ");
Pankaj Bansal338baa32019-02-08 10:29:58 +0000355 clock = sw >> 4;
356 printf("Clock1 = %sMHz Clock2 = %sMHz\n", freq[clock], freq[clock]);
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530357#endif
Pankaj Bansal338baa32019-02-08 10:29:58 +0000358#endif
359 return 0;
360}
361
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530362#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000363/*
364 * implementation of CONFIG_ESDHC_DETECT_QUIRK Macro.
365 */
366u8 qixis_esdhc_detect_quirk(void)
367{
Yangbo Lue1a3cc72020-06-17 18:08:59 +0800368 /*
Pankaj Bansal338baa32019-02-08 10:29:58 +0000369 * SDHC1 Card ID:
370 * Specifies the type of card installed in the SDHC1 adapter slot.
371 * 000= (reserved)
372 * 001= eMMC V4.5 adapter is installed.
373 * 010= SD/MMC 3.3V adapter is installed.
374 * 011= eMMC V4.4 adapter is installed.
375 * 100= eMMC V5.0 adapter is installed.
376 * 101= MMC card/Legacy (3.3V) adapter is installed.
377 * 110= SDCard V2/V3 adapter installed.
378 * 111= no adapter is installed.
379 */
Yangbo Lue1a3cc72020-06-17 18:08:59 +0800380 return ((QIXIS_READ(sdhc1) & QIXIS_SDID_MASK) !=
Pankaj Bansal338baa32019-02-08 10:29:58 +0000381 QIXIS_ESDHC_NO_ADAPTER);
382}
383
Yangbo Lue1a3cc72020-06-17 18:08:59 +0800384static void esdhc_adapter_card_ident(void)
385{
386 u8 card_id, val;
387
388 val = QIXIS_READ(sdhc1);
389 card_id = val & QIXIS_SDID_MASK;
390
391 switch (card_id) {
392 case QIXIS_ESDHC_ADAPTER_TYPE_SD:
393 /* Power cycle to card */
394 val &= ~QIXIS_SDHC1_S1V3;
395 QIXIS_WRITE(sdhc1, val);
396 mdelay(1);
397 val |= QIXIS_SDHC1_S1V3;
398 QIXIS_WRITE(sdhc1, val);
399 /* Route to SDHC1_VS */
400 val = QIXIS_READ(brdcfg[11]);
401 val |= QIXIS_SDHC1_VS;
402 QIXIS_WRITE(brdcfg[11], val);
403 break;
404 default:
405 break;
406 }
407}
408
Pankaj Bansal338baa32019-02-08 10:29:58 +0000409int config_board_mux(void)
410{
411 u8 reg11, reg5, reg13;
412 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
413 u32 sdhc1_base_pmux;
414 u32 sdhc2_base_pmux;
415 u32 iic5_pmux;
416
417 /* Routes {I2C2_SCL, I2C2_SDA} to SDHC1 as {SDHC1_CD_B, SDHC1_WP}.
418 * Routes {I2C3_SCL, I2C3_SDA} to CAN transceiver as {CAN1_TX,CAN1_RX}.
419 * Routes {I2C4_SCL, I2C4_SDA} to CAN transceiver as {CAN2_TX,CAN2_RX}.
420 * Qixis and remote systems are isolated from the I2C1 bus.
421 * Processor connections are still available.
422 * SPI2 CS2_B controls EN25S64 SPI memory device.
423 * SPI3 CS2_B controls EN25S64 SPI memory device.
424 * EC2 connects to PHY #2 using RGMII protocol.
425 * CLK_OUT connects to FPGA for clock measurement.
426 */
427
428 reg5 = QIXIS_READ(brdcfg[5]);
429 reg5 = CFG_MUX_I2C_SDHC(reg5, 0x40);
430 QIXIS_WRITE(brdcfg[5], reg5);
431
432 /* Check RCW field sdhc1_base_pmux
433 * esdhc0 : sdhc1_base_pmux = 0
434 * dspi0 : sdhc1_base_pmux = 2
435 */
436 sdhc1_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
437 & FSL_CHASSIS3_SDHC1_BASE_PMUX_MASK;
438 sdhc1_base_pmux >>= FSL_CHASSIS3_SDHC1_BASE_PMUX_SHIFT;
439
440 if (sdhc1_base_pmux == SDHC1_BASE_PMUX_DSPI) {
441 reg11 = QIXIS_READ(brdcfg[11]);
442 reg11 = SET_CFG_MUX1_SDHC1_DSPI(reg11, 0x40);
443 QIXIS_WRITE(brdcfg[11], reg11);
444 } else {
445 /* - Routes {SDHC1_CMD, SDHC1_CLK } to SDHC1 adapter slot.
446 * {SDHC1_DAT3, SDHC1_DAT2} to SDHC1 adapter slot.
447 * {SDHC1_DAT1, SDHC1_DAT0} to SDHC1 adapter slot.
448 */
449 reg11 = QIXIS_READ(brdcfg[11]);
450 reg11 = SET_CFG_MUX1_SDHC1_SDHC(reg11);
451 QIXIS_WRITE(brdcfg[11], reg11);
452 }
453
454 /* Check RCW field sdhc2_base_pmux
455 * esdhc1 : sdhc2_base_pmux = 0 (default)
456 * dspi1 : sdhc2_base_pmux = 2
457 */
458 sdhc2_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR13_REGSR - 1])
459 & FSL_CHASSIS3_SDHC2_BASE_PMUX_MASK;
460 sdhc2_base_pmux >>= FSL_CHASSIS3_SDHC2_BASE_PMUX_SHIFT;
461
462 if (sdhc2_base_pmux == SDHC2_BASE_PMUX_DSPI) {
463 reg13 = QIXIS_READ(brdcfg[13]);
464 reg13 = SET_CFG_MUX_SDHC2_DSPI(reg13, 0x01);
465 QIXIS_WRITE(brdcfg[13], reg13);
466 } else {
467 reg13 = QIXIS_READ(brdcfg[13]);
468 reg13 = SET_CFG_MUX_SDHC2_DSPI(reg13, 0x00);
469 QIXIS_WRITE(brdcfg[13], reg13);
470 }
471
472 /* Check RCW field IIC5 to enable dspi2 DT nodei
473 * dspi2: IIC5 = 3
474 */
475 iic5_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
476 & FSL_CHASSIS3_IIC5_PMUX_MASK;
477 iic5_pmux >>= FSL_CHASSIS3_IIC5_PMUX_SHIFT;
478
479 if (iic5_pmux == IIC5_PMUX_SPI3) {
480 /* - Routes {SDHC1_DAT4} to SPI3 devices as {SPI3_M_CS0_B}. */
481 reg11 = QIXIS_READ(brdcfg[11]);
482 reg11 = SET_CFG_MUX2_SDHC1_SPI(reg11, 0x10);
483 QIXIS_WRITE(brdcfg[11], reg11);
484
485 /* - Routes {SDHC1_DAT5, SDHC1_DAT6} nowhere.
486 * {SDHC1_DAT7, SDHC1_DS } to {nothing, SPI3_M0_CLK }.
487 * {I2C5_SCL, I2C5_SDA } to {SPI3_M0_MOSI, SPI3_M0_MISO}.
488 */
489 reg11 = QIXIS_READ(brdcfg[11]);
490 reg11 = SET_CFG_MUX3_SDHC1_SPI(reg11, 0x01);
491 QIXIS_WRITE(brdcfg[11], reg11);
492 } else {
Yangbo Lua0923d72020-03-19 15:18:54 +0800493 /*
494 * If {SDHC1_DAT4} has been configured to route to SDHC1_VS,
495 * do not change it.
496 * Otherwise route {SDHC1_DAT4} to SDHC1 adapter slot.
497 */
Pankaj Bansal338baa32019-02-08 10:29:58 +0000498 reg11 = QIXIS_READ(brdcfg[11]);
Yangbo Lua0923d72020-03-19 15:18:54 +0800499 if ((reg11 & 0x30) != 0x30) {
500 reg11 = SET_CFG_MUX2_SDHC1_SPI(reg11, 0x00);
501 QIXIS_WRITE(brdcfg[11], reg11);
502 }
Pankaj Bansal338baa32019-02-08 10:29:58 +0000503
504 /* - Routes {SDHC1_DAT5, SDHC1_DAT6} to SDHC1 adapter slot.
505 * {SDHC1_DAT7, SDHC1_DS } to SDHC1 adapter slot.
506 * {I2C5_SCL, I2C5_SDA } to SDHC1 adapter slot.
507 */
508 reg11 = QIXIS_READ(brdcfg[11]);
509 reg11 = SET_CFG_MUX3_SDHC1_SPI(reg11, 0x00);
510 QIXIS_WRITE(brdcfg[11], reg11);
511 }
512
513 return 0;
514}
Yangbo Lue1a3cc72020-06-17 18:08:59 +0800515
516int board_early_init_r(void)
517{
518 esdhc_adapter_card_ident();
519 return 0;
520}
Pankaj Bansal504472c2019-07-17 09:34:34 +0000521#elif defined(CONFIG_TARGET_LX2160ARDB)
522int config_board_mux(void)
523{
524 u8 brdcfg;
525
526 brdcfg = QIXIS_READ(brdcfg[4]);
527 /* The BRDCFG4 register controls general board configuration.
528 *|-------------------------------------------|
529 *|Field | Function |
530 *|-------------------------------------------|
531 *|5 | CAN I/O Enable (net CFG_CAN_EN_B):|
532 *|CAN_EN | 0= CAN transceivers are disabled. |
533 *| | 1= CAN transceivers are enabled. |
534 *|-------------------------------------------|
535 */
536 brdcfg |= BIT_MASK(5);
537 QIXIS_WRITE(brdcfg[4], brdcfg);
538
539 return 0;
540}
Pankaj Bansal338baa32019-02-08 10:29:58 +0000541#else
542int config_board_mux(void)
543{
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000544 return 0;
545}
Pankaj Bansal338baa32019-02-08 10:29:58 +0000546#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000547
548unsigned long get_board_sys_clk(void)
549{
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530550#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000551 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
552
553 switch (sysclk_conf & 0x03) {
554 case QIXIS_SYSCLK_100:
555 return 100000000;
556 case QIXIS_SYSCLK_125:
557 return 125000000;
558 case QIXIS_SYSCLK_133:
559 return 133333333;
560 }
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000561 return 100000000;
Pankaj Bansal338baa32019-02-08 10:29:58 +0000562#else
563 return 100000000;
564#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000565}
566
567unsigned long get_board_ddr_clk(void)
568{
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530569#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000570 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
571
572 switch ((ddrclk_conf & 0x30) >> 4) {
573 case QIXIS_DDRCLK_100:
574 return 100000000;
575 case QIXIS_DDRCLK_125:
576 return 125000000;
577 case QIXIS_DDRCLK_133:
578 return 133333333;
579 }
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000580 return 100000000;
Pankaj Bansal338baa32019-02-08 10:29:58 +0000581#else
582 return 100000000;
583#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000584}
585
586int board_init(void)
587{
Florin Chiculitad90d5062019-04-22 11:57:47 +0300588#if defined(CONFIG_FSL_MC_ENET) && defined(CONFIG_TARGET_LX2160ARDB)
589 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
590#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000591#ifdef CONFIG_ENV_IS_NOWHERE
592 gd->env_addr = (ulong)&default_environment[0];
593#endif
594
Stephen Carlson70b1e8c2021-06-22 16:43:03 -0700595 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000596
Florin Chiculitad90d5062019-04-22 11:57:47 +0300597#if defined(CONFIG_FSL_MC_ENET) && defined(CONFIG_TARGET_LX2160ARDB)
598 /* invert AQR107 IRQ pins polarity */
599 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR107_IRQ_MASK);
600#endif
601
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000602#ifdef CONFIG_FSL_CAAM
603 sec_init();
604#endif
605
Ioana Ciorneicffa3b12020-04-27 15:21:15 +0300606#if !defined(CONFIG_SYS_EARLY_PCI_INIT) && defined(CONFIG_DM_ETH)
607 pci_init();
608#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000609 return 0;
610}
611
612void detail_board_ddr_info(void)
613{
614 int i;
615 u64 ddr_size = 0;
616
617 puts("\nDDR ");
618 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
619 ddr_size += gd->bd->bi_dram[i].size;
620 print_size(ddr_size, "");
621 print_ddr_info(0);
622}
623
Alex Margineanb4f80232020-01-11 01:05:36 +0200624#ifdef CONFIG_MISC_INIT_R
625int misc_init_r(void)
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000626{
Pankaj Bansal338baa32019-02-08 10:29:58 +0000627 config_board_mux();
628
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000629 return 0;
630}
631#endif
632
Stephen Carlsonc3301a22021-02-08 11:11:29 +0100633#ifdef CONFIG_VID
634u16 soc_get_fuse_vid(int vid_index)
635{
636 static const u16 vdd[32] = {
637 8250,
638 7875,
639 7750,
640 0, /* reserved */
641 0, /* reserved */
642 0, /* reserved */
643 0, /* reserved */
644 0, /* reserved */
645 0, /* reserved */
646 0, /* reserved */
647 0, /* reserved */
648 0, /* reserved */
649 0, /* reserved */
650 0, /* reserved */
651 0, /* reserved */
652 0, /* reserved */
653 8000,
654 8125,
655 8250,
656 0, /* reserved */
657 8500,
658 0, /* reserved */
659 0, /* reserved */
660 0, /* reserved */
661 0, /* reserved */
662 0, /* reserved */
663 0, /* reserved */
664 0, /* reserved */
665 0, /* reserved */
666 0, /* reserved */
667 0, /* reserved */
668 0, /* reserved */
669 };
670
671 return vdd[vid_index];
672};
673#endif
674
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000675#ifdef CONFIG_FSL_MC_ENET
676extern int fdt_fixup_board_phy(void *fdt);
677
678void fdt_fixup_board_enet(void *fdt)
679{
680 int offset;
681
682 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
683
684 if (offset < 0)
685 offset = fdt_path_offset(fdt, "/fsl-mc");
686
687 if (offset < 0) {
688 printf("%s: fsl-mc node not found in device tree (error %d)\n",
689 __func__, offset);
690 return;
691 }
692
Mian Yousaf Kaukabc387c012019-05-23 10:57:33 +0200693 if (get_mc_boot_status() == 0 &&
694 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0)) {
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000695 fdt_status_okay(fdt, offset);
Ioana Ciorneicffa3b12020-04-27 15:21:15 +0300696#ifndef CONFIG_DM_ETH
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000697 fdt_fixup_board_phy(fdt);
Ioana Ciorneicffa3b12020-04-27 15:21:15 +0300698#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000699 } else {
700 fdt_status_fail(fdt, offset);
701 }
702}
703
704void board_quiesce_devices(void)
705{
706 fsl_mc_ldpaa_exit(gd->bd);
707}
708#endif
709
Wasim Khan4c4c1f82021-06-17 09:12:59 +0200710#if CONFIG_IS_ENABLED(TARGET_LX2160ARDB)
711int fdt_fixup_add_thermal(void *blob, int mux_node, int channel, int reg)
712{
713 int err;
714 int noff;
715 int offset;
716 char channel_node_name[50];
717 char thermal_node_name[50];
718 u32 phandle;
719
720 snprintf(channel_node_name, sizeof(channel_node_name),
721 "i2c@%x", channel);
722 debug("channel_node_name = %s\n", channel_node_name);
723
724 snprintf(thermal_node_name, sizeof(thermal_node_name),
725 "temperature-sensor@%x", reg);
726 debug("thermal_node_name = %s\n", thermal_node_name);
727
728 err = fdt_increase_size(blob, 200);
729 if (err) {
730 printf("fdt_increase_size: err=%s\n", fdt_strerror(err));
731 return err;
732 }
733
734 noff = fdt_subnode_offset(blob, mux_node, (const char *)
735 channel_node_name);
736 if (noff < 0) {
737 /* channel node not found - create it */
738 noff = fdt_add_subnode(blob, mux_node, channel_node_name);
739 if (noff < 0) {
740 printf("fdt_add_subnode: err=%s\n", fdt_strerror(err));
741 return err;
742 }
743 fdt_setprop_u32 (blob, noff, "#address-cells", 1);
744 fdt_setprop_u32 (blob, noff, "#size-cells", 0);
745 fdt_setprop_u32 (blob, noff, "reg", channel);
746 }
747
748 /* Create thermal node*/
749 offset = fdt_add_subnode(blob, noff, thermal_node_name);
750 fdt_setprop(blob, offset, "compatible", "nxp,sa56004",
751 strlen("nxp,sa56004") + 1);
752 fdt_setprop_u32 (blob, offset, "reg", reg);
753
754 /* fixup phandle*/
755 noff = fdt_node_offset_by_compatible(blob, -1, "regulator-fixed");
756 if (noff < 0) {
757 printf("%s : failed to get phandle\n", __func__);
758 return noff;
759 }
760 phandle = fdt_get_phandle(blob, noff);
761 fdt_setprop_u32 (blob, offset, "vcc-supply", phandle);
762
763 return 0;
764}
765
766void fdt_fixup_delete_thermal(void *blob, int mux_node, int channel, int reg)
767{
768 int node;
769 int value;
770 int err;
771 int subnode;
772
773 fdt_for_each_subnode(subnode, blob, mux_node) {
774 value = fdtdec_get_uint(blob, subnode, "reg", -1);
775 if (value == channel) {
776 /* delete thermal node */
777 fdt_for_each_subnode(node, blob, subnode) {
778 value = fdtdec_get_uint(blob, node, "reg", -1);
779 err = fdt_node_check_compatible(blob, node,
780 "nxp,sa56004");
781 if (!err && value == reg) {
782 fdt_del_node(blob, node);
783 break;
784 }
785 }
786 }
787 }
788}
789
790void fdt_fixup_i2c_thermal_node(void *blob)
791{
792 int i2coffset;
793 int mux_node;
794 int reg;
795 int err;
796
797 i2coffset = fdt_node_offset_by_compat_reg(blob, "fsl,vf610-i2c",
798 0x2000000);
799 if (i2coffset != -FDT_ERR_NOTFOUND) {
800 fdt_for_each_subnode(mux_node, blob, i2coffset) {
801 reg = fdtdec_get_uint(blob, mux_node, "reg", -1);
802 err = fdt_node_check_compatible(blob, mux_node,
803 "nxp,pca9547");
804 if (!err && reg == 0x77) {
805 fdt_fixup_delete_thermal(blob, mux_node,
806 0x3, 0x4d);
807 err = fdt_fixup_add_thermal(blob, mux_node,
808 0x3, 0x48);
809 if (err)
810 printf("%s: Add thermal node failed\n",
811 __func__);
812 }
813 }
814 } else {
815 printf("%s: i2c node not found\n", __func__);
816 }
817}
818#endif
819
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000820#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900821int ft_board_setup(void *blob, struct bd_info *bd)
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000822{
823 int i;
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530824 u16 mc_memory_bank = 0;
825
826 u64 *base;
827 u64 *size;
828 u64 mc_memory_base = 0;
829 u64 mc_memory_size = 0;
830 u16 total_memory_banks;
Wasim Khan4c4c1f82021-06-17 09:12:59 +0200831#if CONFIG_IS_ENABLED(TARGET_LX2160ARDB)
832 u8 board_rev;
833#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000834
835 ft_cpu_setup(blob, bd);
836
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530837 fdt_fixup_mc_ddr(&mc_memory_base, &mc_memory_size);
838
839 if (mc_memory_base != 0)
840 mc_memory_bank++;
841
842 total_memory_banks = CONFIG_NR_DRAM_BANKS + mc_memory_bank;
843
844 base = calloc(total_memory_banks, sizeof(u64));
845 size = calloc(total_memory_banks, sizeof(u64));
846
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000847 /* fixup DT for the three GPP DDR banks */
848 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
849 base[i] = gd->bd->bi_dram[i].start;
850 size[i] = gd->bd->bi_dram[i].size;
851 }
852
853#ifdef CONFIG_RESV_RAM
854 /* reduce size if reserved memory is within this bank */
855 if (gd->arch.resv_ram >= base[0] &&
856 gd->arch.resv_ram < base[0] + size[0])
857 size[0] = gd->arch.resv_ram - base[0];
858 else if (gd->arch.resv_ram >= base[1] &&
859 gd->arch.resv_ram < base[1] + size[1])
860 size[1] = gd->arch.resv_ram - base[1];
861 else if (gd->arch.resv_ram >= base[2] &&
862 gd->arch.resv_ram < base[2] + size[2])
863 size[2] = gd->arch.resv_ram - base[2];
864#endif
865
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530866 if (mc_memory_base != 0) {
867 for (i = 0; i <= total_memory_banks; i++) {
868 if (base[i] == 0 && size[i] == 0) {
869 base[i] = mc_memory_base;
870 size[i] = mc_memory_size;
871 break;
872 }
873 }
874 }
875
876 fdt_fixup_memory_banks(blob, base, size, total_memory_banks);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000877
Tom Rini8a091622021-07-09 10:11:55 -0400878#ifdef CONFIG_USB_HOST
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000879 fsl_fdt_fixup_dr_usb(blob, bd);
880#endif
881
882#ifdef CONFIG_FSL_MC_ENET
883 fdt_fsl_mc_fixup_iommu_map_entry(blob);
884 fdt_fixup_board_enet(blob);
885#endif
Laurentiu Tudor7085d072019-10-18 09:01:55 +0000886 fdt_fixup_icid(blob);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000887
Wasim Khan4c4c1f82021-06-17 09:12:59 +0200888#if CONFIG_IS_ENABLED(TARGET_LX2160ARDB)
889 board_rev = (QIXIS_READ(arch) & 0xf) - 1 + 'A';
890 if (board_rev == 'C')
891 fdt_fixup_i2c_thermal_node(blob);
892#endif
893
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000894 return 0;
895}
896#endif
897
898void qixis_dump_switch(void)
899{
900 int i, nr_of_cfgsw;
901
902 QIXIS_WRITE(cms[0], 0x00);
903 nr_of_cfgsw = QIXIS_READ(cms[1]);
904
905 puts("DIP switch settings dump:\n");
906 for (i = 1; i <= nr_of_cfgsw; i++) {
907 QIXIS_WRITE(cms[0], i);
908 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
909 }
910}