2006-03-27 17:16:42 +08:00
|
|
|
/*
|
|
|
|
* An RTC test device/driver
|
|
|
|
* Copyright (C) 2005 Tower Technologies
|
|
|
|
* Author: Alessandro Zummo <a.zummo@towertech.it>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/rtc.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2015-04-02 11:34:28 +08:00
|
|
|
static int test_mmss64;
|
|
|
|
module_param(test_mmss64, int, 0644);
|
|
|
|
MODULE_PARM_DESC(test_mmss64, "Test struct rtc_class_ops.set_mmss64().");
|
|
|
|
|
2006-03-27 17:16:42 +08:00
|
|
|
static struct platform_device *test0 = NULL, *test1 = NULL;
|
|
|
|
|
|
|
|
static int test_rtc_read_alarm(struct device *dev,
|
|
|
|
struct rtc_wkalrm *alrm)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_rtc_set_alarm(struct device *dev,
|
|
|
|
struct rtc_wkalrm *alrm)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_rtc_read_time(struct device *dev,
|
|
|
|
struct rtc_time *tm)
|
|
|
|
{
|
2015-04-02 11:34:28 +08:00
|
|
|
rtc_time64_to_tm(ktime_get_real_seconds(), 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);
|
2006-03-27 17:16:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int test_rtc_set_mmss(struct device *dev, unsigned long secs)
|
|
|
|
{
|
2009-01-07 06:42:21 +08:00
|
|
|
dev_info(dev, "%s, secs = %lu\n", __func__, secs);
|
2006-03-27 17:16:42 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-02-03 09:02:41 +08:00
|
|
|
static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
|
2006-03-27 17:16:42 +08:00
|
|
|
{
|
2011-02-03 09:02:41 +08:00
|
|
|
return 0;
|
2006-03-27 17:16:42 +08:00
|
|
|
}
|
|
|
|
|
2015-04-02 11:34:28 +08:00
|
|
|
static struct rtc_class_ops test_rtc_ops = {
|
2006-03-27 17:16:42 +08:00
|
|
|
.proc = test_rtc_proc,
|
|
|
|
.read_time = test_rtc_read_time,
|
|
|
|
.read_alarm = test_rtc_read_alarm,
|
|
|
|
.set_alarm = test_rtc_set_alarm,
|
|
|
|
.set_mmss = test_rtc_set_mmss,
|
2011-02-03 09:02:41 +08:00
|
|
|
.alarm_irq_enable = test_rtc_alarm_irq_enable,
|
2006-03-27 17:16:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2018-04-19 22:06:14 +08:00
|
|
|
struct rtc_device *rtc = dev_get_drvdata(dev);
|
2006-03-27 17:16:42 +08:00
|
|
|
|
|
|
|
retval = count;
|
2011-02-08 05:16:07 +08:00
|
|
|
if (strncmp(buf, "tick", 4) == 0 && rtc->pie_enabled)
|
2007-05-08 15:33:30 +08:00
|
|
|
rtc_update_irq(rtc, 1, RTC_PF | RTC_IRQF);
|
2011-02-08 05:16:07 +08:00
|
|
|
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)
|
2007-05-08 15:33:30 +08:00
|
|
|
rtc_update_irq(rtc, 1, RTC_UF | RTC_IRQF);
|
2006-03-27 17:16:42 +08:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
int err;
|
2013-04-30 07:19:52 +08:00
|
|
|
struct rtc_device *rtc;
|
|
|
|
|
2015-04-02 11:34:28 +08:00
|
|
|
if (test_mmss64) {
|
|
|
|
test_rtc_ops.set_mmss64 = test_rtc_set_mmss64;
|
|
|
|
test_rtc_ops.set_mmss = NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-30 07:19:52 +08:00
|
|
|
rtc = devm_rtc_device_register(&plat_dev->dev, "test",
|
|
|
|
&test_rtc_ops, THIS_MODULE);
|
2006-03-27 17:16:42 +08:00
|
|
|
if (IS_ERR(rtc)) {
|
2014-04-04 05:49:36 +08:00
|
|
|
return PTR_ERR(rtc);
|
2006-03-27 17:16:42 +08:00
|
|
|
}
|
2006-12-07 12:35:34 +08:00
|
|
|
|
|
|
|
err = device_create_file(&plat_dev->dev, &dev_attr_irq);
|
|
|
|
if (err)
|
2014-04-04 05:49:36 +08:00
|
|
|
dev_err(&plat_dev->dev, "Unable to create sysfs entry: %s\n",
|
|
|
|
dev_attr_irq.attr.name);
|
2006-03-27 17:16:42 +08:00
|
|
|
|
|
|
|
platform_set_drvdata(plat_dev, rtc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-22 05:09:38 +08:00
|
|
|
static int test_remove(struct platform_device *plat_dev)
|
2006-03-27 17:16:42 +08:00
|
|
|
{
|
|
|
|
device_remove_file(&plat_dev->dev, &dev_attr_irq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-28 17:11:55 +08:00
|
|
|
static struct platform_driver test_driver = {
|
2006-03-27 17:16:42 +08:00
|
|
|
.probe = test_probe,
|
2012-12-22 05:09:38 +08:00
|
|
|
.remove = test_remove,
|
2006-03-27 17:16:42 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "rtc-test",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init test_init(void)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2008-04-28 17:11:55 +08:00
|
|
|
if ((err = platform_driver_register(&test_driver)))
|
2006-03-27 17:16:42 +08:00
|
|
|
return err;
|
|
|
|
|
|
|
|
if ((test0 = platform_device_alloc("rtc-test", 0)) == NULL) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto exit_driver_unregister;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((test1 = platform_device_alloc("rtc-test", 1)) == NULL) {
|
|
|
|
err = -ENOMEM;
|
2012-12-18 08:02:27 +08:00
|
|
|
goto exit_put_test0;
|
2006-03-27 17:16:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = platform_device_add(test0)))
|
2012-12-18 08:02:27 +08:00
|
|
|
goto exit_put_test1;
|
2006-03-27 17:16:42 +08:00
|
|
|
|
|
|
|
if ((err = platform_device_add(test1)))
|
2012-12-18 08:02:27 +08:00
|
|
|
goto exit_del_test0;
|
2006-03-27 17:16:42 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2012-12-18 08:02:27 +08:00
|
|
|
exit_del_test0:
|
|
|
|
platform_device_del(test0);
|
2006-03-27 17:16:42 +08:00
|
|
|
|
2012-12-18 08:02:27 +08:00
|
|
|
exit_put_test1:
|
2006-03-27 17:16:42 +08:00
|
|
|
platform_device_put(test1);
|
|
|
|
|
2012-12-18 08:02:27 +08:00
|
|
|
exit_put_test0:
|
2006-03-27 17:16:42 +08:00
|
|
|
platform_device_put(test0);
|
|
|
|
|
|
|
|
exit_driver_unregister:
|
2008-04-28 17:11:55 +08:00
|
|
|
platform_driver_unregister(&test_driver);
|
2006-03-27 17:16:42 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit test_exit(void)
|
|
|
|
{
|
|
|
|
platform_device_unregister(test0);
|
|
|
|
platform_device_unregister(test1);
|
2008-04-28 17:11:55 +08:00
|
|
|
platform_driver_unregister(&test_driver);
|
2006-03-27 17:16:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
|
|
|
|
MODULE_DESCRIPTION("RTC test driver/device");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_init(test_init);
|
|
|
|
module_exit(test_exit);
|