blob: 23e6fffbe86171c56c0b547d78557d4c0ff395f7 [file] [log] [blame]
Lijian Zhao2f764f72017-07-14 11:09:10 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2016-2017 Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <chip.h>
17#include <console/console.h>
Pratik Prajapati201fa8f2017-08-16 11:42:40 -070018#include <device/device.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -070019#include <device/pci.h>
20#include <fsp/api.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -070021#include <fsp/util.h>
22#include <romstage_handoff.h>
Abhay kumarfcf88202017-09-20 15:17:42 -070023#include <soc/intel/common/vbt.h>
Pratik Prajapati9027e1b2017-08-23 17:37:43 -070024#include <soc/pci_devs.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -070025#include <soc/ramstage.h>
26#include <string.h>
27
Lijian Zhao2b074d92017-08-17 14:25:24 -070028#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Aaron Durbinaa090cb2017-09-13 16:01:52 -060029static const char *soc_acpi_name(const struct device *dev)
Lijian Zhao2b074d92017-08-17 14:25:24 -070030{
31 if (dev->path.type == DEVICE_PATH_DOMAIN)
32 return "PCI0";
33
34 if (dev->path.type != DEVICE_PATH_PCI)
35 return NULL;
36
37 switch (dev->path.pci.devfn) {
38 case SA_DEVFN_ROOT: return "MCHC";
39 case SA_DEVFN_IGD: return "GFX0";
40 case PCH_DEVFN_ISH: return "ISHB";
41 case PCH_DEVFN_XHCI: return "XHCI";
42 case PCH_DEVFN_USBOTG: return "XDCI";
43 case PCH_DEVFN_THERMAL: return "THRM";
44 case PCH_DEVFN_I2C0: return "I2C0";
45 case PCH_DEVFN_I2C1: return "I2C1";
46 case PCH_DEVFN_I2C2: return "I2C2";
47 case PCH_DEVFN_I2C3: return "I2C3";
48 case PCH_DEVFN_CSE: return "CSE1";
49 case PCH_DEVFN_CSE_2: return "CSE2";
50 case PCH_DEVFN_CSE_IDER: return "CSED";
51 case PCH_DEVFN_CSE_KT: return "CSKT";
52 case PCH_DEVFN_CSE_3: return "CSE3";
53 case PCH_DEVFN_SATA: return "SATA";
54 case PCH_DEVFN_UART2: return "UAR2";
55 case PCH_DEVFN_I2C4: return "I2C4";
56 case PCH_DEVFN_I2C5: return "I2C5";
57 case PCH_DEVFN_PCIE1: return "RP01";
58 case PCH_DEVFN_PCIE2: return "RP02";
59 case PCH_DEVFN_PCIE3: return "RP03";
60 case PCH_DEVFN_PCIE4: return "RP04";
61 case PCH_DEVFN_PCIE5: return "RP05";
62 case PCH_DEVFN_PCIE6: return "RP06";
63 case PCH_DEVFN_PCIE7: return "RP07";
64 case PCH_DEVFN_PCIE8: return "RP08";
65 case PCH_DEVFN_PCIE9: return "RP09";
66 case PCH_DEVFN_PCIE10: return "RP10";
67 case PCH_DEVFN_PCIE11: return "RP11";
68 case PCH_DEVFN_PCIE12: return "RP12";
Lijian Zhao580bc412017-10-04 13:43:47 -070069 case PCH_DEVFN_PCIE13: return "RP13";
70 case PCH_DEVFN_PCIE14: return "RP14";
71 case PCH_DEVFN_PCIE15: return "RP15";
72 case PCH_DEVFN_PCIE16: return "RP16";
Lijian Zhao2b074d92017-08-17 14:25:24 -070073 case PCH_DEVFN_UART0: return "UAR0";
74 case PCH_DEVFN_UART1: return "UAR1";
75 case PCH_DEVFN_GSPI0: return "SPI0";
76 case PCH_DEVFN_GSPI1: return "SPI1";
77 case PCH_DEVFN_GSPI2: return "SPI2";
78 case PCH_DEVFN_EMMC: return "EMMC";
79 case PCH_DEVFN_SDCARD: return "SDXC";
80 case PCH_DEVFN_LPC: return "LPCB";
81 case PCH_DEVFN_P2SB: return "P2SB";
82 case PCH_DEVFN_PMC: return "PMC_";
83 case PCH_DEVFN_HDA: return "HDAS";
84 case PCH_DEVFN_SMBUS: return "SBUS";
85 case PCH_DEVFN_SPI: return "FSPI";
86 case PCH_DEVFN_GBE: return "IGBE";
87 case PCH_DEVFN_TRACEHUB:return "THUB";
88 }
89
90 return NULL;
91}
92#endif
93
Lijian Zhao08231832017-09-05 18:16:21 -070094static void parse_devicetree(FSP_S_CONFIG *params)
95{
96 struct device *dev = SA_DEV_ROOT;
97 if (!dev) {
98 printk(BIOS_ERR, "Could not find root device\n");
99 return;
100 }
101
102 const config_t *config = dev->chip_info;
103 const int SerialIoDev[] = {
104 PCH_DEVFN_I2C0,
105 PCH_DEVFN_I2C1,
106 PCH_DEVFN_I2C2,
107 PCH_DEVFN_I2C3,
108 PCH_DEVFN_I2C4,
109 PCH_DEVFN_I2C5,
110 PCH_DEVFN_GSPI0,
111 PCH_DEVFN_GSPI1,
112 PCH_DEVFN_GSPI2,
113 PCH_DEVFN_UART0,
114 PCH_DEVFN_UART1,
115 PCH_DEVFN_UART2
116 };
117
118 for (int i = 0; i < ARRAY_SIZE(SerialIoDev); i++) {
119 dev = dev_find_slot(0, SerialIoDev[i]);
120 if (!dev->enabled) {
121 params->SerialIoDevMode[i] = PchSerialIoDisabled;
122 continue;
123 }
124 params->SerialIoDevMode[i] = PchSerialIoPci;
125 if (config->SerialIoDevMode[i] == PchSerialIoAcpi ||
126 config->SerialIoDevMode[i] == PchSerialIoHidden)
127 params->SerialIoDevMode[i] = config->SerialIoDevMode[i];
128 }
129}
130
Lijian Zhao2f764f72017-07-14 11:09:10 -0700131void soc_init_pre_device(void *chip_info)
132{
133 /* Perform silicon specific init. */
134 fsp_silicon_init(romstage_handoff_is_resume());
135}
136
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700137static void pci_domain_set_resources(device_t dev)
138{
139 assign_resources(dev->link_list);
140}
141
142static struct device_operations pci_domain_ops = {
143 .read_resources = &pci_domain_read_resources,
144 .set_resources = &pci_domain_set_resources,
145 .scan_bus = &pci_domain_scan_bus,
146 .ops_pci_bus = &pci_bus_default_ops,
Lijian Zhao2b074d92017-08-17 14:25:24 -0700147 #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
148 .acpi_name = &soc_acpi_name,
149 #endif
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700150};
151
152static struct device_operations cpu_bus_ops = {
153 .read_resources = DEVICE_NOOP,
154 .set_resources = DEVICE_NOOP,
155 .enable_resources = DEVICE_NOOP,
156 .init = DEVICE_NOOP,
157};
158
159static void soc_enable(device_t dev)
160{
161 /* Set the operations if it is a special bus type */
162 if (dev->path.type == DEVICE_PATH_DOMAIN)
163 dev->ops = &pci_domain_ops;
164 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
165 dev->ops = &cpu_bus_ops;
166}
167
Lijian Zhao2f764f72017-07-14 11:09:10 -0700168struct chip_operations soc_intel_cannonlake_ops = {
169 CHIP_NAME("Intel Cannonlake")
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700170 .enable_dev = &soc_enable,
Lijian Zhao2f764f72017-07-14 11:09:10 -0700171 .init = &soc_init_pre_device,
172};
173
174/* UPD parameters to be initialized before SiliconInit */
175void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd)
176{
177 int i;
178 FSP_S_CONFIG *params = &supd->FspsConfig;
Pratik Prajapati9027e1b2017-08-23 17:37:43 -0700179 const struct device *dev = SA_DEV_ROOT;
Lijian Zhao580bc412017-10-04 13:43:47 -0700180 config_t *config = dev->chip_info;
Lijian Zhao2f764f72017-07-14 11:09:10 -0700181
Lijian Zhao08231832017-09-05 18:16:21 -0700182 /* Parse device tree and enable/disable devices */
183 parse_devicetree(params);
184
Abhay kumarfcf88202017-09-20 15:17:42 -0700185 /* Load VBT before devicetree-specific config. */
Patrick Georgi22579592017-10-06 17:36:09 +0200186 params->GraphicsConfigPtr = (uintptr_t)vbt_get();
Abhay kumarfcf88202017-09-20 15:17:42 -0700187
Lijian Zhao2f764f72017-07-14 11:09:10 -0700188 /* Set USB OC pin to 0 first */
189 for (i = 0; i < ARRAY_SIZE(params->Usb2OverCurrentPin); i++) {
190 params->Usb2OverCurrentPin[i] = 0;
191 }
192
193 for (i = 0; i < ARRAY_SIZE(params->Usb3OverCurrentPin); i++) {
194 params->Usb3OverCurrentPin[i] = 0;
195 }
196
197 mainboard_silicon_init_params(params);
Pratik Prajapati9027e1b2017-08-23 17:37:43 -0700198
199 /* SATA */
200 params->SataEnable = config->SataEnable;
201 params->SataMode = config->SataMode;
202 params->SataSalpSupport = config->SataSalpSupport;
203 memcpy(params->SataPortsEnable, config->SataPortsEnable,
204 sizeof(params->SataPortsEnable));
205 memcpy(params->SataPortsDevSlp, config->SataPortsDevSlp,
206 sizeof(params->SataPortsDevSlp));
207
208 /* Lan */
209 params->PchLanEnable = config->PchLanEnable;
210
211 /* Audio */
212 params->PchHdaDspEnable = config->PchHdaDspEnable;
213 params->PchHdaAudioLinkHda = config->PchHdaAudioLinkHda;
214
215 /* USB */
216 for (i = 0; i < ARRAY_SIZE(config->usb2_ports); i++) {
217 params->PortUsb20Enable[i] =
218 config->usb2_ports[i].enable;
219 params->Usb2OverCurrentPin[i] =
220 config->usb2_ports[i].ocpin;
221 params->Usb2AfePetxiset[i] =
222 config->usb2_ports[i].pre_emp_bias;
223 params->Usb2AfeTxiset[i] =
224 config->usb2_ports[i].tx_bias;
225 params->Usb2AfePredeemp[i] =
226 config->usb2_ports[i].tx_emp_enable;
227 params->Usb2AfePehalfbit[i] =
228 config->usb2_ports[i].pre_emp_bit;
229 }
230
231 for (i = 0; i < ARRAY_SIZE(config->usb3_ports); i++) {
232 params->PortUsb30Enable[i] = config->usb3_ports[i].enable;
233 params->Usb3OverCurrentPin[i] = config->usb3_ports[i].ocpin;
234 if (config->usb3_ports[i].tx_de_emp) {
235 params->Usb3HsioTxDeEmphEnable[i] = 1;
236 params->Usb3HsioTxDeEmph[i] =
237 config->usb3_ports[i].tx_de_emp;
238 }
239 if (config->usb3_ports[i].tx_downscale_amp) {
240 params->Usb3HsioTxDownscaleAmpEnable[i] = 1;
241 params->Usb3HsioTxDownscaleAmp[i] =
242 config->usb3_ports[i].tx_downscale_amp;
243 }
244 }
245
246 params->XdciEnable = config->XdciEnable;
247
Lijian Zhao580bc412017-10-04 13:43:47 -0700248 /* PCI Express */
249 for (i = 0; i < ARRAY_SIZE(config->PcieClkSrcUsage); i++) {
250 if (config->PcieClkSrcUsage[i] == 0)
251 config->PcieClkSrcUsage[i] = PCIE_CLK_NOTUSED;
252 }
253 memcpy(params->PcieClkSrcUsage, config->PcieClkSrcUsage,
254 sizeof(config->PcieClkSrcUsage));
255 memcpy(params->PcieClkSrcClkReq, config->PcieClkSrcClkReq,
256 sizeof(config->PcieClkSrcClkReq));
257
Pratik Prajapati9027e1b2017-08-23 17:37:43 -0700258 /* eMMC and SD */
259 params->ScsEmmcEnabled = config->ScsEmmcEnabled;
260 params->ScsEmmcHs400Enabled = config->ScsEmmcHs400Enabled;
261 params->ScsSdCardEnabled = config->ScsSdCardEnabled;
262 params->ScsUfsEnabled = config->ScsUfsEnabled;
263
264 params->Heci3Enabled = config->Heci3Enabled;
265 params->Device4Enable = config->Device4Enable;
266 params->SkipMpInit = config->FspSkipMpInit;
267
268 /* VrConfig Settings for 5 domains
269 * 0 = System Agent, 1 = IA Core, 2 = Ring,
270 * 3 = GT unsliced, 4 = GT sliced */
271 for (i = 0; i < ARRAY_SIZE(config->domain_vr_config); i++)
272 fill_vr_domain_config(params, i, &config->domain_vr_config[i]);
Lijian Zhao2f764f72017-07-14 11:09:10 -0700273}
274
275/* Mainboard GPIO Configuration */
276__attribute__((weak)) void mainboard_silicon_init_params(FSP_S_CONFIG *params)
277{
278 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
279}