Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2019 NXP |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <i2c.h> |
| 8 | #include <fdt_support.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/clock.h> |
| 13 | #include <asm/arch/fsl_serdes.h> |
| 14 | #include <asm/arch/soc.h> |
| 15 | #include <asm/arch-fsl-layerscape/fsl_icid.h> |
| 16 | #include <hwconfig.h> |
| 17 | #include <ahci.h> |
| 18 | #include <mmc.h> |
| 19 | #include <scsi.h> |
| 20 | #include <fm_eth.h> |
| 21 | #include <fsl_csu.h> |
| 22 | #include <fsl_esdhc.h> |
| 23 | #include <fsl_sec.h> |
| 24 | #include <fsl_dspi.h> |
| 25 | |
| 26 | #define LS1046A_PORSR1_REG 0x1EE0000 |
| 27 | #define BOOT_SRC_SD 0x20000000 |
| 28 | #define BOOT_SRC_MASK 0xFF800000 |
Pramod Kumar | f5d7a46 | 2019-12-19 10:28:57 +0000 | [diff] [blame] | 29 | #define BOARD_REV_GPIO_SHIFT 17 |
| 30 | #define BOARD_REV_MASK 0x03 |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 31 | #define USB2_SEL_MASK 0x00000100 |
| 32 | |
| 33 | #define BYTE_SWAP_32(word) ((((word) & 0xff000000) >> 24) | \ |
| 34 | (((word) & 0x00ff0000) >> 8) | \ |
| 35 | (((word) & 0x0000ff00) << 8) | \ |
| 36 | (((word) & 0x000000ff) << 24)) |
| 37 | #define SPI_MCR_REG 0x2100000 |
| 38 | |
| 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
Biwen Li | bb1165f | 2020-02-05 22:02:17 +0800 | [diff] [blame] | 41 | int select_i2c_ch_pca9547(u8 ch, int bus_num) |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 42 | { |
| 43 | int ret; |
| 44 | |
Biwen Li | bb1165f | 2020-02-05 22:02:17 +0800 | [diff] [blame] | 45 | #ifdef CONFIG_DM_I2C |
| 46 | struct udevice *dev; |
| 47 | |
| 48 | ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI, |
| 49 | 1, &dev); |
| 50 | if (ret) { |
| 51 | printf("%s: Cannot find udev for a bus %d\n", __func__, |
| 52 | bus_num); |
| 53 | return ret; |
| 54 | } |
| 55 | ret = dm_i2c_write(dev, 0, &ch, 1); |
| 56 | #else |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 57 | ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1); |
Biwen Li | bb1165f | 2020-02-05 22:02:17 +0800 | [diff] [blame] | 58 | #endif |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 59 | if (ret) { |
| 60 | puts("PCA: failed to select proper channel\n"); |
| 61 | return ret; |
| 62 | } |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static inline void demux_select_usb2(void) |
| 68 | { |
| 69 | u32 val; |
| 70 | struct ccsr_gpio *pgpio = (void *)(GPIO3_BASE_ADDR); |
| 71 | |
| 72 | val = in_be32(&pgpio->gpdir); |
| 73 | val |= USB2_SEL_MASK; |
| 74 | out_be32(&pgpio->gpdir, val); |
| 75 | |
| 76 | val = in_be32(&pgpio->gpdat); |
| 77 | val |= USB2_SEL_MASK; |
| 78 | out_be32(&pgpio->gpdat, val); |
| 79 | } |
| 80 | |
| 81 | static inline void set_spi_cs_signal_inactive(void) |
| 82 | { |
| 83 | /* default: all CS signals inactive state is high */ |
| 84 | uint mcr_val; |
| 85 | uint mcr_cfg_val = DSPI_MCR_MSTR | DSPI_MCR_PCSIS_MASK | |
| 86 | DSPI_MCR_CRXF | DSPI_MCR_CTXF; |
| 87 | |
| 88 | mcr_val = in_be32(SPI_MCR_REG); |
| 89 | mcr_val |= DSPI_MCR_HALT; |
| 90 | out_be32(SPI_MCR_REG, mcr_val); |
| 91 | out_be32(SPI_MCR_REG, mcr_cfg_val); |
| 92 | mcr_val = in_be32(SPI_MCR_REG); |
| 93 | mcr_val &= ~DSPI_MCR_HALT; |
| 94 | out_be32(SPI_MCR_REG, mcr_val); |
| 95 | } |
| 96 | |
| 97 | int board_early_init_f(void) |
| 98 | { |
| 99 | fsl_lsch2_early_init_f(); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static inline uint8_t get_board_version(void) |
| 105 | { |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 106 | struct ccsr_gpio *pgpio = (void *)(GPIO2_BASE_ADDR); |
| 107 | |
Pramod Kumar | f5d7a46 | 2019-12-19 10:28:57 +0000 | [diff] [blame] | 108 | /* GPIO 13 and GPIO 14 are used for Board Rev */ |
| 109 | u32 gpio_val = ((in_be32(&pgpio->gpdat) >> BOARD_REV_GPIO_SHIFT)) |
| 110 | & BOARD_REV_MASK; |
| 111 | |
| 112 | /* GPIOs' are 0..31 in Big Endiness, swap GPIO 13 and GPIO 14 */ |
| 113 | u8 val = ((gpio_val >> 1) | (gpio_val << 1)) & BOARD_REV_MASK; |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 114 | |
| 115 | return val; |
| 116 | } |
| 117 | |
| 118 | int checkboard(void) |
| 119 | { |
| 120 | static const char *freq[2] = {"100.00MHZ", "100.00MHZ"}; |
| 121 | u32 boot_src; |
| 122 | u8 rev; |
| 123 | |
| 124 | rev = get_board_version(); |
| 125 | switch (rev) { |
| 126 | case 0x00: |
| 127 | puts("Board: LS1046AFRWY, Rev: A, boot from "); |
| 128 | break; |
| 129 | case 0x01: |
| 130 | puts("Board: LS1046AFRWY, Rev: B, boot from "); |
| 131 | break; |
| 132 | default: |
| 133 | puts("Board: LS1046AFRWY, Rev: Unknown, boot from "); |
| 134 | break; |
| 135 | } |
| 136 | boot_src = BYTE_SWAP_32(readl(LS1046A_PORSR1_REG)); |
| 137 | |
| 138 | if ((boot_src & BOOT_SRC_MASK) == BOOT_SRC_SD) |
| 139 | puts("SD\n"); |
| 140 | else |
| 141 | puts("QSPI\n"); |
| 142 | printf("SD1_CLK1 = %s, SD1_CLK2 = %s\n", freq[0], freq[1]); |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | int board_init(void) |
| 148 | { |
Udit Agarwal | 5536c3c | 2019-11-07 16:11:32 +0000 | [diff] [blame] | 149 | #ifdef CONFIG_NXP_ESBC |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 150 | /* |
| 151 | * In case of Secure Boot, the IBR configures the SMMU |
| 152 | * to allow only Secure transactions. |
| 153 | * SMMU must be reset in bypass mode. |
| 154 | * Set the ClientPD bit and Clear the USFCFG Bit |
| 155 | */ |
| 156 | u32 val; |
| 157 | val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 158 | out_le32(SMMU_SCR0, val); |
| 159 | val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 160 | out_le32(SMMU_NSCR0, val); |
| 161 | #endif |
| 162 | |
| 163 | #ifdef CONFIG_FSL_CAAM |
| 164 | sec_init(); |
| 165 | #endif |
| 166 | |
Biwen Li | bb1165f | 2020-02-05 22:02:17 +0800 | [diff] [blame] | 167 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0); |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | int board_setup_core_volt(u32 vdd) |
| 172 | { |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | void config_board_mux(void) |
| 177 | { |
| 178 | #ifdef CONFIG_HAS_FSL_XHCI_USB |
| 179 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
| 180 | u32 usb_pwrfault; |
| 181 | /* |
| 182 | * USB2 is used, configure mux to USB2_DRVVBUS/USB2_PWRFAULT |
| 183 | * USB3 is not used, configure mux to IIC4_SCL/IIC4_SDA |
| 184 | */ |
| 185 | out_be32(&scfg->rcwpmuxcr0, 0x3300); |
| 186 | #ifdef CONFIG_HAS_FSL_IIC3 |
| 187 | /* IIC3 is used, configure mux to use IIC3_SCL/IIC3/SDA */ |
| 188 | out_be32(&scfg->rcwpmuxcr0, 0x0000); |
| 189 | #endif |
| 190 | out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1); |
| 191 | usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED << |
| 192 | SCFG_USBPWRFAULT_USB3_SHIFT) | |
| 193 | (SCFG_USBPWRFAULT_DEDICATED << |
| 194 | SCFG_USBPWRFAULT_USB2_SHIFT) | |
| 195 | (SCFG_USBPWRFAULT_SHARED << |
| 196 | SCFG_USBPWRFAULT_USB1_SHIFT); |
| 197 | out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault); |
| 198 | #ifndef CONFIG_HAS_FSL_IIC3 |
| 199 | /* |
| 200 | * LS1046A FRWY board has demultiplexer NX3DV42GU with GPIO3_23 as input |
| 201 | * to select I2C3_USB2_SEL_IO |
| 202 | * I2C3_USB2_SEL = 0: I2C3_SCL/SDA signals are routed to |
| 203 | * I2C3 header (default) |
| 204 | * I2C3_USB2_SEL = 1: USB2_DRVVBUS/PWRFAULT signals are routed to |
| 205 | * USB2 port |
| 206 | * programmed to select USB2 by setting GPIO3_23 output to one |
| 207 | */ |
| 208 | demux_select_usb2(); |
| 209 | #endif |
| 210 | #endif |
| 211 | set_spi_cs_signal_inactive(); |
| 212 | } |
| 213 | |
| 214 | #ifdef CONFIG_MISC_INIT_R |
| 215 | int misc_init_r(void) |
| 216 | { |
| 217 | config_board_mux(); |
| 218 | return 0; |
| 219 | } |
| 220 | #endif |
| 221 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 222 | int ft_board_setup(void *blob, struct bd_info *bd) |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 223 | { |
| 224 | u64 base[CONFIG_NR_DRAM_BANKS]; |
| 225 | u64 size[CONFIG_NR_DRAM_BANKS]; |
| 226 | |
| 227 | /* fixup DT for the two DDR banks */ |
| 228 | base[0] = gd->bd->bi_dram[0].start; |
| 229 | size[0] = gd->bd->bi_dram[0].size; |
| 230 | base[1] = gd->bd->bi_dram[1].start; |
| 231 | size[1] = gd->bd->bi_dram[1].size; |
| 232 | |
| 233 | fdt_fixup_memory_banks(blob, base, size, 2); |
| 234 | ft_cpu_setup(blob, bd); |
| 235 | |
| 236 | #ifdef CONFIG_SYS_DPAA_FMAN |
Madalin Bucur | 6eb32a0 | 2020-04-23 16:25:19 +0300 | [diff] [blame] | 237 | #ifndef CONFIG_DM_ETH |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 238 | fdt_fixup_fman_ethernet(blob); |
| 239 | #endif |
Madalin Bucur | 6eb32a0 | 2020-04-23 16:25:19 +0300 | [diff] [blame] | 240 | #endif |
Vabhav Sharma | d90c7ac | 2019-06-06 12:35:28 +0000 | [diff] [blame] | 241 | |
| 242 | fdt_fixup_icid(blob); |
| 243 | |
| 244 | return 0; |
| 245 | } |