Angel Pons | f5627e8 | 2020-04-05 15:46:52 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 2 | |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 3 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 4 | #include <device/mmio.h> |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 5 | #include <device/device.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 6 | #include <device/pci_ops.h> |
Srinidhi N Kaushik | 876b422 | 2020-12-02 17:14:32 -0800 | [diff] [blame] | 7 | #include <intelblocks/dmi.h> |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 8 | #include <intelblocks/fast_spi.h> |
Furquan Shaikh | 1876f3a | 2017-12-07 18:39:34 -0800 | [diff] [blame] | 9 | #include <intelblocks/gspi.h> |
Caveh Jalali | 1428f01 | 2018-01-23 22:15:24 -0800 | [diff] [blame] | 10 | #include <intelblocks/lpc_lib.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 11 | #include <intelblocks/p2sb.h> |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 12 | #include <intelblocks/pcr.h> |
Lijian Zhao | 031020e | 2017-12-15 12:58:07 -0800 | [diff] [blame] | 13 | #include <intelblocks/pmclib.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 14 | #include <intelblocks/rtc.h> |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 15 | #include <soc/bootblock.h> |
Subrata Banik | 73b1bd7 | 2019-11-28 13:56:24 +0530 | [diff] [blame] | 16 | #include <soc/gpio.h> |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 17 | #include <soc/iomap.h> |
| 18 | #include <soc/lpc.h> |
| 19 | #include <soc/p2sb.h> |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 20 | #include <soc/pch.h> |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 21 | #include <soc/pci_devs.h> |
| 22 | #include <soc/pcr_ids.h> |
Lijian Zhao | b3dfcb8 | 2017-08-16 22:18:52 -0700 | [diff] [blame] | 23 | #include <soc/pm.h> |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 24 | |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 25 | #define PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_LP 0x1400 |
| 26 | #define PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_H 0x0980 |
| 27 | |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 28 | #define PCR_PSFX_TO_SHDW_BAR0 0 |
| 29 | #define PCR_PSFX_TO_SHDW_BAR1 0x4 |
| 30 | #define PCR_PSFX_TO_SHDW_BAR2 0x8 |
| 31 | #define PCR_PSFX_TO_SHDW_BAR3 0xC |
| 32 | #define PCR_PSFX_TO_SHDW_BAR4 0x10 |
| 33 | #define PCR_PSFX_TO_SHDW_PCIEN_IOEN 0x01 |
| 34 | #define PCR_PSFX_T0_SHDW_PCIEN 0x1C |
| 35 | |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 36 | #define PCR_DMI_ACPIBA 0x27B4 |
| 37 | #define PCR_DMI_ACPIBDID 0x27B8 |
| 38 | #define PCR_DMI_PMBASEA 0x27AC |
| 39 | #define PCR_DMI_PMBASEC 0x27B0 |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 40 | |
| 41 | #define PCR_DMI_LPCIOD 0x2770 |
| 42 | #define PCR_DMI_LPCIOE 0x2774 |
| 43 | |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 44 | static uint32_t get_pmc_reg_base(void) |
| 45 | { |
| 46 | uint8_t pch_series; |
| 47 | |
| 48 | pch_series = get_pch_series(); |
| 49 | |
| 50 | if (pch_series == PCH_H) |
| 51 | return PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_H; |
| 52 | else if (pch_series == PCH_LP) |
| 53 | return PCR_PSF3_TO_SHDW_PMC_REG_BASE_CNP_LP; |
| 54 | else |
| 55 | return 0; |
| 56 | } |
| 57 | |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 58 | static void soc_config_pwrmbase(void) |
| 59 | { |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 60 | /* |
| 61 | * Assign Resources to PWRMBASE |
Subrata Banik | 45caf97 | 2020-08-05 13:30:30 +0530 | [diff] [blame] | 62 | * Clear BIT 1-2 Command Register |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 63 | */ |
Subrata Banik | 45caf97 | 2020-08-05 13:30:30 +0530 | [diff] [blame] | 64 | pci_and_config16(PCH_DEV_PMC, PCI_COMMAND, ~(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER)); |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 65 | |
| 66 | /* Program PWRM Base */ |
| 67 | pci_write_config32(PCH_DEV_PMC, PWRMBASE, PCH_PWRM_BASE_ADDRESS); |
| 68 | |
| 69 | /* Enable Bus Master and MMIO Space */ |
Subrata Banik | 45caf97 | 2020-08-05 13:30:30 +0530 | [diff] [blame] | 70 | pci_or_config16(PCH_DEV_PMC, PCI_COMMAND, (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER)); |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 71 | |
| 72 | /* Enable PWRM in PMC */ |
Subrata Banik | 45caf97 | 2020-08-05 13:30:30 +0530 | [diff] [blame] | 73 | setbits32((void *) PCH_PWRM_BASE_ADDRESS + ACTL, PWRM_EN); |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void bootblock_pch_early_init(void) |
| 77 | { |
Furquan Shaikh | d149bfa | 2020-11-22 20:00:28 -0800 | [diff] [blame] | 78 | /* |
| 79 | * Perform P2SB configuration before any another controller initialization as the |
| 80 | * controller might want to perform PCR settings. |
| 81 | */ |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 82 | p2sb_enable_bar(); |
| 83 | p2sb_configure_hpet(); |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 84 | |
Furquan Shaikh | d149bfa | 2020-11-22 20:00:28 -0800 | [diff] [blame] | 85 | fast_spi_early_init(SPI_BASE_ADDRESS); |
| 86 | gspi_early_bar_init(); |
| 87 | |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 88 | /* |
| 89 | * Enabling PWRM Base for accessing |
| 90 | * Global Reset Cause Register. |
| 91 | */ |
| 92 | soc_config_pwrmbase(); |
| 93 | } |
| 94 | |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 95 | static void soc_config_acpibase(void) |
| 96 | { |
| 97 | uint32_t pmc_reg_value; |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 98 | uint32_t pmc_base_reg; |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 99 | |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 100 | pmc_base_reg = get_pmc_reg_base(); |
| 101 | if (!pmc_base_reg) |
Keith Short | 15588b0 | 2019-05-09 11:40:34 -0600 | [diff] [blame] | 102 | die_with_post_code(POST_HW_INIT_FAILURE, |
| 103 | "Invalid PMC base address\n"); |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 104 | |
| 105 | pmc_reg_value = pcr_read32(PID_PSF3, pmc_base_reg + |
| 106 | PCR_PSFX_TO_SHDW_BAR4); |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 107 | |
| 108 | if (pmc_reg_value != 0xFFFFFFFF) |
| 109 | { |
| 110 | /* Disable Io Space before changing the address */ |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 111 | pcr_rmw32(PID_PSF3, pmc_base_reg + |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 112 | PCR_PSFX_T0_SHDW_PCIEN, |
| 113 | ~PCR_PSFX_TO_SHDW_PCIEN_IOEN, 0); |
| 114 | /* Program ABASE in PSF3 PMC space BAR4*/ |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 115 | pcr_write32(PID_PSF3, pmc_base_reg + |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 116 | PCR_PSFX_TO_SHDW_BAR4, |
| 117 | ACPI_BASE_ADDRESS); |
| 118 | /* Enable IO Space */ |
Maulik V Vaghela | 9b08a18 | 2018-07-17 21:52:27 +0530 | [diff] [blame] | 119 | pcr_rmw32(PID_PSF3, pmc_base_reg + |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 120 | PCR_PSFX_T0_SHDW_PCIEN, |
| 121 | ~0, PCR_PSFX_TO_SHDW_PCIEN_IOEN); |
| 122 | } |
| 123 | } |
| 124 | |
Duncan Laurie | 2aef7f3 | 2018-11-17 12:13:59 -0700 | [diff] [blame] | 125 | static int pch_check_decode_enable(void) |
| 126 | { |
| 127 | uint32_t dmi_control; |
| 128 | |
| 129 | /* |
| 130 | * This cycle decoding is only allowed to set when |
| 131 | * DMICTL.SRLOCK is 0. |
| 132 | */ |
| 133 | dmi_control = pcr_read32(PID_DMI, PCR_DMI_DMICTL); |
| 134 | if (dmi_control & PCR_DMI_DMICTL_SRLOCK) |
| 135 | return -1; |
| 136 | return 0; |
| 137 | } |
| 138 | |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 139 | void pch_early_iorange_init(void) |
| 140 | { |
Christian Walter | f4aa501 | 2019-08-13 15:09:10 +0200 | [diff] [blame] | 141 | uint16_t io_enables = LPC_IOE_EC_4E_4F | LPC_IOE_SUPERIO_2E_2F | LPC_IOE_KBC_60_64 | |
Duncan Laurie | 2aef7f3 | 2018-11-17 12:13:59 -0700 | [diff] [blame] | 142 | LPC_IOE_EC_62_66 | LPC_IOE_LGE_200; |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 143 | |
| 144 | /* IO Decode Range */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 145 | if (CONFIG(DRIVERS_UART_8250IO)) |
Duncan Laurie | 2aef7f3 | 2018-11-17 12:13:59 -0700 | [diff] [blame] | 146 | lpc_io_setup_comm_a_b(); |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 147 | |
| 148 | /* IO Decode Enable */ |
Duncan Laurie | 2aef7f3 | 2018-11-17 12:13:59 -0700 | [diff] [blame] | 149 | if (pch_check_decode_enable() == 0) { |
| 150 | io_enables = lpc_enable_fixed_io_ranges(io_enables); |
| 151 | /* |
Wim Vervoorn | ee38b99 | 2020-02-03 15:25:49 +0100 | [diff] [blame] | 152 | * Set LPC IO Enables PCR[DMI] + 2774h [15:0] to the same |
| 153 | * value programmed in LPC PCI offset 82h. |
Duncan Laurie | 2aef7f3 | 2018-11-17 12:13:59 -0700 | [diff] [blame] | 154 | */ |
| 155 | pcr_write16(PID_DMI, PCR_DMI_LPCIOE, io_enables); |
Wim Vervoorn | 8440018 | 2020-02-03 15:20:46 +0100 | [diff] [blame] | 156 | /* |
| 157 | * Set LPC IO Decode Ranges PCR[DMI] + 2770h [15:0] to the same |
| 158 | * value programmed in LPC PCI offset 80h. |
| 159 | */ |
| 160 | pcr_write16(PID_DMI, PCR_DMI_LPCIOD, lpc_get_fixed_io_decode()); |
Duncan Laurie | 2aef7f3 | 2018-11-17 12:13:59 -0700 | [diff] [blame] | 161 | } |
Caveh Jalali | 1428f01 | 2018-01-23 22:15:24 -0800 | [diff] [blame] | 162 | |
| 163 | /* Program generic IO Decode Range */ |
| 164 | pch_enable_lpc(); |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Usha P | 33ff4cc | 2019-11-28 10:05:45 +0530 | [diff] [blame] | 167 | void bootblock_pch_init(void) |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 168 | { |
| 169 | /* |
| 170 | * Enabling ABASE for accessing PM1_STS, PM1_EN, PM1_CNT, |
| 171 | * GPE0_STS, GPE0_EN registers. |
| 172 | */ |
| 173 | soc_config_acpibase(); |
| 174 | |
Lijian Zhao | 031020e | 2017-12-15 12:58:07 -0800 | [diff] [blame] | 175 | /* Set up GPE configuration */ |
| 176 | pmc_gpe_init(); |
| 177 | |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 178 | enable_rtc_upper_bank(); |
Subrata Banik | 73b1bd7 | 2019-11-28 13:56:24 +0530 | [diff] [blame] | 179 | |
| 180 | /* GPIO community PM configuration */ |
| 181 | soc_gpio_pm_configuration(); |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 182 | } |