blob: f737e1921f778ff7d188e22f235034c5a408df4b [file] [log] [blame]
Bin Meng828d9af2015-02-02 22:35:27 +08001/*
2 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Bin Meng6df7ffe2015-02-04 16:26:13 +08008#include <mmc.h>
Bin Meng828d9af2015-02-02 22:35:27 +08009#include <asm/io.h>
Bin Meng05b98ec2015-05-25 22:35:06 +080010#include <asm/irq.h>
Bin Meng2fc2b832015-10-12 01:30:42 -070011#include <asm/mrccache.h>
Bin Mengc6d47052015-09-14 00:07:41 -070012#include <asm/mtrr.h>
Bin Meng828d9af2015-02-02 22:35:27 +080013#include <asm/pci.h>
14#include <asm/post.h>
15#include <asm/processor.h>
Bin Mengb1622572015-02-04 16:26:09 +080016#include <asm/arch/device.h>
17#include <asm/arch/msg_port.h>
18#include <asm/arch/quark.h>
19
Bin Meng6df7ffe2015-02-04 16:26:13 +080020static struct pci_device_id mmc_supported[] = {
21 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_SDIO },
22};
23
Bin Meng728b3932015-02-04 16:26:12 +080024/*
25 * TODO:
26 *
27 * This whole routine should be removed until we fully convert the ICH SPI
28 * driver to DM and make use of DT to pass the bios control register offset
29 */
30static void unprotect_spi_flash(void)
31{
32 u32 bc;
33
Bin Mengaa095052015-09-03 05:37:24 -070034 qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, &bc);
Bin Meng728b3932015-02-04 16:26:12 +080035 bc |= 0x1; /* unprotect the flash */
Bin Mengaa095052015-09-03 05:37:24 -070036 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, bc);
Bin Meng728b3932015-02-04 16:26:12 +080037}
38
Bin Mengc6d47052015-09-14 00:07:41 -070039static void quark_setup_mtrr(void)
40{
41 u32 base, mask;
42 int i;
43
44 disable_caches();
45
46 /* mark the VGA RAM area as uncacheable */
47 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_A0000,
48 MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE));
49 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_B0000,
50 MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE));
51
52 /* mark other fixed range areas as cacheable */
53 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_64K_00000,
54 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
55 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_64K_40000,
56 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
57 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_80000,
58 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
59 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_90000,
60 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
61 for (i = MTRR_FIX_4K_C0000; i <= MTRR_FIX_4K_FC000; i++)
62 msg_port_write(MSG_PORT_HOST_BRIDGE, i,
63 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
64
65 /* variable range MTRR#0: ROM area */
66 mask = ~(CONFIG_SYS_MONITOR_LEN - 1);
67 base = CONFIG_SYS_TEXT_BASE & mask;
68 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYBASE(MTRR_VAR_ROM),
69 base | MTRR_TYPE_WRBACK);
70 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYMASK(MTRR_VAR_ROM),
71 mask | MTRR_PHYS_MASK_VALID);
72
73 /* variable range MTRR#1: eSRAM area */
74 mask = ~(ESRAM_SIZE - 1);
75 base = CONFIG_ESRAM_BASE & mask;
76 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYBASE(MTRR_VAR_ESRAM),
77 base | MTRR_TYPE_WRBACK);
78 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYMASK(MTRR_VAR_ESRAM),
79 mask | MTRR_PHYS_MASK_VALID);
80
81 /* enable both variable and fixed range MTRRs */
82 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_DEF_TYPE,
83 MTRR_DEF_TYPE_EN | MTRR_DEF_TYPE_FIX_EN);
84
85 enable_caches();
86}
87
Bin Mengb1622572015-02-04 16:26:09 +080088static void quark_setup_bars(void)
89{
90 /* GPIO - D31:F0:R44h */
Bin Mengaa095052015-09-03 05:37:24 -070091 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA,
92 CONFIG_GPIO_BASE | IO_BAR_EN);
Bin Mengb1622572015-02-04 16:26:09 +080093
94 /* ACPI PM1 Block - D31:F0:R48h */
Bin Mengaa095052015-09-03 05:37:24 -070095 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK,
96 CONFIG_ACPI_PM1_BASE | IO_BAR_EN);
Bin Mengb1622572015-02-04 16:26:09 +080097
98 /* GPE0 - D31:F0:R4Ch */
Bin Mengaa095052015-09-03 05:37:24 -070099 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK,
100 CONFIG_ACPI_GPE0_BASE | IO_BAR_EN);
Bin Mengb1622572015-02-04 16:26:09 +0800101
102 /* WDT - D31:F0:R84h */
Bin Mengaa095052015-09-03 05:37:24 -0700103 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA,
104 CONFIG_WDT_BASE | IO_BAR_EN);
Bin Mengb1622572015-02-04 16:26:09 +0800105
106 /* RCBA - D31:F0:RF0h */
Bin Mengaa095052015-09-03 05:37:24 -0700107 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA,
108 CONFIG_RCBA_BASE | MEM_BAR_EN);
Bin Mengb1622572015-02-04 16:26:09 +0800109
110 /* ACPI P Block - Msg Port 04:R70h */
111 msg_port_write(MSG_PORT_RMU, PBLK_BA,
112 CONFIG_ACPI_PBLK_BASE | IO_BAR_EN);
113
114 /* SPI DMA - Msg Port 04:R7Ah */
115 msg_port_write(MSG_PORT_RMU, SPI_DMA_BA,
116 CONFIG_SPI_DMA_BASE | IO_BAR_EN);
117
118 /* PCIe ECAM */
119 msg_port_write(MSG_PORT_MEM_ARBITER, AEC_CTRL,
120 CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
121 msg_port_write(MSG_PORT_HOST_BRIDGE, HEC_REG,
122 CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
123}
Bin Meng828d9af2015-02-02 22:35:27 +0800124
Bin Meng316fd392015-09-03 05:37:25 -0700125static void quark_pcie_early_init(void)
126{
Bin Meng316fd392015-09-03 05:37:25 -0700127 /*
128 * Step1: Assert PCIe signal PERST#
129 *
130 * The CPU interface to the PERST# signal is platform dependent.
131 * Call the board-specific codes to perform this task.
132 */
133 board_assert_perst();
134
135 /* Step2: PHY common lane reset */
Bin Meng8e368302015-09-09 23:20:25 -0700136 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_PHY_LANE_RST);
Bin Meng316fd392015-09-03 05:37:25 -0700137 /* wait 1 ms for PHY common lane reset */
138 mdelay(1);
139
140 /* Step3: PHY sideband interface reset and controller main reset */
Bin Meng8e368302015-09-09 23:20:25 -0700141 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG,
142 PCIE_PHY_SB_RST | PCIE_CTLR_MAIN_RST);
Bin Meng316fd392015-09-03 05:37:25 -0700143 /* wait 80ms for PLL to lock */
144 mdelay(80);
145
146 /* Step4: Controller sideband interface reset */
Bin Meng8e368302015-09-09 23:20:25 -0700147 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_SB_RST);
Bin Meng316fd392015-09-03 05:37:25 -0700148 /* wait 20ms for controller sideband interface reset */
149 mdelay(20);
150
151 /* Step5: De-assert PERST# */
152 board_deassert_perst();
153
154 /* Step6: Controller primary interface reset */
Bin Meng8e368302015-09-09 23:20:25 -0700155 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_PRI_RST);
Bin Meng316fd392015-09-03 05:37:25 -0700156
157 /* Mixer Load Lane 0 */
Bin Meng8e368302015-09-09 23:20:25 -0700158 msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0,
159 (1 << 6) | (1 << 7));
Bin Meng316fd392015-09-03 05:37:25 -0700160
161 /* Mixer Load Lane 1 */
Bin Meng8e368302015-09-09 23:20:25 -0700162 msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1,
163 (1 << 6) | (1 << 7));
Bin Meng316fd392015-09-03 05:37:25 -0700164}
165
Bin Mengb06862b2015-09-03 05:37:27 -0700166static void quark_usb_early_init(void)
167{
Bin Mengb06862b2015-09-03 05:37:27 -0700168 /* The sequence below comes from Quark firmware writer guide */
169
Bin Meng8e368302015-09-09 23:20:25 -0700170 msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT,
171 1 << 1, (1 << 6) | (1 << 7));
Bin Mengb06862b2015-09-03 05:37:27 -0700172
Bin Meng8e368302015-09-09 23:20:25 -0700173 msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_COMPBG,
174 (1 << 8) | (1 << 9), (1 << 7) | (1 << 10));
Bin Mengb06862b2015-09-03 05:37:27 -0700175
Bin Meng8e368302015-09-09 23:20:25 -0700176 msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29);
Bin Mengb06862b2015-09-03 05:37:27 -0700177
Bin Meng8e368302015-09-09 23:20:25 -0700178 msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL1, 1 << 1);
Bin Mengb06862b2015-09-03 05:37:27 -0700179
Bin Meng8e368302015-09-09 23:20:25 -0700180 msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_PLL1,
181 (1 << 3) | (1 << 4) | (1 << 5), 1 << 6);
Bin Mengb06862b2015-09-03 05:37:27 -0700182
Bin Meng8e368302015-09-09 23:20:25 -0700183 msg_port_alt_clrbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29);
Bin Mengb06862b2015-09-03 05:37:27 -0700184
Bin Meng8e368302015-09-09 23:20:25 -0700185 msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 24);
Bin Mengb06862b2015-09-03 05:37:27 -0700186}
187
Bin Meng554778c2015-09-09 23:20:27 -0700188static void quark_thermal_early_init(void)
189{
190 /* The sequence below comes from Quark firmware writer guide */
191
192 /* thermal sensor mode config */
193 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG1,
194 (1 << 3) | (1 << 4) | (1 << 5), 1 << 5);
195 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG1,
196 (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11) |
197 (1 << 12), 1 << 9);
198 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 14);
199 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 17);
200 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 18);
201 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG2, 0xffff, 0x011f);
202 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG3, 0xff, 0x17);
203 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG3,
204 (1 << 8) | (1 << 9), 1 << 8);
205 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG3, 0xff000000);
206 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG4,
207 0x7ff800, 0xc8 << 11);
208
209 /* thermal monitor catastrophic trip set point (105 celsius) */
210 msg_port_clrsetbits(MSG_PORT_RMU, TS_TRIP, 0xff, 155);
211
212 /* thermal monitor catastrophic trip clear point (0 celsius) */
213 msg_port_clrsetbits(MSG_PORT_RMU, TS_TRIP, 0xff0000, 50 << 16);
214
215 /* take thermal sensor out of reset */
216 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG4, 1 << 0);
217
218 /* enable thermal monitor */
219 msg_port_setbits(MSG_PORT_RMU, TS_MODE, 1 << 15);
220
221 /* lock all thermal configuration */
222 msg_port_setbits(MSG_PORT_RMU, RMU_CTRL, (1 << 5) | (1 << 6));
223}
224
Bin Mengf82a7842015-04-27 14:16:02 +0800225static void quark_enable_legacy_seg(void)
226{
Bin Meng8e368302015-09-09 23:20:25 -0700227 msg_port_setbits(MSG_PORT_HOST_BRIDGE, HMISC2,
228 HMISC2_SEGE | HMISC2_SEGF | HMISC2_SEGAB);
Bin Mengf82a7842015-04-27 14:16:02 +0800229}
230
Bin Meng828d9af2015-02-02 22:35:27 +0800231int arch_cpu_init(void)
232{
Bin Meng828d9af2015-02-02 22:35:27 +0800233 int ret;
234
235 post_code(POST_CPU_INIT);
236#ifdef CONFIG_SYS_X86_TSC_TIMER
237 timer_set_base(rdtsc());
238#endif
239
240 ret = x86_cpu_init_f();
241 if (ret)
242 return ret;
243
Bin Mengb1622572015-02-04 16:26:09 +0800244 /*
Bin Mengc6d47052015-09-14 00:07:41 -0700245 * Quark SoC does not support MSR MTRRs. Fixed and variable range MTRRs
246 * are accessed indirectly via the message port and not the traditional
247 * MSR mechanism. Only UC, WT and WB cache types are supported.
248 */
249 quark_setup_mtrr();
250
251 /*
Bin Mengb1622572015-02-04 16:26:09 +0800252 * Quark SoC has some non-standard BARs (excluding PCI standard BARs)
253 * which need be initialized with suggested values
254 */
255 quark_setup_bars();
256
Bin Meng316fd392015-09-03 05:37:25 -0700257 /*
258 * Initialize PCIe controller
259 *
260 * Quark SoC holds the PCIe controller in reset following a power on.
261 * U-Boot needs to release the PCIe controller from reset. The PCIe
262 * controller (D23:F0/F1) will not be visible in PCI configuration
263 * space and any access to its PCI configuration registers will cause
264 * system hang while it is held in reset.
265 */
266 quark_pcie_early_init();
267
Bin Mengb06862b2015-09-03 05:37:27 -0700268 /* Initialize USB2 PHY */
269 quark_usb_early_init();
270
Bin Meng554778c2015-09-09 23:20:27 -0700271 /* Initialize thermal sensor */
272 quark_thermal_early_init();
273
Bin Mengf82a7842015-04-27 14:16:02 +0800274 /* Turn on legacy segments (A/B/E/F) decode to system RAM */
275 quark_enable_legacy_seg();
276
Bin Meng728b3932015-02-04 16:26:12 +0800277 unprotect_spi_flash();
278
Bin Meng828d9af2015-02-02 22:35:27 +0800279 return 0;
280}
281
282int print_cpuinfo(void)
283{
284 post_code(POST_CPU_INFO);
285 return default_print_cpuinfo();
286}
287
288void reset_cpu(ulong addr)
289{
290 /* cold reset */
Simon Glassebebf052015-04-28 20:11:31 -0600291 x86_full_reset();
Bin Meng828d9af2015-02-02 22:35:27 +0800292}
Bin Meng6df7ffe2015-02-04 16:26:13 +0800293
Bin Meng2afb6232015-09-11 03:24:37 -0700294static void quark_pcie_init(void)
295{
296 u32 val;
297
298 /* PCIe upstream non-posted & posted request size */
299 qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_CCFG,
300 CCFG_UPRS | CCFG_UNRS);
301 qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_CCFG,
302 CCFG_UPRS | CCFG_UNRS);
303
304 /* PCIe packet fast transmit mode (IPF) */
305 qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MPC2, MPC2_IPF);
306 qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MPC2, MPC2_IPF);
307
308 /* PCIe message bus idle counter (SBIC) */
309 qrk_pci_read_config_dword(QUARK_PCIE0, PCIE_RP_MBC, &val);
310 val |= MBC_SBIC;
311 qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MBC, val);
312 qrk_pci_read_config_dword(QUARK_PCIE1, PCIE_RP_MBC, &val);
313 val |= MBC_SBIC;
314 qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MBC, val);
315}
316
317static void quark_usb_init(void)
318{
319 u32 bar;
320
321 /* Change USB EHCI packet buffer OUT/IN threshold */
322 qrk_pci_read_config_dword(QUARK_USB_EHCI, PCI_BASE_ADDRESS_0, &bar);
323 writel((0x7f << 16) | 0x7f, bar + EHCI_INSNREG01);
324
325 /* Disable USB device interrupts */
326 qrk_pci_read_config_dword(QUARK_USB_DEVICE, PCI_BASE_ADDRESS_0, &bar);
327 writel(0x7f, bar + USBD_INT_MASK);
328 writel((0xf << 16) | 0xf, bar + USBD_EP_INT_MASK);
329 writel((0xf << 16) | 0xf, bar + USBD_EP_INT_STS);
330}
331
332int arch_early_init_r(void)
333{
334 quark_pcie_init();
335
336 quark_usb_init();
337
338 return 0;
339}
340
Bin Meng6df7ffe2015-02-04 16:26:13 +0800341int cpu_mmc_init(bd_t *bis)
342{
343 return pci_mmc_init("Quark SDHCI", mmc_supported,
344 ARRAY_SIZE(mmc_supported));
345}
Bin Menge4ad6032015-03-11 11:25:56 +0800346
Bin Meng05b98ec2015-05-25 22:35:06 +0800347void cpu_irq_init(void)
348{
349 struct quark_rcba *rcba;
350 u32 base;
351
Bin Mengaa095052015-09-03 05:37:24 -0700352 qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
Bin Meng05b98ec2015-05-25 22:35:06 +0800353 base &= ~MEM_BAR_EN;
354 rcba = (struct quark_rcba *)base;
355
356 /*
357 * Route Quark PCI device interrupt pin to PIRQ
358 *
359 * Route device#23's INTA/B/C/D to PIRQA/B/C/D
360 * Route device#20,21's INTA/B/C/D to PIRQE/F/G/H
361 */
362 writew(PIRQC, &rcba->rmu_ir);
363 writew(PIRQA | (PIRQB << 4) | (PIRQC << 8) | (PIRQD << 12),
364 &rcba->d23_ir);
365 writew(PIRQD, &rcba->core_ir);
366 writew(PIRQE | (PIRQF << 4) | (PIRQG << 8) | (PIRQH << 12),
367 &rcba->d20d21_ir);
368}
369
370int arch_misc_init(void)
371{
Bin Meng2fc2b832015-10-12 01:30:42 -0700372#ifdef CONFIG_ENABLE_MRC_CACHE
373 /*
374 * We intend not to check any return value here, as even MRC cache
375 * is not saved successfully, it is not a severe error that will
376 * prevent system from continuing to boot.
377 */
378 mrccache_save();
379#endif
380
Simon Glass7e4be122015-08-10 07:05:08 -0600381 return pirq_init();
Bin Meng05b98ec2015-05-25 22:35:06 +0800382}
Bin Meng2afb6232015-09-11 03:24:37 -0700383
384void board_final_cleanup(void)
385{
386 struct quark_rcba *rcba;
387 u32 base, val;
388
389 qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
390 base &= ~MEM_BAR_EN;
391 rcba = (struct quark_rcba *)base;
392
393 /* Initialize 'Component ID' to zero */
394 val = readl(&rcba->esd);
395 val &= ~0xff0000;
396 writel(val, &rcba->esd);
397
Bin Meng693b5f62015-09-09 23:20:26 -0700398 /* Lock HMBOUND for security */
399 msg_port_setbits(MSG_PORT_HOST_BRIDGE, HM_BOUND, HM_BOUND_LOCK);
400
Bin Meng2afb6232015-09-11 03:24:37 -0700401 return;
402}
Bin Meng2fc2b832015-10-12 01:30:42 -0700403
404int reserve_arch(void)
405{
406#ifdef CONFIG_ENABLE_MRC_CACHE
407 return mrccache_reserve();
408#else
409 return 0;
410#endif
411}