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::141; helo=mail-lf1-x141.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-lf1-x141.google.com (mail-lf1-x141.google.com [IPv6:2a00:1450:4864:20::141]) (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 69C002194D3AE for ; Wed, 9 Jan 2019 17:45:06 -0800 (PST) Received: by mail-lf1-x141.google.com with SMTP id z13so7110226lfe.11 for ; Wed, 09 Jan 2019 17:45:06 -0800 (PST) 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=ezxtSnF5PtO9ds0t5vj+UCC2pEv/RCgtncOG3VYfCPc=; b=y69cc/kvpTl/rVNaOPEPUyl9KcLa6c+URET2r8kZmBWzAZByLFqUenmCO0jPbbbYNY dJiYJa2rDz3Wwb36xG8dswOdH5r37A3CaOdwprjRxWSGNaD+Zp2dw3mvl1/c45T9rHHo leTKRjIzAICwmRd0Z05y4qMH6soisCHRFlibJIkc8DdXGEe1d8HrM8+d8szhMQlXTW6T gYNpvWME/hdRju9mfQAVAE1AR0XtLM7DCao7BqNwZkvjMvoXwQN8OwmY1sOVVlPvRxAU GIcR1cT1EB6OZaZGpyMDRnI2jdyiDWmK4kr7IJGHyyRC471QA+hqOeteQMNL/u95kIiS 7U+Q== 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=ezxtSnF5PtO9ds0t5vj+UCC2pEv/RCgtncOG3VYfCPc=; b=dC7l8gYW2tzbV4FgGXZhoRav3/XXCO6VMczwrULr99KNcDuUdAU64pN6A1gLThEMKH hdDi+UTiaVfPAB4xFx+MUSQ/lzAX2/YaBxqA0ilx6Q284RvQBM1kZodPX2z6pyAJuBHk SThAP/Z9aejSVpLKknTCXP6bhfHtUlXC6HvogHQ2YClBX9wOT0H7OD+1MWgzAxEIPSd6 arbufyJC8bjnc7sGFi1aaJ/irwf002ZmCffkt05aEyX75twpFnNSI784yXu5MU9CDIGz clUpR3ZnJqpFasfr1jk1FHkgo6o+NaFqWIuAkV6ey0xM4AElPEmYaVTWEVI35Lc3IpO+ l4gg== X-Gm-Message-State: AJcUukc/1a89edzDPW/U5HnNuhCu1IO8T7ojTRUU79bemayxBAlYwizm +LpHyQ7U3sCIKfPQa0sDQSB6PdGS7ik= X-Google-Smtp-Source: ALg8bN4bBZz5pYYw+PweucLCeV+WcxIh1f5Fhtgby2896a+W31mQLl8jnlxbrrqY26NAzrXhR6V1/w== X-Received: by 2002:a19:2395:: with SMTP id j143mr4571091lfj.107.1547084704196; Wed, 09 Jan 2019 17:45:04 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id l21-v6sm15034142ljj.48.2019.01.09.17.45.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Jan 2019 17:45:03 -0800 (PST) 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: Thu, 10 Jan 2019 02:44:34 +0100 Message-Id: <1547084679-29597-8-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547084679-29597-1-git-send-email-mw@semihalf.com> References: <1547084679-29597-1-git-send-email-mw@semihalf.com> Subject: [platforms: PATCH v2 07/12] Marvell/Protocol: Introduce GPIO helper header 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: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 X-List-Received-Date: Thu, 10 Jan 2019 01:45:06 -0000 From: jinghua This patch introduces a helper header that can be used by multiple EMBEDDED_GPIO protocol producers (e.g. platform driver or GPIO expanders). The drives are differentiated by MV_GPIO_DRIVER_TYPE field of driver's MV_GPIO_DEVICE_PATH. In order to ease selection of the desired GPIO controller a helper function was added - MarvellGpioGetProtocol(). Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas --- Silicon/Marvell/Include/Protocol/MvGpio.h | 156 ++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 Silicon/Marvell/Include/Protocol/MvGpio.h diff --git a/Silicon/Marvell/Include/Protocol/MvGpio.h b/Silicon/Marvell/Include/Protocol/MvGpio.h new file mode 100644 index 0000000..c9f1007 --- /dev/null +++ b/Silicon/Marvell/Include/Protocol/MvGpio.h @@ -0,0 +1,156 @@ +/** +* +* Copyright (C) 2018, Marvell International Ltd. and its affiliates. +* +* This program and the accompanying materials are licensed and made available +* under the terms and conditions of the BSD License which accompanies this +* distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ +#ifndef __MV_GPIO_PROTOCOL_H__ +#define __MV_GPIO_PROTOCOL_H__ + +#include + +#include +#include +#include +#include + +#include + +typedef enum { + MV_GPIO_DRIVER_TYPE_SOC_CONTROLLER, +} MV_GPIO_DRIVER_TYPE; + +typedef struct { + VENDOR_DEVICE_PATH Header; + MV_GPIO_DRIVER_TYPE GpioDriverType; + EFI_DEVICE_PATH_PROTOCOL End; +} MV_GPIO_DEVICE_PATH; + +typedef struct { + UINTN ControllerId; + UINTN PinNumber; + BOOLEAN ActiveHigh; +} MV_GPIO_PIN; + +/* + * Check if the driver type matches the requested value. + * In case of the success open the GPIO protocol and return. + */ +STATIC +inline +EFI_STATUS +EFIAPI +MvGpioFindMatchingDriver ( + IN MV_GPIO_DRIVER_TYPE GpioDriverType, + IN EFI_HANDLE HandleBuffer, + IN EFI_DEVICE_PATH *DevicePath, + IN OUT EMBEDDED_GPIO **GpioProtocol + ) +{ + MV_GPIO_DEVICE_PATH *GpioDevicePath; + EFI_STATUS Status; + + while (!IsDevicePathEndType (DevicePath)) { + /* Check if GpioDriverType matches one found in the device path */ + GpioDevicePath = (MV_GPIO_DEVICE_PATH *)DevicePath; + if (GpioDevicePath->GpioDriverType != GpioDriverType) { + DevicePath = NextDevicePathNode (DevicePath); + continue; + } + + /* + * Open GpioProtocol. With EFI_OPEN_PROTOCOL_GET_PROTOCOL attribute + * the consumer is not obliged to call CloseProtocol. + */ + Status = gBS->OpenProtocol (HandleBuffer, + &gEmbeddedGpioProtocolGuid, + (VOID **)GpioProtocol, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + return Status; + } + + return EFI_NOT_FOUND; +} + +/* + * Select desired protocol producer upon MV_GPIO_DRIVER_TYPE + * field of driver's MV_GPIO_DEVICE_PATH. + */ +STATIC +inline +EFI_STATUS +EFIAPI +MvGpioGetProtocol ( + IN MV_GPIO_DRIVER_TYPE GpioDriverType, + IN OUT EMBEDDED_GPIO **GpioProtocol + ) +{ + EFI_DEVICE_PATH *DevicePath; + EFI_HANDLE *HandleBuffer; + EFI_STATUS Status; + UINTN HandleCount; + UINTN Index; + + /* Locate Handles of all EMBEDDED_GPIO producers */ + Status = gBS->LocateHandleBuffer (ByProtocol, + &gEmbeddedGpioProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Unable to locate handles\n", __FUNCTION__)); + return Status; + } + + /* Iterate over all protocol producers */ + for (Index = 0; Index < HandleCount; Index++) { + /* Open device path protocol installed on each handle */ + Status = gBS->OpenProtocol (HandleBuffer[Index], + &gEfiDevicePathProtocolGuid, + (VOID **)&DevicePath, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Unable to find DevicePath\n", __FUNCTION__)); + continue; + } + + /* + * Check if the driver type matches the requested value. + * In case of the success open the GPIO protocol and return. + * If there is no match, repeat procedure with the next handle. + */ + Status = MvGpioFindMatchingDriver (GpioDriverType, + HandleBuffer[Index], + DevicePath, + GpioProtocol); + if (Status == EFI_NOT_FOUND) { + continue; + } else if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, + "%a: Unable to open GPIO protocol\n", + __FUNCTION__)); + } + + gBS->FreePool (HandleBuffer); + + return Status; + } + + /* No matching GPIO protocol producer was found */ + gBS->FreePool (HandleBuffer); + + return EFI_NOT_FOUND; +} + +#endif // __MV_GPIO_PROTOCOL_H__ -- 2.7.4