2 * An RTC test device/driver
3 * Copyright (C) 2005 Tower Technologies
4 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/module.h>
12 #include <linux/err.h>
13 #include <linux/rtc.h>
14 #include <linux/platform_device.h>
16 static struct platform_device *test0 = NULL, *test1 = NULL;
18 static int test_rtc_read_alarm(struct device *dev,
19 struct rtc_wkalrm *alrm)
24 static int test_rtc_set_alarm(struct device *dev,
25 struct rtc_wkalrm *alrm)
30 static int test_rtc_read_time(struct device *dev,
33 unsigned long time = 0xffffff;
34 rtc_time_to_tm(time, tm);
35 //rtc_time_to_tm(get_seconds(), tm);
39 static int test_rtc_set_mmss(struct device *dev, unsigned long secs)
41 dev_info(dev, "%s, secs = %lu\n", __func__, secs);
45 static int test_rtc_proc(struct device *dev, struct seq_file *seq)
47 struct platform_device *plat_dev = to_platform_device(dev);
49 seq_printf(seq, "test\t\t: yes\n");
50 seq_printf(seq, "id\t\t: %d\n", plat_dev->id);
55 static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
60 static const struct rtc_class_ops test_rtc_ops = {
61 .proc = test_rtc_proc,
62 .read_time = test_rtc_read_time,
63 .read_alarm = test_rtc_read_alarm,
64 .set_alarm = test_rtc_set_alarm,
65 .set_mmss = test_rtc_set_mmss,
66 .alarm_irq_enable = test_rtc_alarm_irq_enable,
69 static ssize_t test_irq_show(struct device *dev,
70 struct device_attribute *attr, char *buf)
72 return sprintf(buf, "%d\n", 42);
74 static ssize_t test_irq_store(struct device *dev,
75 struct device_attribute *attr,
76 const char *buf, size_t count)
79 struct platform_device *plat_dev = to_platform_device(dev);
80 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
83 if (strncmp(buf, "tick", 4) == 0 && rtc->pie_enabled)
84 rtc_update_irq(rtc, 1, RTC_PF | RTC_IRQF);
85 else if (strncmp(buf, "alarm", 5) == 0) {
86 struct rtc_wkalrm alrm;
87 int err = rtc_read_alarm(rtc, &alrm);
89 if (!err && alrm.enabled)
90 rtc_update_irq(rtc, 1, RTC_AF | RTC_IRQF);
92 } else if (strncmp(buf, "update", 6) == 0 && rtc->uie_rtctimer.enabled)
93 rtc_update_irq(rtc, 1, RTC_UF | RTC_IRQF);
99 static DEVICE_ATTR(irq, S_IRUGO | S_IWUSR, test_irq_show, test_irq_store);
101 static int test_probe(struct platform_device *plat_dev)
104 struct rtc_device *rtc = rtc_device_register("test", &plat_dev->dev,
105 &test_rtc_ops, THIS_MODULE);
111 err = device_create_file(&plat_dev->dev, &dev_attr_irq);
115 platform_set_drvdata(plat_dev, rtc);
120 rtc_device_unregister(rtc);
124 static int __devexit test_remove(struct platform_device *plat_dev)
126 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
128 rtc_device_unregister(rtc);
129 device_remove_file(&plat_dev->dev, &dev_attr_irq);
134 static struct platform_driver test_driver = {
136 .remove = __devexit_p(test_remove),
139 .owner = THIS_MODULE,
143 static int __init test_init(void)
147 if ((err = platform_driver_register(&test_driver)))
150 if ((test0 = platform_device_alloc("rtc-test", 0)) == NULL) {
152 goto exit_driver_unregister;
155 if ((test1 = platform_device_alloc("rtc-test", 1)) == NULL) {
157 goto exit_free_test0;
160 if ((err = platform_device_add(test0)))
161 goto exit_free_test1;
163 if ((err = platform_device_add(test1)))
164 goto exit_device_unregister;
168 exit_device_unregister:
169 platform_device_unregister(test0);
172 platform_device_put(test1);
175 platform_device_put(test0);
177 exit_driver_unregister:
178 platform_driver_unregister(&test_driver);
182 static void __exit test_exit(void)
184 platform_device_unregister(test0);
185 platform_device_unregister(test1);
186 platform_driver_unregister(&test_driver);
189 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
190 MODULE_DESCRIPTION("RTC test driver/device");
191 MODULE_LICENSE("GPL");
193 module_init(test_init);
194 module_exit(test_exit);