Merge branch 'rtc-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / rtc / rtc-test.c
bloba82d6fe970763e5388d787f4212c13228d6ea096
1 /*
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.
9 */
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)
21 return 0;
24 static int test_rtc_set_alarm(struct device *dev,
25 struct rtc_wkalrm *alrm)
27 return 0;
30 static int test_rtc_read_time(struct device *dev,
31 struct rtc_time *tm)
33 rtc_time_to_tm(get_seconds(), tm);
34 return 0;
37 static int test_rtc_set_mmss(struct device *dev, unsigned long secs)
39 dev_info(dev, "%s, secs = %lu\n", __func__, secs);
40 return 0;
43 static int test_rtc_proc(struct device *dev, struct seq_file *seq)
45 struct platform_device *plat_dev = to_platform_device(dev);
47 seq_printf(seq, "test\t\t: yes\n");
48 seq_printf(seq, "id\t\t: %d\n", plat_dev->id);
50 return 0;
53 static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
55 return 0;
58 static const struct rtc_class_ops test_rtc_ops = {
59 .proc = test_rtc_proc,
60 .read_time = test_rtc_read_time,
61 .read_alarm = test_rtc_read_alarm,
62 .set_alarm = test_rtc_set_alarm,
63 .set_mmss = test_rtc_set_mmss,
64 .alarm_irq_enable = test_rtc_alarm_irq_enable,
67 static ssize_t test_irq_show(struct device *dev,
68 struct device_attribute *attr, char *buf)
70 return sprintf(buf, "%d\n", 42);
72 static ssize_t test_irq_store(struct device *dev,
73 struct device_attribute *attr,
74 const char *buf, size_t count)
76 int retval;
77 struct platform_device *plat_dev = to_platform_device(dev);
78 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
80 retval = count;
81 if (strncmp(buf, "tick", 4) == 0)
82 rtc_update_irq(rtc, 1, RTC_PF | RTC_IRQF);
83 else if (strncmp(buf, "alarm", 5) == 0)
84 rtc_update_irq(rtc, 1, RTC_AF | RTC_IRQF);
85 else if (strncmp(buf, "update", 6) == 0)
86 rtc_update_irq(rtc, 1, RTC_UF | RTC_IRQF);
87 else
88 retval = -EINVAL;
90 return retval;
92 static DEVICE_ATTR(irq, S_IRUGO | S_IWUSR, test_irq_show, test_irq_store);
94 static int test_probe(struct platform_device *plat_dev)
96 int err;
97 struct rtc_device *rtc = rtc_device_register("test", &plat_dev->dev,
98 &test_rtc_ops, THIS_MODULE);
99 if (IS_ERR(rtc)) {
100 err = PTR_ERR(rtc);
101 return err;
104 err = device_create_file(&plat_dev->dev, &dev_attr_irq);
105 if (err)
106 goto err;
108 platform_set_drvdata(plat_dev, rtc);
110 return 0;
112 err:
113 rtc_device_unregister(rtc);
114 return err;
117 static int __devexit test_remove(struct platform_device *plat_dev)
119 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
121 rtc_device_unregister(rtc);
122 device_remove_file(&plat_dev->dev, &dev_attr_irq);
124 return 0;
127 static struct platform_driver test_driver = {
128 .probe = test_probe,
129 .remove = __devexit_p(test_remove),
130 .driver = {
131 .name = "rtc-test",
132 .owner = THIS_MODULE,
136 static int __init test_init(void)
138 int err;
140 if ((err = platform_driver_register(&test_driver)))
141 return err;
143 if ((test0 = platform_device_alloc("rtc-test", 0)) == NULL) {
144 err = -ENOMEM;
145 goto exit_driver_unregister;
148 if ((test1 = platform_device_alloc("rtc-test", 1)) == NULL) {
149 err = -ENOMEM;
150 goto exit_free_test0;
153 if ((err = platform_device_add(test0)))
154 goto exit_free_test1;
156 if ((err = platform_device_add(test1)))
157 goto exit_device_unregister;
159 return 0;
161 exit_device_unregister:
162 platform_device_unregister(test0);
164 exit_free_test1:
165 platform_device_put(test1);
167 exit_free_test0:
168 platform_device_put(test0);
170 exit_driver_unregister:
171 platform_driver_unregister(&test_driver);
172 return err;
175 static void __exit test_exit(void)
177 platform_device_unregister(test0);
178 platform_device_unregister(test1);
179 platform_driver_unregister(&test_driver);
182 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
183 MODULE_DESCRIPTION("RTC test driver/device");
184 MODULE_LICENSE("GPL");
186 module_init(test_init);
187 module_exit(test_exit);