blob: 0958aace0247f8beb1248e68585a9b56a0fcd22d [file] [log] [blame]
Angel Ponsf5627e82020-04-05 15:46:52 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lijian Zhao2f764f72017-07-14 11:09:10 -07002
Pratik Prajapati201fa8f2017-08-16 11:42:40 -07003#include <device/device.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -07004#include <device/pci.h>
5#include <fsp/api.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -07006#include <fsp/util.h>
Subrata Banik98376b82018-05-22 16:18:16 +05307#include <intelblocks/acpi.h>
Kyösti Mälkki32d47eb2019-09-28 00:00:30 +03008#include <intelblocks/cfg.h>
Michael Niewöhner8913b782020-12-11 22:13:44 +01009#include <intelblocks/gpio.h>
Subrata Banik819b1432018-09-28 19:56:54 +053010#include <intelblocks/itss.h>
Nico Huber9ea70c02019-10-12 15:16:33 +020011#include <intelblocks/pcie_rp.h>
Duncan Laurie2410cd92018-03-26 02:25:07 -070012#include <intelblocks/xdci.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -070013#include <romstage_handoff.h>
Abhay kumarfcf88202017-09-20 15:17:42 -070014#include <soc/intel/common/vbt.h>
Subrata Banik73b1bd72019-11-28 13:56:24 +053015#include <soc/gpio.h>
Pratik Prajapati9027e1b2017-08-23 17:37:43 -070016#include <soc/pci_devs.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -070017#include <soc/ramstage.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -070018
Elyes HAOUASc3385072019-03-21 15:38:06 +010019#include "chip.h"
20
Nico Huber9ea70c02019-10-12 15:16:33 +020021static const struct pcie_rp_group pch_lp_rp_groups[] = {
22 { .slot = PCH_DEV_SLOT_PCIE, .count = 8 },
23 { .slot = PCH_DEV_SLOT_PCIE_1, .count = 8 },
24 { 0 }
25};
26
27static const struct pcie_rp_group pch_h_rp_groups[] = {
28 { .slot = PCH_DEV_SLOT_PCIE, .count = 8 },
29 { .slot = PCH_DEV_SLOT_PCIE_1, .count = 8 },
30 { .slot = PCH_DEV_SLOT_PCIE_2, .count = 8 },
31 { 0 }
32};
33
Julius Wernercd49cce2019-03-05 16:53:33 -080034#if CONFIG(HAVE_ACPI_TABLES)
Subrata Banik98376b82018-05-22 16:18:16 +053035const char *soc_acpi_name(const struct device *dev)
Lijian Zhao2b074d92017-08-17 14:25:24 -070036{
37 if (dev->path.type == DEVICE_PATH_DOMAIN)
38 return "PCI0";
39
Duncan Laurie1e64d232018-12-01 17:00:23 -080040 if (dev->path.type == DEVICE_PATH_USB) {
41 switch (dev->path.usb.port_type) {
42 case 0:
43 /* Root Hub */
44 return "RHUB";
45 case 2:
46 /* USB2 ports */
47 switch (dev->path.usb.port_id) {
48 case 0: return "HS01";
49 case 1: return "HS02";
50 case 2: return "HS03";
51 case 3: return "HS04";
52 case 4: return "HS05";
53 case 5: return "HS06";
54 case 6: return "HS07";
55 case 7: return "HS08";
56 case 8: return "HS09";
57 case 9: return "HS10";
58 case 10: return "HS11";
59 case 11: return "HS12";
60 }
61 break;
62 case 3:
63 /* USB3 ports */
64 switch (dev->path.usb.port_id) {
65 case 0: return "SS01";
66 case 1: return "SS02";
67 case 2: return "SS03";
68 case 3: return "SS04";
69 case 4: return "SS05";
70 case 5: return "SS06";
71 }
72 break;
73 }
74 return NULL;
75 }
76
Lijian Zhao2b074d92017-08-17 14:25:24 -070077 if (dev->path.type != DEVICE_PATH_PCI)
78 return NULL;
79
80 switch (dev->path.pci.devfn) {
81 case SA_DEVFN_ROOT: return "MCHC";
82 case SA_DEVFN_IGD: return "GFX0";
83 case PCH_DEVFN_ISH: return "ISHB";
84 case PCH_DEVFN_XHCI: return "XHCI";
85 case PCH_DEVFN_USBOTG: return "XDCI";
86 case PCH_DEVFN_THERMAL: return "THRM";
87 case PCH_DEVFN_I2C0: return "I2C0";
88 case PCH_DEVFN_I2C1: return "I2C1";
89 case PCH_DEVFN_I2C2: return "I2C2";
90 case PCH_DEVFN_I2C3: return "I2C3";
91 case PCH_DEVFN_CSE: return "CSE1";
92 case PCH_DEVFN_CSE_2: return "CSE2";
93 case PCH_DEVFN_CSE_IDER: return "CSED";
94 case PCH_DEVFN_CSE_KT: return "CSKT";
95 case PCH_DEVFN_CSE_3: return "CSE3";
96 case PCH_DEVFN_SATA: return "SATA";
97 case PCH_DEVFN_UART2: return "UAR2";
98 case PCH_DEVFN_I2C4: return "I2C4";
99 case PCH_DEVFN_I2C5: return "I2C5";
100 case PCH_DEVFN_PCIE1: return "RP01";
101 case PCH_DEVFN_PCIE2: return "RP02";
102 case PCH_DEVFN_PCIE3: return "RP03";
103 case PCH_DEVFN_PCIE4: return "RP04";
104 case PCH_DEVFN_PCIE5: return "RP05";
105 case PCH_DEVFN_PCIE6: return "RP06";
106 case PCH_DEVFN_PCIE7: return "RP07";
107 case PCH_DEVFN_PCIE8: return "RP08";
108 case PCH_DEVFN_PCIE9: return "RP09";
109 case PCH_DEVFN_PCIE10: return "RP10";
110 case PCH_DEVFN_PCIE11: return "RP11";
111 case PCH_DEVFN_PCIE12: return "RP12";
Lijian Zhao580bc412017-10-04 13:43:47 -0700112 case PCH_DEVFN_PCIE13: return "RP13";
113 case PCH_DEVFN_PCIE14: return "RP14";
114 case PCH_DEVFN_PCIE15: return "RP15";
115 case PCH_DEVFN_PCIE16: return "RP16";
praveen hodagatta praneshe26c4a42018-09-20 03:49:45 +0800116 case PCH_DEVFN_PCIE17: return "RP17";
117 case PCH_DEVFN_PCIE18: return "RP18";
118 case PCH_DEVFN_PCIE19: return "RP19";
119 case PCH_DEVFN_PCIE20: return "RP20";
120 case PCH_DEVFN_PCIE21: return "RP21";
121 case PCH_DEVFN_PCIE22: return "RP22";
122 case PCH_DEVFN_PCIE23: return "RP23";
123 case PCH_DEVFN_PCIE24: return "RP24";
Lijian Zhao2b074d92017-08-17 14:25:24 -0700124 case PCH_DEVFN_UART0: return "UAR0";
125 case PCH_DEVFN_UART1: return "UAR1";
126 case PCH_DEVFN_GSPI0: return "SPI0";
127 case PCH_DEVFN_GSPI1: return "SPI1";
128 case PCH_DEVFN_GSPI2: return "SPI2";
129 case PCH_DEVFN_EMMC: return "EMMC";
130 case PCH_DEVFN_SDCARD: return "SDXC";
Lijian Zhao2b074d92017-08-17 14:25:24 -0700131 case PCH_DEVFN_P2SB: return "P2SB";
132 case PCH_DEVFN_PMC: return "PMC_";
133 case PCH_DEVFN_HDA: return "HDAS";
134 case PCH_DEVFN_SMBUS: return "SBUS";
135 case PCH_DEVFN_SPI: return "FSPI";
136 case PCH_DEVFN_GBE: return "IGBE";
137 case PCH_DEVFN_TRACEHUB:return "THUB";
138 }
139
140 return NULL;
141}
142#endif
143
Furquan Shaikh86d2afb2019-02-05 13:59:47 -0800144/*
145 * TODO(furquan): Get rid of this workaround once FSP is fixed. Currently, FSP-S
146 * configures GPIOs when it should not and this results in coreboot GPIO
147 * configuration being overwritten. Until FSP is fixed, maintain the reference
148 * of GPIO config table from mainboard and use that to re-configure GPIOs after
149 * FSP-S is done.
150 */
151void cnl_configure_pads(const struct pad_config *cfg, size_t num_pads)
152{
153 static const struct pad_config *g_cfg;
154 static size_t g_num_pads;
155
156 /*
157 * If cfg and num_pads are passed in from mainboard, maintain a
158 * reference to the GPIO table.
159 */
160 if ((cfg == NULL) || (num_pads == 0)) {
161 cfg = g_cfg;
162 num_pads = g_num_pads;
163 } else {
164 g_cfg = cfg;
165 g_num_pads = num_pads;
166 }
167
168 gpio_configure_pads(cfg, num_pads);
169}
170
Lijian Zhao2f764f72017-07-14 11:09:10 -0700171void soc_init_pre_device(void *chip_info)
172{
173 /* Perform silicon specific init. */
174 fsp_silicon_init(romstage_handoff_is_resume());
Subrata Banika8733e32018-01-23 16:40:56 +0530175
176 /* Display FIRMWARE_VERSION_INFO_HOB */
177 fsp_display_fvi_version_hob();
Subrata Banik819b1432018-09-28 19:56:54 +0530178
Furquan Shaikh86d2afb2019-02-05 13:59:47 -0800179 /* TODO(furquan): Get rid of this workaround once FSP is fixed. */
180 cnl_configure_pads(NULL, 0);
Subrata Banik76a8f9e2019-05-15 21:23:18 +0530181
Subrata Banik73b1bd72019-11-28 13:56:24 +0530182 soc_gpio_pm_configuration();
Nico Huber9ea70c02019-10-12 15:16:33 +0200183
184 /* swap enabled PCI ports in device tree if needed */
185 if (CONFIG(SOC_INTEL_CANNONLAKE_PCH_H))
186 pcie_rp_update_devicetree(pch_h_rp_groups);
187 else
188 pcie_rp_update_devicetree(pch_lp_rp_groups);
Lijian Zhao2f764f72017-07-14 11:09:10 -0700189}
190
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700191static struct device_operations pci_domain_ops = {
192 .read_resources = &pci_domain_read_resources,
193 .set_resources = &pci_domain_set_resources,
194 .scan_bus = &pci_domain_scan_bus,
Julius Wernercd49cce2019-03-05 16:53:33 -0800195 #if CONFIG(HAVE_ACPI_TABLES)
Lijian Zhao2b074d92017-08-17 14:25:24 -0700196 .acpi_name = &soc_acpi_name,
197 #endif
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700198};
199
200static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200201 .read_resources = noop_read_resources,
202 .set_resources = noop_set_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200203 .acpi_fill_ssdt = generate_cpu_entries,
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700204};
205
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200206static void soc_enable(struct device *dev)
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700207{
208 /* Set the operations if it is a special bus type */
209 if (dev->path.type == DEVICE_PATH_DOMAIN)
210 dev->ops = &pci_domain_ops;
211 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
212 dev->ops = &cpu_bus_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +0100213 else if (dev->path.type == DEVICE_PATH_GPIO)
214 block_gpio_enable(dev);
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700215}
216
Lijian Zhao2f764f72017-07-14 11:09:10 -0700217struct chip_operations soc_intel_cannonlake_ops = {
218 CHIP_NAME("Intel Cannonlake")
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700219 .enable_dev = &soc_enable,
Lijian Zhao2f764f72017-07-14 11:09:10 -0700220 .init = &soc_init_pre_device,
221};