blob: 6e20930a4d21940c1311d32d12a68c1cf3a236a1 [file] [log] [blame]
Bin Meng81da5a82015-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 Mengd79593b2015-02-04 16:26:13 +08008#include <mmc.h>
Bin Meng81da5a82015-02-02 22:35:27 +08009#include <asm/io.h>
Bin Meng4c2af8b2015-10-12 01:30:42 -070010#include <asm/mrccache.h>
Bin Meng0244ef42015-09-14 00:07:41 -070011#include <asm/mtrr.h>
Bin Meng81da5a82015-02-02 22:35:27 +080012#include <asm/pci.h>
13#include <asm/post.h>
Bin Meng34469862015-02-04 16:26:09 +080014#include <asm/arch/device.h>
15#include <asm/arch/msg_port.h>
16#include <asm/arch/quark.h>
17
Bin Mengd79593b2015-02-04 16:26:13 +080018static struct pci_device_id mmc_supported[] = {
19 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_SDIO },
Simon Glass0b619282015-11-29 13:18:08 -070020 {},
Bin Mengd79593b2015-02-04 16:26:13 +080021};
22
Bin Mengba6faff2015-02-04 16:26:12 +080023/*
24 * TODO:
25 *
26 * This whole routine should be removed until we fully convert the ICH SPI
27 * driver to DM and make use of DT to pass the bios control register offset
28 */
29static void unprotect_spi_flash(void)
30{
31 u32 bc;
32
Bin Meng9cdcfd72015-09-03 05:37:24 -070033 qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, &bc);
Bin Mengba6faff2015-02-04 16:26:12 +080034 bc |= 0x1; /* unprotect the flash */
Bin Meng9cdcfd72015-09-03 05:37:24 -070035 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, 0xd8, bc);
Bin Mengba6faff2015-02-04 16:26:12 +080036}
37
Bin Meng0244ef42015-09-14 00:07:41 -070038static void quark_setup_mtrr(void)
39{
40 u32 base, mask;
41 int i;
42
43 disable_caches();
44
45 /* mark the VGA RAM area as uncacheable */
46 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_A0000,
47 MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE));
48 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_B0000,
49 MTRR_FIX_TYPE(MTRR_TYPE_UNCACHEABLE));
50
51 /* mark other fixed range areas as cacheable */
52 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_64K_00000,
53 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
54 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_64K_40000,
55 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
56 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_80000,
57 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
58 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_FIX_16K_90000,
59 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
60 for (i = MTRR_FIX_4K_C0000; i <= MTRR_FIX_4K_FC000; i++)
61 msg_port_write(MSG_PORT_HOST_BRIDGE, i,
62 MTRR_FIX_TYPE(MTRR_TYPE_WRBACK));
63
64 /* variable range MTRR#0: ROM area */
65 mask = ~(CONFIG_SYS_MONITOR_LEN - 1);
66 base = CONFIG_SYS_TEXT_BASE & mask;
67 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYBASE(MTRR_VAR_ROM),
68 base | MTRR_TYPE_WRBACK);
69 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYMASK(MTRR_VAR_ROM),
70 mask | MTRR_PHYS_MASK_VALID);
71
72 /* variable range MTRR#1: eSRAM area */
73 mask = ~(ESRAM_SIZE - 1);
74 base = CONFIG_ESRAM_BASE & mask;
75 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYBASE(MTRR_VAR_ESRAM),
76 base | MTRR_TYPE_WRBACK);
77 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_VAR_PHYMASK(MTRR_VAR_ESRAM),
78 mask | MTRR_PHYS_MASK_VALID);
79
80 /* enable both variable and fixed range MTRRs */
81 msg_port_write(MSG_PORT_HOST_BRIDGE, MTRR_DEF_TYPE,
82 MTRR_DEF_TYPE_EN | MTRR_DEF_TYPE_FIX_EN);
83
84 enable_caches();
85}
86
Bin Meng34469862015-02-04 16:26:09 +080087static void quark_setup_bars(void)
88{
89 /* GPIO - D31:F0:R44h */
Bin Meng9cdcfd72015-09-03 05:37:24 -070090 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GBA,
91 CONFIG_GPIO_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080092
93 /* ACPI PM1 Block - D31:F0:R48h */
Bin Meng9cdcfd72015-09-03 05:37:24 -070094 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_PM1BLK,
95 CONFIG_ACPI_PM1_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +080096
97 /* GPE0 - D31:F0:R4Ch */
Bin Meng9cdcfd72015-09-03 05:37:24 -070098 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_GPE0BLK,
99 CONFIG_ACPI_GPE0_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +0800100
101 /* WDT - D31:F0:R84h */
Bin Meng9cdcfd72015-09-03 05:37:24 -0700102 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_WDTBA,
103 CONFIG_WDT_BASE | IO_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +0800104
105 /* RCBA - D31:F0:RF0h */
Bin Meng9cdcfd72015-09-03 05:37:24 -0700106 qrk_pci_write_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA,
107 CONFIG_RCBA_BASE | MEM_BAR_EN);
Bin Meng34469862015-02-04 16:26:09 +0800108
109 /* ACPI P Block - Msg Port 04:R70h */
110 msg_port_write(MSG_PORT_RMU, PBLK_BA,
111 CONFIG_ACPI_PBLK_BASE | IO_BAR_EN);
112
113 /* SPI DMA - Msg Port 04:R7Ah */
114 msg_port_write(MSG_PORT_RMU, SPI_DMA_BA,
115 CONFIG_SPI_DMA_BASE | IO_BAR_EN);
116
117 /* PCIe ECAM */
118 msg_port_write(MSG_PORT_MEM_ARBITER, AEC_CTRL,
119 CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
120 msg_port_write(MSG_PORT_HOST_BRIDGE, HEC_REG,
121 CONFIG_PCIE_ECAM_BASE | MEM_BAR_EN);
122}
Bin Meng81da5a82015-02-02 22:35:27 +0800123
Bin Meng4756cac2015-09-03 05:37:25 -0700124static void quark_pcie_early_init(void)
125{
Bin Meng4756cac2015-09-03 05:37:25 -0700126 /*
127 * Step1: Assert PCIe signal PERST#
128 *
129 * The CPU interface to the PERST# signal is platform dependent.
130 * Call the board-specific codes to perform this task.
131 */
132 board_assert_perst();
133
134 /* Step2: PHY common lane reset */
Bin Mengd8630262015-09-09 23:20:25 -0700135 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_PHY_LANE_RST);
Bin Meng4756cac2015-09-03 05:37:25 -0700136 /* wait 1 ms for PHY common lane reset */
137 mdelay(1);
138
139 /* Step3: PHY sideband interface reset and controller main reset */
Bin Mengd8630262015-09-09 23:20:25 -0700140 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG,
141 PCIE_PHY_SB_RST | PCIE_CTLR_MAIN_RST);
Bin Meng4756cac2015-09-03 05:37:25 -0700142 /* wait 80ms for PLL to lock */
143 mdelay(80);
144
145 /* Step4: Controller sideband interface reset */
Bin Mengd8630262015-09-09 23:20:25 -0700146 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_SB_RST);
Bin Meng4756cac2015-09-03 05:37:25 -0700147 /* wait 20ms for controller sideband interface reset */
148 mdelay(20);
149
150 /* Step5: De-assert PERST# */
151 board_deassert_perst();
152
153 /* Step6: Controller primary interface reset */
Bin Mengd8630262015-09-09 23:20:25 -0700154 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, PCIE_CFG, PCIE_CTLR_PRI_RST);
Bin Meng4756cac2015-09-03 05:37:25 -0700155
156 /* Mixer Load Lane 0 */
Bin Mengd8630262015-09-09 23:20:25 -0700157 msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L0,
158 (1 << 6) | (1 << 7));
Bin Meng4756cac2015-09-03 05:37:25 -0700159
160 /* Mixer Load Lane 1 */
Bin Mengd8630262015-09-09 23:20:25 -0700161 msg_port_io_clrbits(MSG_PORT_PCIE_AFE, PCIE_RXPICTRL0_L1,
162 (1 << 6) | (1 << 7));
Bin Meng4756cac2015-09-03 05:37:25 -0700163}
164
Bin Mengf3763722015-09-03 05:37:27 -0700165static void quark_usb_early_init(void)
166{
Bin Mengf3763722015-09-03 05:37:27 -0700167 /* The sequence below comes from Quark firmware writer guide */
168
Bin Mengd8630262015-09-09 23:20:25 -0700169 msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_GLOBAL_PORT,
170 1 << 1, (1 << 6) | (1 << 7));
Bin Mengf3763722015-09-03 05:37:27 -0700171
Bin Mengd8630262015-09-09 23:20:25 -0700172 msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_COMPBG,
173 (1 << 8) | (1 << 9), (1 << 7) | (1 << 10));
Bin Mengf3763722015-09-03 05:37:27 -0700174
Bin Mengd8630262015-09-09 23:20:25 -0700175 msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29);
Bin Mengf3763722015-09-03 05:37:27 -0700176
Bin Mengd8630262015-09-09 23:20:25 -0700177 msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL1, 1 << 1);
Bin Mengf3763722015-09-03 05:37:27 -0700178
Bin Mengd8630262015-09-09 23:20:25 -0700179 msg_port_alt_clrsetbits(MSG_PORT_USB_AFE, USB2_PLL1,
180 (1 << 3) | (1 << 4) | (1 << 5), 1 << 6);
Bin Mengf3763722015-09-03 05:37:27 -0700181
Bin Mengd8630262015-09-09 23:20:25 -0700182 msg_port_alt_clrbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 29);
Bin Mengf3763722015-09-03 05:37:27 -0700183
Bin Mengd8630262015-09-09 23:20:25 -0700184 msg_port_alt_setbits(MSG_PORT_USB_AFE, USB2_PLL2, 1 << 24);
Bin Mengf3763722015-09-03 05:37:27 -0700185}
186
Bin Meng8f578db2015-09-09 23:20:27 -0700187static void quark_thermal_early_init(void)
188{
189 /* The sequence below comes from Quark firmware writer guide */
190
191 /* thermal sensor mode config */
192 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG1,
193 (1 << 3) | (1 << 4) | (1 << 5), 1 << 5);
194 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG1,
195 (1 << 8) | (1 << 9) | (1 << 10) | (1 << 11) |
196 (1 << 12), 1 << 9);
197 msg_port_alt_setbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 14);
198 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 17);
199 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG1, 1 << 18);
200 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG2, 0xffff, 0x011f);
201 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG3, 0xff, 0x17);
202 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG3,
203 (1 << 8) | (1 << 9), 1 << 8);
204 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG3, 0xff000000);
205 msg_port_alt_clrsetbits(MSG_PORT_SOC_UNIT, TS_CFG4,
206 0x7ff800, 0xc8 << 11);
207
208 /* thermal monitor catastrophic trip set point (105 celsius) */
209 msg_port_clrsetbits(MSG_PORT_RMU, TS_TRIP, 0xff, 155);
210
211 /* thermal monitor catastrophic trip clear point (0 celsius) */
212 msg_port_clrsetbits(MSG_PORT_RMU, TS_TRIP, 0xff0000, 50 << 16);
213
214 /* take thermal sensor out of reset */
215 msg_port_alt_clrbits(MSG_PORT_SOC_UNIT, TS_CFG4, 1 << 0);
216
217 /* enable thermal monitor */
218 msg_port_setbits(MSG_PORT_RMU, TS_MODE, 1 << 15);
219
220 /* lock all thermal configuration */
221 msg_port_setbits(MSG_PORT_RMU, RMU_CTRL, (1 << 5) | (1 << 6));
222}
223
Bin Meng6db14482015-04-27 14:16:02 +0800224static void quark_enable_legacy_seg(void)
225{
Bin Mengd8630262015-09-09 23:20:25 -0700226 msg_port_setbits(MSG_PORT_HOST_BRIDGE, HMISC2,
227 HMISC2_SEGE | HMISC2_SEGF | HMISC2_SEGAB);
Bin Meng6db14482015-04-27 14:16:02 +0800228}
229
Bin Meng81da5a82015-02-02 22:35:27 +0800230int arch_cpu_init(void)
231{
Bin Meng81da5a82015-02-02 22:35:27 +0800232 int ret;
233
234 post_code(POST_CPU_INIT);
Bin Meng81da5a82015-02-02 22:35:27 +0800235
236 ret = x86_cpu_init_f();
237 if (ret)
238 return ret;
239
Bin Meng34469862015-02-04 16:26:09 +0800240 /*
Bin Meng0244ef42015-09-14 00:07:41 -0700241 * Quark SoC does not support MSR MTRRs. Fixed and variable range MTRRs
242 * are accessed indirectly via the message port and not the traditional
243 * MSR mechanism. Only UC, WT and WB cache types are supported.
244 */
245 quark_setup_mtrr();
246
247 /*
Bin Meng34469862015-02-04 16:26:09 +0800248 * Quark SoC has some non-standard BARs (excluding PCI standard BARs)
249 * which need be initialized with suggested values
250 */
251 quark_setup_bars();
252
Bin Mengf3763722015-09-03 05:37:27 -0700253 /* Initialize USB2 PHY */
254 quark_usb_early_init();
255
Bin Meng8f578db2015-09-09 23:20:27 -0700256 /* Initialize thermal sensor */
257 quark_thermal_early_init();
258
Bin Meng6db14482015-04-27 14:16:02 +0800259 /* Turn on legacy segments (A/B/E/F) decode to system RAM */
260 quark_enable_legacy_seg();
261
Bin Mengba6faff2015-02-04 16:26:12 +0800262 unprotect_spi_flash();
263
Bin Meng81da5a82015-02-02 22:35:27 +0800264 return 0;
265}
266
Bin Meng294191c2016-01-18 07:29:32 -0800267int arch_cpu_init_dm(void)
268{
269 /*
270 * Initialize PCIe controller
271 *
272 * Quark SoC holds the PCIe controller in reset following a power on.
273 * U-Boot needs to release the PCIe controller from reset. The PCIe
274 * controller (D23:F0/F1) will not be visible in PCI configuration
275 * space and any access to its PCI configuration registers will cause
276 * system hang while it is held in reset.
277 */
278 quark_pcie_early_init();
279
280 return 0;
281}
282
Bin Meng81da5a82015-02-02 22:35:27 +0800283int print_cpuinfo(void)
284{
285 post_code(POST_CPU_INFO);
286 return default_print_cpuinfo();
287}
288
289void reset_cpu(ulong addr)
290{
291 /* cold reset */
Simon Glassd0963d42015-04-28 20:11:31 -0600292 x86_full_reset();
Bin Meng81da5a82015-02-02 22:35:27 +0800293}
Bin Mengd79593b2015-02-04 16:26:13 +0800294
Bin Meng4e19d7c2015-09-11 03:24:37 -0700295static void quark_pcie_init(void)
296{
297 u32 val;
298
299 /* PCIe upstream non-posted & posted request size */
300 qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_CCFG,
301 CCFG_UPRS | CCFG_UNRS);
302 qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_CCFG,
303 CCFG_UPRS | CCFG_UNRS);
304
305 /* PCIe packet fast transmit mode (IPF) */
306 qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MPC2, MPC2_IPF);
307 qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MPC2, MPC2_IPF);
308
309 /* PCIe message bus idle counter (SBIC) */
310 qrk_pci_read_config_dword(QUARK_PCIE0, PCIE_RP_MBC, &val);
311 val |= MBC_SBIC;
312 qrk_pci_write_config_dword(QUARK_PCIE0, PCIE_RP_MBC, val);
313 qrk_pci_read_config_dword(QUARK_PCIE1, PCIE_RP_MBC, &val);
314 val |= MBC_SBIC;
315 qrk_pci_write_config_dword(QUARK_PCIE1, PCIE_RP_MBC, val);
316}
317
318static void quark_usb_init(void)
319{
320 u32 bar;
321
322 /* Change USB EHCI packet buffer OUT/IN threshold */
323 qrk_pci_read_config_dword(QUARK_USB_EHCI, PCI_BASE_ADDRESS_0, &bar);
324 writel((0x7f << 16) | 0x7f, bar + EHCI_INSNREG01);
325
326 /* Disable USB device interrupts */
327 qrk_pci_read_config_dword(QUARK_USB_DEVICE, PCI_BASE_ADDRESS_0, &bar);
328 writel(0x7f, bar + USBD_INT_MASK);
329 writel((0xf << 16) | 0xf, bar + USBD_EP_INT_MASK);
330 writel((0xf << 16) | 0xf, bar + USBD_EP_INT_STS);
331}
332
333int arch_early_init_r(void)
334{
335 quark_pcie_init();
336
337 quark_usb_init();
338
339 return 0;
340}
341
Bin Mengd79593b2015-02-04 16:26:13 +0800342int cpu_mmc_init(bd_t *bis)
343{
Simon Glass0b619282015-11-29 13:18:08 -0700344 return pci_mmc_init("Quark SDHCI", mmc_supported);
Bin Mengd79593b2015-02-04 16:26:13 +0800345}
Bin Meng7e96d312015-03-11 11:25:56 +0800346
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
Simon Glass754f55e2016-01-19 21:32:26 -0700358 return 0;
Bin Mengef9e9f92015-05-25 22:35:06 +0800359}
Bin Meng4e19d7c2015-09-11 03:24:37 -0700360
361void board_final_cleanup(void)
362{
363 struct quark_rcba *rcba;
364 u32 base, val;
365
366 qrk_pci_read_config_dword(QUARK_LEGACY_BRIDGE, LB_RCBA, &base);
367 base &= ~MEM_BAR_EN;
368 rcba = (struct quark_rcba *)base;
369
370 /* Initialize 'Component ID' to zero */
371 val = readl(&rcba->esd);
372 val &= ~0xff0000;
373 writel(val, &rcba->esd);
374
Bin Meng619c90a2015-09-09 23:20:26 -0700375 /* Lock HMBOUND for security */
376 msg_port_setbits(MSG_PORT_HOST_BRIDGE, HM_BOUND, HM_BOUND_LOCK);
377
Bin Meng4e19d7c2015-09-11 03:24:37 -0700378 return;
379}
Bin Meng4c2af8b2015-10-12 01:30:42 -0700380
381int reserve_arch(void)
382{
383#ifdef CONFIG_ENABLE_MRC_CACHE
384 return mrccache_reserve();
385#else
386 return 0;
387#endif
388}