From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.107.71.124; helo=nam05-by2-obe.outbound.protection.outlook.com; envelope-from=christopher.co@microsoft.com; receiver=edk2-devel@lists.01.org Received: from NAM05-BY2-obe.outbound.protection.outlook.com (mail-eopbgr710124.outbound.protection.outlook.com [40.107.71.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D41842098EABA for ; Thu, 19 Jul 2018 23:33:55 -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=vq1OGK4iK7ho4vQ7ujz0JVRoR+3DNS3hLD8UaG3OkvU=; b=o/DMB2PJ/uUH5RlvuViPX9Fw2Du0aau0qMTZGdfv+5U/EoI4lgFf4GzYb20ra5QZImfgkN8ZASkp3REhLDvrLQqdc9iTruqk+GmmFJ9Egk4rtKQmp1jY93NAcAzvI6wzsEjc+RRha1632+oAp+whAV9F5LqE11YnqTZUShE3YVw= Received: from SN6PR2101MB1136.namprd21.prod.outlook.com (52.132.114.25) by SN6PR2101MB1133.namprd21.prod.outlook.com (52.132.114.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.0; Fri, 20 Jul 2018 06:33:54 +0000 Received: from SN6PR2101MB1136.namprd21.prod.outlook.com ([fe80::78f8:214:33a:3c4]) by SN6PR2101MB1136.namprd21.prod.outlook.com ([fe80::78f8:214:33a:3c4%5]) with mapi id 15.20.0995.008; Fri, 20 Jul 2018 06:33:54 +0000 From: Chris Co To: "edk2-devel@lists.01.org" CC: Ard Biesheuvel , Leif Lindholm , Michael D Kinney Thread-Topic: [PATCH edk2-platforms 07/13] Silicon/NXP: Add i.MX6 I/O MUX library Thread-Index: AQHUH/OhcsuxuoDJsUGCP0w6Y+edFg== Date: Fri, 20 Jul 2018 06:33:54 +0000 Message-ID: <20180720063328.26856-8-christopher.co@microsoft.com> References: <20180720063328.26856-1-christopher.co@microsoft.com> In-Reply-To: <20180720063328.26856-1-christopher.co@microsoft.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: CY4PR18CA0029.namprd18.prod.outlook.com (2603:10b6:903:9a::15) To SN6PR2101MB1136.namprd21.prod.outlook.com (2603:10b6:805:4::25) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [2001:4898:80e8:a:75ac:13c7:7dde:5215] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; SN6PR2101MB1133; 6:gBeqC5osBE+a8mdKbYahaUIlhSRw/9ZE0gEfQ8zV8E5BOkwawlyQq+SwvEpxJdjGFy4FCTXw1473PKy7d9hoV2BvEdtc3DU38CpfLag4N1KdE5Z1nJTCaxiltwIIhuQqrV/JD78MZuvlXgaZ5RIPTEk3Ha+P4N5hTZ/mchMcq8+4z2czUADMgPpwFzW820h0TRwCmNHSqcuEzvYczx9LtBfvc/jtqbgow234V711nGypTFLCDdOOqTt25ff1ag/OEolG65+ONqPCc0S0PTW3H1eqCWt9QrpsLaSLvygtQmrvsUTce8CNsj1LvEgeSn/DCezvrgKsZzPvDBDf+x1IDfP47diM4HC/CDXeDWV+K4PgToEDhEJm8cJIFjSAPfp0/U18OPJtcUGHCIrDRu0Z8fe8mus0krnnjxIYsjOBcwYs+1PK3HMp6ru2hk88qKzsFUN2GUJ7E7nOGtgIojNwHQ==; 5:VS9DqLWs+IS3YgdrSR0cjbG/odZPVR+vJhtQZkrOX2EvcYR5iE/HyG1M/CULih0fdmJ/fyR4FVbV8TLeBMEWhE4OiQPjCIQzZh3NbpdVq5pBAlPXUWp/WA+UtHqbHzB7aUPz3pe4cAq8B5tSHzxgc9x898amN1IdKFGcGeR5NLE=; 7:IRy+6riqcyfNNN4oztofsi1KgiycW63K7AbGCVCEYy0yuN8Z90yY/amNnZ2qKdIxxb6izgkawmNsD1UaRD+Ci0CD8OPjmCHYxqLD80jobQB/gbwB4BMCGUa9pB2jxkFRoVxmvwJH6cVmSN1xo+L2PNOsME+s+E6NcCK37+fjfURbqc4abOkEurDmf39C8u+CHcOtXY1PmmvH/ZUEZzWHrw4fvUuNqsWYjth0uh2W9xjLDjYPW73xr5PA20Mhj1BI x-ms-office365-filtering-correlation-id: 956992d5-794e-4b3f-808b-08d5ee0ac363 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600067)(711020)(4618075)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7193020); SRVR:SN6PR2101MB1133; x-ms-traffictypediagnostic: SN6PR2101MB1133: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Christopher.Co@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231311)(944501410)(52105095)(2018427008)(93006095)(93001095)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123560045)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:SN6PR2101MB1133; BCL:0; PCL:0; RULEID:; SRVR:SN6PR2101MB1133; x-forefront-prvs: 073966E86B x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(376002)(366004)(346002)(136003)(39860400002)(189003)(199004)(52116002)(16799955002)(46003)(2906002)(2900100001)(15188155005)(36756003)(97736004)(386003)(256004)(99286004)(19627235002)(86612001)(6506007)(86362001)(186003)(76176011)(10090500001)(102836004)(1076002)(6306002)(6512007)(8936002)(6486002)(2616005)(476003)(5660300001)(486006)(478600001)(8676002)(6116002)(81156014)(81166006)(25786009)(4326008)(5640700003)(53376002)(53936002)(68736007)(6436002)(2501003)(10290500003)(22452003)(2351001)(7736002)(305945005)(5250100002)(6916009)(54906003)(14454004)(11346002)(72206003)(106356001)(966005)(316002)(446003)(105586002); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR2101MB1133; H:SN6PR2101MB1136.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Bui18Yql9hhiDPsKdSgdyAeDzzqTKcBZaxibJZQDqPZUm54vJoDExbaF2AyVurbVEBnXMmUrFgVj9V0pr0hAvoaFMBFlQZrycgBIyVo7pyLKDss8DNkl6pCxLhpJn8i3rsY25ZpKu+zcluNc+3XFu+nv9okpdhKC91sPGnWf5buta5/GnIna00PtXNRIQBh/2JbO15cCelg72hsOeq/Sds46C4rtuyEkAmOOgVmdz1SmKS3juntlE/qU1taM8qMooDefUjurXHrV9TlICxvmdceHwuZ89biWLolqM1Kf52Rt96BFja1x8/N3AoX09UyAoF+t03mpCB4ZcREQm3Le0VVVc2cOyC+D4Y6HNC7NC1w= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 956992d5-794e-4b3f-808b-08d5ee0ac363 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jul 2018 06:33:54.2954 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR2101MB1133 Subject: [PATCH edk2-platforms 07/13] Silicon/NXP: Add i.MX6 I/O MUX library X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jul 2018 06:33:56 -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 | 163 ++++++++++= ++++++++++ Silicon/NXP/iMX6Pkg/Library/iMX6IoMuxLib/iMX6IoMuxLib.inf | 41 +++++ 2 files changed, 204 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..573f6c581a63 --- /dev/null +++ b/Silicon/NXP/iMX6Pkg/Library/iMX6IoMuxLib/iMX6IoMux.c @@ -0,0 +1,163 @@ +/** @file +* +* 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 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 ( + IMX_PAD Pad, + IMX_PADCFG PadConfig + ) +{ + _Static_assert( + (IOMUXC_SELECT_INPUT_UPPER_BOUND - IOMUXC_SELECT_INPUT_BASE_ADDRESS) <= (0xff * 4), + "Too many SELECT_INPUT registers values to encode in IMX_PADCFG"); + + // + // 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 ( + char *SignalFriendlyName, + IMX_PAD Pad + ) +{ + IMX_IOMUXC_MUX_CTL muxCtl; + 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)); + + IMX_IOMUXC_PAD_CTL padCtl; + 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 PUE:%d P= US:%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 ( + IMX_GPIO_BANK Bank, + UINT32 IoNumber, + IMX_GPIO_DIR Direction + ) +{ + volatile IMX_GPIO_REGISTERS *gpioRegisters =3D + (IMX_GPIO_REGISTERS *) IMX_GPIO_BASE; + + ASSERT (IoNumber < 32); + + if (Direction =3D=3D IMX_GPIO_DIR_INPUT) { + MmioAnd32 ((UINTN) &gpioRegisters->Banks[Bank - 1].GDIR, ~(1 << IoNumb= er)); + } else { + MmioOr32 ((UINTN) &gpioRegisters->Banks[Bank - 1].GDIR, 1 << IoNumber)= ; + } +} + +VOID +ImxGpioWrite ( + IMX_GPIO_BANK Bank, + UINT32 IoNumber, + IMX_GPIO_VALUE Value + ) +{ + volatile IMX_GPIO_REGISTERS *gpioRegisters =3D + (IMX_GPIO_REGISTERS *) IMX_GPIO_BASE; + + ASSERT (IoNumber < 32); + + if (Value =3D=3D IMX_GPIO_LOW) { + MmioAnd32 ((UINTN) &gpioRegisters->Banks[Bank - 1].DR, ~(1 << IoNumber= )); + } else { + MmioOr32 ((UINTN) &gpioRegisters->Banks[Bank - 1].DR, 1 << IoNumber); + } +} + +IMX_GPIO_VALUE +ImxGpioRead ( + IMX_GPIO_BANK Bank, + UINT32 IoNumber + ) +{ + volatile IMX_GPIO_REGISTERS *gpioRegisters =3D + (IMX_GPIO_REGISTERS *) IMX_GPIO_BASE; + + ASSERT (IoNumber < 32); + + UINT32 Mask =3D (1 << IoNumber); + UINT32 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..8af5502be4d8 --- /dev/null +++ b/Silicon/NXP/iMX6Pkg/Library/iMX6IoMuxLib/iMX6IoMuxLib.inf @@ -0,0 +1,41 @@ +## @file +# +# 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 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 0x00010005 + 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] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPkg/ArmPkg.dec + Silicon/NXP/iMXPlatformPkg/iMXPlatformPkg.dec + Silicon/NXP/iMX6Pkg/iMX6Pkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + IoLib + TimerLib + +[Sources.common] + iMX6IoMux.c + + [FixedPcd] + giMXPlatformTokenSpaceGuid.PcdGpioBankMemoryRange --=20 2.16.2.gvfs.1.33.gf5370f1