Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp47874ybp; Thu, 3 Oct 2019 14:36:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqz78B/1EqqXCfW6iyKQIsl0Ixb15UGtSwS3jU0eD42asjKiP3nLWuWslfIQL7JWvysS+DzS X-Received: by 2002:aa7:d988:: with SMTP id u8mr11790588eds.116.1570138583879; Thu, 03 Oct 2019 14:36:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570138583; cv=none; d=google.com; s=arc-20160816; b=fQAEJwb31OdJjPZjvPyWHCRoxGcjuXNtvZY1h7K0Zr427YvKwwerQVzUQex+s1Zotg l3eSe1LhjsgJd9kj33L3ja5wg4lDZZBuAxxjXqhpJV21gMA/7m3X1HD9jSGfa3WrnmPT j/tLPfhCfqt4Clvnc0dfkIMhGc1ujvYPlDATBuEdHqY4YvaUFKGvCdG0UYtRS3mPO78o OAu67Knbl4bJSrXy4GGxx2yt9g4KkXpysBDNtS+hoaN3qHDghZvGENKqjQivYKjyKrUe idjc4clY6wq1OmxjbhjdkFkyFQ3vDxDWOAu+EgbEpPjH4KR2qDGjJSk2zfTKyA3iA+OL kcng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Xj57obJXE+t+1jn1sownTLh0mFTjFN9Ey+BUkrMrSLs=; b=u0P79DUqhrxiNoeMlOtMorpNgsiYW7x1LxHe7DE/4WmlF0fh6oXHIziwr9OYYiTjz2 UjTK1xQpcfEsBMKrVZKq1YCZeo2IAHwkCFgjSouA3SjkArH7XpbDp19FtFOlUAj5ysbG Mq7W3ICfEcCzVly+YKmVGhy6kQsB0A3quS6X0hl48VXRFy5ltNGy11+h8WxkUvXGT12y i6x5NXRlBpeq6001Tk/xNv+y5KCG+vD6/JRjucj08FjTkmWohS0X8lG31e2kUiR6ge4C xRxvM8jW3nNbWyHIee2pMyjarEYKBMVezlX7kkFQWHoh6ocnOX3kbfORsC422KftwSnZ Cr9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nl6si1874351ejb.207.2019.10.03.14.35.53; Thu, 03 Oct 2019 14:36:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732893AbfJCVey (ORCPT + 99 others); Thu, 3 Oct 2019 17:34:54 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:57781 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731371AbfJCVey (ORCPT ); Thu, 3 Oct 2019 17:34:54 -0400 Received: from localhost (lfbn-lyo-1-146-42.w86-202.abo.wanadoo.fr [86.202.229.42]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay11.mail.gandi.net (Postfix) with ESMTPSA id AB04B100005; Thu, 3 Oct 2019 21:34:52 +0000 (UTC) Date: Thu, 3 Oct 2019 23:34:52 +0200 From: Alexandre Belloni To: Lukasz Majewski Cc: Alessandro Zummo , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rtc: Add support for century bits to m41t62 (rv4162) RTC devices Message-ID: <20191003213452.GT4106@piout.net> References: <20190911154803.15969-1-lukma@denx.de> <20191003114831.GR4106@piout.net> <20191003142150.3d73a9d7@jawa> <20191003123538.GS4106@piout.net> <20191003151434.49762715@jawa> <20191003134329.GB575@piout.net> <20191003161054.1eeae401@jawa> <20191003142341.GD575@piout.net> <20191003164906.2f4a1676@jawa> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191003164906.2f4a1676@jawa> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/10/2019 16:49:06+0200, Lukasz Majewski wrote: > Hi Alexandre, > I'm rather thinking about following use cases: > > I. Adjusting time: > > 1. I start with time < 01.01.2099 > > 2. I issue ioctl to set the time to e.g. 2100 > > - When driver receives such request I setup century bits > > - and also perform in kernel driver time correction (and store > corrected time in RTC) > > 3. Subsequent reads from rtc use century bits to provide the time > (after year 2100). Century bits are set, so the correction may be > performed if needed. > > > II. The system is started at year 2098 and is supposed to run for e.g. 3 > years: > > 1. The time is read from the rtc - the "passing" of centuries need to > be detected. > > From the documentation [1] (point 4.5): > > "The two century bits, CB1 and CB0, are bits 7 and 6, respectively, in > the Month / Century register at address 06h. Together, they comprise a > 2 - bit counter which increments at the turn of each century. CB1 is > the most significant bit." > > If those bits increment when we pass century boundaries, we can detect > this fact and correct time when ioctl is issued. > No, you can't because you simply don't know if you still need to correct the time or if you already did it the last time the system was started. Example: Date is set to 2100-02-28, some time pass, the rtc now thinks it is 2100-02-29. You correct it to 2100-03-01, fine. Now, date is set to 2100-02-28, the system is shutdown, some time pass, it starts on 2100-03-02, the rtc thinks 2100-03-01 you can't correct it because you can't know whether a day has been missed. > > The only useful range for an RTC is its fully contiguous range. > > Does the automatic increment of century bits count to "contiguous > range" ? > No, because of the leap day issue. -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com