blob: f7d8a6db8078d9af88e9cdff08b2175d28b49b41 [file] [log] [blame]
David S. Millerde2cf332008-08-28 23:02:36 -07001/* 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. Millerde2cf332008-08-28 23:02:36 -07009#include <linux/rtc.h>
10#include <linux/platform_device.h>
11
12#include <asm/oplib.h>
13
14MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
15MODULE_DESCRIPTION("Starfire RTC driver");
16MODULE_LICENSE("GPL");
17
David S. Millerde2cf332008-08-28 23:02:36 -070018static 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
30static int starfire_read_time(struct device *dev, struct rtc_time *tm)
31{
Alessandro Zummobe1ffce2008-11-21 01:24:38 -080032 rtc_time_to_tm(starfire_get_time(), tm);
33 return rtc_valid_tm(tm);
David S. Millerde2cf332008-08-28 23:02:36 -070034}
35
36static const struct rtc_class_ops starfire_rtc_ops = {
37 .read_time = starfire_read_time,
David S. Millerde2cf332008-08-28 23:02:36 -070038};
39
Alessandro Zummobe1ffce2008-11-21 01:24:38 -080040static int __init starfire_rtc_probe(struct platform_device *pdev)
David S. Millerde2cf332008-08-28 23:02:36 -070041{
Jingoo Han45e39862013-04-29 16:19:50 -070042 struct rtc_device *rtc;
43
44 rtc = devm_rtc_device_register(&pdev->dev, "starfire",
45 &starfire_rtc_ops, THIS_MODULE);
Alessandro Zummobe1ffce2008-11-21 01:24:38 -080046 if (IS_ERR(rtc))
47 return PTR_ERR(rtc);
48
49 platform_set_drvdata(pdev, rtc);
50
David S. Millerde2cf332008-08-28 23:02:36 -070051 return 0;
52}
53
David S. Millerde2cf332008-08-28 23:02:36 -070054static struct platform_driver starfire_rtc_driver = {
55 .driver = {
56 .name = "rtc-starfire",
57 .owner = THIS_MODULE,
58 },
David S. Millerde2cf332008-08-28 23:02:36 -070059};
60
Jingoo Han67bef2d2013-04-29 16:18:52 -070061module_platform_driver_probe(starfire_rtc_driver, starfire_rtc_probe);