Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 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> |
dann frazier | 93d456d | 2009-03-31 15:24:49 -0700 | [diff] [blame] | 10 | #include <linux/rtc.h> |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 11 | |
| 12 | #include <asm/rtc.h> |
| 13 | |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 14 | static int parisc_get_time(struct device *dev, struct rtc_time *tm) |
| 15 | { |
dann frazier | 05439f1 | 2009-03-31 15:24:50 -0700 | [diff] [blame] | 16 | unsigned long ret; |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 17 | |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 18 | ret = get_rtc_time(tm); |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 19 | |
| 20 | if (ret & RTC_BATT_BAD) |
| 21 | return -EOPNOTSUPP; |
| 22 | |
dann frazier | f62bacd | 2009-03-31 15:24:52 -0700 | [diff] [blame] | 23 | return rtc_valid_tm(tm); |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | static int parisc_set_time(struct device *dev, struct rtc_time *tm) |
| 27 | { |
dann frazier | a8c20cd | 2009-03-31 15:24:55 -0700 | [diff] [blame] | 28 | if (set_rtc_time(tm) < 0) |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 29 | return -EOPNOTSUPP; |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static const struct rtc_class_ops parisc_rtc_ops = { |
| 35 | .read_time = parisc_get_time, |
| 36 | .set_time = parisc_set_time, |
| 37 | }; |
| 38 | |
dann frazier | 2b93cff | 2009-03-31 15:24:52 -0700 | [diff] [blame] | 39 | static int __init parisc_rtc_probe(struct platform_device *dev) |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 40 | { |
dann frazier | b250c96 | 2009-03-31 15:24:55 -0700 | [diff] [blame] | 41 | struct rtc_device *rtc; |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 42 | |
dann frazier | b250c96 | 2009-03-31 15:24:55 -0700 | [diff] [blame] | 43 | 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 McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 47 | |
dann frazier | b250c96 | 2009-03-31 15:24:55 -0700 | [diff] [blame] | 48 | platform_set_drvdata(dev, rtc); |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
dann frazier | 2b93cff | 2009-03-31 15:24:52 -0700 | [diff] [blame] | 53 | static int __exit parisc_rtc_remove(struct platform_device *dev) |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 54 | { |
dann frazier | b250c96 | 2009-03-31 15:24:55 -0700 | [diff] [blame] | 55 | struct rtc_device *rtc = platform_get_drvdata(dev); |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 56 | |
dann frazier | b250c96 | 2009-03-31 15:24:55 -0700 | [diff] [blame] | 57 | rtc_device_unregister(rtc); |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static 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 | |
| 71 | static int __init parisc_rtc_init(void) |
| 72 | { |
dann frazier | 2b93cff | 2009-03-31 15:24:52 -0700 | [diff] [blame] | 73 | return platform_driver_probe(&parisc_rtc_driver, parisc_rtc_probe); |
Kyle McMartin | 9eb1686 | 2008-09-10 14:24:07 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static void __exit parisc_rtc_fini(void) |
| 77 | { |
| 78 | platform_driver_unregister(&parisc_rtc_driver); |
| 79 | } |
| 80 | |
| 81 | module_init(parisc_rtc_init); |
| 82 | module_exit(parisc_rtc_fini); |
| 83 | |
| 84 | MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>"); |
| 85 | MODULE_LICENSE("GPL"); |
| 86 | MODULE_DESCRIPTION("HP PA-RISC RTC driver"); |