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::541; helo=mail-ed1-x541.google.com; envelope-from=pete@akeo.ie; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) (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 5FCAB2194D387 for ; Mon, 28 Jan 2019 04:45:02 -0800 (PST) Received: by mail-ed1-x541.google.com with SMTP id o10so12830710edt.13 for ; Mon, 28 Jan 2019 04:45:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/uxjX3ZJL+vr0z4/XuCp+5aFGF476HpQ5K1286HpwTY=; b=PPsgj4m3po6AvCeKqQ9BCsNxiJN+CAJg8iRbjqeKRNiEDUljFxAw9yrJkWa4TnfJKu 3u/JTLl2Fthqs3+DsD9R7xNCzrR25WPRtV4pGYcl2b3IB2twEnHh5cTfP8SYh+87Fxdy ktnInt7ja6jueGLiaMRTwpKwdcxbxYFxik5Qrsht2pHOB1V9wB1A2LA/VYby9RRCw9i6 w7Q8uReEkxA6k6g2SrwrRlKwVOTzKysQ9tD/DgubUlA70SgRBnS28qNYeH3idz1MtONg E+LaYMows//84F+dET+qjYxSHvwCOSwIHBq67XtNMASz/74BWxztml1cQbSzdJ0m8nuG 3XDw== 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=/uxjX3ZJL+vr0z4/XuCp+5aFGF476HpQ5K1286HpwTY=; b=IClhghoYHpzJb1dMVtTBa/+fOH9kQJCEzQ9FZKhsP2GkH0Q0fPobsjkdfAvUB953a1 VdKC5Ybbq1VWOGx0P0Kt8JpryqiY/pVgAjyLCZt9xLNQ7YMKT00BTSF9laZ52Qeo3d1g NpDT9U9dX54WivKc+vtVWrVSXZl5E9RkM8oMZHQPdMMOZyL5yNGbf53cTj5VbOJ3vAjQ U/r8k4pRLRBpv9Cq6v1KdQN7l8dNd8MaL947arxIV2qDmsUnLOeYfFVxvsxejh09NyIy q4y2/uth1wLhEKWeJw1D2IHh1n5Y1/bzgGnNWtwVakUH/ryeeiz9Gt3fy05vyyx+8ERC oZoQ== X-Gm-Message-State: AJcUukcLVPGfgyg0LU+XwKJNQ/XtwrZetK+lNgsDyML/MYZeHqEz+Vdm dm3VJNSmqadAoOSH5RwN8Xsx4OJKI7c= X-Google-Smtp-Source: ALg8bN65nOkIytyEiIXTvu/1uwbo0heAK1YgqNQrbiqUKKGHFaq0TXBbCpxBR9oKcOKYB0ZIcYYquA== X-Received: by 2002:a50:b7ad:: with SMTP id h42mr21712715ede.210.1548679500476; Mon, 28 Jan 2019 04:45:00 -0800 (PST) Received: from localhost.localdomain ([84.203.95.186]) by smtp.gmail.com with ESMTPSA id y16sm13757367edb.41.2019.01.28.04.44.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 04:44:59 -0800 (PST) From: Pete Batard To: edk2-devel@lists.01.org Date: Mon, 28 Jan 2019 12:44:24 +0000 Message-Id: <20190128124445.9868-3-pete@akeo.ie> X-Mailer: git-send-email 2.17.0.windows.1 In-Reply-To: <20190128124445.9868-1-pete@akeo.ie> References: <20190128124445.9868-1-pete@akeo.ie> Subject: [PATCH v3 edk2-platforms 02/23] Silicon/Broadcom/Bcm283x: Add GpioLib 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: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:02 -0000 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Pete Batard --- Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.c | 88 ++++++++++++++++++++ Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf | 39 +++++++++ Silicon/Broadcom/Include/IndustryStandard/Bcm2836Gpio.h | 60 +++++++++++++ 3 files changed, 187 insertions(+) diff --git a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.c b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.c new file mode 100644 index 000000000000..eb6accafb01e --- /dev/null +++ b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.c @@ -0,0 +1,88 @@ +/** @file + * + * GPIO manipulation. + * + * Copyright (c) 2018, Andrei Warkentin + * + * 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 +#include +#include +#include +#include +#include + +STATIC +VOID +GpioFSELModify ( + IN UINTN RegIndex, + IN UINT32 ModifyMask, + IN UINT32 FunctionMask + ) +{ + UINT32 Val; + EFI_PHYSICAL_ADDRESS Reg; + + Reg = RegIndex * sizeof (UINT32) + GPIO_GPFSEL0; + + ASSERT (Reg <= GPIO_GPFSEL5); + ASSERT ((~ModifyMask & FunctionMask) == 0); + + Val = MmioRead32 (Reg); + Val &= ~ModifyMask; + Val |= FunctionMask; + MmioWrite32 (Reg, Val); +} + +VOID +GpioPinFuncSet ( + IN UINTN Pin, + IN UINTN Function + ) +{ + UINTN RegIndex; + UINTN SelIndex; + UINT32 ModifyMask; + UINT32 FunctionMask; + + ASSERT (Pin < GPIO_PINS); + ASSERT (Function <= GPIO_FSEL_MASK); + + RegIndex = Pin / 10; + SelIndex = Pin % 10; + + ModifyMask = GPIO_FSEL_MASK << (SelIndex * GPIO_FSEL_BITS_PER_PIN); + FunctionMask = Function << (SelIndex * GPIO_FSEL_BITS_PER_PIN); + GpioFSELModify (RegIndex, ModifyMask, FunctionMask); +} + +UINTN +GpioPinFuncGet ( + IN UINTN Pin + ) +{ + UINT32 Val; + UINTN RegIndex; + UINTN SelIndex; + EFI_PHYSICAL_ADDRESS Reg; + + ASSERT (Pin < GPIO_PINS); + + RegIndex = Pin / 10; + SelIndex = Pin % 10; + Reg = RegIndex * sizeof (UINT32) + GPIO_GPFSEL0; + + Val = MmioRead32 (Reg); + Val >>= SelIndex * GPIO_FSEL_BITS_PER_PIN; + Val &= GPIO_FSEL_MASK; + return Val; +} diff --git a/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf new file mode 100644 index 000000000000..68ebe44e3d1c --- /dev/null +++ b/Silicon/Broadcom/Bcm283x/Library/GpioLib/GpioLib.inf @@ -0,0 +1,39 @@ +#/** @file +# +# Manipulate GPIOs. +# +# Copyright (c) 2018, Andrei Warkentin +# +# 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 = GpioLib + FILE_GUID = B9F59B6B-B105-41C7-8F5A-2C60DD7FD7AB + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = GpioLib + +[Sources] + GpioLib.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + Silicon/Broadcom/Bcm283x/Bcm283x.dec + +[LibraryClasses] + BaseLib + DebugLib + IoLib + +[Guids] diff --git a/Silicon/Broadcom/Include/IndustryStandard/Bcm2836Gpio.h b/Silicon/Broadcom/Include/IndustryStandard/Bcm2836Gpio.h new file mode 100644 index 000000000000..45774b639ca8 --- /dev/null +++ b/Silicon/Broadcom/Include/IndustryStandard/Bcm2836Gpio.h @@ -0,0 +1,60 @@ +/** @file + * + * Copyright (c) 2018, Andrei Warkentin + * Copyright (c) Microsoft Corporation. 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 __BCM2836_GPIO_H__ +#define __BCM2836_GPIO_H__ + +#define GPIO_BASE_ADDRESS (BCM2836_SOC_REGISTERS + 0x00200000) + +#define GPIO_GPFSEL0 (GPIO_BASE_ADDRESS + 0x00) +#define GPIO_GPFSEL1 (GPIO_BASE_ADDRESS + 0x04) +#define GPIO_GPFSEL2 (GPIO_BASE_ADDRESS + 0x08) +#define GPIO_GPFSEL3 (GPIO_BASE_ADDRESS + 0x0C) +#define GPIO_GPFSEL4 (GPIO_BASE_ADDRESS + 0x10) +#define GPIO_GPFSEL5 (GPIO_BASE_ADDRESS + 0x14) + +#define GPIO_GPCLR0 (GPIO_BASE_ADDRESS + 0x28) +#define GPIO_GPCLR1 (GPIO_BASE_ADDRESS + 0x2C) + +#define GPIO_GPSET0 (GPIO_BASE_ADDRESS + 0x1C) +#define GPIO_GPSET1 (GPIO_BASE_ADDRESS + 0x20) + +#define GPIO_FSEL_INPUT 0x0 +#define GPIO_FSEL_OUTPUT 0x1 +#define GPIO_FSEL_ALT0 0x4 +#define GPIO_FSEL_ALT1 0x5 +#define GPIO_FSEL_ALT2 0x6 +#define GPIO_FSEL_ALT3 0x7 +#define GPIO_FSEL_ALT4 0x3 +#define GPIO_FSEL_ALT5 0x2 + +#define GPIO_FSEL_PINS_PER_REGISTER 10 +#define GPIO_FSEL_BITS_PER_PIN 3 +#define GPIO_FSEL_MASK ((1 << GPIO_FSEL_BITS_PER_PIN) - 1) + +#define GPIO_PINS 54 + +VOID +GpioPinFuncSet ( + IN UINTN Pin, + IN UINTN Function + ); + +UINTN +GpioPinFuncGet ( + IN UINTN Pin + ); + +#endif /* __BCM2836_GPIO_H__ */ -- 2.17.0.windows.1