\r
**/\r
\r
-\r
#include <PiDxe.h>\r
\r
#include <Library/BaseLib.h>\r
\r
#include "PL061Gpio.h"\r
\r
-PLATFORM_GPIO_CONTROLLER *mPL061PlatformGpio;\r
+PLATFORM_GPIO_CONTROLLER *mPL061PlatformGpio;\r
\r
EFI_STATUS\r
EFIAPI\r
PL061Locate (\r
- IN EMBEDDED_GPIO_PIN Gpio,\r
- OUT UINTN *ControllerIndex,\r
- OUT UINTN *ControllerOffset,\r
- OUT UINTN *RegisterBase\r
+ IN EMBEDDED_GPIO_PIN Gpio,\r
+ OUT UINTN *ControllerIndex,\r
+ OUT UINTN *ControllerOffset,\r
+ OUT UINTN *RegisterBase\r
)\r
{\r
- UINT32 Index;\r
+ UINT32 Index;\r
\r
for (Index = 0; Index < mPL061PlatformGpio->GpioControllerCount; Index++) {\r
- if ( (Gpio >= mPL061PlatformGpio->GpioController[Index].GpioIndex)\r
- && (Gpio < mPL061PlatformGpio->GpioController[Index].GpioIndex\r
- + mPL061PlatformGpio->GpioController[Index].InternalGpioCount)) {\r
- *ControllerIndex = Index;\r
+ if ( (Gpio >= mPL061PlatformGpio->GpioController[Index].GpioIndex)\r
+ && (Gpio < mPL061PlatformGpio->GpioController[Index].GpioIndex\r
+ + mPL061PlatformGpio->GpioController[Index].InternalGpioCount))\r
+ {\r
+ *ControllerIndex = Index;\r
*ControllerOffset = Gpio % mPL061PlatformGpio->GpioController[Index].InternalGpioCount;\r
- *RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase;\r
+ *RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase;\r
return EFI_SUCCESS;\r
}\r
}\r
+\r
DEBUG ((DEBUG_ERROR, "%a, failed to locate gpio %d\n", __func__, Gpio));\r
return EFI_INVALID_PARAMETER;\r
}\r
UINTN\r
EFIAPI\r
PL061EffectiveAddress (\r
- IN UINTN Address,\r
- IN UINTN Mask\r
+ IN UINTN Address,\r
+ IN UINTN Mask\r
)\r
{\r
return ((Address + PL061_GPIO_DATA_REG_OFFSET) + (Mask << 2));\r
UINTN\r
EFIAPI\r
PL061GetPins (\r
- IN UINTN Address,\r
- IN UINTN Mask\r
+ IN UINTN Address,\r
+ IN UINTN Mask\r
)\r
{\r
return MmioRead8 (PL061EffectiveAddress (Address, Mask));\r
VOID\r
EFIAPI\r
PL061SetPins (\r
- IN UINTN Address,\r
- IN UINTN Mask,\r
- IN UINTN Value\r
+ IN UINTN Address,\r
+ IN UINTN Mask,\r
+ IN UINTN Value\r
)\r
{\r
MmioWrite8 (PL061EffectiveAddress (Address, Mask), Value);\r
/**\r
Function implementations\r
**/\r
-\r
EFI_STATUS\r
PL061Identify (\r
VOID\r
)\r
{\r
- UINTN Index;\r
- UINTN RegisterBase;\r
+ UINTN Index;\r
+ UINTN RegisterBase;\r
\r
- if ( (mPL061PlatformGpio->GpioCount == 0)\r
- || (mPL061PlatformGpio->GpioControllerCount == 0)) {\r
- return EFI_NOT_FOUND;\r
+ if ( (mPL061PlatformGpio->GpioCount == 0)\r
+ || (mPL061PlatformGpio->GpioControllerCount == 0))\r
+ {\r
+ return EFI_NOT_FOUND;\r
}\r
\r
for (Index = 0; Index < mPL061PlatformGpio->GpioControllerCount; Index++) {\r
RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase;\r
\r
// Check if this is a PrimeCell Peripheral\r
- if ( (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID0) != 0x0D)\r
- || (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID1) != 0xF0)\r
- || (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID2) != 0x05)\r
- || (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID3) != 0xB1)) {\r
+ if ( (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID0) != 0x0D)\r
+ || (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID1) != 0xF0)\r
+ || (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID2) != 0x05)\r
+ || (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID3) != 0xB1))\r
+ {\r
return EFI_NOT_FOUND;\r
}\r
\r
// Check if this PrimeCell Peripheral is the PL061 GPIO\r
- if ( (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID0) != 0x61)\r
- || (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID1) != 0x10)\r
- || ((MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID2) & 0xF) != 0x04)\r
- || (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID3) != 0x00)) {\r
+ if ( (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID0) != 0x61)\r
+ || (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID1) != 0x10)\r
+ || ((MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID2) & 0xF) != 0x04)\r
+ || (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID3) != 0x00))\r
+ {\r
return EFI_NOT_FOUND;\r
}\r
}\r
EFI_STATUS\r
EFIAPI\r
Get (\r
- IN EMBEDDED_GPIO *This,\r
- IN EMBEDDED_GPIO_PIN Gpio,\r
- OUT UINTN *Value\r
+ IN EMBEDDED_GPIO *This,\r
+ IN EMBEDDED_GPIO_PIN Gpio,\r
+ OUT UINTN *Value\r
)\r
{\r
- EFI_STATUS Status;\r
- UINTN Index, Offset, RegisterBase;\r
+ EFI_STATUS Status;\r
+ UINTN Index, Offset, RegisterBase;\r
\r
Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);\r
ASSERT_EFI_ERROR (Status);\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
- if (PL061GetPins (RegisterBase, GPIO_PIN_MASK(Offset)) != 0) {\r
+ if (PL061GetPins (RegisterBase, GPIO_PIN_MASK (Offset)) != 0) {\r
*Value = 1;\r
} else {\r
*Value = 0;\r
IN EMBEDDED_GPIO_MODE Mode\r
)\r
{\r
- EFI_STATUS Status;\r
- UINTN Index, Offset, RegisterBase;\r
+ EFI_STATUS Status;\r
+ UINTN Index, Offset, RegisterBase;\r
\r
Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);\r
ASSERT_EFI_ERROR (Status);\r
\r
- switch (Mode)\r
- {\r
+ switch (Mode) {\r
case GPIO_MODE_INPUT:\r
// Set the corresponding direction bit to LOW for input\r
- MmioAnd8 (RegisterBase + PL061_GPIO_DIR_REG,\r
- ~GPIO_PIN_MASK(Offset) & 0xFF);\r
+ MmioAnd8 (\r
+ RegisterBase + PL061_GPIO_DIR_REG,\r
+ ~GPIO_PIN_MASK(Offset) & 0xFF\r
+ );\r
break;\r
\r
case GPIO_MODE_OUTPUT_0:\r
// Set the corresponding direction bit to HIGH for output\r
- MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset));\r
+ MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK (Offset));\r
// Set the corresponding data bit to LOW for 0\r
- PL061SetPins (RegisterBase, GPIO_PIN_MASK(Offset), 0);\r
+ PL061SetPins (RegisterBase, GPIO_PIN_MASK (Offset), 0);\r
break;\r
\r
case GPIO_MODE_OUTPUT_1:\r
// Set the corresponding direction bit to HIGH for output\r
- MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset));\r
+ MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK (Offset));\r
// Set the corresponding data bit to HIGH for 1\r
- PL061SetPins (RegisterBase, GPIO_PIN_MASK(Offset), 0xff);\r
+ PL061SetPins (RegisterBase, GPIO_PIN_MASK (Offset), 0xff);\r
break;\r
\r
default:\r
OUT EMBEDDED_GPIO_MODE *Mode\r
)\r
{\r
- EFI_STATUS Status;\r
- UINTN Index, Offset, RegisterBase;\r
+ EFI_STATUS Status;\r
+ UINTN Index, Offset, RegisterBase;\r
\r
Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);\r
ASSERT_EFI_ERROR (Status);\r
}\r
\r
// Check if it is input or output\r
- if (MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK(Offset)) {\r
+ if (MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK (Offset)) {\r
// Pin set to output\r
- if (PL061GetPins (RegisterBase, GPIO_PIN_MASK(Offset)) != 0) {\r
+ if (PL061GetPins (RegisterBase, GPIO_PIN_MASK (Offset)) != 0) {\r
*Mode = GPIO_MODE_OUTPUT_1;\r
} else {\r
*Mode = GPIO_MODE_OUTPUT_0;\r
/**\r
Protocol variable definition\r
**/\r
-EMBEDDED_GPIO gGpio = {\r
+EMBEDDED_GPIO gGpio = {\r
Get,\r
Set,\r
GetMode,\r
EFI_STATUS\r
EFIAPI\r
PL061InstallProtocol (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
)\r
{\r
- EFI_STATUS Status;\r
- EFI_HANDLE Handle;\r
- GPIO_CONTROLLER *GpioController;\r
+ EFI_STATUS Status;\r
+ EFI_HANDLE Handle;\r
+ GPIO_CONTROLLER *GpioController;\r
\r
//\r
// Make sure the Gpio protocol has not been installed in the system yet.\r
return EFI_BAD_BUFFER_SIZE;\r
}\r
\r
- mPL061PlatformGpio->GpioCount = PL061_GPIO_PINS;\r
+ mPL061PlatformGpio->GpioCount = PL061_GPIO_PINS;\r
mPL061PlatformGpio->GpioControllerCount = 1;\r
- mPL061PlatformGpio->GpioController = (GPIO_CONTROLLER *)((UINTN) mPL061PlatformGpio + sizeof (PLATFORM_GPIO_CONTROLLER));\r
+ mPL061PlatformGpio->GpioController = (GPIO_CONTROLLER *)((UINTN)mPL061PlatformGpio + sizeof (PLATFORM_GPIO_CONTROLLER));\r
\r
- GpioController = mPL061PlatformGpio->GpioController;\r
- GpioController->RegisterBase = (UINTN) PcdGet32 (PcdPL061GpioBase);\r
- GpioController->GpioIndex = 0;\r
+ GpioController = mPL061PlatformGpio->GpioController;\r
+ GpioController->RegisterBase = (UINTN)PcdGet32 (PcdPL061GpioBase);\r
+ GpioController->GpioIndex = 0;\r
GpioController->InternalGpioCount = PL061_GPIO_PINS;\r
}\r
\r
- Status = PL061Identify();\r
- if (EFI_ERROR(Status)) {\r
+ Status = PL061Identify ();\r
+ if (EFI_ERROR (Status)) {\r
return EFI_DEVICE_ERROR;\r
}\r
\r
// Install the Embedded GPIO Protocol onto a new handle\r
Handle = NULL;\r
- Status = gBS->InstallMultipleProtocolInterfaces(\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
&Handle,\r
- &gEmbeddedGpioProtocolGuid, &gGpio,\r
+ &gEmbeddedGpioProtocolGuid,\r
+ &gGpio,\r
NULL\r
- );\r
- if (EFI_ERROR(Status)) {\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
Status = EFI_OUT_OF_RESOURCES;\r
}\r
\r