Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <i2c.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/clock.h> |
| 11 | #include <asm/arch/fsl_serdes.h> |
| 12 | #include <asm/arch/soc.h> |
Simon Glass | e3ee2fb | 2016-02-22 22:55:43 -0700 | [diff] [blame] | 13 | #include <fdt_support.h> |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 14 | #include <hwconfig.h> |
| 15 | #include <ahci.h> |
Yangbo Lu | da6121b | 2015-10-26 19:47:55 +0800 | [diff] [blame] | 16 | #include <mmc.h> |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 17 | #include <scsi.h> |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 18 | #include <fm_eth.h> |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 19 | #include <fsl_csu.h> |
| 20 | #include <fsl_esdhc.h> |
| 21 | #include <fsl_ifc.h> |
Aneesh Bansal | b3e9820 | 2015-12-08 13:54:29 +0530 | [diff] [blame] | 22 | #include <fsl_sec.h> |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 23 | #include "cpld.h" |
Zhao Qiang | 0be9be8 | 2016-02-05 10:04:17 +0800 | [diff] [blame] | 24 | #ifdef CONFIG_U_QE |
| 25 | #include <fsl_qe.h> |
| 26 | #endif |
| 27 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
| 31 | int checkboard(void) |
| 32 | { |
| 33 | static const char *freq[3] = {"100.00MHZ", "156.25MHZ"}; |
Gong Qianyu | f671f6c | 2015-10-26 19:47:56 +0800 | [diff] [blame] | 34 | #ifndef CONFIG_SD_BOOT |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 35 | u8 cfg_rcw_src1, cfg_rcw_src2; |
| 36 | u32 cfg_rcw_src; |
Gong Qianyu | f671f6c | 2015-10-26 19:47:56 +0800 | [diff] [blame] | 37 | #endif |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 38 | u32 sd1refclk_sel; |
| 39 | |
| 40 | printf("Board: LS1043ARDB, boot from "); |
| 41 | |
Gong Qianyu | f671f6c | 2015-10-26 19:47:56 +0800 | [diff] [blame] | 42 | #ifdef CONFIG_SD_BOOT |
| 43 | puts("SD\n"); |
| 44 | #else |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 45 | cfg_rcw_src1 = CPLD_READ(cfg_rcw_src1); |
| 46 | cfg_rcw_src2 = CPLD_READ(cfg_rcw_src2); |
| 47 | cpld_rev_bit(&cfg_rcw_src1); |
| 48 | cfg_rcw_src = cfg_rcw_src1; |
| 49 | cfg_rcw_src = (cfg_rcw_src << 1) | cfg_rcw_src2; |
| 50 | |
| 51 | if (cfg_rcw_src == 0x25) |
| 52 | printf("vBank %d\n", CPLD_READ(vbank)); |
| 53 | else if (cfg_rcw_src == 0x106) |
| 54 | puts("NAND\n"); |
| 55 | else |
| 56 | printf("Invalid setting of SW4\n"); |
Gong Qianyu | f671f6c | 2015-10-26 19:47:56 +0800 | [diff] [blame] | 57 | #endif |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 58 | |
| 59 | printf("CPLD: V%x.%x\nPCBA: V%x.0\n", CPLD_READ(cpld_ver), |
| 60 | CPLD_READ(cpld_ver_sub), CPLD_READ(pcba_ver)); |
| 61 | |
| 62 | puts("SERDES Reference Clocks:\n"); |
| 63 | sd1refclk_sel = CPLD_READ(sd1refclk_sel); |
| 64 | printf("SD1_CLK1 = %s, SD1_CLK2 = %s\n", freq[sd1refclk_sel], freq[0]); |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | int dram_init(void) |
| 70 | { |
| 71 | gd->ram_size = initdram(0); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | int board_early_init_f(void) |
| 77 | { |
| 78 | fsl_lsch2_early_init_f(); |
Gong Qianyu | 0ea9b3d | 2015-11-11 17:58:40 +0800 | [diff] [blame] | 79 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | int board_init(void) |
| 84 | { |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 85 | #ifdef CONFIG_FSL_IFC |
| 86 | init_final_memctl_regs(); |
| 87 | #endif |
| 88 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 89 | #ifdef CONFIG_LAYERSCAPE_NS_ACCESS |
| 90 | enable_layerscape_ns_access(); |
| 91 | #endif |
| 92 | |
Zhao Qiang | 0be9be8 | 2016-02-05 10:04:17 +0800 | [diff] [blame] | 93 | #ifdef CONFIG_U_QE |
| 94 | u_qe_init(); |
| 95 | #endif |
| 96 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | int config_board_mux(void) |
| 101 | { |
Zhao Qiang | 085d267 | 2016-02-05 10:04:18 +0800 | [diff] [blame] | 102 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
| 103 | u32 usb_pwrfault; |
| 104 | |
Zhao Qiang | 510e792 | 2016-02-05 10:04:19 +0800 | [diff] [blame] | 105 | if (hwconfig("qe-hdlc")) { |
| 106 | out_be32(&scfg->rcwpmuxcr0, |
| 107 | (in_be32(&scfg->rcwpmuxcr0) & ~0xff00) | 0x6600); |
| 108 | printf("Assign to qe-hdlc clk, rcwpmuxcr0=%x\n", |
| 109 | in_be32(&scfg->rcwpmuxcr0)); |
| 110 | } else { |
Zhao Qiang | 085d267 | 2016-02-05 10:04:18 +0800 | [diff] [blame] | 111 | #ifdef CONFIG_HAS_FSL_XHCI_USB |
Zhao Qiang | 510e792 | 2016-02-05 10:04:19 +0800 | [diff] [blame] | 112 | out_be32(&scfg->rcwpmuxcr0, 0x3333); |
| 113 | out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1); |
| 114 | usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED << |
| 115 | SCFG_USBPWRFAULT_USB3_SHIFT) | |
| 116 | (SCFG_USBPWRFAULT_DEDICATED << |
| 117 | SCFG_USBPWRFAULT_USB2_SHIFT) | |
| 118 | (SCFG_USBPWRFAULT_SHARED << |
| 119 | SCFG_USBPWRFAULT_USB1_SHIFT); |
| 120 | out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault); |
Zhao Qiang | 085d267 | 2016-02-05 10:04:18 +0800 | [diff] [blame] | 121 | #endif |
Zhao Qiang | 510e792 | 2016-02-05 10:04:19 +0800 | [diff] [blame] | 122 | } |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | #if defined(CONFIG_MISC_INIT_R) |
| 127 | int misc_init_r(void) |
| 128 | { |
| 129 | config_board_mux(); |
Aneesh Bansal | b3e9820 | 2015-12-08 13:54:29 +0530 | [diff] [blame] | 130 | #ifdef CONFIG_SECURE_BOOT |
| 131 | /* In case of Secure Boot, the IBR configures the SMMU |
| 132 | * to allow only Secure transactions. |
| 133 | * SMMU must be reset in bypass mode. |
| 134 | * Set the ClientPD bit and Clear the USFCFG Bit |
| 135 | */ |
| 136 | u32 val; |
| 137 | val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 138 | out_le32(SMMU_SCR0, val); |
| 139 | val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 140 | out_le32(SMMU_NSCR0, val); |
| 141 | #endif |
| 142 | #ifdef CONFIG_FSL_CAAM |
| 143 | return sec_init(); |
| 144 | #endif |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 145 | return 0; |
| 146 | } |
| 147 | #endif |
| 148 | |
Zhao Qiang | 510e792 | 2016-02-05 10:04:19 +0800 | [diff] [blame] | 149 | void fdt_del_qe(void *blob) |
| 150 | { |
| 151 | int nodeoff = 0; |
| 152 | |
| 153 | while ((nodeoff = fdt_node_offset_by_compatible(blob, 0, |
| 154 | "fsl,qe")) >= 0) { |
| 155 | fdt_del_node(blob, nodeoff); |
| 156 | } |
| 157 | } |
| 158 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 159 | int ft_board_setup(void *blob, bd_t *bd) |
| 160 | { |
Shaohui Xie | f6c8395 | 2015-11-23 15:23:48 +0800 | [diff] [blame] | 161 | u64 base[CONFIG_NR_DRAM_BANKS]; |
| 162 | u64 size[CONFIG_NR_DRAM_BANKS]; |
| 163 | |
| 164 | /* fixup DT for the two DDR banks */ |
| 165 | base[0] = gd->bd->bi_dram[0].start; |
| 166 | size[0] = gd->bd->bi_dram[0].size; |
| 167 | base[1] = gd->bd->bi_dram[1].start; |
| 168 | size[1] = gd->bd->bi_dram[1].size; |
| 169 | |
| 170 | fdt_fixup_memory_banks(blob, base, size, 2); |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 171 | ft_cpu_setup(blob, bd); |
| 172 | |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 173 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 174 | fdt_fixup_fman_ethernet(blob); |
| 175 | #endif |
Zhao Qiang | 510e792 | 2016-02-05 10:04:19 +0800 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * qe-hdlc and usb multi-use the pins, |
| 179 | * when set hwconfig to qe-hdlc, delete usb node. |
| 180 | */ |
| 181 | if (hwconfig("qe-hdlc")) |
| 182 | #ifdef CONFIG_HAS_FSL_XHCI_USB |
| 183 | fdt_del_node_and_alias(blob, "usb1"); |
| 184 | #endif |
| 185 | /* |
| 186 | * qe just support qe-uart and qe-hdlc, |
| 187 | * if qe-uart and qe-hdlc are not set in hwconfig, |
| 188 | * delete qe node. |
| 189 | */ |
| 190 | if (!hwconfig("qe-uart") && !hwconfig("qe-hdlc")) |
| 191 | fdt_del_qe(blob); |
| 192 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | u8 flash_read8(void *addr) |
| 197 | { |
| 198 | return __raw_readb(addr + 1); |
| 199 | } |
| 200 | |
| 201 | void flash_write16(u16 val, void *addr) |
| 202 | { |
| 203 | u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00)); |
| 204 | |
| 205 | __raw_writew(shftval, addr); |
| 206 | } |
| 207 | |
| 208 | u16 flash_read16(void *addr) |
| 209 | { |
| 210 | u16 val = __raw_readw(addr); |
| 211 | |
| 212 | return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00); |
| 213 | } |