rtc-starfire.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* rtc-starfire.c: Starfire platform RTC driver.
  2. *
  3. * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/init.h>
  8. #include <linux/rtc.h>
  9. #include <linux/platform_device.h>
  10. #include <asm/oplib.h>
  11. MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
  12. MODULE_DESCRIPTION("Starfire RTC driver");
  13. MODULE_LICENSE("GPL");
  14. static u32 starfire_get_time(void)
  15. {
  16. static char obp_gettod[32];
  17. static u32 unix_tod;
  18. sprintf(obp_gettod, "h# %08x unix-gettod",
  19. (unsigned int) (long) &unix_tod);
  20. prom_feval(obp_gettod);
  21. return unix_tod;
  22. }
  23. static int starfire_read_time(struct device *dev, struct rtc_time *tm)
  24. {
  25. rtc_time_to_tm(starfire_get_time(), tm);
  26. return rtc_valid_tm(tm);
  27. }
  28. static const struct rtc_class_ops starfire_rtc_ops = {
  29. .read_time = starfire_read_time,
  30. };
  31. static int __init starfire_rtc_probe(struct platform_device *pdev)
  32. {
  33. struct rtc_device *rtc = rtc_device_register("starfire", &pdev->dev,
  34. &starfire_rtc_ops, THIS_MODULE);
  35. if (IS_ERR(rtc))
  36. return PTR_ERR(rtc);
  37. platform_set_drvdata(pdev, rtc);
  38. return 0;
  39. }
  40. static int __exit starfire_rtc_remove(struct platform_device *pdev)
  41. {
  42. struct rtc_device *rtc = platform_get_drvdata(pdev);
  43. rtc_device_unregister(rtc);
  44. return 0;
  45. }
  46. static struct platform_driver starfire_rtc_driver = {
  47. .driver = {
  48. .name = "rtc-starfire",
  49. .owner = THIS_MODULE,
  50. },
  51. .remove = __exit_p(starfire_rtc_remove),
  52. };
  53. static int __init starfire_rtc_init(void)
  54. {
  55. return platform_driver_probe(&starfire_rtc_driver, starfire_rtc_probe);
  56. }
  57. static void __exit starfire_rtc_exit(void)
  58. {
  59. platform_driver_unregister(&starfire_rtc_driver);
  60. }
  61. module_init(starfire_rtc_init);
  62. module_exit(starfire_rtc_exit);