31 IN EMBEDDED_GPIO_PIN Gpio,
39 for (Index = 0; Index < mPL061PlatformGpio->GpioControllerCount; Index++) {
40 if ( (Gpio >= mPL061PlatformGpio->GpioController[Index].GpioIndex)
41 && (Gpio < mPL061PlatformGpio->GpioController[Index].GpioIndex
42 + mPL061PlatformGpio->GpioController[Index].InternalGpioCount))
44 *ControllerIndex = Index;
45 *ControllerOffset = Gpio % mPL061PlatformGpio->GpioController[Index].InternalGpioCount;
46 *RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase;
51 DEBUG ((DEBUG_ERROR,
"%a, failed to locate gpio %d\n", __func__, Gpio));
52 return EFI_INVALID_PARAMETER;
75PL061EffectiveAddress (
80 return ((Address + PL061_GPIO_DATA_REG_OFFSET) + (
UINTN)(Mask << 2));
91 return MmioRead8 (PL061EffectiveAddress (Address, Mask));
103 MmioWrite8 (PL061EffectiveAddress (Address, Mask), Value);
117 if ( (mPL061PlatformGpio->GpioCount == 0)
118 || (mPL061PlatformGpio->GpioControllerCount == 0))
120 return EFI_NOT_FOUND;
123 for (Index = 0; Index < mPL061PlatformGpio->GpioControllerCount; Index++) {
124 if (mPL061PlatformGpio->GpioController[Index].InternalGpioCount != PL061_GPIO_PINS) {
125 return EFI_INVALID_PARAMETER;
128 RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase;
131 if ( (
MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID0) != 0x0D)
132 || (
MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID1) != 0xF0)
133 || (
MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID2) != 0x05)
134 || (
MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID3) != 0xB1))
136 return EFI_NOT_FOUND;
140 if ( (
MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID0) != 0x61)
141 || (
MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID1) != 0x10)
142 || ((
MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID2) & 0xF) != 0x04)
143 || (
MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID3) != 0x00))
145 return EFI_NOT_FOUND;
173 IN EMBEDDED_GPIO_PIN Gpio,
178 UINTN Index, Offset, RegisterBase;
181 return EFI_INVALID_PARAMETER;
184 Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
185 if (EFI_ERROR (Status)) {
190 if (PL061GetPins (RegisterBase, GPIO_PIN_MASK (Offset)) != 0) {
221 IN EMBEDDED_GPIO_PIN Gpio,
222 IN EMBEDDED_GPIO_MODE Mode
226 UINTN Index, Offset, RegisterBase;
228 Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
229 if (EFI_ERROR (Status)) {
235 case GPIO_MODE_INPUT:
238 RegisterBase + PL061_GPIO_DIR_REG,
239 ~GPIO_PIN_MASK(Offset) & 0xFF
243 case GPIO_MODE_OUTPUT_0:
245 MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK (Offset));
247 PL061SetPins (RegisterBase, GPIO_PIN_MASK (Offset), 0);
250 case GPIO_MODE_OUTPUT_1:
252 MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK (Offset));
254 PL061SetPins (RegisterBase, GPIO_PIN_MASK (Offset), 0xff);
259 return EFI_UNSUPPORTED;
287 IN EMBEDDED_GPIO_PIN Gpio,
288 OUT EMBEDDED_GPIO_MODE *Mode
292 UINTN Index, Offset, RegisterBase;
296 return EFI_INVALID_PARAMETER;
299 Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
300 if (EFI_ERROR (Status)) {
306 if (
MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK (Offset)) {
308 if (PL061GetPins (RegisterBase, GPIO_PIN_MASK (Offset)) != 0) {
309 *Mode = GPIO_MODE_OUTPUT_1;
311 *Mode = GPIO_MODE_OUTPUT_0;
315 *Mode = GPIO_MODE_INPUT;
342 IN EMBEDDED_GPIO_PIN Gpio,
343 IN EMBEDDED_GPIO_PULL Direction
346 return EFI_UNSUPPORTED;
386 Status =
gBS->LocateProtocol (&gPlatformGpioProtocolGuid,
NULL, (VOID **)&mPL061PlatformGpio);
387 if (EFI_ERROR (Status) && (Status == EFI_NOT_FOUND)) {
390 if (mPL061PlatformGpio ==
NULL) {
391 DEBUG ((DEBUG_ERROR,
"%a: failed to allocate PLATFORM_GPIO_CONTROLLER\n", __func__));
392 return EFI_BAD_BUFFER_SIZE;
395 mPL061PlatformGpio->GpioCount = PL061_GPIO_PINS;
396 mPL061PlatformGpio->GpioControllerCount = 1;
399 GpioController = mPL061PlatformGpio->GpioController;
400 GpioController->RegisterBase = (
UINTN)
PcdGet32 (PcdPL061GpioBase);
401 GpioController->GpioIndex = 0;
402 GpioController->InternalGpioCount = PL061_GPIO_PINS;
406 if (EFI_ERROR (Status)) {
407 return EFI_DEVICE_ERROR;
412 Status =
gBS->InstallMultipleProtocolInterfaces (
414 &gEmbeddedGpioProtocolGuid,
418 if (EFI_ERROR (Status)) {
419 Status = EFI_OUT_OF_RESOURCES;
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
UINT8 EFIAPI MmioAnd8(IN UINTN Address, IN UINT8 AndData)
UINT8 EFIAPI MmioRead8(IN UINTN Address)
UINT8 EFIAPI MmioOr8(IN UINTN Address, IN UINT8 OrData)
UINT8 EFIAPI MmioWrite8(IN UINTN Address, IN UINT8 Value)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)
EFI_STATUS PL061Identify(VOID)
EFI_STATUS EFIAPI Get(IN EMBEDDED_GPIO *This, IN EMBEDDED_GPIO_PIN Gpio, OUT UINTN *Value)
EFI_STATUS EFIAPI SetPull(IN EMBEDDED_GPIO *This, IN EMBEDDED_GPIO_PIN Gpio, IN EMBEDDED_GPIO_PULL Direction)
EFI_STATUS EFIAPI PL061InstallProtocol(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI GetMode(IN EMBEDDED_GPIO *This, IN EMBEDDED_GPIO_PIN Gpio, OUT EMBEDDED_GPIO_MODE *Mode)
EFI_STATUS EFIAPI Set(IN EMBEDDED_GPIO *This, IN EMBEDDED_GPIO_PIN Gpio, IN EMBEDDED_GPIO_MODE Mode)
#define PcdGet32(TokenName)