/* EFI_SUCCESS - mode value retrieved EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range  */
EFI_STATUS EFIAPI GetMode(IN EMBEDDED_GPIO *This, IN EMBEDDED_GPIO_PIN Gpio, OUT EMBEDDED_GPIO_MODE *Mode)
/* EFI_SUCCESS - mode value retrieved EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range  */
EFI_STATUS EFIAPI GetMode(IN EMBEDDED_GPIO *This, IN EMBEDDED_GPIO_PIN Gpio, OUT EMBEDDED_GPIO_MODE *Mode)
{
  EFI_STATUS  Status;
  UINTN       Index, Offset, RegisterBase;
  Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
  ASSERT_EFI_ERROR (Status);
  if (Mode == NULL) {
    return EFI_INVALID_PARAMETER;
  }
  if (MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK (Offset)) {
    if (PL061GetPins (RegisterBase, GPIO_PIN_MASK (Offset)) != 0) {
      *Mode = GPIO_MODE_OUTPUT_1;
    } else {
      *Mode = GPIO_MODE_OUTPUT_0;
    }
  } else {
    *Mode = GPIO_MODE_INPUT;
  }
  return EFI_SUCCESS;
}