Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Bin Meng | 2b94d9f | 2016-02-01 01:40:54 -0800 | [diff] [blame] | 7 | #include <dm.h> |
Bin Meng | 66484f0 | 2016-02-01 01:40:55 -0800 | [diff] [blame] | 8 | #include <dm/device-internal.h> |
Bin Meng | 2b94d9f | 2016-02-01 01:40:54 -0800 | [diff] [blame] | 9 | #include <pci.h> |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 10 | #include <asm/io.h> |
Bin Meng | 9c7dea6 | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 11 | #include <asm/irq.h> |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 12 | #include <asm/post.h> |
Bin Meng | afbf140 | 2015-04-24 18:10:06 +0800 | [diff] [blame] | 13 | #include <asm/arch/device.h> |
Bin Meng | 9c7dea6 | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 14 | #include <asm/arch/tnc.h> |
Simon Glass | 1021af4 | 2015-01-27 22:13:36 -0700 | [diff] [blame] | 15 | #include <asm/fsp/fsp_support.h> |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 16 | #include <asm/processor.h> |
| 17 | |
Bin Meng | 9e36c53 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 18 | static int __maybe_unused disable_igd(void) |
Bin Meng | 1f124eb | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 19 | { |
Bin Meng | 2b94d9f | 2016-02-01 01:40:54 -0800 | [diff] [blame] | 20 | struct udevice *igd, *sdvo; |
| 21 | int ret; |
| 22 | |
| 23 | ret = dm_pci_bus_find_bdf(TNC_IGD, &igd); |
| 24 | if (ret) |
| 25 | return ret; |
| 26 | if (!igd) |
| 27 | return 0; |
| 28 | |
| 29 | ret = dm_pci_bus_find_bdf(TNC_SDVO, &sdvo); |
| 30 | if (ret) |
| 31 | return ret; |
| 32 | if (!sdvo) |
| 33 | return 0; |
| 34 | |
Bin Meng | e5ffa4b | 2015-10-22 19:13:32 -0700 | [diff] [blame] | 35 | /* |
| 36 | * According to Atom E6xx datasheet, setting VGA Disable (bit17) |
| 37 | * of Graphics Controller register (offset 0x50) prevents IGD |
| 38 | * (D2:F0) from reporting itself as a VGA display controller |
| 39 | * class in the PCI configuration space, and should also prevent |
| 40 | * it from responding to VGA legacy memory range and I/O addresses. |
| 41 | * |
| 42 | * However test result shows that with just VGA Disable bit set and |
| 43 | * a PCIe graphics card connected to one of the PCIe controllers on |
| 44 | * the E6xx, accessing the VGA legacy space still causes system hang. |
| 45 | * After a number of attempts, it turns out besides VGA Disable bit, |
| 46 | * the SDVO (D3:F0) device should be disabled to make it work. |
| 47 | * |
| 48 | * To simplify, use the Function Disable register (offset 0xc4) |
| 49 | * to disable both IGD (D2:F0) and SDVO (D3:F0) devices. Now these |
| 50 | * two devices will be completely disabled (invisible in the PCI |
| 51 | * configuration space) unless a system reset is performed. |
| 52 | */ |
Bin Meng | 2b94d9f | 2016-02-01 01:40:54 -0800 | [diff] [blame] | 53 | dm_pci_write_config32(igd, IGD_FD, FUNC_DISABLE); |
| 54 | dm_pci_write_config32(sdvo, IGD_FD, FUNC_DISABLE); |
Bin Meng | 9e36c53 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 55 | |
Bin Meng | 66484f0 | 2016-02-01 01:40:55 -0800 | [diff] [blame] | 56 | /* |
| 57 | * After setting the function disable bit, IGD and SDVO devices will |
| 58 | * disappear in the PCI configuration space. This however creates an |
| 59 | * inconsistent state from a driver model PCI controller point of view, |
| 60 | * as these two PCI devices are still attached to its parent's child |
| 61 | * device list as maintained by the driver model. Some driver model PCI |
| 62 | * APIs like dm_pci_find_class(), are referring to the list to speed up |
| 63 | * the finding process instead of re-enumerating the whole PCI bus, so |
| 64 | * it gets the stale cached data which is wrong. |
| 65 | * |
| 66 | * Note x86 PCI enueration normally happens twice, in pre-relocation |
| 67 | * phase and post-relocation. One option might be to call disable_igd() |
| 68 | * in one of the pre-relocation initialization hooks so that it gets |
| 69 | * disabled in the first round, and when it comes to the second round |
| 70 | * driver model PCI will construct a correct list. Unfortunately this |
| 71 | * does not work as Intel FSP is used on this platform to perform low |
| 72 | * level initialization, and fsp_init_phase_pci() is called only once |
| 73 | * in the post-relocation phase. If we disable IGD and SDVO devices, |
| 74 | * fsp_init_phase_pci() simply hangs and never returns. |
| 75 | * |
| 76 | * So the only option we have is to manually remove these two devices. |
| 77 | */ |
Stefan Roese | 706865a | 2017-03-20 12:51:48 +0100 | [diff] [blame] | 78 | ret = device_remove(igd, DM_REMOVE_NORMAL); |
Bin Meng | 66484f0 | 2016-02-01 01:40:55 -0800 | [diff] [blame] | 79 | if (ret) |
| 80 | return ret; |
| 81 | ret = device_unbind(igd); |
| 82 | if (ret) |
| 83 | return ret; |
Stefan Roese | 706865a | 2017-03-20 12:51:48 +0100 | [diff] [blame] | 84 | ret = device_remove(sdvo, DM_REMOVE_NORMAL); |
Bin Meng | 66484f0 | 2016-02-01 01:40:55 -0800 | [diff] [blame] | 85 | if (ret) |
| 86 | return ret; |
| 87 | ret = device_unbind(sdvo); |
| 88 | if (ret) |
| 89 | return ret; |
| 90 | |
Bin Meng | 9e36c53 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 91 | return 0; |
Bin Meng | 1f124eb | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 94 | int arch_cpu_init(void) |
| 95 | { |
| 96 | post_code(POST_CPU_INIT); |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 97 | |
Masahiro Yamada | 0a8547a | 2016-09-06 22:17:36 +0900 | [diff] [blame] | 98 | return x86_cpu_init_f(); |
Bin Meng | b2e02d2 | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 99 | } |
Bin Meng | afbf140 | 2015-04-24 18:10:06 +0800 | [diff] [blame] | 100 | |
Bin Meng | bc728b1 | 2018-06-03 19:04:22 -0700 | [diff] [blame] | 101 | static void tnc_irq_init(void) |
| 102 | { |
| 103 | struct tnc_rcba *rcba; |
| 104 | u32 base; |
| 105 | |
| 106 | pci_read_config32(TNC_LPC, LPC_RCBA, &base); |
| 107 | base &= ~MEM_BAR_EN; |
| 108 | rcba = (struct tnc_rcba *)base; |
| 109 | |
| 110 | /* Make sure all internal PCI devices are using INTA */ |
| 111 | writel(INTA, &rcba->d02ip); |
| 112 | writel(INTA, &rcba->d03ip); |
| 113 | writel(INTA, &rcba->d27ip); |
| 114 | writel(INTA, &rcba->d31ip); |
| 115 | writel(INTA, &rcba->d23ip); |
| 116 | writel(INTA, &rcba->d24ip); |
| 117 | writel(INTA, &rcba->d25ip); |
| 118 | writel(INTA, &rcba->d26ip); |
| 119 | |
| 120 | /* |
| 121 | * Route TunnelCreek PCI device interrupt pin to PIRQ |
| 122 | * |
| 123 | * Since PCIe downstream ports received INTx are routed to PIRQ |
| 124 | * A/B/C/D directly and not configurable, we have to route PCIe |
| 125 | * root ports' INTx to PIRQ A/B/C/D as well. For other devices |
| 126 | * on TunneCreek, route them to PIRQ E/F/G/H. |
| 127 | */ |
| 128 | writew(PIRQE, &rcba->d02ir); |
| 129 | writew(PIRQF, &rcba->d03ir); |
| 130 | writew(PIRQG, &rcba->d27ir); |
| 131 | writew(PIRQH, &rcba->d31ir); |
| 132 | writew(PIRQA, &rcba->d23ir); |
| 133 | writew(PIRQB, &rcba->d24ir); |
| 134 | writew(PIRQC, &rcba->d25ir); |
| 135 | writew(PIRQD, &rcba->d26ir); |
| 136 | } |
| 137 | |
Bin Meng | 1f124eb | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 138 | int arch_early_init_r(void) |
| 139 | { |
Bin Meng | 9e36c53 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 140 | int ret = 0; |
| 141 | |
Bin Meng | 1f124eb | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 142 | #ifdef CONFIG_DISABLE_IGD |
Bin Meng | 9e36c53 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 143 | ret = disable_igd(); |
Bin Meng | 1f124eb | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 144 | #endif |
| 145 | |
Bin Meng | bc728b1 | 2018-06-03 19:04:22 -0700 | [diff] [blame] | 146 | tnc_irq_init(); |
| 147 | |
Bin Meng | 9e36c53 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 148 | return ret; |
Bin Meng | 1f124eb | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 149 | } |