ls1046ardb: Add support for JTAG boot
[platform/kernel/u-boot.git] / board / freescale / ls1046ardb / ls1046ardb.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2016 Freescale Semiconductor, Inc.
4  */
5
6 #include <common.h>
7 #include <i2c.h>
8 #include <fdt_support.h>
9 #include <init.h>
10 #include <semihosting.h>
11 #include <serial.h>
12 #include <asm/global_data.h>
13 #include <asm/io.h>
14 #include <asm/arch/clock.h>
15 #include <asm/arch/fsl_serdes.h>
16 #include <asm/arch/ppa.h>
17 #include <asm/arch/soc.h>
18 #include <asm/arch-fsl-layerscape/fsl_icid.h>
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>
26 #include <power/mc34vr500_pmic.h>
27 #include "cpld.h"
28 #include <fsl_sec.h>
29
30 DECLARE_GLOBAL_DATA_PTR;
31
32 struct serial_device *default_serial_console(void)
33 {
34 #if IS_ENABLED(CONFIG_SEMIHOSTING_SERIAL)
35         return &serial_smh_device;
36 #endif
37         return &eserial1_device;
38 }
39
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
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
80 int board_init(void)
81 {
82         struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
83
84 #ifdef CONFIG_NXP_ESBC
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
98 #ifdef CONFIG_FSL_CAAM
99         sec_init();
100 #endif
101
102 #ifdef CONFIG_FSL_LS_PPA
103         ppa_init();
104 #endif
105
106 #if !defined(CONFIG_SYS_EARLY_PCI_INIT) && defined(CONFIG_DM_ETH)
107         pci_init();
108 #endif
109
110         /* invert AQR105 IRQ pins polarity */
111         out_be32(&scfg->intpcr, AQR105_IRQ_MASK);
112
113         return 0;
114 }
115
116 int board_setup_core_volt(u32 vdd)
117 {
118         bool en_0v9;
119
120         en_0v9 = (vdd == 900) ? true : false;
121         cpld_select_core_volt(en_0v9);
122
123         return 0;
124 }
125
126 int get_serdes_volt(void)
127 {
128         return mc34vr500_get_sw_volt(SW4);
129 }
130
131 int set_serdes_volt(int svdd)
132 {
133         return mc34vr500_set_sw_volt(SW4, svdd);
134 }
135
136 int power_init_board(void)
137 {
138         int ret;
139
140         ret = power_mc34vr500_init(0);
141         if (ret)
142                 return ret;
143
144         setup_chip_volt();
145
146         return 0;
147 }
148
149 void config_board_mux(void)
150 {
151 #ifdef CONFIG_HAS_FSL_XHCI_USB
152         struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
153         u32 usb_pwrfault;
154
155         /* USB3 is not used, configure mux to IIC4_SCL/IIC4_SDA */
156         out_be32(&scfg->rcwpmuxcr0, 0x3300);
157         out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
158         usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
159                         SCFG_USBPWRFAULT_USB3_SHIFT) |
160                         (SCFG_USBPWRFAULT_DEDICATED <<
161                         SCFG_USBPWRFAULT_USB2_SHIFT) |
162                         (SCFG_USBPWRFAULT_SHARED <<
163                         SCFG_USBPWRFAULT_USB1_SHIFT);
164         out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
165 #endif
166 }
167
168 #ifdef CONFIG_MISC_INIT_R
169 int misc_init_r(void)
170 {
171         config_board_mux();
172         return 0;
173 }
174 #endif
175
176 int ft_board_setup(void *blob, struct bd_info *bd)
177 {
178         u64 base[CONFIG_NR_DRAM_BANKS];
179         u64 size[CONFIG_NR_DRAM_BANKS];
180
181         /* fixup DT for the two DDR banks */
182         base[0] = gd->bd->bi_dram[0].start;
183         size[0] = gd->bd->bi_dram[0].size;
184         base[1] = gd->bd->bi_dram[1].start;
185         size[1] = gd->bd->bi_dram[1].size;
186
187         fdt_fixup_memory_banks(blob, base, size, 2);
188         ft_cpu_setup(blob, bd);
189
190 #ifdef CONFIG_SYS_DPAA_FMAN
191 #ifndef CONFIG_DM_ETH
192         fdt_fixup_fman_ethernet(blob);
193 #endif
194 #endif
195
196         fdt_fixup_icid(blob);
197
198         return 0;
199 }
200 #endif