]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Drivers/PL061GpioDxe/PL061Gpio.c
ArmPlatformPkg: PL061 - only initialize on protocol load
[mirror_edk2.git] / ArmPlatformPkg / Drivers / PL061GpioDxe / PL061Gpio.c
index ff05662b885d71611adafe7aeeaa97eec6faf872..c8125fd0e08f261af88e9642f735690bb33ac29d 100644 (file)
@@ -1,11 +1,12 @@
 /** @file\r
 *\r
 *  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2016, Linaro Limited. All rights reserved.\r
 *\r
 *  This program and the accompanying materials\r
-*  are licensed and made available under the terms and conditions of the BSD License\r
-*  which accompanies this distribution.  The full text of the license may be found at\r
-*  http://opensource.org/licenses/bsd-license.php\r
+*  are licensed and made available under the terms and conditions of the BSD\r
+*  License which accompanies this distribution.  The full text of the license\r
+*  may be found at http://opensource.org/licenses/bsd-license.php\r
 *\r
 *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 *  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
@@ -27,7 +28,6 @@
 #include <Protocol/EmbeddedGpio.h>\r
 #include <Drivers/PL061Gpio.h>\r
 \r
-BOOLEAN     mPL061Initialized = FALSE;\r
 \r
 /**\r
   Function implementations\r
@@ -78,8 +78,6 @@ PL061Initialize (
   //   // Ensure interrupts are disabled\r
   //}\r
 \r
-  mPL061Initialized = TRUE;\r
-\r
   EXIT:\r
   return Status;\r
 }\r
@@ -109,30 +107,19 @@ Get (
   OUT UINTN             *Value\r
   )\r
 {\r
-  EFI_STATUS    Status = EFI_SUCCESS;\r
-\r
   if (    (Value == NULL)\r
       ||  (Gpio > LAST_GPIO_PIN))\r
   {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  // Initialize the hardware if not already done\r
-  if (!mPL061Initialized) {\r
-    Status = PL061Initialize();\r
-    if (EFI_ERROR(Status)) {\r
-      goto EXIT;\r
-    }\r
-  }\r
-\r
   if (MmioRead8 (PL061_GPIO_DATA_REG) & GPIO_PIN_MASK_HIGH_8BIT(Gpio)) {\r
     *Value = 1;\r
   } else {\r
     *Value = 0;\r
   }\r
 \r
-  EXIT:\r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -169,14 +156,6 @@ Set (
     goto EXIT;\r
   }\r
 \r
-  // Initialize the hardware if not already done\r
-  if (!mPL061Initialized) {\r
-    Status = PL061Initialize();\r
-    if (EFI_ERROR(Status)) {\r
-      goto EXIT;\r
-    }\r
-  }\r
-\r
   switch (Mode)\r
   {\r
     case GPIO_MODE_INPUT:\r
@@ -233,22 +212,12 @@ GetMode (
   OUT EMBEDDED_GPIO_MODE  *Mode\r
   )\r
 {\r
-  EFI_STATUS Status;\r
-\r
   // Check for errors\r
   if (    (Mode == NULL)\r
       ||  (Gpio > LAST_GPIO_PIN)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  // Initialize the hardware if not already done\r
-  if (!mPL061Initialized) {\r
-    Status = PL061Initialize();\r
-    if (EFI_ERROR(Status)) {\r
-      return Status;\r
-    }\r
-  }\r
-\r
   // Check if it is input or output\r
   if (MmioRead8 (PL061_GPIO_DIR_REG) & GPIO_PIN_MASK_HIGH_8BIT(Gpio)) {\r
     // Pin set to output\r
@@ -329,6 +298,11 @@ PL061InstallProtocol (
   //\r
   ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEmbeddedGpioProtocolGuid);\r
 \r
+  Status = PL061Initialize();\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