ls1088a.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2017 NXP
  4. */
  5. #include <common.h>
  6. #include <i2c.h>
  7. #include <malloc.h>
  8. #include <errno.h>
  9. #include <netdev.h>
  10. #include <fsl_ifc.h>
  11. #include <fsl_ddr.h>
  12. #include <fsl_sec.h>
  13. #include <asm/io.h>
  14. #include <fdt_support.h>
  15. #include <linux/libfdt.h>
  16. #include <fsl-mc/fsl_mc.h>
  17. #include <environment.h>
  18. #include <asm/arch-fsl-layerscape/soc.h>
  19. #include <asm/arch/ppa.h>
  20. #include <hwconfig.h>
  21. #include <asm/arch/fsl_serdes.h>
  22. #include <asm/arch/soc.h>
  23. #include "../common/qixis.h"
  24. #include "ls1088a_qixis.h"
  25. #include "../common/vid.h"
  26. #include <fsl_immap.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. int board_early_init_f(void)
  29. {
  30. #if defined(CONFIG_SYS_I2C_EARLY_INIT) && defined(CONFIG_TARGET_LS1088AQDS)
  31. i2c_early_init_f();
  32. #endif
  33. fsl_lsch3_early_init_f();
  34. return 0;
  35. }
  36. #ifdef CONFIG_FSL_QIXIS
  37. unsigned long long get_qixis_addr(void)
  38. {
  39. unsigned long long addr;
  40. if (gd->flags & GD_FLG_RELOC)
  41. addr = QIXIS_BASE_PHYS;
  42. else
  43. addr = QIXIS_BASE_PHYS_EARLY;
  44. /*
  45. * IFC address under 256MB is mapped to 0x30000000, any address above
  46. * is mapped to 0x5_10000000 up to 4GB.
  47. */
  48. addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
  49. return addr;
  50. }
  51. #endif
  52. #if defined(CONFIG_VID)
  53. int init_func_vid(void)
  54. {
  55. if (adjust_vdd(0) < 0)
  56. printf("core voltage not adjusted\n");
  57. return 0;
  58. }
  59. #endif
  60. #if !defined(CONFIG_SPL_BUILD)
  61. int checkboard(void)
  62. {
  63. char buf[64];
  64. u8 sw;
  65. static const char *const freq[] = {"100", "125", "156.25",
  66. "100 separate SSCG"};
  67. int clock;
  68. #ifdef CONFIG_TARGET_LS1088AQDS
  69. printf("Board: LS1088A-QDS, ");
  70. #else
  71. printf("Board: LS1088A-RDB, ");
  72. #endif
  73. sw = QIXIS_READ(arch);
  74. printf("Board Arch: V%d, ", sw >> 4);
  75. #ifdef CONFIG_TARGET_LS1088AQDS
  76. printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
  77. #else
  78. printf("Board version: %c, boot from ", (sw & 0xf) + 'A');
  79. #endif
  80. memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
  81. sw = QIXIS_READ(brdcfg[0]);
  82. sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
  83. #ifdef CONFIG_SD_BOOT
  84. puts("SD card\n");
  85. #endif
  86. switch (sw) {
  87. #ifdef CONFIG_TARGET_LS1088AQDS
  88. case 0:
  89. case 1:
  90. case 2:
  91. case 3:
  92. case 4:
  93. case 5:
  94. case 6:
  95. case 7:
  96. printf("vBank: %d\n", sw);
  97. break;
  98. case 8:
  99. puts("PromJet\n");
  100. break;
  101. case 15:
  102. puts("IFCCard\n");
  103. break;
  104. case 14:
  105. #else
  106. case 0:
  107. #endif
  108. puts("QSPI:");
  109. sw = QIXIS_READ(brdcfg[0]);
  110. sw = (sw & QIXIS_QMAP_MASK) >> QIXIS_QMAP_SHIFT;
  111. if (sw == 0 || sw == 4)
  112. puts("0\n");
  113. else if (sw == 1)
  114. puts("1\n");
  115. else
  116. puts("EMU\n");
  117. break;
  118. default:
  119. printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
  120. break;
  121. }
  122. #ifdef CONFIG_TARGET_LS1088AQDS
  123. printf("FPGA: v%d (%s), build %d",
  124. (int)QIXIS_READ(scver), qixis_read_tag(buf),
  125. (int)qixis_read_minor());
  126. /* the timestamp string contains "\n" at the end */
  127. printf(" on %s", qixis_read_time(buf));
  128. #else
  129. printf("CPLD: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
  130. #endif
  131. /*
  132. * Display the actual SERDES reference clocks as configured by the
  133. * dip switches on the board. Note that the SWx registers could
  134. * technically be set to force the reference clocks to match the
  135. * values that the SERDES expects (or vice versa). For now, however,
  136. * we just display both values and hope the user notices when they
  137. * don't match.
  138. */
  139. puts("SERDES1 Reference : ");
  140. sw = QIXIS_READ(brdcfg[2]);
  141. clock = (sw >> 6) & 3;
  142. printf("Clock1 = %sMHz ", freq[clock]);
  143. clock = (sw >> 4) & 3;
  144. printf("Clock2 = %sMHz", freq[clock]);
  145. puts("\nSERDES2 Reference : ");
  146. clock = (sw >> 2) & 3;
  147. printf("Clock1 = %sMHz ", freq[clock]);
  148. clock = (sw >> 0) & 3;
  149. printf("Clock2 = %sMHz\n", freq[clock]);
  150. return 0;
  151. }
  152. #endif
  153. bool if_board_diff_clk(void)
  154. {
  155. #ifdef CONFIG_TARGET_LS1088AQDS
  156. u8 diff_conf = QIXIS_READ(brdcfg[11]);
  157. return diff_conf & 0x40;
  158. #else
  159. u8 diff_conf = QIXIS_READ(dutcfg[11]);
  160. return diff_conf & 0x80;
  161. #endif
  162. }
  163. unsigned long get_board_sys_clk(void)
  164. {
  165. u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
  166. switch (sysclk_conf & 0x0f) {
  167. case QIXIS_SYSCLK_83:
  168. return 83333333;
  169. case QIXIS_SYSCLK_100:
  170. return 100000000;
  171. case QIXIS_SYSCLK_125:
  172. return 125000000;
  173. case QIXIS_SYSCLK_133:
  174. return 133333333;
  175. case QIXIS_SYSCLK_150:
  176. return 150000000;
  177. case QIXIS_SYSCLK_160:
  178. return 160000000;
  179. case QIXIS_SYSCLK_166:
  180. return 166666666;
  181. }
  182. return 66666666;
  183. }
  184. unsigned long get_board_ddr_clk(void)
  185. {
  186. u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
  187. if (if_board_diff_clk())
  188. return get_board_sys_clk();
  189. switch ((ddrclk_conf & 0x30) >> 4) {
  190. case QIXIS_DDRCLK_100:
  191. return 100000000;
  192. case QIXIS_DDRCLK_125:
  193. return 125000000;
  194. case QIXIS_DDRCLK_133:
  195. return 133333333;
  196. }
  197. return 66666666;
  198. }
  199. int select_i2c_ch_pca9547(u8 ch)
  200. {
  201. int ret;
  202. ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
  203. if (ret) {
  204. puts("PCA: failed to select proper channel\n");
  205. return ret;
  206. }
  207. return 0;
  208. }
  209. #if !defined(CONFIG_SPL_BUILD)
  210. void board_retimer_init(void)
  211. {
  212. u8 reg;
  213. /* Retimer is connected to I2C1_CH5 */
  214. select_i2c_ch_pca9547(I2C_MUX_CH5);
  215. /* Access to Control/Shared register */
  216. reg = 0x0;
  217. i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
  218. /* Read device revision and ID */
  219. i2c_read(I2C_RETIMER_ADDR, 1, 1, &reg, 1);
  220. debug("Retimer version id = 0x%x\n", reg);
  221. /* Enable Broadcast. All writes target all channel register sets */
  222. reg = 0x0c;
  223. i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
  224. /* Reset Channel Registers */
  225. i2c_read(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
  226. reg |= 0x4;
  227. i2c_write(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
  228. /* Set data rate as 10.3125 Gbps */
  229. reg = 0x90;
  230. i2c_write(I2C_RETIMER_ADDR, 0x60, 1, &reg, 1);
  231. reg = 0xb3;
  232. i2c_write(I2C_RETIMER_ADDR, 0x61, 1, &reg, 1);
  233. reg = 0x90;
  234. i2c_write(I2C_RETIMER_ADDR, 0x62, 1, &reg, 1);
  235. reg = 0xb3;
  236. i2c_write(I2C_RETIMER_ADDR, 0x63, 1, &reg, 1);
  237. reg = 0xcd;
  238. i2c_write(I2C_RETIMER_ADDR, 0x64, 1, &reg, 1);
  239. /* Select VCO Divider to full rate (000) */
  240. i2c_read(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
  241. reg &= 0x0f;
  242. reg |= 0x70;
  243. i2c_write(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
  244. #ifdef CONFIG_TARGET_LS1088AQDS
  245. /* Retimer is connected to I2C1_CH5 */
  246. select_i2c_ch_pca9547(I2C_MUX_CH5);
  247. /* Access to Control/Shared register */
  248. reg = 0x0;
  249. i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
  250. /* Read device revision and ID */
  251. i2c_read(I2C_RETIMER_ADDR2, 1, 1, &reg, 1);
  252. debug("Retimer version id = 0x%x\n", reg);
  253. /* Enable Broadcast. All writes target all channel register sets */
  254. reg = 0x0c;
  255. i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
  256. /* Reset Channel Registers */
  257. i2c_read(I2C_RETIMER_ADDR2, 0, 1, &reg, 1);
  258. reg |= 0x4;
  259. i2c_write(I2C_RETIMER_ADDR2, 0, 1, &reg, 1);
  260. /* Set data rate as 10.3125 Gbps */
  261. reg = 0x90;
  262. i2c_write(I2C_RETIMER_ADDR2, 0x60, 1, &reg, 1);
  263. reg = 0xb3;
  264. i2c_write(I2C_RETIMER_ADDR2, 0x61, 1, &reg, 1);
  265. reg = 0x90;
  266. i2c_write(I2C_RETIMER_ADDR2, 0x62, 1, &reg, 1);
  267. reg = 0xb3;
  268. i2c_write(I2C_RETIMER_ADDR2, 0x63, 1, &reg, 1);
  269. reg = 0xcd;
  270. i2c_write(I2C_RETIMER_ADDR2, 0x64, 1, &reg, 1);
  271. /* Select VCO Divider to full rate (000) */
  272. i2c_read(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
  273. reg &= 0x0f;
  274. reg |= 0x70;
  275. i2c_write(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
  276. #endif
  277. /*return the default channel*/
  278. select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
  279. }
  280. #ifdef CONFIG_MISC_INIT_R
  281. int misc_init_r(void)
  282. {
  283. #ifdef CONFIG_TARGET_LS1088ARDB
  284. u8 brdcfg5;
  285. if (hwconfig("esdhc-force-sd")) {
  286. brdcfg5 = QIXIS_READ(brdcfg[5]);
  287. brdcfg5 &= ~BRDCFG5_SPISDHC_MASK;
  288. brdcfg5 |= BRDCFG5_FORCE_SD;
  289. QIXIS_WRITE(brdcfg[5], brdcfg5);
  290. }
  291. #endif
  292. return 0;
  293. }
  294. #endif
  295. #endif
  296. int i2c_multiplexer_select_vid_channel(u8 channel)
  297. {
  298. return select_i2c_ch_pca9547(channel);
  299. }
  300. #ifdef CONFIG_TARGET_LS1088AQDS
  301. /* read the current value(SVDD) of the LTM Regulator Voltage */
  302. int get_serdes_volt(void)
  303. {
  304. int ret, vcode = 0;
  305. u8 chan = PWM_CHANNEL0;
  306. /* Select the PAGE 0 using PMBus commands PAGE for VDD */
  307. ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
  308. PMBUS_CMD_PAGE, 1, &chan, 1);
  309. if (ret) {
  310. printf("VID: failed to select VDD Page 0\n");
  311. return ret;
  312. }
  313. /* Read the output voltage using PMBus command READ_VOUT */
  314. ret = i2c_read(I2C_SVDD_MONITOR_ADDR,
  315. PMBUS_CMD_READ_VOUT, 1, (void *)&vcode, 2);
  316. if (ret) {
  317. printf("VID: failed to read the volatge\n");
  318. return ret;
  319. }
  320. return vcode;
  321. }
  322. int set_serdes_volt(int svdd)
  323. {
  324. int ret, vdd_last;
  325. u8 buff[5] = {0x04, PWM_CHANNEL0, PMBUS_CMD_VOUT_COMMAND,
  326. svdd & 0xFF, (svdd & 0xFF00) >> 8};
  327. /* Write the desired voltage code to the SVDD regulator */
  328. ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
  329. PMBUS_CMD_PAGE_PLUS_WRITE, 1, (void *)&buff, 5);
  330. if (ret) {
  331. printf("VID: I2C failed to write to the volatge regulator\n");
  332. return -1;
  333. }
  334. /* Wait for the volatge to get to the desired value */
  335. do {
  336. vdd_last = get_serdes_volt();
  337. if (vdd_last < 0) {
  338. printf("VID: Couldn't read sensor abort VID adjust\n");
  339. return -1;
  340. }
  341. } while (vdd_last != svdd);
  342. return 1;
  343. }
  344. #else
  345. int get_serdes_volt(void)
  346. {
  347. return 0;
  348. }
  349. int set_serdes_volt(int svdd)
  350. {
  351. int ret;
  352. u8 brdcfg4;
  353. printf("SVDD changing of RDB\n");
  354. /* Read the BRDCFG54 via CLPD */
  355. ret = i2c_read(CONFIG_SYS_I2C_FPGA_ADDR,
  356. QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
  357. if (ret) {
  358. printf("VID: I2C failed to read the CPLD BRDCFG4\n");
  359. return -1;
  360. }
  361. brdcfg4 = brdcfg4 | 0x08;
  362. /* Write to the BRDCFG4 */
  363. ret = i2c_write(CONFIG_SYS_I2C_FPGA_ADDR,
  364. QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
  365. if (ret) {
  366. debug("VID: I2C failed to set the SVDD CPLD BRDCFG4\n");
  367. return -1;
  368. }
  369. /* Wait for the volatge to get to the desired value */
  370. udelay(10000);
  371. return 1;
  372. }
  373. #endif
  374. /* this function disables the SERDES, changes the SVDD Voltage and enables it*/
  375. int board_adjust_vdd(int vdd)
  376. {
  377. int ret = 0;
  378. debug("%s: vdd = %d\n", __func__, vdd);
  379. /* Special settings to be performed when voltage is 900mV */
  380. if (vdd == 900) {
  381. ret = setup_serdes_volt(vdd);
  382. if (ret < 0) {
  383. ret = -1;
  384. goto exit;
  385. }
  386. }
  387. exit:
  388. return ret;
  389. }
  390. #if !defined(CONFIG_SPL_BUILD)
  391. int board_init(void)
  392. {
  393. init_final_memctl_regs();
  394. #if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
  395. u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
  396. #endif
  397. select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
  398. board_retimer_init();
  399. #ifdef CONFIG_ENV_IS_NOWHERE
  400. gd->env_addr = (ulong)&default_environment[0];
  401. #endif
  402. #if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
  403. /* invert AQR105 IRQ pins polarity */
  404. out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR105_IRQ_MASK);
  405. #endif
  406. #ifdef CONFIG_FSL_CAAM
  407. sec_init();
  408. #endif
  409. #ifdef CONFIG_FSL_LS_PPA
  410. ppa_init();
  411. #endif
  412. return 0;
  413. }
  414. void detail_board_ddr_info(void)
  415. {
  416. puts("\nDDR ");
  417. print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
  418. print_ddr_info(0);
  419. }
  420. #if defined(CONFIG_ARCH_MISC_INIT)
  421. int arch_misc_init(void)
  422. {
  423. return 0;
  424. }
  425. #endif
  426. #ifdef CONFIG_FSL_MC_ENET
  427. void fdt_fixup_board_enet(void *fdt)
  428. {
  429. int offset;
  430. offset = fdt_path_offset(fdt, "/fsl-mc");
  431. if (offset < 0)
  432. offset = fdt_path_offset(fdt, "/fsl,dprc@0");
  433. if (offset < 0) {
  434. printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
  435. __func__, offset);
  436. return;
  437. }
  438. if ((get_mc_boot_status() == 0) && (get_dpl_apply_status() == 0))
  439. fdt_status_okay(fdt, offset);
  440. else
  441. fdt_status_fail(fdt, offset);
  442. }
  443. #endif
  444. #ifdef CONFIG_OF_BOARD_SETUP
  445. void fsl_fdt_fixup_flash(void *fdt)
  446. {
  447. int offset;
  448. /*
  449. * IFC-NOR and QSPI are muxed on SoC.
  450. * So disable IFC node in dts if QSPI is enabled or
  451. * disable QSPI node in dts in case QSPI is not enabled.
  452. */
  453. #ifdef CONFIG_FSL_QSPI
  454. offset = fdt_path_offset(fdt, "/soc/ifc/nor");
  455. if (offset < 0)
  456. offset = fdt_path_offset(fdt, "/ifc/nor");
  457. #else
  458. offset = fdt_path_offset(fdt, "/soc/quadspi");
  459. if (offset < 0)
  460. offset = fdt_path_offset(fdt, "/quadspi");
  461. #endif
  462. if (offset < 0)
  463. return;
  464. fdt_status_disabled(fdt, offset);
  465. }
  466. int ft_board_setup(void *blob, bd_t *bd)
  467. {
  468. int err, i;
  469. u64 base[CONFIG_NR_DRAM_BANKS];
  470. u64 size[CONFIG_NR_DRAM_BANKS];
  471. ft_cpu_setup(blob, bd);
  472. /* fixup DT for the two GPP DDR banks */
  473. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  474. base[i] = gd->bd->bi_dram[i].start;
  475. size[i] = gd->bd->bi_dram[i].size;
  476. }
  477. #ifdef CONFIG_RESV_RAM
  478. /* reduce size if reserved memory is within this bank */
  479. if (gd->arch.resv_ram >= base[0] &&
  480. gd->arch.resv_ram < base[0] + size[0])
  481. size[0] = gd->arch.resv_ram - base[0];
  482. else if (gd->arch.resv_ram >= base[1] &&
  483. gd->arch.resv_ram < base[1] + size[1])
  484. size[1] = gd->arch.resv_ram - base[1];
  485. #endif
  486. fdt_fixup_memory_banks(blob, base, size, CONFIG_NR_DRAM_BANKS);
  487. fsl_fdt_fixup_flash(blob);
  488. #ifdef CONFIG_FSL_MC_ENET
  489. fdt_fixup_board_enet(blob);
  490. err = fsl_mc_ldpaa_exit(bd);
  491. if (err)
  492. return err;
  493. #endif
  494. return 0;
  495. }
  496. #endif
  497. #endif /* defined(CONFIG_SPL_BUILD) */