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