提交 4dc2403b 编写于 作者: A Alexandre Belloni

rtc: test: store time as an offset to system time

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: NAlexandre Belloni <alexandre.belloni@bootlin.com>
上级 5b257571
...@@ -15,6 +15,11 @@ ...@@ -15,6 +15,11 @@
#define MAX_RTC_TEST 3 #define MAX_RTC_TEST 3
struct rtc_test_data {
struct rtc_device *rtc;
time64_t offset;
};
struct platform_device *pdev[MAX_RTC_TEST]; struct platform_device *pdev[MAX_RTC_TEST];
static int test_rtc_read_alarm(struct device *dev, static int test_rtc_read_alarm(struct device *dev,
...@@ -29,16 +34,21 @@ static int test_rtc_set_alarm(struct device *dev, ...@@ -29,16 +34,21 @@ static int test_rtc_set_alarm(struct device *dev,
return 0; return 0;
} }
static int test_rtc_read_time(struct device *dev, static int test_rtc_read_time(struct device *dev, struct rtc_time *tm)
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; return 0;
} }
static int test_rtc_set_mmss64(struct device *dev, time64_t secs) 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; return 0;
} }
...@@ -88,21 +98,18 @@ static DEVICE_ATTR(irq, S_IRUGO | S_IWUSR, test_irq_show, test_irq_store); ...@@ -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) static int test_probe(struct platform_device *plat_dev)
{ {
int err; struct rtc_test_data *rtd;
struct rtc_device *rtc;
rtc = devm_rtc_device_register(&plat_dev->dev, "test", rtd = devm_kzalloc(&plat_dev->dev, sizeof(*rtd), GFP_KERNEL);
&test_rtc_ops, THIS_MODULE); if (!rtd)
if (IS_ERR(rtc)) { return -ENOMEM;
return PTR_ERR(rtc);
}
err = device_create_file(&plat_dev->dev, &dev_attr_irq); platform_set_drvdata(plat_dev, rtd);
if (err)
dev_err(&plat_dev->dev, "Unable to create sysfs entry: %s\n",
dev_attr_irq.attr.name);
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; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册