1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
9 #include <dm/device-internal.h>
14 #include <asm/arch/device.h>
15 #include <asm/arch/tnc.h>
16 #include <asm/fsp1/fsp_support.h>
17 #include <asm/processor.h>
19 static int __maybe_unused disable_igd(void)
21 struct udevice *igd, *sdvo;
24 ret = dm_pci_bus_find_bdf(TNC_IGD, &igd);
30 ret = dm_pci_bus_find_bdf(TNC_SDVO, &sdvo);
37 * According to Atom E6xx datasheet, setting VGA Disable (bit17)
38 * of Graphics Controller register (offset 0x50) prevents IGD
39 * (D2:F0) from reporting itself as a VGA display controller
40 * class in the PCI configuration space, and should also prevent
41 * it from responding to VGA legacy memory range and I/O addresses.
43 * However test result shows that with just VGA Disable bit set and
44 * a PCIe graphics card connected to one of the PCIe controllers on
45 * the E6xx, accessing the VGA legacy space still causes system hang.
46 * After a number of attempts, it turns out besides VGA Disable bit,
47 * the SDVO (D3:F0) device should be disabled to make it work.
49 * To simplify, use the Function Disable register (offset 0xc4)
50 * to disable both IGD (D2:F0) and SDVO (D3:F0) devices. Now these
51 * two devices will be completely disabled (invisible in the PCI
52 * configuration space) unless a system reset is performed.
54 dm_pci_write_config32(igd, IGD_FD, FUNC_DISABLE);
55 dm_pci_write_config32(sdvo, IGD_FD, FUNC_DISABLE);
58 * After setting the function disable bit, IGD and SDVO devices will
59 * disappear in the PCI configuration space. This however creates an
60 * inconsistent state from a driver model PCI controller point of view,
61 * as these two PCI devices are still attached to its parent's child
62 * device list as maintained by the driver model. Some driver model PCI
63 * APIs like dm_pci_find_class(), are referring to the list to speed up
64 * the finding process instead of re-enumerating the whole PCI bus, so
65 * it gets the stale cached data which is wrong.
67 * Note x86 PCI enueration normally happens twice, in pre-relocation
68 * phase and post-relocation. One option might be to call disable_igd()
69 * in one of the pre-relocation initialization hooks so that it gets
70 * disabled in the first round, and when it comes to the second round
71 * driver model PCI will construct a correct list. Unfortunately this
72 * does not work as Intel FSP is used on this platform to perform low
73 * level initialization, and fsp_init_phase_pci() is called only once
74 * in the post-relocation phase. If we disable IGD and SDVO devices,
75 * fsp_init_phase_pci() simply hangs and never returns.
77 * So the only option we have is to manually remove these two devices.
79 ret = device_remove(igd, DM_REMOVE_NORMAL);
82 ret = device_unbind(igd);
85 ret = device_remove(sdvo, DM_REMOVE_NORMAL);
88 ret = device_unbind(sdvo);
95 int arch_cpu_init(void)
97 post_code(POST_CPU_INIT);
99 return x86_cpu_init_f();
102 static void tnc_irq_init(void)
104 struct tnc_rcba *rcba;
107 pci_read_config32(TNC_LPC, LPC_RCBA, &base);
109 rcba = (struct tnc_rcba *)base;
111 /* Make sure all internal PCI devices are using INTA */
112 writel(INTA, &rcba->d02ip);
113 writel(INTA, &rcba->d03ip);
114 writel(INTA, &rcba->d27ip);
115 writel(INTA, &rcba->d31ip);
116 writel(INTA, &rcba->d23ip);
117 writel(INTA, &rcba->d24ip);
118 writel(INTA, &rcba->d25ip);
119 writel(INTA, &rcba->d26ip);
122 * Route TunnelCreek PCI device interrupt pin to PIRQ
124 * Since PCIe downstream ports received INTx are routed to PIRQ
125 * A/B/C/D directly and not configurable, we have to route PCIe
126 * root ports' INTx to PIRQ A/B/C/D as well. For other devices
127 * on TunneCreek, route them to PIRQ E/F/G/H.
129 writew(PIRQE, &rcba->d02ir);
130 writew(PIRQF, &rcba->d03ir);
131 writew(PIRQG, &rcba->d27ir);
132 writew(PIRQH, &rcba->d31ir);
133 writew(PIRQA, &rcba->d23ir);
134 writew(PIRQB, &rcba->d24ir);
135 writew(PIRQC, &rcba->d25ir);
136 writew(PIRQD, &rcba->d26ir);
139 int arch_early_init_r(void)
143 #ifdef CONFIG_DISABLE_IGD