David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 1 | /* rtc-starfire.c: Starfire platform RTC driver. |
| 2 | * |
| 3 | * Copyright (C) 2008 David S. Miller <davem@davemloft.net> |
| 4 | */ |
| 5 | |
| 6 | #include <linux/kernel.h> |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/init.h> |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 9 | #include <linux/rtc.h> |
| 10 | #include <linux/platform_device.h> |
| 11 | |
| 12 | #include <asm/oplib.h> |
| 13 | |
| 14 | MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); |
| 15 | MODULE_DESCRIPTION("Starfire RTC driver"); |
| 16 | MODULE_LICENSE("GPL"); |
| 17 | |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 18 | static u32 starfire_get_time(void) |
| 19 | { |
| 20 | static char obp_gettod[32]; |
| 21 | static u32 unix_tod; |
| 22 | |
| 23 | sprintf(obp_gettod, "h# %08x unix-gettod", |
| 24 | (unsigned int) (long) &unix_tod); |
| 25 | prom_feval(obp_gettod); |
| 26 | |
| 27 | return unix_tod; |
| 28 | } |
| 29 | |
| 30 | static int starfire_read_time(struct device *dev, struct rtc_time *tm) |
| 31 | { |
Alessandro Zummo | be1ffce | 2008-11-21 01:24:38 -0800 | [diff] [blame] | 32 | rtc_time_to_tm(starfire_get_time(), tm); |
| 33 | return rtc_valid_tm(tm); |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static const struct rtc_class_ops starfire_rtc_ops = { |
| 37 | .read_time = starfire_read_time, |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Alessandro Zummo | be1ffce | 2008-11-21 01:24:38 -0800 | [diff] [blame] | 40 | static int __init starfire_rtc_probe(struct platform_device *pdev) |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 41 | { |
Alessandro Zummo | be1ffce | 2008-11-21 01:24:38 -0800 | [diff] [blame] | 42 | struct rtc_device *rtc = rtc_device_register("starfire", &pdev->dev, |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 43 | &starfire_rtc_ops, THIS_MODULE); |
Alessandro Zummo | be1ffce | 2008-11-21 01:24:38 -0800 | [diff] [blame] | 44 | if (IS_ERR(rtc)) |
| 45 | return PTR_ERR(rtc); |
| 46 | |
| 47 | platform_set_drvdata(pdev, rtc); |
| 48 | |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 49 | return 0; |
| 50 | } |
| 51 | |
Alessandro Zummo | be1ffce | 2008-11-21 01:24:38 -0800 | [diff] [blame] | 52 | static int __exit starfire_rtc_remove(struct platform_device *pdev) |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 53 | { |
Alessandro Zummo | be1ffce | 2008-11-21 01:24:38 -0800 | [diff] [blame] | 54 | struct rtc_device *rtc = platform_get_drvdata(pdev); |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 55 | |
Alessandro Zummo | be1ffce | 2008-11-21 01:24:38 -0800 | [diff] [blame] | 56 | rtc_device_unregister(rtc); |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static struct platform_driver starfire_rtc_driver = { |
| 62 | .driver = { |
| 63 | .name = "rtc-starfire", |
| 64 | .owner = THIS_MODULE, |
| 65 | }, |
Alessandro Zummo | be1ffce | 2008-11-21 01:24:38 -0800 | [diff] [blame] | 66 | .remove = __exit_p(starfire_rtc_remove), |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static int __init starfire_rtc_init(void) |
| 70 | { |
Alessandro Zummo | be1ffce | 2008-11-21 01:24:38 -0800 | [diff] [blame] | 71 | return platform_driver_probe(&starfire_rtc_driver, starfire_rtc_probe); |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static void __exit starfire_rtc_exit(void) |
| 75 | { |
| 76 | platform_driver_unregister(&starfire_rtc_driver); |
| 77 | } |
| 78 | |
| 79 | module_init(starfire_rtc_init); |
| 80 | module_exit(starfire_rtc_exit); |