blob: 4d61c3b5edaa889ece27f71400bf9fbc5492e526 [file] [log] [blame]
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <device/device.h>
4#include <device/pci.h>
5#include <fsp/api.h>
6#include <fsp/util.h>
Dinesh Gehlota464af42023-01-17 05:23:16 +00007#include <gpio.h>
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -07008#include <intelblocks/acpi.h>
9#include <intelblocks/cfg.h>
10#include <intelblocks/itss.h>
11#include <intelblocks/pcie_rp.h>
Arthur Heymans08769c62022-05-09 14:33:15 +020012#include <intelblocks/systemagent.h>
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070013#include <intelblocks/xdci.h>
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070014#include <soc/intel/common/vbt.h>
15#include <soc/itss.h>
16#include <soc/pci_devs.h>
17#include <soc/ramstage.h>
18#include <soc/soc_chip.h>
19
20static const struct pcie_rp_group pch_rp_groups[] = {
MAULIK V VAGHELAd9c5b142022-02-14 22:04:03 +053021 { .slot = PCH_DEV_SLOT_PCIE, .count = 7, .lcap_port_base = 1 },
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070022 { 0 }
23};
24
25#if CONFIG(HAVE_ACPI_TABLES)
26const char *soc_acpi_name(const struct device *dev)
27{
28 if (dev->path.type == DEVICE_PATH_DOMAIN)
29 return "PCI0";
30
31 if (dev->path.type == DEVICE_PATH_USB) {
32 switch (dev->path.usb.port_type) {
33 case 0:
34 /* Root Hub */
35 return "RHUB";
36 case 2:
37 /* USB2 ports */
38 switch (dev->path.usb.port_id) {
39 case 0: return "HS01";
40 case 1: return "HS02";
41 case 2: return "HS03";
42 case 3: return "HS04";
43 case 4: return "HS05";
44 case 5: return "HS06";
45 case 6: return "HS07";
46 case 7: return "HS08";
47 case 8: return "HS09";
48 case 9: return "HS10";
49 }
50 break;
51 case 3:
52 /* USB3 ports */
53 switch (dev->path.usb.port_id) {
54 case 0: return "SS01";
55 case 1: return "SS02";
56 case 2: return "SS03";
57 case 3: return "SS04";
58 }
59 break;
60 }
61 return NULL;
62 }
63 if (dev->path.type != DEVICE_PATH_PCI)
64 return NULL;
65
66 switch (dev->path.pci.devfn) {
67 case SA_DEVFN_ROOT: return "MCHC";
Tan, Lean Sheng3cf8a032020-12-07 06:14:47 -080068 case PCH_DEVFN_I2C6: return "I2C6";
69 case PCH_DEVFN_I2C7: return "I2C7";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070070 case PCH_DEVFN_XHCI: return "XHCI";
71 case PCH_DEVFN_I2C0: return "I2C0";
72 case PCH_DEVFN_I2C1: return "I2C1";
73 case PCH_DEVFN_I2C2: return "I2C2";
74 case PCH_DEVFN_I2C3: return "I2C3";
Tan, Lean Sheng3cf8a032020-12-07 06:14:47 -080075 case PCH_DEVFN_SATA: return "SATA";
76 case PCH_DEVFN_UART2: return "UAR2";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070077 case PCH_DEVFN_I2C4: return "I2C4";
78 case PCH_DEVFN_I2C5: return "I2C5";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070079 case PCH_DEVFN_PCIE1: return "RP01";
80 case PCH_DEVFN_PCIE2: return "RP02";
81 case PCH_DEVFN_PCIE3: return "RP03";
82 case PCH_DEVFN_PCIE4: return "RP04";
83 case PCH_DEVFN_PCIE5: return "RP05";
84 case PCH_DEVFN_PCIE6: return "RP06";
85 case PCH_DEVFN_PCIE7: return "RP07";
Lean Sheng Tan7760fe42021-07-27 04:28:20 -070086 case PCH_DEVFN_PSEGBE0: return "OTN0";
87 case PCH_DEVFN_PSEGBE1: return "OTN1";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070088 case PCH_DEVFN_UART0: return "UAR0";
89 case PCH_DEVFN_UART1: return "UAR1";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070090 case PCH_DEVFN_GSPI0: return "SPI0";
91 case PCH_DEVFN_GSPI1: return "SPI1";
Lean Sheng Tan7760fe42021-07-27 04:28:20 -070092 case PCH_DEVFN_GBE: return "GTSN";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070093 case PCH_DEVFN_GSPI2: return "SPI2";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070094 case PCH_DEVFN_EMMC: return "EMMC";
95 case PCH_DEVFN_SDCARD: return "SDXC";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070096 case PCH_DEVFN_HDA: return "HDAS";
97 case PCH_DEVFN_SMBUS: return "SBUS";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070098 }
99
100 return NULL;
101}
102#endif
103
Angel Pons73a22ed2021-04-05 12:26:51 +0200104/* SoC routine to fill GPIO PM mask and value for GPIO_MISCCFG register */
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700105static void soc_fill_gpio_pm_configuration(void)
106{
107 uint8_t value[TOTAL_GPIO_COMM];
108 const config_t *config = config_of_soc();
109
110 if (config->gpio_override_pm)
Angel Pons0c0d4922021-04-05 13:02:45 +0200111 memcpy(value, config->gpio_pm, sizeof(value));
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700112 else
Angel Pons0c0d4922021-04-05 13:02:45 +0200113 memset(value, MISCCFG_GPIO_PM_CONFIG_BITS, sizeof(value));
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700114
115 gpio_pm_configure(value, TOTAL_GPIO_COMM);
116}
117
118void soc_init_pre_device(void *chip_info)
119{
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700120 /* Perform silicon specific init. */
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200121 fsp_silicon_init();
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700122
123 /* Display FIRMWARE_VERSION_INFO_HOB */
124 fsp_display_fvi_version_hob();
125
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700126 soc_fill_gpio_pm_configuration();
127
128 /* swap enabled PCI ports in device tree if needed */
129 pcie_rp_update_devicetree(pch_rp_groups);
130}
131
132static struct device_operations pci_domain_ops = {
133 .read_resources = &pci_domain_read_resources,
134 .set_resources = &pci_domain_set_resources,
135 .scan_bus = &pci_domain_scan_bus,
136#if CONFIG(HAVE_ACPI_TABLES)
137 .acpi_name = &soc_acpi_name,
Arthur Heymans08769c62022-05-09 14:33:15 +0200138 .acpi_fill_ssdt = ssdt_set_above_4g_pci,
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700139#endif
140};
141
142static struct device_operations cpu_bus_ops = {
143 .read_resources = noop_read_resources,
144 .set_resources = noop_set_resources,
145#if CONFIG(HAVE_ACPI_TABLES)
146 .acpi_fill_ssdt = generate_cpu_entries,
147#endif
148};
149
150extern struct device_operations pmc_ops;
151static void soc_enable(struct device *dev)
152{
153 /* Set the operations if it is a special bus type */
154 if (dev->path.type == DEVICE_PATH_DOMAIN)
155 dev->ops = &pci_domain_ops;
156 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
157 dev->ops = &cpu_bus_ops;
158 else if (dev->path.type == DEVICE_PATH_PCI &&
159 dev->path.pci.devfn == PCH_DEVFN_PMC)
160 dev->ops = &pmc_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +0100161 else if (dev->path.type == DEVICE_PATH_GPIO)
162 block_gpio_enable(dev);
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700163}
164
165struct chip_operations soc_intel_elkhartlake_ops = {
166 CHIP_NAME("Intel Elkhartlake")
167 .enable_dev = &soc_enable,
168 .init = &soc_init_pre_device,
169};