From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.38.136; helo=nam02-bl2-obe.outbound.protection.outlook.com; envelope-from=christopher.co@microsoft.com; receiver=edk2-devel@lists.01.org Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0136.outbound.protection.outlook.com [104.47.38.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E35ED2115410A for ; Fri, 21 Sep 2018 01:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qF4ClpYXt7VxsBqX1nh9a7n4lT334a55lWivl6IjLOg=; b=B0tkjjOxevU5q7J8n3n5SDzo6O8wgzC/+EneKvR8ENv8EaUhLfSJUXXTC0VhfiyYp1muua1tMEazUkZ2B0GHQg1+7NTlWNj7eSjNym8DFs/JIW/WNbMn4+2B9/DEJRRrJaRsaKQs4cQ8zYNnFpGj8FiagUemWo4RQgaapTYcqYE= Received: from DM5PR2101MB1128.namprd21.prod.outlook.com (52.132.133.20) by DM5PR2101MB0727.namprd21.prod.outlook.com (10.167.110.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.6; Fri, 21 Sep 2018 08:26:03 +0000 Received: from DM5PR2101MB1128.namprd21.prod.outlook.com ([fe80::81f8:300e:d90:d49]) by DM5PR2101MB1128.namprd21.prod.outlook.com ([fe80::81f8:300e:d90:d49%3]) with mapi id 15.20.1164.008; Fri, 21 Sep 2018 08:26:03 +0000 From: Chris Co To: "edk2-devel@lists.01.org" CC: Ard Biesheuvel , Leif Lindholm , Michael D Kinney Thread-Topic: [PATCH edk2-platforms 12/27] Silicon/NXP: Add i.MX6 I/O MUX library Thread-Index: AQHUUYS8K8ZRkLJZhEm6rexKIPRBDA== Date: Fri, 21 Sep 2018 08:26:03 +0000 Message-ID: <20180921082542.35768-13-christopher.co@microsoft.com> References: <20180921082542.35768-1-christopher.co@microsoft.com> In-Reply-To: <20180921082542.35768-1-christopher.co@microsoft.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR17CA0054.namprd17.prod.outlook.com (2603:10b6:300:93::16) To DM5PR2101MB1128.namprd21.prod.outlook.com (2603:10b6:4:a8::20) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [2001:4898:80e8:8:388a:edc9:7085:c18] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR2101MB0727; 6:DaJ+O/sR05M5qzAm8qBMeUcNsvpXRD0cMeCPjclzHjbQo5Ynwn6OkY1Y+cU/XYtO0lKOp61m4Jofkmj8v/PQtxOhMLDTxfpZNpFw54+PA9hbbI3CtvsvT7d4yzD8kM3PiBJEVTZOuzddVg1BtExtfPG95/TlszSBXMaTdXuyoklF7Nbm1IU0wwsQeVoE7P5cYzSML4QNSK07vZNLJEIy1CRxnkiPQnIggYLMHNtysalMNd8mawW5fG23D6ii4UxHPgPmwjzjwaLP/CgttdQgAGXlttHzuoGeZ/kRfHM8r42eege/HZTxioN8x0v9P65gri1FeP6PNVNOr1V0x9p8KwwKwVHaqKqeXPvI8IrW4rYcMGJjVTvli/n5qv4jfv3WSJsE6hnTQJpPzWshq0fhA+2gdRJ6HcT+nnIttQwgX2wA5yalr1tadqrwb9ti/08MnsYjTwVbrTBJT/rl4vcRRw==; 5:Q7tu5aPBNzpkMiNYpfulZF/7OuSX0pLhK94RleXMMTPmXGqrI8T2HbtdRlMYF6uxIbHUz4s9fYDzwfBOh8Y+QmBdwzXUIgEn/G4fxM8Zz2bB5XkqJ7U2L79Lx3bDZYLvi/328eMv3ndBzfq9ODQTFm6hn4xtSqGdlBatrYa2vds=; 7:WvxeXjN7a65FRpcnRYV14B4eP9qppKRgVw3QnDihEcifXGO8g4+TIbpFovj2+Z5oJhMA97va7wonCbupb4sp6YU4CB2GTanDxBgftVy7uTOwmohgz8/rdjI9M8X89uYlIXYyRcewaf3uKHTHcht3ArYMtFE/lsA/OyUdQzM+mbRIi138wvfg1Kh9Oyi0TjovRJwhTNIqFs2xjB+K7SNGSa3ZDIKoZrE/486jcVkHhMcpytcItyQfpZwjWxl/obdx x-ms-office365-filtering-correlation-id: 026771a9-0920-40ac-4670-08d61f9bde8b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7193020); SRVR:DM5PR2101MB0727; x-ms-traffictypediagnostic: DM5PR2101MB0727: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(105169848403564)(28532068793085)(89211679590171)(12401385986421)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231355)(2280164)(944501410)(52105095)(2018427008)(93006095)(93001095)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(20161123558120)(201708071742011)(7699051)(76991041); SRVR:DM5PR2101MB0727; BCL:0; PCL:0; RULEID:; SRVR:DM5PR2101MB0727; x-forefront-prvs: 0802ADD973 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(396003)(136003)(376002)(366004)(346002)(199004)(189003)(8676002)(81156014)(25786009)(446003)(2900100001)(102836004)(46003)(52116002)(6346003)(81166006)(11346002)(105586002)(2351001)(8936002)(386003)(4326008)(76176011)(6506007)(10090500001)(5250100002)(7736002)(2616005)(486006)(305945005)(53376002)(6116002)(186003)(16799955002)(1076002)(2501003)(476003)(6916009)(99286004)(22452003)(97736004)(45954006)(71200400001)(71190400001)(72206003)(478600001)(966005)(6306002)(10290500003)(5640700003)(14454004)(36756003)(86362001)(19627235002)(575784001)(6436002)(15188155005)(2906002)(86612001)(106356001)(54906003)(316002)(6486002)(256004)(6512007)(68736007)(5660300001)(53936002)(60540400001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB0727; H:DM5PR2101MB1128.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Christopher.Co@microsoft.com; x-microsoft-antispam-message-info: ywlG8m09JSs2bMugs9EWfoZclntpjiJqLd5p/AISmXJXNd6HLRvh8HLnKinTbTQ8WaGdGGzMPiiX/+yBnfd9GiWZao2q8TwDF6WZXgVT6SpLAf3WYRpBL80KTRPwM18BsT7roaTtWas9HvRtlA9IUYckvmDqP8uTEf0UxLQGtfiQtPn6CuHiJJA6aNXQ5nkasKOWX4EpFphouttmF4aBWXEU0hFbpq1mke8LZsur22KeQgCfPZCw+oUqo8pExDCxnuFKYQmGuJ/wrMoN8kLtkxF4I54pA1DP4tyzpAQDAvr3wOrYoSE34wTjR6w9USTT44eN6prMkP6FxdazzHhZ/9l+R+GTDj8keKC4yFxb3stDM05qwSZr7RypzQWyqFNNJc7QlyYHxV5VW9yGor66SvWaa0NEcsHWjQLclCZVfaEUl837nSpgYehgiqMbfUAqIeLgCdyoU4wvmFvHPz6pMXc9gibYxCkcOmqSreGqEKgcxdP4tH4K3VFRynDPiTQMZPBTbu9pqIk8+3TeQHrIthBI5/xasMgcksHY4TCevhzGvn5a//ODYY0m1keDzpe+ spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 026771a9-0920-40ac-4670-08d61f9bde8b X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Sep 2018 08:26:03.6846 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0727 Subject: [PATCH edk2-platforms 12/27] Silicon/NXP: Add i.MX6 I/O MUX library 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: Fri, 21 Sep 2018 08:26:06 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable This adds support for initializing and manipulating the I/O Pads on NXP i.MX6 SoCs. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Christopher Co Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Michael D Kinney --- Silicon/NXP/iMX6Pkg/Library/iMX6IoMuxLib/iMX6IoMux.c | 151 ++++++++++= ++++++++++ Silicon/NXP/iMX6Pkg/Library/iMX6IoMuxLib/iMX6IoMuxLib.inf | 41 ++++++ 2 files changed, 192 insertions(+) diff --git a/Silicon/NXP/iMX6Pkg/Library/iMX6IoMuxLib/iMX6IoMux.c b/Silicon= /NXP/iMX6Pkg/Library/iMX6IoMuxLib/iMX6IoMux.c new file mode 100644 index 000000000000..7c0c7b54a2fe --- /dev/null +++ b/Silicon/NXP/iMX6Pkg/Library/iMX6IoMuxLib/iMX6IoMux.c @@ -0,0 +1,151 @@ +/** @file +* +* Copyright (c) 2018 Microsoft Corporation. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +* +**/ + +#include + +#include +#include + +#include +#include + +// Muxing functions +VOID +ImxPadConfig ( + IN IMX_PAD Pad, + IN IMX_PADCFG PadConfig + ) +{ + // Configure Mux Control + MmioWrite32 ( + IMX_IOMUXC_BASE + _IMX_PAD_MUX_OFFSET (Pad), + _IMX_PADCFG_MUX_CTL (PadConfig)); + + // Configure Select Input Control + if (_IMX_PADCFG_SEL_INP (PadConfig) !=3D 0) { + DEBUG ((DEBUG_INFO, "Setting INPUT_SELECT %x value %x\n", + _IMX_SEL_INP_REGISTER (_IMX_PADCFG_SEL_INP (PadConfig)), + _IMX_SEL_INP_VALUE (_IMX_PADCFG_SEL_INP (PadConfig)))); + + MmioWrite32 ( + _IMX_SEL_INP_REGISTER (_IMX_PADCFG_SEL_INP (PadConfig)), + _IMX_SEL_INP_VALUE (_IMX_PADCFG_SEL_INP (PadConfig))); + } + + // Configure Pad Control + MmioWrite32 ( + IMX_IOMUXC_BASE + _IMX_PAD_CTL_OFFSET (Pad), + _IMX_PADCFG_PAD_CTL (PadConfig)); +} + +VOID +ImxPadDumpConfig ( + IN CHAR8 *SignalFriendlyName, + IN IMX_PAD Pad + ) +{ + IMX_IOMUXC_MUX_CTL MuxCtl; + IMX_IOMUXC_PAD_CTL PadCtl; + + MuxCtl.AsUint32 =3D MmioRead32 ( + IMX_IOMUXC_BASE + _IMX_PAD_MUX_OFFSET (Pad)); + + DEBUG (( + DEBUG_INIT, + "- %a MUX_CTL(0x%p)=3D0x%08x: MUX_MODE:%d SION:%d | ", + SignalFriendlyName, + IMX_IOMUXC_BASE + _IMX_PAD_MUX_OFFSET (Pad), + MuxCtl.AsUint32, + MuxCtl.Fields.MUX_MODE, + MuxCtl.Fields.SION)); + + PadCtl.AsUint32 =3D MmioRead32 ( + IMX_IOMUXC_BASE + _IMX_PAD_CTL_OFFSET (Pad)); + + DEBUG (( + DEBUG_INIT, + "PAD_CTL(0x%p)=3D0x%08x: SRE:%d DSE:%d SPEED:%d ODE:%d PKE:%d P= UE:%d PUS:%d HYS:%d\n", + IMX_IOMUXC_BASE + _IMX_PAD_CTL_OFFSET (Pad), + PadCtl.AsUint32, + PadCtl.Fields.SRE, + PadCtl.Fields.DSE, + PadCtl.Fields.SPEED, + PadCtl.Fields.ODE, + PadCtl.Fields.PKE, + PadCtl.Fields.PUE, + PadCtl.Fields.PUS, + PadCtl.Fields.HYS)); +} + +// GPIO functions +VOID +ImxGpioDirection ( + IN IMX_GPIO_BANK Bank, + IN UINT32 IoNumber, + IN IMX_GPIO_DIR Direction + ) +{ + volatile IMX_GPIO_REGISTERS *gpioRegisters; + + ASSERT (IoNumber < 32); + + gpioRegisters =3D (IMX_GPIO_REGISTERS *) IMX_GPIO_BASE; + if (Direction =3D=3D IMX_GPIO_DIR_INPUT) { + MmioAnd32 ((UINTN) &gpioRegisters->Banks[Bank - 1].GDIR, ~ (1 << IoNum= ber)); + } else { + MmioOr32 ((UINTN) &gpioRegisters->Banks[Bank - 1].GDIR, 1 << IoNumber)= ; + } +} + +VOID +ImxGpioWrite ( + IN IMX_GPIO_BANK Bank, + IN UINT32 IoNumber, + IN IMX_GPIO_VALUE Value + ) +{ + volatile IMX_GPIO_REGISTERS *gpioRegisters; + + ASSERT (IoNumber < 32); + + gpioRegisters =3D (IMX_GPIO_REGISTERS *) IMX_GPIO_BASE; + if (Value =3D=3D IMX_GPIO_LOW) { + MmioAnd32 ((UINTN) &gpioRegisters->Banks[Bank - 1].DR, ~ (1 << IoNumbe= r)); + } else { + MmioOr32 ((UINTN) &gpioRegisters->Banks[Bank - 1].DR, 1 << IoNumber); + } +} + +IMX_GPIO_VALUE +ImxGpioRead ( + IN IMX_GPIO_BANK Bank, + IN UINT32 IoNumber + ) +{ + volatile IMX_GPIO_REGISTERS *gpioRegisters; + UINT32 Mask; + UINT32 Psr; + + ASSERT (IoNumber < 32); + + gpioRegisters =3D (IMX_GPIO_REGISTERS *) IMX_GPIO_BASE; + Mask =3D (1 << IoNumber); + Psr =3D MmioRead32 ((UINTN) &gpioRegisters->Banks[Bank - 1].PSR); + + if (Psr & Mask) { + return IMX_GPIO_HIGH; + } else { + return IMX_GPIO_LOW; + } +} diff --git a/Silicon/NXP/iMX6Pkg/Library/iMX6IoMuxLib/iMX6IoMuxLib.inf b/Si= licon/NXP/iMX6Pkg/Library/iMX6IoMuxLib/iMX6IoMuxLib.inf new file mode 100644 index 000000000000..84bbbee5c1db --- /dev/null +++ b/Silicon/NXP/iMX6Pkg/Library/iMX6IoMuxLib/iMX6IoMuxLib.inf @@ -0,0 +1,41 @@ +## @file +# +# Copyright (c) 2018 Microsoft Corporation. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD 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 IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x0001001A + BASE_NAME =3D iMX6IoMuxLib + FILE_GUID =3D FA41BEF0-0666-4C07-9EC3-47F61C36EDBE + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D iMX6IoMuxLib + +[Packages] + ArmPkg/ArmPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/NXP/iMX6Pkg/iMX6Pkg.dec + Silicon/NXP/iMXPlatformPkg/iMXPlatformPkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + IoLib + TimerLib + +[Sources.common] + iMX6IoMux.c + + [FixedPcd] + giMXPlatformTokenSpaceGuid.PcdGpioBankMemoryRange --=20 2.16.2.gvfs.1.33.gf5370f1