ArmPlatformPkg: Introduce ArmPlatformSysConfigLib
authoroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 11 Jun 2011 11:08:34 +0000 (11:08 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 11 Jun 2011 11:08:34 +0000 (11:08 +0000)
The purpose of this library is to create an interface to communicate
with the platform micro-controller.
It abstracts the communication protocol (eg: SPI, UART, etc) between
the application processor and the micro-controller.

ArmPlatformPkg/ArmVExpressPkg: Implement ArmPlaformSysConfigLib

This implementation allows to communicate with the microcontroller of the
Versatile Express motherboard.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11785 6f19259b-4bc3-4df7-8a09-765794883524

ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-CTA9x4.dsc
ArmPlatformPkg/ArmVExpressPkg/Include/VExpressMotherBoard.h
ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfig.c [new file with mode: 0644]
ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf [new file with mode: 0644]
ArmPlatformPkg/Include/Library/ArmPlatformSysConfigLib.h [new file with mode: 0644]

index 75362e1..628c407 100644 (file)
   # ARM PL011 UART Driver
   PL011UartLib|ArmPlatformPkg/Drivers/PL011Uart/PL011Uart.inf
   
+  ArmPlatformSysConfigLib|ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf
   NorFlashPlatformLib|ArmPlatformPkg/ArmVExpressPkg/Library/NorFlashArmVExpressLib/NorFlashArmVExpressLib.inf
 
 #
index 3fcd74f..f927369 100644 (file)
 #define ARM_VE_DAUGHTERBOARD_1_SITE               1\r
 #define ARM_VE_DAUGHTERBOARD_2_SITE               2\r
 \r
+#define VIRTUAL_SYS_CFG(site,func)                (((site) << 24) | (func))\r
+\r
+//\r
+// System Configuration Control Functions\r
+//\r
+#define SYS_CFG_OSC                               1\r
+#define SYS_CFG_VOLT                              2\r
+#define SYS_CFG_AMP                               3\r
+#define SYS_CFG_TEMP                              4\r
+#define SYS_CFG_RESET                             5\r
+#define SYS_CFG_SCC                               6\r
+#define SYS_CFG_MUXFPGA                           7\r
+#define SYS_CFG_SHUTDOWN                          8\r
+#define SYS_CFG_REBOOT                            9\r
+#define SYS_CFG_DVIMODE                           11\r
+#define SYS_CFG_POWER                             12\r
+// Oscillator for Site 1\r
+#define SYS_CFG_OSC_SITE1                         VIRTUAL_SYS_CFG(ARM_VE_DAUGHTERBOARD_1_SITE,SYS_CFG_OSC)\r
+// Oscillator for Site 2\r
+#define SYS_CFG_OSC_SITE2                         VIRTUAL_SYS_CFG(ARM_VE_DAUGHTERBOARD_2_SITE,SYS_CFG_OSC)\r
+// Can not access the battery backed-up hardware clock on the Versatile Express motherboard\r
+#define SYS_CFG_RTC                               VIRTUAL_SYS_CFG(ARM_VE_UNSUPPORTED,1)\r
+\r
 #endif /* VEXPRESSMOTHERBOARD_H_ */\r
diff --git a/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfig.c b/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfig.c
new file mode 100644 (file)
index 0000000..27ef0a7
--- /dev/null
@@ -0,0 +1,255 @@
+/** @file  SysCfgArmVExpress.c\r
+\r
+  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\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
+\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
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Library/IoLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#include <Library/ArmPlatformSysConfigLib.h>\r
+#include <ArmPlatform.h>\r
+\r
+//\r
+// SYS_CFGCTRL Bits\r
+//\r
+#define SYS_CFGCTRL_START                 BIT31\r
+#define SYS_CFGCTRL_READ                  (0 << 30)\r
+#define SYS_CFGCTRL_WRITE                 (1 << 30)\r
+#define SYS_CFGCTRL_FUNCTION(fun)         (((fun ) &  0x3F) << 20)\r
+#define SYS_CFGCTRL_SITE(site)            (((site) &   0x3) << 16)\r
+#define SYS_CFGCTRL_POSITION(pos)         (((pos ) &   0xF) << 12)\r
+#define SYS_CFGCTRL_DEVICE(dev)            ((dev ) & 0xFFF)\r
+\r
+//\r
+// SYS_CFGSTAT Bits\r
+//\r
+#define SYS_CFGSTAT_ERROR                 BIT1\r
+#define SYS_CFGSTAT_COMPLETE              BIT0\r
+\r
+/****************************************************************************\r
+ *\r
+ *  This file makes it easier to access the System Configuration Registers\r
+ *  in the ARM Versatile Express motherboard.\r
+ *\r
+ ****************************************************************************/\r
+\r
+EFI_STATUS\r
+ArmPlatformSysConfigInitialize (\r
+  VOID\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/***************************************\r
+ * GENERAL FUNCTION: AccessSysCfgRegister\r
+ * Interacts with\r
+ *    SYS_CFGSTAT\r
+ *    SYS_CFGDATA\r
+ *    SYS_CFGCTRL\r
+ * for setting and for reading out values\r
+ ***************************************/\r
+\r
+EFI_STATUS\r
+AccessSysCfgRegister (\r
+  IN     UINT32   ReadWrite,\r
+  IN     UINT32   Function,\r
+  IN     UINT32   Site,\r
+  IN     UINT32   Position,\r
+  IN     UINT32   Device,\r
+  IN OUT UINT32*  Data\r
+  )\r
+{\r
+  UINT32          SysCfgCtrl;\r
+\r
+  // Clear the COMPLETE bit\r
+  MmioAnd32(ARM_VE_SYS_CFGSTAT_REG, ~SYS_CFGSTAT_COMPLETE);\r
+\r
+  // If writing, then set the data value\r
+  if(ReadWrite == SYS_CFGCTRL_WRITE) {\r
+    MmioWrite32(ARM_VE_SYS_CFGDATA_REG, *Data);\r
+  }\r
+\r
+  // Set the control value\r
+  SysCfgCtrl = SYS_CFGCTRL_START | ReadWrite | SYS_CFGCTRL_FUNCTION(Function) | SYS_CFGCTRL_SITE(Site) |\r
+      SYS_CFGCTRL_POSITION(Position) | SYS_CFGCTRL_DEVICE(Device);\r
+  MmioWrite32(ARM_VE_SYS_CFGCTRL_REG, SysCfgCtrl);\r
+\r
+  // Wait until the COMPLETE bit is set\r
+  while ((MmioRead32(ARM_VE_SYS_CFGSTAT_REG) & SYS_CFGSTAT_COMPLETE) == 0);\r
+\r
+  // Check for errors\r
+  if(MmioRead32(ARM_VE_SYS_CFGSTAT_REG) & SYS_CFGSTAT_ERROR) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  // If reading then get the data value\r
+  if(ReadWrite == SYS_CFGCTRL_READ) {\r
+    *Data = MmioRead32(ARM_VE_SYS_CFGDATA_REG);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+ArmPlatformSysConfigGet (\r
+  IN  SYS_CONFIG_FUNCTION   Function,\r
+  OUT UINT32*               Value\r
+  )\r
+{\r
+  UINT32          Site;\r
+  UINT32          Position;\r
+  UINT32          Device;\r
+\r
+  Position = 0;\r
+  Device = 0;\r
+\r
+  // Intercept some functions\r
+  switch(Function) {\r
+\r
+  case SYS_CFG_OSC_SITE1:\r
+    Function = SYS_CFG_OSC;\r
+    Site = ARM_VE_DAUGHTERBOARD_1_SITE;\r
+    break;\r
+\r
+  case SYS_CFG_OSC_SITE2:\r
+    Function = SYS_CFG_OSC;\r
+    Site = ARM_VE_DAUGHTERBOARD_2_SITE;\r
+    break;\r
+\r
+  case SYS_CFG_MUXFPGA:\r
+    Site = *Value;\r
+    break;\r
+\r
+  case SYS_CFG_OSC:\r
+  case SYS_CFG_VOLT:\r
+  case SYS_CFG_AMP:\r
+  case SYS_CFG_TEMP:\r
+  case SYS_CFG_RESET:\r
+  case SYS_CFG_SCC:\r
+  case SYS_CFG_DVIMODE:\r
+  case SYS_CFG_POWER:\r
+    Site = ARM_VE_MOTHERBOARD_SITE;\r
+    break;\r
+\r
+  case SYS_CFG_SHUTDOWN:\r
+  case SYS_CFG_REBOOT:\r
+  case SYS_CFG_RTC:\r
+  default:\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return AccessSysCfgRegister (SYS_CFGCTRL_READ, Function, Site, Position, Device, Value);\r
+}\r
+\r
+EFI_STATUS\r
+ArmPlatformSysConfigSet (\r
+  IN  SYS_CONFIG_FUNCTION   Function,\r
+  IN  UINT32                Value\r
+  )\r
+{\r
+  UINT32          Site;\r
+  UINT32          Position;\r
+  UINT32          Device;\r
+\r
+  Position = 0;\r
+  Device = 0;\r
+\r
+  // Intercept some functions\r
+  switch(Function) {\r
+\r
+  case SYS_CFG_OSC_SITE1:\r
+    Function = SYS_CFG_OSC;\r
+    Site = ARM_VE_DAUGHTERBOARD_1_SITE;\r
+    break;\r
+\r
+  case SYS_CFG_OSC_SITE2:\r
+    Function = SYS_CFG_OSC;\r
+    Site = ARM_VE_DAUGHTERBOARD_2_SITE;\r
+    break;\r
+\r
+  case SYS_CFG_MUXFPGA:\r
+    Site = Value;\r
+    break;\r
+\r
+  case SYS_CFG_RESET:\r
+  case SYS_CFG_SCC:\r
+  case SYS_CFG_SHUTDOWN:\r
+  case SYS_CFG_REBOOT:\r
+  case SYS_CFG_DVIMODE:\r
+  case SYS_CFG_POWER:\r
+    Site = ARM_VE_MOTHERBOARD_SITE;\r
+    break;\r
+\r
+  case SYS_CFG_OSC:\r
+  case SYS_CFG_VOLT:\r
+  case SYS_CFG_AMP:\r
+  case SYS_CFG_TEMP:\r
+  case SYS_CFG_RTC:\r
+  default:\r
+    return(EFI_UNSUPPORTED);\r
+  }\r
+\r
+  return AccessSysCfgRegister (SYS_CFGCTRL_WRITE, Function, Site, Position, Device, &Value);\r
+}\r
+\r
+EFI_STATUS\r
+ArmPlatformSysConfigSetDevice (\r
+  IN  SYS_CONFIG_FUNCTION   Function,\r
+  IN  UINT32                Device,\r
+  IN  UINT32                Value\r
+  )\r
+{\r
+  UINT32          Site;\r
+  UINT32          Position;\r
+\r
+  Position = 0;\r
+\r
+  // Intercept some functions\r
+  switch(Function) {\r
+\r
+  case SYS_CFG_OSC_SITE1:\r
+    Function = SYS_CFG_OSC;\r
+    Site = ARM_VE_DAUGHTERBOARD_1_SITE;\r
+    break;\r
+\r
+  case SYS_CFG_OSC_SITE2:\r
+    Function = SYS_CFG_OSC;\r
+    Site = ARM_VE_DAUGHTERBOARD_2_SITE;\r
+    break;\r
+\r
+  case SYS_CFG_MUXFPGA:\r
+    Site = Value;\r
+    break;\r
+\r
+  case SYS_CFG_RTC:\r
+    return(EFI_UNSUPPORTED);\r
+    //break;\r
+\r
+  case SYS_CFG_OSC:\r
+  case SYS_CFG_VOLT:\r
+  case SYS_CFG_AMP:\r
+  case SYS_CFG_TEMP:\r
+  case SYS_CFG_RESET:\r
+  case SYS_CFG_SCC:\r
+  case SYS_CFG_SHUTDOWN:\r
+  case SYS_CFG_REBOOT:\r
+  case SYS_CFG_DVIMODE:\r
+  case SYS_CFG_POWER:\r
+    Site = ARM_VE_MOTHERBOARD_SITE;\r
+    break;\r
+  default:\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return AccessSysCfgRegister (SYS_CFGCTRL_WRITE, Function, Site, Position, Device, &Value);\r
+}\r
diff --git a/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf b/ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfigLib.inf
new file mode 100644 (file)
index 0000000..01027cc
--- /dev/null
@@ -0,0 +1,45 @@
+#/** @file
+#  
+#  Component discription file for ArmVeGraphicsDxe module
+#  
+#  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD License
+#  which accompanies this distribution.  The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.php
+#  
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#  
+#**/
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = ArmVExpressSysConfigLib
+  FILE_GUID                      = a05b5cc0-82d2-11e0-82cb-0002a5d5c51b
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = ArmPlatformSysConfigLib
+  
+[Sources.common]
+  ArmVExpressSysConfig.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  ArmPlatformPkg/ArmVExpressPkg/ArmVExpressPkg.dec
+  ArmPlatformPkg/ArmPlatformPkg.dec
+
+[LibraryClasses]
+  BaseLib
+
+[Guids]
+
+[Protocols]
+
+[FeaturePcd]
+
+[FixedPcd.common]
+  
+[Pcd.common]
+
+[Depex]
diff --git a/ArmPlatformPkg/Include/Library/ArmPlatformSysConfigLib.h b/ArmPlatformPkg/Include/Library/ArmPlatformSysConfigLib.h
new file mode 100644 (file)
index 0000000..6285583
--- /dev/null
@@ -0,0 +1,55 @@
+/** @file  ArmPlatformSysConfigLib.h
+
+  Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef __ARM_PLATFORM_SYS_CONFIG_H__
+#define __ARM_PLATFORM_SYS_CONFIG_H__
+
+#include <Base.h>
+
+/* This header file makes it easier to access the System Configuration Registers
+ * in the ARM Versatile Express motherboard.
+ */
+
+//
+// Typedef
+//
+typedef UINT32  SYS_CONFIG_FUNCTION;
+
+//
+// Functions
+//
+EFI_STATUS
+ArmPlatformSysConfigInitialize (
+  VOID
+  );
+
+EFI_STATUS
+ArmPlatformSysConfigGet (
+  IN  SYS_CONFIG_FUNCTION   Function,
+  OUT UINT32*               Value
+  );
+
+EFI_STATUS
+ArmPlatformSysConfigSet (
+  IN  SYS_CONFIG_FUNCTION   Function,
+  IN  UINT32                Value
+  );
+
+EFI_STATUS
+ArmPlatformSysConfigSetDevice (
+  IN  SYS_CONFIG_FUNCTION   Function,
+  IN  UINT32                Device,
+  IN  UINT32                Value
+  );
+
+#endif /* __SYS_CFG_REGISTERS_H__ */