From patchwork Tue May 19 22:01:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 1293805 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; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=prevas.dk header.i=@prevas.dk header.a=rsa-sha256 header.s=selector1 header.b=Qlp+P8/y; 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49RVKS3Qrzz9sT6 for ; Wed, 20 May 2020 08:04:28 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0CEB081E5D; Wed, 20 May 2020 00:04:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk 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; unprotected) header.d=prevas.dk header.i=@prevas.dk header.b="Qlp+P8/y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0AF9781E28; Wed, 20 May 2020 00:01:42 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,MSGID_FROM_MTA_HEADER, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0718.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1e::718]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E473881E35 for ; Wed, 20 May 2020 00:01:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=prevas.dk Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rasmus.villemoes@prevas.dk ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F2VjI1wqp416qfmDqTnW2yx08ehZMVNwU66RrlIRERcWiGKvHqN50UQrn90BFxeIdDYXLJpxuCnAmJEo/nCUZKde5P50GRptr5Bt/8hsTouWNQvvZsXgNbwnjb3K6uBjKKKiN8JAyDM/WWWJfpbMUDLeKmir33QjQ+uVYjiN0T8xam66vSyQ52VPcYibvqUDhQCof40+UKJgyrTl6TRNDbqaK6nWzXchC/Rj5KObIalgxVwcQLzfchOWCVKdcc0Zlz6h2MMISRwUkOQm0kRPbmOD7gTgbj0P4CwNpdawM288DO/VuduBA02ckVpncEf++zCsyvf0m3hCMDY3wTLFXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kAecCNZD3i6+PPVIOG0UvV8jfJfKnbRYZ4EWKpR3XcU=; b=FQiH/BxVQBnsleMqSSgBNTdRYyZmOc5vCIKqShhlHy8aogl0XF8zA+EfwcqqDl1r47kYFaojPtqAeEpmf29bHIopcdZzOuW5GC0FtaWeogLcEXiK0lGE3KyNwltFIoM6zpIqCwukn0DC7s2hdeT6OCnA8Zaf8mTRqfijL+H9oyZwg1mBXhNGJsmQCUA9GQn3y4whQT0ou9FOkDkl4VjE9D2/m/bRUzzEc6d39GZmj7Lrg7EExMU4k04simX6nNr+mKxneNQYPmLQPLZLJ7FKDuMlPPawXMZY2edqvj7nAT4ozqyuU0fZyAd9QTeoaWVZTsRPgkD9zEtc9yfSdknYGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=prevas.dk; dmarc=pass action=none header.from=prevas.dk; dkim=pass header.d=prevas.dk; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prevas.dk; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kAecCNZD3i6+PPVIOG0UvV8jfJfKnbRYZ4EWKpR3XcU=; b=Qlp+P8/y8puhPHLfSpDKDK3nH2xHLF6wejFEK5ipD4bUO5hPciBuXhRJuSJejol8sJKdlyV3FhVXvzopkU5Bg3DKYc0Mryy180uXxIJcnBSZt+yQuAc7+FUBOHln+0lmPAPAdTuxmhsPS2P/UdPoOh1rSN5tTEXV6Ahsnb5BeMk= Authentication-Results: lists.denx.de; dkim=none (message not signed) header.d=none;lists.denx.de; dmarc=none action=none header.from=prevas.dk; Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:e1::21) by VI1PR10MB2061.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:3a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 22:01:32 +0000 Received: from VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::f0ac:4e97:2536:faa]) by VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM ([fe80::f0ac:4e97:2536:faa%7]) with mapi id 15.20.3000.034; Tue, 19 May 2020 22:01:32 +0000 From: Rasmus Villemoes To: u-boot@lists.denx.de Cc: Simon Glass , Heiko Schocher , Biwen Li , Rasmus Villemoes Subject: [PATCH v2 07/10] rtc: sandbox-rtc: fix set method Date: Wed, 20 May 2020 00:01:14 +0200 Message-Id: <20200519220117.24448-8-rasmus.villemoes@prevas.dk> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200519220117.24448-1-rasmus.villemoes@prevas.dk> References: <20200504212032.3759-1-rasmus.villemoes@prevas.dk> <20200519220117.24448-1-rasmus.villemoes@prevas.dk> X-ClientProxiedBy: AM5PR04CA0032.eurprd04.prod.outlook.com (2603:10a6:206:1::45) To VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:803:e1::21) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from prevas-ravi.prevas.se (5.186.116.45) by AM5PR04CA0032.eurprd04.prod.outlook.com (2603:10a6:206:1::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.26 via Frontend Transport; Tue, 19 May 2020 22:01:31 +0000 X-Mailer: git-send-email 2.23.0 X-Originating-IP: [5.186.116.45] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 68a6546b-37c2-4c37-0eb4-08d7fc403071 X-MS-TrafficTypeDiagnostic: VI1PR10MB2061: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-Forefront-PRVS: 040866B734 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qd6nBxbJYqdh0AhMk1+tOkqhPxt2LnnvmtKh2TxVlGKXNLdK+MBWCIgOnAuWWEbSxiLFmkPHDXJLMpTzbdyv4/aYVetY84rqEoyRR7mls962YVG7DMexz8M9cO7gBgGWFRSrflzQiRF+rTNyjLtd7L5Hs+Ycihgr3sDG+UuY8Lenfo9FNpJaJlz805kgIzVYGgwIZAgP/gVMrJ1e1KLUZt8qDROHdZvA8BsGONZ6pGZOvJZCLQNUt+HLKKNiSHZU6g3kXSa4hJM+sJTblxSpb4MSf6arqyATbdL/u36n/wwfl8ZJuVtWTqZJh3iyOr8mPDkhIROD9plgaQ7Vr6tHQF+c8dpCrWvS0N1+W4doVz1MLEvEo5jfgFAsUQtcBAMVA1JWN7x34BOYY9YDXcH2raPz6PU4qWerhpOXQABvIl8Eaj7Pj8o46G1GFiWWS2OA X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR10MB2765.EURPRD10.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFTY:; SFS:(396003)(376002)(366004)(39830400003)(346002)(136003)(6486002)(2906002)(86362001)(186003)(16526019)(26005)(66556008)(2616005)(66946007)(44832011)(66476007)(956004)(1076003)(8976002)(6916009)(6666004)(316002)(5660300002)(107886003)(54906003)(8676002)(6506007)(478600001)(4326008)(36756003)(52116002)(6512007)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: H3lnT594j0fq3OIo/cI2bjUcW/jETMfLVs/v1MIG+n6sC5hMRXhzyuykvSt2os73L5Pc5V9jp/tjLcCf7n3hrPN5h4YB/nytZSS+27Eo8iGDXcuJ6Ua5lXct+KxMkr74z1lEf6YN2JfJ9QnRYwV+Hs9giVImtzMZ0UTwQG+bNaNT/zHQhCj5AEXoPUumSgOQ2HJiAP8uAe3MsUiNSvVYtg6sO3js0IgM1lYwGIHc0ZN6vom2e6y/I9S+UQoY6SjR2ZRof1VtgnxYd6d1TD65NcOL4XnITY2rnIm64/jKHRd8oWpN9lRY5O9WCec1VZLaO2/dwNO6kkKgY30iaOCoZfEHa+myYYgczd8JUrFE4h1BCmxqMT5YKjiSAvwJc65HXSiFimZWsOSRIZP0xenGPOiZkZ4yqjQeQMuItgkedOszmJxJ78dzDbZserCClWBuu3bY6KaHclWQwETneKl3c5Bm8o/wtvf5nnZn7S0qeeg= X-OriginatorOrg: prevas.dk X-MS-Exchange-CrossTenant-Network-Message-Id: 68a6546b-37c2-4c37-0eb4-08d7fc403071 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 22:01:31.9215 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: d350cf71-778d-4780-88f5-071a4cb1ed61 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: X7UhksHTEJ2ehlgs/espwiMN6UI2e8FoayvV3w6spjxVPzEWIf9CG8iIGAFrN0FWlOXn/Nf+2mnQhk9pTyeWn5dqreLC+NhxU5I5fBxplgs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR10MB2061 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 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.102.2 at phobos.denx.de X-Virus-Status: Clean 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". Signed-off-by: Rasmus Villemoes Reviewed-by: Simon Glass --- drivers/rtc/sandbox_rtc.c | 65 +++++++++++++++------------------------ test/dm/rtc.c | 15 ++++++++- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/drivers/rtc/sandbox_rtc.c b/drivers/rtc/sandbox_rtc.c index b08d758a74..77065e49c7 100644 --- a/drivers/rtc/sandbox_rtc.c +++ b/drivers/rtc/sandbox_rtc.c @@ -14,55 +14,38 @@ static int sandbox_rtc_get(struct udevice *dev, struct rtc_time *time) { - time->tm_sec = dm_i2c_reg_read(dev, REG_SEC); - if (time->tm_sec < 0) - return time->tm_sec; - time->tm_min = dm_i2c_reg_read(dev, REG_MIN); - if (time->tm_min < 0) - return time->tm_min; - time->tm_hour = dm_i2c_reg_read(dev, REG_HOUR); - if (time->tm_hour < 0) - return time->tm_hour; - time->tm_mday = dm_i2c_reg_read(dev, REG_MDAY); - if (time->tm_mday < 0) - return time->tm_mday; - time->tm_mon = dm_i2c_reg_read(dev, REG_MON); - if (time->tm_mon < 0) - return time->tm_mon; - time->tm_year = dm_i2c_reg_read(dev, REG_YEAR); - if (time->tm_year < 0) - return time->tm_year; - time->tm_year += 1900; - time->tm_wday = dm_i2c_reg_read(dev, REG_WDAY); - if (time->tm_wday < 0) - return time->tm_wday; + u8 buf[7]; + int ret; + + ret = dm_i2c_read(dev, REG_SEC, buf, sizeof(buf)); + if (ret < 0) + return ret; + + time->tm_sec = buf[REG_SEC - REG_SEC]; + time->tm_min = buf[REG_MIN - REG_SEC]; + time->tm_hour = buf[REG_HOUR - REG_SEC]; + time->tm_mday = buf[REG_MDAY - REG_SEC]; + time->tm_mon = buf[REG_MON - REG_SEC]; + time->tm_year = buf[REG_YEAR - REG_SEC] + 1900; + time->tm_wday = buf[REG_WDAY - REG_SEC]; return 0; } static int sandbox_rtc_set(struct udevice *dev, const struct rtc_time *time) { + u8 buf[7]; int ret; - ret = dm_i2c_reg_write(dev, REG_SEC, time->tm_sec); - if (ret < 0) - return ret; - ret = dm_i2c_reg_write(dev, REG_MIN, time->tm_min); - if (ret < 0) - return ret; - ret = dm_i2c_reg_write(dev, REG_HOUR, time->tm_hour); - if (ret < 0) - return ret; - ret = dm_i2c_reg_write(dev, REG_MDAY, time->tm_mday); - if (ret < 0) - return ret; - ret = dm_i2c_reg_write(dev, REG_MON, time->tm_mon); - if (ret < 0) - return ret; - ret = dm_i2c_reg_write(dev, REG_YEAR, time->tm_year - 1900); - if (ret < 0) - return ret; - ret = dm_i2c_reg_write(dev, REG_WDAY, time->tm_wday); + buf[REG_SEC - REG_SEC] = time->tm_sec; + buf[REG_MIN - REG_SEC] = time->tm_min; + buf[REG_HOUR - REG_SEC] = time->tm_hour; + buf[REG_MDAY - REG_SEC] = time->tm_mday; + buf[REG_MON - REG_SEC] = time->tm_mon; + buf[REG_YEAR - REG_SEC] = time->tm_year - 1900; + buf[REG_WDAY - REG_SEC] = time->tm_wday; + + ret = dm_i2c_write(dev, REG_SEC, buf, sizeof(buf)); if (ret < 0) return ret; diff --git a/test/dm/rtc.c b/test/dm/rtc.c index 7188742764..e5454139cd 100644 --- a/test/dm/rtc.c +++ b/test/dm/rtc.c @@ -69,7 +69,20 @@ static int dm_test_rtc_set_get(struct unit_test_state *uts) old_base_time = sandbox_i2c_rtc_get_set_base_time(emul, -1); memset(&time, '\0', sizeof(time)); - time.tm_mday = 25; + time.tm_mday = 3; + time.tm_mon = 6; + time.tm_year = 2004; + time.tm_sec = 0; + time.tm_min = 18; + time.tm_hour = 18; + ut_assertok(dm_rtc_set(dev, &time)); + + memset(&cmp, '\0', sizeof(cmp)); + ut_assertok(dm_rtc_get(dev, &cmp)); + ut_assertok(cmp_times(&time, &cmp, true)); + + memset(&time, '\0', sizeof(time)); + time.tm_mday = 31; time.tm_mon = 8; time.tm_year = 2004; time.tm_sec = 0;