From patchwork Sat Jun 12 06:22:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1491243 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.a=rsa-sha256 header.s=badeba3b8450 header.b=P/rbex9k; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G271T3KB9z9sjJ for ; Sat, 12 Jun 2021 16:22:51 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E323080A22; Sat, 12 Jun 2021 08:22:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=gmx.net header.i=@gmx.net header.b="P/rbex9k"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B58E180ECB; Sat, 12 Jun 2021 08:22:40 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_FROM,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id ED6A0800BF for ; Sat, 12 Jun 2021 08:22:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1623478949; bh=A9BPyPX7iDb+qa7F3wdkjtTM2syN61GDY2KwJYeE/5E=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=P/rbex9kyDcCxzttDr/TBjRu80auxBs398nNKYUL3k2yho+SsCb3GHz1kqlXigfax +FCwsHqPxyeIW8NUkjBipLT3BLpE+jRd3dUreHVU2eDSueMpeBs1TYxUYOdqmA8ueD 0Mq+WeAdUcEX60h8UfUHknWi4brx0ar2N5SzyApU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from LT02.fritz.box ([62.143.247.63]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1MN5if-1lZSqW239R-00J10B; Sat, 12 Jun 2021 08:22:29 +0200 From: Heinrich Schuchardt To: Tom Rini Cc: Stefan Roese , =?utf-8?q?Pali_Roh=C3=A1r?= , =?utf-8?q?Marek_Beh=C3=BAn?= , Ying-Chun Liu , Heiko Schocher , Simon Glass , Alexandru Gagniuc , Masahisa Kojima , Anastasiia Lukianenko , Bin Meng , Sean Anderson , Andrii Anisov , Reuben Dowle , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [PATCH 1/1] lib: move rtc-lib.c to lib Date: Sat, 12 Jun 2021 08:22:22 +0200 Message-Id: <20210612062222.23015-1-xypron.glpk@gmx.de> X-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SIc76eSdmbDq7Hb2PJQ8JvPk2HoULywV0yWxtMIkXWeZELHsJZ5I/Ruk lSCktl+VbzjhALaRyk78kramghWHowzoC3H+7tsOsbBzYUkZi+QfC1iIzaOed27d/X9uq1Lnx 0D4LQ0PVNU4nXjMJK/M3qNlV/QRc8H1zW6J3kWtwK8G4gE3hUuLX2WgRriA42MuPoIxfdUX51 w7Avlda1c8Bi020hxTaKNpnHLDMjj3n1Jc0NGww+mMqOqrJCB8rEJOVOR6WW9c7ZRHsYQuIuP mMJP7ErCzhbJ4M2PzKOJ4xI0cuHQxoddyQqdG4n1JC97ruN2ka0oKksU5t88bDQ2g7CE+Nyvk 9LEw3vd6/CYzj7tZ1kaOZc2BQ7LYfz9bffC X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Function rtc_to_tm() is needed for FAT file system support even if we don't have a real time clock. So move it from drivers/ to lib/. Signed-off-by: Heinrich Schuchardt --- drivers/rtc/Makefile | 1 - drivers/rtc/rtc-lib.c | 77 ------------------------------------------- lib/Makefile | 1 + lib/rtc-lib.c | 77 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 78 deletions(-) delete mode 100644 drivers/rtc/rtc-lib.c create mode 100644 lib/rtc-lib.c -- 2.30.2 diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index f668cf9050..331a49ab59 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile @@ -7,7 +7,6 @@ obj-$(CONFIG_$(SPL_TPL_)DM_RTC) += rtc-uclass.o obj-$(CONFIG_RTC_AT91SAM9_RTT) += at91sam9_rtt.o -obj-y += rtc-lib.o obj-$(CONFIG_RTC_ARMADA38X) += armada38x.o obj-$(CONFIG_RTC_DAVINCI) += davinci.o obj-$(CONFIG_RTC_DS1302) += ds1302.o diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c deleted file mode 100644 index 1f7bdade29..0000000000 --- a/drivers/rtc/rtc-lib.c +++ /dev/null @@ -1,77 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * rtc and date/time utility functions - * - * Copyright (C) 2005-06 Tower Technologies - * Author: Alessandro Zummo - * - * U-Boot rtc_time differs from Linux rtc_time: - * - The year field takes the actual value, not year - 1900. - * - January is month 1. - */ - -#include -#include -#include - -static const unsigned char rtc_days_in_month[] = { - 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 -}; - -#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400) - -/* - * The number of days in the month. - */ -int rtc_month_days(unsigned int month, unsigned int year) -{ - return rtc_days_in_month[month] + (is_leap_year(year) && month == 1); -} - -/* - * rtc_to_tm - Converts u64 to rtc_time. - * Convert seconds since 01-01-1970 00:00:00 to Gregorian date. - * - * This function is copied from rtc_time64_to_tm() in the Linux kernel. - * But in U-Boot January is month 1 and we do not subtract 1900 from the year. - */ -void rtc_to_tm(u64 time, struct rtc_time *tm) -{ - unsigned int month, year, secs; - int days; - - days = div_u64_rem(time, 86400, &secs); - - /* day of the week, 1970-01-01 was a Thursday */ - tm->tm_wday = (days + 4) % 7; - - year = 1970 + days / 365; - days -= (year - 1970) * 365 - + LEAPS_THRU_END_OF(year - 1) - - LEAPS_THRU_END_OF(1970 - 1); - while (days < 0) { - year -= 1; - days += 365 + is_leap_year(year); - } - tm->tm_year = year; /* Not year - 1900 */ - tm->tm_yday = days + 1; - - for (month = 0; month < 11; month++) { - int newdays; - - newdays = days - rtc_month_days(month, year); - if (newdays < 0) - break; - days = newdays; - } - tm->tm_mon = month + 1; /* January = 1 */ - tm->tm_mday = days + 1; - - tm->tm_hour = secs / 3600; - secs -= tm->tm_hour * 3600; - tm->tm_min = secs / 60; - tm->tm_sec = secs - tm->tm_min * 60; - - /* Zero unused fields */ - tm->tm_isdst = 0; -} diff --git a/lib/Makefile b/lib/Makefile index 6825671955..be45d4ab06 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -133,6 +133,7 @@ obj-$(CONFIG_SSCANF) += sscanf.o endif obj-y += date.o +obj-y += rtc-lib.o obj-$(CONFIG_LIB_ELF) += elf.o # diff --git a/lib/rtc-lib.c b/lib/rtc-lib.c new file mode 100644 index 0000000000..1f7bdade29 --- /dev/null +++ b/lib/rtc-lib.c @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * rtc and date/time utility functions + * + * Copyright (C) 2005-06 Tower Technologies + * Author: Alessandro Zummo + * + * U-Boot rtc_time differs from Linux rtc_time: + * - The year field takes the actual value, not year - 1900. + * - January is month 1. + */ + +#include +#include +#include + +static const unsigned char rtc_days_in_month[] = { + 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +}; + +#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400) + +/* + * The number of days in the month. + */ +int rtc_month_days(unsigned int month, unsigned int year) +{ + return rtc_days_in_month[month] + (is_leap_year(year) && month == 1); +} + +/* + * rtc_to_tm - Converts u64 to rtc_time. + * Convert seconds since 01-01-1970 00:00:00 to Gregorian date. + * + * This function is copied from rtc_time64_to_tm() in the Linux kernel. + * But in U-Boot January is month 1 and we do not subtract 1900 from the year. + */ +void rtc_to_tm(u64 time, struct rtc_time *tm) +{ + unsigned int month, year, secs; + int days; + + days = div_u64_rem(time, 86400, &secs); + + /* day of the week, 1970-01-01 was a Thursday */ + tm->tm_wday = (days + 4) % 7; + + year = 1970 + days / 365; + days -= (year - 1970) * 365 + + LEAPS_THRU_END_OF(year - 1) + - LEAPS_THRU_END_OF(1970 - 1); + while (days < 0) { + year -= 1; + days += 365 + is_leap_year(year); + } + tm->tm_year = year; /* Not year - 1900 */ + tm->tm_yday = days + 1; + + for (month = 0; month < 11; month++) { + int newdays; + + newdays = days - rtc_month_days(month, year); + if (newdays < 0) + break; + days = newdays; + } + tm->tm_mon = month + 1; /* January = 1 */ + tm->tm_mday = days + 1; + + tm->tm_hour = secs / 3600; + secs -= tm->tm_hour * 3600; + tm->tm_min = secs / 60; + tm->tm_sec = secs - tm->tm_min * 60; + + /* Zero unused fields */ + tm->tm_isdst = 0; +}