From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=2a00:1450:4864:20::142; helo=mail-lf1-x142.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3F84E21BADAB2 for ; Fri, 19 Oct 2018 18:58:14 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id c24-v6so85169lfi.12 for ; Fri, 19 Oct 2018 18:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hMaEl+CMCxmcdY98dt1OeBHGOwH87wvnGEXMcA4GCFU=; b=gM3SmJCNOtleykoSrw9wUS5QJbC2gJH/VcDvFgdyvfanueZ5AArOf0674aA8uXc8at mLuL/oHhinz5dgfF3Otep/T6mdYs+PTnMfE6crnCHlgPoWsIbenHftf1Ke3E8dZiysUW asKDyN3zAInF1TqGA1QFBJ3Tat9+6aWkW4txv3svnAfi6WiTOoDSdUBFJA2LcrV/ljpf TYANF+w+rGynbI24TNp21bJL1VxUvhMEXITbKgJgb5mHGciKia2/wxeQSyQaIZmBuJSk xUcAAdE7UKCzQQF5H0DMfNoKkADHKD4E52Awz3GHCIm8/Muc2F4s4GUn9M4BHG6GfMQ9 BYhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hMaEl+CMCxmcdY98dt1OeBHGOwH87wvnGEXMcA4GCFU=; b=Jn2q0c/hofPc14TJ9+Wzilpc2ZPEL+QCt6k5jb467UFpv2lArep7jtxR3zW/Cxvxji gvd6DB3/Un0itaylY7BG6j4WPgQ7TAWf+nvFBih28ZtlF/V09mtT54npBIg9UcfNHFLF wsTt5d+zr3pDExYBRSo1oLNnB8qN2No1eP7QYWYsCx1N2b2B6EjsoL31YIaSsqsV6DQ/ sglvLS1ktI0f0xEByubc+W/SPE0KmP0eQm0ZJBFPUxkVAIp9xvqaUljREbVsJWf4GvXJ K2CfRy06s8CeVbf7dkddVCjxvMJv5vY4uOVuBYzYwoM7hyYoZd6VY6tkWeJyyt/5sJCd Pdgg== X-Gm-Message-State: ABuFfohu9ZVN4H554t28Q2gO/TmFULijjFyjZMVzWq9AWEidgQm4FPVo Jo/crhT3XFJHX9aTMDOenx8g6msklSk= X-Google-Smtp-Source: ACcGV60s9a619t05guppC0tsHMHPXdhLC8fBySHNk3GQOeqDuXTkPWDdfb1uH0Mg8PobUkgp6vNwgA== X-Received: by 2002:a19:5710:: with SMTP id l16-v6mr4618995lfb.71.1540000692310; Fri, 19 Oct 2018 18:58:12 -0700 (PDT) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id p63-v6sm5562777lfg.46.2018.10.19.18.58.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Oct 2018 18:58:11 -0700 (PDT) From: Marcin Wojtas To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, nadavh@marvell.com, mw@semihalf.com, jsd@semihalf.com, jaz@semihalf.com, kostap@marvell.com, jinghua Date: Sat, 20 Oct 2018 03:57:36 +0200 Message-Id: <1540000661-1956-8-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1540000661-1956-1-git-send-email-mw@semihalf.com> References: <1540000661-1956-1-git-send-email-mw@semihalf.com> Subject: [platforms: PATCH 07/12] Marvell/Protocol: Introduce MARVELL_GPIO_PROTOCOL X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Oct 2018 01:58:14 -0000 From: jinghua 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 --- 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 + +#include +#include +#include +#include + +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