blob: 9682cfff26b96ac7ba0d84d10eb09d660cc280e3 [file] [log] [blame]
Bin Meng08e484c2014-12-17 15:50:36 +08001/*
2 * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <asm/io.h>
Bin Meng51c3b1e2015-05-25 22:35:04 +08009#include <asm/irq.h>
Bin Mengb8b44402014-12-17 15:50:44 +080010#include <asm/pci.h>
Bin Meng08e484c2014-12-17 15:50:36 +080011#include <asm/post.h>
Bin Meng15305362015-04-24 18:10:06 +080012#include <asm/arch/device.h>
Bin Meng51c3b1e2015-05-25 22:35:04 +080013#include <asm/arch/tnc.h>
Simon Glassb93abfc2015-01-27 22:13:36 -070014#include <asm/fsp/fsp_support.h>
Bin Meng08e484c2014-12-17 15:50:36 +080015#include <asm/processor.h>
16
Bin Mengb8b44402014-12-17 15:50:44 +080017static void unprotect_spi_flash(void)
18{
19 u32 bc;
20
Bin Meng80e336a2015-04-13 19:03:42 +080021 bc = x86_pci_read_config32(TNC_LPC, 0xd8);
Bin Mengb8b44402014-12-17 15:50:44 +080022 bc |= 0x1; /* unprotect the flash */
Bin Meng80e336a2015-04-13 19:03:42 +080023 x86_pci_write_config32(TNC_LPC, 0xd8, bc);
Bin Mengb8b44402014-12-17 15:50:44 +080024}
25
Bin Meng08e484c2014-12-17 15:50:36 +080026int arch_cpu_init(void)
27{
Bin Mengb8b44402014-12-17 15:50:44 +080028 int ret;
29
Bin Meng08e484c2014-12-17 15:50:36 +080030 post_code(POST_CPU_INIT);
31#ifdef CONFIG_SYS_X86_TSC_TIMER
32 timer_set_base(rdtsc());
33#endif
34
Bin Mengb8b44402014-12-17 15:50:44 +080035 ret = x86_cpu_init_f();
36 if (ret)
37 return ret;
38
Bin Mengb8b44402014-12-17 15:50:44 +080039 return 0;
Bin Meng08e484c2014-12-17 15:50:36 +080040}
Bin Meng15305362015-04-24 18:10:06 +080041
Bin Meng51c3b1e2015-05-25 22:35:04 +080042void cpu_irq_init(void)
43{
44 struct tnc_rcba *rcba;
45 u32 base;
46
47 base = x86_pci_read_config32(TNC_LPC, LPC_RCBA);
48 base &= ~MEM_BAR_EN;
49 rcba = (struct tnc_rcba *)base;
50
51 /* Make sure all internal PCI devices are using INTA */
52 writel(INTA, &rcba->d02ip);
53 writel(INTA, &rcba->d03ip);
54 writel(INTA, &rcba->d27ip);
55 writel(INTA, &rcba->d31ip);
56 writel(INTA, &rcba->d23ip);
57 writel(INTA, &rcba->d24ip);
58 writel(INTA, &rcba->d25ip);
59 writel(INTA, &rcba->d26ip);
60
61 /*
62 * Route TunnelCreek PCI device interrupt pin to PIRQ
63 *
64 * Since PCIe downstream ports received INTx are routed to PIRQ
Bin Mengd2f66a32015-06-23 12:18:55 +080065 * A/B/C/D directly and not configurable, we have to route PCIe
66 * root ports' INTx to PIRQ A/B/C/D as well. For other devices
67 * on TunneCreek, route them to PIRQ E/F/G/H.
Bin Meng51c3b1e2015-05-25 22:35:04 +080068 */
69 writew(PIRQE, &rcba->d02ir);
70 writew(PIRQF, &rcba->d03ir);
71 writew(PIRQG, &rcba->d27ir);
72 writew(PIRQH, &rcba->d31ir);
Bin Mengd2f66a32015-06-23 12:18:55 +080073 writew(PIRQA, &rcba->d23ir);
74 writew(PIRQB, &rcba->d24ir);
75 writew(PIRQC, &rcba->d25ir);
76 writew(PIRQD, &rcba->d26ir);
Bin Meng51c3b1e2015-05-25 22:35:04 +080077}
78
Bin Meng15305362015-04-24 18:10:06 +080079int arch_misc_init(void)
80{
Bin Meng549ef4d2015-08-20 06:40:21 -070081 unprotect_spi_flash();
82
Simon Glassaf1c2d682015-08-10 07:05:08 -060083 return pirq_init();
Bin Meng15305362015-04-24 18:10:06 +080084}