Angel Pons | 32abdd6 | 2020-04-05 15:47:03 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 2 | |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 3 | #include <device/mmio.h> |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 4 | #include <device/device.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 6 | #include <intelblocks/fast_spi.h> |
| 7 | #include <intelblocks/gspi.h> |
| 8 | #include <intelblocks/lpc_lib.h> |
| 9 | #include <intelblocks/p2sb.h> |
| 10 | #include <intelblocks/pcr.h> |
| 11 | #include <intelblocks/pmclib.h> |
| 12 | #include <intelblocks/rtc.h> |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 13 | #include <soc/bootblock.h> |
| 14 | #include <soc/iomap.h> |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 15 | #include <soc/p2sb.h> |
| 16 | #include <soc/pch.h> |
| 17 | #include <soc/pci_devs.h> |
| 18 | #include <soc/pcr_ids.h> |
| 19 | #include <soc/pm.h> |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 20 | |
Aamir Bohra | c726763 | 2018-06-30 12:38:43 +0530 | [diff] [blame] | 21 | #define PCR_PSF3_TO_SHDW_PMC_REG_BASE 0x0600 |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 22 | #define PCR_PSFX_TO_SHDW_BAR0 0 |
| 23 | #define PCR_PSFX_TO_SHDW_BAR1 0x4 |
| 24 | #define PCR_PSFX_TO_SHDW_BAR2 0x8 |
| 25 | #define PCR_PSFX_TO_SHDW_BAR3 0xC |
| 26 | #define PCR_PSFX_TO_SHDW_BAR4 0x10 |
| 27 | #define PCR_PSFX_TO_SHDW_PCIEN_IOEN 0x01 |
| 28 | #define PCR_PSFX_T0_SHDW_PCIEN 0x1C |
| 29 | |
Subrata Banik | 1c329a0 | 2018-11-26 15:43:18 +0530 | [diff] [blame] | 30 | #define PCR_DMI_DMICTL 0x2234 |
| 31 | #define PCR_DMI_DMICTL_SRLOCK (1 << 31) |
| 32 | |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 33 | #define PCR_DMI_ACPIBA 0x27B4 |
| 34 | #define PCR_DMI_ACPIBDID 0x27B8 |
| 35 | #define PCR_DMI_PMBASEA 0x27AC |
| 36 | #define PCR_DMI_PMBASEC 0x27B0 |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 37 | |
| 38 | #define PCR_DMI_LPCIOD 0x2770 |
| 39 | #define PCR_DMI_LPCIOE 0x2774 |
| 40 | |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 41 | static void soc_config_pwrmbase(void) |
| 42 | { |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 43 | /* |
| 44 | * Assign Resources to PWRMBASE |
Subrata Banik | 45caf97 | 2020-08-05 13:30:30 +0530 | [diff] [blame] | 45 | * Clear BIT 1-2 Command Register |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 46 | */ |
Subrata Banik | 45caf97 | 2020-08-05 13:30:30 +0530 | [diff] [blame] | 47 | pci_and_config16(PCH_DEV_PMC, PCI_COMMAND, ~(PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER)); |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 48 | |
| 49 | /* Program PWRM Base */ |
| 50 | pci_write_config32(PCH_DEV_PMC, PWRMBASE, PCH_PWRM_BASE_ADDRESS); |
| 51 | |
| 52 | /* Enable Bus Master and MMIO Space */ |
Subrata Banik | 45caf97 | 2020-08-05 13:30:30 +0530 | [diff] [blame] | 53 | pci_or_config16(PCH_DEV_PMC, PCI_COMMAND, (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER)); |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 54 | |
| 55 | /* Enable PWRM in PMC */ |
Subrata Banik | 45caf97 | 2020-08-05 13:30:30 +0530 | [diff] [blame] | 56 | setbits32((void *) PCH_PWRM_BASE_ADDRESS + ACTL, PWRM_EN); |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void bootblock_pch_early_init(void) |
| 60 | { |
Furquan Shaikh | d149bfa | 2020-11-22 20:00:28 -0800 | [diff] [blame^] | 61 | /* |
| 62 | * Perform P2SB configuration before any another controller initialization as the |
| 63 | * controller might want to perform PCR settings. |
| 64 | */ |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 65 | p2sb_enable_bar(); |
| 66 | p2sb_configure_hpet(); |
| 67 | |
Furquan Shaikh | d149bfa | 2020-11-22 20:00:28 -0800 | [diff] [blame^] | 68 | fast_spi_early_init(SPI_BASE_ADDRESS); |
| 69 | gspi_early_bar_init(); |
| 70 | |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 71 | /* |
| 72 | * Enabling PWRM Base for accessing |
| 73 | * Global Reset Cause Register. |
| 74 | */ |
| 75 | soc_config_pwrmbase(); |
| 76 | } |
| 77 | |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 78 | static void soc_config_acpibase(void) |
| 79 | { |
| 80 | uint32_t pmc_reg_value; |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 81 | |
Aamir Bohra | c726763 | 2018-06-30 12:38:43 +0530 | [diff] [blame] | 82 | pmc_reg_value = pcr_read32(PID_PSF3, PCR_PSF3_TO_SHDW_PMC_REG_BASE + |
| 83 | PCR_PSFX_TO_SHDW_BAR4); |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 84 | |
| 85 | if (pmc_reg_value != 0xFFFFFFFF) { |
| 86 | /* Disable Io Space before changing the address */ |
Aamir Bohra | c726763 | 2018-06-30 12:38:43 +0530 | [diff] [blame] | 87 | pcr_rmw32(PID_PSF3, PCR_PSF3_TO_SHDW_PMC_REG_BASE + |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 88 | PCR_PSFX_T0_SHDW_PCIEN, |
| 89 | ~PCR_PSFX_TO_SHDW_PCIEN_IOEN, 0); |
| 90 | /* Program ABASE in PSF3 PMC space BAR4*/ |
Aamir Bohra | c726763 | 2018-06-30 12:38:43 +0530 | [diff] [blame] | 91 | pcr_write32(PID_PSF3, PCR_PSF3_TO_SHDW_PMC_REG_BASE + |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 92 | PCR_PSFX_TO_SHDW_BAR4, |
| 93 | ACPI_BASE_ADDRESS); |
| 94 | /* Enable IO Space */ |
Aamir Bohra | c726763 | 2018-06-30 12:38:43 +0530 | [diff] [blame] | 95 | pcr_rmw32(PID_PSF3, PCR_PSF3_TO_SHDW_PMC_REG_BASE + |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 96 | PCR_PSFX_T0_SHDW_PCIEN, |
| 97 | ~0, PCR_PSFX_TO_SHDW_PCIEN_IOEN); |
| 98 | } |
| 99 | } |
| 100 | |
Subrata Banik | 1c329a0 | 2018-11-26 15:43:18 +0530 | [diff] [blame] | 101 | static int pch_check_decode_enable(void) |
| 102 | { |
| 103 | uint32_t dmi_control; |
| 104 | |
| 105 | /* |
| 106 | * This cycle decoding is only allowed to set when |
| 107 | * DMICTL.SRLOCK is 0. |
| 108 | */ |
| 109 | dmi_control = pcr_read32(PID_DMI, PCR_DMI_DMICTL); |
| 110 | if (dmi_control & PCR_DMI_DMICTL_SRLOCK) |
| 111 | return -1; |
| 112 | return 0; |
| 113 | } |
| 114 | |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 115 | void pch_early_iorange_init(void) |
| 116 | { |
Subrata Banik | 1c329a0 | 2018-11-26 15:43:18 +0530 | [diff] [blame] | 117 | uint16_t io_enables = LPC_IOE_SUPERIO_2E_2F | LPC_IOE_KBC_60_64 | |
| 118 | LPC_IOE_EC_62_66 | LPC_IOE_LGE_200; |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 119 | |
| 120 | /* IO Decode Range */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 121 | if (CONFIG(DRIVERS_UART_8250IO)) |
Subrata Banik | 1c329a0 | 2018-11-26 15:43:18 +0530 | [diff] [blame] | 122 | lpc_io_setup_comm_a_b(); |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 123 | |
| 124 | /* IO Decode Enable */ |
Subrata Banik | 1c329a0 | 2018-11-26 15:43:18 +0530 | [diff] [blame] | 125 | if (pch_check_decode_enable() == 0) { |
| 126 | io_enables = lpc_enable_fixed_io_ranges(io_enables); |
| 127 | /* |
Wim Vervoorn | ee38b99 | 2020-02-03 15:25:49 +0100 | [diff] [blame] | 128 | * Set ESPI IO Enables PCR[DMI] + 2774h [15:0] to the same |
| 129 | * value programmed in ESPI PCI offset 82h. |
Subrata Banik | 1c329a0 | 2018-11-26 15:43:18 +0530 | [diff] [blame] | 130 | */ |
| 131 | pcr_write16(PID_DMI, PCR_DMI_LPCIOE, io_enables); |
Wim Vervoorn | 8440018 | 2020-02-03 15:20:46 +0100 | [diff] [blame] | 132 | /* |
| 133 | * Set LPC IO Decode Ranges PCR[DMI] + 2770h [15:0] to the same |
| 134 | * value programmed in LPC PCI offset 80h. |
| 135 | */ |
| 136 | pcr_write16(PID_DMI, PCR_DMI_LPCIOD, lpc_get_fixed_io_decode()); |
Subrata Banik | 1c329a0 | 2018-11-26 15:43:18 +0530 | [diff] [blame] | 137 | } |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 138 | |
| 139 | /* Program generic IO Decode Range */ |
| 140 | pch_enable_lpc(); |
| 141 | } |
| 142 | |
Subrata Banik | 5d14c76 | 2019-11-14 12:14:39 +0530 | [diff] [blame] | 143 | void pch_init(void) |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 144 | { |
| 145 | /* |
| 146 | * Enabling ABASE for accessing PM1_STS, PM1_EN, PM1_CNT, |
| 147 | * GPE0_STS, GPE0_EN registers. |
| 148 | */ |
| 149 | soc_config_acpibase(); |
| 150 | |
Aamir Bohra | 3ee54bb | 2018-10-17 11:55:01 +0530 | [diff] [blame] | 151 | /* Set up GPE configuration */ |
| 152 | pmc_gpe_init(); |
| 153 | |
| 154 | enable_rtc_upper_bank(); |
| 155 | } |