summaryrefslogtreecommitdiff
path: root/Platform/BroxtonPlatformPkg/Board/AuroraGlacier/BoardInitPostMem/BoardGpios.c
blob: 9cf3d1e9920304102f5c5f688b61d23a62bf99b6 (plain)
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
/** @file
  Gpio setting for multiplatform.

  Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>

  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php.

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include "BoardGpios.h"
#include <Library/GpioLib.h>
#include <Library/SteppingLib.h>


/**
  Returns the Correct GPIO table for Mobile/Desktop respectively.
  Before call it, make sure PlatformInfoHob->BoardId&PlatformFlavor is get correctly.

  @param[in] PeiServices         General purpose services available to every PEIM.
  @param[in] PlatformInfoHob     PlatformInfoHob pointer with PlatformFlavor specified.

  @retval    EFI_SUCCESS         The function completed successfully.
  @retval    EFI_DEVICE_ERROR    KSC fails to respond.

**/
EFI_STATUS
AuroraMultiPlatformGpioTableInit (
  IN CONST EFI_PEI_SERVICES     **PeiServices,
  IN EFI_PLATFORM_INFO_HOB      *PlatformInfoHob
  )
{
  DEBUG ((DEBUG_INFO, "AuroraMultiPlatformGpioTableInit()...\n"));
  DEBUG ((DEBUG_INFO, "PlatformInfoHob->BoardId: 0x%02X\n", PlatformInfoHob->BoardId));

  //
  // Select/modify the GPIO initialization data based on the Board ID.
  //
  switch (PlatformInfoHob->BoardId) {
    case BOARD_ID_AURORA:
      PlatformInfoHob->PlatformGpioSetting_SW = &mAuroraGpioInitData_SW[0];
      PlatformInfoHob->PlatformGpioSetting_W = &mAuroraGpioInitData_W[0];
      PlatformInfoHob->PlatformGpioSetting_NW = &mAuroraGpioInitData_NW[0];
      PlatformInfoHob->PlatformGpioSetting_N = &mAuroraGpioInitData_N[0];
      break;
    default:
      PlatformInfoHob->PlatformGpioSetting_SW = &mAuroraGpioInitData_SW[0];
      PlatformInfoHob->PlatformGpioSetting_W = &mAuroraGpioInitData_W[0];
      PlatformInfoHob->PlatformGpioSetting_NW = &mAuroraGpioInitData_NW[0];
      PlatformInfoHob->PlatformGpioSetting_N = &mAuroraGpioInitData_N[0];
      break;
  }

  return EFI_SUCCESS;
}


/**
  Set GPIO Lock for security.

**/
VOID
AuroraSetGpioPadCfgLock (
  VOID
  )
{
  UINT32 Data32;

  Data32 = 0;

  //
  // JTAG
  //
  GpioLockPadCfg (N_TCK);
  GpioLockPadCfg (N_TRST_B);
  GpioLockPadCfg (N_TMS);
  GpioLockPadCfg (N_TDI);
  GpioLockPadCfg (N_TDO);

  //
  // Power
  //
  GpioLockPadCfg (NW_PMIC_THERMTRIP_B);
  GpioLockPadCfg (NW_PROCHOT_B);

  //
  // Touch
  //
  GpioLockPadCfg (NW_GPIO_118);
  GpioLockPadCfg (NW_GPIO_119);
  GpioLockPadCfg (NW_GPIO_120);
  GpioLockPadCfg (NW_GPIO_121);
  GpioLockPadCfg (NW_GPIO_122);
  GpioLockPadCfg (NW_GPIO_123);

  //
  // SPI
  //
  GpioLockPadCfg (NW_GPIO_97);
  GpioLockPadCfg (NW_GPIO_98);
  GpioLockPadCfg (NW_GPIO_99);
  GpioLockPadCfg (NW_GPIO_100);
  GpioLockPadCfg (NW_GPIO_101);
  GpioLockPadCfg (NW_GPIO_102);
  GpioLockPadCfg (NW_GPIO_103);
  GpioLockPadCfg (NW_FST_SPI_CLK_FB);

  //
  // SMBus
  // Set SMBus GPIO PAD_CFG.PADRSTCFG to Powergood
  //
  Data32 = GpioPadRead (SW_SMB_ALERTB);
  Data32 &= ~(BIT31 | BIT30);
  GpioPadWrite (SW_SMB_ALERTB, Data32);

  Data32 = GpioPadRead (SW_SMB_CLK);
  Data32 &= ~(BIT31 | BIT30);
  GpioPadWrite (SW_SMB_CLK, Data32);

  Data32 = GpioPadRead (SW_SMB_DATA);
  Data32 &= ~(BIT31 | BIT30);
  GpioPadWrite (SW_SMB_DATA, Data32);

  GpioLockPadCfg (SW_SMB_ALERTB);
  GpioLockPadCfg (SW_SMB_CLK);
  GpioLockPadCfg (SW_SMB_DATA);
}


/**
  Returns the Correct GPIO table for Mobile/Desktop respectively.
  Before call it, make sure PlatformInfoHob->BoardId&PlatformFlavor is get correctly.

  @param[in] PeiServices          General purpose services available to every PEIM.
  @param[in] PlatformInfoHob      PlatformInfoHob pointer with PlatformFlavor specified.

  @retval    EFI_SUCCESS          The function completed successfully.
  @retval    EFI_DEVICE_ERROR     KSC fails to respond.

**/
EFI_STATUS
AuroraMultiPlatformGpioProgram (
  IN CONST EFI_PEI_SERVICES     **PeiServices,
  IN EFI_PLATFORM_INFO_HOB      *PlatformInfoHob
  )
{
  UINTN                             VariableSize;
  EFI_PEI_READ_ONLY_VARIABLE2_PPI   *VariableServices;
  SYSTEM_CONFIGURATION              SystemConfiguration;

  VariableSize = sizeof (SYSTEM_CONFIGURATION);
  ZeroMem (&SystemConfiguration, sizeof (SYSTEM_CONFIGURATION));

 (*PeiServices)->LocatePpi (
                    PeiServices,
                    &gEfiPeiReadOnlyVariable2PpiGuid,
                    0,
                    NULL,
                    (VOID **) &VariableServices
                     );

  VariableServices->GetVariable (
                      VariableServices,
                      PLATFORM_SETUP_VARIABLE_NAME,
                      &gEfiSetupVariableGuid,
                      NULL,
                      &VariableSize,
                      &SystemConfiguration
                      );

  DEBUG ((DEBUG_INFO, "AuroraMultiPlatformGpioProgram()...\n"));

  switch (PlatformInfoHob->BoardId) {
    case BOARD_ID_AURORA:
      //
      // PAD programming
      //
      DEBUG ((DEBUG_INFO, "PAD programming, Board ID: 0x%X\n", PlatformInfoHob->BoardId));
      GpioPadConfigTable (sizeof (mAuroraGpioInitData_N) / sizeof (mAuroraGpioInitData_N[0]), PlatformInfoHob->PlatformGpioSetting_N);
      GpioPadConfigTable (sizeof (mAuroraGpioInitData_NW) / sizeof (mAuroraGpioInitData_NW[0]), PlatformInfoHob->PlatformGpioSetting_NW);
      GpioPadConfigTable (sizeof (mAuroraGpioInitData_W) / sizeof (mAuroraGpioInitData_W[0]), PlatformInfoHob->PlatformGpioSetting_W);
      GpioPadConfigTable (sizeof (mAuroraGpioInitData_SW) / sizeof (mAuroraGpioInitData_SW[0]), PlatformInfoHob->PlatformGpioSetting_SW);

      if (SystemConfiguration.ScIshEnabled == 0) {
        DEBUG ((DEBUG_INFO, "Switch ISH_I2C0 & ISH_I2C1 to LPSS_I2C5 and LPSS I2C6. \n" ));
        GpioPadConfigTable (sizeof (mAuroraGpioInitData_LPSS_I2C) / sizeof (mAuroraGpioInitData_LPSS_I2C[0]), mAuroraGpioInitData_LPSS_I2C);
      }
      break;
    default:
    //
    // PAD programming
    //
    GpioPadConfigTable (sizeof (mAuroraGpioInitData_N) / sizeof (mAuroraGpioInitData_N[0]), PlatformInfoHob->PlatformGpioSetting_N);
    GpioPadConfigTable (sizeof (mAuroraGpioInitData_NW) / sizeof (mAuroraGpioInitData_NW[0]), PlatformInfoHob->PlatformGpioSetting_NW);
    GpioPadConfigTable (sizeof (mAuroraGpioInitData_W) / sizeof (mAuroraGpioInitData_W[0]), PlatformInfoHob->PlatformGpioSetting_W);
    GpioPadConfigTable (sizeof (mAuroraGpioInitData_SW) / sizeof (mAuroraGpioInitData_SW[0]), PlatformInfoHob->PlatformGpioSetting_SW);

    if (SystemConfiguration.TDO == 2) {  //Auto
      if (BxtA0 == BxtStepping()) {
        DEBUG ((DEBUG_INFO, " BxtA0 TDO disable\n" ));
      }
    } else if (SystemConfiguration.TDO == 0) { // Disable
      DEBUG ((DEBUG_INFO, " Setup option to disable TDO\n" ));
    }

    if (SystemConfiguration.ScHdAudioIoBufferOwnership == 3) {
      DEBUG ((DEBUG_INFO, "HD Audio IO Buffer Ownership is I2S. Change GPIO pin settings for it. \n" ));
      GpioPadConfigTable (sizeof (mAuroraGpioInitData_Audio_SSP6) / sizeof (mAuroraGpioInitData_Audio_SSP6[0]), mAuroraGpioInitData_Audio_SSP6);
    }

    if (SystemConfiguration.PcieRootPortEn[4] == FALSE) {
      DEBUG ((DEBUG_INFO, "Onboard LAN disable. \n" ));
      GpioPadConfigTable (sizeof (AuroraLomDisableGpio) / sizeof (AuroraLomDisableGpio[0]), AuroraLomDisableGpio);
    }

    if (SystemConfiguration.EPIEnable == 1) {
      DEBUG ((DEBUG_INFO, "Overriding GPIO 191 for EPI\n"));
      GpioPadConfigTable (sizeof (mAuroraGpioInitData_EPI_Override) / sizeof (mAuroraGpioInitData_EPI_Override[0]), mAuroraGpioInitData_EPI_Override);
    }
    if (SystemConfiguration.GpioLock == TRUE) {
      AuroraSetGpioPadCfgLock ();
    }
    DEBUG ((DEBUG_INFO, "No board ID available for this board ....\n"));
    break;
  }

  //
  // Dump Community registers
  //
  DumpGpioCommunityRegisters (NORTH);
  DumpGpioCommunityRegisters (NORTHWEST);
  DumpGpioCommunityRegisters (WEST);
  DumpGpioCommunityRegisters (SOUTHWEST);

  switch (PlatformInfoHob->BoardId) {
    case BOARD_ID_AURORA:
      //
      // PAD programming
      //
      DEBUG ((DEBUG_INFO, "Dump Community pad registers, Board ID: 0x%X\n", PlatformInfoHob->BoardId));
      DumpGpioPadTable (sizeof (mAuroraGpioInitData_N) / sizeof (mAuroraGpioInitData_N[0]), PlatformInfoHob->PlatformGpioSetting_N);
      DumpGpioPadTable (sizeof (mAuroraGpioInitData_NW) / sizeof (mAuroraGpioInitData_NW[0]), PlatformInfoHob->PlatformGpioSetting_NW);
      DumpGpioPadTable (sizeof (mAuroraGpioInitData_W) / sizeof (mAuroraGpioInitData_W[0]), PlatformInfoHob->PlatformGpioSetting_W);
      DumpGpioPadTable (sizeof (mAuroraGpioInitData_SW) / sizeof (mAuroraGpioInitData_SW[0]), PlatformInfoHob->PlatformGpioSetting_SW);
      break;
    default:
    //
    // Dump Community pad registers
    //
    DumpGpioPadTable (sizeof (mAuroraGpioInitData_N) / sizeof (mAuroraGpioInitData_N[0]), PlatformInfoHob->PlatformGpioSetting_N);
    DumpGpioPadTable (sizeof (mAuroraGpioInitData_NW) / sizeof (mAuroraGpioInitData_NW[0]), PlatformInfoHob->PlatformGpioSetting_NW);
    DumpGpioPadTable (sizeof (mAuroraGpioInitData_W) / sizeof (mAuroraGpioInitData_W[0]), PlatformInfoHob->PlatformGpioSetting_W);
    DumpGpioPadTable (sizeof (mAuroraGpioInitData_SW) / sizeof (mAuroraGpioInitData_SW[0]), PlatformInfoHob->PlatformGpioSetting_SW);

    break;
  }

  return EFI_SUCCESS;
}