Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 1 | /* |
| 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 Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 9 | #include <asm/irq.h> |
Bin Meng | b8b4440 | 2014-12-17 15:50:44 +0800 | [diff] [blame] | 10 | #include <asm/pci.h> |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 11 | #include <asm/post.h> |
Bin Meng | 1530536 | 2015-04-24 18:10:06 +0800 | [diff] [blame] | 12 | #include <asm/arch/device.h> |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 13 | #include <asm/arch/tnc.h> |
Simon Glass | b93abfc | 2015-01-27 22:13:36 -0700 | [diff] [blame] | 14 | #include <asm/fsp/fsp_support.h> |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 15 | #include <asm/processor.h> |
| 16 | |
Bin Meng | b8b4440 | 2014-12-17 15:50:44 +0800 | [diff] [blame] | 17 | static void unprotect_spi_flash(void) |
| 18 | { |
| 19 | u32 bc; |
| 20 | |
Bin Meng | 80e336a | 2015-04-13 19:03:42 +0800 | [diff] [blame] | 21 | bc = x86_pci_read_config32(TNC_LPC, 0xd8); |
Bin Meng | b8b4440 | 2014-12-17 15:50:44 +0800 | [diff] [blame] | 22 | bc |= 0x1; /* unprotect the flash */ |
Bin Meng | 80e336a | 2015-04-13 19:03:42 +0800 | [diff] [blame] | 23 | x86_pci_write_config32(TNC_LPC, 0xd8, bc); |
Bin Meng | b8b4440 | 2014-12-17 15:50:44 +0800 | [diff] [blame] | 24 | } |
| 25 | |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 26 | int arch_cpu_init(void) |
| 27 | { |
Bin Meng | b8b4440 | 2014-12-17 15:50:44 +0800 | [diff] [blame] | 28 | struct pci_controller *hose; |
| 29 | int ret; |
| 30 | |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 31 | post_code(POST_CPU_INIT); |
| 32 | #ifdef CONFIG_SYS_X86_TSC_TIMER |
| 33 | timer_set_base(rdtsc()); |
| 34 | #endif |
| 35 | |
Bin Meng | b8b4440 | 2014-12-17 15:50:44 +0800 | [diff] [blame] | 36 | ret = x86_cpu_init_f(); |
| 37 | if (ret) |
| 38 | return ret; |
| 39 | |
| 40 | ret = pci_early_init_hose(&hose); |
| 41 | if (ret) |
| 42 | return ret; |
| 43 | |
| 44 | unprotect_spi_flash(); |
| 45 | |
| 46 | return 0; |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 47 | } |
Bin Meng | 1530536 | 2015-04-24 18:10:06 +0800 | [diff] [blame] | 48 | |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 49 | void cpu_irq_init(void) |
| 50 | { |
| 51 | struct tnc_rcba *rcba; |
| 52 | u32 base; |
| 53 | |
| 54 | base = x86_pci_read_config32(TNC_LPC, LPC_RCBA); |
| 55 | base &= ~MEM_BAR_EN; |
| 56 | rcba = (struct tnc_rcba *)base; |
| 57 | |
| 58 | /* Make sure all internal PCI devices are using INTA */ |
| 59 | writel(INTA, &rcba->d02ip); |
| 60 | writel(INTA, &rcba->d03ip); |
| 61 | writel(INTA, &rcba->d27ip); |
| 62 | writel(INTA, &rcba->d31ip); |
| 63 | writel(INTA, &rcba->d23ip); |
| 64 | writel(INTA, &rcba->d24ip); |
| 65 | writel(INTA, &rcba->d25ip); |
| 66 | writel(INTA, &rcba->d26ip); |
| 67 | |
| 68 | /* |
| 69 | * Route TunnelCreek PCI device interrupt pin to PIRQ |
| 70 | * |
| 71 | * Since PCIe downstream ports received INTx are routed to PIRQ |
Bin Meng | d2f66a3 | 2015-06-23 12:18:55 +0800 | [diff] [blame] | 72 | * A/B/C/D directly and not configurable, we have to route PCIe |
| 73 | * root ports' INTx to PIRQ A/B/C/D as well. For other devices |
| 74 | * on TunneCreek, route them to PIRQ E/F/G/H. |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 75 | */ |
| 76 | writew(PIRQE, &rcba->d02ir); |
| 77 | writew(PIRQF, &rcba->d03ir); |
| 78 | writew(PIRQG, &rcba->d27ir); |
| 79 | writew(PIRQH, &rcba->d31ir); |
Bin Meng | d2f66a3 | 2015-06-23 12:18:55 +0800 | [diff] [blame] | 80 | writew(PIRQA, &rcba->d23ir); |
| 81 | writew(PIRQB, &rcba->d24ir); |
| 82 | writew(PIRQC, &rcba->d25ir); |
| 83 | writew(PIRQD, &rcba->d26ir); |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 84 | } |
| 85 | |
Bin Meng | 1530536 | 2015-04-24 18:10:06 +0800 | [diff] [blame] | 86 | int arch_misc_init(void) |
| 87 | { |
| 88 | pirq_init(); |
| 89 | |
| 90 | return 0; |
| 91 | } |