blob: 1f58f84c1817effb1b3b9ab5c77ed41a209a0bdc [file] [log] [blame]
Angel Ponsfabfe9d2020-04-05 15:47:07 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aamir Bohradd7acaa2020-03-25 11:36:22 +05302
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>
Aamir Bohradd7acaa2020-03-25 11:36:22 +053010#include <intelblocks/itss.h>
Karthikeyan Ramasubramanianf8712782020-07-24 15:57:50 -060011#include <intelblocks/pcie_rp.h>
Aamir Bohradd7acaa2020-03-25 11:36:22 +053012#include <intelblocks/xdci.h>
13#include <romstage_handoff.h>
14#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
Karthikeyan Ramasubramanianf8712782020-07-24 15:57:50 -060020static const struct pcie_rp_group pch_rp_groups[] = {
21 { .slot = PCH_DEV_SLOT_PCIE, .count = 8 },
22 { 0 }
23};
24
Aamir Bohradd7acaa2020-03-25 11:36:22 +053025#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";
Tim Wawrzynczak4b748142020-06-29 12:34:55 -060068 case SA_DEVFN_IPU: return "IPU0";
Aamir Bohradd7acaa2020-03-25 11:36:22 +053069 case PCH_DEVFN_ISH: return "ISHB";
70 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";
75 case PCH_DEVFN_I2C4: return "I2C4";
76 case PCH_DEVFN_I2C5: return "I2C5";
77 case PCH_DEVFN_SATA: return "SATA";
78 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";
85 case PCH_DEVFN_PCIE8: return "RP08";
86 case PCH_DEVFN_PCIE9: return "RP09";
87 case PCH_DEVFN_PCIE10: return "RP10";
88 case PCH_DEVFN_PCIE11: return "RP11";
89 case PCH_DEVFN_PCIE12: return "RP12";
90 case PCH_DEVFN_UART0: return "UAR0";
91 case PCH_DEVFN_UART1: return "UAR1";
92 case PCH_DEVFN_UART2: return "UAR2";
93 case PCH_DEVFN_GSPI0: return "SPI0";
94 case PCH_DEVFN_GSPI1: return "SPI1";
95 case PCH_DEVFN_GSPI2: return "SPI2";
96 case PCH_DEVFN_GSPI3: return "SPI3";
Karthikeyan Ramasubramaniane5ec91b2020-04-15 14:27:36 -060097 case PCH_DEVFN_EMMC: return "EMMC";
98 case PCH_DEVFN_SDCARD: return "SDXC";
Aamir Bohradd7acaa2020-03-25 11:36:22 +053099 case PCH_DEVFN_HDA: return "HDAS";
100 case PCH_DEVFN_SMBUS: return "SBUS";
101 case PCH_DEVFN_GBE: return "GLAN";
102 }
103
104 return NULL;
105}
106#endif
107
108/* SoC rotine to fill GPIO PM mask and value for GPIO_MISCCFG register */
109static void soc_fill_gpio_pm_configuration(void)
110{
111 uint8_t value[TOTAL_GPIO_COMM];
112 const config_t *config = config_of_soc();
113
114 if (config->gpio_override_pm)
115 memcpy(value, config->gpio_pm, sizeof(uint8_t) *
116 TOTAL_GPIO_COMM);
117 else
118 memset(value, MISCCFG_ENABLE_GPIO_PM_CONFIG, sizeof(uint8_t) *
119 TOTAL_GPIO_COMM);
120
121 gpio_pm_configure(value, TOTAL_GPIO_COMM);
122}
123
124void soc_init_pre_device(void *chip_info)
125{
126 /* Snapshot the current GPIO IRQ polarities. FSP is setting a
127 * default policy that doesn't honor boards' requirements. */
128 itss_snapshot_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END);
129
130 /* Perform silicon specific init. */
131 fsp_silicon_init(romstage_handoff_is_resume());
132
133 /* Display FIRMWARE_VERSION_INFO_HOB */
134 fsp_display_fvi_version_hob();
135
136 /* Restore GPIO IRQ polarities back to previous settings. */
137 itss_restore_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END);
138
139 soc_fill_gpio_pm_configuration();
Karthikeyan Ramasubramanianf8712782020-07-24 15:57:50 -0600140
141 /* swap enabled PCI ports in device tree if needed */
142 pcie_rp_update_devicetree(pch_rp_groups);
Aamir Bohradd7acaa2020-03-25 11:36:22 +0530143}
144
Aamir Bohradd7acaa2020-03-25 11:36:22 +0530145static struct device_operations pci_domain_ops = {
146 .read_resources = &pci_domain_read_resources,
147 .set_resources = &pci_domain_set_resources,
148 .scan_bus = &pci_domain_scan_bus,
149#if CONFIG(HAVE_ACPI_TABLES)
150 .acpi_name = &soc_acpi_name,
151#endif
152};
153
154static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200155 .read_resources = noop_read_resources,
156 .set_resources = noop_set_resources,
Aamir Bohradd7acaa2020-03-25 11:36:22 +0530157#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +0200158 .acpi_fill_ssdt = generate_cpu_entries,
Aamir Bohradd7acaa2020-03-25 11:36:22 +0530159#endif
160};
161
Tim Wawrzynczakc47422d2020-06-01 17:03:41 -0600162extern struct device_operations pmc_ops;
Aamir Bohradd7acaa2020-03-25 11:36:22 +0530163static void soc_enable(struct device *dev)
164{
165 /* Set the operations if it is a special bus type */
166 if (dev->path.type == DEVICE_PATH_DOMAIN)
167 dev->ops = &pci_domain_ops;
168 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
169 dev->ops = &cpu_bus_ops;
Tim Wawrzynczakc47422d2020-06-01 17:03:41 -0600170 else if (dev->path.type == DEVICE_PATH_PCI &&
171 dev->path.pci.devfn == PCH_DEVFN_PMC)
172 dev->ops = &pmc_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +0100173 else if (dev->path.type == DEVICE_PATH_GPIO)
174 block_gpio_enable(dev);
Aamir Bohradd7acaa2020-03-25 11:36:22 +0530175}
176
Aamir Bohra512b77a2020-03-25 13:20:34 +0530177struct chip_operations soc_intel_jasperlake_ops = {
178 CHIP_NAME("Intel Jasperlake")
Aamir Bohradd7acaa2020-03-25 11:36:22 +0530179 .enable_dev = &soc_enable,
180 .init = &soc_init_pre_device,
181};