hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/** @file
  PEI Library Functions. Initialize GPIOs
 
 
  Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
  SPDX-License-Identifier: BSD-2-Clause-Patent
**/
 
#include <PiPei.h>
#include <PeiPlatformHookLib.h>
#include <SaPolicyCommon.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/IoLib.h>
#include <Library/HobLib.h>
#include <Library/PcdLib.h>
#include <Library/TimerLib.h>
#include <Library/PchCycleDecodingLib.h>
#include <Library/PeiPlatformLib.h>
#include <Library/PciSegmentLib.h>
#include <Library/PeiServicesLib.h>
#include <Library/PmcLib.h>
#include <Library/PeiSaPolicyLib.h>
#include <PchAccess.h>
#include <Library/CpuPlatformLib.h>
#include <Library/GpioNativeLib.h>
#include <Library/GpioLib.h>
#include <GpioPinsCnlLp.h>
#include <GpioPinsCnlH.h>
#include <Library/PchInfoLib.h>
#include <Library/CnviLib.h>
#include <SioRegs.h>
#include <PlatformBoardConfig.h>
#include <Library/PchPcrLib.h>
#include <Library/GpioCheckConflictLib.h>
 
#define SIO_RUNTIME_REG_BASE_ADDRESS                          0x0680
 
#define RECOVERY_MODE_GPIO_PIN                    0                    // Platform specific @todo use PCD
 
#define MANUFACTURE_MODE_GPIO_PIN                 0                    // Platform specific @todo use PCD
 
/**
  Configures GPIO
 
  @param[in]  GpioTable       Point to Platform Gpio table
  @param[in]  GpioTableCount  Number of Gpio table entries
 
**/
VOID
ConfigureGpio (
  IN GPIO_INIT_CONFIG                 *GpioDefinition,
  IN UINT16                           GpioTableCount
  )
{
  DEBUG ((DEBUG_INFO, "ConfigureGpio() Start\n"));
 
  CreateGpioCheckConflictHob (GpioDefinition, GpioTableCount);
 
  GpioConfigurePads (GpioTableCount, GpioDefinition);
 
  DEBUG ((DEBUG_INFO, "ConfigureGpio() End\n"));
}
 
/**
  Configure GPIO group GPE tier.
 
  @retval     none.
**/
VOID
GpioGroupTierInitHook(
  VOID
  )
{
  DEBUG ((DEBUG_INFO, "GpioGroupTierInitHook Start\n"));
 
  if (PcdGet32 (PcdGpioGroupToGpeDw0)) {
    GpioSetGroupToGpeDwX (PcdGet32 (PcdGpioGroupToGpeDw0),
                          PcdGet32 (PcdGpioGroupToGpeDw1),
                          PcdGet32 (PcdGpioGroupToGpeDw2));
  }
  DEBUG ((DEBUG_INFO, "GpioGroupTierInitHook End\n"));
}
 
/**
  Configure single GPIO pad for touchpanel interrupt
**/
VOID
TouchpanelGpioInit (
  VOID
  )
{
  GPIO_INIT_CONFIG*     TouchpanelPad;
  GPIO_PAD_OWN          PadOwnVal;
 
  PadOwnVal = 0;
  TouchpanelPad = (VOID *) (UINTN) PcdGet32 (PcdBoardGpioTableTouchPanel);
  if (TouchpanelPad != NULL) {
    GpioGetPadOwnership (TouchpanelPad->GpioPad, &PadOwnVal);
    if (PadOwnVal == GpioPadOwnHost) {
      GpioConfigurePads (1, TouchpanelPad);
    }
  }
}
 
/**
  Configure GPIO Before Memory is not ready.
 
**/
VOID
GpioInitPreMem (
  VOID
  )
{
  if (PcdGet32 (PcdBoardGpioTablePreMem) != 0 && PcdGet16 (PcdBoardGpioTablePreMemSize) != 0) {
    ConfigureGpio ((VOID *) (UINTN) PcdGet32 (PcdBoardGpioTablePreMem), (UINTN) PcdGet16 (PcdBoardGpioTablePreMemSize));
  }
}
 
/**
  Basic GPIO configuration before memory is ready
 
**/
VOID
GpioInitEarlyPreMem (
  VOID
  )
{
  GPIO_CONFIG                     BbrstConfig;
  UINT32                          WwanBbrstGpio;
 
  WwanBbrstGpio = PcdGet32 (PcdWwanBbrstGpio);
 
  if (WwanBbrstGpio) {
    //
    // BIOS needs to put modem in OFF state for the two scenarios below.
    // 1. Modem RESET# is not asserted via PLTRST# in the previous sleep state
    // 2. Modem is disabled via setup option
    //
    GpioGetPadConfig (WwanBbrstGpio, &BbrstConfig);
    if ((PcdGetBool (PcdPcieWwanEnable) == FALSE) ||
        (PcdGetBool (PcdWwanResetWorkaround) == TRUE &&
        BbrstConfig.Direction == GpioDirOut &&
        BbrstConfig.OutputState == GpioOutHigh)) {
      //
      // Assert FULL_CARD_POWER_OFF#, RESET# and PERST# GPIOs
      //
      if (PcdGet32 (PcdBoardGpioTableWwanOffEarlyPreMem) != 0 && PcdGet16 (PcdBoardGpioTableWwanOffEarlyPreMemSize) != 0) {
        ConfigureGpio ((VOID *) (UINTN) PcdGet32 (PcdBoardGpioTableWwanOffEarlyPreMem), (UINTN) PcdGet16 (PcdBoardGpioTableWwanOffEarlyPreMemSize));
      }
      if (PcdGetBool (PcdPcieWwanEnable) == TRUE && PcdGetBool (PcdWwanResetWorkaround) == TRUE) {
        MicroSecondDelay (1 * 1000); // Delay by 1ms
      }
    }
 
    //
    // Turn ON modem power and de-assert RESET# and PERST# GPIOs
    //
    if (PcdGetBool (PcdPcieWwanEnable) == TRUE) {
      if (PcdGet32 (PcdBoardGpioTableWwanOnEarlyPreMem) != 0 && PcdGet16 (PcdBoardGpioTableWwanOnEarlyPreMemSize) != 0) {
        ConfigureGpio ((VOID *) (UINTN) PcdGet32 (PcdBoardGpioTableWwanOnEarlyPreMem), (UINTN) PcdGet16 (PcdBoardGpioTableWwanOnEarlyPreMemSize));
      }
    }
  }
}
 
/**
  Configure GPIO
 
**/
VOID
GpioInit (
  VOID
  )
{
  ConfigureGpio ((VOID *) (UINTN) PcdGet32 (PcdBoardGpioTable), (UINTN) PcdGet16 (PcdBoardGpioTableSize));
 
  if (PcdGet32 (PcdBoardGpioTable2)) {
    ConfigureGpio ((VOID *) (UINTN) PcdGet32 (PcdBoardGpioTable2), (UINTN) PcdGet16 (PcdBoardGpioTable2Size));
  }
 
  TouchpanelGpioInit ();
 
  //
  // Lock pads after initializing platform GPIO.
  // Pads which were requested to be unlocked during configuration
  // will not be locked.
  //
  GpioLockPads ();
 
  return;
}
 
/**
  Configure Super IO
 
**/
VOID
SioInit (
  VOID
  )
{
  //
  // Program and Enable Default Super IO Configuration Port Addresses and range
  //
  PchLpcGenIoRangeSet (PcdGet16 (PcdLpcSioConfigDefaultPort) & (~0xF), 0x10);
 
  PchLpcGenIoRangeSet (SIO_RUNTIME_REG_BASE_ADDRESS  & (~0x7F), 0x10);
 
  return;
}
 
/**
  Configure GPIO and SIO before memory ready
 
  @retval  EFI_SUCCESS   Operation success.
**/
EFI_STATUS
BoardInitPreMem (
  VOID
  )
{
  //
  // Obtain Platform Info from HOB.
  //
  GpioInitPreMem ();
  GpioGroupTierInitHook ();
  SioInit ();
 
  return EFI_SUCCESS;
}
 
/**
  Configure GPIO and SIO
 
  @retval  EFI_SUCCESS   Operation success.
**/
EFI_STATUS
BoardInit (
  VOID
  )
{
 
  GpioInit ();
 
  return EFI_SUCCESS;
}
 
/**
  Do platform specific programming post-memory.
 
  @retval  EFI_SUCCESS       The function completed successfully.
**/
 
EFI_STATUS
PlatformSpecificInit (
  VOID
  )
{
  GPIO_CONFIG                     GpioConfig;
 
  if (IsCnlPch ()) {
 
    //
    // Tristate unused pins by audio link mode.
    //
    ZeroMem(&GpioConfig, sizeof(GPIO_CONFIG));
    GpioConfig.PadMode = GpioPadModeGpio;
    GpioConfig.HostSoftPadOwn = GpioHostOwnGpio;
    GpioConfig.Direction = GpioDirNone;
    GpioConfig.OutputState = GpioOutDefault;
    GpioConfig.InterruptConfig = GpioIntDis;
    GpioConfig.PowerConfig = GpioPlatformReset;
    GpioConfig.ElectricalConfig = GpioTermNone;
 
    GpioSetPadConfig (GPIO_CNL_LP_SSP1_SFRM, &GpioConfig);
    GpioSetPadConfig (GPIO_CNL_LP_SSP1_TXD, &GpioConfig);
 
  }
 
  return EFI_SUCCESS;
}
 
/**
  Early Board Configuration before memory is ready
 
  @retval  EFI_SUCCESS  Operation success.
**/
EFI_STATUS
BoardInitEarlyPreMem (
  VOID
  )
{
  GpioInitEarlyPreMem ();
 
  return EFI_SUCCESS;
}