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
299
/** @file
  This file contains routines for GPIO native and chipset specific purpose
  used by Reference Code only.
 
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
 
**/
#include <Base.h>
#include <Uefi/UefiBaseType.h>
#include <Library/IoLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <PchAccess.h>
#include <Library/GpioLib.h>
#include <Library/GpioNativeLib.h>
#include <Library/GpioPrivateLib.h>
#include <Library/PchInfoLib.h>
#include <Pch/Library/PeiDxeSmmGpioLib/GpioLibrary.h>
 
//
// Chipset specific data
//
//ISH
extern GPIO_PAD_NATIVE_FUNCTION mPchLpIshGPGpio[PCH_ISH_MAX_GP_PINS];
extern GPIO_PAD_NATIVE_FUNCTION mPchHIshGPGpio[PCH_ISH_MAX_GP_PINS];
extern GPIO_PAD_NATIVE_FUNCTION mPchLpIshI2cGpio[PCH_ISH_MAX_I2C_CONTROLLERS][PCH_ISH_PINS_PER_I2C_CONTROLLER];
extern GPIO_PAD_NATIVE_FUNCTION mPchHIshI2cGpio[PCH_ISH_MAX_I2C_CONTROLLERS][PCH_ISH_PINS_PER_I2C_CONTROLLER];
extern GPIO_PAD_NATIVE_FUNCTION mPchLpIshUartGpio[PCH_ISH_MAX_UART_CONTROLLERS][PCH_ISH_PINS_PER_UART_CONTROLLER];
extern GPIO_PAD_NATIVE_FUNCTION mPchHIshUartGpio[PCH_ISH_MAX_UART_CONTROLLERS][PCH_ISH_PINS_PER_UART_CONTROLLER];
extern GPIO_PAD_NATIVE_FUNCTION mPchLpIshSpiGpio[PCH_ISH_PINS_PER_SPI_CONTROLLER];
extern GPIO_PAD_NATIVE_FUNCTION mPchHIshSpiGpio[PCH_ISH_PINS_PER_SPI_CONTROLLER];
 
 
//PCIe SRCCLKREQB
extern GPIO_PAD_NATIVE_FUNCTION mPchLpPcieSrcClkReqbPinToGpioMap[PCH_LP_PCIE_MAX_CLK_REQ];
extern GPIO_PAD_NATIVE_FUNCTION mPchHPcieSrcClkReqbPinToGpioMap[PCH_H_PCIE_MAX_CLK_REQ];
 
//PCH_HOT
extern GPIO_PAD_NATIVE_FUNCTION mPchLpPchHotbPin;
extern GPIO_PAD_NATIVE_FUNCTION mPchHPchHotbPin;
 
//CPU GP
extern GPIO_PAD_NATIVE_FUNCTION mPchLpCpuGpPinMap[4];
extern GPIO_PAD_NATIVE_FUNCTION mPchHCpuGpPinMap[4];
 
/**
  This function sets ISH I2C controller pins into native mode
 
  @param[in]  IshI2cControllerNumber   I2C controller
 
  @retval Status
**/
EFI_STATUS
GpioSetIshI2cPinsIntoNativeMode (
  IN  UINT32            IshI2cControllerNumber
  )
{
  EFI_STATUS               Status;
  UINTN                    Index;
  GPIO_PAD_NATIVE_FUNCTION (*I2cGpio) [PCH_ISH_PINS_PER_I2C_CONTROLLER];
 
  Status = EFI_SUCCESS;
 
  if (GetPchSeries () == PchLp) {
    I2cGpio = mPchLpIshI2cGpio;
  } else {
    I2cGpio = mPchHIshI2cGpio;
  }
 
  ASSERT (IshI2cControllerNumber < PCH_ISH_MAX_I2C_CONTROLLERS);
 
  for (Index = 0; Index < PCH_ISH_PINS_PER_I2C_CONTROLLER; Index++) {
    Status = SetGpioPadMode (I2cGpio[IshI2cControllerNumber][Index].Pad, I2cGpio[IshI2cControllerNumber][Index].Mode);
    if (EFI_ERROR (Status)) {
      return EFI_UNSUPPORTED;
    }
  }
  return Status;
}
 
/**
  This function sets ISH UART controller pins into native mode
 
  @param[in]  IshUartControllerNumber   UART controller
 
  @retval Status
**/
EFI_STATUS
GpioSetIshUartPinsIntoNativeMode (
  IN  UINT32            IshUartControllerNumber
  )
{
  EFI_STATUS    Status;
  UINTN         Index;
  GPIO_PAD_NATIVE_FUNCTION (*UartGpio) [PCH_ISH_PINS_PER_UART_CONTROLLER];
 
  Status = EFI_SUCCESS;
 
  if (GetPchSeries () == PchLp) {
    UartGpio = mPchLpIshUartGpio;
  } else {
    UartGpio = mPchHIshUartGpio;
  }
 
  ASSERT (IshUartControllerNumber < PCH_ISH_MAX_UART_CONTROLLERS);
 
  for (Index = 0; Index < PCH_ISH_PINS_PER_UART_CONTROLLER; Index++) {
    Status = SetGpioPadMode (UartGpio[IshUartControllerNumber][Index].Pad, UartGpio[IshUartControllerNumber][Index].Mode);
    if (EFI_ERROR (Status)) {
      return EFI_UNSUPPORTED;
    }
  }
  return Status;
}
 
/**
  This function sets ISH SPI controller pins into native mode
 
  @param[in]  none
 
  @retval Status
**/
EFI_STATUS
GpioSetIshSpiPinsIntoNativeMode (
  VOID
  )
{
  EFI_STATUS    Status;
  UINTN         Index;
  GPIO_PAD_NATIVE_FUNCTION *SpiGpio;
 
  Status = EFI_SUCCESS;
 
  if (GetPchSeries () == PchLp) {
    SpiGpio = mPchLpIshSpiGpio;
  } else {
    SpiGpio = mPchHIshSpiGpio;
  }
 
  for (Index = 0; Index < PCH_ISH_PINS_PER_SPI_CONTROLLER; Index++) {
    Status = SetGpioPadMode (SpiGpio[Index].Pad, SpiGpio[Index].Mode);
    if (EFI_ERROR (Status)) {
      return EFI_UNSUPPORTED;
    }
  }
  return Status;
}
 
/**
  This function sets ISH GP pins into native mode
 
  @param[in]  IshGpPinNumber   ISH GP pin number
 
  @retval Status
**/
EFI_STATUS
GpioSetIshGpPinsIntoNativeMode (
  IN  UINT32            IshGpPinNumber
  )
{
  EFI_STATUS               Status;
  GPIO_PAD_NATIVE_FUNCTION *IshGp;
 
  Status = EFI_SUCCESS;
 
  if (GetPchSeries () == PchLp) {
    IshGp = mPchLpIshGPGpio;
  } else {
    IshGp = mPchHIshGPGpio;
  }
  ASSERT (IshGpPinNumber < PCH_ISH_MAX_GP_PINS);
 
  Status = SetGpioPadMode (IshGp[IshGpPinNumber].Pad, IshGp[IshGpPinNumber].Mode);
  if (EFI_ERROR (Status)) {
    return EFI_UNSUPPORTED;
  }
 
  return Status;
}
 
/**
  Returns a pad for given CLKREQ# index.
 
  @param[in]  ClkreqIndex       CLKREQ# number
 
  @return CLKREQ# pad.
**/
GPIO_PAD
GpioGetClkreqPad (
  IN     UINT32   ClkreqIndex
  )
{
  if (GetPchSeries () == PchLp) {
    ASSERT (ClkreqIndex < PCH_LP_PCIE_MAX_CLK_REQ);
    return mPchLpPcieSrcClkReqbPinToGpioMap[ClkreqIndex].Pad;
  } else {
    ASSERT (ClkreqIndex < PCH_H_PCIE_MAX_CLK_REQ);
    return mPchHPcieSrcClkReqbPinToGpioMap[ClkreqIndex].Pad;
  }
}
 
/**
  Enables CLKREQ# pad in native mode.
 
  @param[in]  ClkreqIndex       CLKREQ# number
 
  @return none
**/
VOID
GpioEnableClkreq (
  IN     UINT32   ClkreqIndex
  )
{
  GPIO_CONFIG        PadConfig;
  GPIO_PAD           ClkreqPad;
  GPIO_PAD_MODE      PadMode;
 
  ZeroMem (&PadConfig, sizeof (PadConfig));
 
  if (GetPchSeries () == PchLp) {
    ASSERT (ClkreqIndex < PCH_LP_PCIE_MAX_CLK_REQ);
    ClkreqPad = mPchLpPcieSrcClkReqbPinToGpioMap[ClkreqIndex].Pad;
    PadMode = mPchLpPcieSrcClkReqbPinToGpioMap[ClkreqIndex].Mode;
  } else {
    ASSERT (ClkreqIndex < PCH_H_PCIE_MAX_CLK_REQ);
    ClkreqPad = mPchHPcieSrcClkReqbPinToGpioMap[ClkreqIndex].Pad;
    PadMode = mPchHPcieSrcClkReqbPinToGpioMap[ClkreqIndex].Mode;
  }
 
  PadConfig.PadMode      = PadMode;
  PadConfig.Direction    = GpioDirNone;
  PadConfig.PowerConfig  = GpioHostDeepReset;
  DEBUG ((DEBUG_INFO, "Enabling CLKREQ%d\n", ClkreqIndex));
  GpioSetPadConfig (ClkreqPad, &PadConfig);
}
 
/**
  This function checks if GPIO pin for PCHHOTB is in NATIVE MODE
 
  @param[in]  none
 
  @retval TRUE                    Pin is in PCHHOTB native mode
          FALSE                   Pin is in gpio mode or is not owned by HOST
**/
BOOLEAN
GpioIsPchHotbPinInNativeMode (
  VOID
  )
{
  EFI_STATUS               Status;
  GPIO_PAD_NATIVE_FUNCTION PchHotbPin;
  GPIO_PAD_MODE            GpioMode;
 
 
  if (GetPchSeries () == PchLp) {
    PchHotbPin = mPchLpPchHotbPin;
  } else {
    PchHotbPin = mPchHPchHotbPin;
  }
 
  Status =  GetGpioPadMode (PchHotbPin.Pad, &GpioMode);
 
  if ((EFI_ERROR (Status)) || (GpioMode != PchHotbPin.Mode)) {
    return FALSE;
  } else {
    return TRUE;
  }
}
 
/**
  This function sets CPU GP pins into native mode
 
  @param[in]  CpuGpPinNum               CPU GP pin number
 
  @retval Status
**/
EFI_STATUS
GpioSetCpuGpPinsIntoNativeMode (
  IN  UINT32                            CpuGpPinNum
  )
{
  EFI_STATUS               Status;
  GPIO_PAD_NATIVE_FUNCTION *CpuGpPins;
 
  if (GetPchSeries () == PchLp) {
    CpuGpPins = mPchLpCpuGpPinMap;
  } else {
    CpuGpPins = mPchHCpuGpPinMap;
  }
 
  ASSERT (CpuGpPinNum < 4);
 
  Status = SetGpioPadMode (CpuGpPins[CpuGpPinNum].Pad, CpuGpPins[CpuGpPinNum].Mode);
  if (EFI_ERROR (Status)) {
    return EFI_UNSUPPORTED;
  }
  return EFI_SUCCESS;
}