blob: 103b0cc65916e7a9003bedef3f42c45d69197d75 [file] [log] [blame]
Priyanka Jainfd45ca02018-11-28 13:04:27 +00001// SPDX-License-Identifier: GPL-2.0+
2/*
Xiaowei Bao3a13e292020-01-08 14:29:54 +08003 * Copyright 2018-2020 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>
9#include <dm/platform_data/serial_pl01x.h>
10#include <i2c.h>
11#include <malloc.h>
12#include <errno.h>
13#include <netdev.h>
14#include <fsl_ddr.h>
15#include <fsl_sec.h>
16#include <asm/io.h>
17#include <fdt_support.h>
18#include <linux/libfdt.h>
19#include <fsl-mc/fsl_mc.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060020#include <env_internal.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +000021#include <efi_loader.h>
22#include <asm/arch/mmu.h>
23#include <hwconfig.h>
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +000024#include <asm/arch/clock.h>
25#include <asm/arch/config.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +000026#include <asm/arch/fsl_serdes.h>
27#include <asm/arch/soc.h>
28#include "../common/qixis.h"
29#include "../common/vid.h"
30#include <fsl_immap.h>
Laurentiu Tudor7085d072019-10-18 09:01:55 +000031#include <asm/arch-fsl-layerscape/fsl_icid.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +000032
Meenakshi Aggarwal936a68d2018-11-30 22:32:12 +053033#ifdef CONFIG_EMC2305
34#include "../common/emc2305.h"
35#endif
36
Pankaj Bansal338baa32019-02-08 10:29:58 +000037#ifdef CONFIG_TARGET_LX2160AQDS
38#define CFG_MUX_I2C_SDHC(reg, value) ((reg & 0x3f) | value)
39#define SET_CFG_MUX1_SDHC1_SDHC(reg) (reg & 0x3f)
40#define SET_CFG_MUX2_SDHC1_SPI(reg, value) ((reg & 0xcf) | value)
41#define SET_CFG_MUX3_SDHC1_SPI(reg, value) ((reg & 0xf8) | value)
42#define SET_CFG_MUX_SDHC2_DSPI(reg, value) ((reg & 0xf8) | value)
43#define SET_CFG_MUX1_SDHC1_DSPI(reg, value) ((reg & 0x3f) | value)
44#define SDHC1_BASE_PMUX_DSPI 2
45#define SDHC2_BASE_PMUX_DSPI 2
46#define IIC5_PMUX_SPI3 3
47#endif /* CONFIG_TARGET_LX2160AQDS */
48
Priyanka Jainfd45ca02018-11-28 13:04:27 +000049DECLARE_GLOBAL_DATA_PTR;
50
51static struct pl01x_serial_platdata serial0 = {
52#if CONFIG_CONS_INDEX == 0
53 .base = CONFIG_SYS_SERIAL0,
54#elif CONFIG_CONS_INDEX == 1
55 .base = CONFIG_SYS_SERIAL1,
56#else
57#error "Unsupported console index value."
58#endif
59 .type = TYPE_PL011,
60};
61
62U_BOOT_DEVICE(nxp_serial0) = {
63 .name = "serial_pl01x",
64 .platdata = &serial0,
65};
66
67static struct pl01x_serial_platdata serial1 = {
68 .base = CONFIG_SYS_SERIAL1,
69 .type = TYPE_PL011,
70};
71
72U_BOOT_DEVICE(nxp_serial1) = {
73 .name = "serial_pl01x",
74 .platdata = &serial1,
75};
76
77int select_i2c_ch_pca9547(u8 ch)
78{
79 int ret;
80
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080081#ifndef CONFIG_DM_I2C
Priyanka Jainfd45ca02018-11-28 13:04:27 +000082 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Chuanhua Han37c2c5e2019-07-10 21:00:20 +080083#else
84 struct udevice *dev;
85
86 ret = i2c_get_chip_for_busnum(0, I2C_MUX_PCA_ADDR_PRI, 1, &dev);
87 if (!ret)
88 ret = dm_i2c_write(dev, 0, &ch, 1);
89#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +000090 if (ret) {
91 puts("PCA: failed to select proper channel\n");
92 return ret;
93 }
94
95 return 0;
96}
97
98static void uart_get_clock(void)
99{
100 serial0.clock = get_serial_clock();
101 serial1.clock = get_serial_clock();
102}
103
104int board_early_init_f(void)
105{
106#ifdef CONFIG_SYS_I2C_EARLY_INIT
107 i2c_early_init_f();
108#endif
109 /* get required clock for UART IP */
110 uart_get_clock();
111
Meenakshi Aggarwal936a68d2018-11-30 22:32:12 +0530112#ifdef CONFIG_EMC2305
113 select_i2c_ch_pca9547(I2C_MUX_CH_EMC2305);
114 emc2305_init();
115 set_fan_speed(I2C_EMC2305_PWM);
116 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
117#endif
118
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000119 fsl_lsch3_early_init_f();
120 return 0;
121}
122
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000123#ifdef CONFIG_OF_BOARD_FIXUP
124int board_fix_fdt(void *fdt)
125{
126 char *reg_names, *reg_name;
127 int names_len, old_name_len, new_name_len, remaining_names_len;
128 struct str_map {
129 char *old_str;
130 char *new_str;
131 } reg_names_map[] = {
Pankaj Bansal58ace212019-11-20 09:12:47 +0000132 { "ccsr", "dbi" },
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000133 { "pf_ctrl", "ctrl" }
134 };
Pankaj Bansal844e0ed2020-01-15 05:57:00 +0000135 int off = -1, i = 0;
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000136
137 if (IS_SVR_REV(get_svr(), 1, 0))
138 return 0;
139
140 off = fdt_node_offset_by_compatible(fdt, -1, "fsl,lx2160a-pcie");
141 while (off != -FDT_ERR_NOTFOUND) {
142 fdt_setprop(fdt, off, "compatible", "fsl,ls-pcie",
143 strlen("fsl,ls-pcie") + 1);
144
145 reg_names = (char *)fdt_getprop(fdt, off, "reg-names",
146 &names_len);
147 if (!reg_names)
148 continue;
149
150 reg_name = reg_names;
151 remaining_names_len = names_len - (reg_name - reg_names);
Pankaj Bansal844e0ed2020-01-15 05:57:00 +0000152 while ((i < ARRAY_SIZE(reg_names_map)) && remaining_names_len) {
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000153 old_name_len = strlen(reg_names_map[i].old_str);
154 new_name_len = strlen(reg_names_map[i].new_str);
155 if (memcmp(reg_name, reg_names_map[i].old_str,
156 old_name_len) == 0) {
157 /* first only leave required bytes for new_str
158 * and copy rest of the string after it
159 */
160 memcpy(reg_name + new_name_len,
161 reg_name + old_name_len,
162 remaining_names_len - old_name_len);
163 /* Now copy new_str */
164 memcpy(reg_name, reg_names_map[i].new_str,
165 new_name_len);
166 names_len -= old_name_len;
167 names_len += new_name_len;
Pankaj Bansal844e0ed2020-01-15 05:57:00 +0000168 i++;
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000169 }
170
171 reg_name = memchr(reg_name, '\0', remaining_names_len);
172 if (!reg_name)
173 break;
174
175 reg_name += 1;
176
177 remaining_names_len = names_len -
178 (reg_name - reg_names);
179 }
180
181 fdt_setprop(fdt, off, "reg-names", reg_names, names_len);
182 off = fdt_node_offset_by_compatible(fdt, off,
183 "fsl,lx2160a-pcie");
184 }
185
186 return 0;
187}
188#endif
189
Pankaj Bansal338baa32019-02-08 10:29:58 +0000190#if defined(CONFIG_TARGET_LX2160AQDS)
191void esdhc_dspi_status_fixup(void *blob)
192{
193 const char esdhc0_path[] = "/soc/esdhc@2140000";
194 const char esdhc1_path[] = "/soc/esdhc@2150000";
Xiaowei Bao3a13e292020-01-08 14:29:54 +0800195 const char dspi0_path[] = "/soc/spi@2100000";
196 const char dspi1_path[] = "/soc/spi@2110000";
197 const char dspi2_path[] = "/soc/spi@2120000";
Pankaj Bansal338baa32019-02-08 10:29:58 +0000198
199 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
200 u32 sdhc1_base_pmux;
201 u32 sdhc2_base_pmux;
202 u32 iic5_pmux;
203
204 /* Check RCW field sdhc1_base_pmux to enable/disable
205 * esdhc0/dspi0 DT node
206 */
207 sdhc1_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
208 & FSL_CHASSIS3_SDHC1_BASE_PMUX_MASK;
209 sdhc1_base_pmux >>= FSL_CHASSIS3_SDHC1_BASE_PMUX_SHIFT;
210
211 if (sdhc1_base_pmux == SDHC1_BASE_PMUX_DSPI) {
212 do_fixup_by_path(blob, dspi0_path, "status", "okay",
213 sizeof("okay"), 1);
214 do_fixup_by_path(blob, esdhc0_path, "status", "disabled",
215 sizeof("disabled"), 1);
216 } else {
217 do_fixup_by_path(blob, esdhc0_path, "status", "okay",
218 sizeof("okay"), 1);
219 do_fixup_by_path(blob, dspi0_path, "status", "disabled",
220 sizeof("disabled"), 1);
221 }
222
223 /* Check RCW field sdhc2_base_pmux to enable/disable
224 * esdhc1/dspi1 DT node
225 */
226 sdhc2_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR13_REGSR - 1])
227 & FSL_CHASSIS3_SDHC2_BASE_PMUX_MASK;
228 sdhc2_base_pmux >>= FSL_CHASSIS3_SDHC2_BASE_PMUX_SHIFT;
229
230 if (sdhc2_base_pmux == SDHC2_BASE_PMUX_DSPI) {
231 do_fixup_by_path(blob, dspi1_path, "status", "okay",
232 sizeof("okay"), 1);
233 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
234 sizeof("disabled"), 1);
235 } else {
236 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
237 sizeof("okay"), 1);
238 do_fixup_by_path(blob, dspi1_path, "status", "disabled",
239 sizeof("disabled"), 1);
240 }
241
242 /* Check RCW field IIC5 to enable dspi2 DT node */
243 iic5_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
244 & FSL_CHASSIS3_IIC5_PMUX_MASK;
245 iic5_pmux >>= FSL_CHASSIS3_IIC5_PMUX_SHIFT;
246
Xiaowei Bao3a13e292020-01-08 14:29:54 +0800247 if (iic5_pmux == IIC5_PMUX_SPI3)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000248 do_fixup_by_path(blob, dspi2_path, "status", "okay",
249 sizeof("okay"), 1);
Xiaowei Bao3a13e292020-01-08 14:29:54 +0800250 else
251 do_fixup_by_path(blob, dspi2_path, "status", "disabled",
252 sizeof("disabled"), 1);
Pankaj Bansal338baa32019-02-08 10:29:58 +0000253}
254#endif
255
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000256int esdhc_status_fixup(void *blob, const char *compat)
257{
Pankaj Bansal338baa32019-02-08 10:29:58 +0000258#if defined(CONFIG_TARGET_LX2160AQDS)
259 /* Enable esdhc and dspi DT nodes based on RCW fields */
260 esdhc_dspi_status_fixup(blob);
261#else
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000262 /* Enable both esdhc DT nodes for LX2160ARDB */
263 do_fixup_by_compat(blob, compat, "status", "okay",
264 sizeof("okay"), 1);
Pankaj Bansal338baa32019-02-08 10:29:58 +0000265#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000266 return 0;
267}
268
269#if defined(CONFIG_VID)
270int i2c_multiplexer_select_vid_channel(u8 channel)
271{
272 return select_i2c_ch_pca9547(channel);
273}
274
Priyanka Jaine94c3242019-02-04 06:32:36 +0000275int init_func_vid(void)
276{
277 if (adjust_vdd(0) < 0)
278 printf("core voltage not adjusted\n");
279
280 return 0;
281}
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000282#endif
283
284int checkboard(void)
285{
286 enum boot_src src = get_boot_src();
287 char buf[64];
288 u8 sw;
Pankaj Bansal338baa32019-02-08 10:29:58 +0000289#ifdef CONFIG_TARGET_LX2160AQDS
290 int clock;
291 static const char *const freq[] = {"100", "125", "156.25",
292 "161.13", "322.26", "", "", "",
293 "", "", "", "", "", "", "",
294 "100 separate SSCG"};
295#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000296
297 cpu_name(buf);
Pankaj Bansal338baa32019-02-08 10:29:58 +0000298#ifdef CONFIG_TARGET_LX2160AQDS
299 printf("Board: %s-QDS, ", buf);
300#else
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000301 printf("Board: %s-RDB, ", buf);
Pankaj Bansal338baa32019-02-08 10:29:58 +0000302#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000303
304 sw = QIXIS_READ(arch);
305 printf("Board version: %c, boot from ", (sw & 0xf) - 1 + 'A');
306
307 if (src == BOOT_SOURCE_SD_MMC) {
308 puts("SD\n");
Meenakshi Aggarwal74bd4992020-01-23 17:55:10 +0530309 } else if (src == BOOT_SOURCE_SD_MMC2) {
310 puts("eMMC\n");
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000311 } else {
312 sw = QIXIS_READ(brdcfg[0]);
313 sw = (sw >> QIXIS_XMAP_SHIFT) & QIXIS_XMAP_MASK;
314 switch (sw) {
315 case 0:
316 case 4:
317 puts("FlexSPI DEV#0\n");
318 break;
319 case 1:
320 puts("FlexSPI DEV#1\n");
321 break;
322 case 2:
323 case 3:
324 puts("FlexSPI EMU\n");
325 break;
326 default:
327 printf("invalid setting, xmap: %d\n", sw);
328 break;
329 }
330 }
Pankaj Bansal338baa32019-02-08 10:29:58 +0000331#ifdef CONFIG_TARGET_LX2160AQDS
332 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]);
342 clock = sw & 0x0f;
343 printf("Clock2 = %sMHz", freq[clock]);
344
345 sw = QIXIS_READ(brdcfg[3]);
346 puts("\nSERDES2 Reference : ");
347 clock = sw >> 4;
348 printf("Clock1 = %sMHz ", freq[clock]);
349 clock = sw & 0x0f;
350 printf("Clock2 = %sMHz", freq[clock]);
351
352 sw = QIXIS_READ(brdcfg[12]);
353 puts("\nSERDES3 Reference : ");
354 clock = sw >> 4;
355 printf("Clock1 = %sMHz Clock2 = %sMHz\n", freq[clock], freq[clock]);
356#else
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000357 printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
358
359 puts("SERDES1 Reference: Clock1 = 161.13MHz Clock2 = 161.13MHz\n");
360 puts("SERDES2 Reference: Clock1 = 100MHz Clock2 = 100MHz\n");
Meenakshi Aggarwal06f43882019-09-04 16:39:56 +0530361 puts("SERDES3 Reference: Clock1 = 100MHz Clock2 = 100MHz\n");
Pankaj Bansal338baa32019-02-08 10:29:58 +0000362#endif
363 return 0;
364}
365
366#ifdef CONFIG_TARGET_LX2160AQDS
367/*
368 * implementation of CONFIG_ESDHC_DETECT_QUIRK Macro.
369 */
370u8 qixis_esdhc_detect_quirk(void)
371{
372 /* for LX2160AQDS res1[1] @ offset 0x1A is SDHC1 Control/Status (SDHC1)
373 * SDHC1 Card ID:
374 * Specifies the type of card installed in the SDHC1 adapter slot.
375 * 000= (reserved)
376 * 001= eMMC V4.5 adapter is installed.
377 * 010= SD/MMC 3.3V adapter is installed.
378 * 011= eMMC V4.4 adapter is installed.
379 * 100= eMMC V5.0 adapter is installed.
380 * 101= MMC card/Legacy (3.3V) adapter is installed.
381 * 110= SDCard V2/V3 adapter installed.
382 * 111= no adapter is installed.
383 */
384 return ((QIXIS_READ(res1[1]) & QIXIS_SDID_MASK) !=
385 QIXIS_ESDHC_NO_ADAPTER);
386}
387
388int config_board_mux(void)
389{
390 u8 reg11, reg5, reg13;
391 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
392 u32 sdhc1_base_pmux;
393 u32 sdhc2_base_pmux;
394 u32 iic5_pmux;
395
396 /* Routes {I2C2_SCL, I2C2_SDA} to SDHC1 as {SDHC1_CD_B, SDHC1_WP}.
397 * Routes {I2C3_SCL, I2C3_SDA} to CAN transceiver as {CAN1_TX,CAN1_RX}.
398 * Routes {I2C4_SCL, I2C4_SDA} to CAN transceiver as {CAN2_TX,CAN2_RX}.
399 * Qixis and remote systems are isolated from the I2C1 bus.
400 * Processor connections are still available.
401 * SPI2 CS2_B controls EN25S64 SPI memory device.
402 * SPI3 CS2_B controls EN25S64 SPI memory device.
403 * EC2 connects to PHY #2 using RGMII protocol.
404 * CLK_OUT connects to FPGA for clock measurement.
405 */
406
407 reg5 = QIXIS_READ(brdcfg[5]);
408 reg5 = CFG_MUX_I2C_SDHC(reg5, 0x40);
409 QIXIS_WRITE(brdcfg[5], reg5);
410
411 /* Check RCW field sdhc1_base_pmux
412 * esdhc0 : sdhc1_base_pmux = 0
413 * dspi0 : sdhc1_base_pmux = 2
414 */
415 sdhc1_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
416 & FSL_CHASSIS3_SDHC1_BASE_PMUX_MASK;
417 sdhc1_base_pmux >>= FSL_CHASSIS3_SDHC1_BASE_PMUX_SHIFT;
418
419 if (sdhc1_base_pmux == SDHC1_BASE_PMUX_DSPI) {
420 reg11 = QIXIS_READ(brdcfg[11]);
421 reg11 = SET_CFG_MUX1_SDHC1_DSPI(reg11, 0x40);
422 QIXIS_WRITE(brdcfg[11], reg11);
423 } else {
424 /* - Routes {SDHC1_CMD, SDHC1_CLK } to SDHC1 adapter slot.
425 * {SDHC1_DAT3, SDHC1_DAT2} to SDHC1 adapter slot.
426 * {SDHC1_DAT1, SDHC1_DAT0} to SDHC1 adapter slot.
427 */
428 reg11 = QIXIS_READ(brdcfg[11]);
429 reg11 = SET_CFG_MUX1_SDHC1_SDHC(reg11);
430 QIXIS_WRITE(brdcfg[11], reg11);
431 }
432
433 /* Check RCW field sdhc2_base_pmux
434 * esdhc1 : sdhc2_base_pmux = 0 (default)
435 * dspi1 : sdhc2_base_pmux = 2
436 */
437 sdhc2_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR13_REGSR - 1])
438 & FSL_CHASSIS3_SDHC2_BASE_PMUX_MASK;
439 sdhc2_base_pmux >>= FSL_CHASSIS3_SDHC2_BASE_PMUX_SHIFT;
440
441 if (sdhc2_base_pmux == SDHC2_BASE_PMUX_DSPI) {
442 reg13 = QIXIS_READ(brdcfg[13]);
443 reg13 = SET_CFG_MUX_SDHC2_DSPI(reg13, 0x01);
444 QIXIS_WRITE(brdcfg[13], reg13);
445 } else {
446 reg13 = QIXIS_READ(brdcfg[13]);
447 reg13 = SET_CFG_MUX_SDHC2_DSPI(reg13, 0x00);
448 QIXIS_WRITE(brdcfg[13], reg13);
449 }
450
451 /* Check RCW field IIC5 to enable dspi2 DT nodei
452 * dspi2: IIC5 = 3
453 */
454 iic5_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
455 & FSL_CHASSIS3_IIC5_PMUX_MASK;
456 iic5_pmux >>= FSL_CHASSIS3_IIC5_PMUX_SHIFT;
457
458 if (iic5_pmux == IIC5_PMUX_SPI3) {
459 /* - Routes {SDHC1_DAT4} to SPI3 devices as {SPI3_M_CS0_B}. */
460 reg11 = QIXIS_READ(brdcfg[11]);
461 reg11 = SET_CFG_MUX2_SDHC1_SPI(reg11, 0x10);
462 QIXIS_WRITE(brdcfg[11], reg11);
463
464 /* - Routes {SDHC1_DAT5, SDHC1_DAT6} nowhere.
465 * {SDHC1_DAT7, SDHC1_DS } to {nothing, SPI3_M0_CLK }.
466 * {I2C5_SCL, I2C5_SDA } to {SPI3_M0_MOSI, SPI3_M0_MISO}.
467 */
468 reg11 = QIXIS_READ(brdcfg[11]);
469 reg11 = SET_CFG_MUX3_SDHC1_SPI(reg11, 0x01);
470 QIXIS_WRITE(brdcfg[11], reg11);
471 } else {
472 /* Routes {SDHC1_DAT4} to SDHC1 adapter slot */
473 reg11 = QIXIS_READ(brdcfg[11]);
474 reg11 = SET_CFG_MUX2_SDHC1_SPI(reg11, 0x00);
475 QIXIS_WRITE(brdcfg[11], reg11);
476
477 /* - Routes {SDHC1_DAT5, SDHC1_DAT6} to SDHC1 adapter slot.
478 * {SDHC1_DAT7, SDHC1_DS } to SDHC1 adapter slot.
479 * {I2C5_SCL, I2C5_SDA } to SDHC1 adapter slot.
480 */
481 reg11 = QIXIS_READ(brdcfg[11]);
482 reg11 = SET_CFG_MUX3_SDHC1_SPI(reg11, 0x00);
483 QIXIS_WRITE(brdcfg[11], reg11);
484 }
485
486 return 0;
487}
Pankaj Bansal504472c2019-07-17 09:34:34 +0000488#elif defined(CONFIG_TARGET_LX2160ARDB)
489int config_board_mux(void)
490{
491 u8 brdcfg;
492
493 brdcfg = QIXIS_READ(brdcfg[4]);
494 /* The BRDCFG4 register controls general board configuration.
495 *|-------------------------------------------|
496 *|Field | Function |
497 *|-------------------------------------------|
498 *|5 | CAN I/O Enable (net CFG_CAN_EN_B):|
499 *|CAN_EN | 0= CAN transceivers are disabled. |
500 *| | 1= CAN transceivers are enabled. |
501 *|-------------------------------------------|
502 */
503 brdcfg |= BIT_MASK(5);
504 QIXIS_WRITE(brdcfg[4], brdcfg);
505
506 return 0;
507}
Pankaj Bansal338baa32019-02-08 10:29:58 +0000508#else
509int config_board_mux(void)
510{
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000511 return 0;
512}
Pankaj Bansal338baa32019-02-08 10:29:58 +0000513#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000514
515unsigned long get_board_sys_clk(void)
516{
Pankaj Bansal338baa32019-02-08 10:29:58 +0000517#ifdef CONFIG_TARGET_LX2160AQDS
518 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
519
520 switch (sysclk_conf & 0x03) {
521 case QIXIS_SYSCLK_100:
522 return 100000000;
523 case QIXIS_SYSCLK_125:
524 return 125000000;
525 case QIXIS_SYSCLK_133:
526 return 133333333;
527 }
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000528 return 100000000;
Pankaj Bansal338baa32019-02-08 10:29:58 +0000529#else
530 return 100000000;
531#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000532}
533
534unsigned long get_board_ddr_clk(void)
535{
Pankaj Bansal338baa32019-02-08 10:29:58 +0000536#ifdef CONFIG_TARGET_LX2160AQDS
537 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
538
539 switch ((ddrclk_conf & 0x30) >> 4) {
540 case QIXIS_DDRCLK_100:
541 return 100000000;
542 case QIXIS_DDRCLK_125:
543 return 125000000;
544 case QIXIS_DDRCLK_133:
545 return 133333333;
546 }
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000547 return 100000000;
Pankaj Bansal338baa32019-02-08 10:29:58 +0000548#else
549 return 100000000;
550#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000551}
552
553int board_init(void)
554{
Florin Chiculitad90d5062019-04-22 11:57:47 +0300555#if defined(CONFIG_FSL_MC_ENET) && defined(CONFIG_TARGET_LX2160ARDB)
556 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
557#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000558#ifdef CONFIG_ENV_IS_NOWHERE
559 gd->env_addr = (ulong)&default_environment[0];
560#endif
561
562 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
563
Florin Chiculitad90d5062019-04-22 11:57:47 +0300564#if defined(CONFIG_FSL_MC_ENET) && defined(CONFIG_TARGET_LX2160ARDB)
565 /* invert AQR107 IRQ pins polarity */
566 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR107_IRQ_MASK);
567#endif
568
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000569#ifdef CONFIG_FSL_CAAM
570 sec_init();
571#endif
572
573 return 0;
574}
575
576void detail_board_ddr_info(void)
577{
578 int i;
579 u64 ddr_size = 0;
580
581 puts("\nDDR ");
582 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
583 ddr_size += gd->bd->bi_dram[i].size;
584 print_size(ddr_size, "");
585 print_ddr_info(0);
586}
587
Alex Margineanb4f80232020-01-11 01:05:36 +0200588#ifdef CONFIG_MISC_INIT_R
589int misc_init_r(void)
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000590{
Pankaj Bansal338baa32019-02-08 10:29:58 +0000591 config_board_mux();
592
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000593 return 0;
594}
595#endif
596
597#ifdef CONFIG_FSL_MC_ENET
598extern int fdt_fixup_board_phy(void *fdt);
599
600void fdt_fixup_board_enet(void *fdt)
601{
602 int offset;
603
604 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
605
606 if (offset < 0)
607 offset = fdt_path_offset(fdt, "/fsl-mc");
608
609 if (offset < 0) {
610 printf("%s: fsl-mc node not found in device tree (error %d)\n",
611 __func__, offset);
612 return;
613 }
614
Mian Yousaf Kaukabc387c012019-05-23 10:57:33 +0200615 if (get_mc_boot_status() == 0 &&
616 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0)) {
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000617 fdt_status_okay(fdt, offset);
618 fdt_fixup_board_phy(fdt);
619 } else {
620 fdt_status_fail(fdt, offset);
621 }
622}
623
624void board_quiesce_devices(void)
625{
626 fsl_mc_ldpaa_exit(gd->bd);
627}
628#endif
629
630#ifdef CONFIG_OF_BOARD_SETUP
631
632int ft_board_setup(void *blob, bd_t *bd)
633{
634 int i;
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530635 u16 mc_memory_bank = 0;
636
637 u64 *base;
638 u64 *size;
639 u64 mc_memory_base = 0;
640 u64 mc_memory_size = 0;
641 u16 total_memory_banks;
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000642
643 ft_cpu_setup(blob, bd);
644
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530645 fdt_fixup_mc_ddr(&mc_memory_base, &mc_memory_size);
646
647 if (mc_memory_base != 0)
648 mc_memory_bank++;
649
650 total_memory_banks = CONFIG_NR_DRAM_BANKS + mc_memory_bank;
651
652 base = calloc(total_memory_banks, sizeof(u64));
653 size = calloc(total_memory_banks, sizeof(u64));
654
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000655 /* fixup DT for the three GPP DDR banks */
656 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
657 base[i] = gd->bd->bi_dram[i].start;
658 size[i] = gd->bd->bi_dram[i].size;
659 }
660
661#ifdef CONFIG_RESV_RAM
662 /* reduce size if reserved memory is within this bank */
663 if (gd->arch.resv_ram >= base[0] &&
664 gd->arch.resv_ram < base[0] + size[0])
665 size[0] = gd->arch.resv_ram - base[0];
666 else if (gd->arch.resv_ram >= base[1] &&
667 gd->arch.resv_ram < base[1] + size[1])
668 size[1] = gd->arch.resv_ram - base[1];
669 else if (gd->arch.resv_ram >= base[2] &&
670 gd->arch.resv_ram < base[2] + size[2])
671 size[2] = gd->arch.resv_ram - base[2];
672#endif
673
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530674 if (mc_memory_base != 0) {
675 for (i = 0; i <= total_memory_banks; i++) {
676 if (base[i] == 0 && size[i] == 0) {
677 base[i] = mc_memory_base;
678 size[i] = mc_memory_size;
679 break;
680 }
681 }
682 }
683
684 fdt_fixup_memory_banks(blob, base, size, total_memory_banks);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000685
686#ifdef CONFIG_USB
687 fsl_fdt_fixup_dr_usb(blob, bd);
688#endif
689
690#ifdef CONFIG_FSL_MC_ENET
691 fdt_fsl_mc_fixup_iommu_map_entry(blob);
692 fdt_fixup_board_enet(blob);
693#endif
Laurentiu Tudor7085d072019-10-18 09:01:55 +0000694 fdt_fixup_icid(blob);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000695
696 return 0;
697}
698#endif
699
700void qixis_dump_switch(void)
701{
702 int i, nr_of_cfgsw;
703
704 QIXIS_WRITE(cms[0], 0x00);
705 nr_of_cfgsw = QIXIS_READ(cms[1]);
706
707 puts("DIP switch settings dump:\n");
708 for (i = 1; i <= nr_of_cfgsw; i++) {
709 QIXIS_WRITE(cms[0], i);
710 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
711 }
712}