Geert Uytterhoeven | 3afe6d0 | 2009-02-19 16:46:49 +0100 | [diff] [blame] | 1 | /* 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 Bergmann | 169047f | 2016-05-30 20:58:00 +0200 | [diff] [blame] | 12 | #if 0 |
Geert Uytterhoeven | 3afe6d0 | 2009-02-19 16:46:49 +0100 | [diff] [blame] | 13 | #include <asm/rtc.h> |
| 14 | |
| 15 | static int generic_get_time(struct device *dev, struct rtc_time *tm) |
| 16 | { |
| 17 | unsigned int ret = get_rtc_time(tm); |
| 18 | |
| 19 | if (ret & RTC_BATT_BAD) |
| 20 | return -EOPNOTSUPP; |
| 21 | |
| 22 | return rtc_valid_tm(tm); |
| 23 | } |
| 24 | |
| 25 | static int generic_set_time(struct device *dev, struct rtc_time *tm) |
| 26 | { |
| 27 | if (set_rtc_time(tm) < 0) |
| 28 | return -EOPNOTSUPP; |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | static const struct rtc_class_ops generic_rtc_ops = { |
| 34 | .read_time = generic_get_time, |
| 35 | .set_time = generic_set_time, |
| 36 | }; |
Arnd Bergmann | 64232fc | 2016-03-01 17:59:57 +0100 | [diff] [blame] | 37 | #else |
| 38 | #define generic_rtc_ops *(struct rtc_class_ops*)NULL |
| 39 | #endif |
Geert Uytterhoeven | 3afe6d0 | 2009-02-19 16:46:49 +0100 | [diff] [blame] | 40 | |
| 41 | static int __init generic_rtc_probe(struct platform_device *dev) |
| 42 | { |
| 43 | struct rtc_device *rtc; |
Arnd Bergmann | 64232fc | 2016-03-01 17:59:57 +0100 | [diff] [blame] | 44 | const struct rtc_class_ops *ops; |
| 45 | |
| 46 | ops = dev_get_platdata(&dev->dev); |
| 47 | if (!ops) |
| 48 | ops = &generic_rtc_ops; |
Geert Uytterhoeven | 3afe6d0 | 2009-02-19 16:46:49 +0100 | [diff] [blame] | 49 | |
Jingoo Han | 360fe13 | 2013-04-29 16:19:37 -0700 | [diff] [blame] | 50 | rtc = devm_rtc_device_register(&dev->dev, "rtc-generic", |
Arnd Bergmann | 64232fc | 2016-03-01 17:59:57 +0100 | [diff] [blame] | 51 | ops, THIS_MODULE); |
Geert Uytterhoeven | 3afe6d0 | 2009-02-19 16:46:49 +0100 | [diff] [blame] | 52 | if (IS_ERR(rtc)) |
| 53 | return PTR_ERR(rtc); |
| 54 | |
| 55 | platform_set_drvdata(dev, rtc); |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
Geert Uytterhoeven | 3afe6d0 | 2009-02-19 16:46:49 +0100 | [diff] [blame] | 60 | static struct platform_driver generic_rtc_driver = { |
| 61 | .driver = { |
| 62 | .name = "rtc-generic", |
Geert Uytterhoeven | 3afe6d0 | 2009-02-19 16:46:49 +0100 | [diff] [blame] | 63 | }, |
Geert Uytterhoeven | 3afe6d0 | 2009-02-19 16:46:49 +0100 | [diff] [blame] | 64 | }; |
| 65 | |
Jingoo Han | a53f9a4 | 2013-04-29 16:18:41 -0700 | [diff] [blame] | 66 | module_platform_driver_probe(generic_rtc_driver, generic_rtc_probe); |
Geert Uytterhoeven | 3afe6d0 | 2009-02-19 16:46:49 +0100 | [diff] [blame] | 67 | |
| 68 | MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>"); |
| 69 | MODULE_LICENSE("GPL"); |
| 70 | MODULE_DESCRIPTION("Generic RTC driver"); |
| 71 | MODULE_ALIAS("platform:rtc-generic"); |