1 /* rtc-starfire.c: Starfire platform RTC driver.
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
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>
13 #include <asm/oplib.h>
15 MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
16 MODULE_DESCRIPTION("Starfire RTC driver");
17 MODULE_LICENSE("GPL");
20 struct rtc_device
*rtc
;
24 static u32
starfire_get_time(void)
26 static char obp_gettod
[32];
29 sprintf(obp_gettod
, "h# %08x unix-gettod",
30 (unsigned int) (long) &unix_tod
);
31 prom_feval(obp_gettod
);
36 static int starfire_read_time(struct device
*dev
, struct rtc_time
*tm
)
38 struct starfire_rtc
*p
= dev_get_drvdata(dev
);
39 unsigned long flags
, secs
;
41 spin_lock_irqsave(&p
->lock
, flags
);
42 secs
= starfire_get_time();
43 spin_unlock_irqrestore(&p
->lock
, flags
);
45 rtc_time_to_tm(secs
, tm
);
50 static int starfire_set_time(struct device
*dev
, struct rtc_time
*tm
)
55 err
= rtc_tm_to_time(tm
, &secs
);
59 /* Do nothing, time is set using the service processor
60 * console on this platform.
65 static const struct rtc_class_ops starfire_rtc_ops
= {
66 .read_time
= starfire_read_time
,
67 .set_time
= starfire_set_time
,
70 static int __devinit
starfire_rtc_probe(struct platform_device
*pdev
)
72 struct starfire_rtc
*p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
77 spin_lock_init(&p
->lock
);
79 p
->rtc
= rtc_device_register("starfire", &pdev
->dev
,
80 &starfire_rtc_ops
, THIS_MODULE
);
82 int err
= PTR_ERR(p
->rtc
);
86 platform_set_drvdata(pdev
, p
);
90 static int __devexit
starfire_rtc_remove(struct platform_device
*pdev
)
92 struct starfire_rtc
*p
= platform_get_drvdata(pdev
);
94 rtc_device_unregister(p
->rtc
);
100 static struct platform_driver starfire_rtc_driver
= {
102 .name
= "rtc-starfire",
103 .owner
= THIS_MODULE
,
105 .probe
= starfire_rtc_probe
,
106 .remove
= __devexit_p(starfire_rtc_remove
),
109 static int __init
starfire_rtc_init(void)
111 return platform_driver_register(&starfire_rtc_driver
);
114 static void __exit
starfire_rtc_exit(void)
116 platform_driver_unregister(&starfire_rtc_driver
);
119 module_init(starfire_rtc_init
);
120 module_exit(starfire_rtc_exit
);