PeiGalagoPro3InitPostMemLib.c 5.1 KB

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