rtc-ppc.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * RTC driver for ppc_md RTC functions
  3. *
  4. * © 2007 Red Hat, Inc.
  5. *
  6. * Author: David Woodhouse <dwmw2@infradead.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/err.h>
  14. #include <linux/rtc.h>
  15. #include <linux/platform_device.h>
  16. #include <asm/machdep.h>
  17. static int ppc_rtc_read_time(struct device *dev, struct rtc_time *tm)
  18. {
  19. ppc_md.get_rtc_time(tm);
  20. return 0;
  21. }
  22. static int ppc_rtc_set_time(struct device *dev, struct rtc_time *tm)
  23. {
  24. return ppc_md.set_rtc_time(tm);
  25. }
  26. static const struct rtc_class_ops ppc_rtc_ops = {
  27. .set_time = ppc_rtc_set_time,
  28. .read_time = ppc_rtc_read_time,
  29. };
  30. static struct rtc_device *rtc;
  31. static struct platform_device *ppc_rtc_pdev;
  32. static int __init ppc_rtc_init(void)
  33. {
  34. if (!ppc_md.get_rtc_time || !ppc_md.set_rtc_time)
  35. return -ENODEV;
  36. ppc_rtc_pdev = platform_device_register_simple("ppc-rtc", 0, NULL, 0);
  37. if (IS_ERR(ppc_rtc_pdev))
  38. return PTR_ERR(ppc_rtc_pdev);
  39. rtc = rtc_device_register("ppc_md", &ppc_rtc_pdev->dev,
  40. &ppc_rtc_ops, THIS_MODULE);
  41. if (IS_ERR(rtc)) {
  42. platform_device_unregister(ppc_rtc_pdev);
  43. return PTR_ERR(rtc);
  44. }
  45. return 0;
  46. }
  47. static void __exit ppc_rtc_exit(void)
  48. {
  49. rtc_device_unregister(rtc);
  50. platform_device_unregister(ppc_rtc_pdev);
  51. }
  52. module_init(ppc_rtc_init);
  53. module_exit(ppc_rtc_exit);
  54. MODULE_LICENSE("GPL");
  55. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  56. MODULE_DESCRIPTION("Generic RTC class driver for PowerPC");