blob: d726c6aa96a8fab1f69859cc364d969522d93be0 [file] [log] [blame]
Geert Uytterhoeven3afe6d02009-02-19 16:46:49 +01001/* rtc-generic: RTC driver using the generic RTC abstraction
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
Arnd Bergmann64232fc2016-03-01 17:59:57 +010012#if defined(CONFIG_M68K) || defined(CONFIG_PARISC) || \
13 defined(CONFIG_PPC) || defined(CONFIG_SUPERH32)
Geert Uytterhoeven3afe6d02009-02-19 16:46:49 +010014#include <asm/rtc.h>
15
16static int generic_get_time(struct device *dev, struct rtc_time *tm)
17{
18 unsigned int ret = get_rtc_time(tm);
19
20 if (ret & RTC_BATT_BAD)
21 return -EOPNOTSUPP;
22
23 return rtc_valid_tm(tm);
24}
25
26static int generic_set_time(struct device *dev, struct rtc_time *tm)
27{
28 if (set_rtc_time(tm) < 0)
29 return -EOPNOTSUPP;
30
31 return 0;
32}
33
34static const struct rtc_class_ops generic_rtc_ops = {
35 .read_time = generic_get_time,
36 .set_time = generic_set_time,
37};
Arnd Bergmann64232fc2016-03-01 17:59:57 +010038#else
39#define generic_rtc_ops *(struct rtc_class_ops*)NULL
40#endif
Geert Uytterhoeven3afe6d02009-02-19 16:46:49 +010041
42static int __init generic_rtc_probe(struct platform_device *dev)
43{
44 struct rtc_device *rtc;
Arnd Bergmann64232fc2016-03-01 17:59:57 +010045 const struct rtc_class_ops *ops;
46
47 ops = dev_get_platdata(&dev->dev);
48 if (!ops)
49 ops = &generic_rtc_ops;
Geert Uytterhoeven3afe6d02009-02-19 16:46:49 +010050
Jingoo Han360fe132013-04-29 16:19:37 -070051 rtc = devm_rtc_device_register(&dev->dev, "rtc-generic",
Arnd Bergmann64232fc2016-03-01 17:59:57 +010052 ops, THIS_MODULE);
Geert Uytterhoeven3afe6d02009-02-19 16:46:49 +010053 if (IS_ERR(rtc))
54 return PTR_ERR(rtc);
55
56 platform_set_drvdata(dev, rtc);
57
58 return 0;
59}
60
Geert Uytterhoeven3afe6d02009-02-19 16:46:49 +010061static struct platform_driver generic_rtc_driver = {
62 .driver = {
63 .name = "rtc-generic",
Geert Uytterhoeven3afe6d02009-02-19 16:46:49 +010064 },
Geert Uytterhoeven3afe6d02009-02-19 16:46:49 +010065};
66
Jingoo Hana53f9a42013-04-29 16:18:41 -070067module_platform_driver_probe(generic_rtc_driver, generic_rtc_probe);
Geert Uytterhoeven3afe6d02009-02-19 16:46:49 +010068
69MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
70MODULE_LICENSE("GPL");
71MODULE_DESCRIPTION("Generic RTC driver");
72MODULE_ALIAS("platform:rtc-generic");