David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 1 | /* rtc-starfire.c: Starfire platform RTC driver. |
| 2 | * |
Paul Gortmaker | 683cec8 | 2016-10-31 14:55:26 -0400 | [diff] [blame] | 3 | * Author: David S. Miller |
| 4 | * License: GPL |
| 5 | * |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 6 | * Copyright (C) 2008 David S. Miller <davem@davemloft.net> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/kernel.h> |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 10 | #include <linux/init.h> |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 11 | #include <linux/rtc.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | |
| 14 | #include <asm/oplib.h> |
| 15 | |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 16 | static u32 starfire_get_time(void) |
| 17 | { |
| 18 | static char obp_gettod[32]; |
| 19 | static u32 unix_tod; |
| 20 | |
| 21 | sprintf(obp_gettod, "h# %08x unix-gettod", |
| 22 | (unsigned int) (long) &unix_tod); |
| 23 | prom_feval(obp_gettod); |
| 24 | |
| 25 | return unix_tod; |
| 26 | } |
| 27 | |
| 28 | static int starfire_read_time(struct device *dev, struct rtc_time *tm) |
| 29 | { |
Alessandro Zummo | be1ffce | 2008-11-21 01:24:38 -0800 | [diff] [blame] | 30 | rtc_time_to_tm(starfire_get_time(), tm); |
| 31 | return rtc_valid_tm(tm); |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static const struct rtc_class_ops starfire_rtc_ops = { |
| 35 | .read_time = starfire_read_time, |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
Alessandro Zummo | be1ffce | 2008-11-21 01:24:38 -0800 | [diff] [blame] | 38 | static int __init starfire_rtc_probe(struct platform_device *pdev) |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 39 | { |
Jingoo Han | 45e3986 | 2013-04-29 16:19:50 -0700 | [diff] [blame] | 40 | struct rtc_device *rtc; |
| 41 | |
| 42 | rtc = devm_rtc_device_register(&pdev->dev, "starfire", |
| 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 | |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 52 | static struct platform_driver starfire_rtc_driver = { |
| 53 | .driver = { |
| 54 | .name = "rtc-starfire", |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 55 | }, |
David S. Miller | de2cf33 | 2008-08-28 23:02:36 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Paul Gortmaker | 683cec8 | 2016-10-31 14:55:26 -0400 | [diff] [blame] | 58 | builtin_platform_driver_probe(starfire_rtc_driver, starfire_rtc_probe); |