From patchwork Tue Jan 2 05:10:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 123090 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8567236qgn; Mon, 1 Jan 2018 21:10:50 -0800 (PST) X-Google-Smtp-Source: ACJfBotZN/RlZ1hVmbZa2AMtmuDwIaT5cM6tEWngw38ZpJd4eaDeRzLpH1PcG0Pmp8pldbuZOk4k X-Received: by 10.99.2.13 with SMTP id 13mr8628615pgc.427.1514869850099; Mon, 01 Jan 2018 21:10:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514869850; cv=none; d=google.com; s=arc-20160816; b=BbujXz23Lj61aHJqSkgv2WdABrCT1HWq2fa2m9dBK9D1+fbierPLeheqQn6RWWfutY DMQO8X/tBq9tszMsatC0kJWkcclNShqGUiV5NUCI1eojr84Hiw/UZvzz4Q9iVjA3VPHo vGGclrWTS6Tk28gw+Vr7D4LRQqkGGXl2AhkpJSr1LSlblRiLVlP5BEcD2Ln2CQ8ndA+Z LCTMeGyM/q+lcB1QaOnwZrk6HTCAdR0szxEhS71LPRNJ66Ben7OPSqjgRYO173vqMUhw +EYlQ1SvBHqdPBkz7TXS0hDhgjKU4dJzQtpc1mBqQ6gsrCsG1GjJibx4ThMYECBCR/od HCUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=G9sSaSOkR0mwSBUMiQvlccBzBe4nPRlyOtDuvIoqKnI=; b=PUvsUebg912DCE4azg0pCmfO0Lgfcag1pRRbonqr/NUf7dTWe1qMs3W6CEmQyOs/Is vRZxFMpS8RHvT6Wc7+bxY6la27hYUTHSjrN/D6SrmrP8SIpDb6E9vSv/TvmNllaMhFBF gdl6arDfQmfQyiWff3eNkWI8Tppfb4OTnMptbubY+3BHtaCKTxv7SmxZAybC9aPSarAu C8Z8EBMO3mmqiT6YbJsQmRp1DMEK9wNBUf7TZIpfT4TIMLlp6g6JymWFccJ7W3a0sYzg jJS4o2u+PeIF74dfkXWVrgRRfjXl6uZSKnqn06odtE5azpdmF4vvO2X/Cf6eZYHsvaGr nvJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EDFL2SaY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11si27541101plg.702.2018.01.01.21.10.49; Mon, 01 Jan 2018 21:10:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EDFL2SaY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751430AbeABFKb (ORCPT + 28 others); Tue, 2 Jan 2018 00:10:31 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:45763 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751242AbeABFK3 (ORCPT ); Tue, 2 Jan 2018 00:10:29 -0500 Received: by mail-pf0-f196.google.com with SMTP id u19so25250247pfa.12 for ; Mon, 01 Jan 2018 21:10:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=G9sSaSOkR0mwSBUMiQvlccBzBe4nPRlyOtDuvIoqKnI=; b=EDFL2SaYjnRfNhse1+q2OaKPfmam0VX1JmiTwDL2zdnVHH2BnEcKU34bZg9ZietuvT nhuz+ZS/pwcp1yL43gulEMR2hj93GIhEs/lh36eoP3zgprRxpKA7JfInzIqAoO4CS7Js 05k0nzFiLT0fUycbO3IgcQWZ1aRQQ0QBbj2Vk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=G9sSaSOkR0mwSBUMiQvlccBzBe4nPRlyOtDuvIoqKnI=; b=bKwjvHa6hM+vDWw6gzdsM/Vt1Smj7+byx/MuhXfwb4bLg8GjDUAu5ngKD6aIjbAOBG 9Dn26mJCUImzGroQomcZUK9ba6cd1aVAOR8LmmTONfeGiNs9JsX/Zym/HKz7VAsn6Ud8 3pKeD9CnsAaqo2BdopwkDLcOHS+hTBgBg3JM/BrG2hXr+MSWFmbJI80scaF8IquvAOLx ZdyU8grEr+GpRfS4++8vLaKZ11ZvNdQRiCNCOVPHoTAE+at6bntaJY0Zaj1ye+jCOK+5 vthoHfODUf170Rwen9xYXfuyssOe0lxO6I3csdijGYNx6Xuoh/7nBUHr6RCcNYpfy1Qi oiBg== X-Gm-Message-State: AKGB3mI5fbmZHSwJ4PkNGhXYPX5tI7JRLmCBzOSFq8gld6W5bh7KkXRr psPEPgl8EmN5gbMhjD5JLUprFACdffQ= X-Received: by 10.101.75.3 with SMTP id r3mr20819364pgq.259.1514869828836; Mon, 01 Jan 2018 21:10:28 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id 6sm63989675pgf.54.2018.01.01.21.10.26 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Jan 2018 21:10:28 -0800 (PST) From: Baolin Wang To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com, corbet@lwn.net Cc: arnd@arndb.de, broonie@kernel.org, linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH 1/4] rtc: Introduce one interface to save the RTC hardware time range Date: Tue, 2 Jan 2018 13:10:05 +0800 Message-Id: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to the setting time values are not beyond the limitation supported by RTC hardware, we introduce one interface to tell the hardware range to the RTC core, which are used to valid if the setting time values are in the RTC hardware range. Moreover we also need the RTC hardware range to expand the RTC range in next patches by adding one offset. Signed-off-by: Baolin Wang --- drivers/rtc/class.c | 13 ++++++++++ drivers/rtc/interface.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/rtc.h | 9 +++++++ 3 files changed, 84 insertions(+) -- 1.7.9.5 diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 722d683..31fc0f1 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -247,6 +247,12 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, dev_set_name(&rtc->dev, "rtc%d", id); + err = rtc_read_range(rtc, &rtc->max_hw_secs, &rtc->min_hw_secs); + if (err) { + dev_err(&rtc->dev, "%s: failed to get RTC range\n", name); + goto exit_ida; + } + /* Check to see if there is an ALARM already set in hw */ err = __rtc_read_alarm(rtc, &alrm); @@ -436,6 +442,13 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc) rtc->owner = owner; + err = rtc_read_range(rtc, &rtc->max_hw_secs, &rtc->min_hw_secs); + if (err) { + dev_err(&rtc->dev, "%s: failed to get RTC range\n", + dev_name(&rtc->dev)); + return err; + } + /* Check to see if there is an ALARM already set in hw */ err = __rtc_read_alarm(rtc, &alrm); if (!err && !rtc_valid_tm(&alrm.time)) diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 672b192..c8090e3 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -65,6 +65,10 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) if (err != 0) return err; + err = rtc_valid_range(rtc, tm); + if (err) + return err; + err = mutex_lock_interruptible(&rtc->ops_lock); if (err) return err; @@ -329,6 +333,11 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) err = rtc_valid_tm(&alarm->time); if (err) return err; + + err = rtc_valid_range(rtc, &alarm->time); + if (err) + return err; + scheduled = rtc_tm_to_time64(&alarm->time); /* Make sure we're not setting alarms in the past */ @@ -1027,3 +1036,56 @@ int rtc_set_offset(struct rtc_device *rtc, long offset) mutex_unlock(&rtc->ops_lock); return ret; } + +/* rtc_read_range - Read the max and min hardware count supported by RTC device + * @ rtc: rtc device to be used. + * @ max_hw_secs: maximum hardware count in seconds, which can represent + * the maximum time values in RTC hardware. + * @ min_hw_secs: minimum hardware count in seconds, which can represent + * the minimum time values in RTC hardware. + * + * The max_hw_secs and min_hw_secs implemented by user must represent the + * correct hardware start time and maximum time, which means the count + * will wrap around to min_hw_secs after the maximum count. + * + * If user did not implement the read_range() interface, we can set max_hw_secs + * and min_hw_secs to 0, which avoids validing the range. + */ +int rtc_read_range(struct rtc_device *rtc, time64_t *max_hw_secs, + time64_t *min_hw_secs) +{ + int ret; + + if (!rtc->ops || !rtc->ops->read_range) { + *max_hw_secs = 0; + *min_hw_secs = 0; + return 0; + } + + mutex_lock(&rtc->ops_lock); + ret = rtc->ops->read_range(rtc->dev.parent, max_hw_secs, min_hw_secs); + mutex_unlock(&rtc->ops_lock); + + return ret; +} + +/* rtc_valid_range - Valid if the setting time in the RTC range + * @ rtc: rtc device to be used. + * @ tm: time values need to valid. + * + * Only the rtc->max_hw_secs was set, then we can valid if the setting time + * values are beyond the RTC range. + */ +int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm) +{ + time64_t secs; + + if (!rtc->max_hw_secs) + return 0; + + secs = rtc_tm_to_time64(tm); + if (secs < rtc->min_hw_secs || secs > rtc->max_hw_secs) + return -EINVAL; + + return 0; +} diff --git a/include/linux/rtc.h b/include/linux/rtc.h index 41319a2..19a8989 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -85,6 +85,8 @@ struct rtc_class_ops { int (*alarm_irq_enable)(struct device *, unsigned int enabled); int (*read_offset)(struct device *, long *offset); int (*set_offset)(struct device *, long offset); + int (*read_range)(struct device *, time64_t *max_hw_secs, + time64_t *min_hw_secs); }; #define RTC_DEVICE_NAME_SIZE 20 @@ -152,6 +154,9 @@ struct rtc_device { bool nvram_old_abi; struct bin_attribute *nvram; + time64_t max_hw_secs; + time64_t min_hw_secs; + #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL struct work_struct uie_task; struct timer_list uie_timer; @@ -225,6 +230,10 @@ int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer *timer, int rtc_set_offset(struct rtc_device *rtc, long offset); void rtc_timer_do_work(struct work_struct *work); +int rtc_read_range(struct rtc_device *rtc, time64_t *max_hw_secs, + time64_t *min_hw_secs); +int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm); + static inline bool is_leap_year(unsigned int year) { return (!(year % 4) && (year % 100)) || !(year % 400); From patchwork Tue Jan 2 05:10:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 123091 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8567243qgn; Mon, 1 Jan 2018 21:10:50 -0800 (PST) X-Google-Smtp-Source: ACJfBovLzkuXB6Cv9fbbUgapT7Wd7W8vJBh05VYGSSD0riDZ/XP0Yx+4a/e/DEUC+PNdUkhvYMHg X-Received: by 10.99.61.67 with SMTP id k64mr38799763pga.421.1514869850819; Mon, 01 Jan 2018 21:10:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514869850; cv=none; d=google.com; s=arc-20160816; b=cdFJP6k9hU6xRzL2qANG/IFU88BDcT5c9irKVlSTuG2iZb9f5xxGlax9YMHbX0WEx/ hKoXfZHdvVrzjNdOuT0jQMR5JTFnfk/iKTiCtbDT6zanL/c2Kq7bnFowf11h/ebDVrYp cd4rD3wzSEuq/kYKqegbNMQnQJTwY4Ywquql0mf13rE/qw15I+OHthJKdTSZzelf5qGD zlTefvmMip66e31o544fxC3TnPP8Aqekifwiui0mT10c+5XKx+7pcbTDQRnHkkZQjy71 k0+9NTL32Ye6GN2MK1LAhiyDbzTMIIY18xHX3tiOWAdg5eXVeiQ9nugSr8pHgKRTiSrZ XVwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=lTo38F1iaDK9ShkX7uHgWhIP4pdpecg189FrZlfTXUw=; b=lbkqaw9FN/pgASehyM+ZbKb0BIXia6FuuKeggEh24LiL4PpGKJrgZEt6fQr4590T/4 BuoNz95NyEnXu5yucpsPBc8LCKNQDNRW6BlNIj4wwo22k4jgcziRTA46kGlP94E1rFoc Zmb9s9rt5Zv+xwRWQGuOtQGz4R0axBdxr21iyphdrjWJtwhPY1sItBgvUztoXVzgmFAW 9T9RJnsMsjBjA+CQ3P6t7EIIA90/G4VlLCG/lOjeb+d10P1IAWTiDSJ413B+T4yJuQxY XSd9UZuNNMtH/q4/wpP+etYCCzIDZ5dP15ug7CO2mhY/WJtdpovulZs7hcnm2nFlpttY WYCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kI4xeHHg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11si27541101plg.702.2018.01.01.21.10.50; Mon, 01 Jan 2018 21:10:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kI4xeHHg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751503AbeABFKf (ORCPT + 28 others); Tue, 2 Jan 2018 00:10:35 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:40782 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751435AbeABFKc (ORCPT ); Tue, 2 Jan 2018 00:10:32 -0500 Received: by mail-pg0-f67.google.com with SMTP id q12so6967517pgt.7 for ; Mon, 01 Jan 2018 21:10:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=lTo38F1iaDK9ShkX7uHgWhIP4pdpecg189FrZlfTXUw=; b=kI4xeHHgZZKVofVFE7Qf6QxwymOICx5rA75pMZERuet3CsJ9NvYISvyNFKRwXCFX+3 O285WXeAPP4RajuEVWLNHdN7IE+VULsjCrGM91v+X3XdcZ9UaIBC0IdNXjeK5JyhVKIQ RWoezQwWDk31s4aX0pW81GfV4bn+kNoRKowJA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=lTo38F1iaDK9ShkX7uHgWhIP4pdpecg189FrZlfTXUw=; b=PI9uKqofCMYwOhwbuxArxd4MCEqRLI1ds6ZcELAQIXGrzr9BYd16uHF6ZLuOtBbW/r hcNSwz61XLlHTQBWsa1yJ9bC10TLt39NOMYEIyIByyeFOxaCi1U3ehZmRQ0N5TdiP5RJ ClYd3R+S0Wk4yNXSdwAZVe9JDgCeZ+zWurdA6RJLkrqXHV0cdK1iNbUe6sXqRE2Z2lmT rvrfpwllSBnUwcvrPTY8ZZg9VK5htmelku4mrt6T5YRXnrFtJa0YJM5KFp2hCHZm4YNp IQrTLwCOdoKrKALq21ZBt1udY99xJZWXjSS7olpUvseiHXXNgOMSlj4dBk9iUfAMaNkX BvLQ== X-Gm-Message-State: AKGB3mIwbnnX804fiH1ixUgaN0bHv2abyuPJt2SXW8Gqe6UX2iuzXj5o X///zRVFCqM1w4DmF0Y9xQL0YQ== X-Received: by 10.101.88.206 with SMTP id e14mr26460102pgu.216.1514869831533; Mon, 01 Jan 2018 21:10:31 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id 6sm63989675pgf.54.2018.01.01.21.10.29 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Jan 2018 21:10:31 -0800 (PST) From: Baolin Wang To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com, corbet@lwn.net Cc: arnd@arndb.de, broonie@kernel.org, linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH 2/4] rtc: sysfs: Export the valid range supported by RTC hardware Date: Tue, 2 Jan 2018 13:10:06 +0800 Message-Id: <2f0fb91c39534ecc2e94148a1a6998ba32ab90cf.1514869622.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> References: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> In-Reply-To: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> References: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We have introduced one interface to get the RTC range, so this patch exports the valid range supported by RTC hardware to userspace. Signed-off-by: Baolin Wang --- Documentation/rtc.txt | 2 ++ drivers/rtc/rtc-sysfs.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) -- 1.7.9.5 diff --git a/Documentation/rtc.txt b/Documentation/rtc.txt index c0c9774..4fe437b 100644 --- a/Documentation/rtc.txt +++ b/Documentation/rtc.txt @@ -164,6 +164,8 @@ offset The amount which the rtc clock has been adjusted in firmware. which are added to or removed from the rtc's base clock per billion ticks. A positive value makes a day pass more slowly, longer, and a negative value makes a day pass more quickly. +range_max The maximum time values in seconds supported by RTC hardware. +range_min The minimum time values in seconds supported by RTC hardware. */nvmem The non volatile storage exported as a raw file, as described in Documentation/nvmem/nvmem.txt ================ ============================================================== diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c index 92ff2ed..60e1f6c 100644 --- a/drivers/rtc/rtc-sysfs.c +++ b/drivers/rtc/rtc-sysfs.c @@ -248,6 +248,34 @@ } static DEVICE_ATTR_RW(offset); +static ssize_t +range_max_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + ssize_t retval; + time64_t max_hw_secs, min_hw_secs; + + retval = rtc_read_range(to_rtc_device(dev), &max_hw_secs, &min_hw_secs); + if (retval == 0) + retval = sprintf(buf, "%lld\n", max_hw_secs); + + return retval; +} +static DEVICE_ATTR_RO(range_max); + +static ssize_t +range_min_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + ssize_t retval; + time64_t max_hw_secs, min_hw_secs; + + retval = rtc_read_range(to_rtc_device(dev), &max_hw_secs, &min_hw_secs); + if (retval == 0) + retval = sprintf(buf, "%lld\n", min_hw_secs); + + return retval; +} +static DEVICE_ATTR_RO(range_min); + static struct attribute *rtc_attrs[] = { &dev_attr_name.attr, &dev_attr_date.attr, @@ -257,6 +285,8 @@ &dev_attr_hctosys.attr, &dev_attr_wakealarm.attr, &dev_attr_offset.attr, + &dev_attr_range_max.attr, + &dev_attr_range_min.attr, NULL, }; From patchwork Tue Jan 2 05:10:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 123093 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8567408qgn; Mon, 1 Jan 2018 21:11:05 -0800 (PST) X-Google-Smtp-Source: ACJfBosgaU9WEQD1dELn5MPqQA+WDIEUbDA2hhR1LARVKPFQ4BeIF3CUmj7f58GymfDVlibKpdkw X-Received: by 10.99.183.14 with SMTP id t14mr20766540pgf.147.1514869865137; Mon, 01 Jan 2018 21:11:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514869865; cv=none; d=google.com; s=arc-20160816; b=smf0gphZgk4ZOGWJFK6/FhZzV0tqr3aZfn5R2nmIpC4Kwhj92PQNj3T32huCbJDbei rvGB92o995i19G3apbiwh1W5q+bDbsEm4VuHObBLaEK7AePOS3oS7SUfsyQvyCB78Tn9 XYVciqZdOYaHLSL3i3/BgpNMQw5zc6ia3uukz8r/1VgEsAHKajao4s4XPVSnePTjJRir WK3WLOAEPCwVwYqr2BZeTPA/S4WAvFMLC9Ier0E5NWEwS/Ayzm5WrbhVZmbXmRAhxY0o JQq8nKM59FT6OtDpypvPgH8NnaQNxV2yUB3jl4h7kNICPIKqhtqsiHwtG3n/y1jVORU4 sQKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=TXZPNBPzJLI0ZLb1NHwNqn1Zn9JmE68VFOlRVLYxhSU=; b=gjrqwGV+X9v2YRIZNNYRlgy3y3zt/nOjEEl0EPqft0XHwWu3synqKhVKb5lWoIRFvD E65YdVQt+8fTDAq6zYzJENpFGQJEITX8SgoDJu9Mj4nf+sP7smtW1/jF+infN/QsEHeu 4SCSltxMVrT46AOLGydDVEqsR76mChNFkoK0eOOul1956HXt6m/5Q7F63fzpRtUXwx2h M7pbjz1w+zykVlQJb+mE49GUDSJL+yC18eJhYYVxgpli7SJMc/8fBOzAauyvXL91Qq2U N4yupHdQEDX46CHAie1DHkD2OiVWDhoVrtl4wdAPidtaX8jEcnx5dn4A+0oabsYuTkIu YHbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LUVqwrtR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m12si7594330pgp.734.2018.01.01.21.11.04; Mon, 01 Jan 2018 21:11:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LUVqwrtR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751662AbeABFK7 (ORCPT + 28 others); Tue, 2 Jan 2018 00:10:59 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:36089 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751493AbeABFKe (ORCPT ); Tue, 2 Jan 2018 00:10:34 -0500 Received: by mail-pf0-f195.google.com with SMTP id p84so25280315pfd.3 for ; Mon, 01 Jan 2018 21:10:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=TXZPNBPzJLI0ZLb1NHwNqn1Zn9JmE68VFOlRVLYxhSU=; b=LUVqwrtRp+5nsH4Q7OpoNpvBwmNXcUF9K2LYZHCa2/WGxg2rKOrOREG+0Evu/2lZhT nua5mP3s7S/lV5b92PAzaj3y3J2bEgCJlNZSqv5Q9Zv24DHjjeUbwP5XmRhtXwOMWNoJ rxS0DINrruAyGnYdiI0iuB5CSmZi22nEAQ3Gg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=TXZPNBPzJLI0ZLb1NHwNqn1Zn9JmE68VFOlRVLYxhSU=; b=QVohWd7dUAopJ8YvqmyH90BzpwLdQIFTOI+NrsQLU2c/bvDrgESiIW4Qz/Ay1rEmXr dZbn4J7Xap96Ly0TCrlkD+5zwyhB4m3fuslprtfiYEFDyaScfSPm/0ekV3IFHhicL3qb FzdIkQZmpj3sIM1HqJnMyFNGP44w+uPLHdZ9ntyi0zIdzYT2EykqxrkdhwzTZcn86plV ckt0GZ2HxBtkGnMxB89rAHS4zjzn6+blectz6BgjVpmLHXeR/Bpxy1z4/Cw+WvbiVHt6 0w31dSVra3lk6Rp9ToOlKlReMx0ZJufs8uVajYmltCiZgGXlRIsG1mJqmoa2Nm+9SBH6 O7Fw== X-Gm-Message-State: AKGB3mIpMqQ9BmMBBCphXnSlwbOevO5e/NP7ecQOzZAU/h2zi5EZOBQ9 2DoVi58SSB2LXYLJplNkpUirWA== X-Received: by 10.98.197.68 with SMTP id j65mr45124569pfg.176.1514869834246; Mon, 01 Jan 2018 21:10:34 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id 6sm63989675pgf.54.2018.01.01.21.10.31 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Jan 2018 21:10:33 -0800 (PST) From: Baolin Wang To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com, corbet@lwn.net Cc: arnd@arndb.de, broonie@kernel.org, linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH 3/4] rtc: Add one offset seconds to expand RTC range Date: Tue, 2 Jan 2018 13:10:07 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> References: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> In-Reply-To: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> References: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >From our investigation for all RTC drivers, 1 driver will be expired before year 2017, 7 drivers will be expired before year 2038, 23 drivers will be expired before year 2069, 72 drivers will be expired before 2100 and 104 drivers will be expired before 2106. Especially for these early expired drivers, we need to expand the RTC range to make the RTC can still work after the expired year. So we can expand the RTC range by adding one offset to the time when reading from hardware, and subtracting it when writing back. For example, if you have an RTC that can do 100 years, and currently is configured to be based in Jan 1 1970, so it can represents times from 1970 to 2069. Then if you change the start year from 1970 to 2000, which means it can represents times from 2000 to 2099. By adding or subtracting the offset produced by moving the wrap point, all times between 1970 and 1999 from RTC hardware could get interpreted as times from 2070 to 2099, but the interpretation of dates between 2000 and 2069 would not change. Signed-off-by: Baolin Wang --- drivers/rtc/class.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/rtc/interface.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-- include/linux/rtc.h | 2 ++ 3 files changed, 106 insertions(+), 2 deletions(-) -- 1.7.9.5 diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 31fc0f1..8e59cf0 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c @@ -211,6 +211,55 @@ static int rtc_device_get_id(struct device *dev) return id; } +static void rtc_device_get_offset(struct rtc_device *rtc) +{ + u32 start_year; + int ret; + + rtc->offset_secs = 0; + rtc->start_secs = rtc->min_hw_secs; + + /* + * If RTC driver did not implement the range of RTC hardware device, + * then we can not expand the RTC range by adding or subtracting one + * offset. + */ + if (!rtc->max_hw_secs) + return; + + ret = device_property_read_u32(rtc->dev.parent, "start-year", + &start_year); + if (ret) + return; + + /* + * Record the start time values in seconds, which are used to valid if + * the setting time values are in the new expanded range. + */ + rtc->start_secs = max_t(time64_t, mktime64(start_year, 1, 1, 0, 0, 0), + rtc->min_hw_secs); + + /* + * If the start_secs is larger than the maximum seconds (max_hw_secs) + * support by RTC hardware, which means the minimum seconds + * (min_hw_secs) of RTC hardware will be mapped to start_secs by adding + * one offset, so the offset seconds calculation formula should be: + * rtc->offset_secs = rtc->start_secs - rtc->min_hw_secs; + * + * If the start_secs is less than max_hw_secs, then there is one region + * is overlapped between the original RTC hardware range and the new + * expanded range, and this overlapped region do not need to be mapped + * into the new expanded range due to it is valid for RTC device. So + * the minimum seconds of RTC hardware (min_hw_secs) should be mapped to + * max_hw_secs + 1, then the offset seconds formula should be: + * rtc->offset_secs = rtc->max_hw_secs - rtc->min_hw_secs + 1; + */ + if (rtc->start_secs > rtc->max_hw_secs) + rtc->offset_secs = rtc->start_secs - rtc->min_hw_secs; + else + rtc->offset_secs = rtc->max_hw_secs - rtc->min_hw_secs + 1; +} + /** * rtc_device_register - register w/ RTC class * @dev: the device to register @@ -253,6 +302,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, goto exit_ida; } + rtc_device_get_offset(rtc); + /* Check to see if there is an ALARM already set in hw */ err = __rtc_read_alarm(rtc, &alrm); @@ -449,6 +500,8 @@ int __rtc_register_device(struct module *owner, struct rtc_device *rtc) return err; } + rtc_device_get_offset(rtc); + /* Check to see if there is an ALARM already set in hw */ err = __rtc_read_alarm(rtc, &alrm); if (!err && !rtc_valid_tm(&alrm.time)) diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index c8090e3..eb96a90 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -20,6 +20,46 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer); static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer); +static void rtc_add_offset(struct rtc_device *rtc, struct rtc_time *tm) +{ + time64_t secs; + + if (!rtc->offset_secs) + return; + + secs = rtc_tm_to_time64(tm); + /* + * Since the reading time values from RTC device are always less than + * rtc->max_hw_secs, then if the reading time values are larger than + * the rtc->start_secs, which means they did not subtract the offset + * when writing into RTC device, so we do not need to add the offset. + */ + if (secs >= rtc->start_secs) + return; + + rtc_time64_to_tm(secs + rtc->offset_secs, tm); +} + +static void rtc_subtract_offset(struct rtc_device *rtc, struct rtc_time *tm) +{ + time64_t secs; + + if (!rtc->offset_secs) + return; + + secs = rtc_tm_to_time64(tm); + /* + * If the setting time values are in the valid range of RTC hardware + * device, then no need to subtract the offset when setting time to RTC + * device. Otherwise we need to subtract the offset to make the time + * values are valid for RTC hardware device. + */ + if (secs <= rtc->max_hw_secs) + return; + + rtc_time64_to_tm(secs - rtc->offset_secs, tm); +} + static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) { int err; @@ -36,6 +76,8 @@ static int __rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) return err; } + rtc_add_offset(rtc, tm); + err = rtc_valid_tm(tm); if (err < 0) dev_dbg(&rtc->dev, "read_time: rtc_time isn't valid\n"); @@ -69,6 +111,8 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) if (err) return err; + rtc_subtract_offset(rtc, tm); + err = mutex_lock_interruptible(&rtc->ops_lock); if (err) return err; @@ -123,6 +167,8 @@ static int rtc_read_alarm_internal(struct rtc_device *rtc, struct rtc_wkalrm *al } mutex_unlock(&rtc->ops_lock); + + rtc_add_offset(rtc, &alarm->time); return err; } @@ -338,6 +384,7 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) if (err) return err; + rtc_subtract_offset(rtc, &alarm->time); scheduled = rtc_tm_to_time64(&alarm->time); /* Make sure we're not setting alarms in the past */ @@ -1074,7 +1121,8 @@ int rtc_read_range(struct rtc_device *rtc, time64_t *max_hw_secs, * @ tm: time values need to valid. * * Only the rtc->max_hw_secs was set, then we can valid if the setting time - * values are beyond the RTC range. + * values are beyond the RTC range. When drivers set one start time values, + * we need to valid if the setting time values are in the new expanded range. */ int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm) { @@ -1084,7 +1132,8 @@ int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm) return 0; secs = rtc_tm_to_time64(tm); - if (secs < rtc->min_hw_secs || secs > rtc->max_hw_secs) + if (secs < rtc->start_secs || + secs > (rtc->start_secs + rtc->max_hw_secs - rtc->min_hw_secs)) return -EINVAL; return 0; diff --git a/include/linux/rtc.h b/include/linux/rtc.h index 19a8989..11879b7 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -156,6 +156,8 @@ struct rtc_device { time64_t max_hw_secs; time64_t min_hw_secs; + time64_t start_secs; + time64_t offset_secs; #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL struct work_struct uie_task; From patchwork Tue Jan 2 05:10:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 123092 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8567249qgn; Mon, 1 Jan 2018 21:10:51 -0800 (PST) X-Google-Smtp-Source: ACJfBoueJjwrP+dq4QujykqvYl1BD7dEbR3q6FKjnz3v6nrfR2nqA9tC5Lg9HQsnRo8xGD1tbNuw X-Received: by 10.84.210.109 with SMTP id z100mr45000098plh.364.1514869851149; Mon, 01 Jan 2018 21:10:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514869851; cv=none; d=google.com; s=arc-20160816; b=ZAmly158/qOTKmOqoN2XAwNKaa0rOyZnODwYjAxFsPrGM7O/U4SifazX/UHm3Q/L2V tuuGp29E7Gr2usKvZ5xZnWPApaK7VkNsYB9n6+xJpjGBtH6L+JzgeTfE4qvaH7wWW69x lCC0TysNdSi9wolGidLopUWIZJ5ARo+Kh0MSsae4Jxx7IEtdJo0bk0hKoZ60eEuKuo5F Oh6ueUGquKstWPEkwnD2X/LDYK+jqpeTiolRhro2mx08zQIjyGSr970KNZM3MjE9FMQZ MAbU4tBbhEiTf2Nse5k0RktxHXdzWglhaAsEXCMA54VbMAN0lkVpsC3L89577gGw3c2H 6eMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=DqIEPV1qa7N5g3oC1Diirx4TZ+IKpCUeroYOX9JuUD0=; b=OVNVNETPVATif7PT69cMlmUG6FhitMDHlEu0OZH6j0iGRTGBf/FOsVtXJnwQWdhaPf g6iT0WcEmRh+1x6rSFQQvPohXA6JORCNXivR9RsNtOBB3VRVG7zq/7zyddcui0rohdES CFVwmgv74V5+RzVmEucEIasYqWetFeuUyI3xiQfuxhWOLB98/RdvEcFCAd1M3NebHgZD 5VCxBedVOMdvV+nGzC9jk2L8lfsoch+mVRHAzcn/jc0IejDsDgQ/Uk4kidszQ1h6N0hM zZRqH4TaNz/Nf4W+NB0t8NdgmVfRRtSBauUHAlvz1x8elvX3fHTJ3CFyucOch8EDJqbe BN7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Sp/fARVE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y11si27541101plg.702.2018.01.01.21.10.50; Mon, 01 Jan 2018 21:10:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Sp/fARVE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751575AbeABFKl (ORCPT + 28 others); Tue, 2 Jan 2018 00:10:41 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:37932 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751506AbeABFKi (ORCPT ); Tue, 2 Jan 2018 00:10:38 -0500 Received: by mail-pg0-f67.google.com with SMTP id t67so2256129pgc.5 for ; Mon, 01 Jan 2018 21:10:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=DqIEPV1qa7N5g3oC1Diirx4TZ+IKpCUeroYOX9JuUD0=; b=Sp/fARVE+4/QAqBG+v3OTs6UzQp2QauYtE0jP57XDYtp6cvVubI+Hf6HXh8AeEvN4p hML/89c4v1Na+f1tfJ0qSmO4+5u7Q2RNAqvZ0t9ZneCpgNqmwn+V77r2oyftucNIoZPC r68RlYw/3Jyu00DryhUnU63Ndbt0raJ2kW6c8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=DqIEPV1qa7N5g3oC1Diirx4TZ+IKpCUeroYOX9JuUD0=; b=eBLFwTcMOmJhGCLRgwITHjPWCye7OuaKYY85oqLcXPHib9k6YwL94+pBghvNv0swda E8IJs21leaa3exQ/NUD2vAUZCvhcmgONt+m04BN1LprZdQ8G44nZw6Fu4SpXu/HIktDf CbBFRmJnxhiSxdKT4taSeDolr7+kooAu/5PRy78bRgWoNuQmJKRlSaAl+FStXPqft583 tZZQG658YtCWYXWmTsGD1FHR4F2wSXihp6cb7t3v1WAVKkDMZYosaxGC/SHQw75XHKR3 b7yyjuxLDyrbfFx4juALhor6HSj8wDbUWhCRoy3ufr2twWO1RdOGbrIkAbKi6FXVhWEh XFLA== X-Gm-Message-State: AKGB3mIFNqszaw1HLofcaI2acvK/spDs6cmHgdW6iOAAgI1PM3YQc65d gYZZ3ytNZZf1j6jDdc7sMKZI2Q== X-Received: by 10.99.143.87 with SMTP id r23mr38115847pgn.188.1514869837531; Mon, 01 Jan 2018 21:10:37 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id 6sm63989675pgf.54.2018.01.01.21.10.34 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Jan 2018 21:10:37 -0800 (PST) From: Baolin Wang To: a.zummo@towertech.it, alexandre.belloni@free-electrons.com, corbet@lwn.net Cc: arnd@arndb.de, broonie@kernel.org, linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, baolin.wang@linaro.org Subject: [RFC PATCH 4/4] rtc: sc27xx: Add the get_range interface Date: Tue, 2 Jan 2018 13:10:08 +0800 Message-Id: <2240e08e757926ff01d3b73596b0a8c9e29f2530.1514869622.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> References: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> In-Reply-To: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> References: <9ab56bdcaeb52241e22b738d6babe7b01728f64c.1514869621.git.baolin.wang@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the get_range interface for sc27xx RTC driver to tell the RTC core what is the valid range for RTC hardware device. Signed-off-by: Baolin Wang --- drivers/rtc/rtc-sc27xx.c | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 1.7.9.5 diff --git a/drivers/rtc/rtc-sc27xx.c b/drivers/rtc/rtc-sc27xx.c index d544d52..97b1120 100644 --- a/drivers/rtc/rtc-sc27xx.c +++ b/drivers/rtc/rtc-sc27xx.c @@ -536,12 +536,22 @@ static int sprd_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) return ret; } +static int sprd_rtc_read_range(struct device *dev, time64_t *max_hw_secs, + time64_t *min_hw_secs) +{ + *min_hw_secs = 0; + *max_hw_secs = (((time64_t)(SPRD_RTC_DAY_MASK * 24) + 23) * 60 + 59) * 60 + 59; + + return 0; +} + static const struct rtc_class_ops sprd_rtc_ops = { .read_time = sprd_rtc_read_time, .set_time = sprd_rtc_set_time, .read_alarm = sprd_rtc_read_alarm, .set_alarm = sprd_rtc_set_alarm, .alarm_irq_enable = sprd_rtc_alarm_irq_enable, + .read_range = sprd_rtc_read_range, }; static irqreturn_t sprd_rtc_handler(int irq, void *dev_id)