From patchwork Fri Nov 14 23:06:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnaud Ebalard X-Patchwork-Id: 5310101 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B21F4C11AC for ; Fri, 14 Nov 2014 23:07:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BCE452012B for ; Fri, 14 Nov 2014 23:07:30 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D5A7F20123 for ; Fri, 14 Nov 2014 23:07:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XpPvZ-0005dt-OD; Fri, 14 Nov 2014 23:05:17 +0000 Received: from 36.223.133.77.rev.sfr.net ([77.133.223.36] helo=smtp.natisbad.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XpPvW-0004Qq-FM for linux-arm-kernel@lists.infradead.org; Fri, 14 Nov 2014 23:05:15 +0000 Received: by smtp.natisbad.org (Postfix, from userid 109) id 8CEFF1700699; Sat, 15 Nov 2014 00:04:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=natisbad.org; s=mail; t=1416006270; bh=FFC+MLd9TMSfkbe/QYf0OulDShtAW0qzJ9vCJ8ORAJk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=fBBOqu0HkBpSu+eVKk/feTohHNAQJb7eU8J+J1HB78Q3qkjKwRlm7V1mtcNtaxt80 qngMQZZR6YTGU6oDPdOhqJO36c1GU8ez+fp8UETLnJmfG0RkzNOrtpDVEIMpJ2zQuT zCNv1/S6zD0tIKznOZlH6iYT4xc0RSTBl1ig3hy4= X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from small (localhost [IPv6:::1]) by smtp.natisbad.org (Postfix) with ESMTP id 739B01700508; Sat, 15 Nov 2014 00:03:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=natisbad.org; s=mail; t=1416006203; bh=FFC+MLd9TMSfkbe/QYf0OulDShtAW0qzJ9vCJ8ORAJk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=viX15cC/IhamZS5qxEumXBXII6oK6ZNy5G1NtfggL2+DRGh9hNqvNIHy/DNgMyu7T SgKdIIGNcpCCuMmSN+waMr/iVI5pnQ70TGfSFfTDpdjB7pkxHGnJPM47jfcx8Euy6k NjWNwzTwgEtHLyNeDV9iVc3jG2C+WoQJ2nchajTE= X-Hashcash: 1:20:141114:mark.rutland@arm.com::y3X2MNX6vhU+kfcZ:000000000000000000000000000000000000000000IOF X-Hashcash: 1:20:141114:a.zummo@towertech.it::koa3n+BliaAB6Wq5:000000000000000000000000000000000000000000fDq X-Hashcash: 1:20:141114:peter.huewe@infineon.com::KFQOle5ec6OcUC6B:00000000000000000000000000000000000000PhP X-Hashcash: 1:20:141114:linus.walleij@linaro.org::zY3Ar+Qy5H6jP+L8:00000000000000000000000000000000000000/+j X-Hashcash: 1:20:141114:treding@nvidia.com::ErnOIW5e8AYG7ZK4:0000000000000000000000000000000000000000000AHJG X-Hashcash: 1:20:141114:broonie@kernel.org::rfMb/AvNU1WDT654:00000000000000000000000000000000000000000000oZw X-Hashcash: 1:20:141114:rob.herring@calxeda.com::e7WQNF/piE8Ul4d5:000000000000000000000000000000000000002Uly X-Hashcash: 1:20:141114:pawel.moll@arm.com::t6VlD2OoFe+qZ9M8:0000000000000000000000000000000000000000000116o X-Hashcash: 1:20:141114:swarren@wwwdotorg.org::kvjgKHITAENcXNeQ:000000000000000000000000000000000000000065yd X-Hashcash: 1:20:141114:ijc+devicetree@hellion.org.uk::ICA1TmvO2eeHN2hK:000000000000000000000000000000002W6A X-Hashcash: 1:20:141114:grant.likely@linaro.org::raMZv74AWN+xU8jv:000000000000000000000000000000000000000B5G X-Hashcash: 1:20:141114:devicetree@vger.kernel.org::u111Wr9fijJplOb3:000000000000000000000000000000000004wyQ X-Hashcash: 1:20:141114:linux-doc@vger.kernel.org::655lxOP/8NpXr91Y:0000000000000000000000000000000000001WxO X-Hashcash: 1:20:141114:rob@landley.net::uZ7E3YJVWUcj/2Ev:002PqE X-Hashcash: 1:20:141114:rtc-linux@googlegroups.com::0sEVnL51f3cb2kmt:000000000000000000000000000000000009xDU X-Hashcash: 1:20:141114:jason@lakedaemon.net::/07Dw72YKnDrP3r0:000000000000000000000000000000000000000000bsV X-Hashcash: 1:20:141114:linux@roeck-us.net::dPRSjCrRh5MTB4QF:0000000000000000000000000000000000000000000G/7H X-Hashcash: 1:20:141114:jgunthorpe@obsidianresearch.com::pthn/bUlCPPw3yqr:0000000000000000000000000000006xVG X-Hashcash: 1:20:141114:galak@codeaurora.org::MgLxC6dI8GjnBcuE:00000000000000000000000000000000000000000CRPo X-Hashcash: 1:20:141114:linux-arm-kernel@lists.infradead.org::luJKlLycSCliUKgP:00000000000000000000000008Yai X-Hashcash: 1:20:141114:uwe@kleine-koenig.org::lxVlqvkn//JVURJn:000000000000000000000000000000000000000023mz From: Arnaud Ebalard To: Mark Rutland , Alessandro Zummo , Peter Huewe , Linus Walleij , Thierry Reding , Mark Brown Subject: [PATCHv1 2/6] rtc: rtc-isl12057: add support for century bit In-Reply-To: References: Message-Id: <83c5f7964faf3b04371f2dd447b78d65f0c11fb8.1416006090.git.arno@natisbad.org> Date: Sat, 15 Nov 2014 00:06:41 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141114_150514_916222_B1791BD0 X-CRM114-Status: GOOD ( 16.47 ) X-Spam-Score: 0.3 (/) Cc: devicetree@vger.kernel.org, rtc-linux@googlegroups.com, Pawel Moll , Ian Campbell , Stephen Warren , linux-doc@vger.kernel.org, Rob Herring , Jason Gunthorpe , Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, Rob Landley , Kumar Gala , Grant Likely , Guenter Roeck , Jason Cooper X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The month register of ISL12057 RTC chip includes a century bit which reports overflow of year register from 99 to 0. This bit can also be written, which allows using it to extend the time interval the chip can support from 99 to 199 years. This patch adds support for century overflow bit in tm to regs and regs to tm helpers in ISL12057 driver. This was tested by putting a device 100 years in the future (using a specific kernel due to the inability of userland tools such as date or hwclock to pass year 2038), rebooting on a kernel w/ this patch applied and verifying the device was still 100 years in the future. Suggested-by: Uwe Kleine-König Signed-off-by: Arnaud Ebalard --- drivers/rtc/rtc-isl12057.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/rtc/rtc-isl12057.c b/drivers/rtc/rtc-isl12057.c index 8c3f60737df8..b538fabfcfd3 100644 --- a/drivers/rtc/rtc-isl12057.c +++ b/drivers/rtc/rtc-isl12057.c @@ -41,6 +41,7 @@ #define ISL12057_REG_RTC_DW 0x03 /* Day of the Week */ #define ISL12057_REG_RTC_DT 0x04 /* Date */ #define ISL12057_REG_RTC_MO 0x05 /* Month */ +#define ISL12057_REG_RTC_MO_CEN BIT(7) /* Century bit */ #define ISL12057_REG_RTC_YR 0x06 /* Year */ #define ISL12057_RTC_SEC_LEN 7 @@ -99,24 +100,35 @@ static void isl12057_rtc_regs_to_tm(struct rtc_time *tm, u8 *regs) tm->tm_wday = bcd2bin(regs[ISL12057_REG_RTC_DW]) - 1; /* starts at 1 */ tm->tm_mon = bcd2bin(regs[ISL12057_REG_RTC_MO] & 0x1f) - 1; /* ditto */ tm->tm_year = bcd2bin(regs[ISL12057_REG_RTC_YR]) + 100; + + /* Check if years register has overflown from 99 to 00 */ + if (regs[ISL12057_REG_RTC_MO] & ISL12057_REG_RTC_MO_CEN) + tm->tm_year += 100; } static int isl12057_rtc_tm_to_regs(u8 *regs, struct rtc_time *tm) { + u8 century_bit; + /* * The clock has an 8 bit wide bcd-coded register for the year. + * It also has a century bit encoded in MO flag which provides + * information about overflow of year register from 99 to 00. * tm_year is an offset from 1900 and we are interested in the - * 2000-2099 range, so any value less than 100 is invalid. + * 2000-2199 range, so any value less than 100 or larger than + * 299 is invalid. */ - if (tm->tm_year < 100) + if (tm->tm_year < 100 || tm->tm_year > 299) return -EINVAL; + century_bit = (tm->tm_year > 199) ? ISL12057_REG_RTC_MO_CEN : 0; + regs[ISL12057_REG_RTC_SC] = bin2bcd(tm->tm_sec); regs[ISL12057_REG_RTC_MN] = bin2bcd(tm->tm_min); regs[ISL12057_REG_RTC_HR] = bin2bcd(tm->tm_hour); /* 24-hour format */ regs[ISL12057_REG_RTC_DT] = bin2bcd(tm->tm_mday); - regs[ISL12057_REG_RTC_MO] = bin2bcd(tm->tm_mon + 1); - regs[ISL12057_REG_RTC_YR] = bin2bcd(tm->tm_year - 100); + regs[ISL12057_REG_RTC_MO] = bin2bcd(tm->tm_mon + 1) | century_bit; + regs[ISL12057_REG_RTC_YR] = bin2bcd(tm->tm_year % 100); regs[ISL12057_REG_RTC_DW] = bin2bcd(tm->tm_wday + 1); return 0;