blob: b966f56da976e4dec379c56eb6fcc88545883295 [file] [log] [blame]
Kyle McMartin9eb16862008-09-10 14:24:07 +00001/* rtc-parisc: RTC for HP PA-RISC firmware
2 *
3 * Copyright (C) 2008 Kyle McMartin <kyle@mcmartin.ca>
4 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/time.h>
9#include <linux/platform_device.h>
dann frazier93d456d2009-03-31 15:24:49 -070010#include <linux/rtc.h>
Kyle McMartin9eb16862008-09-10 14:24:07 +000011
12#include <asm/rtc.h>
13
Kyle McMartin9eb16862008-09-10 14:24:07 +000014static int parisc_get_time(struct device *dev, struct rtc_time *tm)
15{
dann frazier05439f12009-03-31 15:24:50 -070016 unsigned long ret;
Kyle McMartin9eb16862008-09-10 14:24:07 +000017
Kyle McMartin9eb16862008-09-10 14:24:07 +000018 ret = get_rtc_time(tm);
Kyle McMartin9eb16862008-09-10 14:24:07 +000019
20 if (ret & RTC_BATT_BAD)
21 return -EOPNOTSUPP;
22
dann frazierf62bacd2009-03-31 15:24:52 -070023 return rtc_valid_tm(tm);
Kyle McMartin9eb16862008-09-10 14:24:07 +000024}
25
26static int parisc_set_time(struct device *dev, struct rtc_time *tm)
27{
dann fraziera8c20cd2009-03-31 15:24:55 -070028 if (set_rtc_time(tm) < 0)
Kyle McMartin9eb16862008-09-10 14:24:07 +000029 return -EOPNOTSUPP;
30
31 return 0;
32}
33
34static const struct rtc_class_ops parisc_rtc_ops = {
35 .read_time = parisc_get_time,
36 .set_time = parisc_set_time,
37};
38
dann frazier2b93cff2009-03-31 15:24:52 -070039static int __init parisc_rtc_probe(struct platform_device *dev)
Kyle McMartin9eb16862008-09-10 14:24:07 +000040{
dann frazierb250c962009-03-31 15:24:55 -070041 struct rtc_device *rtc;
Kyle McMartin9eb16862008-09-10 14:24:07 +000042
dann frazierb250c962009-03-31 15:24:55 -070043 rtc = rtc_device_register("rtc-parisc", &dev->dev, &parisc_rtc_ops,
44 THIS_MODULE);
45 if (IS_ERR(rtc))
46 return PTR_ERR(rtc);
Kyle McMartin9eb16862008-09-10 14:24:07 +000047
dann frazierb250c962009-03-31 15:24:55 -070048 platform_set_drvdata(dev, rtc);
Kyle McMartin9eb16862008-09-10 14:24:07 +000049
50 return 0;
51}
52
dann frazier2b93cff2009-03-31 15:24:52 -070053static int __exit parisc_rtc_remove(struct platform_device *dev)
Kyle McMartin9eb16862008-09-10 14:24:07 +000054{
dann frazierb250c962009-03-31 15:24:55 -070055 struct rtc_device *rtc = platform_get_drvdata(dev);
Kyle McMartin9eb16862008-09-10 14:24:07 +000056
dann frazierb250c962009-03-31 15:24:55 -070057 rtc_device_unregister(rtc);
Kyle McMartin9eb16862008-09-10 14:24:07 +000058
59 return 0;
60}
61
62static struct platform_driver parisc_rtc_driver = {
63 .driver = {
64 .name = "rtc-parisc",
65 .owner = THIS_MODULE,
66 },
67 .probe = parisc_rtc_probe,
68 .remove = __devexit_p(parisc_rtc_remove),
69};
70
71static int __init parisc_rtc_init(void)
72{
dann frazier2b93cff2009-03-31 15:24:52 -070073 return platform_driver_probe(&parisc_rtc_driver, parisc_rtc_probe);
Kyle McMartin9eb16862008-09-10 14:24:07 +000074}
75
76static void __exit parisc_rtc_fini(void)
77{
78 platform_driver_unregister(&parisc_rtc_driver);
79}
80
81module_init(parisc_rtc_init);
82module_exit(parisc_rtc_fini);
83
84MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
85MODULE_LICENSE("GPL");
86MODULE_DESCRIPTION("HP PA-RISC RTC driver");