rtc-starfire.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* rtc-starfire.c: Starfire platform RTC driver.
  2. *
  3. * Author: David S. Miller
  4. * License: GPL
  5. *
  6. * Copyright (C) 2008 David S. Miller <[email protected]>
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/rtc.h>
  11. #include <linux/platform_device.h>
  12. #include <asm/oplib.h>
  13. static u32 starfire_get_time(void)
  14. {
  15. static char obp_gettod[32];
  16. static u32 unix_tod;
  17. sprintf(obp_gettod, "h# %08x unix-gettod",
  18. (unsigned int) (long) &unix_tod);
  19. prom_feval(obp_gettod);
  20. return unix_tod;
  21. }
  22. static int starfire_read_time(struct device *dev, struct rtc_time *tm)
  23. {
  24. rtc_time64_to_tm(starfire_get_time(), tm);
  25. return 0;
  26. }
  27. static const struct rtc_class_ops starfire_rtc_ops = {
  28. .read_time = starfire_read_time,
  29. };
  30. static int __init starfire_rtc_probe(struct platform_device *pdev)
  31. {
  32. struct rtc_device *rtc;
  33. rtc = devm_rtc_allocate_device(&pdev->dev);
  34. if (IS_ERR(rtc))
  35. return PTR_ERR(rtc);
  36. rtc->ops = &starfire_rtc_ops;
  37. rtc->range_max = U32_MAX;
  38. platform_set_drvdata(pdev, rtc);
  39. return devm_rtc_register_device(rtc);
  40. }
  41. static struct platform_driver starfire_rtc_driver = {
  42. .driver = {
  43. .name = "rtc-starfire",
  44. },
  45. };
  46. builtin_platform_driver_probe(starfire_rtc_driver, starfire_rtc_probe);