public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [platforms: PATCH v2 00/12] Armada 7k8k GPIO support
@ 2019-01-10  1:44 Marcin Wojtas
  2019-01-10  1:44 ` [platforms: PATCH v2 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information Marcin Wojtas
                   ` (11 more replies)
  0 siblings, 12 replies; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

Hi,

With a big delay caused by private and professional matters,
I finaly submit the second version of the GPIO support for
Marvell Armada SoCs. The rework was HUGE. The biggest change
is dropping custom GPIO protocol and start using the generic
EMBEDDED_GPIO with all its types. I think I answered
all of the review remarks, the details can be found in the changelog
below.

Patches are available in the github:
https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/commits/gpio-upstream-r20190110

I also enclose a diff between v1 and v2, which maybe can ease a bit
the effort of review:
https://pastebin.com/GvAiYfJD

I am looking forward to your feedback.

Best regards,
Marcin

Changelog:
v1->v2:
* All
  - rebase on top of the master branch and Xenon changes

* 1/12
  - s/AP/AP806/ in order to avoid confusion
  - drop desc/DESC usage and improve variables naming
  - use GPIO_CONTROLLER from EmbeddedGpio.h instead of custom MV_SOC_GPIO
  - update commit message

* 2,3,4,5/12
  - drop desc/DESC usage and improve variables naming
  - drop reference to I2c and use GpioExpander
  - improve commit logs

* 6/12
  - drop desc/DESC usage and improve variables naming
  - drop reference to I2c and use GpioExpander
  - remove global variable - same as for other interfaces the consumer
    is responsible for avoiding memory leak

* 7/12
  - use MV_GPIO_ prefix
  - switch to EMBEDDED_GPIO
  - remove custom Marvell GPIO Protocol and types
  - add subroutine to MvGpioGetProtocol and more coments to clarify the code
  - add driver types and related enums in other commits

* 8/12
  - extend error path in the entry point, rename variables
  - use MV_GPIO_ prefix
  - switch to EMBEDDED_GPIO
  - remove custom Marvell GPIO Protocol and types
  - replace '!!' expression for obtaining pin state
  - remove BIT() macro
  - use generic mDevicePathTemplate name
  - put validate function under '#if !defined(MDEPKG_NDEBUG)' and
     call from inside ASSERT_EFI_ERROR, add comment
  - update commit message
  - add common enum for describing controllers
  - change authorship

- 9/12
  - Add Leif's RB

* 10/12
  - same modifications as 8/12
  - use I2C flags directly and remove PCA95XX_OPERATION enum
  - add common enum for describing controllers

* 11/12
  - Add Leif's RB

* 12/12
  - Add local headers
  - Make STATIC names more generic
  - s/GetInitializerForType/NonDiscoverableDeviceInitializerGet/
  - Use global enum for McBin GPIO controller

Marcin Wojtas (11):
  Marvell/Library: ArmadaSoCDescLib: Add GPIO information
  Marvell/Library: ArmadaBoardDescLib: Add GPIO information
  SolidRun/Armada80x0McBin: Extend board description library with GPIO
  Marvell/Armada70x0Db: Extend board description library with GPIO
  Marvell/Armada80x0Db: Extend board description library with GPIO
  Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
  Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver
  Marvell/Drivers: I2c: Use common header for macros
  Marvell/Drivers: MvPca95xxDxe: Introduce GPIO expander driver
  Marvell/Armada7k8k: Enable GPIO drivers compilation
  Marvell/Armada7k8k: Introduce NonDiscoverable device init routines

jinghua (1):
  Marvell/Protocol: Introduce GPIO helper header

 Silicon/Marvell/Marvell.dec                                                                   |   1 +
 Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc                                                 |   2 +
 Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc                                                |   7 +-
 Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc                                                |   3 +
 Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc                                         |   3 +
 Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf           |   1 +
 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf               |  48 ++
 Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf           |   1 +
 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf               |  49 ++
 Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf |   1 +
 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf           |  49 ++
 Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf                                |   1 +
 Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf              |   1 +
 Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf                                          |   1 +
 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf                                          |  44 ++
 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf                                    |  45 ++
 Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf                                             |   1 +
 Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf                                           |   1 +
 Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf                             |   1 +
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf                                           |   1 +
 Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf                                               |   1 +
 Silicon/Marvell/Library/IcuLib/IcuLib.inf                                                     |   1 +
 Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf                                             |   1 +
 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h                 |  23 +
 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h                 |  28 +
 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h             |  20 +
 Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h                |  10 +
 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h                                            |  49 ++
 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h                                      |  65 ++
 Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.h                                         |  10 -
 Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.h                                               |  17 +-
 Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h                                          |  23 +
 Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h                                            |  12 +
 Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h                                      |  28 +
 Silicon/Marvell/Include/Protocol/BoardDesc.h                                                  |   8 +
 Silicon/Marvell/Include/Protocol/MvGpio.h                                                     | 182 ++++++
 Silicon/Marvell/Include/Protocol/MvI2c.h                                                      |  31 +
 Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c             |  25 +
 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c                 |  96 +++
 Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c             |  31 +
 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c                 | 106 ++++
 Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c   |  17 +
 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c             |  71 +++
 Silicon/Marvell/Applications/EepromCmd/EepromCmd.c                                            |   5 +-
 Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c                |  39 ++
 Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c                                            |  43 ++
 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c                                            | 372 +++++++++++
 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c                                      | 651 ++++++++++++++++++++
 Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.c                                         |   3 +-
 Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c                                               |   4 +-
 Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c                               |  13 +-
 Platform/Marvell/Armada70x0Db/Armada70x0Db.fdf.inc                                            |   2 +
 Platform/Marvell/Armada80x0Db/Armada80x0Db.fdf.inc                                            |   2 +
 Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.fdf.inc                                     |   2 +
 54 files changed, 2214 insertions(+), 38 deletions(-)
 create mode 100644 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
 create mode 100644 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
 create mode 100644 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
 create mode 100644 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
 create mode 100644 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
 create mode 100644 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
 create mode 100644 Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
 create mode 100644 Silicon/Marvell/Include/Protocol/MvGpio.h
 create mode 100644 Silicon/Marvell/Include/Protocol/MvI2c.h
 create mode 100644 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
 create mode 100644 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
 create mode 100644 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c

-- 
2.7.4



^ permalink raw reply	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-14 23:45   ` Leif Lindholm
  2019-01-10  1:44 ` [platforms: PATCH v2 02/12] Marvell/Library: ArmadaBoardDescLib: " Marcin Wojtas
                   ` (10 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

This patch introduces new library callback (ArmadaSoCGpioGet ()),
which dynamically allocates and fills EmbeddedGpio's
GPIO_CONTROLLER structure with the SoC description of GPIO controllers.

Because the library header is indirectly used in many modules,
update all dependencies after including EmbeddedGpio.h.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf                   |  1 +
 Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf |  1 +
 Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf                             |  1 +
 Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf                                |  1 +
 Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf                              |  1 +
 Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf                              |  1 +
 Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf                                  |  1 +
 Silicon/Marvell/Library/IcuLib/IcuLib.inf                                        |  1 +
 Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf                                |  1 +
 Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h   | 10 +++++
 Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h                               | 12 ++++++
 Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c   | 39 ++++++++++++++++++++
 12 files changed, 70 insertions(+)

diff --git a/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf b/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf
index 5503463..e707fe9 100644
--- a/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf
+++ b/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf
@@ -25,6 +25,7 @@
   PlatInitDxe.c
 
 [Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   Silicon/Marvell/Marvell.dec
diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf
index 2b73b73..48a320c 100644
--- a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf
+++ b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf
@@ -24,6 +24,7 @@
   Armada7k8kSoCDescLib.c
 
 [Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   Silicon/Marvell/Marvell.dec
diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
index 0b93948..0b641fe 100644
--- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
+++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
@@ -42,6 +42,7 @@
   MvBoardDescDxe.h
 
 [Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   Silicon/Marvell/Marvell.dec
diff --git a/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf b/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf
index 0eef350..e5bd370 100755
--- a/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf
+++ b/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf
@@ -41,6 +41,7 @@
   MvI2cDxe.c
 
 [Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
   ArmPlatformPkg/ArmPlatformPkg.dec
diff --git a/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf b/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf
index 739576f..8a877da 100644
--- a/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf
+++ b/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf
@@ -45,6 +45,7 @@
 [Packages]
   ArmPkg/ArmPkg.dec
   ArmPlatformPkg/ArmPlatformPkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   Silicon/Marvell/Marvell.dec
diff --git a/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf b/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf
index 00c738a..09c5842 100644
--- a/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf
+++ b/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf
@@ -35,6 +35,7 @@
   XenonSdMmcOverride.h
 
 [Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
   Silicon/Marvell/Marvell.dec
diff --git a/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf b/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf
index 36f498b..c360edd 100644
--- a/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf
+++ b/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf
@@ -41,6 +41,7 @@
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
   ArmPkg/ArmPkg.dec
   ArmPlatformPkg/ArmPlatformPkg.dec
   Silicon/Marvell/Marvell.dec
diff --git a/Silicon/Marvell/Library/IcuLib/IcuLib.inf b/Silicon/Marvell/Library/IcuLib/IcuLib.inf
index 0010141..ea662be 100644
--- a/Silicon/Marvell/Library/IcuLib/IcuLib.inf
+++ b/Silicon/Marvell/Library/IcuLib/IcuLib.inf
@@ -24,6 +24,7 @@
   IcuLib.c
 
 [Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   Silicon/Marvell/Marvell.dec
diff --git a/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf b/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf
index e2381f4..805a057 100644
--- a/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf
+++ b/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf
@@ -41,6 +41,7 @@
 [Packages]
   ArmPkg/ArmPkg.dec
   ArmPlatformPkg/ArmPlatformPkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   Silicon/Marvell/Marvell.dec
diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
index c14b985..bfc8639 100644
--- a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
+++ b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
@@ -22,6 +22,7 @@
 // Common macros
 //
 #define MV_SOC_CP_BASE(Cp)               (0xF2000000 + ((Cp) * 0x2000000))
+#define MV_SOC_AP806_COUNT               1
 
 //
 // Platform description of AHCI controllers
@@ -38,6 +39,15 @@
 #define MV_SOC_COMPHY_MUX_BITS           4
 
 //
+// Platform description of GPIO controllers
+//
+#define MV_SOC_AP806_GPIO_BASE           0xF06F5040
+#define MV_SOC_AP806_GPIO_PIN_COUNT      20
+#define MV_SOC_GPIO_PER_CP_COUNT         2
+#define MV_SOC_CP_GPIO_BASE(Gpio)        (0x440100 + ((Gpio) * 0x40))
+#define MV_SOC_CP_GPIO_PIN_COUNT(Gpio)   ((Gpio) == 0 ? 32 : 31)
+
+//
 // Platform description of I2C controllers
 //
 #define MV_SOC_I2C_PER_CP_COUNT          2
diff --git a/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h b/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
index cdfb51b..26b075a 100644
--- a/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
+++ b/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
@@ -17,6 +17,8 @@
 #include <Library/MvComPhyLib.h>
 #include <Library/NonDiscoverableDeviceRegistrationLib.h>
 
+#include <Protocol/EmbeddedGpio.h>
+
 //
 // ComPhy SoC description
 //
@@ -46,6 +48,16 @@ ArmadaSoCDescCpBaseGet (
   );
 
 //
+// GPIO devices description template definition
+//
+EFI_STATUS
+EFIAPI
+ArmadaSoCGpioGet (
+  IN OUT GPIO_CONTROLLER  **SoCGpioDescription,
+  IN OUT UINTN             *Count
+  );
+
+//
 // I2C
 //
 typedef struct {
diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
index 6902fda..5b72c20 100644
--- a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
+++ b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
@@ -74,6 +74,45 @@ ArmadaSoCDescCpBaseGet (
 
 EFI_STATUS
 EFIAPI
+ArmadaSoCGpioGet (
+  IN OUT GPIO_CONTROLLER  **SoCGpioDescription,
+  IN OUT UINTN             *Count
+  )
+{
+  GPIO_CONTROLLER *GpioInstance;
+  UINTN CpCount, CpIndex, Index;
+
+  CpCount = FixedPcdGet8 (PcdMaxCpCount);
+
+  *Count = CpCount * MV_SOC_GPIO_PER_CP_COUNT + MV_SOC_AP806_COUNT;
+  GpioInstance = AllocateZeroPool (*Count * sizeof (GPIO_CONTROLLER));
+  if (GpioInstance == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  *SoCGpioDescription = GpioInstance;
+
+  /* AP806 GPIO controller */
+  GpioInstance->RegisterBase = MV_SOC_AP806_GPIO_BASE;
+  GpioInstance->InternalGpioCount = MV_SOC_AP806_GPIO_PIN_COUNT;
+  GpioInstance++;
+
+  /* CP110 GPIO controllers */
+  for (CpIndex = 0; CpIndex < CpCount; CpIndex++) {
+    for (Index = 0; Index < MV_SOC_GPIO_PER_CP_COUNT; Index++) {
+      GpioInstance->RegisterBase = MV_SOC_CP_BASE (CpIndex) +
+                                   MV_SOC_CP_GPIO_BASE (Index);
+      GpioInstance->InternalGpioCount = MV_SOC_CP_GPIO_PIN_COUNT (Index);
+      GpioInstance++;
+    }
+  }
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
 ArmadaSoCDescI2cGet (
   IN OUT MV_SOC_I2C_DESC  **I2cDesc,
   IN OUT UINTN             *DescCount
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 02/12] Marvell/Library: ArmadaBoardDescLib: Add GPIO information
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
  2019-01-10  1:44 ` [platforms: PATCH v2 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-14 23:46   ` Leif Lindholm
  2019-01-10  1:44 ` [platforms: PATCH v2 03/12] SolidRun/Armada80x0McBin: Extend board description library with GPIO Marcin Wojtas
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

This patch extends library with GPIO devices per-board
description. Both embedded SoC controllers and
I2C IO expanders are supported. Add a helper routine
for obtaining information about the latter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h | 23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h b/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
index 3fe2988..6ec5ace 100644
--- a/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
+++ b/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
@@ -25,6 +25,29 @@ typedef struct {
 } MV_BOARD_COMPHY_DESC;
 
 //
+// GPIO devices per-board description
+//
+typedef struct {
+  UINTN ChipId;
+  UINTN I2cAddress;
+  UINTN I2cBus;
+} MV_GPIO_EXPANDER;
+
+typedef struct {
+  GPIO_CONTROLLER  *SoCGpio;
+  UINTN             GpioDeviceCount;
+  MV_GPIO_EXPANDER *GpioExpanders;
+  UINTN             GpioExpanderCount;
+} MV_BOARD_GPIO_DESCRIPTION;
+
+EFI_STATUS
+EFIAPI
+ArmadaBoardGpioExpanderGet (
+  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
+  IN OUT UINTN             *GpioExpanderCount
+  );
+
+//
 // I2C devices per-board description
 //
 typedef struct {
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 03/12] SolidRun/Armada80x0McBin: Extend board description library with GPIO
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
  2019-01-10  1:44 ` [platforms: PATCH v2 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information Marcin Wojtas
  2019-01-10  1:44 ` [platforms: PATCH v2 02/12] Marvell/Library: ArmadaBoardDescLib: " Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-14 23:46   ` Leif Lindholm
  2019-01-10  1:44 ` [platforms: PATCH v2 04/12] Marvell/Armada70x0Db: " Marcin Wojtas
                   ` (8 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

This patch implements ArmadaBoarDescLib library for
Armada80x0McBin comunity board and introduces ArmadaBoardGpioGet
routine with per-board GPIO expander description.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf |  1 +
 Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c   | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
index 63a4f66..43e4b9e 100644
--- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
+++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
@@ -25,6 +25,7 @@
   Armada80x0McBinBoardDescLib.c
 
 [Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   Silicon/Marvell/Marvell.dec
diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
index d52adfc..32596ad 100644
--- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
+++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
@@ -22,6 +22,23 @@
 #include <Library/UefiBootServicesTableLib.h>
 
 //
+// GPIO Expander
+//
+EFI_STATUS
+EFIAPI
+ArmadaBoardGpioExpanderGet (
+  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
+  IN OUT UINTN             *GpioExpanderCount
+  )
+{
+  /* No GPIO expanders on board */
+  *GpioExpanders = NULL;
+  *GpioExpanderCount = 0;
+
+  return EFI_SUCCESS;
+}
+
+//
 // Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
 //
 STATIC
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 04/12] Marvell/Armada70x0Db: Extend board description library with GPIO
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
                   ` (2 preceding siblings ...)
  2019-01-10  1:44 ` [platforms: PATCH v2 03/12] SolidRun/Armada80x0McBin: Extend board description library with GPIO Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-14 22:41   ` Leif Lindholm
  2019-01-10  1:44 ` [platforms: PATCH v2 05/12] Marvell/Armada80x0Db: " Marcin Wojtas
                   ` (7 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

This patch implements ArmadaBoarDescLib library for
Armada70x0Db comunity board and introduces ArmadaBoardGpioGet
routine with per-board GPIO expander description.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf |  1 +
 Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c   | 25 ++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
index b26f55b..c995515 100644
--- a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
+++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
@@ -25,6 +25,7 @@
   Armada70x0DbBoardDescLib.c
 
 [Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   Silicon/Marvell/Marvell.dec
diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
index 48c68e4..f63d8fd 100644
--- a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
+++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
@@ -21,6 +21,31 @@
 #include <Library/MemoryAllocationLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 
+#include <Protocol/MvGpio.h>
+
+//
+// GPIO Expander
+//
+STATIC MV_GPIO_EXPANDER mGpioExpander = {
+  8, /* PCA9555 */
+  0x21,
+  0x0,
+};
+
+
+EFI_STATUS
+EFIAPI
+ArmadaBoardGpioExpanderGet (
+  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
+  IN OUT UINTN             *GpioExpanderCount
+  )
+{
+  *GpioExpanderCount = 1;
+  *GpioExpanders = &mGpioExpander;
+
+  return EFI_SUCCESS;
+}
+
 //
 // Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
 //
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 05/12] Marvell/Armada80x0Db: Extend board description library with GPIO
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
                   ` (3 preceding siblings ...)
  2019-01-10  1:44 ` [platforms: PATCH v2 04/12] Marvell/Armada70x0Db: " Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-14 22:44   ` Leif Lindholm
  2019-01-10  1:44 ` [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support Marcin Wojtas
                   ` (6 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

This patch implements ArmadaBoarDescLib library for
Armada80x0Db comunity board and introduces ArmadaBoardGpioGet
routine with per-board GPIO expander description.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf |  1 +
 Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c   | 31 ++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
index 2d39d96..786b7f0 100644
--- a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
+++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
@@ -25,6 +25,7 @@
   Armada80x0DbBoardDescLib.c
 
 [Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
   MdeModulePkg/MdeModulePkg.dec
   MdePkg/MdePkg.dec
   Silicon/Marvell/Marvell.dec
diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
index feb69ad..f6e3675 100644
--- a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
+++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
@@ -21,6 +21,37 @@
 #include <Library/MemoryAllocationLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 
+#include <Protocol/MvGpio.h>
+
+//
+// GPIO Expanders
+//
+STATIC MV_GPIO_EXPANDER mGpioExpanders[] = {
+  {
+    8, /* PCA9555 */
+    0x21,
+    0x0,
+  },
+  {
+    8, /* PCA9555 */
+    0x25,
+    0x0,
+  },
+};
+
+EFI_STATUS
+EFIAPI
+ArmadaBoardGpioExpanderGet (
+  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
+  IN OUT UINTN             *GpioExpanderCount
+  )
+{
+  *GpioExpanderCount = ARRAY_SIZE (mGpioExpanders);
+  *GpioExpanders = mGpioExpanders;
+
+  return EFI_SUCCESS;
+}
+
 //
 // Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
 //
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
                   ` (4 preceding siblings ...)
  2019-01-10  1:44 ` [platforms: PATCH v2 05/12] Marvell/Armada80x0Db: " Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-14 22:58   ` Leif Lindholm
  2019-01-10  1:44 ` [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header Marcin Wojtas
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

Introduce new callback that can provide information
about GPIO SoC controllers, as well as on-board
I2C IO expanders. According ArmadaSoCDescLib
ArmadaBoardDescLib routines are used for
obtaining required data.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Silicon/Marvell/Include/Protocol/BoardDesc.h       |  8 ++++
 Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c | 43 ++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/Silicon/Marvell/Include/Protocol/BoardDesc.h b/Silicon/Marvell/Include/Protocol/BoardDesc.h
index 1d57a16..02905ea 100644
--- a/Silicon/Marvell/Include/Protocol/BoardDesc.h
+++ b/Silicon/Marvell/Include/Protocol/BoardDesc.h
@@ -50,6 +50,13 @@ EFI_STATUS
 
 typedef
 EFI_STATUS
+(EFIAPI *MV_BOARD_GPIO_DESCRIPTION_GET) (
+  IN MARVELL_BOARD_DESC_PROTOCOL    *This,
+  IN OUT MV_BOARD_GPIO_DESCRIPTION **GpioDescription
+  );
+
+typedef
+EFI_STATUS
 (EFIAPI *MV_BOARD_DESC_I2C_GET) (
   IN MARVELL_BOARD_DESC_PROTOCOL  *This,
   IN OUT MV_BOARD_I2C_DESC       **I2cDesc
@@ -113,6 +120,7 @@ struct _MARVELL_BOARD_DESC_PROTOCOL {
   MV_BOARD_DESC_UTMI_GET         BoardDescUtmiGet;
   MV_BOARD_DESC_XHCI_GET         BoardDescXhciGet;
   MV_BOARD_DESC_FREE             BoardDescFree;
+  MV_BOARD_GPIO_DESCRIPTION_GET  GpioDescriptionGet;
 };
 
 #endif // __MARVELL_BOARD_DESC_PROTOCOL_H__
diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
index f71bfc4..e348b85 100644
--- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
+++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
@@ -100,6 +100,48 @@ MvBoardDescComPhyGet (
 
 STATIC
 EFI_STATUS
+MvBoardGpioDescriptionGet (
+  IN MARVELL_BOARD_DESC_PROTOCOL    *This,
+  IN OUT MV_BOARD_GPIO_DESCRIPTION **GpioDescription
+  )
+{
+  MV_BOARD_GPIO_DESCRIPTION *Description;
+  UINTN SoCGpioCount, GpioExpanderCount;
+  MV_GPIO_EXPANDER *GpioExpanders;
+  GPIO_CONTROLLER *SoCGpio;
+  EFI_STATUS Status;
+
+  /* Get SoC data about all available GPIO controllers */
+  Status = ArmadaSoCGpioGet (&SoCGpio, &SoCGpioCount);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  /* Get per-board information about all available I2C IO expanders */
+  Status = ArmadaBoardGpioExpanderGet (&GpioExpanders, &GpioExpanderCount);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  /* Allocate and fill board description */
+  Description = AllocateZeroPool (sizeof (MV_BOARD_GPIO_DESCRIPTION));
+  if (Description == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  Description->SoCGpio = SoCGpio;
+  Description->GpioDeviceCount = SoCGpioCount;
+  Description->GpioExpanders = GpioExpanders;
+  Description->GpioExpanderCount = GpioExpanderCount;
+
+  *GpioDescription = Description;
+
+  return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
 MvBoardDescI2cGet (
   IN MARVELL_BOARD_DESC_PROTOCOL  *This,
   IN OUT MV_BOARD_I2C_DESC       **I2cDesc
@@ -571,6 +613,7 @@ MvBoardDescInitProtocol (
   BoardDescProtocol->BoardDescUtmiGet = MvBoardDescUtmiGet;
   BoardDescProtocol->BoardDescXhciGet = MvBoardDescXhciGet;
   BoardDescProtocol->BoardDescFree = MvBoardDescFree;
+  BoardDescProtocol->GpioDescriptionGet = MvBoardGpioDescriptionGet;
 
   return EFI_SUCCESS;
 }
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
                   ` (5 preceding siblings ...)
  2019-01-10  1:44 ` [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-14 23:12   ` Leif Lindholm
  2019-01-10  1:44 ` [platforms: PATCH v2 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver Marcin Wojtas
                   ` (4 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel
  Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap,
	jinghua

From: jinghua <jinghua@marvell.com>

This patch introduces a helper header that can be used by
multiple EMBEDDED_GPIO protocol producers (e.g. platform
driver or GPIO expanders). The drives are differentiated by
MV_GPIO_DRIVER_TYPE field of driver's MV_GPIO_DEVICE_PATH.

In order to ease selection of the desired GPIO controller
a helper function was added - MarvellGpioGetProtocol().

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Silicon/Marvell/Include/Protocol/MvGpio.h | 156 ++++++++++++++++++++
 1 file changed, 156 insertions(+)
 create mode 100644 Silicon/Marvell/Include/Protocol/MvGpio.h

diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
new file mode 100644
index 0000000..c9f1007
--- /dev/null
+++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
@@ -0,0 +1,156 @@
+/**
+*
+*  Copyright (C) 2018, Marvell International Ltd. and its affiliates.
+*
+*  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 __MV_GPIO_PROTOCOL_H__
+#define __MV_GPIO_PROTOCOL_H__
+
+#include <Uefi.h>
+
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Protocol/EmbeddedGpio.h>
+
+typedef enum {
+  MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
+} MV_GPIO_DRIVER_TYPE;
+
+typedef struct {
+  VENDOR_DEVICE_PATH        Header;
+  MV_GPIO_DRIVER_TYPE       GpioDriverType;
+  EFI_DEVICE_PATH_PROTOCOL  End;
+} MV_GPIO_DEVICE_PATH;
+
+typedef struct {
+  UINTN    ControllerId;
+  UINTN    PinNumber;
+  BOOLEAN  ActiveHigh;
+} MV_GPIO_PIN;
+
+/*
+ * Check if the driver type matches the requested value.
+ * In case of the success open the GPIO protocol and return.
+ */
+STATIC
+inline
+EFI_STATUS
+EFIAPI
+MvGpioFindMatchingDriver (
+  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
+  IN     EFI_HANDLE             HandleBuffer,
+  IN     EFI_DEVICE_PATH       *DevicePath,
+  IN OUT EMBEDDED_GPIO        **GpioProtocol
+  )
+{
+  MV_GPIO_DEVICE_PATH *GpioDevicePath;
+  EFI_STATUS           Status;
+
+  while (!IsDevicePathEndType (DevicePath)) {
+    /* Check if GpioDriverType matches one found in the device path */
+    GpioDevicePath = (MV_GPIO_DEVICE_PATH *)DevicePath;
+    if (GpioDevicePath->GpioDriverType != GpioDriverType) {
+      DevicePath = NextDevicePathNode (DevicePath);
+      continue;
+    }
+
+    /*
+     * Open GpioProtocol. With EFI_OPEN_PROTOCOL_GET_PROTOCOL attribute
+     * the consumer is not obliged to call CloseProtocol.
+     */
+    Status = gBS->OpenProtocol (HandleBuffer,
+                    &gEmbeddedGpioProtocolGuid,
+                    (VOID **)GpioProtocol,
+                    gImageHandle,
+                    NULL,
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+    return Status;
+  }
+
+  return EFI_NOT_FOUND;
+}
+
+/*
+ * Select desired protocol producer upon MV_GPIO_DRIVER_TYPE
+ * field of driver's MV_GPIO_DEVICE_PATH.
+ */
+STATIC
+inline
+EFI_STATUS
+EFIAPI
+MvGpioGetProtocol (
+  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
+  IN OUT EMBEDDED_GPIO        **GpioProtocol
+  )
+{
+  EFI_DEVICE_PATH     *DevicePath;
+  EFI_HANDLE          *HandleBuffer;
+  EFI_STATUS           Status;
+  UINTN                HandleCount;
+  UINTN                Index;
+
+  /* Locate Handles of all EMBEDDED_GPIO producers */
+  Status = gBS->LocateHandleBuffer (ByProtocol,
+                  &gEmbeddedGpioProtocolGuid,
+                  NULL,
+                  &HandleCount,
+                  &HandleBuffer);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Unable to locate handles\n", __FUNCTION__));
+    return Status;
+  }
+
+  /* Iterate over all protocol producers */
+  for (Index = 0; Index < HandleCount; Index++) {
+    /* Open device path protocol installed on each handle */
+    Status = gBS->OpenProtocol (HandleBuffer[Index],
+                    &gEfiDevicePathProtocolGuid,
+                    (VOID **)&DevicePath,
+                    gImageHandle,
+                    NULL,
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: Unable to find DevicePath\n", __FUNCTION__));
+      continue;
+    }
+
+    /*
+     * Check if the driver type matches the requested value.
+     * In case of the success open the GPIO protocol and return.
+     * If there is no match, repeat procedure with the next handle.
+     */
+    Status = MvGpioFindMatchingDriver (GpioDriverType,
+               HandleBuffer[Index],
+               DevicePath,
+               GpioProtocol);
+    if (Status == EFI_NOT_FOUND) {
+      continue;
+    } else if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR,
+        "%a: Unable to open GPIO protocol\n",
+        __FUNCTION__));
+    }
+
+    gBS->FreePool (HandleBuffer);
+
+    return Status;
+  }
+
+  /* No matching GPIO protocol producer was found */
+  gBS->FreePool (HandleBuffer);
+
+  return EFI_NOT_FOUND;
+}
+
+#endif // __MV_GPIO_PROTOCOL_H__
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
                   ` (6 preceding siblings ...)
  2019-01-10  1:44 ` [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-14 23:32   ` Leif Lindholm
  2019-01-10  1:44 ` [platforms: PATCH v2 09/12] Marvell/Drivers: I2c: Use common header for macros Marcin Wojtas
                   ` (3 subsequent siblings)
  11 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

Marvell Armada 7k/8k SoCs comprise integrated GPIO controllers,
one in AP806 and two in each south bridge hardware blocks.

This patch introduces support for them. The new driver implements
a generic EMBEDDED_GPIO protocol.

In order to ease description of used GPIO pins and controllers
of the Armada 7k8k platforms, add a common enum type.

Based on original work of Jing Hua <jinghua@marvell.com>.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf |  44 +++
 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h   |  49 +++
 Silicon/Marvell/Include/Protocol/MvGpio.h            |  10 +
 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c   | 372 ++++++++++++++++++++
 4 files changed, 475 insertions(+)
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c

diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
new file mode 100644
index 0000000..5ff9130
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
@@ -0,0 +1,44 @@
+## @file
+#
+#  Copyright (c) 2017, Marvell International 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                    = 0x0001001A
+  BASE_NAME                      = MvGpioDxe
+  FILE_GUID                      = 706eb761-b3b5-4f41-8558-5fd9217c0079
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = MvGpioEntryPoint
+
+[Sources]
+  MvGpioDxe.c
+  MvGpioDxe.h
+
+[Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+  ArmadaSoCDescLib
+  DebugLib
+  MemoryAllocationLib
+  UefiDriverEntryPoint
+  UefiLib
+
+[Protocols]
+  gEmbeddedGpioProtocolGuid
+  gMarvellBoardDescProtocolGuid
+
+[Depex]
+  TRUE
diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
new file mode 100644
index 0000000..4e5422b
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
@@ -0,0 +1,49 @@
+/**
+*
+*  Copyright (c) 2018, Marvell International 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 __MV_GPIO_H__
+#define __MV_GPIO_H__
+
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/IoLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/BoardDesc.h>
+#include <Protocol/MvGpio.h>
+
+#include <Uefi/UefiBaseType.h>
+
+#define MV_GPIO_SIGNATURE        SIGNATURE_32 ('G', 'P', 'I', 'O')
+
+// Marvell MV_GPIO Controller Registers
+#define MV_GPIO_DATA_OUT_REG     (0x0)
+#define MV_GPIO_OUT_EN_REG       (0x4)
+#define MV_GPIO_BLINK_EN_REG     (0x8)
+#define MV_GPIO_DATA_IN_POL_REG  (0xc)
+#define MV_GPIO_DATA_IN_REG      (0x10)
+
+typedef struct {
+  EMBEDDED_GPIO     GpioProtocol;
+  GPIO_CONTROLLER  *SoCGpio;
+  UINTN             GpioDeviceCount;
+  UINTN             Signature;
+  EFI_HANDLE        Handle;
+} MV_GPIO;
+
+#endif // __MV_GPIO_H__
diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
index c9f1007..3319b79 100644
--- a/Silicon/Marvell/Include/Protocol/MvGpio.h
+++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
@@ -27,6 +27,16 @@ typedef enum {
   MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
 } MV_GPIO_DRIVER_TYPE;
 
+typedef enum {
+  MV_GPIO_AP806_CONTROLLER0,
+  MV_GPIO_CP0_CONTROLLER0,
+  MV_GPIO_CP0_CONTROLLER1,
+  MV_GPIO_CP1_CONTROLLER0,
+  MV_GPIO_CP1_CONTROLLER1,
+  MV_GPIO_CP2_CONTROLLER0,
+  MV_GPIO_CP2_CONTROLLER1,
+} MV_GPIO_SOC_CONTROLLER_TYPE;
+
 typedef struct {
   VENDOR_DEVICE_PATH        Header;
   MV_GPIO_DRIVER_TYPE       GpioDriverType;
diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
new file mode 100644
index 0000000..4d5e530
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
@@ -0,0 +1,372 @@
+/**
+*
+*  Copyright (c) 2018, Marvell International 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 "MvGpioDxe.h"
+
+STATIC MV_GPIO *mGpioInstance;
+
+STATIC MV_GPIO_DEVICE_PATH mDevicePathTemplate = {
+  {
+    {
+      HARDWARE_DEVICE_PATH,
+      HW_VENDOR_DP,
+      {
+        (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
+                 sizeof (MV_GPIO_DRIVER_TYPE)),
+        (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
+                 sizeof (MV_GPIO_DRIVER_TYPE)) >> 8),
+      },
+    },
+    EFI_CALLER_ID_GUID
+  },
+  MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
+  {
+    END_DEVICE_PATH_TYPE,
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,
+    {
+      sizeof(EFI_DEVICE_PATH_PROTOCOL),
+      0
+    }
+  }
+};
+
+#if !defined(MDEPKG_NDEBUG)
+/**
+
+Routine Description:
+
+  Verifies if controller index / GPIO pin values
+  are within proper boundaries.
+
+Arguments:
+
+  ControllerIndex - index of controller
+  GpioPin - which pin to read
+
+Returns:
+
+  EFI_SUCCESS           - GPIO pin / controller index are proper
+  EFI_INVALID_PARAMETER - GPIO pin / controller index is out of range
+**/
+STATIC
+EFI_STATUS
+MvGpioValidate (
+  IN UINTN ControllerIndex,
+  IN UINTN GpioPin
+  )
+{
+  if (ControllerIndex >= mGpioInstance->GpioDeviceCount) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Invalid GPIO ControllerIndex: %d\n",
+      __FUNCTION__,
+      ControllerIndex));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (GpioPin >= mGpioInstance->SoCGpio[ControllerIndex].InternalGpioCount) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: GPIO pin #%d not available in Controller#%d\n",
+      __FUNCTION__,
+      GpioPin,
+      ControllerIndex));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  return EFI_SUCCESS;
+}
+#endif
+
+/**
+
+Routine Description:
+
+  Gets the mode (function) of a GPIO pin
+
+Arguments:
+
+  This  - pointer to protocol
+  Gpio  - which pin
+  Mode  - pointer to output mode value
+
+Returns:
+
+  EFI_SUCCESS           - mode value retrieved
+  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range
+
+**/
+STATIC
+EFI_STATUS
+MvGpioGetMode (
+  IN  EMBEDDED_GPIO       *This,
+  IN  EMBEDDED_GPIO_PIN    Gpio,
+  OUT EMBEDDED_GPIO_MODE  *Mode
+  )
+{
+  UINTN ControllerIndex;
+  UINTN BaseAddress;
+  UINTN GpioPin;
+
+  GpioPin = GPIO_PIN (Gpio);
+  ControllerIndex = GPIO_PORT (Gpio);
+
+  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
+
+  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
+
+  if (MmioRead32 (BaseAddress + MV_GPIO_OUT_EN_REG) & (1 << GpioPin)) {
+    *Mode = GPIO_MODE_INPUT;
+  } else {
+    if (MmioRead32 (BaseAddress + MV_GPIO_DATA_IN_REG) & (1 << GpioPin)) {
+      *Mode = GPIO_MODE_OUTPUT_1;
+    } else {
+      *Mode = GPIO_MODE_OUTPUT_0;
+    }
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+
+Routine Description:
+
+  Gets the state of a GPIO pin
+
+Arguments:
+
+  This  - pointer to protocol
+  Gpio  - which pin to read
+  Value - state of the pin
+
+Returns:
+
+  EFI_SUCCESS           - GPIO state returned in Value
+  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range
+**/
+STATIC
+EFI_STATUS
+MvGpioGet (
+  IN  EMBEDDED_GPIO      *This,
+  IN  EMBEDDED_GPIO_PIN   Gpio,
+  OUT UINTN              *Value
+  )
+{
+  UINTN ControllerIndex;
+  UINTN BaseAddress;
+  UINTN GpioPin;
+
+  GpioPin = GPIO_PIN (Gpio);
+  ControllerIndex = GPIO_PORT (Gpio);
+
+  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
+
+  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
+
+  if (MmioRead32 (BaseAddress + MV_GPIO_DATA_IN_REG) & (1 << GpioPin)) {
+    *Value = 1;
+  } else {
+    *Value = 0;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+
+Routine Description:
+
+  Sets the state of a GPIO pin
+
+Arguments:
+
+  This  - pointer to protocol
+  Gpio  - which pin to modify
+  Mode  - mode to set
+
+Returns:
+
+  EFI_SUCCESS           - GPIO set as requested
+  EFI_UNSUPPORTED       - Mode is not supported
+  EFI_INVALID_PARAMETER - Gpio pin is out of range
+**/
+STATIC
+EFI_STATUS
+MvGpioSet (
+  IN EMBEDDED_GPIO       *This,
+  IN EMBEDDED_GPIO_PIN    Gpio,
+  IN EMBEDDED_GPIO_MODE   Mode
+  )
+{
+  UINTN ControllerIndex;
+  UINTN BaseAddress;
+  UINTN GpioPin;
+
+  GpioPin = GPIO_PIN (Gpio);
+  ControllerIndex = GPIO_PORT (Gpio);
+
+  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
+
+  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
+
+  switch (Mode) {
+  case GPIO_MODE_OUTPUT_0:
+    MmioAnd32 (BaseAddress + MV_GPIO_DATA_OUT_REG, ~(1 << GpioPin));
+    MmioAnd32 (BaseAddress + MV_GPIO_OUT_EN_REG, ~(1 << GpioPin));
+    break;
+
+  case GPIO_MODE_OUTPUT_1:
+    MmioOr32 (BaseAddress + MV_GPIO_DATA_OUT_REG, (1 << GpioPin));
+    MmioAnd32 (BaseAddress + MV_GPIO_OUT_EN_REG, ~(1 << GpioPin));
+    break;
+
+  case GPIO_MODE_INPUT:
+    MmioOr32 (BaseAddress + MV_GPIO_OUT_EN_REG, (1 << GpioPin));
+    break;
+
+  default:
+    return EFI_UNSUPPORTED;
+  }
+ 
+  return EFI_SUCCESS;
+}
+
+/**
+
+Routine Description:
+
+  Sets the pull-up / pull-down resistor of a GPIO pin
+
+Arguments:
+
+  This  - pointer to protocol
+  Gpio  - which pin
+  Direction - pull-up, pull-down, or none
+
+Returns:
+
+  EFI_UNSUPPORTED - Can not perform the requested operation
+
+**/
+EFI_STATUS
+EFIAPI
+MvGpioSetPull (
+  IN  EMBEDDED_GPIO       *This,
+  IN  EMBEDDED_GPIO_PIN   Gpio,
+  IN  EMBEDDED_GPIO_PULL  Direction
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+STATIC
+VOID
+MvGpioInitProtocol (
+  IN EMBEDDED_GPIO *GpioProtocol
+  )
+{
+  GpioProtocol->Get     = MvGpioGet;
+  GpioProtocol->Set     = MvGpioSet;
+  GpioProtocol->GetMode = MvGpioGetMode;
+  GpioProtocol->SetPull = MvGpioSetPull;
+}
+
+EFI_STATUS
+EFIAPI
+MvGpioEntryPoint (
+  IN EFI_HANDLE       ImageHandle,
+  IN EFI_SYSTEM_TABLE *SystemTable
+  )
+{
+  MARVELL_BOARD_DESC_PROTOCOL *MvBoardProtocol;
+  MV_BOARD_GPIO_DESCRIPTION *GpioDescription;
+  MV_GPIO_DEVICE_PATH *GpioDevicePath;
+  EFI_STATUS Status;
+
+  GpioDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
+                     &mDevicePathTemplate);
+  if (GpioDevicePath == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  mGpioInstance = AllocateZeroPool (sizeof (MV_GPIO));
+  if (mGpioInstance == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto ErrGpioInstanceAlloc;
+  }
+
+  /* Obtain list of available controllers */
+  Status = gBS->LocateProtocol (&gMarvellBoardDescProtocolGuid,
+                  NULL,
+                  (VOID **)&MvBoardProtocol);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Cannot locate BoardDesc protocol\n",
+      __FUNCTION__));
+    goto ErrLocateBoardDesc;
+  }
+
+  Status = MvBoardProtocol->GpioDescriptionGet (MvBoardProtocol,
+             &GpioDescription);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
+      __FUNCTION__));
+    goto ErrLocateBoardDesc;
+  }
+
+  mGpioInstance->Signature = MV_GPIO_SIGNATURE;
+  mGpioInstance->GpioDeviceCount = GpioDescription->GpioDeviceCount;
+  mGpioInstance->SoCGpio = AllocateCopyPool (sizeof (GPIO_CONTROLLER) *
+                             GpioDescription->GpioDeviceCount,
+                             GpioDescription->SoCGpio);
+  if (mGpioInstance->SoCGpio == NULL) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Fail to copy GPIO SoC controllers description\n",
+      __FUNCTION__));
+    Status = EFI_OUT_OF_RESOURCES;
+    goto ErrAllocateSoCGpio;
+  }
+
+  MvGpioInitProtocol (&mGpioInstance->GpioProtocol);
+
+  Status = gBS->InstallMultipleProtocolInterfaces (&(mGpioInstance->Handle),
+                  &gEmbeddedGpioProtocolGuid,
+                  &(mGpioInstance->GpioProtocol),
+                  &gEfiDevicePathProtocolGuid,
+                  (EFI_DEVICE_PATH_PROTOCOL *)GpioDevicePath,
+                  NULL);
+  if (EFI_ERROR (Status)) {
+    goto ErrInstallProtocols;
+  }
+
+  gBS->FreePool (GpioDescription->SoCGpio);
+  gBS->FreePool (GpioDescription);
+
+  return EFI_SUCCESS;
+
+ErrInstallProtocols:
+  gBS->FreePool (mGpioInstance->SoCGpio);
+
+ErrAllocateSoCGpio:
+  gBS->FreePool (GpioDescription->SoCGpio);
+  gBS->FreePool (GpioDescription);
+
+ErrLocateBoardDesc:
+  gBS->FreePool (mGpioInstance);
+
+ErrGpioInstanceAlloc:
+  gBS->FreePool (GpioDevicePath);
+
+  return Status;
+}
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 09/12] Marvell/Drivers: I2c: Use common header for macros
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
                   ` (7 preceding siblings ...)
  2019-01-10  1:44 ` [platforms: PATCH v2 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-10  1:44 ` [platforms: PATCH v2 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce GPIO expander driver Marcin Wojtas
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

Hitherto I2c solution used same macros, defined in multiple
places. Move them to a new common header.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
---
 Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.h | 10 -------
 Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.h       | 17 ++---------
 Silicon/Marvell/Include/Protocol/MvI2c.h              | 31 ++++++++++++++++++++
 Silicon/Marvell/Applications/EepromCmd/EepromCmd.c    |  5 +---
 Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.c |  3 +-
 Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c       |  4 +--
 6 files changed, 37 insertions(+), 33 deletions(-)
 create mode 100644 Silicon/Marvell/Include/Protocol/MvI2c.h

diff --git a/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.h b/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.h
index b1af645..c32ee48 100644
--- a/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.h
+++ b/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.h
@@ -41,16 +41,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #define MAX_BUFFER_LENGTH 64
 
-/*
- * I2C_FLAG_NORESTART is not part of PI spec, it allows to continue
- * transmission without repeated start operation.
- * FIXME: This flag is also defined in Drivers/I2c/MvI2cDxe/MvI2cDxe.h
- * and it's important to have both version synced. This solution is
- * temporary and shared flag should be used by both files.
- * Situation is analogous with I2C_GUID, which also should be common, but is
- * for now defined same way in two header files.
- */
-#define I2C_FLAG_NORESTART 0x00000002
 #define I2C_GUID \
   { \
   0xadc1901b, 0xb83c, 0x4831, { 0x8f, 0x59, 0x70, 0x89, 0x8f, 0x26, 0x57, 0x1e } \
diff --git a/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.h b/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.h
index 3c9beaf..6850c34 100644
--- a/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.h
+++ b/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.h
@@ -32,8 +32,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 *******************************************************************************/
 
-#ifndef __MV_I2C_H__
-#define __MV_I2C_H__
+#ifndef __MV_I2C_DXE_H__
+#define __MV_I2C_DXE_H__
 
 #include <Uefi.h>
 
@@ -75,17 +75,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #define I2C_FAST           0x2
 #define I2C_FASTEST        0x3
 
-/*
- * I2C_FLAG_NORESTART is not part of PI spec, it allows to continue
- * transmission without repeated start operation.
- * FIXME: This flag is also defined in
- * Platforms/Marvell/Include/Protocol/Eeprom.h and it's important to have both
- * version synced. This solution is temporary and shared flag should be used by
- * both files.
- * Situation is analogous with I2C_GUID, which also should be common, but is
- * for now defined same way in two header files.
- */
-#define I2C_FLAG_NORESTART 0x00000002
 #define I2C_GUID \
   { \
   0xadc1901b, 0xb83c, 0x4831, { 0x8f, 0x59, 0x70, 0x89, 0x8f, 0x26, 0x57, 0x1e } \
@@ -266,4 +255,4 @@ MvI2cEnableConf (
   IN EFI_STATUS                                          *I2cStatus OPTIONAL
   );
 
-#endif // __MV_I2C_H__
+#endif // __MV_I2C_DXE_H__
diff --git a/Silicon/Marvell/Include/Protocol/MvI2c.h b/Silicon/Marvell/Include/Protocol/MvI2c.h
new file mode 100644
index 0000000..d8e644e
--- /dev/null
+++ b/Silicon/Marvell/Include/Protocol/MvI2c.h
@@ -0,0 +1,31 @@
+/**
+*
+*  Copyright (c) 2018, Marvell International 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 __MV_I2C_H__
+#define __MV_I2C_H__
+
+/*
+ * I2C_FLAG_NORESTART is not part of PI spec, it allows to continue
+ * transmission without repeated start operation.
+ */
+#define I2C_FLAG_NORESTART             0x00000002
+
+/*
+ * Helper macros for maintaining multiple I2C buses
+ * and devices defined via EFI_I2C_DEVICE.
+ */
+#define I2C_DEVICE_ADDRESS(Index)      ((Index) & MAX_UINT16)
+#define I2C_DEVICE_BUS(Index)          ((Index) >> 16)
+#define I2C_DEVICE_INDEX(Bus, Address) (((Address) & MAX_UINT16) | (Bus) << 16)
+
+#endif
diff --git a/Silicon/Marvell/Applications/EepromCmd/EepromCmd.c b/Silicon/Marvell/Applications/EepromCmd/EepromCmd.c
index dc3c95f..712aba9 100644
--- a/Silicon/Marvell/Applications/EepromCmd/EepromCmd.c
+++ b/Silicon/Marvell/Applications/EepromCmd/EepromCmd.c
@@ -51,10 +51,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <Library/UefiBootServicesTableLib.h>
 
 #include <Protocol/Eeprom.h>
-
-#define I2C_DEVICE_INDEX(bus, address) (((address) & 0xffff) | (bus) << 16)
-#define I2C_DEVICE_ADDRESS(index) ((index) & 0xffff)
-#define I2C_DEVICE_BUS(index) ((index) >> 16)
+#include <Protocol/MvI2c.h>
 
 CONST CHAR16 ShellEepromFileName[] = L"ShellCommand";
 EFI_HANDLE ShellEepromHiiHandle = NULL;
diff --git a/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.c b/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.c
index 9d2f650..90d0d1e 100644
--- a/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.c
+++ b/Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.c
@@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <Protocol/DriverBinding.h>
 #include <Protocol/I2cIo.h>
 #include <Protocol/Eeprom.h>
+#include <Protocol/MvI2c.h>
 
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
@@ -49,8 +50,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include "MvEepromDxe.h"
 
-#define I2C_DEVICE_INDEX(bus, address) (((address) & 0xffff) | (bus) << 16)
-
 STATIC CONST EFI_GUID I2cGuid = I2C_GUID;
 
 EFI_DRIVER_BINDING_PROTOCOL gDriverBindingProtocol = {
diff --git a/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c b/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c
index 9ec4929..582e2b9 100755
--- a/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c
+++ b/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.c
@@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <Protocol/I2cEnumerate.h>
 #include <Protocol/I2cBusConfigurationManagement.h>
 #include <Protocol/DevicePath.h>
+#include <Protocol/MvI2c.h>
 
 #include <Library/BaseLib.h>
 #include <Library/IoLib.h>
@@ -628,9 +629,6 @@ MvI2cStartRequest (
 
 STATIC CONST EFI_GUID DevGuid = I2C_GUID;
 
-#define I2C_DEVICE_INDEX(bus, address) (((address) & 0xffff) | (bus) << 16)
-#define I2C_DEVICE_ADDRESS(index) ((index) & 0xffff)
-
 STATIC
 EFI_STATUS
 MvI2cAllocDevice (
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce GPIO expander driver
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
                   ` (8 preceding siblings ...)
  2019-01-10  1:44 ` [platforms: PATCH v2 09/12] Marvell/Drivers: I2c: Use common header for macros Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-14 23:40   ` Leif Lindholm
  2019-01-10  1:44 ` [platforms: PATCH v2 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation Marcin Wojtas
  2019-01-10  1:44 ` [platforms: PATCH v2 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines Marcin Wojtas
  11 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

Marvell Armada 7k/8k-based platforms may use Pca95xx to extend
amount of the GPIO pins.

This patch introduces support for them. The new driver implements
a generic EMBEDDED_GPIO protocol.

In order to ease description of used PCA9XXX controllers
add a common enum type. It can be used e.g. in the board description
library to specify the expander model on a board (instead of passing
a raw number). Update relevant libraries.

Driver is based on initial work done by Allen Yan <yanwei@marvell.com>.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf                        |  45 ++
 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h                          |  65 ++
 Silicon/Marvell/Include/Protocol/MvGpio.h                                         |  16 +
 Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c |   2 +-
 Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c |   4 +-
 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c                          | 651 ++++++++++++++++++++
 6 files changed, 780 insertions(+), 3 deletions(-)
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
 create mode 100644 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c

diff --git a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
new file mode 100644
index 0000000..3b1ab4e
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
@@ -0,0 +1,45 @@
+## @file
+#
+#  Copyright (c) 2017, Marvell International 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                    = 0x0001001A
+  BASE_NAME                      = MvPca95xxDxe
+  FILE_GUID                      = f0e405eb-8407-43b9-88e6-2f7d70715c72
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = MvPca95xxEntryPoint
+
+[Sources]
+  MvPca95xxDxe.c
+  MvPca95xxDxe.h
+
+[Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+  DebugLib
+  MemoryAllocationLib
+  UefiDriverEntryPoint
+  UefiLib
+
+[Protocols]
+  gEfiDriverBindingProtocolGuid
+  gEfiI2cIoProtocolGuid
+  gEmbeddedGpioProtocolGuid
+  gMarvellBoardDescProtocolGuid
+
+[Depex]
+  TRUE
diff --git a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
new file mode 100644
index 0000000..1fed739
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
@@ -0,0 +1,65 @@
+/**
+*
+*  Copyright (c) 2018, Marvell International 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 __MV_PCA953X_H__
+#define __MV_PCA953X_H__
+
+#include <Library/ArmadaBoardDescLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/IoLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/BoardDesc.h>
+#include <Protocol/MvGpio.h>
+#include <Protocol/MvI2c.h>
+
+#include <Uefi/UefiBaseType.h>
+
+#define PCA95XX_GPIO_SIGNATURE   SIGNATURE_32 ('I', 'O', 'E', 'X')
+
+#define PCA95XX_INPUT_REG        0x0
+#define PCA95XX_OUTPUT_REG       0x2
+#define PCA95XX_DIRECTION_REG    0x6
+
+#define PCA95XX_BANK_SIZE        8
+#define PCA95XX_OPERATION_COUNT  2
+#define PCA95XX_OPERATION_LENGTH 1
+
+typedef enum {
+  PCA9505_PIN_COUNT = 40,
+  PCA9534_PIN_COUNT = 8,
+  PCA9535_PIN_COUNT = 16,
+  PCA9536_PIN_COUNT = 4,
+  PCA9537_PIN_COUNT = 4,
+  PCA9538_PIN_COUNT = 8,
+  PCA9539_PIN_COUNT = 16,
+  PCA9554_PIN_COUNT = 8,
+  PCA9555_PIN_COUNT = 16,
+  PCA9556_PIN_COUNT = 16,
+  PCA9557_PIN_COUNT = 16,
+} PCA95XX_PIN_COUNT;
+
+typedef struct {
+  EMBEDDED_GPIO      GpioProtocol;
+  MV_GPIO_EXPANDER  *GpioExpanders;
+  UINTN              GpioExpanderCount;
+  UINTN              Signature;
+  EFI_HANDLE         ControllerHandle;
+} PCA95XX;
+
+#endif
diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
index 3319b79..5037fc2 100644
--- a/Silicon/Marvell/Include/Protocol/MvGpio.h
+++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
@@ -25,6 +25,7 @@
 
 typedef enum {
   MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
+  MV_GPIO_DRIVER_TYPE_PCA95XX,
 } MV_GPIO_DRIVER_TYPE;
 
 typedef enum {
@@ -37,6 +38,21 @@ typedef enum {
   MV_GPIO_CP2_CONTROLLER1,
 } MV_GPIO_SOC_CONTROLLER_TYPE;
 
+typedef enum {
+  PCA9505_ID,
+  PCA9534_ID,
+  PCA9535_ID,
+  PCA9536_ID,
+  PCA9537_ID,
+  PCA9538_ID,
+  PCA9539_ID,
+  PCA9554_ID,
+  PCA9555_ID,
+  PCA9556_ID,
+  PCA9557_ID,
+  PCA95XX_MAX_ID,
+} MV_GPIO_EXPANDER_TYPE_PCA95XX;
+
 typedef struct {
   VENDOR_DEVICE_PATH        Header;
   MV_GPIO_DRIVER_TYPE       GpioDriverType;
diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
index f63d8fd..9595b01 100644
--- a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
+++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
@@ -27,7 +27,7 @@
 // GPIO Expander
 //
 STATIC MV_GPIO_EXPANDER mGpioExpander = {
-  8, /* PCA9555 */
+  PCA9555_ID,
   0x21,
   0x0,
 };
diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
index f6e3675..a1ac4bf 100644
--- a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
+++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
@@ -28,12 +28,12 @@
 //
 STATIC MV_GPIO_EXPANDER mGpioExpanders[] = {
   {
-    8, /* PCA9555 */
+    PCA9555_ID,
     0x21,
     0x0,
   },
   {
-    8, /* PCA9555 */
+    PCA9555_ID,
     0x25,
     0x0,
   },
diff --git a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
new file mode 100644
index 0000000..37c2b27
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
@@ -0,0 +1,651 @@
+/**
+*
+*  Copyright (c) 2018, Marvell International 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 <Protocol/I2cIo.h>
+
+#include <Pi/PiI2c.h>
+
+#include "MvPca95xxDxe.h"
+
+STATIC PCA95XX *mPca95xxInstance;
+
+STATIC MV_GPIO_DEVICE_PATH mDevicePathTemplate = {
+  {
+    {
+      HARDWARE_DEVICE_PATH,
+      HW_VENDOR_DP,
+      {
+        (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
+                 sizeof (MV_GPIO_DRIVER_TYPE)),
+        (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
+                 sizeof (MV_GPIO_DRIVER_TYPE)) >> 8),
+      },
+    },
+    EFI_CALLER_ID_GUID
+  },
+  MV_GPIO_DRIVER_TYPE_PCA95XX,
+  {
+    END_DEVICE_PATH_TYPE,
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,
+    {
+      sizeof(EFI_DEVICE_PATH_PROTOCOL),
+      0
+    }
+  }
+};
+
+STATIC PCA95XX_PIN_COUNT mPca95xxPinCount[PCA95XX_MAX_ID] = {
+  PCA9505_PIN_COUNT,
+  PCA9534_PIN_COUNT,
+  PCA9535_PIN_COUNT,
+  PCA9536_PIN_COUNT,
+  PCA9537_PIN_COUNT,
+  PCA9538_PIN_COUNT,
+  PCA9539_PIN_COUNT,
+  PCA9554_PIN_COUNT,
+  PCA9555_PIN_COUNT,
+  PCA9556_PIN_COUNT,
+  PCA9557_PIN_COUNT,
+};
+
+#if !defined(MDEPKG_NDEBUG)
+/**
+
+Routine Description:
+
+  Verifies if controller index / GPIO pin values
+  are within proper boundaries.
+
+Arguments:
+
+  ControllerIndex - index of controller
+  GpioPin - which pin to read
+
+Returns:
+
+  EFI_SUCCESS           - GPIO pin / controller index are proper
+  EFI_INVALID_PARAMETER - GPIO pin / controller index is out of range
+**/
+STATIC
+EFI_STATUS
+MvPca95xxValidate (
+  IN UINTN ControllerIndex,
+  IN UINTN GpioPin
+  )
+{
+  UINTN ControllerId;
+
+  if (ControllerIndex >= mPca95xxInstance->GpioExpanderCount) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Invalid GPIO ControllerIndex: %d\n",
+      __FUNCTION__,
+      ControllerIndex));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  ControllerId = mPca95xxInstance->GpioExpanders[ControllerIndex].ChipId;
+
+  if (GpioPin >= mPca95xxPinCount[ControllerId]) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: GPIO pin #%d not available in Controller#%d\n",
+      __FUNCTION__,
+      GpioPin,
+      ControllerIndex));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  return EFI_SUCCESS;
+}
+#endif
+
+EFI_STATUS
+EFIAPI
+MvPca95xxGetI2c (
+  IN     UINTN                 ControllerIndex,
+  IN OUT EFI_I2C_IO_PROTOCOL **I2cIo
+  )
+{
+  UINTN        I2cBus, I2cAddress;
+  UINTN        HandleCount, Index;
+  EFI_HANDLE  *HandleBuffer;
+  EFI_STATUS   Status;
+
+  I2cBus = mPca95xxInstance->GpioExpanders[ControllerIndex].I2cBus;
+  I2cAddress = mPca95xxInstance->GpioExpanders[ControllerIndex].I2cAddress;
+
+  /* Locate Handles of all EfiI2cIoProtocol producers */
+  Status = gBS->LocateHandleBuffer (ByProtocol,
+                  &gEfiI2cIoProtocolGuid,
+                  NULL,
+                  &HandleCount,
+                  &HandleBuffer);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Unable to locate handles\n", __FUNCTION__));
+    return Status;
+  }
+
+  /* Iterate over all protocol producers and pick one upon DeviceIndex match */
+  for (Index = 0; Index < HandleCount; Index++) {
+    Status = gBS->OpenProtocol (HandleBuffer[Index],
+                    &gEfiI2cIoProtocolGuid,
+                    (VOID **)I2cIo,
+                    gImageHandle,
+                    NULL,
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: Unable to open protocol\n", __FUNCTION__));
+      gBS->FreePool (HandleBuffer);
+      return Status;
+    }
+    if ((*I2cIo)->DeviceIndex == I2C_DEVICE_INDEX (I2cBus, I2cAddress)) {
+      gBS->FreePool (HandleBuffer);
+      return EFI_SUCCESS;
+    }
+  }
+
+  gBS->FreePool (HandleBuffer);
+
+  return EFI_NOT_FOUND;
+}
+
+EFI_STATUS
+EFIAPI
+MvPca95xxI2cTransfer (
+  IN EFI_I2C_IO_PROTOCOL *I2cIo,
+  IN UINT8                Address,
+  IN UINT8               *Buffer,
+  IN UINT32               Flag
+  )
+{
+  EFI_I2C_REQUEST_PACKET *RequestPacket;
+  UINTN RequestPacketSize;
+  UINT8 AddressBuffer;
+  EFI_STATUS Status;
+
+  RequestPacketSize = sizeof (UINTN) +
+                      sizeof (EFI_I2C_OPERATION) * PCA95XX_OPERATION_COUNT;
+  RequestPacket = AllocateZeroPool (RequestPacketSize);
+  if (RequestPacket == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  /* Operations contain address and payload, consecutively. */
+  RequestPacket->OperationCount = PCA95XX_OPERATION_COUNT;
+  RequestPacket->Operation[0].LengthInBytes = PCA95XX_OPERATION_LENGTH;
+  RequestPacket->Operation[0].Buffer = &AddressBuffer;
+  RequestPacket->Operation[0].Buffer[0] = Address & MAX_UINT8;
+  RequestPacket->Operation[1].LengthInBytes = PCA95XX_OPERATION_LENGTH;
+  RequestPacket->Operation[1].Buffer = Buffer;
+  RequestPacket->Operation[1].Flags = Flag;
+
+  Status = I2cIo->QueueRequest (I2cIo, 0, NULL, RequestPacket, NULL);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: transmission error: 0x%d\n",
+      __FUNCTION__,
+      Status));
+  }
+
+  gBS->FreePool(RequestPacket);
+
+  return Status;
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxReadRegs (
+  IN  EFI_I2C_IO_PROTOCOL *I2cIo,
+  IN  UINT8                Reg,
+  OUT UINT8               *RegVal
+  )
+{
+  return MvPca95xxI2cTransfer (I2cIo, Reg, RegVal, I2C_FLAG_READ);
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxWriteRegs (
+  IN  EFI_I2C_IO_PROTOCOL *I2cIo,
+  IN  UINTN                Reg,
+  IN  UINT8                RegVal
+  )
+{
+  return MvPca95xxI2cTransfer (I2cIo, Reg, &RegVal, I2C_FLAG_NORESTART);
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxSetOutputValue (
+  IN UINTN               ControllerIndex,
+  IN UINTN               GpioPin,
+  IN EMBEDDED_GPIO_MODE  Mode
+  )
+{
+  EFI_I2C_IO_PROTOCOL *I2cIo;
+  EFI_STATUS Status;
+  UINT8 RegVal;
+  UINTN Bank;
+
+  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
+    return EFI_DEVICE_ERROR;
+  }
+
+  Bank = GpioPin / PCA95XX_BANK_SIZE;
+
+  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_OUTPUT_REG + Bank, &RegVal);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
+    return EFI_DEVICE_ERROR;
+  }
+
+  if (Mode == GPIO_MODE_OUTPUT_1) {
+    RegVal |= (1 << (GpioPin % PCA95XX_BANK_SIZE));
+  } else {
+    RegVal &= ~(1 << (GpioPin % PCA95XX_BANK_SIZE));
+  }
+
+  Status = MvPca95xxWriteRegs (I2cIo, PCA95XX_OUTPUT_REG + Bank, RegVal);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: fail to write device register\n", __FUNCTION__));
+    return EFI_DEVICE_ERROR;
+  }
+
+  return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxSetDirection (
+  IN UINTN              ControllerIndex,
+  IN UINTN              GpioPin,
+  IN EMBEDDED_GPIO_MODE Mode
+  )
+{
+  EFI_I2C_IO_PROTOCOL *I2cIo;
+  EFI_STATUS Status;
+  UINT8 RegVal;
+  UINTN Bank;
+
+  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
+    return Status;
+  }
+
+  Bank = GpioPin / PCA95XX_BANK_SIZE;
+
+  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_DIRECTION_REG + Bank, &RegVal);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
+    return Status;
+  }
+
+  if (Mode == GPIO_MODE_INPUT) {
+    RegVal |= (1 << (GpioPin % PCA95XX_BANK_SIZE));
+  } else {
+    RegVal &= ~(1 << (GpioPin % PCA95XX_BANK_SIZE));
+  }
+
+  Status = MvPca95xxWriteRegs (I2cIo, PCA95XX_DIRECTION_REG + Bank, RegVal);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: fail to write device register\n", __FUNCTION__));
+    return Status;
+  }
+
+  return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxReadMode (
+  IN  UINTN               ControllerIndex,
+  IN  UINTN               GpioPin,
+  OUT EMBEDDED_GPIO_MODE *Mode
+  )
+{
+  EFI_I2C_IO_PROTOCOL *I2cIo;
+  EFI_STATUS Status;
+  UINT8 RegVal;
+  UINTN Bank;
+
+  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
+
+  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
+    return Status;
+  }
+
+  Bank = GpioPin / PCA95XX_BANK_SIZE;
+
+  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_DIRECTION_REG + Bank, &RegVal);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
+    return Status;
+  }
+
+  if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
+    *Mode = GPIO_MODE_INPUT;
+  } else {
+    Status = MvPca95xxReadRegs (I2cIo, PCA95XX_INPUT_REG + Bank, &RegVal);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
+      return Status;
+    }
+
+    if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
+      *Mode = GPIO_MODE_OUTPUT_1;
+    } else {
+      *Mode = GPIO_MODE_OUTPUT_0;
+    }
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+
+Routine Description:
+
+  Gets the mode (function) of a GPIO pin
+
+Arguments:
+
+  This  - pointer to protocol
+  Gpio  - which pin
+  Mode  - pointer to output mode value
+
+Returns:
+
+  EFI_SUCCESS           - mode value retrieved
+  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range
+
+**/
+STATIC
+EFI_STATUS
+MvPca95xxGetMode (
+  IN  EMBEDDED_GPIO       *This,
+  IN  EMBEDDED_GPIO_PIN    Gpio,
+  OUT EMBEDDED_GPIO_MODE  *Mode
+  )
+{
+  EFI_STATUS Status;
+  UINTN ControllerIndex;
+  UINTN GpioPin;
+
+  GpioPin = GPIO_PIN (Gpio);
+  ControllerIndex = GPIO_PORT (Gpio);
+
+  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
+
+  Status = MvPca95xxReadMode (ControllerIndex, GpioPin, Mode);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: fail to get pin %d of controller#%d mode\n",
+      __FUNCTION__,
+      GpioPin,
+      ControllerIndex));
+  }
+
+  return Status;
+}
+
+/**
+
+Routine Description:
+
+  Gets the state of a GPIO pin
+
+Arguments:
+
+  This  - pointer to protocol
+  Gpio  - which pin to read
+  Value - state of the pin
+
+Returns:
+
+  EFI_SUCCESS           - GPIO state returned in Value
+  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range
+**/
+STATIC
+EFI_STATUS
+MvPca95xxGet (
+  IN  EMBEDDED_GPIO      *This,
+  IN  EMBEDDED_GPIO_PIN   Gpio,
+  OUT UINTN              *Value
+  )
+{
+  EFI_I2C_IO_PROTOCOL *I2cIo;
+  EFI_STATUS Status;
+  UINTN ControllerIndex;
+  UINTN GpioPin;
+  UINT8 RegVal;
+  UINTN Bank;
+
+  GpioPin = GPIO_PIN (Gpio);
+  ControllerIndex = GPIO_PORT (Gpio);
+
+  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
+
+  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
+    return Status;
+  }
+
+  Bank = GpioPin / PCA95XX_BANK_SIZE;
+
+  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_INPUT_REG + Bank, &RegVal);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
+    return Status;
+  }
+
+  if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
+    *Value = 1;
+  } else {
+    *Value = 0;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+
+Routine Description:
+
+  Sets the state of a GPIO pin
+
+Arguments:
+
+  This  - pointer to protocol
+  Gpio  - which pin to modify
+  Mode  - mode to set
+
+Returns:
+
+  EFI_SUCCESS           - GPIO set as requested
+  EFI_UNSUPPORTED       - Mode is not supported
+  EFI_INVALID_PARAMETER - Gpio pin is out of range
+**/
+STATIC
+EFI_STATUS
+MvPca95xxSet (
+  IN EMBEDDED_GPIO       *This,
+  IN EMBEDDED_GPIO_PIN   Gpio,
+  IN EMBEDDED_GPIO_MODE  Mode
+  )
+{
+  EFI_STATUS Status;
+  UINTN ControllerIndex;
+  UINTN GpioPin;
+
+  GpioPin = GPIO_PIN (Gpio);
+  ControllerIndex = GPIO_PORT (Gpio);
+
+  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
+
+  switch (Mode) {
+  case GPIO_MODE_OUTPUT_0:
+  case GPIO_MODE_OUTPUT_1:
+    Status = MvPca95xxSetOutputValue (ControllerIndex, GpioPin, Mode);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: fail to set ouput value\n", __FUNCTION__));
+      return Status;
+    }
+
+  /* Fall-through */
+  case GPIO_MODE_INPUT:
+    Status = MvPca95xxSetDirection (ControllerIndex, GpioPin, Mode);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: fail to set direction\n", __FUNCTION__));
+      return Status;
+    }
+    break;
+
+  default:
+    return EFI_UNSUPPORTED;
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+
+Routine Description:
+
+  Sets the pull-up / pull-down resistor of a GPIO pin
+
+Arguments:
+
+  This  - pointer to protocol
+  Gpio  - which pin
+  Direction - pull-up, pull-down, or none
+
+Returns:
+
+  EFI_UNSUPPORTED - Can not perform the requested operation
+
+**/
+EFI_STATUS
+EFIAPI
+MvPca95xxSetPull (
+  IN EMBEDDED_GPIO       *This,
+  IN EMBEDDED_GPIO_PIN   Gpio,
+  IN EMBEDDED_GPIO_PULL  Direction
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+STATIC
+VOID
+MvPca95xxInitProtocol (
+  IN EMBEDDED_GPIO *GpioProtocol
+  )
+{
+  GpioProtocol->Get     = MvPca95xxGet;
+  GpioProtocol->Set     = MvPca95xxSet;
+  GpioProtocol->GetMode = MvPca95xxGetMode;
+  GpioProtocol->SetPull = MvPca95xxSetPull;
+}
+
+EFI_STATUS
+EFIAPI
+MvPca95xxEntryPoint (
+  IN EFI_HANDLE       ImageHandle,
+  IN EFI_SYSTEM_TABLE *SystemTable
+  )
+{
+  MARVELL_BOARD_DESC_PROTOCOL *MvBoardProtocol;
+  MV_BOARD_GPIO_DESCRIPTION *GpioDescription;
+  MV_GPIO_DEVICE_PATH *Pca95xxDevicePath;
+  EFI_STATUS Status;
+
+  /* Obtain list of available controllers */
+  Status = gBS->LocateProtocol (&gMarvellBoardDescProtocolGuid,
+                  NULL,
+                  (VOID **)&MvBoardProtocol);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Cannot locate BoardDesc protocol\n",
+      __FUNCTION__));
+    return Status;
+  }
+
+  Status = MvBoardProtocol->GpioDescriptionGet (MvBoardProtocol,
+             &GpioDescription);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
+      __FUNCTION__));
+    return Status;
+  } else if (GpioDescription->GpioExpanders == NULL) {
+    /* Silently exit, if the board does not support the controllers */
+    return EFI_SUCCESS;
+  }
+
+  Pca95xxDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
+                        &mDevicePathTemplate);
+  if (Pca95xxDevicePath == NULL) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Fail to allocate Pca95xxDevicePath\n",
+      __FUNCTION__));
+    Status = EFI_OUT_OF_RESOURCES;
+    goto ErrPca95xxDevicePathAlloc;
+  }
+
+  mPca95xxInstance = AllocateZeroPool (sizeof (PCA95XX));
+  if (mPca95xxInstance == NULL) {
+    DEBUG ((DEBUG_ERROR,
+      "%a: Fail to allocate mPca95xxInstance\n",
+      __FUNCTION__));
+    Status = EFI_OUT_OF_RESOURCES;
+    goto ErrPca95xxInstanceAlloc;
+  }
+
+  MvPca95xxInitProtocol (&mPca95xxInstance->GpioProtocol);
+
+  mPca95xxInstance->Signature = PCA95XX_GPIO_SIGNATURE;
+  mPca95xxInstance->GpioExpanders = GpioDescription->GpioExpanders;
+  mPca95xxInstance->GpioExpanderCount = GpioDescription->GpioExpanderCount;
+
+  Status = gBS->InstallMultipleProtocolInterfaces (
+                  &(mPca95xxInstance->ControllerHandle),
+                  &gEmbeddedGpioProtocolGuid,
+                  &(mPca95xxInstance->GpioProtocol),
+                  &gEfiDevicePathProtocolGuid,
+                  (EFI_DEVICE_PATH_PROTOCOL *)Pca95xxDevicePath,
+                  NULL);
+  if (EFI_ERROR (Status)) {
+    goto ErrInstallProtocols;
+  }
+
+  gBS->FreePool (GpioDescription);
+
+  return EFI_SUCCESS;
+
+ErrInstallProtocols:
+  gBS->FreePool (mPca95xxInstance);
+
+ErrPca95xxInstanceAlloc:
+  gBS->FreePool (Pca95xxDevicePath);
+
+ErrPca95xxDevicePathAlloc:
+  gBS->FreePool (GpioDescription);
+
+  return Status;
+}
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
                   ` (9 preceding siblings ...)
  2019-01-10  1:44 ` [platforms: PATCH v2 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce GPIO expander driver Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-10  1:44 ` [platforms: PATCH v2 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines Marcin Wojtas
  11 siblings, 0 replies; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

Enable building new GPIO drivers before adding VBUS
pins handling. Update relevant boards .dsc files with
IO expander information.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
---
 Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc             | 2 ++
 Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc            | 4 ++--
 Platform/Marvell/Armada70x0Db/Armada70x0Db.fdf.inc        | 2 ++
 Platform/Marvell/Armada80x0Db/Armada80x0Db.fdf.inc        | 2 ++
 Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.fdf.inc | 2 ++
 5 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc b/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
index b3fd184..a0175de 100644
--- a/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
+++ b/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
@@ -455,6 +455,8 @@
   Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf
 
   # Platform drivers
+  Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
+  Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
   Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf
   MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.inf
   Silicon/Marvell/Drivers/I2c/MvEepromDxe/MvEepromDxe.inf
diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
index a935f36..31815e4 100644
--- a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
+++ b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
@@ -89,8 +89,8 @@
   gMarvellTokenSpaceGuid.PcdChip1MppSel6|{ 0xE, 0xE, 0xE, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }
 
   # I2C
-  gMarvellTokenSpaceGuid.PcdI2cSlaveAddresses|{ 0x50, 0x57, 0x60 }
-  gMarvellTokenSpaceGuid.PcdI2cSlaveBuses|{ 0x0, 0x0, 0x0 }
+  gMarvellTokenSpaceGuid.PcdI2cSlaveAddresses|{ 0x50, 0x57, 0x60, 0x21 }
+  gMarvellTokenSpaceGuid.PcdI2cSlaveBuses|{ 0x0, 0x0, 0x0, 0x0 }
   gMarvellTokenSpaceGuid.PcdI2cControllersEnabled|{ 0x1, 0x1 }
   gMarvellTokenSpaceGuid.PcdEepromI2cAddresses|{ 0x50, 0x57 }
   gMarvellTokenSpaceGuid.PcdEepromI2cBuses|{ 0x0, 0x0 }
diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0Db.fdf.inc b/Platform/Marvell/Armada70x0Db/Armada70x0Db.fdf.inc
index b7e7a65..7129606 100644
--- a/Platform/Marvell/Armada70x0Db/Armada70x0Db.fdf.inc
+++ b/Platform/Marvell/Armada70x0Db/Armada70x0Db.fdf.inc
@@ -12,6 +12,8 @@
 
 # Per-board additional content of the DXE phase firmware volume
 
+  INF Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
+
   # DTB
   INF RuleOverride = DTB Silicon/Marvell/Armada7k8k/DeviceTree/Armada70x0Db.inf
 
diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0Db.fdf.inc b/Platform/Marvell/Armada80x0Db/Armada80x0Db.fdf.inc
index 81a81d0..f2fcc55 100644
--- a/Platform/Marvell/Armada80x0Db/Armada80x0Db.fdf.inc
+++ b/Platform/Marvell/Armada80x0Db/Armada80x0Db.fdf.inc
@@ -12,6 +12,8 @@
 
 # Per-board additional content of the DXE phase firmware volume
 
+  INF Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
+
   # DTB
   INF RuleOverride = DTB Silicon/Marvell/Armada7k8k/DeviceTree/Armada80x0Db.inf
 
diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.fdf.inc b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.fdf.inc
index 326da2e..254fcee 100644
--- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.fdf.inc
+++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.fdf.inc
@@ -12,6 +12,8 @@
 
 # Per-board additional content of the DXE phase firmware volume
 
+  INF Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
+
   # DTB
   INF RuleOverride = DTB Silicon/Marvell/Armada7k8k/DeviceTree/Armada80x0McBin.inf
 
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [platforms: PATCH v2 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines
  2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
                   ` (10 preceding siblings ...)
  2019-01-10  1:44 ` [platforms: PATCH v2 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation Marcin Wojtas
@ 2019-01-10  1:44 ` Marcin Wojtas
  2019-01-14 23:44   ` Leif Lindholm
  11 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-10  1:44 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap

To abstract the initialization required for non-discoverable devices,
which is often platform specific (e.g. enable GPIO-driven power supply),
introduce a NonDiscoverableInitLib for use by the NonDiscoverable code,
for which each platform can supply its own version.

Add XHCI power supply (so called 'VBUS') enabling routines
for supported platforms (Armada70x0Db, Armada80x0Db, Armada80x0McBin).

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 Silicon/Marvell/Marvell.dec                                                         |   1 +
 Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc                                      |   3 +
 Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc                                      |   3 +
 Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc                               |   3 +
 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf     |  48 +++++++++
 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf     |  49 +++++++++
 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf |  49 +++++++++
 Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf                   |   1 +
 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h       |  23 +++++
 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h       |  28 ++++++
 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h   |  20 ++++
 Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h                            |  28 ++++++
 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c       |  96 ++++++++++++++++++
 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c       | 106 ++++++++++++++++++++
 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c   |  71 +++++++++++++
 Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c                     |  13 ++-
 16 files changed, 539 insertions(+), 3 deletions(-)
 create mode 100644 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
 create mode 100644 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
 create mode 100644 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
 create mode 100644 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
 create mode 100644 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
 create mode 100644 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h
 create mode 100644 Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
 create mode 100644 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
 create mode 100644 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
 create mode 100644 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c

diff --git a/Silicon/Marvell/Marvell.dec b/Silicon/Marvell/Marvell.dec
index 616624e..12bac55 100644
--- a/Silicon/Marvell/Marvell.dec
+++ b/Silicon/Marvell/Marvell.dec
@@ -63,6 +63,7 @@
   ArmadaBoardDescLib|Include/Library/ArmadaBoardDescLib.h
   ArmadaIcuLib|Include/Library/ArmadaIcuLib.h
   ArmadaSoCDescLib|Include/Library/ArmadaSoCDescLib.h
+  NonDiscoverableInitLib|Include/Library/NonDiscoverableInitLib.h
   SampleAtResetLib|Include/Library/SampleAtResetLib.h
 
 [Protocols]
diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
index 31815e4..e8cd177 100644
--- a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
+++ b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
@@ -48,6 +48,9 @@
 
 !include Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
 
+[LibraryClasses.common]
+  NonDiscoverableInitLib|Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
+
 [Components.common]
   Silicon/Marvell/Armada7k8k/DeviceTree/Armada70x0Db.inf
 
diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc b/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
index 42f7bd3..8e8c2ba 100644
--- a/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
+++ b/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
@@ -48,6 +48,9 @@
 
 !include Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
 
+[LibraryClasses.common]
+  NonDiscoverableInitLib|Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
+
 [Components.common]
   Silicon/Marvell/Armada7k8k/DeviceTree/Armada80x0Db.inf
 
diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
index 077224d..d080136 100644
--- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
+++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
@@ -49,6 +49,9 @@
 
 !include Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
 
+[LibraryClasses.common]
+  NonDiscoverableInitLib|Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
+
 [Components.common]
   Silicon/Marvell/Armada7k8k/DeviceTree/Armada80x0McBin.inf
 
diff --git a/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
new file mode 100644
index 0000000..8d33e1d
--- /dev/null
+++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
@@ -0,0 +1,48 @@
+## @file
+#
+#  Copyright (c) 2017, Linaro 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                    = 0x0001001A
+  BASE_NAME                      = Armada70x0DbNonDiscoverableInitLib
+  FILE_GUID                      = 151b04bc-9195-4380-b1fa-987130b450f0
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = NonDiscoverableInitLib
+
+#
+# The following information is for reference only and not required by the build
+# tools.
+#
+#  VALID_ARCHITECTURES           = AARCH64
+#
+
+[Sources]
+  NonDiscoverableInitLib.c
+
+[Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+  DebugLib
+  IoLib
+
+[Protocols]
+  gEmbeddedGpioProtocolGuid
+
+[Depex]
+  gMarvellPlatformInitCompleteProtocolGuid
diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
new file mode 100644
index 0000000..e69e48a
--- /dev/null
+++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
@@ -0,0 +1,49 @@
+## @file
+#
+#  Copyright (c) 2017, Linaro Ltd. All rights reserved.<BR>
+#  Copyright (c) 2018, Marvell International 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                    = 0x0001001A
+  BASE_NAME                      = Armada80x0DbNonDiscoverableInitLib
+  FILE_GUID                      = 719c91d5-25aa-4366-988a-1642ae3a6734
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = NonDiscoverableInitLib
+
+#
+# The following information is for reference only and not required by the build
+# tools.
+#
+#  VALID_ARCHITECTURES           = AARCH64
+#
+
+[Sources]
+  NonDiscoverableInitLib.c
+
+[Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+  DebugLib
+  IoLib
+
+[Protocols]
+  gEmbeddedGpioProtocolGuid
+
+[Depex]
+  gMarvellPlatformInitCompleteProtocolGuid
diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
new file mode 100644
index 0000000..d0190b6
--- /dev/null
+++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
@@ -0,0 +1,49 @@
+## @file
+#
+#  Copyright (c) 2017, Linaro Ltd. All rights reserved.<BR>
+#  Copyright (c) 2018, Marvell International 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                    = 0x0001001A
+  BASE_NAME                      = Armada80x0McBinNonDiscoverableInitLib
+  FILE_GUID                      = 470963c4-476e-4b85-a7c4-17868177f441
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = NonDiscoverableInitLib
+
+#
+# The following information is for reference only and not required by the build
+# tools.
+#
+#  VALID_ARCHITECTURES           = AARCH64
+#
+
+[Sources]
+  NonDiscoverableInitLib.c
+
+[Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+  DebugLib
+  IoLib
+
+[Protocols]
+  gEmbeddedGpioProtocolGuid
+
+[Depex]
+  gMarvellPlatformInitCompleteProtocolGuid
diff --git a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf
index 98e5b0c..3f9f7bc 100644
--- a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf
+++ b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf
@@ -50,6 +50,7 @@
 
 [LibraryClasses]
   NonDiscoverableDeviceRegistrationLib
+  NonDiscoverableInitLib
   UefiDriverEntryPoint
 
 [Protocols]
diff --git a/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
new file mode 100644
index 0000000..8a0e424
--- /dev/null
+++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
@@ -0,0 +1,23 @@
+/**
+*
+*  Copyright (c) 2018, Marvell International 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 __NON_DISCOVERABLE_INIT_LIB_H__
+#define __NON_DISCOVERABLE_INIT_LIB_H__
+
+#define ARMADA_70x0_DB_IO_EXPANDER0       0
+#define ARMADA_70x0_DB_VBUS0_PIN          0
+#define ARMADA_70x0_DB_VBUS0_LIMIT_PIN    4
+#define ARMADA_70x0_DB_VBUS1_PIN          1
+#define ARMADA_70x0_DB_VBUS1_LIMIT_PIN    5
+
+#endif
diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
new file mode 100644
index 0000000..64373ff
--- /dev/null
+++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
@@ -0,0 +1,28 @@
+/**
+*
+*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
+*  Copyright (c) 2018, Marvell International 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 __NON_DISCOVERABLE_INIT_LIB_H__
+#define __NON_DISCOVERABLE_INIT_LIB_H__
+
+#define ARMADA_80x0_DB_IO_EXPANDER0       0
+#define ARMADA_80x0_DB_VBUS0_PIN          0
+#define ARMADA_80x0_DB_VBUS0_LIMIT_PIN    4
+#define ARMADA_80x0_DB_VBUS1_PIN          1
+#define ARMADA_80x0_DB_VBUS1_LIMIT_PIN    5
+
+#define ARMADA_80x0_DB_IO_EXPANDER1       1
+#define ARMADA_80x0_DB_VBUS2_PIN          0
+#define ARMADA_80x0_DB_VBUS2_LIMIT_PIN    4
+
+#endif
diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h
new file mode 100644
index 0000000..38e1f20
--- /dev/null
+++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h
@@ -0,0 +1,20 @@
+/**
+*
+*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
+*  Copyright (c) 2018, Marvell International 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 __NON_DISCOVERABLE_INIT_LIB_H__
+#define __NON_DISCOVERABLE_INIT_LIB_H__
+
+#define ARMADA_80x0_MCBIN_VBUS0_PIN               15
+
+#endif
diff --git a/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h b/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
new file mode 100644
index 0000000..18de24f
--- /dev/null
+++ b/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
@@ -0,0 +1,28 @@
+/**
+*
+*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
+*  Copyright (c) 2018, Marvell International 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 __NON_DISCOVERABLE_INIT_LIB_H__
+#define __NON_DISCOVERABLE_INIT_LIB_H__
+
+#include <Library/NonDiscoverableDeviceRegistrationLib.h>
+
+NON_DISCOVERABLE_DEVICE_INIT
+EFIAPI
+NonDiscoverableDeviceInitializerGet (
+  IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
+  IN  UINTN                         Index
+  );
+
+#endif
diff --git a/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
new file mode 100644
index 0000000..586b189
--- /dev/null
+++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
@@ -0,0 +1,96 @@
+/**
+*
+*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
+*  Copyright (c) 2018, Marvell International 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 <Uefi.h>
+
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/IoLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/NonDiscoverableDeviceRegistrationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Protocol/MvGpio.h>
+#include <Protocol/NonDiscoverableDevice.h>
+
+#include "NonDiscoverableInitLib.h"
+
+STATIC CONST MV_GPIO_PIN mXhciVbusPins[] = {
+  {
+    ARMADA_70x0_DB_IO_EXPANDER0,
+    ARMADA_70x0_DB_VBUS0_PIN,
+    TRUE,
+  },
+  {
+    ARMADA_70x0_DB_IO_EXPANDER0,
+    ARMADA_70x0_DB_VBUS0_LIMIT_PIN,
+    TRUE,
+  },
+  {
+    ARMADA_70x0_DB_IO_EXPANDER0,
+    ARMADA_70x0_DB_VBUS1_PIN,
+    TRUE,
+  },
+  {
+    ARMADA_70x0_DB_IO_EXPANDER0,
+    ARMADA_70x0_DB_VBUS1_LIMIT_PIN,
+    TRUE,
+  },
+};
+
+STATIC
+EFI_STATUS
+EFIAPI
+XhciInit (
+  IN  NON_DISCOVERABLE_DEVICE  *This
+  )
+{
+  CONST MV_GPIO_PIN   *VbusPin;
+  EMBEDDED_GPIO_MODE   Mode;
+  EMBEDDED_GPIO_PIN    Gpio;
+  EMBEDDED_GPIO       *GpioProtocol;
+  EFI_STATUS           Status;
+  UINTN                Index;
+
+  Status = MvGpioGetProtocol (MV_GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
+    return Status;
+  }
+
+  VbusPin = mXhciVbusPins;
+  for (Index = 0; Index < ARRAY_SIZE (mXhciVbusPins); Index++) {
+    Mode = VbusPin->ActiveHigh ? GPIO_MODE_OUTPUT_1 : GPIO_MODE_OUTPUT_0;
+    Gpio = GPIO (VbusPin->ControllerId, VbusPin->PinNumber);
+    GpioProtocol->Set (GpioProtocol, Gpio, Mode);
+    VbusPin++;
+  }
+
+  return EFI_SUCCESS;
+}
+
+NON_DISCOVERABLE_DEVICE_INIT
+EFIAPI
+NonDiscoverableDeviceInitializerGet (
+  IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
+  IN  UINTN                         Index
+  )
+{
+  if (Type == NonDiscoverableDeviceTypeXhci) {
+        return XhciInit;
+  }
+
+  return NULL;
+}
diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
new file mode 100644
index 0000000..3988f9a
--- /dev/null
+++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
@@ -0,0 +1,106 @@
+/**
+*
+*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
+*  Copyright (c) 2018, Marvell International 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 <Uefi.h>
+
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/IoLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/NonDiscoverableDeviceRegistrationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Protocol/MvGpio.h>
+#include <Protocol/NonDiscoverableDevice.h>
+
+#include "NonDiscoverableInitLib.h"
+
+STATIC CONST MV_GPIO_PIN mXhciVbusPins[] = {
+  {
+    ARMADA_80x0_DB_IO_EXPANDER0,
+    ARMADA_80x0_DB_VBUS0_PIN,
+    TRUE,
+  },
+  {
+    ARMADA_80x0_DB_IO_EXPANDER0,
+    ARMADA_80x0_DB_VBUS0_LIMIT_PIN,
+    TRUE,
+  },
+  {
+    ARMADA_80x0_DB_IO_EXPANDER0,
+    ARMADA_80x0_DB_VBUS1_PIN,
+    TRUE,
+  },
+  {
+    ARMADA_80x0_DB_IO_EXPANDER0,
+    ARMADA_80x0_DB_VBUS1_LIMIT_PIN,
+    TRUE,
+  },
+  {
+    ARMADA_80x0_DB_IO_EXPANDER1,
+    ARMADA_80x0_DB_VBUS2_PIN,
+    TRUE,
+  },
+  {
+    ARMADA_80x0_DB_IO_EXPANDER1,
+    ARMADA_80x0_DB_VBUS2_LIMIT_PIN,
+    TRUE,
+  },
+};
+
+STATIC
+EFI_STATUS
+EFIAPI
+XhciInit (
+  IN  NON_DISCOVERABLE_DEVICE  *This
+  )
+{
+  CONST MV_GPIO_PIN   *VbusPin;
+  EMBEDDED_GPIO_MODE   Mode;
+  EMBEDDED_GPIO_PIN    Gpio;
+  EMBEDDED_GPIO       *GpioProtocol;
+  EFI_STATUS           Status;
+  UINTN                Index;
+
+  Status = MvGpioGetProtocol (MV_GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
+    return Status;
+  }
+
+  VbusPin = mXhciVbusPins;
+  for (Index = 0; Index < ARRAY_SIZE (mXhciVbusPins); Index++) {
+    Mode = VbusPin->ActiveHigh ? GPIO_MODE_OUTPUT_1 : GPIO_MODE_OUTPUT_0;
+    Gpio = GPIO (VbusPin->ControllerId, VbusPin->PinNumber);
+    GpioProtocol->Set (GpioProtocol, Gpio, Mode);
+    VbusPin++;
+  }
+
+  return EFI_SUCCESS;
+}
+
+NON_DISCOVERABLE_DEVICE_INIT
+EFIAPI
+NonDiscoverableDeviceInitializerGet (
+  IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
+  IN  UINTN                         Index
+  )
+{
+  if (Type == NonDiscoverableDeviceTypeXhci) {
+        return XhciInit;
+  }
+
+  return NULL;
+}
diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
new file mode 100644
index 0000000..676feeb
--- /dev/null
+++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
@@ -0,0 +1,71 @@
+/**
+*
+*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
+*  Copyright (c) 2018, Marvell International 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 <Uefi.h>
+
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/IoLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/NonDiscoverableDeviceRegistrationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Protocol/MvGpio.h>
+#include <Protocol/NonDiscoverableDevice.h>
+
+#include "NonDiscoverableInitLib.h"
+
+STATIC CONST MV_GPIO_PIN mXhciVbusPin = {
+  MV_GPIO_CP0_CONTROLLER1,
+  ARMADA_80x0_MCBIN_VBUS0_PIN,
+  TRUE,
+};
+
+STATIC
+EFI_STATUS
+EFIAPI
+XhciInit (
+  IN  NON_DISCOVERABLE_DEVICE  *This
+  )
+{
+  EMBEDDED_GPIO  *GpioProtocol;
+  EFI_STATUS      Status;
+
+  Status = MvGpioGetProtocol (MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER, &GpioProtocol);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
+    return Status;
+  }
+
+  GpioProtocol->Set (GpioProtocol,
+                  GPIO (mXhciVbusPin.ControllerId, mXhciVbusPin.PinNumber),
+                  GPIO_MODE_OUTPUT_1);
+
+  return Status;
+}
+
+NON_DISCOVERABLE_DEVICE_INIT
+EFIAPI
+NonDiscoverableDeviceInitializerGet (
+  IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
+  IN  UINTN                         Index
+  )
+{
+  if (Type == NonDiscoverableDeviceTypeXhci) {
+        return XhciInit;
+  }
+
+  return NULL;
+}
diff --git a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c
index 116e9d4..74040b2 100644
--- a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c
+++ b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c
@@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #include <Library/DebugLib.h>
 #include <Library/NonDiscoverableDeviceRegistrationLib.h>
+#include <Library/NonDiscoverableInitLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 
 #include <Protocol/BoardDesc.h>
@@ -57,7 +58,9 @@ NonDiscoverableInitXhci (
     Status = RegisterNonDiscoverableMmioDevice (
                      NonDiscoverableDeviceTypeXhci,
                      Desc[i].SoC->XhciDmaType,
-                     NULL,
+                     NonDiscoverableDeviceInitializerGet (
+                       NonDiscoverableDeviceTypeXhci,
+                       i),
                      NULL,
                      1,
                      Desc[i].SoC->XhciBaseAddress,
@@ -86,7 +89,9 @@ NonDiscoverableInitAhci (
     Status = RegisterNonDiscoverableMmioDevice (
                      NonDiscoverableDeviceTypeAhci,
                      Desc[i].SoC->AhciDmaType,
-                     NULL,
+                     NonDiscoverableDeviceInitializerGet (
+                       NonDiscoverableDeviceTypeAhci,
+                       i),
                      NULL,
                      1,
                      Desc[i].SoC->AhciBaseAddress,
@@ -115,7 +120,9 @@ NonDiscoverableInitSdhci (
     Status = RegisterNonDiscoverableMmioDevice (
                      NonDiscoverableDeviceTypeSdhci,
                      Desc[i].SoC->SdMmcDmaType,
-                     NULL,
+                     NonDiscoverableDeviceInitializerGet (
+                       NonDiscoverableDeviceTypeSdhci,
+                       i),
                      NULL,
                      1,
                      Desc[i].SoC->SdMmcBaseAddress,
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 04/12] Marvell/Armada70x0Db: Extend board description library with GPIO
  2019-01-10  1:44 ` [platforms: PATCH v2 04/12] Marvell/Armada70x0Db: " Marcin Wojtas
@ 2019-01-14 22:41   ` Leif Lindholm
  2019-01-15  5:48     ` Marcin Wojtas
  0 siblings, 1 reply; 34+ messages in thread
From: Leif Lindholm @ 2019-01-14 22:41 UTC (permalink / raw)
  To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap

On Thu, Jan 10, 2019 at 02:44:31AM +0100, Marcin Wojtas wrote:
> This patch implements ArmadaBoarDescLib library for
> Armada70x0Db comunity board and introduces ArmadaBoardGpioGet
> routine with per-board GPIO expander description.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf |  1 +
>  Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c   | 25 ++++++++++++++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
> index b26f55b..c995515 100644
> --- a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
> +++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
> @@ -25,6 +25,7 @@
>    Armada70x0DbBoardDescLib.c
>  
>  [Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    MdePkg/MdePkg.dec
>    Silicon/Marvell/Marvell.dec
> diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
> index 48c68e4..f63d8fd 100644
> --- a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
> +++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
> @@ -21,6 +21,31 @@
>  #include <Library/MemoryAllocationLib.h>
>  #include <Library/UefiBootServicesTableLib.h>
>  
> +#include <Protocol/MvGpio.h>
> +
> +//
> +// GPIO Expander
> +//
> +STATIC MV_GPIO_EXPANDER mGpioExpander = {
> +  8, /* PCA9555 */

Why did you drop the use of the still existing enumeration in favour
of live coding the integer value that it currently produces for the
member PCA9555_ID?

/
    Leif

> +  0x21,
> +  0x0,
> +};
> +
> +
> +EFI_STATUS
> +EFIAPI
> +ArmadaBoardGpioExpanderGet (
> +  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
> +  IN OUT UINTN             *GpioExpanderCount
> +  )
> +{
> +  *GpioExpanderCount = 1;
> +  *GpioExpanders = &mGpioExpander;
> +
> +  return EFI_SUCCESS;
> +}
> +
>  //
>  // Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
>  //
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 05/12] Marvell/Armada80x0Db: Extend board description library with GPIO
  2019-01-10  1:44 ` [platforms: PATCH v2 05/12] Marvell/Armada80x0Db: " Marcin Wojtas
@ 2019-01-14 22:44   ` Leif Lindholm
  0 siblings, 0 replies; 34+ messages in thread
From: Leif Lindholm @ 2019-01-14 22:44 UTC (permalink / raw)
  To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap

On Thu, Jan 10, 2019 at 02:44:32AM +0100, Marcin Wojtas wrote:
> This patch implements ArmadaBoarDescLib library for
> Armada80x0Db comunity board and introduces ArmadaBoardGpioGet
> routine with per-board GPIO expander description.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf |  1 +
>  Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c   | 31 ++++++++++++++++++++
>  2 files changed, 32 insertions(+)
> 
> diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
> index 2d39d96..786b7f0 100644
> --- a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
> +++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
> @@ -25,6 +25,7 @@
>    Armada80x0DbBoardDescLib.c
>  
>  [Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    MdePkg/MdePkg.dec
>    Silicon/Marvell/Marvell.dec
> diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
> index feb69ad..f6e3675 100644
> --- a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
> +++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
> @@ -21,6 +21,37 @@
>  #include <Library/MemoryAllocationLib.h>
>  #include <Library/UefiBootServicesTableLib.h>
>  
> +#include <Protocol/MvGpio.h>
> +
> +//
> +// GPIO Expanders
> +//
> +STATIC MV_GPIO_EXPANDER mGpioExpanders[] = {
> +  {
> +    8, /* PCA9555 */

Same as for 4/12.

> +    0x21,
> +    0x0,
> +  },
> +  {
> +    8, /* PCA9555 */

And again.

Please re-jig such that the enum appears in time to be used by this
and preceding patches, then resubmit affected patches.

/
    Leif

> +    0x25,
> +    0x0,
> +  },
> +};
> +
> +EFI_STATUS
> +EFIAPI
> +ArmadaBoardGpioExpanderGet (
> +  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
> +  IN OUT UINTN             *GpioExpanderCount
> +  )
> +{
> +  *GpioExpanderCount = ARRAY_SIZE (mGpioExpanders);
> +  *GpioExpanders = mGpioExpanders;
> +
> +  return EFI_SUCCESS;
> +}
> +
>  //
>  // Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
>  //
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
  2019-01-10  1:44 ` [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support Marcin Wojtas
@ 2019-01-14 22:58   ` Leif Lindholm
  2019-01-15  6:05     ` Marcin Wojtas
  0 siblings, 1 reply; 34+ messages in thread
From: Leif Lindholm @ 2019-01-14 22:58 UTC (permalink / raw)
  To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap

On Thu, Jan 10, 2019 at 02:44:33AM +0100, Marcin Wojtas wrote:
> Introduce new callback that can provide information
> about GPIO SoC controllers, as well as on-board
> I2C IO expanders. According ArmadaSoCDescLib
> ArmadaBoardDescLib routines are used for
> obtaining required data.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Silicon/Marvell/Include/Protocol/BoardDesc.h       |  8 ++++
>  Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c | 43 ++++++++++++++++++++
>  2 files changed, 51 insertions(+)
> 
> diff --git a/Silicon/Marvell/Include/Protocol/BoardDesc.h b/Silicon/Marvell/Include/Protocol/BoardDesc.h
> index 1d57a16..02905ea 100644
> --- a/Silicon/Marvell/Include/Protocol/BoardDesc.h
> +++ b/Silicon/Marvell/Include/Protocol/BoardDesc.h
> @@ -50,6 +50,13 @@ EFI_STATUS
>  
>  typedef
>  EFI_STATUS
> +(EFIAPI *MV_BOARD_GPIO_DESCRIPTION_GET) (
> +  IN MARVELL_BOARD_DESC_PROTOCOL    *This,
> +  IN OUT MV_BOARD_GPIO_DESCRIPTION **GpioDescription
> +  );
> +
> +typedef
> +EFI_STATUS
>  (EFIAPI *MV_BOARD_DESC_I2C_GET) (
>    IN MARVELL_BOARD_DESC_PROTOCOL  *This,
>    IN OUT MV_BOARD_I2C_DESC       **I2cDesc
> @@ -113,6 +120,7 @@ struct _MARVELL_BOARD_DESC_PROTOCOL {
>    MV_BOARD_DESC_UTMI_GET         BoardDescUtmiGet;
>    MV_BOARD_DESC_XHCI_GET         BoardDescXhciGet;
>    MV_BOARD_DESC_FREE             BoardDescFree;
> +  MV_BOARD_GPIO_DESCRIPTION_GET  GpioDescriptionGet;
>  };
>  
>  #endif // __MARVELL_BOARD_DESC_PROTOCOL_H__
> diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> index f71bfc4..e348b85 100644
> --- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> @@ -100,6 +100,48 @@ MvBoardDescComPhyGet (
>  
>  STATIC
>  EFI_STATUS
> +MvBoardGpioDescriptionGet (
> +  IN MARVELL_BOARD_DESC_PROTOCOL    *This,
> +  IN OUT MV_BOARD_GPIO_DESCRIPTION **GpioDescription
> +  )
> +{
> +  MV_BOARD_GPIO_DESCRIPTION *Description;

My request on v1 was that this be refactored from a STATIC local
variable to a global variable.

> +  UINTN SoCGpioCount, GpioExpanderCount;
> +  MV_GPIO_EXPANDER *GpioExpanders;
> +  GPIO_CONTROLLER *SoCGpio;
> +  EFI_STATUS Status;
> +
> +  /* Get SoC data about all available GPIO controllers */
> +  Status = ArmadaSoCGpioGet (&SoCGpio, &SoCGpioCount);
> +  if (EFI_ERROR (Status)) {
> +    return Status;
> +  }
> +
> +  /* Get per-board information about all available I2C IO expanders */

GPIO

> +  Status = ArmadaBoardGpioExpanderGet (&GpioExpanders, &GpioExpanderCount);
> +  if (EFI_ERROR (Status)) {
> +    return Status;
> +  }
> +
> +  /* Allocate and fill board description */
> +  Description = AllocateZeroPool (sizeof (MV_BOARD_GPIO_DESCRIPTION));

Instead, this space is now dynamically allocated. But none of the call
sites actually change, leading to potential memory leaks.

I don't have a problem if you prefer an alternative solution to the
one I propose, but please discuss the change first rather than
submitting a new revision containing something I didn't ask for.

/
    Leif

> +  if (Description == NULL) {
> +    DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> +
> +  Description->SoCGpio = SoCGpio;
> +  Description->GpioDeviceCount = SoCGpioCount;
> +  Description->GpioExpanders = GpioExpanders;
> +  Description->GpioExpanderCount = GpioExpanderCount;
> +
> +  *GpioDescription = Description;
> +
> +  return EFI_SUCCESS;
> +}
> +
> +STATIC
> +EFI_STATUS
>  MvBoardDescI2cGet (
>    IN MARVELL_BOARD_DESC_PROTOCOL  *This,
>    IN OUT MV_BOARD_I2C_DESC       **I2cDesc
> @@ -571,6 +613,7 @@ MvBoardDescInitProtocol (
>    BoardDescProtocol->BoardDescUtmiGet = MvBoardDescUtmiGet;
>    BoardDescProtocol->BoardDescXhciGet = MvBoardDescXhciGet;
>    BoardDescProtocol->BoardDescFree = MvBoardDescFree;
> +  BoardDescProtocol->GpioDescriptionGet = MvBoardGpioDescriptionGet;
>  
>    return EFI_SUCCESS;
>  }
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header
  2019-01-10  1:44 ` [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header Marcin Wojtas
@ 2019-01-14 23:12   ` Leif Lindholm
  2019-01-15  6:12     ` Marcin Wojtas
  0 siblings, 1 reply; 34+ messages in thread
From: Leif Lindholm @ 2019-01-14 23:12 UTC (permalink / raw)
  To: Marcin Wojtas
  Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap, jinghua

On Thu, Jan 10, 2019 at 02:44:34AM +0100, Marcin Wojtas wrote:
> From: jinghua <jinghua@marvell.com>
> 
> This patch introduces a helper header that can be used by
> multiple EMBEDDED_GPIO protocol producers (e.g. platform
> driver or GPIO expanders). The drives are differentiated by
> MV_GPIO_DRIVER_TYPE field of driver's MV_GPIO_DEVICE_PATH.
> 
> In order to ease selection of the desired GPIO controller
> a helper function was added - MarvellGpioGetProtocol().
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Silicon/Marvell/Include/Protocol/MvGpio.h | 156 ++++++++++++++++++++
>  1 file changed, 156 insertions(+)
>  create mode 100644 Silicon/Marvell/Include/Protocol/MvGpio.h
> 
> diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
> new file mode 100644
> index 0000000..c9f1007
> --- /dev/null
> +++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
> @@ -0,0 +1,156 @@
> +/**
> +*
> +*  Copyright (C) 2018, Marvell International Ltd. and its affiliates.
> +*
> +*  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 __MV_GPIO_PROTOCOL_H__
> +#define __MV_GPIO_PROTOCOL_H__
> +
> +#include <Uefi.h>
> +
> +#include <Library/DebugLib.h>
> +#include <Library/DevicePathLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +
> +#include <Protocol/EmbeddedGpio.h>
> +
> +typedef enum {
> +  MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
> +} MV_GPIO_DRIVER_TYPE;
> +
> +typedef struct {
> +  VENDOR_DEVICE_PATH        Header;
> +  MV_GPIO_DRIVER_TYPE       GpioDriverType;
> +  EFI_DEVICE_PATH_PROTOCOL  End;
> +} MV_GPIO_DEVICE_PATH;
> +
> +typedef struct {
> +  UINTN    ControllerId;
> +  UINTN    PinNumber;
> +  BOOLEAN  ActiveHigh;
> +} MV_GPIO_PIN;
> +
> +/*
> + * Check if the driver type matches the requested value.
> + * In case of the success open the GPIO protocol and return.
> + */
> +STATIC
> +inline
> +EFI_STATUS
> +EFIAPI
> +MvGpioFindMatchingDriver (

Eep!
I missed this in v1 (I assumed I'd missed the new file indicator
whilst scrolling) - please move these functions out of this .h file.
https://edk2-docs.gitbooks.io/edk-ii-c-coding-standards-specification/content/v/release/2.20/5_source_files/53_include_files.html#537-include-files-shall-not-generate-code-or-define-data-variables

This makes me take a closer look at the rest of the patch ... and this
just isn't a protocol - it's a library. Please restrucure it as such
and move the header file to Include/Library rather than
Include/Protocol.

/
    Leif

> +  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
> +  IN     EFI_HANDLE             HandleBuffer,
> +  IN     EFI_DEVICE_PATH       *DevicePath,
> +  IN OUT EMBEDDED_GPIO        **GpioProtocol
> +  )
> +{
> +  MV_GPIO_DEVICE_PATH *GpioDevicePath;
> +  EFI_STATUS           Status;
> +
> +  while (!IsDevicePathEndType (DevicePath)) {
> +    /* Check if GpioDriverType matches one found in the device path */
> +    GpioDevicePath = (MV_GPIO_DEVICE_PATH *)DevicePath;
> +    if (GpioDevicePath->GpioDriverType != GpioDriverType) {
> +      DevicePath = NextDevicePathNode (DevicePath);
> +      continue;
> +    }
> +
> +    /*
> +     * Open GpioProtocol. With EFI_OPEN_PROTOCOL_GET_PROTOCOL attribute
> +     * the consumer is not obliged to call CloseProtocol.
> +     */
> +    Status = gBS->OpenProtocol (HandleBuffer,
> +                    &gEmbeddedGpioProtocolGuid,
> +                    (VOID **)GpioProtocol,
> +                    gImageHandle,
> +                    NULL,
> +                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> +    return Status;
> +  }
> +
> +  return EFI_NOT_FOUND;
> +}
> +
> +/*
> + * Select desired protocol producer upon MV_GPIO_DRIVER_TYPE
> + * field of driver's MV_GPIO_DEVICE_PATH.
> + */
> +STATIC
> +inline
> +EFI_STATUS
> +EFIAPI
> +MvGpioGetProtocol (
> +  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
> +  IN OUT EMBEDDED_GPIO        **GpioProtocol
> +  )
> +{
> +  EFI_DEVICE_PATH     *DevicePath;
> +  EFI_HANDLE          *HandleBuffer;
> +  EFI_STATUS           Status;
> +  UINTN                HandleCount;
> +  UINTN                Index;
> +
> +  /* Locate Handles of all EMBEDDED_GPIO producers */
> +  Status = gBS->LocateHandleBuffer (ByProtocol,
> +                  &gEmbeddedGpioProtocolGuid,
> +                  NULL,
> +                  &HandleCount,
> +                  &HandleBuffer);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: Unable to locate handles\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  /* Iterate over all protocol producers */
> +  for (Index = 0; Index < HandleCount; Index++) {
> +    /* Open device path protocol installed on each handle */
> +    Status = gBS->OpenProtocol (HandleBuffer[Index],
> +                    &gEfiDevicePathProtocolGuid,
> +                    (VOID **)&DevicePath,
> +                    gImageHandle,
> +                    NULL,
> +                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "%a: Unable to find DevicePath\n", __FUNCTION__));
> +      continue;
> +    }
> +
> +    /*
> +     * Check if the driver type matches the requested value.
> +     * In case of the success open the GPIO protocol and return.
> +     * If there is no match, repeat procedure with the next handle.
> +     */
> +    Status = MvGpioFindMatchingDriver (GpioDriverType,
> +               HandleBuffer[Index],
> +               DevicePath,
> +               GpioProtocol);
> +    if (Status == EFI_NOT_FOUND) {
> +      continue;
> +    } else if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR,
> +        "%a: Unable to open GPIO protocol\n",
> +        __FUNCTION__));
> +    }
> +
> +    gBS->FreePool (HandleBuffer);
> +
> +    return Status;
> +  }
> +
> +  /* No matching GPIO protocol producer was found */
> +  gBS->FreePool (HandleBuffer);
> +
> +  return EFI_NOT_FOUND;
> +}
> +
> +#endif // __MV_GPIO_PROTOCOL_H__
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver
  2019-01-10  1:44 ` [platforms: PATCH v2 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver Marcin Wojtas
@ 2019-01-14 23:32   ` Leif Lindholm
  2019-01-15  6:19     ` Marcin Wojtas
  0 siblings, 1 reply; 34+ messages in thread
From: Leif Lindholm @ 2019-01-14 23:32 UTC (permalink / raw)
  To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap

On Thu, Jan 10, 2019 at 02:44:35AM +0100, Marcin Wojtas wrote:
> Marvell Armada 7k/8k SoCs comprise integrated GPIO controllers,
> one in AP806 and two in each south bridge hardware blocks.
> 
> This patch introduces support for them. The new driver implements
> a generic EMBEDDED_GPIO protocol.
> 
> In order to ease description of used GPIO pins and controllers
> of the Armada 7k8k platforms, add a common enum type.
> 
> Based on original work of Jing Hua <jinghua@marvell.com>.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf |  44 +++
>  Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h   |  49 +++
>  Silicon/Marvell/Include/Protocol/MvGpio.h            |  10 +
>  Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c   | 372 ++++++++++++++++++++
>  4 files changed, 475 insertions(+)
>  create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
>  create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
>  create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
> 
> diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
> new file mode 100644
> index 0000000..5ff9130
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
> @@ -0,0 +1,44 @@
> +## @file
> +#
> +#  Copyright (c) 2017, Marvell International 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                    = 0x0001001A
> +  BASE_NAME                      = MvGpioDxe
> +  FILE_GUID                      = 706eb761-b3b5-4f41-8558-5fd9217c0079
> +  MODULE_TYPE                    = DXE_DRIVER
> +  VERSION_STRING                 = 1.0
> +  ENTRY_POINT                    = MvGpioEntryPoint
> +
> +[Sources]
> +  MvGpioDxe.c
> +  MvGpioDxe.h
> +
> +[Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  MdePkg/MdePkg.dec
> +  Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> +  ArmadaSoCDescLib
> +  DebugLib
> +  MemoryAllocationLib
> +  UefiDriverEntryPoint
> +  UefiLib
> +
> +[Protocols]
> +  gEmbeddedGpioProtocolGuid
> +  gMarvellBoardDescProtocolGuid
> +
> +[Depex]
> +  TRUE
> diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
> new file mode 100644
> index 0000000..4e5422b
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
> @@ -0,0 +1,49 @@
> +/**
> +*
> +*  Copyright (c) 2018, Marvell International 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 __MV_GPIO_H__
> +#define __MV_GPIO_H__
> +
> +
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/DevicePathLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +#include <Library/UefiLib.h>
> +
> +#include <Protocol/BoardDesc.h>
> +#include <Protocol/MvGpio.h>
> +
> +#include <Uefi/UefiBaseType.h>
> +
> +#define MV_GPIO_SIGNATURE        SIGNATURE_32 ('G', 'P', 'I', 'O')

Unaddressed feedback from last time. But rereading it makes it clear
my feedback was too imprecise, apologies. The point was that "GPIO" is
not a very good choice of key to distinguish _this_ GPIO driver from
other GPIO drivers. (As well as the MV_ prefix.)

One more comment below, but it does not require code changes.
If you can just change the signature, I'm happy with this patch.

> +
> +// Marvell MV_GPIO Controller Registers
> +#define MV_GPIO_DATA_OUT_REG     (0x0)
> +#define MV_GPIO_OUT_EN_REG       (0x4)
> +#define MV_GPIO_BLINK_EN_REG     (0x8)
> +#define MV_GPIO_DATA_IN_POL_REG  (0xc)
> +#define MV_GPIO_DATA_IN_REG      (0x10)
> +
> +typedef struct {
> +  EMBEDDED_GPIO     GpioProtocol;
> +  GPIO_CONTROLLER  *SoCGpio;
> +  UINTN             GpioDeviceCount;
> +  UINTN             Signature;
> +  EFI_HANDLE        Handle;
> +} MV_GPIO;
> +
> +#endif // __MV_GPIO_H__
> diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
> index c9f1007..3319b79 100644
> --- a/Silicon/Marvell/Include/Protocol/MvGpio.h
> +++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
> @@ -27,6 +27,16 @@ typedef enum {
>    MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
>  } MV_GPIO_DRIVER_TYPE;
>  
> +typedef enum {
> +  MV_GPIO_AP806_CONTROLLER0,
> +  MV_GPIO_CP0_CONTROLLER0,
> +  MV_GPIO_CP0_CONTROLLER1,
> +  MV_GPIO_CP1_CONTROLLER0,
> +  MV_GPIO_CP1_CONTROLLER1,
> +  MV_GPIO_CP2_CONTROLLER0,
> +  MV_GPIO_CP2_CONTROLLER1,
> +} MV_GPIO_SOC_CONTROLLER_TYPE;
> +
>  typedef struct {
>    VENDOR_DEVICE_PATH        Header;
>    MV_GPIO_DRIVER_TYPE       GpioDriverType;
> diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
> new file mode 100644
> index 0000000..4d5e530
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
> @@ -0,0 +1,372 @@
> +/**
> +*
> +*  Copyright (c) 2018, Marvell International 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 "MvGpioDxe.h"
> +
> +STATIC MV_GPIO *mGpioInstance;
> +
> +STATIC MV_GPIO_DEVICE_PATH mDevicePathTemplate = {
> +  {
> +    {
> +      HARDWARE_DEVICE_PATH,
> +      HW_VENDOR_DP,
> +      {
> +        (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
> +                 sizeof (MV_GPIO_DRIVER_TYPE)),
> +        (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
> +                 sizeof (MV_GPIO_DRIVER_TYPE)) >> 8),
> +      },
> +    },
> +    EFI_CALLER_ID_GUID
> +  },
> +  MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
> +  {
> +    END_DEVICE_PATH_TYPE,
> +    END_ENTIRE_DEVICE_PATH_SUBTYPE,
> +    {
> +      sizeof(EFI_DEVICE_PATH_PROTOCOL),
> +      0
> +    }
> +  }
> +};
> +
> +#if !defined(MDEPKG_NDEBUG)
> +/**
> +
> +Routine Description:
> +
> +  Verifies if controller index / GPIO pin values
> +  are within proper boundaries.
> +
> +Arguments:
> +
> +  ControllerIndex - index of controller
> +  GpioPin - which pin to read
> +
> +Returns:
> +
> +  EFI_SUCCESS           - GPIO pin / controller index are proper
> +  EFI_INVALID_PARAMETER - GPIO pin / controller index is out of range
> +**/
> +STATIC
> +EFI_STATUS
> +MvGpioValidate (
> +  IN UINTN ControllerIndex,
> +  IN UINTN GpioPin
> +  )
> +{
> +  if (ControllerIndex >= mGpioInstance->GpioDeviceCount) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: Invalid GPIO ControllerIndex: %d\n",
> +      __FUNCTION__,
> +      ControllerIndex));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  if (GpioPin >= mGpioInstance->SoCGpio[ControllerIndex].InternalGpioCount) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: GPIO pin #%d not available in Controller#%d\n",
> +      __FUNCTION__,
> +      GpioPin,
> +      ControllerIndex));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +#endif
> +
> +/**
> +
> +Routine Description:
> +
> +  Gets the mode (function) of a GPIO pin
> +
> +Arguments:
> +
> +  This  - pointer to protocol
> +  Gpio  - which pin
> +  Mode  - pointer to output mode value
> +
> +Returns:
> +
> +  EFI_SUCCESS           - mode value retrieved
> +  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range
> +
> +**/
> +STATIC
> +EFI_STATUS
> +MvGpioGetMode (

Is this a refactored version of MvGpioGetFunction?

> +  IN  EMBEDDED_GPIO       *This,
> +  IN  EMBEDDED_GPIO_PIN    Gpio,
> +  OUT EMBEDDED_GPIO_MODE  *Mode
> +  )
> +{
> +  UINTN ControllerIndex;
> +  UINTN BaseAddress;
> +  UINTN GpioPin;
> +
> +  GpioPin = GPIO_PIN (Gpio);
> +  ControllerIndex = GPIO_PORT (Gpio);
> +
> +  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
> +
> +  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
> +
> +  if (MmioRead32 (BaseAddress + MV_GPIO_OUT_EN_REG) & (1 << GpioPin)) {
> +    *Mode = GPIO_MODE_INPUT;
> +  } else {
> +    if (MmioRead32 (BaseAddress + MV_GPIO_DATA_IN_REG) & (1 << GpioPin)) {
> +      *Mode = GPIO_MODE_OUTPUT_1;
> +    } else {
> +      *Mode = GPIO_MODE_OUTPUT_0;

Ah, right, it's the change to EMBEDDED_GPIO that means we have two
output modes to return instead of just input or output.
Could I just ask that you're a bit more explicit about such things in
the cover letter? Would have saved me a couple of minutes of head
scratching.

> +    }
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +
> +Routine Description:
> +
> +  Gets the state of a GPIO pin
> +
> +Arguments:
> +
> +  This  - pointer to protocol
> +  Gpio  - which pin to read
> +  Value - state of the pin
> +
> +Returns:
> +
> +  EFI_SUCCESS           - GPIO state returned in Value
> +  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range
> +**/
> +STATIC
> +EFI_STATUS
> +MvGpioGet (
> +  IN  EMBEDDED_GPIO      *This,
> +  IN  EMBEDDED_GPIO_PIN   Gpio,
> +  OUT UINTN              *Value
> +  )
> +{
> +  UINTN ControllerIndex;
> +  UINTN BaseAddress;
> +  UINTN GpioPin;
> +
> +  GpioPin = GPIO_PIN (Gpio);
> +  ControllerIndex = GPIO_PORT (Gpio);
> +
> +  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
> +
> +  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
> +
> +  if (MmioRead32 (BaseAddress + MV_GPIO_DATA_IN_REG) & (1 << GpioPin)) {
> +    *Value = 1;
> +  } else {
> +    *Value = 0;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +
> +Routine Description:
> +
> +  Sets the state of a GPIO pin
> +
> +Arguments:
> +
> +  This  - pointer to protocol
> +  Gpio  - which pin to modify
> +  Mode  - mode to set
> +
> +Returns:
> +
> +  EFI_SUCCESS           - GPIO set as requested
> +  EFI_UNSUPPORTED       - Mode is not supported
> +  EFI_INVALID_PARAMETER - Gpio pin is out of range
> +**/
> +STATIC
> +EFI_STATUS
> +MvGpioSet (
> +  IN EMBEDDED_GPIO       *This,
> +  IN EMBEDDED_GPIO_PIN    Gpio,
> +  IN EMBEDDED_GPIO_MODE   Mode
> +  )
> +{
> +  UINTN ControllerIndex;
> +  UINTN BaseAddress;
> +  UINTN GpioPin;
> +
> +  GpioPin = GPIO_PIN (Gpio);
> +  ControllerIndex = GPIO_PORT (Gpio);
> +
> +  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
> +
> +  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
> +
> +  switch (Mode) {
> +  case GPIO_MODE_OUTPUT_0:
> +    MmioAnd32 (BaseAddress + MV_GPIO_DATA_OUT_REG, ~(1 << GpioPin));
> +    MmioAnd32 (BaseAddress + MV_GPIO_OUT_EN_REG, ~(1 << GpioPin));
> +    break;
> +
> +  case GPIO_MODE_OUTPUT_1:
> +    MmioOr32 (BaseAddress + MV_GPIO_DATA_OUT_REG, (1 << GpioPin));
> +    MmioAnd32 (BaseAddress + MV_GPIO_OUT_EN_REG, ~(1 << GpioPin));
> +    break;
> +
> +  case GPIO_MODE_INPUT:
> +    MmioOr32 (BaseAddress + MV_GPIO_OUT_EN_REG, (1 << GpioPin));
> +    break;
> +
> +  default:
> +    return EFI_UNSUPPORTED;
> +  }
> + 
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +
> +Routine Description:
> +
> +  Sets the pull-up / pull-down resistor of a GPIO pin
> +
> +Arguments:
> +
> +  This  - pointer to protocol
> +  Gpio  - which pin
> +  Direction - pull-up, pull-down, or none
> +
> +Returns:
> +
> +  EFI_UNSUPPORTED - Can not perform the requested operation
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +MvGpioSetPull (
> +  IN  EMBEDDED_GPIO       *This,
> +  IN  EMBEDDED_GPIO_PIN   Gpio,
> +  IN  EMBEDDED_GPIO_PULL  Direction
> +  )
> +{
> +  return EFI_UNSUPPORTED;
> +}
> +
> +STATIC
> +VOID
> +MvGpioInitProtocol (
> +  IN EMBEDDED_GPIO *GpioProtocol
> +  )
> +{
> +  GpioProtocol->Get     = MvGpioGet;
> +  GpioProtocol->Set     = MvGpioSet;
> +  GpioProtocol->GetMode = MvGpioGetMode;
> +  GpioProtocol->SetPull = MvGpioSetPull;
> +}
> +
> +EFI_STATUS
> +EFIAPI
> +MvGpioEntryPoint (
> +  IN EFI_HANDLE       ImageHandle,
> +  IN EFI_SYSTEM_TABLE *SystemTable
> +  )
> +{
> +  MARVELL_BOARD_DESC_PROTOCOL *MvBoardProtocol;
> +  MV_BOARD_GPIO_DESCRIPTION *GpioDescription;
> +  MV_GPIO_DEVICE_PATH *GpioDevicePath;
> +  EFI_STATUS Status;
> +
> +  GpioDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
> +                     &mDevicePathTemplate);
> +  if (GpioDevicePath == NULL) {
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> +
> +  mGpioInstance = AllocateZeroPool (sizeof (MV_GPIO));
> +  if (mGpioInstance == NULL) {
> +    Status = EFI_OUT_OF_RESOURCES;
> +    goto ErrGpioInstanceAlloc;
> +  }
> +
> +  /* Obtain list of available controllers */
> +  Status = gBS->LocateProtocol (&gMarvellBoardDescProtocolGuid,
> +                  NULL,
> +                  (VOID **)&MvBoardProtocol);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: Cannot locate BoardDesc protocol\n",
> +      __FUNCTION__));
> +    goto ErrLocateBoardDesc;
> +  }
> +
> +  Status = MvBoardProtocol->GpioDescriptionGet (MvBoardProtocol,
> +             &GpioDescription);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
> +      __FUNCTION__));
> +    goto ErrLocateBoardDesc;
> +  }
> +
> +  mGpioInstance->Signature = MV_GPIO_SIGNATURE;
> +  mGpioInstance->GpioDeviceCount = GpioDescription->GpioDeviceCount;
> +  mGpioInstance->SoCGpio = AllocateCopyPool (sizeof (GPIO_CONTROLLER) *
> +                             GpioDescription->GpioDeviceCount,
> +                             GpioDescription->SoCGpio);
> +  if (mGpioInstance->SoCGpio == NULL) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: Fail to copy GPIO SoC controllers description\n",
> +      __FUNCTION__));
> +    Status = EFI_OUT_OF_RESOURCES;
> +    goto ErrAllocateSoCGpio;
> +  }
> +
> +  MvGpioInitProtocol (&mGpioInstance->GpioProtocol);
> +
> +  Status = gBS->InstallMultipleProtocolInterfaces (&(mGpioInstance->Handle),
> +                  &gEmbeddedGpioProtocolGuid,
> +                  &(mGpioInstance->GpioProtocol),
> +                  &gEfiDevicePathProtocolGuid,
> +                  (EFI_DEVICE_PATH_PROTOCOL *)GpioDevicePath,
> +                  NULL);
> +  if (EFI_ERROR (Status)) {
> +    goto ErrInstallProtocols;
> +  }
> +
> +  gBS->FreePool (GpioDescription->SoCGpio);
> +  gBS->FreePool (GpioDescription);
> +
> +  return EFI_SUCCESS;
> +
> +ErrInstallProtocols:
> +  gBS->FreePool (mGpioInstance->SoCGpio);
> +
> +ErrAllocateSoCGpio:
> +  gBS->FreePool (GpioDescription->SoCGpio);
> +  gBS->FreePool (GpioDescription);
> +
> +ErrLocateBoardDesc:
> +  gBS->FreePool (mGpioInstance);
> +
> +ErrGpioInstanceAlloc:
> +  gBS->FreePool (GpioDevicePath);
> +
> +  return Status;
> +}
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce GPIO expander driver
  2019-01-10  1:44 ` [platforms: PATCH v2 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce GPIO expander driver Marcin Wojtas
@ 2019-01-14 23:40   ` Leif Lindholm
  0 siblings, 0 replies; 34+ messages in thread
From: Leif Lindholm @ 2019-01-14 23:40 UTC (permalink / raw)
  To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap

On Thu, Jan 10, 2019 at 02:44:37AM +0100, Marcin Wojtas wrote:
> Marvell Armada 7k/8k-based platforms may use Pca95xx to extend
> amount of the GPIO pins.
> 
> This patch introduces support for them. The new driver implements
> a generic EMBEDDED_GPIO protocol.
> 
> In order to ease description of used PCA9XXX controllers
> add a common enum type. It can be used e.g. in the board description
> library to specify the expander model on a board (instead of passing
> a raw number). Update relevant libraries.
> 
> Driver is based on initial work done by Allen Yan <yanwei@marvell.com>.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf                        |  45 ++
>  Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h                          |  65 ++
>  Silicon/Marvell/Include/Protocol/MvGpio.h                                         |  16 +
>  Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c |   2 +-
>  Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c |   4 +-
>  Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c                          | 651 ++++++++++++++++++++
>  6 files changed, 780 insertions(+), 3 deletions(-)
>  create mode 100644 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
>  create mode 100644 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
>  create mode 100644 Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
> 
> diff --git a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
> new file mode 100644
> index 0000000..3b1ab4e
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf
> @@ -0,0 +1,45 @@
> +## @file
> +#
> +#  Copyright (c) 2017, Marvell International 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                    = 0x0001001A
> +  BASE_NAME                      = MvPca95xxDxe
> +  FILE_GUID                      = f0e405eb-8407-43b9-88e6-2f7d70715c72
> +  MODULE_TYPE                    = DXE_DRIVER
> +  VERSION_STRING                 = 1.0
> +  ENTRY_POINT                    = MvPca95xxEntryPoint
> +
> +[Sources]
> +  MvPca95xxDxe.c
> +  MvPca95xxDxe.h
> +
> +[Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  MdePkg/MdePkg.dec
> +  Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> +  DebugLib
> +  MemoryAllocationLib
> +  UefiDriverEntryPoint
> +  UefiLib
> +
> +[Protocols]
> +  gEfiDriverBindingProtocolGuid
> +  gEfiI2cIoProtocolGuid
> +  gEmbeddedGpioProtocolGuid
> +  gMarvellBoardDescProtocolGuid
> +
> +[Depex]
> +  TRUE
> diff --git a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
> new file mode 100644
> index 0000000..1fed739
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
> @@ -0,0 +1,65 @@
> +/**
> +*
> +*  Copyright (c) 2018, Marvell International 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 __MV_PCA953X_H__
> +#define __MV_PCA953X_H__
> +
> +#include <Library/ArmadaBoardDescLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/DevicePathLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +#include <Library/UefiLib.h>
> +
> +#include <Protocol/BoardDesc.h>
> +#include <Protocol/MvGpio.h>
> +#include <Protocol/MvI2c.h>
> +
> +#include <Uefi/UefiBaseType.h>
> +
> +#define PCA95XX_GPIO_SIGNATURE   SIGNATURE_32 ('I', 'O', 'E', 'X')
> +
> +#define PCA95XX_INPUT_REG        0x0
> +#define PCA95XX_OUTPUT_REG       0x2
> +#define PCA95XX_DIRECTION_REG    0x6
> +
> +#define PCA95XX_BANK_SIZE        8
> +#define PCA95XX_OPERATION_COUNT  2
> +#define PCA95XX_OPERATION_LENGTH 1
> +
> +typedef enum {
> +  PCA9505_PIN_COUNT = 40,
> +  PCA9534_PIN_COUNT = 8,
> +  PCA9535_PIN_COUNT = 16,
> +  PCA9536_PIN_COUNT = 4,
> +  PCA9537_PIN_COUNT = 4,
> +  PCA9538_PIN_COUNT = 8,
> +  PCA9539_PIN_COUNT = 16,
> +  PCA9554_PIN_COUNT = 8,
> +  PCA9555_PIN_COUNT = 16,
> +  PCA9556_PIN_COUNT = 16,
> +  PCA9557_PIN_COUNT = 16,
> +} PCA95XX_PIN_COUNT;
> +
> +typedef struct {
> +  EMBEDDED_GPIO      GpioProtocol;
> +  MV_GPIO_EXPANDER  *GpioExpanders;
> +  UINTN              GpioExpanderCount;
> +  UINTN              Signature;
> +  EFI_HANDLE         ControllerHandle;
> +} PCA95XX;
> +
> +#endif
> diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
> index 3319b79..5037fc2 100644
> --- a/Silicon/Marvell/Include/Protocol/MvGpio.h
> +++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
> @@ -25,6 +25,7 @@
>  
>  typedef enum {
>    MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
> +  MV_GPIO_DRIVER_TYPE_PCA95XX,
>  } MV_GPIO_DRIVER_TYPE;
>  
>  typedef enum {
> @@ -37,6 +38,21 @@ typedef enum {
>    MV_GPIO_CP2_CONTROLLER1,
>  } MV_GPIO_SOC_CONTROLLER_TYPE;
>  
> +typedef enum {
> +  PCA9505_ID,
> +  PCA9534_ID,
> +  PCA9535_ID,
> +  PCA9536_ID,
> +  PCA9537_ID,
> +  PCA9538_ID,
> +  PCA9539_ID,
> +  PCA9554_ID,
> +  PCA9555_ID,
> +  PCA9556_ID,
> +  PCA9557_ID,
> +  PCA95XX_MAX_ID,
> +} MV_GPIO_EXPANDER_TYPE_PCA95XX;
> +
>  typedef struct {
>    VENDOR_DEVICE_PATH        Header;
>    MV_GPIO_DRIVER_TYPE       GpioDriverType;
> diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
> index f63d8fd..9595b01 100644
> --- a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
> +++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
> @@ -27,7 +27,7 @@
>  // GPIO Expander
>  //
>  STATIC MV_GPIO_EXPANDER mGpioExpander = {
> -  8, /* PCA9555 */
> +  PCA9555_ID,

Right. So we do fix the nastiness here.
But surely the original live coding was nonsense until the enum was
added? 

I would lean towards breaking the changes to
Silicon/Marvell/Include/Protocol/MvGpio.h out as a separate patch and
moving that before the preceding patches that (will) depend on it.

Other than that, no issues with this patch.

/
    Leif

>    0x21,
>    0x0,
>  };
> diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
> index f6e3675..a1ac4bf 100644
> --- a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
> +++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
> @@ -28,12 +28,12 @@
>  //
>  STATIC MV_GPIO_EXPANDER mGpioExpanders[] = {
>    {
> -    8, /* PCA9555 */
> +    PCA9555_ID,
>      0x21,
>      0x0,
>    },
>    {
> -    8, /* PCA9555 */
> +    PCA9555_ID,
>      0x25,
>      0x0,
>    },
> diff --git a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
> new file mode 100644
> index 0000000..37c2b27
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
> @@ -0,0 +1,651 @@
> +/**
> +*
> +*  Copyright (c) 2018, Marvell International 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 <Protocol/I2cIo.h>
> +
> +#include <Pi/PiI2c.h>
> +
> +#include "MvPca95xxDxe.h"
> +
> +STATIC PCA95XX *mPca95xxInstance;
> +
> +STATIC MV_GPIO_DEVICE_PATH mDevicePathTemplate = {
> +  {
> +    {
> +      HARDWARE_DEVICE_PATH,
> +      HW_VENDOR_DP,
> +      {
> +        (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
> +                 sizeof (MV_GPIO_DRIVER_TYPE)),
> +        (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
> +                 sizeof (MV_GPIO_DRIVER_TYPE)) >> 8),
> +      },
> +    },
> +    EFI_CALLER_ID_GUID
> +  },
> +  MV_GPIO_DRIVER_TYPE_PCA95XX,
> +  {
> +    END_DEVICE_PATH_TYPE,
> +    END_ENTIRE_DEVICE_PATH_SUBTYPE,
> +    {
> +      sizeof(EFI_DEVICE_PATH_PROTOCOL),
> +      0
> +    }
> +  }
> +};
> +
> +STATIC PCA95XX_PIN_COUNT mPca95xxPinCount[PCA95XX_MAX_ID] = {
> +  PCA9505_PIN_COUNT,
> +  PCA9534_PIN_COUNT,
> +  PCA9535_PIN_COUNT,
> +  PCA9536_PIN_COUNT,
> +  PCA9537_PIN_COUNT,
> +  PCA9538_PIN_COUNT,
> +  PCA9539_PIN_COUNT,
> +  PCA9554_PIN_COUNT,
> +  PCA9555_PIN_COUNT,
> +  PCA9556_PIN_COUNT,
> +  PCA9557_PIN_COUNT,
> +};
> +
> +#if !defined(MDEPKG_NDEBUG)
> +/**
> +
> +Routine Description:
> +
> +  Verifies if controller index / GPIO pin values
> +  are within proper boundaries.
> +
> +Arguments:
> +
> +  ControllerIndex - index of controller
> +  GpioPin - which pin to read
> +
> +Returns:
> +
> +  EFI_SUCCESS           - GPIO pin / controller index are proper
> +  EFI_INVALID_PARAMETER - GPIO pin / controller index is out of range
> +**/
> +STATIC
> +EFI_STATUS
> +MvPca95xxValidate (
> +  IN UINTN ControllerIndex,
> +  IN UINTN GpioPin
> +  )
> +{
> +  UINTN ControllerId;
> +
> +  if (ControllerIndex >= mPca95xxInstance->GpioExpanderCount) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: Invalid GPIO ControllerIndex: %d\n",
> +      __FUNCTION__,
> +      ControllerIndex));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  ControllerId = mPca95xxInstance->GpioExpanders[ControllerIndex].ChipId;
> +
> +  if (GpioPin >= mPca95xxPinCount[ControllerId]) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: GPIO pin #%d not available in Controller#%d\n",
> +      __FUNCTION__,
> +      GpioPin,
> +      ControllerIndex));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +#endif
> +
> +EFI_STATUS
> +EFIAPI
> +MvPca95xxGetI2c (
> +  IN     UINTN                 ControllerIndex,
> +  IN OUT EFI_I2C_IO_PROTOCOL **I2cIo
> +  )
> +{
> +  UINTN        I2cBus, I2cAddress;
> +  UINTN        HandleCount, Index;
> +  EFI_HANDLE  *HandleBuffer;
> +  EFI_STATUS   Status;
> +
> +  I2cBus = mPca95xxInstance->GpioExpanders[ControllerIndex].I2cBus;
> +  I2cAddress = mPca95xxInstance->GpioExpanders[ControllerIndex].I2cAddress;
> +
> +  /* Locate Handles of all EfiI2cIoProtocol producers */
> +  Status = gBS->LocateHandleBuffer (ByProtocol,
> +                  &gEfiI2cIoProtocolGuid,
> +                  NULL,
> +                  &HandleCount,
> +                  &HandleBuffer);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: Unable to locate handles\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  /* Iterate over all protocol producers and pick one upon DeviceIndex match */
> +  for (Index = 0; Index < HandleCount; Index++) {
> +    Status = gBS->OpenProtocol (HandleBuffer[Index],
> +                    &gEfiI2cIoProtocolGuid,
> +                    (VOID **)I2cIo,
> +                    gImageHandle,
> +                    NULL,
> +                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "%a: Unable to open protocol\n", __FUNCTION__));
> +      gBS->FreePool (HandleBuffer);
> +      return Status;
> +    }
> +    if ((*I2cIo)->DeviceIndex == I2C_DEVICE_INDEX (I2cBus, I2cAddress)) {
> +      gBS->FreePool (HandleBuffer);
> +      return EFI_SUCCESS;
> +    }
> +  }
> +
> +  gBS->FreePool (HandleBuffer);
> +
> +  return EFI_NOT_FOUND;
> +}
> +
> +EFI_STATUS
> +EFIAPI
> +MvPca95xxI2cTransfer (
> +  IN EFI_I2C_IO_PROTOCOL *I2cIo,
> +  IN UINT8                Address,
> +  IN UINT8               *Buffer,
> +  IN UINT32               Flag
> +  )
> +{
> +  EFI_I2C_REQUEST_PACKET *RequestPacket;
> +  UINTN RequestPacketSize;
> +  UINT8 AddressBuffer;
> +  EFI_STATUS Status;
> +
> +  RequestPacketSize = sizeof (UINTN) +
> +                      sizeof (EFI_I2C_OPERATION) * PCA95XX_OPERATION_COUNT;
> +  RequestPacket = AllocateZeroPool (RequestPacketSize);
> +  if (RequestPacket == NULL) {
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> +
> +  /* Operations contain address and payload, consecutively. */
> +  RequestPacket->OperationCount = PCA95XX_OPERATION_COUNT;
> +  RequestPacket->Operation[0].LengthInBytes = PCA95XX_OPERATION_LENGTH;
> +  RequestPacket->Operation[0].Buffer = &AddressBuffer;
> +  RequestPacket->Operation[0].Buffer[0] = Address & MAX_UINT8;
> +  RequestPacket->Operation[1].LengthInBytes = PCA95XX_OPERATION_LENGTH;
> +  RequestPacket->Operation[1].Buffer = Buffer;
> +  RequestPacket->Operation[1].Flags = Flag;
> +
> +  Status = I2cIo->QueueRequest (I2cIo, 0, NULL, RequestPacket, NULL);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: transmission error: 0x%d\n",
> +      __FUNCTION__,
> +      Status));
> +  }
> +
> +  gBS->FreePool(RequestPacket);
> +
> +  return Status;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxReadRegs (
> +  IN  EFI_I2C_IO_PROTOCOL *I2cIo,
> +  IN  UINT8                Reg,
> +  OUT UINT8               *RegVal
> +  )
> +{
> +  return MvPca95xxI2cTransfer (I2cIo, Reg, RegVal, I2C_FLAG_READ);
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxWriteRegs (
> +  IN  EFI_I2C_IO_PROTOCOL *I2cIo,
> +  IN  UINTN                Reg,
> +  IN  UINT8                RegVal
> +  )
> +{
> +  return MvPca95xxI2cTransfer (I2cIo, Reg, &RegVal, I2C_FLAG_NORESTART);
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxSetOutputValue (
> +  IN UINTN               ControllerIndex,
> +  IN UINTN               GpioPin,
> +  IN EMBEDDED_GPIO_MODE  Mode
> +  )
> +{
> +  EFI_I2C_IO_PROTOCOL *I2cIo;
> +  EFI_STATUS Status;
> +  UINT8 RegVal;
> +  UINTN Bank;
> +
> +  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
> +    return EFI_DEVICE_ERROR;
> +  }
> +
> +  Bank = GpioPin / PCA95XX_BANK_SIZE;
> +
> +  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_OUTPUT_REG + Bank, &RegVal);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
> +    return EFI_DEVICE_ERROR;
> +  }
> +
> +  if (Mode == GPIO_MODE_OUTPUT_1) {
> +    RegVal |= (1 << (GpioPin % PCA95XX_BANK_SIZE));
> +  } else {
> +    RegVal &= ~(1 << (GpioPin % PCA95XX_BANK_SIZE));
> +  }
> +
> +  Status = MvPca95xxWriteRegs (I2cIo, PCA95XX_OUTPUT_REG + Bank, RegVal);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: fail to write device register\n", __FUNCTION__));
> +    return EFI_DEVICE_ERROR;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxSetDirection (
> +  IN UINTN              ControllerIndex,
> +  IN UINTN              GpioPin,
> +  IN EMBEDDED_GPIO_MODE Mode
> +  )
> +{
> +  EFI_I2C_IO_PROTOCOL *I2cIo;
> +  EFI_STATUS Status;
> +  UINT8 RegVal;
> +  UINTN Bank;
> +
> +  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  Bank = GpioPin / PCA95XX_BANK_SIZE;
> +
> +  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_DIRECTION_REG + Bank, &RegVal);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  if (Mode == GPIO_MODE_INPUT) {
> +    RegVal |= (1 << (GpioPin % PCA95XX_BANK_SIZE));
> +  } else {
> +    RegVal &= ~(1 << (GpioPin % PCA95XX_BANK_SIZE));
> +  }
> +
> +  Status = MvPca95xxWriteRegs (I2cIo, PCA95XX_DIRECTION_REG + Bank, RegVal);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: fail to write device register\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxReadMode (
> +  IN  UINTN               ControllerIndex,
> +  IN  UINTN               GpioPin,
> +  OUT EMBEDDED_GPIO_MODE *Mode
> +  )
> +{
> +  EFI_I2C_IO_PROTOCOL *I2cIo;
> +  EFI_STATUS Status;
> +  UINT8 RegVal;
> +  UINTN Bank;
> +
> +  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
> +
> +  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  Bank = GpioPin / PCA95XX_BANK_SIZE;
> +
> +  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_DIRECTION_REG + Bank, &RegVal);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
> +    *Mode = GPIO_MODE_INPUT;
> +  } else {
> +    Status = MvPca95xxReadRegs (I2cIo, PCA95XX_INPUT_REG + Bank, &RegVal);
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
> +      return Status;
> +    }
> +
> +    if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
> +      *Mode = GPIO_MODE_OUTPUT_1;
> +    } else {
> +      *Mode = GPIO_MODE_OUTPUT_0;
> +    }
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +
> +Routine Description:
> +
> +  Gets the mode (function) of a GPIO pin
> +
> +Arguments:
> +
> +  This  - pointer to protocol
> +  Gpio  - which pin
> +  Mode  - pointer to output mode value
> +
> +Returns:
> +
> +  EFI_SUCCESS           - mode value retrieved
> +  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range
> +
> +**/
> +STATIC
> +EFI_STATUS
> +MvPca95xxGetMode (
> +  IN  EMBEDDED_GPIO       *This,
> +  IN  EMBEDDED_GPIO_PIN    Gpio,
> +  OUT EMBEDDED_GPIO_MODE  *Mode
> +  )
> +{
> +  EFI_STATUS Status;
> +  UINTN ControllerIndex;
> +  UINTN GpioPin;
> +
> +  GpioPin = GPIO_PIN (Gpio);
> +  ControllerIndex = GPIO_PORT (Gpio);
> +
> +  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
> +
> +  Status = MvPca95xxReadMode (ControllerIndex, GpioPin, Mode);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: fail to get pin %d of controller#%d mode\n",
> +      __FUNCTION__,
> +      GpioPin,
> +      ControllerIndex));
> +  }
> +
> +  return Status;
> +}
> +
> +/**
> +
> +Routine Description:
> +
> +  Gets the state of a GPIO pin
> +
> +Arguments:
> +
> +  This  - pointer to protocol
> +  Gpio  - which pin to read
> +  Value - state of the pin
> +
> +Returns:
> +
> +  EFI_SUCCESS           - GPIO state returned in Value
> +  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range
> +**/
> +STATIC
> +EFI_STATUS
> +MvPca95xxGet (
> +  IN  EMBEDDED_GPIO      *This,
> +  IN  EMBEDDED_GPIO_PIN   Gpio,
> +  OUT UINTN              *Value
> +  )
> +{
> +  EFI_I2C_IO_PROTOCOL *I2cIo;
> +  EFI_STATUS Status;
> +  UINTN ControllerIndex;
> +  UINTN GpioPin;
> +  UINT8 RegVal;
> +  UINTN Bank;
> +
> +  GpioPin = GPIO_PIN (Gpio);
> +  ControllerIndex = GPIO_PORT (Gpio);
> +
> +  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
> +
> +  Status = MvPca95xxGetI2c (ControllerIndex, &I2cIo);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: fail to get I2C protocol\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  Bank = GpioPin / PCA95XX_BANK_SIZE;
> +
> +  Status = MvPca95xxReadRegs (I2cIo, PCA95XX_INPUT_REG + Bank, &RegVal);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: fail to read device register\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  if (RegVal & (1 << (GpioPin % PCA95XX_BANK_SIZE))) {
> +    *Value = 1;
> +  } else {
> +    *Value = 0;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +
> +Routine Description:
> +
> +  Sets the state of a GPIO pin
> +
> +Arguments:
> +
> +  This  - pointer to protocol
> +  Gpio  - which pin to modify
> +  Mode  - mode to set
> +
> +Returns:
> +
> +  EFI_SUCCESS           - GPIO set as requested
> +  EFI_UNSUPPORTED       - Mode is not supported
> +  EFI_INVALID_PARAMETER - Gpio pin is out of range
> +**/
> +STATIC
> +EFI_STATUS
> +MvPca95xxSet (
> +  IN EMBEDDED_GPIO       *This,
> +  IN EMBEDDED_GPIO_PIN   Gpio,
> +  IN EMBEDDED_GPIO_MODE  Mode
> +  )
> +{
> +  EFI_STATUS Status;
> +  UINTN ControllerIndex;
> +  UINTN GpioPin;
> +
> +  GpioPin = GPIO_PIN (Gpio);
> +  ControllerIndex = GPIO_PORT (Gpio);
> +
> +  ASSERT_EFI_ERROR (MvPca95xxValidate (ControllerIndex, GpioPin));
> +
> +  switch (Mode) {
> +  case GPIO_MODE_OUTPUT_0:
> +  case GPIO_MODE_OUTPUT_1:
> +    Status = MvPca95xxSetOutputValue (ControllerIndex, GpioPin, Mode);
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "%a: fail to set ouput value\n", __FUNCTION__));
> +      return Status;
> +    }
> +
> +  /* Fall-through */
> +  case GPIO_MODE_INPUT:
> +    Status = MvPca95xxSetDirection (ControllerIndex, GpioPin, Mode);
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "%a: fail to set direction\n", __FUNCTION__));
> +      return Status;
> +    }
> +    break;
> +
> +  default:
> +    return EFI_UNSUPPORTED;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> +
> +Routine Description:
> +
> +  Sets the pull-up / pull-down resistor of a GPIO pin
> +
> +Arguments:
> +
> +  This  - pointer to protocol
> +  Gpio  - which pin
> +  Direction - pull-up, pull-down, or none
> +
> +Returns:
> +
> +  EFI_UNSUPPORTED - Can not perform the requested operation
> +
> +**/
> +EFI_STATUS
> +EFIAPI
> +MvPca95xxSetPull (
> +  IN EMBEDDED_GPIO       *This,
> +  IN EMBEDDED_GPIO_PIN   Gpio,
> +  IN EMBEDDED_GPIO_PULL  Direction
> +  )
> +{
> +  return EFI_UNSUPPORTED;
> +}
> +
> +STATIC
> +VOID
> +MvPca95xxInitProtocol (
> +  IN EMBEDDED_GPIO *GpioProtocol
> +  )
> +{
> +  GpioProtocol->Get     = MvPca95xxGet;
> +  GpioProtocol->Set     = MvPca95xxSet;
> +  GpioProtocol->GetMode = MvPca95xxGetMode;
> +  GpioProtocol->SetPull = MvPca95xxSetPull;
> +}
> +
> +EFI_STATUS
> +EFIAPI
> +MvPca95xxEntryPoint (
> +  IN EFI_HANDLE       ImageHandle,
> +  IN EFI_SYSTEM_TABLE *SystemTable
> +  )
> +{
> +  MARVELL_BOARD_DESC_PROTOCOL *MvBoardProtocol;
> +  MV_BOARD_GPIO_DESCRIPTION *GpioDescription;
> +  MV_GPIO_DEVICE_PATH *Pca95xxDevicePath;
> +  EFI_STATUS Status;
> +
> +  /* Obtain list of available controllers */
> +  Status = gBS->LocateProtocol (&gMarvellBoardDescProtocolGuid,
> +                  NULL,
> +                  (VOID **)&MvBoardProtocol);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: Cannot locate BoardDesc protocol\n",
> +      __FUNCTION__));
> +    return Status;
> +  }
> +
> +  Status = MvBoardProtocol->GpioDescriptionGet (MvBoardProtocol,
> +             &GpioDescription);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
> +      __FUNCTION__));
> +    return Status;
> +  } else if (GpioDescription->GpioExpanders == NULL) {
> +    /* Silently exit, if the board does not support the controllers */
> +    return EFI_SUCCESS;
> +  }
> +
> +  Pca95xxDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
> +                        &mDevicePathTemplate);
> +  if (Pca95xxDevicePath == NULL) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: Fail to allocate Pca95xxDevicePath\n",
> +      __FUNCTION__));
> +    Status = EFI_OUT_OF_RESOURCES;
> +    goto ErrPca95xxDevicePathAlloc;
> +  }
> +
> +  mPca95xxInstance = AllocateZeroPool (sizeof (PCA95XX));
> +  if (mPca95xxInstance == NULL) {
> +    DEBUG ((DEBUG_ERROR,
> +      "%a: Fail to allocate mPca95xxInstance\n",
> +      __FUNCTION__));
> +    Status = EFI_OUT_OF_RESOURCES;
> +    goto ErrPca95xxInstanceAlloc;
> +  }
> +
> +  MvPca95xxInitProtocol (&mPca95xxInstance->GpioProtocol);
> +
> +  mPca95xxInstance->Signature = PCA95XX_GPIO_SIGNATURE;
> +  mPca95xxInstance->GpioExpanders = GpioDescription->GpioExpanders;
> +  mPca95xxInstance->GpioExpanderCount = GpioDescription->GpioExpanderCount;
> +
> +  Status = gBS->InstallMultipleProtocolInterfaces (
> +                  &(mPca95xxInstance->ControllerHandle),
> +                  &gEmbeddedGpioProtocolGuid,
> +                  &(mPca95xxInstance->GpioProtocol),
> +                  &gEfiDevicePathProtocolGuid,
> +                  (EFI_DEVICE_PATH_PROTOCOL *)Pca95xxDevicePath,
> +                  NULL);
> +  if (EFI_ERROR (Status)) {
> +    goto ErrInstallProtocols;
> +  }
> +
> +  gBS->FreePool (GpioDescription);
> +
> +  return EFI_SUCCESS;
> +
> +ErrInstallProtocols:
> +  gBS->FreePool (mPca95xxInstance);
> +
> +ErrPca95xxInstanceAlloc:
> +  gBS->FreePool (Pca95xxDevicePath);
> +
> +ErrPca95xxDevicePathAlloc:
> +  gBS->FreePool (GpioDescription);
> +
> +  return Status;
> +}
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines
  2019-01-10  1:44 ` [platforms: PATCH v2 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines Marcin Wojtas
@ 2019-01-14 23:44   ` Leif Lindholm
  0 siblings, 0 replies; 34+ messages in thread
From: Leif Lindholm @ 2019-01-14 23:44 UTC (permalink / raw)
  To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap

On Thu, Jan 10, 2019 at 02:44:39AM +0100, Marcin Wojtas wrote:
> To abstract the initialization required for non-discoverable devices,
> which is often platform specific (e.g. enable GPIO-driven power supply),
> introduce a NonDiscoverableInitLib for use by the NonDiscoverable code,
> for which each platform can supply its own version.
> 
> Add XHCI power supply (so called 'VBUS') enabling routines
> for supported platforms (Armada70x0Db, Armada80x0Db, Armada80x0McBin).
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>

Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

> ---
>  Silicon/Marvell/Marvell.dec                                                         |   1 +
>  Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc                                      |   3 +
>  Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc                                      |   3 +
>  Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc                               |   3 +
>  Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf     |  48 +++++++++
>  Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf     |  49 +++++++++
>  Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf |  49 +++++++++
>  Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf                   |   1 +
>  Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h       |  23 +++++
>  Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h       |  28 ++++++
>  Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h   |  20 ++++
>  Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h                            |  28 ++++++
>  Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c       |  96 ++++++++++++++++++
>  Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c       | 106 ++++++++++++++++++++
>  Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c   |  71 +++++++++++++
>  Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c                     |  13 ++-
>  16 files changed, 539 insertions(+), 3 deletions(-)
>  create mode 100644 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
>  create mode 100644 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
>  create mode 100644 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
>  create mode 100644 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
>  create mode 100644 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
>  create mode 100644 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h
>  create mode 100644 Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
>  create mode 100644 Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
>  create mode 100644 Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
>  create mode 100644 Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> 
> diff --git a/Silicon/Marvell/Marvell.dec b/Silicon/Marvell/Marvell.dec
> index 616624e..12bac55 100644
> --- a/Silicon/Marvell/Marvell.dec
> +++ b/Silicon/Marvell/Marvell.dec
> @@ -63,6 +63,7 @@
>    ArmadaBoardDescLib|Include/Library/ArmadaBoardDescLib.h
>    ArmadaIcuLib|Include/Library/ArmadaIcuLib.h
>    ArmadaSoCDescLib|Include/Library/ArmadaSoCDescLib.h
> +  NonDiscoverableInitLib|Include/Library/NonDiscoverableInitLib.h
>    SampleAtResetLib|Include/Library/SampleAtResetLib.h
>  
>  [Protocols]
> diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
> index 31815e4..e8cd177 100644
> --- a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
> +++ b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
> @@ -48,6 +48,9 @@
>  
>  !include Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
>  
> +[LibraryClasses.common]
> +  NonDiscoverableInitLib|Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> +
>  [Components.common]
>    Silicon/Marvell/Armada7k8k/DeviceTree/Armada70x0Db.inf
>  
> diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc b/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
> index 42f7bd3..8e8c2ba 100644
> --- a/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
> +++ b/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
> @@ -48,6 +48,9 @@
>  
>  !include Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
>  
> +[LibraryClasses.common]
> +  NonDiscoverableInitLib|Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> +
>  [Components.common]
>    Silicon/Marvell/Armada7k8k/DeviceTree/Armada80x0Db.inf
>  
> diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
> index 077224d..d080136 100644
> --- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
> +++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
> @@ -49,6 +49,9 @@
>  
>  !include Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
>  
> +[LibraryClasses.common]
> +  NonDiscoverableInitLib|Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> +
>  [Components.common]
>    Silicon/Marvell/Armada7k8k/DeviceTree/Armada80x0McBin.inf
>  
> diff --git a/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> new file mode 100644
> index 0000000..8d33e1d
> --- /dev/null
> +++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> @@ -0,0 +1,48 @@
> +## @file
> +#
> +#  Copyright (c) 2017, Linaro 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                    = 0x0001001A
> +  BASE_NAME                      = Armada70x0DbNonDiscoverableInitLib
> +  FILE_GUID                      = 151b04bc-9195-4380-b1fa-987130b450f0
> +  MODULE_TYPE                    = BASE
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = NonDiscoverableInitLib
> +
> +#
> +# The following information is for reference only and not required by the build
> +# tools.
> +#
> +#  VALID_ARCHITECTURES           = AARCH64
> +#
> +
> +[Sources]
> +  NonDiscoverableInitLib.c
> +
> +[Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> +  DebugLib
> +  IoLib
> +
> +[Protocols]
> +  gEmbeddedGpioProtocolGuid
> +
> +[Depex]
> +  gMarvellPlatformInitCompleteProtocolGuid
> diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> new file mode 100644
> index 0000000..e69e48a
> --- /dev/null
> +++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> @@ -0,0 +1,49 @@
> +## @file
> +#
> +#  Copyright (c) 2017, Linaro Ltd. All rights reserved.<BR>
> +#  Copyright (c) 2018, Marvell International 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                    = 0x0001001A
> +  BASE_NAME                      = Armada80x0DbNonDiscoverableInitLib
> +  FILE_GUID                      = 719c91d5-25aa-4366-988a-1642ae3a6734
> +  MODULE_TYPE                    = BASE
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = NonDiscoverableInitLib
> +
> +#
> +# The following information is for reference only and not required by the build
> +# tools.
> +#
> +#  VALID_ARCHITECTURES           = AARCH64
> +#
> +
> +[Sources]
> +  NonDiscoverableInitLib.c
> +
> +[Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> +  DebugLib
> +  IoLib
> +
> +[Protocols]
> +  gEmbeddedGpioProtocolGuid
> +
> +[Depex]
> +  gMarvellPlatformInitCompleteProtocolGuid
> diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> new file mode 100644
> index 0000000..d0190b6
> --- /dev/null
> +++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> @@ -0,0 +1,49 @@
> +## @file
> +#
> +#  Copyright (c) 2017, Linaro Ltd. All rights reserved.<BR>
> +#  Copyright (c) 2018, Marvell International 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                    = 0x0001001A
> +  BASE_NAME                      = Armada80x0McBinNonDiscoverableInitLib
> +  FILE_GUID                      = 470963c4-476e-4b85-a7c4-17868177f441
> +  MODULE_TYPE                    = BASE
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = NonDiscoverableInitLib
> +
> +#
> +# The following information is for reference only and not required by the build
> +# tools.
> +#
> +#  VALID_ARCHITECTURES           = AARCH64
> +#
> +
> +[Sources]
> +  NonDiscoverableInitLib.c
> +
> +[Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> +  DebugLib
> +  IoLib
> +
> +[Protocols]
> +  gEmbeddedGpioProtocolGuid
> +
> +[Depex]
> +  gMarvellPlatformInitCompleteProtocolGuid
> diff --git a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf
> index 98e5b0c..3f9f7bc 100644
> --- a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf
> +++ b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf
> @@ -50,6 +50,7 @@
>  
>  [LibraryClasses]
>    NonDiscoverableDeviceRegistrationLib
> +  NonDiscoverableInitLib
>    UefiDriverEntryPoint
>  
>  [Protocols]
> diff --git a/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
> new file mode 100644
> index 0000000..8a0e424
> --- /dev/null
> +++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
> @@ -0,0 +1,23 @@
> +/**
> +*
> +*  Copyright (c) 2018, Marvell International 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 __NON_DISCOVERABLE_INIT_LIB_H__
> +#define __NON_DISCOVERABLE_INIT_LIB_H__
> +
> +#define ARMADA_70x0_DB_IO_EXPANDER0       0
> +#define ARMADA_70x0_DB_VBUS0_PIN          0
> +#define ARMADA_70x0_DB_VBUS0_LIMIT_PIN    4
> +#define ARMADA_70x0_DB_VBUS1_PIN          1
> +#define ARMADA_70x0_DB_VBUS1_LIMIT_PIN    5
> +
> +#endif
> diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
> new file mode 100644
> index 0000000..64373ff
> --- /dev/null
> +++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.h
> @@ -0,0 +1,28 @@
> +/**
> +*
> +*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
> +*  Copyright (c) 2018, Marvell International 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 __NON_DISCOVERABLE_INIT_LIB_H__
> +#define __NON_DISCOVERABLE_INIT_LIB_H__
> +
> +#define ARMADA_80x0_DB_IO_EXPANDER0       0
> +#define ARMADA_80x0_DB_VBUS0_PIN          0
> +#define ARMADA_80x0_DB_VBUS0_LIMIT_PIN    4
> +#define ARMADA_80x0_DB_VBUS1_PIN          1
> +#define ARMADA_80x0_DB_VBUS1_LIMIT_PIN    5
> +
> +#define ARMADA_80x0_DB_IO_EXPANDER1       1
> +#define ARMADA_80x0_DB_VBUS2_PIN          0
> +#define ARMADA_80x0_DB_VBUS2_LIMIT_PIN    4
> +
> +#endif
> diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h
> new file mode 100644
> index 0000000..38e1f20
> --- /dev/null
> +++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.h
> @@ -0,0 +1,20 @@
> +/**
> +*
> +*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
> +*  Copyright (c) 2018, Marvell International 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 __NON_DISCOVERABLE_INIT_LIB_H__
> +#define __NON_DISCOVERABLE_INIT_LIB_H__
> +
> +#define ARMADA_80x0_MCBIN_VBUS0_PIN               15
> +
> +#endif
> diff --git a/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h b/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
> new file mode 100644
> index 0000000..18de24f
> --- /dev/null
> +++ b/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
> @@ -0,0 +1,28 @@
> +/**
> +*
> +*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
> +*  Copyright (c) 2018, Marvell International 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 __NON_DISCOVERABLE_INIT_LIB_H__
> +#define __NON_DISCOVERABLE_INIT_LIB_H__
> +
> +#include <Library/NonDiscoverableDeviceRegistrationLib.h>
> +
> +NON_DISCOVERABLE_DEVICE_INIT
> +EFIAPI
> +NonDiscoverableDeviceInitializerGet (
> +  IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
> +  IN  UINTN                         Index
> +  );
> +
> +#endif
> diff --git a/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> new file mode 100644
> index 0000000..586b189
> --- /dev/null
> +++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> @@ -0,0 +1,96 @@
> +/**
> +*
> +*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
> +*  Copyright (c) 2018, Marvell International 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 <Uefi.h>
> +
> +#include <Library/DebugLib.h>
> +#include <Library/DevicePathLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/NonDiscoverableDeviceRegistrationLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +
> +#include <Protocol/MvGpio.h>
> +#include <Protocol/NonDiscoverableDevice.h>
> +
> +#include "NonDiscoverableInitLib.h"
> +
> +STATIC CONST MV_GPIO_PIN mXhciVbusPins[] = {
> +  {
> +    ARMADA_70x0_DB_IO_EXPANDER0,
> +    ARMADA_70x0_DB_VBUS0_PIN,
> +    TRUE,
> +  },
> +  {
> +    ARMADA_70x0_DB_IO_EXPANDER0,
> +    ARMADA_70x0_DB_VBUS0_LIMIT_PIN,
> +    TRUE,
> +  },
> +  {
> +    ARMADA_70x0_DB_IO_EXPANDER0,
> +    ARMADA_70x0_DB_VBUS1_PIN,
> +    TRUE,
> +  },
> +  {
> +    ARMADA_70x0_DB_IO_EXPANDER0,
> +    ARMADA_70x0_DB_VBUS1_LIMIT_PIN,
> +    TRUE,
> +  },
> +};
> +
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +XhciInit (
> +  IN  NON_DISCOVERABLE_DEVICE  *This
> +  )
> +{
> +  CONST MV_GPIO_PIN   *VbusPin;
> +  EMBEDDED_GPIO_MODE   Mode;
> +  EMBEDDED_GPIO_PIN    Gpio;
> +  EMBEDDED_GPIO       *GpioProtocol;
> +  EFI_STATUS           Status;
> +  UINTN                Index;
> +
> +  Status = MvGpioGetProtocol (MV_GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  VbusPin = mXhciVbusPins;
> +  for (Index = 0; Index < ARRAY_SIZE (mXhciVbusPins); Index++) {
> +    Mode = VbusPin->ActiveHigh ? GPIO_MODE_OUTPUT_1 : GPIO_MODE_OUTPUT_0;
> +    Gpio = GPIO (VbusPin->ControllerId, VbusPin->PinNumber);
> +    GpioProtocol->Set (GpioProtocol, Gpio, Mode);
> +    VbusPin++;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +NON_DISCOVERABLE_DEVICE_INIT
> +EFIAPI
> +NonDiscoverableDeviceInitializerGet (
> +  IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
> +  IN  UINTN                         Index
> +  )
> +{
> +  if (Type == NonDiscoverableDeviceTypeXhci) {
> +        return XhciInit;
> +  }
> +
> +  return NULL;
> +}
> diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> new file mode 100644
> index 0000000..3988f9a
> --- /dev/null
> +++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> @@ -0,0 +1,106 @@
> +/**
> +*
> +*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
> +*  Copyright (c) 2018, Marvell International 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 <Uefi.h>
> +
> +#include <Library/DebugLib.h>
> +#include <Library/DevicePathLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/NonDiscoverableDeviceRegistrationLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +
> +#include <Protocol/MvGpio.h>
> +#include <Protocol/NonDiscoverableDevice.h>
> +
> +#include "NonDiscoverableInitLib.h"
> +
> +STATIC CONST MV_GPIO_PIN mXhciVbusPins[] = {
> +  {
> +    ARMADA_80x0_DB_IO_EXPANDER0,
> +    ARMADA_80x0_DB_VBUS0_PIN,
> +    TRUE,
> +  },
> +  {
> +    ARMADA_80x0_DB_IO_EXPANDER0,
> +    ARMADA_80x0_DB_VBUS0_LIMIT_PIN,
> +    TRUE,
> +  },
> +  {
> +    ARMADA_80x0_DB_IO_EXPANDER0,
> +    ARMADA_80x0_DB_VBUS1_PIN,
> +    TRUE,
> +  },
> +  {
> +    ARMADA_80x0_DB_IO_EXPANDER0,
> +    ARMADA_80x0_DB_VBUS1_LIMIT_PIN,
> +    TRUE,
> +  },
> +  {
> +    ARMADA_80x0_DB_IO_EXPANDER1,
> +    ARMADA_80x0_DB_VBUS2_PIN,
> +    TRUE,
> +  },
> +  {
> +    ARMADA_80x0_DB_IO_EXPANDER1,
> +    ARMADA_80x0_DB_VBUS2_LIMIT_PIN,
> +    TRUE,
> +  },
> +};
> +
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +XhciInit (
> +  IN  NON_DISCOVERABLE_DEVICE  *This
> +  )
> +{
> +  CONST MV_GPIO_PIN   *VbusPin;
> +  EMBEDDED_GPIO_MODE   Mode;
> +  EMBEDDED_GPIO_PIN    Gpio;
> +  EMBEDDED_GPIO       *GpioProtocol;
> +  EFI_STATUS           Status;
> +  UINTN                Index;
> +
> +  Status = MvGpioGetProtocol (MV_GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  VbusPin = mXhciVbusPins;
> +  for (Index = 0; Index < ARRAY_SIZE (mXhciVbusPins); Index++) {
> +    Mode = VbusPin->ActiveHigh ? GPIO_MODE_OUTPUT_1 : GPIO_MODE_OUTPUT_0;
> +    Gpio = GPIO (VbusPin->ControllerId, VbusPin->PinNumber);
> +    GpioProtocol->Set (GpioProtocol, Gpio, Mode);
> +    VbusPin++;
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +NON_DISCOVERABLE_DEVICE_INIT
> +EFIAPI
> +NonDiscoverableDeviceInitializerGet (
> +  IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
> +  IN  UINTN                         Index
> +  )
> +{
> +  if (Type == NonDiscoverableDeviceTypeXhci) {
> +        return XhciInit;
> +  }
> +
> +  return NULL;
> +}
> diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> new file mode 100644
> index 0000000..676feeb
> --- /dev/null
> +++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> @@ -0,0 +1,71 @@
> +/**
> +*
> +*  Copyright (c) 2017, Linaro Ltd. All rights reserved.
> +*  Copyright (c) 2018, Marvell International 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 <Uefi.h>
> +
> +#include <Library/DebugLib.h>
> +#include <Library/DevicePathLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/NonDiscoverableDeviceRegistrationLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +
> +#include <Protocol/MvGpio.h>
> +#include <Protocol/NonDiscoverableDevice.h>
> +
> +#include "NonDiscoverableInitLib.h"
> +
> +STATIC CONST MV_GPIO_PIN mXhciVbusPin = {
> +  MV_GPIO_CP0_CONTROLLER1,
> +  ARMADA_80x0_MCBIN_VBUS0_PIN,
> +  TRUE,
> +};
> +
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +XhciInit (
> +  IN  NON_DISCOVERABLE_DEVICE  *This
> +  )
> +{
> +  EMBEDDED_GPIO  *GpioProtocol;
> +  EFI_STATUS      Status;
> +
> +  Status = MvGpioGetProtocol (MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER, &GpioProtocol);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  GpioProtocol->Set (GpioProtocol,
> +                  GPIO (mXhciVbusPin.ControllerId, mXhciVbusPin.PinNumber),
> +                  GPIO_MODE_OUTPUT_1);
> +
> +  return Status;
> +}
> +
> +NON_DISCOVERABLE_DEVICE_INIT
> +EFIAPI
> +NonDiscoverableDeviceInitializerGet (
> +  IN  NON_DISCOVERABLE_DEVICE_TYPE  Type,
> +  IN  UINTN                         Index
> +  )
> +{
> +  if (Type == NonDiscoverableDeviceTypeXhci) {
> +        return XhciInit;
> +  }
> +
> +  return NULL;
> +}
> diff --git a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c
> index 116e9d4..74040b2 100644
> --- a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c
> +++ b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c
> @@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>  
>  #include <Library/DebugLib.h>
>  #include <Library/NonDiscoverableDeviceRegistrationLib.h>
> +#include <Library/NonDiscoverableInitLib.h>
>  #include <Library/UefiBootServicesTableLib.h>
>  
>  #include <Protocol/BoardDesc.h>
> @@ -57,7 +58,9 @@ NonDiscoverableInitXhci (
>      Status = RegisterNonDiscoverableMmioDevice (
>                       NonDiscoverableDeviceTypeXhci,
>                       Desc[i].SoC->XhciDmaType,
> -                     NULL,
> +                     NonDiscoverableDeviceInitializerGet (
> +                       NonDiscoverableDeviceTypeXhci,
> +                       i),
>                       NULL,
>                       1,
>                       Desc[i].SoC->XhciBaseAddress,
> @@ -86,7 +89,9 @@ NonDiscoverableInitAhci (
>      Status = RegisterNonDiscoverableMmioDevice (
>                       NonDiscoverableDeviceTypeAhci,
>                       Desc[i].SoC->AhciDmaType,
> -                     NULL,
> +                     NonDiscoverableDeviceInitializerGet (
> +                       NonDiscoverableDeviceTypeAhci,
> +                       i),
>                       NULL,
>                       1,
>                       Desc[i].SoC->AhciBaseAddress,
> @@ -115,7 +120,9 @@ NonDiscoverableInitSdhci (
>      Status = RegisterNonDiscoverableMmioDevice (
>                       NonDiscoverableDeviceTypeSdhci,
>                       Desc[i].SoC->SdMmcDmaType,
> -                     NULL,
> +                     NonDiscoverableDeviceInitializerGet (
> +                       NonDiscoverableDeviceTypeSdhci,
> +                       i),
>                       NULL,
>                       1,
>                       Desc[i].SoC->SdMmcBaseAddress,
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information
  2019-01-10  1:44 ` [platforms: PATCH v2 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information Marcin Wojtas
@ 2019-01-14 23:45   ` Leif Lindholm
  0 siblings, 0 replies; 34+ messages in thread
From: Leif Lindholm @ 2019-01-14 23:45 UTC (permalink / raw)
  To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap

On Thu, Jan 10, 2019 at 02:44:28AM +0100, Marcin Wojtas wrote:
> This patch introduces new library callback (ArmadaSoCGpioGet ()),
> which dynamically allocates and fills EmbeddedGpio's
> GPIO_CONTROLLER structure with the SoC description of GPIO controllers.
> 
> Because the library header is indirectly used in many modules,
> update all dependencies after including EmbeddedGpio.h.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>

Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

> ---
>  Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf                   |  1 +
>  Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf |  1 +
>  Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf                             |  1 +
>  Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf                                |  1 +
>  Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf                              |  1 +
>  Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf                              |  1 +
>  Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf                                  |  1 +
>  Silicon/Marvell/Library/IcuLib/IcuLib.inf                                        |  1 +
>  Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf                                |  1 +
>  Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h   | 10 +++++
>  Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h                               | 12 ++++++
>  Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c   | 39 ++++++++++++++++++++
>  12 files changed, 70 insertions(+)
> 
> diff --git a/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf b/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf
> index 5503463..e707fe9 100644
> --- a/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf
> +++ b/Silicon/Marvell/Armada7k8k/Drivers/PlatInitDxe/PlatInitDxe.inf
> @@ -25,6 +25,7 @@
>    PlatInitDxe.c
>  
>  [Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    MdePkg/MdePkg.dec
>    Silicon/Marvell/Marvell.dec
> diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf
> index 2b73b73..48a320c 100644
> --- a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf
> +++ b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.inf
> @@ -24,6 +24,7 @@
>    Armada7k8kSoCDescLib.c
>  
>  [Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    MdePkg/MdePkg.dec
>    Silicon/Marvell/Marvell.dec
> diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
> index 0b93948..0b641fe 100644
> --- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
> +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
> @@ -42,6 +42,7 @@
>    MvBoardDescDxe.h
>  
>  [Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    MdePkg/MdePkg.dec
>    Silicon/Marvell/Marvell.dec
> diff --git a/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf b/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf
> index 0eef350..e5bd370 100755
> --- a/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf
> +++ b/Silicon/Marvell/Drivers/I2c/MvI2cDxe/MvI2cDxe.inf
> @@ -41,6 +41,7 @@
>    MvI2cDxe.c
>  
>  [Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
>    MdePkg/MdePkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    ArmPlatformPkg/ArmPlatformPkg.dec
> diff --git a/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf b/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf
> index 739576f..8a877da 100644
> --- a/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf
> +++ b/Silicon/Marvell/Drivers/Net/MvMdioDxe/MvMdioDxe.inf
> @@ -45,6 +45,7 @@
>  [Packages]
>    ArmPkg/ArmPkg.dec
>    ArmPlatformPkg/ArmPlatformPkg.dec
> +  EmbeddedPkg/EmbeddedPkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    MdePkg/MdePkg.dec
>    Silicon/Marvell/Marvell.dec
> diff --git a/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf b/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf
> index 00c738a..09c5842 100644
> --- a/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf
> +++ b/Silicon/Marvell/Drivers/SdMmc/XenonDxe/XenonDxe.inf
> @@ -35,6 +35,7 @@
>    XenonSdMmcOverride.h
>  
>  [Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
>    MdePkg/MdePkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    Silicon/Marvell/Marvell.dec
> diff --git a/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf b/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf
> index 36f498b..c360edd 100644
> --- a/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf
> +++ b/Silicon/Marvell/Library/ComPhyLib/ComPhyLib.inf
> @@ -41,6 +41,7 @@
>  [Packages]
>    MdePkg/MdePkg.dec
>    MdeModulePkg/MdeModulePkg.dec
> +  EmbeddedPkg/EmbeddedPkg.dec
>    ArmPkg/ArmPkg.dec
>    ArmPlatformPkg/ArmPlatformPkg.dec
>    Silicon/Marvell/Marvell.dec
> diff --git a/Silicon/Marvell/Library/IcuLib/IcuLib.inf b/Silicon/Marvell/Library/IcuLib/IcuLib.inf
> index 0010141..ea662be 100644
> --- a/Silicon/Marvell/Library/IcuLib/IcuLib.inf
> +++ b/Silicon/Marvell/Library/IcuLib/IcuLib.inf
> @@ -24,6 +24,7 @@
>    IcuLib.c
>  
>  [Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    MdePkg/MdePkg.dec
>    Silicon/Marvell/Marvell.dec
> diff --git a/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf b/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf
> index e2381f4..805a057 100644
> --- a/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf
> +++ b/Silicon/Marvell/Library/UtmiPhyLib/UtmiPhyLib.inf
> @@ -41,6 +41,7 @@
>  [Packages]
>    ArmPkg/ArmPkg.dec
>    ArmPlatformPkg/ArmPlatformPkg.dec
> +  EmbeddedPkg/EmbeddedPkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    MdePkg/MdePkg.dec
>    Silicon/Marvell/Marvell.dec
> diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
> index c14b985..bfc8639 100644
> --- a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
> +++ b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
> @@ -22,6 +22,7 @@
>  // Common macros
>  //
>  #define MV_SOC_CP_BASE(Cp)               (0xF2000000 + ((Cp) * 0x2000000))
> +#define MV_SOC_AP806_COUNT               1
>  
>  //
>  // Platform description of AHCI controllers
> @@ -38,6 +39,15 @@
>  #define MV_SOC_COMPHY_MUX_BITS           4
>  
>  //
> +// Platform description of GPIO controllers
> +//
> +#define MV_SOC_AP806_GPIO_BASE           0xF06F5040
> +#define MV_SOC_AP806_GPIO_PIN_COUNT      20
> +#define MV_SOC_GPIO_PER_CP_COUNT         2
> +#define MV_SOC_CP_GPIO_BASE(Gpio)        (0x440100 + ((Gpio) * 0x40))
> +#define MV_SOC_CP_GPIO_PIN_COUNT(Gpio)   ((Gpio) == 0 ? 32 : 31)
> +
> +//
>  // Platform description of I2C controllers
>  //
>  #define MV_SOC_I2C_PER_CP_COUNT          2
> diff --git a/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h b/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
> index cdfb51b..26b075a 100644
> --- a/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
> +++ b/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
> @@ -17,6 +17,8 @@
>  #include <Library/MvComPhyLib.h>
>  #include <Library/NonDiscoverableDeviceRegistrationLib.h>
>  
> +#include <Protocol/EmbeddedGpio.h>
> +
>  //
>  // ComPhy SoC description
>  //
> @@ -46,6 +48,16 @@ ArmadaSoCDescCpBaseGet (
>    );
>  
>  //
> +// GPIO devices description template definition
> +//
> +EFI_STATUS
> +EFIAPI
> +ArmadaSoCGpioGet (
> +  IN OUT GPIO_CONTROLLER  **SoCGpioDescription,
> +  IN OUT UINTN             *Count
> +  );
> +
> +//
>  // I2C
>  //
>  typedef struct {
> diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
> index 6902fda..5b72c20 100644
> --- a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
> +++ b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
> @@ -74,6 +74,45 @@ ArmadaSoCDescCpBaseGet (
>  
>  EFI_STATUS
>  EFIAPI
> +ArmadaSoCGpioGet (
> +  IN OUT GPIO_CONTROLLER  **SoCGpioDescription,
> +  IN OUT UINTN             *Count
> +  )
> +{
> +  GPIO_CONTROLLER *GpioInstance;
> +  UINTN CpCount, CpIndex, Index;
> +
> +  CpCount = FixedPcdGet8 (PcdMaxCpCount);
> +
> +  *Count = CpCount * MV_SOC_GPIO_PER_CP_COUNT + MV_SOC_AP806_COUNT;
> +  GpioInstance = AllocateZeroPool (*Count * sizeof (GPIO_CONTROLLER));
> +  if (GpioInstance == NULL) {
> +    DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> +
> +  *SoCGpioDescription = GpioInstance;
> +
> +  /* AP806 GPIO controller */
> +  GpioInstance->RegisterBase = MV_SOC_AP806_GPIO_BASE;
> +  GpioInstance->InternalGpioCount = MV_SOC_AP806_GPIO_PIN_COUNT;
> +  GpioInstance++;
> +
> +  /* CP110 GPIO controllers */
> +  for (CpIndex = 0; CpIndex < CpCount; CpIndex++) {
> +    for (Index = 0; Index < MV_SOC_GPIO_PER_CP_COUNT; Index++) {
> +      GpioInstance->RegisterBase = MV_SOC_CP_BASE (CpIndex) +
> +                                   MV_SOC_CP_GPIO_BASE (Index);
> +      GpioInstance->InternalGpioCount = MV_SOC_CP_GPIO_PIN_COUNT (Index);
> +      GpioInstance++;
> +    }
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +EFI_STATUS
> +EFIAPI
>  ArmadaSoCDescI2cGet (
>    IN OUT MV_SOC_I2C_DESC  **I2cDesc,
>    IN OUT UINTN             *DescCount
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 02/12] Marvell/Library: ArmadaBoardDescLib: Add GPIO information
  2019-01-10  1:44 ` [platforms: PATCH v2 02/12] Marvell/Library: ArmadaBoardDescLib: " Marcin Wojtas
@ 2019-01-14 23:46   ` Leif Lindholm
  0 siblings, 0 replies; 34+ messages in thread
From: Leif Lindholm @ 2019-01-14 23:46 UTC (permalink / raw)
  To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap

On Thu, Jan 10, 2019 at 02:44:29AM +0100, Marcin Wojtas wrote:
> This patch extends library with GPIO devices per-board
> description. Both embedded SoC controllers and
> I2C IO expanders are supported. Add a helper routine
> for obtaining information about the latter.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>

Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

> ---
>  Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h | 23 ++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h b/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
> index 3fe2988..6ec5ace 100644
> --- a/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
> +++ b/Silicon/Marvell/Include/Library/ArmadaBoardDescLib.h
> @@ -25,6 +25,29 @@ typedef struct {
>  } MV_BOARD_COMPHY_DESC;
>  
>  //
> +// GPIO devices per-board description
> +//
> +typedef struct {
> +  UINTN ChipId;
> +  UINTN I2cAddress;
> +  UINTN I2cBus;
> +} MV_GPIO_EXPANDER;
> +
> +typedef struct {
> +  GPIO_CONTROLLER  *SoCGpio;
> +  UINTN             GpioDeviceCount;
> +  MV_GPIO_EXPANDER *GpioExpanders;
> +  UINTN             GpioExpanderCount;
> +} MV_BOARD_GPIO_DESCRIPTION;
> +
> +EFI_STATUS
> +EFIAPI
> +ArmadaBoardGpioExpanderGet (
> +  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
> +  IN OUT UINTN             *GpioExpanderCount
> +  );
> +
> +//
>  // I2C devices per-board description
>  //
>  typedef struct {
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 03/12] SolidRun/Armada80x0McBin: Extend board description library with GPIO
  2019-01-10  1:44 ` [platforms: PATCH v2 03/12] SolidRun/Armada80x0McBin: Extend board description library with GPIO Marcin Wojtas
@ 2019-01-14 23:46   ` Leif Lindholm
  0 siblings, 0 replies; 34+ messages in thread
From: Leif Lindholm @ 2019-01-14 23:46 UTC (permalink / raw)
  To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap

On Thu, Jan 10, 2019 at 02:44:30AM +0100, Marcin Wojtas wrote:
> This patch implements ArmadaBoarDescLib library for
> Armada80x0McBin comunity board and introduces ArmadaBoardGpioGet
> routine with per-board GPIO expander description.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>

Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

> ---
>  Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf |  1 +
>  Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c   | 17 +++++++++++++++++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
> index 63a4f66..43e4b9e 100644
> --- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
> +++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
> @@ -25,6 +25,7 @@
>    Armada80x0McBinBoardDescLib.c
>  
>  [Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    MdePkg/MdePkg.dec
>    Silicon/Marvell/Marvell.dec
> diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
> index d52adfc..32596ad 100644
> --- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
> +++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
> @@ -22,6 +22,23 @@
>  #include <Library/UefiBootServicesTableLib.h>
>  
>  //
> +// GPIO Expander
> +//
> +EFI_STATUS
> +EFIAPI
> +ArmadaBoardGpioExpanderGet (
> +  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
> +  IN OUT UINTN             *GpioExpanderCount
> +  )
> +{
> +  /* No GPIO expanders on board */
> +  *GpioExpanders = NULL;
> +  *GpioExpanderCount = 0;
> +
> +  return EFI_SUCCESS;
> +}
> +
> +//
>  // Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
>  //
>  STATIC
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 04/12] Marvell/Armada70x0Db: Extend board description library with GPIO
  2019-01-14 22:41   ` Leif Lindholm
@ 2019-01-15  5:48     ` Marcin Wojtas
  0 siblings, 0 replies; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-15  5:48 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
	Grzegorz Jaszczyk, Kostya Porotchkin

Hi Leif,

pon., 14 sty 2019 o 23:41 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Thu, Jan 10, 2019 at 02:44:31AM +0100, Marcin Wojtas wrote:
> > This patch implements ArmadaBoarDescLib library for
> > Armada70x0Db comunity board and introduces ArmadaBoardGpioGet
> > routine with per-board GPIO expander description.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> > ---
> >  Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf |  1 +
> >  Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c   | 25 ++++++++++++++++++++
> >  2 files changed, 26 insertions(+)
> >
> > diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
> > index b26f55b..c995515 100644
> > --- a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
> > +++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
> > @@ -25,6 +25,7 @@
> >    Armada70x0DbBoardDescLib.c
> >
> >  [Packages]
> > +  EmbeddedPkg/EmbeddedPkg.dec
> >    MdeModulePkg/MdeModulePkg.dec
> >    MdePkg/MdePkg.dec
> >    Silicon/Marvell/Marvell.dec
> > diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
> > index 48c68e4..f63d8fd 100644
> > --- a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
> > +++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
> > @@ -21,6 +21,31 @@
> >  #include <Library/MemoryAllocationLib.h>
> >  #include <Library/UefiBootServicesTableLib.h>
> >
> > +#include <Protocol/MvGpio.h>
> > +
> > +//
> > +// GPIO Expander
> > +//
> > +STATIC MV_GPIO_EXPANDER mGpioExpander = {
> > +  8, /* PCA9555 */
>
> Why did you drop the use of the still existing enumeration in favour
> of live coding the integer value that it currently produces for the
> member PCA9555_ID?
>

As you noticed, I 'fixed' it in 10/12 - otherwise compilation for this
board would be temporarily broken. I will split add MvGpio header with
the enum before this one.

Best regards,
Marcin

> /
>     Leif
>
> > +  0x21,
> > +  0x0,
> > +};
> > +
> > +
> > +EFI_STATUS
> > +EFIAPI
> > +ArmadaBoardGpioExpanderGet (
> > +  IN OUT MV_GPIO_EXPANDER **GpioExpanders,
> > +  IN OUT UINTN             *GpioExpanderCount
> > +  )
> > +{
> > +  *GpioExpanderCount = 1;
> > +  *GpioExpanders = &mGpioExpander;
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> >  //
> >  // Order of devices in SdMmcDescTemplate has to be in par with ArmadaSoCDescLib
> >  //
> > --
> > 2.7.4
> >


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
  2019-01-14 22:58   ` Leif Lindholm
@ 2019-01-15  6:05     ` Marcin Wojtas
  2019-01-15  9:56       ` Leif Lindholm
  0 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-15  6:05 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
	Grzegorz Jaszczyk, Kostya Porotchkin

Hi Leif,

pon., 14 sty 2019 o 23:58 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Thu, Jan 10, 2019 at 02:44:33AM +0100, Marcin Wojtas wrote:
> > Introduce new callback that can provide information
> > about GPIO SoC controllers, as well as on-board
> > I2C IO expanders. According ArmadaSoCDescLib
> > ArmadaBoardDescLib routines are used for
> > obtaining required data.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> > ---
> >  Silicon/Marvell/Include/Protocol/BoardDesc.h       |  8 ++++
> >  Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c | 43 ++++++++++++++++++++
> >  2 files changed, 51 insertions(+)
> >
> > diff --git a/Silicon/Marvell/Include/Protocol/BoardDesc.h b/Silicon/Marvell/Include/Protocol/BoardDesc.h
> > index 1d57a16..02905ea 100644
> > --- a/Silicon/Marvell/Include/Protocol/BoardDesc.h
> > +++ b/Silicon/Marvell/Include/Protocol/BoardDesc.h
> > @@ -50,6 +50,13 @@ EFI_STATUS
> >
> >  typedef
> >  EFI_STATUS
> > +(EFIAPI *MV_BOARD_GPIO_DESCRIPTION_GET) (
> > +  IN MARVELL_BOARD_DESC_PROTOCOL    *This,
> > +  IN OUT MV_BOARD_GPIO_DESCRIPTION **GpioDescription
> > +  );
> > +
> > +typedef
> > +EFI_STATUS
> >  (EFIAPI *MV_BOARD_DESC_I2C_GET) (
> >    IN MARVELL_BOARD_DESC_PROTOCOL  *This,
> >    IN OUT MV_BOARD_I2C_DESC       **I2cDesc
> > @@ -113,6 +120,7 @@ struct _MARVELL_BOARD_DESC_PROTOCOL {
> >    MV_BOARD_DESC_UTMI_GET         BoardDescUtmiGet;
> >    MV_BOARD_DESC_XHCI_GET         BoardDescXhciGet;
> >    MV_BOARD_DESC_FREE             BoardDescFree;
> > +  MV_BOARD_GPIO_DESCRIPTION_GET  GpioDescriptionGet;
> >  };
> >
> >  #endif // __MARVELL_BOARD_DESC_PROTOCOL_H__
> > diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> > index f71bfc4..e348b85 100644
> > --- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> > +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> > @@ -100,6 +100,48 @@ MvBoardDescComPhyGet (
> >
> >  STATIC
> >  EFI_STATUS
> > +MvBoardGpioDescriptionGet (
> > +  IN MARVELL_BOARD_DESC_PROTOCOL    *This,
> > +  IN OUT MV_BOARD_GPIO_DESCRIPTION **GpioDescription
> > +  )
> > +{
> > +  MV_BOARD_GPIO_DESCRIPTION *Description;
>
> My request on v1 was that this be refactored from a STATIC local
> variable to a global variable.
>
> > +  UINTN SoCGpioCount, GpioExpanderCount;
> > +  MV_GPIO_EXPANDER *GpioExpanders;
> > +  GPIO_CONTROLLER *SoCGpio;
> > +  EFI_STATUS Status;
> > +
> > +  /* Get SoC data about all available GPIO controllers */
> > +  Status = ArmadaSoCGpioGet (&SoCGpio, &SoCGpioCount);
> > +  if (EFI_ERROR (Status)) {
> > +    return Status;
> > +  }
> > +
> > +  /* Get per-board information about all available I2C IO expanders */
>
> GPIO

OK.

>
> > +  Status = ArmadaBoardGpioExpanderGet (&GpioExpanders, &GpioExpanderCount);
> > +  if (EFI_ERROR (Status)) {
> > +    return Status;
> > +  }
> > +
> > +  /* Allocate and fill board description */
> > +  Description = AllocateZeroPool (sizeof (MV_BOARD_GPIO_DESCRIPTION));
>
> Instead, this space is now dynamically allocated. But none of the call
> sites actually change, leading to potential memory leaks.
>
> I don't have a problem if you prefer an alternative solution to the
> one I propose, but please discuss the change first rather than
> submitting a new revision containing something I didn't ask for.
>

Indeed, I could have asked, but didn't want to spoil your Christmas
time with questions, especially gitven it was 3+ weeks from review:/

Anyway, I tried to play with the MV_BOARD_GPIO_DESCRIPTION to be the
global variable, but was not convinced by the outcome. My biggest
objection to the global variable and checking whether it's NULL in the
consumer driver is following - until now all users of the
BoardDescProtocol 'know' and call only the relevant protocol routine,
everything what happens underneath (PCDs, variable names, etc) is
transparent.

The consumers should be responsible for avoiding the memory leaks and
this was an improvement of v2. Both MvGpioDxe and MvPca9xxxDxe have
now fixed error path an properly take care of freeing the memory after
using protocol.

Please let know if above approach is acceptable.

Best regards,
Marcin

> /
>     Leif
>
> > +  if (Description == NULL) {
> > +    DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
> > +    return EFI_OUT_OF_RESOURCES;
> > +  }
> > +
> > +  Description->SoCGpio = SoCGpio;
> > +  Description->GpioDeviceCount = SoCGpioCount;
> > +  Description->GpioExpanders = GpioExpanders;
> > +  Description->GpioExpanderCount = GpioExpanderCount;
> > +
> > +  *GpioDescription = Description;
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> > +STATIC
> > +EFI_STATUS
> >  MvBoardDescI2cGet (
> >    IN MARVELL_BOARD_DESC_PROTOCOL  *This,
> >    IN OUT MV_BOARD_I2C_DESC       **I2cDesc
> > @@ -571,6 +613,7 @@ MvBoardDescInitProtocol (
> >    BoardDescProtocol->BoardDescUtmiGet = MvBoardDescUtmiGet;
> >    BoardDescProtocol->BoardDescXhciGet = MvBoardDescXhciGet;
> >    BoardDescProtocol->BoardDescFree = MvBoardDescFree;
> > +  BoardDescProtocol->GpioDescriptionGet = MvBoardGpioDescriptionGet;
> >
> >    return EFI_SUCCESS;
> >  }
> > --
> > 2.7.4
> >


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header
  2019-01-14 23:12   ` Leif Lindholm
@ 2019-01-15  6:12     ` Marcin Wojtas
  0 siblings, 0 replies; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-15  6:12 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
	Grzegorz Jaszczyk, Kostya Porotchkin, jinghua

Hi Leif,

wt., 15 sty 2019 o 00:12 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Thu, Jan 10, 2019 at 02:44:34AM +0100, Marcin Wojtas wrote:
> > From: jinghua <jinghua@marvell.com>
> >
> > This patch introduces a helper header that can be used by
> > multiple EMBEDDED_GPIO protocol producers (e.g. platform
> > driver or GPIO expanders). The drives are differentiated by
> > MV_GPIO_DRIVER_TYPE field of driver's MV_GPIO_DEVICE_PATH.
> >
> > In order to ease selection of the desired GPIO controller
> > a helper function was added - MarvellGpioGetProtocol().
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> > ---
> >  Silicon/Marvell/Include/Protocol/MvGpio.h | 156 ++++++++++++++++++++
> >  1 file changed, 156 insertions(+)
> >  create mode 100644 Silicon/Marvell/Include/Protocol/MvGpio.h
> >
> > diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
> > new file mode 100644
> > index 0000000..c9f1007
> > --- /dev/null
> > +++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
> > @@ -0,0 +1,156 @@
> > +/**
> > +*
> > +*  Copyright (C) 2018, Marvell International Ltd. and its affiliates.
> > +*
> > +*  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 __MV_GPIO_PROTOCOL_H__
> > +#define __MV_GPIO_PROTOCOL_H__
> > +
> > +#include <Uefi.h>
> > +
> > +#include <Library/DebugLib.h>
> > +#include <Library/DevicePathLib.h>
> > +#include <Library/MemoryAllocationLib.h>
> > +#include <Library/UefiBootServicesTableLib.h>
> > +
> > +#include <Protocol/EmbeddedGpio.h>
> > +
> > +typedef enum {
> > +  MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
> > +} MV_GPIO_DRIVER_TYPE;
> > +
> > +typedef struct {
> > +  VENDOR_DEVICE_PATH        Header;
> > +  MV_GPIO_DRIVER_TYPE       GpioDriverType;
> > +  EFI_DEVICE_PATH_PROTOCOL  End;
> > +} MV_GPIO_DEVICE_PATH;
> > +
> > +typedef struct {
> > +  UINTN    ControllerId;
> > +  UINTN    PinNumber;
> > +  BOOLEAN  ActiveHigh;
> > +} MV_GPIO_PIN;
> > +
> > +/*
> > + * Check if the driver type matches the requested value.
> > + * In case of the success open the GPIO protocol and return.
> > + */
> > +STATIC
> > +inline
> > +EFI_STATUS
> > +EFIAPI
> > +MvGpioFindMatchingDriver (
>
> Eep!
> I missed this in v1 (I assumed I'd missed the new file indicator
> whilst scrolling) - please move these functions out of this .h file.
> https://edk2-docs.gitbooks.io/edk-ii-c-coding-standards-specification/content/v/release/2.20/5_source_files/53_include_files.html#537-include-files-shall-not-generate-code-or-define-data-variables
>
> This makes me take a closer look at the rest of the patch ... and this
> just isn't a protocol - it's a library. Please restrucure it as such
> and move the header file to Include/Library rather than
> Include/Protocol.
>

Initially it was a header for MvGpioProtocol + this inline C addition
at the end... I will change it to the library.

Thanks,
Marcin

> /
>     Leif
>
> > +  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
> > +  IN     EFI_HANDLE             HandleBuffer,
> > +  IN     EFI_DEVICE_PATH       *DevicePath,
> > +  IN OUT EMBEDDED_GPIO        **GpioProtocol
> > +  )
> > +{
> > +  MV_GPIO_DEVICE_PATH *GpioDevicePath;
> > +  EFI_STATUS           Status;
> > +
> > +  while (!IsDevicePathEndType (DevicePath)) {
> > +    /* Check if GpioDriverType matches one found in the device path */
> > +    GpioDevicePath = (MV_GPIO_DEVICE_PATH *)DevicePath;
> > +    if (GpioDevicePath->GpioDriverType != GpioDriverType) {
> > +      DevicePath = NextDevicePathNode (DevicePath);
> > +      continue;
> > +    }
> > +
> > +    /*
> > +     * Open GpioProtocol. With EFI_OPEN_PROTOCOL_GET_PROTOCOL attribute
> > +     * the consumer is not obliged to call CloseProtocol.
> > +     */
> > +    Status = gBS->OpenProtocol (HandleBuffer,
> > +                    &gEmbeddedGpioProtocolGuid,
> > +                    (VOID **)GpioProtocol,
> > +                    gImageHandle,
> > +                    NULL,
> > +                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> > +    return Status;
> > +  }
> > +
> > +  return EFI_NOT_FOUND;
> > +}
> > +
> > +/*
> > + * Select desired protocol producer upon MV_GPIO_DRIVER_TYPE
> > + * field of driver's MV_GPIO_DEVICE_PATH.
> > + */
> > +STATIC
> > +inline
> > +EFI_STATUS
> > +EFIAPI
> > +MvGpioGetProtocol (
> > +  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
> > +  IN OUT EMBEDDED_GPIO        **GpioProtocol
> > +  )
> > +{
> > +  EFI_DEVICE_PATH     *DevicePath;
> > +  EFI_HANDLE          *HandleBuffer;
> > +  EFI_STATUS           Status;
> > +  UINTN                HandleCount;
> > +  UINTN                Index;
> > +
> > +  /* Locate Handles of all EMBEDDED_GPIO producers */
> > +  Status = gBS->LocateHandleBuffer (ByProtocol,
> > +                  &gEmbeddedGpioProtocolGuid,
> > +                  NULL,
> > +                  &HandleCount,
> > +                  &HandleBuffer);
> > +  if (EFI_ERROR (Status)) {
> > +    DEBUG ((DEBUG_ERROR, "%a: Unable to locate handles\n", __FUNCTION__));
> > +    return Status;
> > +  }
> > +
> > +  /* Iterate over all protocol producers */
> > +  for (Index = 0; Index < HandleCount; Index++) {
> > +    /* Open device path protocol installed on each handle */
> > +    Status = gBS->OpenProtocol (HandleBuffer[Index],
> > +                    &gEfiDevicePathProtocolGuid,
> > +                    (VOID **)&DevicePath,
> > +                    gImageHandle,
> > +                    NULL,
> > +                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> > +    if (EFI_ERROR (Status)) {
> > +      DEBUG ((DEBUG_ERROR, "%a: Unable to find DevicePath\n", __FUNCTION__));
> > +      continue;
> > +    }
> > +
> > +    /*
> > +     * Check if the driver type matches the requested value.
> > +     * In case of the success open the GPIO protocol and return.
> > +     * If there is no match, repeat procedure with the next handle.
> > +     */
> > +    Status = MvGpioFindMatchingDriver (GpioDriverType,
> > +               HandleBuffer[Index],
> > +               DevicePath,
> > +               GpioProtocol);
> > +    if (Status == EFI_NOT_FOUND) {
> > +      continue;
> > +    } else if (EFI_ERROR (Status)) {
> > +      DEBUG ((DEBUG_ERROR,
> > +        "%a: Unable to open GPIO protocol\n",
> > +        __FUNCTION__));
> > +    }
> > +
> > +    gBS->FreePool (HandleBuffer);
> > +
> > +    return Status;
> > +  }
> > +
> > +  /* No matching GPIO protocol producer was found */
> > +  gBS->FreePool (HandleBuffer);
> > +
> > +  return EFI_NOT_FOUND;
> > +}
> > +
> > +#endif // __MV_GPIO_PROTOCOL_H__
> > --
> > 2.7.4
> >


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver
  2019-01-14 23:32   ` Leif Lindholm
@ 2019-01-15  6:19     ` Marcin Wojtas
  2019-01-15 10:04       ` Leif Lindholm
  0 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-15  6:19 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
	Grzegorz Jaszczyk, Kostya Porotchkin

Hi Leif,


wt., 15 sty 2019 o 00:32 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Thu, Jan 10, 2019 at 02:44:35AM +0100, Marcin Wojtas wrote:
> > Marvell Armada 7k/8k SoCs comprise integrated GPIO controllers,
> > one in AP806 and two in each south bridge hardware blocks.
> >
> > This patch introduces support for them. The new driver implements
> > a generic EMBEDDED_GPIO protocol.
> >
> > In order to ease description of used GPIO pins and controllers
> > of the Armada 7k8k platforms, add a common enum type.
> >
> > Based on original work of Jing Hua <jinghua@marvell.com>.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> > ---
> >  Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf |  44 +++
> >  Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h   |  49 +++
> >  Silicon/Marvell/Include/Protocol/MvGpio.h            |  10 +
> >  Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c   | 372 ++++++++++++++++++++
> >  4 files changed, 475 insertions(+)
> >  create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
> >  create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
> >  create mode 100644 Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
> >
> > diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
> > new file mode 100644
> > index 0000000..5ff9130
> > --- /dev/null
> > +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
> > @@ -0,0 +1,44 @@
> > +## @file
> > +#
> > +#  Copyright (c) 2017, Marvell International 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                    = 0x0001001A
> > +  BASE_NAME                      = MvGpioDxe
> > +  FILE_GUID                      = 706eb761-b3b5-4f41-8558-5fd9217c0079
> > +  MODULE_TYPE                    = DXE_DRIVER
> > +  VERSION_STRING                 = 1.0
> > +  ENTRY_POINT                    = MvGpioEntryPoint
> > +
> > +[Sources]
> > +  MvGpioDxe.c
> > +  MvGpioDxe.h
> > +
> > +[Packages]
> > +  EmbeddedPkg/EmbeddedPkg.dec
> > +  MdeModulePkg/MdeModulePkg.dec
> > +  MdePkg/MdePkg.dec
> > +  Silicon/Marvell/Marvell.dec
> > +
> > +[LibraryClasses]
> > +  ArmadaSoCDescLib
> > +  DebugLib
> > +  MemoryAllocationLib
> > +  UefiDriverEntryPoint
> > +  UefiLib
> > +
> > +[Protocols]
> > +  gEmbeddedGpioProtocolGuid
> > +  gMarvellBoardDescProtocolGuid
> > +
> > +[Depex]
> > +  TRUE
> > diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
> > new file mode 100644
> > index 0000000..4e5422b
> > --- /dev/null
> > +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
> > @@ -0,0 +1,49 @@
> > +/**
> > +*
> > +*  Copyright (c) 2018, Marvell International 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 __MV_GPIO_H__
> > +#define __MV_GPIO_H__
> > +
> > +
> > +#include <Library/BaseMemoryLib.h>
> > +#include <Library/DebugLib.h>
> > +#include <Library/DevicePathLib.h>
> > +#include <Library/IoLib.h>
> > +#include <Library/MemoryAllocationLib.h>
> > +#include <Library/PcdLib.h>
> > +#include <Library/UefiBootServicesTableLib.h>
> > +#include <Library/UefiLib.h>
> > +
> > +#include <Protocol/BoardDesc.h>
> > +#include <Protocol/MvGpio.h>
> > +
> > +#include <Uefi/UefiBaseType.h>
> > +
> > +#define MV_GPIO_SIGNATURE        SIGNATURE_32 ('G', 'P', 'I', 'O')
>
> Unaddressed feedback from last time. But rereading it makes it clear
> my feedback was too imprecise, apologies. The point was that "GPIO" is
> not a very good choice of key to distinguish _this_ GPIO driver from
> other GPIO drivers. (As well as the MV_ prefix.)
>

Sure, I will modify it to be more specific signature.

> One more comment below, but it does not require code changes.
> If you can just change the signature, I'm happy with this patch.
>
> > +
> > +// Marvell MV_GPIO Controller Registers
> > +#define MV_GPIO_DATA_OUT_REG     (0x0)
> > +#define MV_GPIO_OUT_EN_REG       (0x4)
> > +#define MV_GPIO_BLINK_EN_REG     (0x8)
> > +#define MV_GPIO_DATA_IN_POL_REG  (0xc)
> > +#define MV_GPIO_DATA_IN_REG      (0x10)
> > +
> > +typedef struct {
> > +  EMBEDDED_GPIO     GpioProtocol;
> > +  GPIO_CONTROLLER  *SoCGpio;
> > +  UINTN             GpioDeviceCount;
> > +  UINTN             Signature;
> > +  EFI_HANDLE        Handle;
> > +} MV_GPIO;
> > +
> > +#endif // __MV_GPIO_H__
> > diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
> > index c9f1007..3319b79 100644
> > --- a/Silicon/Marvell/Include/Protocol/MvGpio.h
> > +++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
> > @@ -27,6 +27,16 @@ typedef enum {
> >    MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
> >  } MV_GPIO_DRIVER_TYPE;
> >
> > +typedef enum {
> > +  MV_GPIO_AP806_CONTROLLER0,
> > +  MV_GPIO_CP0_CONTROLLER0,
> > +  MV_GPIO_CP0_CONTROLLER1,
> > +  MV_GPIO_CP1_CONTROLLER0,
> > +  MV_GPIO_CP1_CONTROLLER1,
> > +  MV_GPIO_CP2_CONTROLLER0,
> > +  MV_GPIO_CP2_CONTROLLER1,
> > +} MV_GPIO_SOC_CONTROLLER_TYPE;
> > +
> >  typedef struct {
> >    VENDOR_DEVICE_PATH        Header;
> >    MV_GPIO_DRIVER_TYPE       GpioDriverType;
> > diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
> > new file mode 100644
> > index 0000000..4d5e530
> > --- /dev/null
> > +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
> > @@ -0,0 +1,372 @@
> > +/**
> > +*
> > +*  Copyright (c) 2018, Marvell International 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 "MvGpioDxe.h"
> > +
> > +STATIC MV_GPIO *mGpioInstance;
> > +
> > +STATIC MV_GPIO_DEVICE_PATH mDevicePathTemplate = {
> > +  {
> > +    {
> > +      HARDWARE_DEVICE_PATH,
> > +      HW_VENDOR_DP,
> > +      {
> > +        (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
> > +                 sizeof (MV_GPIO_DRIVER_TYPE)),
> > +        (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
> > +                 sizeof (MV_GPIO_DRIVER_TYPE)) >> 8),
> > +      },
> > +    },
> > +    EFI_CALLER_ID_GUID
> > +  },
> > +  MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
> > +  {
> > +    END_DEVICE_PATH_TYPE,
> > +    END_ENTIRE_DEVICE_PATH_SUBTYPE,
> > +    {
> > +      sizeof(EFI_DEVICE_PATH_PROTOCOL),
> > +      0
> > +    }
> > +  }
> > +};
> > +
> > +#if !defined(MDEPKG_NDEBUG)
> > +/**
> > +
> > +Routine Description:
> > +
> > +  Verifies if controller index / GPIO pin values
> > +  are within proper boundaries.
> > +
> > +Arguments:
> > +
> > +  ControllerIndex - index of controller
> > +  GpioPin - which pin to read
> > +
> > +Returns:
> > +
> > +  EFI_SUCCESS           - GPIO pin / controller index are proper
> > +  EFI_INVALID_PARAMETER - GPIO pin / controller index is out of range
> > +**/
> > +STATIC
> > +EFI_STATUS
> > +MvGpioValidate (
> > +  IN UINTN ControllerIndex,
> > +  IN UINTN GpioPin
> > +  )
> > +{
> > +  if (ControllerIndex >= mGpioInstance->GpioDeviceCount) {
> > +    DEBUG ((DEBUG_ERROR,
> > +      "%a: Invalid GPIO ControllerIndex: %d\n",
> > +      __FUNCTION__,
> > +      ControllerIndex));
> > +    return EFI_INVALID_PARAMETER;
> > +  }
> > +
> > +  if (GpioPin >= mGpioInstance->SoCGpio[ControllerIndex].InternalGpioCount) {
> > +    DEBUG ((DEBUG_ERROR,
> > +      "%a: GPIO pin #%d not available in Controller#%d\n",
> > +      __FUNCTION__,
> > +      GpioPin,
> > +      ControllerIndex));
> > +    return EFI_INVALID_PARAMETER;
> > +  }
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +#endif
> > +
> > +/**
> > +
> > +Routine Description:
> > +
> > +  Gets the mode (function) of a GPIO pin
> > +
> > +Arguments:
> > +
> > +  This  - pointer to protocol
> > +  Gpio  - which pin
> > +  Mode  - pointer to output mode value
> > +
> > +Returns:
> > +
> > +  EFI_SUCCESS           - mode value retrieved
> > +  EFI_INVALID_PARAMETER - Mode is a null pointer or Gpio pin is out of range
> > +
> > +**/
> > +STATIC
> > +EFI_STATUS
> > +MvGpioGetMode (
>
> Is this a refactored version of MvGpioGetFunction?
>
> > +  IN  EMBEDDED_GPIO       *This,
> > +  IN  EMBEDDED_GPIO_PIN    Gpio,
> > +  OUT EMBEDDED_GPIO_MODE  *Mode
> > +  )
> > +{
> > +  UINTN ControllerIndex;
> > +  UINTN BaseAddress;
> > +  UINTN GpioPin;
> > +
> > +  GpioPin = GPIO_PIN (Gpio);
> > +  ControllerIndex = GPIO_PORT (Gpio);
> > +
> > +  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
> > +
> > +  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
> > +
> > +  if (MmioRead32 (BaseAddress + MV_GPIO_OUT_EN_REG) & (1 << GpioPin)) {
> > +    *Mode = GPIO_MODE_INPUT;
> > +  } else {
> > +    if (MmioRead32 (BaseAddress + MV_GPIO_DATA_IN_REG) & (1 << GpioPin)) {
> > +      *Mode = GPIO_MODE_OUTPUT_1;
> > +    } else {
> > +      *Mode = GPIO_MODE_OUTPUT_0;
>
> Ah, right, it's the change to EMBEDDED_GPIO that means we have two
> output modes to return instead of just input or output.
> Could I just ask that you're a bit more explicit about such things in
> the cover letter? Would have saved me a couple of minutes of head
> scratching.
>

Well, in the cover letter I wrote:
"The biggest change is dropping custom GPIO protocol and start using
the generic EMBEDDED_GPIO with all its types."

And in the commit log of both drivers:
"The new driver implements a generic EMBEDDED_GPIO protocol."

Wasn't it explicit enough? :)

Best regards,
Marcin

> > +    }
> > +  }
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> > +/**
> > +
> > +Routine Description:
> > +
> > +  Gets the state of a GPIO pin
> > +
> > +Arguments:
> > +
> > +  This  - pointer to protocol
> > +  Gpio  - which pin to read
> > +  Value - state of the pin
> > +
> > +Returns:
> > +
> > +  EFI_SUCCESS           - GPIO state returned in Value
> > +  EFI_INVALID_PARAMETER - Value is NULL pointer or Gpio pin is out of range
> > +**/
> > +STATIC
> > +EFI_STATUS
> > +MvGpioGet (
> > +  IN  EMBEDDED_GPIO      *This,
> > +  IN  EMBEDDED_GPIO_PIN   Gpio,
> > +  OUT UINTN              *Value
> > +  )
> > +{
> > +  UINTN ControllerIndex;
> > +  UINTN BaseAddress;
> > +  UINTN GpioPin;
> > +
> > +  GpioPin = GPIO_PIN (Gpio);
> > +  ControllerIndex = GPIO_PORT (Gpio);
> > +
> > +  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
> > +
> > +  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
> > +
> > +  if (MmioRead32 (BaseAddress + MV_GPIO_DATA_IN_REG) & (1 << GpioPin)) {
> > +    *Value = 1;
> > +  } else {
> > +    *Value = 0;
> > +  }
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> > +/**
> > +
> > +Routine Description:
> > +
> > +  Sets the state of a GPIO pin
> > +
> > +Arguments:
> > +
> > +  This  - pointer to protocol
> > +  Gpio  - which pin to modify
> > +  Mode  - mode to set
> > +
> > +Returns:
> > +
> > +  EFI_SUCCESS           - GPIO set as requested
> > +  EFI_UNSUPPORTED       - Mode is not supported
> > +  EFI_INVALID_PARAMETER - Gpio pin is out of range
> > +**/
> > +STATIC
> > +EFI_STATUS
> > +MvGpioSet (
> > +  IN EMBEDDED_GPIO       *This,
> > +  IN EMBEDDED_GPIO_PIN    Gpio,
> > +  IN EMBEDDED_GPIO_MODE   Mode
> > +  )
> > +{
> > +  UINTN ControllerIndex;
> > +  UINTN BaseAddress;
> > +  UINTN GpioPin;
> > +
> > +  GpioPin = GPIO_PIN (Gpio);
> > +  ControllerIndex = GPIO_PORT (Gpio);
> > +
> > +  ASSERT_EFI_ERROR (MvGpioValidate (ControllerIndex, GpioPin));
> > +
> > +  BaseAddress = mGpioInstance->SoCGpio[ControllerIndex].RegisterBase;
> > +
> > +  switch (Mode) {
> > +  case GPIO_MODE_OUTPUT_0:
> > +    MmioAnd32 (BaseAddress + MV_GPIO_DATA_OUT_REG, ~(1 << GpioPin));
> > +    MmioAnd32 (BaseAddress + MV_GPIO_OUT_EN_REG, ~(1 << GpioPin));
> > +    break;
> > +
> > +  case GPIO_MODE_OUTPUT_1:
> > +    MmioOr32 (BaseAddress + MV_GPIO_DATA_OUT_REG, (1 << GpioPin));
> > +    MmioAnd32 (BaseAddress + MV_GPIO_OUT_EN_REG, ~(1 << GpioPin));
> > +    break;
> > +
> > +  case GPIO_MODE_INPUT:
> > +    MmioOr32 (BaseAddress + MV_GPIO_OUT_EN_REG, (1 << GpioPin));
> > +    break;
> > +
> > +  default:
> > +    return EFI_UNSUPPORTED;
> > +  }
> > +
> > +  return EFI_SUCCESS;
> > +}
> > +
> > +/**
> > +
> > +Routine Description:
> > +
> > +  Sets the pull-up / pull-down resistor of a GPIO pin
> > +
> > +Arguments:
> > +
> > +  This  - pointer to protocol
> > +  Gpio  - which pin
> > +  Direction - pull-up, pull-down, or none
> > +
> > +Returns:
> > +
> > +  EFI_UNSUPPORTED - Can not perform the requested operation
> > +
> > +**/
> > +EFI_STATUS
> > +EFIAPI
> > +MvGpioSetPull (
> > +  IN  EMBEDDED_GPIO       *This,
> > +  IN  EMBEDDED_GPIO_PIN   Gpio,
> > +  IN  EMBEDDED_GPIO_PULL  Direction
> > +  )
> > +{
> > +  return EFI_UNSUPPORTED;
> > +}
> > +
> > +STATIC
> > +VOID
> > +MvGpioInitProtocol (
> > +  IN EMBEDDED_GPIO *GpioProtocol
> > +  )
> > +{
> > +  GpioProtocol->Get     = MvGpioGet;
> > +  GpioProtocol->Set     = MvGpioSet;
> > +  GpioProtocol->GetMode = MvGpioGetMode;
> > +  GpioProtocol->SetPull = MvGpioSetPull;
> > +}
> > +
> > +EFI_STATUS
> > +EFIAPI
> > +MvGpioEntryPoint (
> > +  IN EFI_HANDLE       ImageHandle,
> > +  IN EFI_SYSTEM_TABLE *SystemTable
> > +  )
> > +{
> > +  MARVELL_BOARD_DESC_PROTOCOL *MvBoardProtocol;
> > +  MV_BOARD_GPIO_DESCRIPTION *GpioDescription;
> > +  MV_GPIO_DEVICE_PATH *GpioDevicePath;
> > +  EFI_STATUS Status;
> > +
> > +  GpioDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
> > +                     &mDevicePathTemplate);
> > +  if (GpioDevicePath == NULL) {
> > +    return EFI_OUT_OF_RESOURCES;
> > +  }
> > +
> > +  mGpioInstance = AllocateZeroPool (sizeof (MV_GPIO));
> > +  if (mGpioInstance == NULL) {
> > +    Status = EFI_OUT_OF_RESOURCES;
> > +    goto ErrGpioInstanceAlloc;
> > +  }
> > +
> > +  /* Obtain list of available controllers */
> > +  Status = gBS->LocateProtocol (&gMarvellBoardDescProtocolGuid,
> > +                  NULL,
> > +                  (VOID **)&MvBoardProtocol);
> > +  if (EFI_ERROR (Status)) {
> > +    DEBUG ((DEBUG_ERROR,
> > +      "%a: Cannot locate BoardDesc protocol\n",
> > +      __FUNCTION__));
> > +    goto ErrLocateBoardDesc;
> > +  }
> > +
> > +  Status = MvBoardProtocol->GpioDescriptionGet (MvBoardProtocol,
> > +             &GpioDescription);
> > +  if (EFI_ERROR (Status)) {
> > +    DEBUG ((DEBUG_ERROR,
> > +      "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
> > +      __FUNCTION__));
> > +    goto ErrLocateBoardDesc;
> > +  }
> > +
> > +  mGpioInstance->Signature = MV_GPIO_SIGNATURE;
> > +  mGpioInstance->GpioDeviceCount = GpioDescription->GpioDeviceCount;
> > +  mGpioInstance->SoCGpio = AllocateCopyPool (sizeof (GPIO_CONTROLLER) *
> > +                             GpioDescription->GpioDeviceCount,
> > +                             GpioDescription->SoCGpio);
> > +  if (mGpioInstance->SoCGpio == NULL) {
> > +    DEBUG ((DEBUG_ERROR,
> > +      "%a: Fail to copy GPIO SoC controllers description\n",
> > +      __FUNCTION__));
> > +    Status = EFI_OUT_OF_RESOURCES;
> > +    goto ErrAllocateSoCGpio;
> > +  }
> > +
> > +  MvGpioInitProtocol (&mGpioInstance->GpioProtocol);
> > +
> > +  Status = gBS->InstallMultipleProtocolInterfaces (&(mGpioInstance->Handle),
> > +                  &gEmbeddedGpioProtocolGuid,
> > +                  &(mGpioInstance->GpioProtocol),
> > +                  &gEfiDevicePathProtocolGuid,
> > +                  (EFI_DEVICE_PATH_PROTOCOL *)GpioDevicePath,
> > +                  NULL);
> > +  if (EFI_ERROR (Status)) {
> > +    goto ErrInstallProtocols;
> > +  }
> > +
> > +  gBS->FreePool (GpioDescription->SoCGpio);
> > +  gBS->FreePool (GpioDescription);
> > +
> > +  return EFI_SUCCESS;
> > +
> > +ErrInstallProtocols:
> > +  gBS->FreePool (mGpioInstance->SoCGpio);
> > +
> > +ErrAllocateSoCGpio:
> > +  gBS->FreePool (GpioDescription->SoCGpio);
> > +  gBS->FreePool (GpioDescription);
> > +
> > +ErrLocateBoardDesc:
> > +  gBS->FreePool (mGpioInstance);
> > +
> > +ErrGpioInstanceAlloc:
> > +  gBS->FreePool (GpioDevicePath);
> > +
> > +  return Status;
> > +}
> > --
> > 2.7.4
> >


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
  2019-01-15  6:05     ` Marcin Wojtas
@ 2019-01-15  9:56       ` Leif Lindholm
  2019-01-15 10:05         ` Marcin Wojtas
  0 siblings, 1 reply; 34+ messages in thread
From: Leif Lindholm @ 2019-01-15  9:56 UTC (permalink / raw)
  To: Marcin Wojtas
  Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
	Grzegorz Jaszczyk, Kostya Porotchkin

On Tue, Jan 15, 2019 at 07:05:42AM +0100, Marcin Wojtas wrote:
> > > index f71bfc4..e348b85 100644
> > > --- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> > > +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> > > @@ -100,6 +100,48 @@ MvBoardDescComPhyGet (
> > >
> > >  STATIC
> > >  EFI_STATUS
> > > +MvBoardGpioDescriptionGet (
> > > +  IN MARVELL_BOARD_DESC_PROTOCOL    *This,
> > > +  IN OUT MV_BOARD_GPIO_DESCRIPTION **GpioDescription
> > > +  )
> > > +{
> > > +  MV_BOARD_GPIO_DESCRIPTION *Description;
> >
> > My request on v1 was that this be refactored from a STATIC local
> > variable to a global variable.
> >
> > > +  UINTN SoCGpioCount, GpioExpanderCount;
> > > +  MV_GPIO_EXPANDER *GpioExpanders;
> > > +  GPIO_CONTROLLER *SoCGpio;
> > > +  EFI_STATUS Status;
> > > +
> > > +  /* Get SoC data about all available GPIO controllers */
> > > +  Status = ArmadaSoCGpioGet (&SoCGpio, &SoCGpioCount);
> > > +  if (EFI_ERROR (Status)) {
> > > +    return Status;
> > > +  }
> > > +
> > > +  /* Get per-board information about all available I2C IO expanders */
> >
> > GPIO
> 
> OK.
> 
> >
> > > +  Status = ArmadaBoardGpioExpanderGet (&GpioExpanders, &GpioExpanderCount);
> > > +  if (EFI_ERROR (Status)) {
> > > +    return Status;
> > > +  }
> > > +
> > > +  /* Allocate and fill board description */
> > > +  Description = AllocateZeroPool (sizeof (MV_BOARD_GPIO_DESCRIPTION));
> >
> > Instead, this space is now dynamically allocated. But none of the call
> > sites actually change, leading to potential memory leaks.
> >
> > I don't have a problem if you prefer an alternative solution to the
> > one I propose, but please discuss the change first rather than
> > submitting a new revision containing something I didn't ask for.
> 
> Indeed, I could have asked, but didn't want to spoil your Christmas
> time with questions, especially gitven it was 3+ weeks from review:/

It's not like I was checking email :)

> Anyway, I tried to play with the MV_BOARD_GPIO_DESCRIPTION to be the
> global variable, but was not convinced by the outcome. My biggest
> objection to the global variable and checking whether it's NULL in the
> consumer driver is following - until now all users of the
> BoardDescProtocol 'know' and call only the relevant protocol routine,
> everything what happens underneath (PCDs, variable names, etc) is
> transparent.
> 
> The consumers should be responsible for avoiding the memory leaks and
> this was an improvement of v2. Both MvGpioDxe and MvPca9xxxDxe have
> now fixed error path an properly take care of freeing the memory after
> using protocol.

But the call sites don't keep track of freeing it when error handling.

Which I think serves as a clear demonstrator of how magically
allocating buffers makes for difficult code to keep correct. (Which is
why the UEFI intefaces all require you to allocate a buffer and then
pass that and a size as parameters.)

So, since we are dealing with data that isn't changing, I prefer the
original design - just not the original implemenation.

So how about sticking with that, but moving the STATIC struct global
in that source file (but keeping it STATIC)?

/
    Leif

> Please let know if above approach is acceptable.
> 
> Best regards,
> Marcin
> 
> > /
> >     Leif
> >
> > > +  if (Description == NULL) {
> > > +    DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
> > > +    return EFI_OUT_OF_RESOURCES;
> > > +  }
> > > +
> > > +  Description->SoCGpio = SoCGpio;
> > > +  Description->GpioDeviceCount = SoCGpioCount;
> > > +  Description->GpioExpanders = GpioExpanders;
> > > +  Description->GpioExpanderCount = GpioExpanderCount;
> > > +
> > > +  *GpioDescription = Description;
> > > +
> > > +  return EFI_SUCCESS;
> > > +}
> > > +
> > > +STATIC
> > > +EFI_STATUS
> > >  MvBoardDescI2cGet (
> > >    IN MARVELL_BOARD_DESC_PROTOCOL  *This,
> > >    IN OUT MV_BOARD_I2C_DESC       **I2cDesc
> > > @@ -571,6 +613,7 @@ MvBoardDescInitProtocol (
> > >    BoardDescProtocol->BoardDescUtmiGet = MvBoardDescUtmiGet;
> > >    BoardDescProtocol->BoardDescXhciGet = MvBoardDescXhciGet;
> > >    BoardDescProtocol->BoardDescFree = MvBoardDescFree;
> > > +  BoardDescProtocol->GpioDescriptionGet = MvBoardGpioDescriptionGet;
> > >
> > >    return EFI_SUCCESS;
> > >  }
> > > --
> > > 2.7.4
> > >


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver
  2019-01-15  6:19     ` Marcin Wojtas
@ 2019-01-15 10:04       ` Leif Lindholm
  2019-01-15 10:06         ` Marcin Wojtas
  0 siblings, 1 reply; 34+ messages in thread
From: Leif Lindholm @ 2019-01-15 10:04 UTC (permalink / raw)
  To: Marcin Wojtas
  Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
	Grzegorz Jaszczyk, Kostya Porotchkin

On Tue, Jan 15, 2019 at 07:19:04AM +0100, Marcin Wojtas wrote:
> > > +  if (MmioRead32 (BaseAddress + MV_GPIO_OUT_EN_REG) & (1 << GpioPin)) {
> > > +    *Mode = GPIO_MODE_INPUT;
> > > +  } else {
> > > +    if (MmioRead32 (BaseAddress + MV_GPIO_DATA_IN_REG) & (1 << GpioPin)) {
> > > +      *Mode = GPIO_MODE_OUTPUT_1;
> > > +    } else {
> > > +      *Mode = GPIO_MODE_OUTPUT_0;
> >
> > Ah, right, it's the change to EMBEDDED_GPIO that means we have two
> > output modes to return instead of just input or output.
> > Could I just ask that you're a bit more explicit about such things in
> > the cover letter? Would have saved me a couple of minutes of head
> > scratching.
> 
> Well, in the cover letter I wrote:
> "The biggest change is dropping custom GPIO protocol and start using
> the generic EMBEDDED_GPIO with all its types."
> 
> And in the commit log of both drivers:
> "The new driver implements a generic EMBEDDED_GPIO protocol."
> 
> Wasn't it explicit enough? :)

I mean, it's fine - you've technically given all the information
needed to deduce that. But it does sort of imply that the reader knows
all EDK2 interfaces by heart. And I'm not quite there.

/
    Leif


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
  2019-01-15  9:56       ` Leif Lindholm
@ 2019-01-15 10:05         ` Marcin Wojtas
  2019-01-15 10:12           ` Leif Lindholm
  0 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-15 10:05 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
	Grzegorz Jaszczyk, Kostya Porotchkin

wt., 15 sty 2019 o 10:56 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Tue, Jan 15, 2019 at 07:05:42AM +0100, Marcin Wojtas wrote:
> > > > index f71bfc4..e348b85 100644
> > > > --- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> > > > +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> > > > @@ -100,6 +100,48 @@ MvBoardDescComPhyGet (
> > > >
> > > >  STATIC
> > > >  EFI_STATUS
> > > > +MvBoardGpioDescriptionGet (
> > > > +  IN MARVELL_BOARD_DESC_PROTOCOL    *This,
> > > > +  IN OUT MV_BOARD_GPIO_DESCRIPTION **GpioDescription
> > > > +  )
> > > > +{
> > > > +  MV_BOARD_GPIO_DESCRIPTION *Description;
> > >
> > > My request on v1 was that this be refactored from a STATIC local
> > > variable to a global variable.
> > >
> > > > +  UINTN SoCGpioCount, GpioExpanderCount;
> > > > +  MV_GPIO_EXPANDER *GpioExpanders;
> > > > +  GPIO_CONTROLLER *SoCGpio;
> > > > +  EFI_STATUS Status;
> > > > +
> > > > +  /* Get SoC data about all available GPIO controllers */
> > > > +  Status = ArmadaSoCGpioGet (&SoCGpio, &SoCGpioCount);
> > > > +  if (EFI_ERROR (Status)) {
> > > > +    return Status;
> > > > +  }
> > > > +
> > > > +  /* Get per-board information about all available I2C IO expanders */
> > >
> > > GPIO
> >
> > OK.
> >
> > >
> > > > +  Status = ArmadaBoardGpioExpanderGet (&GpioExpanders, &GpioExpanderCount);
> > > > +  if (EFI_ERROR (Status)) {
> > > > +    return Status;
> > > > +  }
> > > > +
> > > > +  /* Allocate and fill board description */
> > > > +  Description = AllocateZeroPool (sizeof (MV_BOARD_GPIO_DESCRIPTION));
> > >
> > > Instead, this space is now dynamically allocated. But none of the call
> > > sites actually change, leading to potential memory leaks.
> > >
> > > I don't have a problem if you prefer an alternative solution to the
> > > one I propose, but please discuss the change first rather than
> > > submitting a new revision containing something I didn't ask for.
> >
> > Indeed, I could have asked, but didn't want to spoil your Christmas
> > time with questions, especially gitven it was 3+ weeks from review:/
>
> It's not like I was checking email :)
>
> > Anyway, I tried to play with the MV_BOARD_GPIO_DESCRIPTION to be the
> > global variable, but was not convinced by the outcome. My biggest
> > objection to the global variable and checking whether it's NULL in the
> > consumer driver is following - until now all users of the
> > BoardDescProtocol 'know' and call only the relevant protocol routine,
> > everything what happens underneath (PCDs, variable names, etc) is
> > transparent.
> >
> > The consumers should be responsible for avoiding the memory leaks and
> > this was an improvement of v2. Both MvGpioDxe and MvPca9xxxDxe have
> > now fixed error path an properly take care of freeing the memory after
> > using protocol.
>
> But the call sites don't keep track of freeing it when error handling.
>
> Which I think serves as a clear demonstrator of how magically
> allocating buffers makes for difficult code to keep correct. (Which is
> why the UEFI intefaces all require you to allocate a buffer and then
> pass that and a size as parameters.)
>
> So, since we are dealing with data that isn't changing, I prefer the
> original design - just not the original implemenation.
>
> So how about sticking with that, but moving the STATIC struct global
> in that source file (but keeping it STATIC)?
>

Good, keeping the global variable inside MvBoardDescDxe and checking
it there is a clean and easy solution (consumers won't have to bother
about the stuff additional to calling the protocol and error handling
will be simpler).

How about on top of the file I add a section for global varibles (IMO
it's worth to modify other interfaces to that scheme later) and call
it:

STATIC MV_BOARD_GPIO_DESCRIPTION gGpioDescription;
?

Thanks,
Marcin

> /
>     Leif
>
> > Please let know if above approach is acceptable.
> >
> > Best regards,
> > Marcin
> >
> > > /
> > >     Leif
> > >
> > > > +  if (Description == NULL) {
> > > > +    DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
> > > > +    return EFI_OUT_OF_RESOURCES;
> > > > +  }
> > > > +
> > > > +  Description->SoCGpio = SoCGpio;
> > > > +  Description->GpioDeviceCount = SoCGpioCount;
> > > > +  Description->GpioExpanders = GpioExpanders;
> > > > +  Description->GpioExpanderCount = GpioExpanderCount;
> > > > +
> > > > +  *GpioDescription = Description;
> > > > +
> > > > +  return EFI_SUCCESS;
> > > > +}
> > > > +
> > > > +STATIC
> > > > +EFI_STATUS
> > > >  MvBoardDescI2cGet (
> > > >    IN MARVELL_BOARD_DESC_PROTOCOL  *This,
> > > >    IN OUT MV_BOARD_I2C_DESC       **I2cDesc
> > > > @@ -571,6 +613,7 @@ MvBoardDescInitProtocol (
> > > >    BoardDescProtocol->BoardDescUtmiGet = MvBoardDescUtmiGet;
> > > >    BoardDescProtocol->BoardDescXhciGet = MvBoardDescXhciGet;
> > > >    BoardDescProtocol->BoardDescFree = MvBoardDescFree;
> > > > +  BoardDescProtocol->GpioDescriptionGet = MvBoardGpioDescriptionGet;
> > > >
> > > >    return EFI_SUCCESS;
> > > >  }
> > > > --
> > > > 2.7.4
> > > >


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver
  2019-01-15 10:04       ` Leif Lindholm
@ 2019-01-15 10:06         ` Marcin Wojtas
  0 siblings, 0 replies; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-15 10:06 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
	Grzegorz Jaszczyk, Kostya Porotchkin

wt., 15 sty 2019 o 11:04 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Tue, Jan 15, 2019 at 07:19:04AM +0100, Marcin Wojtas wrote:
> > > > +  if (MmioRead32 (BaseAddress + MV_GPIO_OUT_EN_REG) & (1 << GpioPin)) {
> > > > +    *Mode = GPIO_MODE_INPUT;
> > > > +  } else {
> > > > +    if (MmioRead32 (BaseAddress + MV_GPIO_DATA_IN_REG) & (1 << GpioPin)) {
> > > > +      *Mode = GPIO_MODE_OUTPUT_1;
> > > > +    } else {
> > > > +      *Mode = GPIO_MODE_OUTPUT_0;
> > >
> > > Ah, right, it's the change to EMBEDDED_GPIO that means we have two
> > > output modes to return instead of just input or output.
> > > Could I just ask that you're a bit more explicit about such things in
> > > the cover letter? Would have saved me a couple of minutes of head
> > > scratching.
> >
> > Well, in the cover letter I wrote:
> > "The biggest change is dropping custom GPIO protocol and start using
> > the generic EMBEDDED_GPIO with all its types."
> >
> > And in the commit log of both drivers:
> > "The new driver implements a generic EMBEDDED_GPIO protocol."
> >
> > Wasn't it explicit enough? :)
>
> I mean, it's fine - you've technically given all the information
> needed to deduce that. But it does sort of imply that the reader knows
> all EDK2 interfaces by heart. And I'm not quite there.
>

Ok, sorry for not being specific enough.

Best regards,
Marcin


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
  2019-01-15 10:05         ` Marcin Wojtas
@ 2019-01-15 10:12           ` Leif Lindholm
  2019-01-15 10:14             ` Marcin Wojtas
  0 siblings, 1 reply; 34+ messages in thread
From: Leif Lindholm @ 2019-01-15 10:12 UTC (permalink / raw)
  To: Marcin Wojtas
  Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
	Grzegorz Jaszczyk, Kostya Porotchkin

On Tue, Jan 15, 2019 at 11:05:12AM +0100, Marcin Wojtas wrote:
> > > Anyway, I tried to play with the MV_BOARD_GPIO_DESCRIPTION to be the
> > > global variable, but was not convinced by the outcome. My biggest
> > > objection to the global variable and checking whether it's NULL in the
> > > consumer driver is following - until now all users of the
> > > BoardDescProtocol 'know' and call only the relevant protocol routine,
> > > everything what happens underneath (PCDs, variable names, etc) is
> > > transparent.
> > >
> > > The consumers should be responsible for avoiding the memory leaks and
> > > this was an improvement of v2. Both MvGpioDxe and MvPca9xxxDxe have
> > > now fixed error path an properly take care of freeing the memory after
> > > using protocol.
> >
> > But the call sites don't keep track of freeing it when error handling.
> >
> > Which I think serves as a clear demonstrator of how magically
> > allocating buffers makes for difficult code to keep correct. (Which is
> > why the UEFI intefaces all require you to allocate a buffer and then
> > pass that and a size as parameters.)
> >
> > So, since we are dealing with data that isn't changing, I prefer the
> > original design - just not the original implemenation.
> >
> > So how about sticking with that, but moving the STATIC struct global
> > in that source file (but keeping it STATIC)?
> >
> 
> Good, keeping the global variable inside MvBoardDescDxe and checking
> it there is a clean and easy solution (consumers won't have to bother
> about the stuff additional to calling the protocol and error handling
> will be simpler).
> 
> How about on top of the file I add a section for global varibles (IMO
> it's worth to modify other interfaces to that scheme later) and call
> it:
> 
> STATIC MV_BOARD_GPIO_DESCRIPTION gGpioDescription;
> ?

Static, so 'm', not 'g', but yeah.

Regards,

Leif


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
  2019-01-15 10:12           ` Leif Lindholm
@ 2019-01-15 10:14             ` Marcin Wojtas
  2019-01-15 10:26               ` Leif Lindholm
  0 siblings, 1 reply; 34+ messages in thread
From: Marcin Wojtas @ 2019-01-15 10:14 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
	Grzegorz Jaszczyk, Kostya Porotchkin

wt., 15 sty 2019 o 11:12 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Tue, Jan 15, 2019 at 11:05:12AM +0100, Marcin Wojtas wrote:
> > > > Anyway, I tried to play with the MV_BOARD_GPIO_DESCRIPTION to be the
> > > > global variable, but was not convinced by the outcome. My biggest
> > > > objection to the global variable and checking whether it's NULL in the
> > > > consumer driver is following - until now all users of the
> > > > BoardDescProtocol 'know' and call only the relevant protocol routine,
> > > > everything what happens underneath (PCDs, variable names, etc) is
> > > > transparent.
> > > >
> > > > The consumers should be responsible for avoiding the memory leaks and
> > > > this was an improvement of v2. Both MvGpioDxe and MvPca9xxxDxe have
> > > > now fixed error path an properly take care of freeing the memory after
> > > > using protocol.
> > >
> > > But the call sites don't keep track of freeing it when error handling.
> > >
> > > Which I think serves as a clear demonstrator of how magically
> > > allocating buffers makes for difficult code to keep correct. (Which is
> > > why the UEFI intefaces all require you to allocate a buffer and then
> > > pass that and a size as parameters.)
> > >
> > > So, since we are dealing with data that isn't changing, I prefer the
> > > original design - just not the original implemenation.
> > >
> > > So how about sticking with that, but moving the STATIC struct global
> > > in that source file (but keeping it STATIC)?
> > >
> >
> > Good, keeping the global variable inside MvBoardDescDxe and checking
> > it there is a clean and easy solution (consumers won't have to bother
> > about the stuff additional to calling the protocol and error handling
> > will be simpler).
> >
> > How about on top of the file I add a section for global varibles (IMO
> > it's worth to modify other interfaces to that scheme later) and call
> > it:
> >
> > STATIC MV_BOARD_GPIO_DESCRIPTION gGpioDescription;
> > ?
>
> Static, so 'm', not 'g', but yeah.
>

Effectively it will be global to other files :) But I will change to
'm' prefix of course.

Thanks,
Marcin


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
  2019-01-15 10:14             ` Marcin Wojtas
@ 2019-01-15 10:26               ` Leif Lindholm
  0 siblings, 0 replies; 34+ messages in thread
From: Leif Lindholm @ 2019-01-15 10:26 UTC (permalink / raw)
  To: Marcin Wojtas
  Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
	Grzegorz Jaszczyk, Kostya Porotchkin

On Tue, Jan 15, 2019 at 11:14:16AM +0100, Marcin Wojtas wrote:
> wt., 15 sty 2019 o 11:12 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
> >
> > On Tue, Jan 15, 2019 at 11:05:12AM +0100, Marcin Wojtas wrote:
> > > > > Anyway, I tried to play with the MV_BOARD_GPIO_DESCRIPTION to be the
> > > > > global variable, but was not convinced by the outcome. My biggest
> > > > > objection to the global variable and checking whether it's NULL in the
> > > > > consumer driver is following - until now all users of the
> > > > > BoardDescProtocol 'know' and call only the relevant protocol routine,
> > > > > everything what happens underneath (PCDs, variable names, etc) is
> > > > > transparent.
> > > > >
> > > > > The consumers should be responsible for avoiding the memory leaks and
> > > > > this was an improvement of v2. Both MvGpioDxe and MvPca9xxxDxe have
> > > > > now fixed error path an properly take care of freeing the memory after
> > > > > using protocol.
> > > >
> > > > But the call sites don't keep track of freeing it when error handling.
> > > >
> > > > Which I think serves as a clear demonstrator of how magically
> > > > allocating buffers makes for difficult code to keep correct. (Which is
> > > > why the UEFI intefaces all require you to allocate a buffer and then
> > > > pass that and a size as parameters.)
> > > >
> > > > So, since we are dealing with data that isn't changing, I prefer the
> > > > original design - just not the original implemenation.
> > > >
> > > > So how about sticking with that, but moving the STATIC struct global
> > > > in that source file (but keeping it STATIC)?
> > > >
> > >
> > > Good, keeping the global variable inside MvBoardDescDxe and checking
> > > it there is a clean and easy solution (consumers won't have to bother
> > > about the stuff additional to calling the protocol and error handling
> > > will be simpler).
> > >
> > > How about on top of the file I add a section for global varibles (IMO
> > > it's worth to modify other interfaces to that scheme later) and call
> > > it:
> > >
> > > STATIC MV_BOARD_GPIO_DESCRIPTION gGpioDescription;
> > > ?
> >
> > Static, so 'm', not 'g', but yeah.
> 
> Effectively it will be global to other files :) But I will change to
> 'm' prefix of course.

Global is about visibility, not accessibility. This will not be
globally visible.

/
    Leif


^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2019-01-15 10:26 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-10  1:44 [platforms: PATCH v2 00/12] Armada 7k8k GPIO support Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information Marcin Wojtas
2019-01-14 23:45   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 02/12] Marvell/Library: ArmadaBoardDescLib: " Marcin Wojtas
2019-01-14 23:46   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 03/12] SolidRun/Armada80x0McBin: Extend board description library with GPIO Marcin Wojtas
2019-01-14 23:46   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 04/12] Marvell/Armada70x0Db: " Marcin Wojtas
2019-01-14 22:41   ` Leif Lindholm
2019-01-15  5:48     ` Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 05/12] Marvell/Armada80x0Db: " Marcin Wojtas
2019-01-14 22:44   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support Marcin Wojtas
2019-01-14 22:58   ` Leif Lindholm
2019-01-15  6:05     ` Marcin Wojtas
2019-01-15  9:56       ` Leif Lindholm
2019-01-15 10:05         ` Marcin Wojtas
2019-01-15 10:12           ` Leif Lindholm
2019-01-15 10:14             ` Marcin Wojtas
2019-01-15 10:26               ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header Marcin Wojtas
2019-01-14 23:12   ` Leif Lindholm
2019-01-15  6:12     ` Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver Marcin Wojtas
2019-01-14 23:32   ` Leif Lindholm
2019-01-15  6:19     ` Marcin Wojtas
2019-01-15 10:04       ` Leif Lindholm
2019-01-15 10:06         ` Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 09/12] Marvell/Drivers: I2c: Use common header for macros Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce GPIO expander driver Marcin Wojtas
2019-01-14 23:40   ` Leif Lindholm
2019-01-10  1:44 ` [platforms: PATCH v2 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation Marcin Wojtas
2019-01-10  1:44 ` [platforms: PATCH v2 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines Marcin Wojtas
2019-01-14 23:44   ` Leif Lindholm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox