diff mbox series

[edk2,v2,edk-platforms,4/4] Platform/Hisilicon/HiKey: enable virtual keyboard

Message ID 1520515856-29683-1-git-send-email-haojian.zhuang@linaro.org
State Superseded
Headers show
Series enable virtual keyboards on hikey | expand

Commit Message

Haojian Zhuang March 8, 2018, 1:30 p.m. UTC
Enable virtual keyboard driver on HiKey platform. The platform
driver reads pattern from memory or GPIO pin. When the value
is matched, it simulates a key value that is used to adjust
the sequence of boot options.

Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>

---
 Platform/Hisilicon/HiKey/HiKey.dsc                |   8 +
 Platform/Hisilicon/HiKey/HiKey.fdf                |   8 +
 Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf    |  57 +++++
 Silicon/Hisilicon/Hi6220/Include/Hi6220RegsPeri.h |  48 ++++
 Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c      | 229 ++++++++++++++++++++
 5 files changed, 350 insertions(+)

-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Leif Lindholm May 2, 2018, 11:13 p.m. UTC | #1
On Thu, Mar 08, 2018 at 09:30:56PM +0800, Haojian Zhuang wrote:
> Enable virtual keyboard driver on HiKey platform. The platform

> driver reads pattern from memory or GPIO pin. When the value

> is matched, it simulates a key value that is used to adjust

> the sequence of boot options.


The addition of HiKeyDxe and the enabling of virtual keyboard support
should be separate patches, just like for 2/4.


> Cc: Leif Lindholm <leif.lindholm@linaro.org>

> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> Contributed-under: TianoCore Contribution Agreement 1.1

> Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>

> ---

>  Platform/Hisilicon/HiKey/HiKey.dsc                |   8 +

>  Platform/Hisilicon/HiKey/HiKey.fdf                |   8 +

>  Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf    |  57 +++++

>  Silicon/Hisilicon/Hi6220/Include/Hi6220RegsPeri.h |  48 ++++

>  Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c      | 229 ++++++++++++++++++++

>  5 files changed, 350 insertions(+)

> 

> diff --git a/Platform/Hisilicon/HiKey/HiKey.dsc b/Platform/Hisilicon/HiKey/HiKey.dsc

> index 5c1604d7f689..83dd68a820b1 100644

> --- a/Platform/Hisilicon/HiKey/HiKey.dsc

> +++ b/Platform/Hisilicon/HiKey/HiKey.dsc

> @@ -189,9 +189,17 @@ [Components.common]

>    #

>    # GPIO

>    #

> +  Platform/Hisilicon/HiKey/HiKeyGpioDxe/HiKeyGpioDxe.inf

>    ArmPlatformPkg/Drivers/PL061GpioDxe/PL061GpioDxe.inf

>  

>    #

> +  # Virtual Keyboard

> +  #

> +  EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboardDxe.inf

> +

> +  Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf

> +

> +  #

>    # MMC/SD

>    #

>    EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

> diff --git a/Platform/Hisilicon/HiKey/HiKey.fdf b/Platform/Hisilicon/HiKey/HiKey.fdf

> index 2a5c5a4d6e79..2bca7232b6e5 100644

> --- a/Platform/Hisilicon/HiKey/HiKey.fdf

> +++ b/Platform/Hisilicon/HiKey/HiKey.fdf

> @@ -120,9 +120,17 @@ [FV.FvMain]

>    #

>    # GPIO

>    #

> +  INF Platform/Hisilicon/HiKey/HiKeyGpioDxe/HiKeyGpioDxe.inf

>    INF ArmPlatformPkg/Drivers/PL061GpioDxe/PL061GpioDxe.inf

>  

>    #

> +  # Virtual Keyboard

> +  #

> +  INF EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboardDxe.inf

> +

> +  INF Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf

> +

> +  #

>    # Multimedia Card Interface

>    #

>    INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf

> diff --git a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf

> new file mode 100644

> index 000000000000..702fdb1eebf0

> --- /dev/null

> +++ b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf

> @@ -0,0 +1,57 @@

> +#

> +#  Copyright (c) 2013 - 2014, ARM Ltd. All rights reserved.

> +#  Copyright (c) 2018, Linaro Ltd. All rights reserved.

> +#

> +#  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


0x0001001a

> +  BASE_NAME                      = HiKeyDxe

> +  FILE_GUID                      = f567684b-1089-4214-8881-d64b20cbda2f

> +  MODULE_TYPE                    = DXE_DRIVER

> +  VERSION_STRING                 = 1.0

> +  ENTRY_POINT                    = HiKeyEntryPoint

> +

> +[Sources.common]

> +  HiKeyDxe.c

> +

> +[Packages]

> +  ArmPkg/ArmPkg.dec

> +  EmbeddedPkg/EmbeddedPkg.dec

> +  MdePkg/MdePkg.dec

> +  MdeModulePkg/MdeModulePkg.dec


MdeM... before MdeP...

> +

> +[LibraryClasses]

> +  BaseMemoryLib

> +  CacheMaintenanceLib

> +  DebugLib

> +  DxeServicesLib

> +  DxeServicesTableLib

> +  FdtLib

> +  IoLib

> +  PcdLib

> +  PrintLib

> +  SerialPortLib

> +  TimerLib

> +  UefiBootServicesTableLib

> +  UefiRuntimeServicesTableLib

> +  UefiLib

> +  UefiDriverEntryPoint


Are all of the above used by this driver?

> +

> +[Protocols]

> +  gEmbeddedGpioProtocolGuid

> +  gPlatformVirtualKeyboardProtocolGuid

> +

> +[Guids]

> +  gEfiEndOfDxeEventGroupGuid

> +  gEfiFileInfoGuid


I can't find any references to gEfiFileInfoGuid in this patch.

> +

> +[Depex]

> +  TRUE

> diff --git a/Silicon/Hisilicon/Hi6220/Include/Hi6220RegsPeri.h b/Silicon/Hisilicon/Hi6220/Include/Hi6220RegsPeri.h

> new file mode 100644

> index 000000000000..8419685611bf

> --- /dev/null

> +++ b/Silicon/Hisilicon/Hi6220/Include/Hi6220RegsPeri.h

> @@ -0,0 +1,48 @@

> +/** @file

> +*

> +*  Copyright (c) 2018, Linaro Ltd. All rights reserved.

> +*

> +*  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 __HI6220_REGS_PERI_H__

> +#define __HI6220_REGS_PERI_H__

> +

> +#define SC_PERIPH_CLKEN3                0x230

> +#define SC_PERIPH_RSTEN3                0x330

> +#define SC_PERIPH_RSTDIS0               0x304

> +#define SC_PERIPH_RSTDIS3               0x334

> +#define SC_PERIPH_RSTSTAT3              0x338

> +

> +/* SC_PERIPH_RSTEN0/RSTDIS0/RSTSTAT0 */

> +#define PERIPH_RST0_MMC2                (1 << 2)

> +

> +/* SC_PERIPH_RSTEN3/RSTDIS3/RSTSTAT3 */

> +#define PERIPH_RST3_CSSYS               (1 << 0)

> +#define PERIPH_RST3_I2C0                (1 << 1)

> +#define PERIPH_RST3_I2C1                (1 << 2)

> +#define PERIPH_RST3_I2C2                (1 << 3)

> +#define PERIPH_RST3_I2C3                (1 << 4)

> +#define PERIPH_RST3_UART1               (1 << 5)

> +#define PERIPH_RST3_UART2               (1 << 6)

> +#define PERIPH_RST3_UART3               (1 << 7)

> +#define PERIPH_RST3_UART4               (1 << 8)

> +#define PERIPH_RST3_SSP                 (1 << 9)

> +#define PERIPH_RST3_PWM                 (1 << 10)

> +#define PERIPH_RST3_BLPWM               (1 << 11)

> +#define PERIPH_RST3_TSENSOR             (1 << 12)

> +#define PERIPH_RST3_DAPB                (1 << 18)

> +#define PERIPH_RST3_HKADC               (1 << 19)

> +#define PERIPH_RST3_CODEC_SSI           (1 << 20)

> +#define PERIPH_RST3_PMUSSI1             (1 << 22)

> +

> +#define PMUSSI_REG(x)                   (PMUSSI_BASE + ((x) << 2))

> +

> +#endif /* __HI6220_REGS_PERI_H__ */

> diff --git a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c

> new file mode 100644

> index 000000000000..65e800116b76

> --- /dev/null

> +++ b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c

> @@ -0,0 +1,229 @@

> +/** @file

> +*

> +*  Copyright (c) 2018, Linaro Ltd. All rights reserved.

> +*

> +*  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.

> +*

> +**/

> +

> +#include <Library/BaseMemoryLib.h>

> +#include <Library/CacheMaintenanceLib.h>

> +#include <Library/DebugLib.h>

> +#include <Library/DevicePathLib.h>

> +#include <Library/IoLib.h>

> +#include <Library/MemoryAllocationLib.h>

> +#include <Library/PrintLib.h>

> +#include <Library/UefiBootServicesTableLib.h>

> +#include <Library/UefiLib.h>

> +#include <Library/UefiRuntimeServicesTableLib.h>

> +

> +#include <Protocol/EmbeddedGpio.h>

> +#include <Protocol/PlatformVirtualKeyboard.h>

> +

> +#include <Hi6220.h>

> +#include <Hi6220RegsPeri.h>

> +#include <libfdt.h>

> +

> +#define SERIAL_NUMBER_SIZE               17

> +#define SERIAL_NUMBER_BLOCK_SIZE         EFI_PAGE_SIZE

> +#define SERIAL_NUMBER_LBA                1024

> +#define RANDOM_MAX                       0x7FFFFFFFFFFFFFFF

> +#define RANDOM_MAGIC                     0x9A4DBEAF

> +

> +#define DETECT_J15_FASTBOOT              24   // GPIO3_0

> +

> +#define ADB_REBOOT_ADDRESS               0x05F01000

> +#define ADB_REBOOT_BOOTLOADER            0x77665500

> +#define ADB_REBOOT_NONE                  0x77665501


If these ADB values are generic, this ought to be defined in a common
header somewhere in EmbeddedPkg. Please apply the same feedback to 2/4
if I missed that aspect there.

> +

> +

> +typedef struct {

> +  UINT64        Magic;

> +  UINT64        Data;

> +  CHAR16        UnicodeSN[SERIAL_NUMBER_SIZE];

> +} RANDOM_SERIAL_NUMBER;


Please move all of the above #defines and struct to a local HiKeyDxe.h
(apart from possibly the ADB ones).

> +

> +STATIC EMBEDDED_GPIO        *mGpio;

> +

> +STATIC

> +VOID

> +UartInit (

> +  IN VOID

> +  )

> +{

> +  UINT32     Val;

> +

> +  /* make UART1 out of reset */

> +  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS3, PERIPH_RST3_UART1);

> +  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_CLKEN3, PERIPH_RST3_UART1);

> +  /* make UART2 out of reset */

> +  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS3, PERIPH_RST3_UART2);

> +  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_CLKEN3, PERIPH_RST3_UART2);

> +  /* make UART3 out of reset */

> +  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS3, PERIPH_RST3_UART3);

> +  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_CLKEN3, PERIPH_RST3_UART3);

> +  /* make UART4 out of reset */

> +  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS3, PERIPH_RST3_UART4);

> +  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_CLKEN3, PERIPH_RST3_UART4);

> +

> +  /* make DW_MMC2 out of reset */

> +  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS0, PERIPH_RST0_MMC2);

> +

> +  /* enable clock for BT/WIFI */


Please expand BT->Bluetooth.

> +  Val = MmioRead32 (PMUSSI_REG(0x1c)) | 0x40;

> +  MmioWrite32 (PMUSSI_REG(0x1c), Val);


Some #defines for those 0x1c and 0x40?
(Could also use MmioOr32 instead of the temporary variable.)

> +}

> +

> +STATIC

> +VOID

> +MtcmosInit (

> +  IN VOID

> +  )

> +{

> +  UINT32     Data;

> +

> +  /* enable MTCMOS for GPU */


https://en.wikipedia.org/wiki/Multi-threshold_CMOS ?
Please expand abbreviation.

> +  MmioWrite32 (AO_CTRL_BASE + SC_PW_MTCMOS_EN0, PW_EN0_G3D);

> +  do {

> +    Data = MmioRead32 (AO_CTRL_BASE + SC_PW_MTCMOS_ACK_STAT0);

> +  } while ((Data & PW_EN0_G3D) == 0);

> +}

> +

> +EFI_STATUS

> +HiKeyInitPeripherals (

> +  IN VOID

> +  )

> +{

> +  UINT32     Data, Bits;

> +

> +  /* make I2C0/I2C1/I2C2/SPI0 out of reset */

> +  Bits = PERIPH_RST3_I2C0 | PERIPH_RST3_I2C1 | PERIPH_RST3_I2C2 | \

> +         PERIPH_RST3_SSP;

> +  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS3, Bits);

> +

> +  do {

> +    Data = MmioRead32 (PERI_CTRL_BASE + SC_PERIPH_RSTSTAT3);

> +  } while (Data & Bits);

> +

> +  UartInit ();

> +  MtcmosInit ();

> +

> +  /* Set DETECT_J15_FASTBOOT (GPIO24) pin as GPIO function */

> +  MmioWrite32 (0xf7010950, 0);        /* configure GPIO24 as nopull */

> +  MmioWrite32 (0xf7010140, 0);        /* configure GPIO24 as GPIO */


Please replace hard-coded register addresses with #defines.

> +

> +  return EFI_SUCCESS;

> +}

> +

> +EFI_STATUS

> +EFIAPI

> +VirtualKeyboardRegister (

> +  IN VOID

> +  )

> +{

> +  EFI_STATUS           Status;

> +

> +  Status = gBS->LocateProtocol (

> +                  &gEmbeddedGpioProtocolGuid,

> +                  NULL,

> +                  (VOID **) &mGpio

> +                  );

> +  if (EFI_ERROR (Status)) {

> +    return Status;

> +  }

> +  return EFI_SUCCESS;

> +}

> +

> +EFI_STATUS

> +EFIAPI

> +VirtualKeyboardReset (

> +  IN VOID

> +  )

> +{

> +  EFI_STATUS           Status;

> +

> +  if (mGpio == NULL) {

> +    return EFI_INVALID_PARAMETER;

> +  }

> +  Status = mGpio->Set (mGpio, DETECT_J15_FASTBOOT, GPIO_MODE_INPUT);

> +  return Status;

> +}

> +

> +BOOLEAN

> +EFIAPI

> +VirtualKeyboardQuery (

> +  IN VIRTUAL_KBD_KEY             *VirtualKey

> +  )

> +{

> +  EFI_STATUS           Status;

> +  UINTN                Value = 0;

> +

> +  if ((VirtualKey == NULL) || (mGpio == NULL)) {

> +    return FALSE;

> +  }

> +  if (MmioRead32 (ADB_REBOOT_ADDRESS) == ADB_REBOOT_BOOTLOADER) {

> +    goto Done;

> +  } else {

> +    Status = mGpio->Get (mGpio, DETECT_J15_FASTBOOT, &Value);

> +    if (EFI_ERROR (Status) || (Value != 0)) {


Please give a #define for that 0.

> +      return FALSE;

> +    }

> +  }

> +Done:

> +  VirtualKey->Signature = VIRTUAL_KEYBOARD_KEY_SIGNATURE;

> +  VirtualKey->Key.ScanCode = SCAN_NULL;

> +  VirtualKey->Key.UnicodeChar = L'f';

> +  return TRUE;

> +}

> +

> +EFI_STATUS

> +EFIAPI

> +VirtualKeyboardClear (

> +  IN VIRTUAL_KBD_KEY            *VirtualKey

> +  )

> +{

> +  if (VirtualKey == NULL) {

> +    return EFI_INVALID_PARAMETER;

> +  }

> +  if (MmioRead32 (ADB_REBOOT_ADDRESS) == ADB_REBOOT_BOOTLOADER) {

> +    MmioWrite32 (ADB_REBOOT_ADDRESS, ADB_REBOOT_NONE);

> +    WriteBackInvalidateDataCacheRange ((VOID *)ADB_REBOOT_ADDRESS, 4);


Express that 4 as a suitable sizeof().

/
    Leif

> +  }

> +  return EFI_SUCCESS;

> +}

> +

> +PLATFORM_VIRTUAL_KBD_PROTOCOL mVirtualKeyboard = {

> +  VirtualKeyboardRegister,

> +  VirtualKeyboardReset,

> +  VirtualKeyboardQuery,

> +  VirtualKeyboardClear

> +};

> +

> +EFI_STATUS

> +EFIAPI

> +HiKeyEntryPoint (

> +  IN EFI_HANDLE         ImageHandle,

> +  IN EFI_SYSTEM_TABLE   *SystemTable

> +  )

> +{

> +  EFI_STATUS            Status;

> +

> +  Status = HiKeyInitPeripherals ();

> +  if (EFI_ERROR (Status)) {

> +    return Status;

> +  }

> +

> +  Status = gBS->InstallProtocolInterface (

> +                  &ImageHandle,

> +                  &gPlatformVirtualKeyboardProtocolGuid,

> +                  EFI_NATIVE_INTERFACE,

> +                  &mVirtualKeyboard

> +                  );

> +  return Status;

> +}

> -- 

> 2.7.4

> 

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

diff --git a/Platform/Hisilicon/HiKey/HiKey.dsc b/Platform/Hisilicon/HiKey/HiKey.dsc
index 5c1604d7f689..83dd68a820b1 100644
--- a/Platform/Hisilicon/HiKey/HiKey.dsc
+++ b/Platform/Hisilicon/HiKey/HiKey.dsc
@@ -189,9 +189,17 @@  [Components.common]
   #
   # GPIO
   #
+  Platform/Hisilicon/HiKey/HiKeyGpioDxe/HiKeyGpioDxe.inf
   ArmPlatformPkg/Drivers/PL061GpioDxe/PL061GpioDxe.inf
 
   #
+  # Virtual Keyboard
+  #
+  EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboardDxe.inf
+
+  Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf
+
+  #
   # MMC/SD
   #
   EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf
diff --git a/Platform/Hisilicon/HiKey/HiKey.fdf b/Platform/Hisilicon/HiKey/HiKey.fdf
index 2a5c5a4d6e79..2bca7232b6e5 100644
--- a/Platform/Hisilicon/HiKey/HiKey.fdf
+++ b/Platform/Hisilicon/HiKey/HiKey.fdf
@@ -120,9 +120,17 @@  [FV.FvMain]
   #
   # GPIO
   #
+  INF Platform/Hisilicon/HiKey/HiKeyGpioDxe/HiKeyGpioDxe.inf
   INF ArmPlatformPkg/Drivers/PL061GpioDxe/PL061GpioDxe.inf
 
   #
+  # Virtual Keyboard
+  #
+  INF EmbeddedPkg/Drivers/VirtualKeyboardDxe/VirtualKeyboardDxe.inf
+
+  INF Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf
+
+  #
   # Multimedia Card Interface
   #
   INF EmbeddedPkg/Universal/MmcDxe/MmcDxe.inf
diff --git a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf
new file mode 100644
index 000000000000..702fdb1eebf0
--- /dev/null
+++ b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf
@@ -0,0 +1,57 @@ 
+#
+#  Copyright (c) 2013 - 2014, ARM Ltd. All rights reserved.
+#  Copyright (c) 2018, Linaro Ltd. All rights reserved.
+#
+#  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                      = HiKeyDxe
+  FILE_GUID                      = f567684b-1089-4214-8881-d64b20cbda2f
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = HiKeyEntryPoint
+
+[Sources.common]
+  HiKeyDxe.c
+
+[Packages]
+  ArmPkg/ArmPkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+  CacheMaintenanceLib
+  DebugLib
+  DxeServicesLib
+  DxeServicesTableLib
+  FdtLib
+  IoLib
+  PcdLib
+  PrintLib
+  SerialPortLib
+  TimerLib
+  UefiBootServicesTableLib
+  UefiRuntimeServicesTableLib
+  UefiLib
+  UefiDriverEntryPoint
+
+[Protocols]
+  gEmbeddedGpioProtocolGuid
+  gPlatformVirtualKeyboardProtocolGuid
+
+[Guids]
+  gEfiEndOfDxeEventGroupGuid
+  gEfiFileInfoGuid
+
+[Depex]
+  TRUE
diff --git a/Silicon/Hisilicon/Hi6220/Include/Hi6220RegsPeri.h b/Silicon/Hisilicon/Hi6220/Include/Hi6220RegsPeri.h
new file mode 100644
index 000000000000..8419685611bf
--- /dev/null
+++ b/Silicon/Hisilicon/Hi6220/Include/Hi6220RegsPeri.h
@@ -0,0 +1,48 @@ 
+/** @file
+*
+*  Copyright (c) 2018, Linaro Ltd. All rights reserved.
+*
+*  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 __HI6220_REGS_PERI_H__
+#define __HI6220_REGS_PERI_H__
+
+#define SC_PERIPH_CLKEN3                0x230
+#define SC_PERIPH_RSTEN3                0x330
+#define SC_PERIPH_RSTDIS0               0x304
+#define SC_PERIPH_RSTDIS3               0x334
+#define SC_PERIPH_RSTSTAT3              0x338
+
+/* SC_PERIPH_RSTEN0/RSTDIS0/RSTSTAT0 */
+#define PERIPH_RST0_MMC2                (1 << 2)
+
+/* SC_PERIPH_RSTEN3/RSTDIS3/RSTSTAT3 */
+#define PERIPH_RST3_CSSYS               (1 << 0)
+#define PERIPH_RST3_I2C0                (1 << 1)
+#define PERIPH_RST3_I2C1                (1 << 2)
+#define PERIPH_RST3_I2C2                (1 << 3)
+#define PERIPH_RST3_I2C3                (1 << 4)
+#define PERIPH_RST3_UART1               (1 << 5)
+#define PERIPH_RST3_UART2               (1 << 6)
+#define PERIPH_RST3_UART3               (1 << 7)
+#define PERIPH_RST3_UART4               (1 << 8)
+#define PERIPH_RST3_SSP                 (1 << 9)
+#define PERIPH_RST3_PWM                 (1 << 10)
+#define PERIPH_RST3_BLPWM               (1 << 11)
+#define PERIPH_RST3_TSENSOR             (1 << 12)
+#define PERIPH_RST3_DAPB                (1 << 18)
+#define PERIPH_RST3_HKADC               (1 << 19)
+#define PERIPH_RST3_CODEC_SSI           (1 << 20)
+#define PERIPH_RST3_PMUSSI1             (1 << 22)
+
+#define PMUSSI_REG(x)                   (PMUSSI_BASE + ((x) << 2))
+
+#endif /* __HI6220_REGS_PERI_H__ */
diff --git a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c
new file mode 100644
index 000000000000..65e800116b76
--- /dev/null
+++ b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c
@@ -0,0 +1,229 @@ 
+/** @file
+*
+*  Copyright (c) 2018, Linaro Ltd. All rights reserved.
+*
+*  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.
+*
+**/
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/CacheMaintenanceLib.h>
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/IoLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PrintLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+
+#include <Protocol/EmbeddedGpio.h>
+#include <Protocol/PlatformVirtualKeyboard.h>
+
+#include <Hi6220.h>
+#include <Hi6220RegsPeri.h>
+#include <libfdt.h>
+
+#define SERIAL_NUMBER_SIZE               17
+#define SERIAL_NUMBER_BLOCK_SIZE         EFI_PAGE_SIZE
+#define SERIAL_NUMBER_LBA                1024
+#define RANDOM_MAX                       0x7FFFFFFFFFFFFFFF
+#define RANDOM_MAGIC                     0x9A4DBEAF
+
+#define DETECT_J15_FASTBOOT              24   // GPIO3_0
+
+#define ADB_REBOOT_ADDRESS               0x05F01000
+#define ADB_REBOOT_BOOTLOADER            0x77665500
+#define ADB_REBOOT_NONE                  0x77665501
+
+
+typedef struct {
+  UINT64        Magic;
+  UINT64        Data;
+  CHAR16        UnicodeSN[SERIAL_NUMBER_SIZE];
+} RANDOM_SERIAL_NUMBER;
+
+STATIC EMBEDDED_GPIO        *mGpio;
+
+STATIC
+VOID
+UartInit (
+  IN VOID
+  )
+{
+  UINT32     Val;
+
+  /* make UART1 out of reset */
+  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS3, PERIPH_RST3_UART1);
+  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_CLKEN3, PERIPH_RST3_UART1);
+  /* make UART2 out of reset */
+  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS3, PERIPH_RST3_UART2);
+  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_CLKEN3, PERIPH_RST3_UART2);
+  /* make UART3 out of reset */
+  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS3, PERIPH_RST3_UART3);
+  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_CLKEN3, PERIPH_RST3_UART3);
+  /* make UART4 out of reset */
+  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS3, PERIPH_RST3_UART4);
+  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_CLKEN3, PERIPH_RST3_UART4);
+
+  /* make DW_MMC2 out of reset */
+  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS0, PERIPH_RST0_MMC2);
+
+  /* enable clock for BT/WIFI */
+  Val = MmioRead32 (PMUSSI_REG(0x1c)) | 0x40;
+  MmioWrite32 (PMUSSI_REG(0x1c), Val);
+}
+
+STATIC
+VOID
+MtcmosInit (
+  IN VOID
+  )
+{
+  UINT32     Data;
+
+  /* enable MTCMOS for GPU */
+  MmioWrite32 (AO_CTRL_BASE + SC_PW_MTCMOS_EN0, PW_EN0_G3D);
+  do {
+    Data = MmioRead32 (AO_CTRL_BASE + SC_PW_MTCMOS_ACK_STAT0);
+  } while ((Data & PW_EN0_G3D) == 0);
+}
+
+EFI_STATUS
+HiKeyInitPeripherals (
+  IN VOID
+  )
+{
+  UINT32     Data, Bits;
+
+  /* make I2C0/I2C1/I2C2/SPI0 out of reset */
+  Bits = PERIPH_RST3_I2C0 | PERIPH_RST3_I2C1 | PERIPH_RST3_I2C2 | \
+         PERIPH_RST3_SSP;
+  MmioWrite32 (PERI_CTRL_BASE + SC_PERIPH_RSTDIS3, Bits);
+
+  do {
+    Data = MmioRead32 (PERI_CTRL_BASE + SC_PERIPH_RSTSTAT3);
+  } while (Data & Bits);
+
+  UartInit ();
+  MtcmosInit ();
+
+  /* Set DETECT_J15_FASTBOOT (GPIO24) pin as GPIO function */
+  MmioWrite32 (0xf7010950, 0);        /* configure GPIO24 as nopull */
+  MmioWrite32 (0xf7010140, 0);        /* configure GPIO24 as GPIO */
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtualKeyboardRegister (
+  IN VOID
+  )
+{
+  EFI_STATUS           Status;
+
+  Status = gBS->LocateProtocol (
+                  &gEmbeddedGpioProtocolGuid,
+                  NULL,
+                  (VOID **) &mGpio
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+VirtualKeyboardReset (
+  IN VOID
+  )
+{
+  EFI_STATUS           Status;
+
+  if (mGpio == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+  Status = mGpio->Set (mGpio, DETECT_J15_FASTBOOT, GPIO_MODE_INPUT);
+  return Status;
+}
+
+BOOLEAN
+EFIAPI
+VirtualKeyboardQuery (
+  IN VIRTUAL_KBD_KEY             *VirtualKey
+  )
+{
+  EFI_STATUS           Status;
+  UINTN                Value = 0;
+
+  if ((VirtualKey == NULL) || (mGpio == NULL)) {
+    return FALSE;
+  }
+  if (MmioRead32 (ADB_REBOOT_ADDRESS) == ADB_REBOOT_BOOTLOADER) {
+    goto Done;
+  } else {
+    Status = mGpio->Get (mGpio, DETECT_J15_FASTBOOT, &Value);
+    if (EFI_ERROR (Status) || (Value != 0)) {
+      return FALSE;
+    }
+  }
+Done:
+  VirtualKey->Signature = VIRTUAL_KEYBOARD_KEY_SIGNATURE;
+  VirtualKey->Key.ScanCode = SCAN_NULL;
+  VirtualKey->Key.UnicodeChar = L'f';
+  return TRUE;
+}
+
+EFI_STATUS
+EFIAPI
+VirtualKeyboardClear (
+  IN VIRTUAL_KBD_KEY            *VirtualKey
+  )
+{
+  if (VirtualKey == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+  if (MmioRead32 (ADB_REBOOT_ADDRESS) == ADB_REBOOT_BOOTLOADER) {
+    MmioWrite32 (ADB_REBOOT_ADDRESS, ADB_REBOOT_NONE);
+    WriteBackInvalidateDataCacheRange ((VOID *)ADB_REBOOT_ADDRESS, 4);
+  }
+  return EFI_SUCCESS;
+}
+
+PLATFORM_VIRTUAL_KBD_PROTOCOL mVirtualKeyboard = {
+  VirtualKeyboardRegister,
+  VirtualKeyboardReset,
+  VirtualKeyboardQuery,
+  VirtualKeyboardClear
+};
+
+EFI_STATUS
+EFIAPI
+HiKeyEntryPoint (
+  IN EFI_HANDLE         ImageHandle,
+  IN EFI_SYSTEM_TABLE   *SystemTable
+  )
+{
+  EFI_STATUS            Status;
+
+  Status = HiKeyInitPeripherals ();
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = gBS->InstallProtocolInterface (
+                  &ImageHandle,
+                  &gPlatformVirtualKeyboardProtocolGuid,
+                  EFI_NATIVE_INTERFACE,
+                  &mVirtualKeyboard
+                  );
+  return Status;
+}