Skip to content

Commit 4dc2403

Browse files
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: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 5b25757 commit 4dc2403

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

drivers/rtc/rtc-test.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
#define MAX_RTC_TEST 3
1717

18+
struct rtc_test_data {
19+
struct rtc_device *rtc;
20+
time64_t offset;
21+
};
22+
1823
struct platform_device *pdev[MAX_RTC_TEST];
1924

2025
static int test_rtc_read_alarm(struct device *dev,
@@ -29,16 +34,21 @@ static int test_rtc_set_alarm(struct device *dev,
2934
return 0;
3035
}
3136

32-
static int test_rtc_read_time(struct device *dev,
33-
struct rtc_time *tm)
37+
static int test_rtc_read_time(struct device *dev, struct rtc_time *tm)
3438
{
35-
rtc_time64_to_tm(ktime_get_real_seconds(), tm);
39+
struct rtc_test_data *rtd = dev_get_drvdata(dev);
40+
41+
rtc_time64_to_tm(ktime_get_real_seconds() + rtd->offset, tm);
42+
3643
return 0;
3744
}
3845

3946
static int test_rtc_set_mmss64(struct device *dev, time64_t secs)
4047
{
41-
dev_info(dev, "%s, secs = %lld\n", __func__, (long long)secs);
48+
struct rtc_test_data *rtd = dev_get_drvdata(dev);
49+
50+
rtd->offset = secs - ktime_get_real_seconds();
51+
4252
return 0;
4353
}
4454

@@ -88,21 +98,18 @@ static DEVICE_ATTR(irq, S_IRUGO | S_IWUSR, test_irq_show, test_irq_store);
8898

8999
static int test_probe(struct platform_device *plat_dev)
90100
{
91-
int err;
92-
struct rtc_device *rtc;
101+
struct rtc_test_data *rtd;
93102

94-
rtc = devm_rtc_device_register(&plat_dev->dev, "test",
95-
&test_rtc_ops, THIS_MODULE);
96-
if (IS_ERR(rtc)) {
97-
return PTR_ERR(rtc);
98-
}
103+
rtd = devm_kzalloc(&plat_dev->dev, sizeof(*rtd), GFP_KERNEL);
104+
if (!rtd)
105+
return -ENOMEM;
99106

100-
err = device_create_file(&plat_dev->dev, &dev_attr_irq);
101-
if (err)
102-
dev_err(&plat_dev->dev, "Unable to create sysfs entry: %s\n",
103-
dev_attr_irq.attr.name);
107+
platform_set_drvdata(plat_dev, rtd);
104108

105-
platform_set_drvdata(plat_dev, rtc);
109+
rtd->rtc = devm_rtc_device_register(&plat_dev->dev, "test",
110+
&test_rtc_ops, THIS_MODULE);
111+
if (IS_ERR(rtd->rtc))
112+
return PTR_ERR(rtd->rtc);
106113

107114
return 0;
108115
}

0 commit comments

Comments
 (0)