PeiKabylakeRvp3InitPostMemLib.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 <SaPolicyCommon.h>
  7. #include <Library/DebugLib.h>
  8. #include <Library/BaseMemoryLib.h>
  9. #include <Library/IoLib.h>
  10. #include <Library/HobLib.h>
  11. #include <Library/PcdLib.h>
  12. #include <Library/PchCycleDecodingLib.h>
  13. #include <Library/PciLib.h>
  14. #include <Library/PeiSaPolicyLib.h>
  15. #include <Library/BoardInitLib.h>
  16. #include <PchAccess.h>
  17. #include <Library/GpioNativeLib.h>
  18. #include <Library/GpioLib.h>
  19. #include <GpioPinsSklLp.h>
  20. #include <GpioPinsSklH.h>
  21. #include <Library/GpioExpanderLib.h>
  22. #include <SioRegs.h>
  23. #include <Library/PchPcrLib.h>
  24. #include <IoExpander.h>
  25. #include <Library/PcdLib.h>
  26. #include <Library/SiliconInitLib.h>
  27. #include "PeiKabylakeRvp3InitLib.h"
  28. /**
  29. SkylaeA0Rvp3 board configuration init function for PEI post memory phase.
  30. PEI_BOARD_CONFIG_PCD_INIT
  31. @param Content pointer to the buffer contain init information for board init.
  32. @retval EFI_SUCCESS The function completed successfully.
  33. @retval EFI_INVALID_PARAMETER The parameter is NULL.
  34. **/
  35. EFI_STATUS
  36. EFIAPI
  37. KabylakeRvp3Init (
  38. VOID
  39. )
  40. {
  41. PcdSet32S (PcdHdaVerbTable, (UINTN) &HdaVerbTableAlc286Rvp3);
  42. //
  43. // Assign the GPIO table with pin configs to be used for UCMC
  44. //
  45. PcdSet32S (PcdBoardUcmcGpioTable, (UINTN)mGpioTableLpddr3Rvp3UcmcDevice);
  46. PcdSet16S (PcdBoardUcmcGpioTableSize, mGpioTableLpddr3Rvp3UcmcDeviceSize);
  47. return EFI_SUCCESS;
  48. }
  49. #define EXPANDERS 2 // defines expander's quantity
  50. /**
  51. Configures GPIO
  52. @param[in] GpioTable Point to Platform Gpio table
  53. @param[in] GpioTableCount Number of Gpio table entries
  54. **/
  55. VOID
  56. ConfigureGpio (
  57. IN GPIO_INIT_CONFIG *GpioDefinition,
  58. IN UINT16 GpioTableCount
  59. )
  60. {
  61. EFI_STATUS Status;
  62. DEBUG ((DEBUG_INFO, "ConfigureGpio() Start\n"));
  63. Status = GpioConfigurePads (GpioTableCount, GpioDefinition);
  64. DEBUG ((DEBUG_INFO, "ConfigureGpio() End\n"));
  65. }
  66. VOID
  67. SetBit (
  68. IN OUT UINT32 *Value,
  69. IN UINT32 BitNumber,
  70. IN BOOLEAN NewBitValue
  71. )
  72. {
  73. if (NewBitValue) {
  74. *Value |= 1 << BitNumber;
  75. } else {
  76. *Value &= ~(1 << BitNumber);
  77. }
  78. }
  79. /**
  80. Configures IO Expander GPIO device
  81. @param[in] IOExpGpioDefinition Point to IO Expander Gpio table
  82. @param[in] IOExpGpioTableCount Number of Gpio table entries
  83. **/
  84. void
  85. ConfigureIoExpanderGpio (
  86. IN IO_EXPANDER_GPIO_CONFIG *IoExpGpioDefinition,
  87. IN UINT16 IoExpGpioTableCount
  88. )
  89. {
  90. UINT8 Index;
  91. UINT32 Direction[EXPANDERS] = {0x00FFFFFF, 0x00FFFFFF};
  92. UINT32 Level[EXPANDERS] = {0};
  93. UINT32 Polarity[EXPANDERS] = {0};
  94. // IoExpander {TCA6424A}
  95. DEBUG ((DEBUG_INFO, "IO Expander Configuration Start\n"));
  96. for (Index = 0; Index < IoExpGpioTableCount; Index++) { //Program IO Expander as per the table defined in PeiPlatformHooklib.c
  97. SetBit(&Direction[IoExpGpioDefinition[Index].IoExpanderNumber], IoExpGpioDefinition[Index].GpioPinNumber, (BOOLEAN)IoExpGpioDefinition[Index].GpioDirection);
  98. SetBit(&Level[IoExpGpioDefinition[Index].IoExpanderNumber], IoExpGpioDefinition[Index].GpioPinNumber, (BOOLEAN)IoExpGpioDefinition[Index].GpioLevel);
  99. SetBit(&Polarity[IoExpGpioDefinition[Index].IoExpanderNumber], IoExpGpioDefinition[Index].GpioPinNumber, (BOOLEAN)IoExpGpioDefinition[Index].GpioInversion);
  100. }
  101. for (Index = 0; Index < EXPANDERS; Index++) {
  102. GpioExpBulkConfig(Index, Direction[Index], Polarity[Index], Level[Index]);
  103. }
  104. DEBUG ((DEBUG_INFO, "IO Expander Configuration End\n"));
  105. return;
  106. }
  107. /**
  108. Configure GPIO behind IoExpander.
  109. @param[in] PeiServices General purpose services available to every PEIM.
  110. @param[in] NotifyDescriptor
  111. @param[in] Interface
  112. @retval EFI_SUCCESS Operation success.
  113. **/
  114. VOID
  115. ExpanderGpioInit (
  116. VOID
  117. )
  118. {
  119. ConfigureIoExpanderGpio(mGpioTableIoExpander, mGpioTableIoExpanderSize);
  120. }
  121. /**
  122. Configure single GPIO pad for touchpanel interrupt
  123. **/
  124. VOID
  125. TouchpanelGpioInit (
  126. VOID
  127. )
  128. {
  129. GPIO_INIT_CONFIG* TouchpanelPad;
  130. GPIO_PAD_OWN PadOwnVal;
  131. PadOwnVal = 0;
  132. TouchpanelPad = &mGpioTableLpDdr3Rvp3Touchpanel;
  133. GpioGetPadOwnership (TouchpanelPad->GpioPad, &PadOwnVal);
  134. if (PadOwnVal == GpioPadOwnHost) {
  135. GpioConfigurePads (1, TouchpanelPad);
  136. }
  137. }
  138. /**
  139. Configure GPIO
  140. **/
  141. VOID
  142. GpioInit (
  143. VOID
  144. )
  145. {
  146. ConfigureGpio (mGpioTableLpDdr3Rvp3, mGpioTableLpDdr3Rvp3Size);
  147. TouchpanelGpioInit();
  148. return;
  149. }
  150. /**
  151. Configure GPIO and SIO
  152. @retval EFI_SUCCESS Operation success.
  153. **/
  154. EFI_STATUS
  155. EFIAPI
  156. KabylakeRvp3BoardInitBeforeSiliconInit (
  157. VOID
  158. )
  159. {
  160. KabylakeRvp3Init ();
  161. GpioInit ();
  162. ExpanderGpioInit ();
  163. ///
  164. /// Do Late PCH init
  165. ///
  166. LateSiliconInit ();
  167. return EFI_SUCCESS;
  168. }