From patchwork Fri Sep 17 06:46:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathew McBride X-Patchwork-Id: 514169 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp1944248jao; Thu, 16 Sep 2021 23:47:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzun3VROMPCKYLZWjaxA2wU11t+vbta2ZwWs2RaPVX5pkDKra6uCu90uuEwVVmsnvZqDkj0 X-Received: by 2002:a17:907:1b06:: with SMTP id mp6mr10169329ejc.188.1631861243769; Thu, 16 Sep 2021 23:47:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631861243; cv=none; d=google.com; s=arc-20160816; b=ojz354glQr40tX/1zcI4XrEP5JZLHiSMnrZq6DWKmth+271G/ikCNuaMdGriP3ekA5 pLD3ZBLD3oCLjdAD3IPUT8bdgIUsx+jEO9RqRYdxO97CzJ09iUWJkiZ1d5GgxoqaM1/h 8twBvOi6wdG1UDok53wZ+KnWOWq3O6rV4xLcjksTilmDLjxlxiEMs0DyIVIWRz99km1W sy4mtPYBo7iUo/a2WOsCoktXMF+qiuUw5jOuY5i4bDXsO9bo98FeNSh9/LTXw2zscUmH 7q1OYIZvQTFnYPeSHNoHS2zY0IPz0JAh650PRccHLFkI3TVu3Y9VSx3sgmQ7LXHGXGfd 7+KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dkim-signature; bh=MHQ0Dzp4J2auLnbQOKEqK7x6t858fjiad6JaGCsIRvU=; b=ho8e9djQIDhhGBdeyjapJtS+6zIc3jR9+1a0+rweHnKigY0RUa31wfQWwnsAwUSFdV 0GtZTQ+skVVz05Y7r1QfjWfmJGqXTfVI4+j3p+3Amlthvr+IrncDPWWZG2CyiYh3ts8A 6Dshw21d+PCnscMCUNHs6Qk0pGL5PhQD8wl76dyY1CwmeMZ7mgDktLnu8nT75yteDQHB KxMDUEANLx9I8cDr7YVIIwtyUIImi/5F839V0YZZ0Mym0olHqWNihIYy6z4fJF9HDkhd juaEZyJRT8PL/shC+Rt7bBIwwO3TbntHGqRxNK/buunNP/XjIisZDFtCSyr153j0/1xW 00Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@traverse.com.au header.s=fm1 header.b=BicDGa8q; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=F1bePsuL; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 5si6037072ejm.407.2021.09.16.23.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 23:47:23 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@traverse.com.au header.s=fm1 header.b=BicDGa8q; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=F1bePsuL; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 31AEB83231; Fri, 17 Sep 2021 08:46:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=traverse.com.au Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=traverse.com.au header.i=@traverse.com.au header.b="BicDGa8q"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="F1bePsuL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6556F82F34; Fri, 17 Sep 2021 08:46:35 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (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 55659831C8 for ; Fri, 17 Sep 2021 08:46:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=traverse.com.au Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=matt@traverse.com.au Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 7B2CE5C0107; Fri, 17 Sep 2021 02:46:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 17 Sep 2021 02:46:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=traverse.com.au; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=MHQ0Dzp4J2auL nbQOKEqK7x6t858fjiad6JaGCsIRvU=; b=BicDGa8qm18+7yCNFUbHxjzuH2IOp wCeVneaqCjHT3LlhfrLAEDopoQSiZO/tjMMb214p0qPLaqbjl7kalzl+BwT2Qz5L Wbfy9CWjLOeCZ2KxSxqoE/0XpuxZB71lt9Ls6F8hbENBrSuFyb+XE2sY+xEeTjP5 PpEpmVDR+4nFntHxpFjHyiBIANT6V8WurQNHet7KskhIqeF6D9nCYR/xZ5nK+Nut koeqgW86FHfJIgAy3apFiSW89l+yeEPhA+wc0LauytYTWVBlkX0+6BAYGGhg7dJs ZK/7JWGUPC25T62T8oWMzvCTJ7fog/qakxPO/j412lrVE8wz9UhgD0Lpw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=MHQ0Dzp4J2auLnbQOKEqK7x6t858fjiad6JaGCsIRvU=; b=F1bePsuL XMIGuxEqqZYHjgFcVwg3sjn7WUGgP7axlzqqW17Q2t7f4/hN50JR+Y+yaVrxdD4b aByxROP05OwSKDhebMZYPucbKelI0cn+Jv/FNa6S6GB3JtHKJE9X7p/8P8zq524A 5y4pUCfoaKY4vWW/tbGNe+fq78Y4IiygzNx0bOMPNebArps0/HwQQE861EEgTfCc UsMSiACXHtojwPoqjJfUToF6LuiBdVA+x9IUT8DsAIVsoBbH6M7dxOpLXo86NY4h fCZig8e/iAc1hDDoFLHiOdJ9BEaItrmEJBf8gVcSPb0bilsJXwnJcnxjC52hv6sO kSnGDueWzWQ9ig== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudehhedguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpeforghthhgvficuofgtuehrihguvgcuoehmrghtthesthhr rghvvghrshgvrdgtohhmrdgruheqnecuggftrfgrthhtvghrnhepkeelveetledvudehte fgvdefleeukeffgeegteehtdetleejieevvdfgheejjeehnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhgrthhtsehtrhgrvhgvrhhsvgdrtg homhdrrghu X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 17 Sep 2021 02:46:22 -0400 (EDT) From: Mathew McBride To: u-boot@lists.denx.de Cc: Mathew McBride Subject: [PATCH 3/4] rtc: rx8025: set date in a single i2c transaction Date: Fri, 17 Sep 2021 06:46:03 +0000 Message-Id: <20210917064604.3912-4-matt@traverse.com.au> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210917064604.3912-1-matt@traverse.com.au> References: <20210917064604.3912-1-matt@traverse.com.au> MIME-Version: 1.0 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 The RX8025/RX8035 does not like having it's time registers set byte-by-byte in separate I2C transactions. >From the note at the top of the file, it appears target-dependent workarounds have been used in the past for this. Resolve this by setting the time registers in a single I2C transaction. As part of this, also ensure the '24/12' flag in the RTC is reset before writing the date (instead of after), otherwise the RX8035 will clear the seconds and minutes registers. Tested on Traverse Ten64 (NXP LS1088A) with RX8035. Signed-off-by: Mathew McBride --- drivers/rtc/rx8025.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) -- 2.30.1 diff --git a/drivers/rtc/rx8025.c b/drivers/rtc/rx8025.c index 09bf365f63..9423a1bb82 100644 --- a/drivers/rtc/rx8025.c +++ b/drivers/rtc/rx8025.c @@ -39,6 +39,7 @@ enum rx_model { #define RTC_DATE_REG_ADDR 0x04 #define RTC_MON_REG_ADDR 0x05 #define RTC_YR_REG_ADDR 0x06 +#define RTC_OFFSET_REG_ADDR 0x07 #define RTC_CTL1_REG_ADDR 0x0e #define RTC_CTL2_REG_ADDR 0x0f @@ -152,6 +153,19 @@ static int rx8025_rtc_get(struct udevice *dev, struct rtc_time *tmp) */ static int rx8025_rtc_set(struct udevice *dev, const struct rtc_time *tmp) { + /* To work around the read/write cycle issue mentioned + * at the top of this file, write all the time registers + * in one I2C transaction + */ + u8 write_op[8]; + + /* 2412 flag must be set before doing a RTC write, + * otherwise the seconds and minute register + * will be cleared when the flag is set + */ + if (rtc_write(dev, RTC_CTL1_REG_ADDR, RTC_CTL1_BIT_2412)) + return -EIO; + DEBUGR("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); @@ -159,28 +173,16 @@ static int rx8025_rtc_set(struct udevice *dev, const struct rtc_time *tmp) if (tmp->tm_year < 1970 || tmp->tm_year > 2069) printf("WARNING: year should be between 1970 and 2069!\n"); - if (rtc_write(dev, RTC_YR_REG_ADDR, bin2bcd(tmp->tm_year % 100))) - return -EIO; - - if (rtc_write(dev, RTC_MON_REG_ADDR, bin2bcd(tmp->tm_mon))) - return -EIO; - - if (rtc_write(dev, RTC_DAY_REG_ADDR, bin2bcd(tmp->tm_wday))) - return -EIO; - - if (rtc_write(dev, RTC_DATE_REG_ADDR, bin2bcd(tmp->tm_mday))) - return -EIO; - - if (rtc_write(dev, RTC_HR_REG_ADDR, bin2bcd(tmp->tm_hour))) - return -EIO; - - if (rtc_write(dev, RTC_MIN_REG_ADDR, bin2bcd(tmp->tm_min))) - return -EIO; - - if (rtc_write(dev, RTC_SEC_REG_ADDR, bin2bcd(tmp->tm_sec))) - return -EIO; + write_op[RTC_SEC_REG_ADDR] = bin2bcd(tmp->tm_sec); + write_op[RTC_MIN_REG_ADDR] = bin2bcd(tmp->tm_min); + write_op[RTC_HR_REG_ADDR] = bin2bcd(tmp->tm_hour); + write_op[RTC_DAY_REG_ADDR] = bin2bcd(tmp->tm_wday); + write_op[RTC_DATE_REG_ADDR] = bin2bcd(tmp->tm_mday); + write_op[RTC_MON_REG_ADDR] = bin2bcd(tmp->tm_mon); + write_op[RTC_YR_REG_ADDR] = bin2bcd(tmp->tm_year % 100); + write_op[RTC_OFFSET_REG_ADDR] = 0; - return rtc_write(dev, RTC_CTL1_REG_ADDR, RTC_CTL1_BIT_2412); + return dm_i2c_write(dev, 0, &write_op[0], 8); } /*