PeiAspireVn7Dash572GInitPostMemLib.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /** @file
  2. Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #include <PiPei.h>
  6. #include <Library/BoardEcLib.h>
  7. #include <Library/DebugLib.h>
  8. #include <Library/EcLib.h>
  9. #include <Library/GpioLib.h>
  10. #include <Library/IoLib.h>
  11. #include <Library/PcdLib.h>
  12. #include <Library/PchCycleDecodingLib.h>
  13. #include <Library/PciLib.h>
  14. #include <Library/PeiServicesLib.h>
  15. #include <Library/SiliconInitLib.h>
  16. #include <PchAccess.h>
  17. #include <GpioPinsSklLp.h>
  18. #include "PeiAspireVn7Dash572GInitLib.h"
  19. /**
  20. Init from vendor's PeiOemModule. KbcPeim does not appear to be used
  21. (It implements commands also found in RtKbcDriver and SmmKbcDriver).
  22. Mostly, this puts the system back to sleep if the lid is closed during
  23. an S3 resume.
  24. **/
  25. VOID
  26. EcInit (
  27. VOID
  28. )
  29. {
  30. EFI_BOOT_MODE BootMode;
  31. UINT8 PowerRegister;
  32. UINT8 OutData;
  33. UINT16 ABase;
  34. UINT16 Pm1Sts;
  35. UINT32 GpeSts;
  36. UINT16 XhciPmCs;
  37. /* This is called via a "$FNC" in a PeiOemModule pointer table, with "$DPX" on SiInit */
  38. IoWrite8 (0x6C, 0x5A); // 6Ch is the EC sideband port
  39. PeiServicesGetBootMode (&BootMode);
  40. if (BootMode == BOOT_ON_S3_RESUME) {
  41. /* "MLID" in LGMR-based memory map is equivalent to "ELID" in EC-based
  42. * memory map. Vendor firmware accesses through LGMR; remapped
  43. * - EcCmd* function calls will not remapped */
  44. EcRead (0x70, &PowerRegister);
  45. if (!(PowerRegister & BIT1)) { // Lid is closed
  46. EcCmd90Read (0x0A, &OutData);
  47. if (!(OutData & BIT1)) {
  48. EcCmd91Write (0x0A, OutData | BIT1);
  49. }
  50. /* Clear events and go back to sleep */
  51. PchAcpiBaseGet (&ABase);
  52. /* Clear ABase PM1_STS - RW/1C set bits */
  53. Pm1Sts = IoRead16 (ABase + R_PCH_ACPI_PM1_STS);
  54. IoWrite16 (ABase + R_PCH_ACPI_PM1_STS, Pm1Sts);
  55. /* Clear ABase GPE0_STS[127:96] - RW/1C set bits */
  56. GpeSts = IoRead32 (ABase + R_PCH_ACPI_GPE0_STS_127_96);
  57. IoWrite32 (ABase + R_PCH_ACPI_GPE0_STS_127_96, GpeSts);
  58. /* Clear xHCI PM_CS[PME_Status] - RW/1C - and disable xHCI PM_CS[PME_En] */
  59. PciAndThenOr16 (PCI_LIB_ADDRESS(PCI_BUS_NUMBER_PCH_XHCI, PCI_DEVICE_NUMBER_PCH_XHCI, PCI_FUNCTION_NUMBER_PCH_XHCI, R_PCH_XHCI_PWR_CNTL_STS),
  60. ~B_PCH_XHCI_PWR_CNTL_STS_PME_EN,
  61. B_PCH_XHCI_PWR_CNTL_STS_PME_STS
  62. );
  63. /* Enter S3 sleep */
  64. IoAndThenOr32 (ABase + R_PCH_ACPI_PM1_CNT,
  65. ~(B_PCH_ACPI_PM1_CNT_SLP_TYP | B_PCH_ACPI_PM1_CNT_SLP_EN),
  66. V_PCH_ACPI_PM1_CNT_S3
  67. );
  68. IoWrite32 (ABase + R_PCH_ACPI_PM1_CNT, B_PCH_ACPI_PM1_CNT_SLP_EN);
  69. CpuDeadLoop ();
  70. }
  71. }
  72. }
  73. /**
  74. Aspire VN7-572G board configuration init function for PEI post memory phase.
  75. **/
  76. VOID
  77. AspireVn7Dash572GInit (
  78. VOID
  79. )
  80. {
  81. PcdSet32S (PcdHdaVerbTable, (UINTN) &HdaVerbTableAlc255AspireVn7Dash572G);
  82. PcdSet32S (PcdDisplayAudioHdaVerbTable, (UINTN) &HdaVerbTableDisplayAudio);
  83. }
  84. /**
  85. Configures GPIO
  86. **/
  87. EFI_STATUS
  88. EFIAPI
  89. GpioInitPostMem (
  90. VOID
  91. )
  92. {
  93. EFI_STATUS Status;
  94. DEBUG ((DEBUG_INFO, "GpioInitPostMem() Start\n"));
  95. Status = GpioConfigurePads (mGpioTableAspireVn7Dash572GSize, mGpioTableAspireVn7Dash572G);
  96. if (EFI_ERROR (Status)) {
  97. DEBUG ((DEBUG_ERROR, "Failed to configure early GPIOs!\n"));
  98. return EFI_DEVICE_ERROR;
  99. }
  100. DEBUG ((DEBUG_INFO, "GpioInitPostMem() End\n"));
  101. return EFI_SUCCESS;
  102. }
  103. /**
  104. Configure GPIO and SIO
  105. @retval EFI_SUCCESS Operation success.
  106. **/
  107. EFI_STATUS
  108. EFIAPI
  109. AspireVn7Dash572GBoardInitBeforeSiliconInit (
  110. VOID
  111. )
  112. {
  113. GpioInitPostMem ();
  114. AspireVn7Dash572GInit ();
  115. ///
  116. /// Do Late PCH init
  117. ///
  118. LateSiliconInit ();
  119. return EFI_SUCCESS;
  120. }
  121. /**
  122. Notify EC
  123. @retval EFI_SUCCESS Operation success.
  124. **/
  125. EFI_STATUS
  126. EFIAPI
  127. AspireVn7Dash572GBoardInitAfterSiliconInit (
  128. VOID
  129. )
  130. {
  131. EcInit ();
  132. return EFI_SUCCESS;
  133. }