Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc. |
| 5 | * Copyright (C) 2017 Intel Corporation. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <device/device.h> |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 18 | #include <intelblocks/fast_spi.h> |
Furquan Shaikh | 1876f3a | 2017-12-07 18:39:34 -0800 | [diff] [blame] | 19 | #include <intelblocks/gspi.h> |
Caveh Jalali | 1428f01 | 2018-01-23 22:15:24 -0800 | [diff] [blame] | 20 | #include <intelblocks/lpc_lib.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 21 | #include <intelblocks/p2sb.h> |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 22 | #include <intelblocks/pcr.h> |
Lijian Zhao | 031020e | 2017-12-15 12:58:07 -0800 | [diff] [blame] | 23 | #include <intelblocks/pmclib.h> |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 24 | #include <intelblocks/rtc.h> |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 25 | #include <intelblocks/smbus.h> |
| 26 | #include <soc/bootblock.h> |
| 27 | #include <soc/iomap.h> |
| 28 | #include <soc/lpc.h> |
| 29 | #include <soc/p2sb.h> |
| 30 | #include <soc/pci_devs.h> |
| 31 | #include <soc/pcr_ids.h> |
Lijian Zhao | b3dfcb8 | 2017-08-16 22:18:52 -0700 | [diff] [blame] | 32 | #include <soc/pm.h> |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 33 | #include <soc/smbus.h> |
| 34 | |
| 35 | #define PCR_PSF3_TO_SHDW_PMC_REG_BASE 0x1400 |
| 36 | #define PCR_PSFX_TO_SHDW_BAR0 0 |
| 37 | #define PCR_PSFX_TO_SHDW_BAR1 0x4 |
| 38 | #define PCR_PSFX_TO_SHDW_BAR2 0x8 |
| 39 | #define PCR_PSFX_TO_SHDW_BAR3 0xC |
| 40 | #define PCR_PSFX_TO_SHDW_BAR4 0x10 |
| 41 | #define PCR_PSFX_TO_SHDW_PCIEN_IOEN 0x01 |
| 42 | #define PCR_PSFX_T0_SHDW_PCIEN 0x1C |
| 43 | |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 44 | #define PCR_DMI_ACPIBA 0x27B4 |
| 45 | #define PCR_DMI_ACPIBDID 0x27B8 |
| 46 | #define PCR_DMI_PMBASEA 0x27AC |
| 47 | #define PCR_DMI_PMBASEC 0x27B0 |
| 48 | #define PCR_DMI_TCOBASE 0x2778 |
| 49 | #define TCOEN (1 << 1) /* Enable TCO I/O range decode. */ |
| 50 | |
| 51 | #define PCR_DMI_LPCIOD 0x2770 |
| 52 | #define PCR_DMI_LPCIOE 0x2774 |
| 53 | |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 54 | static void soc_config_pwrmbase(void) |
| 55 | { |
| 56 | uint32_t reg32; |
| 57 | |
| 58 | /* Assign Resources to PWRMBASE */ |
| 59 | /* Clear BIT 1-2 Command Register */ |
| 60 | reg32 = pci_read_config32(PCH_DEV_PMC, PCI_COMMAND); |
| 61 | reg32 &= ~(PCI_COMMAND_MEMORY); |
| 62 | pci_write_config32(PCH_DEV_PMC, PCI_COMMAND, reg32); |
| 63 | |
| 64 | /* Program PWRM Base */ |
| 65 | pci_write_config32(PCH_DEV_PMC, PWRMBASE, PCH_PWRM_BASE_ADDRESS); |
| 66 | |
| 67 | /* Enable Bus Master and MMIO Space */ |
| 68 | reg32 = pci_read_config32(PCH_DEV_PMC, PCI_COMMAND); |
| 69 | reg32 |= PCI_COMMAND_MEMORY; |
| 70 | pci_write_config32(PCH_DEV_PMC, PCI_COMMAND, reg32); |
| 71 | |
| 72 | /* Enable PWRM in PMC */ |
| 73 | reg32 = read32((void *)(PCH_PWRM_BASE_ADDRESS + ACTL)); |
| 74 | write32((void *)(PCH_PWRM_BASE_ADDRESS + ACTL), reg32 | PWRM_EN); |
| 75 | } |
| 76 | |
| 77 | void bootblock_pch_early_init(void) |
| 78 | { |
| 79 | fast_spi_early_init(SPI_BASE_ADDRESS); |
Furquan Shaikh | 1876f3a | 2017-12-07 18:39:34 -0800 | [diff] [blame] | 80 | gspi_early_bar_init(); |
Subrata Banik | 7837c20 | 2018-05-07 17:13:40 +0530 | [diff] [blame] | 81 | p2sb_enable_bar(); |
| 82 | p2sb_configure_hpet(); |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame^] | 83 | |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 84 | /* |
| 85 | * Enabling PWRM Base for accessing |
| 86 | * Global Reset Cause Register. |
| 87 | */ |
| 88 | soc_config_pwrmbase(); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | static void soc_config_acpibase(void) |
| 93 | { |
| 94 | uint32_t pmc_reg_value; |
| 95 | |
| 96 | pmc_reg_value = pcr_read32(PID_PSF3, PCR_PSF3_TO_SHDW_PMC_REG_BASE + |
| 97 | PCR_PSFX_TO_SHDW_BAR4); |
| 98 | |
| 99 | if (pmc_reg_value != 0xFFFFFFFF) |
| 100 | { |
| 101 | /* Disable Io Space before changing the address */ |
| 102 | pcr_rmw32(PID_PSF3, PCR_PSF3_TO_SHDW_PMC_REG_BASE + |
| 103 | PCR_PSFX_T0_SHDW_PCIEN, |
| 104 | ~PCR_PSFX_TO_SHDW_PCIEN_IOEN, 0); |
| 105 | /* Program ABASE in PSF3 PMC space BAR4*/ |
| 106 | pcr_write32(PID_PSF3, PCR_PSF3_TO_SHDW_PMC_REG_BASE + |
| 107 | PCR_PSFX_TO_SHDW_BAR4, |
| 108 | ACPI_BASE_ADDRESS); |
| 109 | /* Enable IO Space */ |
| 110 | pcr_rmw32(PID_PSF3, PCR_PSF3_TO_SHDW_PMC_REG_BASE + |
| 111 | PCR_PSFX_T0_SHDW_PCIEN, |
| 112 | ~0, PCR_PSFX_TO_SHDW_PCIEN_IOEN); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | static void soc_config_tco(void) |
| 117 | { |
| 118 | uint32_t reg32; |
| 119 | uint16_t tcobase; |
| 120 | uint16_t tcocnt; |
| 121 | |
| 122 | /* Disable TCO in SMBUS Device first before changing Base Address */ |
| 123 | reg32 = pci_read_config32(PCH_DEV_SMBUS, TCOCTL); |
Lijian Zhao | 6dc125f | 2017-07-13 19:11:45 -0700 | [diff] [blame] | 124 | reg32 &= ~TCO_BASE_EN; |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 125 | pci_write_config32(PCH_DEV_SMBUS, TCOCTL, reg32); |
| 126 | |
| 127 | /* Program TCO Base */ |
| 128 | tcobase = TCO_BASE_ADDRESS; |
| 129 | pci_write_config32(PCH_DEV_SMBUS, TCOBASE, tcobase); |
| 130 | |
| 131 | /* Enable TCO in SMBUS */ |
| 132 | pci_write_config32(PCH_DEV_SMBUS, TCOCTL, reg32 | TCO_BASE_EN); |
| 133 | |
| 134 | /* |
| 135 | * Program "TCO Base Address" PCR[DMI] + 2778h[15:5, 1] |
| 136 | */ |
| 137 | pcr_write32(PID_DMI, PCR_DMI_TCOBASE, tcobase | TCOEN); |
| 138 | |
| 139 | /* Program TCO timer halt */ |
| 140 | tcocnt = inw(tcobase + TCO1_CNT); |
| 141 | tcocnt |= TCO_TMR_HLT; |
| 142 | outw(tcocnt, tcobase + TCO1_CNT); |
| 143 | } |
| 144 | |
| 145 | void pch_early_iorange_init(void) |
| 146 | { |
| 147 | uint16_t dec_rng, dec_en = 0; |
| 148 | |
| 149 | /* IO Decode Range */ |
| 150 | if (IS_ENABLED(CONFIG_DRIVERS_UART_8250IO) && |
| 151 | IS_ENABLED(CONFIG_UART_DEBUG)) { |
| 152 | dec_rng = COMA_RANGE | (COMB_RANGE << 4); |
| 153 | dec_en = COMA_LPC_EN | COMB_LPC_EN; |
| 154 | pci_write_config16(PCH_DEV_LPC, LPC_IO_DEC, dec_rng); |
| 155 | pcr_write16(PID_DMI, PCR_DMI_LPCIOD, dec_rng); |
| 156 | } |
| 157 | |
| 158 | /* IO Decode Enable */ |
Lijian Zhao | 9b50a57 | 2017-12-21 13:40:07 -0800 | [diff] [blame] | 159 | dec_en |= SE_LPC_EN | KBC_LPC_EN | MC1_LPC_EN | GAMEL_LPC_EN; |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 160 | pci_write_config16(PCH_DEV_LPC, LPC_EN, dec_en); |
| 161 | pcr_write16(PID_DMI, PCR_DMI_LPCIOE, dec_en); |
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 | |
| 167 | void pch_early_init(void) |
| 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 | |
| 175 | /* Programming TCO_BASE_ADDRESS and TCO Timer Halt */ |
| 176 | soc_config_tco(); |
| 177 | |
| 178 | /* Program SMBUS_BASE_ADDRESS and Enable it */ |
| 179 | smbus_common_init(); |
| 180 | |
Lijian Zhao | 031020e | 2017-12-15 12:58:07 -0800 | [diff] [blame] | 181 | /* Set up GPE configuration */ |
| 182 | pmc_gpe_init(); |
| 183 | |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 184 | enable_rtc_upper_bank(); |
Andrey Petrov | f35804b | 2017-06-05 13:22:41 -0700 | [diff] [blame] | 185 | } |