* [PATCH 1/5] rtc: test: remove useless proc info
@ 2018-05-31 21:09 Alexandre Belloni
2018-05-31 21:09 ` [PATCH 2/5] rtc: test: allow registering many devices Alexandre Belloni
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Alexandre Belloni @ 2018-05-31 21:09 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
The rtc proc callback is useless for two reasosn:
- the test RTC is often not the first RTC so it will never be used
- all the info is available in the name file of the RTC sys folder
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-test.c | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index a0d1571c4af6..f0eb8e0c5055 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -40,23 +40,12 @@ static int test_rtc_set_mmss64(struct device *dev, time64_t secs)
return 0;
}
-static int test_rtc_proc(struct device *dev, struct seq_file *seq)
-{
- struct platform_device *plat_dev = to_platform_device(dev);
-
- seq_printf(seq, "test\t\t: yes\n");
- seq_printf(seq, "id\t\t: %d\n", plat_dev->id);
-
- return 0;
-}
-
static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
{
return 0;
}
static const struct rtc_class_ops test_rtc_ops = {
- .proc = test_rtc_proc,
.read_time = test_rtc_read_time,
.read_alarm = test_rtc_read_alarm,
.set_alarm = test_rtc_set_alarm,
--
2.17.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/5] rtc: test: allow registering many devices
2018-05-31 21:09 [PATCH 1/5] rtc: test: remove useless proc info Alexandre Belloni
@ 2018-05-31 21:09 ` Alexandre Belloni
2018-05-31 21:09 ` [PATCH 3/5] rtc: test: store time as an offset to system time Alexandre Belloni
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2018-05-31 21:09 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
Use a loop to register RTC devices
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-test.c | 48 +++++++++++++++++++++---------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index f0eb8e0c5055..796c45dee661 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -13,7 +13,9 @@
#include <linux/rtc.h>
#include <linux/platform_device.h>
-static struct platform_device *test0 = NULL, *test1 = NULL;
+#define MAX_RTC_TEST 3
+
+struct platform_device *pdev[MAX_RTC_TEST];
static int test_rtc_read_alarm(struct device *dev,
struct rtc_wkalrm *alrm)
@@ -122,47 +124,45 @@ static struct platform_driver test_driver = {
static int __init test_init(void)
{
- int err;
+ int i, err;
if ((err = platform_driver_register(&test_driver)))
return err;
- if ((test0 = platform_device_alloc("rtc-test", 0)) == NULL) {
- err = -ENOMEM;
- goto exit_driver_unregister;
+ err = -ENOMEM;
+ for (i = 0; i < MAX_RTC_TEST; i++) {
+ pdev[i] = platform_device_alloc("rtc-test", i);
+ if (!pdev[i])
+ goto exit_free_mem;
}
- if ((test1 = platform_device_alloc("rtc-test", 1)) == NULL) {
- err = -ENOMEM;
- goto exit_put_test0;
+ for (i = 0; i < MAX_RTC_TEST; i++) {
+ err = platform_device_add(pdev[i]);
+ if (err)
+ goto exit_device_del;
}
- if ((err = platform_device_add(test0)))
- goto exit_put_test1;
-
- if ((err = platform_device_add(test1)))
- goto exit_del_test0;
-
return 0;
-exit_del_test0:
- platform_device_del(test0);
+exit_device_del:
+ for (; i > 0; i--)
+ platform_device_del(pdev[i - 1]);
-exit_put_test1:
- platform_device_put(test1);
+exit_free_mem:
+ for (i = 0; i < MAX_RTC_TEST; i++)
+ platform_device_put(pdev[i]);
-exit_put_test0:
- platform_device_put(test0);
-
-exit_driver_unregister:
platform_driver_unregister(&test_driver);
return err;
}
static void __exit test_exit(void)
{
- platform_device_unregister(test0);
- platform_device_unregister(test1);
+ int i;
+
+ for (i = 0; i < MAX_RTC_TEST; i++)
+ platform_device_unregister(pdev[i]);
+
platform_driver_unregister(&test_driver);
}
--
2.17.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/5] rtc: test: store time as an offset to system time
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
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
3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2018-05-31 21:09 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/5] rtc: test: emulate alarms using timers
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 ` [PATCH 3/5] rtc: test: store time as an offset to system time Alexandre Belloni
@ 2018-05-31 21:09 ` Alexandre Belloni
2018-05-31 21:09 ` [PATCH 5/5] rtc: test: remove irq sysfs file Alexandre Belloni
3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2018-05-31 21:09 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
Use timers to emulate alarms. Note that multiple alarms may happen if they
are set more than 15 days after the current RTC time.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-test.c | 56 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 52 insertions(+), 4 deletions(-)
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index 041150e53fd7..975f6cdda73f 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -18,19 +18,49 @@
struct rtc_test_data {
struct rtc_device *rtc;
time64_t offset;
+ struct timer_list alarm;
+ bool alarm_en;
};
struct platform_device *pdev[MAX_RTC_TEST];
-static int test_rtc_read_alarm(struct device *dev,
- struct rtc_wkalrm *alrm)
+static int test_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
+ struct rtc_test_data *rtd = dev_get_drvdata(dev);
+ time64_t alarm;
+
+ alarm = (rtd->alarm.expires - jiffies) / HZ;
+ alarm += ktime_get_real_seconds() + rtd->offset;
+
+ rtc_time64_to_tm(alarm, &alrm->time);
+ alrm->enabled = rtd->alarm_en;
+
return 0;
}
-static int test_rtc_set_alarm(struct device *dev,
- struct rtc_wkalrm *alrm)
+static int test_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
+ struct rtc_test_data *rtd = dev_get_drvdata(dev);
+ ktime_t timeout;
+ u64 expires;
+
+ timeout = rtc_tm_to_time64(&alrm->time) - ktime_get_real_seconds();
+ timeout -= rtd->offset;
+
+ del_timer(&rtd->alarm);
+
+ expires = jiffies + timeout * HZ;
+ if (expires > U32_MAX)
+ expires = U32_MAX;
+
+ pr_err("ABE: %s +%d %s\n", __FILE__, __LINE__, __func__);
+ rtd->alarm.expires = expires;
+
+ if (alrm->enabled)
+ add_timer(&rtd->alarm);
+
+ rtd->alarm_en = alrm->enabled;
+
return 0;
}
@@ -54,6 +84,14 @@ static int test_rtc_set_mmss64(struct device *dev, time64_t secs)
static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
{
+ struct rtc_test_data *rtd = dev_get_drvdata(dev);
+
+ rtd->alarm_en = enable;
+ if (enable)
+ add_timer(&rtd->alarm);
+ else
+ del_timer(&rtd->alarm);
+
return 0;
}
@@ -65,6 +103,13 @@ static const struct rtc_class_ops test_rtc_ops = {
.alarm_irq_enable = test_rtc_alarm_irq_enable,
};
+static void test_rtc_alarm_handler(struct timer_list *t)
+{
+ struct rtc_test_data *rtd = from_timer(rtd, t, alarm);
+
+ rtc_update_irq(rtd->rtc, 1, RTC_AF | RTC_IRQF);
+}
+
static ssize_t test_irq_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -111,6 +156,9 @@ static int test_probe(struct platform_device *plat_dev)
if (IS_ERR(rtd->rtc))
return PTR_ERR(rtd->rtc);
+ timer_setup(&rtd->alarm, test_rtc_alarm_handler, 0);
+ rtd->alarm.expires = 0;
+
return 0;
}
--
2.17.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 5/5] rtc: test: remove irq sysfs file
2018-05-31 21:09 [PATCH 1/5] rtc: test: remove useless proc info Alexandre Belloni
` (2 preceding siblings ...)
2018-05-31 21:09 ` [PATCH 4/5] rtc: test: emulate alarms using timers Alexandre Belloni
@ 2018-05-31 21:09 ` Alexandre Belloni
3 siblings, 0 replies; 5+ messages in thread
From: Alexandre Belloni @ 2018-05-31 21:09 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
Now that alarms are emulated, remove the irq sysfs file that could be used
to send alarms.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-test.c | 39 ---------------------------------------
1 file changed, 39 deletions(-)
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index 975f6cdda73f..fbcec4a2e3c9 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -110,37 +110,6 @@ static void test_rtc_alarm_handler(struct timer_list *t)
rtc_update_irq(rtd->rtc, 1, RTC_AF | RTC_IRQF);
}
-static ssize_t test_irq_show(struct device *dev,
- struct device_attribute *attr, char *buf)
-{
- return sprintf(buf, "%d\n", 42);
-}
-static ssize_t test_irq_store(struct device *dev,
- struct device_attribute *attr,
- const char *buf, size_t count)
-{
- int retval;
- struct rtc_device *rtc = dev_get_drvdata(dev);
-
- retval = count;
- if (strncmp(buf, "tick", 4) == 0 && rtc->pie_enabled)
- rtc_update_irq(rtc, 1, RTC_PF | RTC_IRQF);
- else if (strncmp(buf, "alarm", 5) == 0) {
- struct rtc_wkalrm alrm;
- int err = rtc_read_alarm(rtc, &alrm);
-
- if (!err && alrm.enabled)
- rtc_update_irq(rtc, 1, RTC_AF | RTC_IRQF);
-
- } else if (strncmp(buf, "update", 6) == 0 && rtc->uie_rtctimer.enabled)
- rtc_update_irq(rtc, 1, RTC_UF | RTC_IRQF);
- else
- retval = -EINVAL;
-
- return retval;
-}
-static DEVICE_ATTR(irq, S_IRUGO | S_IWUSR, test_irq_show, test_irq_store);
-
static int test_probe(struct platform_device *plat_dev)
{
struct rtc_test_data *rtd;
@@ -162,16 +131,8 @@ static int test_probe(struct platform_device *plat_dev)
return 0;
}
-static int test_remove(struct platform_device *plat_dev)
-{
- device_remove_file(&plat_dev->dev, &dev_attr_irq);
-
- return 0;
-}
-
static struct platform_driver test_driver = {
.probe = test_probe,
- .remove = test_remove,
.driver = {
.name = "rtc-test",
},
--
2.17.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-05-31 21:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 3/5] rtc: test: store time as an offset to system time Alexandre Belloni
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
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).