From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: linux-rtc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Alexandre Belloni <alexandre.belloni@bootlin.com>
Subject: [PATCH 3/5] rtc: test: store time as an offset to system time
Date: Thu, 31 May 2018 23:09:57 +0200 [thread overview]
Message-ID: <20180531210959.2472-3-alexandre.belloni@bootlin.com> (raw)
In-Reply-To: <20180531210959.2472-1-alexandre.belloni@bootlin.com>
Store the time as an offset to system time. As the offset is in second, it
is currently always synced with system time.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-test.c | 39 +++++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index 796c45dee661..041150e53fd7 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -15,6 +15,11 @@
#define MAX_RTC_TEST 3
+struct rtc_test_data {
+ struct rtc_device *rtc;
+ time64_t offset;
+};
+
struct platform_device *pdev[MAX_RTC_TEST];
static int test_rtc_read_alarm(struct device *dev,
@@ -29,16 +34,21 @@ static int test_rtc_set_alarm(struct device *dev,
return 0;
}
-static int test_rtc_read_time(struct device *dev,
- struct rtc_time *tm)
+static int test_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
- rtc_time64_to_tm(ktime_get_real_seconds(), tm);
+ struct rtc_test_data *rtd = dev_get_drvdata(dev);
+
+ rtc_time64_to_tm(ktime_get_real_seconds() + rtd->offset, tm);
+
return 0;
}
static int test_rtc_set_mmss64(struct device *dev, time64_t secs)
{
- dev_info(dev, "%s, secs = %lld\n", __func__, (long long)secs);
+ struct rtc_test_data *rtd = dev_get_drvdata(dev);
+
+ rtd->offset = secs - ktime_get_real_seconds();
+
return 0;
}
@@ -88,21 +98,18 @@ static DEVICE_ATTR(irq, S_IRUGO | S_IWUSR, test_irq_show, test_irq_store);
static int test_probe(struct platform_device *plat_dev)
{
- int err;
- struct rtc_device *rtc;
+ struct rtc_test_data *rtd;
- rtc = devm_rtc_device_register(&plat_dev->dev, "test",
- &test_rtc_ops, THIS_MODULE);
- if (IS_ERR(rtc)) {
- return PTR_ERR(rtc);
- }
+ rtd = devm_kzalloc(&plat_dev->dev, sizeof(*rtd), GFP_KERNEL);
+ if (!rtd)
+ return -ENOMEM;
- err = device_create_file(&plat_dev->dev, &dev_attr_irq);
- if (err)
- dev_err(&plat_dev->dev, "Unable to create sysfs entry: %s\n",
- dev_attr_irq.attr.name);
+ platform_set_drvdata(plat_dev, rtd);
- platform_set_drvdata(plat_dev, rtc);
+ rtd->rtc = devm_rtc_device_register(&plat_dev->dev, "test",
+ &test_rtc_ops, THIS_MODULE);
+ if (IS_ERR(rtd->rtc))
+ return PTR_ERR(rtd->rtc);
return 0;
}
--
2.17.0
next prev parent reply other threads:[~2018-05-31 21:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-31 21:09 [PATCH 1/5] rtc: test: remove useless proc info Alexandre Belloni
2018-05-31 21:09 ` [PATCH 2/5] rtc: test: allow registering many devices Alexandre Belloni
2018-05-31 21:09 ` Alexandre Belloni [this message]
2018-05-31 21:09 ` [PATCH 4/5] rtc: test: emulate alarms using timers Alexandre Belloni
2018-05-31 21:09 ` [PATCH 5/5] rtc: test: remove irq sysfs file Alexandre Belloni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180531210959.2472-3-alexandre.belloni@bootlin.com \
--to=alexandre.belloni@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).