time.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * PS3 time and rtc routines.
  3. *
  4. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  5. * Copyright 2006 Sony Corp.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <asm/rtc.h>
  22. #include <asm/lv1call.h>
  23. #include <asm/ps3.h>
  24. #include "platform.h"
  25. #define dump_tm(_a) _dump_tm(_a, __func__, __LINE__)
  26. static void _dump_tm(const struct rtc_time *tm, const char* func, int line)
  27. {
  28. pr_debug("%s:%d tm_sec %d\n", func, line, tm->tm_sec);
  29. pr_debug("%s:%d tm_min %d\n", func, line, tm->tm_min);
  30. pr_debug("%s:%d tm_hour %d\n", func, line, tm->tm_hour);
  31. pr_debug("%s:%d tm_mday %d\n", func, line, tm->tm_mday);
  32. pr_debug("%s:%d tm_mon %d\n", func, line, tm->tm_mon);
  33. pr_debug("%s:%d tm_year %d\n", func, line, tm->tm_year);
  34. pr_debug("%s:%d tm_wday %d\n", func, line, tm->tm_wday);
  35. }
  36. #define dump_time(_a) _dump_time(_a, __func__, __LINE__)
  37. static void __attribute__ ((unused)) _dump_time(int time, const char* func,
  38. int line)
  39. {
  40. struct rtc_time tm;
  41. to_tm(time, &tm);
  42. pr_debug("%s:%d time %d\n", func, line, time);
  43. _dump_tm(&tm, func, line);
  44. }
  45. /**
  46. * rtc_shift - Difference in seconds between 1970 and the ps3 rtc value.
  47. */
  48. static s64 rtc_shift;
  49. void __init ps3_calibrate_decr(void)
  50. {
  51. int result;
  52. u64 tmp;
  53. result = ps3_repository_read_be_tb_freq(0, &tmp);
  54. BUG_ON(result);
  55. ppc_tb_freq = tmp;
  56. ppc_proc_freq = ppc_tb_freq * 40;
  57. rtc_shift = ps3_os_area_rtc_diff();
  58. }
  59. static u64 read_rtc(void)
  60. {
  61. int result;
  62. u64 rtc_val;
  63. u64 tb_val;
  64. result = lv1_get_rtc(&rtc_val, &tb_val);
  65. BUG_ON(result);
  66. return rtc_val;
  67. }
  68. int ps3_set_rtc_time(struct rtc_time *tm)
  69. {
  70. u64 now = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
  71. tm->tm_hour, tm->tm_min, tm->tm_sec);
  72. rtc_shift = now - read_rtc();
  73. return 0;
  74. }
  75. void ps3_get_rtc_time(struct rtc_time *tm)
  76. {
  77. to_tm(read_rtc() + rtc_shift, tm);
  78. tm->tm_year -= 1900;
  79. tm->tm_mon -= 1;
  80. }
  81. unsigned long __init ps3_get_boot_time(void)
  82. {
  83. return read_rtc() + rtc_shift;
  84. }