blob: 62b83c228cfba3ac22f344bce947eb457343dd4a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Meng81da5a82015-02-02 22:35:27 +08002/*
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
Bin Meng81da5a82015-02-02 22:35:27 +08004 */
5
6#include <common.h>
Simon Glass1fa70f82019-11-14 12:57:34 -07007#include <cpu_func.h>
Simon Glassfc557362022-03-04 08:43:05 -07008#include <event.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Bin Mengd79593b2015-02-04 16:26:13 +080010#include <mmc.h>
Simon Glassc1c4a8f2020-05-10 11:39:57 -060011#include <asm/cache.h>
Bin Meng81da5a82015-02-02 22:35:27 +080012#include <asm/io.h>
Bin Meng330be032016-05-22 01:45:34 -070013#include <asm/ioapic.h>
Bin Meng0c9f5942018-06-03 19:04:22 -070014#include <asm/irq.h>
Bin Meng4c2af8b2015-10-12 01:30:42 -070015#include <asm/mrccache.h>
Bin Meng0244ef42015-09-14 00:07:41 -070016#include <asm/mtrr.h>
Bin Meng81da5a82015-02-02 22:35:27 +080017#include <asm/pci.h>
18#include <asm/post.h>
Bin Meng34469862015-02-04 16:26:09 +080019#include <asm/arch/device.h>
20#include <asm/arch/msg_port.h>
21#include <asm/arch/quark.h>
Simon Glassdbd79542020-05-10 11:40:11 -060022#include <linux/delay.h>
Bin Meng34469862015-02-04 16:26:09 +080023
Bin Meng0244ef42015-09-14 00:07:41 -070024static void quark_setup_mtrr(void)
25{
26 u32 base, mask;
27 int i;
28
29 disable_caches();
30
31 /* mark the VGA RAM area as uncacheable */
32 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_A0000,
33 MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE));
34 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_B0000,
35 MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE));
36
37 /* mark other fixed range areas as cacheable */
38 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_64K_00000,
39 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
40 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_64K_40000,
41 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
42 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_80000,
43 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
44 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_90000,
45 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
46 for (i = MTRR_FIX_4K_C0000; i <= MTRR_FIX_4K_FC000; i++)
47 msg_port_write(MSG_PORT_HOST_BRIDGE, i,
48 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
49
50 /* variable range MTRR#0: ROM area */
51 mask = ~(CONFIG_SYS_MONITOR_LEN - 1);
Simon Glass72cc5382022-10-20 18:22:39 -060052 base = CONFIG_TEXT_BASE & mask;
Bin Meng0244ef42015-09-14 00:07:41 -070053 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYBASE(MTRR_VAR_ROM),
54 base | MTRR_TYPE_WRBACK);
55 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYMASK(MTRR_VAR_ROM),
56 mask | MTRR_PHYS_MASK_VALID);
57
58 /* variable range MTRR#1: eSRAM area */
59 mask = ~(ESRAM_SIZE - 1);
60 base = CONFIG_ESRAM_BASE & mask;
61 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYBASE(MTRR_VAR_ESRAM),
62 base | MTRR_TYPE_WRBACK);
63 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYMASK(MTRR_VAR_ESRAM),
64 mask | MTRR_PHYS_MASK_VALID);
65
66 /* enable both variable and fixed range MTRRs */
67 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_DEF_TYPE,
68 MTRR_DEF_TYPE_EN | MTRR_DEF_TYPE_FIX_EN);
69
70 enable_caches();
71}
72
Bin Meng34469862015-02-04 16:26:09 +080073static void quark_setup_bars(void)
74{
75 /* GPIO - D31:F0:R44h */
Bin Meng9cdcfd72015-09-03 05:37:24 -070076 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA,
77 CONFIG_GPIO_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080078
79 /* ACPI PM1 Block - D31:F0:R48h */
Bin Meng9cdcfd72015-09-03 05:37:24 -070080 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK,
81 CONFIG_ACPI_PM1_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080082
83 /* GPE0 - D31:F0:R4Ch */
Bin Meng9cdcfd72015-09-03 05:37:24 -070084 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK,
85 CONFIG_ACPI_GPE0_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080086
87 /* WDT - D31:F0:R84h */
Bin Meng9cdcfd72015-09-03 05:37:24 -070088 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA,
89 CONFIG_WDT_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080090
91 /* RCBA - D31:F0:RF0h */
Bin Meng9cdcfd72015-09-03 05:37:24 -070092 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA,
93 CONFIG_RCBA_BASE | MEM_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080094
95 /* ACPI P Block - Msg Port 04:R70h */
96 msg_port_write(MSG_PORT_RMU, PBLK_BA,
97 CONFIG_ACPI_PBLK_BASE | IO_BAR_EN);
98
99 /* SPI DMA - Msg Port 04:R7Ah */
100 msg_port_write(MSG_PORT_RMU, SPI_DMA_BA,
101 CONFIG_SPI_DMA_BASE | IO_BAR_EN);
102
103 /* PCIe ECAM */
104 msg_port_write(MSG_PORT_MEM_ARBITER, AEC_CTRL,
105 CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
106 msg_port_write(MSG_PORT_HOST_BRIDGE, HEC_REG,
107 CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
108}
Bin Meng81da5a82015-02-02 22:35:27 +0800109
Simon Glass1cedca12023-08-21 21:17:01 -0600110static int quark_pcie_early_init(void)
Bin Meng4756cac2015-09-03 05:37:25 -0700111{
Bin Meng4756cac2015-09-03 05:37:25 -0700112 /*
113 * Step1: Assert PCIe signal PERST#
114 *
115 * The CPU interface to the PERST# signal is platform dependent.
116 * Call the board-specific codes to perform this task.
117 */
118 board_assert_perst();
119
120 /* Step2: PHY common lane reset */
Bin Mengd8630262015-09-09 23:20:25 -0700121 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_PHY_LANE_RST);
Bin Meng4756cac2015-09-03 05:37:25 -0700122 /* wait 1 ms for PHY common lane reset */
123 mdelay(1);
124
125 /* Step3: PHY sideband interface reset and controller main reset */
Bin Mengd8630262015-09-09 23:20:25 -0700126 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG,
127 PCIE_PHY_SB_RST | PCIE_CTLR_MAIN_RST);
Bin Meng4756cac2015-09-03 05:37:25 -0700128 /* wait 80ms for PLL to lock */
129 mdelay(80);
130
131 /* Step4: Controller sideband interface reset */
Bin Mengd8630262015-09-09 23:20:25 -0700132 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_SB_RST);
Bin Meng4756cac2015-09-03 05:37:25 -0700133 /* wait 20ms for controller sideband interface reset */
134 mdelay(20);
135
136 /* Step5: De-assert PERST# */
137 board_deassert_perst();
138
139 /* Step6: Controller primary interface reset */
Bin Mengd8630262015-09-09 23:20:25 -0700140 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_PRI_RST);
Bin Meng4756cac2015-09-03 05:37:25 -0700141
142 /* Mixer Load Lane 0 */
Bin Mengd8630262015-09-09 23:20:25 -0700143 msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0,
144 (1 << 6) | (1 << 7));
Bin Meng4756cac2015-09-03 05:37:25 -0700145
146 /* Mixer Load Lane 1 */
Bin Mengd8630262015-09-09 23:20:25 -0700147 msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1,
148 (1 << 6) | (1 << 7));
Simon Glass1cedca12023-08-21 21:17:01 -0600149
150 return 0;
Bin Meng4756cac2015-09-03 05:37:25 -0700151}
152
Bin Mengf3763722015-09-03 05:37:27 -0700153static void quark_usb_early_init(void)
154{
Bin Mengf3763722015-09-03 05:37:27 -0700155 /* The sequence below comes from Quark firmware writer guide */
156
Bin Mengd8630262015-09-09 23:20:25 -0700157 msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT,
158 1 << 1, (1 << 6) | (1 << 7));
Bin Mengf3763722015-09-03 05:37:27 -0700159
Bin Mengd8630262015-09-09 23:20:25 -0700160 msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_COMPBG,
161 (1 << 8) | (1 << 9), (1 << 7) | (1 << 10));
Bin Mengf3763722015-09-03 05:37:27 -0700162
Bin Mengd8630262015-09-09 23:20:25 -0700163 msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29);
Bin Mengf3763722015-09-03 05:37:27 -0700164
Bin Mengd8630262015-09-09 23:20:25 -0700165 msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL1, 1 << 1);
Bin Mengf3763722015-09-03 05:37:27 -0700166
Bin Mengd8630262015-09-09 23:20:25 -0700167 msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_PLL1,
168 (1 << 3) | (1 << 4) | (1 << 5), 1 << 6);
Bin Mengf3763722015-09-03 05:37:27 -0700169
Bin Mengd8630262015-09-09 23:20:25 -0700170 msg_port_alt_clrbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29);
Bin Mengf3763722015-09-03 05:37:27 -0700171
Bin Mengd8630262015-09-09 23:20:25 -0700172 msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 24);
Bin Mengf3763722015-09-03 05:37:27 -0700173}
174
Bin Meng8f578db2015-09-09 23:20:27 -0700175static void quark_thermal_early_init(void)
176{
177 /* The sequence below comes from Quark firmware writer guide */
178
179 /* thermal sensor mode config */
180 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG1,
181 (1 << 3) | (1 << 4) | (1 << 5), 1 << 5);
182 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG1,
183 (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11) |
184 (1 << 12), 1 << 9);
185 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 14);
186 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 17);
187 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 18);
188 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG2, 0xffff, 0x011f);
189 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG3, 0xff, 0x17);
190 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG3,
191 (1 << 8) | (1 << 9), 1 << 8);
192 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG3, 0xff000000);
193 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG4,
194 0x7ff800, 0xc8 << 11);
195
196 /* thermal monitor catastrophic trip set point (105 celsius) */
197 msg_port_clrsetbits(MSG_PORT_RMU, TS_TRIP, 0xff, 155);
198
199 /* thermal monitor catastrophic trip clear point (0 celsius) */
200 msg_port_clrsetbits(MSG_PORT_RMU, TS_TRIP, 0xff0000, 50 << 16);
201
202 /* take thermal sensor out of reset */
203 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG4, 1 << 0);
204
205 /* enable thermal monitor */
206 msg_port_setbits(MSG_PORT_RMU, TS_MODE, 1 << 15);
207
208 /* lock all thermal configuration */
209 msg_port_setbits(MSG_PORT_RMU, RMU_CTRL, (1 << 5) | (1 << 6));
210}
211
Bin Meng6db14482015-04-27 14:16:02 +0800212static void quark_enable_legacy_seg(void)
213{
Bin Mengd8630262015-09-09 23:20:25 -0700214 msg_port_setbits(MSG_PORT_HOST_BRIDGE, HMISC2,
215 HMISC2_SEGE | HMISC2_SEGF | HMISC2_SEGAB);
Bin Meng6db14482015-04-27 14:16:02 +0800216}
217
Bin Meng81da5a82015-02-02 22:35:27 +0800218int arch_cpu_init(void)
219{
Bin Meng81da5a82015-02-02 22:35:27 +0800220 int ret;
221
222 post_code(POST_CPU_INIT);
Bin Meng81da5a82015-02-02 22:35:27 +0800223
224 ret = x86_cpu_init_f();
225 if (ret)
226 return ret;
227
Bin Meng34469862015-02-04 16:26:09 +0800228 /*
Bin Meng0244ef42015-09-14 00:07:41 -0700229 * Quark SoC does not support MSR MTRRs. Fixed and variable range MTRRs
230 * are accessed indirectly via the message port and not the traditional
231 * MSR mechanism. Only UC, WT and WB cache types are supported.
232 */
233 quark_setup_mtrr();
234
235 /*
Bin Meng34469862015-02-04 16:26:09 +0800236 * Quark SoC has some non-standard BARs (excluding PCI standard BARs)
237 * which need be initialized with suggested values
238 */
239 quark_setup_bars();
240
Bin Mengf3763722015-09-03 05:37:27 -0700241 /* Initialize USB2 PHY */
242 quark_usb_early_init();
243
Bin Meng8f578db2015-09-09 23:20:27 -0700244 /* Initialize thermal sensor */
245 quark_thermal_early_init();
246
Bin Meng6db14482015-04-27 14:16:02 +0800247 /* Turn on legacy segments (A/B/E/F) decode to system RAM */
248 quark_enable_legacy_seg();
249
Bin Meng81da5a82015-02-02 22:35:27 +0800250 return 0;
251}
252
Simon Glassb8357c12023-08-21 21:16:56 -0600253/*
254 * Initialize PCIe controller
255 *
256 * Quark SoC holds the PCIe controller in reset following a power on.
257 * U-Boot needs to release the PCIe controller from reset. The PCIe
258 * controller (D23:F0/F1) will not be visible in PCI configuration
259 * space and any access to its PCI configuration registers will cause
260 * system hang while it is held in reset.
261 */
262EVENT_SPY_SIMPLE(EVT_DM_POST_INIT_F, quark_pcie_early_init);
Bin Meng294191c2016-01-18 07:29:32 -0800263
Simon Glassee7c36f2017-03-28 10:27:30 -0600264int checkcpu(void)
265{
266 return 0;
267}
268
Bin Meng81da5a82015-02-02 22:35:27 +0800269int print_cpuinfo(void)
270{
271 post_code(POST_CPU_INFO);
272 return default_print_cpuinfo();
273}
274
Bin Meng4e19d7c2015-09-11 03:24:37 -0700275static void quark_pcie_init(void)
276{
277 u32 val;
278
279 /* PCIe upstream non-posted & posted request size */
280 qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_CCFG,
281 CCFG_UPRS | CCFG_UNRS);
282 qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_CCFG,
283 CCFG_UPRS | CCFG_UNRS);
284
285 /* PCIe packet fast transmit mode (IPF) */
286 qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MPC2, MPC2_IPF);
287 qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MPC2, MPC2_IPF);
288
289 /* PCIe message bus idle counter (SBIC) */
290 qrk_pci_read_config_dword(QUARK_PCIE0, PCIE_RP_MBC, &val);
291 val |= MBC_SBIC;
292 qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MBC, val);
293 qrk_pci_read_config_dword(QUARK_PCIE1, PCIE_RP_MBC, &val);
294 val |= MBC_SBIC;
295 qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MBC, val);
296}
297
298static void quark_usb_init(void)
299{
300 u32 bar;
301
302 /* Change USB EHCI packet buffer OUT/IN threshold */
303 qrk_pci_read_config_dword(QUARK_USB_EHCI, PCI_BASE_ADDRESS_0, &bar);
304 writel((0x7f << 16) | 0x7f, bar + EHCI_INSNREG01);
305
306 /* Disable USB device interrupts */
307 qrk_pci_read_config_dword(QUARK_USB_DEVICE, PCI_BASE_ADDRESS_0, &bar);
308 writel(0x7f, bar + USBD_INT_MASK);
309 writel((0xf << 16) | 0xf, bar + USBD_EP_INT_MASK);
310 writel((0xf << 16) | 0xf, bar + USBD_EP_INT_STS);
311}
312
Bin Meng0c9f5942018-06-03 19:04:22 -0700313static void quark_irq_init(void)
314{
315 struct quark_rcba *rcba;
316 u32 base;
317
318 qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
319 base &= ~MEM_BAR_EN;
320 rcba = (struct quark_rcba *)base;
321
322 /*
323 * Route Quark PCI device interrupt pin to PIRQ
324 *
325 * Route device#23's INTA/B/C/D to PIRQA/B/C/D
326 * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H
327 */
328 writew(PIRQC, &rcba->rmu_ir);
329 writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12),
330 &rcba->d23_ir);
331 writew(PIRQD, &rcba->core_ir);
332 writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12),
333 &rcba->d20d21_ir);
334}
335
Bin Meng4e19d7c2015-09-11 03:24:37 -0700336int arch_early_init_r(void)
337{
338 quark_pcie_init();
339
340 quark_usb_init();
341
Bin Meng0c9f5942018-06-03 19:04:22 -0700342 quark_irq_init();
343
Bin Meng4e19d7c2015-09-11 03:24:37 -0700344 return 0;
345}
346
Bin Mengef9e9f92015-05-25 22:35:06 +0800347int arch_misc_init(void)
348{
Bin Meng4c2af8b2015-10-12 01:30:42 -0700349#ifdef CONFIG_ENABLE_MRC_CACHE
350 /*
351 * We intend not to check any return value here, as even MRC cache
352 * is not saved successfully, it is not a severe error that will
353 * prevent system from continuing to boot.
354 */
355 mrccache_save();
356#endif
357
Bin Meng330be032016-05-22 01:45:34 -0700358 /* Assign a unique I/O APIC ID */
359 io_apic_set_id(1);
360
Simon Glass754f55e2016-01-19 21:32:26 -0700361 return 0;
Bin Mengef9e9f92015-05-25 22:35:06 +0800362}
Bin Meng4e19d7c2015-09-11 03:24:37 -0700363
Simon Glass75ece5f2020-07-16 21:22:38 -0600364void board_final_init(void)
Bin Meng4e19d7c2015-09-11 03:24:37 -0700365{
366 struct quark_rcba *rcba;
367 u32 base, val;
368
369 qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
370 base &= ~MEM_BAR_EN;
371 rcba = (struct quark_rcba *)base;
372
373 /* Initialize 'Component ID' to zero */
374 val = readl(&rcba->esd);
375 val &= ~0xff0000;
376 writel(val, &rcba->esd);
377
Bin Meng619c90a2015-09-09 23:20:26 -0700378 /* Lock HMBOUND for security */
379 msg_port_setbits(MSG_PORT_HOST_BRIDGE, HM_BOUND, HM_BOUND_LOCK);
380
Bin Meng4e19d7c2015-09-11 03:24:37 -0700381 return;
382}