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