From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.34.136; helo=nam01-by2-obe.outbound.protection.outlook.com; envelope-from=christopher.co@microsoft.com; receiver=edk2-devel@lists.01.org Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0136.outbound.protection.outlook.com [104.47.34.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 4A083202E5446 for ; Wed, 18 Jul 2018 21:11:25 -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=cS6MO30oa4HBtmuLTk5zK6L9g3WR7xh3gsjegqR+jEg=; b=dElJZ9xD3q6kXoLPPuoZUg6B1TDzg9LFvBwy0ksVJJJtx2E6UtDEFbVd8ulLQh5z5jPPWIPQDKRHrS5Zu59wEx4WEt3WfBbM13j5hMX2dUzlq3mOu3dFlxdIDlOCVGFSnm0/d0J40rCwknut9m53WQNjqumRHQdyU8zO+PgasFY= Received: from DM5PR2101MB1128.namprd21.prod.outlook.com (52.132.133.20) by DM5PR2101MB0983.namprd21.prod.outlook.com (52.132.133.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.0; Thu, 19 Jul 2018 04:11:23 +0000 Received: from DM5PR2101MB1128.namprd21.prod.outlook.com ([fe80::b4d3:dabb:9372:9740]) by DM5PR2101MB1128.namprd21.prod.outlook.com ([fe80::b4d3:dabb:9372:9740%2]) with mapi id 15.20.0995.008; Thu, 19 Jul 2018 04:11:23 +0000 From: Chris Co To: "edk2-devel@lists.01.org" CC: Ard Biesheuvel , Leif Lindholm , Michael D Kinney Thread-Topic: [PATCH edk2-platforms 4/7] Silicon/NXP: Add UART library support for iMX platforms Thread-Index: AQHUHxaN23ZREd7DFUScFwOjUnKSeA== Date: Thu, 19 Jul 2018 04:11:23 +0000 Message-ID: <20180719041103.9072-5-christopher.co@microsoft.com> References: <20180719041103.9072-1-christopher.co@microsoft.com> In-Reply-To: <20180719041103.9072-1-christopher.co@microsoft.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BN6PR11CA0037.namprd11.prod.outlook.com (2603:10b6:404:4b::23) To DM5PR2101MB1128.namprd21.prod.outlook.com (2603:10b6:4:a8::20) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [2001:4898:80e8:1:d144:e4c:c05:68bd] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR2101MB0983; 6:Imju5a8F7ZrkYZw6K+CQvxWYJFaoaIjsxljN0fqIEGjjxH/51+vbIM3tTmI0ECeVD9ovNwki5ZDbbKWyL4YL7CaddhFcEr20s2Wf4NwhZZOnzFcfQsI7Zg7Hw4PbL1TNz4F7NMHK6kBI5O1i5JsksWbhCPlmRSNjxXO7tVJZCJ87t2cc9c7BBknpomLEa9DVU0eZDh1MD3s8UP+CXyMMC71y3KOnzX8QfX6DiGVyuYKjoZJLJS0Oi4sAR1nEHPlSymS2GmuT+0ZJVDBg0GtIFvSDaAaVJQoDDBnrAwoPHfrs9bdBr5hptq7JNGF2tE/ee0qtqszdB1xhPOLc4zw9B+aBH62O6y6kd6mBaEc2Mhks23uc6AonUwwlReCPcmX2z3bJEYMbb1G5cbjS5iYR9eL0UZUbiNZjXkja8RNhGMyiU4DfkhmAXl2by+FcOYtQ2bBvgJbz6/YRSDsC/8pBBw==; 5:C+xor4O/PvMmRYVoFJoFCL4sM3SYxIta5YzkR5Bv2pqMXXYBOzYk0RqSDf54YAgGVn/iXsklJ4pUzT/FSmCI+0x5c+ipoAmN7JJzAHGVdeGrCwAvI5rd0mR6xEZ3nFSzFLGdRd2Ddd8bFJj4gaWIRxlsiXOCiJgL/mwsoxRAZpY=; 7:7O/YC02Xbv8iBSjEDgma/N1CkzDjmcxXfcYW4iu3bavPETUY0Eq8CcLqLfOYdjg7DQ9P4y3byaAKE/UDhTxck7r04SVLvBYi8iMVp1farAzdfsHiCAVmApTm5674Aju9I25yzSDPqVpjn4iVInuka6XpyI7gEzSY14FNCjZtnCxMqBtf566Rmx06Lzj/j9W+JiMRXReQpVpFQZy1k20+8ddWzhIki6MOY7opTXCNxox9JVcNpYTKsQmJ+1TeACK8 x-ms-office365-filtering-correlation-id: 8905f6c2-e2d8-4b7d-b9ef-08d5ed2db039 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:DM5PR2101MB0983; x-ms-traffictypediagnostic: DM5PR2101MB0983: 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)(35073007944872)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231311)(944501410)(52105095)(2018427008)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(20161123562045)(20161123560045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:DM5PR2101MB0983; BCL:0; PCL:0; RULEID:; SRVR:DM5PR2101MB0983; x-forefront-prvs: 0738AF4208 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(396003)(346002)(366004)(376002)(39860400002)(189003)(199004)(25786009)(8936002)(4326008)(53936002)(386003)(53376002)(6506007)(68736007)(52116002)(86612001)(6916009)(76176011)(5640700003)(6512007)(10090500001)(6436002)(106356001)(6306002)(6486002)(5660300001)(105586002)(256004)(2351001)(8676002)(53946003)(81166006)(7736002)(305945005)(81156014)(36756003)(478600001)(5250100002)(99286004)(1076002)(14454004)(46003)(54906003)(186003)(2501003)(10290500003)(16799955002)(72206003)(966005)(22452003)(102836004)(486006)(2900100001)(2906002)(6116002)(446003)(2616005)(476003)(316002)(15188155005)(86362001)(11346002)(97736004)(579004); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB0983; H:DM5PR2101MB1128.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: K8dhxFWmSTESIq3qZiAxarY3R2dQ9eE+qJI331pZDPg5LVmwfiXFNl3SLG/DOpps08oKB4TCos0fhji3BBgIcV/DDaWnPTC4oa0ktEXtsLhaPTmyFUGA/tNuULA078pWSOiSZ4caMlRWPjSZvfHeR8kBFrUMCLQpcMtraNdmaBvZE+TRlWLZI/j2aIqbkMu3T5ACflvawexpxnYZw40VNzafjOOMQiy8AlkkN9n9z/ZGPltJzBDWn1DX1GGxjnjPGGnhx76Gvdb/u8cl8NuDIWjZpb3PSPAVN0hifL/vKVrtu2P40jxcRcTW5NkRDErA0dHFA3yvUzFkU0dnIMoL/g== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8905f6c2-e2d8-4b7d-b9ef-08d5ed2db039 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jul 2018 04:11:23.4146 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0983 Subject: [PATCH edk2-platforms 4/7] Silicon/NXP: Add UART library support for iMX platforms 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: Thu, 19 Jul 2018 04:11:25 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable This adds support for interact with the UART controller on NXP i.MX platforms. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Christopher Co Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Michael D Kinney --- Silicon/NXP/iMXPlatformPkg/Include/iMXUart.h = | 225 ++++++++++++++++++ Silicon/NXP/iMXPlatformPkg/Library/UartSerialPortLib/UartSerialPortLib.c = | 242 ++++++++++++++++++++ Silicon/NXP/iMXPlatformPkg/Library/UartSerialPortLib/UartSerialPortLib.inf= | 41 ++++ 3 files changed, 508 insertions(+) diff --git a/Silicon/NXP/iMXPlatformPkg/Include/iMXUart.h b/Silicon/NXP/iMX= PlatformPkg/Include/iMXUart.h new file mode 100644 index 000000000000..56b286e6250f --- /dev/null +++ b/Silicon/NXP/iMXPlatformPkg/Include/iMXUart.h @@ -0,0 +1,225 @@ +/** @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. +* +**/ + +#ifndef _IMXUART_H_ +#define _IMXUART_H_ + +// +// UART Receiver Register bit definitions +// +enum MX6UART_RXD { + MX6UART_RXD_RX_DATA_MASK =3D (0xff << 0), + MX6UART_RXD_PRERR =3D (1 << 10), + MX6UART_RXD_BRK =3D (1 << 11), + MX6UART_RXD_FRMERR =3D (1 << 12), + MX6UART_RXD_OVRRUN =3D (1 << 13), + MX6UART_RXD_ERR =3D (1 << 14), + MX6UART_RXD_CHARRDY =3D (1 << 15), +}; + +// +// UART Control Register 1 bit definitions +// +enum MX6UART_UCR1 { + MX6UART_UCR1_UARTEN =3D (1 << 0), + MX6UART_UCR1_DOZE =3D (1 << 1), + MX6UART_UCR1_ATDMAEN =3D (1 << 2), + MX6UART_UCR1_TXDMAEN =3D (1 << 3), + MX6UART_UCR1_SNDBRK =3D (1 << 4), + MX6UART_UCR1_RTSDEN =3D (1 << 5), + MX6UART_UCR1_TXMPTYEN =3D (1 << 6), + MX6UART_UCR1_IREN =3D (1 << 7), + MX6UART_UCR1_RXDMAEN =3D (1 << 8), + MX6UART_UCR1_RRDYEN =3D (1 << 9), + MX6UART_UCR1_ICD_MASK =3D (3 << 10), + MX6UART_UCR1_ICD_4 =3D (0 << 10), + MX6UART_UCR1_ICD_8 =3D (1 << 10), + MX6UART_UCR1_ICD_16 =3D (2 << 10), + MX6UART_UCR1_ICD_32 =3D (3 << 10), + MX6UART_UCR1_IDEN =3D (1 << 12), + MX6UART_UCR1_TRDYEN =3D (1 << 13), + MX6UART_UCR1_ADBR =3D (1 << 14), + MX6UART_UCR1_ADEN =3D (1 << 15), +}; + +// +// UART Control Register 2 bit definitions +// +enum MX6UART_UCR2 { + MX6UART_UCR2_SRST =3D (1 << 0), + MX6UART_UCR2_RXEN =3D (1 << 1), + MX6UART_UCR2_TXEN =3D (1 << 2), + MX6UART_UCR2_ATEN =3D (1 << 3), + MX6UART_UCR2_RTSEN =3D (1 << 4), + MX6UART_UCR2_WS =3D (1 << 5), + MX6UART_UCR2_STPB =3D (1 << 6), + MX6UART_UCR2_PROE =3D (1 << 7), + MX6UART_UCR2_PREN =3D (1 << 8), + MX6UART_UCR2_RTEC_MASK =3D (3 << 9), + MX6UART_UCR2_RTEC_RISING =3D (0 << 9), + MX6UART_UCR2_RTEC_FALLING =3D (1 << 9), + MX6UART_UCR2_RTEC_BOTH =3D (2 << 9), + MX6UART_UCR2_ESCEN =3D (1 << 11), + MX6UART_UCR2_CTS =3D (1 << 12), + MX6UART_UCR2_CTSC =3D (1 << 13), + MX6UART_UCR2_IRTS =3D (1 << 14), + MX6UART_UCR2_ESCI =3D (1 << 15), +}; + +// +// UART Control Register 3 bit definitions +// +enum MX6UART_UCR3 { + MX6UART_UCR3_ACIEN =3D (1 << 0), + MX6UART_UCR3_INVT =3D (1 << 1), + MX6UART_UCR3_RXDMUXSEL =3D (1 << 2), + MX6UART_UCR3_DTRDEN =3D (1 << 3), + MX6UART_UCR3_AWAKEN =3D (1 << 4), + MX6UART_UCR3_AIRINTEN =3D (1 << 5), + MX6UART_UCR3_RXDSEN =3D (1 << 6), + MX6UART_UCR3_ADNIMP =3D (1 << 7), + MX6UART_UCR3_RI =3D (1 << 8), + MX6UART_UCR3_DCD =3D (1 << 9), + MX6UART_UCR3_DSR =3D (1 << 10), + MX6UART_UCR3_FRAERREN =3D (1 << 11), + MX6UART_UCR3_PARERREN =3D (1 << 12), + MX6UART_UCR3_DTREN =3D (1 << 13), + MX6UART_UCR3_DPEC_MASK =3D (3 << 14), + MX6UART_UCR3_DPEC_RISING =3D (0 << 14), + MX6UART_UCR3_DPEC_FALLING =3D (1 << 14), + MX6UART_UCR3_DPEC_BOTH =3D (2 << 14), +}; + +// +// UART Control Register 4 bit definitions +// +enum MX6UART_UCR4 { + MX6UART_UCR4_DREN =3D (1 << 0), + MX6UART_UCR4_OREN =3D (1 << 1), + MX6UART_UCR4_BKEN =3D (1 << 2), + MX6UART_UCR4_TCEN =3D (1 << 3), + MX6UART_UCR4_LPBYP =3D (1 << 4), + MX6UART_UCR4_IRSC =3D (1 << 5), + MX6UART_UCR4_IDDMAEN =3D (1 << 6), + MX6UART_UCR4_WKEN =3D (1 << 7), + MX6UART_UCR4_ENIRI =3D (1 << 8), + MX6UART_UCR4_INVR =3D (1 << 9), + MX6UART_UCR4_CTSTL_MASK =3D (0x3f << 10), + MX6UART_UCR4_CTSTL_SHIFT =3D 10, +}; + +// +// UART FIFO Control Register bit definitions +// +enum MX6UART_UFCR { + MX6UART_UFCR_RXTL_MASK =3D (0x3f << 0), + MX6UART_UFCR_RXTL_SHIFT =3D 0, + MX6UART_UFCR_DCEDTE =3D (1 << 6), + MX6UART_UFCR_RFDIV_MASK =3D (7 << 7), + MX6UART_UFCR_RFDIV_6 =3D (0 << 7), + MX6UART_UFCR_RFDIV_5 =3D (1 << 7), + MX6UART_UFCR_RFDIV_4 =3D (2 << 7), + MX6UART_UFCR_RFDIV_3 =3D (3 << 7), + MX6UART_UFCR_RFDIV_2 =3D (4 << 7), + MX6UART_UFCR_RFDIV_1 =3D (5 << 7), + MX6UART_UFCR_RFDIV_7 =3D (6 << 7), + MX6UART_UFCR_TXTL_MASK =3D (0x3f << 10), + MX6UART_UFCR_TXTL_SHIFT =3D 10, +}; + +// +// UART Status Register 1 bit definitions +// +enum MX6UART_USR1 { + MX6UART_USR1_SAD =3D (1 << 3), + MX6UART_USR1_AWAKE =3D (1 << 4), + MX6UART_USR1_AIRINT =3D (1 << 5), + MX6UART_USR1_RXDS =3D (1 << 6), + MX6UART_USR1_DTRD =3D (1 << 7), + MX6UART_USR1_AGTIM =3D (1 << 8), + MX6UART_USR1_RRDY =3D (1 << 9), + MX6UART_USR1_FRAMERR =3D (1 << 10), + MX6UART_USR1_ESCF =3D (1 << 11), + MX6UART_USR1_RTSD =3D (1 << 12), + MX6UART_USR1_TRDY =3D (1 << 13), + MX6UART_USR1_RTSS =3D (1 << 14), + MX6UART_USR1_PARITYERR =3D (1 << 15), +}; + +// +// UART Status Register 2 bit definitions +// +enum MX6UART_USR2 { + MX6UART_USR2_RDR =3D (1 << 0), + MX6UART_USR2_ORE =3D (1 << 1), + MX6UART_USR2_BRCD =3D (1 << 2), + MX6UART_USR2_TXDC =3D (1 << 3), + MX6UART_USR2_RTSF =3D (1 << 4), + MX6UART_USR2_DCDIN =3D (1 << 5), + MX6UART_USR2_DCDDELT =3D (1 << 6), + MX6UART_USR2_WAKE =3D (1 << 7), + MX6UART_USR2_IRINT =3D (1 << 8), + MX6UART_USR2_RIIN =3D (1 << 9), + MX6UART_USR2_RIDLET =3D (1 << 10), + MX6UART_USR2_ACST =3D (1 << 11), + MX6UART_USR2_IDLE =3D (1 << 12), + MX6UART_USR2_DTRF =3D (1 << 13), + MX6UART_USR2_TXFE =3D (1 << 14), + MX6UART_USR2_ADET =3D (1 << 15), +}; + +// +// UART Test Register bit definitions +// +enum MX6UART_UTS { + MX6UART_UTS_SOFTRST =3D (1 << 0), + MX6UART_UTS_RXFULL =3D (1 << 3), + MX6UART_UTS_TXFULL =3D (1 << 4), + MX6UART_UTS_RXEMPTY =3D (1 << 5), + MX6UART_UTS_TXEMPTY =3D (1 << 6), + MX6UART_UTS_RXDBG =3D (1 << 9), + MX6UART_UTS_LOOPIR =3D (1 << 10), + MX6UART_UTS_DBGEN =3D (1 << 11), + MX6UART_UTS_LOOP =3D (1 << 12), + MX6UART_UTS_FRCPERR =3D (1 << 13), +}; + +// +// Size of RX and TX FIFOs +// +enum { MX6UART_FIFO_COUNT =3D 32 }; + +typedef struct _MX6UART_REGISTERS { + UINT32 Rxd; // 0x00: UART Receiver Register + UINT32 reserved1[15]; + UINT32 Txd; // 0x40: UART Transmitter Register + UINT32 reserved2[15]; + UINT32 Ucr1; // 0x80: UART Control Register 1 + UINT32 Ucr2; // 0x84: UART Control Register 2 + UINT32 Ucr3; // 0x88: UART Control Register 3 + UINT32 Ucr4; // 0x8C: UART Control Register 4 + UINT32 Ufcr; // 0x90: UART FIFO Control Register + UINT32 Usr1; // 0x94: UART Status Register 1 + UINT32 Usr2; // 0x98: UART Status Register 2 + UINT32 Uesc; // 0x9C: UART Escape Character Register + UINT32 Utim; // 0xA0: UART Escape Timer Register + UINT32 Ubir; // 0xA4: UART BRM Incremental Register + UINT32 Ubmr; // 0xA8: UART BRM Modulator Register (UAR= T1_UBMR) + UINT32 Ubrc; // 0xAC: UART Baud Rate Count Register + UINT32 Onems; // 0xB0: UART One Millisecond Register + UINT32 Uts; // 0xB4: UART Test Register + UINT32 Umcr; // 0xB8: UART RS-485 Mode Control Registe= r +} MX6UART_REGISTERS; + +#endif // _IMXUART_H_ diff --git a/Silicon/NXP/iMXPlatformPkg/Library/UartSerialPortLib/UartSeria= lPortLib.c b/Silicon/NXP/iMXPlatformPkg/Library/UartSerialPortLib/UartSeria= lPortLib.c new file mode 100644 index 000000000000..f591fe7967b9 --- /dev/null +++ b/Silicon/NXP/iMXPlatformPkg/Library/UartSerialPortLib/UartSerialPortLi= b.c @@ -0,0 +1,242 @@ +/** @file + + Copyright (c) 2006 - 2008, Intel Corporation + Copyright (c) Microsoft Corporation. All rights reserved. + + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e 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 IMP= LIED. + +**/ + +#include +#include +#include +#include + + +/** + Initialize the serial device hardware. + + If no initialization is required, then return RETURN_SUCCESS. + If the serial device was successfully initialized, then return RETURN_SU= CCESS. + If the serial device could not be initialized, then return RETURN_DEVICE= _ERROR. + + @retval RETURN_SUCCESS The serial device was initialized. + @retval RETURN_DEVICE_ERROR The serial device could not be initialized= . + +**/ +RETURN_STATUS +EFIAPI +SerialPortInitialize ( + VOID + ) +{ + MX6UART_REGISTERS *UartBase =3D + (MX6UART_REGISTERS *)FixedPcdGet32(PcdSerialRegisterBase); + + UINT32 Ucr1 =3D MmioRead32 ((UINTN)&UartBase->Ucr1); + if ((Ucr1 & MX6UART_UCR1_UARTEN) =3D=3D 0) { + // UART should have been initialized by previous boot stage + return RETURN_DEVICE_ERROR; + } + + return RETURN_SUCCESS; +} + +/** + Write data from buffer to serial device. + + Writes NumberOfBytes data bytes from Buffer to the serial device. + The number of bytes actually written to the serial device is returned. + If the return value is less than NumberOfBytes, then the write operation= failed. + If Buffer is NULL, then ASSERT(). + If NumberOfBytes is zero, then return 0. + + @param Buffer Pointer to the data buffer to be written. + @param NumberOfBytes Number of bytes to written to the serial device= . + + @retval 0 NumberOfBytes is 0. + @retval >0 The number of bytes written to the serial devic= e. + If this value is less than NumberOfBytes, then = the read operation failed. + +**/ +UINTN +EFIAPI +SerialPortWrite ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + MX6UART_REGISTERS *UartBase =3D + (MX6UART_REGISTERS *)FixedPcdGet32(PcdSerialRegisterBase); + + UINTN BytesSent =3D 0; + + while (BytesSent < NumberOfBytes) { + + // Check if FIFO is full and wait if it is. + while ((MmioRead32 ((UINTN)&UartBase->Uts) & MX6UART_UTS_TXFULL) != =3D 0); + + MmioWrite32 ((UINTN)&UartBase->Txd, Buffer[BytesSent]); + BytesSent++; + } + + return BytesSent; +} + + +/** + Read data from serial device and save the datas in buffer. + + Reads NumberOfBytes data bytes from a serial device into the buffer + specified by Buffer. The number of bytes actually read is returned. + If the return value is less than NumberOfBytes, then the rest operation = failed. + If Buffer is NULL, then ASSERT(). + If NumberOfBytes is zero, then return 0. + + @param Buffer Pointer to the data buffer to store the data re= ad from the serial device. + @param NumberOfBytes Number of bytes which will be read. + + @retval 0 Read data failed, No data is to be read. + @retval >0 Aactual number of bytes read from serial device= . + +**/ +UINTN +EFIAPI +SerialPortRead ( + OUT UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + MX6UART_REGISTERS *UartBase =3D + (MX6UART_REGISTERS *)FixedPcdGet32(PcdSerialRegisterBase); + + UINTN BytesRead =3D 0; + UINT32 Rxd; + + while (BytesRead < NumberOfBytes) { + Rxd =3D MmioRead32 ((UINTN)&UartBase->Rxd); + if ((Rxd & MX6UART_RXD_CHARRDY) =3D=3D 0) { + break; + } + + Buffer[BytesRead] =3D (UINT8)(Rxd & MX6UART_RXD_RX_DATA_MASK); + BytesRead++; + } + + return BytesRead; +} + +/** + Polls a serial device to see if there is any data waiting to be read. + + Polls a serial device to see if there is any data waiting to be read. + If there is data waiting to be read from the serial device, then TRUE is= returned. + If there is no data waiting to be read from the serial device, then FALS= E is returned. + + @retval TRUE Data is waiting to be read from the serial devi= ce. + @retval FALSE There is no data waiting to be read from the se= rial device. + +**/ +BOOLEAN +EFIAPI +SerialPortPoll ( + VOID + ) +{ + MX6UART_REGISTERS *UartBase =3D + (MX6UART_REGISTERS *)FixedPcdGet32(PcdSerialRegisterBase); + + UINT32 Usr2 =3D MmioRead32 ((UINTN)&UartBase->Usr2); + + return (Usr2 & MX6UART_USR2_RDR) !=3D 0; +} +/** + Sets the control bits on a serial device. + + @param Control Sets the bits of Control that are settable= . + + @retval RETURN_SUCCESS The new control bits were set on the seria= l device. + @retval RETURN_UNSUPPORTED The serial device does not support this op= eration. + @retval RETURN_DEVICE_ERROR The serial device is not functioning corre= ctly. + +**/ +RETURN_STATUS +EFIAPI +SerialPortSetControl ( + IN UINT32 Control + ) +{ + return RETURN_UNSUPPORTED; +} + +/** + Retrieve the status of the control bits on a serial device. + + @param Control A pointer to return the current control si= gnals from the serial device. + + @retval RETURN_SUCCESS The control bits were read from the serial= device. + @retval RETURN_UNSUPPORTED The serial device does not support this op= eration. + @retval RETURN_DEVICE_ERROR The serial device is not functioning corre= ctly. + +**/ +RETURN_STATUS +EFIAPI +SerialPortGetControl ( + OUT UINT32 *Control + ) +{ + return RETURN_UNSUPPORTED; +} + +/** + Sets the baud rate, receive FIFO depth, transmit/receice time out, parit= y, + data bits, and stop bits on a serial device. + + @param BaudRate The requested baud rate. A BaudRate value of 0= will use the + device's default interface speed. + On output, the value actually set. + @param ReveiveFifoDepth The requested depth of the FIFO on the receive= side of the + serial interface. A ReceiveFifoDepth value of = 0 will use + the device's default FIFO depth. + On output, the value actually set. + @param Timeout The requested time out for a single character = in microseconds. + This timeout applies to both the transmit and = receive side of the + interface. A Timeout value of 0 will use the d= evice's default time + out value. + On output, the value actually set. + @param Parity The type of parity to use on this serial devic= e. A Parity value of + DefaultParity will use the device's default pa= rity value. + On output, the value actually set. + @param DataBits The number of data bits to use on the serial d= evice. A DataBits + vaule of 0 will use the device's default data = bit setting. + On output, the value actually set. + @param StopBits The number of stop bits to use on this serial = device. A StopBits + value of DefaultStopBits will use the device's= default number of + stop bits. + On output, the value actually set. + + @retval RETURN_SUCCESS The new attributes were set on the ser= ial device. + @retval RETURN_UNSUPPORTED The serial device does not support thi= s operation. + @retval RETURN_INVALID_PARAMETER One or more of the attributes has an u= nsupported value. + @retval RETURN_DEVICE_ERROR The serial device is not functioning c= orrectly. + +**/ +RETURN_STATUS +EFIAPI +SerialPortSetAttributes ( + IN OUT UINT64 *BaudRate, + IN OUT UINT32 *ReceiveFifoDepth, + IN OUT UINT32 *Timeout, + IN OUT EFI_PARITY_TYPE *Parity, + IN OUT UINT8 *DataBits, + IN OUT EFI_STOP_BITS_TYPE *StopBits + ) +{ + return RETURN_UNSUPPORTED; +} diff --git a/Silicon/NXP/iMXPlatformPkg/Library/UartSerialPortLib/UartSeria= lPortLib.inf b/Silicon/NXP/iMXPlatformPkg/Library/UartSerialPortLib/UartSer= ialPortLib.inf new file mode 100644 index 000000000000..3fc4f587e65c --- /dev/null +++ b/Silicon/NXP/iMXPlatformPkg/Library/UartSerialPortLib/UartSerialPortLi= b.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 SerialPortLib + FILE_GUID =3D C22D85E6-8B3E-4c05-AA5B-5732F3ACD055 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SerialPortLib + +[Sources.common] + UartSerialPortLib.c + +[LibraryClasses] + PcdLib + BaseMemoryLib + CacheMaintenanceLib + IoLib + TimerLib + ArmLib + +[Packages] + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + MdePkg/MdePkg.dec + Silicon/NXP/iMXPlatformPkg/iMXPlatformPkg.dec + +[FixedPcd] + giMXPlatformTokenSpaceGuid.PcdSerialRegisterBase --=20 2.16.2.gvfs.1.33.gf5370f1