/* EFI_SUCCESS - GPIO set as requested EFI_UNSUPPORTED - Mode is not supported EFI_INVALID_PARAMETER - Gpio pin is out of range  */
EFI_STATUS EFIAPI Set(IN EMBEDDED_GPIO *This, IN EMBEDDED_GPIO_PIN Gpio, IN EMBEDDED_GPIO_MODE Mode)
/* EFI_SUCCESS - GPIO set as requested EFI_UNSUPPORTED - Mode is not supported EFI_INVALID_PARAMETER - Gpio pin is out of range  */
EFI_STATUS EFIAPI Set(IN EMBEDDED_GPIO *This, IN EMBEDDED_GPIO_PIN Gpio, IN EMBEDDED_GPIO_MODE Mode)
{
  EFI_STATUS  Status;
  UINTN       Index, Offset, RegisterBase;
  Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
  ASSERT_EFI_ERROR (Status);
  switch (Mode) {
    case GPIO_MODE_INPUT:
      MmioAnd8 (
        RegisterBase + PL061_GPIO_DIR_REG,
        ~GPIO_PIN_MASK(Offset) & 0xFF
        );
      break;
    case GPIO_MODE_OUTPUT_0:
      MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK (Offset));
      PL061SetPins (RegisterBase, GPIO_PIN_MASK (Offset), 0);
      break;
    case GPIO_MODE_OUTPUT_1:
      MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK (Offset));
      PL061SetPins (RegisterBase, GPIO_PIN_MASK (Offset), 0xff);
      break;
    default:
      return EFI_UNSUPPORTED;
  }
  return EFI_SUCCESS;
}