blob: 16d0520bf90d1ded6090ad970252c77d782bafbf [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgie72a8a32012-11-06 11:05:09 +01002
Patrick Georgie72a8a32012-11-06 11:05:09 +01003#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Patrick Georgie72a8a32012-11-06 11:05:09 +01005#include <device/device.h>
6#include <device/pci.h>
7#include <console/console.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +03008#include "chip.h"
Patrick Georgie72a8a32012-11-06 11:05:09 +01009#include "i82801ix.h"
10
11typedef struct southbridge_intel_i82801ix_config config_t;
12
Elyes HAOUAS8aa50732018-05-13 13:34:58 +020013static void i82801ix_enable_device(struct device *dev)
Patrick Georgie72a8a32012-11-06 11:05:09 +010014{
Patrick Georgie72a8a32012-11-06 11:05:09 +010015 /* Enable SERR */
Elyes HAOUASb9d2e222020-04-28 10:25:12 +020016 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_SERR);
Patrick Georgie72a8a32012-11-06 11:05:09 +010017}
18
19static void i82801ix_early_settings(const config_t *const info)
20{
21 /* Program FERR# as processor break event indicator. */
Stefan Taunercea31ea2018-08-11 18:45:28 +020022 RCBA32(GCS) |= (1 << 6);
23 /* BIOS must program...
24 * NB: other CIRs are handled in i82801ix_dmi_setup(). */
25 RCBA32(RCBA_CIR8) = (RCBA32(RCBA_CIR8) & ~(0x3 << 0)) | (0x2 << 0);
26 RCBA32(RCBA_FD) |= (1 << 0);
27 RCBA32(RCBA_CIR9) = (RCBA32(RCBA_CIR9) & ~(0x3 << 26)) | (0x2 << 26);
28 RCBA32(RCBA_CIR7) = (RCBA32(RCBA_CIR7) & ~(0xf << 16)) | (0x5 << 16);
29 RCBA32(RCBA_CIR13) = (RCBA32(RCBA_CIR13) & ~(0xf << 16)) | (0x5 << 16);
Stefan Tauner97c80892018-08-15 08:06:13 +020030 /* RCBA32(RCBA_CIR5) |= (1 << 0); cf. Specification Update */
Stefan Taunercea31ea2018-08-11 18:45:28 +020031 RCBA32(RCBA_CIR10) |= (3 << 16);
Patrick Georgie72a8a32012-11-06 11:05:09 +010032}
33
34static void i82801ix_pcie_init(const config_t *const info)
35{
Elyes HAOUAS8aa50732018-05-13 13:34:58 +020036 struct device *pciePort[6];
Patrick Georgie72a8a32012-11-06 11:05:09 +010037 int i, slot_number = 1; /* Reserve slot number 0 for nb's PEG. */
38 u32 reg32;
39
40 /* PCIe - BIOS must program... */
41 for (i = 0; i < 6; ++i) {
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030042 pciePort[i] = pcidev_on_root(0x1c, i);
Patrick Georgie72a8a32012-11-06 11:05:09 +010043 if (!pciePort[i]) {
44 printk(BIOS_EMERG, "PCIe port 00:1c.%x", i);
45 die(" is not listed in devicetree.\n");
46 }
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030047 reg32 = pci_read_config32(pciePort[i], 0x300);
48 pci_write_config32(pciePort[i], 0x300, reg32 | (1 << 21));
49 pci_write_config8(pciePort[i], 0x324, 0x40);
Patrick Georgie72a8a32012-11-06 11:05:09 +010050 }
51
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030052 if (LPC_IS_MOBILE(pcidev_on_root(0x1f, 0))) {
Patrick Georgie72a8a32012-11-06 11:05:09 +010053 for (i = 0; i < 6; ++i) {
54 if (pciePort[i]->enabled) {
Angel Pons67406472020-06-08 11:13:42 +020055 pci_or_config32(pciePort[i], 0xe8, 1);
Patrick Georgie72a8a32012-11-06 11:05:09 +010056 }
57 }
58 }
59
60 for (i = 5; (i >= 0) && !pciePort[i]->enabled; --i) {
61 /* Only for the top disabled ports. */
Angel Pons67406472020-06-08 11:13:42 +020062 pci_or_config32(pciePort[i], 0x300, 0x3 << 16);
Patrick Georgie72a8a32012-11-06 11:05:09 +010063 }
64
65 /* Set slot implemented, slot number and slot power limits. */
66 for (i = 0; i < 6; ++i) {
Elyes HAOUAS8aa50732018-05-13 13:34:58 +020067 struct device *const dev = pciePort[i];
Patrick Georgie72a8a32012-11-06 11:05:09 +010068 u32 xcap = pci_read_config32(dev, D28Fx_XCAP);
69 if (info->pcie_slot_implemented & (1 << i))
70 xcap |= PCI_EXP_FLAGS_SLOT;
71 else
72 xcap &= ~PCI_EXP_FLAGS_SLOT;
73 pci_write_config32(dev, D28Fx_XCAP, xcap);
74
75 if (info->pcie_slot_implemented & (1 << i)) {
76 u32 slcap = pci_read_config32(dev, D28Fx_SLCAP);
77 slcap &= ~(0x1fff << 19);
78 slcap |= (slot_number++ << 19);
79 slcap &= ~(0x0003 << 16);
80 slcap |= (info->pcie_power_limits[i].scale << 16);
81 slcap &= ~(0x00ff << 7);
82 slcap |= (info->pcie_power_limits[i].value << 7);
83 pci_write_config32(dev, D28Fx_SLCAP, slcap);
84 }
85 }
86
87 /* Lock R/WO ASPM support bits. */
88 for (i = 0; i < 6; ++i) {
Angel Pons67406472020-06-08 11:13:42 +020089 pci_update_config32(pciePort[i], 0x4c, ~0, 0);
Patrick Georgie72a8a32012-11-06 11:05:09 +010090 }
91}
92
93static void i82801ix_ehci_init(void)
94{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030095 struct device *const pciEHCI1 = pcidev_on_root(0x1d, 7);
Patrick Georgie72a8a32012-11-06 11:05:09 +010096 if (!pciEHCI1)
97 die("EHCI controller (00:1d.7) not listed in devicetree.\n");
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030098 struct device *const pciEHCI2 = pcidev_on_root(0x1a, 7);
Patrick Georgie72a8a32012-11-06 11:05:09 +010099 if (!pciEHCI2)
100 die("EHCI controller (00:1a.7) not listed in devicetree.\n");
101
102 u32 reg32;
103
104 /* TODO: Maybe we have to save and
105 restore these settings across S3. */
106 reg32 = pci_read_config32(pciEHCI1, 0xfc);
107 pci_write_config32(pciEHCI1, 0xfc, (reg32 & ~(3 << 2)) |
108 (1 << 29) | (1 << 17) | (2 << 2));
109 reg32 = pci_read_config32(pciEHCI2, 0xfc);
110 pci_write_config32(pciEHCI2, 0xfc, (reg32 & ~(3 << 2)) |
111 (1 << 29) | (1 << 17) | (2 << 2));
112}
113
Martin Rothff744bf2019-10-23 21:46:03 -0600114static int i82801ix_function_disabled(const unsigned int devfn)
Patrick Georgie72a8a32012-11-06 11:05:09 +0100115{
Kyösti Mälkkie7377552018-06-21 16:20:55 +0300116 struct device *const dev = pcidev_path_on_root(devfn);
Patrick Georgie72a8a32012-11-06 11:05:09 +0100117 if (!dev) {
118 printk(BIOS_EMERG,
119 "PCI device 00:%x.%x",
120 PCI_SLOT(devfn), PCI_FUNC(devfn));
121 die(" is not listed in devicetree.\n");
122 }
123 return !dev->enabled;
124}
125
126static void i82801ix_hide_functions(void)
127{
128 int i;
129 u32 reg32;
130
131 /* FIXME: This works pretty good if the devicetree is consistent. But
132 some functions have to be disabled in right order and/or have
133 other constraints. */
134
135 if (i82801ix_function_disabled(PCI_DEVFN(0x19, 0)))
136 RCBA32(RCBA_BUC) |= BUC_LAND;
137
138 reg32 = RCBA32(RCBA_FD);
139 struct {
140 int devfn;
141 u32 mask;
142 } functions[] = {
143 { PCI_DEVFN(0x1a, 0), FD_U4D }, /* UHCI #4 */
144 { PCI_DEVFN(0x1a, 1), FD_U5D }, /* UHCI #5 */
145 { PCI_DEVFN(0x1a, 2), FD_U6D }, /* UHCI #6 */
146 { PCI_DEVFN(0x1a, 7), FD_EHCI2D }, /* EHCI #2 */
147 { PCI_DEVFN(0x1b, 0), FD_HDAD }, /* HD Audio */
148 { PCI_DEVFN(0x1c, 0), FD_PE1D }, /* PCIe #1 */
149 { PCI_DEVFN(0x1c, 1), FD_PE2D }, /* PCIe #2 */
150 { PCI_DEVFN(0x1c, 2), FD_PE3D }, /* PCIe #3 */
151 { PCI_DEVFN(0x1c, 3), FD_PE4D }, /* PCIe #4 */
152 { PCI_DEVFN(0x1c, 4), FD_PE5D }, /* PCIe #5 */
153 { PCI_DEVFN(0x1c, 5), FD_PE6D }, /* PCIe #6 */
154 { PCI_DEVFN(0x1d, 0), FD_U1D }, /* UHCI #1 */
155 { PCI_DEVFN(0x1d, 1), FD_U2D }, /* UHCI #2 */
156 { PCI_DEVFN(0x1d, 2), FD_U3D }, /* UHCI #3 */
157 { PCI_DEVFN(0x1d, 7), FD_EHCI1D }, /* EHCI #1 */
158 { PCI_DEVFN(0x1f, 0), FD_LBD }, /* LPC */
159 { PCI_DEVFN(0x1f, 2), FD_SAD1 }, /* SATA #1 */
160 { PCI_DEVFN(0x1f, 3), FD_SD }, /* SMBus */
161 { PCI_DEVFN(0x1f, 5), FD_SAD2 }, /* SATA #2 */
162 { PCI_DEVFN(0x1f, 6), FD_TTD }, /* Thermal Throttle */
163 };
164 for (i = 0; i < ARRAY_SIZE(functions); ++i) {
165 if (i82801ix_function_disabled(functions[i].devfn))
166 reg32 |= functions[i].mask;
167 }
168 RCBA32(RCBA_FD) = reg32;
169 RCBA32(RCBA_FD) |= (1 << 0); /* BIOS must write this... */
170 RCBA32(RCBA_FDSW) |= (1 << 7); /* Lock function-disable? */
171
172 /* Hide PCIe root port PCI functions. RPFN is partially R/WO. */
173 reg32 = RCBA32(RCBA_RPFN);
174 for (i = 0; i < 6; ++i) {
175 if (i82801ix_function_disabled(PCI_DEVFN(0x1c, i)))
176 reg32 |= (1 << ((i * 4) + 3));
177 }
178 RCBA32(RCBA_RPFN) = reg32;
179
180 /* Lock R/WO UHCI controller #6 remapping. */
181 RCBA32(RCBA_MAP) = RCBA32(RCBA_MAP);
182}
183
184static void i82801ix_init(void *chip_info)
185{
186 const config_t *const info = (config_t *)chip_info;
187
188 printk(BIOS_DEBUG, "Initializing i82801ix southbridge...\n");
189
190 i82801ix_early_settings(info);
191
192 /* PCI Express setup. */
193 i82801ix_pcie_init(info);
194
195 /* EHCI configuration. */
196 i82801ix_ehci_init();
197
198 /* Now hide internal functions. We can't access them after this. */
199 i82801ix_hide_functions();
200
201 /* Reset watchdog timer. */
Julius Wernercd49cce2019-03-05 16:53:33 -0800202#if !CONFIG(HAVE_SMI_HANDLER)
Patrick Georgie72a8a32012-11-06 11:05:09 +0100203 outw(0x0008, DEFAULT_TCOBASE + 0x12); /* Set higher timer value. */
204#endif
205 outw(0x0000, DEFAULT_TCOBASE + 0x00); /* Update timer. */
Patrick Georgie72a8a32012-11-06 11:05:09 +0100206}
207
208struct chip_operations southbridge_intel_i82801ix_ops = {
209 CHIP_NAME("Intel ICH9/ICH9-M (82801Ix) Series Southbridge")
210 .enable_dev = i82801ix_enable_device,
211 .init = i82801ix_init,
212};