rtc-ps3.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * PS3 RTC Driver
  3. *
  4. * Copyright 2009 Sony Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program.
  17. * If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/rtc.h>
  23. #include <asm/lv1call.h>
  24. #include <asm/ps3.h>
  25. static u64 read_rtc(void)
  26. {
  27. int result;
  28. u64 rtc_val;
  29. u64 tb_val;
  30. result = lv1_get_rtc(&rtc_val, &tb_val);
  31. BUG_ON(result);
  32. return rtc_val;
  33. }
  34. static int ps3_get_time(struct device *dev, struct rtc_time *tm)
  35. {
  36. rtc_time_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
  37. return rtc_valid_tm(tm);
  38. }
  39. static int ps3_set_time(struct device *dev, struct rtc_time *tm)
  40. {
  41. unsigned long now;
  42. rtc_tm_to_time(tm, &now);
  43. ps3_os_area_set_rtc_diff(now - read_rtc());
  44. return 0;
  45. }
  46. static const struct rtc_class_ops ps3_rtc_ops = {
  47. .read_time = ps3_get_time,
  48. .set_time = ps3_set_time,
  49. };
  50. static int __init ps3_rtc_probe(struct platform_device *dev)
  51. {
  52. struct rtc_device *rtc;
  53. rtc = devm_rtc_device_register(&dev->dev, "rtc-ps3", &ps3_rtc_ops,
  54. THIS_MODULE);
  55. if (IS_ERR(rtc))
  56. return PTR_ERR(rtc);
  57. platform_set_drvdata(dev, rtc);
  58. return 0;
  59. }
  60. static struct platform_driver ps3_rtc_driver = {
  61. .driver = {
  62. .name = "rtc-ps3",
  63. },
  64. };
  65. module_platform_driver_probe(ps3_rtc_driver, ps3_rtc_probe);
  66. MODULE_AUTHOR("Sony Corporation");
  67. MODULE_LICENSE("GPL");
  68. MODULE_DESCRIPTION("ps3 RTC driver");
  69. MODULE_ALIAS("platform:rtc-ps3");