blob: 5f0cc9eb7e9e60c74bda1412233441ac7dee15e3 [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>
Simon Glass1ab16922022-07-31 12:28:48 -06008#include <display_options.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +00009#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +000012#include <dm/platform_data/serial_pl01x.h>
13#include <i2c.h>
14#include <malloc.h>
15#include <errno.h>
16#include <netdev.h>
17#include <fsl_ddr.h>
Priyanka Jainfd45ca02018-11-28 13:04:27 +000018#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{
Tom Rini714482a2021-08-18 23:12:25 -040092#if defined(CONFIG_SYS_I2C_EARLY_INIT) && defined(CONFIG_SPL_BUILD)
Priyanka Jainfd45ca02018-11-28 13:04:27 +000093 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
Marek Behún5d6b4482022-01-20 01:04:42 +0100126 fdt_for_each_node_by_compatible(off, fdt, -1, "fsl,lx2160a-pcie") {
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000127 fdt_setprop(fdt, off, "compatible", "fsl,ls-pcie",
128 strlen("fsl,ls-pcie") + 1);
129
130 reg_names = (char *)fdt_getprop(fdt, off, "reg-names",
131 &names_len);
132 if (!reg_names)
133 continue;
134
135 reg_name = reg_names;
136 remaining_names_len = names_len - (reg_name - reg_names);
Vikas Singh1fe634a2020-02-12 13:47:09 +0530137 i = 0;
Pankaj Bansal844e0ed2020-01-15 05:57:00 +0000138 while ((i < ARRAY_SIZE(reg_names_map)) && remaining_names_len) {
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000139 old_name_len = strlen(reg_names_map[i].old_str);
140 new_name_len = strlen(reg_names_map[i].new_str);
141 if (memcmp(reg_name, reg_names_map[i].old_str,
142 old_name_len) == 0) {
143 /* first only leave required bytes for new_str
144 * and copy rest of the string after it
145 */
146 memcpy(reg_name + new_name_len,
147 reg_name + old_name_len,
148 remaining_names_len - old_name_len);
149 /* Now copy new_str */
150 memcpy(reg_name, reg_names_map[i].new_str,
151 new_name_len);
152 names_len -= old_name_len;
153 names_len += new_name_len;
Pankaj Bansal844e0ed2020-01-15 05:57:00 +0000154 i++;
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000155 }
156
157 reg_name = memchr(reg_name, '\0', remaining_names_len);
158 if (!reg_name)
159 break;
160
161 reg_name += 1;
162
163 remaining_names_len = names_len -
164 (reg_name - reg_names);
165 }
166
167 fdt_setprop(fdt, off, "reg-names", reg_names, names_len);
Pankaj Bansalc6b6ba62019-08-17 01:07:32 +0000168 }
169
170 return 0;
171}
172#endif
173
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530174#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000175void esdhc_dspi_status_fixup(void *blob)
176{
177 const char esdhc0_path[] = "/soc/esdhc@2140000";
178 const char esdhc1_path[] = "/soc/esdhc@2150000";
Xiaowei Bao3a13e292020-01-08 14:29:54 +0800179 const char dspi0_path[] = "/soc/spi@2100000";
180 const char dspi1_path[] = "/soc/spi@2110000";
181 const char dspi2_path[] = "/soc/spi@2120000";
Pankaj Bansal338baa32019-02-08 10:29:58 +0000182
183 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
184 u32 sdhc1_base_pmux;
185 u32 sdhc2_base_pmux;
186 u32 iic5_pmux;
187
188 /* Check RCW field sdhc1_base_pmux to enable/disable
189 * esdhc0/dspi0 DT node
190 */
191 sdhc1_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
192 & FSL_CHASSIS3_SDHC1_BASE_PMUX_MASK;
193 sdhc1_base_pmux >>= FSL_CHASSIS3_SDHC1_BASE_PMUX_SHIFT;
194
195 if (sdhc1_base_pmux == SDHC1_BASE_PMUX_DSPI) {
196 do_fixup_by_path(blob, dspi0_path, "status", "okay",
197 sizeof("okay"), 1);
198 do_fixup_by_path(blob, esdhc0_path, "status", "disabled",
199 sizeof("disabled"), 1);
200 } else {
201 do_fixup_by_path(blob, esdhc0_path, "status", "okay",
202 sizeof("okay"), 1);
203 do_fixup_by_path(blob, dspi0_path, "status", "disabled",
204 sizeof("disabled"), 1);
205 }
206
207 /* Check RCW field sdhc2_base_pmux to enable/disable
208 * esdhc1/dspi1 DT node
209 */
210 sdhc2_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR13_REGSR - 1])
211 & FSL_CHASSIS3_SDHC2_BASE_PMUX_MASK;
212 sdhc2_base_pmux >>= FSL_CHASSIS3_SDHC2_BASE_PMUX_SHIFT;
213
214 if (sdhc2_base_pmux == SDHC2_BASE_PMUX_DSPI) {
215 do_fixup_by_path(blob, dspi1_path, "status", "okay",
216 sizeof("okay"), 1);
217 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
218 sizeof("disabled"), 1);
219 } else {
220 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
221 sizeof("okay"), 1);
222 do_fixup_by_path(blob, dspi1_path, "status", "disabled",
223 sizeof("disabled"), 1);
224 }
225
226 /* Check RCW field IIC5 to enable dspi2 DT node */
227 iic5_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
228 & FSL_CHASSIS3_IIC5_PMUX_MASK;
229 iic5_pmux >>= FSL_CHASSIS3_IIC5_PMUX_SHIFT;
230
Xiaowei Bao3a13e292020-01-08 14:29:54 +0800231 if (iic5_pmux == IIC5_PMUX_SPI3)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000232 do_fixup_by_path(blob, dspi2_path, "status", "okay",
233 sizeof("okay"), 1);
Xiaowei Bao3a13e292020-01-08 14:29:54 +0800234 else
235 do_fixup_by_path(blob, dspi2_path, "status", "disabled",
236 sizeof("disabled"), 1);
Pankaj Bansal338baa32019-02-08 10:29:58 +0000237}
238#endif
239
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000240int esdhc_status_fixup(void *blob, const char *compat)
241{
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530242#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000243 /* Enable esdhc and dspi DT nodes based on RCW fields */
244 esdhc_dspi_status_fixup(blob);
245#else
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000246 /* Enable both esdhc DT nodes for LX2160ARDB */
247 do_fixup_by_compat(blob, compat, "status", "okay",
248 sizeof("okay"), 1);
Pankaj Bansal338baa32019-02-08 10:29:58 +0000249#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000250 return 0;
251}
252
253#if defined(CONFIG_VID)
254int i2c_multiplexer_select_vid_channel(u8 channel)
255{
Stephen Carlson70b1e8c2021-06-22 16:43:03 -0700256 return select_i2c_ch_pca9547(channel, 0);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000257}
258
Priyanka Jaine94c3242019-02-04 06:32:36 +0000259int init_func_vid(void)
260{
Meenakshi Aggarwalcdc12002020-02-26 16:46:48 +0530261 int set_vid;
262
263 if (IS_SVR_REV(get_svr(), 1, 0))
264 set_vid = adjust_vdd(800);
265 else
266 set_vid = adjust_vdd(0);
267
268 if (set_vid < 0)
Priyanka Jaine94c3242019-02-04 06:32:36 +0000269 printf("core voltage not adjusted\n");
270
271 return 0;
272}
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000273#endif
274
275int checkboard(void)
276{
277 enum boot_src src = get_boot_src();
278 char buf[64];
279 u8 sw;
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530280#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000281 int clock;
282 static const char *const freq[] = {"100", "125", "156.25",
283 "161.13", "322.26", "", "", "",
284 "", "", "", "", "", "", "",
285 "100 separate SSCG"};
286#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000287
288 cpu_name(buf);
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530289#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000290 printf("Board: %s-QDS, ", buf);
291#else
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000292 printf("Board: %s-RDB, ", buf);
Pankaj Bansal338baa32019-02-08 10:29:58 +0000293#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000294
295 sw = QIXIS_READ(arch);
296 printf("Board version: %c, boot from ", (sw & 0xf) - 1 + 'A');
297
298 if (src == BOOT_SOURCE_SD_MMC) {
299 puts("SD\n");
Meenakshi Aggarwal74bd4992020-01-23 17:55:10 +0530300 } else if (src == BOOT_SOURCE_SD_MMC2) {
301 puts("eMMC\n");
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000302 } else {
303 sw = QIXIS_READ(brdcfg[0]);
304 sw = (sw >> QIXIS_XMAP_SHIFT) & QIXIS_XMAP_MASK;
305 switch (sw) {
306 case 0:
307 case 4:
308 puts("FlexSPI DEV#0\n");
309 break;
310 case 1:
311 puts("FlexSPI DEV#1\n");
312 break;
313 case 2:
314 case 3:
315 puts("FlexSPI EMU\n");
316 break;
317 default:
318 printf("invalid setting, xmap: %d\n", sw);
319 break;
320 }
321 }
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530322#if defined(CONFIG_TARGET_LX2160ARDB)
323 printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
324
325 puts("SERDES1 Reference: Clock1 = 161.13MHz Clock2 = 161.13MHz\n");
326 puts("SERDES2 Reference: Clock1 = 100MHz Clock2 = 100MHz\n");
327 puts("SERDES3 Reference: Clock1 = 100MHz Clock2 = 100MHz\n");
328#else
Pankaj Bansal338baa32019-02-08 10:29:58 +0000329 printf("FPGA: v%d (%s), build %d",
330 (int)QIXIS_READ(scver), qixis_read_tag(buf),
331 (int)qixis_read_minor());
332 /* the timestamp string contains "\n" at the end */
333 printf(" on %s", qixis_read_time(buf));
334
335 puts("SERDES1 Reference : ");
336 sw = QIXIS_READ(brdcfg[2]);
337 clock = sw >> 4;
338 printf("Clock1 = %sMHz ", freq[clock]);
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530339#if defined(CONFIG_TARGET_LX2160AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000340 clock = sw & 0x0f;
341 printf("Clock2 = %sMHz", freq[clock]);
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530342#endif
Pankaj Bansal338baa32019-02-08 10:29:58 +0000343 sw = QIXIS_READ(brdcfg[3]);
344 puts("\nSERDES2 Reference : ");
345 clock = sw >> 4;
346 printf("Clock1 = %sMHz ", freq[clock]);
347 clock = sw & 0x0f;
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530348 printf("Clock2 = %sMHz\n", freq[clock]);
349#if defined(CONFIG_TARGET_LX2160AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000350 sw = QIXIS_READ(brdcfg[12]);
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530351 puts("SERDES3 Reference : ");
Pankaj Bansal338baa32019-02-08 10:29:58 +0000352 clock = sw >> 4;
353 printf("Clock1 = %sMHz Clock2 = %sMHz\n", freq[clock], freq[clock]);
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530354#endif
Pankaj Bansal338baa32019-02-08 10:29:58 +0000355#endif
356 return 0;
357}
358
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530359#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Yangbo Lue1a3cc72020-06-17 18:08:59 +0800360static void esdhc_adapter_card_ident(void)
361{
362 u8 card_id, val;
363
364 val = QIXIS_READ(sdhc1);
365 card_id = val & QIXIS_SDID_MASK;
366
367 switch (card_id) {
368 case QIXIS_ESDHC_ADAPTER_TYPE_SD:
369 /* Power cycle to card */
370 val &= ~QIXIS_SDHC1_S1V3;
371 QIXIS_WRITE(sdhc1, val);
372 mdelay(1);
373 val |= QIXIS_SDHC1_S1V3;
374 QIXIS_WRITE(sdhc1, val);
375 /* Route to SDHC1_VS */
376 val = QIXIS_READ(brdcfg[11]);
377 val |= QIXIS_SDHC1_VS;
378 QIXIS_WRITE(brdcfg[11], val);
379 break;
380 default:
381 break;
382 }
383}
384
Pankaj Bansal338baa32019-02-08 10:29:58 +0000385int config_board_mux(void)
386{
387 u8 reg11, reg5, reg13;
388 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
389 u32 sdhc1_base_pmux;
390 u32 sdhc2_base_pmux;
391 u32 iic5_pmux;
392
393 /* Routes {I2C2_SCL, I2C2_SDA} to SDHC1 as {SDHC1_CD_B, SDHC1_WP}.
394 * Routes {I2C3_SCL, I2C3_SDA} to CAN transceiver as {CAN1_TX,CAN1_RX}.
395 * Routes {I2C4_SCL, I2C4_SDA} to CAN transceiver as {CAN2_TX,CAN2_RX}.
396 * Qixis and remote systems are isolated from the I2C1 bus.
397 * Processor connections are still available.
398 * SPI2 CS2_B controls EN25S64 SPI memory device.
399 * SPI3 CS2_B controls EN25S64 SPI memory device.
400 * EC2 connects to PHY #2 using RGMII protocol.
401 * CLK_OUT connects to FPGA for clock measurement.
402 */
403
404 reg5 = QIXIS_READ(brdcfg[5]);
405 reg5 = CFG_MUX_I2C_SDHC(reg5, 0x40);
406 QIXIS_WRITE(brdcfg[5], reg5);
407
408 /* Check RCW field sdhc1_base_pmux
409 * esdhc0 : sdhc1_base_pmux = 0
410 * dspi0 : sdhc1_base_pmux = 2
411 */
412 sdhc1_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
413 & FSL_CHASSIS3_SDHC1_BASE_PMUX_MASK;
414 sdhc1_base_pmux >>= FSL_CHASSIS3_SDHC1_BASE_PMUX_SHIFT;
415
416 if (sdhc1_base_pmux == SDHC1_BASE_PMUX_DSPI) {
417 reg11 = QIXIS_READ(brdcfg[11]);
418 reg11 = SET_CFG_MUX1_SDHC1_DSPI(reg11, 0x40);
419 QIXIS_WRITE(brdcfg[11], reg11);
420 } else {
421 /* - Routes {SDHC1_CMD, SDHC1_CLK } to SDHC1 adapter slot.
422 * {SDHC1_DAT3, SDHC1_DAT2} to SDHC1 adapter slot.
423 * {SDHC1_DAT1, SDHC1_DAT0} to SDHC1 adapter slot.
424 */
425 reg11 = QIXIS_READ(brdcfg[11]);
426 reg11 = SET_CFG_MUX1_SDHC1_SDHC(reg11);
427 QIXIS_WRITE(brdcfg[11], reg11);
428 }
429
430 /* Check RCW field sdhc2_base_pmux
431 * esdhc1 : sdhc2_base_pmux = 0 (default)
432 * dspi1 : sdhc2_base_pmux = 2
433 */
434 sdhc2_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR13_REGSR - 1])
435 & FSL_CHASSIS3_SDHC2_BASE_PMUX_MASK;
436 sdhc2_base_pmux >>= FSL_CHASSIS3_SDHC2_BASE_PMUX_SHIFT;
437
438 if (sdhc2_base_pmux == SDHC2_BASE_PMUX_DSPI) {
439 reg13 = QIXIS_READ(brdcfg[13]);
440 reg13 = SET_CFG_MUX_SDHC2_DSPI(reg13, 0x01);
441 QIXIS_WRITE(brdcfg[13], reg13);
442 } else {
443 reg13 = QIXIS_READ(brdcfg[13]);
444 reg13 = SET_CFG_MUX_SDHC2_DSPI(reg13, 0x00);
445 QIXIS_WRITE(brdcfg[13], reg13);
446 }
447
448 /* Check RCW field IIC5 to enable dspi2 DT nodei
449 * dspi2: IIC5 = 3
450 */
451 iic5_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
452 & FSL_CHASSIS3_IIC5_PMUX_MASK;
453 iic5_pmux >>= FSL_CHASSIS3_IIC5_PMUX_SHIFT;
454
455 if (iic5_pmux == IIC5_PMUX_SPI3) {
456 /* - Routes {SDHC1_DAT4} to SPI3 devices as {SPI3_M_CS0_B}. */
457 reg11 = QIXIS_READ(brdcfg[11]);
458 reg11 = SET_CFG_MUX2_SDHC1_SPI(reg11, 0x10);
459 QIXIS_WRITE(brdcfg[11], reg11);
460
461 /* - Routes {SDHC1_DAT5, SDHC1_DAT6} nowhere.
462 * {SDHC1_DAT7, SDHC1_DS } to {nothing, SPI3_M0_CLK }.
463 * {I2C5_SCL, I2C5_SDA } to {SPI3_M0_MOSI, SPI3_M0_MISO}.
464 */
465 reg11 = QIXIS_READ(brdcfg[11]);
466 reg11 = SET_CFG_MUX3_SDHC1_SPI(reg11, 0x01);
467 QIXIS_WRITE(brdcfg[11], reg11);
468 } else {
Yangbo Lua0923d72020-03-19 15:18:54 +0800469 /*
470 * If {SDHC1_DAT4} has been configured to route to SDHC1_VS,
471 * do not change it.
472 * Otherwise route {SDHC1_DAT4} to SDHC1 adapter slot.
473 */
Pankaj Bansal338baa32019-02-08 10:29:58 +0000474 reg11 = QIXIS_READ(brdcfg[11]);
Yangbo Lua0923d72020-03-19 15:18:54 +0800475 if ((reg11 & 0x30) != 0x30) {
476 reg11 = SET_CFG_MUX2_SDHC1_SPI(reg11, 0x00);
477 QIXIS_WRITE(brdcfg[11], reg11);
478 }
Pankaj Bansal338baa32019-02-08 10:29:58 +0000479
480 /* - Routes {SDHC1_DAT5, SDHC1_DAT6} to SDHC1 adapter slot.
481 * {SDHC1_DAT7, SDHC1_DS } to SDHC1 adapter slot.
482 * {I2C5_SCL, I2C5_SDA } to SDHC1 adapter slot.
483 */
484 reg11 = QIXIS_READ(brdcfg[11]);
485 reg11 = SET_CFG_MUX3_SDHC1_SPI(reg11, 0x00);
486 QIXIS_WRITE(brdcfg[11], reg11);
487 }
488
489 return 0;
490}
Yangbo Lue1a3cc72020-06-17 18:08:59 +0800491
492int board_early_init_r(void)
493{
494 esdhc_adapter_card_ident();
495 return 0;
496}
Pankaj Bansal504472c2019-07-17 09:34:34 +0000497#elif defined(CONFIG_TARGET_LX2160ARDB)
498int config_board_mux(void)
499{
500 u8 brdcfg;
501
502 brdcfg = QIXIS_READ(brdcfg[4]);
503 /* The BRDCFG4 register controls general board configuration.
504 *|-------------------------------------------|
505 *|Field | Function |
506 *|-------------------------------------------|
507 *|5 | CAN I/O Enable (net CFG_CAN_EN_B):|
508 *|CAN_EN | 0= CAN transceivers are disabled. |
509 *| | 1= CAN transceivers are enabled. |
510 *|-------------------------------------------|
511 */
512 brdcfg |= BIT_MASK(5);
513 QIXIS_WRITE(brdcfg[4], brdcfg);
514
515 return 0;
516}
Pankaj Bansal338baa32019-02-08 10:29:58 +0000517#else
518int config_board_mux(void)
519{
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000520 return 0;
521}
Pankaj Bansal338baa32019-02-08 10:29:58 +0000522#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000523
524unsigned long get_board_sys_clk(void)
525{
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530526#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000527 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
528
529 switch (sysclk_conf & 0x03) {
530 case QIXIS_SYSCLK_100:
531 return 100000000;
532 case QIXIS_SYSCLK_125:
533 return 125000000;
534 case QIXIS_SYSCLK_133:
535 return 133333333;
536 }
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000537 return 100000000;
Pankaj Bansal338baa32019-02-08 10:29:58 +0000538#else
539 return 100000000;
540#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000541}
542
543unsigned long get_board_ddr_clk(void)
544{
Meenakshi Aggarwal8a03b0d2020-12-04 20:17:28 +0530545#if defined(CONFIG_TARGET_LX2160AQDS) || defined(CONFIG_TARGET_LX2162AQDS)
Pankaj Bansal338baa32019-02-08 10:29:58 +0000546 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
547
548 switch ((ddrclk_conf & 0x30) >> 4) {
549 case QIXIS_DDRCLK_100:
550 return 100000000;
551 case QIXIS_DDRCLK_125:
552 return 125000000;
553 case QIXIS_DDRCLK_133:
554 return 133333333;
555 }
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000556 return 100000000;
Pankaj Bansal338baa32019-02-08 10:29:58 +0000557#else
558 return 100000000;
559#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000560}
561
562int board_init(void)
563{
Florin Chiculitad90d5062019-04-22 11:57:47 +0300564#if defined(CONFIG_FSL_MC_ENET) && defined(CONFIG_TARGET_LX2160ARDB)
565 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
566#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000567
Stephen Carlson70b1e8c2021-06-22 16:43:03 -0700568 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000569
Florin Chiculitad90d5062019-04-22 11:57:47 +0300570#if defined(CONFIG_FSL_MC_ENET) && defined(CONFIG_TARGET_LX2160ARDB)
571 /* invert AQR107 IRQ pins polarity */
572 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR107_IRQ_MASK);
573#endif
574
Ioana Ciorneicffa3b12020-04-27 15:21:15 +0300575#if !defined(CONFIG_SYS_EARLY_PCI_INIT) && defined(CONFIG_DM_ETH)
576 pci_init();
577#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000578 return 0;
579}
580
581void detail_board_ddr_info(void)
582{
583 int i;
584 u64 ddr_size = 0;
585
586 puts("\nDDR ");
587 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
588 ddr_size += gd->bd->bi_dram[i].size;
589 print_size(ddr_size, "");
590 print_ddr_info(0);
591}
592
Alex Margineanb4f80232020-01-11 01:05:36 +0200593#ifdef CONFIG_MISC_INIT_R
594int misc_init_r(void)
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000595{
Pankaj Bansal338baa32019-02-08 10:29:58 +0000596 config_board_mux();
597
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000598 return 0;
599}
600#endif
601
Stephen Carlsonc3301a22021-02-08 11:11:29 +0100602#ifdef CONFIG_VID
603u16 soc_get_fuse_vid(int vid_index)
604{
605 static const u16 vdd[32] = {
606 8250,
607 7875,
608 7750,
609 0, /* reserved */
610 0, /* reserved */
611 0, /* reserved */
612 0, /* reserved */
613 0, /* reserved */
614 0, /* reserved */
615 0, /* reserved */
616 0, /* reserved */
617 0, /* reserved */
618 0, /* reserved */
619 0, /* reserved */
620 0, /* reserved */
621 0, /* reserved */
622 8000,
623 8125,
624 8250,
625 0, /* reserved */
626 8500,
627 0, /* reserved */
628 0, /* reserved */
629 0, /* reserved */
630 0, /* reserved */
631 0, /* reserved */
632 0, /* reserved */
633 0, /* reserved */
634 0, /* reserved */
635 0, /* reserved */
636 0, /* reserved */
637 0, /* reserved */
638 };
639
640 return vdd[vid_index];
641};
642#endif
643
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000644#ifdef CONFIG_FSL_MC_ENET
645extern int fdt_fixup_board_phy(void *fdt);
646
647void fdt_fixup_board_enet(void *fdt)
648{
649 int offset;
650
651 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
652
653 if (offset < 0)
654 offset = fdt_path_offset(fdt, "/fsl-mc");
655
656 if (offset < 0) {
657 printf("%s: fsl-mc node not found in device tree (error %d)\n",
658 __func__, offset);
659 return;
660 }
661
Mian Yousaf Kaukabc387c012019-05-23 10:57:33 +0200662 if (get_mc_boot_status() == 0 &&
663 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0)) {
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000664 fdt_status_okay(fdt, offset);
Ioana Ciorneicffa3b12020-04-27 15:21:15 +0300665#ifndef CONFIG_DM_ETH
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000666 fdt_fixup_board_phy(fdt);
Ioana Ciorneicffa3b12020-04-27 15:21:15 +0300667#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000668 } else {
669 fdt_status_fail(fdt, offset);
670 }
671}
672
673void board_quiesce_devices(void)
674{
675 fsl_mc_ldpaa_exit(gd->bd);
676}
677#endif
678
Wasim Khan4c4c1f82021-06-17 09:12:59 +0200679#if CONFIG_IS_ENABLED(TARGET_LX2160ARDB)
680int fdt_fixup_add_thermal(void *blob, int mux_node, int channel, int reg)
681{
682 int err;
683 int noff;
684 int offset;
685 char channel_node_name[50];
686 char thermal_node_name[50];
687 u32 phandle;
688
689 snprintf(channel_node_name, sizeof(channel_node_name),
690 "i2c@%x", channel);
691 debug("channel_node_name = %s\n", channel_node_name);
692
693 snprintf(thermal_node_name, sizeof(thermal_node_name),
694 "temperature-sensor@%x", reg);
695 debug("thermal_node_name = %s\n", thermal_node_name);
696
697 err = fdt_increase_size(blob, 200);
698 if (err) {
699 printf("fdt_increase_size: err=%s\n", fdt_strerror(err));
700 return err;
701 }
702
703 noff = fdt_subnode_offset(blob, mux_node, (const char *)
704 channel_node_name);
705 if (noff < 0) {
706 /* channel node not found - create it */
707 noff = fdt_add_subnode(blob, mux_node, channel_node_name);
708 if (noff < 0) {
709 printf("fdt_add_subnode: err=%s\n", fdt_strerror(err));
710 return err;
711 }
712 fdt_setprop_u32 (blob, noff, "#address-cells", 1);
713 fdt_setprop_u32 (blob, noff, "#size-cells", 0);
714 fdt_setprop_u32 (blob, noff, "reg", channel);
715 }
716
717 /* Create thermal node*/
718 offset = fdt_add_subnode(blob, noff, thermal_node_name);
719 fdt_setprop(blob, offset, "compatible", "nxp,sa56004",
720 strlen("nxp,sa56004") + 1);
721 fdt_setprop_u32 (blob, offset, "reg", reg);
722
723 /* fixup phandle*/
724 noff = fdt_node_offset_by_compatible(blob, -1, "regulator-fixed");
725 if (noff < 0) {
726 printf("%s : failed to get phandle\n", __func__);
727 return noff;
728 }
729 phandle = fdt_get_phandle(blob, noff);
730 fdt_setprop_u32 (blob, offset, "vcc-supply", phandle);
731
732 return 0;
733}
734
735void fdt_fixup_delete_thermal(void *blob, int mux_node, int channel, int reg)
736{
737 int node;
738 int value;
739 int err;
740 int subnode;
741
742 fdt_for_each_subnode(subnode, blob, mux_node) {
743 value = fdtdec_get_uint(blob, subnode, "reg", -1);
744 if (value == channel) {
745 /* delete thermal node */
746 fdt_for_each_subnode(node, blob, subnode) {
747 value = fdtdec_get_uint(blob, node, "reg", -1);
748 err = fdt_node_check_compatible(blob, node,
749 "nxp,sa56004");
750 if (!err && value == reg) {
751 fdt_del_node(blob, node);
752 break;
753 }
754 }
755 }
756 }
757}
758
759void fdt_fixup_i2c_thermal_node(void *blob)
760{
761 int i2coffset;
762 int mux_node;
763 int reg;
764 int err;
765
766 i2coffset = fdt_node_offset_by_compat_reg(blob, "fsl,vf610-i2c",
767 0x2000000);
768 if (i2coffset != -FDT_ERR_NOTFOUND) {
769 fdt_for_each_subnode(mux_node, blob, i2coffset) {
770 reg = fdtdec_get_uint(blob, mux_node, "reg", -1);
771 err = fdt_node_check_compatible(blob, mux_node,
772 "nxp,pca9547");
773 if (!err && reg == 0x77) {
774 fdt_fixup_delete_thermal(blob, mux_node,
775 0x3, 0x4d);
776 err = fdt_fixup_add_thermal(blob, mux_node,
777 0x3, 0x48);
778 if (err)
779 printf("%s: Add thermal node failed\n",
780 __func__);
781 }
782 }
783 } else {
784 printf("%s: i2c node not found\n", __func__);
785 }
786}
787#endif
788
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000789#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900790int ft_board_setup(void *blob, struct bd_info *bd)
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000791{
792 int i;
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530793 u16 mc_memory_bank = 0;
794
795 u64 *base;
796 u64 *size;
797 u64 mc_memory_base = 0;
798 u64 mc_memory_size = 0;
799 u16 total_memory_banks;
Wasim Khandd7ea292021-09-20 15:45:33 +0200800 int err;
Wasim Khan4c4c1f82021-06-17 09:12:59 +0200801#if CONFIG_IS_ENABLED(TARGET_LX2160ARDB)
802 u8 board_rev;
803#endif
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000804
Wasim Khandd7ea292021-09-20 15:45:33 +0200805 err = fdt_increase_size(blob, 512);
806 if (err) {
807 printf("%s fdt_increase_size: err=%s\n", __func__,
808 fdt_strerror(err));
809 return err;
810 }
811
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000812 ft_cpu_setup(blob, bd);
813
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530814 fdt_fixup_mc_ddr(&mc_memory_base, &mc_memory_size);
815
816 if (mc_memory_base != 0)
817 mc_memory_bank++;
818
819 total_memory_banks = CONFIG_NR_DRAM_BANKS + mc_memory_bank;
820
821 base = calloc(total_memory_banks, sizeof(u64));
822 size = calloc(total_memory_banks, sizeof(u64));
823
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000824 /* fixup DT for the three GPP DDR banks */
825 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
826 base[i] = gd->bd->bi_dram[i].start;
827 size[i] = gd->bd->bi_dram[i].size;
828 }
829
830#ifdef CONFIG_RESV_RAM
831 /* reduce size if reserved memory is within this bank */
832 if (gd->arch.resv_ram >= base[0] &&
833 gd->arch.resv_ram < base[0] + size[0])
834 size[0] = gd->arch.resv_ram - base[0];
835 else if (gd->arch.resv_ram >= base[1] &&
836 gd->arch.resv_ram < base[1] + size[1])
837 size[1] = gd->arch.resv_ram - base[1];
838 else if (gd->arch.resv_ram >= base[2] &&
839 gd->arch.resv_ram < base[2] + size[2])
840 size[2] = gd->arch.resv_ram - base[2];
841#endif
842
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530843 if (mc_memory_base != 0) {
844 for (i = 0; i <= total_memory_banks; i++) {
845 if (base[i] == 0 && size[i] == 0) {
846 base[i] = mc_memory_base;
847 size[i] = mc_memory_size;
848 break;
849 }
850 }
851 }
852
853 fdt_fixup_memory_banks(blob, base, size, total_memory_banks);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000854
Tom Rini8a091622021-07-09 10:11:55 -0400855#ifdef CONFIG_USB_HOST
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000856 fsl_fdt_fixup_dr_usb(blob, bd);
857#endif
858
859#ifdef CONFIG_FSL_MC_ENET
860 fdt_fsl_mc_fixup_iommu_map_entry(blob);
861 fdt_fixup_board_enet(blob);
862#endif
Laurentiu Tudor7085d072019-10-18 09:01:55 +0000863 fdt_fixup_icid(blob);
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000864
Wasim Khan4c4c1f82021-06-17 09:12:59 +0200865#if CONFIG_IS_ENABLED(TARGET_LX2160ARDB)
866 board_rev = (QIXIS_READ(arch) & 0xf) - 1 + 'A';
867 if (board_rev == 'C')
868 fdt_fixup_i2c_thermal_node(blob);
869#endif
870
Priyanka Jainfd45ca02018-11-28 13:04:27 +0000871 return 0;
872}
873#endif
874
875void qixis_dump_switch(void)
876{
877 int i, nr_of_cfgsw;
878
879 QIXIS_WRITE(cms[0], 0x00);
880 nr_of_cfgsw = QIXIS_READ(cms[1]);
881
882 puts("DIP switch settings dump:\n");
883 for (i = 1; i <= nr_of_cfgsw; i++) {
884 QIXIS_WRITE(cms[0], i);
885 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
886 }
887}