From nobody Fri Dec 10 16:09:38 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id B534E18D2CFB; Fri, 10 Dec 2021 16:09:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J9bSy2bG4z4vFR; Fri, 10 Dec 2021 16:09:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 38AB21D6B1; Fri, 10 Dec 2021 16:09:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BAG9csl050765; Fri, 10 Dec 2021 16:09:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BAG9cSh050764; Fri, 10 Dec 2021 16:09:38 GMT (envelope-from git) Date: Fri, 10 Dec 2021 16:09:38 GMT Message-Id: <202112101609.1BAG9cSh050764@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wojciech Macek Subject: git: 3662b8f1cf77 - main - pcf85063: Fix real time clock List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wma X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3662b8f1cf7729853f77125af7ad4c822c285eee Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639152578; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Veh/x2KPL8uESqCjmWsju/o913NhUt8Rtayj020JWUI=; b=DZTfS9AxqOiTaf9rhIpDhAbby0fkWx2/3v5+TU4tz3vH2JkZkviXcXdeC6N4+ssVLmFq4o bvt3/LnK2CfDrhtQ1xLXXLumNAjkATIZGMXjOoJvo6ctcgmiLtzyI/LGGE5IpW0nKS7Kn0 jCQWJ1qdGV5tu6+HoLynBxlSpYtmgbZcwXMWJj2LgK0DAq/myxSTbs07CVFRFz8/9MDlRO W9GPRm8U7pj3Q2RT1xzIY/kDA5OdBBp7aIFit3U1z8pRzFDJekD3X9ktwES0R82W8VlzaU pG6jn3T9gnFcLlsJT/DQjO0oIF5VTdT4Q41llE1KXoyLBSnvK958vZ2bX6PUhA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639152578; a=rsa-sha256; cv=none; b=cLwU8skBj12MkEeSs3joOPWsdNLuXyQuGEy+r06R/HaGB59F7mWMBshqi8EfyQq5XXhhEN sOi+sU25Jtlu5PQ1k8QnqDr39Z25jCVExpX7mQrShwQVGfeLo1duW/nKc1zGnuLDMxMy7i x7feDdTKgYF1zwiXfx992JQzQw8IIQxYUEKDOwjtsfcVrp8CAR3xFKDFyTFXt7ItK80dWM DlJwDvfflRoBQUYIsd3DTQiaQ7axhQUu1Xokvsis9tOerAdyhfGTM5rRZiisB15OPDleL3 3wODqlAnlBfczJAQK3vZpX8Vp1esJXfNjuur6mtZODAvTGwj5NaRh/7+YPGRmg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=3662b8f1cf7729853f77125af7ad4c822c285eee commit 3662b8f1cf7729853f77125af7ad4c822c285eee Author: Hubert Mazur AuthorDate: 2021-12-10 15:07:25 +0000 Commit: Wojciech Macek CommitDate: 2021-12-10 16:09:29 +0000 pcf85063: Fix real time clock Previosuly real time clock driver always set time format to 12-hour mode. Fix this by choosing hour mode depending on HW register. --- sys/dev/iicbus/rtc/pcf85063.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/sys/dev/iicbus/rtc/pcf85063.c b/sys/dev/iicbus/rtc/pcf85063.c index f3038ac32340..dad52239f061 100644 --- a/sys/dev/iicbus/rtc/pcf85063.c +++ b/sys/dev/iicbus/rtc/pcf85063.c @@ -147,14 +147,17 @@ pcf85063_get_time(device_t dev, struct timespec *ts) bcd.nsec = 0; bcd.sec = data.sec & 0x7F; bcd.min = data.min & 0x7F; - bcd.ispm = data.hour & 0x20; - if (control_reg & PCF85063_CTRL1_TIME_FORMAT) + if (control_reg & PCF85063_CTRL1_TIME_FORMAT) { /* 12 hour mode */ bcd.hour = data.hour & 0x1F; - else + /* Check if hour is pm */ + bcd.ispm = data.hour & 0x20; + } else { /* 24 hour mode */ bcd.hour = data.hour & 0x3F; + bcd.ispm = false; + } bcd.dow = (data.dow & 0x7) + 1; bcd.day = data.day & 0x3F; @@ -162,7 +165,8 @@ pcf85063_get_time(device_t dev, struct timespec *ts) bcd.year = data.year; clock_dbgprint_bcd(dev, CLOCK_DBG_READ, &bcd); - error = clock_bcd_to_ts(&bcd, ts, true); + error = clock_bcd_to_ts(&bcd, ts, + control_reg & PCF85063_CTRL1_TIME_FORMAT); return (error); } @@ -175,8 +179,11 @@ pcf85063_set_time(device_t dev, struct timespec *ts) struct bcd_clocktime bcd; int error; + error = iicdev_readfrom(dev, PCF85063_TIME_REG, &ctrl_reg, + sizeof(uint8_t), IIC_WAIT); + ts->tv_sec -= utc_offset(); - clock_ts_to_bcd(ts, &bcd, true); + clock_ts_to_bcd(ts, &bcd, ctrl_reg & PCF85063_CTRL1_TIME_FORMAT); clock_dbgprint_bcd(dev, CLOCK_DBG_WRITE, &bcd); data.sec = bcd.sec; @@ -187,6 +194,11 @@ pcf85063_set_time(device_t dev, struct timespec *ts) data.mon = bcd.mon; data.year = bcd.year; + /* Set this bit in case of 12-hour mode and pm hour. */ + if (!(ctrl_reg & PCF85063_CTRL1_TIME_FORMAT)) + if (bcd.ispm) + data.hour |= 0x20; + if (ts->tv_nsec > PCF85063_HALF_OF_SEC_NS) data.sec++;