Blame view
drivers/rtc/rtc-test.c
4.22 KB
a95579cd4 [PATCH] RTC subsy... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
/* * 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> 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) { rtc_time_to_tm(get_seconds(), tm); return 0; } |
a95579cd4 [PATCH] RTC subsy... |
36 37 |
static int test_rtc_set_mmss(struct device *dev, unsigned long secs) { |
bbccf83f6 rtc: use set_mmss... |
38 39 |
dev_info(dev, "%s, secs = %lu ", __func__, secs); |
a95579cd4 [PATCH] RTC subsy... |
40 41 42 43 44 45 |
return 0; } static int test_rtc_proc(struct device *dev, struct seq_file *seq) { struct platform_device *plat_dev = to_platform_device(dev); |
a95579cd4 [PATCH] RTC subsy... |
46 47 48 49 50 51 52 |
seq_printf(seq, "test\t\t: yes "); seq_printf(seq, "id\t\t: %d ", plat_dev->id); return 0; } |
16380c153 RTC: Convert rtc ... |
53 |
static int test_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) |
a95579cd4 [PATCH] RTC subsy... |
54 |
{ |
16380c153 RTC: Convert rtc ... |
55 |
return 0; |
a95579cd4 [PATCH] RTC subsy... |
56 |
} |
ff8371ac9 [PATCH] constify ... |
57 |
static const struct rtc_class_ops test_rtc_ops = { |
a95579cd4 [PATCH] RTC subsy... |
58 59 |
.proc = test_rtc_proc, .read_time = test_rtc_read_time, |
a95579cd4 [PATCH] RTC subsy... |
60 61 62 |
.read_alarm = test_rtc_read_alarm, .set_alarm = test_rtc_set_alarm, .set_mmss = test_rtc_set_mmss, |
16380c153 RTC: Convert rtc ... |
63 |
.alarm_irq_enable = test_rtc_alarm_irq_enable, |
a95579cd4 [PATCH] RTC subsy... |
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
}; static ssize_t test_irq_show(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%d ", 42); } static ssize_t test_irq_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int retval; struct platform_device *plat_dev = to_platform_device(dev); struct rtc_device *rtc = platform_get_drvdata(plat_dev); retval = count; |
a417493ef RTC: Fix the cros... |
81 |
if (strncmp(buf, "tick", 4) == 0 && rtc->pie_enabled) |
ab6a2d70d rtc: rtc interfac... |
82 |
rtc_update_irq(rtc, 1, RTC_PF | RTC_IRQF); |
a417493ef RTC: Fix the cros... |
83 84 85 86 87 88 89 90 |
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) |
ab6a2d70d rtc: rtc interfac... |
91 |
rtc_update_irq(rtc, 1, RTC_UF | RTC_IRQF); |
a95579cd4 [PATCH] RTC subsy... |
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
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; struct rtc_device *rtc = rtc_device_register("test", &plat_dev->dev, &test_rtc_ops, THIS_MODULE); if (IS_ERR(rtc)) { err = PTR_ERR(rtc); |
a95579cd4 [PATCH] RTC subsy... |
106 107 |
return err; } |
91046a8a6 [PATCH] RTC: hand... |
108 109 110 111 |
err = device_create_file(&plat_dev->dev, &dev_attr_irq); if (err) goto err; |
a95579cd4 [PATCH] RTC subsy... |
112 113 114 115 |
platform_set_drvdata(plat_dev, rtc); return 0; |
91046a8a6 [PATCH] RTC: hand... |
116 117 118 119 |
err: rtc_device_unregister(rtc); return err; |
a95579cd4 [PATCH] RTC subsy... |
120 121 122 123 124 125 126 127 128 129 130 |
} static int __devexit test_remove(struct platform_device *plat_dev) { struct rtc_device *rtc = platform_get_drvdata(plat_dev); rtc_device_unregister(rtc); device_remove_file(&plat_dev->dev, &dev_attr_irq); return 0; } |
c46465281 rtc: silence sect... |
131 |
static struct platform_driver test_driver = { |
a95579cd4 [PATCH] RTC subsy... |
132 133 134 135 136 137 138 139 140 141 142 |
.probe = test_probe, .remove = __devexit_p(test_remove), .driver = { .name = "rtc-test", .owner = THIS_MODULE, }, }; static int __init test_init(void) { int err; |
c46465281 rtc: silence sect... |
143 |
if ((err = platform_driver_register(&test_driver))) |
a95579cd4 [PATCH] RTC subsy... |
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
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; goto exit_free_test0; } if ((err = platform_device_add(test0))) goto exit_free_test1; if ((err = platform_device_add(test1))) goto exit_device_unregister; return 0; exit_device_unregister: platform_device_unregister(test0); exit_free_test1: platform_device_put(test1); exit_free_test0: platform_device_put(test0); exit_driver_unregister: |
c46465281 rtc: silence sect... |
174 |
platform_driver_unregister(&test_driver); |
a95579cd4 [PATCH] RTC subsy... |
175 176 177 178 179 180 181 |
return err; } static void __exit test_exit(void) { platform_device_unregister(test0); platform_device_unregister(test1); |
c46465281 rtc: silence sect... |
182 |
platform_driver_unregister(&test_driver); |
a95579cd4 [PATCH] RTC subsy... |
183 184 185 186 187 188 189 190 |
} 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); |