Merge remote-tracking branch 'blackfin/for-linus'
[linux-2.6/next.git] / drivers / rtc / rtc-generic.c
blob98322004ad2e48eedb901038eef0f51663c92b67
1 /* rtc-generic: RTC driver using the generic RTC abstraction
3 * Copyright (C) 2008 Kyle McMartin <kyle@mcmartin.ca>
4 */
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/time.h>
9 #include <linux/platform_device.h>
10 #include <linux/rtc.h>
12 #include <asm/rtc.h>
14 static int generic_get_time(struct device *dev, struct rtc_time *tm)
16 unsigned int ret = get_rtc_time(tm);
18 if (ret & RTC_BATT_BAD)
19 return -EOPNOTSUPP;
21 return rtc_valid_tm(tm);
24 static int generic_set_time(struct device *dev, struct rtc_time *tm)
26 if (set_rtc_time(tm) < 0)
27 return -EOPNOTSUPP;
29 return 0;
32 static const struct rtc_class_ops generic_rtc_ops = {
33 .read_time = generic_get_time,
34 .set_time = generic_set_time,
37 static int __init generic_rtc_probe(struct platform_device *dev)
39 struct rtc_device *rtc;
41 rtc = rtc_device_register("rtc-generic", &dev->dev, &generic_rtc_ops,
42 THIS_MODULE);
43 if (IS_ERR(rtc))
44 return PTR_ERR(rtc);
46 platform_set_drvdata(dev, rtc);
48 return 0;
51 static int __exit generic_rtc_remove(struct platform_device *dev)
53 struct rtc_device *rtc = platform_get_drvdata(dev);
55 rtc_device_unregister(rtc);
57 return 0;
60 static struct platform_driver generic_rtc_driver = {
61 .driver = {
62 .name = "rtc-generic",
63 .owner = THIS_MODULE,
65 .remove = __exit_p(generic_rtc_remove),
68 static int __init generic_rtc_init(void)
70 return platform_driver_probe(&generic_rtc_driver, generic_rtc_probe);
73 static void __exit generic_rtc_fini(void)
75 platform_driver_unregister(&generic_rtc_driver);
78 module_init(generic_rtc_init);
79 module_exit(generic_rtc_fini);
81 MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
82 MODULE_LICENSE("GPL");
83 MODULE_DESCRIPTION("Generic RTC driver");
84 MODULE_ALIAS("platform:rtc-generic");