Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2016 Freescale Semiconductor, Inc. |
Gaurav Jain | 476c639 | 2022-03-24 11:50:35 +0530 | [diff] [blame] | 4 | * Copyright 2021 NXP |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 7 | #include <common.h> |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 8 | #include <i2c.h> |
| 9 | #include <fdt_support.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Sean Anderson | 99e1286 | 2022-03-22 17:16:05 -0400 | [diff] [blame] | 11 | #include <semihosting.h> |
| 12 | #include <serial.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <asm/arch/clock.h> |
| 16 | #include <asm/arch/fsl_serdes.h> |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 17 | #include <asm/arch/soc.h> |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 18 | #include <asm/arch-fsl-layerscape/fsl_icid.h> |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 19 | #include <hwconfig.h> |
| 20 | #include <ahci.h> |
| 21 | #include <mmc.h> |
| 22 | #include <scsi.h> |
| 23 | #include <fm_eth.h> |
| 24 | #include <fsl_csu.h> |
| 25 | #include <fsl_esdhc.h> |
Hou Zhiqiang | 67b6d0a | 2016-12-09 16:09:01 +0800 | [diff] [blame] | 26 | #include <power/mc34vr500_pmic.h> |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 27 | #include "cpld.h" |
| 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Sean Anderson | 99e1286 | 2022-03-22 17:16:05 -0400 | [diff] [blame] | 31 | struct serial_device *default_serial_console(void) |
| 32 | { |
| 33 | #if IS_ENABLED(CONFIG_SEMIHOSTING_SERIAL) |
Sean Anderson | 409024e | 2022-03-22 16:59:33 -0400 | [diff] [blame] | 34 | if (semihosting_enabled()) |
| 35 | return &serial_smh_device; |
Sean Anderson | 99e1286 | 2022-03-22 17:16:05 -0400 | [diff] [blame] | 36 | #endif |
| 37 | return &eserial1_device; |
| 38 | } |
| 39 | |
Sumit Garg | c064fc7 | 2017-03-30 09:53:13 +0530 | [diff] [blame] | 40 | int board_early_init_f(void) |
| 41 | { |
| 42 | fsl_lsch2_early_init_f(); |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | #ifndef CONFIG_SPL_BUILD |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 48 | int checkboard(void) |
| 49 | { |
| 50 | static const char *freq[2] = {"100.00MHZ", "156.25MHZ"}; |
| 51 | u8 cfg_rcw_src1, cfg_rcw_src2; |
| 52 | u16 cfg_rcw_src; |
| 53 | u8 sd1refclk_sel; |
| 54 | |
| 55 | puts("Board: LS1046ARDB, boot from "); |
| 56 | |
| 57 | cfg_rcw_src1 = CPLD_READ(cfg_rcw_src1); |
| 58 | cfg_rcw_src2 = CPLD_READ(cfg_rcw_src2); |
| 59 | cpld_rev_bit(&cfg_rcw_src1); |
| 60 | cfg_rcw_src = cfg_rcw_src1; |
| 61 | cfg_rcw_src = (cfg_rcw_src << 1) | cfg_rcw_src2; |
| 62 | |
| 63 | if (cfg_rcw_src == 0x44) |
| 64 | printf("QSPI vBank %d\n", CPLD_READ(vbank)); |
| 65 | else if (cfg_rcw_src == 0x40) |
| 66 | puts("SD\n"); |
| 67 | else |
| 68 | puts("Invalid setting of SW5\n"); |
| 69 | |
| 70 | printf("CPLD: V%x.%x\nPCBA: V%x.0\n", CPLD_READ(cpld_ver), |
| 71 | CPLD_READ(cpld_ver_sub), CPLD_READ(pcba_ver)); |
| 72 | |
| 73 | puts("SERDES Reference Clocks:\n"); |
| 74 | sd1refclk_sel = CPLD_READ(sd1refclk_sel); |
| 75 | printf("SD1_CLK1 = %s, SD1_CLK2 = %s\n", freq[sd1refclk_sel], freq[0]); |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 80 | int board_init(void) |
| 81 | { |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 82 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CFG_SYS_FSL_SCFG_ADDR; |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 83 | |
Udit Agarwal | 22ec238 | 2019-11-07 16:11:32 +0000 | [diff] [blame] | 84 | #ifdef CONFIG_NXP_ESBC |
Vinitha Pillai-B57223 | a47072e | 2017-03-23 13:48:18 +0530 | [diff] [blame] | 85 | /* |
| 86 | * In case of Secure Boot, the IBR configures the SMMU |
| 87 | * to allow only Secure transactions. |
| 88 | * SMMU must be reset in bypass mode. |
| 89 | * Set the ClientPD bit and Clear the USFCFG Bit |
| 90 | */ |
| 91 | u32 val; |
| 92 | val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 93 | out_le32(SMMU_SCR0, val); |
| 94 | val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 95 | out_le32(SMMU_NSCR0, val); |
| 96 | #endif |
| 97 | |
Martin Schiller | fb425ee | 2021-11-17 12:59:20 +0100 | [diff] [blame] | 98 | #if !defined(CONFIG_SYS_EARLY_PCI_INIT) && defined(CONFIG_DM_ETH) |
| 99 | pci_init(); |
| 100 | #endif |
| 101 | |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 102 | /* invert AQR105 IRQ pins polarity */ |
| 103 | out_be32(&scfg->intpcr, AQR105_IRQ_MASK); |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
Hou Zhiqiang | 67b6d0a | 2016-12-09 16:09:01 +0800 | [diff] [blame] | 108 | int board_setup_core_volt(u32 vdd) |
| 109 | { |
| 110 | bool en_0v9; |
| 111 | |
| 112 | en_0v9 = (vdd == 900) ? true : false; |
| 113 | cpld_select_core_volt(en_0v9); |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | int get_serdes_volt(void) |
| 119 | { |
| 120 | return mc34vr500_get_sw_volt(SW4); |
| 121 | } |
| 122 | |
| 123 | int set_serdes_volt(int svdd) |
| 124 | { |
| 125 | return mc34vr500_set_sw_volt(SW4, svdd); |
| 126 | } |
| 127 | |
| 128 | int power_init_board(void) |
| 129 | { |
| 130 | int ret; |
| 131 | |
| 132 | ret = power_mc34vr500_init(0); |
| 133 | if (ret) |
| 134 | return ret; |
| 135 | |
| 136 | setup_chip_volt(); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 141 | void config_board_mux(void) |
| 142 | { |
| 143 | #ifdef CONFIG_HAS_FSL_XHCI_USB |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 144 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CFG_SYS_FSL_SCFG_ADDR; |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 145 | u32 usb_pwrfault; |
| 146 | |
| 147 | /* USB3 is not used, configure mux to IIC4_SCL/IIC4_SDA */ |
| 148 | out_be32(&scfg->rcwpmuxcr0, 0x3300); |
| 149 | out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1); |
| 150 | usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED << |
| 151 | SCFG_USBPWRFAULT_USB3_SHIFT) | |
| 152 | (SCFG_USBPWRFAULT_DEDICATED << |
| 153 | SCFG_USBPWRFAULT_USB2_SHIFT) | |
| 154 | (SCFG_USBPWRFAULT_SHARED << |
| 155 | SCFG_USBPWRFAULT_USB1_SHIFT); |
| 156 | out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault); |
| 157 | #endif |
| 158 | } |
| 159 | |
| 160 | #ifdef CONFIG_MISC_INIT_R |
| 161 | int misc_init_r(void) |
| 162 | { |
| 163 | config_board_mux(); |
| 164 | return 0; |
| 165 | } |
| 166 | #endif |
| 167 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 168 | int ft_board_setup(void *blob, struct bd_info *bd) |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 169 | { |
| 170 | u64 base[CONFIG_NR_DRAM_BANKS]; |
| 171 | u64 size[CONFIG_NR_DRAM_BANKS]; |
| 172 | |
| 173 | /* fixup DT for the two DDR banks */ |
| 174 | base[0] = gd->bd->bi_dram[0].start; |
| 175 | size[0] = gd->bd->bi_dram[0].size; |
| 176 | base[1] = gd->bd->bi_dram[1].start; |
| 177 | size[1] = gd->bd->bi_dram[1].size; |
| 178 | |
| 179 | fdt_fixup_memory_banks(blob, base, size, 2); |
| 180 | ft_cpu_setup(blob, bd); |
| 181 | |
| 182 | #ifdef CONFIG_SYS_DPAA_FMAN |
Madalin Bucur | b76b0a6 | 2020-04-23 16:25:19 +0300 | [diff] [blame] | 183 | #ifndef CONFIG_DM_ETH |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 184 | fdt_fixup_fman_ethernet(blob); |
| 185 | #endif |
Madalin Bucur | b76b0a6 | 2020-04-23 16:25:19 +0300 | [diff] [blame] | 186 | #endif |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 187 | |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 188 | fdt_fixup_icid(blob); |
| 189 | |
Mingkai Hu | d239651 | 2016-09-07 18:47:28 +0800 | [diff] [blame] | 190 | return 0; |
| 191 | } |
Sumit Garg | c064fc7 | 2017-03-30 09:53:13 +0530 | [diff] [blame] | 192 | #endif |