]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c
ArmPlatformPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmPlatformPkg / Drivers / PL061GpioDxe / PL061Gpio.c
index 8057cbb5518c80687567e0a1e4720b49e93de8c6..d87ab3d3dee7d45e7dc21db6960f80c0f6f74c02 100644 (file)
@@ -7,7 +7,6 @@
 \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
@@ -72,8 +73,8 @@ STATIC
 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
@@ -83,8 +84,8 @@ STATIC
 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
@@ -94,9 +95,9 @@ STATIC
 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
@@ -105,18 +106,18 @@ PL061SetPins (
 /**\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
@@ -127,18 +128,20 @@ PL061Identify (
     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
@@ -166,13 +169,13 @@ Returns:
 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
@@ -181,7 +184,7 @@ Get (
     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
@@ -216,32 +219,33 @@ Set (
   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
@@ -278,8 +282,8 @@ GetMode (
   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
@@ -290,9 +294,9 @@ GetMode (
   }\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
@@ -336,7 +340,7 @@ SetPull (
 /**\r
  Protocol variable definition\r
  **/\r
-EMBEDDED_GPIO gGpio = {\r
+EMBEDDED_GPIO  gGpio = {\r
   Get,\r
   Set,\r
   GetMode,\r
@@ -357,13 +361,13 @@ EMBEDDED_GPIO gGpio = {
 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
@@ -379,29 +383,30 @@ PL061InstallProtocol (
       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