blob: ad634819f283eebed6c93d5774650cfac9d3263f [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>
7#include <intelblocks/acpi.h>
8#include <intelblocks/cfg.h>
Michael Niewöhner8913b782020-12-11 22:13:44 +01009#include <intelblocks/gpio.h>
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070010#include <intelblocks/itss.h>
11#include <intelblocks/pcie_rp.h>
12#include <intelblocks/xdci.h>
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070013#include <soc/intel/common/vbt.h>
14#include <soc/itss.h>
15#include <soc/pci_devs.h>
16#include <soc/ramstage.h>
17#include <soc/soc_chip.h>
18
19static const struct pcie_rp_group pch_rp_groups[] = {
Tan, Lean Sheng3cf8a032020-12-07 06:14:47 -080020 { .slot = PCH_DEV_SLOT_PCIE, .count = 7 },
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070021 { 0 }
22};
23
24#if CONFIG(HAVE_ACPI_TABLES)
25const char *soc_acpi_name(const struct device *dev)
26{
27 if (dev->path.type == DEVICE_PATH_DOMAIN)
28 return "PCI0";
29
30 if (dev->path.type == DEVICE_PATH_USB) {
31 switch (dev->path.usb.port_type) {
32 case 0:
33 /* Root Hub */
34 return "RHUB";
35 case 2:
36 /* USB2 ports */
37 switch (dev->path.usb.port_id) {
38 case 0: return "HS01";
39 case 1: return "HS02";
40 case 2: return "HS03";
41 case 3: return "HS04";
42 case 4: return "HS05";
43 case 5: return "HS06";
44 case 6: return "HS07";
45 case 7: return "HS08";
46 case 8: return "HS09";
47 case 9: return "HS10";
48 }
49 break;
50 case 3:
51 /* USB3 ports */
52 switch (dev->path.usb.port_id) {
53 case 0: return "SS01";
54 case 1: return "SS02";
55 case 2: return "SS03";
56 case 3: return "SS04";
57 }
58 break;
59 }
60 return NULL;
61 }
62 if (dev->path.type != DEVICE_PATH_PCI)
63 return NULL;
64
65 switch (dev->path.pci.devfn) {
66 case SA_DEVFN_ROOT: return "MCHC";
Tan, Lean Sheng3cf8a032020-12-07 06:14:47 -080067 case PCH_DEVFN_I2C6: return "I2C6";
68 case PCH_DEVFN_I2C7: return "I2C7";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070069 case PCH_DEVFN_XHCI: return "XHCI";
70 case PCH_DEVFN_I2C0: return "I2C0";
71 case PCH_DEVFN_I2C1: return "I2C1";
72 case PCH_DEVFN_I2C2: return "I2C2";
73 case PCH_DEVFN_I2C3: return "I2C3";
Tan, Lean Sheng3cf8a032020-12-07 06:14:47 -080074 case PCH_DEVFN_SATA: return "SATA";
75 case PCH_DEVFN_UART2: return "UAR2";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070076 case PCH_DEVFN_I2C4: return "I2C4";
77 case PCH_DEVFN_I2C5: return "I2C5";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070078 case PCH_DEVFN_PCIE1: return "RP01";
79 case PCH_DEVFN_PCIE2: return "RP02";
80 case PCH_DEVFN_PCIE3: return "RP03";
81 case PCH_DEVFN_PCIE4: return "RP04";
82 case PCH_DEVFN_PCIE5: return "RP05";
83 case PCH_DEVFN_PCIE6: return "RP06";
84 case PCH_DEVFN_PCIE7: return "RP07";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070085 case PCH_DEVFN_UART0: return "UAR0";
86 case PCH_DEVFN_UART1: return "UAR1";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070087 case PCH_DEVFN_GSPI0: return "SPI0";
88 case PCH_DEVFN_GSPI1: return "SPI1";
Tan, Lean Sheng3cf8a032020-12-07 06:14:47 -080089 case PCH_DEVFN_GBE: return "GLAN";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070090 case PCH_DEVFN_GSPI2: return "SPI2";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070091 case PCH_DEVFN_EMMC: return "EMMC";
92 case PCH_DEVFN_SDCARD: return "SDXC";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070093 case PCH_DEVFN_HDA: return "HDAS";
94 case PCH_DEVFN_SMBUS: return "SBUS";
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070095 }
96
97 return NULL;
98}
99#endif
100
Angel Pons73a22ed2021-04-05 12:26:51 +0200101/* SoC routine to fill GPIO PM mask and value for GPIO_MISCCFG register */
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700102static void soc_fill_gpio_pm_configuration(void)
103{
104 uint8_t value[TOTAL_GPIO_COMM];
105 const config_t *config = config_of_soc();
106
107 if (config->gpio_override_pm)
Angel Pons0c0d4922021-04-05 13:02:45 +0200108 memcpy(value, config->gpio_pm, sizeof(value));
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700109 else
Angel Pons0c0d4922021-04-05 13:02:45 +0200110 memset(value, MISCCFG_GPIO_PM_CONFIG_BITS, sizeof(value));
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700111
112 gpio_pm_configure(value, TOTAL_GPIO_COMM);
113}
114
115void soc_init_pre_device(void *chip_info)
116{
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700117 /* Perform silicon specific init. */
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200118 fsp_silicon_init();
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700119
120 /* Display FIRMWARE_VERSION_INFO_HOB */
121 fsp_display_fvi_version_hob();
122
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700123 soc_fill_gpio_pm_configuration();
124
125 /* swap enabled PCI ports in device tree if needed */
126 pcie_rp_update_devicetree(pch_rp_groups);
127}
128
129static struct device_operations pci_domain_ops = {
130 .read_resources = &pci_domain_read_resources,
131 .set_resources = &pci_domain_set_resources,
132 .scan_bus = &pci_domain_scan_bus,
133#if CONFIG(HAVE_ACPI_TABLES)
134 .acpi_name = &soc_acpi_name,
135#endif
136};
137
138static struct device_operations cpu_bus_ops = {
139 .read_resources = noop_read_resources,
140 .set_resources = noop_set_resources,
141#if CONFIG(HAVE_ACPI_TABLES)
142 .acpi_fill_ssdt = generate_cpu_entries,
143#endif
144};
145
146extern struct device_operations pmc_ops;
147static void soc_enable(struct device *dev)
148{
149 /* Set the operations if it is a special bus type */
150 if (dev->path.type == DEVICE_PATH_DOMAIN)
151 dev->ops = &pci_domain_ops;
152 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
153 dev->ops = &cpu_bus_ops;
154 else if (dev->path.type == DEVICE_PATH_PCI &&
155 dev->path.pci.devfn == PCH_DEVFN_PMC)
156 dev->ops = &pmc_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +0100157 else if (dev->path.type == DEVICE_PATH_GPIO)
158 block_gpio_enable(dev);
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700159}
160
161struct chip_operations soc_intel_elkhartlake_ops = {
162 CHIP_NAME("Intel Elkhartlake")
163 .enable_dev = &soc_enable,
164 .init = &soc_init_pre_device,
165};