public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@linaro.org>
To: Marcin Wojtas <mw@semihalf.com>
Cc: edk2-devel@lists.01.org, ard.biesheuvel@linaro.org,
	nadavh@marvell.com, jsd@semihalf.com, jaz@semihalf.com,
	kostap@marvell.com
Subject: Re: [platforms: PATCH v3 03/12] Marvell/Library: Introduce MvGpioLib class
Date: Thu, 17 Jan 2019 11:33:06 +0000	[thread overview]
Message-ID: <20190117113305.muntfdgceho4safl@bivouac.eciton.net> (raw)
In-Reply-To: <1547723715-4562-4-git-send-email-mw@semihalf.com>

(Can drop the "class" from subject line)

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

On Thu, Jan 17, 2019 at 12:15:06PM +0100, Marcin Wojtas wrote:
> Following patches will add two drivers that are capable
> of producing the generic EMBEDDED_GPIO protocol. In order
> to handle a situation, when the consumer module attempts
> to locate and open a proper protocol, add a library
> helper function.
> 
> In order to ease description of used GPIO pins and controllers
> of the Armada 7k8k platforms, add the common enum types.
> 
> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  Silicon/Marvell/Marvell.dec                     |   1 +
>  Silicon/Marvell/Library/MvGpioLib/MvGpioLib.inf |  32 +++++
>  Silicon/Marvell/Include/Library/MvGpioLib.h     |  68 ++++++++++
>  Silicon/Marvell/Library/MvGpioLib/MvGpioLib.c   | 132 ++++++++++++++++++++
>  4 files changed, 233 insertions(+)
>  create mode 100644 Silicon/Marvell/Library/MvGpioLib/MvGpioLib.inf
>  create mode 100644 Silicon/Marvell/Include/Library/MvGpioLib.h
>  create mode 100644 Silicon/Marvell/Library/MvGpioLib/MvGpioLib.c
> 
> diff --git a/Silicon/Marvell/Marvell.dec b/Silicon/Marvell/Marvell.dec
> index 616624e..ac922a0 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
> +  MvGpioLib|Include/Library/MvGpioLib.h
>    SampleAtResetLib|Include/Library/SampleAtResetLib.h
>  
>  [Protocols]
> diff --git a/Silicon/Marvell/Library/MvGpioLib/MvGpioLib.inf b/Silicon/Marvell/Library/MvGpioLib/MvGpioLib.inf
> new file mode 100644
> index 0000000..3bc54ce
> --- /dev/null
> +++ b/Silicon/Marvell/Library/MvGpioLib/MvGpioLib.inf
> @@ -0,0 +1,32 @@
> +## @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                      = MvGpioLib
> +  FILE_GUID                      = f4386b44-6bc2-4fa1-9989-8513bbb22692
> +  MODULE_TYPE                    = BASE
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = MvGpioLib
> +
> +[Sources]
> +  MvGpioLib.c
> +
> +[Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdePkg/MdePkg.dec
> +  Silicon/Marvell/Marvell.dec
> +
> +[LibraryClasses]
> +  DebugLib
> diff --git a/Silicon/Marvell/Include/Library/MvGpioLib.h b/Silicon/Marvell/Include/Library/MvGpioLib.h
> new file mode 100644
> index 0000000..a14acdf
> --- /dev/null
> +++ b/Silicon/Marvell/Include/Library/MvGpioLib.h
> @@ -0,0 +1,68 @@
> +/**
> +*
> +*  Copyright (C) 2018, Marvell International Ltd. and its affiliates.
> +*
> +*  This program and the accompanying materials are licensed and made available
> +*  under the terms and conditions of the BSD License which accompanies this
> +*  distribution. The full text of the license may be found at
> +*  http://opensource.org/licenses/bsd-license.php
> +*
> +*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +*
> +**/
> +#ifndef __MV_GPIO_LIB_H__
> +#define __MV_GPIO_LIB_H__
> +
> +#include <Protocol/EmbeddedGpio.h>
> +
> +typedef enum {
> +  MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER,
> +  MV_GPIO_DRIVER_TYPE_PCA95XX,
> +} MV_GPIO_DRIVER_TYPE;
> +
> +typedef enum {
> +  MV_GPIO_AP806_CONTROLLER0,
> +  MV_GPIO_CP0_CONTROLLER0,
> +  MV_GPIO_CP0_CONTROLLER1,
> +  MV_GPIO_CP1_CONTROLLER0,
> +  MV_GPIO_CP1_CONTROLLER1,
> +  MV_GPIO_CP2_CONTROLLER0,
> +  MV_GPIO_CP2_CONTROLLER1,
> +} MV_GPIO_SOC_CONTROLLER_TYPE;
> +
> +typedef enum {
> +  PCA9505_ID,
> +  PCA9534_ID,
> +  PCA9535_ID,
> +  PCA9536_ID,
> +  PCA9537_ID,
> +  PCA9538_ID,
> +  PCA9539_ID,
> +  PCA9554_ID,
> +  PCA9555_ID,
> +  PCA9556_ID,
> +  PCA9557_ID,
> +  PCA95XX_MAX_ID,
> +} MV_GPIO_EXPANDER_TYPE_PCA95XX;
> +
> +typedef struct {
> +  VENDOR_DEVICE_PATH        Header;
> +  MV_GPIO_DRIVER_TYPE       GpioDriverType;
> +  EFI_DEVICE_PATH_PROTOCOL  End;
> +} MV_GPIO_DEVICE_PATH;
> +
> +typedef struct {
> +  UINTN    ControllerId;
> +  UINTN    PinNumber;
> +  BOOLEAN  ActiveHigh;
> +} MV_GPIO_PIN;
> +
> +EFI_STATUS
> +EFIAPI
> +MvGpioGetProtocol (
> +  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
> +  IN OUT EMBEDDED_GPIO        **GpioProtocol
> +  );
> +
> +#endif // __MV_GPIO_LIB_H__
> diff --git a/Silicon/Marvell/Library/MvGpioLib/MvGpioLib.c b/Silicon/Marvell/Library/MvGpioLib/MvGpioLib.c
> new file mode 100644
> index 0000000..a95d5ae
> --- /dev/null
> +++ b/Silicon/Marvell/Library/MvGpioLib/MvGpioLib.c
> @@ -0,0 +1,132 @@
> +/**
> +*
> +*  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/DebugLib.h>
> +#include <Library/DevicePathLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/MvGpioLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +
> +#include <Protocol/EmbeddedGpio.h>
> +
> +/*
> + * Check if the driver type matches the requested value.
> + * In case of the success open the GPIO protocol and return.
> + */
> +STATIC
> +EFI_STATUS
> +MvGpioFindMatchingDriver (
> +  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
> +  IN     EFI_HANDLE             HandleBuffer,
> +  IN     EFI_DEVICE_PATH       *DevicePath,
> +  IN OUT EMBEDDED_GPIO        **GpioProtocol
> +  )
> +{
> +  MV_GPIO_DEVICE_PATH *GpioDevicePath;
> +  EFI_STATUS           Status;
> +
> +  while (!IsDevicePathEndType (DevicePath)) {
> +    /* Check if GpioDriverType matches one found in the device path */
> +    GpioDevicePath = (MV_GPIO_DEVICE_PATH *)DevicePath;
> +    if (GpioDevicePath->GpioDriverType != GpioDriverType) {
> +      DevicePath = NextDevicePathNode (DevicePath);
> +      continue;
> +    }
> +
> +    /*
> +     * Open GpioProtocol. With EFI_OPEN_PROTOCOL_GET_PROTOCOL attribute
> +     * the consumer is not obliged to call CloseProtocol.
> +     */
> +    Status = gBS->OpenProtocol (HandleBuffer,
> +                    &gEmbeddedGpioProtocolGuid,
> +                    (VOID **)GpioProtocol,
> +                    gImageHandle,
> +                    NULL,
> +                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> +    return Status;
> +  }
> +
> +  return EFI_NOT_FOUND;
> +}
> +
> +/*
> + * Select desired protocol producer upon MV_GPIO_DRIVER_TYPE
> + * field of driver's MV_GPIO_DEVICE_PATH.
> + */
> +EFI_STATUS
> +EFIAPI
> +MvGpioGetProtocol (
> +  IN     MV_GPIO_DRIVER_TYPE    GpioDriverType,
> +  IN OUT EMBEDDED_GPIO        **GpioProtocol
> +  )
> +{
> +  EFI_DEVICE_PATH     *DevicePath;
> +  EFI_HANDLE          *HandleBuffer;
> +  EFI_STATUS           Status;
> +  UINTN                HandleCount;
> +  UINTN                Index;
> +
> +  /* Locate Handles of all EMBEDDED_GPIO producers */
> +  Status = gBS->LocateHandleBuffer (ByProtocol,
> +                  &gEmbeddedGpioProtocolGuid,
> +                  NULL,
> +                  &HandleCount,
> +                  &HandleBuffer);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "%a: Unable to locate handles\n", __FUNCTION__));
> +    return Status;
> +  }
> +
> +  /* Iterate over all protocol producers */
> +  for (Index = 0; Index < HandleCount; Index++) {
> +    /* Open device path protocol installed on each handle */
> +    Status = gBS->OpenProtocol (HandleBuffer[Index],
> +                    &gEfiDevicePathProtocolGuid,
> +                    (VOID **)&DevicePath,
> +                    gImageHandle,
> +                    NULL,
> +                    EFI_OPEN_PROTOCOL_GET_PROTOCOL);
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "%a: Unable to find DevicePath\n", __FUNCTION__));
> +      continue;
> +    }
> +
> +    /*
> +     * Check if the driver type matches the requested value.
> +     * In case of the success open the GPIO protocol and return.
> +     * If there is no match, repeat procedure with the next handle.
> +     */
> +    Status = MvGpioFindMatchingDriver (GpioDriverType,
> +               HandleBuffer[Index],
> +               DevicePath,
> +               GpioProtocol);
> +    if (Status == EFI_NOT_FOUND) {
> +      continue;
> +    } else if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR,
> +        "%a: Unable to open GPIO protocol\n",
> +        __FUNCTION__));
> +    }
> +
> +    gBS->FreePool (HandleBuffer);
> +
> +    return Status;
> +  }
> +
> +  /* No matching GPIO protocol producer was found */
> +  gBS->FreePool (HandleBuffer);
> +
> +  return EFI_NOT_FOUND;
> +}
> -- 
> 2.7.4
> 


  reply	other threads:[~2019-01-17 11:33 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-17 11:15 [platforms: PATCH v3 00/12] Armada 7k8k GPIO support Marcin Wojtas
2019-01-17 11:15 ` [platforms: PATCH v3 01/12] Marvell/Library: ArmadaSoCDescLib: Add GPIO information Marcin Wojtas
2019-01-17 11:15 ` [platforms: PATCH v3 02/12] Marvell/Library: ArmadaBoardDescLib: " Marcin Wojtas
2019-01-17 11:15 ` [platforms: PATCH v3 03/12] Marvell/Library: Introduce MvGpioLib class Marcin Wojtas
2019-01-17 11:33   ` Leif Lindholm [this message]
2019-01-17 12:19     ` Marcin Wojtas
2019-01-17 14:18       ` Leif Lindholm
2019-01-17 14:39         ` Marcin Wojtas
2019-01-17 11:15 ` [platforms: PATCH v3 04/12] SolidRun/Armada80x0McBin: Extend board description library with GPIO Marcin Wojtas
2019-01-17 11:15 ` [platforms: PATCH v3 05/12] Marvell/Armada70x0Db: " Marcin Wojtas
2019-01-17 11:34   ` Leif Lindholm
2019-01-17 11:15 ` [platforms: PATCH v3 06/12] Marvell/Armada80x0Db: " Marcin Wojtas
2019-01-17 11:34   ` Leif Lindholm
2019-01-17 11:15 ` [platforms: PATCH v3 07/12] Marvell/Drivers: MvBoardDesc: Extend protocol with GPIO support Marcin Wojtas
2019-01-17 11:50   ` Leif Lindholm
2019-01-17 11:15 ` [platforms: PATCH v3 08/12] Marvell/Drivers: MvGpioDxe: Introduce platform GPIO driver Marcin Wojtas
2019-01-17 11:52   ` Leif Lindholm
2019-01-17 11:15 ` [platforms: PATCH v3 09/12] Marvell/Drivers: I2c: Use common header for macros Marcin Wojtas
2019-01-17 11:15 ` [platforms: PATCH v3 10/12] Marvell/Drivers: MvPca95xxDxe: Introduce GPIO expander driver Marcin Wojtas
2019-01-17 11:55   ` Leif Lindholm
2019-01-17 11:15 ` [platforms: PATCH v3 11/12] Marvell/Armada7k8k: Enable GPIO drivers compilation Marcin Wojtas
2019-01-17 11:15 ` [platforms: PATCH v3 12/12] Marvell/Armada7k8k: Introduce NonDiscoverable device init routines Marcin Wojtas
2019-01-17 12:03 ` [platforms: PATCH v3 00/12] Armada 7k8k GPIO support Leif Lindholm
2019-01-17 12:26   ` Marcin Wojtas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190117113305.muntfdgceho4safl@bivouac.eciton.net \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox