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