From patchwork Mon Jun 18 12:31:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 138922 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp3898367lji; Mon, 18 Jun 2018 05:33:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ4O9pwFRD1OiYzcPna2gC8nRZoS0amYrZOfF3tlj06GMEe41lcivUmESb4occMPZpTGk1M X-Received: by 2002:a62:8d03:: with SMTP id z3-v6mr13144224pfd.112.1529325197943; Mon, 18 Jun 2018 05:33:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529325197; cv=none; d=google.com; s=arc-20160816; b=SUK5fhJO1laKle05/JOvaRFxrQrW06ysoSv1WO7ICmhjp6UQCh7SHIV9LkVmt+h7p6 K8bYIoYqzN0RsolgSNrYvucUD8TZcpYvYwqZMxXLjWI5T2Mn0YAiibzBAUA0A092WFTI 8pB3nr2RLFyfyWoIRrFGEc1cfEfy8vxy10MOw4ulJigLZUFjYMJk5dxABJjeYSh9j1LZ J9Di5kAtmXHwg/FnnF1O2YpyoDKMQhANTy2kF1vr7FVWHYU10LCKjQRm1Yz242e1RNXK RB+P2HCJ6/bBl+xdlD9Zc7vkmnHEn0nMY/+EkiiZsNIO7OhsRmR1alNaw5JC/hUYU/6b 8mug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=qG+zDoJpcWStlZlylW/TU+9vtDf/Ti37coERiX/wso0=; b=FpIwdlufaNqSQe25tkKM1a9JZb0TnarZTJaxpo2Ju6CUXVwUdsAbgJqk38shHvCaiX Q0xt1/q0sQaWTUlES4VtV7ZQl/Kh3j6Gc1boAHZAIVRGh9C0cmfwqGbfQNzr3b6PQumx PAf4S4aEHVo0XGW5Li423oRndBM4KVXbEg0KYvswNYFxIDVEkq4gyUAGjT6P7BTSXDZi f398DJDXBmtaYOK8TwHztKoOMXg+FxgmmcF7gFx3nqXJjDqDe2tLcfmptY4dCMhGw60O qnQpx7R5MGBjteFV+T0ahPUL03et/ti+nprn4Dvsevc9KzDsjkJFGhV1Q2dZLMyhJDS5 9Qkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=b6O5+n0m; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id w12-v6si14751456pfa.113.2018.06.18.05.33.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jun 2018 05:33:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=b6O5+n0m; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 768E5210D7F58; Mon, 18 Jun 2018 05:33:17 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c00::243; helo=mail-pf0-x243.google.com; envelope-from=masahisa.kojima@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf0-x243.google.com (mail-pf0-x243.google.com [IPv6:2607:f8b0:400e:c00::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 52A35210D7F55 for ; Mon, 18 Jun 2018 05:33:16 -0700 (PDT) Received: by mail-pf0-x243.google.com with SMTP id c22-v6so8113879pfi.2 for ; Mon, 18 Jun 2018 05:33:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=vmUYi0dNYtD0XLkS5rb7rqddNoqOYz15G84/FSUzmPk=; b=b6O5+n0mYBxb/MIT3k+lQ5vBD2qs9K2gdw9Mz7uULDO1LOO6TyYurPk1N7W0wM+trr 7hmBCr1siGV/KXSngmNCsnBjM1PewJDuKYMICbjTz2OQgZhjL2ObhMRriG/kll4YS4sG wwxqSuejkfyafwlkZhqT4R4bZmGriKCtz9Ais= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vmUYi0dNYtD0XLkS5rb7rqddNoqOYz15G84/FSUzmPk=; b=MljXF/pke1Es0vVMTR0f4XxH4WvE/tD+8AfGQUbhLwUCTwMiTzVcLy+bSBIfJowuHu K/uClWYYs6IevToELF/5B68sVKN/oDg5IXrI2KvpWrhxGEIxeyBPaapoVdLl8ahw3AeN pSyxGL6w9qdz3qxIs0VVzCY73pJ/iTUF89kBhdjmXEAv61ICM6NmURv5u2y/72ogy4p4 irLt6G1VtL+TmhQyVjprYkkBb83gQlpGulilY5ooBNot813AMunkd6nJbHisE+5Rp31v lrYGZIk1fBFb1Nzy8TLCC0P0rsoQI7vUttpeFe7GlIhBjREfqvIUOs/cpiFOEAaMVmN3 Pe6g== X-Gm-Message-State: APt69E2p2LCIiuh4+DUBIF9nPMg/MU+7YNlTSipoZidksqSAnMnKTH0q boNQ3woLJYApRp4YdC1fdsWFTeyHXD0= X-Received: by 2002:a65:5106:: with SMTP id f6-v6mr10773148pgq.122.1529325195638; Mon, 18 Jun 2018 05:33:15 -0700 (PDT) Received: from localhost ([121.95.100.191]) by smtp.gmail.com with ESMTPSA id e16-v6sm21443804pff.185.2018.06.18.05.33.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jun 2018 05:33:15 -0700 (PDT) From: masahisa.kojima@linaro.org To: edk2-devel@lists.01.org Date: Mon, 18 Jun 2018 21:31:55 +0900 Message-Id: <20180618123155.2141-1-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.14.2 Subject: [edk2] [PATCH] Silicon/NXP/Pcf8563RealTimeClockLib: add rtc device initialization X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yoshitoyo Osaki , leif.lindholm@linaro.org, ard.biesheuvel@linaro.org MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" From: Masahisa Kojima BcdToDecimal8() in LibGetTime() asserts with the following condition. 1) RTC device has not been initialized yet, RTC device returns indeterminate value 2) DEBUG build UEFI shell commands "date/time" expect that getting time from RTC should success when user sets the time. ShellCommandRunTime() performs GetTime()->update time->SetTime(), if the first GetTime() fails, user can not set time. To avoid this situation, even if it only occurs in DEBUG build, RTC driver should check the VL bit in the VL_seconds register. This VL bit is voltage-low detector, it means integrity of the clock information is not guaranteed if it sets to 1. In this case, driver set dummy date/time(01/01/2000 00:00:00) to proceed succeeding SetTime process. linux driver also checks this bit when driver gets the time from RTC. If VL bit is 1, linux driver discard the retreived time data. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Masahisa Kojima Signed-off-by: Yoshitoyo Osaki --- .../Pcf8563RealTimeClockLib.c | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) -- 2.14.2 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c index fb58e1feb4..7be0d23eea 100644 --- a/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c +++ b/Silicon/NXP/Library/Pcf8563RealTimeClockLib/Pcf8563RealTimeClockLib.c @@ -19,11 +19,13 @@ #include #include #include +#include #include #define SLAVE_ADDRESS (FixedPcdGet8 (PcdI2cSlaveAddress)) #define PCF8563_DATA_REG_OFFSET 0x2 +#define PCF8563_CLOCK_INVALID 0x80 #define PCF8563_SECONDS_MASK 0x7f #define PCF8563_MINUTES_MASK 0x7f #define PCF8563_HOURS_MASK 0x3f @@ -95,6 +97,7 @@ LibGetTime ( RTC_DATETIME DateTime; EFI_STATUS Status; UINT8 Reg; + EFI_TIME InitTime; if (Time == NULL) { return EFI_INVALID_PARAMETER; @@ -122,15 +125,26 @@ LibGetTime ( return EFI_DEVICE_ERROR; } - Time->Second = BcdToDecimal8 (DateTime.VL_seconds & PCF8563_SECONDS_MASK); - Time->Minute = BcdToDecimal8 (DateTime.Minutes & PCF8563_MINUTES_MASK); - Time->Hour = BcdToDecimal8 (DateTime.Hours & PCF8563_HOURS_MASK); - Time->Day = BcdToDecimal8 (DateTime.Days & PCF8563_DAYS_MASK); - Time->Month = BcdToDecimal8 (DateTime.Century_months & PCF8563_MONTHS_MASK); - Time->Year = BcdToDecimal8 (DateTime.Years) + EPOCH_BASE; - - if (DateTime.Century_months & PCF8563_CENTURY_MASK) { - Time->Year += 100; + if ((DateTime.VL_seconds & PCF8563_CLOCK_INVALID) != 0) { + InitTime.Second = 0; + InitTime.Minute = 0; + InitTime.Hour = 0; + InitTime.Day = 1; + InitTime.Month = 1; + InitTime.Year = EPOCH_BASE; + (VOID)LibSetTime (&InitTime); + (VOID)CopyMem (Time, &InitTime, sizeof(EFI_TIME)); + } else { + Time->Second = BcdToDecimal8 (DateTime.VL_seconds & PCF8563_SECONDS_MASK); + Time->Minute = BcdToDecimal8 (DateTime.Minutes & PCF8563_MINUTES_MASK); + Time->Hour = BcdToDecimal8 (DateTime.Hours & PCF8563_HOURS_MASK); + Time->Day = BcdToDecimal8 (DateTime.Days & PCF8563_DAYS_MASK); + Time->Month = BcdToDecimal8 (DateTime.Century_months & PCF8563_MONTHS_MASK); + Time->Year = BcdToDecimal8 (DateTime.Years) + EPOCH_BASE; + + if (DateTime.Century_months & PCF8563_CENTURY_MASK) { + Time->Year += 100; + } } if (Capabilities != NULL) {