rtc-ps3.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * PS3 RTC Driver
  4. *
  5. * Copyright 2009 Sony Corporation
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/rtc.h>
  11. #include <asm/lv1call.h>
  12. #include <asm/ps3.h>
  13. static u64 read_rtc(void)
  14. {
  15. int result;
  16. u64 rtc_val;
  17. u64 tb_val;
  18. result = lv1_get_rtc(&rtc_val, &tb_val);
  19. BUG_ON(result);
  20. return rtc_val;
  21. }
  22. static int ps3_get_time(struct device *dev, struct rtc_time *tm)
  23. {
  24. rtc_time64_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
  25. return 0;
  26. }
  27. static int ps3_set_time(struct device *dev, struct rtc_time *tm)
  28. {
  29. ps3_os_area_set_rtc_diff(rtc_tm_to_time64(tm) - read_rtc());
  30. return 0;
  31. }
  32. static const struct rtc_class_ops ps3_rtc_ops = {
  33. .read_time = ps3_get_time,
  34. .set_time = ps3_set_time,
  35. };
  36. static int __init ps3_rtc_probe(struct platform_device *dev)
  37. {
  38. struct rtc_device *rtc;
  39. rtc = devm_rtc_allocate_device(&dev->dev);
  40. if (IS_ERR(rtc))
  41. return PTR_ERR(rtc);
  42. rtc->ops = &ps3_rtc_ops;
  43. rtc->range_max = U64_MAX;
  44. platform_set_drvdata(dev, rtc);
  45. return rtc_register_device(rtc);
  46. }
  47. static struct platform_driver ps3_rtc_driver = {
  48. .driver = {
  49. .name = "rtc-ps3",
  50. },
  51. };
  52. module_platform_driver_probe(ps3_rtc_driver, ps3_rtc_probe);
  53. MODULE_AUTHOR("Sony Corporation");
  54. MODULE_LICENSE("GPL");
  55. MODULE_DESCRIPTION("ps3 RTC driver");
  56. MODULE_ALIAS("platform:rtc-ps3");