* [platforms: PATCH 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-11-14 1:10 ` Leif Lindholm
2018-10-20 1:57 ` [platforms: PATCH 02/12] Marvell/Library: ArmadaBoardDescLib: " Marcin Wojtas
` (10 subsequent siblings)
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 UTC (permalink / raw)
To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap
This patch introduces new library callback (ArmadaSoCDescGpioGet ()),
which dynamically allocates and fills MV_SOC_GPIO_DESC structure with
the SoC description of GPIO controllers.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h | 10 +++++
Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h | 15 ++++++++
Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c | 39 ++++++++++++++++++++
3 files changed, 64 insertions(+)
diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
index c14b985..85dd67c 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_AP_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_AP_GPIO_BASE 0xF06F5040
+#define MV_SOC_AP_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..f3d4f80 100644
--- a/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
+++ b/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
@@ -46,6 +46,21 @@ ArmadaSoCDescCpBaseGet (
);
//
+// GPIO devices description template definition
+//
+typedef struct {
+ UINTN GpioBaseAddress;
+ UINTN GpioPinCount;
+} MV_SOC_GPIO_DESC;
+
+EFI_STATUS
+EFIAPI
+ArmadaSoCDescGpioGet (
+ IN OUT MV_SOC_GPIO_DESC **GpioDesc,
+ IN OUT UINTN *DescCount
+ );
+
+//
// I2C
//
typedef struct {
diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
index 6902fda..7db4ec7 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
+ArmadaSoCDescGpioGet (
+ IN OUT MV_SOC_GPIO_DESC **GpioDesc,
+ IN OUT UINTN *DescCount
+ )
+{
+ MV_SOC_GPIO_DESC *Desc;
+ UINTN CpCount, CpIndex, Index;
+
+ CpCount = FixedPcdGet8 (PcdMaxCpCount);
+
+ *DescCount = CpCount * MV_SOC_GPIO_PER_CP_COUNT + MV_SOC_AP_COUNT;
+ Desc = AllocateZeroPool (*DescCount * sizeof (MV_SOC_GPIO_DESC));
+ if (Desc == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ *GpioDesc = Desc;
+
+ /* AP GPIO controller */
+ Desc->GpioBaseAddress = MV_SOC_AP_GPIO_BASE;
+ Desc->GpioPinCount = MV_SOC_AP_GPIO_PIN_COUNT;
+ Desc++;
+
+ /* CP GPIO controllers */
+ for (CpIndex = 0; CpIndex < CpCount; CpIndex++) {
+ for (Index = 0; Index < MV_SOC_GPIO_PER_CP_COUNT; Index++) {
+ Desc->GpioBaseAddress = MV_SOC_CP_BASE (CpIndex) +
+ MV_SOC_CP_GPIO_BASE (Index);
+ Desc->GpioPinCount = MV_SOC_CP_GPIO_PIN_COUNT (Index);
+ Desc++;
+ }
+ }
+
+ 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] 35+ messages in thread
* Re: [platforms: PATCH 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information
2018-10-20 1:57 ` [platforms: PATCH 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information Marcin Wojtas
@ 2018-11-14 1:10 ` Leif Lindholm
2018-11-14 6:05 ` Marcin Wojtas
0 siblings, 1 reply; 35+ messages in thread
From: Leif Lindholm @ 2018-11-14 1:10 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap
On Sat, Oct 20, 2018 at 03:57:30AM +0200, Marcin Wojtas wrote:
> This patch introduces new library callback (ArmadaSoCDescGpioGet ()),
> which dynamically allocates and fills MV_SOC_GPIO_DESC structure with
> the SoC description of GPIO controllers.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
> Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h | 10 +++++
> Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h | 15 ++++++++
> Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c | 39 ++++++++++++++++++++
> 3 files changed, 64 insertions(+)
>
> diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
> index c14b985..85dd67c 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_AP_COUNT 1
I think all of my comments on this patch can be summarised as "what is
an AP in this context"?
The term either needs explicit documenting, or expansion in the macro
names such that documentation is not required.
/
Leif
>
> //
> // Platform description of AHCI controllers
> @@ -38,6 +39,15 @@
> #define MV_SOC_COMPHY_MUX_BITS 4
>
> //
> +// Platform description of GPIO controllers
> +//
> +#define MV_SOC_AP_GPIO_BASE 0xF06F5040
> +#define MV_SOC_AP_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..f3d4f80 100644
> --- a/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
> +++ b/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
> @@ -46,6 +46,21 @@ ArmadaSoCDescCpBaseGet (
> );
>
> //
> +// GPIO devices description template definition
> +//
> +typedef struct {
> + UINTN GpioBaseAddress;
> + UINTN GpioPinCount;
> +} MV_SOC_GPIO_DESC;
> +
> +EFI_STATUS
> +EFIAPI
> +ArmadaSoCDescGpioGet (
> + IN OUT MV_SOC_GPIO_DESC **GpioDesc,
> + IN OUT UINTN *DescCount
> + );
> +
> +//
> // I2C
> //
> typedef struct {
> diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
> index 6902fda..7db4ec7 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
> +ArmadaSoCDescGpioGet (
> + IN OUT MV_SOC_GPIO_DESC **GpioDesc,
> + IN OUT UINTN *DescCount
> + )
> +{
> + MV_SOC_GPIO_DESC *Desc;
> + UINTN CpCount, CpIndex, Index;
> +
> + CpCount = FixedPcdGet8 (PcdMaxCpCount);
> +
> + *DescCount = CpCount * MV_SOC_GPIO_PER_CP_COUNT + MV_SOC_AP_COUNT;
> + Desc = AllocateZeroPool (*DescCount * sizeof (MV_SOC_GPIO_DESC));
> + if (Desc == NULL) {
> + DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
> + return EFI_OUT_OF_RESOURCES;
> + }
> +
> + *GpioDesc = Desc;
> +
> + /* AP GPIO controller */
> + Desc->GpioBaseAddress = MV_SOC_AP_GPIO_BASE;
> + Desc->GpioPinCount = MV_SOC_AP_GPIO_PIN_COUNT;
> + Desc++;
> +
> + /* CP GPIO controllers */
> + for (CpIndex = 0; CpIndex < CpCount; CpIndex++) {
> + for (Index = 0; Index < MV_SOC_GPIO_PER_CP_COUNT; Index++) {
> + Desc->GpioBaseAddress = MV_SOC_CP_BASE (CpIndex) +
> + MV_SOC_CP_GPIO_BASE (Index);
> + Desc->GpioPinCount = MV_SOC_CP_GPIO_PIN_COUNT (Index);
> + Desc++;
> + }
> + }
> +
> + 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] 35+ messages in thread
* Re: [platforms: PATCH 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information
2018-11-14 1:10 ` Leif Lindholm
@ 2018-11-14 6:05 ` Marcin Wojtas
2018-11-14 17:33 ` Leif Lindholm
0 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-11-14 6:05 UTC (permalink / raw)
To: Leif Lindholm
Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
Grzegorz Jaszczyk, Kostya Porotchkin
Hi Leif,
śr., 14 lis 2018 o 02:10 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Sat, Oct 20, 2018 at 03:57:30AM +0200, Marcin Wojtas wrote:
> > This patch introduces new library callback (ArmadaSoCDescGpioGet ()),
> > which dynamically allocates and fills MV_SOC_GPIO_DESC structure with
> > the SoC description of GPIO controllers.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> > ---
> > Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h | 10 +++++
> > Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h | 15 ++++++++
> > Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c | 39 ++++++++++++++++++++
> > 3 files changed, 64 insertions(+)
> >
> > diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h
> > index c14b985..85dd67c 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_AP_COUNT 1
>
> I think all of my comments on this patch can be summarised as "what is
> an AP in this context"?
>
> The term either needs explicit documenting, or expansion in the macro
> names such that documentation is not required.
Isn't a glossary on top of this file:
https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/blob/8ff9b13675a401588d3cc999aef9891838047b18/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h#L13
and C file:
https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/blob/8ff9b13675a401588d3cc999aef9891838047b18/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c#L13
sufficient?
Thanks,
Marcin
>
> >
> > //
> > // Platform description of AHCI controllers
> > @@ -38,6 +39,15 @@
> > #define MV_SOC_COMPHY_MUX_BITS 4
> >
> > //
> > +// Platform description of GPIO controllers
> > +//
> > +#define MV_SOC_AP_GPIO_BASE 0xF06F5040
> > +#define MV_SOC_AP_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..f3d4f80 100644
> > --- a/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
> > +++ b/Silicon/Marvell/Include/Library/ArmadaSoCDescLib.h
> > @@ -46,6 +46,21 @@ ArmadaSoCDescCpBaseGet (
> > );
> >
> > //
> > +// GPIO devices description template definition
> > +//
> > +typedef struct {
> > + UINTN GpioBaseAddress;
> > + UINTN GpioPinCount;
> > +} MV_SOC_GPIO_DESC;
> > +
> > +EFI_STATUS
> > +EFIAPI
> > +ArmadaSoCDescGpioGet (
> > + IN OUT MV_SOC_GPIO_DESC **GpioDesc,
> > + IN OUT UINTN *DescCount
> > + );
> > +
> > +//
> > // I2C
> > //
> > typedef struct {
> > diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c
> > index 6902fda..7db4ec7 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
> > +ArmadaSoCDescGpioGet (
> > + IN OUT MV_SOC_GPIO_DESC **GpioDesc,
> > + IN OUT UINTN *DescCount
> > + )
> > +{
> > + MV_SOC_GPIO_DESC *Desc;
> > + UINTN CpCount, CpIndex, Index;
> > +
> > + CpCount = FixedPcdGet8 (PcdMaxCpCount);
> > +
> > + *DescCount = CpCount * MV_SOC_GPIO_PER_CP_COUNT + MV_SOC_AP_COUNT;
> > + Desc = AllocateZeroPool (*DescCount * sizeof (MV_SOC_GPIO_DESC));
> > + if (Desc == NULL) {
> > + DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
> > + return EFI_OUT_OF_RESOURCES;
> > + }
> > +
> > + *GpioDesc = Desc;
> > +
> > + /* AP GPIO controller */
> > + Desc->GpioBaseAddress = MV_SOC_AP_GPIO_BASE;
> > + Desc->GpioPinCount = MV_SOC_AP_GPIO_PIN_COUNT;
> > + Desc++;
> > +
> > + /* CP GPIO controllers */
> > + for (CpIndex = 0; CpIndex < CpCount; CpIndex++) {
> > + for (Index = 0; Index < MV_SOC_GPIO_PER_CP_COUNT; Index++) {
> > + Desc->GpioBaseAddress = MV_SOC_CP_BASE (CpIndex) +
> > + MV_SOC_CP_GPIO_BASE (Index);
> > + Desc->GpioPinCount = MV_SOC_CP_GPIO_PIN_COUNT (Index);
> > + Desc++;
> > + }
> > + }
> > +
> > + 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] 35+ messages in thread
* Re: [platforms: PATCH 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information
2018-11-14 6:05 ` Marcin Wojtas
@ 2018-11-14 17:33 ` Leif Lindholm
2018-11-21 1:26 ` Marcin Wojtas
0 siblings, 1 reply; 35+ messages in thread
From: Leif Lindholm @ 2018-11-14 17:33 UTC (permalink / raw)
To: Marcin Wojtas
Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
Grzegorz Jaszczyk, Kostya Porotchkin
On Wed, Nov 14, 2018 at 07:05:01AM +0100, Marcin Wojtas wrote:
> > I think all of my comments on this patch can be summarised as "what is
> > an AP in this context"?
> >
> > The term either needs explicit documenting, or expansion in the macro
> > names such that documentation is not required.
>
> Isn't a glossary on top of this file:
> https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/blob/8ff9b13675a401588d3cc999aef9891838047b18/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h#L13
> and C file:
> https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/blob/8ff9b13675a401588d3cc999aef9891838047b18/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c#L13
> sufficient?
I will confess I missed that. But that also clearly shows the problem.
The glossary in is sufficient according to the coding style.
But it gets confusing, specifically for the abbreviation "AP", since
this has a specific (and different) meaning in PI.
/
Leif
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information
2018-11-14 17:33 ` Leif Lindholm
@ 2018-11-21 1:26 ` Marcin Wojtas
2018-11-26 14:49 ` Leif Lindholm
0 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-11-21 1:26 UTC (permalink / raw)
To: Leif Lindholm
Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
Grzegorz Jaszczyk, Kostya Porotchkin
Hi Leif,
śr., 14 lis 2018 o 18:33 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Wed, Nov 14, 2018 at 07:05:01AM +0100, Marcin Wojtas wrote:
> > > I think all of my comments on this patch can be summarised as "what is
> > > an AP in this context"?
> > >
> > > The term either needs explicit documenting, or expansion in the macro
> > > names such that documentation is not required.
> >
> > Isn't a glossary on top of this file:
> > https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/blob/8ff9b13675a401588d3cc999aef9891838047b18/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h#L13
> > and C file:
> > https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/blob/8ff9b13675a401588d3cc999aef9891838047b18/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c#L13
> > sufficient?
>
> I will confess I missed that. But that also clearly shows the problem.
>
> The glossary in is sufficient according to the coding style.
> But it gets confusing, specifically for the abbreviation "AP", since
> this has a specific (and different) meaning in PI.
>
Xenon is in, so we can focus on the GPIO ;) I will use AP806 in order
to avoid confusion. Please don't mind my ignorance - what is the
default 'AP' meaning?
BoardDesc library patches will be affected when rebasing onto latest
merged patches - should I resend v2 or wait for more remarks?
Thanks,
Marcin
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information
2018-11-21 1:26 ` Marcin Wojtas
@ 2018-11-26 14:49 ` Leif Lindholm
0 siblings, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-11-26 14:49 UTC (permalink / raw)
To: Marcin Wojtas
Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
Grzegorz Jaszczyk, Kostya Porotchkin
On Wed, Nov 21, 2018 at 02:26:23AM +0100, Marcin Wojtas wrote:
> Hi Leif,
>
> śr., 14 lis 2018 o 18:33 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
> >
> > On Wed, Nov 14, 2018 at 07:05:01AM +0100, Marcin Wojtas wrote:
> > > > I think all of my comments on this patch can be summarised as "what is
> > > > an AP in this context"?
> > > >
> > > > The term either needs explicit documenting, or expansion in the macro
> > > > names such that documentation is not required.
> > >
> > > Isn't a glossary on top of this file:
> > > https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/blob/8ff9b13675a401588d3cc999aef9891838047b18/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.h#L13
> > > and C file:
> > > https://github.com/MarvellEmbeddedProcessors/edk2-open-platform/blob/8ff9b13675a401588d3cc999aef9891838047b18/Silicon/Marvell/Armada7k8k/Library/Armada7k8kSoCDescLib/Armada7k8kSoCDescLib.c#L13
> > > sufficient?
> >
> > I will confess I missed that. But that also clearly shows the problem.
> >
> > The glossary in is sufficient according to the coding style.
> > But it gets confusing, specifically for the abbreviation "AP", since
> > this has a specific (and different) meaning in PI.
>
> Xenon is in, so we can focus on the GPIO ;) I will use AP806 in order
> to avoid confusion.
Thanks, that works for me.
> Please don't mind my ignorance - what is the default 'AP' meaning?
Application Processor. In contrast to the BootStrap Processor (BSP),
when using the EFI_MP_SERVICES_PROTOCOL to assign isolated tasks to
other logical processors.
> BoardDesc library patches will be affected when rebasing onto latest
> merged patches - should I resend v2 or wait for more remarks?
Hold back for a few more days please.
/
Leif
^ permalink raw reply [flat|nested] 35+ messages in thread
* [platforms: PATCH 02/12] Marvell/Library: ArmadaBoardDescLib: Add GPIO information
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
2018-10-20 1:57 ` [platforms: PATCH 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-11-14 1:12 ` Leif Lindholm
2018-10-20 1:57 ` [platforms: PATCH 03/12] SolidRun/Armada80x0McBin: Introduce board description library Marcin Wojtas
` (9 subsequent siblings)
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 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 ee8e06e..109164c 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_I2C_IO_EXPANDER_DESC;
+
+typedef struct {
+ MV_SOC_GPIO_DESC *SoC;
+ UINTN GpioDevCount;
+ MV_I2C_IO_EXPANDER_DESC *I2cIoExpanderDesc;
+ UINTN I2cIoExpanderCount;
+} MV_BOARD_GPIO_DESC;
+
+EFI_STATUS
+EFIAPI
+ArmadaBoardDescGpioGet (
+ IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
+ IN OUT UINTN *I2cIoExpanderCount
+ );
+
+//
// I2C devices per-board description
//
typedef struct {
--
2.7.4
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 02/12] Marvell/Library: ArmadaBoardDescLib: Add GPIO information
2018-10-20 1:57 ` [platforms: PATCH 02/12] Marvell/Library: ArmadaBoardDescLib: " Marcin Wojtas
@ 2018-11-14 1:12 ` Leif Lindholm
2018-11-14 6:16 ` Marcin Wojtas
2018-12-04 15:18 ` Leif Lindholm
0 siblings, 2 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-11-14 1:12 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap
On Sat, Oct 20, 2018 at 03:57:31AM +0200, 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>
> ---
> 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 ee8e06e..109164c 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_I2C_IO_EXPANDER_DESC;
> +
> +typedef struct {
> + MV_SOC_GPIO_DESC *SoC;
> + UINTN GpioDevCount;
> + MV_I2C_IO_EXPANDER_DESC *I2cIoExpanderDesc;
> + UINTN I2cIoExpanderCount;
> +} MV_BOARD_GPIO_DESC;
> +
> +EFI_STATUS
> +EFIAPI
> +ArmadaBoardDescGpioGet (
> + IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
> + IN OUT UINTN *I2cIoExpanderCount
Please expand all DESC/Desc to descriptor/description/whatever as
appropriate.
With that, Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
> + );
> +
> +//
> // I2C devices per-board description
> //
> typedef struct {
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 02/12] Marvell/Library: ArmadaBoardDescLib: Add GPIO information
2018-11-14 1:12 ` Leif Lindholm
@ 2018-11-14 6:16 ` Marcin Wojtas
2018-11-14 17:29 ` Leif Lindholm
2018-12-04 15:18 ` Leif Lindholm
1 sibling, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-11-14 6:16 UTC (permalink / raw)
To: Leif Lindholm
Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
Grzegorz Jaszczyk, Kostya Porotchkin
Hi Leif,
śr., 14 lis 2018 o 02:12 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
>
> On Sat, Oct 20, 2018 at 03:57:31AM +0200, 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>
> > ---
> > 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 ee8e06e..109164c 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_I2C_IO_EXPANDER_DESC;
> > +
> > +typedef struct {
> > + MV_SOC_GPIO_DESC *SoC;
> > + UINTN GpioDevCount;
> > + MV_I2C_IO_EXPANDER_DESC *I2cIoExpanderDesc;
> > + UINTN I2cIoExpanderCount;
> > +} MV_BOARD_GPIO_DESC;
> > +
> > +EFI_STATUS
> > +EFIAPI
> > +ArmadaBoardDescGpioGet (
> > + IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
> > + IN OUT UINTN *I2cIoExpanderCount
>
> Please expand all DESC/Desc to descriptor/description/whatever as
> appropriate.
Just to confirm - until now in every case there was an abbreviation
used (in SoCDescLib, structures names, etc.). It may look somewhat
inconsistently, but of course I can change according to your wish.
Please let know your thoughts on that.
Thanks,
Marcin
> With that, Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
>
> > + );
> > +
> > +//
> > // I2C devices per-board description
> > //
> > typedef struct {
> > --
> > 2.7.4
> >
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 02/12] Marvell/Library: ArmadaBoardDescLib: Add GPIO information
2018-11-14 6:16 ` Marcin Wojtas
@ 2018-11-14 17:29 ` Leif Lindholm
0 siblings, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-11-14 17:29 UTC (permalink / raw)
To: Marcin Wojtas
Cc: edk2-devel-01, Ard Biesheuvel, nadavh, jsd@semihalf.com,
Grzegorz Jaszczyk, Kostya Porotchkin
On Wed, Nov 14, 2018 at 07:16:33AM +0100, Marcin Wojtas wrote:
> Hi Leif,
>
> śr., 14 lis 2018 o 02:12 Leif Lindholm <leif.lindholm@linaro.org> napisał(a):
> >
> > On Sat, Oct 20, 2018 at 03:57:31AM +0200, 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>
> > > ---
> > > 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 ee8e06e..109164c 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_I2C_IO_EXPANDER_DESC;
> > > +
> > > +typedef struct {
> > > + MV_SOC_GPIO_DESC *SoC;
> > > + UINTN GpioDevCount;
> > > + MV_I2C_IO_EXPANDER_DESC *I2cIoExpanderDesc;
> > > + UINTN I2cIoExpanderCount;
> > > +} MV_BOARD_GPIO_DESC;
> > > +
> > > +EFI_STATUS
> > > +EFIAPI
> > > +ArmadaBoardDescGpioGet (
> > > + IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
> > > + IN OUT UINTN *I2cIoExpanderCount
> >
> > Please expand all DESC/Desc to descriptor/description/whatever as
> > appropriate.
>
> Just to confirm - until now in every case there was an abbreviation
> used (in SoCDescLib, structures names, etc.). It may look somewhat
> inconsistently, but of course I can change according to your wish.
> Please let know your thoughts on that.
Well, I'd prefer to change it all, but I'm happy to stick to following
the coding style for new patches.
/
Leif
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 02/12] Marvell/Library: ArmadaBoardDescLib: Add GPIO information
2018-11-14 1:12 ` Leif Lindholm
2018-11-14 6:16 ` Marcin Wojtas
@ 2018-12-04 15:18 ` Leif Lindholm
1 sibling, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 15:18 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap
On Wed, Nov 14, 2018 at 01:12:22AM +0000, Leif Lindholm wrote:
> On Sat, Oct 20, 2018 at 03:57:31AM +0200, 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>
> > ---
> > 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 ee8e06e..109164c 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_I2C_IO_EXPANDER_DESC;
> > +
> > +typedef struct {
> > + MV_SOC_GPIO_DESC *SoC;
> > + UINTN GpioDevCount;
> > + MV_I2C_IO_EXPANDER_DESC *I2cIoExpanderDesc;
> > + UINTN I2cIoExpanderCount;
> > +} MV_BOARD_GPIO_DESC;
> > +
> > +EFI_STATUS
> > +EFIAPI
> > +ArmadaBoardDescGpioGet (
> > + IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
> > + IN OUT UINTN *I2cIoExpanderCount
>
> Please expand all DESC/Desc to descriptor/description/whatever as
> appropriate.
> With that, Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Actually, I spotted something in 3-4/12 on finally getting back to this
set. The function is called ArmadaBoardDescGpioGet, but the IN/OUT
parameters talk abour I2c.
This seems like either a lack of abstraction (which given this is a
generic library class seems suboptimal).
Could that too be addressed in v2? (I'll mention it here instead of in
the users.)
Regards,
Leif
> > + );
> > +
> > +//
> > // I2C devices per-board description
> > //
> > typedef struct {
> > --
> > 2.7.4
> >
^ permalink raw reply [flat|nested] 35+ messages in thread
* [platforms: PATCH 03/12] SolidRun/Armada80x0McBin: Introduce board description library
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
2018-10-20 1:57 ` [platforms: PATCH 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information Marcin Wojtas
2018-10-20 1:57 ` [platforms: PATCH 02/12] Marvell/Library: ArmadaBoardDescLib: " Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-12-04 15:23 ` Leif Lindholm
2018-10-20 1:57 ` [platforms: PATCH 04/12] Marvell/Armada70x0Db: " Marcin Wojtas
` (8 subsequent siblings)
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 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 ArmadaBoardDescGpioGet
routine with per-board I2C IO expander description.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc | 3 ++
Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf | 34 ++++++++++++++++++
Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c | 36 ++++++++++++++++++++
3 files changed, 73 insertions(+)
create mode 100644 Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
create mode 100644 Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
index 52e2b9b..077224d 100644
--- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
+++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
@@ -55,6 +55,9 @@
[Components.AARCH64]
Silicon/Marvell/Armada7k8k/AcpiTables/Armada80x0McBin.inf
+[LibraryClasses.common]
+ ArmadaBoardDescLib|Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
+
################################################################################
#
# Pcd Section - list of all EDK II PCD Entries defined by this Platform
diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
new file mode 100644
index 0000000..63a4f66
--- /dev/null
+++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
@@ -0,0 +1,34 @@
+## @file
+#
+# Copyright (C) 2018, Marvell International Ltd. and its affiliates<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 = ArmadaMcBinBoardDescLib
+ FILE_GUID = 8208558f-5f33-46e2-b5c5-43354384389e
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = ArmadaBoardDescLib
+
+[Sources]
+ Armada80x0McBinBoardDescLib.c
+
+[Packages]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+ DebugLib
+ IoLib
diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
new file mode 100644
index 0000000..979db11
--- /dev/null
+++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
@@ -0,0 +1,36 @@
+/**
+*
+* 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.
+*
+**/
+
+#include <Uefi.h>
+
+#include <Library/ArmadaBoardDescLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/IoLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+EFI_STATUS
+EFIAPI
+ArmadaBoardDescGpioGet (
+ IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
+ IN OUT UINTN *I2cIoExpanderCount
+ )
+{
+ /* No I2C IO expanders on board */
+ *I2cIoExpanderDesc = NULL;
+ *I2cIoExpanderCount = 0;
+
+ return EFI_SUCCESS;
+}
--
2.7.4
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 03/12] SolidRun/Armada80x0McBin: Introduce board description library
2018-10-20 1:57 ` [platforms: PATCH 03/12] SolidRun/Armada80x0McBin: Introduce board description library Marcin Wojtas
@ 2018-12-04 15:23 ` Leif Lindholm
0 siblings, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 15:23 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap
On Sat, Oct 20, 2018 at 03:57:32AM +0200, Marcin Wojtas wrote:
> This patch implements ArmadaBoarDescLib library for
> Armada80x0McBin comunity board and introduces ArmadaBoardDescGpioGet
> routine with per-board I2C IO expander description.
I would argue it "adds an implementation" rather than "introduces"
(2/12 did that). Also, since there _is_ no expansion here, the
referring to it as I2C gets ever weirder.
No issues beyond such nitpicking: if you address the commit message
and purge all mentions of I2C from this patch:
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
> Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc | 3 ++
> Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf | 34 ++++++++++++++++++
> Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c | 36 ++++++++++++++++++++
> 3 files changed, 73 insertions(+)
> create mode 100644 Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
> create mode 100644 Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
>
> diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
> index 52e2b9b..077224d 100644
> --- a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
> +++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBin.dsc
> @@ -55,6 +55,9 @@
> [Components.AARCH64]
> Silicon/Marvell/Armada7k8k/AcpiTables/Armada80x0McBin.inf
>
> +[LibraryClasses.common]
> + ArmadaBoardDescLib|Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
> +
> ################################################################################
> #
> # Pcd Section - list of all EDK II PCD Entries defined by this Platform
> diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
> new file mode 100644
> index 0000000..63a4f66
> --- /dev/null
> +++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.inf
> @@ -0,0 +1,34 @@
> +## @file
> +#
> +# Copyright (C) 2018, Marvell International Ltd. and its affiliates<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 = ArmadaMcBinBoardDescLib
> + FILE_GUID = 8208558f-5f33-46e2-b5c5-43354384389e
> + MODULE_TYPE = BASE
> + VERSION_STRING = 1.0
> + LIBRARY_CLASS = ArmadaBoardDescLib
> +
> +[Sources]
> + Armada80x0McBinBoardDescLib.c
> +
> +[Packages]
> + MdeModulePkg/MdeModulePkg.dec
> + MdePkg/MdePkg.dec
> + Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> + DebugLib
> + IoLib
> diff --git a/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
> new file mode 100644
> index 0000000..979db11
> --- /dev/null
> +++ b/Platform/SolidRun/Armada80x0McBin/Armada80x0McBinBoardDescLib/Armada80x0McBinBoardDescLib.c
> @@ -0,0 +1,36 @@
> +/**
> +*
> +* 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.
> +*
> +**/
> +
> +#include <Uefi.h>
> +
> +#include <Library/ArmadaBoardDescLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +
> +EFI_STATUS
> +EFIAPI
> +ArmadaBoardDescGpioGet (
> + IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
> + IN OUT UINTN *I2cIoExpanderCount
> + )
> +{
> + /* No I2C IO expanders on board */
> + *I2cIoExpanderDesc = NULL;
> + *I2cIoExpanderCount = 0;
> +
> + return EFI_SUCCESS;
> +}
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [platforms: PATCH 04/12] Marvell/Armada70x0Db: Introduce board description library
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
` (2 preceding siblings ...)
2018-10-20 1:57 ` [platforms: PATCH 03/12] SolidRun/Armada80x0McBin: Introduce board description library Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-12-04 15:27 ` Leif Lindholm
2018-10-20 1:57 ` [platforms: PATCH 05/12] Marvell/Armada80x0Db: " Marcin Wojtas
` (7 subsequent siblings)
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 UTC (permalink / raw)
To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap
This patch implements ArmadaBoarDescLib library for
Armada70x0Db and introduces ArmadaBoardDescGpioGet
routine with per-board I2C IO expander description.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc | 3 ++
Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf | 34 ++++++++++++++++
Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c | 43 ++++++++++++++++++++
3 files changed, 80 insertions(+)
create mode 100644 Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
create mode 100644 Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
index e0bf447..a935f36 100644
--- a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
+++ b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
@@ -54,6 +54,9 @@
[Components.AARCH64]
Silicon/Marvell/Armada7k8k/AcpiTables/Armada70x0Db.inf
+[LibraryClasses.common]
+ ArmadaBoardDescLib|Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
+
################################################################################
#
# Pcd Section - list of all EDK II PCD Entries defined by this Platform
diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
new file mode 100644
index 0000000..b26f55b
--- /dev/null
+++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
@@ -0,0 +1,34 @@
+## @file
+#
+# Copyright (C) 2018, Marvell International Ltd. and its affiliates<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 = Armada70x0DbBoardDescLib
+ FILE_GUID = 3164c8d9-19d4-4ad6-8196-cea094b1ddf1
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = ArmadaBoardDescLib
+
+[Sources]
+ Armada70x0DbBoardDescLib.c
+
+[Packages]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+ DebugLib
+ IoLib
diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
new file mode 100644
index 0000000..51e6687
--- /dev/null
+++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
@@ -0,0 +1,43 @@
+/**
+*
+* 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.
+*
+**/
+
+#include <Uefi.h>
+
+#include <Library/ArmadaBoardDescLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/IoLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Protocol/MvGpio.h>
+
+STATIC MV_I2C_IO_EXPANDER_DESC mI2cIoExpanderDescTemplate = {
+ PCA9555_ID,
+ 0x21,
+ 0x0,
+};
+
+EFI_STATUS
+EFIAPI
+ArmadaBoardDescGpioGet (
+ IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
+ IN OUT UINTN *I2cIoExpanderCount
+ )
+{
+ *I2cIoExpanderCount = 1;
+ *I2cIoExpanderDesc = &mI2cIoExpanderDescTemplate;
+
+ return EFI_SUCCESS;
+}
--
2.7.4
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 04/12] Marvell/Armada70x0Db: Introduce board description library
2018-10-20 1:57 ` [platforms: PATCH 04/12] Marvell/Armada70x0Db: " Marcin Wojtas
@ 2018-12-04 15:27 ` Leif Lindholm
0 siblings, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 15:27 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap
On Sat, Oct 20, 2018 at 03:57:33AM +0200, Marcin Wojtas wrote:
> This patch implements ArmadaBoarDescLib library for
> Armada70x0Db and introduces ArmadaBoardDescGpioGet
> routine with per-board I2C IO expander description.
Same commit message comment as 3/12.
This one actually has I2c, but still - please rename all of the types
and variables. (Feel free to add a comment saying the expander is on
I2c, but that is not the relevant bit code-wise.)
/
Leif
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
> Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc | 3 ++
> Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf | 34 ++++++++++++++++
> Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c | 43 ++++++++++++++++++++
> 3 files changed, 80 insertions(+)
> create mode 100644 Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
> create mode 100644 Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
>
> diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
> index e0bf447..a935f36 100644
> --- a/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
> +++ b/Platform/Marvell/Armada70x0Db/Armada70x0Db.dsc
> @@ -54,6 +54,9 @@
> [Components.AARCH64]
> Silicon/Marvell/Armada7k8k/AcpiTables/Armada70x0Db.inf
>
> +[LibraryClasses.common]
> + ArmadaBoardDescLib|Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
> +
> ################################################################################
> #
> # Pcd Section - list of all EDK II PCD Entries defined by this Platform
> diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
> new file mode 100644
> index 0000000..b26f55b
> --- /dev/null
> +++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.inf
> @@ -0,0 +1,34 @@
> +## @file
> +#
> +# Copyright (C) 2018, Marvell International Ltd. and its affiliates<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 = Armada70x0DbBoardDescLib
> + FILE_GUID = 3164c8d9-19d4-4ad6-8196-cea094b1ddf1
> + MODULE_TYPE = BASE
> + VERSION_STRING = 1.0
> + LIBRARY_CLASS = ArmadaBoardDescLib
> +
> +[Sources]
> + Armada70x0DbBoardDescLib.c
> +
> +[Packages]
> + MdeModulePkg/MdeModulePkg.dec
> + MdePkg/MdePkg.dec
> + Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> + DebugLib
> + IoLib
> diff --git a/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
> new file mode 100644
> index 0000000..51e6687
> --- /dev/null
> +++ b/Platform/Marvell/Armada70x0Db/Armada70x0DbBoardDescLib/Armada70x0DbBoardDescLib.c
> @@ -0,0 +1,43 @@
> +/**
> +*
> +* 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.
> +*
> +**/
> +
> +#include <Uefi.h>
> +
> +#include <Library/ArmadaBoardDescLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +
> +#include <Protocol/MvGpio.h>
> +
> +STATIC MV_I2C_IO_EXPANDER_DESC mI2cIoExpanderDescTemplate = {
> + PCA9555_ID,
> + 0x21,
> + 0x0,
> +};
> +
> +EFI_STATUS
> +EFIAPI
> +ArmadaBoardDescGpioGet (
> + IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
> + IN OUT UINTN *I2cIoExpanderCount
> + )
> +{
> + *I2cIoExpanderCount = 1;
> + *I2cIoExpanderDesc = &mI2cIoExpanderDescTemplate;
> +
> + return EFI_SUCCESS;
> +}
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [platforms: PATCH 05/12] Marvell/Armada80x0Db: Introduce board description library
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
` (3 preceding siblings ...)
2018-10-20 1:57 ` [platforms: PATCH 04/12] Marvell/Armada70x0Db: " Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-12-04 15:31 ` Leif Lindholm
2018-10-20 1:57 ` [platforms: PATCH 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support Marcin Wojtas
` (6 subsequent siblings)
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 UTC (permalink / raw)
To: edk2-devel; +Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap
This patch implements ArmadaBoarDescLib library for
Armada80x0Db and introduces ArmadaBoardDescGpioGet
routine with per-board I2C IO expander description.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc | 3 ++
Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf | 34 +++++++++++++
Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c | 50 ++++++++++++++++++++
3 files changed, 87 insertions(+)
create mode 100644 Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
create mode 100644 Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc b/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
index 92e2dc8..42f7bd3 100644
--- a/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
+++ b/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
@@ -54,6 +54,9 @@
[Components.AARCH64]
Silicon/Marvell/Armada7k8k/AcpiTables/Armada80x0Db.inf
+[LibraryClasses.common]
+ ArmadaBoardDescLib|Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
+
################################################################################
#
# Pcd Section - list of all EDK II PCD Entries defined by this Platform
diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
new file mode 100644
index 0000000..2d39d96
--- /dev/null
+++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
@@ -0,0 +1,34 @@
+## @file
+#
+# Copyright (C) 2018, Marvell International Ltd. and its affiliates<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 = Armada80x0DbBoardDescLib
+ FILE_GUID = fee9e874-1481-4b4f-9882-966bd0d1310f
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = ArmadaBoardDescLib
+
+[Sources]
+ Armada80x0DbBoardDescLib.c
+
+[Packages]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+ DebugLib
+ IoLib
diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
new file mode 100644
index 0000000..16561bc
--- /dev/null
+++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
@@ -0,0 +1,50 @@
+/**
+*
+* 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.
+*
+**/
+
+#include <Uefi.h>
+
+#include <Library/ArmadaBoardDescLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/IoLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Protocol/MvGpio.h>
+
+STATIC MV_I2C_IO_EXPANDER_DESC mI2cIoExpanderDescTemplate[] = {
+ {
+ PCA9555_ID,
+ 0x21,
+ 0x0,
+ },
+ {
+ PCA9555_ID,
+ 0x25,
+ 0x0,
+ },
+};
+
+EFI_STATUS
+EFIAPI
+ArmadaBoardDescGpioGet (
+ IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
+ IN OUT UINTN *I2cIoExpanderCount
+ )
+{
+ *I2cIoExpanderCount = ARRAY_SIZE (mI2cIoExpanderDescTemplate);
+ *I2cIoExpanderDesc = mI2cIoExpanderDescTemplate;
+
+ return EFI_SUCCESS;
+}
--
2.7.4
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 05/12] Marvell/Armada80x0Db: Introduce board description library
2018-10-20 1:57 ` [platforms: PATCH 05/12] Marvell/Armada80x0Db: " Marcin Wojtas
@ 2018-12-04 15:31 ` Leif Lindholm
0 siblings, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 15:31 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap
On Sat, Oct 20, 2018 at 03:57:34AM +0200, Marcin Wojtas wrote:
> This patch implements ArmadaBoarDescLib library for
> Armada80x0Db and introduces ArmadaBoardDescGpioGet
> routine with per-board I2C IO expander description.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
> Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc | 3 ++
> Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf | 34 +++++++++++++
> Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c | 50 ++++++++++++++++++++
> 3 files changed, 87 insertions(+)
> create mode 100644 Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
> create mode 100644 Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
>
> diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc b/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
> index 92e2dc8..42f7bd3 100644
> --- a/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
> +++ b/Platform/Marvell/Armada80x0Db/Armada80x0Db.dsc
> @@ -54,6 +54,9 @@
> [Components.AARCH64]
> Silicon/Marvell/Armada7k8k/AcpiTables/Armada80x0Db.inf
>
> +[LibraryClasses.common]
> + ArmadaBoardDescLib|Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
> +
> ################################################################################
> #
> # Pcd Section - list of all EDK II PCD Entries defined by this Platform
> diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
> new file mode 100644
> index 0000000..2d39d96
> --- /dev/null
> +++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.inf
> @@ -0,0 +1,34 @@
> +## @file
> +#
> +# Copyright (C) 2018, Marvell International Ltd. and its affiliates<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 = Armada80x0DbBoardDescLib
> + FILE_GUID = fee9e874-1481-4b4f-9882-966bd0d1310f
> + MODULE_TYPE = BASE
> + VERSION_STRING = 1.0
> + LIBRARY_CLASS = ArmadaBoardDescLib
> +
> +[Sources]
> + Armada80x0DbBoardDescLib.c
> +
> +[Packages]
> + MdeModulePkg/MdeModulePkg.dec
> + MdePkg/MdePkg.dec
> + Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> + DebugLib
> + IoLib
> diff --git a/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
> new file mode 100644
> index 0000000..16561bc
> --- /dev/null
> +++ b/Platform/Marvell/Armada80x0Db/Armada80x0DbBoardDescLib/Armada80x0DbBoardDescLib.c
> @@ -0,0 +1,50 @@
> +/**
> +*
> +* 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.
> +*
> +**/
> +
> +#include <Uefi.h>
> +
> +#include <Library/ArmadaBoardDescLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/IoLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +
> +#include <Protocol/MvGpio.h>
> +
> +STATIC MV_I2C_IO_EXPANDER_DESC mI2cIoExpanderDescTemplate[] = {
No objection to the above (apart from the I2c bit, see previous
patches), but: this is a STATIC array - it doesn't need to worry about
namespace.
And it isn't really a template - it is the actual description.
So ... you could just call it mGpioExpanders or something.
Same I2c -> GPIO comment as for preceding patches.
> + {
> + PCA9555_ID,
> + 0x21,
> + 0x0,
> + },
> + {
> + PCA9555_ID,
> + 0x25,
> + 0x0,
> + },
> +};
> +
> +EFI_STATUS
> +EFIAPI
> +ArmadaBoardDescGpioGet (
> + IN OUT MV_I2C_IO_EXPANDER_DESC **I2cIoExpanderDesc,
> + IN OUT UINTN *I2cIoExpanderCount
> + )
> +{
> + *I2cIoExpanderCount = ARRAY_SIZE (mI2cIoExpanderDescTemplate);
> + *I2cIoExpanderDesc = mI2cIoExpanderDescTemplate;
> +
> + return EFI_SUCCESS;
> +}
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [platforms: PATCH 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
` (4 preceding siblings ...)
2018-10-20 1:57 ` [platforms: PATCH 05/12] Marvell/Armada80x0Db: " Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-12-04 15:42 ` Leif Lindholm
2018-10-20 1:57 ` [platforms: PATCH 07/12] Marvell/Protocol: Introduce MARVELL_GPIO_PROTOCOL Marcin Wojtas
` (5 subsequent siblings)
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 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/Drivers/BoardDesc/MvBoardDescDxe.inf | 1 +
Silicon/Marvell/Include/Protocol/BoardDesc.h | 8 ++++
Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c | 48 ++++++++++++++++++++
3 files changed, 57 insertions(+)
diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
index 41f72d6..0b93948 100644
--- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
+++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
@@ -47,6 +47,7 @@
Silicon/Marvell/Marvell.dec
[LibraryClasses]
+ ArmadaBoardDescLib
ArmadaSoCDescLib
DebugLib
MemoryAllocationLib
diff --git a/Silicon/Marvell/Include/Protocol/BoardDesc.h b/Silicon/Marvell/Include/Protocol/BoardDesc.h
index 1d57a16..e06d689 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_DESC_GPIO_GET) (
+ IN MARVELL_BOARD_DESC_PROTOCOL *This,
+ IN OUT MV_BOARD_GPIO_DESC **GpioDesc
+ );
+
+typedef
+EFI_STATUS
(EFIAPI *MV_BOARD_DESC_I2C_GET) (
IN MARVELL_BOARD_DESC_PROTOCOL *This,
IN OUT MV_BOARD_I2C_DESC **I2cDesc
@@ -106,6 +113,7 @@ VOID
struct _MARVELL_BOARD_DESC_PROTOCOL {
MV_BOARD_DESC_AHCI_GET BoardDescAhciGet;
MV_BOARD_DESC_COMPHY_GET BoardDescComPhyGet;
+ MV_BOARD_DESC_GPIO_GET BoardDescGpioGet;
MV_BOARD_DESC_I2C_GET BoardDescI2cGet;
MV_BOARD_DESC_MDIO_GET BoardDescMdioGet;
MV_BOARD_DESC_PP2_GET BoardDescPp2Get;
diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
index 39dc06c..948a6a0 100644
--- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
+++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
@@ -100,6 +100,53 @@ MvBoardDescComPhyGet (
STATIC
EFI_STATUS
+MvBoardDescGpioGet (
+ IN MARVELL_BOARD_DESC_PROTOCOL *This,
+ IN OUT MV_BOARD_GPIO_DESC **GpioDesc
+ )
+{
+ MV_I2C_IO_EXPANDER_DESC *I2cIoExpanderDesc;
+ UINTN SoCGpioCount, I2cIoExpanderCount;
+ STATIC MV_BOARD_GPIO_DESC *BoardDesc;
+ MV_SOC_GPIO_DESC *SoCDesc;
+ EFI_STATUS Status;
+
+ if (BoardDesc != NULL) {
+ *GpioDesc = BoardDesc;
+ return EFI_SUCCESS;
+ }
+
+ /* Get SoC data about all available GPIO controllers */
+ Status = ArmadaSoCDescGpioGet (&SoCDesc, &SoCGpioCount);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ /* Get per-board information about all available I2C IO expanders */
+ Status = ArmadaBoardDescGpioGet (&I2cIoExpanderDesc, &I2cIoExpanderCount);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ /* Allocate and fill board description */
+ BoardDesc = AllocateZeroPool (sizeof (MV_BOARD_GPIO_DESC));
+ if (BoardDesc == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ BoardDesc->SoC = SoCDesc;
+ BoardDesc->GpioDevCount = SoCGpioCount;
+ BoardDesc->I2cIoExpanderDesc = I2cIoExpanderDesc;
+ BoardDesc->I2cIoExpanderCount = I2cIoExpanderCount;
+
+ *GpioDesc = BoardDesc;
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
MvBoardDescI2cGet (
IN MARVELL_BOARD_DESC_PROTOCOL *This,
IN OUT MV_BOARD_I2C_DESC **I2cDesc
@@ -556,6 +603,7 @@ MvBoardDescInitProtocol (
{
BoardDescProtocol->BoardDescAhciGet = MvBoardDescAhciGet;
BoardDescProtocol->BoardDescComPhyGet = MvBoardDescComPhyGet;
+ BoardDescProtocol->BoardDescGpioGet = MvBoardDescGpioGet;
BoardDescProtocol->BoardDescI2cGet = MvBoardDescI2cGet;
BoardDescProtocol->BoardDescMdioGet = MvBoardDescMdioGet;
BoardDescProtocol->BoardDescPp2Get = MvBoardDescPp2Get;
--
2.7.4
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support
2018-10-20 1:57 ` [platforms: PATCH 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support Marcin Wojtas
@ 2018-12-04 15:42 ` Leif Lindholm
0 siblings, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 15:42 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap
On Sat, Oct 20, 2018 at 03:57:35AM +0200, 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/Drivers/BoardDesc/MvBoardDescDxe.inf | 1 +
> Silicon/Marvell/Include/Protocol/BoardDesc.h | 8 ++++
> Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c | 48 ++++++++++++++++++++
> 3 files changed, 57 insertions(+)
>
> diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
> index 41f72d6..0b93948 100644
> --- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
> +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.inf
> @@ -47,6 +47,7 @@
> Silicon/Marvell/Marvell.dec
>
> [LibraryClasses]
> + ArmadaBoardDescLib
> ArmadaSoCDescLib
> DebugLib
> MemoryAllocationLib
> diff --git a/Silicon/Marvell/Include/Protocol/BoardDesc.h b/Silicon/Marvell/Include/Protocol/BoardDesc.h
> index 1d57a16..e06d689 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_DESC_GPIO_GET) (
> + IN MARVELL_BOARD_DESC_PROTOCOL *This,
> + IN OUT MV_BOARD_GPIO_DESC **GpioDesc
> + );
> +
> +typedef
> +EFI_STATUS
> (EFIAPI *MV_BOARD_DESC_I2C_GET) (
> IN MARVELL_BOARD_DESC_PROTOCOL *This,
> IN OUT MV_BOARD_I2C_DESC **I2cDesc
> @@ -106,6 +113,7 @@ VOID
> struct _MARVELL_BOARD_DESC_PROTOCOL {
> MV_BOARD_DESC_AHCI_GET BoardDescAhciGet;
> MV_BOARD_DESC_COMPHY_GET BoardDescComPhyGet;
> + MV_BOARD_DESC_GPIO_GET BoardDescGpioGet;
> MV_BOARD_DESC_I2C_GET BoardDescI2cGet;
> MV_BOARD_DESC_MDIO_GET BoardDescMdioGet;
> MV_BOARD_DESC_PP2_GET BoardDescPp2Get;
> diff --git a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> index 39dc06c..948a6a0 100644
> --- a/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> +++ b/Silicon/Marvell/Drivers/BoardDesc/MvBoardDescDxe.c
> @@ -100,6 +100,53 @@ MvBoardDescComPhyGet (
>
> STATIC
> EFI_STATUS
> +MvBoardDescGpioGet (
> + IN MARVELL_BOARD_DESC_PROTOCOL *This,
> + IN OUT MV_BOARD_GPIO_DESC **GpioDesc
> + )
> +{
> + MV_I2C_IO_EXPANDER_DESC *I2cIoExpanderDesc;
> + UINTN SoCGpioCount, I2cIoExpanderCount;
> + STATIC MV_BOARD_GPIO_DESC *BoardDesc;
> + MV_SOC_GPIO_DESC *SoCDesc;
> + EFI_STATUS Status;
> +
> + if (BoardDesc != NULL) {
> + *GpioDesc = BoardDesc;
> + return EFI_SUCCESS;
> + }
For a completely opposite comment to the previous patch:
I would much prefer for BoardDesc to be a globally visible variable
with a g prefix and proper namespace.
Even though it itself is not globally visible, the above maneuver
makes it effectively so, but not semantically.
It's not like there's a million call sites, so I would prefer if the
check was there rather than in this function.
> +
> + /* Get SoC data about all available GPIO controllers */
> + Status = ArmadaSoCDescGpioGet (&SoCDesc, &SoCGpioCount);
> + if (EFI_ERROR (Status)) {
> + return Status;
> + }
> +
> + /* Get per-board information about all available I2C IO expanders */
> + Status = ArmadaBoardDescGpioGet (&I2cIoExpanderDesc, &I2cIoExpanderCount);
Same I2C->GPIO comments apply here.
> + if (EFI_ERROR (Status)) {
> + return Status;
> + }
> +
> + /* Allocate and fill board description */
> + BoardDesc = AllocateZeroPool (sizeof (MV_BOARD_GPIO_DESC));
> + if (BoardDesc == NULL) {
> + DEBUG ((DEBUG_ERROR, "%a: Cannot allocate memory\n", __FUNCTION__));
> + return EFI_OUT_OF_RESOURCES;
> + }
> +
> + BoardDesc->SoC = SoCDesc;
> + BoardDesc->GpioDevCount = SoCGpioCount;
> + BoardDesc->I2cIoExpanderDesc = I2cIoExpanderDesc;
> + BoardDesc->I2cIoExpanderCount = I2cIoExpanderCount;
> +
> + *GpioDesc = BoardDesc;
> +
> + return EFI_SUCCESS;
> +}
> +
> +STATIC
> +EFI_STATUS
> MvBoardDescI2cGet (
> IN MARVELL_BOARD_DESC_PROTOCOL *This,
> IN OUT MV_BOARD_I2C_DESC **I2cDesc
> @@ -556,6 +603,7 @@ MvBoardDescInitProtocol (
> {
> BoardDescProtocol->BoardDescAhciGet = MvBoardDescAhciGet;
> BoardDescProtocol->BoardDescComPhyGet = MvBoardDescComPhyGet;
> + BoardDescProtocol->BoardDescGpioGet = MvBoardDescGpioGet;
> BoardDescProtocol->BoardDescI2cGet = MvBoardDescI2cGet;
Even more so because of the two lines above :)
/
Leif
> BoardDescProtocol->BoardDescMdioGet = MvBoardDescMdioGet;
> BoardDescProtocol->BoardDescPp2Get = MvBoardDescPp2Get;
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [platforms: PATCH 07/12] Marvell/Protocol: Introduce MARVELL_GPIO_PROTOCOL
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
` (5 preceding siblings ...)
2018-10-20 1:57 ` [platforms: PATCH 06/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-12-04 16:00 ` Leif Lindholm
2018-10-20 1:57 ` [platforms: PATCH 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver Marcin Wojtas
` (4 subsequent siblings)
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 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 protocol that can be used by multiple
producers (e.g. platform driver or I2C I/O expander).
It exposes generic api for controlling GPIO pins state.
Drives are differentiated by MARVELL_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 - MarvellGpioGetHandle().
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
Silicon/Marvell/Marvell.dec | 1 +
Silicon/Marvell/Include/Protocol/MvGpio.h | 199 ++++++++++++++++++++
2 files changed, 200 insertions(+)
create mode 100644 Silicon/Marvell/Include/Protocol/MvGpio.h
diff --git a/Silicon/Marvell/Marvell.dec b/Silicon/Marvell/Marvell.dec
index 616624e..7e1c37a 100644
--- a/Silicon/Marvell/Marvell.dec
+++ b/Silicon/Marvell/Marvell.dec
@@ -215,6 +215,7 @@
[Protocols]
gMarvellBoardDescProtocolGuid = { 0xebed8738, 0xd4a6, 0x4001, { 0xa9, 0xc9, 0x52, 0xb0, 0xcb, 0x7d, 0xdb, 0xf9 }}
gMarvellEepromProtocolGuid = { 0x71954bda, 0x60d3, 0x4ef8, { 0x8e, 0x3c, 0x0e, 0x33, 0x9f, 0x3b, 0xc2, 0x2b }}
+ gMarvellGpioProtocolGuid = { 0x8b01a5b7, 0xc570, 0x4e97, { 0x80, 0x95, 0x4f, 0x74, 0x2a, 0x8d, 0x7d, 0x43 }}
gMarvellMdioProtocolGuid = { 0x40010b03, 0x5f08, 0x496a, { 0xa2, 0x64, 0x10, 0x5e, 0x72, 0xd3, 0x71, 0xaa }}
gMarvellPhyProtocolGuid = { 0x32f48a43, 0x37e3, 0x4acf, { 0x93, 0xc4, 0x3e, 0x57, 0xa7, 0xb0, 0xfb, 0xdc }}
gMarvellSpiMasterProtocolGuid = { 0x23de66a3, 0xf666, 0x4b3e, { 0xaa, 0xa2, 0x68, 0x9b, 0x18, 0xae, 0x2e, 0x19 }}
diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
new file mode 100644
index 0000000..a335cab
--- /dev/null
+++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
@@ -0,0 +1,199 @@
+/**
+*
+* 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 __MARVELL_GPIO_PROTOCOL_H__
+#define __MARVELL_GPIO_PROTOCOL_H__
+
+#include <Uefi.h>
+
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+extern EFI_GUID gMarvellGpioProtocolGuid;
+
+typedef struct _MARVELL_GPIO_PROTOCOL MARVELL_GPIO_PROTOCOL;
+
+typedef enum {
+ GPIO_MODE_INPUT = 0x0,
+ GPIO_MODE_OUTPUT = 0x1
+} MARVELL_GPIO_MODE;
+
+typedef enum {
+ GPIO_DRIVER_TYPE_SOC_CONTROLLER = 0x0,
+ GPIO_DRIVER_TYPE_PCA95XX = 0x1
+} MARVELL_GPIO_DRIVER_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,
+} MARVELL_IO_EXPANDER_TYPE_PCA95XX;
+
+typedef
+EFI_STATUS
+(EFIAPI *MV_GPIO_DIRECTION_OUTPUT) (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ IN BOOLEAN Value
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI *MV_GPIO_DIRECTION_INPUT) (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI *MV_GPIO_GET_FUNCTION) (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ OUT MARVELL_GPIO_MODE *Mode
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI *MV_GPIO_GET_VALUE) (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ OUT BOOLEAN *Value
+ );
+
+typedef
+EFI_STATUS
+(EFIAPI *MV_GPIO_SET_VALUE) (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ IN BOOLEAN Value
+ );
+
+struct _MARVELL_GPIO_PROTOCOL {
+ MV_GPIO_DIRECTION_INPUT DirectionInput;
+ MV_GPIO_DIRECTION_OUTPUT DirectionOutput;
+ MV_GPIO_GET_FUNCTION GetFunction;
+ MV_GPIO_GET_VALUE GetValue;
+ MV_GPIO_SET_VALUE SetValue;
+};
+
+typedef struct {
+ VENDOR_DEVICE_PATH Header;
+ MARVELL_GPIO_DRIVER_TYPE GpioDriverType;
+ EFI_DEVICE_PATH_PROTOCOL End;
+} MV_GPIO_DEVICE_PATH;
+
+typedef struct {
+ UINTN ControllerId;
+ UINTN PinNumber;
+ BOOLEAN ActiveHigh;
+} GPIO_PIN_DESC;
+
+/*
+ * Select desired protocol producer upon MARVELL_GPIO_DRIVER_TYPE
+ * field of driver's MV_GPIO_DEVICE_PATH.
+ */
+STATIC
+inline
+EFI_STATUS
+EFIAPI
+MvGpioGetProtocol (
+ IN MARVELL_GPIO_DRIVER_TYPE GpioDriverType,
+ IN OUT MARVELL_GPIO_PROTOCOL **GpioProtocol
+ )
+{
+ MV_GPIO_DEVICE_PATH *GpioDevicePath;
+ EFI_DEVICE_PATH *DevicePath;
+ EFI_HANDLE *HandleBuffer;
+ EFI_STATUS Status;
+ UINTN HandleCount;
+ UINTN Index;
+
+ /* Locate Handles of all MARVELL_GPIO_PROTOCOL producers */
+ Status = gBS->LocateHandleBuffer (ByProtocol,
+ &gMarvellGpioProtocolGuid,
+ 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;
+ }
+
+ 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[Index],
+ &gMarvellGpioProtocolGuid,
+ (VOID **)GpioProtocol,
+ gImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Unable to open GPIO protocol\n",
+ __FUNCTION__));
+ gBS->FreePool (HandleBuffer);
+ return Status;
+ }
+
+ gBS->FreePool (HandleBuffer);
+
+ return EFI_SUCCESS;
+ }
+ }
+
+ gBS->FreePool (HandleBuffer);
+
+ return EFI_UNSUPPORTED;
+}
+
+#endif // __MARVELL_GPIO_PROTOCOL_H__
--
2.7.4
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 07/12] Marvell/Protocol: Introduce MARVELL_GPIO_PROTOCOL
2018-10-20 1:57 ` [platforms: PATCH 07/12] Marvell/Protocol: Introduce MARVELL_GPIO_PROTOCOL Marcin Wojtas
@ 2018-12-04 16:00 ` Leif Lindholm
0 siblings, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 16:00 UTC (permalink / raw)
To: Marcin Wojtas
Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap, jinghua
On Sat, Oct 20, 2018 at 03:57:36AM +0200, Marcin Wojtas wrote:
> From: jinghua <jinghua@marvell.com>
>
> This patch introduces protocol that can be used by multiple
> producers (e.g. platform driver or I2C I/O expander).
> It exposes generic api for controlling GPIO pins state.
> Drives are differentiated by MARVELL_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 - MarvellGpioGetHandle().
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
> Silicon/Marvell/Marvell.dec | 1 +
> Silicon/Marvell/Include/Protocol/MvGpio.h | 199 ++++++++++++++++++++
> 2 files changed, 200 insertions(+)
> create mode 100644 Silicon/Marvell/Include/Protocol/MvGpio.h
>
> diff --git a/Silicon/Marvell/Marvell.dec b/Silicon/Marvell/Marvell.dec
> index 616624e..7e1c37a 100644
> --- a/Silicon/Marvell/Marvell.dec
> +++ b/Silicon/Marvell/Marvell.dec
> @@ -215,6 +215,7 @@
> [Protocols]
> gMarvellBoardDescProtocolGuid = { 0xebed8738, 0xd4a6, 0x4001, { 0xa9, 0xc9, 0x52, 0xb0, 0xcb, 0x7d, 0xdb, 0xf9 }}
> gMarvellEepromProtocolGuid = { 0x71954bda, 0x60d3, 0x4ef8, { 0x8e, 0x3c, 0x0e, 0x33, 0x9f, 0x3b, 0xc2, 0x2b }}
> + gMarvellGpioProtocolGuid = { 0x8b01a5b7, 0xc570, 0x4e97, { 0x80, 0x95, 0x4f, 0x74, 0x2a, 0x8d, 0x7d, 0x43 }}
> gMarvellMdioProtocolGuid = { 0x40010b03, 0x5f08, 0x496a, { 0xa2, 0x64, 0x10, 0x5e, 0x72, 0xd3, 0x71, 0xaa }}
> gMarvellPhyProtocolGuid = { 0x32f48a43, 0x37e3, 0x4acf, { 0x93, 0xc4, 0x3e, 0x57, 0xa7, 0xb0, 0xfb, 0xdc }}
> gMarvellSpiMasterProtocolGuid = { 0x23de66a3, 0xf666, 0x4b3e, { 0xaa, 0xa2, 0x68, 0x9b, 0x18, 0xae, 0x2e, 0x19 }}
> diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h
> new file mode 100644
> index 0000000..a335cab
> --- /dev/null
> +++ b/Silicon/Marvell/Include/Protocol/MvGpio.h
> @@ -0,0 +1,199 @@
> +/**
> +*
> +* 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 __MARVELL_GPIO_PROTOCOL_H__
> +#define __MARVELL_GPIO_PROTOCOL_H__
> +
> +#include <Uefi.h>
> +
> +#include <Library/DebugLib.h>
> +#include <Library/DevicePathLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +
> +extern EFI_GUID gMarvellGpioProtocolGuid;
> +
> +typedef struct _MARVELL_GPIO_PROTOCOL MARVELL_GPIO_PROTOCOL;
> +
> +typedef enum {
> + GPIO_MODE_INPUT = 0x0,
> + GPIO_MODE_OUTPUT = 0x1
> +} MARVELL_GPIO_MODE;
GPIO_ is a bit too specific a prefix (even if only used in
Marvell-specific code, it makes it look not Marvell-specific).
MVGPIO?
> +
> +typedef enum {
> + GPIO_DRIVER_TYPE_SOC_CONTROLLER = 0x0,
> + GPIO_DRIVER_TYPE_PCA95XX = 0x1
> +} MARVELL_GPIO_DRIVER_TYPE;
Here is sort of what I was getting at before. If you ever end up
adding another type to this enum (say on a derivative board), that
means the hard (semantic) dependence on I2c for the expander will make
things really confusing. And may require substantial code refactoring
at that point.
> +
> +typedef enum {
> + PCA9505_ID,
Are these referring to software-addressable hardware IDs, or just used
for software-internal references?
> + PCA9534_ID,
> + PCA9535_ID,
> + PCA9536_ID,
> + PCA9537_ID,
> + PCA9538_ID,
> + PCA9539_ID,
> + PCA9554_ID,
> + PCA9555_ID,
> + PCA9556_ID,
> + PCA9557_ID,
> + PCA95XX_MAX_ID,
> +} MARVELL_IO_EXPANDER_TYPE_PCA95XX;
MARVELL_PCA95XX_VARIANT? If you're checking for which version of it
you're dealing with, you already know what it is.
Either way, it would be easier to understand its use if it was
introduced with the patch that adds code that makes use of it.
> +
> +typedef
> +EFI_STATUS
> +(EFIAPI *MV_GPIO_DIRECTION_OUTPUT) (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + IN BOOLEAN Value
> + );
> +
> +typedef
> +EFI_STATUS
> +(EFIAPI *MV_GPIO_DIRECTION_INPUT) (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin
> + );
> +
> +typedef
> +EFI_STATUS
> +(EFIAPI *MV_GPIO_GET_FUNCTION) (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + OUT MARVELL_GPIO_MODE *Mode
> + );
> +
> +typedef
> +EFI_STATUS
> +(EFIAPI *MV_GPIO_GET_VALUE) (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + OUT BOOLEAN *Value
> + );
> +
> +typedef
> +EFI_STATUS
> +(EFIAPI *MV_GPIO_SET_VALUE) (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + IN BOOLEAN Value
> + );
> +
> +struct _MARVELL_GPIO_PROTOCOL {
> + MV_GPIO_DIRECTION_INPUT DirectionInput;
> + MV_GPIO_DIRECTION_OUTPUT DirectionOutput;
> + MV_GPIO_GET_FUNCTION GetFunction;
> + MV_GPIO_GET_VALUE GetValue;
> + MV_GPIO_SET_VALUE SetValue;
> +};
> +
> +typedef struct {
> + VENDOR_DEVICE_PATH Header;
> + MARVELL_GPIO_DRIVER_TYPE GpioDriverType;
> + EFI_DEVICE_PATH_PROTOCOL End;
> +} MV_GPIO_DEVICE_PATH;
> +
> +typedef struct {
> + UINTN ControllerId;
> + UINTN PinNumber;
> + BOOLEAN ActiveHigh;
> +} GPIO_PIN_DESC;
> +
> +/*
> + * Select desired protocol producer upon MARVELL_GPIO_DRIVER_TYPE
> + * field of driver's MV_GPIO_DEVICE_PATH.
> + */
> +STATIC
> +inline
> +EFI_STATUS
> +EFIAPI
> +MvGpioGetProtocol (
> + IN MARVELL_GPIO_DRIVER_TYPE GpioDriverType,
> + IN OUT MARVELL_GPIO_PROTOCOL **GpioProtocol
> + )
> +{
> + MV_GPIO_DEVICE_PATH *GpioDevicePath;
> + EFI_DEVICE_PATH *DevicePath;
> + EFI_HANDLE *HandleBuffer;
> + EFI_STATUS Status;
> + UINTN HandleCount;
> + UINTN Index;
> +
> + /* Locate Handles of all MARVELL_GPIO_PROTOCOL producers */
> + Status = gBS->LocateHandleBuffer (ByProtocol,
> + &gMarvellGpioProtocolGuid,
> + 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;
> + }
> +
> + 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[Index],
> + &gMarvellGpioProtocolGuid,
> + (VOID **)GpioProtocol,
> + gImageHandle,
> + NULL,
> + EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Unable to open GPIO protocol\n",
> + __FUNCTION__));
> + gBS->FreePool (HandleBuffer);
> + return Status;
> + }
> +
> + gBS->FreePool (HandleBuffer);
> +
> + return EFI_SUCCESS;
> + }
> + }
Could this while loop be broken out into a separate helper function?
The loop and function exit conditions become a but foggy with the
current layout.
/
Leif
> +
> + gBS->FreePool (HandleBuffer);
> +
> + return EFI_UNSUPPORTED;
> +}
> +
> +#endif // __MARVELL_GPIO_PROTOCOL_H__
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [platforms: PATCH 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
` (6 preceding siblings ...)
2018-10-20 1:57 ` [platforms: PATCH 07/12] Marvell/Protocol: Introduce MARVELL_GPIO_PROTOCOL Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-12-04 16:37 ` Leif Lindholm
2018-10-20 1:57 ` [platforms: PATCH 09/12] Marvell/Drivers: I2c: Use common header for macros Marcin Wojtas
` (3 subsequent siblings)
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 UTC (permalink / raw)
To: edk2-devel
Cc: leif.lindholm, ard.biesheuvel, nadavh, mw, jsd, jaz, kostap,
jinghua
From: jinghua <jinghua@marvell.com>
Marvell Armada 7k/8k SoCs comprise integrated GPIO controllers,
one in AP and two in each possible CP hardware blocks.
This patch introduces support for them, which is a producer of
MARVELL_GPIO_PROTOCOL, which add necessary routines.
Hardware description of the controllers is placed in MvHwDescLib.c,
same as other devices.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf | 43 +++
Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h | 52 ++++
Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c | 298 ++++++++++++++++++++
3 files changed, 393 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..2d56433
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
@@ -0,0 +1,43 @@
+## @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]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+ ArmadaSoCDescLib
+ DebugLib
+ MemoryAllocationLib
+ UefiDriverEntryPoint
+ UefiLib
+
+[Protocols]
+ gMarvellBoardDescProtocolGuid
+ gMarvellGpioProtocolGuid
+
+[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..48744dc
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
@@ -0,0 +1,52 @@
+/**
+*
+* 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 GPIO_SIGNATURE SIGNATURE_32 ('G', 'P', 'I', 'O')
+
+#ifndef BIT
+#define BIT(nr) (1 << (nr))
+#endif
+
+// Marvell GPIO Controller Registers
+#define GPIO_DATA_OUT_REG (0x0)
+#define GPIO_OUT_EN_REG (0x4)
+#define GPIO_BLINK_EN_REG (0x8)
+#define GPIO_DATA_IN_POL_REG (0xc)
+#define GPIO_DATA_IN_REG (0x10)
+
+typedef struct {
+ MARVELL_GPIO_PROTOCOL GpioProtocol;
+ MV_BOARD_GPIO_DESC *Desc;
+ UINTN Signature;
+ EFI_HANDLE Handle;
+} MV_GPIO;
+
+#endif // __MV_GPIO_H__
diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
new file mode 100644
index 0000000..fc2d416
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
@@ -0,0 +1,298 @@
+/**
+*
+* 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 mGpioDevicePathTemplate = {
+ {
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ {
+ (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
+ sizeof (MARVELL_GPIO_DRIVER_TYPE)),
+ (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
+ sizeof (MARVELL_GPIO_DRIVER_TYPE)) >> 8),
+ },
+ },
+ EFI_CALLER_ID_GUID
+ },
+ GPIO_DRIVER_TYPE_SOC_CONTROLLER,
+ {
+ END_DEVICE_PATH_TYPE,
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ {
+ sizeof(EFI_DEVICE_PATH_PROTOCOL),
+ 0
+ }
+ }
+};
+
+STATIC
+EFI_STATUS
+MvGpioValidate (
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin
+ )
+{
+ if (ControllerIndex >= mGpioInstance->Desc->GpioDevCount) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Invalid GPIO ControllerIndex: %d\n",
+ __FUNCTION__,
+ ControllerIndex));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (GpioPin >= mGpioInstance->Desc->SoC[ControllerIndex].GpioPinCount) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: GPIO pin #%d not available in Controller#%d\n",
+ __FUNCTION__,
+ GpioPin,
+ ControllerIndex));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MvGpioDirectionOutput (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ IN BOOLEAN Value
+ )
+{
+ UINTN BaseAddress;
+ EFI_STATUS Status;
+
+ Status = MvGpioValidate (ControllerIndex, GpioPin);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Fail to set output for pin #%d\n",
+ __FUNCTION__,
+ GpioPin));
+ return Status;
+ }
+
+ BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
+
+ MmioAndThenOr32 (BaseAddress + GPIO_DATA_OUT_REG,
+ ~BIT (GpioPin),
+ (Value) << GpioPin);
+
+ MmioAnd32 (BaseAddress + GPIO_OUT_EN_REG, ~BIT (GpioPin));
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MvGpioDirectionInput (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin
+ )
+{
+ UINTN BaseAddress;
+ EFI_STATUS Status;
+
+ Status = MvGpioValidate (ControllerIndex, GpioPin);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Fail to set input for pin #%d\n",
+ __FUNCTION__,
+ GpioPin));
+ return Status;
+ }
+
+ BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
+
+ MmioOr32 (BaseAddress + GPIO_OUT_EN_REG, BIT (GpioPin));
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MvGpioGetFunction (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ OUT MARVELL_GPIO_MODE *Mode
+ )
+{
+ UINT32 RegVal;
+ UINTN BaseAddress;
+ EFI_STATUS Status;
+
+ Status = MvGpioValidate (ControllerIndex, GpioPin);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Fail to get function of pin #%d\n",
+ __FUNCTION__,
+ GpioPin));
+ return Status;
+ }
+
+ BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
+
+ RegVal = MmioRead32 (BaseAddress + GPIO_OUT_EN_REG);
+ *Mode = ((RegVal & BIT (GpioPin)) ? GPIO_MODE_INPUT : GPIO_MODE_OUTPUT);
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MvGpioGetValue (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ IN OUT BOOLEAN *Value
+ )
+{
+ UINTN BaseAddress;
+ EFI_STATUS Status;
+
+ Status = MvGpioValidate (ControllerIndex, GpioPin);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Fail to get value of pin #%d\n",
+ __FUNCTION__,
+ GpioPin));
+ return Status;
+ }
+
+ BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
+
+ *Value = !!(MmioRead32 (BaseAddress + GPIO_DATA_IN_REG) & BIT (GpioPin));
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MvGpioSetValue (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ IN BOOLEAN Value
+ )
+{
+ UINTN BaseAddress;
+ EFI_STATUS Status;
+
+ Status = MvGpioValidate (ControllerIndex, GpioPin);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Fail to get value of pin #%d\n",
+ __FUNCTION__,
+ GpioPin));
+ return Status;
+ }
+
+ BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
+
+ MmioAndThenOr32 (BaseAddress + GPIO_DATA_OUT_REG,
+ ~BIT (GpioPin),
+ Value << GpioPin);
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+VOID
+MvGpioInitProtocol (
+ IN MARVELL_GPIO_PROTOCOL *GpioProtocol
+ )
+{
+ GpioProtocol->DirectionInput = MvGpioDirectionInput;
+ GpioProtocol->DirectionOutput = MvGpioDirectionOutput;
+ GpioProtocol->GetFunction = MvGpioGetFunction;
+ GpioProtocol->GetValue = MvGpioGetValue;
+ GpioProtocol->SetValue = MvGpioSetValue;
+}
+
+EFI_STATUS
+EFIAPI
+MvGpioEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ MARVELL_BOARD_DESC_PROTOCOL *BoardDescProtocol;
+ MV_GPIO_DEVICE_PATH *GpioDevicePath;
+ MV_BOARD_GPIO_DESC *Desc;
+ EFI_STATUS Status;
+
+ GpioDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
+ &mGpioDevicePathTemplate);
+ 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 **)&BoardDescProtocol);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Cannot locate BoardDesc protocol\n",
+ __FUNCTION__));
+ goto ErrLocateBoardDesc;
+ }
+
+ Status = BoardDescProtocol->BoardDescGpioGet (BoardDescProtocol, &Desc);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
+ __FUNCTION__));
+ goto ErrLocateBoardDesc;
+ }
+
+ mGpioInstance->Signature = GPIO_SIGNATURE;
+ mGpioInstance->Desc = Desc;
+
+ MvGpioInitProtocol (&mGpioInstance->GpioProtocol);
+
+ Status = gBS->InstallMultipleProtocolInterfaces (&(mGpioInstance->Handle),
+ &gMarvellGpioProtocolGuid,
+ &(mGpioInstance->GpioProtocol),
+ &gEfiDevicePathProtocolGuid,
+ (EFI_DEVICE_PATH_PROTOCOL *)GpioDevicePath,
+ NULL);
+ if (EFI_ERROR (Status)) {
+ goto ErrLocateBoardDesc;
+ }
+
+ return EFI_SUCCESS;
+
+ErrLocateBoardDesc:
+ gBS->FreePool (mGpioInstance);
+
+ErrGpioInstanceAlloc:
+ gBS->FreePool (GpioDevicePath);
+
+ return Status;
+}
--
2.7.4
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver
2018-10-20 1:57 ` [platforms: PATCH 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver Marcin Wojtas
@ 2018-12-04 16:37 ` Leif Lindholm
2018-12-04 16:40 ` Ard Biesheuvel
0 siblings, 1 reply; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 16:37 UTC (permalink / raw)
To: Marcin Wojtas
Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap, jinghua
On Sat, Oct 20, 2018 at 03:57:37AM +0200, Marcin Wojtas wrote:
> From: jinghua <jinghua@marvell.com>
>
> Marvell Armada 7k/8k SoCs comprise integrated GPIO controllers,
> one in AP and two in each possible CP hardware blocks.
>
> This patch introduces support for them, which is a producer of
> MARVELL_GPIO_PROTOCOL, which add necessary routines.
> Hardware description of the controllers is placed in MvHwDescLib.c,
> same as other devices.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
> Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf | 43 +++
> Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h | 52 ++++
> Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c | 298 ++++++++++++++++++++
> 3 files changed, 393 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..2d56433
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
> @@ -0,0 +1,43 @@
> +## @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]
> + MdeModulePkg/MdeModulePkg.dec
> + MdePkg/MdePkg.dec
> + Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> + ArmadaSoCDescLib
> + DebugLib
> + MemoryAllocationLib
> + UefiDriverEntryPoint
> + UefiLib
> +
> +[Protocols]
> + gMarvellBoardDescProtocolGuid
> + gMarvellGpioProtocolGuid
> +
> +[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..48744dc
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
> @@ -0,0 +1,52 @@
> +/**
> +*
> +* 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 GPIO_SIGNATURE SIGNATURE_32 ('G', 'P', 'I', 'O')
Needs more MV.
> +
> +#ifndef BIT
> +#define BIT(nr) (1 << (nr))
> +#endif
OK, you are using this with non-constants.
But please drop the #ifndef and submit a patch to add a BIT macro to
MdePkg/Include/Base.h. (And drop this if you get it accepted :)
> +
> +// Marvell GPIO Controller Registers
> +#define GPIO_DATA_OUT_REG (0x0)
> +#define GPIO_OUT_EN_REG (0x4)
> +#define GPIO_BLINK_EN_REG (0x8)
> +#define GPIO_DATA_IN_POL_REG (0xc)
> +#define GPIO_DATA_IN_REG (0x10)
Needs more MV.
> +
> +typedef struct {
> + MARVELL_GPIO_PROTOCOL GpioProtocol;
> + MV_BOARD_GPIO_DESC *Desc;
> + UINTN Signature;
> + EFI_HANDLE Handle;
> +} MV_GPIO;
> +
> +#endif // __MV_GPIO_H__
> diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
> new file mode 100644
> index 0000000..fc2d416
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
> @@ -0,0 +1,298 @@
> +/**
> +*
> +* 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 mGpioDevicePathTemplate = {
(Again, not used outside this file, doesn't really need the Gpio bit
in the name. Up to you.)
> + {
> + {
> + HARDWARE_DEVICE_PATH,
> + HW_VENDOR_DP,
> + {
> + (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
> + sizeof (MARVELL_GPIO_DRIVER_TYPE)),
> + (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
> + sizeof (MARVELL_GPIO_DRIVER_TYPE)) >> 8),
> + },
> + },
> + EFI_CALLER_ID_GUID
> + },
> + GPIO_DRIVER_TYPE_SOC_CONTROLLER,
> + {
> + END_DEVICE_PATH_TYPE,
> + END_ENTIRE_DEVICE_PATH_SUBTYPE,
> + {
> + sizeof(EFI_DEVICE_PATH_PROTOCOL),
> + 0
> + }
> + }
> +};
> +
> +STATIC
> +EFI_STATUS
> +MvGpioValidate (
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin
> + )
> +{
Please add a comment header for this function explaining what it does.
(I will start becoming more strict on this in general, but I know I've
been lax in the past, so I'll ease into it.)
> + if (ControllerIndex >= mGpioInstance->Desc->GpioDevCount) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Invalid GPIO ControllerIndex: %d\n",
> + __FUNCTION__,
> + ControllerIndex));
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + if (GpioPin >= mGpioInstance->Desc->SoC[ControllerIndex].GpioPinCount) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: GPIO pin #%d not available in Controller#%d\n",
> + __FUNCTION__,
> + GpioPin,
> + ControllerIndex));
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + return EFI_SUCCESS;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvGpioDirectionOutput (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + IN BOOLEAN Value
> + )
> +{
> + UINTN BaseAddress;
> + EFI_STATUS Status;
> +
> + Status = MvGpioValidate (ControllerIndex, GpioPin);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Fail to set output for pin #%d\n",
> + __FUNCTION__,
> + GpioPin));
> + return Status;
> + }
So, I'm on the fence here. Do we need to validate that we're not
trying to write pins that don't exist all the time?
I could see why it may be useful for DEBUG builds and new board
bringup, but even then - could it be a helper function that is called
from an ASSERT and only included ifndef MDEPKG_NDEBUG?
> +
> + BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
> +
> + MmioAndThenOr32 (BaseAddress + GPIO_DATA_OUT_REG,
> + ~BIT (GpioPin),
> + (Value) << GpioPin);
Would be cleaner to have a BITPOSITION macro to match the BIT one.
> +
> + MmioAnd32 (BaseAddress + GPIO_OUT_EN_REG, ~BIT (GpioPin));
> +
> + return EFI_SUCCESS;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvGpioDirectionInput (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin
> + )
> +{
> + UINTN BaseAddress;
> + EFI_STATUS Status;
> +
> + Status = MvGpioValidate (ControllerIndex, GpioPin);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Fail to set input for pin #%d\n",
> + __FUNCTION__,
> + GpioPin));
> + return Status;
> + }
> +
> + BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
> +
> + MmioOr32 (BaseAddress + GPIO_OUT_EN_REG, BIT (GpioPin));
> +
> + return EFI_SUCCESS;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvGpioGetFunction (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + OUT MARVELL_GPIO_MODE *Mode
> + )
> +{
> + UINT32 RegVal;
> + UINTN BaseAddress;
> + EFI_STATUS Status;
> +
> + Status = MvGpioValidate (ControllerIndex, GpioPin);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Fail to get function of pin #%d\n",
> + __FUNCTION__,
> + GpioPin));
> + return Status;
> + }
> +
> + BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
> +
> + RegVal = MmioRead32 (BaseAddress + GPIO_OUT_EN_REG);
> + *Mode = ((RegVal & BIT (GpioPin)) ? GPIO_MODE_INPUT : GPIO_MODE_OUTPUT);
Not a fan of this. This is abusing the fact that the programmer knows
the numeric values of the enum members. At which point, why not nuke
the ternary overhead and go
*Mode = (RegVal & BIT (GpioPin)) >> BIT (GpioPin);
?
An alternative interpretation is that the enum is the software view
only, and that the bit meaning is hardware dependent. In that case, we
additionally need a #define for that.
> +
> + return EFI_SUCCESS;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvGpioGetValue (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + IN OUT BOOLEAN *Value
> + )
> +{
> + UINTN BaseAddress;
> + EFI_STATUS Status;
> +
> + Status = MvGpioValidate (ControllerIndex, GpioPin);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Fail to get value of pin #%d\n",
> + __FUNCTION__,
> + GpioPin));
> + return Status;
> + }
> +
> + BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
> +
> + *Value = !!(MmioRead32 (BaseAddress + GPIO_DATA_IN_REG) & BIT (GpioPin));
Please don't !!.
If necessary, please shift.
/
Leif
> +
> + return EFI_SUCCESS;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvGpioSetValue (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + IN BOOLEAN Value
> + )
> +{
> + UINTN BaseAddress;
> + EFI_STATUS Status;
> +
> + Status = MvGpioValidate (ControllerIndex, GpioPin);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Fail to get value of pin #%d\n",
> + __FUNCTION__,
> + GpioPin));
> + return Status;
> + }
> +
> + BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
> +
> + MmioAndThenOr32 (BaseAddress + GPIO_DATA_OUT_REG,
> + ~BIT (GpioPin),
> + Value << GpioPin);
> +
> + return EFI_SUCCESS;
> +}
> +
> +STATIC
> +VOID
> +MvGpioInitProtocol (
> + IN MARVELL_GPIO_PROTOCOL *GpioProtocol
> + )
> +{
> + GpioProtocol->DirectionInput = MvGpioDirectionInput;
> + GpioProtocol->DirectionOutput = MvGpioDirectionOutput;
> + GpioProtocol->GetFunction = MvGpioGetFunction;
> + GpioProtocol->GetValue = MvGpioGetValue;
> + GpioProtocol->SetValue = MvGpioSetValue;
> +}
> +
> +EFI_STATUS
> +EFIAPI
> +MvGpioEntryPoint (
> + IN EFI_HANDLE ImageHandle,
> + IN EFI_SYSTEM_TABLE *SystemTable
> + )
> +{
> + MARVELL_BOARD_DESC_PROTOCOL *BoardDescProtocol;
> + MV_GPIO_DEVICE_PATH *GpioDevicePath;
> + MV_BOARD_GPIO_DESC *Desc;
> + EFI_STATUS Status;
> +
> + GpioDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
> + &mGpioDevicePathTemplate);
> + 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 **)&BoardDescProtocol);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Cannot locate BoardDesc protocol\n",
> + __FUNCTION__));
> + goto ErrLocateBoardDesc;
> + }
> +
> + Status = BoardDescProtocol->BoardDescGpioGet (BoardDescProtocol, &Desc);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
> + __FUNCTION__));
> + goto ErrLocateBoardDesc;
> + }
> +
> + mGpioInstance->Signature = GPIO_SIGNATURE;
> + mGpioInstance->Desc = Desc;
> +
> + MvGpioInitProtocol (&mGpioInstance->GpioProtocol);
> +
> + Status = gBS->InstallMultipleProtocolInterfaces (&(mGpioInstance->Handle),
> + &gMarvellGpioProtocolGuid,
> + &(mGpioInstance->GpioProtocol),
> + &gEfiDevicePathProtocolGuid,
> + (EFI_DEVICE_PATH_PROTOCOL *)GpioDevicePath,
> + NULL);
> + if (EFI_ERROR (Status)) {
> + goto ErrLocateBoardDesc;
> + }
> +
> + return EFI_SUCCESS;
> +
> +ErrLocateBoardDesc:
> + gBS->FreePool (mGpioInstance);
> +
> +ErrGpioInstanceAlloc:
> + gBS->FreePool (GpioDevicePath);
> +
> + return Status;
> +}
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver
2018-12-04 16:37 ` Leif Lindholm
@ 2018-12-04 16:40 ` Ard Biesheuvel
2018-12-04 17:19 ` Leif Lindholm
0 siblings, 1 reply; 35+ messages in thread
From: Ard Biesheuvel @ 2018-12-04 16:40 UTC (permalink / raw)
To: Leif Lindholm
Cc: Marcin Wojtas, edk2-devel@lists.01.org, Nadav Haklai,
Jan Dąbroś, Grzegorz Jaszczyk, Kostya Porotchkin,
Hua Jing
On Tue, 4 Dec 2018 at 17:37, Leif Lindholm <leif.lindholm@linaro.org> wrote:
>
> On Sat, Oct 20, 2018 at 03:57:37AM +0200, Marcin Wojtas wrote:
> > From: jinghua <jinghua@marvell.com>
> >
> > Marvell Armada 7k/8k SoCs comprise integrated GPIO controllers,
> > one in AP and two in each possible CP hardware blocks.
> >
> > This patch introduces support for them, which is a producer of
> > MARVELL_GPIO_PROTOCOL, which add necessary routines.
> > Hardware description of the controllers is placed in MvHwDescLib.c,
> > same as other devices.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> > ---
> > Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf | 43 +++
> > Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h | 52 ++++
> > Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c | 298 ++++++++++++++++++++
> > 3 files changed, 393 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..2d56433
> > --- /dev/null
> > +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.inf
> > @@ -0,0 +1,43 @@
> > +## @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]
> > + MdeModulePkg/MdeModulePkg.dec
> > + MdePkg/MdePkg.dec
> > + Silicon/Marvell/Marvell.dec
> > +
> > +[LibraryClasses]
> > + ArmadaSoCDescLib
> > + DebugLib
> > + MemoryAllocationLib
> > + UefiDriverEntryPoint
> > + UefiLib
> > +
> > +[Protocols]
> > + gMarvellBoardDescProtocolGuid
> > + gMarvellGpioProtocolGuid
> > +
> > +[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..48744dc
> > --- /dev/null
> > +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.h
> > @@ -0,0 +1,52 @@
> > +/**
> > +*
> > +* 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 GPIO_SIGNATURE SIGNATURE_32 ('G', 'P', 'I', 'O')
>
> Needs more MV.
>
> > +
> > +#ifndef BIT
> > +#define BIT(nr) (1 << (nr))
> > +#endif
>
> OK, you are using this with non-constants.
> But please drop the #ifndef and submit a patch to add a BIT macro to
> MdePkg/Include/Base.h. (And drop this if you get it accepted :)
>
> > +
> > +// Marvell GPIO Controller Registers
> > +#define GPIO_DATA_OUT_REG (0x0)
> > +#define GPIO_OUT_EN_REG (0x4)
> > +#define GPIO_BLINK_EN_REG (0x8)
> > +#define GPIO_DATA_IN_POL_REG (0xc)
> > +#define GPIO_DATA_IN_REG (0x10)
>
> Needs more MV.
>
> > +
> > +typedef struct {
> > + MARVELL_GPIO_PROTOCOL GpioProtocol;
> > + MV_BOARD_GPIO_DESC *Desc;
> > + UINTN Signature;
> > + EFI_HANDLE Handle;
> > +} MV_GPIO;
> > +
> > +#endif // __MV_GPIO_H__
> > diff --git a/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
> > new file mode 100644
> > index 0000000..fc2d416
> > --- /dev/null
> > +++ b/Silicon/Marvell/Drivers/Gpio/MvGpioDxe/MvGpioDxe.c
> > @@ -0,0 +1,298 @@
> > +/**
> > +*
> > +* 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 mGpioDevicePathTemplate = {
>
> (Again, not used outside this file, doesn't really need the Gpio bit
> in the name. Up to you.)
>
> > + {
> > + {
> > + HARDWARE_DEVICE_PATH,
> > + HW_VENDOR_DP,
> > + {
> > + (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
> > + sizeof (MARVELL_GPIO_DRIVER_TYPE)),
> > + (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
> > + sizeof (MARVELL_GPIO_DRIVER_TYPE)) >> 8),
> > + },
> > + },
> > + EFI_CALLER_ID_GUID
> > + },
> > + GPIO_DRIVER_TYPE_SOC_CONTROLLER,
> > + {
> > + END_DEVICE_PATH_TYPE,
> > + END_ENTIRE_DEVICE_PATH_SUBTYPE,
> > + {
> > + sizeof(EFI_DEVICE_PATH_PROTOCOL),
> > + 0
> > + }
> > + }
> > +};
> > +
> > +STATIC
> > +EFI_STATUS
> > +MvGpioValidate (
> > + IN UINTN ControllerIndex,
> > + IN UINTN GpioPin
> > + )
> > +{
>
> Please add a comment header for this function explaining what it does.
> (I will start becoming more strict on this in general, but I know I've
> been lax in the past, so I'll ease into it.)
>
> > + if (ControllerIndex >= mGpioInstance->Desc->GpioDevCount) {
> > + DEBUG ((DEBUG_ERROR,
> > + "%a: Invalid GPIO ControllerIndex: %d\n",
> > + __FUNCTION__,
> > + ControllerIndex));
> > + return EFI_INVALID_PARAMETER;
> > + }
> > +
> > + if (GpioPin >= mGpioInstance->Desc->SoC[ControllerIndex].GpioPinCount) {
> > + DEBUG ((DEBUG_ERROR,
> > + "%a: GPIO pin #%d not available in Controller#%d\n",
> > + __FUNCTION__,
> > + GpioPin,
> > + ControllerIndex));
> > + return EFI_INVALID_PARAMETER;
> > + }
> > +
> > + return EFI_SUCCESS;
> > +}
> > +
> > +STATIC
> > +EFI_STATUS
> > +MvGpioDirectionOutput (
> > + IN MARVELL_GPIO_PROTOCOL *This,
> > + IN UINTN ControllerIndex,
> > + IN UINTN GpioPin,
> > + IN BOOLEAN Value
> > + )
> > +{
> > + UINTN BaseAddress;
> > + EFI_STATUS Status;
> > +
> > + Status = MvGpioValidate (ControllerIndex, GpioPin);
> > + if (EFI_ERROR (Status)) {
> > + DEBUG ((DEBUG_ERROR,
> > + "%a: Fail to set output for pin #%d\n",
> > + __FUNCTION__,
> > + GpioPin));
> > + return Status;
> > + }
>
> So, I'm on the fence here. Do we need to validate that we're not
> trying to write pins that don't exist all the time?
>
> I could see why it may be useful for DEBUG builds and new board
> bringup, but even then - could it be a helper function that is called
> from an ASSERT and only included ifndef MDEPKG_NDEBUG?
>
> > +
> > + BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
> > +
> > + MmioAndThenOr32 (BaseAddress + GPIO_DATA_OUT_REG,
> > + ~BIT (GpioPin),
> > + (Value) << GpioPin);
>
> Would be cleaner to have a BITPOSITION macro to match the BIT one.
>
> > +
> > + MmioAnd32 (BaseAddress + GPIO_OUT_EN_REG, ~BIT (GpioPin));
> > +
> > + return EFI_SUCCESS;
> > +}
> > +
> > +STATIC
> > +EFI_STATUS
> > +MvGpioDirectionInput (
> > + IN MARVELL_GPIO_PROTOCOL *This,
> > + IN UINTN ControllerIndex,
> > + IN UINTN GpioPin
> > + )
> > +{
> > + UINTN BaseAddress;
> > + EFI_STATUS Status;
> > +
> > + Status = MvGpioValidate (ControllerIndex, GpioPin);
> > + if (EFI_ERROR (Status)) {
> > + DEBUG ((DEBUG_ERROR,
> > + "%a: Fail to set input for pin #%d\n",
> > + __FUNCTION__,
> > + GpioPin));
> > + return Status;
> > + }
> > +
> > + BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
> > +
> > + MmioOr32 (BaseAddress + GPIO_OUT_EN_REG, BIT (GpioPin));
> > +
> > + return EFI_SUCCESS;
> > +}
> > +
> > +STATIC
> > +EFI_STATUS
> > +MvGpioGetFunction (
> > + IN MARVELL_GPIO_PROTOCOL *This,
> > + IN UINTN ControllerIndex,
> > + IN UINTN GpioPin,
> > + OUT MARVELL_GPIO_MODE *Mode
> > + )
> > +{
> > + UINT32 RegVal;
> > + UINTN BaseAddress;
> > + EFI_STATUS Status;
> > +
> > + Status = MvGpioValidate (ControllerIndex, GpioPin);
> > + if (EFI_ERROR (Status)) {
> > + DEBUG ((DEBUG_ERROR,
> > + "%a: Fail to get function of pin #%d\n",
> > + __FUNCTION__,
> > + GpioPin));
> > + return Status;
> > + }
> > +
> > + BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
> > +
> > + RegVal = MmioRead32 (BaseAddress + GPIO_OUT_EN_REG);
> > + *Mode = ((RegVal & BIT (GpioPin)) ? GPIO_MODE_INPUT : GPIO_MODE_OUTPUT);
>
> Not a fan of this. This is abusing the fact that the programmer knows
> the numeric values of the enum members. At which point, why not nuke
> the ternary overhead and go
> *Mode = (RegVal & BIT (GpioPin)) >> BIT (GpioPin);
> ?
>
> An alternative interpretation is that the enum is the software view
> only, and that the bit meaning is hardware dependent. In that case, we
> additionally need a #define for that.
>
> > +
> > + return EFI_SUCCESS;
> > +}
> > +
> > +STATIC
> > +EFI_STATUS
> > +MvGpioGetValue (
> > + IN MARVELL_GPIO_PROTOCOL *This,
> > + IN UINTN ControllerIndex,
> > + IN UINTN GpioPin,
> > + IN OUT BOOLEAN *Value
> > + )
> > +{
> > + UINTN BaseAddress;
> > + EFI_STATUS Status;
> > +
> > + Status = MvGpioValidate (ControllerIndex, GpioPin);
> > + if (EFI_ERROR (Status)) {
> > + DEBUG ((DEBUG_ERROR,
> > + "%a: Fail to get value of pin #%d\n",
> > + __FUNCTION__,
> > + GpioPin));
> > + return Status;
> > + }
> > +
> > + BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
> > +
> > + *Value = !!(MmioRead32 (BaseAddress + GPIO_DATA_IN_REG) & BIT (GpioPin));
>
> Please don't !!.
> If necessary, please shift.
>
Or cast to (BOOLEAN)
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver
2018-12-04 16:40 ` Ard Biesheuvel
@ 2018-12-04 17:19 ` Leif Lindholm
2018-12-04 17:20 ` Ard Biesheuvel
0 siblings, 1 reply; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 17:19 UTC (permalink / raw)
To: Ard Biesheuvel
Cc: Marcin Wojtas, edk2-devel@lists.01.org, Nadav Haklai,
Jan Dąbroś, Grzegorz Jaszczyk, Kostya Porotchkin,
Hua Jing
On Tue, Dec 04, 2018 at 05:40:14PM +0100, Ard Biesheuvel wrote:
> > > +STATIC
> > > +EFI_STATUS
> > > +MvGpioGetValue (
> > > + IN MARVELL_GPIO_PROTOCOL *This,
> > > + IN UINTN ControllerIndex,
> > > + IN UINTN GpioPin,
> > > + IN OUT BOOLEAN *Value
> > > + )
> > > +{
> > > + UINTN BaseAddress;
> > > + EFI_STATUS Status;
> > > +
> > > + Status = MvGpioValidate (ControllerIndex, GpioPin);
> > > + if (EFI_ERROR (Status)) {
> > > + DEBUG ((DEBUG_ERROR,
> > > + "%a: Fail to get value of pin #%d\n",
> > > + __FUNCTION__,
> > > + GpioPin));
> > > + return Status;
> > > + }
> > > +
> > > + BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
> > > +
> > > + *Value = !!(MmioRead32 (BaseAddress + GPIO_DATA_IN_REG) & BIT (GpioPin));
> >
> > Please don't !!.
> > If necessary, please shift.
>
> Or cast to (BOOLEAN)
Would be ideal if BOOLEAN wasn't just a typedef for unsigned char :/
/
Leif
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver
2018-12-04 17:19 ` Leif Lindholm
@ 2018-12-04 17:20 ` Ard Biesheuvel
0 siblings, 0 replies; 35+ messages in thread
From: Ard Biesheuvel @ 2018-12-04 17:20 UTC (permalink / raw)
To: Leif Lindholm
Cc: Marcin Wojtas, edk2-devel@lists.01.org, Nadav Haklai,
Jan Dąbroś, Grzegorz Jaszczyk, Kostya Porotchkin,
Hua Jing
On Tue, 4 Dec 2018 at 18:19, Leif Lindholm <leif.lindholm@linaro.org> wrote:
>
> On Tue, Dec 04, 2018 at 05:40:14PM +0100, Ard Biesheuvel wrote:
> > > > +STATIC
> > > > +EFI_STATUS
> > > > +MvGpioGetValue (
> > > > + IN MARVELL_GPIO_PROTOCOL *This,
> > > > + IN UINTN ControllerIndex,
> > > > + IN UINTN GpioPin,
> > > > + IN OUT BOOLEAN *Value
> > > > + )
> > > > +{
> > > > + UINTN BaseAddress;
> > > > + EFI_STATUS Status;
> > > > +
> > > > + Status = MvGpioValidate (ControllerIndex, GpioPin);
> > > > + if (EFI_ERROR (Status)) {
> > > > + DEBUG ((DEBUG_ERROR,
> > > > + "%a: Fail to get value of pin #%d\n",
> > > > + __FUNCTION__,
> > > > + GpioPin));
> > > > + return Status;
> > > > + }
> > > > +
> > > > + BaseAddress = mGpioInstance->Desc->SoC[ControllerIndex].GpioBaseAddress;
> > > > +
> > > > + *Value = !!(MmioRead32 (BaseAddress + GPIO_DATA_IN_REG) & BIT (GpioPin));
> > >
> > > Please don't !!.
> > > If necessary, please shift.
> >
> > Or cast to (BOOLEAN)
>
> Would be ideal if BOOLEAN wasn't just a typedef for unsigned char :/
>
Ugh.
^ permalink raw reply [flat|nested] 35+ messages in thread
* [platforms: PATCH 09/12] Marvell/Drivers: I2c: Use common header for macros
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
` (7 preceding siblings ...)
2018-10-20 1:57 ` [platforms: PATCH 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-12-04 16:38 ` Leif Lindholm
2018-10-20 1:57 ` [platforms: PATCH 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce I2C GPIO driver Marcin Wojtas
` (2 subsequent siblings)
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 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>
---
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 f43e411..a390f23 100644
--- a/Silicon/Marvell/Applications/EepromCmd/EepromCmd.c
+++ b/Silicon/Marvell/Applications/EepromCmd/EepromCmd.c
@@ -52,10 +52,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] 35+ messages in thread
* Re: [platforms: PATCH 09/12] Marvell/Drivers: I2c: Use common header for macros
2018-10-20 1:57 ` [platforms: PATCH 09/12] Marvell/Drivers: I2c: Use common header for macros Marcin Wojtas
@ 2018-12-04 16:38 ` Leif Lindholm
0 siblings, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 16:38 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap
On Sat, Oct 20, 2018 at 03:57:38AM +0200, Marcin Wojtas wrote:
> 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 f43e411..a390f23 100644
> --- a/Silicon/Marvell/Applications/EepromCmd/EepromCmd.c
> +++ b/Silicon/Marvell/Applications/EepromCmd/EepromCmd.c
> @@ -52,10 +52,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 [flat|nested] 35+ messages in thread
* [platforms: PATCH 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce I2C GPIO driver
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
` (8 preceding siblings ...)
2018-10-20 1:57 ` [platforms: PATCH 09/12] Marvell/Drivers: I2c: Use common header for macros Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-12-04 17:02 ` Leif Lindholm
2018-10-20 1:57 ` [platforms: PATCH 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation Marcin Wojtas
2018-10-20 1:57 ` [platforms: PATCH 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines Marcin Wojtas
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 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 PCA95xxx I2C IO expander family,
which is a producer of MARVELL_GPIO_PROTOCOL, by implementing
necessary routines.
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 | 44 ++
Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h | 74 +++
Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c | 592 ++++++++++++++++++++
3 files changed, 710 insertions(+)
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..3066732
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.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 = 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]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+ DebugLib
+ MemoryAllocationLib
+ UefiDriverEntryPoint
+ UefiLib
+
+[Protocols]
+ gEfiDriverBindingProtocolGuid
+ gEfiI2cIoProtocolGuid
+ gMarvellBoardDescProtocolGuid
+ gMarvellGpioProtocolGuid
+
+[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..43daee0
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
@@ -0,0 +1,74 @@
+/**
+*
+* 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')
+
+#ifndef BIT
+#define BIT(nr) (1 << (nr))
+#endif
+
+#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 enum {
+ PCA95XX_READ,
+ PCA95XX_WRITE,
+} PCA95XX_OPERATION;
+
+typedef struct {
+ MARVELL_GPIO_PROTOCOL GpioProtocol;
+ MV_I2C_IO_EXPANDER_DESC *ControllerDesc;
+ UINTN ControllerCount;
+ UINTN Signature;
+ EFI_HANDLE ControllerHandle;
+} PCA95XX;
+
+#endif
diff --git a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
new file mode 100644
index 0000000..f4a474e
--- /dev/null
+++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
@@ -0,0 +1,592 @@
+/**
+*
+* 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 mPca95xxDevicePathTemplate = {
+ {
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ {
+ (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
+ sizeof (MARVELL_GPIO_DRIVER_TYPE)),
+ (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
+ sizeof (MARVELL_GPIO_DRIVER_TYPE)) >> 8),
+ },
+ },
+ EFI_CALLER_ID_GUID
+ },
+ 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,
+};
+
+STATIC
+EFI_STATUS
+MvPca95xxValidate (
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin
+ )
+{
+ UINTN ControllerId;
+
+ if (ControllerIndex >= mPca95xxInstance->ControllerCount) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Invalid GPIO ControllerIndex: %d\n",
+ __FUNCTION__,
+ ControllerIndex));
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ControllerId = mPca95xxInstance->ControllerDesc[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;
+}
+
+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->ControllerDesc[ControllerIndex].I2cBus;
+ I2cAddress = mPca95xxInstance->ControllerDesc[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 PCA95XX_OPERATION Operation
+ )
+{
+ 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 = (Operation == PCA95XX_READ ?
+ I2C_FLAG_READ : I2C_FLAG_NORESTART);
+
+ 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, PCA95XX_READ);
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxWriteRegs (
+ IN EFI_I2C_IO_PROTOCOL *I2cIo,
+ IN UINTN Reg,
+ IN UINT8 RegVal
+ )
+{
+ return MvPca95xxI2cTransfer (I2cIo, Reg, &RegVal, PCA95XX_WRITE);
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxSetOutputValue (
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ IN BOOLEAN Value
+ )
+{
+ 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 (Value) {
+ RegVal |= BIT (GpioPin % PCA95XX_BANK_SIZE);
+ } else {
+ RegVal &= ~BIT (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 MARVELL_GPIO_MODE Direction
+ )
+{
+ 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 (Direction == GPIO_MODE_INPUT) {
+ RegVal |= BIT (GpioPin % PCA95XX_BANK_SIZE);
+ } else {
+ RegVal &= ~BIT (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
+MvPca95xxIsOutput (
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ OUT MARVELL_GPIO_MODE *Mode
+ )
+{
+ EFI_I2C_IO_PROTOCOL *I2cIo;
+ EFI_STATUS Status;
+ UINT8 RegVal;
+ UINTN Bank;
+
+ Status = MvPca95xxValidate (ControllerIndex, GpioPin);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: invalid pin/controller data\n",
+ __FUNCTION__,
+ GpioPin));
+ return Status;
+ }
+
+ 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;
+ }
+
+ *Mode = ((RegVal & BIT (GpioPin % PCA95XX_BANK_SIZE)) ?
+ GPIO_MODE_INPUT : GPIO_MODE_OUTPUT);
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxDirectionOutput (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ IN BOOLEAN Value
+ )
+{
+ EFI_STATUS Status;
+
+ Status = MvPca95xxValidate (ControllerIndex, GpioPin);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: invalid pin/controller data\n",
+ __FUNCTION__,
+ GpioPin));
+ return Status;
+ }
+
+ /* Configure output value. */
+ Status = MvPca95xxSetOutputValue (ControllerIndex, GpioPin, Value);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: fail to set ouput value\n", __FUNCTION__));
+ return EFI_DEVICE_ERROR;
+ }
+
+ /* Configure direction as output. */
+ Status = MvPca95xxSetDirection (ControllerIndex, GpioPin, GPIO_MODE_OUTPUT);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: fail to set direction\n", __FUNCTION__));
+ }
+
+ return Status;
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxDirectionInput (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin
+ )
+{
+ EFI_STATUS Status;
+
+ Status = MvPca95xxValidate (ControllerIndex, GpioPin);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: invalid pin/controller data\n",
+ __FUNCTION__,
+ GpioPin));
+ return Status;
+ }
+
+ /* Configure direction as input. */
+ Status = MvPca95xxSetDirection (ControllerIndex, GpioPin, GPIO_MODE_INPUT);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: fail to set direction\n", __FUNCTION__));
+ }
+
+ return Status;
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxGetFunction (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ OUT MARVELL_GPIO_MODE *Mode
+ )
+{
+ EFI_STATUS Status;
+
+ Status = MvPca95xxValidate (ControllerIndex, GpioPin);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: invalid pin/controller data\n",
+ __FUNCTION__,
+ GpioPin));
+ return Status;
+ }
+
+ Status = MvPca95xxIsOutput (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;
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxGetValue (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ IN OUT BOOLEAN *Value
+ )
+{
+ EFI_I2C_IO_PROTOCOL *I2cIo;
+ EFI_STATUS Status;
+ UINT8 RegVal;
+ UINTN Bank;
+
+ Status = MvPca95xxValidate (ControllerIndex, GpioPin);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: invalid pin/controller data\n",
+ __FUNCTION__,
+ GpioPin));
+ return Status;
+ }
+
+ 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;
+ }
+
+ *Value = !!(RegVal & BIT (GpioPin % PCA95XX_BANK_SIZE));
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+MvPca95xxSetValue (
+ IN MARVELL_GPIO_PROTOCOL *This,
+ IN UINTN ControllerIndex,
+ IN UINTN GpioPin,
+ IN BOOLEAN Value
+ )
+{
+ EFI_STATUS Status;
+
+ Status = MvPca95xxValidate (ControllerIndex, GpioPin);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: invalid pin/controller data\n",
+ __FUNCTION__,
+ GpioPin));
+ return Status;
+ }
+
+ Status = MvPca95xxSetOutputValue (ControllerIndex, GpioPin, Value);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: fail to set ouput value\n", __FUNCTION__));
+ }
+
+ return Status;
+}
+
+
+STATIC
+VOID
+MvPca95xxInitProtocol (
+ IN MARVELL_GPIO_PROTOCOL *GpioProtocol
+ )
+{
+ GpioProtocol->DirectionInput = MvPca95xxDirectionInput;
+ GpioProtocol->DirectionOutput = MvPca95xxDirectionOutput;
+ GpioProtocol->GetFunction = MvPca95xxGetFunction;
+ GpioProtocol->GetValue = MvPca95xxGetValue;
+ GpioProtocol->SetValue = MvPca95xxSetValue;
+}
+
+EFI_STATUS
+EFIAPI
+MvPca95xxEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ MARVELL_BOARD_DESC_PROTOCOL *BoardDescProtocol;
+ MV_GPIO_DEVICE_PATH *Pca95xxDevicePath;
+ MV_BOARD_GPIO_DESC *GpioDesc;
+ EFI_STATUS Status;
+
+ /* Obtain list of available controllers */
+ Status = gBS->LocateProtocol (&gMarvellBoardDescProtocolGuid,
+ NULL,
+ (VOID **)&BoardDescProtocol);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Cannot locate BoardDesc protocol\n",
+ __FUNCTION__));
+ return Status;
+ }
+
+ Status = BoardDescProtocol->BoardDescGpioGet (BoardDescProtocol, &GpioDesc);
+ if (EFI_ERROR (Status) || !GpioDesc->I2cIoExpanderDesc) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
+ __FUNCTION__));
+ return Status;
+ } else if (!GpioDesc->I2cIoExpanderDesc) {
+ /* Silently exit, if the board does not support the controllers */
+ return EFI_SUCCESS;
+ }
+
+ Pca95xxDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
+ &mPca95xxDevicePathTemplate);
+ if (Pca95xxDevicePath == NULL) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Fail to allocate Pca95xxDevicePath\n",
+ __FUNCTION__));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ mPca95xxInstance = AllocateZeroPool (sizeof (PCA95XX));
+ if (mPca95xxInstance == NULL) {
+ DEBUG ((DEBUG_ERROR,
+ "%a: Fail to allocate mPca95xxInstance\n",
+ __FUNCTION__));
+ goto ErrPca95xxInstanceAlloc;
+ }
+
+ MvPca95xxInitProtocol (&mPca95xxInstance->GpioProtocol);
+
+ mPca95xxInstance->Signature = PCA95XX_GPIO_SIGNATURE;
+ mPca95xxInstance->ControllerDesc = GpioDesc->I2cIoExpanderDesc;
+ mPca95xxInstance->ControllerCount = GpioDesc->I2cIoExpanderCount;
+
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &(mPca95xxInstance->ControllerHandle),
+ &gMarvellGpioProtocolGuid,
+ &(mPca95xxInstance->GpioProtocol),
+ &gEfiDevicePathProtocolGuid,
+ (EFI_DEVICE_PATH_PROTOCOL *)Pca95xxDevicePath,
+ NULL);
+ if (EFI_ERROR (Status)) {
+ goto ErrLocateBoardDesc;
+ }
+
+ return EFI_SUCCESS;
+
+ErrLocateBoardDesc:
+ gBS->FreePool (mPca95xxInstance);
+
+ErrPca95xxInstanceAlloc:
+ gBS->FreePool (Pca95xxDevicePath);
+
+ return Status;
+}
--
2.7.4
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce I2C GPIO driver
2018-10-20 1:57 ` [platforms: PATCH 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce I2C GPIO driver Marcin Wojtas
@ 2018-12-04 17:02 ` Leif Lindholm
0 siblings, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 17:02 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap
On Sat, Oct 20, 2018 at 03:57:39AM +0200, Marcin Wojtas wrote:
> Marvell Armada 7k/8k-based platforms may use Pca95xx to extend
> amount of the GPIO pins.
>
> This patch introduces support for PCA95xxx I2C IO expander family,
> which is a producer of MARVELL_GPIO_PROTOCOL, by implementing
> necessary routines.
>
> Driver is based on initial work done by Allen Yan <yanwei@marvell.com>.
Yeah, this is the patch I would also like to add the enums and enum
values previously mentioned.
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
> Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.inf | 44 ++
> Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h | 74 +++
> Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c | 592 ++++++++++++++++++++
> 3 files changed, 710 insertions(+)
> 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..3066732
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.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 = 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]
> + MdeModulePkg/MdeModulePkg.dec
> + MdePkg/MdePkg.dec
> + Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> + DebugLib
> + MemoryAllocationLib
> + UefiDriverEntryPoint
> + UefiLib
> +
> +[Protocols]
> + gEfiDriverBindingProtocolGuid
> + gEfiI2cIoProtocolGuid
> + gMarvellBoardDescProtocolGuid
> + gMarvellGpioProtocolGuid
> +
> +[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..43daee0
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.h
> @@ -0,0 +1,74 @@
> +/**
> +*
> +* 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')
> +
> +#ifndef BIT
> +#define BIT(nr) (1 << (nr))
> +#endif
Eew, now we're adding it again, in yet another file.
Same comment as (patch - 2) (I think). Consider trying to add this
macro (and a BITPOS one) to Base.h.
The alternative is just inlining the shifts. It's basic C and doesn't
confuse things.
> +
> +#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 enum {
> + PCA95XX_READ,
> + PCA95XX_WRITE,
> +} PCA95XX_OPERATION;
So, the only use I see of this is where it is used to in turn select
between I2C_FLAG_READ and I2C_FLAG_NORESTART. Can we instead use
these directly in MvPca95xxReadRegs/MvPca95xxWriteRegs?
> +
> +typedef struct {
> + MARVELL_GPIO_PROTOCOL GpioProtocol;
> + MV_I2C_IO_EXPANDER_DESC *ControllerDesc;
> + UINTN ControllerCount;
> + UINTN Signature;
> + EFI_HANDLE ControllerHandle;
> +} PCA95XX;
> +
> +#endif
> diff --git a/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
> new file mode 100644
> index 0000000..f4a474e
> --- /dev/null
> +++ b/Silicon/Marvell/Drivers/Gpio/MvPca95xxDxe/MvPca95xxDxe.c
> @@ -0,0 +1,592 @@
> +/**
> +*
> +* 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 mPca95xxDevicePathTemplate = {
(Again, static, don't specifically need the Pca95xx prefix. But up to
you.)
> + {
> + {
> + HARDWARE_DEVICE_PATH,
> + HW_VENDOR_DP,
> + {
> + (UINT8) (sizeof (VENDOR_DEVICE_PATH) +
> + sizeof (MARVELL_GPIO_DRIVER_TYPE)),
> + (UINT8) ((sizeof (VENDOR_DEVICE_PATH) +
> + sizeof (MARVELL_GPIO_DRIVER_TYPE)) >> 8),
> + },
> + },
> + EFI_CALLER_ID_GUID
> + },
> + 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,
> +};
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxValidate (
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin
> + )
Same comment as previous patch: add description comment.
> +{
> + UINTN ControllerId;
> +
> + if (ControllerIndex >= mPca95xxInstance->ControllerCount) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Invalid GPIO ControllerIndex: %d\n",
> + __FUNCTION__,
> + ControllerIndex));
> + return EFI_INVALID_PARAMETER;
> + }
> +
> + ControllerId = mPca95xxInstance->ControllerDesc[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;
> +}
> +
> +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->ControllerDesc[ControllerIndex].I2cBus;
> + I2cAddress = mPca95xxInstance->ControllerDesc[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 PCA95XX_OPERATION Operation
> + )
> +{
> + 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 = (Operation == PCA95XX_READ ?
> + I2C_FLAG_READ : I2C_FLAG_NORESTART);
> +
> + 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, PCA95XX_READ);
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxWriteRegs (
> + IN EFI_I2C_IO_PROTOCOL *I2cIo,
> + IN UINTN Reg,
> + IN UINT8 RegVal
> + )
> +{
> + return MvPca95xxI2cTransfer (I2cIo, Reg, &RegVal, PCA95XX_WRITE);
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxSetOutputValue (
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + IN BOOLEAN Value
> + )
> +{
> + 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 (Value) {
> + RegVal |= BIT (GpioPin % PCA95XX_BANK_SIZE);
> + } else {
> + RegVal &= ~BIT (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 MARVELL_GPIO_MODE Direction
> + )
> +{
> + 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 (Direction == GPIO_MODE_INPUT) {
> + RegVal |= BIT (GpioPin % PCA95XX_BANK_SIZE);
> + } else {
> + RegVal &= ~BIT (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
> +MvPca95xxIsOutput (
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + OUT MARVELL_GPIO_MODE *Mode
> + )
> +{
> + EFI_I2C_IO_PROTOCOL *I2cIo;
> + EFI_STATUS Status;
> + UINT8 RegVal;
> + UINTN Bank;
> +
> + Status = MvPca95xxValidate (ControllerIndex, GpioPin);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: invalid pin/controller data\n",
> + __FUNCTION__,
> + GpioPin));
> + return Status;
> + }
Same comment as previous patch: could this be a helper function called
from an assert instead? (Applies to identical snippets below too.)
> +
> + 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;
> + }
> +
> + *Mode = ((RegVal & BIT (GpioPin % PCA95XX_BANK_SIZE)) ?
> + GPIO_MODE_INPUT : GPIO_MODE_OUTPUT);
Really same comment as before. If the GPIO_MODE_* values are not
meant to reflect the hardware state, we need #defines to do that. And
neither way does the ternary make things better.
> +
> + return EFI_SUCCESS;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxDirectionOutput (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + IN BOOLEAN Value
> + )
> +{
> + EFI_STATUS Status;
> +
> + Status = MvPca95xxValidate (ControllerIndex, GpioPin);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: invalid pin/controller data\n",
> + __FUNCTION__,
> + GpioPin));
> + return Status;
> + }
> +
> + /* Configure output value. */
> + Status = MvPca95xxSetOutputValue (ControllerIndex, GpioPin, Value);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "%a: fail to set ouput value\n", __FUNCTION__));
> + return EFI_DEVICE_ERROR;
> + }
> +
> + /* Configure direction as output. */
> + Status = MvPca95xxSetDirection (ControllerIndex, GpioPin, GPIO_MODE_OUTPUT);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "%a: fail to set direction\n", __FUNCTION__));
> + }
> +
> + return Status;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxDirectionInput (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin
> + )
> +{
> + EFI_STATUS Status;
> +
> + Status = MvPca95xxValidate (ControllerIndex, GpioPin);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: invalid pin/controller data\n",
> + __FUNCTION__,
> + GpioPin));
> + return Status;
> + }
> +
> + /* Configure direction as input. */
> + Status = MvPca95xxSetDirection (ControllerIndex, GpioPin, GPIO_MODE_INPUT);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "%a: fail to set direction\n", __FUNCTION__));
> + }
> +
> + return Status;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxGetFunction (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + OUT MARVELL_GPIO_MODE *Mode
> + )
> +{
> + EFI_STATUS Status;
> +
> + Status = MvPca95xxValidate (ControllerIndex, GpioPin);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: invalid pin/controller data\n",
> + __FUNCTION__,
> + GpioPin));
> + return Status;
> + }
> +
> + Status = MvPca95xxIsOutput (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;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxGetValue (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + IN OUT BOOLEAN *Value
> + )
> +{
> + EFI_I2C_IO_PROTOCOL *I2cIo;
> + EFI_STATUS Status;
> + UINT8 RegVal;
> + UINTN Bank;
> +
> + Status = MvPca95xxValidate (ControllerIndex, GpioPin);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: invalid pin/controller data\n",
> + __FUNCTION__,
> + GpioPin));
> + return Status;
> + }
> +
> + 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;
> + }
> +
> + *Value = !!(RegVal & BIT (GpioPin % PCA95XX_BANK_SIZE));
!!!
Shift if necessary.
/
Leif
> +
> + return EFI_SUCCESS;
> +}
> +
> +STATIC
> +EFI_STATUS
> +MvPca95xxSetValue (
> + IN MARVELL_GPIO_PROTOCOL *This,
> + IN UINTN ControllerIndex,
> + IN UINTN GpioPin,
> + IN BOOLEAN Value
> + )
> +{
> + EFI_STATUS Status;
> +
> + Status = MvPca95xxValidate (ControllerIndex, GpioPin);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: invalid pin/controller data\n",
> + __FUNCTION__,
> + GpioPin));
> + return Status;
> + }
> +
> + Status = MvPca95xxSetOutputValue (ControllerIndex, GpioPin, Value);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "%a: fail to set ouput value\n", __FUNCTION__));
> + }
> +
> + return Status;
> +}
> +
> +
> +STATIC
> +VOID
> +MvPca95xxInitProtocol (
> + IN MARVELL_GPIO_PROTOCOL *GpioProtocol
> + )
> +{
> + GpioProtocol->DirectionInput = MvPca95xxDirectionInput;
> + GpioProtocol->DirectionOutput = MvPca95xxDirectionOutput;
> + GpioProtocol->GetFunction = MvPca95xxGetFunction;
> + GpioProtocol->GetValue = MvPca95xxGetValue;
> + GpioProtocol->SetValue = MvPca95xxSetValue;
> +}
> +
> +EFI_STATUS
> +EFIAPI
> +MvPca95xxEntryPoint (
> + IN EFI_HANDLE ImageHandle,
> + IN EFI_SYSTEM_TABLE *SystemTable
> + )
> +{
> + MARVELL_BOARD_DESC_PROTOCOL *BoardDescProtocol;
> + MV_GPIO_DEVICE_PATH *Pca95xxDevicePath;
> + MV_BOARD_GPIO_DESC *GpioDesc;
> + EFI_STATUS Status;
> +
> + /* Obtain list of available controllers */
> + Status = gBS->LocateProtocol (&gMarvellBoardDescProtocolGuid,
> + NULL,
> + (VOID **)&BoardDescProtocol);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Cannot locate BoardDesc protocol\n",
> + __FUNCTION__));
> + return Status;
> + }
> +
> + Status = BoardDescProtocol->BoardDescGpioGet (BoardDescProtocol, &GpioDesc);
> + if (EFI_ERROR (Status) || !GpioDesc->I2cIoExpanderDesc) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Cannot get GPIO board desc from BoardDesc protocol\n",
> + __FUNCTION__));
> + return Status;
> + } else if (!GpioDesc->I2cIoExpanderDesc) {
> + /* Silently exit, if the board does not support the controllers */
> + return EFI_SUCCESS;
> + }
> +
> + Pca95xxDevicePath = AllocateCopyPool (sizeof (MV_GPIO_DEVICE_PATH),
> + &mPca95xxDevicePathTemplate);
> + if (Pca95xxDevicePath == NULL) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Fail to allocate Pca95xxDevicePath\n",
> + __FUNCTION__));
> + return EFI_OUT_OF_RESOURCES;
> + }
> +
> + mPca95xxInstance = AllocateZeroPool (sizeof (PCA95XX));
> + if (mPca95xxInstance == NULL) {
> + DEBUG ((DEBUG_ERROR,
> + "%a: Fail to allocate mPca95xxInstance\n",
> + __FUNCTION__));
> + goto ErrPca95xxInstanceAlloc;
> + }
> +
> + MvPca95xxInitProtocol (&mPca95xxInstance->GpioProtocol);
> +
> + mPca95xxInstance->Signature = PCA95XX_GPIO_SIGNATURE;
> + mPca95xxInstance->ControllerDesc = GpioDesc->I2cIoExpanderDesc;
> + mPca95xxInstance->ControllerCount = GpioDesc->I2cIoExpanderCount;
> +
> + Status = gBS->InstallMultipleProtocolInterfaces (
> + &(mPca95xxInstance->ControllerHandle),
> + &gMarvellGpioProtocolGuid,
> + &(mPca95xxInstance->GpioProtocol),
> + &gEfiDevicePathProtocolGuid,
> + (EFI_DEVICE_PATH_PROTOCOL *)Pca95xxDevicePath,
> + NULL);
> + if (EFI_ERROR (Status)) {
> + goto ErrLocateBoardDesc;
> + }
> +
> + return EFI_SUCCESS;
> +
> +ErrLocateBoardDesc:
> + gBS->FreePool (mPca95xxInstance);
> +
> +ErrPca95xxInstanceAlloc:
> + gBS->FreePool (Pca95xxDevicePath);
> +
> + return Status;
> +}
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [platforms: PATCH 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
` (9 preceding siblings ...)
2018-10-20 1:57 ` [platforms: PATCH 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce I2C GPIO driver Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-12-04 17:06 ` Leif Lindholm
2018-10-20 1:57 ` [platforms: PATCH 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines Marcin Wojtas
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 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>
---
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 d4c67a2..62a46a6 100644
--- a/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
+++ b/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
@@ -456,6 +456,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] 35+ messages in thread
* Re: [platforms: PATCH 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation
2018-10-20 1:57 ` [platforms: PATCH 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation Marcin Wojtas
@ 2018-12-04 17:06 ` Leif Lindholm
0 siblings, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 17:06 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap
On Sat, Oct 20, 2018 at 03:57:40AM +0200, Marcin Wojtas wrote:
> 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 d4c67a2..62a46a6 100644
> --- a/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
> +++ b/Silicon/Marvell/Armada7k8k/Armada7k8k.dsc.inc
> @@ -456,6 +456,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 [flat|nested] 35+ messages in thread
* [platforms: PATCH 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines
2018-10-20 1:57 [platforms: PATCH 00/12] Armada7k8k GPIO support Marcin Wojtas
` (10 preceding siblings ...)
2018-10-20 1:57 ` [platforms: PATCH 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation Marcin Wojtas
@ 2018-10-20 1:57 ` Marcin Wojtas
2018-12-04 17:16 ` Leif Lindholm
11 siblings, 1 reply; 35+ messages in thread
From: Marcin Wojtas @ 2018-10-20 1:57 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 (i.e., enabling VBUS gpios for USB), introduce
a NonDiscoverableInitLib for use by the NonDiscoverable code, for which
each platform can supply its own version.
Add 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 | 47 ++++++++
Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf | 48 +++++++++
Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf | 48 +++++++++
Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf | 1 +
Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h | 28 +++++
Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c | 99 +++++++++++++++++
Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c | 113 ++++++++++++++++++++
Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c | 73 +++++++++++++
Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c | 7 +-
13 files changed, 471 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 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 7e1c37a..20a32ef 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..bbe7ff8
--- /dev/null
+++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
@@ -0,0 +1,47 @@
+## @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]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+ DebugLib
+ IoLib
+
+[Protocols]
+ gMarvellGpioProtocolGuid
+
+[Depex]
+ gMarvellPlatformInitCompleteProtocolGuid
diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
new file mode 100644
index 0000000..00b5ed5
--- /dev/null
+++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
@@ -0,0 +1,48 @@
+## @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]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+ DebugLib
+ IoLib
+
+[Protocols]
+ gMarvellGpioProtocolGuid
+
+[Depex]
+ gMarvellPlatformInitCompleteProtocolGuid
diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
new file mode 100644
index 0000000..66720d2
--- /dev/null
+++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
@@ -0,0 +1,48 @@
+## @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]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ Silicon/Marvell/Marvell.dec
+
+[LibraryClasses]
+ DebugLib
+ IoLib
+
+[Protocols]
+ gMarvellGpioProtocolGuid
+
+[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/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h b/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
new file mode 100644
index 0000000..eaffce3
--- /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
+GetInitializerForType (
+ 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..a93576e
--- /dev/null
+++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
@@ -0,0 +1,99 @@
+/**
+*
+* 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>
+
+#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
+
+STATIC CONST GPIO_PIN_DESC mArmada70x0DbVbusEn[] = {
+ {
+ 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
+Armada70x0DbInitXhciVbus (
+ IN NON_DISCOVERABLE_DEVICE *This
+ )
+{
+ CONST GPIO_PIN_DESC *VbusEnPinDesc;
+ MARVELL_GPIO_PROTOCOL *GpioProtocol;
+ EFI_STATUS Status;
+ UINTN Index;
+
+ Status = MvGpioGetProtocol (GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
+ return Status;
+ }
+
+ VbusEnPinDesc = mArmada70x0DbVbusEn;
+ for (Index = 0; Index < ARRAY_SIZE (mArmada70x0DbVbusEn); Index++) {
+ GpioProtocol->DirectionOutput (GpioProtocol,
+ VbusEnPinDesc->ControllerId,
+ VbusEnPinDesc->PinNumber,
+ VbusEnPinDesc->ActiveHigh);
+ VbusEnPinDesc++;
+ }
+
+ return EFI_SUCCESS;
+}
+
+NON_DISCOVERABLE_DEVICE_INIT
+EFIAPI
+GetInitializerForType (
+ IN NON_DISCOVERABLE_DEVICE_TYPE Type,
+ IN UINTN Index
+ )
+{
+ if (Type == NonDiscoverableDeviceTypeXhci) {
+ return Armada70x0DbInitXhciVbus;
+ }
+
+ return NULL;
+}
diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
new file mode 100644
index 0000000..05f6b89
--- /dev/null
+++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
@@ -0,0 +1,113 @@
+/**
+*
+* 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>
+
+#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
+
+STATIC CONST GPIO_PIN_DESC mArmada80x0DbVbusEn[] = {
+ {
+ 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
+Armada80x0DbInitXhciVbus (
+ IN NON_DISCOVERABLE_DEVICE *This
+ )
+{
+ CONST GPIO_PIN_DESC *VbusEnPinDesc;
+ MARVELL_GPIO_PROTOCOL *GpioProtocol;
+ EFI_STATUS Status;
+ UINTN Index;
+
+ Status = MvGpioGetProtocol (GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
+ return Status;
+ }
+
+ VbusEnPinDesc = mArmada80x0DbVbusEn;
+ for (Index = 0; Index < ARRAY_SIZE (mArmada80x0DbVbusEn); Index++) {
+ GpioProtocol->DirectionOutput (GpioProtocol,
+ VbusEnPinDesc->ControllerId,
+ VbusEnPinDesc->PinNumber,
+ VbusEnPinDesc->ActiveHigh);
+ VbusEnPinDesc++;
+ }
+
+ return EFI_SUCCESS;
+}
+
+NON_DISCOVERABLE_DEVICE_INIT
+EFIAPI
+GetInitializerForType (
+ IN NON_DISCOVERABLE_DEVICE_TYPE Type,
+ IN UINTN Index
+ )
+{
+ if (Type == NonDiscoverableDeviceTypeXhci) {
+ return Armada80x0DbInitXhciVbus;
+ }
+
+ return NULL;
+}
diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
new file mode 100644
index 0000000..764b3b8
--- /dev/null
+++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
@@ -0,0 +1,73 @@
+/**
+*
+* 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>
+
+#define ARMADA_80x0_CP0_CONTROLLER1_INDEX 2
+#define ARMADA_80x0_MCBIN_VBUS0_PIN 15
+
+STATIC CONST GPIO_PIN_DESC mArmada80x0McBinVbusEn = {
+ ARMADA_80x0_CP0_CONTROLLER1_INDEX,
+ ARMADA_80x0_MCBIN_VBUS0_PIN,
+ TRUE,
+};
+
+STATIC
+EFI_STATUS
+EFIAPI
+Armada80x0McBinInitXhciVbus (
+ IN NON_DISCOVERABLE_DEVICE *This
+ )
+{
+ MARVELL_GPIO_PROTOCOL *GpioProtocol;
+ EFI_STATUS Status;
+
+ Status = MvGpioGetProtocol (GPIO_DRIVER_TYPE_SOC_CONTROLLER, &GpioProtocol);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
+ return Status;
+ }
+
+ GpioProtocol->DirectionOutput (GpioProtocol,
+ mArmada80x0McBinVbusEn.ControllerId,
+ mArmada80x0McBinVbusEn.PinNumber,
+ mArmada80x0McBinVbusEn.ActiveHigh);
+
+ return Status;
+}
+
+NON_DISCOVERABLE_DEVICE_INIT
+EFIAPI
+GetInitializerForType (
+ IN NON_DISCOVERABLE_DEVICE_TYPE Type,
+ IN UINTN Index
+ )
+{
+ if (Type == NonDiscoverableDeviceTypeXhci) {
+ return Armada80x0McBinInitXhciVbus;
+ }
+
+ return NULL;
+}
diff --git a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c
index c5cf904..5de9b7b 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,7 @@ NonDiscoverableInitXhci (
Status = RegisterNonDiscoverableMmioDevice (
NonDiscoverableDeviceTypeXhci,
Desc[i].SoC->XhciDmaType,
- NULL,
+ GetInitializerForType (NonDiscoverableDeviceTypeXhci, i),
NULL,
1,
Desc[i].SoC->XhciBaseAddress,
@@ -86,7 +87,7 @@ NonDiscoverableInitAhci (
Status = RegisterNonDiscoverableMmioDevice (
NonDiscoverableDeviceTypeAhci,
Desc[i].SoC->AhciDmaType,
- NULL,
+ GetInitializerForType (NonDiscoverableDeviceTypeAhci, i),
NULL,
1,
Desc[i].SoC->AhciBaseAddress,
@@ -115,7 +116,7 @@ NonDiscoverableInitSdhci (
Status = RegisterNonDiscoverableMmioDevice (
NonDiscoverableDeviceTypeSdhci,
Desc[i].SoC->SdMmcDmaType,
- NULL,
+ GetInitializerForType (NonDiscoverableDeviceTypeSdhci, i),
NULL,
1,
Desc[i].SoC->SdMmcBaseAddress,
--
2.7.4
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [platforms: PATCH 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines
2018-10-20 1:57 ` [platforms: PATCH 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines Marcin Wojtas
@ 2018-12-04 17:16 ` Leif Lindholm
0 siblings, 0 replies; 35+ messages in thread
From: Leif Lindholm @ 2018-12-04 17:16 UTC (permalink / raw)
To: Marcin Wojtas; +Cc: edk2-devel, ard.biesheuvel, nadavh, jsd, jaz, kostap
On Sat, Oct 20, 2018 at 03:57:41AM +0200, Marcin Wojtas wrote:
> To abstract the initialization required for non-discoverable devices, which
> is often platform specific (i.e., enabling VBUS gpios for USB), introduce
> a NonDiscoverableInitLib for use by the NonDiscoverable code, for which
> each platform can supply its own version.
>
> Add VBUS enabling routines for supported platforms (Armada70x0Db,
> Armada80x0Db, Armada80x0McBin).
Please expand VBUS on first use in commit message.
>
> 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 | 47 ++++++++
> Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf | 48 +++++++++
> Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf | 48 +++++++++
> Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.inf | 1 +
> Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h | 28 +++++
> Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c | 99 +++++++++++++++++
> Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c | 113 ++++++++++++++++++++
> Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c | 73 +++++++++++++
> Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c | 7 +-
> 13 files changed, 471 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 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 7e1c37a..20a32ef 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..bbe7ff8
> --- /dev/null
> +++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> @@ -0,0 +1,47 @@
> +## @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]
> + MdePkg/MdePkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> + Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> + DebugLib
> + IoLib
> +
> +[Protocols]
> + gMarvellGpioProtocolGuid
> +
> +[Depex]
> + gMarvellPlatformInitCompleteProtocolGuid
> diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> new file mode 100644
> index 0000000..00b5ed5
> --- /dev/null
> +++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> @@ -0,0 +1,48 @@
> +## @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]
> + MdePkg/MdePkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> + Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> + DebugLib
> + IoLib
> +
> +[Protocols]
> + gMarvellGpioProtocolGuid
> +
> +[Depex]
> + gMarvellPlatformInitCompleteProtocolGuid
> diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> new file mode 100644
> index 0000000..66720d2
> --- /dev/null
> +++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.inf
> @@ -0,0 +1,48 @@
> +## @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]
> + MdePkg/MdePkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> + Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> + DebugLib
> + IoLib
> +
> +[Protocols]
> + gMarvellGpioProtocolGuid
> +
> +[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/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h b/Silicon/Marvell/Include/Library/NonDiscoverableInitLib.h
> new file mode 100644
> index 0000000..eaffce3
> --- /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
> +GetInitializerForType (
This needs some namespacing. Also not that clear from the name what it
does. I'll see if I can think of a better name from looking at point
of call.
> + 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..a93576e
> --- /dev/null
> +++ b/Platform/Marvell/Armada70x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> @@ -0,0 +1,99 @@
> +/**
> +*
> +* 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>
> +
> +#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
Please put the #defines in a local .h.
> +
> +STATIC CONST GPIO_PIN_DESC mArmada70x0DbVbusEn[] = {
Doesn't need Armada70x0Db, does need more than VbusEn.
> + {
> + 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
> +Armada70x0DbInitXhciVbus (
STATIC doesn't need Armada70x0Db prefix.
> + IN NON_DISCOVERABLE_DEVICE *This
> + )
> +{
> + CONST GPIO_PIN_DESC *VbusEnPinDesc;
> + MARVELL_GPIO_PROTOCOL *GpioProtocol;
> + EFI_STATUS Status;
> + UINTN Index;
> +
> + Status = MvGpioGetProtocol (GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
> + return Status;
> + }
> +
> + VbusEnPinDesc = mArmada70x0DbVbusEn;
> + for (Index = 0; Index < ARRAY_SIZE (mArmada70x0DbVbusEn); Index++) {
> + GpioProtocol->DirectionOutput (GpioProtocol,
> + VbusEnPinDesc->ControllerId,
> + VbusEnPinDesc->PinNumber,
> + VbusEnPinDesc->ActiveHigh);
> + VbusEnPinDesc++;
> + }
> +
> + return EFI_SUCCESS;
> +}
> +
> +NON_DISCOVERABLE_DEVICE_INIT
> +EFIAPI
> +GetInitializerForType (
> + IN NON_DISCOVERABLE_DEVICE_TYPE Type,
> + IN UINTN Index
> + )
> +{
> + if (Type == NonDiscoverableDeviceTypeXhci) {
> + return Armada70x0DbInitXhciVbus;
> + }
> +
> + return NULL;
> +}
> diff --git a/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> new file mode 100644
> index 0000000..05f6b89
> --- /dev/null
> +++ b/Platform/Marvell/Armada80x0Db/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> @@ -0,0 +1,113 @@
> +/**
> +*
> +* 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>
> +
> +#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
> +
Local .h?
> +STATIC CONST GPIO_PIN_DESC mArmada80x0DbVbusEn[] = {
Name as above.
> + {
> + 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
> +Armada80x0DbInitXhciVbus (
STATIC doesn't need Armada80x0Db prefix.
> + IN NON_DISCOVERABLE_DEVICE *This
> + )
> +{
> + CONST GPIO_PIN_DESC *VbusEnPinDesc;
> + MARVELL_GPIO_PROTOCOL *GpioProtocol;
> + EFI_STATUS Status;
> + UINTN Index;
> +
> + Status = MvGpioGetProtocol (GPIO_DRIVER_TYPE_PCA95XX, &GpioProtocol);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
> + return Status;
> + }
> +
> + VbusEnPinDesc = mArmada80x0DbVbusEn;
> + for (Index = 0; Index < ARRAY_SIZE (mArmada80x0DbVbusEn); Index++) {
> + GpioProtocol->DirectionOutput (GpioProtocol,
> + VbusEnPinDesc->ControllerId,
> + VbusEnPinDesc->PinNumber,
> + VbusEnPinDesc->ActiveHigh);
> + VbusEnPinDesc++;
> + }
> +
> + return EFI_SUCCESS;
> +}
> +
> +NON_DISCOVERABLE_DEVICE_INIT
> +EFIAPI
> +GetInitializerForType (
> + IN NON_DISCOVERABLE_DEVICE_TYPE Type,
> + IN UINTN Index
> + )
> +{
> + if (Type == NonDiscoverableDeviceTypeXhci) {
> + return Armada80x0DbInitXhciVbus;
> + }
> +
> + return NULL;
> +}
> diff --git a/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> new file mode 100644
> index 0000000..764b3b8
> --- /dev/null
> +++ b/Platform/SolidRun/Armada80x0McBin/NonDiscoverableInitLib/NonDiscoverableInitLib.c
> @@ -0,0 +1,73 @@
> +/**
> +*
> +* 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>
> +
> +#define ARMADA_80x0_CP0_CONTROLLER1_INDEX 2
Hmm, this doean't look Macchiato-specific. Could it be pulled in from
elsewhere?
> +#define ARMADA_80x0_MCBIN_VBUS0_PIN 15
Local .h?
> +
> +STATIC CONST GPIO_PIN_DESC mArmada80x0McBinVbusEn = {
Name as above.
> + ARMADA_80x0_CP0_CONTROLLER1_INDEX,
> + ARMADA_80x0_MCBIN_VBUS0_PIN,
> + TRUE,
> +};
> +
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +Armada80x0McBinInitXhciVbus (
STATIC as above.
/
Leif
> + IN NON_DISCOVERABLE_DEVICE *This
> + )
> +{
> + MARVELL_GPIO_PROTOCOL *GpioProtocol;
> + EFI_STATUS Status;
> +
> + Status = MvGpioGetProtocol (GPIO_DRIVER_TYPE_SOC_CONTROLLER, &GpioProtocol);
> + if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "%a: Unable to find GPIO protocol\n", __FUNCTION__));
> + return Status;
> + }
> +
> + GpioProtocol->DirectionOutput (GpioProtocol,
> + mArmada80x0McBinVbusEn.ControllerId,
> + mArmada80x0McBinVbusEn.PinNumber,
> + mArmada80x0McBinVbusEn.ActiveHigh);
> +
> + return Status;
> +}
> +
> +NON_DISCOVERABLE_DEVICE_INIT
> +EFIAPI
> +GetInitializerForType (
> + IN NON_DISCOVERABLE_DEVICE_TYPE Type,
> + IN UINTN Index
> + )
> +{
> + if (Type == NonDiscoverableDeviceTypeXhci) {
> + return Armada80x0McBinInitXhciVbus;
> + }
> +
> + return NULL;
> +}
> diff --git a/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c b/Silicon/Marvell/Drivers/NonDiscoverableDxe/NonDiscoverableDxe.c
> index c5cf904..5de9b7b 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,7 @@ NonDiscoverableInitXhci (
> Status = RegisterNonDiscoverableMmioDevice (
> NonDiscoverableDeviceTypeXhci,
> Desc[i].SoC->XhciDmaType,
> - NULL,
> + GetInitializerForType (NonDiscoverableDeviceTypeXhci, i),
> NULL,
> 1,
> Desc[i].SoC->XhciBaseAddress,
> @@ -86,7 +87,7 @@ NonDiscoverableInitAhci (
> Status = RegisterNonDiscoverableMmioDevice (
> NonDiscoverableDeviceTypeAhci,
> Desc[i].SoC->AhciDmaType,
> - NULL,
> + GetInitializerForType (NonDiscoverableDeviceTypeAhci, i),
> NULL,
> 1,
> Desc[i].SoC->AhciBaseAddress,
> @@ -115,7 +116,7 @@ NonDiscoverableInitSdhci (
> Status = RegisterNonDiscoverableMmioDevice (
> NonDiscoverableDeviceTypeSdhci,
> Desc[i].SoC->SdMmcDmaType,
> - NULL,
> + GetInitializerForType (NonDiscoverableDeviceTypeSdhci, i),
> NULL,
> 1,
> Desc[i].SoC->SdMmcBaseAddress,
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 35+ messages in thread