rtc-generic.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* rtc-generic: RTC driver using the generic RTC abstraction
  2. *
  3. * Copyright (C) 2008 Kyle McMartin <kyle@mcmartin.ca>
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/time.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/rtc.h>
  10. #include <asm/rtc.h>
  11. static int generic_get_time(struct device *dev, struct rtc_time *tm)
  12. {
  13. unsigned int ret = get_rtc_time(tm);
  14. if (ret & RTC_BATT_BAD)
  15. return -EOPNOTSUPP;
  16. return rtc_valid_tm(tm);
  17. }
  18. static int generic_set_time(struct device *dev, struct rtc_time *tm)
  19. {
  20. if (set_rtc_time(tm) < 0)
  21. return -EOPNOTSUPP;
  22. return 0;
  23. }
  24. static const struct rtc_class_ops generic_rtc_ops = {
  25. .read_time = generic_get_time,
  26. .set_time = generic_set_time,
  27. };
  28. static int __init generic_rtc_probe(struct platform_device *dev)
  29. {
  30. struct rtc_device *rtc;
  31. rtc = devm_rtc_device_register(&dev->dev, "rtc-generic",
  32. &generic_rtc_ops, THIS_MODULE);
  33. if (IS_ERR(rtc))
  34. return PTR_ERR(rtc);
  35. platform_set_drvdata(dev, rtc);
  36. return 0;
  37. }
  38. static struct platform_driver generic_rtc_driver = {
  39. .driver = {
  40. .name = "rtc-generic",
  41. },
  42. };
  43. module_platform_driver_probe(generic_rtc_driver, generic_rtc_probe);
  44. MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
  45. MODULE_LICENSE("GPL");
  46. MODULE_DESCRIPTION("Generic RTC driver");
  47. MODULE_ALIAS("platform:rtc-generic");