From nobody Wed Dec 25 13:38:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1510044883145753.6806006298027; Tue, 7 Nov 2017 00:54:43 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 901502034EE07; Tue, 7 Nov 2017 00:50:42 -0800 (PST) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0045.outbound.protection.outlook.com [104.47.36.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5F6232034D82B for ; Tue, 7 Nov 2017 00:50:41 -0800 (PST) Received: from BN6PR03CA0092.namprd03.prod.outlook.com (10.164.122.158) by BN3PR03MB2353.namprd03.prod.outlook.com (10.166.74.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.197.13; Tue, 7 Nov 2017 08:54:39 +0000 Received: from BL2FFO11FD005.protection.gbl (2a01:111:f400:7c09::182) by BN6PR03CA0092.outlook.office365.com (2603:10b6:405:6f::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.197.13 via Frontend Transport; Tue, 7 Nov 2017 08:54:39 +0000 Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD005.mail.protection.outlook.com (10.173.161.1) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.178.5 via Frontend Transport; Tue, 7 Nov 2017 08:54:39 +0000 Received: from uefi-OptiPlex-790.ap.freescale.net (uefi-OptiPlex-790.ap.freescale.net [10.232.132.78]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id vA78s4De009319; Tue, 7 Nov 2017 01:54:36 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.36.45; helo=nam02-sn1-obe.outbound.protection.outlook.com; envelope-from=meenakshi.aggarwal@nxp.com; receiver=edk2-devel@lists.01.org Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; From: Meenakshi Aggarwal To: , , , Date: Tue, 7 Nov 2017 20:12:13 +0530 Message-ID: <1510065736-9394-8-git-send-email-meenakshi.aggarwal@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1510065736-9394-1-git-send-email-meenakshi.aggarwal@nxp.com> References: <1510065736-9394-1-git-send-email-meenakshi.aggarwal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131545184792988959; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(7966004)(346002)(376002)(39380400002)(39860400002)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(85426001)(33646002)(106466001)(104016004)(305945005)(356003)(2906002)(50986999)(76176999)(105606002)(53376002)(966005)(4326008)(36756003)(53936002)(5660300001)(47776003)(498600001)(8656006)(189998001)(16799955002)(15188155005)(2950100002)(6306002)(6666003)(5003940100001)(2201001)(16586007)(110136005)(68736007)(86362001)(575784001)(50466002)(54906003)(48376002)(77096006)(8676002)(97736004)(50226002)(316002)(81156014)(81166006)(8936002)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:BN3PR03MB2353; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD005; 1:xJOT7Cj9ey6ILEqmM45o2JVNtJ3saSL2KNfBmAsvhr50THBiqtxy4bQuSm0kvxoGgjRf/oJ8uhcO/ZIOeZeJel3GoiLB+DarjcB1r1oYjs+dZK0MzfqI+Myj1tR7qqvw MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d58a0214-efd6-47d7-6bbe-08d525bd2df4 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4628075)(201703131517081)(2017052603199); SRVR:BN3PR03MB2353; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2353; 3:5a6g/26FTn2ZNk/vdChNDKLh0edQHxbGgl0Ngr8p7SJNmnAwMqbBC2Jmjx+z2ucs0h/OvHwRR8ipPCvub40559BZFeZGANaUYe9eiCx0dbuNZ1rJJDkA8NmRXZLF54xBjnx0UOxsCi5VQvSm0HrJEsjMrt/xlDSpJxWR/aJRzCDO9KoGNnGlx2SUD5jrmZw4fafAQCvKkL3ADrrBbIauXPwOYCmk9keqNmgdOuz6VZ3qETFBcxVpi6FcELbptYu76YW33Wh5bMT2o6xEK/YOLUs1cze4iktj4AEcsGRloE4HnhelUhsKu5Vnm1890NRyBTwqB1wUbdUo85uk34WTDKYhvZHk74NuMs9ABBYx92s=; 25:tMHfaYOxKatt+gwvCaamwumc3gXz5ujZqjWcaGTXoVQSrC6i0yA3XEDWtO21KKs2lDGSD3b+JdH+pRKRj6AtxfNNx7kimaRsT9SezOGpqndU/4mNpRjgu+BzzuU+KZeW2G+3ExLqV/7if+NbwFbYnrJSz183jnZvEbB8knKJ4KRr95AZsmq+RjBnKjfUXS8buumYEsA6lfLoxpTULMFS7Eab/h69SoqI+fTyx39YiNRLQwnbS9oT20sxolKNW3VlglVSJO9ZTlaHSW0SMjm01FsGlau9RpbC8v3x+e2WPhZh/E0vFctt69btI5W43o7k3YNFPJYSgD9nXAH9DZqtRQ== X-MS-TrafficTypeDiagnostic: BN3PR03MB2353: X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2353; 31:cL3JS/AT56hGwklKbegU0y9RwqS8QYOrTpeSl63rYM/lrjmUlnT8V89Pz69e8XH/nC6yVlUwZL7o3Pv60EKZ7ggmgFo/40UCHm1bw5iVIiG7nzFkA48ydvpTOHkK0dL8yN2MdvCLJmq3/mjLeoFRzACQJkIZCnuecO3d4LZcUawC6TY111ldXkz913un/16ZXguyYUN+MIVcjUaZc/+eymj9JTq7TzJI1Sl9QrgmBvI=; 4:+FzKw7+QP0Jg74/naCnSv2XRt+T6JYY6Ks6950iiTL4mSjR2PWsKEbWMhw38LVC6eEeDdZ7jZvGsWmIru147hIyREs3PluaXuSu0XfclW6/0uRRd10CpWRpIdu2qR1NfDdfQw7cg0gxAVLaZLZL57ATCSO7tbNS2pKjEL/u5DmC6CPmiqMu+EXGQiAzCsKoU2jhL0QCsVWQt1VlYxljmPih5W3l9OOX1/g70PlvYAyk3cCPtRCWegmFVd4caNfOf3u0T9CvnXih0kxXz7wzVnZvLHIGCd9duNiHT2UDRMrRsdhzdKyFEey47N7Jdlx+q X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231021)(93006095)(93001095)(100000703101)(100105400095)(6055026)(6096035)(20161123563025)(20161123556025)(20161123565025)(20161123559100)(201703131430075)(201703131433075)(201703131441075)(201703131448075)(201703161259150)(20161123561025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BN3PR03MB2353; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BN3PR03MB2353; X-Forefront-PRVS: 0484063412 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR03MB2353; 23:rMSOXsgnkSdHBcXDmmPlx1BI4iXB//mcADpuKU0By?= =?us-ascii?Q?IwWj2wWp1FE3q2jGxtEixSnH5Fs6lhma4xstcEwWqauBwta9AVzwBFUVrpV1?= =?us-ascii?Q?QqsdUUXPedMD86vo87lc56JI9WVXa7YPjjzf3jp+x6F9FkxVR2kE8Mt/INgE?= =?us-ascii?Q?iIzP4zwpjS+65zGSsfBFVa2FritMUSlD8StUswNpvMPkju1VHo42DOahyiT6?= =?us-ascii?Q?t1PEdsOy1i4OalHTTGGgiEFz88pzR9a2TEQQ1p4srv0Qq5qVdtK6u8cpdMGt?= =?us-ascii?Q?oPopVrdwv9RqKUgvBzZUA/Y65Xu0G0OcY3vQz831uVkRFecii9T0zoDlHGBE?= =?us-ascii?Q?FedVQc/sgTX6Nch7QnYBTiNijB+2eymrzj4OcPa+58zOYfPleNoTJ7KDyB7e?= =?us-ascii?Q?xYBQBoDOpB0o9ocyLzge0H9msy6ODxaOyNYyIZSgJzW0JhZJYsOAKr/aSFAk?= =?us-ascii?Q?Lh9oqew3vH3Cc/5cSw/XE8gwfSuCC17nBixUV5/JTzTao8OCyhPnhyRIp/tF?= =?us-ascii?Q?KdB/aVSF/pnQUdiNdIUO5l0wAG+MM+i2j/bDqzlfDq5ivUkwi/Ds8G0q8aNY?= =?us-ascii?Q?UY+qGIhW4PXtygNRTUm6JhaY66eCtQtBrY2GmjsEIjCN/z7oApJZ3ZLW52lr?= =?us-ascii?Q?Ap244FKokxpbhDjsk/gHRwldzX7WrBVeEAv3zKZCo0xciwqy+IO9WvDgIw74?= =?us-ascii?Q?Y0xrAyaWURcHyuklykxlt66ws6nsppLIzg4t/5fLMvIvFu60Bd2+TnMrpyYP?= =?us-ascii?Q?3TgPR7AhlVhfOe7B8qvBqpoa1tfobda5td3VIpRLxyoL6Lbp9eJp66Nydp+K?= =?us-ascii?Q?4KrbwTkUUEqfugjXxFUUbDuHH5GJ6m25cxw2SdYUPhPvcrkCMqEHC4pzzKtU?= =?us-ascii?Q?0v9j/2DfO7bqknKsQ2N/O2tCPmr99/kxxjMjv9XlyjEkmVDkysnz4tomqs/i?= =?us-ascii?Q?gZ1/tbOdl/WJrrGxKDMMmsE7i/eNh9Wb6p/4Mz1Xe9a6yWXxmLZETTuu8JUm?= =?us-ascii?Q?yue1M/xhbthnPKGKm1+XAwzZJRCRSCZAqxUHd7gLl5zHWrGWzZTPHAIxoRbr?= =?us-ascii?Q?HTlbQB8IO26PJ5dDugODAA8v6RfBYQ/igIhHcC5hnNZFd/6tP+vrsalr3GYa?= =?us-ascii?Q?agP+IGBzKTGroUR7lx76etuoAEaQHsJa8mxjG5dJL+00aPsBskmgoHRYY/no?= =?us-ascii?Q?tx3NoLkKc/eOuFazQ6jDxAqwonmnUHAvziq6sjVpEDqx2CMDiva8lfXpLewy?= =?us-ascii?Q?m22l6IbcSQyGO/okd8tsHmlcjhJwFi7ZirMkXkP7zswj9uRm/niP807sauNC?= =?us-ascii?Q?LzwMEmAXA1UWoWJ9EgBv0m8NBgJhucWK25ytWJoI4c7?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB2353; 6:+71fwx6fwqUXtHEN3UPKZ5WG0ZLRzWc/nWmN1Wx2bCaTz+OkPGJpKX4bQcQEAf8Gh+Q1ROnKwOS+UFNzCxlPYRfTzwWfc3BwNHHAOvo16UbSPwye5FhUkcfhkBn0OI6MI12rKj/8lmTJL3BmSFviMHtvmMzvlJ7kHw5ci/95DInOSw+yD+qZmTe4TehlqaDIWpIB7dIr2VCoIbDZnG55jZRjN+cZesn7S0/Jqr+rVbD5PS/UMI7l9iAwfkgFaXAIxj2KS65f1pXwZQ8Gt97WHKSm+Blk7s+33JaDp2zkBsZeof7EoyOMTGqOZay0PsegGSlALeHA4DLcbIYpX5ltg1Jd19wk7kyRFC6SpzCPnoo=; 5:11wXmFsYGHXnkH7ptUIEJuimbHBZlz71wZCs6bE9fB2do4erBIfSQBRlevKcTDleScGHdVR5hlNdMNS6b8yh3e1vdG0QMzdM71wFaUrpBnzb9iUJcyFWs/REio7aIEs95ay8FygvM0635reSYV+b4hitLCEZCF5NiI30O5RV43A=; 24:iAs9mgq+L/4Xd9Q7neNz1KlR4GxegExF2wy8qkRCI6Iztc44JNlXOofYYGLFYl3D0crLQ7oMpgualbPZ4x2v2PguJeyZ9CmVv3rHmf62qZk=; 7:NZRCaV6e54ZzZ1bKZg/alQNlFVy/gornQX2ZKxNvESmP6X0pNqB4wcbL/0pCrye4ZBTUFhD0qq2IteGzabou+gyNlwccGMOFSa4S1bxm+RjBUp6GHdDYhphFjJHNO1uz/BeRQRRxrGNW+Y1M0J4XK2rM8n8l604kF2DjfydNXJJPOrc7LahDilXgcxaqKUBm4Na5chTaosuZgQAtuhdgYvqhmlG6Sl+pD6Yw1ZnO37eP44A0fuOifbDNBohdJCPA SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2017 08:54:39.1272 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d58a0214-efd6-47d7-6bbe-08d525bd2df4 X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR03MB2353 Subject: [edk2] [PATCH 07/10] Platform/NXP : Add support for DS1307 RTC library X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Real time clock Apis on top of I2C Apis Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Meenakshi Aggarwal --- Platform/NXP/Library/Ds1307RtcLib/Ds1307Rtc.h | 40 ++++ Platform/NXP/Library/Ds1307RtcLib/Ds1307RtcLib.c | 226 +++++++++++++++++= ++++ Platform/NXP/Library/Ds1307RtcLib/Ds1307RtcLib.inf | 40 ++++ 3 files changed, 306 insertions(+) create mode 100644 Platform/NXP/Library/Ds1307RtcLib/Ds1307Rtc.h create mode 100644 Platform/NXP/Library/Ds1307RtcLib/Ds1307RtcLib.c create mode 100644 Platform/NXP/Library/Ds1307RtcLib/Ds1307RtcLib.inf diff --git a/Platform/NXP/Library/Ds1307RtcLib/Ds1307Rtc.h b/Platform/NXP/L= ibrary/Ds1307RtcLib/Ds1307Rtc.h new file mode 100644 index 0000000..952933f --- /dev/null +++ b/Platform/NXP/Library/Ds1307RtcLib/Ds1307Rtc.h @@ -0,0 +1,40 @@ +/** Ds1307Rtc.h +* +* Copyright 2017 NXP +* +* 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 __DS1307RTC_H__ +#define __DS1307RTC_H__ + +#define Bin(Bcd) ((Bcd) & 0x0f) + ((Bcd) >> 4) * 10 +#define Bcd(Bin) (((Bin / 10) << 4) | (Bin % 10)) + +/* + * RTC register addresses + */ +#define DS1307_SEC_REG_ADDR 0x00 +#define DS1307_MIN_REG_ADDR 0x01 +#define DS1307_HR_REG_ADDR 0x02 +#define DS1307_DAY_REG_ADDR 0x03 +#define DS1307_DATE_REG_ADDR 0x04 +#define DS1307_MON_REG_ADDR 0x05 +#define DS1307_YR_REG_ADDR 0x06 +#define DS1307_CTL_REG_ADDR 0x07 + +#define DS1307_SEC_BIT_CH 0x80 /* Clock Halt (in Register 0) */ + +#define DS1307_CTL_BIT_RS0 0x01 /* Rate select 0 */ +#define DS1307_CTL_BIT_RS1 0x02 /* Rate select 1 */ +#define DS1307_CTL_BIT_SQWE 0x10 /* Square Wave Enable */ +#define DS1307_CTL_BIT_OUT 0x80 /* Output Control */ + +#endif // __DS1307RTC_H__ diff --git a/Platform/NXP/Library/Ds1307RtcLib/Ds1307RtcLib.c b/Platform/NX= P/Library/Ds1307RtcLib/Ds1307RtcLib.c new file mode 100644 index 0000000..5f620a3 --- /dev/null +++ b/Platform/NXP/Library/Ds1307RtcLib/Ds1307RtcLib.c @@ -0,0 +1,226 @@ +/** Ds1307RtcLib.c + Implement EFI RealTimeClock with runtime services via RTC Lib for DS1307= RTC. + + Based on RTC implementation available in + EmbeddedPkg/Library/TemplateRealTimeClockLib/RealTimeClockLib.c + + Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
+ Copyright 2017 NXP + + 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 +#include + +#include "Ds1307Rtc.h" + +/** + Read RTC register. + + @param RtcRegAddr Register offset of RTC to be read. + + @retval Register Value read + +**/ + +UINT8 +RtcRead ( + IN UINT8 RtcRegAddr + ) +{ + INT32 Status; + UINT8 Val; + + Val =3D 0; + Status =3D I2cDataRead(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdDs1307I2cAddr= ess), + RtcRegAddr, 0x1, &Val, sizeof(Val)); + if (EFI_ERROR(Status)) + DEBUG((DEBUG_ERROR, "RTC read error at Addr:0x%x\n", RtcRegAddr)); + + return Val; +} +/** + Write RTC register. + + @param RtcRegAddr Register offset of RTC to write. + @param Val Value to be written + +**/ + +VOID +RtcWrite( + IN UINT8 RtcRegAddr, + IN UINT8 Val + ) +{ + EFI_STATUS Status; + + Status =3D I2cDataWrite(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdDs1307I2cAdd= ress), + RtcRegAddr, 0x1, &Val, sizeof(Val)); + if (EFI_ERROR(Status)) + DEBUG((DEBUG_ERROR, "RTC write error at Addr:0x%x\n", RtcRegAddr)); +} + +/** + Returns the current time and date information, and the time-keeping capa= bilities + of the hardware platform. + + @param Time A pointer to storage to receive a snapshot= of the current time. + @param Capabilities An optional pointer to a buffer to receive= the real time clock + device's capabilities. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The time could not be retrieved due to har= dware error. + +**/ + +EFI_STATUS +EFIAPI +LibGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities + ) +{ + EFI_STATUS Status; + UINT8 Second; + UINT8 Minute; + UINT8 Hour; + UINT8 Day; + UINT8 Month; + UINT8 Year; + + Status =3D EFI_SUCCESS; + + Second =3D RtcRead (DS1307_SEC_REG_ADDR); + Minute =3D RtcRead (DS1307_MIN_REG_ADDR); + Hour =3D RtcRead (DS1307_HR_REG_ADDR); + Day =3D RtcRead (DS1307_DATE_REG_ADDR); + Month =3D RtcRead (DS1307_MON_REG_ADDR); + Year =3D RtcRead (DS1307_YR_REG_ADDR); + + if (Second & DS1307_SEC_BIT_CH) { + DEBUG ((DEBUG_ERROR, "### Warning: RTC oscillator has stopped\n")); + /* clear the CH flag */ + RtcWrite (DS1307_SEC_REG_ADDR, + RtcRead (DS1307_SEC_REG_ADDR) & ~DS1307_SEC_BIT_CH); + Status =3D EFI_DEVICE_ERROR; + } + + Time->Second =3D Bin (Second & 0x7F); + Time->Minute =3D Bin (Minute & 0x7F); + Time->Hour =3D Bin (Hour & 0x3F); + Time->Day =3D Bin (Day & 0x3F); + Time->Month =3D Bin (Month & 0x1F); + Time->Year =3D Bin (Year) + ( Bin (Year) >=3D 70 ? 1900 : 2000); + + return Status; +} + +/** + Sets the current local time and date information. + + @param Time A pointer to the current time. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The time could not be set due due to hardw= are error. + +**/ +EFI_STATUS +EFIAPI +LibSetTime ( + IN EFI_TIME *Time + ) +{ + if (Time->Year < 1970 || Time->Year > 2069) + DEBUG((DEBUG_ERROR, "WARNING: Year should be between 1970 and 2069!\n"= )); + + RtcWrite (DS1307_YR_REG_ADDR, Bcd (Time->Year % 100)); + RtcWrite (DS1307_MON_REG_ADDR, Bcd (Time->Month)); + RtcWrite (DS1307_DATE_REG_ADDR, Bcd (Time->Day)); + RtcWrite (DS1307_HR_REG_ADDR, Bcd (Time->Hour)); + RtcWrite (DS1307_MIN_REG_ADDR, Bcd (Time->Minute)); + RtcWrite (DS1307_SEC_REG_ADDR, Bcd (Time->Second)); + + return EFI_SUCCESS; +} + +/** + Returns the current wakeup alarm clock setting. + + @param Enabled Indicates if the alarm is currently enable= d or disabled. + @param Pending Indicates if the alarm signal is pending a= nd requires acknowledgement. + @param Time The current alarm setting. + + @retval EFI_SUCCESS The alarm settings were returned. + @retval EFI_INVALID_PARAMETER Any parameter is NULL. + @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due= to a hardware error. + +**/ +EFI_STATUS +EFIAPI +LibGetWakeupTime ( + OUT BOOLEAN *Enabled, + OUT BOOLEAN *Pending, + OUT EFI_TIME *Time + ) +{ + // Not a required feature + return EFI_UNSUPPORTED; +} + +/** + Sets the system wakeup alarm clock time. + + @param Enabled Enable or disable the wakeup alarm. + @param Time If Enable is TRUE, the time to set the wak= eup alarm for. + + @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm w= as enabled. If + Enable is FALSE, then the wakeup alarm was= disabled. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a = hardware error. + @retval EFI_UNSUPPORTED A wakeup timer is not supported on this pl= atform. + +**/ +EFI_STATUS +EFIAPI +LibSetWakeupTime ( + IN BOOLEAN Enabled, + OUT EFI_TIME *Time + ) +{ + // Not a required feature + return EFI_UNSUPPORTED; +} + +/** + This is the declaration of an EFI image entry point. This can be the ent= ry point to an application + written to this specification, an EFI boot service driver, or an EFI run= time driver. + + @param ImageHandle Handle that identifies the loaded image. + @param SystemTable System Table for this image. + + @retval EFI_SUCCESS The operation completed successfully. + +**/ +EFI_STATUS +EFIAPI +LibRtcInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return I2cBusInit(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdI2cSpeed)); +} diff --git a/Platform/NXP/Library/Ds1307RtcLib/Ds1307RtcLib.inf b/Platform/= NXP/Library/Ds1307RtcLib/Ds1307RtcLib.inf new file mode 100644 index 0000000..b068b43 --- /dev/null +++ b/Platform/NXP/Library/Ds1307RtcLib/Ds1307RtcLib.inf @@ -0,0 +1,40 @@ +# @Ds1307RtcLib.inf +# +# Lib to provide support for DS1307 Real Time Clock +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# Copyright (c) 2017 NXP +# +# 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 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 IM= PLIED. +# +# + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D Ds1307RtcLib + FILE_GUID =3D B661E02D-A90B-42AB-A5F9-CF841AAA43D9 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RealTimeClockLib + +[Sources.common] + Ds1307RtcLib.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + edk2-platforms/Platform/NXP/NxpQoriqLs.dec + +[LibraryClasses] + DebugLib + I2cLib + +[Pcd] + gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus + gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed + gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress --=20 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel