diff options
-rw-r--r-- | drivers/rtc/Kconfig | 7 | ||||
-rw-r--r-- | drivers/rtc/Makefile | 1 | ||||
-rw-r--r-- | drivers/rtc/rtc-starfire.c | 120 |
3 files changed, 128 insertions, 0 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 23403fae45a7..ecdff2002476 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -599,4 +599,11 @@ config RTC_DRV_SUN4V | |||
599 | If you say Y here you will get support for the Hypervisor | 599 | If you say Y here you will get support for the Hypervisor |
600 | based RTC on SUN4V systems. | 600 | based RTC on SUN4V systems. |
601 | 601 | ||
602 | config RTC_DRV_STARFIRE | ||
603 | bool "Starfire RTC" | ||
604 | depends on SPARC64 | ||
605 | help | ||
606 | If you say Y here you will get support for the RTC found on | ||
607 | Starfire systems. | ||
608 | |||
602 | endif # RTC_CLASS | 609 | endif # RTC_CLASS |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 6850b04a9dd8..10f41f85c38a 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
@@ -40,6 +40,7 @@ obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o | |||
40 | obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o | 40 | obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o |
41 | obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o | 41 | obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o |
42 | obj-$(CONFIG_RTC_DRV_SUN4V) += rtc-sun4v.o | 42 | obj-$(CONFIG_RTC_DRV_SUN4V) += rtc-sun4v.o |
43 | obj-$(CONFIG_RTC_DRV_STARFIRE) += rtc-starfire.o | ||
43 | obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o | 44 | obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o |
44 | obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o | 45 | obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o |
45 | obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o | 46 | obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o |
diff --git a/drivers/rtc/rtc-starfire.c b/drivers/rtc/rtc-starfire.c new file mode 100644 index 000000000000..7ccb0dd700af --- /dev/null +++ b/drivers/rtc/rtc-starfire.c | |||
@@ -0,0 +1,120 @@ | |||
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> | ||
9 | #include <linux/time.h> | ||
10 | #include <linux/rtc.h> | ||
11 | #include <linux/platform_device.h> | ||
12 | |||
13 | #include <asm/oplib.h> | ||
14 | |||
15 | MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); | ||
16 | MODULE_DESCRIPTION("Starfire RTC driver"); | ||
17 | MODULE_LICENSE("GPL"); | ||
18 | |||
19 | struct starfire_rtc { | ||
20 | struct rtc_device *rtc; | ||
21 | spinlock_t lock; | ||
22 | }; | ||
23 | |||
24 | static u32 starfire_get_time(void) | ||
25 | { | ||
26 | static char obp_gettod[32]; | ||
27 | static u32 unix_tod; | ||
28 | |||
29 | sprintf(obp_gettod, "h# %08x unix-gettod", | ||
30 | (unsigned int) (long) &unix_tod); | ||
31 | prom_feval(obp_gettod); | ||
32 | |||
33 | return unix_tod; | ||
34 | } | ||
35 | |||
36 | static int starfire_read_time(struct device *dev, struct rtc_time *tm) | ||
37 | { | ||
38 | struct starfire_rtc *p = dev_get_drvdata(dev); | ||
39 | unsigned long flags, secs; | ||
40 | |||
41 | spin_lock_irqsave(&p->lock, flags); | ||
42 | secs = starfire_get_time(); | ||
43 | spin_unlock_irqrestore(&p->lock, flags); | ||
44 | |||
45 | rtc_time_to_tm(secs, tm); | ||
46 | |||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | static int starfire_set_time(struct device *dev, struct rtc_time *tm) | ||
51 | { | ||
52 | unsigned long secs; | ||
53 | int err; | ||
54 | |||
55 | err = rtc_tm_to_time(tm, &secs); | ||
56 | if (err) | ||
57 | return err; | ||
58 | |||
59 | /* Do nothing, time is set using the service processor | ||
60 | * console on this platform. | ||
61 | */ | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | static const struct rtc_class_ops starfire_rtc_ops = { | ||
66 | .read_time = starfire_read_time, | ||
67 | .set_time = starfire_set_time, | ||
68 | }; | ||
69 | |||
70 | static int __devinit starfire_rtc_probe(struct platform_device *pdev) | ||
71 | { | ||
72 | struct starfire_rtc *p = kzalloc(sizeof(*p), GFP_KERNEL); | ||
73 | |||
74 | if (!p) | ||
75 | return -ENOMEM; | ||
76 | |||
77 | spin_lock_init(&p->lock); | ||
78 | |||
79 | p->rtc = rtc_device_register("starfire", &pdev->dev, | ||
80 | &starfire_rtc_ops, THIS_MODULE); | ||
81 | if (IS_ERR(p->rtc)) { | ||
82 | int err = PTR_ERR(p->rtc); | ||
83 | kfree(p); | ||
84 | return err; | ||
85 | } | ||
86 | platform_set_drvdata(pdev, p); | ||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | static int __devexit starfire_rtc_remove(struct platform_device *pdev) | ||
91 | { | ||
92 | struct starfire_rtc *p = platform_get_drvdata(pdev); | ||
93 | |||
94 | rtc_device_unregister(p->rtc); | ||
95 | kfree(p); | ||
96 | |||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | static struct platform_driver starfire_rtc_driver = { | ||
101 | .driver = { | ||
102 | .name = "rtc-starfire", | ||
103 | .owner = THIS_MODULE, | ||
104 | }, | ||
105 | .probe = starfire_rtc_probe, | ||
106 | .remove = __devexit_p(starfire_rtc_remove), | ||
107 | }; | ||
108 | |||
109 | static int __init starfire_rtc_init(void) | ||
110 | { | ||
111 | return platform_driver_register(&starfire_rtc_driver); | ||
112 | } | ||
113 | |||
114 | static void __exit starfire_rtc_exit(void) | ||
115 | { | ||
116 | platform_driver_unregister(&starfire_rtc_driver); | ||
117 | } | ||
118 | |||
119 | module_init(starfire_rtc_init); | ||
120 | module_exit(starfire_rtc_exit); | ||