rtc-parisc: use rtc_valid_tm() in parisc_get_time
[deliverable/linux.git] / drivers / rtc / rtc-parisc.c
1 /* 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>
10 #include <linux/rtc.h>
11
12 #include <asm/rtc.h>
13
14 static int parisc_get_time(struct device *dev, struct rtc_time *tm)
15 {
16 unsigned long ret;
17
18 ret = get_rtc_time(tm);
19
20 if (ret & RTC_BATT_BAD)
21 return -EOPNOTSUPP;
22
23 return rtc_valid_tm(tm);
24 }
25
26 static int parisc_set_time(struct device *dev, struct rtc_time *tm)
27 {
28 int ret;
29
30 ret = set_rtc_time(tm);
31
32 if (ret < 0)
33 return -EOPNOTSUPP;
34
35 return 0;
36 }
37
38 static const struct rtc_class_ops parisc_rtc_ops = {
39 .read_time = parisc_get_time,
40 .set_time = parisc_set_time,
41 };
42
43 static int __devinit parisc_rtc_probe(struct platform_device *dev)
44 {
45 struct rtc_device *p;
46
47 p = kzalloc(sizeof (*p), GFP_KERNEL);
48 if (!p)
49 return -ENOMEM;
50
51 p = rtc_device_register("rtc-parisc", &dev->dev, &parisc_rtc_ops,
52 THIS_MODULE);
53 if (IS_ERR(p)) {
54 int err = PTR_ERR(p);
55 kfree(p);
56 return err;
57 }
58
59 platform_set_drvdata(dev, p);
60
61 return 0;
62 }
63
64 static int __devexit parisc_rtc_remove(struct platform_device *dev)
65 {
66 struct rtc_device *p = platform_get_drvdata(dev);
67
68 rtc_device_unregister(p);
69 kfree(p);
70
71 return 0;
72 }
73
74 static struct platform_driver parisc_rtc_driver = {
75 .driver = {
76 .name = "rtc-parisc",
77 .owner = THIS_MODULE,
78 },
79 .probe = parisc_rtc_probe,
80 .remove = __devexit_p(parisc_rtc_remove),
81 };
82
83 static int __init parisc_rtc_init(void)
84 {
85 return platform_driver_register(&parisc_rtc_driver);
86 }
87
88 static void __exit parisc_rtc_fini(void)
89 {
90 platform_driver_unregister(&parisc_rtc_driver);
91 }
92
93 module_init(parisc_rtc_init);
94 module_exit(parisc_rtc_fini);
95
96 MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
97 MODULE_LICENSE("GPL");
98 MODULE_DESCRIPTION("HP PA-RISC RTC driver");
This page took 0.035343 seconds and 5 git commands to generate.