From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heiko Schocher Date: Thu, 9 Jul 2020 10:37:55 +0200 Subject: [PATCH v4 07/11] rtc: sandbox-rtc: fix set method In-Reply-To: <20200706200120.23093-8-rasmus.villemoes@prevas.dk> References: <20200706200120.23093-1-rasmus.villemoes@prevas.dk> <20200706200120.23093-8-rasmus.villemoes@prevas.dk> Message-ID: <28a1bc20-efc5-4e57-478d-c44a1a399faa@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hello Rasmus, Am 06.07.2020 um 22:01 schrieb Rasmus Villemoes: > The current set method is broken; a simple test case is to first set > the date to something in April, then change the date to 31st May: > > => date 040412122020.34 > Date: 2020-04-04 (Saturday) Time: 12:12:34 > => date 053112122020.34 > Date: 2020-05-01 (Friday) Time: 12:12:34 > > or via the amending of the existing rtc_set_get test case similarly: > > $ ./u-boot -T -v > => ut dm rtc_set_get > Test: dm_test_rtc_set_get: rtc.c > expected: 31/08/2004 18:18:00 > actual: 01/08/2004 18:18:00 > > The problem is that after each register write, > sandbox_i2c_rtc_complete_write() gets called and sets the internal > time from the current set of registers. However, when we get to > writing 31 to mday, the registers are in an inconsistent state (mon is > still 4), so the mktime machinery ends up translating April 31st to > May 1st. Upon the next register write, the registers are populated by > sandbox_i2c_rtc_prepare_read(), so the 31 we just wrote to mday gets > overwritten by a 1. > > Fix it by writing all registers at once, and for consistency, update > the get method to retrieve them all with one "i2c transfer". > > Reviewed-by: Simon Glass > Reviewed-by: Heiko Schocher > Signed-off-by: Rasmus Villemoes > --- > drivers/rtc/sandbox_rtc.c | 65 +++++++++++++++------------------------ > test/dm/rtc.c | 15 ++++++++- > 2 files changed, 38 insertions(+), 42 deletions(-) Applied to u-boot-i2c.git master Thanks! bye, Heiko -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de