From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.107.0.69; helo=eur02-am5-obe.outbound.protection.outlook.com; envelope-from=meenakshi.aggarwal@nxp.com; receiver=edk2-devel@lists.01.org Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00069.outbound.protection.outlook.com [40.107.0.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CF1FA223230CE for ; Fri, 16 Feb 2018 00:48:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=gbfRik/Uphqr3KjVMqsdrQedJtUeM0ZLeZjUSxwifMk=; b=GAfbBsGVtl8MHuVX5xk+xkpCycXoJvYSpMfV5U6ubFjJ1nDdhcq7j+lNUQqPO1DFeVKG4H4ESSfyC7PCayqpGISsW5/R/l1SukCyAh+MROi1NBm6WVBYdYkq5CPV4A9/rUKDyaaS5oNrYpbTEDC1wgX8OEBS7gymfdU0mSvIPGs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=meenakshi.aggarwal@nxp.com; Received: from idcbfarm.ap.freescale.net (192.88.169.1) by VI1PR04MB1008.eurprd04.prod.outlook.com (2a01:111:e400:5090::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.485.10; Fri, 16 Feb 2018 08:53:52 +0000 From: Meenakshi To: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, michael.d.kinney@intel.com, edk2-devel@lists.01.org Date: Fri, 16 Feb 2018 14:20:15 +0530 Message-Id: <1518771035-6733-20-git-send-email-meenakshi.aggarwal@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1518771035-6733-1-git-send-email-meenakshi.aggarwal@nxp.com> References: <1518771035-6733-1-git-send-email-meenakshi.aggarwal@nxp.com> MIME-Version: 1.0 X-Originating-IP: [192.88.169.1] X-ClientProxiedBy: HK2PR02CA0172.apcprd02.prod.outlook.com (2603:1096:201:1f::32) To VI1PR04MB1008.eurprd04.prod.outlook.com (2a01:111:e400:5090::28) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 501816ea-9079-4aa4-b1a3-08d5751acf7e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603307)(7153060)(7193020); SRVR:VI1PR04MB1008; X-Microsoft-Exchange-Diagnostics: 1; VI1PR04MB1008; 3:FOhvtbDhwYI1g2YdfT4eMpJAPJs6/qFKYoU/Lwa2CkTLsiMEv+Ht3xJxjpDXV4qjfTwrcuSofd++8yMFk61AcyGUpW+nxc5zLFfx+yNOaiJ2wt7p1evVt6e3o3CKIjosSmOUnTfQrH+JfXfcX8/6mAjjHJziNFajSDA77HpKP+zP6VlRed545xf+Wnzf7fNf/ip43eW6jkTJ/PQ7HPO57mQGNto1QiynCQoupkwLvZz2CNhzVf60b/J15AOtOL5V; 25:d64Hv0tmwU8ewRMyJTYnJBFSp5Zzjt5jiue+GMx/8B6dRrzV+OfUPJtKGT1///lHBHg2aHuMVHILv0DLSYALKptE9qRlt6O+xlInz20DdqAY/nidKxy6h+TYMgsTW24JHA54/BEclyMA9unX/TqpqHcAa7GuijlOGdJKbguIjKGo1C+ZfB/7MGDHRwMp6vW5ZBdbCcEsK+RK3opaDm/4/g83MexIkrE5qHQMCph4TMuHUdZcoW2myd+HcMk7xK1oW+C+JV0lWmHHP2ZJNyzGryFhvoLfz4fFu7CP3NA6kKRY1BVLHCb+CTn4kV+QlpAqq0qczrG9bePfRqXrgOwT6w==; 31:0qzCFRe9kU1BveV4bvE7LTJ1nC4JY5U5VA+pJ2iciZFINF0eg9Usk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DGNW9QxuLCuWKmIRiXW89RJTS25IrRofRFHWCvKwWQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(788757137089); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231101)(944501161)(6055026)(6041288)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:VI1PR04MB1008; BCL:0; PCL:0; RULEID:; SRVR:VI1PR04MB1008; X-Forefront-PRVS: 0585417D7B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(376002)(39380400002)(396003)(39860400002)(366004)(199004)(189003)(86362001)(6486002)(8676002)(76176011)(36756003)(53376002)(966005)(4326008)(6116002)(15188155005)(16799955002)(7736002)(386003)(68736007)(186003)(26005)(53936002)(305945005)(16526019)(81156014)(3846002)(6506007)(478600001)(50226002)(16586007)(8936002)(2950100002)(316002)(2906002)(59450400001)(25786009)(97736004)(50466002)(48376002)(105586002)(52116002)(47776003)(81166006)(51416003)(5660300001)(6666003)(106356001)(66066001)(6306002)(6512007)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR04MB1008; H:idcbfarm.ap.freescale.net; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR04MB1008; 23:+FgeZyXnu+0DgnrM8slfE0Hv+gXk62GzvY9jwuldV?= =?us-ascii?Q?OGIg+xbO1aWZnVvo0sz71O/UuontE/Rhi+SZYINExVsBr7GT1YpMxq2+nxlD?= =?us-ascii?Q?sINeDSPti8cTMuQIC7iVd/0uo4zPtQieRuLKSUY1NiNOgV1jUo+aclh5TiNs?= =?us-ascii?Q?hPx7Dc9n7jvGH44zc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MyBltd4lMNSHNusU1+cMEJiyEuPgBvJj3qgPQGIsuEwqrXBqzJ7lOxamXQsS3FG9qk91zNDRdZmwS9IN5szq6ZQfArpqwYTaMlvvat5YMsxRuMb+K7Vjav4Gr44RO1L/YiVLZzHEOtvnoKkgoWf SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2018 08:53:52.3891 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 501816ea-9079-4aa4-b1a3-08d5751acf7e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB1008 Subject: [PATCH edk2-platforms 19/39] Silicon/NXP:Add support for PCF2129 Real Time Clock Library X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Feb 2018 08:48:05 -0000 Content-Type: text/plain From: Vabhav Library to provide functions for NXP pcf2129 real time clock library Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Vabhav --- Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129Rtc.h | 43 +++ Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129RtcLib.c | 330 +++++++++++++++++++++ .../NXP/Library/Pcf2129RtcLib/Pcf2129RtcLib.inf | 47 +++ 3 files changed, 420 insertions(+) create mode 100644 Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129Rtc.h create mode 100644 Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129RtcLib.c create mode 100644 Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129RtcLib.inf diff --git a/Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129Rtc.h b/Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129Rtc.h new file mode 100644 index 0000000..735f697 --- /dev/null +++ b/Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129Rtc.h @@ -0,0 +1,43 @@ +/** Pcf2129Rtc.h +* +* Copyright 2017 NXP +* +* 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 __PCF2129RTC_H__ +#define __PCF2129RTC_H__ + +/* + * RTC register addresses + */ +#define PCF2129_CTRL1_REG_ADDR 0x00 // Control Register 1 +#define PCF2129_CTRL2_REG_ADDR 0x01 // Control Register 2 +#define PCF2129_CTRL3_REG_ADDR 0x02 // Control Register 3 +#define PCF2129_SEC_REG_ADDR 0x03 +#define PCF2129_MIN_REG_ADDR 0x04 +#define PCF2129_HR_REG_ADDR 0x05 +#define PCF2129_DAY_REG_ADDR 0x06 +#define PCF2129_WEEKDAY_REG_ADDR 0x07 +#define PCF2129_MON_REG_ADDR 0x08 +#define PCF2129_YR_REG_ADDR 0x09 + +#define PCF2129_CTRL3_BIT_BLF BIT2 /* Battery Low Flag*/ + +// Define EPOCH (1998-JANUARY-01) in the Julian Date representation +#define EPOCH_JULIAN_DATE 2450815 + +typedef struct { + UINTN OperationCount; + EFI_I2C_OPERATION SetAddressOp; + EFI_I2C_OPERATION GetSetDateTimeOp; +} RTC_I2C_REQUEST; + +#endif // __PCF2129RTC_H__ diff --git a/Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129RtcLib.c b/Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129RtcLib.c new file mode 100644 index 0000000..2e21014 --- /dev/null +++ b/Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129RtcLib.c @@ -0,0 +1,330 @@ +/** @PCF2129RtcLib.c + Implement EFI RealTimeClock with runtime services via RTC Lib for PCF2129 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 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 +#include +#include + +#include "Pcf2129Rtc.h" + +STATIC EFI_I2C_MASTER_PROTOCOL *mI2cMaster; + +/** + returns Day of the week [0-6] 0=Sunday + Don't try to provide a Year that's before 1998, please ! + **/ +UINTN +EfiTimeToWday ( + IN EFI_TIME *Time + ) +{ + UINTN MonthDiff; + UINTN Year; + UINTN Month; + UINTN JulianDate; // Absolute Julian Date representation of the supplied Time + UINTN EpochDays; // Number of days elapsed since EPOCH_JULIAN_DAY + + MonthDiff = (14 - Time->Month) / 12 ; + Year = Time->Year + 4800 - MonthDiff; + Month = Time->Month + (12*MonthDiff) - 3; + + JulianDate = Time->Day + ((153*Month + 2)/5) + (365*Year) + (Year/4) - (Year/100) + (Year/400) - 32045; + + ASSERT (JulianDate >= EPOCH_JULIAN_DATE); + EpochDays = JulianDate - EPOCH_JULIAN_DATE; + + // 4=1/1/1998 was a Thursday + + return (EpochDays + 4) % 7; +} + +/** + Write RTC register. + + @param RtcRegAddr Register offset of RTC to write. + @param Val Value to be written + +**/ + +STATIC +VOID +RtcWrite ( + IN UINT8 RtcRegAddr, + IN UINT8 Val + ) +{ + RTC_I2C_REQUEST Req; + EFI_STATUS Status; + + Req.OperationCount = 2; + + Req.SetAddressOp.Flags = 0; + Req.SetAddressOp.LengthInBytes = 0; + Req.SetAddressOp.Buffer = &RtcRegAddr; + + Req.GetSetDateTimeOp.Flags = 0; + Req.GetSetDateTimeOp.LengthInBytes = sizeof (Val); + Req.GetSetDateTimeOp.Buffer = &Val; + + Status = mI2cMaster->StartRequest (mI2cMaster, FixedPcdGet8 (PcdI2cSlaveAddress), + (VOID *)&Req, + NULL, NULL); + 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 capabilities + 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 hardware error. + +**/ + +EFI_STATUS +EFIAPI +LibGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities + ) +{ + EFI_STATUS Status; + UINT8 Buffer[10]; + RTC_I2C_REQUEST Req; + UINT8 RtcRegAddr; + + Status = EFI_SUCCESS; + RtcRegAddr = PCF2129_CTRL1_REG_ADDR; + Buffer[0] = 0; + + if (mI2cMaster == NULL) { + return EFI_DEVICE_ERROR; + } + + RtcWrite (PCF2129_CTRL1_REG_ADDR, Buffer[0]); + + if (Time == NULL) { + return EFI_INVALID_PARAMETER; + } + + Req.OperationCount = 2; + + Req.SetAddressOp.Flags = 0; + Req.SetAddressOp.LengthInBytes = 0; + Req.SetAddressOp.Buffer = &RtcRegAddr; + + Req.GetSetDateTimeOp.Flags = I2C_FLAG_READ; + Req.GetSetDateTimeOp.LengthInBytes = sizeof (Buffer); + Req.GetSetDateTimeOp.Buffer = Buffer; + + Status = mI2cMaster->StartRequest (mI2cMaster, FixedPcdGet8 (PcdI2cSlaveAddress), + (VOID *)&Req, + NULL, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "RTC read error at Addr:0x%x\n", RtcRegAddr)); + } + + if (Buffer[PCF2129_CTRL3_REG_ADDR] & PCF2129_CTRL3_BIT_BLF) { + DEBUG((DEBUG_INFO, "### Warning: RTC battery status low, check/replace RTC battery.\n")); + } + + Time->Nanosecond = 0; + Time->Second = BcdToDecimal8 (Buffer[PCF2129_SEC_REG_ADDR] & 0x7F); + Time->Minute = BcdToDecimal8 (Buffer[PCF2129_MIN_REG_ADDR] & 0x7F); + Time->Hour = BcdToDecimal8 (Buffer[PCF2129_HR_REG_ADDR] & 0x3F); + Time->Day = BcdToDecimal8 (Buffer[PCF2129_DAY_REG_ADDR] & 0x3F); + Time->Month = BcdToDecimal8 (Buffer[PCF2129_MON_REG_ADDR] & 0x1F); + Time->Year = BcdToDecimal8 (Buffer[PCF2129_YR_REG_ADDR]) + ( BcdToDecimal8 (Buffer[PCF2129_YR_REG_ADDR]) >= 98 ? 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 hardware error. + +**/ + +EFI_STATUS +EFIAPI +LibSetTime ( + IN EFI_TIME *Time + ) +{ + UINT8 Buffer[8]; + UINT8 Index; + EFI_STATUS Status; + RTC_I2C_REQUEST Req; + UINT8 RtcRegAddr; + + Index = 0; + Status = EFI_SUCCESS; + RtcRegAddr = PCF2129_CTRL1_REG_ADDR; + + if (mI2cMaster == NULL) { + return EFI_DEVICE_ERROR; + } + + // start register address + Buffer[Index++] = PCF2129_SEC_REG_ADDR; + + // hours, minutes and seconds + Buffer[Index++] = DecimalToBcd8 (Time->Second); + Buffer[Index++] = DecimalToBcd8 (Time->Minute); + Buffer[Index++] = DecimalToBcd8 (Time->Hour); + Buffer[Index++] = DecimalToBcd8 (Time->Day); + Buffer[Index++] = EfiTimeToWday (Time) & 0x07; + Buffer[Index++] = DecimalToBcd8 (Time->Month); + Buffer[Index++] = DecimalToBcd8 (Time->Year % 100); + + Req.OperationCount = 2; + Req.SetAddressOp.Flags = 0; + Req.SetAddressOp.LengthInBytes = 0; + Req.SetAddressOp.Buffer = &RtcRegAddr; + + Req.GetSetDateTimeOp.Flags = 0; + Req.GetSetDateTimeOp.LengthInBytes = sizeof (Buffer); + Req.GetSetDateTimeOp.Buffer = Buffer; + + Status = mI2cMaster->StartRequest (mI2cMaster, FixedPcdGet8 (PcdI2cSlaveAddress), + (VOID *)&Req, + NULL, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "RTC write error at Addr:0x%x\n", RtcRegAddr)); + return Status; + } + + return Status; +} + + +/** + Returns the current wakeup alarm clock setting. + + @param Enabled Indicates if the alarm is currently enabled or disabled. + @param Pending Indicates if the alarm signal is pending and 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. + @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform. + +**/ +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 wakeup alarm for. + + @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was 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 platform. + +**/ +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 entry point to an application + written to this specification, an EFI boot service driver, or an EFI runtime driver. + + @param ImageHandle Handle that identifies the loaded image. + @param SystemTable System Table for this image. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_DEVICE_ERROR The operation could not be started. + +**/ +EFI_STATUS +EFIAPI +LibRtcInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + + EFI_STATUS Status; + EFI_I2C_MASTER_PROTOCOL *I2cMaster; + UINTN BusFrequency; + + Status = gBS->LocateProtocol (&gEfiI2cMasterProtocolGuid, NULL, (VOID **)&I2cMaster); + + ASSERT_EFI_ERROR (Status); + + Status = I2cMaster->Reset (I2cMaster); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: I2CMaster->Reset () failed - %r\n", + __FUNCTION__, Status)); + return Status; + } + + BusFrequency = FixedPcdGet32 (PcdI2cSpeed); + Status = I2cMaster->SetBusFrequency (I2cMaster, &BusFrequency); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: I2CMaster->SetBusFrequency () failed - %r\n", + __FUNCTION__, Status)); + return Status; + } + + mI2cMaster = I2cMaster; + + return EFI_SUCCESS; +} diff --git a/Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129RtcLib.inf b/Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129RtcLib.inf new file mode 100644 index 0000000..873bcea --- /dev/null +++ b/Silicon/NXP/Library/Pcf2129RtcLib/Pcf2129RtcLib.inf @@ -0,0 +1,47 @@ +#/** @Pcf2129RtcLib.inf +# +# Copyright 2017 NXP +# +# 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 = Pcf2129RtcLib + FILE_GUID = B661E02D-A90B-42AB-A5F9-CF841AAA43D9 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = RealTimeClockLib + + +[Sources.common] + Pcf2129RtcLib.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + Silicon/NXP/NxpQoriqLs.dec + +[LibraryClasses] + DebugLib + UefiBootServicesTableLib + UefiLib + +[Protocols] + gEfiDriverBindingProtocolGuid ## CONSUMES + gEfiI2cMasterProtocolGuid ## CONSUMES + +[Pcd] + gNxpQoriqLsTokenSpaceGuid.PcdI2cBus + gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed + gNxpQoriqLsTokenSpaceGuid.PcdI2cSlaveAddress + +[Depex] + gEfiI2cMasterProtocolGuid -- 1.9.1