blob: 61c7ac196e3e95c46aa54fbc4ae0fa0f4e9a65c2 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin239c2e82012-12-19 11:31:17 -06002
Aaron Durbin239c2e82012-12-19 11:31:17 -06003#include <console/console.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Duncan Laurie8d783b82013-05-14 11:16:34 -07005#include <device/device.h>
Aaron Durbin239c2e82012-12-19 11:31:17 -06006#include <device/pci_def.h>
Kyösti Mälkkif555a582020-01-06 19:41:42 +02007#include <device/smbus_host.h>
Elyes HAOUAS27ce8e32020-08-12 09:50:48 +02008#include <southbridge/intel/common/pmbase.h>
Elyes Haouasbd5fe982024-04-09 17:34:33 +02009
Aaron Durbin239c2e82012-12-19 11:31:17 -060010#include "pch.h"
Duncan Laurie8d783b82013-05-14 11:16:34 -070011#include "chip.h"
Aaron Durbin239c2e82012-12-19 11:31:17 -060012
Julius Wernercd49cce2019-03-05 16:53:33 -080013#if CONFIG(INTEL_LYNXPOINT_LP)
Aaron Durbin239c2e82012-12-19 11:31:17 -060014#include "lp_gpio.h"
15#else
Elyes HAOUAS65bb5432018-07-03 14:59:50 +020016#include <southbridge/intel/common/gpio.h>
Aaron Durbin239c2e82012-12-19 11:31:17 -060017#endif
18
Angel Pons31739932020-07-03 23:14:40 +020019enum pch_platform_type get_pch_platform_type(void)
20{
21 const u16 did = pci_read_config16(PCH_LPC_DEV, PCI_DEVICE_ID);
22
23 /* Check if this is a LPT-LP or WPT-LP device ID */
24 if ((did & 0xff00) == 0x9c00)
25 return PCH_TYPE_ULT;
26
27 /* Non-LP laptop SKUs have an odd device ID (least significant bit is one) */
28 if (did & 1)
29 return PCH_TYPE_MOBILE;
30
31 /* Desktop and Server SKUs have an even device ID */
32 return PCH_TYPE_DESKTOP;
33}
34
Aaron Durbin239c2e82012-12-19 11:31:17 -060035static void pch_enable_bars(void)
36{
Angel Pons6e732d32021-01-28 13:56:18 +010037 pci_write_config32(PCH_LPC_DEV, RCBA, CONFIG_FIXED_RCBA_MMIO_BASE | 1);
Aaron Durbin239c2e82012-12-19 11:31:17 -060038
39 pci_write_config32(PCH_LPC_DEV, PMBASE, DEFAULT_PMBASE | 1);
40 /* Enable ACPI BAR */
Angel Ponsf4711712020-11-04 00:38:28 +010041 pci_write_config8(PCH_LPC_DEV, ACPI_CNTL, ACPI_EN);
Aaron Durbin239c2e82012-12-19 11:31:17 -060042
Angel Pons84fa2242020-10-24 11:53:47 +020043 pci_write_config32(PCH_LPC_DEV, GPIO_BASE, DEFAULT_GPIOBASE | 1);
Aaron Durbin239c2e82012-12-19 11:31:17 -060044
45 /* Enable GPIO functionality. */
46 pci_write_config8(PCH_LPC_DEV, GPIO_CNTL, 0x10);
47}
48
49static void pch_generic_setup(void)
50{
Aaron Durbin239c2e82012-12-19 11:31:17 -060051 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
52 RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
Elyes HAOUAS27ce8e32020-08-12 09:50:48 +020053 write_pmbase16(0x60 | 0x08, (1 << 11)); /* halt timer */
Aaron Durbin239c2e82012-12-19 11:31:17 -060054 printk(BIOS_DEBUG, " done.\n");
Aaron Durbin239c2e82012-12-19 11:31:17 -060055}
56
Stefan Reinauer779e1782013-10-07 16:29:54 -070057void pch_enable_lpc(void)
Aaron Durbin239c2e82012-12-19 11:31:17 -060058{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030059 const struct device *dev = pcidev_on_root(0x1f, 0);
Duncan Laurie8d783b82013-05-14 11:16:34 -070060 const struct southbridge_intel_lynxpoint_config *config = NULL;
Aaron Durbin239c2e82012-12-19 11:31:17 -060061
62 /* Set COM1/COM2 decode range */
Duncan Laurie8d783b82013-05-14 11:16:34 -070063 pci_write_config16(PCH_LPC_DEV, LPC_IO_DEC, 0x0010);
Aaron Durbin239c2e82012-12-19 11:31:17 -060064
Duncan Laurie7a3fd4d2013-03-07 14:00:43 -080065 /* Enable SuperIO + MC + COM1 + PS/2 Keyboard/Mouse */
Duncan Lauriea103d072013-05-01 11:12:53 -070066 u16 lpc_config = CNF1_LPC_EN | CNF2_LPC_EN | GAMEL_LPC_EN |
Duncan Laurie7a3fd4d2013-03-07 14:00:43 -080067 COMA_LPC_EN | KBC_LPC_EN | MC_LPC_EN;
Duncan Laurie8d783b82013-05-14 11:16:34 -070068 pci_write_config16(PCH_LPC_DEV, LPC_EN, lpc_config);
69
70 /* Set up generic decode ranges */
71 if (!dev)
72 return;
73 if (dev->chip_info)
74 config = dev->chip_info;
75 if (!config)
76 return;
77
78 pci_write_config32(PCH_LPC_DEV, LPC_GEN1_DEC, config->gen1_dec);
79 pci_write_config32(PCH_LPC_DEV, LPC_GEN2_DEC, config->gen2_dec);
80 pci_write_config32(PCH_LPC_DEV, LPC_GEN3_DEC, config->gen3_dec);
81 pci_write_config32(PCH_LPC_DEV, LPC_GEN4_DEC, config->gen4_dec);
Aaron Durbin239c2e82012-12-19 11:31:17 -060082}
83
Tristan Corrick655ef612018-10-31 02:26:19 +130084void __weak mainboard_config_superio(void)
85{
86}
87
Angel Pons30931f52021-03-12 13:06:45 +010088void early_pch_init(void)
Aaron Durbin239c2e82012-12-19 11:31:17 -060089{
Aaron Durbin239c2e82012-12-19 11:31:17 -060090 pch_enable_bars();
91
Julius Wernercd49cce2019-03-05 16:53:33 -080092#if CONFIG(INTEL_LYNXPOINT_LP)
Angel Pons88f94a92021-03-19 15:13:46 +010093 setup_pch_lp_gpios(mainboard_lp_gpio_map);
Aaron Durbin239c2e82012-12-19 11:31:17 -060094#else
Angel Pons03f0e432020-07-03 13:51:15 +020095 setup_pch_gpios(&mainboard_gpio_map);
Aaron Durbin239c2e82012-12-19 11:31:17 -060096#endif
Aaron Durbin239c2e82012-12-19 11:31:17 -060097 pch_generic_setup();
98
99 /* Enable SMBus for reading SPDs. */
100 enable_smbus();
101
Angel Pons55d148c2020-07-03 12:41:48 +0200102 /* Enable IOAPIC */
103 RCBA16(OIC) = 0x0100;
104
105 /* PCH BWG says to read back the IOAPIC enable register */
Angel Pons8cb83742020-10-17 18:28:29 +0200106 (void)RCBA16(OIC);
Duncan Laurie18af4d22012-12-19 13:17:06 -0800107
108 /* Mainboard RCBA settings */
Angel Pons6e1c4712020-07-03 13:05:10 +0200109 mainboard_config_rcba();
Aaron Durbin239c2e82012-12-19 11:31:17 -0600110
Angel Ponsb4f98332020-07-03 12:49:05 +0200111 RCBA32_OR(FD, PCH_DISABLE_ALWAYS);
112
Angel Pons2cdf8bd2020-11-04 17:47:45 +0100113 RCBA32(0x2088) = 0x00109000;
114
115 RCBA32_OR(0x20ac, 1 << 30);
116
117 if (!pch_is_lp()) {
118 RCBA32_AND_OR(0x2340, ~(0xff << 0), 0x1b << 0);
119 RCBA32_AND_OR(0x2340, ~(0xff << 16), 0x3a << 16);
120
121 RCBA32(0x2324) = 0x00854c74;
122 }
Aaron Durbin239c2e82012-12-19 11:31:17 -0600123}